MVTWorkTile.js 671 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628
  1. /**
  2. * Cesium - https://github.com/AnalyticalGraphicsInc/cesium
  3. *
  4. * Copyright 2011-2017 Cesium Contributors
  5. *
  6. * Licensed under the Apache License, Version 2.0 (the "License");
  7. * you may not use this file except in compliance with the License.
  8. * You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. *
  18. * Columbus View (Pat. Pend.)
  19. *
  20. * Portions licensed separately.
  21. * See https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md for full licensing details.
  22. */
  23. define(['./when-8d13db60', './createTaskProcessorWorker', './earcut-2.2.1-b404d9e6', './defined-21f7e510', './pbf-9fe59c76'], function (when, createTaskProcessorWorker, earcut2_2_1, defined, pbf) { 'use strict';
  24. function DictionaryCoder(strings) {
  25. this._stringToNumber = {};
  26. this._numberToString = [];
  27. for (var i = 0; i < strings.length; i++) {
  28. var string = strings[i];
  29. this._stringToNumber[string] = i;
  30. this._numberToString[i] = string;
  31. }
  32. }
  33. DictionaryCoder.prototype.encode = function(string) {
  34. return this._stringToNumber[string];
  35. };
  36. DictionaryCoder.prototype.decode = function(n) {
  37. return this._numberToString[n];
  38. };
  39. var viewTypes = {
  40. 'Int8': Int8Array,
  41. 'Uint8': Uint8Array,
  42. 'Int16': Int16Array,
  43. 'Uint16': Uint16Array,
  44. 'Int32': Int32Array,
  45. 'Uint32': Uint32Array,
  46. 'Float32': Float32Array
  47. };
  48. /**
  49. * Given a list of member fields, create a full StructArrayLayout, in
  50. * particular calculating the correct byte offset for each field. This data
  51. * is used at build time to generate StructArrayLayout_*#emplaceBack() and
  52. * other accessors, and at runtime for binding vertex buffer attributes.
  53. *
  54. * @private
  55. */
  56. function createLayout(members, alignment) {
  57. if (alignment === void 0) alignment = 1;
  58. var offset = 0;
  59. var maxSize = 0;
  60. var layoutMembers = members.map(function (member) {
  61. //assert_1(member.name.length);
  62. var typeSize = sizeOf(member.type);
  63. var memberOffset = offset = align(offset, Math.max(alignment, typeSize));
  64. var components = member.components || 1;
  65. maxSize = Math.max(maxSize, typeSize);
  66. offset += typeSize * components;
  67. return {
  68. name: member.name,
  69. type: member.type,
  70. components: components,
  71. offset: memberOffset,
  72. };
  73. });
  74. var size = align(offset, Math.max(maxSize, alignment));
  75. return {
  76. members: layoutMembers,
  77. size: size,
  78. alignment: alignment
  79. };
  80. }
  81. function sizeOf(type) {
  82. return viewTypes[type].BYTES_PER_ELEMENT;
  83. }
  84. function align(offset, size) {
  85. return Math.ceil(offset / size) * size;
  86. }
  87. var IMAGE_PADDING = 1;
  88. var ImagePosition = function ImagePosition(paddedRect, ref) {
  89. var pixelRatio = ref.pixelRatio;
  90. var version = ref.version;
  91. var stretchX = ref.stretchX;
  92. var stretchY = ref.stretchY;
  93. var content = ref.content;
  94. this.paddedRect = paddedRect;
  95. this.pixelRatio = pixelRatio;
  96. this.stretchX = stretchX;
  97. this.stretchY = stretchY;
  98. this.content = content;
  99. this.version = version;
  100. };
  101. var prototypeAccessors = { tl: { configurable: true }, br: { configurable: true }, tlbr: { configurable: true }, displaySize: { configurable: true } };
  102. prototypeAccessors.tl.get = function () {
  103. return [
  104. this.paddedRect.x + IMAGE_PADDING,
  105. this.paddedRect.y + IMAGE_PADDING
  106. ];
  107. };
  108. prototypeAccessors.br.get = function () {
  109. return [
  110. this.paddedRect.x + this.paddedRect.w - IMAGE_PADDING,
  111. this.paddedRect.y + this.paddedRect.h - IMAGE_PADDING
  112. ];
  113. };
  114. prototypeAccessors.tlbr.get = function () {
  115. return this.tl.concat(this.br);
  116. };
  117. prototypeAccessors.displaySize.get = function () {
  118. return [
  119. (this.paddedRect.w - IMAGE_PADDING * 2) / this.pixelRatio,
  120. (this.paddedRect.h - IMAGE_PADDING * 2) / this.pixelRatio
  121. ];
  122. };
  123. Object.defineProperties(ImagePosition.prototype, prototypeAccessors);
  124. // Not premultiplied, because ImageData is not premultiplied.
  125. // UNPACK_PREMULTIPLY_ALPHA_WEBGL must be used when uploading to a texture.
  126. var RGBAImage = function RGBAImage(size, data) {
  127. createImage(this, size, 4, data);
  128. };
  129. RGBAImage.prototype.resize = function resize(size) {
  130. resizeImage(this, size, 4);
  131. };
  132. RGBAImage.prototype.replace = function replace(data, copy) {
  133. if (copy) {
  134. this.data.set(data);
  135. } else if (data instanceof Uint8ClampedArray) {
  136. this.data = new Uint8Array(data.buffer);
  137. } else {
  138. this.data = data;
  139. }
  140. };
  141. RGBAImage.prototype.clone = function clone() {
  142. return new RGBAImage({width: this.width, height: this.height}, new Uint8Array(this.data));
  143. };
  144. RGBAImage.copy = function copy(srcImg, dstImg, srcPt, dstPt, size) {
  145. copyImage(srcImg, dstImg, srcPt, dstPt, size, 4);
  146. };
  147. function createImage(image, ref, channels, data) {
  148. var width = ref.width;
  149. var height = ref.height;
  150. if (!data) {
  151. data = new Uint8Array(width * height * channels);
  152. } else if (data instanceof Uint8ClampedArray) {
  153. data = new Uint8Array(data.buffer);
  154. } else if (data.length !== width * height * channels) {
  155. throw new RangeError('mismatched image size');
  156. }
  157. image.width = width;
  158. image.height = height;
  159. image.data = data;
  160. return image;
  161. }
  162. function resizeImage(image, ref, channels) {
  163. var width = ref.width;
  164. var height = ref.height;
  165. if (width === image.width && height === image.height) {
  166. return;
  167. }
  168. var newImage = createImage({}, {width: width, height: height}, channels);
  169. copyImage(image, newImage, {x: 0, y: 0}, {x: 0, y: 0}, {
  170. width: Math.min(image.width, width),
  171. height: Math.min(image.height, height)
  172. }, channels);
  173. image.width = width;
  174. image.height = height;
  175. image.data = newImage.data;
  176. }
  177. function copyImage(srcImg, dstImg, srcPt, dstPt, size, channels) {
  178. if (size.width === 0 || size.height === 0) {
  179. return dstImg;
  180. }
  181. if (size.width > srcImg.width ||
  182. size.height > srcImg.height ||
  183. srcPt.x > srcImg.width - size.width ||
  184. srcPt.y > srcImg.height - size.height) {
  185. throw new RangeError('out of range source coordinates for image copy');
  186. }
  187. if (size.width > dstImg.width ||
  188. size.height > dstImg.height ||
  189. dstPt.x > dstImg.width - size.width ||
  190. dstPt.y > dstImg.height - size.height) {
  191. throw new RangeError('out of range destination coordinates for image copy');
  192. }
  193. var srcData = srcImg.data;
  194. var dstData = dstImg.data;
  195. //assert_1(srcData !== dstData);
  196. for (var y = 0; y < size.height; y++) {
  197. var srcOffset = ((srcPt.y + y) * srcImg.width + srcPt.x) * channels;
  198. var dstOffset = ((dstPt.y + y) * dstImg.width + dstPt.x) * channels;
  199. for (var i = 0; i < size.width * channels; i++) {
  200. dstData[dstOffset + i] = srcData[srcOffset + i];
  201. }
  202. }
  203. return dstImg;
  204. }
  205. function potpack(boxes) {
  206. // calculate total box area and maximum box width
  207. var area = 0;
  208. var maxWidth = 0;
  209. for (var i$1 = 0, list = boxes; i$1 < list.length; i$1 += 1) {
  210. var box = list[i$1];
  211. area += box.w * box.h;
  212. maxWidth = Math.max(maxWidth, box.w);
  213. }
  214. // sort the boxes for insertion by height, descending
  215. boxes.sort(function (a, b) { return b.h - a.h; });
  216. // aim for a squarish resulting container,
  217. // slightly adjusted for sub-100% space utilization
  218. var startWidth = Math.max(Math.ceil(Math.sqrt(area / 0.95)), maxWidth);
  219. // start with a single empty space, unbounded at the bottom
  220. var spaces = [{x: 0, y: 0, w: startWidth, h: Infinity}];
  221. var width = 0;
  222. var height = 0;
  223. for (var i$2 = 0, list$1 = boxes; i$2 < list$1.length; i$2 += 1) {
  224. // look through spaces backwards so that we check smaller spaces first
  225. var box$1 = list$1[i$2];
  226. for (var i = spaces.length - 1; i >= 0; i--) {
  227. var space = spaces[i];
  228. // look for empty spaces that can accommodate the current box
  229. if (box$1.w > space.w || box$1.h > space.h) { continue; }
  230. // found the space; add the box to its top-left corner
  231. // |-------|-------|
  232. // | box | |
  233. // |_______| |
  234. // | space |
  235. // |_______________|
  236. box$1.x = space.x;
  237. box$1.y = space.y;
  238. height = Math.max(height, box$1.y + box$1.h);
  239. width = Math.max(width, box$1.x + box$1.w);
  240. if (box$1.w === space.w && box$1.h === space.h) {
  241. // space matches the box exactly; remove it
  242. var last = spaces.pop();
  243. if (i < spaces.length) { spaces[i] = last; }
  244. } else if (box$1.h === space.h) {
  245. // space matches the box height; update it accordingly
  246. // |-------|---------------|
  247. // | box | updated space |
  248. // |_______|_______________|
  249. space.x += box$1.w;
  250. space.w -= box$1.w;
  251. } else if (box$1.w === space.w) {
  252. // space matches the box width; update it accordingly
  253. // |---------------|
  254. // | box |
  255. // |_______________|
  256. // | updated space |
  257. // |_______________|
  258. space.y += box$1.h;
  259. space.h -= box$1.h;
  260. } else {
  261. // otherwise the box splits the space into two spaces
  262. // |-------|-----------|
  263. // | box | new space |
  264. // |_______|___________|
  265. // | updated space |
  266. // |___________________|
  267. spaces.push({
  268. x: space.x + box$1.w,
  269. y: space.y,
  270. w: space.w - box$1.w,
  271. h: box$1.h
  272. });
  273. space.y += box$1.h;
  274. space.h -= box$1.h;
  275. }
  276. break;
  277. }
  278. }
  279. return {
  280. w: width, // container width
  281. h: height, // container height
  282. fill: (area / (width * height)) || 0 // space utilization
  283. };
  284. }
  285. var IMAGE_PADDING$1 = 1;
  286. var ImageAtlas = function ImageAtlas(icons, patterns) {
  287. var iconPositions = {}, patternPositions = {};
  288. this.haveRenderCallbacks = [];
  289. var bins = [];
  290. this.addImages(icons, iconPositions, bins);
  291. this.addImages(patterns, patternPositions, bins);
  292. var ref = potpack(bins);
  293. var w = ref.w;
  294. var h = ref.h;
  295. var image = new RGBAImage({width: w || 1, height: h || 1});
  296. for (var id in icons) {
  297. var src = icons[id];
  298. var bin = iconPositions[id].paddedRect;
  299. RGBAImage.copy(src.data, image, {x: 0, y: 0}, {x: bin.x + IMAGE_PADDING$1, y: bin.y + IMAGE_PADDING$1}, src.data);
  300. }
  301. for (var id$1 in patterns) {
  302. var src$1 = patterns[id$1];
  303. var bin$1 = patternPositions[id$1].paddedRect;
  304. var x = bin$1.x + IMAGE_PADDING$1,
  305. y = bin$1.y + IMAGE_PADDING$1,
  306. w$1 = src$1.data.width,
  307. h$1 = src$1.data.height;
  308. RGBAImage.copy(src$1.data, image, {x: 0, y: 0}, {x: x, y: y}, src$1.data);
  309. // Add 1 pixel wrapped padding on each side of the image.
  310. RGBAImage.copy(src$1.data, image, {x: 0, y: h$1 - 1}, {x: x, y: y - 1}, {width: w$1, height: 1}); // T
  311. RGBAImage.copy(src$1.data, image, {x: 0, y: 0}, {x: x, y: y + h$1}, {width: w$1, height: 1}); // B
  312. RGBAImage.copy(src$1.data, image, {x: w$1 - 1, y: 0}, {x: x - 1, y: y}, {width: 1, height: h$1}); // L
  313. RGBAImage.copy(src$1.data, image, {x: 0, y: 0}, {x: x + w$1, y: y}, {width: 1, height: h$1}); // R
  314. }
  315. this.image = image;
  316. this.iconPositions = iconPositions;
  317. this.patternPositions = patternPositions;
  318. };
  319. ImageAtlas.prototype.addImages = function addImages(images, positions, bins) {
  320. for (var id in images) {
  321. var src = images[id];
  322. var bin = {
  323. x: 0,
  324. y: 0,
  325. w: src.data.width + 2 * IMAGE_PADDING$1,
  326. h: src.data.height + 2 * IMAGE_PADDING$1,
  327. };
  328. bins.push(bin);
  329. positions[id] = new ImagePosition(bin, src);
  330. if (src.hasRenderCallback) {
  331. this.haveRenderCallbacks.push(id);
  332. }
  333. }
  334. };
  335. ImageAtlas.prototype.patchUpdatedImages = function patchUpdatedImages(imageManager, texture) {
  336. imageManager.dispatchRenderCallbacks(this.haveRenderCallbacks);
  337. for (var name in imageManager.updatedImages) {
  338. this.patchUpdatedImage(this.iconPositions[name], imageManager.getImage(name), texture);
  339. this.patchUpdatedImage(this.patternPositions[name], imageManager.getImage(name), texture);
  340. }
  341. };
  342. ImageAtlas.prototype.patchUpdatedImage = function patchUpdatedImage(position, image, texture) {
  343. if (!position || !image) {
  344. return;
  345. }
  346. if (position.version === image.version) {
  347. return;
  348. }
  349. position.version = image.version;
  350. var ref = position.tl;
  351. var x = ref[0];
  352. var y = ref[1];
  353. texture.update(image.data, undefined, {x: x, y: y});
  354. };
  355. // http://www.w3.org/TR/css3-color/
  356. var kCSSColorTable = {
  357. "transparent": [0,0,0,0], "aliceblue": [240,248,255,1],
  358. "antiquewhite": [250,235,215,1], "aqua": [0,255,255,1],
  359. "aquamarine": [127,255,212,1], "azure": [240,255,255,1],
  360. "beige": [245,245,220,1], "bisque": [255,228,196,1],
  361. "black": [0,0,0,1], "blanchedalmond": [255,235,205,1],
  362. "blue": [0,0,255,1], "blueviolet": [138,43,226,1],
  363. "brown": [165,42,42,1], "burlywood": [222,184,135,1],
  364. "cadetblue": [95,158,160,1], "chartreuse": [127,255,0,1],
  365. "chocolate": [210,105,30,1], "coral": [255,127,80,1],
  366. "cornflowerblue": [100,149,237,1], "cornsilk": [255,248,220,1],
  367. "crimson": [220,20,60,1], "cyan": [0,255,255,1],
  368. "darkblue": [0,0,139,1], "darkcyan": [0,139,139,1],
  369. "darkgoldenrod": [184,134,11,1], "darkgray": [169,169,169,1],
  370. "darkgreen": [0,100,0,1], "darkgrey": [169,169,169,1],
  371. "darkkhaki": [189,183,107,1], "darkmagenta": [139,0,139,1],
  372. "darkolivegreen": [85,107,47,1], "darkorange": [255,140,0,1],
  373. "darkorchid": [153,50,204,1], "darkred": [139,0,0,1],
  374. "darksalmon": [233,150,122,1], "darkseagreen": [143,188,143,1],
  375. "darkslateblue": [72,61,139,1], "darkslategray": [47,79,79,1],
  376. "darkslategrey": [47,79,79,1], "darkturquoise": [0,206,209,1],
  377. "darkviolet": [148,0,211,1], "deeppink": [255,20,147,1],
  378. "deepskyblue": [0,191,255,1], "dimgray": [105,105,105,1],
  379. "dimgrey": [105,105,105,1], "dodgerblue": [30,144,255,1],
  380. "firebrick": [178,34,34,1], "floralwhite": [255,250,240,1],
  381. "forestgreen": [34,139,34,1], "fuchsia": [255,0,255,1],
  382. "gainsboro": [220,220,220,1], "ghostwhite": [248,248,255,1],
  383. "gold": [255,215,0,1], "goldenrod": [218,165,32,1],
  384. "gray": [128,128,128,1], "green": [0,128,0,1],
  385. "greenyellow": [173,255,47,1], "grey": [128,128,128,1],
  386. "honeydew": [240,255,240,1], "hotpink": [255,105,180,1],
  387. "indianred": [205,92,92,1], "indigo": [75,0,130,1],
  388. "ivory": [255,255,240,1], "khaki": [240,230,140,1],
  389. "lavender": [230,230,250,1], "lavenderblush": [255,240,245,1],
  390. "lawngreen": [124,252,0,1], "lemonchiffon": [255,250,205,1],
  391. "lightblue": [173,216,230,1], "lightcoral": [240,128,128,1],
  392. "lightcyan": [224,255,255,1], "lightgoldenrodyellow": [250,250,210,1],
  393. "lightgray": [211,211,211,1], "lightgreen": [144,238,144,1],
  394. "lightgrey": [211,211,211,1], "lightpink": [255,182,193,1],
  395. "lightsalmon": [255,160,122,1], "lightseagreen": [32,178,170,1],
  396. "lightskyblue": [135,206,250,1], "lightslategray": [119,136,153,1],
  397. "lightslategrey": [119,136,153,1], "lightsteelblue": [176,196,222,1],
  398. "lightyellow": [255,255,224,1], "lime": [0,255,0,1],
  399. "limegreen": [50,205,50,1], "linen": [250,240,230,1],
  400. "magenta": [255,0,255,1], "maroon": [128,0,0,1],
  401. "mediumaquamarine": [102,205,170,1], "mediumblue": [0,0,205,1],
  402. "mediumorchid": [186,85,211,1], "mediumpurple": [147,112,219,1],
  403. "mediumseagreen": [60,179,113,1], "mediumslateblue": [123,104,238,1],
  404. "mediumspringgreen": [0,250,154,1], "mediumturquoise": [72,209,204,1],
  405. "mediumvioletred": [199,21,133,1], "midnightblue": [25,25,112,1],
  406. "mintcream": [245,255,250,1], "mistyrose": [255,228,225,1],
  407. "moccasin": [255,228,181,1], "navajowhite": [255,222,173,1],
  408. "navy": [0,0,128,1], "oldlace": [253,245,230,1],
  409. "olive": [128,128,0,1], "olivedrab": [107,142,35,1],
  410. "orange": [255,165,0,1], "orangered": [255,69,0,1],
  411. "orchid": [218,112,214,1], "palegoldenrod": [238,232,170,1],
  412. "palegreen": [152,251,152,1], "paleturquoise": [175,238,238,1],
  413. "palevioletred": [219,112,147,1], "papayawhip": [255,239,213,1],
  414. "peachpuff": [255,218,185,1], "peru": [205,133,63,1],
  415. "pink": [255,192,203,1], "plum": [221,160,221,1],
  416. "powderblue": [176,224,230,1], "purple": [128,0,128,1],
  417. "rebeccapurple": [102,51,153,1],
  418. "red": [255,0,0,1], "rosybrown": [188,143,143,1],
  419. "royalblue": [65,105,225,1], "saddlebrown": [139,69,19,1],
  420. "salmon": [250,128,114,1], "sandybrown": [244,164,96,1],
  421. "seagreen": [46,139,87,1], "seashell": [255,245,238,1],
  422. "sienna": [160,82,45,1], "silver": [192,192,192,1],
  423. "skyblue": [135,206,235,1], "slateblue": [106,90,205,1],
  424. "slategray": [112,128,144,1], "slategrey": [112,128,144,1],
  425. "snow": [255,250,250,1], "springgreen": [0,255,127,1],
  426. "steelblue": [70,130,180,1], "tan": [210,180,140,1],
  427. "teal": [0,128,128,1], "thistle": [216,191,216,1],
  428. "tomato": [255,99,71,1], "turquoise": [64,224,208,1],
  429. "violet": [238,130,238,1], "wheat": [245,222,179,1],
  430. "white": [255,255,255,1], "whitesmoke": [245,245,245,1],
  431. "yellow": [255,255,0,1], "yellowgreen": [154,205,50,1]};
  432. function clamp_css_byte(i) { // Clamp to integer 0 .. 255.
  433. i = Math.round(i); // Seems to be what Chrome does (vs truncation).
  434. return i < 0 ? 0 : i > 255 ? 255 : i;
  435. }
  436. function clamp_css_float(f) { // Clamp to float 0.0 .. 1.0.
  437. return f < 0 ? 0 : f > 1 ? 1 : f;
  438. }
  439. function parse_css_int(str) { // int or percentage.
  440. if (str[str.length - 1] === '%')
  441. return clamp_css_byte(parseFloat(str) / 100 * 255);
  442. return clamp_css_byte(parseInt(str));
  443. }
  444. function parse_css_float(str) { // float or percentage.
  445. if (str[str.length - 1] === '%')
  446. return clamp_css_float(parseFloat(str) / 100);
  447. return clamp_css_float(parseFloat(str));
  448. }
  449. function css_hue_to_rgb(m1, m2, h) {
  450. if (h < 0) h += 1;
  451. else if (h > 1) h -= 1;
  452. if (h * 6 < 1) return m1 + (m2 - m1) * h * 6;
  453. if (h * 2 < 1) return m2;
  454. if (h * 3 < 2) return m1 + (m2 - m1) * (2/3 - h) * 6;
  455. return m1;
  456. }
  457. function parseCSSColor(css_str) {
  458. // Remove all whitespace, not compliant, but should just be more accepting.
  459. var str = css_str.replace(/ /g, '').toLowerCase();
  460. // Color keywords (and transparent) lookup.
  461. if (str in kCSSColorTable) return kCSSColorTable[str].slice(); // dup.
  462. // #abc and #abc123 syntax.
  463. if (str[0] === '#') {
  464. if (str.length === 4) {
  465. var iv = parseInt(str.substr(1), 16); // TODO(deanm): Stricter parsing.
  466. if (!(iv >= 0 && iv <= 0xfff)) return null; // Covers NaN.
  467. return [((iv & 0xf00) >> 4) | ((iv & 0xf00) >> 8),
  468. (iv & 0xf0) | ((iv & 0xf0) >> 4),
  469. (iv & 0xf) | ((iv & 0xf) << 4),
  470. 1];
  471. } else if (str.length === 7) {
  472. var iv = parseInt(str.substr(1), 16); // TODO(deanm): Stricter parsing.
  473. if (!(iv >= 0 && iv <= 0xffffff)) return null; // Covers NaN.
  474. return [(iv & 0xff0000) >> 16,
  475. (iv & 0xff00) >> 8,
  476. iv & 0xff,
  477. 1];
  478. }
  479. return null;
  480. }
  481. var op = str.indexOf('('), ep = str.indexOf(')');
  482. if (op !== -1 && ep + 1 === str.length) {
  483. var fname = str.substr(0, op);
  484. var params = str.substr(op+1, ep-(op+1)).split(',');
  485. var alpha = 1; // To allow case fallthrough.
  486. switch (fname) {
  487. case 'rgba':
  488. if (params.length !== 4) return null;
  489. alpha = parse_css_float(params.pop());
  490. // Fall through.
  491. case 'rgb':
  492. if (params.length !== 3) return null;
  493. return [parse_css_int(params[0]),
  494. parse_css_int(params[1]),
  495. parse_css_int(params[2]),
  496. alpha];
  497. case 'hsla':
  498. if (params.length !== 4) return null;
  499. alpha = parse_css_float(params.pop());
  500. // Fall through.
  501. case 'hsl':
  502. if (params.length !== 3) return null;
  503. var h = (((parseFloat(params[0]) % 360) + 360) % 360) / 360; // 0 .. 1
  504. // NOTE(deanm): According to the CSS spec s/l should only be
  505. // percentages, but we don't bother and let float or percentage.
  506. var s = parse_css_float(params[1]);
  507. var l = parse_css_float(params[2]);
  508. var m2 = l <= 0.5 ? l * (s + 1) : l + s - l * s;
  509. var m1 = l * 2 - m2;
  510. return [clamp_css_byte(css_hue_to_rgb(m1, m2, h+1/3) * 255),
  511. clamp_css_byte(css_hue_to_rgb(m1, m2, h) * 255),
  512. clamp_css_byte(css_hue_to_rgb(m1, m2, h-1/3) * 255),
  513. alpha];
  514. default:
  515. return null;
  516. }
  517. }
  518. return null;
  519. }
  520. /**
  521. * An RGBA color value. Create instances from color strings using the static
  522. * method `Color.parse`. The constructor accepts RGB channel values in the range
  523. * `[0, 1]`, premultiplied by A.
  524. *
  525. * @param {number} r The red channel.
  526. * @param {number} g The green channel.
  527. * @param {number} b The blue channel.
  528. * @param {number} a The alpha channel.
  529. * @private
  530. */
  531. var Color$1 = function Color(r, g, b, a) {
  532. if (a === void 0) a = 1;
  533. this.r = r;
  534. this.g = g;
  535. this.b = b;
  536. this.a = a;
  537. };
  538. /**
  539. * Parses valid CSS color strings and returns a `Color` instance.
  540. * @returns A `Color` instance, or `undefined` if the input is not a valid color string.
  541. */
  542. Color$1.parse = function parse(input) {
  543. if (!input) {
  544. return undefined;
  545. }
  546. if (input instanceof Color$1) {
  547. return input;
  548. }
  549. if (typeof input !== 'string') {
  550. return undefined;
  551. }
  552. var rgba = parseCSSColor(input);
  553. if (!rgba) {
  554. return undefined;
  555. }
  556. return new Color$1(
  557. rgba[0] / 255 * rgba[3],
  558. rgba[1] / 255 * rgba[3],
  559. rgba[2] / 255 * rgba[3],
  560. rgba[3]
  561. );
  562. };
  563. /**
  564. * Returns an RGBA string representing the color value.
  565. *
  566. * @returns An RGBA string.
  567. * @example
  568. * var purple = new Color.parse('purple');
  569. * purple.toString; // = "rgba(128,0,128,1)"
  570. * var translucentGreen = new Color.parse('rgba(26, 207, 26, .73)');
  571. * translucentGreen.toString(); // = "rgba(26,207,26,0.73)"
  572. */
  573. Color$1.prototype.toString = function toString() {
  574. var ref = this.toArray();
  575. var r = ref[0];
  576. var g = ref[1];
  577. var b = ref[2];
  578. var a = ref[3];
  579. return ("rgba(" + (Math.round(r)) + "," + (Math.round(g)) + "," + (Math.round(b)) + "," + a + ")");
  580. };
  581. Color$1.prototype.toArray = function toArray() {
  582. var ref = this;
  583. var r = ref.r;
  584. var g = ref.g;
  585. var b = ref.b;
  586. var a = ref.a;
  587. return a === 0 ? [0, 0, 0, 0] : [
  588. r * 255 / a,
  589. g * 255 / a,
  590. b * 255 / a,
  591. a
  592. ];
  593. };
  594. Color$1.black = new Color$1(0, 0, 0, 1);
  595. Color$1.white = new Color$1(1, 1, 1, 1);
  596. Color$1.transparent = new Color$1(0, 0, 0, 0);
  597. Color$1.red = new Color$1(1, 0, 0, 1);
  598. var NullType = {kind: 'null'};
  599. var NumberType$1 = {kind: 'number'};
  600. var StringType = {kind: 'string'};
  601. var BooleanType = {kind: 'boolean'};
  602. var ColorType$1 = {kind: 'color'};
  603. var ObjectType = {kind: 'object'};
  604. var ValueType = {kind: 'value'};
  605. var FormattedType = {kind: 'formatted'};
  606. var ResolvedImageType = {kind: 'resolvedImage'};
  607. function array(itemType, N) {
  608. return {
  609. kind: 'array',
  610. itemType: itemType,
  611. N: N
  612. };
  613. }
  614. function toString$2(type) {
  615. if (type.kind === 'array') {
  616. var itemType = toString$2(type.itemType);
  617. return typeof type.N === 'number' ?
  618. ("array<" + itemType + ", " + (type.N) + ">") :
  619. type.itemType.kind === 'value' ? 'array' : ("array<" + itemType + ">");
  620. } else {
  621. return type.kind;
  622. }
  623. }
  624. var valueMemberTypes = [
  625. NullType,
  626. NumberType$1,
  627. StringType,
  628. BooleanType,
  629. ColorType$1,
  630. FormattedType,
  631. ObjectType,
  632. array(ValueType),
  633. ResolvedImageType
  634. ];
  635. /**
  636. * Returns null if `t` is a subtype of `expected`; otherwise returns an
  637. * error message.
  638. * @private
  639. */
  640. function checkSubtype(expected, t) {
  641. if (t.kind === 'error') {
  642. // Error is a subtype of every type
  643. return null;
  644. } else if (expected.kind === 'array') {
  645. if (t.kind === 'array' &&
  646. ((t.N === 0 && t.itemType.kind === 'value') || !checkSubtype(expected.itemType, t.itemType)) &&
  647. (typeof expected.N !== 'number' || expected.N === t.N)) {
  648. return null;
  649. }
  650. } else if (expected.kind === t.kind) {
  651. return null;
  652. } else if (expected.kind === 'value') {
  653. for (var i = 0, list = valueMemberTypes; i < list.length; i += 1) {
  654. var memberType = list[i];
  655. if (!checkSubtype(memberType, t)) {
  656. return null;
  657. }
  658. }
  659. }
  660. return ("Expected " + (toString$2(expected)) + " but found " + (toString$2(t)) + " instead.");
  661. }
  662. var Collator = function Collator(caseSensitive , diacriticSensitive , locale ) {
  663. if (caseSensitive)
  664. { this.sensitivity = diacriticSensitive ? 'variant' : 'case'; }
  665. else
  666. { this.sensitivity = diacriticSensitive ? 'accent' : 'base'; }
  667. this.locale = locale;
  668. this.collator = new Intl.Collator(this.locale ? this.locale : [],
  669. {sensitivity: this.sensitivity, usage: 'search'});
  670. };
  671. Collator.prototype.compare = function compare (lhs , rhs ) {
  672. return this.collator.compare(lhs, rhs);
  673. };
  674. Collator.prototype.resolvedLocale = function resolvedLocale () {
  675. // We create a Collator without "usage: search" because we don't want
  676. // the search options encoded in our result (e.g. "en-u-co-search")
  677. return new Intl.Collator(this.locale ? this.locale : [])
  678. .resolvedOptions().locale;
  679. };
  680. var FormattedSection = function FormattedSection(text, image, scale, fontStack, textColor) {
  681. this.text = text;
  682. this.image = image;
  683. this.scale = scale;
  684. this.fontStack = fontStack;
  685. this.textColor = textColor;
  686. };
  687. var Formatted$1 = function Formatted(sections) {
  688. this.sections = sections;
  689. };
  690. Formatted$1.fromString = function fromString(unformatted) {
  691. return new Formatted$1([new FormattedSection(unformatted, null, null, null, null)]);
  692. };
  693. Formatted$1.prototype.isEmpty = function isEmpty() {
  694. if (this.sections.length === 0) {
  695. return true;
  696. }
  697. return !this.sections.some(function (section) {
  698. return section.text.length !== 0 ||
  699. (section.image && section.image.name.length !== 0);
  700. });
  701. };
  702. Formatted$1.factory = function factory(text) {
  703. if (text instanceof Formatted$1) {
  704. return text;
  705. } else {
  706. return Formatted$1.fromString(text);
  707. }
  708. };
  709. Formatted$1.prototype.toString = function toString() {
  710. if (this.sections.length === 0) {
  711. return '';
  712. }
  713. return this.sections.map(function (section) {
  714. return section.text;
  715. }).join('');
  716. };
  717. Formatted$1.prototype.serialize = function serialize() {
  718. var serialized = ["format"];
  719. for (var i = 0, list = this.sections; i < list.length; i += 1) {
  720. var section = list[i];
  721. if (section.image) {
  722. serialized.push(["image", section.image.name]);
  723. continue;
  724. }
  725. serialized.push(section.text);
  726. var options = {};
  727. if (section.fontStack) {
  728. options["text-font"] = ["literal", section.fontStack.split(',')];
  729. }
  730. if (section.scale) {
  731. options["font-scale"] = section.scale;
  732. }
  733. if (section.textColor) {
  734. options["text-color"] = (["rgba"] ).concat(section.textColor.toArray());
  735. }
  736. serialized.push(options);
  737. }
  738. return serialized;
  739. };
  740. var ResolvedImage$1 = function ResolvedImage(options) {
  741. this.name = options.name;
  742. this.available = options.available;
  743. };
  744. ResolvedImage$1.prototype.toString = function toString() {
  745. return this.name;
  746. };
  747. ResolvedImage$1.fromString = function fromString(name) {
  748. return new ResolvedImage$1({name: name, available: false});
  749. };
  750. ResolvedImage$1.prototype.serialize = function serialize() {
  751. return ["image", this.name];
  752. };
  753. var NullType$1 = {kind: 'null'};
  754. var NumberType$2 = {kind: 'number'};
  755. var StringType$1 = {kind: 'string'};
  756. var BooleanType$1 = {kind: 'boolean'};
  757. var ColorType$2 = {kind: 'color'};
  758. var ObjectType$1 = {kind: 'object'};
  759. var ValueType$1 = {kind: 'value'};
  760. var CollatorType = {kind: 'collator'};
  761. var FormattedType$1 = {kind: 'formatted'};
  762. var ResolvedImageType$1 = {kind: 'resolvedImage'};
  763. function array$1(itemType, N) {
  764. return {
  765. kind: 'array',
  766. itemType: itemType,
  767. N: N
  768. };
  769. }
  770. function Values$1() {
  771. }
  772. Values$1.validateRGBA = function(r, g, b, a){
  773. if (!(
  774. typeof r === 'number' && r >= 0 && r <= 255 &&
  775. typeof g === 'number' && g >= 0 && g <= 255 &&
  776. typeof b === 'number' && b >= 0 && b <= 255
  777. )) {
  778. var value = typeof a === 'number' ? [r, g, b, a] : [r, g, b];
  779. return ("Invalid rgba value [" + (value.join(', ')) + "]: 'r', 'g', and 'b' must be between 0 and 255.");
  780. }
  781. if (!(
  782. typeof a === 'undefined' || (typeof a === 'number' && a >= 0 && a <= 1)
  783. )) {
  784. return ("Invalid rgba value [" + ([r, g, b, a].join(', ')) + "]: 'a' must be between 0 and 1.");
  785. }
  786. return null;
  787. };
  788. Values$1.isValue = function(mixed){
  789. if (mixed === null) {
  790. return true;
  791. } else if (typeof mixed === 'string') {
  792. return true;
  793. } else if (typeof mixed === 'boolean') {
  794. return true;
  795. } else if (typeof mixed === 'number') {
  796. return true;
  797. } else if (mixed instanceof Color$1) {
  798. return true;
  799. } else if (mixed instanceof Collator) {
  800. return true;
  801. } else if (mixed instanceof Formatted$1) {
  802. return true;
  803. } else if (mixed instanceof ResolvedImage$1) {
  804. return true;
  805. } else if (Array.isArray(mixed)) {
  806. for (var i = 0, list = mixed; i < list.length; i += 1) {
  807. var item = list[i];
  808. if (!Values$1.isValue(item)) {
  809. return false;
  810. }
  811. }
  812. return true;
  813. } else if (typeof mixed === 'object') {
  814. for (var key in mixed) {
  815. if (!Values$1.isValue(mixed[key])) {
  816. return false;
  817. }
  818. }
  819. return true;
  820. } else {
  821. return false;
  822. }
  823. };
  824. Values$1.typeOf = function(value){
  825. if (value === null) {
  826. return NullType$1;
  827. } else if (typeof value === 'string') {
  828. return StringType$1;
  829. } else if (typeof value === 'boolean') {
  830. return BooleanType$1;
  831. } else if (typeof value === 'number') {
  832. return NumberType$2;
  833. } else if (value instanceof Color$1) {
  834. return ColorType$2;
  835. } else if (value instanceof Collator) {
  836. return CollatorType;
  837. } else if (value instanceof Formatted$1) {
  838. return FormattedType$1;
  839. } else if (value instanceof ResolvedImage$1) {
  840. return ResolvedImageType$1;
  841. } else if (Array.isArray(value)) {
  842. var length = value.length;
  843. var itemType;
  844. for (var i = 0, list = value; i < list.length; i += 1) {
  845. var item = list[i];
  846. var t = Values$1.typeOf(item);
  847. if (!itemType) {
  848. itemType = t;
  849. } else if (itemType === t) {
  850. continue;
  851. } else {
  852. itemType = ValueType$1;
  853. break;
  854. }
  855. }
  856. return array$1(itemType || ValueType$1, length);
  857. } else {
  858. assert_1(typeof value === 'object');
  859. return ObjectType$1;
  860. }
  861. };
  862. Values$1.toString$1 = function(value){
  863. var type = typeof value;
  864. if (value === null) {
  865. return '';
  866. } else if (type === 'string' || type === 'number' || type === 'boolean') {
  867. return String(value);
  868. } else if (value instanceof Color$1 || value instanceof Formatted$1 || value instanceof ResolvedImage$1) {
  869. return value.toString();
  870. } else {
  871. return JSON.stringify(value);
  872. }
  873. };
  874. var NumberType$3 = {kind: 'number'};
  875. var StringType$2 = {kind: 'string'};
  876. var BooleanType$2 = {kind: 'boolean'};
  877. var ObjectType$2 = {kind: 'object'};
  878. var ValueType$2 = {kind: 'value'};
  879. function array$2(itemType, N) {
  880. return {
  881. kind: 'array',
  882. itemType: itemType,
  883. N: N
  884. };
  885. }
  886. var types = {
  887. string: StringType$2,
  888. number: NumberType$3,
  889. boolean: BooleanType$2,
  890. object: ObjectType$2
  891. };
  892. var Assertion = function Assertion(type, args) {
  893. this.type = type;
  894. this.args = args;
  895. };
  896. Assertion.parse = function parse(args, context) {
  897. if (args.length < 2) {
  898. return context.error("Expected at least one argument.");
  899. }
  900. var i = 1;
  901. var type;
  902. var name = (args[0] );
  903. if (name === 'array') {
  904. var itemType;
  905. if (args.length > 2) {
  906. var type$1 = args[1];
  907. if (typeof type$1 !== 'string' || !(type$1 in types) || type$1 === 'object') {
  908. return context.error('The item type argument of "array" must be one of string, number, boolean', 1);
  909. }
  910. itemType = types[type$1];
  911. i++;
  912. } else {
  913. itemType = ValueType$2;
  914. }
  915. var N;
  916. if (args.length > 3) {
  917. if (args[2] !== null &&
  918. (typeof args[2] !== 'number' ||
  919. args[2] < 0 ||
  920. args[2] !== Math.floor(args[2]))
  921. ) {
  922. return context.error('The length argument to "array" must be a positive integer literal', 2);
  923. }
  924. N = args[2];
  925. i++;
  926. }
  927. type = array$2(itemType, N);
  928. } else {
  929. assert_1(types[name], name);
  930. type = types[name];
  931. }
  932. var parsed = [];
  933. for (; i < args.length; i++) {
  934. var input = context.parse(args[i], i, ValueType$2);
  935. if (!input) {
  936. return null;
  937. }
  938. parsed.push(input);
  939. }
  940. return new Assertion(type, parsed);
  941. };
  942. Assertion.prototype.evaluate = function evaluate(ctx) {
  943. for (var i = 0; i < this.args.length; i++) {
  944. var value = this.args[i].evaluate(ctx);
  945. var error = checkSubtype(this.type, Values$1.typeOf(value));
  946. if (!error) {
  947. return value;
  948. } else if (i === this.args.length - 1) {
  949. throw new RuntimeError(("Expected value to be of type " + (toString(this.type)) + ", but found " + (toString(Values$1.typeOf(value))) + " instead."));
  950. }
  951. }
  952. assert_1(false);
  953. return null;
  954. };
  955. Assertion.prototype.eachChild = function eachChild(fn) {
  956. this.args.forEach(fn);
  957. };
  958. Assertion.prototype.possibleOutputs = function possibleOutputs() {
  959. var ref;
  960. return (ref = []).concat.apply(ref, this.args.map(function (arg) {
  961. return arg.possibleOutputs();
  962. }));
  963. };
  964. Assertion.prototype.serialize = function serialize() {
  965. var type = this.type;
  966. var serialized = [type.kind];
  967. if (type.kind === 'array') {
  968. var itemType = type.itemType;
  969. if (itemType.kind === 'string' ||
  970. itemType.kind === 'number' ||
  971. itemType.kind === 'boolean') {
  972. serialized.push(itemType.kind);
  973. var N = type.N;
  974. if (typeof N === 'number' || this.args.length > 1) {
  975. serialized.push(N);
  976. }
  977. }
  978. }
  979. return serialized.concat(this.args.map(function (arg) {
  980. return arg.serialize();
  981. }));
  982. };
  983. var NumberType$4 = {kind: 'number'};
  984. var ValueType$3 = {kind: 'value'};
  985. function array$3(itemType, N) {
  986. return {
  987. kind: 'array',
  988. itemType: itemType,
  989. N: N
  990. };
  991. }
  992. var At = function At(type, index, input) {
  993. this.type = type;
  994. this.index = index;
  995. this.input = input;
  996. };
  997. At.parse = function parse(args, context) {
  998. if (args.length !== 3) {
  999. return context.error(("Expected 2 arguments, but found " + (args.length - 1) + " instead."));
  1000. }
  1001. var index = context.parse(args[1], 1, NumberType$4);
  1002. var input = context.parse(args[2], 2, array$3(context.expectedType || ValueType$3));
  1003. if (!index || !input) {
  1004. return null;
  1005. }
  1006. var t = (input.type );
  1007. return new At(t.itemType, index, input);
  1008. };
  1009. At.prototype.evaluate = function evaluate(ctx) {
  1010. var index = ((this.index.evaluate(ctx) ) );
  1011. var array = ((this.input.evaluate(ctx) ) );
  1012. if (index < 0) {
  1013. throw new RuntimeError(("Array index out of bounds: " + index + " < 0."));
  1014. }
  1015. if (index >= array.length) {
  1016. throw new RuntimeError(("Array index out of bounds: " + index + " > " + (array.length - 1) + "."));
  1017. }
  1018. if (index !== Math.floor(index)) {
  1019. throw new RuntimeError(("Array index must be an integer, but found " + index + " instead."));
  1020. }
  1021. return array[index];
  1022. };
  1023. At.prototype.eachChild = function eachChild(fn) {
  1024. fn(this.index);
  1025. fn(this.input);
  1026. };
  1027. At.prototype.possibleOutputs = function possibleOutputs() {
  1028. return [undefined];
  1029. };
  1030. At.prototype.serialize = function serialize() {
  1031. return ["at", this.index.serialize(), this.input.serialize()];
  1032. };
  1033. var BooleanType$3 = {kind: 'boolean'};
  1034. var Case = function Case(type, branches, otherwise) {
  1035. this.type = type;
  1036. this.branches = branches;
  1037. this.otherwise = otherwise;
  1038. };
  1039. Case.parse = function parse(args, context) {
  1040. if (args.length < 4) {
  1041. return context.error(("Expected at least 3 arguments, but found only " + (args.length - 1) + "."));
  1042. }
  1043. if (args.length % 2 !== 0) {
  1044. return context.error("Expected an odd number of arguments.");
  1045. }
  1046. var outputType;
  1047. if (context.expectedType && context.expectedType.kind !== 'value') {
  1048. outputType = context.expectedType;
  1049. }
  1050. var branches = [];
  1051. for (var i = 1; i < args.length - 1; i += 2) {
  1052. var test = context.parse(args[i], i, BooleanType$3);
  1053. if (!test) {
  1054. return null;
  1055. }
  1056. var result = context.parse(args[i + 1], i + 1, outputType);
  1057. if (!result) {
  1058. return null;
  1059. }
  1060. branches.push([test, result]);
  1061. outputType = outputType || result.type;
  1062. }
  1063. var otherwise = context.parse(args[args.length - 1], args.length - 1, outputType);
  1064. if (!otherwise) {
  1065. return null;
  1066. }
  1067. assert_1(outputType);
  1068. return new Case((outputType ), branches, otherwise);
  1069. };
  1070. Case.prototype.evaluate = function evaluate(ctx) {
  1071. for (var i = 0, list = this.branches; i < list.length; i += 1) {
  1072. var ref = list[i];
  1073. var test = ref[0];
  1074. var expression = ref[1];
  1075. if (test.evaluate(ctx)) {
  1076. return expression.evaluate(ctx);
  1077. }
  1078. }
  1079. return this.otherwise.evaluate(ctx);
  1080. };
  1081. Case.prototype.eachChild = function eachChild(fn) {
  1082. for (var i = 0, list = this.branches; i < list.length; i += 1) {
  1083. var ref = list[i];
  1084. var test = ref[0];
  1085. var expression = ref[1];
  1086. fn(test);
  1087. fn(expression);
  1088. }
  1089. fn(this.otherwise);
  1090. };
  1091. Case.prototype.possibleOutputs = function possibleOutputs() {
  1092. var ref;
  1093. return (ref = [])
  1094. .concat.apply(ref, this.branches.map(function (ref) {
  1095. var _ = ref[0];
  1096. var out = ref[1];
  1097. return out.possibleOutputs();
  1098. }))
  1099. .concat(this.otherwise.possibleOutputs());
  1100. };
  1101. Case.prototype.serialize = function serialize() {
  1102. var serialized = ["case"];
  1103. this.eachChild(function (child) {
  1104. serialized.push(child.serialize());
  1105. });
  1106. return serialized;
  1107. };
  1108. var ValueType$4 = {kind: 'value'};
  1109. var Coalesce = function Coalesce(type, args) {
  1110. this.type = type;
  1111. this.args = args;
  1112. };
  1113. Coalesce.parse = function parse(args, context) {
  1114. if (args.length < 2) {
  1115. return context.error("Expectected at least one argument.");
  1116. }
  1117. var outputType = (null );
  1118. var expectedType = context.expectedType;
  1119. if (expectedType && expectedType.kind !== 'value') {
  1120. outputType = expectedType;
  1121. }
  1122. var parsedArgs = [];
  1123. for (var i = 0, list = args.slice(1); i < list.length; i += 1) {
  1124. var arg = list[i];
  1125. var parsed = context.parse(arg, 1 + parsedArgs.length, outputType, undefined, {typeAnnotation: 'omit'});
  1126. if (!parsed) {
  1127. return null;
  1128. }
  1129. outputType = outputType || parsed.type;
  1130. parsedArgs.push(parsed);
  1131. }
  1132. assert_1(outputType);
  1133. // Above, we parse arguments without inferred type annotation so that
  1134. // they don't produce a runtime error for `null` input, which would
  1135. // preempt the desired null-coalescing behavior.
  1136. // Thus, if any of our arguments would have needed an annotation, we
  1137. // need to wrap the enclosing coalesce expression with it instead.
  1138. var needsAnnotation = expectedType &&
  1139. parsedArgs.some(function (arg) {
  1140. return checkSubtype(expectedType, arg.type);
  1141. });
  1142. return needsAnnotation ?
  1143. new Coalesce(ValueType$4, parsedArgs) :
  1144. new Coalesce((outputType ), parsedArgs);
  1145. };
  1146. Coalesce.prototype.evaluate = function evaluate(ctx) {
  1147. var result = null;
  1148. var argCount = 0;
  1149. var requestedImageName;
  1150. for (var i = 0, list = this.args; i < list.length; i += 1) {
  1151. var arg = list[i];
  1152. argCount++;
  1153. result = arg.evaluate(ctx);
  1154. // we need to keep track of the first requested image in a coalesce statement
  1155. // if coalesce can't find a valid image, we return the first image name so styleimagemissing can fire
  1156. if (result && result instanceof ResolvedImage$1 && !result.available) {
  1157. if (!requestedImageName) {
  1158. requestedImageName = result.name;
  1159. }
  1160. result = null;
  1161. if (argCount === this.args.length) {
  1162. result = requestedImageName;
  1163. }
  1164. }
  1165. if (result !== null) {
  1166. break;
  1167. }
  1168. }
  1169. return result;
  1170. };
  1171. Coalesce.prototype.eachChild = function eachChild(fn) {
  1172. this.args.forEach(fn);
  1173. };
  1174. Coalesce.prototype.possibleOutputs = function possibleOutputs() {
  1175. var ref;
  1176. return (ref = []).concat.apply(ref, this.args.map(function (arg) {
  1177. return arg.possibleOutputs();
  1178. }));
  1179. };
  1180. Coalesce.prototype.serialize = function serialize() {
  1181. var serialized = ["coalesce"];
  1182. this.eachChild(function (child) {
  1183. serialized.push(child.serialize());
  1184. });
  1185. return serialized;
  1186. };
  1187. var NumberType$5 = {kind: 'number'};
  1188. var StringType$3 = {kind: 'string'};
  1189. var BooleanType$4 = {kind: 'boolean'};
  1190. var ColorType$3 = {kind: 'color'};
  1191. var ValueType$5 = {kind: 'value'};
  1192. var types$1 = {
  1193. 'to-boolean': BooleanType$4,
  1194. 'to-color': ColorType$3,
  1195. 'to-number': NumberType$5,
  1196. 'to-string': StringType$3
  1197. };
  1198. /**
  1199. * Special form for error-coalescing coercion expressions "to-number",
  1200. * "to-color". Since these coercions can fail at runtime, they accept multiple
  1201. * arguments, only evaluating one at a time until one succeeds.
  1202. *
  1203. * @private
  1204. */
  1205. var Coercion = function Coercion(type, args) {
  1206. this.type = type;
  1207. this.args = args;
  1208. };
  1209. Coercion.parse = function parse(args, context) {
  1210. if (args.length < 2) {
  1211. return context.error("Expected at least one argument.");
  1212. }
  1213. var name = (args[0] );
  1214. assert_1(types$1[name], name);
  1215. if ((name === 'to-boolean' || name === 'to-string') && args.length !== 2) {
  1216. return context.error("Expected one argument.");
  1217. }
  1218. var type = types$1[name];
  1219. var parsed = [];
  1220. for (var i = 1; i < args.length; i++) {
  1221. var input = context.parse(args[i], i, ValueType$5);
  1222. if (!input) {
  1223. return null;
  1224. }
  1225. parsed.push(input);
  1226. }
  1227. return new Coercion(type, parsed);
  1228. };
  1229. Coercion.prototype.evaluate = function evaluate(ctx) {
  1230. if (this.type.kind === 'boolean') {
  1231. return Boolean(this.args[0].evaluate(ctx));
  1232. } else if (this.type.kind === 'color') {
  1233. var input;
  1234. var error;
  1235. for (var i = 0, list = this.args; i < list.length; i += 1) {
  1236. var arg = list[i];
  1237. input = arg.evaluate(ctx);
  1238. error = null;
  1239. if (input instanceof Color) {
  1240. return input;
  1241. } else if (typeof input === 'string') {
  1242. var c = ctx.parseColor(input);
  1243. if (c) {
  1244. return c;
  1245. }
  1246. } else if (Array.isArray(input)) {
  1247. if (input.length < 3 || input.length > 4) {
  1248. error = "Invalid rbga value " + (JSON.stringify(input)) + ": expected an array containing either three or four numeric values.";
  1249. } else {
  1250. error = validateRGBA(input[0], input[1], input[2], input[3]);
  1251. }
  1252. if (!error) {
  1253. return new Color((input[0] ) / 255, (input[1] ) / 255, (input[2] ) / 255, (input[3] ));
  1254. }
  1255. }
  1256. }
  1257. throw new RuntimeError(error || ("Could not parse color from value '" + (typeof input === 'string' ? input : String(JSON.stringify(input))) + "'"));
  1258. } else if (this.type.kind === 'number') {
  1259. var value = null;
  1260. for (var i$1 = 0, list$1 = this.args; i$1 < list$1.length; i$1 += 1) {
  1261. var arg$1 = list$1[i$1];
  1262. value = arg$1.evaluate(ctx);
  1263. if (value === null) {
  1264. return 0;
  1265. }
  1266. var num = Number(value);
  1267. if (isNaN(num)) {
  1268. continue;
  1269. }
  1270. return num;
  1271. }
  1272. throw new RuntimeError(("Could not convert " + (JSON.stringify(value)) + " to number."));
  1273. } else if (this.type.kind === 'formatted') {
  1274. // There is no explicit 'to-formatted' but this coercion can be implicitly
  1275. // created by properties that expect the 'formatted' type.
  1276. return Formatted.fromString(toString$1(this.args[0].evaluate(ctx)));
  1277. } else if (this.type.kind === 'resolvedImage') {
  1278. return ResolvedImage.fromString(toString$1(this.args[0].evaluate(ctx)));
  1279. } else {
  1280. return toString$1(this.args[0].evaluate(ctx));
  1281. }
  1282. };
  1283. Coercion.prototype.eachChild = function eachChild(fn) {
  1284. this.args.forEach(fn);
  1285. };
  1286. Coercion.prototype.possibleOutputs = function possibleOutputs() {
  1287. var ref;
  1288. return (ref = []).concat.apply(ref, this.args.map(function (arg) {
  1289. return arg.possibleOutputs();
  1290. }));
  1291. };
  1292. Coercion.prototype.serialize = function serialize() {
  1293. if (this.type.kind === 'formatted') {
  1294. return new FormatExpression([
  1295. {content: this.args[0], scale: null, font: null, textColor: null}
  1296. ]).serialize();
  1297. }
  1298. if (this.type.kind === 'resolvedImage') {
  1299. return new ImageExpression(this.args[0]).serialize();
  1300. }
  1301. var serialized = [("to-" + (this.type.kind))];
  1302. this.eachChild(function (child) {
  1303. serialized.push(child.serialize());
  1304. });
  1305. return serialized;
  1306. };
  1307. var StringType$4 = {kind: 'string'};
  1308. var BooleanType$5 = {kind: 'boolean'};
  1309. var CollatorType$1 = {kind: 'collator'};
  1310. var CollatorExpression = function CollatorExpression(caseSensitive, diacriticSensitive, locale) {
  1311. this.type = CollatorType$1;
  1312. this.locale = locale;
  1313. this.caseSensitive = caseSensitive;
  1314. this.diacriticSensitive = diacriticSensitive;
  1315. };
  1316. CollatorExpression.parse = function parse(args, context) {
  1317. if (args.length !== 2) {
  1318. return context.error("Expected one argument.");
  1319. }
  1320. var options = (args[1] );
  1321. if (typeof options !== "object" || Array.isArray(options)) {
  1322. return context.error("Collator options argument must be an object.");
  1323. }
  1324. var caseSensitive = context.parse(
  1325. options['case-sensitive'] === undefined ? false : options['case-sensitive'], 1, BooleanType$5);
  1326. if (!caseSensitive) {
  1327. return null;
  1328. }
  1329. var diacriticSensitive = context.parse(
  1330. options['diacritic-sensitive'] === undefined ? false : options['diacritic-sensitive'], 1, BooleanType$5);
  1331. if (!diacriticSensitive) {
  1332. return null;
  1333. }
  1334. var locale = null;
  1335. if (options['locale']) {
  1336. locale = context.parse(options['locale'], 1, StringType$4);
  1337. if (!locale) {
  1338. return null;
  1339. }
  1340. }
  1341. return new CollatorExpression(caseSensitive, diacriticSensitive, locale);
  1342. };
  1343. CollatorExpression.prototype.evaluate = function evaluate(ctx) {
  1344. return new Collator(this.caseSensitive.evaluate(ctx), this.diacriticSensitive.evaluate(ctx), this.locale ? this.locale.evaluate(ctx) : null);
  1345. };
  1346. CollatorExpression.prototype.eachChild = function eachChild(fn) {
  1347. fn(this.caseSensitive);
  1348. fn(this.diacriticSensitive);
  1349. if (this.locale) {
  1350. fn(this.locale);
  1351. }
  1352. };
  1353. CollatorExpression.prototype.possibleOutputs = function possibleOutputs() {
  1354. // Technically the set of possible outputs is the combinatoric set of Collators produced
  1355. // by all possibleOutputs of locale/caseSensitive/diacriticSensitive
  1356. // But for the primary use of Collators in comparison operators, we ignore the Collator's
  1357. // possibleOutputs anyway, so we can get away with leaving this undefined for now.
  1358. return [undefined];
  1359. };
  1360. CollatorExpression.prototype.serialize = function serialize() {
  1361. var options = {};
  1362. options['case-sensitive'] = this.caseSensitive.serialize();
  1363. options['diacritic-sensitive'] = this.diacriticSensitive.serialize();
  1364. if (this.locale) {
  1365. options['locale'] = this.locale.serialize();
  1366. }
  1367. return ["collator", options];
  1368. };
  1369. var BooleanType$6 = {kind: 'boolean'};
  1370. var ValueType$6 = {kind: 'value'};
  1371. var CollatorType$2 = {kind: 'collator'};
  1372. function isComparableType$1(op, type) {
  1373. if (op === '==' || op === '!=') {
  1374. // equality operator
  1375. return type.kind === 'boolean' ||
  1376. type.kind === 'string' ||
  1377. type.kind === 'number' ||
  1378. type.kind === 'null' ||
  1379. type.kind === 'value';
  1380. } else {
  1381. // ordering operator
  1382. return type.kind === 'string' ||
  1383. type.kind === 'number' ||
  1384. type.kind === 'value';
  1385. }
  1386. }
  1387. function eq(ctx, a, b) {
  1388. return a === b;
  1389. }
  1390. function neq(ctx, a, b) {
  1391. return a !== b;
  1392. }
  1393. function lt(ctx, a, b) {
  1394. return a < b;
  1395. }
  1396. function gt(ctx, a, b) {
  1397. return a > b;
  1398. }
  1399. function lteq(ctx, a, b) {
  1400. return a <= b;
  1401. }
  1402. function gteq(ctx, a, b) {
  1403. return a >= b;
  1404. }
  1405. function eqCollate(ctx, a, b, c) {
  1406. return c.compare(a, b) === 0;
  1407. }
  1408. function neqCollate(ctx, a, b, c) {
  1409. return !eqCollate(ctx, a, b, c);
  1410. }
  1411. function ltCollate(ctx, a, b, c) {
  1412. return c.compare(a, b) < 0;
  1413. }
  1414. function gtCollate(ctx, a, b, c) {
  1415. return c.compare(a, b) > 0;
  1416. }
  1417. function lteqCollate(ctx, a, b, c) {
  1418. return c.compare(a, b) <= 0;
  1419. }
  1420. function gteqCollate(ctx, a, b, c) {
  1421. return c.compare(a, b) >= 0;
  1422. }
  1423. /**
  1424. * Special form for comparison operators, implementing the signatures:
  1425. * - (T, T, ?Collator) => boolean
  1426. * - (T, value, ?Collator) => boolean
  1427. * - (value, T, ?Collator) => boolean
  1428. *
  1429. * For inequalities, T must be either value, string, or number. For ==/!=, it
  1430. * can also be boolean or null.
  1431. *
  1432. * Equality semantics are equivalent to Javascript's strict equality (===/!==)
  1433. * -- i.e., when the arguments' types don't match, == evaluates to false, != to
  1434. * true.
  1435. *
  1436. * When types don't match in an ordering comparison, a runtime error is thrown.
  1437. *
  1438. * @private
  1439. */
  1440. function makeComparison(op, compareBasic, compareWithCollator) {
  1441. var isOrderComparison = op !== '==' && op !== '!=';
  1442. return /*@__PURE__*/(function () {
  1443. function Comparison(lhs, rhs, collator) {
  1444. this.type = BooleanType$6;
  1445. this.lhs = lhs;
  1446. this.rhs = rhs;
  1447. this.collator = collator;
  1448. this.hasUntypedArgument = lhs.type.kind === 'value' || rhs.type.kind === 'value';
  1449. }
  1450. Comparison.parse = function parse(args, context) {
  1451. if (args.length !== 3 && args.length !== 4) {
  1452. return context.error("Expected two or three arguments.");
  1453. }
  1454. var op = (args[0] );
  1455. var lhs = context.parse(args[1], 1, ValueType$6);
  1456. if (!lhs) {
  1457. return null;
  1458. }
  1459. if (!isComparableType$1(op, lhs.type)) {
  1460. return context.concat(1).error(("\"" + op + "\" comparisons are not supported for type '" + (toString(lhs.type)) + "'."));
  1461. }
  1462. var rhs = context.parse(args[2], 2, ValueType$6);
  1463. if (!rhs) {
  1464. return null;
  1465. }
  1466. if (!isComparableType$1(op, rhs.type)) {
  1467. return context.concat(2).error(("\"" + op + "\" comparisons are not supported for type '" + (toString(rhs.type)) + "'."));
  1468. }
  1469. if (
  1470. lhs.type.kind !== rhs.type.kind &&
  1471. lhs.type.kind !== 'value' &&
  1472. rhs.type.kind !== 'value'
  1473. ) {
  1474. return context.error(("Cannot compare types '" + (toString(lhs.type)) + "' and '" + (toString(rhs.type)) + "'."));
  1475. }
  1476. if (isOrderComparison) {
  1477. // typing rules specific to less/greater than operators
  1478. if (lhs.type.kind === 'value' && rhs.type.kind !== 'value') {
  1479. // (value, T)
  1480. lhs = new Assertion(rhs.type, [lhs]);
  1481. } else if (lhs.type.kind !== 'value' && rhs.type.kind === 'value') {
  1482. // (T, value)
  1483. rhs = new Assertion(lhs.type, [rhs]);
  1484. }
  1485. }
  1486. var collator = null;
  1487. if (args.length === 4) {
  1488. if (
  1489. lhs.type.kind !== 'string' &&
  1490. rhs.type.kind !== 'string' &&
  1491. lhs.type.kind !== 'value' &&
  1492. rhs.type.kind !== 'value'
  1493. ) {
  1494. return context.error("Cannot use collator to compare non-string types.");
  1495. }
  1496. collator = context.parse(args[3], 3, CollatorType$2);
  1497. if (!collator) {
  1498. return null;
  1499. }
  1500. }
  1501. return new Comparison(lhs, rhs, collator);
  1502. };
  1503. Comparison.prototype.evaluate = function evaluate(ctx) {
  1504. var lhs = this.lhs.evaluate(ctx);
  1505. var rhs = this.rhs.evaluate(ctx);
  1506. if (isOrderComparison && this.hasUntypedArgument) {
  1507. var lt = Values$1.typeOf(lhs);
  1508. var rt = Values$1.typeOf(rhs);
  1509. // check that type is string or number, and equal
  1510. if (lt.kind !== rt.kind || !(lt.kind === 'string' || lt.kind === 'number')) {
  1511. throw new RuntimeError(("Expected arguments for \"" + op + "\" to be (string, string) or (number, number), but found (" + (lt.kind) + ", " + (rt.kind) + ") instead."));
  1512. }
  1513. }
  1514. if (this.collator && !isOrderComparison && this.hasUntypedArgument) {
  1515. var lt$1 = Values$1.typeOf(lhs);
  1516. var rt$1 = Values$1.typeOf(rhs);
  1517. if (lt$1.kind !== 'string' || rt$1.kind !== 'string') {
  1518. return compareBasic(ctx, lhs, rhs);
  1519. }
  1520. }
  1521. return this.collator ?
  1522. compareWithCollator(ctx, lhs, rhs, this.collator.evaluate(ctx)) :
  1523. compareBasic(ctx, lhs, rhs);
  1524. };
  1525. Comparison.prototype.eachChild = function eachChild(fn) {
  1526. fn(this.lhs);
  1527. fn(this.rhs);
  1528. if (this.collator) {
  1529. fn(this.collator);
  1530. }
  1531. };
  1532. Comparison.prototype.possibleOutputs = function possibleOutputs() {
  1533. return [true, false];
  1534. };
  1535. Comparison.prototype.serialize = function serialize() {
  1536. var serialized = [op];
  1537. this.eachChild(function (child) {
  1538. serialized.push(child.serialize());
  1539. });
  1540. return serialized;
  1541. };
  1542. return Comparison;
  1543. }());
  1544. }
  1545. var ComparisonEnum = {
  1546. };
  1547. ComparisonEnum.Equals = makeComparison('==', eq, eqCollate);
  1548. ComparisonEnum.NotEquals = makeComparison('!=', neq, neqCollate);
  1549. ComparisonEnum.LessThan = makeComparison('<', lt, ltCollate);
  1550. ComparisonEnum.GreaterThan = makeComparison('>', gt, gtCollate);
  1551. ComparisonEnum.LessThanOrEqual = makeComparison('<=', lteq, lteqCollate);
  1552. ComparisonEnum.GreaterThanOrEqual = makeComparison('>=', gteq, gteqCollate);
  1553. var NumberType$6 = {kind: 'number'};
  1554. var StringType$5 = {kind: 'string'};
  1555. var ColorType$4 = {kind: 'color'};
  1556. var ValueType$7 = {kind: 'value'};
  1557. var FormattedType$2 = {kind: 'formatted'};
  1558. var ResolvedImageType$2 = {kind: 'resolvedImage'};
  1559. function array$4(itemType, N) {
  1560. return {
  1561. kind: 'array',
  1562. itemType: itemType,
  1563. N: N
  1564. };
  1565. }
  1566. var FormatExpression$1 = function FormatExpression(sections) {
  1567. this.type = FormattedType$2;
  1568. this.sections = sections;
  1569. };
  1570. FormatExpression$1.parse = function parse(args, context) {
  1571. if (args.length < 2) {
  1572. return context.error("Expected at least one argument.");
  1573. }
  1574. var firstArg = args[1];
  1575. if (!Array.isArray(firstArg) && typeof firstArg === 'object') {
  1576. return context.error("First argument must be an image or text section.");
  1577. }
  1578. var sections = [];
  1579. var nextTokenMayBeObject = false;
  1580. for (var i = 1; i <= args.length - 1; ++i) {
  1581. var arg = (args[i] );
  1582. if (nextTokenMayBeObject && typeof arg === "object" && !Array.isArray(arg)) {
  1583. nextTokenMayBeObject = false;
  1584. var scale = null;
  1585. if (arg['font-scale']) {
  1586. scale = context.parse(arg['font-scale'], 1, NumberType$6);
  1587. if (!scale) {
  1588. return null;
  1589. }
  1590. }
  1591. var font = null;
  1592. if (arg['text-font']) {
  1593. font = context.parse(arg['text-font'], 1, array$4(StringType$5));
  1594. if (!font) {
  1595. return null;
  1596. }
  1597. }
  1598. var textColor = null;
  1599. if (arg['text-color']) {
  1600. textColor = context.parse(arg['text-color'], 1, ColorType$4);
  1601. if (!textColor) {
  1602. return null;
  1603. }
  1604. }
  1605. var lastExpression = sections[sections.length - 1];
  1606. lastExpression.scale = scale;
  1607. lastExpression.font = font;
  1608. lastExpression.textColor = textColor;
  1609. } else {
  1610. var content = context.parse(args[i], 1, ValueType$7);
  1611. if (!content) {
  1612. return null;
  1613. }
  1614. var kind = content.type.kind;
  1615. if (kind !== 'string' && kind !== 'value' && kind !== 'null' && kind !== 'resolvedImage') {
  1616. return context.error("Formatted text type must be 'string', 'value', 'image' or 'null'.");
  1617. }
  1618. nextTokenMayBeObject = true;
  1619. sections.push({content: content, scale: null, font: null, textColor: null});
  1620. }
  1621. }
  1622. return new FormatExpression$1(sections);
  1623. };
  1624. FormatExpression$1.prototype.evaluate = function evaluate(ctx) {
  1625. var evaluateSection = function (section) {
  1626. var evaluatedContent = section.content.evaluate(ctx);
  1627. if (Values$1.typeOf(evaluatedContent) === ResolvedImageType$2) {
  1628. return new FormattedSection('', evaluatedContent, null, null, null);
  1629. }
  1630. return new FormattedSection(
  1631. Values$1.toString$1(evaluatedContent),
  1632. null,
  1633. section.scale ? section.scale.evaluate(ctx) : null,
  1634. section.font ? section.font.evaluate(ctx).join(',') : null,
  1635. section.textColor ? section.textColor.evaluate(ctx) : null
  1636. );
  1637. };
  1638. return new Formatted$1(this.sections.map(evaluateSection));
  1639. };
  1640. FormatExpression$1.prototype.eachChild = function eachChild(fn) {
  1641. for (var i = 0, list = this.sections; i < list.length; i += 1) {
  1642. var section = list[i];
  1643. fn(section.content);
  1644. if (section.scale) {
  1645. fn(section.scale);
  1646. }
  1647. if (section.font) {
  1648. fn(section.font);
  1649. }
  1650. if (section.textColor) {
  1651. fn(section.textColor);
  1652. }
  1653. }
  1654. };
  1655. FormatExpression$1.prototype.possibleOutputs = function possibleOutputs() {
  1656. // Technically the combinatoric set of all children
  1657. // Usually, this.text will be undefined anyway
  1658. return [undefined];
  1659. };
  1660. FormatExpression$1.prototype.serialize = function serialize() {
  1661. var serialized = ["format"];
  1662. for (var i = 0, list = this.sections; i < list.length; i += 1) {
  1663. var section = list[i];
  1664. serialized.push(section.content.serialize());
  1665. var options = {};
  1666. if (section.scale) {
  1667. options['font-scale'] = section.scale.serialize();
  1668. }
  1669. if (section.font) {
  1670. options['text-font'] = section.font.serialize();
  1671. }
  1672. if (section.textColor) {
  1673. options['text-color'] = section.textColor.serialize();
  1674. }
  1675. serialized.push(options);
  1676. }
  1677. return serialized;
  1678. };
  1679. var StringType$6 = {kind: 'string'};
  1680. var ResolvedImageType$3 = {kind: 'resolvedImage'};
  1681. var ImageExpression$1 = function ImageExpression(input) {
  1682. this.type = ResolvedImageType$3;
  1683. this.input = input;
  1684. };
  1685. ImageExpression$1.parse = function parse(args, context) {
  1686. if (args.length !== 2) {
  1687. return context.error("Expected two arguments.");
  1688. }
  1689. var name = context.parse(args[1], 1, StringType$6);
  1690. if (!name) {
  1691. return context.error("No image name provided.");
  1692. }
  1693. return new ImageExpression$1(name);
  1694. };
  1695. ImageExpression$1.prototype.evaluate = function evaluate(ctx) {
  1696. var evaluatedImageName = this.input.evaluate(ctx);
  1697. var available = false;
  1698. if (ctx.availableImages && ctx.availableImages.indexOf(evaluatedImageName) > -1) {
  1699. available = true;
  1700. }
  1701. return new ResolvedImage$1({name: evaluatedImageName, available: available});
  1702. };
  1703. ImageExpression$1.prototype.eachChild = function eachChild(fn) {
  1704. fn(this.input);
  1705. };
  1706. ImageExpression$1.prototype.possibleOutputs = function possibleOutputs() {
  1707. // The output of image is determined by the list of available images in the evaluation context
  1708. return [undefined];
  1709. };
  1710. ImageExpression$1.prototype.serialize = function serialize() {
  1711. return ["image", this.input.serialize()];
  1712. };
  1713. var Interpolate$1 = function Interpolate(type, operator, interpolation, input, stops) {
  1714. this.type = type;
  1715. this.operator = operator;
  1716. this.interpolation = interpolation;
  1717. this.input = input;
  1718. this.labels = [];
  1719. this.outputs = [];
  1720. for (var i = 0, list = stops; i < list.length; i += 1) {
  1721. var ref = list[i];
  1722. var label = ref[0];
  1723. var expression = ref[1];
  1724. this.labels.push(label);
  1725. this.outputs.push(expression);
  1726. }
  1727. };
  1728. Interpolate$1.interpolationFactor = function interpolationFactor(interpolation, input, lower, upper) {
  1729. var t = 0;
  1730. if (interpolation.name === 'exponential') {
  1731. t = exponentialInterpolation(input, interpolation.base, lower, upper);
  1732. } else if (interpolation.name === 'linear') {
  1733. t = exponentialInterpolation(input, 1, lower, upper);
  1734. } else if (interpolation.name === 'cubic-bezier') {
  1735. var c = interpolation.controlPoints;
  1736. var ub = new unitbezier(c[0], c[1], c[2], c[3]);
  1737. t = ub.solve(exponentialInterpolation(input, 1, lower, upper));
  1738. }
  1739. return t;
  1740. };
  1741. Interpolate$1.parse = function parse(args, context) {
  1742. var operator = args[0];
  1743. var interpolation = args[1];
  1744. var input = args[2];
  1745. var rest = args.slice(3);
  1746. if (!Array.isArray(interpolation) || interpolation.length === 0) {
  1747. return context.error("Expected an interpolation type expression.", 1);
  1748. }
  1749. if (interpolation[0] === 'linear') {
  1750. interpolation = {name: 'linear'};
  1751. } else if (interpolation[0] === 'exponential') {
  1752. var base = interpolation[1];
  1753. if (typeof base !== 'number') {
  1754. return context.error("Exponential interpolation requires a numeric base.", 1, 1);
  1755. }
  1756. interpolation = {
  1757. name: 'exponential',
  1758. base: base
  1759. };
  1760. } else if (interpolation[0] === 'cubic-bezier') {
  1761. var controlPoints = interpolation.slice(1);
  1762. if (
  1763. controlPoints.length !== 4 ||
  1764. controlPoints.some(function (t) {
  1765. return typeof t !== 'number' || t < 0 || t > 1;
  1766. })
  1767. ) {
  1768. return context.error('Cubic bezier interpolation requires four numeric arguments with values between 0 and 1.', 1);
  1769. }
  1770. interpolation = {
  1771. name: 'cubic-bezier',
  1772. controlPoints: (controlPoints )
  1773. };
  1774. } else {
  1775. return context.error(("Unknown interpolation type " + (String(interpolation[0]))), 1, 0);
  1776. }
  1777. if (args.length - 1 < 4) {
  1778. return context.error(("Expected at least 4 arguments, but found only " + (args.length - 1) + "."));
  1779. }
  1780. if ((args.length - 1) % 2 !== 0) {
  1781. return context.error("Expected an even number of arguments.");
  1782. }
  1783. input = context.parse(input, 2, NumberType);
  1784. if (!input) {
  1785. return null;
  1786. }
  1787. var stops = [];
  1788. var outputType = (null );
  1789. if (operator === 'interpolate-hcl' || operator === 'interpolate-lab') {
  1790. outputType = ColorType;
  1791. } else if (context.expectedType && context.expectedType.kind !== 'value') {
  1792. outputType = context.expectedType;
  1793. }
  1794. for (var i = 0; i < rest.length; i += 2) {
  1795. var label = rest[i];
  1796. var value = rest[i + 1];
  1797. var labelKey = i + 3;
  1798. var valueKey = i + 4;
  1799. if (typeof label !== 'number') {
  1800. return context.error('Input/output pairs for "interpolate" expressions must be defined using literal numeric values (not computed expressions) for the input values.', labelKey);
  1801. }
  1802. if (stops.length && stops[stops.length - 1][0] >= label) {
  1803. return context.error('Input/output pairs for "interpolate" expressions must be arranged with input values in strictly ascending order.', labelKey);
  1804. }
  1805. var parsed = context.parse(value, valueKey, outputType);
  1806. if (!parsed) {
  1807. return null;
  1808. }
  1809. outputType = outputType || parsed.type;
  1810. stops.push([label, parsed]);
  1811. }
  1812. if (outputType.kind !== 'number' &&
  1813. outputType.kind !== 'color' && !(
  1814. outputType.kind === 'array' &&
  1815. outputType.itemType.kind === 'number' &&
  1816. typeof outputType.N === 'number'
  1817. )
  1818. ) {
  1819. return context.error(("Type " + (toString(outputType)) + " is not interpolatable."));
  1820. }
  1821. return new Interpolate$1(outputType, (operator ), interpolation, input, stops);
  1822. };
  1823. Interpolate$1.prototype.evaluate = function evaluate(ctx) {
  1824. var labels = this.labels;
  1825. var outputs = this.outputs;
  1826. if (labels.length === 1) {
  1827. return outputs[0].evaluate(ctx);
  1828. }
  1829. var value = ((this.input.evaluate(ctx) ) );
  1830. if (value <= labels[0]) {
  1831. return outputs[0].evaluate(ctx);
  1832. }
  1833. var stopCount = labels.length;
  1834. if (value >= labels[stopCount - 1]) {
  1835. return outputs[stopCount - 1].evaluate(ctx);
  1836. }
  1837. var index = findStopLessThanOrEqualTo(labels, value);
  1838. var lower = labels[index];
  1839. var upper = labels[index + 1];
  1840. var t = Interpolate$1.interpolationFactor(this.interpolation, value, lower, upper);
  1841. var outputLower = outputs[index].evaluate(ctx);
  1842. var outputUpper = outputs[index + 1].evaluate(ctx);
  1843. if (this.operator === 'interpolate') {
  1844. return (interpolate[this.type.kind.toLowerCase()] )(outputLower, outputUpper, t); // eslint-disable-line import/namespace
  1845. } else if (this.operator === 'interpolate-hcl') {
  1846. return hcl.reverse(hcl.interpolate(hcl.forward(outputLower), hcl.forward(outputUpper), t));
  1847. } else {
  1848. return lab.reverse(lab.interpolate(lab.forward(outputLower), lab.forward(outputUpper), t));
  1849. }
  1850. };
  1851. Interpolate$1.prototype.eachChild = function eachChild(fn) {
  1852. fn(this.input);
  1853. for (var i = 0, list = this.outputs; i < list.length; i += 1) {
  1854. var expression = list[i];
  1855. fn(expression);
  1856. }
  1857. };
  1858. Interpolate$1.prototype.possibleOutputs = function possibleOutputs() {
  1859. var ref;
  1860. return (ref = []).concat.apply(ref, this.outputs.map(function (output) {
  1861. return output.possibleOutputs();
  1862. }));
  1863. };
  1864. Interpolate$1.prototype.serialize = function serialize() {
  1865. var interpolation;
  1866. if (this.interpolation.name === 'linear') {
  1867. interpolation = ["linear"];
  1868. } else if (this.interpolation.name === 'exponential') {
  1869. if (this.interpolation.base === 1) {
  1870. interpolation = ["linear"];
  1871. } else {
  1872. interpolation = ["exponential", this.interpolation.base];
  1873. }
  1874. } else {
  1875. interpolation = ["cubic-bezier" ].concat(this.interpolation.controlPoints);
  1876. }
  1877. var serialized = [this.operator, interpolation, this.input.serialize()];
  1878. for (var i = 0; i < this.labels.length; i++) {
  1879. serialized.push(
  1880. this.labels[i],
  1881. this.outputs[i].serialize()
  1882. );
  1883. }
  1884. return serialized;
  1885. };
  1886. /**
  1887. * Returns a ratio that can be used to interpolate between exponential function
  1888. * stops.
  1889. * How it works: Two consecutive stop values define a (scaled and shifted) exponential function `f(x) = a * base^x + b`, where `base` is the user-specified base,
  1890. * and `a` and `b` are constants affording sufficient degrees of freedom to fit
  1891. * the function to the given stops.
  1892. *
  1893. * Here's a bit of algebra that lets us compute `f(x)` directly from the stop
  1894. * values without explicitly solving for `a` and `b`:
  1895. *
  1896. * First stop value: `f(x0) = y0 = a * base^x0 + b`
  1897. * Second stop value: `f(x1) = y1 = a * base^x1 + b`
  1898. * => `y1 - y0 = a(base^x1 - base^x0)`
  1899. * => `a = (y1 - y0)/(base^x1 - base^x0)`
  1900. *
  1901. * Desired value: `f(x) = y = a * base^x + b`
  1902. * => `f(x) = y0 + a * (base^x - base^x0)`
  1903. *
  1904. * From the above, we can replace the `a` in `a * (base^x - base^x0)` and do a
  1905. * little algebra:
  1906. * ```
  1907. * a * (base^x - base^x0) = (y1 - y0)/(base^x1 - base^x0) * (base^x - base^x0)
  1908. * = (y1 - y0) * (base^x - base^x0) / (base^x1 - base^x0)
  1909. * ```
  1910. *
  1911. * If we let `(base^x - base^x0) / (base^x1 base^x0)`, then we have
  1912. * `f(x) = y0 + (y1 - y0) * ratio`. In other words, `ratio` may be treated as
  1913. * an interpolation factor between the two stops' output values.
  1914. *
  1915. * (Note: a slightly different form for `ratio`,
  1916. * `(base^(x-x0) - 1) / (base^(x1-x0) - 1) `, is equivalent, but requires fewer
  1917. * expensive `Math.pow()` operations.)
  1918. *
  1919. * @private
  1920. */
  1921. function exponentialInterpolation(input, base, lowerValue, upperValue) {
  1922. var difference = upperValue - lowerValue;
  1923. var progress = input - lowerValue;
  1924. if (difference === 0) {
  1925. return 0;
  1926. } else if (base === 1) {
  1927. return progress / difference;
  1928. } else {
  1929. return (Math.pow(base, progress) - 1) / (Math.pow(base, difference) - 1);
  1930. }
  1931. }
  1932. var BooleanType$7 = {kind: 'boolean'};
  1933. var ValueType$8 = {kind: 'value'};
  1934. function isComparableType(type) {
  1935. return type.kind === 'boolean' ||
  1936. type.kind === 'string' ||
  1937. type.kind === 'number' ||
  1938. type.kind === 'null' ||
  1939. type.kind === 'value';
  1940. }
  1941. function isComparableRuntimeValue(needle) {
  1942. return typeof needle === 'boolean' ||
  1943. typeof needle === 'string' ||
  1944. typeof needle === 'number';
  1945. }
  1946. function isSearchableRuntimeValue(haystack) {
  1947. return Array.isArray(haystack) ||
  1948. typeof haystack === 'string';
  1949. }
  1950. var In = function In(needle, haystack) {
  1951. this.type = BooleanType$7;
  1952. this.needle = needle;
  1953. this.haystack = haystack;
  1954. };
  1955. In.parse = function parse(args, context) {
  1956. if (args.length !== 3) {
  1957. return context.error(("Expected 2 arguments, but found " + (args.length - 1) + " instead."));
  1958. }
  1959. var needle = context.parse(args[1], 1, ValueType$8);
  1960. var haystack = context.parse(args[2], 2, ValueType$8);
  1961. if (!needle || !haystack) {
  1962. return null;
  1963. }
  1964. if (!isComparableType(needle.type)) {
  1965. return context.error(("Expected first argument to be of type boolean, string, number or null, but found " + (toString(needle.type)) + " instead"));
  1966. }
  1967. return new In(needle, haystack);
  1968. };
  1969. In.prototype.evaluate = function evaluate(ctx) {
  1970. var needle = (this.needle.evaluate(ctx) );
  1971. var haystack = (this.haystack.evaluate(ctx) );
  1972. if (!needle || !haystack) {
  1973. return false;
  1974. }
  1975. if (!isComparableRuntimeValue(needle)) {
  1976. throw new RuntimeError(("Expected first argument to be of type boolean, string or number, but found " + (toString(typeOf(needle))) + " instead."));
  1977. }
  1978. if (!isSearchableRuntimeValue(haystack)) {
  1979. throw new RuntimeError(("Expected second argument to be of type array or string, but found " + (toString(typeOf(haystack))) + " instead."));
  1980. }
  1981. return haystack.indexOf(needle) >= 0;
  1982. };
  1983. In.prototype.eachChild = function eachChild(fn) {
  1984. fn(this.needle);
  1985. fn(this.haystack);
  1986. };
  1987. In.prototype.possibleOutputs = function possibleOutputs() {
  1988. return [true, false];
  1989. };
  1990. In.prototype.serialize = function serialize() {
  1991. return ["in", this.needle.serialize(), this.haystack.serialize()];
  1992. };
  1993. var Let = function Let(bindings, result) {
  1994. this.type = result.type;
  1995. this.bindings = [].concat(bindings);
  1996. this.result = result;
  1997. };
  1998. Let.prototype.evaluate = function evaluate(ctx) {
  1999. return this.result.evaluate(ctx);
  2000. };
  2001. Let.prototype.eachChild = function eachChild(fn) {
  2002. for (var i = 0, list = this.bindings; i < list.length; i += 1) {
  2003. var binding = list[i];
  2004. fn(binding[1]);
  2005. }
  2006. fn(this.result);
  2007. };
  2008. Let.parse = function parse(args, context) {
  2009. if (args.length < 4) {
  2010. return context.error(("Expected at least 3 arguments, but found " + (args.length - 1) + " instead."));
  2011. }
  2012. var bindings = [];
  2013. for (var i = 1; i < args.length - 1; i += 2) {
  2014. var name = args[i];
  2015. if (typeof name !== 'string') {
  2016. return context.error(("Expected string, but found " + (typeof name) + " instead."), i);
  2017. }
  2018. if (/[^a-zA-Z0-9_]/.test(name)) {
  2019. return context.error("Variable names must contain only alphanumeric characters or '_'.", i);
  2020. }
  2021. var value = context.parse(args[i + 1], i + 1);
  2022. if (!value) {
  2023. return null;
  2024. }
  2025. bindings.push([name, value]);
  2026. }
  2027. var result = context.parse(args[args.length - 1], args.length - 1, context.expectedType, bindings);
  2028. if (!result) {
  2029. return null;
  2030. }
  2031. return new Let(bindings, result);
  2032. };
  2033. Let.prototype.possibleOutputs = function possibleOutputs() {
  2034. return this.result.possibleOutputs();
  2035. };
  2036. Let.prototype.serialize = function serialize() {
  2037. var serialized = ["let"];
  2038. for (var i = 0, list = this.bindings; i < list.length; i += 1) {
  2039. var ref = list[i];
  2040. var name = ref[0];
  2041. var expr = ref[1];
  2042. serialized.push(name, expr.serialize());
  2043. }
  2044. serialized.push(this.result.serialize());
  2045. return serialized;
  2046. };
  2047. var NumberType$7 = {kind: 'number'};
  2048. var Length = function Length(input) {
  2049. this.type = NumberType$7;
  2050. this.input = input;
  2051. };
  2052. Length.parse = function parse(args, context) {
  2053. if (args.length !== 2) {
  2054. return context.error(("Expected 1 argument, but found " + (args.length - 1) + " instead."));
  2055. }
  2056. var input = context.parse(args[1], 1);
  2057. if (!input) {
  2058. return null;
  2059. }
  2060. if (input.type.kind !== 'array' && input.type.kind !== 'string' && input.type.kind !== 'value') {
  2061. return context.error(("Expected argument of type string or array, but found " + (toString(input.type)) + " instead."));
  2062. }
  2063. return new Length(input);
  2064. };
  2065. Length.prototype.evaluate = function evaluate(ctx) {
  2066. var input = this.input.evaluate(ctx);
  2067. if (typeof input === 'string') {
  2068. return input.length;
  2069. } else if (Array.isArray(input)) {
  2070. return input.length;
  2071. } else {
  2072. throw new RuntimeError(("Expected value to be of type string or array, but found " + (toString(typeOf(input))) + " instead."));
  2073. }
  2074. };
  2075. Length.prototype.eachChild = function eachChild(fn) {
  2076. fn(this.input);
  2077. };
  2078. Length.prototype.possibleOutputs = function possibleOutputs() {
  2079. return [undefined];
  2080. };
  2081. Length.prototype.serialize = function serialize() {
  2082. var serialized = ["length"];
  2083. this.eachChild(function (child) {
  2084. serialized.push(child.serialize());
  2085. });
  2086. return serialized;
  2087. };
  2088. var Literal = function Literal(type, value) {
  2089. this.type = type;
  2090. this.value = value;
  2091. };
  2092. Literal.parse = function parse(args, context) {
  2093. if (args.length !== 2) {
  2094. return context.error(("'literal' expression requires exactly one argument, but found " + (args.length - 1) + " instead."));
  2095. }
  2096. if (!Values$1.isValue(args[1])) {
  2097. return context.error("invalid value");
  2098. }
  2099. var value = (args[1] );
  2100. var type = Values$1.typeOf(value);
  2101. // special case: infer the item type if possible for zero-length arrays
  2102. var expected = context.expectedType;
  2103. if (
  2104. type.kind === 'array' &&
  2105. type.N === 0 &&
  2106. expected &&
  2107. expected.kind === 'array' &&
  2108. (typeof expected.N !== 'number' || expected.N === 0)
  2109. ) {
  2110. type = expected;
  2111. }
  2112. return new Literal(type, value);
  2113. };
  2114. Literal.prototype.evaluate = function evaluate() {
  2115. return this.value;
  2116. };
  2117. Literal.prototype.eachChild = function eachChild() {
  2118. };
  2119. Literal.prototype.possibleOutputs = function possibleOutputs() {
  2120. return [this.value];
  2121. };
  2122. Literal.prototype.serialize = function serialize() {
  2123. if (this.type.kind === 'array' || this.type.kind === 'object') {
  2124. return ["literal", this.value];
  2125. } else if (this.value instanceof Color) {
  2126. // Constant-folding can generate Literal expressions that you
  2127. // couldn't actually generate with a "literal" expression,
  2128. // so we have to implement an equivalent serialization here
  2129. return ["rgba"].concat(this.value.toArray());
  2130. } else if (this.value instanceof Formatted$1) {
  2131. // Same as Color
  2132. return this.value.serialize();
  2133. } else {
  2134. assert_1(this.value === null ||
  2135. typeof this.value === 'string' ||
  2136. typeof this.value === 'number' ||
  2137. typeof this.value === 'boolean');
  2138. return (this.value );
  2139. }
  2140. };
  2141. var ValueType$9 = {kind: 'value'};
  2142. // Map input label values to output expression index
  2143. var Match = function Match(inputType, outputType, input, cases, outputs, otherwise) {
  2144. this.inputType = inputType;
  2145. this.type = outputType;
  2146. this.input = input;
  2147. this.cases = cases;
  2148. this.outputs = outputs;
  2149. this.otherwise = otherwise;
  2150. };
  2151. Match.parse = function parse(args, context) {
  2152. if (args.length < 5) {
  2153. return context.error(("Expected at least 4 arguments, but found only " + (args.length - 1) + "."));
  2154. }
  2155. if (args.length % 2 !== 1) {
  2156. return context.error("Expected an even number of arguments.");
  2157. }
  2158. var inputType;
  2159. var outputType;
  2160. if (context.expectedType && context.expectedType.kind !== 'value') {
  2161. outputType = context.expectedType;
  2162. }
  2163. var cases = {};
  2164. var outputs = [];
  2165. for (var i = 2; i < args.length - 1; i += 2) {
  2166. var labels = args[i];
  2167. var value = args[i + 1];
  2168. if (!Array.isArray(labels)) {
  2169. labels = [labels];
  2170. }
  2171. var labelContext = context.concat(i);
  2172. if (labels.length === 0) {
  2173. return labelContext.error('Expected at least one branch label.');
  2174. }
  2175. for (var i$1 = 0, list = labels; i$1 < list.length; i$1 += 1) {
  2176. var label = list[i$1];
  2177. if (typeof label !== 'number' && typeof label !== 'string') {
  2178. return labelContext.error("Branch labels must be numbers or strings.");
  2179. } else if (typeof label === 'number' && Math.abs(label) > Number.MAX_SAFE_INTEGER) {
  2180. return labelContext.error(("Branch labels must be integers no larger than " + (Number.MAX_SAFE_INTEGER) + "."));
  2181. } else if (typeof label === 'number' && Math.floor(label) !== label) {
  2182. return labelContext.error("Numeric branch labels must be integer values.");
  2183. } else if (!inputType) {
  2184. inputType = Values$1.typeOf(label);
  2185. } else if (labelContext.checkSubtype(inputType, Values$1.typeOf(label))) {
  2186. return null;
  2187. }
  2188. if (typeof cases[String(label)] !== 'undefined') {
  2189. return labelContext.error('Branch labels must be unique.');
  2190. }
  2191. cases[String(label)] = outputs.length;
  2192. }
  2193. var result = context.parse(value, i, outputType);
  2194. if (!result) {
  2195. return null;
  2196. }
  2197. outputType = outputType || result.type;
  2198. outputs.push(result);
  2199. }
  2200. var input = context.parse(args[1], 1, ValueType$9);
  2201. if (!input) {
  2202. return null;
  2203. }
  2204. var otherwise = context.parse(args[args.length - 1], args.length - 1, outputType);
  2205. if (!otherwise) {
  2206. return null;
  2207. }
  2208. assert_1(inputType && outputType);
  2209. if (input.type.kind !== 'value' && context.concat(1).checkSubtype((inputType ), input.type)) {
  2210. return null;
  2211. }
  2212. return new Match((inputType ), (outputType ), input, cases, outputs, otherwise);
  2213. };
  2214. Match.prototype.evaluate = function evaluate(ctx) {
  2215. var input = (this.input.evaluate(ctx) );
  2216. var output = (Values$1.typeOf(input) === this.inputType && this.outputs[this.cases[input]]) || this.otherwise;
  2217. return output.evaluate(ctx);
  2218. };
  2219. Match.prototype.eachChild = function eachChild(fn) {
  2220. fn(this.input);
  2221. this.outputs.forEach(fn);
  2222. fn(this.otherwise);
  2223. };
  2224. Match.prototype.possibleOutputs = function possibleOutputs() {
  2225. var ref;
  2226. return (ref = [])
  2227. .concat.apply(ref, this.outputs.map(function (out) {
  2228. return out.possibleOutputs();
  2229. }))
  2230. .concat(this.otherwise.possibleOutputs());
  2231. };
  2232. Match.prototype.serialize = function serialize() {
  2233. var this$1 = this;
  2234. var serialized = ["match", this.input.serialize()];
  2235. // Sort so serialization has an arbitrary defined order, even though
  2236. // branch order doesn't affect evaluation
  2237. var sortedLabels = Object.keys(this.cases).sort();
  2238. // Group branches by unique match expression to support condensed
  2239. // serializations of the form [case1, case2, ...] -> matchExpression
  2240. var groupedByOutput = [];
  2241. var outputLookup = {}; // lookup index into groupedByOutput for a given output expression
  2242. for (var i = 0, list = sortedLabels; i < list.length; i += 1) {
  2243. var label = list[i];
  2244. var outputIndex = outputLookup[this.cases[label]];
  2245. if (outputIndex === undefined) {
  2246. // First time seeing this output, add it to the end of the grouped list
  2247. outputLookup[this.cases[label]] = groupedByOutput.length;
  2248. groupedByOutput.push([this.cases[label], [label]]);
  2249. } else {
  2250. // We've seen this expression before, add the label to that output's group
  2251. groupedByOutput[outputIndex][1].push(label);
  2252. }
  2253. }
  2254. var coerceLabel = function (label) {
  2255. return this$1.inputType.kind === 'number' ? Number(label) : label;
  2256. };
  2257. for (var i$1 = 0, list$1 = groupedByOutput; i$1 < list$1.length; i$1 += 1) {
  2258. var ref = list$1[i$1];
  2259. var outputIndex = ref[0];
  2260. var labels = ref[1];
  2261. if (labels.length === 1) {
  2262. // Only a single label matches this output expression
  2263. serialized.push(coerceLabel(labels[0]));
  2264. } else {
  2265. // Array of literal labels pointing to this output expression
  2266. serialized.push(labels.map(coerceLabel));
  2267. }
  2268. serialized.push(this.outputs[outputIndex$1].serialize());
  2269. }
  2270. serialized.push(this.otherwise.serialize());
  2271. return serialized;
  2272. };
  2273. var NumberType$8 = {kind: 'number'};
  2274. var StringType$7 = {kind: 'string'};
  2275. var NumberFormat = function NumberFormat(number, locale, currency, minFractionDigits, maxFractionDigits) {
  2276. this.type = StringType$7;
  2277. this.number = number;
  2278. this.locale = locale;
  2279. this.currency = currency;
  2280. this.minFractionDigits = minFractionDigits;
  2281. this.maxFractionDigits = maxFractionDigits;
  2282. };
  2283. NumberFormat.parse = function parse(args, context) {
  2284. if (args.length !== 3) {
  2285. return context.error("Expected two arguments.");
  2286. }
  2287. var number = context.parse(args[1], 1, NumberType$8);
  2288. if (!number) {
  2289. return null;
  2290. }
  2291. var options = (args[2] );
  2292. if (typeof options !== "object" || Array.isArray(options)) {
  2293. return context.error("NumberFormat options argument must be an object.");
  2294. }
  2295. var locale = null;
  2296. if (options['locale']) {
  2297. locale = context.parse(options['locale'], 1, StringType$7);
  2298. if (!locale) {
  2299. return null;
  2300. }
  2301. }
  2302. var currency = null;
  2303. if (options['currency']) {
  2304. currency = context.parse(options['currency'], 1, StringType$7);
  2305. if (!currency) {
  2306. return null;
  2307. }
  2308. }
  2309. var minFractionDigits = null;
  2310. if (options['min-fraction-digits']) {
  2311. minFractionDigits = context.parse(options['min-fraction-digits'], 1, NumberType$8);
  2312. if (!minFractionDigits) {
  2313. return null;
  2314. }
  2315. }
  2316. var maxFractionDigits = null;
  2317. if (options['max-fraction-digits']) {
  2318. maxFractionDigits = context.parse(options['max-fraction-digits'], 1, NumberType$8);
  2319. if (!maxFractionDigits) {
  2320. return null;
  2321. }
  2322. }
  2323. return new NumberFormat(number, locale, currency, minFractionDigits, maxFractionDigits);
  2324. };
  2325. NumberFormat.prototype.evaluate = function evaluate(ctx) {
  2326. return new Intl.NumberFormat(this.locale ? this.locale.evaluate(ctx) : [],
  2327. {
  2328. style: this.currency ? "currency" : "decimal",
  2329. currency: this.currency ? this.currency.evaluate(ctx) : undefined,
  2330. minimumFractionDigits: this.minFractionDigits ? this.minFractionDigits.evaluate(ctx) : undefined,
  2331. maximumFractionDigits: this.maxFractionDigits ? this.maxFractionDigits.evaluate(ctx) : undefined,
  2332. }).format(this.number.evaluate(ctx));
  2333. };
  2334. NumberFormat.prototype.eachChild = function eachChild(fn) {
  2335. fn(this.number);
  2336. if (this.locale) {
  2337. fn(this.locale);
  2338. }
  2339. if (this.currency) {
  2340. fn(this.currency);
  2341. }
  2342. if (this.minFractionDigits) {
  2343. fn(this.minFractionDigits);
  2344. }
  2345. if (this.maxFractionDigits) {
  2346. fn(this.maxFractionDigits);
  2347. }
  2348. };
  2349. NumberFormat.prototype.possibleOutputs = function possibleOutputs() {
  2350. return [undefined];
  2351. };
  2352. NumberFormat.prototype.serialize = function serialize() {
  2353. var options = {};
  2354. if (this.locale) {
  2355. options['locale'] = this.locale.serialize();
  2356. }
  2357. if (this.currency) {
  2358. options['currency'] = this.currency.serialize();
  2359. }
  2360. if (this.minFractionDigits) {
  2361. options['min-fraction-digits'] = this.minFractionDigits.serialize();
  2362. }
  2363. if (this.maxFractionDigits) {
  2364. options['max-fraction-digits'] = this.maxFractionDigits.serialize();
  2365. }
  2366. return ["number-format", this.number.serialize(), options];
  2367. };
  2368. /**
  2369. * Returns the index of the last stop <= input, or 0 if it doesn't exist.
  2370. * @private
  2371. */
  2372. function findStopLessThanOrEqualTo$1(stops, input) {
  2373. var lastIndex = stops.length - 1;
  2374. var lowerIndex = 0;
  2375. var upperIndex = lastIndex;
  2376. var currentIndex = 0;
  2377. var currentValue, nextValue;
  2378. while (lowerIndex <= upperIndex) {
  2379. currentIndex = Math.floor((lowerIndex + upperIndex) / 2);
  2380. currentValue = stops[currentIndex];
  2381. nextValue = stops[currentIndex + 1];
  2382. if (currentValue <= input) {
  2383. if (currentIndex === lastIndex || input < nextValue) { // Search complete
  2384. return currentIndex;
  2385. }
  2386. lowerIndex = currentIndex + 1;
  2387. } else if (currentValue > input) {
  2388. upperIndex = currentIndex - 1;
  2389. } else {
  2390. throw new RuntimeError('Input is not a number.');
  2391. }
  2392. }
  2393. return 0;
  2394. }
  2395. var NumberType$9 = {kind: 'number'};
  2396. var Step = function Step(type, input, stops) {
  2397. this.type = type;
  2398. this.input = input;
  2399. this.labels = [];
  2400. this.outputs = [];
  2401. for (var i = 0, list = stops; i < list.length; i += 1) {
  2402. var ref = list[i];
  2403. var label = ref[0];
  2404. var expression = ref[1];
  2405. this.labels.push(label);
  2406. this.outputs.push(expression);
  2407. }
  2408. };
  2409. Step.parse = function parse(args, context) {
  2410. if (args.length - 1 < 4) {
  2411. return context.error(("Expected at least 4 arguments, but found only " + (args.length - 1) + "."));
  2412. }
  2413. if ((args.length - 1) % 2 !== 0) {
  2414. return context.error("Expected an even number of arguments.");
  2415. }
  2416. var input = context.parse(args[1], 1, NumberType$9);
  2417. if (!input) {
  2418. return null;
  2419. }
  2420. var stops = [];
  2421. var outputType = (null );
  2422. if (context.expectedType && context.expectedType.kind !== 'value') {
  2423. outputType = context.expectedType;
  2424. }
  2425. for (var i = 1; i < args.length; i += 2) {
  2426. var label = i === 1 ? -Infinity : args[i];
  2427. var value = args[i + 1];
  2428. var labelKey = i;
  2429. var valueKey = i + 1;
  2430. if (typeof label !== 'number') {
  2431. return context.error('Input/output pairs for "step" expressions must be defined using literal numeric values (not computed expressions) for the input values.', labelKey);
  2432. }
  2433. if (stops.length && stops[stops.length - 1][0] >= label) {
  2434. return context.error('Input/output pairs for "step" expressions must be arranged with input values in strictly ascending order.', labelKey);
  2435. }
  2436. var parsed = context.parse(value, valueKey, outputType);
  2437. if (!parsed) {
  2438. return null;
  2439. }
  2440. outputType = outputType || parsed.type;
  2441. stops.push([label, parsed]);
  2442. }
  2443. return new Step(outputType, input, stops);
  2444. };
  2445. Step.prototype.evaluate = function evaluate(ctx) {
  2446. var labels = this.labels;
  2447. var outputs = this.outputs;
  2448. if (labels.length === 1) {
  2449. return outputs[0].evaluate(ctx);
  2450. }
  2451. var value = ((this.input.evaluate(ctx) ) );
  2452. if (value <= labels[0]) {
  2453. return outputs[0].evaluate(ctx);
  2454. }
  2455. var stopCount = labels.length;
  2456. if (value >= labels[stopCount - 1]) {
  2457. return outputs[stopCount - 1].evaluate(ctx);
  2458. }
  2459. var index = findStopLessThanOrEqualTo$1(labels, value);
  2460. return outputs[index].evaluate(ctx);
  2461. };
  2462. Step.prototype.eachChild = function eachChild(fn) {
  2463. fn(this.input);
  2464. for (var i = 0, list = this.outputs; i < list.length; i += 1) {
  2465. var expression = list[i];
  2466. fn(expression);
  2467. }
  2468. };
  2469. Step.prototype.possibleOutputs = function possibleOutputs() {
  2470. var ref;
  2471. return (ref = []).concat.apply(ref, this.outputs.map(function (output) {
  2472. return output.possibleOutputs();
  2473. }));
  2474. };
  2475. Step.prototype.serialize = function serialize() {
  2476. var serialized = ["step", this.input.serialize()];
  2477. for (var i = 0; i < this.labels.length; i++) {
  2478. if (i > 0) {
  2479. serialized.push(this.labels[i]);
  2480. }
  2481. serialized.push(this.outputs[i].serialize());
  2482. }
  2483. return serialized;
  2484. };
  2485. var Var = function Var(name, boundExpression) {
  2486. this.type = boundExpression.type;
  2487. this.name = name;
  2488. this.boundExpression = boundExpression;
  2489. };
  2490. Var.parse = function parse(args, context) {
  2491. if (args.length !== 2 || typeof args[1] !== 'string') {
  2492. return context.error("'var' expression requires exactly one string literal argument.");
  2493. }
  2494. var name = args[1];
  2495. if (!context.scope.has(name)) {
  2496. return context.error(("Unknown variable \"" + name + "\". Make sure \"" + name + "\" has been bound in an enclosing \"let\" expression before using it."), 1);
  2497. }
  2498. return new Var(name, context.scope.get(name));
  2499. };
  2500. Var.prototype.evaluate = function evaluate(ctx) {
  2501. return this.boundExpression.evaluate(ctx);
  2502. };
  2503. Var.prototype.eachChild = function eachChild() {
  2504. };
  2505. Var.prototype.possibleOutputs = function possibleOutputs() {
  2506. return [undefined];
  2507. };
  2508. Var.prototype.serialize = function serialize() {
  2509. return ["var", this.name];
  2510. };
  2511. var expressions = {
  2512. // special forms
  2513. '==': ComparisonEnum.Equals,
  2514. '!=': ComparisonEnum.NotEquals,
  2515. '>': ComparisonEnum.GreaterThan,
  2516. '<': ComparisonEnum.LessThan,
  2517. '>=': ComparisonEnum.GreaterThanOrEqual,
  2518. '<=': ComparisonEnum.LessThanOrEqual,
  2519. 'array': Assertion,
  2520. 'at': At,
  2521. 'boolean': Assertion,
  2522. 'case': Case,
  2523. 'coalesce': Coalesce,
  2524. 'collator': CollatorExpression,
  2525. 'format': FormatExpression$1,
  2526. 'image': ImageExpression$1,
  2527. 'in': In,
  2528. 'interpolate': Interpolate$1,
  2529. 'interpolate-hcl': Interpolate$1,
  2530. 'interpolate-lab': Interpolate$1,
  2531. 'length': Length,
  2532. 'let': Let,
  2533. 'literal': Literal,
  2534. 'match': Match,
  2535. 'number': Assertion,
  2536. 'number-format': NumberFormat,
  2537. 'object': Assertion,
  2538. 'step': Step,
  2539. 'string': Assertion,
  2540. 'to-boolean': Coercion,
  2541. 'to-color': Coercion,
  2542. 'to-number': Coercion,
  2543. 'to-string': Coercion,
  2544. 'var': Var
  2545. };
  2546. function WebWorkerTransfer() {
  2547. }
  2548. var registry = {};
  2549. /**
  2550. * Register the given class as serializable.
  2551. *
  2552. * @param options
  2553. * @param options.omit List of properties to omit from serialization (e.g., cached/computed properties)
  2554. * @param options.shallow List of properties that should be serialized by a simple shallow copy, rather than by a recursive call to serialize().
  2555. *
  2556. * @private
  2557. */
  2558. WebWorkerTransfer.register = function (name, klass, options) {
  2559. if (options === void 0) options = {};
  2560. //assert(!registry[name], (name + " is already registered."));
  2561. (Object.defineProperty )(klass, '_classRegistryKey', {
  2562. value: name,
  2563. writeable: false
  2564. });
  2565. registry[name] = {
  2566. klass: klass,
  2567. omit: options.omit || [],
  2568. shallow: options.shallow || []
  2569. };
  2570. };
  2571. WebWorkerTransfer.register('Object', Object);
  2572. // gridIndex.serialize = function serialize(grid, transferables) {
  2573. // var buffer = grid.toArrayBuffer();
  2574. // if (transferables) {
  2575. // transferables.push(buffer);
  2576. // }
  2577. // return {buffer: buffer};
  2578. // };
  2579. //
  2580. // gridIndex.deserialize = function deserialize(serialized) {
  2581. // return new gridIndex(serialized.buffer);
  2582. // };
  2583. // register('Grid', gridIndex);
  2584. WebWorkerTransfer.register('Color', Color$1);
  2585. //WebWorkerTransfer.register('Error', Error);
  2586. WebWorkerTransfer.register('ResolvedImage', ResolvedImage$1);
  2587. WebWorkerTransfer.register('ImageAtlas', ImageAtlas);
  2588. WebWorkerTransfer.register('ImagePosition', ImagePosition);
  2589. WebWorkerTransfer.register('RGBAImage', RGBAImage);
  2590. WebWorkerTransfer.register('Formatted', Formatted$1);
  2591. WebWorkerTransfer.register('FormattedSection', FormattedSection);
  2592. // WebWorkerTransfer.register('StylePropertyFunction', StylePropertyFunction);
  2593. // WebWorkerTransfer.register('StyleExpression', StyleExpression, {omit: ['_evaluator']});
  2594. //
  2595. // WebWorkerTransfer.register('ZoomDependentExpression', ZoomDependentExpression);
  2596. // WebWorkerTransfer.register('ZoomConstantExpression', ZoomConstantExpression);
  2597. // WebWorkerTransfer.register('CompoundExpression', CompoundExpression, {omit: ['_evaluate']});
  2598. for (var name$1 in expressions) {
  2599. if ((expressions[name$1] )._classRegistryKey) {
  2600. continue;
  2601. }
  2602. WebWorkerTransfer.register(("Expression_" + name$1), expressions[name$1]);
  2603. }
  2604. function isArrayBuffer(val) {
  2605. return val && typeof ArrayBuffer !== 'undefined' &&
  2606. (val instanceof ArrayBuffer || (val.constructor && val.constructor.name === 'ArrayBuffer'));
  2607. }
  2608. /**
  2609. * Serialize the given object for transfer to or from a web worker.
  2610. *
  2611. * For non-builtin types, recursively serialize each property (possibly
  2612. * omitting certain properties - see register()), and package the result along
  2613. * with the constructor's `name` so that the appropriate constructor can be
  2614. * looked up in `deserialize()`.
  2615. *
  2616. * If a `transferables` array is provided, add any transferable objects (i.e.,
  2617. * any ArrayBuffers or ArrayBuffer views) to the list. (If a copy is needed,
  2618. * this should happen in the client code, before using serialize().)
  2619. *
  2620. * @private
  2621. */
  2622. WebWorkerTransfer.serialize = function (input, transferables) {
  2623. if (input === null ||
  2624. input === undefined ||
  2625. typeof input === 'boolean' ||
  2626. typeof input === 'number' ||
  2627. typeof input === 'string' ||
  2628. input instanceof Boolean ||
  2629. input instanceof Number ||
  2630. input instanceof String ||
  2631. input instanceof Date ||
  2632. input instanceof RegExp) {
  2633. return input;
  2634. }
  2635. if (isArrayBuffer(input)) {
  2636. if (transferables) {
  2637. transferables.push(((input ) ));
  2638. }
  2639. return input;
  2640. }
  2641. if (ArrayBuffer.isView(input)) {
  2642. var view = (input );
  2643. if (transferables) {
  2644. transferables.push(view.buffer);
  2645. }
  2646. return view;
  2647. }
  2648. if (input instanceof ImageData) {
  2649. if (transferables) {
  2650. transferables.push(input.data.buffer);
  2651. }
  2652. return input;
  2653. }
  2654. if (Array.isArray(input)) {
  2655. var serialized = [];
  2656. for (var i = 0, list = input; i < list.length; i += 1) {
  2657. var item = list[i];
  2658. serialized.push(WebWorkerTransfer.serialize(item, transferables));
  2659. }
  2660. return serialized;
  2661. }
  2662. if (typeof input === 'object') {
  2663. var klass = (input.constructor );
  2664. var name = klass._classRegistryKey;
  2665. if (!name) {
  2666. throw new Error("can't serialize object of unregistered class");
  2667. }
  2668. //assert(registry[name]);
  2669. var properties = klass.serialize ?
  2670. // (Temporary workaround) allow a class to provide static
  2671. // `serialize()` and `deserialize()` methods to bypass the generic
  2672. // approach.
  2673. // This temporary workaround lets us use the generic serialization
  2674. // approach for objects whose members include instances of dynamic
  2675. // StructArray types. Once we refactor StructArray to be static,
  2676. // we can remove this complexity.
  2677. (klass.serialize(input, transferables) ) : {};
  2678. if (!klass.serialize) {
  2679. for (var key in input) {
  2680. // any cast due to https://github.com/facebook/flow/issues/5393
  2681. if (!(input ).hasOwnProperty(key)) {
  2682. continue;
  2683. }
  2684. if (registry[name].omit.indexOf(key) >= 0) {
  2685. continue;
  2686. }
  2687. var property = (input )[key];
  2688. properties[key] = registry[name].shallow.indexOf(key) >= 0 ?
  2689. property :
  2690. WebWorkerTransfer.serialize(property, transferables);
  2691. }
  2692. if (input instanceof Error) {
  2693. properties.message = input.message;
  2694. }
  2695. }
  2696. if (properties.$name) {
  2697. throw new Error('$name property is reserved for worker serialization logic.');
  2698. }
  2699. if (name !== 'Object') {
  2700. properties.$name = name;
  2701. }
  2702. return properties;
  2703. }
  2704. throw new Error(("can't serialize object of type " + (typeof input)));
  2705. };
  2706. WebWorkerTransfer.deserialize = function (input) {
  2707. if (input === null ||
  2708. input === undefined ||
  2709. typeof input === 'boolean' ||
  2710. typeof input === 'number' ||
  2711. typeof input === 'string' ||
  2712. input instanceof Boolean ||
  2713. input instanceof Number ||
  2714. input instanceof String ||
  2715. input instanceof Date ||
  2716. input instanceof RegExp ||
  2717. isArrayBuffer(input) ||
  2718. ArrayBuffer.isView(input) ||
  2719. input instanceof ImageData) {
  2720. return input;
  2721. }
  2722. if (Array.isArray(input)) {
  2723. return input.map(WebWorkerTransfer.deserialize);
  2724. }
  2725. if (typeof input === 'object') {
  2726. var name = (input ).$name || 'Object';
  2727. var ref = registry[name];
  2728. var klass = ref.klass;
  2729. if (!klass) {
  2730. throw new Error(("can't deserialize unregistered class " + name));
  2731. }
  2732. if (klass.deserialize) {
  2733. return (klass.deserialize )(input);
  2734. }
  2735. var result = Object.create(klass.prototype);
  2736. for (var i = 0, list = Object.keys(input); i < list.length; i += 1) {
  2737. var key = list[i];
  2738. if (key === '$name') {
  2739. continue;
  2740. }
  2741. var value = (input )[key];
  2742. result[key] = registry[name].shallow.indexOf(key) >= 0 ? value : WebWorkerTransfer.deserialize(value);
  2743. }
  2744. return result;
  2745. }
  2746. throw new Error(("can't deserialize object of type " + (typeof input)));
  2747. };
  2748. var ZoomHistory = function ZoomHistory() {
  2749. this.first = true;
  2750. };
  2751. ZoomHistory.prototype.update = function update (z , now ) {
  2752. var floorZ = Math.floor(z);
  2753. if (this.first) {
  2754. this.first = false;
  2755. this.lastIntegerZoom = floorZ;
  2756. this.lastIntegerZoomTime = 0;
  2757. this.lastZoom = z;
  2758. this.lastFloorZoom = floorZ;
  2759. return true;
  2760. }
  2761. if (this.lastFloorZoom > floorZ) {
  2762. this.lastIntegerZoom = floorZ + 1;
  2763. this.lastIntegerZoomTime = now;
  2764. } else if (this.lastFloorZoom < floorZ) {
  2765. this.lastIntegerZoom = floorZ;
  2766. this.lastIntegerZoomTime = now;
  2767. }
  2768. if (z !== this.lastZoom) {
  2769. this.lastZoom = z;
  2770. this.lastFloorZoom = floorZ;
  2771. return true;
  2772. }
  2773. return false;
  2774. };
  2775. var EvaluationParameters$1 = function EvaluationParameters(zoom, options) {
  2776. this.zoom = zoom;
  2777. if (options) {
  2778. this.now = options.now;
  2779. this.fadeDuration = options.fadeDuration;
  2780. this.zoomHistory = options.zoomHistory;
  2781. this.transition = options.transition;
  2782. } else {
  2783. this.now = 0;
  2784. this.fadeDuration = 0;
  2785. this.zoomHistory = new ZoomHistory();
  2786. this.transition = {};
  2787. }
  2788. };
  2789. EvaluationParameters$1.prototype.isSupportedScript = function isSupportedScript(str) {
  2790. return false;
  2791. //return isStringInSupportedScript(str, plugin.isLoaded());
  2792. };
  2793. EvaluationParameters$1.prototype.crossFadingFactor = function crossFadingFactor() {
  2794. if (this.fadeDuration === 0) {
  2795. return 1;
  2796. } else {
  2797. return Math.min((this.now - this.zoomHistory.lastIntegerZoomTime) / this.fadeDuration, 1);
  2798. }
  2799. };
  2800. EvaluationParameters$1.prototype.getCrossfadeParameters = function getCrossfadeParameters() {
  2801. var z = this.zoom;
  2802. var fraction = z - Math.floor(z);
  2803. var t = this.crossFadingFactor();
  2804. return z > this.zoomHistory.lastIntegerZoom ?
  2805. {fromScale: 2, toScale: 1, t: fraction + (1 - fraction) * t} :
  2806. {fromScale: 0.5, toScale: 1, t: 1 - (1 - t) * fraction};
  2807. };
  2808. var EXTENT = 8192;
  2809. function clamp(n, min, max) {
  2810. return Math.min(max, Math.max(min, n));
  2811. }
  2812. // These bounds define the minimum and maximum supported coordinate values.
  2813. // While visible coordinates are within [0, EXTENT], tiles may theoretically
  2814. // contain cordinates within [-Infinity, Infinity]. Our range is limited by the
  2815. // number of bits used to represent the coordinate.
  2816. function createBounds(bits) {
  2817. return {
  2818. min: -1 * Math.pow(2, bits - 1),
  2819. max: Math.pow(2, bits - 1) - 1
  2820. };
  2821. }
  2822. var bounds = createBounds(15);
  2823. /**
  2824. * Loads a geometry from a VectorTileFeature and scales it to the common extent
  2825. * used internally.
  2826. * @param {VectorTileFeature} feature
  2827. * @private
  2828. */
  2829. function loadGeometry(feature) {
  2830. var scale = EXTENT / feature.extent;
  2831. var geometry = feature.loadGeometry();
  2832. for (var r = 0; r < geometry.length; r++) {
  2833. var ring = geometry[r];
  2834. for (var p = 0; p < ring.length; p++) {
  2835. var point = ring[p];
  2836. // round here because mapbox-gl-native uses integers to represent
  2837. // points and we need to do the same to avoid renering differences.
  2838. point.x = Math.round(point.x * scale);
  2839. // 因为绘制到纹理上颠倒了,所以在这里取反
  2840. point.y = EXTENT - Math.round(point.y * scale);
  2841. if (point.x < bounds.min || point.x > bounds.max || point.y < bounds.min || point.y > bounds.max) {
  2842. //warnOnce('Geometry exceeds allowed extent, reduce your vector tile buffer size');
  2843. point.x = clamp(point.x, bounds.min, bounds.max);
  2844. point.y = clamp(point.y, bounds.min, bounds.max);
  2845. }
  2846. }
  2847. }
  2848. return geometry;
  2849. }
  2850. var SegmentVector = function SegmentVector(segments) {
  2851. if (segments === void 0) segments = [];
  2852. this.segments = segments;
  2853. };
  2854. SegmentVector.prototype.prepareSegment = function prepareSegment(numVertices, layoutVertexArray, indexArray, sortKey) {
  2855. var segment = this.segments[this.segments.length - 1];
  2856. if (!segment || segment.vertexLength + numVertices > SegmentVector.MAX_VERTEX_ARRAY_LENGTH || segment.sortKey !== sortKey) {
  2857. segment = ({
  2858. vertexOffset: layoutVertexArray.length,
  2859. primitiveOffset: indexArray.length,
  2860. vertexLength: 0,
  2861. primitiveLength: 0
  2862. } );
  2863. if (sortKey !== undefined) {
  2864. segment.sortKey = sortKey;
  2865. }
  2866. this.segments.push(segment);
  2867. }
  2868. return segment;
  2869. };
  2870. SegmentVector.prototype.get = function get() {
  2871. return this.segments;
  2872. };
  2873. SegmentVector.prototype.destroy = function destroy() {
  2874. for (var i = 0, list = this.segments; i < list.length; i += 1) {
  2875. var segment = list[i];
  2876. for (var k in segment.vaos) {
  2877. segment.vaos[k].destroy();
  2878. }
  2879. }
  2880. };
  2881. SegmentVector.simpleSegment = function simpleSegment(vertexOffset, primitiveOffset, vertexLength, primitiveLength) {
  2882. return new SegmentVector([
  2883. {
  2884. vertexOffset: vertexOffset,
  2885. primitiveOffset: primitiveOffset,
  2886. vertexLength: vertexLength,
  2887. primitiveLength: primitiveLength,
  2888. vaos: {},
  2889. sortKey: 0
  2890. }
  2891. ]);
  2892. };
  2893. /*
  2894. * The maximum size of a vertex array. This limit is imposed by WebGL's 16 bit
  2895. * addressing of vertex buffers.
  2896. * @private
  2897. * @readonly
  2898. */
  2899. SegmentVector.MAX_VERTEX_ARRAY_LENGTH = Math.pow(2, 16) - 1;
  2900. WebWorkerTransfer.register('SegmentVector', SegmentVector);
  2901. /**
  2902. * @private
  2903. */
  2904. var DEFAULT_CAPACITY = 128;
  2905. var RESIZE_MULTIPLIER = 5;
  2906. /**
  2907. * `StructArray` provides an abstraction over `ArrayBuffer` and `TypedArray`
  2908. * making it behave like an array of typed structs.
  2909. *
  2910. * Conceptually, a StructArray is comprised of elements, i.e., instances of its
  2911. * associated struct type. Each particular struct type, together with an
  2912. * alignment size, determines the memory layout of a StructArray whose elements
  2913. * are of that type. Thus, for each such layout that we need, we have
  2914. * a corrseponding StructArrayLayout class, inheriting from StructArray and
  2915. * implementing `emplaceBack()` and `_refreshViews()`.
  2916. *
  2917. * In some cases, where we need to access particular elements of a StructArray,
  2918. * we implement a more specific subclass that inherits from one of the
  2919. * StructArrayLayouts and adds a `get(i): T` accessor that returns a structured
  2920. * object whose properties are proxies into the underlying memory space for the
  2921. * i-th element. This affords the convience of working with (seemingly) plain
  2922. * Javascript objects without the overhead of serializing/deserializing them
  2923. * into ArrayBuffers for efficient web worker transfer.
  2924. *
  2925. * @private
  2926. */
  2927. var StructArray = function StructArray() {
  2928. this.isTransferred = false;
  2929. this.capacity = -1;
  2930. this.resize(0);
  2931. };
  2932. /**
  2933. * Serialize a StructArray instance.Serializes both the raw data and the
  2934. * metadata needed to reconstruct the StructArray base class during
  2935. * deserialization.
  2936. */
  2937. StructArray.serialize = function serialize(array, transferables) {
  2938. //assert_1(!array.isTransferred);
  2939. if(array.isTransferred){
  2940. console.log("StructArray array.isTransferred.");
  2941. }
  2942. array._trim();
  2943. if (transferables) {
  2944. array.isTransferred = true;
  2945. transferables.push(array.arrayBuffer);
  2946. }
  2947. return {
  2948. length: array.length,
  2949. arrayBuffer: array.arrayBuffer,
  2950. };
  2951. };
  2952. StructArray.deserialize = function deserialize(input) {
  2953. var structArray = Object.create(this.prototype);
  2954. structArray.arrayBuffer = input.arrayBuffer;
  2955. structArray.length = input.length;
  2956. structArray.capacity = input.arrayBuffer.byteLength / structArray.bytesPerElement;
  2957. structArray._refreshViews();
  2958. return structArray;
  2959. };
  2960. /**
  2961. * Resize the array to discard unused capacity.
  2962. */
  2963. StructArray.prototype._trim = function _trim() {
  2964. if (this.length !== this.capacity) {
  2965. this.capacity = this.length;
  2966. this.arrayBuffer = this.arrayBuffer.slice(0, this.length * this.bytesPerElement);
  2967. this._refreshViews();
  2968. }
  2969. };
  2970. /**
  2971. * Resets the the length of the array to 0 without de-allocating capcacity.
  2972. */
  2973. StructArray.prototype.clear = function clear() {
  2974. this.length = 0;
  2975. };
  2976. /**
  2977. * Resize the array.
  2978. * If `n` is greater than the current length then additional elements with undefined values are added.
  2979. * If `n` is less than the current length then the array will be reduced to the first `n` elements.
  2980. * @param {number} n The new size of the array.
  2981. */
  2982. StructArray.prototype.resize = function resize(n) {
  2983. //assert_1(!this.isTransferred);
  2984. this.reserve(n);
  2985. this.length = n;
  2986. };
  2987. /**
  2988. * Indicate a planned increase in size, so that any necessary allocation may
  2989. * be done once, ahead of time.
  2990. * @param {number} n The expected size of the array.
  2991. */
  2992. StructArray.prototype.reserve = function reserve(n) {
  2993. if (n > this.capacity) {
  2994. this.capacity = Math.max(n, Math.floor(this.capacity * RESIZE_MULTIPLIER), DEFAULT_CAPACITY);
  2995. this.arrayBuffer = new ArrayBuffer(this.capacity * this.bytesPerElement);
  2996. var oldUint8Array = this.uint8;
  2997. this._refreshViews();
  2998. if (oldUint8Array) {
  2999. this.uint8.set(oldUint8Array);
  3000. }
  3001. }
  3002. };
  3003. /**
  3004. * Create TypedArray views for the current ArrayBuffer.
  3005. */
  3006. StructArray.prototype._refreshViews = function _refreshViews() {
  3007. throw new Error('_refreshViews() must be implemented by each concrete StructArray layout');
  3008. };
  3009. /**
  3010. * Implementation of the StructArray layout:
  3011. * [0]: Int16[2]
  3012. * [4]: Uint8[4]
  3013. *
  3014. * @private
  3015. */
  3016. var StructArrayLayout2i4ub8 = /*@__PURE__*/(function (StructArray) {
  3017. function StructArrayLayout2i4ub8() {
  3018. StructArray.apply(this, arguments);
  3019. }
  3020. if (StructArray) StructArrayLayout2i4ub8.__proto__ = StructArray;
  3021. StructArrayLayout2i4ub8.prototype = Object.create(StructArray && StructArray.prototype);
  3022. StructArrayLayout2i4ub8.prototype.constructor = StructArrayLayout2i4ub8;
  3023. StructArrayLayout2i4ub8.prototype._refreshViews = function _refreshViews() {
  3024. this.uint8 = new Uint8Array(this.arrayBuffer);
  3025. this.int16 = new Int16Array(this.arrayBuffer);
  3026. };
  3027. StructArrayLayout2i4ub8.prototype.emplaceBack = function emplaceBack(v0, v1, v2, v3, v4, v5) {
  3028. var i = this.length;
  3029. this.resize(i + 1);
  3030. return this.emplace(i, v0, v1, v2, v3, v4, v5);
  3031. };
  3032. StructArrayLayout2i4ub8.prototype.emplace = function emplace(i, v0, v1, v2, v3, v4, v5) {
  3033. var o2 = i * 4;
  3034. var o1 = i * 8;
  3035. this.int16[o2 + 0] = v0;
  3036. this.int16[o2 + 1] = v1;
  3037. this.uint8[o1 + 4] = v2;
  3038. this.uint8[o1 + 5] = v3;
  3039. this.uint8[o1 + 6] = v4;
  3040. this.uint8[o1 + 7] = v5;
  3041. return i;
  3042. };
  3043. return StructArrayLayout2i4ub8;
  3044. }(StructArray));
  3045. StructArrayLayout2i4ub8.prototype.bytesPerElement = 8;
  3046. WebWorkerTransfer.register('StructArrayLayout2i4ub8', StructArrayLayout2i4ub8);
  3047. /**
  3048. * Implementation of the StructArray layout:
  3049. * [0]: Uint16[3]
  3050. *
  3051. * @private
  3052. */
  3053. var StructArrayLayout3ui6 = /*@__PURE__*/(function (StructArray) {
  3054. function StructArrayLayout3ui6() {
  3055. StructArray.apply(this, arguments);
  3056. }
  3057. if (StructArray) StructArrayLayout3ui6.__proto__ = StructArray;
  3058. StructArrayLayout3ui6.prototype = Object.create(StructArray && StructArray.prototype);
  3059. StructArrayLayout3ui6.prototype.constructor = StructArrayLayout3ui6;
  3060. StructArrayLayout3ui6.prototype._refreshViews = function _refreshViews() {
  3061. this.uint8 = new Uint8Array(this.arrayBuffer);
  3062. this.uint16 = new Uint16Array(this.arrayBuffer);
  3063. };
  3064. StructArrayLayout3ui6.prototype.emplaceBack = function emplaceBack(v0, v1, v2) {
  3065. var i = this.length;
  3066. this.resize(i + 1);
  3067. return this.emplace(i, v0, v1, v2);
  3068. };
  3069. StructArrayLayout3ui6.prototype.emplace = function emplace(i, v0, v1, v2) {
  3070. var o2 = i * 3;
  3071. this.uint16[o2 + 0] = v0;
  3072. this.uint16[o2 + 1] = v1;
  3073. this.uint16[o2 + 2] = v2;
  3074. return i;
  3075. };
  3076. return StructArrayLayout3ui6;
  3077. }(StructArray));
  3078. StructArrayLayout3ui6.prototype.bytesPerElement = 6;
  3079. WebWorkerTransfer.register('StructArrayLayout3ui6', StructArrayLayout3ui6);
  3080. // A transferable data structure that maps feature ids to their indices and buffer offsets
  3081. var FeaturePositionMap = function FeaturePositionMap() {
  3082. this.ids = [];
  3083. this.positions = [];
  3084. this.indexed = false;
  3085. };
  3086. FeaturePositionMap.prototype.add = function add(id, index, start, end) {
  3087. this.ids.push(id);
  3088. this.positions.push(index, start, end);
  3089. };
  3090. FeaturePositionMap.prototype.getPositions = function getPositions(id) {
  3091. //assert_1(this.indexed);
  3092. // binary search for the first occurrence of id in this.ids;
  3093. // relies on ids/positions being sorted by id, which happens in serialization
  3094. var i = 0;
  3095. var j = this.ids.length - 1;
  3096. while (i < j) {
  3097. var m = (i + j) >> 1;
  3098. if (this.ids[m] >= id) {
  3099. j = m;
  3100. } else {
  3101. i = m + 1;
  3102. }
  3103. }
  3104. var positions = [];
  3105. while (this.ids[i] === id) {
  3106. var index = this.positions[3 * i];
  3107. var start = this.positions[3 * i + 1];
  3108. var end = this.positions[3 * i + 2];
  3109. positions.push({index: index, start: start, end: end});
  3110. i++;
  3111. }
  3112. return positions;
  3113. };
  3114. FeaturePositionMap.serialize = function serialize(map, transferables) {
  3115. var ids = new Float64Array(map.ids);
  3116. var positions = new Uint32Array(map.positions);
  3117. sort(ids, positions, 0, ids.length - 1);
  3118. if (transferables) {
  3119. transferables.push(ids.buffer, positions.buffer);
  3120. }
  3121. return {ids: ids, positions: positions};
  3122. };
  3123. FeaturePositionMap.deserialize = function deserialize(obj) {
  3124. var map = new FeaturePositionMap();
  3125. // after transferring, we only use these arrays statically (no pushes),
  3126. // so TypedArray vs Array distinction that flow points out doesn't matter
  3127. map.ids = (obj.ids );
  3128. map.positions = (obj.positions );
  3129. map.indexed = true;
  3130. return map;
  3131. };
  3132. // custom quicksort that sorts ids, indices and offsets together (by ids)
  3133. function sort(ids, positions, left, right) {
  3134. if (left >= right) {
  3135. return;
  3136. }
  3137. var pivot = ids[(left + right) >> 1];
  3138. var i = left - 1;
  3139. var j = right + 1;
  3140. while (true) {
  3141. do {
  3142. i++;
  3143. } while (ids[i] < pivot);
  3144. do {
  3145. j--;
  3146. } while (ids[j] > pivot);
  3147. if (i >= j) {
  3148. break;
  3149. }
  3150. swap(ids, i, j);
  3151. swap(positions, 3 * i, 3 * j);
  3152. swap(positions, 3 * i + 1, 3 * j + 1);
  3153. swap(positions, 3 * i + 2, 3 * j + 2);
  3154. }
  3155. sort(ids, positions, left, j);
  3156. sort(ids, positions, j + 1, right);
  3157. }
  3158. function swap(arr, i, j) {
  3159. var tmp = arr[i];
  3160. arr[i] = arr[j];
  3161. arr[j] = tmp;
  3162. }
  3163. WebWorkerTransfer.register('FeaturePositionMap', FeaturePositionMap);
  3164. /**
  3165. * `PossiblyEvaluatedPropertyValue` is used for data-driven paint and layout property values. It holds a
  3166. * `PossiblyEvaluatedValue` and the `GlobalProperties` that were used to generate it. You're not allowed to supply
  3167. * a different set of `GlobalProperties` when performing the final evaluation because they would be ignored in the
  3168. * case where the input value was a constant or camera function.
  3169. *
  3170. * @private
  3171. */
  3172. var PossiblyEvaluatedPropertyValue$1 = function PossiblyEvaluatedPropertyValue(property, value, parameters) {
  3173. this.property = property;
  3174. this.value = value;
  3175. this.parameters = parameters;
  3176. };
  3177. PossiblyEvaluatedPropertyValue$1.prototype.isConstant = function isConstant() {
  3178. return this.value.kind === 'constant';
  3179. };
  3180. PossiblyEvaluatedPropertyValue$1.prototype.constantOr = function constantOr(value) {
  3181. if (this.value.kind === 'constant') {
  3182. return this.value.value;
  3183. } else {
  3184. return value;
  3185. }
  3186. };
  3187. PossiblyEvaluatedPropertyValue$1.prototype.evaluate = function evaluate(feature, featureState, availableImages) {
  3188. return this.property.evaluate(this.value, this.parameters, feature, featureState, availableImages);
  3189. };
  3190. function Supports() {
  3191. }
  3192. Supports.supportsPropertyExpression = function (spec) {
  3193. return spec['property-type'] === 'data-driven' || spec['property-type'] === 'cross-faded-data-driven';
  3194. };
  3195. Supports.supportsZoomExpression = function (spec) {
  3196. return !!spec.expression && spec.expression.parameters.indexOf('zoom') > -1;
  3197. };
  3198. Supports.supportsInterpolation = function (spec) {
  3199. return !!spec.expression && spec.expression.interpolated;
  3200. };
  3201. var UniformType = {};
  3202. var Uniform = function Uniform(context, location) {
  3203. this.gl = context.gl;
  3204. this.location = location;
  3205. };
  3206. UniformType.Uniform1i = /*@__PURE__*/(function (Uniform) {
  3207. function Uniform1i(context, location) {
  3208. Uniform.call(this, context, location);
  3209. this.current = 0;
  3210. }
  3211. if (Uniform) Uniform1i.__proto__ = Uniform;
  3212. Uniform1i.prototype = Object.create(Uniform && Uniform.prototype);
  3213. Uniform1i.prototype.constructor = Uniform1i;
  3214. Uniform1i.prototype.set = function set(v) {
  3215. if (this.current !== v) {
  3216. this.current = v;
  3217. this.gl.uniform1i(this.location, v);
  3218. }
  3219. };
  3220. return Uniform1i;
  3221. }(Uniform));
  3222. UniformType.Uniform1f = /*@__PURE__*/(function (Uniform) {
  3223. function Uniform1f(context, location) {
  3224. Uniform.call(this, context, location);
  3225. this.current = 0;
  3226. }
  3227. if (Uniform) Uniform1f.__proto__ = Uniform;
  3228. Uniform1f.prototype = Object.create(Uniform && Uniform.prototype);
  3229. Uniform1f.prototype.constructor = Uniform1f;
  3230. Uniform1f.prototype.set = function set(v) {
  3231. if (this.current !== v) {
  3232. this.current = v;
  3233. this.gl.uniform1f(this.location, v);
  3234. }
  3235. };
  3236. return Uniform1f;
  3237. }(Uniform));
  3238. UniformType.Uniform2f = /*@__PURE__*/(function (Uniform) {
  3239. function Uniform2f(context, location) {
  3240. Uniform.call(this, context, location);
  3241. this.current = [0, 0];
  3242. }
  3243. if (Uniform) Uniform2f.__proto__ = Uniform;
  3244. Uniform2f.prototype = Object.create(Uniform && Uniform.prototype);
  3245. Uniform2f.prototype.constructor = Uniform2f;
  3246. Uniform2f.prototype.set = function set(v) {
  3247. if (v[0] !== this.current[0] || v[1] !== this.current[1]) {
  3248. this.current = v;
  3249. this.gl.uniform2f(this.location, v[0], v[1]);
  3250. }
  3251. };
  3252. return Uniform2f;
  3253. }(Uniform));
  3254. UniformType.Uniform3f = /*@__PURE__*/(function (Uniform) {
  3255. function Uniform3f(context, location) {
  3256. Uniform.call(this, context, location);
  3257. this.current = [0, 0, 0];
  3258. }
  3259. if (Uniform) Uniform3f.__proto__ = Uniform;
  3260. Uniform3f.prototype = Object.create(Uniform && Uniform.prototype);
  3261. Uniform3f.prototype.constructor = Uniform3f;
  3262. Uniform3f.prototype.set = function set(v) {
  3263. if (v[0] !== this.current[0] || v[1] !== this.current[1] || v[2] !== this.current[2]) {
  3264. this.current = v;
  3265. this.gl.uniform3f(this.location, v[0], v[1], v[2]);
  3266. }
  3267. };
  3268. return Uniform3f;
  3269. }(Uniform));
  3270. UniformType.Uniform4f = /*@__PURE__*/(function (Uniform) {
  3271. function Uniform4f(context, location) {
  3272. Uniform.call(this, context, location);
  3273. this.current = [0, 0, 0, 0];
  3274. }
  3275. if (Uniform) Uniform4f.__proto__ = Uniform;
  3276. Uniform4f.prototype = Object.create(Uniform && Uniform.prototype);
  3277. Uniform4f.prototype.constructor = Uniform4f;
  3278. Uniform4f.prototype.set = function set(v) {
  3279. if (v[0] !== this.current[0] || v[1] !== this.current[1] ||
  3280. v[2] !== this.current[2] || v[3] !== this.current[3]) {
  3281. this.current = v;
  3282. this.gl.uniform4f(this.location, v[0], v[1], v[2], v[3]);
  3283. }
  3284. };
  3285. return Uniform4f;
  3286. }(Uniform));
  3287. UniformType.UniformColor = /*@__PURE__*/(function (Uniform) {
  3288. function UniformColor(context, location) {
  3289. Uniform.call(this, context, location);
  3290. this.current = Color$1.transparent;
  3291. }
  3292. if (Uniform) UniformColor.__proto__ = Uniform;
  3293. UniformColor.prototype = Object.create(Uniform && Uniform.prototype);
  3294. UniformColor.prototype.constructor = UniformColor;
  3295. UniformColor.prototype.set = function set(v) {
  3296. if (v.r !== this.current.r || v.g !== this.current.g ||
  3297. v.b !== this.current.b || v.a !== this.current.a) {
  3298. this.current = v;
  3299. this.gl.uniform4f(this.location, v.r, v.g, v.b, v.a);
  3300. }
  3301. };
  3302. return UniformColor;
  3303. }(Uniform));
  3304. var emptyMat4 = new Float32Array(16);
  3305. UniformType.UniformMatrix4f = /*@__PURE__*/(function (Uniform) {
  3306. function UniformMatrix4f(context, location) {
  3307. Uniform.call(this, context, location);
  3308. this.current = emptyMat4;
  3309. }
  3310. if (Uniform) UniformMatrix4f.__proto__ = Uniform;
  3311. UniformMatrix4f.prototype = Object.create(Uniform && Uniform.prototype);
  3312. UniformMatrix4f.prototype.constructor = UniformMatrix4f;
  3313. UniformMatrix4f.prototype.set = function set(v) {
  3314. this.gl.uniformMatrix4fv(this.location, false, v);
  3315. // The vast majority of matrix comparisons that will trip this set
  3316. // happen at i=12 or i=0, so we check those first to avoid lots of
  3317. // unnecessary iteration:
  3318. // if (v[12] !== this.current[12] || v[0] !== this.current[0]) {
  3319. // this.current = v;
  3320. // this.gl.uniformMatrix4fv(this.location, false, v);
  3321. // return;
  3322. // }
  3323. // for (var i = 1; i < 16; i++) {
  3324. // if (v[i] !== this.current[i]) {
  3325. // this.current = v;
  3326. // this.gl.uniformMatrix4fv(this.location, false, v);
  3327. // break;
  3328. // }
  3329. // }
  3330. };
  3331. return UniformMatrix4f;
  3332. }(Uniform));
  3333. /**
  3334. * Implementation of the StructArray layout:
  3335. * [0]: Uint16[8]
  3336. *
  3337. * @private
  3338. */
  3339. var StructArrayLayout8ui16 = /*@__PURE__*/(function (StructArray) {
  3340. function StructArrayLayout8ui16() {
  3341. StructArray.apply(this, arguments);
  3342. }
  3343. if (StructArray) StructArrayLayout8ui16.__proto__ = StructArray;
  3344. StructArrayLayout8ui16.prototype = Object.create(StructArray && StructArray.prototype);
  3345. StructArrayLayout8ui16.prototype.constructor = StructArrayLayout8ui16;
  3346. StructArrayLayout8ui16.prototype._refreshViews = function _refreshViews() {
  3347. this.uint8 = new Uint8Array(this.arrayBuffer);
  3348. this.uint16 = new Uint16Array(this.arrayBuffer);
  3349. };
  3350. StructArrayLayout8ui16.prototype.emplaceBack = function emplaceBack(v0, v1, v2, v3, v4, v5, v6, v7) {
  3351. var i = this.length;
  3352. this.resize(i + 1);
  3353. return this.emplace(i, v0, v1, v2, v3, v4, v5, v6, v7);
  3354. };
  3355. StructArrayLayout8ui16.prototype.emplace = function emplace(i, v0, v1, v2, v3, v4, v5, v6, v7) {
  3356. var o2 = i * 8;
  3357. this.uint16[o2 + 0] = v0;
  3358. this.uint16[o2 + 1] = v1;
  3359. this.uint16[o2 + 2] = v2;
  3360. this.uint16[o2 + 3] = v3;
  3361. this.uint16[o2 + 4] = v4;
  3362. this.uint16[o2 + 5] = v5;
  3363. this.uint16[o2 + 6] = v6;
  3364. this.uint16[o2 + 7] = v7;
  3365. return i;
  3366. };
  3367. return StructArrayLayout8ui16;
  3368. }(StructArray));
  3369. StructArrayLayout8ui16.prototype.bytesPerElement = 16;
  3370. WebWorkerTransfer.register('StructArrayLayout8ui16', StructArrayLayout8ui16);
  3371. /**
  3372. * Implementation of the StructArray layout:
  3373. * [0]: Float32[2]
  3374. *
  3375. * @private
  3376. */
  3377. var StructArrayLayout2f8 = /*@__PURE__*/(function (StructArray) {
  3378. function StructArrayLayout2f8() {
  3379. StructArray.apply(this, arguments);
  3380. }
  3381. if (StructArray) StructArrayLayout2f8.__proto__ = StructArray;
  3382. StructArrayLayout2f8.prototype = Object.create(StructArray && StructArray.prototype);
  3383. StructArrayLayout2f8.prototype.constructor = StructArrayLayout2f8;
  3384. StructArrayLayout2f8.prototype._refreshViews = function _refreshViews() {
  3385. this.uint8 = new Uint8Array(this.arrayBuffer);
  3386. this.float32 = new Float32Array(this.arrayBuffer);
  3387. };
  3388. StructArrayLayout2f8.prototype.emplaceBack = function emplaceBack(v0, v1) {
  3389. var i = this.length;
  3390. this.resize(i + 1);
  3391. return this.emplace(i, v0, v1);
  3392. };
  3393. StructArrayLayout2f8.prototype.emplace = function emplace(i, v0, v1) {
  3394. var o4 = i * 2;
  3395. this.float32[o4 + 0] = v0;
  3396. this.float32[o4 + 1] = v1;
  3397. return i;
  3398. };
  3399. return StructArrayLayout2f8;
  3400. }(StructArray));
  3401. StructArrayLayout2f8.prototype.bytesPerElement = 8;
  3402. WebWorkerTransfer.register('StructArrayLayout2f8', StructArrayLayout2f8);
  3403. /**
  3404. * Implementation of the StructArray layout:
  3405. * [0]: Float32[4]
  3406. *
  3407. * @private
  3408. */
  3409. var StructArrayLayout4f16 = /*@__PURE__*/(function (StructArray) {
  3410. function StructArrayLayout4f16() {
  3411. StructArray.apply(this, arguments);
  3412. }
  3413. if (StructArray) StructArrayLayout4f16.__proto__ = StructArray;
  3414. StructArrayLayout4f16.prototype = Object.create(StructArray && StructArray.prototype);
  3415. StructArrayLayout4f16.prototype.constructor = StructArrayLayout4f16;
  3416. StructArrayLayout4f16.prototype._refreshViews = function _refreshViews() {
  3417. this.uint8 = new Uint8Array(this.arrayBuffer);
  3418. this.float32 = new Float32Array(this.arrayBuffer);
  3419. };
  3420. StructArrayLayout4f16.prototype.emplaceBack = function emplaceBack(v0, v1, v2, v3) {
  3421. var i = this.length;
  3422. this.resize(i + 1);
  3423. return this.emplace(i, v0, v1, v2, v3);
  3424. };
  3425. StructArrayLayout4f16.prototype.emplace = function emplace(i, v0, v1, v2, v3) {
  3426. var o4 = i * 4;
  3427. this.float32[o4 + 0] = v0;
  3428. this.float32[o4 + 1] = v1;
  3429. this.float32[o4 + 2] = v2;
  3430. this.float32[o4 + 3] = v3;
  3431. return i;
  3432. };
  3433. return StructArrayLayout4f16;
  3434. }(StructArray));
  3435. StructArrayLayout4f16.prototype.bytesPerElement = 16;
  3436. WebWorkerTransfer.register('StructArrayLayout4f16', StructArrayLayout4f16);
  3437. /**
  3438. * Implementation of the StructArray layout:
  3439. * [0]: Float32[1]
  3440. *
  3441. * @private
  3442. */
  3443. var StructArrayLayout1f4 = /*@__PURE__*/(function (StructArray) {
  3444. function StructArrayLayout1f4() {
  3445. StructArray.apply(this, arguments);
  3446. }
  3447. if (StructArray) StructArrayLayout1f4.__proto__ = StructArray;
  3448. StructArrayLayout1f4.prototype = Object.create(StructArray && StructArray.prototype);
  3449. StructArrayLayout1f4.prototype.constructor = StructArrayLayout1f4;
  3450. StructArrayLayout1f4.prototype._refreshViews = function _refreshViews() {
  3451. this.uint8 = new Uint8Array(this.arrayBuffer);
  3452. this.float32 = new Float32Array(this.arrayBuffer);
  3453. };
  3454. StructArrayLayout1f4.prototype.emplaceBack = function emplaceBack(v0) {
  3455. var i = this.length;
  3456. this.resize(i + 1);
  3457. return this.emplace(i, v0);
  3458. };
  3459. StructArrayLayout1f4.prototype.emplace = function emplace(i, v0) {
  3460. var o4 = i * 1;
  3461. this.float32[o4 + 0] = v0;
  3462. return i;
  3463. };
  3464. return StructArrayLayout1f4;
  3465. }(StructArray));
  3466. StructArrayLayout1f4.prototype.bytesPerElement = 4;
  3467. WebWorkerTransfer.register('StructArrayLayout1f4', StructArrayLayout1f4);
  3468. function clamp$1(n, min, max) {
  3469. return Math.min(max, Math.max(min, n));
  3470. }
  3471. function packUint8ToFloat(a, b) {
  3472. // coerce a and b to 8-bit ints
  3473. a = clamp$1(Math.floor(a), 0, 255);
  3474. b = clamp$1(Math.floor(b), 0, 255);
  3475. return 256 * a + b;
  3476. }
  3477. function packColor(color) {
  3478. return [
  3479. packUint8ToFloat(255 * color.r, 255 * color.g),
  3480. packUint8ToFloat(255 * color.b, 255 * color.a)
  3481. ];
  3482. }
  3483. var ConstantBinder = function ConstantBinder(value, names, type) {
  3484. this.value = value;
  3485. this.names = names;
  3486. this.uniformNames = this.names.map(function (name) {
  3487. return ("u_" + name);
  3488. });
  3489. this.type = type;
  3490. this.maxValue = -Infinity;
  3491. };
  3492. ConstantBinder.prototype.defines = function defines() {
  3493. return this.names.map(function (name) {
  3494. return ("#define HAS_UNIFORM_u_" + name);
  3495. });
  3496. };
  3497. ConstantBinder.prototype.setConstantPatternPositions = function setConstantPatternPositions() {
  3498. };
  3499. ConstantBinder.prototype.populatePaintArray = function populatePaintArray() {
  3500. };
  3501. ConstantBinder.prototype.updatePaintArray = function updatePaintArray() {
  3502. };
  3503. ConstantBinder.prototype.upload = function upload() {
  3504. };
  3505. ConstantBinder.prototype.destroy = function destroy() {
  3506. };
  3507. ConstantBinder.prototype.setUniforms = function setUniforms(context, uniform, globals, currentValue) {
  3508. uniform.set(currentValue.constantOr(this.value));
  3509. };
  3510. ConstantBinder.prototype.getBinding = function getBinding(context, location) {
  3511. return (this.type === 'color') ?
  3512. new UniformType.UniformColor(context, location) :
  3513. new UniformType.Uniform1f(context, location);
  3514. };
  3515. ConstantBinder.serialize = function serialize$1(binder) {
  3516. var value = binder.value;
  3517. var names = binder.names;
  3518. var type = binder.type;
  3519. return {value: WebWorkerTransfer.serialize(value), names: names, type: type};
  3520. };
  3521. ConstantBinder.deserialize = function deserialize$1(serialized) {
  3522. var value = serialized.value;
  3523. var names = serialized.names;
  3524. var type = serialized.type;
  3525. return new ConstantBinder(WebWorkerTransfer.deserialize(value), names, type);
  3526. };
  3527. var CrossFadedConstantBinder = function CrossFadedConstantBinder(value, names, type) {
  3528. this.value = value;
  3529. this.names = names;
  3530. this.uniformNames = this.names.map(function (name) {
  3531. return ("u_" + name);
  3532. });
  3533. this.type = type;
  3534. this.maxValue = -Infinity;
  3535. this.patternPositions = {patternTo: null, patternFrom: null};
  3536. };
  3537. CrossFadedConstantBinder.prototype.defines = function defines() {
  3538. return this.names.map(function (name) {
  3539. return ("#define HAS_UNIFORM_u_" + name);
  3540. });
  3541. };
  3542. CrossFadedConstantBinder.prototype.populatePaintArray = function populatePaintArray() {
  3543. };
  3544. CrossFadedConstantBinder.prototype.updatePaintArray = function updatePaintArray() {
  3545. };
  3546. CrossFadedConstantBinder.prototype.upload = function upload() {
  3547. };
  3548. CrossFadedConstantBinder.prototype.destroy = function destroy() {
  3549. };
  3550. CrossFadedConstantBinder.prototype.setConstantPatternPositions = function setConstantPatternPositions(posTo, posFrom) {
  3551. this.patternPositions.patternTo = posTo.tlbr;
  3552. this.patternPositions.patternFrom = posFrom.tlbr;
  3553. };
  3554. CrossFadedConstantBinder.prototype.setUniforms = function setUniforms(context, uniform, globals, currentValue, uniformName) {
  3555. var pos = this.patternPositions;
  3556. if (uniformName === "u_pattern_to" && pos.patternTo) {
  3557. uniform.set(pos.patternTo);
  3558. }
  3559. if (uniformName === "u_pattern_from" && pos.patternFrom) {
  3560. uniform.set(pos.patternFrom);
  3561. }
  3562. };
  3563. CrossFadedConstantBinder.prototype.getBinding = function getBinding(context, location) {
  3564. return new UniformType.Uniform4f(context, location);
  3565. };
  3566. var SourceExpressionBinder = function SourceExpressionBinder(expression, names, type, PaintVertexArray) {
  3567. this.expression = expression;
  3568. this.names = names;
  3569. this.type = type;
  3570. this.uniformNames = this.names.map(function (name) {
  3571. return ("a_" + name);
  3572. });
  3573. this.maxValue = -Infinity;
  3574. this.paintVertexAttributes = names.map(function (name) {
  3575. return ({
  3576. name: ("a_" + name),
  3577. type: 'Float32',
  3578. components: type === 'color' ? 2 : 1,
  3579. offset: 0
  3580. });
  3581. }
  3582. );
  3583. this.paintVertexArray = new PaintVertexArray();
  3584. };
  3585. SourceExpressionBinder.prototype.defines = function defines() {
  3586. return [];
  3587. };
  3588. SourceExpressionBinder.prototype.setConstantPatternPositions = function setConstantPatternPositions() {
  3589. };
  3590. SourceExpressionBinder.prototype.populatePaintArray = function populatePaintArray(newLength, feature, imagePositions, formattedSection) {
  3591. var paintArray = this.paintVertexArray;
  3592. var start = paintArray.length;
  3593. paintArray.reserve(newLength);
  3594. var value = this.expression.evaluate(new EvaluationParameters(0), feature, {}, [], formattedSection);
  3595. if (this.type === 'color') {
  3596. var color = packColor(value);
  3597. for (var i = start; i < newLength; i++) {
  3598. paintArray.emplaceBack(color[0], color[1]);
  3599. }
  3600. } else {
  3601. for (var i$1 = start; i$1 < newLength; i$1++) {
  3602. paintArray.emplaceBack(value);
  3603. }
  3604. this.maxValue = Math.max(this.maxValue, value);
  3605. }
  3606. };
  3607. SourceExpressionBinder.prototype.updatePaintArray = function updatePaintArray(start, end, feature, featureState) {
  3608. var paintArray = this.paintVertexArray;
  3609. var value = this.expression.evaluate({zoom: 0}, feature, featureState);
  3610. if (this.type === 'color') {
  3611. var color = packColor(value);
  3612. for (var i = start; i < end; i++) {
  3613. paintArray.emplace(i, color[0], color[1]);
  3614. }
  3615. } else {
  3616. for (var i$1 = start; i$1 < end; i$1++) {
  3617. paintArray.emplace(i$1, value);
  3618. }
  3619. this.maxValue = Math.max(this.maxValue, value);
  3620. }
  3621. };
  3622. SourceExpressionBinder.prototype.upload = function upload(context) {
  3623. if (this.paintVertexArray && this.paintVertexArray.arrayBuffer) {
  3624. if (this.paintVertexBuffer && this.paintVertexBuffer.buffer) {
  3625. this.paintVertexBuffer.updateData(this.paintVertexArray);
  3626. } else {
  3627. this.paintVertexBuffer = context.createVertexBuffer(this.paintVertexArray, this.paintVertexAttributes, this.expression.isStateDependent);
  3628. }
  3629. }
  3630. };
  3631. SourceExpressionBinder.prototype.destroy = function destroy() {
  3632. if (this.paintVertexBuffer) {
  3633. this.paintVertexBuffer.destroy();
  3634. }
  3635. };
  3636. SourceExpressionBinder.prototype.setUniforms = function setUniforms(context, uniform) {
  3637. uniform.set(0);
  3638. };
  3639. SourceExpressionBinder.prototype.getBinding = function getBinding(context, location) {
  3640. return new UniformType.Uniform1f(context, location);
  3641. };
  3642. var CompositeExpressionBinder = function CompositeExpressionBinder(expression, names, type, useIntegerZoom, zoom, layout) {
  3643. this.expression = expression;
  3644. this.names = names;
  3645. this.uniformNames = this.names.map(function (name) {
  3646. return ("u_" + name + "_t");
  3647. });
  3648. this.type = type;
  3649. this.useIntegerZoom = useIntegerZoom;
  3650. this.zoom = zoom;
  3651. this.maxValue = -Infinity;
  3652. var PaintVertexArray = layout;
  3653. this.paintVertexAttributes = names.map(function (name) {
  3654. return {
  3655. name: ("a_" + name),
  3656. type: 'Float32',
  3657. components: type === 'color' ? 4 : 2,
  3658. offset: 0
  3659. };
  3660. });
  3661. this.paintVertexArray = new PaintVertexArray();
  3662. };
  3663. CompositeExpressionBinder.prototype.defines = function defines() {
  3664. return [];
  3665. };
  3666. CompositeExpressionBinder.prototype.setConstantPatternPositions = function setConstantPatternPositions() {
  3667. };
  3668. CompositeExpressionBinder.prototype.populatePaintArray = function populatePaintArray(newLength, feature, imagePositions, formattedSection) {
  3669. var paintArray = this.paintVertexArray;
  3670. var start = paintArray.length;
  3671. paintArray.reserve(newLength);
  3672. var min = this.expression.evaluate(new EvaluationParameters(this.zoom), feature, {}, [], formattedSection);
  3673. var max = this.expression.evaluate(new EvaluationParameters(this.zoom + 1), feature, {}, [], formattedSection);
  3674. if (this.type === 'color') {
  3675. var minColor = packColor(min);
  3676. var maxColor = packColor(max);
  3677. for (var i = start; i < newLength; i++) {
  3678. paintArray.emplaceBack(minColor[0], minColor[1], maxColor[0], maxColor[1]);
  3679. }
  3680. } else {
  3681. for (var i$1 = start; i$1 < newLength; i$1++) {
  3682. paintArray.emplaceBack(min, max);
  3683. }
  3684. this.maxValue = Math.max(this.maxValue, min, max);
  3685. }
  3686. };
  3687. CompositeExpressionBinder.prototype.updatePaintArray = function updatePaintArray(start, end, feature, featureState) {
  3688. var paintArray = this.paintVertexArray;
  3689. var min = this.expression.evaluate({zoom: this.zoom}, feature, featureState);
  3690. var max = this.expression.evaluate({zoom: this.zoom + 1}, feature, featureState);
  3691. if (this.type === 'color') {
  3692. var minColor = packColor(min);
  3693. var maxColor = packColor(max);
  3694. for (var i = start; i < end; i++) {
  3695. paintArray.emplace(i, minColor[0], minColor[1], maxColor[0], maxColor[1]);
  3696. }
  3697. } else {
  3698. for (var i$1 = start; i$1 < end; i$1++) {
  3699. paintArray.emplace(i$1, min, max);
  3700. }
  3701. this.maxValue = Math.max(this.maxValue, min, max);
  3702. }
  3703. };
  3704. CompositeExpressionBinder.prototype.upload = function upload(context) {
  3705. if (this.paintVertexArray && this.paintVertexArray.arrayBuffer) {
  3706. if (this.paintVertexBuffer && this.paintVertexBuffer.buffer) {
  3707. this.paintVertexBuffer.updateData(this.paintVertexArray);
  3708. } else {
  3709. this.paintVertexBuffer = context.createVertexBuffer(this.paintVertexArray, this.paintVertexAttributes, this.expression.isStateDependent);
  3710. }
  3711. }
  3712. };
  3713. CompositeExpressionBinder.prototype.destroy = function destroy() {
  3714. if (this.paintVertexBuffer) {
  3715. this.paintVertexBuffer.destroy();
  3716. }
  3717. };
  3718. CompositeExpressionBinder.prototype.interpolationFactor = function interpolationFactor(currentZoom) {
  3719. if (this.useIntegerZoom) {
  3720. currentZoom = Math.floor(currentZoom);
  3721. }
  3722. return clamp$1(this.expression.interpolationFactor(currentZoom, this.zoom, this.zoom + 1), 0, 1);
  3723. };
  3724. CompositeExpressionBinder.prototype.setUniforms = function setUniforms(context, uniform, globals) {
  3725. uniform.set(this.interpolationFactor(globals.zoom));
  3726. };
  3727. CompositeExpressionBinder.prototype.getBinding = function getBinding(context, location) {
  3728. return new UniformType.Uniform1f(context, location);
  3729. };
  3730. var CrossFadedCompositeBinder = function CrossFadedCompositeBinder(expression, names, type, useIntegerZoom, zoom, PaintVertexArray, layerId) {
  3731. this.expression = expression;
  3732. this.names = names;
  3733. this.type = type;
  3734. this.uniformNames = this.names.map(function (name) {
  3735. return ("u_" + name + "_t");
  3736. });
  3737. this.useIntegerZoom = useIntegerZoom;
  3738. this.zoom = zoom;
  3739. this.maxValue = -Infinity;
  3740. this.layerId = layerId;
  3741. this.paintVertexAttributes = names.map(function (name) {
  3742. return ({
  3743. name: ("a_" + name),
  3744. type: 'Uint16',
  3745. components: 4,
  3746. offset: 0
  3747. });
  3748. }
  3749. );
  3750. this.zoomInPaintVertexArray = new PaintVertexArray();
  3751. this.zoomOutPaintVertexArray = new PaintVertexArray();
  3752. };
  3753. CrossFadedCompositeBinder.prototype.defines = function defines() {
  3754. return [];
  3755. };
  3756. CrossFadedCompositeBinder.prototype.setConstantPatternPositions = function setConstantPatternPositions() {
  3757. };
  3758. CrossFadedCompositeBinder.prototype.populatePaintArray = function populatePaintArray(length, feature, imagePositions) {
  3759. // We populate two paint arrays because, for cross-faded properties, we don't know which direction
  3760. // we're cross-fading to at layout time. In order to keep vertex attributes to a minimum and not pass
  3761. // unnecessary vertex data to the shaders, we determine which to upload at draw time.
  3762. var zoomInArray = this.zoomInPaintVertexArray;
  3763. var zoomOutArray = this.zoomOutPaintVertexArray;
  3764. var ref = this;
  3765. var layerId = ref.layerId;
  3766. var start = zoomInArray.length;
  3767. zoomInArray.reserve(length);
  3768. zoomOutArray.reserve(length);
  3769. if (imagePositions && feature.patterns && feature.patterns[layerId]) {
  3770. var ref$1 = feature.patterns[layerId];
  3771. var min = ref$1.min;
  3772. var mid = ref$1.mid;
  3773. var max = ref$1.max;
  3774. var imageMin = imagePositions[min];
  3775. var imageMid = imagePositions[mid];
  3776. var imageMax = imagePositions[max];
  3777. if (!imageMin || !imageMid || !imageMax) {
  3778. return;
  3779. }
  3780. for (var i = start; i < length; i++) {
  3781. zoomInArray.emplaceBack(
  3782. imageMid.tl[0], imageMid.tl[1], imageMid.br[0], imageMid.br[1],
  3783. imageMin.tl[0], imageMin.tl[1], imageMin.br[0], imageMin.br[1]
  3784. );
  3785. zoomOutArray.emplaceBack(
  3786. imageMid.tl[0], imageMid.tl[1], imageMid.br[0], imageMid.br[1],
  3787. imageMax.tl[0], imageMax.tl[1], imageMax.br[0], imageMax.br[1]
  3788. );
  3789. }
  3790. }
  3791. };
  3792. CrossFadedCompositeBinder.prototype.updatePaintArray = function updatePaintArray(start, end, feature, featureState, imagePositions) {
  3793. // We populate two paint arrays because, for cross-faded properties, we don't know which direction
  3794. // we're cross-fading to at layout time. In order to keep vertex attributes to a minimum and not pass
  3795. // unnecessary vertex data to the shaders, we determine which to upload at draw time.
  3796. var zoomInArray = this.zoomInPaintVertexArray;
  3797. var zoomOutArray = this.zoomOutPaintVertexArray;
  3798. var ref = this;
  3799. var layerId = ref.layerId;
  3800. if (imagePositions && feature.patterns && feature.patterns[layerId]) {
  3801. var ref$1 = feature.patterns[layerId];
  3802. var min = ref$1.min;
  3803. var mid = ref$1.mid;
  3804. var max = ref$1.max;
  3805. var imageMin = imagePositions[min];
  3806. var imageMid = imagePositions[mid];
  3807. var imageMax = imagePositions[max];
  3808. if (!imageMin || !imageMid || !imageMax) {
  3809. return;
  3810. }
  3811. for (var i = start; i < end; i++) {
  3812. zoomInArray.emplace(i,
  3813. imageMid.tl[0], imageMid.tl[1], imageMid.br[0], imageMid.br[1],
  3814. imageMin.tl[0], imageMin.tl[1], imageMin.br[0], imageMin.br[1]
  3815. );
  3816. zoomOutArray.emplace(i,
  3817. imageMid.tl[0], imageMid.tl[1], imageMid.br[0], imageMid.br[1],
  3818. imageMax.tl[0], imageMax.tl[1], imageMax.br[0], imageMax.br[1]
  3819. );
  3820. }
  3821. }
  3822. };
  3823. CrossFadedCompositeBinder.prototype.upload = function upload(context) {
  3824. if (this.zoomInPaintVertexArray && this.zoomInPaintVertexArray.arrayBuffer && this.zoomOutPaintVertexArray && this.zoomOutPaintVertexArray.arrayBuffer) {
  3825. this.zoomInPaintVertexBuffer = context.createVertexBuffer(this.zoomInPaintVertexArray, this.paintVertexAttributes, this.expression.isStateDependent);
  3826. this.zoomOutPaintVertexBuffer = context.createVertexBuffer(this.zoomOutPaintVertexArray, this.paintVertexAttributes, this.expression.isStateDependent);
  3827. }
  3828. };
  3829. CrossFadedCompositeBinder.prototype.destroy = function destroy() {
  3830. if (this.zoomOutPaintVertexBuffer) {
  3831. this.zoomOutPaintVertexBuffer.destroy();
  3832. }
  3833. if (this.zoomInPaintVertexBuffer) {
  3834. this.zoomInPaintVertexBuffer.destroy();
  3835. }
  3836. };
  3837. CrossFadedCompositeBinder.prototype.setUniforms = function setUniforms(context, uniform) {
  3838. uniform.set(0);
  3839. };
  3840. CrossFadedCompositeBinder.prototype.getBinding = function getBinding(context, location) {
  3841. return new Uniform1f(context, location);
  3842. };
  3843. /**
  3844. * ProgramConfiguration contains the logic for binding style layer properties and tile
  3845. * layer feature data into GL program uniforms and vertex attributes.
  3846. *
  3847. * Non-data-driven property values are bound to shader uniforms. Data-driven property
  3848. * values are bound to vertex attributes. In order to support a uniform GLSL syntax over
  3849. * both, [Mapbox GL Shaders](https://github.com/mapbox/mapbox-gl-shaders) defines a `#pragma`
  3850. * abstraction, which ProgramConfiguration is responsible for implementing. At runtime,
  3851. * it examines the attributes of a particular layer, combines this with fixed knowledge
  3852. * about how layers of the particular type are implemented, and determines which uniforms
  3853. * and vertex attributes will be required. It can then substitute the appropriate text
  3854. * into the shader source code, create and link a program, and bind the uniforms and
  3855. * vertex attributes in preparation for drawing.
  3856. *
  3857. * When a vector tile is parsed, this same configuration information is used to
  3858. * populate the attribute buffers needed for data-driven styling using the zoom
  3859. * level and feature property data.
  3860. *
  3861. * @private
  3862. */
  3863. var ProgramConfiguration = function ProgramConfiguration() {
  3864. this.binders = {};
  3865. this.cacheKey = '';
  3866. this._buffers = [];
  3867. };
  3868. ProgramConfiguration.createDynamic = function createDynamic(layer, zoom, filterProperties) {
  3869. var self = new ProgramConfiguration();
  3870. var keys = [];
  3871. for (var property in layer.paint._values) {
  3872. if (!filterProperties(property)) {
  3873. continue;
  3874. }
  3875. var value = layer.paint.get(property);
  3876. if (!(value instanceof PossiblyEvaluatedPropertyValue$1) || !Supports.supportsPropertyExpression(value.property.specification)) {
  3877. continue;
  3878. }
  3879. var names = paintAttributeNames(property, layer.type);
  3880. var type = value.property.specification.type;
  3881. var useIntegerZoom = value.property.useIntegerZoom;
  3882. var isCrossFaded = value.property.specification['property-type'] === 'cross-faded' ||
  3883. value.property.specification['property-type'] === 'cross-faded-data-driven';
  3884. if (isCrossFaded) {
  3885. if (value.value.kind === 'constant') {
  3886. self.binders[property] = new CrossFadedConstantBinder(value.value.value, names, type);
  3887. keys.push(("/u_" + property));
  3888. } else {
  3889. var StructArrayLayout = layoutType(property, type, 'source');
  3890. self.binders[property] = new CrossFadedCompositeBinder(value.value, names, type, useIntegerZoom, zoom, StructArrayLayout, layer.id);
  3891. keys.push(("/a_" + property));
  3892. }
  3893. } else if (value.value.kind === 'constant') {
  3894. self.binders[property] = new ConstantBinder(value.value.value, names, type);
  3895. keys.push(("/u_" + property));
  3896. } else if (value.value.kind === 'source') {
  3897. var StructArrayLayout$1 = layoutType(property, type, 'source');
  3898. self.binders[property] = new SourceExpressionBinder(value.value, names, type, StructArrayLayout$1);
  3899. keys.push(("/a_" + property));
  3900. } else {
  3901. var StructArrayLayout$2 = layoutType(property, type, 'composite');
  3902. self.binders[property] = new CompositeExpressionBinder(value.value, names, type, useIntegerZoom, zoom, StructArrayLayout$2);
  3903. keys.push(("/z_" + property));
  3904. }
  3905. }
  3906. self.cacheKey = keys.sort().join('');
  3907. return self;
  3908. };
  3909. ProgramConfiguration.prototype.populatePaintArrays = function populatePaintArrays(newLength, feature, index, imagePositions, formattedSection) {
  3910. for (var property in this.binders) {
  3911. var binder = this.binders[property];
  3912. binder.populatePaintArray(newLength, feature, imagePositions, formattedSection);
  3913. }
  3914. };
  3915. ProgramConfiguration.prototype.setConstantPatternPositions = function setConstantPatternPositions(posTo, posFrom) {
  3916. for (var property in this.binders) {
  3917. var binder = this.binders[property];
  3918. binder.setConstantPatternPositions(posTo, posFrom);
  3919. }
  3920. };
  3921. ProgramConfiguration.prototype.updatePaintArrays = function updatePaintArrays(featureStates, featureMap, vtLayer, layer, imagePositions) {
  3922. var dirty = false;
  3923. for (var id in featureStates) {
  3924. var positions = featureMap.getPositions(+id);
  3925. for (var i = 0, list = positions; i < list.length; i += 1) {
  3926. var pos = list[i];
  3927. var feature = vtLayer.feature(pos.index);
  3928. for (var property in this.binders) {
  3929. var binder = this.binders[property];
  3930. if (binder instanceof ConstantBinder || binder instanceof CrossFadedConstantBinder) {
  3931. continue;
  3932. }
  3933. if ((binder ).expression.isStateDependent === true) {
  3934. //AHM: Remove after https://github.com/mapbox/mapbox-gl-js/issues/6255
  3935. var value = layer.paint.get(property);
  3936. (binder ).expression = value.value;
  3937. binder.updatePaintArray(pos.start, pos.end, feature, featureStates[id], imagePositions);
  3938. dirty = true;
  3939. }
  3940. }
  3941. }
  3942. }
  3943. return dirty;
  3944. };
  3945. ProgramConfiguration.prototype.defines = function defines() {
  3946. var result = [];
  3947. for (var property in this.binders) {
  3948. result.push.apply(result, this.binders[property].defines());
  3949. }
  3950. return result;
  3951. };
  3952. ProgramConfiguration.prototype.getPaintVertexBuffers = function getPaintVertexBuffers() {
  3953. return this._buffers;
  3954. };
  3955. ProgramConfiguration.prototype.getUniforms = function getUniforms(context, locations) {
  3956. var uniforms = [];
  3957. for (var property in this.binders) {
  3958. var binder = this.binders[property];
  3959. for (var i = 0, list = binder.uniformNames; i < list.length; i += 1) {
  3960. var name = list[i];
  3961. if (locations[name]) {
  3962. var binding = binder.getBinding(context, locations[name]);
  3963. uniforms.push({name: name, property: property, binding: binding});
  3964. }
  3965. }
  3966. }
  3967. return uniforms;
  3968. };
  3969. ProgramConfiguration.prototype.setUniforms = function setUniforms(context, binderUniforms, properties, globals) {
  3970. // Uniform state bindings are owned by the Program, but we set them
  3971. // from within the ProgramConfiguraton's binder members.
  3972. for (var i = 0, list = binderUniforms; i < list.length; i += 1) {
  3973. var ref = list[i];
  3974. var name = ref.name;
  3975. var property = ref.property;
  3976. var binding = ref.binding;
  3977. this.binders[property].setUniforms(context, binding, globals, properties.get(property), name);
  3978. }
  3979. };
  3980. ProgramConfiguration.prototype.updatePatternPaintBuffers = function updatePatternPaintBuffers(crossfade) {
  3981. var buffers = [];
  3982. for (var property in this.binders) {
  3983. var binder = this.binders[property];
  3984. if (binder instanceof CrossFadedCompositeBinder) {
  3985. var patternVertexBuffer = crossfade.fromScale === 2 ? binder.zoomInPaintVertexBuffer : binder.zoomOutPaintVertexBuffer;
  3986. if (patternVertexBuffer) {
  3987. buffers.push(patternVertexBuffer);
  3988. }
  3989. } else if ((binder instanceof SourceExpressionBinder ||
  3990. binder instanceof CompositeExpressionBinder) &&
  3991. binder.paintVertexBuffer
  3992. ) {
  3993. buffers.push(binder.paintVertexBuffer);
  3994. }
  3995. }
  3996. this._buffers = buffers;
  3997. };
  3998. ProgramConfiguration.prototype.upload = function upload(context) {
  3999. for (var property in this.binders) {
  4000. this.binders[property].upload(context);
  4001. }
  4002. var buffers = [];
  4003. for (var property$1 in this.binders) {
  4004. var binder = this.binders[property$1];
  4005. if ((binder instanceof SourceExpressionBinder ||
  4006. binder instanceof CompositeExpressionBinder) &&
  4007. binder.paintVertexBuffer
  4008. ) {
  4009. buffers.push(binder.paintVertexBuffer);
  4010. }
  4011. }
  4012. this._buffers = buffers;
  4013. };
  4014. ProgramConfiguration.prototype.destroy = function destroy() {
  4015. for (var property in this.binders) {
  4016. this.binders[property].destroy();
  4017. }
  4018. };
  4019. function paintAttributeNames(property, type) {
  4020. var attributeNameExceptions = {
  4021. 'text-opacity': ['opacity'],
  4022. 'icon-opacity': ['opacity'],
  4023. 'text-color': ['fill_color'],
  4024. 'icon-color': ['fill_color'],
  4025. 'text-halo-color': ['halo_color'],
  4026. 'icon-halo-color': ['halo_color'],
  4027. 'text-halo-blur': ['halo_blur'],
  4028. 'icon-halo-blur': ['halo_blur'],
  4029. 'text-halo-width': ['halo_width'],
  4030. 'icon-halo-width': ['halo_width'],
  4031. 'line-gap-width': ['gapwidth'],
  4032. 'line-pattern': ['pattern_to', 'pattern_from'],
  4033. 'fill-pattern': ['pattern_to', 'pattern_from'],
  4034. 'fill-extrusion-pattern': ['pattern_to', 'pattern_from'],
  4035. };
  4036. return attributeNameExceptions[property] ||
  4037. [property.replace((type + "-"), '').replace(/-/g, '_')];
  4038. }
  4039. function getLayoutException(property) {
  4040. var propertyExceptions = {
  4041. 'line-pattern': {
  4042. 'source': StructArrayLayout8ui16,
  4043. 'composite': StructArrayLayout8ui16
  4044. },
  4045. 'fill-pattern': {
  4046. 'source': StructArrayLayout8ui16,
  4047. 'composite': StructArrayLayout8ui16
  4048. },
  4049. 'fill-extrusion-pattern': {
  4050. 'source': StructArrayLayout8ui16,
  4051. 'composite': StructArrayLayout8ui16
  4052. }
  4053. };
  4054. return propertyExceptions[property];
  4055. }
  4056. function layoutType(property, type, binderType) {
  4057. var defaultLayouts = {
  4058. 'color': {
  4059. 'source': StructArrayLayout2f8,
  4060. 'composite': StructArrayLayout4f16
  4061. },
  4062. 'number': {
  4063. 'source': StructArrayLayout1f4,
  4064. 'composite': StructArrayLayout2f8
  4065. }
  4066. };
  4067. var layoutException = getLayoutException(property);
  4068. return layoutException && layoutException[binderType] ||
  4069. defaultLayouts[type][binderType];
  4070. }
  4071. WebWorkerTransfer.register('ConstantBinder', ConstantBinder);
  4072. WebWorkerTransfer.register('CrossFadedConstantBinder', CrossFadedConstantBinder);
  4073. WebWorkerTransfer.register('SourceExpressionBinder', SourceExpressionBinder);
  4074. WebWorkerTransfer.register('CrossFadedCompositeBinder', CrossFadedCompositeBinder);
  4075. WebWorkerTransfer.register('CompositeExpressionBinder', CompositeExpressionBinder);
  4076. WebWorkerTransfer.register('ProgramConfiguration', ProgramConfiguration, {omit: ['_buffers']});
  4077. var ProgramConfigurationSet = function ProgramConfigurationSet(layoutAttributes, layers, zoom, filterProperties) {
  4078. if (filterProperties === void 0) filterProperties = function () {
  4079. return true;
  4080. };
  4081. this.programConfigurations = {};
  4082. for (var i = 0, list = layers; i < list.length; i += 1) {
  4083. var layer = list[i];
  4084. this.programConfigurations[layer.id] = ProgramConfiguration.createDynamic(layer, zoom, filterProperties);
  4085. this.programConfigurations[layer.id].layoutAttributes = layoutAttributes;
  4086. }
  4087. this.needsUpload = false;
  4088. this._featureMap = new FeaturePositionMap();
  4089. this._bufferOffset = 0;
  4090. };
  4091. ProgramConfigurationSet.prototype.populatePaintArrays = function populatePaintArrays(length, feature, index, imagePositions, formattedSection) {
  4092. for (var key in this.programConfigurations) {
  4093. this.programConfigurations[key].populatePaintArrays(length, feature, index, imagePositions, formattedSection);
  4094. }
  4095. if (feature.id !== undefined) {
  4096. this._featureMap.add(+feature.id, index, this._bufferOffset, length);
  4097. }
  4098. this._bufferOffset = length;
  4099. this.needsUpload = true;
  4100. };
  4101. ProgramConfigurationSet.prototype.updatePaintArrays = function updatePaintArrays(featureStates, vtLayer, layers, imagePositions) {
  4102. for (var i = 0, list = layers; i < list.length; i += 1) {
  4103. var layer = list[i];
  4104. this.needsUpload = this.programConfigurations[layer.id].updatePaintArrays(featureStates, this._featureMap, vtLayer, layer, imagePositions) || this.needsUpload;
  4105. }
  4106. };
  4107. ProgramConfigurationSet.prototype.get = function get(layerId) {
  4108. return this.programConfigurations[layerId];
  4109. };
  4110. ProgramConfigurationSet.prototype.upload = function upload(context) {
  4111. if (!this.needsUpload) {
  4112. return;
  4113. }
  4114. for (var layerId in this.programConfigurations) {
  4115. this.programConfigurations[layerId].upload(context);
  4116. }
  4117. this.needsUpload = false;
  4118. };
  4119. ProgramConfigurationSet.prototype.destroy = function destroy() {
  4120. for (var layerId in this.programConfigurations) {
  4121. this.programConfigurations[layerId].destroy();
  4122. }
  4123. };
  4124. WebWorkerTransfer.register('ProgramConfigurationSet', ProgramConfigurationSet);
  4125. function addPatternDependencies(type, layers, patternFeature, zoom, options) {
  4126. var patterns = options.patternDependencies;
  4127. for (var i = 0, list = layers; i < list.length; i += 1) {
  4128. var layer = list[i];
  4129. var patternProperty = layer.paint.get((type + "-pattern"));
  4130. var patternPropertyValue = patternProperty.value;
  4131. if (patternPropertyValue.kind !== "constant") {
  4132. var min = patternPropertyValue.evaluate({zoom: zoom - 1}, patternFeature, {}, options.availableImages);
  4133. var mid = patternPropertyValue.evaluate({zoom: zoom}, patternFeature, {}, options.availableImages);
  4134. var max = patternPropertyValue.evaluate({zoom: zoom + 1}, patternFeature, {}, options.availableImages);
  4135. min = min && min.name ? min.name : min;
  4136. mid = mid && mid.name ? mid.name : mid;
  4137. max = max && max.name ? max.name : max;
  4138. // add to patternDependencies
  4139. patterns[min] = true;
  4140. patterns[mid] = true;
  4141. patterns[max] = true;
  4142. // save for layout
  4143. patternFeature.patterns[layer.id] = {min: min, mid: mid, max: max};
  4144. }
  4145. }
  4146. return patternFeature;
  4147. }
  4148. var VectorTileFeatureTypes = ['Unknown', 'Point', 'LineString', 'Polygon'];
  4149. var lineLayoutAttributes = createLayout([
  4150. {name: 'a_pos_normal', components: 2, type: 'Int16'},
  4151. {name: 'a_data', components: 4, type: 'Uint8'}
  4152. ], 4);
  4153. var members$3 = lineLayoutAttributes.members;
  4154. // NOTE ON EXTRUDE SCALE:
  4155. // scale the extrusion vector so that the normal length is this value.
  4156. // contains the "texture" normals (-1..1). this is distinct from the extrude
  4157. // normals for line joins, because the x-value remains 0 for the texture
  4158. // normal array, while the extrude normal actually moves the vertex to create
  4159. // the acute/bevelled line join.
  4160. var EXTRUDE_SCALE = 63;
  4161. /*
  4162. * Sharp corners cause dashed lines to tilt because the distance along the line
  4163. * is the same at both the inner and outer corners. To improve the appearance of
  4164. * dashed lines we add extra points near sharp corners so that a smaller part
  4165. * of the line is tilted.
  4166. *
  4167. * COS_HALF_SHARP_CORNER controls how sharp a corner has to be for us to add an
  4168. * extra vertex. The default is 75 degrees.
  4169. *
  4170. * The newly created vertices are placed SHARP_CORNER_OFFSET pixels from the corner.
  4171. */
  4172. var COS_HALF_SHARP_CORNER = Math.cos(75 / 2 * (Math.PI / 180));
  4173. var SHARP_CORNER_OFFSET = 15;
  4174. // Angle per triangle for approximating round line joins.
  4175. var DEG_PER_TRIANGLE = 20;
  4176. // The number of bits that is used to store the line distance in the buffer.
  4177. var LINE_DISTANCE_BUFFER_BITS = 15;
  4178. // We don't have enough bits for the line distance as we'd like to have, so
  4179. // use this value to scale the line distance (in tile units) down to a smaller
  4180. // value. This lets us store longer distances while sacrificing precision.
  4181. var LINE_DISTANCE_SCALE = 1 / 2;
  4182. // The maximum line distance, in tile units, that fits in the buffer.
  4183. var MAX_LINE_DISTANCE = Math.pow(2, LINE_DISTANCE_BUFFER_BITS - 1) / LINE_DISTANCE_SCALE;
  4184. /**
  4185. * @private
  4186. */
  4187. var LineBucket = function LineBucket(options) {
  4188. this.zoom = options.zoom;
  4189. this.overscaling = options.overscaling;
  4190. this.layers = options.layers;
  4191. this.layerIds = this.layers.map(function (layer) {
  4192. return layer.id;
  4193. });
  4194. this.index = options.index;
  4195. this.hasPattern = false;
  4196. this.patternFeatures = [];
  4197. this.layoutVertexArray = new StructArrayLayout2i4ub8();
  4198. this.indexArray = new StructArrayLayout3ui6();
  4199. this.programConfigurations = new ProgramConfigurationSet(members$3, options.layers, options.zoom);
  4200. this.segments = new SegmentVector();
  4201. this.stateDependentLayerIds = this.layers.filter(function (l) {
  4202. return l.isStateDependent();
  4203. }).map(function (l) {
  4204. return l.id;
  4205. });
  4206. };
  4207. LineBucket.prototype.populate = function populate(features, options) {
  4208. //this.hasPattern = hasPattern('line', this.layers, options);
  4209. this.hasPattern = false;
  4210. var lineSortKey = this.layers[0].layout.get('line-sort-key');
  4211. var bucketFeatures = [];
  4212. for (var i = 0, list = features; i < list.length; i += 1) {
  4213. var ref = list[i];
  4214. var feature = ref.feature;
  4215. var index = ref.index;
  4216. var sourceLayerIndex = ref.sourceLayerIndex;
  4217. if (!this.layers[0]._featureFilter(new EvaluationParameters$1(0), feature)) {
  4218. continue;
  4219. }
  4220. var geometry = loadGeometry(feature);
  4221. var sortKey = lineSortKey ?
  4222. lineSortKey.evaluate(feature, {}) :
  4223. undefined;
  4224. var bucketFeature = {
  4225. id: feature.id,
  4226. properties: feature.properties,
  4227. type: feature.type,
  4228. sourceLayerIndex: sourceLayerIndex,
  4229. index: index,
  4230. geometry: geometry,
  4231. patterns: {},
  4232. sortKey: sortKey
  4233. };
  4234. bucketFeatures.push(bucketFeature);
  4235. }
  4236. if (lineSortKey) {
  4237. bucketFeatures.sort(function (a, b) {
  4238. // a.sortKey is always a number when in use
  4239. return ((a.sortKey ) ) - ((b.sortKey ) );
  4240. });
  4241. }
  4242. for (var i$1 = 0, list$1 = bucketFeatures; i$1 < list$1.length; i$1 += 1) {
  4243. var bucketFeature$1 = list$1[i$1];
  4244. var ref$1 = bucketFeature$1;
  4245. var geometry$1 = ref$1.geometry;
  4246. var index$1 = ref$1.index;
  4247. var sourceLayerIndex$1 = ref$1.sourceLayerIndex;
  4248. if (this.hasPattern) {
  4249. var patternBucketFeature = addPatternDependencies('line', this.layers, bucketFeature$1, this.zoom, options);
  4250. // pattern features are added only once the pattern is loaded into the image atlas
  4251. // so are stored during populate until later updated with positions by tile worker in addFeatures
  4252. this.patternFeatures.push(patternBucketFeature);
  4253. } else {
  4254. this.addFeature(bucketFeature$1, geometry$1, index$1, {});
  4255. }
  4256. var feature$1 = features[index$1].feature;
  4257. options.featureIndex.insert(feature$1, geometry$1, index$1, sourceLayerIndex$1, this.index);
  4258. }
  4259. };
  4260. LineBucket.prototype.update = function update(states, vtLayer, imagePositions) {
  4261. if (!this.stateDependentLayers.length) {
  4262. return;
  4263. }
  4264. this.programConfigurations.updatePaintArrays(states, vtLayer, this.stateDependentLayers, imagePositions);
  4265. };
  4266. LineBucket.prototype.addFeatures = function addFeatures(options, imagePositions) {
  4267. for (var i = 0, list = this.patternFeatures; i < list.length; i += 1) {
  4268. var feature = list[i];
  4269. this.addFeature(feature, feature.geometry, feature.index, imagePositions);
  4270. }
  4271. };
  4272. LineBucket.prototype.isEmpty = function isEmpty() {
  4273. return this.layoutVertexArray.length === 0;
  4274. };
  4275. LineBucket.prototype.uploadPending = function uploadPending() {
  4276. return !this.uploaded || this.programConfigurations.needsUpload;
  4277. };
  4278. LineBucket.prototype.upload = function upload(context) {
  4279. if (!this.uploaded) {
  4280. this.layoutVertexBuffer = context.createVertexBuffer(this.layoutVertexArray, members$3);
  4281. this.indexBuffer = context.createIndexBuffer(this.indexArray);
  4282. }
  4283. this.programConfigurations.upload(context);
  4284. this.uploaded = true;
  4285. };
  4286. LineBucket.prototype.destroy = function destroy() {
  4287. if (!this.layoutVertexBuffer) {
  4288. return;
  4289. }
  4290. this.layoutVertexBuffer.destroy();
  4291. this.indexBuffer.destroy();
  4292. this.programConfigurations.destroy();
  4293. this.segments.destroy();
  4294. };
  4295. LineBucket.prototype.clear = function clear() {
  4296. if (defined.defined(this.layoutVertexArray)) {
  4297. this.layoutVertexArray = null;
  4298. }
  4299. if (defined.defined(this.indexArray)) {
  4300. this.indexArray = null;
  4301. }
  4302. };
  4303. LineBucket.prototype.addFeature = function addFeature(feature, geometry, index, imagePositions) {
  4304. var layout = this.layers[0].layout;
  4305. var join = layout.get('line-join').evaluate(feature, {});
  4306. var cap = layout.get('line-cap');
  4307. var miterLimit = layout.get('line-miter-limit');
  4308. var roundLimit = layout.get('line-round-limit');
  4309. for (var i = 0, list = geometry; i < list.length; i += 1) {
  4310. var line = list[i];
  4311. this.addLine(line, feature, join, cap, miterLimit, roundLimit, index, imagePositions);
  4312. }
  4313. };
  4314. LineBucket.prototype.addLine = function addLine(vertices, feature, join, cap, miterLimit, roundLimit, index, imagePositions) {
  4315. this.distance = 0;
  4316. this.scaledDistance = 0;
  4317. this.totalDistance = 0;
  4318. if (!!feature.properties &&
  4319. feature.properties.hasOwnProperty('mapbox_clip_start') &&
  4320. feature.properties.hasOwnProperty('mapbox_clip_end')) {
  4321. this.clipStart = +feature.properties['mapbox_clip_start'];
  4322. this.clipEnd = +feature.properties['mapbox_clip_end'];
  4323. // Calculate the total distance, in tile units, of this tiled line feature
  4324. for (var i = 0; i < vertices.length - 1; i++) {
  4325. this.totalDistance += vertices[i].dist(vertices[i + 1]);
  4326. }
  4327. }
  4328. var isPolygon = VectorTileFeatureTypes[feature.type] === 'Polygon';
  4329. // If the line has duplicate vertices at the ends, adjust start/length to remove them.
  4330. var len = vertices.length;
  4331. while (len >= 2 && vertices[len - 1].equals(vertices[len - 2])) {
  4332. len--;
  4333. }
  4334. var first = 0;
  4335. while (first < len - 1 && vertices[first].equals(vertices[first + 1])) {
  4336. first++;
  4337. }
  4338. // Ignore invalid geometry.
  4339. if (len < (isPolygon ? 3 : 2)) {
  4340. return;
  4341. }
  4342. if (join === 'bevel') {
  4343. miterLimit = 1.05;
  4344. }
  4345. var sharpCornerOffset = this.overscaling <= 16 ?
  4346. SHARP_CORNER_OFFSET * EXTENT / (512 * this.overscaling) :
  4347. 0;
  4348. // we could be more precise, but it would only save a negligible amount of space
  4349. var segment = this.segments.prepareSegment(len * 10, this.layoutVertexArray, this.indexArray);
  4350. var currentVertex;
  4351. var prevVertex = ((undefined ) );
  4352. var nextVertex = ((undefined ) );
  4353. var prevNormal = ((undefined ) );
  4354. var nextNormal = ((undefined ) );
  4355. // the last two vertices added
  4356. this.e1 = this.e2 = -1;
  4357. if (isPolygon) {
  4358. currentVertex = vertices[len - 2];
  4359. nextNormal = vertices[first].sub(currentVertex)._unit()._perp();
  4360. }
  4361. for (var i$1 = first; i$1 < len; i$1++) {
  4362. nextVertex = isPolygon && i$1 === len - 1 ?
  4363. vertices[first + 1] : // if the line is closed, we treat the last vertex like the first
  4364. vertices[i$1 + 1]; // just the next vertex
  4365. // if two consecutive vertices exist, skip the current one
  4366. if (nextVertex && vertices[i$1].equals(nextVertex)) {
  4367. continue;
  4368. }
  4369. if (nextNormal) {
  4370. prevNormal = nextNormal;
  4371. }
  4372. if (currentVertex) {
  4373. prevVertex = currentVertex;
  4374. }
  4375. currentVertex = vertices[i$1];
  4376. // Calculate the normal towards the next vertex in this line. In case
  4377. // there is no next vertex, pretend that the line is continuing straight,
  4378. // meaning that we are just using the previous normal.
  4379. nextNormal = nextVertex ? nextVertex.sub(currentVertex)._unit()._perp() : prevNormal;
  4380. // If we still don't have a previous normal, this is the beginning of a
  4381. // non-closed line, so we're doing a straight "join".
  4382. prevNormal = prevNormal || nextNormal;
  4383. // Determine the normal of the join extrusion. It is the angle bisector
  4384. // of the segments between the previous line and the next line.
  4385. // In the case of 180° angles, the prev and next normals cancel each other out:
  4386. // prevNormal + nextNormal = (0, 0), its magnitude is 0, so the unit vector would be
  4387. // undefined. In that case, we're keeping the joinNormal at (0, 0), so that the cosHalfAngle
  4388. // below will also become 0 and miterLength will become Infinity.
  4389. var joinNormal = prevNormal.add(nextNormal);
  4390. if (joinNormal.x !== 0 || joinNormal.y !== 0) {
  4391. joinNormal._unit();
  4392. }
  4393. /* joinNormal prevNormal
  4394. * ↖ ↑
  4395. * .________. prevVertex
  4396. * |
  4397. * nextNormal ← | currentVertex
  4398. * |
  4399. * nextVertex !
  4400. *
  4401. */
  4402. // calculate cosines of the angle (and its half) using dot product
  4403. var cosAngle = prevNormal.x * nextNormal.x + prevNormal.y * nextNormal.y;
  4404. var cosHalfAngle = joinNormal.x * nextNormal.x + joinNormal.y * nextNormal.y;
  4405. // Calculate the length of the miter (the ratio of the miter to the width)
  4406. // as the inverse of cosine of the angle between next and join normals
  4407. var miterLength = cosHalfAngle !== 0 ? 1 / cosHalfAngle : Infinity;
  4408. // approximate angle from cosine
  4409. var approxAngle = 2 * Math.sqrt(2 - 2 * cosHalfAngle);
  4410. var isSharpCorner = cosHalfAngle < COS_HALF_SHARP_CORNER && prevVertex && nextVertex;
  4411. var lineTurnsLeft = prevNormal.x * nextNormal.y - prevNormal.y * nextNormal.x > 0;
  4412. if (isSharpCorner && i$1 > first) {
  4413. var prevSegmentLength = currentVertex.dist(prevVertex);
  4414. if (prevSegmentLength > 2 * sharpCornerOffset) {
  4415. var newPrevVertex = currentVertex.sub(currentVertex.sub(prevVertex)._mult(sharpCornerOffset / prevSegmentLength)._round());
  4416. this.updateDistance(prevVertex, newPrevVertex);
  4417. this.addCurrentVertex(newPrevVertex, prevNormal, 0, 0, segment);
  4418. prevVertex = newPrevVertex;
  4419. }
  4420. }
  4421. // The join if a middle vertex, otherwise the cap.
  4422. var middleVertex = prevVertex && nextVertex;
  4423. var currentJoin = middleVertex ? join : isPolygon ? 'butt' : cap;
  4424. if (middleVertex && currentJoin === 'round') {
  4425. if (miterLength < roundLimit) {
  4426. currentJoin = 'miter';
  4427. } else if (miterLength <= 2) {
  4428. currentJoin = 'fakeround';
  4429. }
  4430. }
  4431. if (currentJoin === 'miter' && miterLength > miterLimit) {
  4432. currentJoin = 'bevel';
  4433. }
  4434. if (currentJoin === 'bevel') {
  4435. // The maximum extrude length is 128 / 63 = 2 times the width of the line
  4436. // so if miterLength >= 2 we need to draw a different type of bevel here.
  4437. if (miterLength > 2) {
  4438. currentJoin = 'flipbevel';
  4439. }
  4440. // If the miterLength is really small and the line bevel wouldn't be visible,
  4441. // just draw a miter join to save a triangle.
  4442. if (miterLength < miterLimit) {
  4443. currentJoin = 'miter';
  4444. }
  4445. }
  4446. // Calculate how far along the line the currentVertex is
  4447. if (prevVertex) {
  4448. this.updateDistance(prevVertex, currentVertex);
  4449. }
  4450. if (currentJoin === 'miter') {
  4451. joinNormal._mult(miterLength);
  4452. this.addCurrentVertex(currentVertex, joinNormal, 0, 0, segment);
  4453. } else if (currentJoin === 'flipbevel') {
  4454. // miter is too big, flip the direction to make a beveled join
  4455. if (miterLength > 100) {
  4456. // Almost parallel lines
  4457. joinNormal = nextNormal.mult(-1);
  4458. } else {
  4459. var bevelLength = miterLength * prevNormal.add(nextNormal).mag() / prevNormal.sub(nextNormal).mag();
  4460. joinNormal._perp()._mult(bevelLength * (lineTurnsLeft ? -1 : 1));
  4461. }
  4462. this.addCurrentVertex(currentVertex, joinNormal, 0, 0, segment);
  4463. this.addCurrentVertex(currentVertex, joinNormal.mult(-1), 0, 0, segment);
  4464. } else if (currentJoin === 'bevel' || currentJoin === 'fakeround') {
  4465. var offset = -Math.sqrt(miterLength * miterLength - 1);
  4466. var offsetA = lineTurnsLeft ? offset : 0;
  4467. var offsetB = lineTurnsLeft ? 0 : offset;
  4468. // Close previous segment with a bevel
  4469. if (prevVertex) {
  4470. this.addCurrentVertex(currentVertex, prevNormal, offsetA, offsetB, segment);
  4471. }
  4472. if (currentJoin === 'fakeround') {
  4473. // The join angle is sharp enough that a round join would be visible.
  4474. // Bevel joins fill the gap between segments with a single pie slice triangle.
  4475. // Create a round join by adding multiple pie slices. The join isn't actually round, but
  4476. // it looks like it is at the sizes we render lines at.
  4477. // pick the number of triangles for approximating round join by based on the angle between normals
  4478. var n = Math.round((approxAngle * 180 / Math.PI) / DEG_PER_TRIANGLE);
  4479. for (var m = 1; m < n; m++) {
  4480. var t = m / n;
  4481. if (t !== 0.5) {
  4482. // approximate spherical interpolation https://observablehq.com/@mourner/approximating-geometric-slerp
  4483. var t2 = t - 0.5;
  4484. var A = 1.0904 + cosAngle * (-3.2452 + cosAngle * (3.55645 - cosAngle * 1.43519));
  4485. var B = 0.848013 + cosAngle * (-1.06021 + cosAngle * 0.215638);
  4486. t = t + t * t2 * (t - 1) * (A * t2 * t2 + B);
  4487. }
  4488. var extrude = nextNormal.sub(prevNormal)._mult(t)._add(prevNormal)._unit()._mult(lineTurnsLeft ? -1 : 1);
  4489. this.addHalfVertex(currentVertex, extrude.x, extrude.y, false, lineTurnsLeft, 0, segment);
  4490. }
  4491. }
  4492. if (nextVertex) {
  4493. // Start next segment
  4494. this.addCurrentVertex(currentVertex, nextNormal, -offsetA, -offsetB, segment);
  4495. }
  4496. } else if (currentJoin === 'butt') {
  4497. this.addCurrentVertex(currentVertex, joinNormal, 0, 0, segment); // butt cap
  4498. } else if (currentJoin === 'square') {
  4499. var offset$1 = prevVertex ? 1 : -1; // closing or starting square cap
  4500. this.addCurrentVertex(currentVertex, joinNormal, offset$1, offset$1, segment);
  4501. } else if (currentJoin === 'round') {
  4502. if (prevVertex) {
  4503. // Close previous segment with butt
  4504. this.addCurrentVertex(currentVertex, prevNormal, 0, 0, segment);
  4505. // Add round cap or linejoin at end of segment
  4506. this.addCurrentVertex(currentVertex, prevNormal, 1, 1, segment, true);
  4507. }
  4508. if (nextVertex) {
  4509. // Add round cap before first segment
  4510. this.addCurrentVertex(currentVertex, nextNormal, -1, -1, segment, true);
  4511. // Start next segment with a butt
  4512. this.addCurrentVertex(currentVertex, nextNormal, 0, 0, segment);
  4513. }
  4514. }
  4515. if (isSharpCorner && i$1 < len - 1) {
  4516. var nextSegmentLength = currentVertex.dist(nextVertex);
  4517. if (nextSegmentLength > 2 * sharpCornerOffset) {
  4518. var newCurrentVertex = currentVertex.add(nextVertex.sub(currentVertex)._mult(sharpCornerOffset / nextSegmentLength)._round());
  4519. this.updateDistance(currentVertex, newCurrentVertex);
  4520. this.addCurrentVertex(newCurrentVertex, nextNormal, 0, 0, segment);
  4521. currentVertex = newCurrentVertex;
  4522. }
  4523. }
  4524. }
  4525. this.programConfigurations.populatePaintArrays(this.layoutVertexArray.length, feature, index, imagePositions);
  4526. };
  4527. /**
  4528. * Add two vertices to the buffers.
  4529. *
  4530. * @param p the line vertex to add buffer vertices for
  4531. * @param normal vertex normal
  4532. * @param endLeft extrude to shift the left vertex along the line
  4533. * @param endRight extrude to shift the left vertex along the line
  4534. * @param segment the segment object to add the vertex to
  4535. * @param round whether this is a round cap
  4536. * @private
  4537. */
  4538. LineBucket.prototype.addCurrentVertex = function addCurrentVertex(p, normal, endLeft, endRight, segment, round) {
  4539. if (round === void 0) round = false;
  4540. // left and right extrude vectors, perpendicularly shifted by endLeft/endRight
  4541. var leftX = normal.x + normal.y * endLeft;
  4542. var leftY = normal.y - normal.x * endLeft;
  4543. var rightX = -normal.x + normal.y * endRight;
  4544. var rightY = -normal.y - normal.x * endRight;
  4545. this.addHalfVertex(p, leftX, leftY, round, false, endLeft, segment);
  4546. this.addHalfVertex(p, rightX, rightY, round, true, -endRight, segment);
  4547. // There is a maximum "distance along the line" that we can store in the buffers.
  4548. // When we get close to the distance, reset it to zero and add the vertex again with
  4549. // a distance of zero. The max distance is determined by the number of bits we allocate
  4550. // to `linesofar`.
  4551. if (this.distance > MAX_LINE_DISTANCE / 2 && this.totalDistance === 0) {
  4552. this.distance = 0;
  4553. this.addCurrentVertex(p, normal, endLeft, endRight, segment, round);
  4554. }
  4555. };
  4556. LineBucket.prototype.addHalfVertex = function addHalfVertex(ref, extrudeX, extrudeY, round, up, dir, segment) {
  4557. var x = ref.x;
  4558. var y = ref.y;
  4559. // scale down so that we can store longer distances while sacrificing precision.
  4560. var linesofar = this.scaledDistance * LINE_DISTANCE_SCALE;
  4561. this.layoutVertexArray.emplaceBack(
  4562. // a_pos_normal
  4563. // Encode round/up the least significant bits
  4564. (x << 1) + (round ? 1 : 0),
  4565. (y << 1) + (up ? 1 : 0),
  4566. // a_data
  4567. // add 128 to store a byte in an unsigned byte
  4568. Math.round(EXTRUDE_SCALE * extrudeX) + 128,
  4569. Math.round(EXTRUDE_SCALE * extrudeY) + 128,
  4570. // Encode the -1/0/1 direction value into the first two bits of .z of a_data.
  4571. // Combine it with the lower 6 bits of `linesofar` (shifted by 2 bites to make
  4572. // room for the direction value). The upper 8 bits of `linesofar` are placed in
  4573. // the `w` component.
  4574. ((dir === 0 ? 0 : (dir < 0 ? -1 : 1)) + 1) | ((linesofar & 0x3F) << 2),
  4575. linesofar >> 6);
  4576. var e = segment.vertexLength++;
  4577. if (this.e1 >= 0 && this.e2 >= 0) {
  4578. this.indexArray.emplaceBack(this.e1, this.e2, e);
  4579. segment.primitiveLength++;
  4580. }
  4581. if (up) {
  4582. this.e2 = e;
  4583. } else {
  4584. this.e1 = e;
  4585. }
  4586. };
  4587. LineBucket.prototype.updateDistance = function updateDistance(prev, next) {
  4588. this.distance += prev.dist(next);
  4589. // Knowing the ratio of the full linestring covered by this tiled feature, as well
  4590. // as the total distance (in tile units) of this tiled feature, and the distance
  4591. // (in tile units) of the current vertex, we can determine the relative distance
  4592. // of this vertex along the full linestring feature and scale it to [0, 2^15)
  4593. this.scaledDistance = this.totalDistance > 0 ?
  4594. (this.clipStart + (this.clipEnd - this.clipStart) * this.distance / this.totalDistance) * (MAX_LINE_DISTANCE - 1) :
  4595. this.distance;
  4596. };
  4597. WebWorkerTransfer.register('LineBucket', LineBucket, {omit: ['layers', 'patternFeatures']});
  4598. function quickselect(arr, k, left, right, compare) {
  4599. quickselectStep(arr, k, left || 0, right || (arr.length - 1), compare || defaultCompare);
  4600. }
  4601. function quickselectStep(arr, k, left, right, compare) {
  4602. while (right > left) {
  4603. if (right - left > 600) {
  4604. var n = right - left + 1;
  4605. var m = k - left + 1;
  4606. var z = Math.log(n);
  4607. var s = 0.5 * Math.exp(2 * z / 3);
  4608. var sd = 0.5 * Math.sqrt(z * s * (n - s) / n) * (m - n / 2 < 0 ? -1 : 1);
  4609. var newLeft = Math.max(left, Math.floor(k - m * s / n + sd));
  4610. var newRight = Math.min(right, Math.floor(k + (n - m) * s / n + sd));
  4611. quickselectStep(arr, k, newLeft, newRight, compare);
  4612. }
  4613. var t = arr[k];
  4614. var i = left;
  4615. var j = right;
  4616. swap$1(arr, left, k);
  4617. if (compare(arr[right], t) > 0) swap$1(arr, left, right);
  4618. while (i < j) {
  4619. swap$1(arr, i, j);
  4620. i++;
  4621. j--;
  4622. while (compare(arr[i], t) < 0) i++;
  4623. while (compare(arr[j], t) > 0) j--;
  4624. }
  4625. if (compare(arr[left], t) === 0) swap$1(arr, left, j);
  4626. else {
  4627. j++;
  4628. swap$1(arr, j, right);
  4629. }
  4630. if (j <= k) left = j + 1;
  4631. if (k <= j) right = j - 1;
  4632. }
  4633. }
  4634. function swap$1(arr, i, j) {
  4635. var tmp = arr[i];
  4636. arr[i] = arr[j];
  4637. arr[j] = tmp;
  4638. }
  4639. function defaultCompare(a, b) {
  4640. return a < b ? -1 : a > b ? 1 : 0;
  4641. }
  4642. /**
  4643. * Returns the signed area for the polygon ring. Postive areas are exterior rings and
  4644. * have a clockwise winding. Negative areas are interior rings and have a counter clockwise
  4645. * ordering.
  4646. *
  4647. * @private
  4648. * @param ring Exterior or interior ring
  4649. */
  4650. function calculateSignedArea(ring) {
  4651. var sum = 0;
  4652. for (var i = 0, len = ring.length, j = len - 1, p1 = (void 0), p2 = (void 0); i < len; j = i++) {
  4653. p1 = ring[i];
  4654. p2 = ring[j];
  4655. sum += (p2.x - p1.x) * (p1.y + p2.y);
  4656. }
  4657. return sum;
  4658. }
  4659. // classifies an array of rings into polygons with outer rings and holes
  4660. function classifyRings(rings, maxRings) {
  4661. var len = rings.length;
  4662. if (len <= 1) {
  4663. return [rings];
  4664. }
  4665. var polygons = [];
  4666. var polygon,
  4667. ccw;
  4668. for (var i = 0; i < len; i++) {
  4669. var area = calculateSignedArea(rings[i]);
  4670. if (area === 0) {
  4671. continue;
  4672. }
  4673. (rings[i] ).area = Math.abs(area);
  4674. if (ccw === undefined) {
  4675. ccw = area < 0;
  4676. }
  4677. if (ccw === area < 0) {
  4678. if (polygon) {
  4679. polygons.push(polygon);
  4680. }
  4681. polygon = [rings[i]];
  4682. } else {
  4683. (polygon ).push(rings[i]);
  4684. }
  4685. }
  4686. if (polygon) {
  4687. polygons.push(polygon);
  4688. }
  4689. // Earcut performance degrades with the # of rings in a polygon. For this
  4690. // reason, we limit strip out all but the `maxRings` largest rings.
  4691. if (maxRings > 1) {
  4692. for (var j = 0; j < polygons.length; j++) {
  4693. if (polygons[j].length <= maxRings) {
  4694. continue;
  4695. }
  4696. quickselect(polygons[j], maxRings, 1, polygons[j].length - 1, compareAreas);
  4697. polygons[j] = polygons[j].slice(0, maxRings);
  4698. }
  4699. }
  4700. return polygons;
  4701. }
  4702. function compareAreas(a, b) {
  4703. return b.area - a.area;
  4704. }
  4705. var StructArrayLayout2i4 = /*@__PURE__*/(function (StructArray) {
  4706. function StructArrayLayout2i4() {
  4707. StructArray.apply(this, arguments);
  4708. }
  4709. if (StructArray) StructArrayLayout2i4.__proto__ = StructArray;
  4710. StructArrayLayout2i4.prototype = Object.create(StructArray && StructArray.prototype);
  4711. StructArrayLayout2i4.prototype.constructor = StructArrayLayout2i4;
  4712. StructArrayLayout2i4.prototype._refreshViews = function _refreshViews() {
  4713. this.uint8 = new Uint8Array(this.arrayBuffer);
  4714. this.int16 = new Int16Array(this.arrayBuffer);
  4715. };
  4716. StructArrayLayout2i4.prototype.emplaceBack = function emplaceBack(v0, v1) {
  4717. var i = this.length;
  4718. this.resize(i + 1);
  4719. return this.emplace(i, v0, v1);
  4720. };
  4721. StructArrayLayout2i4.prototype.emplace = function emplace(i, v0, v1) {
  4722. var o2 = i * 2;
  4723. this.int16[o2 + 0] = v0;
  4724. this.int16[o2 + 1] = v1;
  4725. return i;
  4726. };
  4727. return StructArrayLayout2i4;
  4728. }(StructArray));
  4729. StructArrayLayout2i4.prototype.bytesPerElement = 4;
  4730. WebWorkerTransfer.register('StructArrayLayout2i4', StructArrayLayout2i4);
  4731. var StructArrayLayout2ui4 = /*@__PURE__*/(function (StructArray) {
  4732. function StructArrayLayout2ui4() {
  4733. StructArray.apply(this, arguments);
  4734. }
  4735. if (StructArray) StructArrayLayout2ui4.__proto__ = StructArray;
  4736. StructArrayLayout2ui4.prototype = Object.create(StructArray && StructArray.prototype);
  4737. StructArrayLayout2ui4.prototype.constructor = StructArrayLayout2ui4;
  4738. StructArrayLayout2ui4.prototype._refreshViews = function _refreshViews() {
  4739. this.uint8 = new Uint8Array(this.arrayBuffer);
  4740. this.uint16 = new Uint16Array(this.arrayBuffer);
  4741. };
  4742. StructArrayLayout2ui4.prototype.emplaceBack = function emplaceBack(v0, v1) {
  4743. var i = this.length;
  4744. this.resize(i + 1);
  4745. return this.emplace(i, v0, v1);
  4746. };
  4747. StructArrayLayout2ui4.prototype.emplace = function emplace(i, v0, v1) {
  4748. var o2 = i * 2;
  4749. this.uint16[o2 + 0] = v0;
  4750. this.uint16[o2 + 1] = v1;
  4751. return i;
  4752. };
  4753. return StructArrayLayout2ui4;
  4754. }(StructArray));
  4755. StructArrayLayout2ui4.prototype.bytesPerElement = 4;
  4756. WebWorkerTransfer.register('StructArrayLayout2ui4', StructArrayLayout2ui4);
  4757. function hasPattern(type, layers, options) {
  4758. var patterns = options.patternDependencies;
  4759. var hasPattern = false;
  4760. for (var i = 0, list = layers; i < list.length; i += 1) {
  4761. var layer = list[i];
  4762. var patternProperty = layer.paint.get((type + "-pattern"));
  4763. if (!patternProperty.isConstant()) {
  4764. hasPattern = true;
  4765. }
  4766. var constantPattern = patternProperty.constantOr(null);
  4767. if (constantPattern) {
  4768. hasPattern = true;
  4769. patterns[constantPattern.to] = true;
  4770. patterns[constantPattern.from] = true;
  4771. }
  4772. }
  4773. return hasPattern;
  4774. }
  4775. // Copyright 2010 The Emscripten Authors. All rights reserved.
  4776. // Emscripten is available under two separate licenses, the MIT license and the
  4777. // University of Illinois/NCSA Open Source License. Both these licenses can be
  4778. // found in the LICENSE file.
  4779. // The Module object: Our interface to the outside world. We import
  4780. // and export values on it. There are various ways Module can be used:
  4781. // 1. Not defined. We create it here
  4782. // 2. A function parameter, function(Module) { ..generated code.. }
  4783. // 3. pre-run appended it, var Module = {}; ..generated code..
  4784. // 4. External script tag defines var Module.
  4785. // We need to check if Module already exists (e.g. case 3 above).
  4786. // Substitution will be replaced with actual code on later stage of the build,
  4787. // this way Closure Compiler will not mangle it (e.g. case 4. above).
  4788. // Note that if you want to run closure, and also to use Module
  4789. // after the generated code, you will need to define var Module = {};
  4790. // before the code. Then that object will be used in the code, and you
  4791. // can continue to use Module afterwards as well.
  4792. if (typeof WebAssembly !== 'undefined') {
  4793. var Module = typeof Module !== 'undefined' ? Module : {};
  4794. // --pre-jses are emitted after the Module integration code, so that they can
  4795. // refer to Module (if they choose; they can also define Module)
  4796. // {{PRE_JSES}}
  4797. // Sometimes an existing Module object exists with properties
  4798. // meant to overwrite the default module functionality. Here
  4799. // we collect those properties and reapply _after_ we configure
  4800. // the current environment's defaults to avoid having to be so
  4801. // defensive during initialization.
  4802. var moduleOverrides = {};
  4803. var key;
  4804. for (key in Module) {
  4805. if (Module.hasOwnProperty(key)) {
  4806. moduleOverrides[key] = Module[key];
  4807. }
  4808. }
  4809. Module['arguments'] = [];
  4810. Module['thisProgram'] = './this.program';
  4811. Module['quit'] = function(status, toThrow) {
  4812. throw toThrow;
  4813. };
  4814. Module['preRun'] = [];
  4815. Module['postRun'] = [];
  4816. // Determine the runtime environment we are in. You can customize this by
  4817. // setting the ENVIRONMENT setting at compile time (see settings.js).
  4818. var ENVIRONMENT_IS_WEB = false;
  4819. var ENVIRONMENT_IS_WORKER = false;
  4820. var ENVIRONMENT_IS_NODE = false;
  4821. var ENVIRONMENT_HAS_NODE = false;
  4822. var ENVIRONMENT_IS_SHELL = false;
  4823. ENVIRONMENT_IS_WEB = typeof window === 'object';
  4824. ENVIRONMENT_IS_WORKER = typeof importScripts === 'function';
  4825. // A web environment like Electron.js can have Node enabled, so we must
  4826. // distinguish between Node-enabled environments and Node environments per se.
  4827. // This will allow the former to do things like mount NODEFS.
  4828. ENVIRONMENT_HAS_NODE = typeof process === 'object' && typeof require === 'function';
  4829. ENVIRONMENT_IS_NODE = ENVIRONMENT_HAS_NODE && !ENVIRONMENT_IS_WEB && !ENVIRONMENT_IS_WORKER;
  4830. ENVIRONMENT_IS_SHELL = !ENVIRONMENT_IS_WEB && !ENVIRONMENT_IS_NODE && !ENVIRONMENT_IS_WORKER;
  4831. if (Module['ENVIRONMENT']) {
  4832. throw new Error('Module.ENVIRONMENT has been deprecated. To force the environment, use the ENVIRONMENT compile-time option (for example, -s ENVIRONMENT=web or -s ENVIRONMENT=node)');
  4833. }
  4834. // Three configurations we can be running in:
  4835. // 1) We could be the application main() thread running in the main JS UI thread. (ENVIRONMENT_IS_WORKER == false and ENVIRONMENT_IS_PTHREAD == false)
  4836. // 2) We could be the application main() thread proxied to worker. (with Emscripten -s PROXY_TO_WORKER=1) (ENVIRONMENT_IS_WORKER == true, ENVIRONMENT_IS_PTHREAD == false)
  4837. // 3) We could be an application pthread running in a worker. (ENVIRONMENT_IS_WORKER == true and ENVIRONMENT_IS_PTHREAD == true)
  4838. // `/` should be present at the end if `scriptDirectory` is not empty
  4839. var scriptDirectory = '';
  4840. function locateFile(path) {
  4841. if (Module['locateFile']) {
  4842. return Module['locateFile'](path, scriptDirectory);
  4843. } else {
  4844. return scriptDirectory + path;
  4845. }
  4846. }
  4847. if (ENVIRONMENT_IS_NODE) {
  4848. scriptDirectory = __dirname + '/';
  4849. // Expose functionality in the same simple way that the shells work
  4850. // Note that we pollute the global namespace here, otherwise we break in node
  4851. var nodeFS;
  4852. var nodePath;
  4853. Module['read'] = function shell_read(filename, binary) {
  4854. var ret;
  4855. if (!nodeFS) nodeFS = require('fs');
  4856. if (!nodePath) nodePath = require('path');
  4857. filename = nodePath['normalize'](filename);
  4858. ret = nodeFS['readFileSync'](filename);
  4859. return binary ? ret : ret.toString();
  4860. };
  4861. Module['readBinary'] = function readBinary(filename) {
  4862. var ret = Module['read'](filename, true);
  4863. if (!ret.buffer) {
  4864. ret = new Uint8Array(ret);
  4865. }
  4866. assert(ret.buffer);
  4867. return ret;
  4868. };
  4869. if (process['argv'].length > 1) {
  4870. Module['thisProgram'] = process['argv'][1].replace(/\\/g, '/');
  4871. }
  4872. Module['arguments'] = process['argv'].slice(2);
  4873. if (typeof module !== 'undefined') {
  4874. module['exports'] = Module;
  4875. }
  4876. process['on']('uncaughtException', function(ex) {
  4877. // suppress ExitStatus exceptions from showing an error
  4878. if (!(ex instanceof ExitStatus)) {
  4879. throw ex;
  4880. }
  4881. });
  4882. // Currently node will swallow unhandled rejections, but this behavior is
  4883. // deprecated, and in the future it will exit with error status.
  4884. process['on']('unhandledRejection', abort);
  4885. Module['quit'] = function(status) {
  4886. process['exit'](status);
  4887. };
  4888. Module['inspect'] = function () { return '[Emscripten Module object]'; };
  4889. } else
  4890. if (ENVIRONMENT_IS_SHELL) {
  4891. if (typeof read != 'undefined') {
  4892. Module['read'] = function shell_read(f) {
  4893. return read(f);
  4894. };
  4895. }
  4896. Module['readBinary'] = function readBinary(f) {
  4897. var data;
  4898. if (typeof readbuffer === 'function') {
  4899. return new Uint8Array(readbuffer(f));
  4900. }
  4901. data = read(f, 'binary');
  4902. assert(typeof data === 'object');
  4903. return data;
  4904. };
  4905. if (typeof scriptArgs != 'undefined') {
  4906. Module['arguments'] = scriptArgs;
  4907. } else if (typeof arguments != 'undefined') {
  4908. Module['arguments'] = arguments;
  4909. }
  4910. if (typeof quit === 'function') {
  4911. Module['quit'] = function(status) {
  4912. quit(status);
  4913. };
  4914. }
  4915. } else
  4916. if (ENVIRONMENT_IS_WEB || ENVIRONMENT_IS_WORKER) {
  4917. if (ENVIRONMENT_IS_WORKER) { // Check worker, not web, since window could be polyfilled
  4918. scriptDirectory = self.location.href;
  4919. } else if (document.currentScript) { // web
  4920. scriptDirectory = document.currentScript.src;
  4921. }
  4922. // blob urls look like blob:http://site.com/etc/etc and we cannot infer anything from them.
  4923. // otherwise, slice off the final part of the url to find the script directory.
  4924. // if scriptDirectory does not contain a slash, lastIndexOf will return -1,
  4925. // and scriptDirectory will correctly be replaced with an empty string.
  4926. if (scriptDirectory.indexOf('blob:') !== 0) {
  4927. scriptDirectory = scriptDirectory.substr(0, scriptDirectory.lastIndexOf('/')+1);
  4928. } else {
  4929. scriptDirectory = '';
  4930. }
  4931. Module['read'] = function shell_read(url) {
  4932. var xhr = new XMLHttpRequest();
  4933. xhr.open('GET', url, false);
  4934. xhr.send(null);
  4935. return xhr.responseText;
  4936. };
  4937. if (ENVIRONMENT_IS_WORKER) {
  4938. Module['readBinary'] = function readBinary(url) {
  4939. var xhr = new XMLHttpRequest();
  4940. xhr.open('GET', url, false);
  4941. xhr.responseType = 'arraybuffer';
  4942. xhr.send(null);
  4943. return new Uint8Array(xhr.response);
  4944. };
  4945. }
  4946. Module['readAsync'] = function readAsync(url, onload, onerror) {
  4947. var xhr = new XMLHttpRequest();
  4948. xhr.open('GET', url, true);
  4949. xhr.responseType = 'arraybuffer';
  4950. xhr.onload = function xhr_onload() {
  4951. if (xhr.status == 200 || (xhr.status == 0 && xhr.response)) { // file URLs can return 0
  4952. onload(xhr.response);
  4953. return;
  4954. }
  4955. onerror();
  4956. };
  4957. xhr.onerror = onerror;
  4958. xhr.send(null);
  4959. };
  4960. Module['setWindowTitle'] = function(title) { document.title = title; };
  4961. } else
  4962. {
  4963. throw new Error('environment detection error');
  4964. }
  4965. // Set up the out() and err() hooks, which are how we can print to stdout or
  4966. // stderr, respectively.
  4967. // If the user provided Module.print or printErr, use that. Otherwise,
  4968. // console.log is checked first, as 'print' on the web will open a print dialogue
  4969. // printErr is preferable to console.warn (works better in shells)
  4970. // bind(console) is necessary to fix IE/Edge closed dev tools panel behavior.
  4971. var out = Module['print'] || (typeof console !== 'undefined' ? console.log.bind(console) : (typeof print !== 'undefined' ? print : null));
  4972. var err = Module['printErr'] || (typeof printErr !== 'undefined' ? printErr : ((typeof console !== 'undefined' && console.warn.bind(console)) || out));
  4973. // Merge back in the overrides
  4974. for (key in moduleOverrides) {
  4975. if (moduleOverrides.hasOwnProperty(key)) {
  4976. Module[key] = moduleOverrides[key];
  4977. }
  4978. }
  4979. // Free the object hierarchy contained in the overrides, this lets the GC
  4980. // reclaim data used e.g. in memoryInitializerRequest, which is a large typed array.
  4981. moduleOverrides = undefined;
  4982. // perform assertions in shell.js after we set up out() and err(), as otherwise if an assertion fails it cannot print the message
  4983. assert(typeof Module['memoryInitializerPrefixURL'] === 'undefined', 'Module.memoryInitializerPrefixURL option was removed, use Module.locateFile instead');
  4984. assert(typeof Module['pthreadMainPrefixURL'] === 'undefined', 'Module.pthreadMainPrefixURL option was removed, use Module.locateFile instead');
  4985. assert(typeof Module['cdInitializerPrefixURL'] === 'undefined', 'Module.cdInitializerPrefixURL option was removed, use Module.locateFile instead');
  4986. assert(typeof Module['filePackagePrefixURL'] === 'undefined', 'Module.filePackagePrefixURL option was removed, use Module.locateFile instead');
  4987. // stack management, and other functionality that is provided by the compiled code,
  4988. // should not be used before it is ready
  4989. stackSave = stackRestore = stackAlloc = function() {
  4990. abort('cannot use the stack before compiled code is ready to run, and has provided stack access');
  4991. };
  4992. function warnOnce(text) {
  4993. if (!warnOnce.shown) warnOnce.shown = {};
  4994. if (!warnOnce.shown[text]) {
  4995. warnOnce.shown[text] = 1;
  4996. //err(text);
  4997. }
  4998. }
  4999. var asm2wasmImports = { // special asm2wasm imports
  5000. "f64-rem": function(x, y) {
  5001. return x % y;
  5002. },
  5003. "debugger": function() {
  5004. debugger;
  5005. }
  5006. };
  5007. var functionPointers = new Array(0);
  5008. var tempRet0 = 0;
  5009. var setTempRet0 = function(value) {
  5010. tempRet0 = value;
  5011. };
  5012. var getTempRet0 = function() {
  5013. return tempRet0;
  5014. };
  5015. // === Preamble library stuff ===
  5016. // Documentation for the public APIs defined in this file must be updated in:
  5017. // site/source/docs/api_reference/preamble.js.rst
  5018. // A prebuilt local version of the documentation is available at:
  5019. // site/build/text/docs/api_reference/preamble.js.txt
  5020. // You can also build docs locally as HTML or other formats in site/
  5021. // An online HTML version (which may be of a different version of Emscripten)
  5022. // is up at http://kripken.github.io/emscripten-site/docs/api_reference/preamble.js.html
  5023. if (typeof WebAssembly !== 'object') {
  5024. abort('No WebAssembly support found. Build with -s WASM=0 to target JavaScript instead.');
  5025. }
  5026. /** @type {function(number, string, boolean=)} */
  5027. function getValue(ptr, type, noSafe) {
  5028. type = type || 'i8';
  5029. if (type.charAt(type.length-1) === '*') type = 'i32'; // pointers are 32-bit
  5030. switch(type) {
  5031. case 'i1': return HEAP8[((ptr)>>0)];
  5032. case 'i8': return HEAP8[((ptr)>>0)];
  5033. case 'i16': return HEAP16[((ptr)>>1)];
  5034. case 'i32': return HEAP32[((ptr)>>2)];
  5035. case 'i64': return HEAP32[((ptr)>>2)];
  5036. case 'float': return HEAPF32[((ptr)>>2)];
  5037. case 'double': return HEAPF64[((ptr)>>3)];
  5038. default: abort('invalid type for getValue: ' + type);
  5039. }
  5040. return null;
  5041. }
  5042. // Wasm globals
  5043. var wasmMemory;
  5044. // Potentially used for direct table calls.
  5045. var wasmTable;
  5046. //========================================
  5047. // Runtime essentials
  5048. //========================================
  5049. // whether we are quitting the application. no code should run after this.
  5050. // set in exit() and abort()
  5051. var ABORT = false;
  5052. /** @type {function(*, string=)} */
  5053. function assert(condition, text) {
  5054. if (!condition) {
  5055. abort('Assertion failed: ' + text);
  5056. }
  5057. }
  5058. // Returns the C function with a specified identifier (for C++, you need to do manual name mangling)
  5059. function getCFunc(ident) {
  5060. var func = Module['_' + ident]; // closure exported function
  5061. assert(func, 'Cannot call unknown function ' + ident + ', make sure it is exported');
  5062. return func;
  5063. }
  5064. // C calling interface.
  5065. function ccall(ident, returnType, argTypes, args, opts) {
  5066. // For fast lookup of conversion functions
  5067. var toC = {
  5068. 'string': function(str) {
  5069. var ret = 0;
  5070. if (str !== null && str !== undefined && str !== 0) { // null string
  5071. // at most 4 bytes per UTF-8 code point, +1 for the trailing '\0'
  5072. var len = (str.length << 2) + 1;
  5073. ret = stackAlloc(len);
  5074. stringToUTF8(str, ret, len);
  5075. }
  5076. return ret;
  5077. },
  5078. 'array': function(arr) {
  5079. var ret = stackAlloc(arr.length);
  5080. writeArrayToMemory(arr, ret);
  5081. return ret;
  5082. }
  5083. };
  5084. function convertReturnValue(ret) {
  5085. if (returnType === 'string') return UTF8ToString(ret);
  5086. if (returnType === 'boolean') return Boolean(ret);
  5087. return ret;
  5088. }
  5089. var func = getCFunc(ident);
  5090. var cArgs = [];
  5091. var stack = 0;
  5092. assert(returnType !== 'array', 'Return type should not be "array".');
  5093. if (args) {
  5094. for (var i = 0; i < args.length; i++) {
  5095. var converter = toC[argTypes[i]];
  5096. if (converter) {
  5097. if (stack === 0) stack = stackSave();
  5098. cArgs[i] = converter(args[i]);
  5099. } else {
  5100. cArgs[i] = args[i];
  5101. }
  5102. }
  5103. }
  5104. var ret = func.apply(null, cArgs);
  5105. ret = convertReturnValue(ret);
  5106. if (stack !== 0) stackRestore(stack);
  5107. return ret;
  5108. }
  5109. function cwrap(ident, returnType, argTypes, opts) {
  5110. return function() {
  5111. return ccall(ident, returnType, argTypes, arguments);
  5112. }
  5113. }
  5114. // Given a pointer 'ptr' to a null-terminated UTF8-encoded string in the given array that contains uint8 values, returns
  5115. // a copy of that string as a Javascript String object.
  5116. var UTF8Decoder = typeof TextDecoder !== 'undefined' ? new TextDecoder('utf8') : undefined;
  5117. /**
  5118. * @param {number} idx
  5119. * @param {number=} maxBytesToRead
  5120. * @return {string}
  5121. */
  5122. function UTF8ArrayToString(u8Array, idx, maxBytesToRead) {
  5123. var endIdx = idx + maxBytesToRead;
  5124. var endPtr = idx;
  5125. // TextDecoder needs to know the byte length in advance, it doesn't stop on null terminator by itself.
  5126. // Also, use the length info to avoid running tiny strings through TextDecoder, since .subarray() allocates garbage.
  5127. // (As a tiny code save trick, compare endPtr against endIdx using a negation, so that undefined means Infinity)
  5128. while (u8Array[endPtr] && !(endPtr >= endIdx)) ++endPtr;
  5129. if (endPtr - idx > 16 && u8Array.subarray && UTF8Decoder) {
  5130. return UTF8Decoder.decode(u8Array.subarray(idx, endPtr));
  5131. } else {
  5132. var str = '';
  5133. // If building with TextDecoder, we have already computed the string length above, so test loop end condition against that
  5134. while (idx < endPtr) {
  5135. // For UTF8 byte structure, see:
  5136. // http://en.wikipedia.org/wiki/UTF-8#Description
  5137. // https://www.ietf.org/rfc/rfc2279.txt
  5138. // https://tools.ietf.org/html/rfc3629
  5139. var u0 = u8Array[idx++];
  5140. if (!(u0 & 0x80)) { str += String.fromCharCode(u0); continue; }
  5141. var u1 = u8Array[idx++] & 63;
  5142. if ((u0 & 0xE0) == 0xC0) { str += String.fromCharCode(((u0 & 31) << 6) | u1); continue; }
  5143. var u2 = u8Array[idx++] & 63;
  5144. if ((u0 & 0xF0) == 0xE0) {
  5145. u0 = ((u0 & 15) << 12) | (u1 << 6) | u2;
  5146. } else {
  5147. if ((u0 & 0xF8) != 0xF0) warnOnce('Invalid UTF-8 leading byte 0x' + u0.toString(16) + ' encountered when deserializing a UTF-8 string on the asm.js/wasm heap to a JS string!');
  5148. u0 = ((u0 & 7) << 18) | (u1 << 12) | (u2 << 6) | (u8Array[idx++] & 63);
  5149. }
  5150. if (u0 < 0x10000) {
  5151. str += String.fromCharCode(u0);
  5152. } else {
  5153. var ch = u0 - 0x10000;
  5154. str += String.fromCharCode(0xD800 | (ch >> 10), 0xDC00 | (ch & 0x3FF));
  5155. }
  5156. }
  5157. }
  5158. return str;
  5159. }
  5160. // Given a pointer 'ptr' to a null-terminated UTF8-encoded string in the emscripten HEAP, returns a
  5161. // copy of that string as a Javascript String object.
  5162. // maxBytesToRead: an optional length that specifies the maximum number of bytes to read. You can omit
  5163. // this parameter to scan the string until the first \0 byte. If maxBytesToRead is
  5164. // passed, and the string at [ptr, ptr+maxBytesToReadr[ contains a null byte in the
  5165. // middle, then the string will cut short at that byte index (i.e. maxBytesToRead will
  5166. // not produce a string of exact length [ptr, ptr+maxBytesToRead[)
  5167. // N.B. mixing frequent uses of UTF8ToString() with and without maxBytesToRead may
  5168. // throw JS JIT optimizations off, so it is worth to consider consistently using one
  5169. // style or the other.
  5170. /**
  5171. * @param {number} ptr
  5172. * @param {number=} maxBytesToRead
  5173. * @return {string}
  5174. */
  5175. function UTF8ToString(ptr, maxBytesToRead) {
  5176. return ptr ? UTF8ArrayToString(HEAPU8, ptr, maxBytesToRead) : '';
  5177. }
  5178. // Copies the given Javascript String object 'str' to the given byte array at address 'outIdx',
  5179. // encoded in UTF8 form and null-terminated. The copy will require at most str.length*4+1 bytes of space in the HEAP.
  5180. // Use the function lengthBytesUTF8 to compute the exact number of bytes (excluding null terminator) that this function will write.
  5181. // Parameters:
  5182. // str: the Javascript string to copy.
  5183. // outU8Array: the array to copy to. Each index in this array is assumed to be one 8-byte element.
  5184. // outIdx: The starting offset in the array to begin the copying.
  5185. // maxBytesToWrite: The maximum number of bytes this function can write to the array.
  5186. // This count should include the null terminator,
  5187. // i.e. if maxBytesToWrite=1, only the null terminator will be written and nothing else.
  5188. // maxBytesToWrite=0 does not write any bytes to the output, not even the null terminator.
  5189. // Returns the number of bytes written, EXCLUDING the null terminator.
  5190. function stringToUTF8Array(str, outU8Array, outIdx, maxBytesToWrite) {
  5191. if (!(maxBytesToWrite > 0)) // Parameter maxBytesToWrite is not optional. Negative values, 0, null, undefined and false each don't write out any bytes.
  5192. return 0;
  5193. var startIdx = outIdx;
  5194. var endIdx = outIdx + maxBytesToWrite - 1; // -1 for string null terminator.
  5195. for (var i = 0; i < str.length; ++i) {
  5196. // Gotcha: charCodeAt returns a 16-bit word that is a UTF-16 encoded code unit, not a Unicode code point of the character! So decode UTF16->UTF32->UTF8.
  5197. // See http://unicode.org/faq/utf_bom.html#utf16-3
  5198. // For UTF8 byte structure, see http://en.wikipedia.org/wiki/UTF-8#Description and https://www.ietf.org/rfc/rfc2279.txt and https://tools.ietf.org/html/rfc3629
  5199. var u = str.charCodeAt(i); // possibly a lead surrogate
  5200. if (u >= 0xD800 && u <= 0xDFFF) {
  5201. var u1 = str.charCodeAt(++i);
  5202. u = 0x10000 + ((u & 0x3FF) << 10) | (u1 & 0x3FF);
  5203. }
  5204. if (u <= 0x7F) {
  5205. if (outIdx >= endIdx) break;
  5206. outU8Array[outIdx++] = u;
  5207. } else if (u <= 0x7FF) {
  5208. if (outIdx + 1 >= endIdx) break;
  5209. outU8Array[outIdx++] = 0xC0 | (u >> 6);
  5210. outU8Array[outIdx++] = 0x80 | (u & 63);
  5211. } else if (u <= 0xFFFF) {
  5212. if (outIdx + 2 >= endIdx) break;
  5213. outU8Array[outIdx++] = 0xE0 | (u >> 12);
  5214. outU8Array[outIdx++] = 0x80 | ((u >> 6) & 63);
  5215. outU8Array[outIdx++] = 0x80 | (u & 63);
  5216. } else {
  5217. if (outIdx + 3 >= endIdx) break;
  5218. if (u >= 0x200000) warnOnce('Invalid Unicode code point 0x' + u.toString(16) + ' encountered when serializing a JS string to an UTF-8 string on the asm.js/wasm heap! (Valid unicode code points should be in range 0-0x1FFFFF).');
  5219. outU8Array[outIdx++] = 0xF0 | (u >> 18);
  5220. outU8Array[outIdx++] = 0x80 | ((u >> 12) & 63);
  5221. outU8Array[outIdx++] = 0x80 | ((u >> 6) & 63);
  5222. outU8Array[outIdx++] = 0x80 | (u & 63);
  5223. }
  5224. }
  5225. // Null-terminate the pointer to the buffer.
  5226. outU8Array[outIdx] = 0;
  5227. return outIdx - startIdx;
  5228. }
  5229. // Copies the given Javascript String object 'str' to the emscripten HEAP at address 'outPtr',
  5230. // null-terminated and encoded in UTF8 form. The copy will require at most str.length*4+1 bytes of space in the HEAP.
  5231. // Use the function lengthBytesUTF8 to compute the exact number of bytes (excluding null terminator) that this function will write.
  5232. // Returns the number of bytes written, EXCLUDING the null terminator.
  5233. function stringToUTF8(str, outPtr, maxBytesToWrite) {
  5234. assert(typeof maxBytesToWrite == 'number', 'stringToUTF8(str, outPtr, maxBytesToWrite) is missing the third parameter that specifies the length of the output buffer!');
  5235. return stringToUTF8Array(str, HEAPU8,outPtr, maxBytesToWrite);
  5236. }
  5237. // Given a pointer 'ptr' to a null-terminated UTF16LE-encoded string in the emscripten HEAP, returns
  5238. // a copy of that string as a Javascript String object.
  5239. var UTF16Decoder = typeof TextDecoder !== 'undefined' ? new TextDecoder('utf-16le') : undefined;
  5240. function writeArrayToMemory(array, buffer) {
  5241. assert(array.length >= 0, 'writeArrayToMemory array must have a length (should be an array or typed array)');
  5242. HEAP8.set(array, buffer);
  5243. }
  5244. function demangle(func) {
  5245. return func;
  5246. }
  5247. function demangleAll(text) {
  5248. var regex =
  5249. /__Z[\w\d_]+/g;
  5250. return text.replace(regex,
  5251. function(x) {
  5252. var y = demangle(x);
  5253. return x === y ? x : (y + ' [' + x + ']');
  5254. });
  5255. }
  5256. function jsStackTrace() {
  5257. var err = new Error();
  5258. if (!err.stack) {
  5259. // IE10+ special cases: It does have callstack info, but it is only populated if an Error object is thrown,
  5260. // so try that as a special-case.
  5261. try {
  5262. throw new Error(0);
  5263. } catch(e) {
  5264. err = e;
  5265. }
  5266. if (!err.stack) {
  5267. return '(no stack trace available)';
  5268. }
  5269. }
  5270. return err.stack.toString();
  5271. }
  5272. function stackTrace() {
  5273. var js = jsStackTrace();
  5274. if (Module['extraStackTrace']) js += '\n' + Module['extraStackTrace']();
  5275. return demangleAll(js);
  5276. }
  5277. var WASM_PAGE_SIZE = 65536;
  5278. function alignUp(x, multiple) {
  5279. if (x % multiple > 0) {
  5280. x += multiple - (x % multiple);
  5281. }
  5282. return x;
  5283. }
  5284. var /** @type {ArrayBuffer} */
  5285. buffer,
  5286. /** @type {Int8Array} */
  5287. HEAP8,
  5288. /** @type {Uint8Array} */
  5289. HEAPU8,
  5290. /** @type {Int16Array} */
  5291. HEAP16,
  5292. /** @type {Uint16Array} */
  5293. HEAPU16,
  5294. /** @type {Int32Array} */
  5295. HEAP32,
  5296. /** @type {Uint32Array} */
  5297. HEAPU32,
  5298. /** @type {Float32Array} */
  5299. HEAPF32,
  5300. /** @type {Float64Array} */
  5301. HEAPF64;
  5302. function updateGlobalBufferViews() {
  5303. Module['HEAP8'] = HEAP8 = new Int8Array(buffer);
  5304. Module['HEAP16'] = HEAP16 = new Int16Array(buffer);
  5305. Module['HEAP32'] = HEAP32 = new Int32Array(buffer);
  5306. Module['HEAPU8'] = HEAPU8 = new Uint8Array(buffer);
  5307. Module['HEAPU16'] = HEAPU16 = new Uint16Array(buffer);
  5308. Module['HEAPU32'] = HEAPU32 = new Uint32Array(buffer);
  5309. Module['HEAPF32'] = HEAPF32 = new Float32Array(buffer);
  5310. Module['HEAPF64'] = HEAPF64 = new Float64Array(buffer);
  5311. }
  5312. var STACK_BASE = 5872,
  5313. STACK_MAX = 5248752,
  5314. DYNAMIC_BASE = 5248752,
  5315. DYNAMICTOP_PTR = 5840;
  5316. assert(STACK_BASE % 16 === 0, 'stack must start aligned');
  5317. assert(DYNAMIC_BASE % 16 === 0, 'heap must start aligned');
  5318. var TOTAL_STACK = 5242880;
  5319. if (Module['TOTAL_STACK']) assert(TOTAL_STACK === Module['TOTAL_STACK'], 'the stack size can no longer be determined at runtime');
  5320. var INITIAL_TOTAL_MEMORY = Module['TOTAL_MEMORY'] || 16777216;
  5321. if (INITIAL_TOTAL_MEMORY < TOTAL_STACK) err('TOTAL_MEMORY should be larger than TOTAL_STACK, was ' + INITIAL_TOTAL_MEMORY + '! (TOTAL_STACK=' + TOTAL_STACK + ')');
  5322. // Initialize the runtime's memory
  5323. // check for full engine support (use string 'subarray' to avoid closure compiler confusion)
  5324. assert(typeof Int32Array !== 'undefined' && typeof Float64Array !== 'undefined' && Int32Array.prototype.subarray !== undefined && Int32Array.prototype.set !== undefined,
  5325. 'JS engine does not provide full typed array support');
  5326. // Use a provided buffer, if there is one, or else allocate a new one
  5327. if (Module['buffer']) {
  5328. buffer = Module['buffer'];
  5329. assert(buffer.byteLength === INITIAL_TOTAL_MEMORY, 'provided buffer should be ' + INITIAL_TOTAL_MEMORY + ' bytes, but it is ' + buffer.byteLength);
  5330. } else {
  5331. // Use a WebAssembly memory where available
  5332. if (typeof WebAssembly === 'object' && typeof WebAssembly.Memory === 'function') {
  5333. assert(INITIAL_TOTAL_MEMORY % WASM_PAGE_SIZE === 0);
  5334. wasmMemory = new WebAssembly.Memory({ 'initial': INITIAL_TOTAL_MEMORY / WASM_PAGE_SIZE });
  5335. buffer = wasmMemory.buffer;
  5336. } else
  5337. {
  5338. buffer = new ArrayBuffer(INITIAL_TOTAL_MEMORY);
  5339. }
  5340. assert(buffer.byteLength === INITIAL_TOTAL_MEMORY);
  5341. }
  5342. updateGlobalBufferViews();
  5343. HEAP32[DYNAMICTOP_PTR>>2] = DYNAMIC_BASE;
  5344. // Initializes the stack cookie. Called at the startup of main and at the startup of each thread in pthreads mode.
  5345. function writeStackCookie() {
  5346. assert((STACK_MAX & 3) == 0);
  5347. HEAPU32[(STACK_MAX >> 2)-1] = 0x02135467;
  5348. HEAPU32[(STACK_MAX >> 2)-2] = 0x89BACDFE;
  5349. }
  5350. function checkStackCookie() {
  5351. if (HEAPU32[(STACK_MAX >> 2)-1] != 0x02135467 || HEAPU32[(STACK_MAX >> 2)-2] != 0x89BACDFE) {
  5352. abort('Stack overflow! Stack cookie has been overwritten, expected hex dwords 0x89BACDFE and 0x02135467, but received 0x' + HEAPU32[(STACK_MAX >> 2)-2].toString(16) + ' ' + HEAPU32[(STACK_MAX >> 2)-1].toString(16));
  5353. }
  5354. // Also test the global address 0 for integrity.
  5355. if (HEAP32[0] !== 0x63736d65 /* 'emsc' */) abort('Runtime error: The application has corrupted its heap memory area (address zero)!');
  5356. }
  5357. function abortStackOverflow(allocSize) {
  5358. abort('Stack overflow! Attempted to allocate ' + allocSize + ' bytes on the stack, but stack has only ' + (STACK_MAX - stackSave() + allocSize) + ' bytes available!');
  5359. }
  5360. HEAP32[0] = 0x63736d65; /* 'emsc' */
  5361. // Endianness check (note: assumes compiler arch was little-endian)
  5362. HEAP16[1] = 0x6373;
  5363. if (HEAPU8[2] !== 0x73 || HEAPU8[3] !== 0x63) throw 'Runtime error: expected the system to be little-endian!';
  5364. function callRuntimeCallbacks(callbacks) {
  5365. while(callbacks.length > 0) {
  5366. var callback = callbacks.shift();
  5367. if (typeof callback == 'function') {
  5368. callback();
  5369. continue;
  5370. }
  5371. var func = callback.func;
  5372. if (typeof func === 'number') {
  5373. if (callback.arg === undefined) {
  5374. Module['dynCall_v'](func);
  5375. } else {
  5376. Module['dynCall_vi'](func, callback.arg);
  5377. }
  5378. } else {
  5379. func(callback.arg === undefined ? null : callback.arg);
  5380. }
  5381. }
  5382. }
  5383. var __ATPRERUN__ = []; // functions called before the runtime is initialized
  5384. var __ATINIT__ = []; // functions called during startup
  5385. var __ATMAIN__ = []; // functions called when main() is to be run
  5386. var __ATPOSTRUN__ = []; // functions called after the main() is called
  5387. var runtimeInitialized = false;
  5388. var runtimeExited = false;
  5389. function preRun() {
  5390. // compatibility - merge in anything from Module['preRun'] at this time
  5391. if (Module['preRun']) {
  5392. if (typeof Module['preRun'] == 'function') Module['preRun'] = [Module['preRun']];
  5393. while (Module['preRun'].length) {
  5394. addOnPreRun(Module['preRun'].shift());
  5395. }
  5396. }
  5397. callRuntimeCallbacks(__ATPRERUN__);
  5398. }
  5399. function ensureInitRuntime() {
  5400. checkStackCookie();
  5401. if (runtimeInitialized) return;
  5402. runtimeInitialized = true;
  5403. callRuntimeCallbacks(__ATINIT__);
  5404. }
  5405. function preMain() {
  5406. checkStackCookie();
  5407. callRuntimeCallbacks(__ATMAIN__);
  5408. }
  5409. function postRun() {
  5410. checkStackCookie();
  5411. // compatibility - merge in anything from Module['postRun'] at this time
  5412. if (Module['postRun']) {
  5413. if (typeof Module['postRun'] == 'function') Module['postRun'] = [Module['postRun']];
  5414. while (Module['postRun'].length) {
  5415. addOnPostRun(Module['postRun'].shift());
  5416. }
  5417. }
  5418. callRuntimeCallbacks(__ATPOSTRUN__);
  5419. }
  5420. function addOnPreRun(cb) {
  5421. __ATPRERUN__.unshift(cb);
  5422. }
  5423. function addOnPostRun(cb) {
  5424. __ATPOSTRUN__.unshift(cb);
  5425. }
  5426. assert(Math.imul, 'This browser does not support Math.imul(), build with LEGACY_VM_SUPPORT or POLYFILL_OLD_MATH_FUNCTIONS to add in a polyfill');
  5427. assert(Math.fround, 'This browser does not support Math.fround(), build with LEGACY_VM_SUPPORT or POLYFILL_OLD_MATH_FUNCTIONS to add in a polyfill');
  5428. assert(Math.clz32, 'This browser does not support Math.clz32(), build with LEGACY_VM_SUPPORT or POLYFILL_OLD_MATH_FUNCTIONS to add in a polyfill');
  5429. assert(Math.trunc, 'This browser does not support Math.trunc(), build with LEGACY_VM_SUPPORT or POLYFILL_OLD_MATH_FUNCTIONS to add in a polyfill');
  5430. // A counter of dependencies for calling run(). If we need to
  5431. // do asynchronous work before running, increment this and
  5432. // decrement it. Incrementing must happen in a place like
  5433. // Module.preRun (used by emcc to add file preloading).
  5434. // Note that you can add dependencies in preRun, even though
  5435. // it happens right before run - run will be postponed until
  5436. // the dependencies are met.
  5437. var runDependencies = 0;
  5438. var runDependencyWatcher = null;
  5439. var dependenciesFulfilled = null; // overridden to take different actions when all run dependencies are fulfilled
  5440. var runDependencyTracking = {};
  5441. function addRunDependency(id) {
  5442. runDependencies++;
  5443. if (Module['monitorRunDependencies']) {
  5444. Module['monitorRunDependencies'](runDependencies);
  5445. }
  5446. if (id) {
  5447. assert(!runDependencyTracking[id]);
  5448. runDependencyTracking[id] = 1;
  5449. if (runDependencyWatcher === null && typeof setInterval !== 'undefined') {
  5450. // Check for missing dependencies every few seconds
  5451. runDependencyWatcher = setInterval(function() {
  5452. if (ABORT) {
  5453. clearInterval(runDependencyWatcher);
  5454. runDependencyWatcher = null;
  5455. return;
  5456. }
  5457. }, 10000);
  5458. }
  5459. }
  5460. }
  5461. function removeRunDependency(id) {
  5462. runDependencies--;
  5463. if (Module['monitorRunDependencies']) {
  5464. Module['monitorRunDependencies'](runDependencies);
  5465. }
  5466. if (id) {
  5467. assert(runDependencyTracking[id]);
  5468. delete runDependencyTracking[id];
  5469. }
  5470. if (runDependencies == 0) {
  5471. if (runDependencyWatcher !== null) {
  5472. clearInterval(runDependencyWatcher);
  5473. runDependencyWatcher = null;
  5474. }
  5475. if (dependenciesFulfilled) {
  5476. var callback = dependenciesFulfilled;
  5477. dependenciesFulfilled = null;
  5478. callback(); // can add another dependenciesFulfilled
  5479. }
  5480. }
  5481. }
  5482. Module["preloadedImages"] = {}; // maps url to image data
  5483. Module["preloadedAudios"] = {}; // maps url to audio data
  5484. // show errors on likely calls to FS when it was not included
  5485. var FS = {
  5486. error: function() {
  5487. abort('Filesystem support (FS) was not included. The problem is that you are using files from JS, but files were not used from C/C++, so filesystem support was not auto-included. You can force-include filesystem support with -s FORCE_FILESYSTEM=1');
  5488. },
  5489. init: function() { FS.error(); },
  5490. createDataFile: function() { FS.error(); },
  5491. createPreloadedFile: function() { FS.error(); },
  5492. createLazyFile: function() { FS.error(); },
  5493. open: function() { FS.error(); },
  5494. mkdev: function() { FS.error(); },
  5495. registerDevice: function() { FS.error(); },
  5496. analyzePath: function() { FS.error(); },
  5497. loadFilesFromDB: function() { FS.error(); },
  5498. ErrnoError: function ErrnoError() { FS.error(); },
  5499. };
  5500. Module['FS_createDataFile'] = FS.createDataFile;
  5501. Module['FS_createPreloadedFile'] = FS.createPreloadedFile;
  5502. // Copyright 2017 The Emscripten Authors. All rights reserved.
  5503. // Emscripten is available under two separate licenses, the MIT license and the
  5504. // University of Illinois/NCSA Open Source License. Both these licenses can be
  5505. // found in the LICENSE file.
  5506. // Prefix of data URIs emitted by SINGLE_FILE and related options.
  5507. var dataURIPrefix = 'data:application/octet-stream;base64,';
  5508. // Indicates whether filename is a base64 data URI.
  5509. function isDataURI(filename) {
  5510. return String.prototype.startsWith ?
  5511. filename.startsWith(dataURIPrefix) :
  5512. filename.indexOf(dataURIPrefix) === 0;
  5513. }
  5514. var wasmBinaryFile = 'ThirdParty/earcut.wasm';
  5515. if (!isDataURI(wasmBinaryFile)) {
  5516. wasmBinaryFile = locateFile(wasmBinaryFile);
  5517. }
  5518. function getBinary() {
  5519. try {
  5520. if (Module['wasmBinary']) {
  5521. return new Uint8Array(Module['wasmBinary']);
  5522. }
  5523. if (Module['readBinary']) {
  5524. return Module['readBinary'](wasmBinaryFile);
  5525. } else {
  5526. throw "both async and sync fetching of the wasm failed";
  5527. }
  5528. }
  5529. catch (err) {
  5530. abort(err);
  5531. }
  5532. }
  5533. function getBinaryPromise() {
  5534. // if we don't have the binary yet, and have the Fetch api, use that
  5535. // in some environments, like Electron's render process, Fetch api may be present, but have a different context than expected, let's only use it on the Web
  5536. if (!Module['wasmBinary'] && (ENVIRONMENT_IS_WEB || ENVIRONMENT_IS_WORKER) && typeof fetch === 'function') {
  5537. return fetch(wasmBinaryFile, { credentials: 'same-origin' }).then(function(response) {
  5538. if (!response['ok']) {
  5539. throw "failed to load wasm binary file at '" + wasmBinaryFile + "'";
  5540. }
  5541. return response['arrayBuffer']();
  5542. }).catch(function () {
  5543. return getBinary();
  5544. });
  5545. }
  5546. // Otherwise, getBinary should be able to get it synchronously
  5547. return new Promise(function(resolve, reject) {
  5548. resolve(getBinary());
  5549. });
  5550. }
  5551. // Create the wasm instance.
  5552. // Receives the wasm imports, returns the exports.
  5553. function createWasm(env) {
  5554. // prepare imports
  5555. var info = {
  5556. 'env': env
  5557. ,
  5558. 'global': {
  5559. 'NaN': NaN,
  5560. 'Infinity': Infinity
  5561. },
  5562. 'global.Math': Math,
  5563. 'asm2wasm': asm2wasmImports
  5564. };
  5565. // Load the wasm module and create an instance of using native support in the JS engine.
  5566. // handle a generated wasm instance, receiving its exports and
  5567. // performing other necessary setup
  5568. function receiveInstance(instance, module) {
  5569. var exports = instance.exports;
  5570. Module['asm'] = exports;
  5571. removeRunDependency('wasm-instantiate');
  5572. }
  5573. addRunDependency('wasm-instantiate');
  5574. // Async compilation can be confusing when an error on the page overwrites Module
  5575. // (for example, if the order of elements is wrong, and the one defining Module is
  5576. // later), so we save Module and check it later.
  5577. var trueModule = Module;
  5578. function receiveInstantiatedSource(output) {
  5579. // 'output' is a WebAssemblyInstantiatedSource object which has both the module and instance.
  5580. // receiveInstance() will swap in the exports (to Module.asm) so they can be called
  5581. assert(Module === trueModule, 'the Module object should not be replaced during async compilation - perhaps the order of HTML elements is wrong?');
  5582. trueModule = null;
  5583. // TODO: Due to Closure regression https://github.com/google/closure-compiler/issues/3193, the above line no longer optimizes out down to the following line.
  5584. // When the regression is fixed, can restore the above USE_PTHREADS-enabled path.
  5585. receiveInstance(output['instance']);
  5586. }
  5587. function instantiateArrayBuffer(receiver) {
  5588. return getBinaryPromise().then(function(binary) {
  5589. return WebAssembly.instantiate(binary, info);
  5590. }).then(receiver, function(reason) {
  5591. //err('failed to asynchronously prepare wasm: ' + reason);
  5592. //abort(reason);
  5593. });
  5594. }
  5595. // Prefer streaming instantiation if available.
  5596. function instantiateAsync() {
  5597. if (!Module['wasmBinary'] &&
  5598. typeof WebAssembly.instantiateStreaming === 'function' &&
  5599. !isDataURI(wasmBinaryFile) &&
  5600. typeof fetch === 'function') {
  5601. fetch(wasmBinaryFile, { credentials: 'same-origin' }).then(function (response) {
  5602. return WebAssembly.instantiateStreaming(response, info)
  5603. .then(receiveInstantiatedSource, function(reason) {
  5604. // We expect the most common failure cause to be a bad MIME type for the binary,
  5605. // in which case falling back to ArrayBuffer instantiation should work.
  5606. //err('wasm streaming compile failed: ' + reason);
  5607. //err('falling back to ArrayBuffer instantiation');
  5608. instantiateArrayBuffer(receiveInstantiatedSource);
  5609. });
  5610. });
  5611. } else {
  5612. return instantiateArrayBuffer(receiveInstantiatedSource);
  5613. }
  5614. }
  5615. // User shell pages can write their own Module.instantiateWasm = function(imports, successCallback) callback
  5616. // to manually instantiate the Wasm module themselves. This allows pages to run the instantiation parallel
  5617. // to any other async startup actions they are performing.
  5618. if (Module['instantiateWasm']) {
  5619. try {
  5620. return Module['instantiateWasm'](info, receiveInstance);
  5621. } catch(e) {
  5622. //err('Module.instantiateWasm callback failed with error: ' + e);
  5623. return false;
  5624. }
  5625. }
  5626. instantiateAsync();
  5627. return {}; // no exports yet; we'll fill them in later
  5628. }
  5629. // Provide an "asm.js function" for the application, called to "link" the asm.js module. We instantiate
  5630. // the wasm module at that time, and it receives imports and provides exports and so forth, the app
  5631. // doesn't need to care that it is wasm or asm.js.
  5632. Module['asm'] = function(global, env, providedBuffer) {
  5633. // memory was already allocated (so js could use the buffer)
  5634. env['memory'] = wasmMemory
  5635. ;
  5636. // import table
  5637. env['table'] = wasmTable = new WebAssembly.Table({
  5638. 'initial': 260,
  5639. 'maximum': 260,
  5640. 'element': 'anyfunc'
  5641. });
  5642. // With the wasm backend __memory_base and __table_base and only needed for
  5643. // relocatable output.
  5644. env['__memory_base'] = 1024; // tell the memory segments where to place themselves
  5645. // table starts at 0 by default (even in dynamic linking, for the main module)
  5646. env['__table_base'] = 0;
  5647. var exports = createWasm(env);
  5648. assert(exports, 'binaryen setup failed (no wasm support?)');
  5649. return exports;
  5650. };
  5651. // STATICTOP = STATIC_BASE + 4848;
  5652. /* global initializers */ /*__ATINIT__.push();*/
  5653. /* no memory initializer */
  5654. var tempDoublePtr = 5856;
  5655. assert(tempDoublePtr % 8 == 0);
  5656. // {{PRE_LIBRARY}}
  5657. function ___cxa_allocate_exception(size) {
  5658. return _malloc(size);
  5659. }
  5660. var ___exception_infos={};
  5661. var ___exception_caught= [];
  5662. function ___exception_addRef(ptr) {
  5663. if (!ptr) return;
  5664. var info = ___exception_infos[ptr];
  5665. info.refcount++;
  5666. }
  5667. function ___exception_deAdjust(adjusted) {
  5668. if (!adjusted || ___exception_infos[adjusted]) return adjusted;
  5669. for (var key in ___exception_infos) {
  5670. var ptr = +key; // the iteration key is a string, and if we throw this, it must be an integer as that is what we look for
  5671. var adj = ___exception_infos[ptr].adjusted;
  5672. var len = adj.length;
  5673. for (var i = 0; i < len; i++) {
  5674. if (adj[i] === adjusted) {
  5675. return ptr;
  5676. }
  5677. }
  5678. }
  5679. return adjusted;
  5680. }function ___cxa_begin_catch(ptr) {
  5681. var info = ___exception_infos[ptr];
  5682. if (info && !info.caught) {
  5683. info.caught = true;
  5684. __ZSt18uncaught_exceptionv.uncaught_exception--;
  5685. }
  5686. if (info) info.rethrown = false;
  5687. ___exception_caught.push(ptr);
  5688. ___exception_addRef(___exception_deAdjust(ptr));
  5689. return ptr;
  5690. }
  5691. function ___cxa_throw(ptr, type, destructor) {
  5692. ___exception_infos[ptr] = {
  5693. ptr: ptr,
  5694. adjusted: [ptr],
  5695. type: type,
  5696. destructor: destructor,
  5697. refcount: 0,
  5698. caught: false,
  5699. rethrown: false
  5700. };
  5701. if (!("uncaught_exception" in __ZSt18uncaught_exceptionv)) {
  5702. __ZSt18uncaught_exceptionv.uncaught_exception = 1;
  5703. } else {
  5704. __ZSt18uncaught_exceptionv.uncaught_exception++;
  5705. }
  5706. throw ptr + " - Exception catching is disabled, this exception cannot be caught. Compile with -s DISABLE_EXCEPTION_CATCHING=0 or DISABLE_EXCEPTION_CATCHING=2 to catch.";
  5707. }
  5708. function ___cxa_uncaught_exception() {
  5709. return !!__ZSt18uncaught_exceptionv.uncaught_exception;
  5710. }
  5711. function ___gxx_personality_v0() {
  5712. }
  5713. function ___lock() {}
  5714. var SYSCALLS={buffers:[null,[],[]],printChar:function (stream, curr) {
  5715. var buffer = SYSCALLS.buffers[stream];
  5716. assert(buffer);
  5717. if (curr === 0 || curr === 10) {
  5718. (stream === 1 ? out : err)(UTF8ArrayToString(buffer, 0));
  5719. buffer.length = 0;
  5720. } else {
  5721. buffer.push(curr);
  5722. }
  5723. },varargs:0,get:function (varargs) {
  5724. SYSCALLS.varargs += 4;
  5725. var ret = HEAP32[(((SYSCALLS.varargs)-(4))>>2)];
  5726. return ret;
  5727. },getStr:function () {
  5728. var ret = UTF8ToString(SYSCALLS.get());
  5729. return ret;
  5730. },get64:function () {
  5731. var low = SYSCALLS.get(), high = SYSCALLS.get();
  5732. if (low >= 0) assert(high === 0);
  5733. else assert(high === -1);
  5734. return low;
  5735. },getZero:function () {
  5736. assert(SYSCALLS.get() === 0);
  5737. }};function ___syscall140(which, varargs) {SYSCALLS.varargs = varargs;
  5738. try {
  5739. // llseek
  5740. var stream = SYSCALLS.getStreamFromFD(), offset_high = SYSCALLS.get(), offset_low = SYSCALLS.get(), result = SYSCALLS.get(), whence = SYSCALLS.get();
  5741. abort('it should not be possible to operate on streams when !SYSCALLS_REQUIRE_FILESYSTEM');
  5742. return 0;
  5743. } catch (e) {
  5744. if (typeof FS === 'undefined' || !(e instanceof FS.ErrnoError)) abort(e);
  5745. return -e.errno;
  5746. }
  5747. }
  5748. function flush_NO_FILESYSTEM() {
  5749. // flush anything remaining in the buffers during shutdown
  5750. var fflush = Module["_fflush"];
  5751. if (fflush) fflush(0);
  5752. var buffers = SYSCALLS.buffers;
  5753. if (buffers[1].length) SYSCALLS.printChar(1, 10);
  5754. if (buffers[2].length) SYSCALLS.printChar(2, 10);
  5755. }function ___syscall146(which, varargs) {SYSCALLS.varargs = varargs;
  5756. try {
  5757. // writev
  5758. // hack to support printf in SYSCALLS_REQUIRE_FILESYSTEM=0
  5759. var stream = SYSCALLS.get(), iov = SYSCALLS.get(), iovcnt = SYSCALLS.get();
  5760. var ret = 0;
  5761. for (var i = 0; i < iovcnt; i++) {
  5762. var ptr = HEAP32[(((iov)+(i*8))>>2)];
  5763. var len = HEAP32[(((iov)+(i*8 + 4))>>2)];
  5764. for (var j = 0; j < len; j++) {
  5765. SYSCALLS.printChar(stream, HEAPU8[ptr+j]);
  5766. }
  5767. ret += len;
  5768. }
  5769. return ret;
  5770. } catch (e) {
  5771. if (typeof FS === 'undefined' || !(e instanceof FS.ErrnoError)) abort(e);
  5772. return -e.errno;
  5773. }
  5774. }
  5775. function ___syscall54(which, varargs) {SYSCALLS.varargs = varargs;
  5776. try {
  5777. // ioctl
  5778. return 0;
  5779. } catch (e) {
  5780. if (typeof FS === 'undefined' || !(e instanceof FS.ErrnoError)) abort(e);
  5781. return -e.errno;
  5782. }
  5783. }
  5784. function ___syscall6(which, varargs) {SYSCALLS.varargs = varargs;
  5785. try {
  5786. // close
  5787. var stream = SYSCALLS.getStreamFromFD();
  5788. abort('it should not be possible to operate on streams when !SYSCALLS_REQUIRE_FILESYSTEM');
  5789. return 0;
  5790. } catch (e) {
  5791. if (typeof FS === 'undefined' || !(e instanceof FS.ErrnoError)) abort(e);
  5792. return -e.errno;
  5793. }
  5794. }
  5795. function ___unlock() {}
  5796. function _abort() {
  5797. Module['abort']();
  5798. }
  5799. function _emscripten_get_heap_size() {
  5800. return HEAP8.length;
  5801. }
  5802. function _emscripten_memcpy_big(dest, src, num) {
  5803. HEAPU8.set(HEAPU8.subarray(src, src+num), dest);
  5804. }
  5805. function ___setErrNo(value) {
  5806. if (Module['___errno_location']) HEAP32[((Module['___errno_location']())>>2)]=value;
  5807. else //err('failed to set errno from JS');
  5808. return value;
  5809. }
  5810. function abortOnCannotGrowMemory(requestedSize) {
  5811. abort('Cannot enlarge memory arrays to size ' + requestedSize + ' bytes (OOM). Either (1) compile with -s TOTAL_MEMORY=X with X higher than the current value ' + HEAP8.length + ', (2) compile with -s ALLOW_MEMORY_GROWTH=1 which allows increasing the size at runtime, or (3) if you want malloc to return NULL (0) instead of this abort, compile with -s ABORTING_MALLOC=0 ');
  5812. }
  5813. function emscripten_realloc_buffer(size) {
  5814. var PAGE_MULTIPLE = 65536;
  5815. size = alignUp(size, PAGE_MULTIPLE); // round up to wasm page size
  5816. var oldSize = buffer.byteLength;
  5817. // native wasm support
  5818. // note that this is *not* threadsafe. multiple threads can call .grow(), and each
  5819. // presents a delta, so in theory we may over-allocate here (e.g. if two threads
  5820. // ask to grow from 256MB to 512MB, we get 2 requests to add +256MB, and may end
  5821. // up growing to 768MB (even though we may have been able to make do with 512MB).
  5822. // TODO: consider decreasing the step sizes in emscripten_resize_heap
  5823. try {
  5824. var result = wasmMemory.grow((size - oldSize) / 65536); // .grow() takes a delta compared to the previous size
  5825. if (result !== (-1 | 0)) {
  5826. // success in native wasm memory growth, get the buffer from the memory
  5827. buffer = wasmMemory.buffer;
  5828. return true;
  5829. } else {
  5830. return false;
  5831. }
  5832. } catch(e) {
  5833. console.error('emscripten_realloc_buffer: Attempted to grow from ' + oldSize + ' bytes to ' + size + ' bytes, but got error: ' + e);
  5834. return false;
  5835. }
  5836. }function _emscripten_resize_heap(requestedSize) {
  5837. var oldSize = _emscripten_get_heap_size();
  5838. // With pthreads, races can happen (another thread might increase the size in between), so return a failure, and let the caller retry.
  5839. assert(requestedSize > oldSize);
  5840. var PAGE_MULTIPLE = 65536;
  5841. var LIMIT = 2147483648 - PAGE_MULTIPLE; // We can do one page short of 2GB as theoretical maximum.
  5842. if (requestedSize > LIMIT) {
  5843. //err('Cannot enlarge memory, asked to go up to ' + requestedSize + ' bytes, but the limit is ' + LIMIT + ' bytes!');
  5844. return false;
  5845. }
  5846. var MIN_TOTAL_MEMORY = 16777216;
  5847. var newSize = Math.max(oldSize, MIN_TOTAL_MEMORY); // So the loop below will not be infinite, and minimum asm.js memory size is 16MB.
  5848. // TODO: see realloc_buffer - for PTHREADS we may want to decrease these jumps
  5849. while (newSize < requestedSize) { // Keep incrementing the heap size as long as it's less than what is requested.
  5850. if (newSize <= 536870912) {
  5851. newSize = alignUp(2 * newSize, PAGE_MULTIPLE); // Simple heuristic: double until 1GB...
  5852. } else {
  5853. // ..., but after that, add smaller increments towards 2GB, which we cannot reach
  5854. newSize = Math.min(alignUp((3 * newSize + 2147483648) / 4, PAGE_MULTIPLE), LIMIT);
  5855. }
  5856. if (newSize === oldSize) {
  5857. warnOnce('Cannot ask for more memory since we reached the practical limit in browsers (which is just below 2GB), so the request would have failed. Requesting only ' + HEAP8.length);
  5858. }
  5859. }
  5860. if (!emscripten_realloc_buffer(newSize)) {
  5861. //err('Failed to grow the heap from ' + oldSize + ' bytes to ' + newSize + ' bytes, not enough memory!');
  5862. return false;
  5863. }
  5864. updateGlobalBufferViews();
  5865. return true;
  5866. }
  5867. // ASM_LIBRARY EXTERN PRIMITIVES: Math_max,Math_min,Int8Array,Int32Array
  5868. function nullFunc_ii(x) { err("Invalid function pointer called with signature 'ii'. Perhaps this is an invalid value (e.g. caused by calling a virtual method on a NULL pointer)? Or calling a function with an incorrect type, which will fail? (it is worth building your source files with -Werror (warnings are errors), as warnings can indicate undefined behavior which can cause this)"); err("Build with ASSERTIONS=2 for more info.");abort(x); }
  5869. function nullFunc_iidiiii(x) { err("Invalid function pointer called with signature 'iidiiii'. Perhaps this is an invalid value (e.g. caused by calling a virtual method on a NULL pointer)? Or calling a function with an incorrect type, which will fail? (it is worth building your source files with -Werror (warnings are errors), as warnings can indicate undefined behavior which can cause this)"); err("Build with ASSERTIONS=2 for more info.");abort(x); }
  5870. function nullFunc_iiii(x) { err("Invalid function pointer called with signature 'iiii'. Perhaps this is an invalid value (e.g. caused by calling a virtual method on a NULL pointer)? Or calling a function with an incorrect type, which will fail? (it is worth building your source files with -Werror (warnings are errors), as warnings can indicate undefined behavior which can cause this)"); err("Build with ASSERTIONS=2 for more info.");abort(x); }
  5871. function nullFunc_jiji(x) { err("Invalid function pointer called with signature 'jiji'. Perhaps this is an invalid value (e.g. caused by calling a virtual method on a NULL pointer)? Or calling a function with an incorrect type, which will fail? (it is worth building your source files with -Werror (warnings are errors), as warnings can indicate undefined behavior which can cause this)"); err("Build with ASSERTIONS=2 for more info.");abort(x); }
  5872. function nullFunc_v(x) { err("Invalid function pointer called with signature 'v'. Perhaps this is an invalid value (e.g. caused by calling a virtual method on a NULL pointer)? Or calling a function with an incorrect type, which will fail? (it is worth building your source files with -Werror (warnings are errors), as warnings can indicate undefined behavior which can cause this)"); err("Build with ASSERTIONS=2 for more info.");abort(x); }
  5873. function nullFunc_vi(x) { err("Invalid function pointer called with signature 'vi'. Perhaps this is an invalid value (e.g. caused by calling a virtual method on a NULL pointer)? Or calling a function with an incorrect type, which will fail? (it is worth building your source files with -Werror (warnings are errors), as warnings can indicate undefined behavior which can cause this)"); err("Build with ASSERTIONS=2 for more info.");abort(x); }
  5874. function nullFunc_vii(x) { err("Invalid function pointer called with signature 'vii'. Perhaps this is an invalid value (e.g. caused by calling a virtual method on a NULL pointer)? Or calling a function with an incorrect type, which will fail? (it is worth building your source files with -Werror (warnings are errors), as warnings can indicate undefined behavior which can cause this)"); err("Build with ASSERTIONS=2 for more info.");abort(x); }
  5875. function nullFunc_viiii(x) { err("Invalid function pointer called with signature 'viiii'. Perhaps this is an invalid value (e.g. caused by calling a virtual method on a NULL pointer)? Or calling a function with an incorrect type, which will fail? (it is worth building your source files with -Werror (warnings are errors), as warnings can indicate undefined behavior which can cause this)"); err("Build with ASSERTIONS=2 for more info.");abort(x); }
  5876. function nullFunc_viiiii(x) { err("Invalid function pointer called with signature 'viiiii'. Perhaps this is an invalid value (e.g. caused by calling a virtual method on a NULL pointer)? Or calling a function with an incorrect type, which will fail? (it is worth building your source files with -Werror (warnings are errors), as warnings can indicate undefined behavior which can cause this)"); err("Build with ASSERTIONS=2 for more info.");abort(x); }
  5877. function nullFunc_viiiiii(x) { err("Invalid function pointer called with signature 'viiiiii'. Perhaps this is an invalid value (e.g. caused by calling a virtual method on a NULL pointer)? Or calling a function with an incorrect type, which will fail? (it is worth building your source files with -Werror (warnings are errors), as warnings can indicate undefined behavior which can cause this)"); err("Build with ASSERTIONS=2 for more info.");abort(x); }
  5878. var asmGlobalArg = {};
  5879. var asmLibraryArg = {
  5880. "abort": abort,
  5881. "setTempRet0": setTempRet0,
  5882. "getTempRet0": getTempRet0,
  5883. "abortStackOverflow": abortStackOverflow,
  5884. "nullFunc_ii": nullFunc_ii,
  5885. "nullFunc_iidiiii": nullFunc_iidiiii,
  5886. "nullFunc_iiii": nullFunc_iiii,
  5887. "nullFunc_jiji": nullFunc_jiji,
  5888. "nullFunc_v": nullFunc_v,
  5889. "nullFunc_vi": nullFunc_vi,
  5890. "nullFunc_vii": nullFunc_vii,
  5891. "nullFunc_viiii": nullFunc_viiii,
  5892. "nullFunc_viiiii": nullFunc_viiiii,
  5893. "nullFunc_viiiiii": nullFunc_viiiiii,
  5894. "___cxa_allocate_exception": ___cxa_allocate_exception,
  5895. "___cxa_begin_catch": ___cxa_begin_catch,
  5896. "___cxa_throw": ___cxa_throw,
  5897. "___cxa_uncaught_exception": ___cxa_uncaught_exception,
  5898. "___exception_addRef": ___exception_addRef,
  5899. "___exception_deAdjust": ___exception_deAdjust,
  5900. "___gxx_personality_v0": ___gxx_personality_v0,
  5901. "___lock": ___lock,
  5902. "___setErrNo": ___setErrNo,
  5903. "___syscall140": ___syscall140,
  5904. "___syscall146": ___syscall146,
  5905. "___syscall54": ___syscall54,
  5906. "___syscall6": ___syscall6,
  5907. "___unlock": ___unlock,
  5908. "_abort": _abort,
  5909. "_emscripten_get_heap_size": _emscripten_get_heap_size,
  5910. "_emscripten_memcpy_big": _emscripten_memcpy_big,
  5911. "_emscripten_resize_heap": _emscripten_resize_heap,
  5912. "abortOnCannotGrowMemory": abortOnCannotGrowMemory,
  5913. "emscripten_realloc_buffer": emscripten_realloc_buffer,
  5914. "flush_NO_FILESYSTEM": flush_NO_FILESYSTEM,
  5915. "tempDoublePtr": tempDoublePtr,
  5916. "DYNAMICTOP_PTR": DYNAMICTOP_PTR
  5917. };
  5918. // EMSCRIPTEN_START_ASM
  5919. var asm =Module["asm"]// EMSCRIPTEN_END_ASM
  5920. (asmGlobalArg, asmLibraryArg, buffer);
  5921. var real___ZSt18uncaught_exceptionv = asm["__ZSt18uncaught_exceptionv"];
  5922. asm["__ZSt18uncaught_exceptionv"] = function() {
  5923. assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  5924. assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  5925. return real___ZSt18uncaught_exceptionv.apply(null, arguments);
  5926. };
  5927. var real____cxa_can_catch = asm["___cxa_can_catch"];
  5928. asm["___cxa_can_catch"] = function() {
  5929. assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  5930. assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  5931. return real____cxa_can_catch.apply(null, arguments);
  5932. };
  5933. var real____cxa_is_pointer_type = asm["___cxa_is_pointer_type"];
  5934. asm["___cxa_is_pointer_type"] = function() {
  5935. assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  5936. assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  5937. return real____cxa_is_pointer_type.apply(null, arguments);
  5938. };
  5939. var real____errno_location = asm["___errno_location"];
  5940. asm["___errno_location"] = function() {
  5941. assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  5942. assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  5943. return real____errno_location.apply(null, arguments);
  5944. };
  5945. var real__earcut = asm["_earcut"];
  5946. asm["_earcut"] = function() {
  5947. assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  5948. assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  5949. return real__earcut.apply(null, arguments);
  5950. };
  5951. var real__fflush = asm["_fflush"];
  5952. asm["_fflush"] = function() {
  5953. assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  5954. assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  5955. return real__fflush.apply(null, arguments);
  5956. };
  5957. var real__free = asm["_free"];
  5958. asm["_free"] = function() {
  5959. assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  5960. assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  5961. return real__free.apply(null, arguments);
  5962. };
  5963. var real__llvm_maxnum_f64 = asm["_llvm_maxnum_f64"];
  5964. asm["_llvm_maxnum_f64"] = function() {
  5965. assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  5966. assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  5967. return real__llvm_maxnum_f64.apply(null, arguments);
  5968. };
  5969. var real__llvm_minnum_f64 = asm["_llvm_minnum_f64"];
  5970. asm["_llvm_minnum_f64"] = function() {
  5971. assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  5972. assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  5973. return real__llvm_minnum_f64.apply(null, arguments);
  5974. };
  5975. var real__malloc = asm["_malloc"];
  5976. asm["_malloc"] = function() {
  5977. assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  5978. assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  5979. return real__malloc.apply(null, arguments);
  5980. };
  5981. var real__sbrk = asm["_sbrk"];
  5982. asm["_sbrk"] = function() {
  5983. assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  5984. assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  5985. return real__sbrk.apply(null, arguments);
  5986. };
  5987. var real_establishStackSpace = asm["establishStackSpace"];
  5988. asm["establishStackSpace"] = function() {
  5989. assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  5990. assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  5991. return real_establishStackSpace.apply(null, arguments);
  5992. };
  5993. var real_stackAlloc = asm["stackAlloc"];
  5994. asm["stackAlloc"] = function() {
  5995. assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  5996. assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  5997. return real_stackAlloc.apply(null, arguments);
  5998. };
  5999. var real_stackRestore = asm["stackRestore"];
  6000. asm["stackRestore"] = function() {
  6001. assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  6002. assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  6003. return real_stackRestore.apply(null, arguments);
  6004. };
  6005. var real_stackSave = asm["stackSave"];
  6006. asm["stackSave"] = function() {
  6007. assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  6008. assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  6009. return real_stackSave.apply(null, arguments);
  6010. };
  6011. Module["asm"] = asm;
  6012. var __ZSt18uncaught_exceptionv = Module["__ZSt18uncaught_exceptionv"] = function() {
  6013. assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  6014. assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  6015. return Module["asm"]["__ZSt18uncaught_exceptionv"].apply(null, arguments)
  6016. };
  6017. var ___cxa_can_catch = Module["___cxa_can_catch"] = function() {
  6018. assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  6019. assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  6020. return Module["asm"]["___cxa_can_catch"].apply(null, arguments)
  6021. };
  6022. var ___cxa_is_pointer_type = Module["___cxa_is_pointer_type"] = function() {
  6023. assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  6024. assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  6025. return Module["asm"]["___cxa_is_pointer_type"].apply(null, arguments)
  6026. };
  6027. var ___errno_location = Module["___errno_location"] = function() {
  6028. assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  6029. assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  6030. return Module["asm"]["___errno_location"].apply(null, arguments)
  6031. };
  6032. var _earcut = Module["_earcut"] = function() {
  6033. assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  6034. assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  6035. return Module["asm"]["_earcut"].apply(null, arguments)
  6036. };
  6037. var _emscripten_replace_memory = Module["_emscripten_replace_memory"] = function() {
  6038. assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  6039. assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  6040. return Module["asm"]["_emscripten_replace_memory"].apply(null, arguments)
  6041. };
  6042. var _fflush = Module["_fflush"] = function() {
  6043. assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  6044. assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  6045. return Module["asm"]["_fflush"].apply(null, arguments)
  6046. };
  6047. var _free = Module["_free"] = function() {
  6048. assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  6049. assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  6050. return Module["asm"]["_free"].apply(null, arguments)
  6051. };
  6052. var _llvm_maxnum_f64 = Module["_llvm_maxnum_f64"] = function() {
  6053. assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  6054. assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  6055. return Module["asm"]["_llvm_maxnum_f64"].apply(null, arguments)
  6056. };
  6057. var _llvm_minnum_f64 = Module["_llvm_minnum_f64"] = function() {
  6058. assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  6059. assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  6060. return Module["asm"]["_llvm_minnum_f64"].apply(null, arguments)
  6061. };
  6062. var _malloc = Module["_malloc"] = function() {
  6063. assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  6064. assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  6065. return Module["asm"]["_malloc"].apply(null, arguments)
  6066. };
  6067. var _memcpy = Module["_memcpy"] = function() {
  6068. assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  6069. assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  6070. return Module["asm"]["_memcpy"].apply(null, arguments)
  6071. };
  6072. var _memset = Module["_memset"] = function() {
  6073. assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  6074. assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  6075. return Module["asm"]["_memset"].apply(null, arguments)
  6076. };
  6077. var _sbrk = Module["_sbrk"] = function() {
  6078. assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  6079. assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  6080. return Module["asm"]["_sbrk"].apply(null, arguments)
  6081. };
  6082. var establishStackSpace = Module["establishStackSpace"] = function() {
  6083. assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  6084. assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  6085. return Module["asm"]["establishStackSpace"].apply(null, arguments)
  6086. };
  6087. var stackAlloc = Module["stackAlloc"] = function() {
  6088. assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  6089. assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  6090. return Module["asm"]["stackAlloc"].apply(null, arguments)
  6091. };
  6092. var stackRestore = Module["stackRestore"] = function() {
  6093. assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  6094. assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  6095. return Module["asm"]["stackRestore"].apply(null, arguments)
  6096. };
  6097. var stackSave = Module["stackSave"] = function() {
  6098. assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  6099. assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  6100. return Module["asm"]["stackSave"].apply(null, arguments)
  6101. };
  6102. var dynCall_ii = Module["dynCall_ii"] = function() {
  6103. assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  6104. assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  6105. return Module["asm"]["dynCall_ii"].apply(null, arguments)
  6106. };
  6107. var dynCall_iidiiii = Module["dynCall_iidiiii"] = function() {
  6108. assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  6109. assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  6110. return Module["asm"]["dynCall_iidiiii"].apply(null, arguments)
  6111. };
  6112. var dynCall_iiii = Module["dynCall_iiii"] = function() {
  6113. assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  6114. assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  6115. return Module["asm"]["dynCall_iiii"].apply(null, arguments)
  6116. };
  6117. var dynCall_jiji = Module["dynCall_jiji"] = function() {
  6118. assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  6119. assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  6120. return Module["asm"]["dynCall_jiji"].apply(null, arguments)
  6121. };
  6122. var dynCall_v = Module["dynCall_v"] = function() {
  6123. assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  6124. assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  6125. return Module["asm"]["dynCall_v"].apply(null, arguments)
  6126. };
  6127. var dynCall_vi = Module["dynCall_vi"] = function() {
  6128. assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  6129. assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  6130. return Module["asm"]["dynCall_vi"].apply(null, arguments)
  6131. };
  6132. var dynCall_vii = Module["dynCall_vii"] = function() {
  6133. assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  6134. assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  6135. return Module["asm"]["dynCall_vii"].apply(null, arguments)
  6136. };
  6137. var dynCall_viiii = Module["dynCall_viiii"] = function() {
  6138. assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  6139. assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  6140. return Module["asm"]["dynCall_viiii"].apply(null, arguments)
  6141. };
  6142. var dynCall_viiiii = Module["dynCall_viiiii"] = function() {
  6143. assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  6144. assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  6145. return Module["asm"]["dynCall_viiiii"].apply(null, arguments)
  6146. };
  6147. var dynCall_viiiiii = Module["dynCall_viiiiii"] = function() {
  6148. assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  6149. assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  6150. return Module["asm"]["dynCall_viiiiii"].apply(null, arguments)
  6151. };
  6152. // === Auto-generated postamble setup entry stuff ===
  6153. Module['asm'] = asm;
  6154. if (!Module["intArrayFromString"]) Module["intArrayFromString"] = function() { abort("'intArrayFromString' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6155. if (!Module["intArrayToString"]) Module["intArrayToString"] = function() { abort("'intArrayToString' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6156. Module["ccall"] = ccall;
  6157. Module["cwrap"] = cwrap;
  6158. if (!Module["setValue"]) Module["setValue"] = function() { abort("'setValue' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6159. Module["getValue"] = getValue;
  6160. if (!Module["allocate"]) Module["allocate"] = function() { abort("'allocate' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6161. if (!Module["getMemory"]) Module["getMemory"] = function() { abort("'getMemory' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ). Alternatively, forcing filesystem support (-s FORCE_FILESYSTEM=1) can export this for you"); };
  6162. if (!Module["AsciiToString"]) Module["AsciiToString"] = function() { abort("'AsciiToString' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6163. if (!Module["stringToAscii"]) Module["stringToAscii"] = function() { abort("'stringToAscii' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6164. if (!Module["UTF8ArrayToString"]) Module["UTF8ArrayToString"] = function() { abort("'UTF8ArrayToString' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6165. if (!Module["UTF8ToString"]) Module["UTF8ToString"] = function() { abort("'UTF8ToString' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6166. if (!Module["stringToUTF8Array"]) Module["stringToUTF8Array"] = function() { abort("'stringToUTF8Array' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6167. if (!Module["stringToUTF8"]) Module["stringToUTF8"] = function() { abort("'stringToUTF8' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6168. if (!Module["lengthBytesUTF8"]) Module["lengthBytesUTF8"] = function() { abort("'lengthBytesUTF8' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6169. if (!Module["UTF16ToString"]) Module["UTF16ToString"] = function() { abort("'UTF16ToString' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6170. if (!Module["stringToUTF16"]) Module["stringToUTF16"] = function() { abort("'stringToUTF16' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6171. if (!Module["lengthBytesUTF16"]) Module["lengthBytesUTF16"] = function() { abort("'lengthBytesUTF16' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6172. if (!Module["UTF32ToString"]) Module["UTF32ToString"] = function() { abort("'UTF32ToString' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6173. if (!Module["stringToUTF32"]) Module["stringToUTF32"] = function() { abort("'stringToUTF32' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6174. if (!Module["lengthBytesUTF32"]) Module["lengthBytesUTF32"] = function() { abort("'lengthBytesUTF32' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6175. if (!Module["allocateUTF8"]) Module["allocateUTF8"] = function() { abort("'allocateUTF8' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6176. if (!Module["stackTrace"]) Module["stackTrace"] = function() { abort("'stackTrace' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6177. if (!Module["addOnPreRun"]) Module["addOnPreRun"] = function() { abort("'addOnPreRun' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6178. if (!Module["addOnInit"]) Module["addOnInit"] = function() { abort("'addOnInit' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6179. if (!Module["addOnPreMain"]) Module["addOnPreMain"] = function() { abort("'addOnPreMain' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6180. if (!Module["addOnExit"]) Module["addOnExit"] = function() { abort("'addOnExit' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6181. if (!Module["addOnPostRun"]) Module["addOnPostRun"] = function() { abort("'addOnPostRun' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6182. if (!Module["writeStringToMemory"]) Module["writeStringToMemory"] = function() { abort("'writeStringToMemory' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6183. if (!Module["writeArrayToMemory"]) Module["writeArrayToMemory"] = function() { abort("'writeArrayToMemory' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6184. if (!Module["writeAsciiToMemory"]) Module["writeAsciiToMemory"] = function() { abort("'writeAsciiToMemory' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6185. if (!Module["addRunDependency"]) Module["addRunDependency"] = function() { abort("'addRunDependency' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ). Alternatively, forcing filesystem support (-s FORCE_FILESYSTEM=1) can export this for you"); };
  6186. if (!Module["removeRunDependency"]) Module["removeRunDependency"] = function() { abort("'removeRunDependency' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ). Alternatively, forcing filesystem support (-s FORCE_FILESYSTEM=1) can export this for you"); };
  6187. if (!Module["ENV"]) Module["ENV"] = function() { abort("'ENV' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6188. if (!Module["FS"]) Module["FS"] = function() { abort("'FS' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6189. if (!Module["FS_createFolder"]) Module["FS_createFolder"] = function() { abort("'FS_createFolder' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ). Alternatively, forcing filesystem support (-s FORCE_FILESYSTEM=1) can export this for you"); };
  6190. if (!Module["FS_createPath"]) Module["FS_createPath"] = function() { abort("'FS_createPath' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ). Alternatively, forcing filesystem support (-s FORCE_FILESYSTEM=1) can export this for you"); };
  6191. if (!Module["FS_createDataFile"]) Module["FS_createDataFile"] = function() { abort("'FS_createDataFile' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ). Alternatively, forcing filesystem support (-s FORCE_FILESYSTEM=1) can export this for you"); };
  6192. if (!Module["FS_createPreloadedFile"]) Module["FS_createPreloadedFile"] = function() { abort("'FS_createPreloadedFile' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ). Alternatively, forcing filesystem support (-s FORCE_FILESYSTEM=1) can export this for you"); };
  6193. if (!Module["FS_createLazyFile"]) Module["FS_createLazyFile"] = function() { abort("'FS_createLazyFile' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ). Alternatively, forcing filesystem support (-s FORCE_FILESYSTEM=1) can export this for you"); };
  6194. if (!Module["FS_createLink"]) Module["FS_createLink"] = function() { abort("'FS_createLink' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ). Alternatively, forcing filesystem support (-s FORCE_FILESYSTEM=1) can export this for you"); };
  6195. if (!Module["FS_createDevice"]) Module["FS_createDevice"] = function() { abort("'FS_createDevice' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ). Alternatively, forcing filesystem support (-s FORCE_FILESYSTEM=1) can export this for you"); };
  6196. if (!Module["FS_unlink"]) Module["FS_unlink"] = function() { abort("'FS_unlink' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ). Alternatively, forcing filesystem support (-s FORCE_FILESYSTEM=1) can export this for you"); };
  6197. if (!Module["GL"]) Module["GL"] = function() { abort("'GL' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6198. if (!Module["dynamicAlloc"]) Module["dynamicAlloc"] = function() { abort("'dynamicAlloc' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6199. if (!Module["warnOnce"]) Module["warnOnce"] = function() { abort("'warnOnce' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6200. if (!Module["loadDynamicLibrary"]) Module["loadDynamicLibrary"] = function() { abort("'loadDynamicLibrary' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6201. if (!Module["loadWebAssemblyModule"]) Module["loadWebAssemblyModule"] = function() { abort("'loadWebAssemblyModule' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6202. if (!Module["getLEB"]) Module["getLEB"] = function() { abort("'getLEB' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6203. if (!Module["getFunctionTables"]) Module["getFunctionTables"] = function() { abort("'getFunctionTables' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6204. if (!Module["alignFunctionTables"]) Module["alignFunctionTables"] = function() { abort("'alignFunctionTables' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6205. if (!Module["registerFunctions"]) Module["registerFunctions"] = function() { abort("'registerFunctions' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6206. if (!Module["addFunction"]) Module["addFunction"] = function() { abort("'addFunction' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6207. if (!Module["removeFunction"]) Module["removeFunction"] = function() { abort("'removeFunction' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6208. if (!Module["getFuncWrapper"]) Module["getFuncWrapper"] = function() { abort("'getFuncWrapper' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6209. if (!Module["prettyPrint"]) Module["prettyPrint"] = function() { abort("'prettyPrint' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6210. if (!Module["makeBigInt"]) Module["makeBigInt"] = function() { abort("'makeBigInt' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6211. if (!Module["dynCall"]) Module["dynCall"] = function() { abort("'dynCall' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6212. if (!Module["getCompilerSetting"]) Module["getCompilerSetting"] = function() { abort("'getCompilerSetting' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6213. if (!Module["stackSave"]) Module["stackSave"] = function() { abort("'stackSave' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6214. if (!Module["stackRestore"]) Module["stackRestore"] = function() { abort("'stackRestore' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6215. if (!Module["stackAlloc"]) Module["stackAlloc"] = function() { abort("'stackAlloc' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6216. if (!Module["establishStackSpace"]) Module["establishStackSpace"] = function() { abort("'establishStackSpace' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6217. if (!Module["print"]) Module["print"] = function() { abort("'print' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6218. if (!Module["printErr"]) Module["printErr"] = function() { abort("'printErr' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6219. if (!Module["getTempRet0"]) Module["getTempRet0"] = function() { abort("'getTempRet0' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6220. if (!Module["setTempRet0"]) Module["setTempRet0"] = function() { abort("'setTempRet0' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6221. if (!Module["Pointer_stringify"]) Module["Pointer_stringify"] = function() { abort("'Pointer_stringify' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };if (!Module["ALLOC_NORMAL"]) Object.defineProperty(Module, "ALLOC_NORMAL", { get: function() { abort("'ALLOC_NORMAL' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); } });
  6222. if (!Module["ALLOC_STACK"]) Object.defineProperty(Module, "ALLOC_STACK", { get: function() { abort("'ALLOC_STACK' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); } });
  6223. if (!Module["ALLOC_DYNAMIC"]) Object.defineProperty(Module, "ALLOC_DYNAMIC", { get: function() { abort("'ALLOC_DYNAMIC' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); } });
  6224. if (!Module["ALLOC_NONE"]) Object.defineProperty(Module, "ALLOC_NONE", { get: function() { abort("'ALLOC_NONE' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); } });
  6225. /**
  6226. * @constructor
  6227. * @extends {Error}
  6228. * @this {ExitStatus}
  6229. */
  6230. function ExitStatus(status) {
  6231. this.name = "ExitStatus";
  6232. this.message = "Program terminated with exit(" + status + ")";
  6233. this.status = status;
  6234. } ExitStatus.prototype = new Error();
  6235. ExitStatus.prototype.constructor = ExitStatus;
  6236. dependenciesFulfilled = function runCaller() {
  6237. // If run has never been called, and we should call run (INVOKE_RUN is true, and Module.noInitialRun is not false)
  6238. if (!Module['calledRun']) run();
  6239. if (!Module['calledRun']) dependenciesFulfilled = runCaller; // try this again later, after new deps are fulfilled
  6240. };
  6241. /** @type {function(Array=)} */
  6242. function run(args) {
  6243. args = args || Module['arguments'];
  6244. if (runDependencies > 0) {
  6245. return;
  6246. }
  6247. writeStackCookie();
  6248. preRun();
  6249. if (runDependencies > 0) return; // a preRun added a dependency, run will be called later
  6250. if (Module['calledRun']) return; // run may have just been called through dependencies being fulfilled just in this very frame
  6251. function doRun() {
  6252. if (Module['calledRun']) return; // run may have just been called while the async setStatus time below was happening
  6253. Module['calledRun'] = true;
  6254. if (ABORT) return;
  6255. ensureInitRuntime();
  6256. preMain();
  6257. if (Module['onRuntimeInitialized']) Module['onRuntimeInitialized']();
  6258. assert(!Module['_main'], 'compiled without a main, but one is present. if you added it from JS, use Module["onRuntimeInitialized"]');
  6259. postRun();
  6260. }
  6261. if (Module['setStatus']) {
  6262. Module['setStatus']('Running...');
  6263. setTimeout(function() {
  6264. setTimeout(function() {
  6265. Module['setStatus']('');
  6266. }, 1);
  6267. doRun();
  6268. }, 1);
  6269. } else {
  6270. doRun();
  6271. }
  6272. checkStackCookie();
  6273. }
  6274. Module['run'] = run;
  6275. var abortDecorators = [];
  6276. function abort(what) {
  6277. if (Module['onAbort']) {
  6278. Module['onAbort'](what);
  6279. }
  6280. if (what !== undefined) {
  6281. //out(what);
  6282. //err(what);
  6283. what = '"' + what + '"';
  6284. } else {
  6285. what = '';
  6286. }
  6287. ABORT = true;
  6288. var extra = '';
  6289. var output = 'abort(' + what + ') at ' + stackTrace() + extra;
  6290. if (abortDecorators) {
  6291. abortDecorators.forEach(function(decorator) {
  6292. output = decorator(output, what);
  6293. });
  6294. }
  6295. throw output;
  6296. }
  6297. Module['abort'] = abort;
  6298. if (Module['preInit']) {
  6299. if (typeof Module['preInit'] == 'function') Module['preInit'] = [Module['preInit']];
  6300. while (Module['preInit'].length > 0) {
  6301. Module['preInit'].pop()();
  6302. }
  6303. }
  6304. Module["noExitRuntime"] = true;
  6305. run();
  6306. } else {
  6307. var Module = null;
  6308. }
  6309. var earcutWasm = Module;
  6310. // {{MODULE_ADDITIONS}}
  6311. var earcutWasmReady = false;
  6312. if (defined.defined(earcutWasm)) {
  6313. earcutWasm.onRuntimeInitialized = function () {
  6314. earcutWasmReady = true;
  6315. };
  6316. var earcutwasm = earcutWasm.cwrap('earcut','number',['number','number','number','number','number','number']);
  6317. }
  6318. var layout$3 = createLayout([
  6319. {name: 'a_pos', components: 2, type: 'Int16'}
  6320. ], 4);
  6321. var members$1 = layout$3.members;
  6322. var EARCUT_MAX_RINGS = 500;
  6323. var FillBucket = function FillBucket(options) {
  6324. this.zoom = options.zoom;
  6325. this.overscaling = options.overscaling;
  6326. this.layers = options.layers;
  6327. this.layerIds = this.layers.map(function (layer) {
  6328. return layer.id;
  6329. });
  6330. this.index = options.index;
  6331. this.hasPattern = false;
  6332. this.patternFeatures = [];
  6333. this.layoutVertexArray = new StructArrayLayout2i4();
  6334. this.indexArray = new StructArrayLayout3ui6();
  6335. this.indexArray2 = new StructArrayLayout2ui4();
  6336. this.programConfigurations = new ProgramConfigurationSet(members$1, options.layers, options.zoom);
  6337. this.segments = new SegmentVector();
  6338. this.segments2 = new SegmentVector();
  6339. this.stateDependentLayerIds = this.layers.filter(function (l) {
  6340. return l.isStateDependent();
  6341. }).map(function (l) {
  6342. return l.id;
  6343. });
  6344. };
  6345. FillBucket.prototype.populate = function populate(features, options) {
  6346. this.hasPattern = hasPattern('fill', this.layers, options);
  6347. var bucketFeatures = [];
  6348. for (var i = 0, list = features; i < list.length; i += 1) {
  6349. var ref = list[i];
  6350. var feature = ref.feature;
  6351. var index = ref.index;
  6352. var sourceLayerIndex = ref.sourceLayerIndex;
  6353. if (!this.layers[0]._featureFilter(new EvaluationParameters$1(0), feature)) {
  6354. continue;
  6355. }
  6356. var geometry = loadGeometry(feature);
  6357. var sortKey =
  6358. undefined;
  6359. var bucketFeature = {
  6360. id: feature.id,
  6361. properties: feature.properties,
  6362. type: feature.type,
  6363. sourceLayerIndex: sourceLayerIndex,
  6364. index: index,
  6365. geometry: geometry,
  6366. patterns: {},
  6367. sortKey: sortKey
  6368. };
  6369. bucketFeatures.push(bucketFeature);
  6370. }
  6371. for (var i$1 = 0, list$1 = bucketFeatures; i$1 < list$1.length; i$1 += 1) {
  6372. var bucketFeature$1 = list$1[i$1];
  6373. var ref$1 = bucketFeature$1;
  6374. var geometry$1 = ref$1.geometry;
  6375. var index$1 = ref$1.index;
  6376. var sourceLayerIndex$1 = ref$1.sourceLayerIndex;
  6377. if (this.hasPattern) {
  6378. var patternFeature = addPatternDependencies('fill', this.layers, bucketFeature$1, this.zoom, options);
  6379. // pattern features are added only once the pattern is loaded into the image atlas
  6380. // so are stored during populate until later updated with positions by tile worker in addFeatures
  6381. this.patternFeatures.push(patternFeature);
  6382. } else {
  6383. this.addFeature(bucketFeature$1, geometry$1, index$1, {}, options.indexData);
  6384. }
  6385. var feature$1 = features[index$1].feature;
  6386. options.featureIndex.insert(feature$1, geometry$1, index$1, sourceLayerIndex$1, this.index);
  6387. }
  6388. };
  6389. FillBucket.prototype.update = function update(states, vtLayer, imagePositions) {
  6390. if (!this.stateDependentLayers.length) {
  6391. return;
  6392. }
  6393. this.programConfigurations.updatePaintArrays(states, vtLayer, this.stateDependentLayers, imagePositions);
  6394. };
  6395. FillBucket.prototype.addFeatures = function addFeatures(options, imagePositions) {
  6396. for (var i = 0, list = this.patternFeatures; i < list.length; i += 1) {
  6397. var feature = list[i];
  6398. this.addFeature(feature, feature.geometry, feature.index, imagePositions);
  6399. }
  6400. };
  6401. FillBucket.prototype.isEmpty = function isEmpty() {
  6402. return this.layoutVertexArray.length === 0;
  6403. };
  6404. FillBucket.prototype.uploadPending = function uploadPending() {
  6405. return !this.uploaded || this.programConfigurations.needsUpload;
  6406. };
  6407. FillBucket.prototype.upload = function upload(context) {
  6408. if (!this.uploaded) {
  6409. this.layoutVertexBuffer = context.createVertexBuffer(this.layoutVertexArray, members$1);
  6410. this.indexBuffer = context.createIndexBuffer(this.indexArray);
  6411. this.indexBuffer2 = context.createIndexBuffer(this.indexArray2);
  6412. }
  6413. this.programConfigurations.upload(context);
  6414. this.uploaded = true;
  6415. };
  6416. FillBucket.prototype.destroy = function destroy() {
  6417. if (!this.layoutVertexBuffer) {
  6418. return;
  6419. }
  6420. this.layoutVertexBuffer.destroy();
  6421. this.indexBuffer.destroy();
  6422. this.indexBuffer2.destroy();
  6423. this.programConfigurations.destroy();
  6424. this.segments.destroy();
  6425. this.segments2.destroy();
  6426. };
  6427. FillBucket.prototype.clear = function clear() {
  6428. if (defined.defined(this.layoutVertexArray)) {
  6429. this.layoutVertexArray = null;
  6430. }
  6431. if (defined.defined(this.indexArray)) {
  6432. this.indexArray = null;
  6433. }
  6434. if (defined.defined(this.indexArray2)) {
  6435. this.indexArray2 = null;
  6436. }
  6437. };
  6438. FillBucket.prototype.addFeature = function addFeature(feature, geometry, index, imagePositions, indexData) {
  6439. for (var i$4 = 0, list$2 = classifyRings(geometry, EARCUT_MAX_RINGS); i$4 < list$2.length; i$4 += 1) {
  6440. var polygon = list$2[i$4];
  6441. var numVertices = 0;
  6442. for (var i$2 = 0, list = polygon; i$2 < list.length; i$2 += 1) {
  6443. var ring = list[i$2];
  6444. numVertices += ring.length;
  6445. }
  6446. var triangleSegment = this.segments.prepareSegment(numVertices, this.layoutVertexArray, this.indexArray);
  6447. var triangleIndex = triangleSegment.vertexLength;
  6448. var flattened = [];
  6449. var holeIndices = [];
  6450. for (var i$3 = 0, list$1 = polygon; i$3 < list$1.length; i$3 += 1) {
  6451. var ring$1 = list$1[i$3];
  6452. if (ring$1.length === 0) {
  6453. continue;
  6454. }
  6455. if (ring$1 !== polygon[0]) {
  6456. holeIndices.push(flattened.length / 2);
  6457. }
  6458. var lineSegment = this.segments2.prepareSegment(ring$1.length, this.layoutVertexArray, this.indexArray2);
  6459. var lineIndex = lineSegment.vertexLength;
  6460. this.layoutVertexArray.emplaceBack(ring$1[0].x, ring$1[0].y);
  6461. this.indexArray2.emplaceBack(lineIndex + ring$1.length - 1, lineIndex);
  6462. flattened.push(ring$1[0].x);
  6463. flattened.push(ring$1[0].y);
  6464. for (var i = 1; i < ring$1.length; i++) {
  6465. this.layoutVertexArray.emplaceBack(ring$1[i].x, ring$1[i].y);
  6466. this.indexArray2.emplaceBack(lineIndex + i - 1, lineIndex + i);
  6467. flattened.push(ring$1[i].x);
  6468. flattened.push(ring$1[i].y);
  6469. }
  6470. lineSegment.vertexLength += ring$1.length;
  6471. lineSegment.primitiveLength += ring$1.length;
  6472. }
  6473. var indices;
  6474. if (defined.defined(indexData) && defined.defined(indexData[feature.id])) {
  6475. indices = indexData[feature.id];
  6476. } else if (earcutWasmReady === true) {
  6477. var data = new Int32Array(flattened);
  6478. var dataLength = data.length;
  6479. var offset = earcutWasm._malloc(Int32Array.BYTES_PER_ELEMENT * dataLength); //开辟内存
  6480. earcutWasm.HEAP32.set(data, offset / Int32Array.BYTES_PER_ELEMENT); //设置值
  6481. var hole = new Int32Array(holeIndices);
  6482. var holeLength = hole.length;
  6483. var offset1 = earcutWasm._malloc(Int32Array.BYTES_PER_ELEMENT * holeLength); //开辟内存
  6484. earcutWasm.HEAP32.set(hole, offset1 / Int32Array.BYTES_PER_ELEMENT); //设置值
  6485. var res = new Int32Array(dataLength * 10);
  6486. var offset2 = earcutWasm._malloc(Int32Array.BYTES_PER_ELEMENT * dataLength * 10); //开辟内存
  6487. earcutWasm.HEAP32.set(res, offset2 / Int32Array.BYTES_PER_ELEMENT);
  6488. var len = earcutwasm(offset, dataLength, offset1, holeLength, 2, offset2);
  6489. var result = new Int32Array(earcutWasm.HEAP32.buffer, offset2, len);
  6490. indices = new Int32Array(result);
  6491. earcutWasm._free(offset);
  6492. earcutWasm._free(offset1);
  6493. earcutWasm._free(offset2);
  6494. } else {
  6495. indices = earcut2_2_1.earcut(flattened, holeIndices);
  6496. }
  6497. for (var i$1 = 0; i$1 < indices.length; i$1 += 3) {
  6498. this.indexArray.emplaceBack(
  6499. triangleIndex + indices[i$1],
  6500. triangleIndex + indices[i$1 + 1],
  6501. triangleIndex + indices[i$1 + 2]);
  6502. }
  6503. triangleSegment.vertexLength += numVertices;
  6504. triangleSegment.primitiveLength += indices.length / 3;
  6505. }
  6506. this.programConfigurations.populatePaintArrays(this.layoutVertexArray.length, feature, index, imagePositions);
  6507. };
  6508. WebWorkerTransfer.register('FillBucket', FillBucket, {omit: ['layers', 'patternFeatures']});
  6509. var Struct = function Struct(structArray , index ) {
  6510. (this )._structArray = structArray;
  6511. this._pos1 = index * this.size;
  6512. this._pos2 = this._pos1 / 2;
  6513. this._pos4 = this._pos1 / 4;
  6514. this._pos8 = this._pos1 / 8;
  6515. };
  6516. var DEFAULT_CAPACITY$1 = 128;
  6517. var RESIZE_MULTIPLIER$1 = 5;
  6518. /**
  6519. * `StructArray` provides an abstraction over `ArrayBuffer` and `TypedArray`
  6520. * making it behave like an array of typed structs.
  6521. *
  6522. * Conceptually, a StructArray is comprised of elements, i.e., instances of its
  6523. * associated struct type. Each particular struct type, together with an
  6524. * alignment size, determines the memory layout of a StructArray whose elements
  6525. * are of that type. Thus, for each such layout that we need, we have
  6526. * a corrseponding StructArrayLayout class, inheriting from StructArray and
  6527. * implementing `emplaceBack()` and `_refreshViews()`.
  6528. *
  6529. * In some cases, where we need to access particular elements of a StructArray,
  6530. * we implement a more specific subclass that inherits from one of the
  6531. * StructArrayLayouts and adds a `get(i): T` accessor that returns a structured
  6532. * object whose properties are proxies into the underlying memory space for the
  6533. * i-th element. This affords the convience of working with (seemingly) plain
  6534. * Javascript objects without the overhead of serializing/deserializing them
  6535. * into ArrayBuffers for efficient web worker transfer.
  6536. *
  6537. * @private
  6538. */
  6539. var StructArray$1 = function StructArray() {
  6540. this.isTransferred = false;
  6541. this.capacity = -1;
  6542. this.resize(0);
  6543. };
  6544. /**
  6545. * Serialize a StructArray instance.Serializes both the raw data and the
  6546. * metadata needed to reconstruct the StructArray base class during
  6547. * deserialization.
  6548. */
  6549. StructArray$1.serialize = function serialize (array, transferables) {
  6550. //assert_1(!array.isTransferred);
  6551. if(array.isTransferred){
  6552. console.log("StructArray array.isTransferred.");
  6553. }
  6554. array._trim();
  6555. if (transferables) {
  6556. array.isTransferred = true;
  6557. transferables.push(array.arrayBuffer);
  6558. }
  6559. return {
  6560. length: array.length,
  6561. arrayBuffer: array.arrayBuffer,
  6562. };
  6563. };
  6564. StructArray$1.deserialize = function deserialize (input ) {
  6565. var structArray = Object.create(this.prototype);
  6566. structArray.arrayBuffer = input.arrayBuffer;
  6567. structArray.length = input.length;
  6568. structArray.capacity = input.arrayBuffer.byteLength / structArray.bytesPerElement;
  6569. structArray._refreshViews();
  6570. return structArray;
  6571. };
  6572. /**
  6573. * Resize the array to discard unused capacity.
  6574. */
  6575. StructArray$1.prototype._trim = function _trim () {
  6576. if (this.length !== this.capacity) {
  6577. this.capacity = this.length;
  6578. this.arrayBuffer = this.arrayBuffer.slice(0, this.length * this.bytesPerElement);
  6579. this._refreshViews();
  6580. }
  6581. };
  6582. /**
  6583. * Resets the the length of the array to 0 without de-allocating capcacity.
  6584. */
  6585. StructArray$1.prototype.clear = function clear () {
  6586. this.length = 0;
  6587. };
  6588. /**
  6589. * Resize the array.
  6590. * If `n` is greater than the current length then additional elements with undefined values are added.
  6591. * If `n` is less than the current length then the array will be reduced to the first `n` elements.
  6592. * @param {number} n The new size of the array.
  6593. */
  6594. StructArray$1.prototype.resize = function resize (n ) {
  6595. //assert_1(!this.isTransferred);
  6596. this.reserve(n);
  6597. this.length = n;
  6598. };
  6599. /**
  6600. * Indicate a planned increase in size, so that any necessary allocation may
  6601. * be done once, ahead of time.
  6602. * @param {number} n The expected size of the array.
  6603. */
  6604. StructArray$1.prototype.reserve = function reserve (n ) {
  6605. if (n > this.capacity) {
  6606. this.capacity = Math.max(n, Math.floor(this.capacity * RESIZE_MULTIPLIER$1), DEFAULT_CAPACITY$1);
  6607. this.arrayBuffer = new ArrayBuffer(this.capacity * this.bytesPerElement);
  6608. var oldUint8Array = this.uint8;
  6609. this._refreshViews();
  6610. if (oldUint8Array) { this.uint8.set(oldUint8Array); }
  6611. }
  6612. };
  6613. /**
  6614. * Create TypedArray views for the current ArrayBuffer.
  6615. */
  6616. StructArray$1.prototype._refreshViews = function _refreshViews () {
  6617. throw new Error('_refreshViews() must be implemented by each concrete StructArray layout');
  6618. };
  6619. /**
  6620. * Implementation of the StructArray layout:
  6621. * [0]: Uint32[1]
  6622. * [4]: Uint16[2]
  6623. *
  6624. * @private
  6625. */
  6626. var StructArrayLayout1ul2ui8 = /*@__PURE__*/(function (StructArray) {
  6627. function StructArrayLayout1ul2ui8 () {
  6628. StructArray.apply(this, arguments);
  6629. }
  6630. if ( StructArray ) StructArrayLayout1ul2ui8.__proto__ = StructArray;
  6631. StructArrayLayout1ul2ui8.prototype = Object.create( StructArray && StructArray.prototype );
  6632. StructArrayLayout1ul2ui8.prototype.constructor = StructArrayLayout1ul2ui8;
  6633. StructArrayLayout1ul2ui8.prototype._refreshViews = function _refreshViews () {
  6634. this.uint8 = new Uint8Array(this.arrayBuffer);
  6635. this.uint32 = new Uint32Array(this.arrayBuffer);
  6636. this.uint16 = new Uint16Array(this.arrayBuffer);
  6637. };
  6638. StructArrayLayout1ul2ui8.prototype.emplaceBack = function emplaceBack (v0 , v1 , v2 ) {
  6639. var i = this.length;
  6640. this.resize(i + 1);
  6641. return this.emplace(i, v0, v1, v2);
  6642. };
  6643. StructArrayLayout1ul2ui8.prototype.emplace = function emplace (i , v0 , v1 , v2 ) {
  6644. var o4 = i * 2;
  6645. var o2 = i * 4;
  6646. this.uint32[o4 + 0] = v0;
  6647. this.uint16[o2 + 2] = v1;
  6648. this.uint16[o2 + 3] = v2;
  6649. return i;
  6650. };
  6651. return StructArrayLayout1ul2ui8;
  6652. }(StructArray$1));
  6653. StructArrayLayout1ul2ui8.prototype.bytesPerElement = 8;
  6654. var FeatureIndexStruct = /*@__PURE__*/(function (Struct) {
  6655. function FeatureIndexStruct () {
  6656. Struct.apply(this, arguments);
  6657. }
  6658. if ( Struct ) FeatureIndexStruct.__proto__ = Struct;
  6659. FeatureIndexStruct.prototype = Object.create( Struct && Struct.prototype );
  6660. FeatureIndexStruct.prototype.constructor = FeatureIndexStruct;
  6661. var prototypeAccessors$5 = { featureIndex: { configurable: true },sourceLayerIndex: { configurable: true },bucketIndex: { configurable: true } };
  6662. prototypeAccessors$5.featureIndex.get = function () { return this._structArray.uint32[this._pos4 + 0]; };
  6663. prototypeAccessors$5.featureIndex.set = function (x ) { this._structArray.uint32[this._pos4 + 0] = x; };
  6664. prototypeAccessors$5.sourceLayerIndex.get = function () { return this._structArray.uint16[this._pos2 + 2]; };
  6665. prototypeAccessors$5.sourceLayerIndex.set = function (x ) { this._structArray.uint16[this._pos2 + 2] = x; };
  6666. prototypeAccessors$5.bucketIndex.get = function () { return this._structArray.uint16[this._pos2 + 3]; };
  6667. prototypeAccessors$5.bucketIndex.set = function (x ) { this._structArray.uint16[this._pos2 + 3] = x; };
  6668. Object.defineProperties( FeatureIndexStruct.prototype, prototypeAccessors$5 );
  6669. return FeatureIndexStruct;
  6670. }(Struct));
  6671. FeatureIndexStruct.prototype.size = 8;
  6672. /**
  6673. * @private
  6674. */
  6675. var FeatureIndexArray = /*@__PURE__*/(function (StructArrayLayout1ul2ui8) {
  6676. function FeatureIndexArray () {
  6677. StructArrayLayout1ul2ui8.apply(this, arguments);
  6678. }
  6679. if ( StructArrayLayout1ul2ui8 ) FeatureIndexArray.__proto__ = StructArrayLayout1ul2ui8;
  6680. FeatureIndexArray.prototype = Object.create( StructArrayLayout1ul2ui8 && StructArrayLayout1ul2ui8.prototype );
  6681. FeatureIndexArray.prototype.constructor = FeatureIndexArray;
  6682. FeatureIndexArray.prototype.get = function get (index ) {
  6683. //assert_1(!this.isTransferred);
  6684. return new FeatureIndexStruct(this, index);
  6685. };
  6686. return FeatureIndexArray;
  6687. }(StructArrayLayout1ul2ui8));
  6688. WebWorkerTransfer.register('FeatureIndexArray', FeatureIndexArray, {omit: ['layers', 'patternFeatures']});
  6689. var arrayTypes = {
  6690. FeatureIndexArray : FeatureIndexArray
  6691. };
  6692. /**
  6693. * A standalone point geometry with useful accessor, comparison, and
  6694. * modification methods.
  6695. *
  6696. * @class Point
  6697. * @param {Number} x the x-coordinate. this could be longitude or screen
  6698. * pixels, or any other sort of unit.
  6699. * @param {Number} y the y-coordinate. this could be latitude or screen
  6700. * pixels, or any other sort of unit.
  6701. * @example
  6702. * var point = new Point(-77, 38);
  6703. */
  6704. function Point(x, y) {
  6705. this.x = x;
  6706. this.y = y;
  6707. }
  6708. Point.prototype = {
  6709. /**
  6710. * Clone this point, returning a new point that can be modified
  6711. * without affecting the old one.
  6712. * @return {Point} the clone
  6713. */
  6714. clone: function() { return new Point(this.x, this.y); },
  6715. /**
  6716. * Add this point's x & y coordinates to another point,
  6717. * yielding a new point.
  6718. * @param {Point} p the other point
  6719. * @return {Point} output point
  6720. */
  6721. add: function(p) { return this.clone()._add(p); },
  6722. /**
  6723. * Subtract this point's x & y coordinates to from point,
  6724. * yielding a new point.
  6725. * @param {Point} p the other point
  6726. * @return {Point} output point
  6727. */
  6728. sub: function(p) { return this.clone()._sub(p); },
  6729. /**
  6730. * Multiply this point's x & y coordinates by point,
  6731. * yielding a new point.
  6732. * @param {Point} p the other point
  6733. * @return {Point} output point
  6734. */
  6735. multByPoint: function(p) { return this.clone()._multByPoint(p); },
  6736. /**
  6737. * Divide this point's x & y coordinates by point,
  6738. * yielding a new point.
  6739. * @param {Point} p the other point
  6740. * @return {Point} output point
  6741. */
  6742. divByPoint: function(p) { return this.clone()._divByPoint(p); },
  6743. /**
  6744. * Multiply this point's x & y coordinates by a factor,
  6745. * yielding a new point.
  6746. * @param {Point} k factor
  6747. * @return {Point} output point
  6748. */
  6749. mult: function(k) { return this.clone()._mult(k); },
  6750. /**
  6751. * Divide this point's x & y coordinates by a factor,
  6752. * yielding a new point.
  6753. * @param {Point} k factor
  6754. * @return {Point} output point
  6755. */
  6756. div: function(k) { return this.clone()._div(k); },
  6757. /**
  6758. * Rotate this point around the 0, 0 origin by an angle a,
  6759. * given in radians
  6760. * @param {Number} a angle to rotate around, in radians
  6761. * @return {Point} output point
  6762. */
  6763. rotate: function(a) { return this.clone()._rotate(a); },
  6764. /**
  6765. * Rotate this point around p point by an angle a,
  6766. * given in radians
  6767. * @param {Number} a angle to rotate around, in radians
  6768. * @param {Point} p Point to rotate around
  6769. * @return {Point} output point
  6770. */
  6771. rotateAround: function(a,p) { return this.clone()._rotateAround(a,p); },
  6772. /**
  6773. * Multiply this point by a 4x1 transformation matrix
  6774. * @param {Array<Number>} m transformation matrix
  6775. * @return {Point} output point
  6776. */
  6777. matMult: function(m) { return this.clone()._matMult(m); },
  6778. /**
  6779. * Calculate this point but as a unit vector from 0, 0, meaning
  6780. * that the distance from the resulting point to the 0, 0
  6781. * coordinate will be equal to 1 and the angle from the resulting
  6782. * point to the 0, 0 coordinate will be the same as before.
  6783. * @return {Point} unit vector point
  6784. */
  6785. unit: function() { return this.clone()._unit(); },
  6786. /**
  6787. * Compute a perpendicular point, where the new y coordinate
  6788. * is the old x coordinate and the new x coordinate is the old y
  6789. * coordinate multiplied by -1
  6790. * @return {Point} perpendicular point
  6791. */
  6792. perp: function() { return this.clone()._perp(); },
  6793. /**
  6794. * Return a version of this point with the x & y coordinates
  6795. * rounded to integers.
  6796. * @return {Point} rounded point
  6797. */
  6798. round: function() { return this.clone()._round(); },
  6799. /**
  6800. * Return the magitude of this point: this is the Euclidean
  6801. * distance from the 0, 0 coordinate to this point's x and y
  6802. * coordinates.
  6803. * @return {Number} magnitude
  6804. */
  6805. mag: function() {
  6806. return Math.sqrt(this.x * this.x + this.y * this.y);
  6807. },
  6808. /**
  6809. * Judge whether this point is equal to another point, returning
  6810. * true or false.
  6811. * @param {Point} other the other point
  6812. * @return {boolean} whether the points are equal
  6813. */
  6814. equals: function(other) {
  6815. return this.x === other.x &&
  6816. this.y === other.y;
  6817. },
  6818. /**
  6819. * Calculate the distance from this point to another point
  6820. * @param {Point} p the other point
  6821. * @return {Number} distance
  6822. */
  6823. dist: function(p) {
  6824. return Math.sqrt(this.distSqr(p));
  6825. },
  6826. /**
  6827. * Calculate the distance from this point to another point,
  6828. * without the square root step. Useful if you're comparing
  6829. * relative distances.
  6830. * @param {Point} p the other point
  6831. * @return {Number} distance
  6832. */
  6833. distSqr: function(p) {
  6834. var dx = p.x - this.x,
  6835. dy = p.y - this.y;
  6836. return dx * dx + dy * dy;
  6837. },
  6838. /**
  6839. * Get the angle from the 0, 0 coordinate to this point, in radians
  6840. * coordinates.
  6841. * @return {Number} angle
  6842. */
  6843. angle: function() {
  6844. return Math.atan2(this.y, this.x);
  6845. },
  6846. /**
  6847. * Get the angle from this point to another point, in radians
  6848. * @param {Point} b the other point
  6849. * @return {Number} angle
  6850. */
  6851. angleTo: function(b) {
  6852. return Math.atan2(this.y - b.y, this.x - b.x);
  6853. },
  6854. /**
  6855. * Get the angle between this point and another point, in radians
  6856. * @param {Point} b the other point
  6857. * @return {Number} angle
  6858. */
  6859. angleWith: function(b) {
  6860. return this.angleWithSep(b.x, b.y);
  6861. },
  6862. /*
  6863. * Find the angle of the two vectors, solving the formula for
  6864. * the cross product a x b = |a||b|sin(θ) for θ.
  6865. * @param {Number} x the x-coordinate
  6866. * @param {Number} y the y-coordinate
  6867. * @return {Number} the angle in radians
  6868. */
  6869. angleWithSep: function(x, y) {
  6870. return Math.atan2(
  6871. this.x * y - this.y * x,
  6872. this.x * x + this.y * y);
  6873. },
  6874. _matMult: function(m) {
  6875. var x = m[0] * this.x + m[1] * this.y,
  6876. y = m[2] * this.x + m[3] * this.y;
  6877. this.x = x;
  6878. this.y = y;
  6879. return this;
  6880. },
  6881. _add: function(p) {
  6882. this.x += p.x;
  6883. this.y += p.y;
  6884. return this;
  6885. },
  6886. _sub: function(p) {
  6887. this.x -= p.x;
  6888. this.y -= p.y;
  6889. return this;
  6890. },
  6891. _mult: function(k) {
  6892. this.x *= k;
  6893. this.y *= k;
  6894. return this;
  6895. },
  6896. _div: function(k) {
  6897. this.x /= k;
  6898. this.y /= k;
  6899. return this;
  6900. },
  6901. _multByPoint: function(p) {
  6902. this.x *= p.x;
  6903. this.y *= p.y;
  6904. return this;
  6905. },
  6906. _divByPoint: function(p) {
  6907. this.x /= p.x;
  6908. this.y /= p.y;
  6909. return this;
  6910. },
  6911. _unit: function() {
  6912. this._div(this.mag());
  6913. return this;
  6914. },
  6915. _perp: function() {
  6916. var y = this.y;
  6917. this.y = this.x;
  6918. this.x = -y;
  6919. return this;
  6920. },
  6921. _rotate: function(angle) {
  6922. var cos = Math.cos(angle),
  6923. sin = Math.sin(angle),
  6924. x = cos * this.x - sin * this.y,
  6925. y = sin * this.x + cos * this.y;
  6926. this.x = x;
  6927. this.y = y;
  6928. return this;
  6929. },
  6930. _rotateAround: function(angle, p) {
  6931. var cos = Math.cos(angle),
  6932. sin = Math.sin(angle),
  6933. x = p.x + cos * (this.x - p.x) - sin * (this.y - p.y),
  6934. y = p.y + sin * (this.x - p.x) + cos * (this.y - p.y);
  6935. this.x = x;
  6936. this.y = y;
  6937. return this;
  6938. },
  6939. _round: function() {
  6940. this.x = Math.round(this.x);
  6941. this.y = Math.round(this.y);
  6942. return this;
  6943. }
  6944. };
  6945. /**
  6946. * Construct a point from an array if necessary, otherwise if the input
  6947. * is already a Point, or an unknown type, return it unchanged
  6948. * @param {Array<Number>|Point|*} a any kind of input value
  6949. * @return {Point} constructed point, or passed-through value.
  6950. * @example
  6951. * // this
  6952. * var point = Point.convert([0, 1]);
  6953. * // is equivalent to
  6954. * var point = new Point(0, 1);
  6955. */
  6956. Point.convert = function (a) {
  6957. if (a instanceof Point) {
  6958. return a;
  6959. }
  6960. if (Array.isArray(a)) {
  6961. return new Point(a[0], a[1]);
  6962. }
  6963. return a;
  6964. };
  6965. function VectorTileFeature(pbf, end, extent, keys, values) {
  6966. // Public
  6967. this.properties = {};
  6968. this.extent = extent;
  6969. this.type = 0;
  6970. // Private
  6971. this._pbf = pbf;
  6972. this._geometry = -1;
  6973. this._keys = keys;
  6974. this._values = values;
  6975. pbf.readFields(readFeature, this, end);
  6976. }
  6977. function readFeature(tag, feature, pbf) {
  6978. if (tag == 1) feature.id = pbf.readVarint();
  6979. else if (tag == 2) readTag(pbf, feature);
  6980. else if (tag == 3) feature.type = pbf.readVarint();
  6981. else if (tag == 4) feature._geometry = pbf.pos;
  6982. }
  6983. function readTag(pbf, feature) {
  6984. var end = pbf.readVarint() + pbf.pos;
  6985. while (pbf.pos < end) {
  6986. var key = feature._keys[pbf.readVarint()],
  6987. value = feature._values[pbf.readVarint()];
  6988. feature.properties[key] = value;
  6989. }
  6990. }
  6991. VectorTileFeature.types = ['Unknown', 'Point', 'LineString', 'Polygon'];
  6992. VectorTileFeature.prototype.loadGeometry = function() {
  6993. var pbf = this._pbf;
  6994. pbf.pos = this._geometry;
  6995. var end = pbf.readVarint() + pbf.pos,
  6996. cmd = 1,
  6997. length = 0,
  6998. x = 0,
  6999. y = 0,
  7000. lines = [],
  7001. line;
  7002. while (pbf.pos < end) {
  7003. if (length <= 0) {
  7004. var cmdLen = pbf.readVarint();
  7005. cmd = cmdLen & 0x7;
  7006. length = cmdLen >> 3;
  7007. }
  7008. length--;
  7009. if (cmd === 1 || cmd === 2) {
  7010. x += pbf.readSVarint();
  7011. y += pbf.readSVarint();
  7012. if (cmd === 1) { // moveTo
  7013. if (line) lines.push(line);
  7014. line = [];
  7015. }
  7016. line.push(new Point(x, y));
  7017. } else if (cmd === 7) {
  7018. // Workaround for https://github.com/mapbox/mapnik-vector-tile/issues/90
  7019. if (line) {
  7020. line.push(line[0].clone()); // closePolygon
  7021. }
  7022. } else {
  7023. throw new Error('unknown command ' + cmd);
  7024. }
  7025. }
  7026. if (line) lines.push(line);
  7027. return lines;
  7028. };
  7029. VectorTileFeature.prototype.bbox = function() {
  7030. var pbf = this._pbf;
  7031. pbf.pos = this._geometry;
  7032. var end = pbf.readVarint() + pbf.pos,
  7033. cmd = 1,
  7034. length = 0,
  7035. x = 0,
  7036. y = 0,
  7037. x1 = Infinity,
  7038. x2 = -Infinity,
  7039. y1 = Infinity,
  7040. y2 = -Infinity;
  7041. while (pbf.pos < end) {
  7042. if (length <= 0) {
  7043. var cmdLen = pbf.readVarint();
  7044. cmd = cmdLen & 0x7;
  7045. length = cmdLen >> 3;
  7046. }
  7047. length--;
  7048. if (cmd === 1 || cmd === 2) {
  7049. x += pbf.readSVarint();
  7050. y += pbf.readSVarint();
  7051. if (x < x1) x1 = x;
  7052. if (x > x2) x2 = x;
  7053. if (y < y1) y1 = y;
  7054. if (y > y2) y2 = y;
  7055. } else if (cmd !== 7) {
  7056. throw new Error('unknown command ' + cmd);
  7057. }
  7058. }
  7059. return [x1, y1, x2, y2];
  7060. };
  7061. VectorTileFeature.prototype.toGeoJSON = function(x, y, z) {
  7062. var size = this.extent * Math.pow(2, z),
  7063. x0 = this.extent * x,
  7064. y0 = this.extent * y,
  7065. coords = this.loadGeometry(),
  7066. type = VectorTileFeature.types[this.type],
  7067. i, j;
  7068. function project(line) {
  7069. for (var j = 0; j < line.length; j++) {
  7070. var p = line[j], y2 = 180 - (p.y + y0) * 360 / size;
  7071. line[j] = [
  7072. (p.x + x0) * 360 / size - 180,
  7073. 360 / Math.PI * Math.atan(Math.exp(y2 * Math.PI / 180)) - 90
  7074. ];
  7075. }
  7076. }
  7077. switch (this.type) {
  7078. case 1:
  7079. var points = [];
  7080. for (i = 0; i < coords.length; i++) {
  7081. points[i] = coords[i][0];
  7082. }
  7083. coords = points;
  7084. project(coords);
  7085. break;
  7086. case 2:
  7087. for (i = 0; i < coords.length; i++) {
  7088. project(coords[i]);
  7089. }
  7090. break;
  7091. case 3:
  7092. coords = classifyRings$1(coords);
  7093. for (i = 0; i < coords.length; i++) {
  7094. for (j = 0; j < coords[i].length; j++) {
  7095. project(coords[i][j]);
  7096. }
  7097. }
  7098. break;
  7099. }
  7100. if (coords.length === 1) {
  7101. coords = coords[0];
  7102. } else {
  7103. type = 'Multi' + type;
  7104. }
  7105. var result = {
  7106. type: "Feature",
  7107. geometry: {
  7108. type: type,
  7109. coordinates: coords
  7110. },
  7111. properties: this.properties
  7112. };
  7113. if ('id' in this) {
  7114. result.id = this.id;
  7115. }
  7116. return result;
  7117. };
  7118. // classifies an array of rings into polygons with outer rings and holes
  7119. function classifyRings$1(rings) {
  7120. var len = rings.length;
  7121. if (len <= 1) return [rings];
  7122. var polygons = [],
  7123. polygon,
  7124. ccw;
  7125. for (var i = 0; i < len; i++) {
  7126. var area = signedArea(rings[i]);
  7127. if (area === 0) continue;
  7128. if (ccw === undefined) ccw = area < 0;
  7129. if (ccw === area < 0) {
  7130. if (polygon) polygons.push(polygon);
  7131. polygon = [rings[i]];
  7132. } else {
  7133. polygon.push(rings[i]);
  7134. }
  7135. }
  7136. if (polygon) polygons.push(polygon);
  7137. return polygons;
  7138. }
  7139. function signedArea(ring) {
  7140. var sum = 0;
  7141. for (var i = 0, len = ring.length, j = len - 1, p1, p2; i < len; j = i++) {
  7142. p1 = ring[i];
  7143. p2 = ring[j];
  7144. sum += (p2.x - p1.x) * (p1.y + p2.y);
  7145. }
  7146. return sum;
  7147. }
  7148. function VectorTileLayer(pbf, end) {
  7149. // Public
  7150. this.version = 1;
  7151. this.name = null;
  7152. this.extent = 4096;
  7153. this.length = 0;
  7154. // Private
  7155. this._pbf = pbf;
  7156. this._keys = [];
  7157. this._values = [];
  7158. this._features = [];
  7159. pbf.readFields(readLayer, this, end);
  7160. this.length = this._features.length;
  7161. }
  7162. function readLayer(tag, layer, pbf) {
  7163. if (tag === 15) layer.version = pbf.readVarint();
  7164. else if (tag === 1) layer.name = pbf.readString();
  7165. else if (tag === 5) layer.extent = pbf.readVarint();
  7166. else if (tag === 2) layer._features.push(pbf.pos);
  7167. else if (tag === 3) layer._keys.push(pbf.readString());
  7168. else if (tag === 4) layer._values.push(readValueMessage(pbf));
  7169. }
  7170. function readValueMessage(pbf) {
  7171. var value = null,
  7172. end = pbf.readVarint() + pbf.pos;
  7173. while (pbf.pos < end) {
  7174. var tag = pbf.readVarint() >> 3;
  7175. value = tag === 1 ? pbf.readString() :
  7176. tag === 2 ? pbf.readFloat() :
  7177. tag === 3 ? pbf.readDouble() :
  7178. tag === 4 ? pbf.readVarint64() :
  7179. tag === 5 ? pbf.readVarint() :
  7180. tag === 6 ? pbf.readSVarint() :
  7181. tag === 7 ? pbf.readBoolean() : null;
  7182. }
  7183. return value;
  7184. }
  7185. // return feature `i` from this layer as a `VectorTileFeature`
  7186. VectorTileLayer.prototype.feature = function(i) {
  7187. if (i < 0 || i >= this._features.length) throw new Error('feature index out of bounds');
  7188. this._pbf.pos = this._features[i];
  7189. var end = this._pbf.readVarint() + this._pbf.pos;
  7190. return new VectorTileFeature(this._pbf, end, this.extent, this._keys, this._values);
  7191. };
  7192. function VectorTile(pbf, end) {
  7193. this.layers = pbf.readFields(readTile, {}, end);
  7194. }
  7195. function readTile(tag, layers, pbf) {
  7196. if (tag === 3) {
  7197. var layer = new VectorTileLayer(pbf, pbf.readVarint() + pbf.pos);
  7198. if (layer.length) layers[layer.name] = layer;
  7199. }
  7200. }
  7201. var NUM_PARAMS = 3;
  7202. function GridIndex(extent, n, padding) {
  7203. var cells = this.cells = [];
  7204. if (extent instanceof ArrayBuffer) {
  7205. this.arrayBuffer = extent;
  7206. var array = new Int32Array(this.arrayBuffer);
  7207. extent = array[0];
  7208. n = array[1];
  7209. padding = array[2];
  7210. this.d = n + 2 * padding;
  7211. for (var k = 0; k < this.d * this.d; k++) {
  7212. var start = array[NUM_PARAMS + k];
  7213. var end = array[NUM_PARAMS + k + 1];
  7214. cells.push(start === end ?
  7215. null :
  7216. array.subarray(start, end));
  7217. }
  7218. var keysOffset = array[NUM_PARAMS + cells.length];
  7219. var bboxesOffset = array[NUM_PARAMS + cells.length + 1];
  7220. this.keys = array.subarray(keysOffset, bboxesOffset);
  7221. this.bboxes = array.subarray(bboxesOffset);
  7222. this.insert = this._insertReadonly;
  7223. } else {
  7224. this.d = n + 2 * padding;
  7225. for (var i = 0; i < this.d * this.d; i++) {
  7226. cells.push([]);
  7227. }
  7228. this.keys = [];
  7229. this.bboxes = [];
  7230. }
  7231. this.n = n;
  7232. this.extent = extent;
  7233. this.padding = padding;
  7234. this.scale = n / extent;
  7235. this.uid = 0;
  7236. var p = (padding / n) * extent;
  7237. this.min = -p;
  7238. this.max = extent + p;
  7239. }
  7240. GridIndex.prototype.insert = function(key, x1, y1, x2, y2) {
  7241. this._forEachCell(x1, y1, x2, y2, this._insertCell, this.uid++);
  7242. this.keys.push(key);
  7243. this.bboxes.push(x1);
  7244. this.bboxes.push(y1);
  7245. this.bboxes.push(x2);
  7246. this.bboxes.push(y2);
  7247. };
  7248. GridIndex.prototype._insertReadonly = function() {
  7249. throw 'Cannot insert into a GridIndex created from an ArrayBuffer.';
  7250. };
  7251. GridIndex.prototype._insertCell = function(x1, y1, x2, y2, cellIndex, uid) {
  7252. this.cells[cellIndex].push(uid);
  7253. };
  7254. GridIndex.prototype.query = function(x1, y1, x2, y2, intersectionTest) {
  7255. var min = this.min;
  7256. var max = this.max;
  7257. if (x1 <= min && y1 <= min && max <= x2 && max <= y2 && !intersectionTest) {
  7258. // We use `Array#slice` because `this.keys` may be a `Int32Array` and
  7259. // some browsers (Safari and IE) do not support `TypedArray#slice`
  7260. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/slice#Browser_compatibility
  7261. return Array.prototype.slice.call(this.keys);
  7262. } else {
  7263. var result = [];
  7264. var seenUids = {};
  7265. this._forEachCell(x1, y1, x2, y2, this._queryCell, result, seenUids, intersectionTest);
  7266. return result;
  7267. }
  7268. };
  7269. GridIndex.prototype._queryCell = function(x1, y1, x2, y2, cellIndex, result, seenUids, intersectionTest) {
  7270. var cell = this.cells[cellIndex];
  7271. if (cell !== null) {
  7272. var keys = this.keys;
  7273. var bboxes = this.bboxes;
  7274. for (var u = 0; u < cell.length; u++) {
  7275. var uid = cell[u];
  7276. if (seenUids[uid] === undefined) {
  7277. var offset = uid * 4;
  7278. if (intersectionTest ?
  7279. intersectionTest(bboxes[offset + 0], bboxes[offset + 1], bboxes[offset + 2], bboxes[offset + 3]) :
  7280. ((x1 <= bboxes[offset + 2]) &&
  7281. (y1 <= bboxes[offset + 3]) &&
  7282. (x2 >= bboxes[offset + 0]) &&
  7283. (y2 >= bboxes[offset + 1]))) {
  7284. seenUids[uid] = true;
  7285. result.push(keys[uid]);
  7286. } else {
  7287. seenUids[uid] = false;
  7288. }
  7289. }
  7290. }
  7291. }
  7292. };
  7293. GridIndex.prototype._forEachCell = function(x1, y1, x2, y2, fn, arg1, arg2, intersectionTest) {
  7294. var cx1 = this._convertToCellCoord(x1);
  7295. var cy1 = this._convertToCellCoord(y1);
  7296. var cx2 = this._convertToCellCoord(x2);
  7297. var cy2 = this._convertToCellCoord(y2);
  7298. for (var x = cx1; x <= cx2; x++) {
  7299. for (var y = cy1; y <= cy2; y++) {
  7300. var cellIndex = this.d * y + x;
  7301. if (intersectionTest && !intersectionTest(
  7302. this._convertFromCellCoord(x),
  7303. this._convertFromCellCoord(y),
  7304. this._convertFromCellCoord(x + 1),
  7305. this._convertFromCellCoord(y + 1))) { continue; }
  7306. if (fn.call(this, x1, y1, x2, y2, cellIndex, arg1, arg2, intersectionTest)) { return; }
  7307. }
  7308. }
  7309. };
  7310. GridIndex.prototype._convertFromCellCoord = function(x) {
  7311. return (x - this.padding) / this.scale;
  7312. };
  7313. GridIndex.prototype._convertToCellCoord = function(x) {
  7314. return Math.max(0, Math.min(this.d - 1, Math.floor(x * this.scale) + this.padding));
  7315. };
  7316. GridIndex.prototype.toArrayBuffer = function() {
  7317. if (this.arrayBuffer) { return this.arrayBuffer; }
  7318. var cells = this.cells;
  7319. var metadataLength = NUM_PARAMS + this.cells.length + 1 + 1;
  7320. var totalCellLength = 0;
  7321. for (var i = 0; i < this.cells.length; i++) {
  7322. totalCellLength += this.cells[i].length;
  7323. }
  7324. var array = new Int32Array(metadataLength + totalCellLength + this.keys.length + this.bboxes.length);
  7325. array[0] = this.extent;
  7326. array[1] = this.n;
  7327. array[2] = this.padding;
  7328. var offset = metadataLength;
  7329. for (var k = 0; k < cells.length; k++) {
  7330. var cell = cells[k];
  7331. array[NUM_PARAMS + k] = offset;
  7332. array.set(cell, offset);
  7333. offset += cell.length;
  7334. }
  7335. array[NUM_PARAMS + cells.length] = offset;
  7336. array.set(this.keys, offset);
  7337. offset += this.keys.length;
  7338. array[NUM_PARAMS + cells.length + 1] = offset;
  7339. array.set(this.bboxes, offset);
  7340. offset += this.bboxes.length;
  7341. return array.buffer;
  7342. };
  7343. WebWorkerTransfer.register('GridIndex', GridIndex, {omit: ['layers', 'patternFeatures']});
  7344. /**
  7345. * @module util
  7346. * @private
  7347. */
  7348. function Util() {
  7349. }
  7350. /**
  7351. * Given a value `t` that varies between 0 and 1, return
  7352. * an interpolation function that eases between 0 and 1 in a pleasing
  7353. * cubic in-out fashion.
  7354. *
  7355. * @private
  7356. */
  7357. Util.easeCubicInOut = function (t) {
  7358. if (t <= 0) {
  7359. return 0;
  7360. }
  7361. if (t >= 1) {
  7362. return 1;
  7363. }
  7364. var t2 = t * t,
  7365. t3 = t2 * t;
  7366. return 4 * (t < 0.5 ? t3 : 3 * (t - t2) + t3 - 0.75);
  7367. };
  7368. /*
  7369. * Call an asynchronous function on an array of arguments,
  7370. * calling `callback` with the completed results of all calls.
  7371. *
  7372. * @param array input to each call of the async function.
  7373. * @param fn an async function with signature (data, callback)
  7374. * @param callback a callback run after all async work is done.
  7375. * called with an array, containing the results of each async call.
  7376. * @private
  7377. */
  7378. Util.asyncAll = function (array, fn, callback) {
  7379. if (!array.length) {
  7380. return callback(null, []);
  7381. }
  7382. var remaining = array.length;
  7383. var results = new Array(array.length);
  7384. var error = null;
  7385. array.forEach(function (item, i) {
  7386. fn(item, function (err, result) {
  7387. if (err) {
  7388. error = err;
  7389. }
  7390. results[i] = ((result ) ); // https://github.com/facebook/flow/issues/2123
  7391. if (--remaining === 0) {
  7392. callback(error, results);
  7393. }
  7394. });
  7395. });
  7396. };
  7397. /**
  7398. * Given a destination object and optionally many source objects,
  7399. * copy all properties from the source objects into the destination.
  7400. * The last source object given overrides properties from previous
  7401. * source objects.
  7402. *
  7403. * @param dest destination object
  7404. * @param sources sources from which properties are pulled
  7405. * @private
  7406. */
  7407. Util.extend = function (dest) {
  7408. var sources = [], len = arguments.length - 1;
  7409. while (len-- > 0) sources[ len ] = arguments[ len + 1 ];
  7410. for (var i = 0, list = sources; i < list.length; i += 1) {
  7411. var src = list[i];
  7412. for (var k in src) {
  7413. dest[k] = src[k];
  7414. }
  7415. }
  7416. return dest;
  7417. };
  7418. var id = 1;
  7419. /**
  7420. * Return a unique numeric id, starting at 1 and incrementing with
  7421. * each call.
  7422. *
  7423. * @returns unique numeric id.
  7424. * @private
  7425. */
  7426. Util.uniqueId = function () {
  7427. return id++;
  7428. };
  7429. /**
  7430. * Return a random UUID (v4). Taken from: https://gist.github.com/jed/982883
  7431. * @private
  7432. */
  7433. Util.uuid = function () {
  7434. function b(a) {
  7435. return a ? (a ^ Math.random() * 16 >> a / 4).toString(16) :
  7436. //$FlowFixMe: Flow doesn't like the implied array literal conversion here
  7437. ([1e7] + -[1e3] + -4e3 + -8e3 + -1e11).replace(/[018]/g, b);
  7438. }
  7439. return b();
  7440. };
  7441. /**
  7442. * Validate a string to match UUID(v4) of the
  7443. * form: xxxxxxxx-xxxx-4xxx-[89ab]xxx-xxxxxxxxxxxx
  7444. * @param str string to validate.
  7445. * @private
  7446. */
  7447. Util.validateUuid = function (str) {
  7448. return str ? /^[0-9a-f]{8}-[0-9a-f]{4}-[4][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(str) : false;
  7449. };
  7450. /**
  7451. * Given an array of member function names as strings, replace all of them
  7452. * with bound versions that will always refer to `context` as `this`. This
  7453. * is useful for classes where otherwise event bindings would reassign
  7454. * `this` to the evented object or some other value: this lets you ensure
  7455. * the `this` value always.
  7456. *
  7457. * @param fns list of member function names
  7458. * @param context the context value
  7459. * @example
  7460. * function MyClass() {
  7461. * bindAll(['ontimer'], this);
  7462. * this.name = 'Tom';
  7463. * }
  7464. * MyClass.prototype.ontimer = function() {
  7465. * alert(this.name);
  7466. * };
  7467. * var myClass = new MyClass();
  7468. * setTimeout(myClass.ontimer, 100);
  7469. * @private
  7470. */
  7471. Util.bindAll = function (fns, context) {
  7472. fns.forEach(function (fn) {
  7473. if (!context[fn]) {
  7474. return;
  7475. }
  7476. context[fn] = context[fn].bind(context);
  7477. });
  7478. };
  7479. /**
  7480. * Determine if a string ends with a particular substring
  7481. *
  7482. * @private
  7483. */
  7484. Util.endsWith = function (string, suffix) {
  7485. return string.indexOf(suffix, string.length - suffix.length) !== -1;
  7486. };
  7487. /**
  7488. * Create an object by mapping all the values of an existing object while
  7489. * preserving their keys.
  7490. *
  7491. * @private
  7492. */
  7493. Util.mapObject = function (input, iterator, context) {
  7494. var output = {};
  7495. for (var key in input) {
  7496. output[key] = iterator.call(context || this, input[key], key, input);
  7497. }
  7498. return output;
  7499. };
  7500. /**
  7501. * Create an object by filtering out values of an existing object.
  7502. *
  7503. * @private
  7504. */
  7505. Util.filterObject = function (input, iterator, context) {
  7506. var output = {};
  7507. for (var key in input) {
  7508. if (iterator.call(context || this, input[key], key, input)) {
  7509. output[key] = input[key];
  7510. }
  7511. }
  7512. return output;
  7513. };
  7514. /**
  7515. * Deeply clones two objects.
  7516. *
  7517. * @private
  7518. */
  7519. Util.clone = function (input) {
  7520. if (Array.isArray(input)) {
  7521. return input.map(Util.clone);
  7522. } else if (typeof input === 'object' && input) {
  7523. return ((Util.mapObject(input, Util.clone) ) );
  7524. } else {
  7525. return input;
  7526. }
  7527. };
  7528. Util.deepEqual = function (a, b) {
  7529. if (Array.isArray(a)) {
  7530. if (!Array.isArray(b) || a.length !== b.length) {
  7531. return false;
  7532. }
  7533. for (var i = 0; i < a.length; i++) {
  7534. if (!Util.deepEqual(a[i], b[i])) {
  7535. return false;
  7536. }
  7537. }
  7538. return true;
  7539. }
  7540. if (typeof a === 'object' && a !== null && b !== null) {
  7541. if (!(typeof b === 'object')) {
  7542. return false;
  7543. }
  7544. var keys = Object.keys(a);
  7545. if (keys.length !== Object.keys(b).length) {
  7546. return false;
  7547. }
  7548. for (var key in a) {
  7549. if (!Util.deepEqual(a[key], b[key])) {
  7550. return false;
  7551. }
  7552. }
  7553. return true;
  7554. }
  7555. return a === b;
  7556. };
  7557. /**
  7558. * Check if two arrays have at least one common element.
  7559. *
  7560. * @private
  7561. */
  7562. Util.arraysIntersect = function (a, b) {
  7563. for (var l = 0; l < a.length; l++) {
  7564. if (b.indexOf(a[l]) >= 0) {
  7565. return true;
  7566. }
  7567. }
  7568. return false;
  7569. };
  7570. /**
  7571. * Indicates if the provided Points are in a counter clockwise (true) or clockwise (false) order
  7572. *
  7573. * @private
  7574. * @returns true for a counter clockwise set of points
  7575. */
  7576. // http://bryceboe.com/2006/10/23/line-segment-intersection-algorithm/
  7577. Util.isCounterClockwise = function (a, b, c) {
  7578. return (c.y - a.y) * (b.x - a.x) > (b.y - a.y) * (c.x - a.x);
  7579. };
  7580. /* global self, WorkerGlobalScope */
  7581. /**
  7582. * Retuns true if the when run in the web-worker context.
  7583. *
  7584. * @private
  7585. * @returns {boolean}
  7586. */
  7587. Util.isWorker = function () {
  7588. return typeof WorkerGlobalScope !== 'undefined' && typeof self !== 'undefined' &&
  7589. self instanceof WorkerGlobalScope;
  7590. };
  7591. var _isSafari = null;
  7592. /**
  7593. * Returns true when run in WebKit derived browsers.
  7594. * This is used as a workaround for a memory leak in Safari caused by using Transferable objects to
  7595. * transfer data between WebWorkers and the main thread.
  7596. * https://github.com/mapbox/mapbox-gl-js/issues/8771
  7597. *
  7598. * This should be removed once the underlying Safari issue is fixed.
  7599. *
  7600. * @private
  7601. * @param scope {WindowOrWorkerGlobalScope} Since this function is used both on the main thread and WebWorker context,
  7602. * let the calling scope pass in the global scope object.
  7603. * @returns {boolean}
  7604. */
  7605. Util.isSafari = function (scope) {
  7606. if (_isSafari == null) {
  7607. var userAgent = scope.navigator ? scope.navigator.userAgent : null;
  7608. _isSafari = !!scope.safari || !!(userAgent && (/\b(iPad|iPhone|iPod)\b/.test(userAgent) || (!!userAgent.match('Safari') && !userAgent.match('Chrome'))));
  7609. }
  7610. return _isSafari;
  7611. };
  7612. /**
  7613. * Replace tokens in a string template with values in an object
  7614. *
  7615. * @param properties a key/value relationship between tokens and replacements
  7616. * @param text the template string
  7617. * @returns the template with tokens replaced
  7618. * @private
  7619. */
  7620. Util.resolveTokens = function (properties, text) {
  7621. return text.replace(/{([^{}]+)}/g, function (match, key) {
  7622. return key in properties ? String(properties[key]) : '';
  7623. });
  7624. };
  7625. /**
  7626. * Tracks `let` bindings during expression parsing.
  7627. * @private
  7628. */
  7629. var Scope = function Scope(parent, bindings) {
  7630. if (bindings === void 0) bindings = [];
  7631. this.parent = parent;
  7632. this.bindings = {};
  7633. for (var i = 0, list = bindings; i < list.length; i += 1) {
  7634. var ref = list[i];
  7635. var name = ref[0];
  7636. var expression = ref[1];
  7637. this.bindings[name] = expression;
  7638. }
  7639. };
  7640. Scope.prototype.concat = function concat(bindings) {
  7641. return new Scope(this, bindings);
  7642. };
  7643. Scope.prototype.get = function get(name) {
  7644. if (this.bindings[name]) {
  7645. return this.bindings[name];
  7646. }
  7647. if (this.parent) {
  7648. return this.parent.get(name);
  7649. }
  7650. throw new Error((name + " not found in scope."));
  7651. };
  7652. Scope.prototype.has = function has(name) {
  7653. if (this.bindings[name]) {
  7654. return true;
  7655. }
  7656. return this.parent ? this.parent.has(name) : false;
  7657. };
  7658. var ParsingError = /*@__PURE__*/(function (Error) {
  7659. function ParsingError(key , message ) {
  7660. Error.call(this, message);
  7661. this.message = message;
  7662. this.key = key;
  7663. }
  7664. if ( Error ) ParsingError.__proto__ = Error;
  7665. ParsingError.prototype = Object.create( Error && Error.prototype );
  7666. ParsingError.prototype.constructor = ParsingError;
  7667. return ParsingError;
  7668. }(Error));
  7669. var geometryTypes = ['Unknown', 'Point', 'LineString', 'Polygon'];
  7670. var EvaluationContext = function EvaluationContext() {
  7671. this.globals = (null );
  7672. this.feature = null;
  7673. this.featureState = null;
  7674. this.formattedSection = null;
  7675. this._parseColorCache = {};
  7676. this.availableImages = null;
  7677. };
  7678. EvaluationContext.prototype.id = function id () {
  7679. return this.feature && 'id' in this.feature ? this.feature.id : null;
  7680. };
  7681. EvaluationContext.prototype.geometryType = function geometryType () {
  7682. return this.feature ? typeof this.feature.type === 'number' ? geometryTypes[this.feature.type] : this.feature.type : null;
  7683. };
  7684. EvaluationContext.prototype.properties = function properties () {
  7685. return this.feature && this.feature.properties || {};
  7686. };
  7687. EvaluationContext.prototype.parseColor = function parseColor (input ) {
  7688. var cached = this._parseColorCache[input];
  7689. if (!cached) {
  7690. cached = this._parseColorCache[input] = Color.parse(input);
  7691. }
  7692. return cached;
  7693. };
  7694. function isConstant() {
  7695. }
  7696. isConstant.isFeatureConstant = function(e){
  7697. if (e instanceof CompoundExpression) {
  7698. if (e.name === 'get' && e.args.length === 1) {
  7699. return false;
  7700. } else if (e.name === 'feature-state') {
  7701. return false;
  7702. } else if (e.name === 'has' && e.args.length === 1) {
  7703. return false;
  7704. } else if (
  7705. e.name === 'properties' ||
  7706. e.name === 'geometry-type' ||
  7707. e.name === 'id'
  7708. ) {
  7709. return false;
  7710. } else if (/^filter-/.test(e.name)) {
  7711. return false;
  7712. }
  7713. }
  7714. var result = true;
  7715. e.eachChild(function (arg) {
  7716. if (result && !isConstant.isFeatureConstant(arg)) {
  7717. result = false;
  7718. }
  7719. });
  7720. return result;
  7721. };
  7722. isConstant.isStateConstant = function(e){
  7723. if (e instanceof CompoundExpression) {
  7724. if (e.name === 'feature-state') {
  7725. return false;
  7726. }
  7727. }
  7728. var result = true;
  7729. e.eachChild(function (arg) {
  7730. if (result && !isConstant.isStateConstant(arg)) {
  7731. result = false;
  7732. }
  7733. });
  7734. return result;
  7735. };
  7736. isConstant.isGlobalPropertyConstant = function(e, properties){
  7737. if (e instanceof CompoundExpression && properties.indexOf(e.name) >= 0) {
  7738. return false;
  7739. }
  7740. var result = true;
  7741. e.eachChild(function (arg) {
  7742. if (result && !isConstant.isGlobalPropertyConstant(arg, properties)) {
  7743. result = false;
  7744. }
  7745. });
  7746. return result;
  7747. };
  7748. /**
  7749. * State associated parsing at a given point in an expression tree.
  7750. * @private
  7751. */
  7752. var ParsingContext = function ParsingContext(registry, path, expectedType, scope, errors) {
  7753. if (path === void 0) path = [];
  7754. if (scope === void 0) scope = new Scope();
  7755. if (errors === void 0) errors = [];
  7756. this.registry = registry;
  7757. this.path = path;
  7758. this.key = path.map(function (part) {
  7759. return ("[" + part + "]");
  7760. }).join('');
  7761. this.scope = scope;
  7762. this.errors = errors;
  7763. this.expectedType = expectedType;
  7764. };
  7765. /**
  7766. * @param expr the JSON expression to parse
  7767. * @param index the optional argument index if this expression is an argument of a parent expression that's being parsed
  7768. * @param options
  7769. * @param options.omitTypeAnnotations set true to omit inferred type annotations. Caller beware: with this option set, the parsed expression's type will NOT satisfy `expectedType` if it would normally be wrapped in an inferred annotation.
  7770. * @private
  7771. */
  7772. ParsingContext.prototype.parse = function parse(expr, index, expectedType, bindings, options) {
  7773. if (options === void 0) options = {};
  7774. if (index) {
  7775. return this.concat(index, expectedType, bindings)._parse(expr, options);
  7776. }
  7777. return this._parse(expr, options);
  7778. };
  7779. ParsingContext.prototype._parse = function _parse(expr, options) {
  7780. if (expr === null || typeof expr === 'string' || typeof expr === 'boolean' || typeof expr === 'number') {
  7781. expr = ['literal', expr];
  7782. }
  7783. function annotate(parsed, type, typeAnnotation) {
  7784. if (typeAnnotation === 'assert') {
  7785. return new Assertion(type, [parsed]);
  7786. } else if (typeAnnotation === 'coerce') {
  7787. return new Coercion(type, [parsed]);
  7788. } else {
  7789. return parsed;
  7790. }
  7791. }
  7792. if (Array.isArray(expr)) {
  7793. if (expr.length === 0) {
  7794. return this.error("Expected an array with at least one element. If you wanted a literal array, use [\"literal\", []].");
  7795. }
  7796. var op = expr[0];
  7797. if (typeof op !== 'string') {
  7798. this.error(("Expression name must be a string, but found " + (typeof op) + " instead. If you wanted a literal array, use [\"literal\", [...]]."), 0);
  7799. return null;
  7800. }
  7801. var Expr = this.registry[op];
  7802. if (Expr) {
  7803. var parsed = Expr.parse(expr, this);
  7804. if (!parsed) {
  7805. return null;
  7806. }
  7807. if (this.expectedType) {
  7808. var expected = this.expectedType;
  7809. var actual = parsed.type;
  7810. // When we expect a number, string, boolean, or array but have a value, wrap it in an assertion.
  7811. // When we expect a color or formatted string, but have a string or value, wrap it in a coercion.
  7812. // Otherwise, we do static type-checking.
  7813. //
  7814. // These behaviors are overridable for:
  7815. // * The "coalesce" operator, which needs to omit type annotations.
  7816. // * String-valued properties (e.g. `text-field`), where coercion is more convenient than assertion.
  7817. //
  7818. if ((expected.kind === 'string' || expected.kind === 'number' || expected.kind === 'boolean' || expected.kind === 'object' || expected.kind === 'array') && actual.kind === 'value') {
  7819. parsed = annotate(parsed, expected, options.typeAnnotation || 'assert');
  7820. } else if ((expected.kind === 'color' || expected.kind === 'formatted' || expected.kind === 'resolvedImage') && (actual.kind === 'value' || actual.kind === 'string')) {
  7821. parsed = annotate(parsed, expected, options.typeAnnotation || 'coerce');
  7822. } else if (this.checkSubtype(expected, actual)) {
  7823. return null;
  7824. }
  7825. }
  7826. // If an expression's arguments are all literals, we can evaluate
  7827. // it immediately and replace it with a literal value in the
  7828. // parsed/compiled result. Expressions that expect an image should
  7829. // not be resolved here so we can later get the available images.
  7830. if (!(parsed instanceof Literal) && (parsed.type.kind !== 'resolvedImage') && isConstant()) {
  7831. var ec = new EvaluationContext();
  7832. try {
  7833. parsed = new Literal(parsed.type, parsed.evaluate(ec));
  7834. } catch (e) {
  7835. this.error(e.message);
  7836. return null;
  7837. }
  7838. }
  7839. return parsed;
  7840. }
  7841. return this.error(("Unknown expression \"" + op + "\". If you wanted a literal array, use [\"literal\", [...]]."), 0);
  7842. } else if (typeof expr === 'undefined') {
  7843. return this.error("'undefined' value invalid. Use null instead.");
  7844. } else if (typeof expr === 'object') {
  7845. return this.error("Bare objects invalid. Use [\"literal\", {...}] instead.");
  7846. } else {
  7847. return this.error(("Expected an array, but found " + (typeof expr) + " instead."));
  7848. }
  7849. };
  7850. /**
  7851. * Returns a copy of this context suitable for parsing the subexpression at
  7852. * index `index`, optionally appending to 'let' binding map.
  7853. *
  7854. * Note that `errors` property, intended for collecting errors while
  7855. * parsing, is copied by reference rather than cloned.
  7856. * @private
  7857. */
  7858. ParsingContext.prototype.concat = function concat(index, expectedType, bindings) {
  7859. var path = typeof index === 'number' ? this.path.concat(index) : this.path;
  7860. var scope = bindings ? this.scope.concat(bindings) : this.scope;
  7861. return new ParsingContext(
  7862. this.registry,
  7863. path,
  7864. expectedType || null,
  7865. scope,
  7866. this.errors
  7867. );
  7868. };
  7869. /**
  7870. * Push a parsing (or type checking) error into the `this.errors`
  7871. * @param error The message
  7872. * @param keys Optionally specify the source of the error at a child
  7873. * of the current expression at `this.key`.
  7874. * @private
  7875. */
  7876. ParsingContext.prototype.error = function error(error$1) {
  7877. var keys = [], len = arguments.length - 1;
  7878. while (len-- > 0) keys[ len ] = arguments[ len + 1 ];
  7879. var key = "" + (this.key) + (keys.map(function (k) {
  7880. return ("[" + k + "]");
  7881. }).join(''));
  7882. this.errors.push(new ParsingError(key, error$1));
  7883. };
  7884. /**
  7885. * Returns null if `t` is a subtype of `expected`; otherwise returns an
  7886. * error message and also pushes it to `this.errors`.
  7887. */
  7888. ParsingContext.prototype.checkSubtype = function checkSubtype$1(expected, t) {
  7889. var error = checkSubtype(expected, t);
  7890. if (error) {
  7891. this.error(error);
  7892. }
  7893. return error;
  7894. };
  7895. function get(key, obj) {
  7896. const v = obj[key];
  7897. return typeof v === 'undefined' ? null : v;
  7898. }
  7899. var CompoundExpression$1 = function CompoundExpression(name, type, evaluate, args) {
  7900. this.name = name;
  7901. this.type = type;
  7902. this._evaluate = evaluate;
  7903. this.args = args;
  7904. };
  7905. CompoundExpression$1.prototype.evaluate = function evaluate(ctx) {
  7906. return this._evaluate(ctx, this.args);
  7907. };
  7908. CompoundExpression$1.prototype.eachChild = function eachChild(fn) {
  7909. this.args.forEach(fn);
  7910. };
  7911. CompoundExpression$1.prototype.possibleOutputs = function possibleOutputs() {
  7912. return [undefined];
  7913. };
  7914. CompoundExpression$1.prototype.serialize = function serialize() {
  7915. return [this.name].concat(this.args.map(function (arg) {
  7916. return arg.serialize();
  7917. }));
  7918. };
  7919. CompoundExpression$1.parse = function parse(args, context) {
  7920. var ref$1;
  7921. var op = (args[0] );
  7922. var definition = CompoundExpression$1.definitions[op];
  7923. if (!definition) {
  7924. return context.error(("Unknown expression \"" + op + "\". If you wanted a literal array, use [\"literal\", [...]]."), 0);
  7925. }
  7926. // Now check argument types against each signature
  7927. var type = Array.isArray(definition) ?
  7928. definition[0] : definition.type;
  7929. var availableOverloads = Array.isArray(definition) ?
  7930. [
  7931. [definition[1], definition[2]]
  7932. ] :
  7933. definition.overloads;
  7934. var overloads = availableOverloads.filter(function (ref) {
  7935. var signature = ref[0];
  7936. return (
  7937. !Array.isArray(signature) || // varags
  7938. signature.length === args.length - 1 // correct param count
  7939. );
  7940. });
  7941. var signatureContext = (null );
  7942. for (var i$3 = 0, list = overloads; i$3 < list.length; i$3 += 1) {
  7943. // Use a fresh context for each attempted signature so that, if
  7944. // we eventually succeed, we haven't polluted `context.errors`.
  7945. var ref = list[i$3];
  7946. var params = ref[0];
  7947. var evaluate = ref[1];
  7948. signatureContext = new ParsingContext(context.registry, context.path, null, context.scope);
  7949. // First parse all the args, potentially coercing to the
  7950. // types expected by this overload.
  7951. var parsedArgs = [];
  7952. var argParseFailed = false;
  7953. for (var i = 1; i < args.length; i++) {
  7954. var arg = args[i];
  7955. var expectedType = Array.isArray(params) ?
  7956. params[i - 1] :
  7957. params.type;
  7958. var parsed = signatureContext.parse(arg, 1 + parsedArgs.length, expectedType);
  7959. if (!parsed) {
  7960. argParseFailed = true;
  7961. break;
  7962. }
  7963. parsedArgs.push(parsed);
  7964. }
  7965. if (argParseFailed) {
  7966. // Couldn't coerce args of this overload to expected type, move
  7967. // on to next one.
  7968. continue;
  7969. }
  7970. if (Array.isArray(params)) {
  7971. if (params.length !== parsedArgs.length) {
  7972. signatureContext.error(("Expected " + (params.length) + " arguments, but found " + (parsedArgs.length) + " instead."));
  7973. continue;
  7974. }
  7975. }
  7976. for (var i$1 = 0; i$1 < parsedArgs.length; i$1++) {
  7977. var expected = Array.isArray(params) ? params[i$1] : params.type;
  7978. var arg$1 = parsedArgs[i$1];
  7979. signatureContext.concat(i$1 + 1).checkSubtype(expected, arg$1.type);
  7980. }
  7981. if (signatureContext.errors.length === 0) {
  7982. return new CompoundExpression$1(op, type, evaluate, parsedArgs);
  7983. }
  7984. }
  7985. //assert_1(!signatureContext || signatureContext.errors.length > 0);
  7986. if (overloads.length === 1) {
  7987. (ref$1 = context.errors).push.apply(ref$1, signatureContext.errors);
  7988. } else {
  7989. var expected$1 = overloads.length ? overloads : availableOverloads;
  7990. var signatures = expected$1
  7991. .map(function (ref) {
  7992. var params = ref[0];
  7993. return stringifySignature(params);
  7994. })
  7995. .join(' | ');
  7996. var actualTypes = [];
  7997. // For error message, re-parse arguments without trying to
  7998. // apply any coercions
  7999. for (var i$2 = 1; i$2 < args.length; i$2++) {
  8000. var parsed$1 = context.parse(args[i$2], 1 + actualTypes.length);
  8001. if (!parsed$1) {
  8002. return null;
  8003. }
  8004. actualTypes.push(toString(parsed$1.type));
  8005. }
  8006. context.error(("Expected arguments of type " + signatures + ", but found (" + (actualTypes.join(', ')) + ") instead."));
  8007. }
  8008. return null;
  8009. };
  8010. CompoundExpression$1.register = function register(registry, definitions) {
  8011. //assert_1(!CompoundExpression.definitions);
  8012. CompoundExpression$1.definitions = definitions;
  8013. for (var name in definitions) {
  8014. registry[name] = CompoundExpression$1;
  8015. }
  8016. };
  8017. function stringifySignature(signature) {
  8018. if (Array.isArray(signature)) {
  8019. return ("(" + (signature.map(toString).join(', ')) + ")");
  8020. } else {
  8021. return ("(" + (toString(signature.type)) + "...)");
  8022. }
  8023. }
  8024. var NumberType$a = {kind: 'number'};
  8025. var StringType$8 = {kind: 'string'};
  8026. var BooleanType$8 = {kind: 'boolean'};
  8027. var ColorType$5 = {kind: 'color'};
  8028. var ObjectType$3 = {kind: 'object'};
  8029. var ValueType$a = {kind: 'value'};
  8030. var ErrorType = {kind: 'error'};
  8031. var CollatorType$3 = {kind: 'collator'};
  8032. function array$5(itemType, N) {
  8033. return {
  8034. kind: 'array',
  8035. itemType: itemType,
  8036. N: N
  8037. };
  8038. }
  8039. function varargs(type) {
  8040. return {type: type};
  8041. }
  8042. function rgba(ctx, ref) {
  8043. var r = ref[0];
  8044. var g = ref[1];
  8045. var b = ref[2];
  8046. var a = ref[3];
  8047. r = r.evaluate(ctx);
  8048. g = g.evaluate(ctx);
  8049. b = b.evaluate(ctx);
  8050. var alpha = a ? a.evaluate(ctx) : 1;
  8051. var error = Values.validateRGBA(r, g, b, alpha);
  8052. if (error) {
  8053. throw new RuntimeError(error);
  8054. }
  8055. return new Color(r / 255 * alpha, g / 255 * alpha, b / 255 * alpha, alpha);
  8056. }
  8057. CompoundExpression$1.register(expressions, {
  8058. 'error': [
  8059. ErrorType,
  8060. [StringType$8],
  8061. function (ctx, ref) {
  8062. var v = ref[0];
  8063. throw new RuntimeError(v.evaluate(ctx));
  8064. }
  8065. ],
  8066. 'typeof': [
  8067. StringType$8,
  8068. [ValueType$a],
  8069. function (ctx, ref) {
  8070. var v = ref[0];
  8071. return toString(Values.typeOf(v.evaluate(ctx)));
  8072. }
  8073. ],
  8074. 'to-rgba': [
  8075. array$5(NumberType$a, 4),
  8076. [ColorType$5],
  8077. function (ctx, ref) {
  8078. var v = ref[0];
  8079. return v.evaluate(ctx).toArray();
  8080. }
  8081. ],
  8082. 'rgb': [
  8083. ColorType$5,
  8084. [NumberType$a, NumberType$a, NumberType$a],
  8085. rgba
  8086. ],
  8087. 'rgba': [
  8088. ColorType$5,
  8089. [NumberType$a, NumberType$a, NumberType$a, NumberType$a],
  8090. rgba
  8091. ],
  8092. 'has': {
  8093. type: BooleanType$8,
  8094. overloads: [
  8095. [
  8096. [StringType$8],
  8097. function (ctx, ref) {
  8098. var key = ref[0];
  8099. return has(key.evaluate(ctx), ctx.properties());
  8100. }
  8101. ],
  8102. [
  8103. [StringType$8, ObjectType$3],
  8104. function (ctx, ref) {
  8105. var key = ref[0];
  8106. var obj = ref[1];
  8107. return has(key.evaluate(ctx), obj.evaluate(ctx));
  8108. }
  8109. ]
  8110. ]
  8111. },
  8112. 'get': {
  8113. type: ValueType$a,
  8114. overloads: [
  8115. [
  8116. [StringType$8],
  8117. function (ctx, ref) {
  8118. var key = ref[0];
  8119. return get(key.evaluate(ctx), ctx.properties());
  8120. }
  8121. ],
  8122. [
  8123. [StringType$8, ObjectType$3],
  8124. function (ctx, ref) {
  8125. var key = ref[0];
  8126. var obj = ref[1];
  8127. return get(key.evaluate(ctx), obj.evaluate(ctx));
  8128. }
  8129. ]
  8130. ]
  8131. },
  8132. 'feature-state': [
  8133. ValueType$a,
  8134. [StringType$8],
  8135. function (ctx, ref) {
  8136. var key = ref[0];
  8137. return get(key.evaluate(ctx), ctx.featureState || {});
  8138. }
  8139. ],
  8140. 'properties': [
  8141. ObjectType$3,
  8142. [],
  8143. function (ctx) {
  8144. return ctx.properties();
  8145. }
  8146. ],
  8147. 'geometry-type': [
  8148. StringType$8,
  8149. [],
  8150. function (ctx) {
  8151. return ctx.geometryType();
  8152. }
  8153. ],
  8154. 'id': [
  8155. ValueType$a,
  8156. [],
  8157. function (ctx) {
  8158. return ctx.id();
  8159. }
  8160. ],
  8161. 'zoom': [
  8162. NumberType$a,
  8163. [],
  8164. function (ctx) {
  8165. return ctx.globals.zoom;
  8166. }
  8167. ],
  8168. 'heatmap-density': [
  8169. NumberType$a,
  8170. [],
  8171. function (ctx) {
  8172. return ctx.globals.heatmapDensity || 0;
  8173. }
  8174. ],
  8175. 'line-progress': [
  8176. NumberType$a,
  8177. [],
  8178. function (ctx) {
  8179. return ctx.globals.lineProgress || 0;
  8180. }
  8181. ],
  8182. 'accumulated': [
  8183. ValueType$a,
  8184. [],
  8185. function (ctx) {
  8186. return ctx.globals.accumulated === undefined ? null : ctx.globals.accumulated;
  8187. }
  8188. ],
  8189. '+': [
  8190. NumberType$a,
  8191. varargs(NumberType$a),
  8192. function (ctx, args) {
  8193. var result = 0;
  8194. for (var i = 0, list = args; i < list.length; i += 1) {
  8195. var arg = list[i];
  8196. result += arg.evaluate(ctx);
  8197. }
  8198. return result;
  8199. }
  8200. ],
  8201. '*': [
  8202. NumberType$a,
  8203. varargs(NumberType$a),
  8204. function (ctx, args) {
  8205. var result = 1;
  8206. for (var i = 0, list = args; i < list.length; i += 1) {
  8207. var arg = list[i];
  8208. result *= arg.evaluate(ctx);
  8209. }
  8210. return result;
  8211. }
  8212. ],
  8213. '-': {
  8214. type: NumberType$a,
  8215. overloads: [
  8216. [
  8217. [NumberType$a, NumberType$a],
  8218. function (ctx, ref) {
  8219. var a = ref[0];
  8220. var b = ref[1];
  8221. return a.evaluate(ctx) - b.evaluate(ctx);
  8222. }
  8223. ],
  8224. [
  8225. [NumberType$a],
  8226. function (ctx, ref) {
  8227. var a = ref[0];
  8228. return -a.evaluate(ctx);
  8229. }
  8230. ]
  8231. ]
  8232. },
  8233. '/': [
  8234. NumberType$a,
  8235. [NumberType$a, NumberType$a],
  8236. function (ctx, ref) {
  8237. var a = ref[0];
  8238. var b = ref[1];
  8239. return a.evaluate(ctx) / b.evaluate(ctx);
  8240. }
  8241. ],
  8242. '%': [
  8243. NumberType$a,
  8244. [NumberType$a, NumberType$a],
  8245. function (ctx, ref) {
  8246. var a = ref[0];
  8247. var b = ref[1];
  8248. return a.evaluate(ctx) % b.evaluate(ctx);
  8249. }
  8250. ],
  8251. 'ln2': [
  8252. NumberType$a,
  8253. [],
  8254. function () {
  8255. return Math.LN2;
  8256. }
  8257. ],
  8258. 'pi': [
  8259. NumberType$a,
  8260. [],
  8261. function () {
  8262. return Math.PI;
  8263. }
  8264. ],
  8265. 'e': [
  8266. NumberType$a,
  8267. [],
  8268. function () {
  8269. return Math.E;
  8270. }
  8271. ],
  8272. '^': [
  8273. NumberType$a,
  8274. [NumberType$a, NumberType$a],
  8275. function (ctx, ref) {
  8276. var b = ref[0];
  8277. var e = ref[1];
  8278. return Math.pow(b.evaluate(ctx), e.evaluate(ctx));
  8279. }
  8280. ],
  8281. 'sqrt': [
  8282. NumberType$a,
  8283. [NumberType$a],
  8284. function (ctx, ref) {
  8285. var x = ref[0];
  8286. return Math.sqrt(x.evaluate(ctx));
  8287. }
  8288. ],
  8289. 'log10': [
  8290. NumberType$a,
  8291. [NumberType$a],
  8292. function (ctx, ref) {
  8293. var n = ref[0];
  8294. return Math.log(n.evaluate(ctx)) / Math.LN10;
  8295. }
  8296. ],
  8297. 'ln': [
  8298. NumberType$a,
  8299. [NumberType$a],
  8300. function (ctx, ref) {
  8301. var n = ref[0];
  8302. return Math.log(n.evaluate(ctx));
  8303. }
  8304. ],
  8305. 'log2': [
  8306. NumberType$a,
  8307. [NumberType$a],
  8308. function (ctx, ref) {
  8309. var n = ref[0];
  8310. return Math.log(n.evaluate(ctx)) / Math.LN2;
  8311. }
  8312. ],
  8313. 'sin': [
  8314. NumberType$a,
  8315. [NumberType$a],
  8316. function (ctx, ref) {
  8317. var n = ref[0];
  8318. return Math.sin(n.evaluate(ctx));
  8319. }
  8320. ],
  8321. 'cos': [
  8322. NumberType$a,
  8323. [NumberType$a],
  8324. function (ctx, ref) {
  8325. var n = ref[0];
  8326. return Math.cos(n.evaluate(ctx));
  8327. }
  8328. ],
  8329. 'tan': [
  8330. NumberType$a,
  8331. [NumberType$a],
  8332. function (ctx, ref) {
  8333. var n = ref[0];
  8334. return Math.tan(n.evaluate(ctx));
  8335. }
  8336. ],
  8337. 'asin': [
  8338. NumberType$a,
  8339. [NumberType$a],
  8340. function (ctx, ref) {
  8341. var n = ref[0];
  8342. return Math.asin(n.evaluate(ctx));
  8343. }
  8344. ],
  8345. 'acos': [
  8346. NumberType$a,
  8347. [NumberType$a],
  8348. function (ctx, ref) {
  8349. var n = ref[0];
  8350. return Math.acos(n.evaluate(ctx));
  8351. }
  8352. ],
  8353. 'atan': [
  8354. NumberType$a,
  8355. [NumberType$a],
  8356. function (ctx, ref) {
  8357. var n = ref[0];
  8358. return Math.atan(n.evaluate(ctx));
  8359. }
  8360. ],
  8361. 'min': [
  8362. NumberType$a,
  8363. varargs(NumberType$a),
  8364. function (ctx, args) {
  8365. return Math.min.apply(Math, args.map(function (arg) {
  8366. return arg.evaluate(ctx);
  8367. }));
  8368. }
  8369. ],
  8370. 'max': [
  8371. NumberType$a,
  8372. varargs(NumberType$a),
  8373. function (ctx, args) {
  8374. return Math.max.apply(Math, args.map(function (arg) {
  8375. return arg.evaluate(ctx);
  8376. }));
  8377. }
  8378. ],
  8379. 'abs': [
  8380. NumberType$a,
  8381. [NumberType$a],
  8382. function (ctx, ref) {
  8383. var n = ref[0];
  8384. return Math.abs(n.evaluate(ctx));
  8385. }
  8386. ],
  8387. 'round': [
  8388. NumberType$a,
  8389. [NumberType$a],
  8390. function (ctx, ref) {
  8391. var n = ref[0];
  8392. var v = n.evaluate(ctx);
  8393. // Javascript's Math.round() rounds towards +Infinity for halfway
  8394. // values, even when they're negative. It's more common to round
  8395. // away from 0 (e.g., this is what python and C++ do)
  8396. return v < 0 ? -Math.round(-v) : Math.round(v);
  8397. }
  8398. ],
  8399. 'floor': [
  8400. NumberType$a,
  8401. [NumberType$a],
  8402. function (ctx, ref) {
  8403. var n = ref[0];
  8404. return Math.floor(n.evaluate(ctx));
  8405. }
  8406. ],
  8407. 'ceil': [
  8408. NumberType$a,
  8409. [NumberType$a],
  8410. function (ctx, ref) {
  8411. var n = ref[0];
  8412. return Math.ceil(n.evaluate(ctx));
  8413. }
  8414. ],
  8415. 'filter-==': [
  8416. BooleanType$8,
  8417. [StringType$8, ValueType$a],
  8418. function (ctx, ref) {
  8419. var k = ref[0];
  8420. var v = ref[1];
  8421. return ctx.properties()[(k ).value] === (v ).value;
  8422. }
  8423. ],
  8424. 'filter-id-==': [
  8425. BooleanType$8,
  8426. [ValueType$a],
  8427. function (ctx, ref) {
  8428. var v = ref[0];
  8429. return ctx.id() === (v ).value;
  8430. }
  8431. ],
  8432. 'filter-like': [
  8433. BooleanType$8,
  8434. [StringType$8, StringType$8],
  8435. function (ctx, ref) {
  8436. var a = ref[0].value;
  8437. var b = ref[1].value;
  8438. var properties = ctx.properties();
  8439. return (a in properties) && (properties[a].indexOf(b)) > -1;
  8440. }
  8441. ],
  8442. 'filter-type-==': [
  8443. BooleanType$8,
  8444. [StringType$8],
  8445. function (ctx, ref) {
  8446. var v = ref[0];
  8447. return ctx.geometryType() === (v ).value;
  8448. }
  8449. ],
  8450. 'filter-<': [
  8451. BooleanType$8,
  8452. [StringType$8, ValueType$a],
  8453. function (ctx, ref) {
  8454. var k = ref[0];
  8455. var v = ref[1];
  8456. var a = ctx.properties()[(k ).value];
  8457. var b = (v ).value;
  8458. return typeof a === typeof b && a < b;
  8459. }
  8460. ],
  8461. 'filter-id-<': [
  8462. BooleanType$8,
  8463. [ValueType$a],
  8464. function (ctx, ref) {
  8465. var v = ref[0];
  8466. var a = ctx.id();
  8467. var b = (v ).value;
  8468. return typeof a === typeof b && a < b;
  8469. }
  8470. ],
  8471. 'filter->': [
  8472. BooleanType$8,
  8473. [StringType$8, ValueType$a],
  8474. function (ctx, ref) {
  8475. var k = ref[0];
  8476. var v = ref[1];
  8477. var a = ctx.properties()[(k ).value];
  8478. var b = (v ).value;
  8479. return typeof a === typeof b && a > b;
  8480. }
  8481. ],
  8482. 'filter-id->': [
  8483. BooleanType$8,
  8484. [ValueType$a],
  8485. function (ctx, ref) {
  8486. var v = ref[0];
  8487. var a = ctx.id();
  8488. var b = (v ).value;
  8489. return typeof a === typeof b && a > b;
  8490. }
  8491. ],
  8492. 'filter-<=': [
  8493. BooleanType$8,
  8494. [StringType$8, ValueType$a],
  8495. function (ctx, ref) {
  8496. var k = ref[0];
  8497. var v = ref[1];
  8498. var a = ctx.properties()[(k ).value];
  8499. var b = (v ).value;
  8500. return typeof a === typeof b && a <= b;
  8501. }
  8502. ],
  8503. 'filter-id-<=': [
  8504. BooleanType$8,
  8505. [ValueType$a],
  8506. function (ctx, ref) {
  8507. var v = ref[0];
  8508. var a = ctx.id();
  8509. var b = (v ).value;
  8510. return typeof a === typeof b && a <= b;
  8511. }
  8512. ],
  8513. 'filter->=': [
  8514. BooleanType$8,
  8515. [StringType$8, ValueType$a],
  8516. function (ctx, ref) {
  8517. var k = ref[0];
  8518. var v = ref[1];
  8519. var a = ctx.properties()[(k ).value];
  8520. var b = (v ).value;
  8521. return typeof a === typeof b && a >= b;
  8522. }
  8523. ],
  8524. 'filter-id->=': [
  8525. BooleanType$8,
  8526. [ValueType$a],
  8527. function (ctx, ref) {
  8528. var v = ref[0];
  8529. var a = ctx.id();
  8530. var b = (v ).value;
  8531. return typeof a === typeof b && a >= b;
  8532. }
  8533. ],
  8534. 'filter-has': [
  8535. BooleanType$8,
  8536. [ValueType$a],
  8537. function (ctx, ref) {
  8538. var k = ref[0];
  8539. return (k ).value in ctx.properties();
  8540. }
  8541. ],
  8542. 'filter-has-id': [
  8543. BooleanType$8,
  8544. [],
  8545. function (ctx) {
  8546. return ctx.id() !== null;
  8547. }
  8548. ],
  8549. 'filter-type-in': [
  8550. BooleanType$8,
  8551. [array$5(StringType$8)],
  8552. function (ctx, ref) {
  8553. var v = ref[0];
  8554. return (v ).value.indexOf(ctx.geometryType()) >= 0;
  8555. }
  8556. ],
  8557. 'filter-id-in': [
  8558. BooleanType$8,
  8559. [array$5(ValueType$a)],
  8560. function (ctx, ref) {
  8561. var v = ref[0];
  8562. return (v ).value.indexOf(ctx.id()) >= 0;
  8563. }
  8564. ],
  8565. 'filter-in-small': [
  8566. BooleanType$8,
  8567. [StringType$8, array$5(ValueType$a)],
  8568. // assumes v is an array literal
  8569. function (ctx, ref) {
  8570. var k = ref[0];
  8571. var v = ref[1];
  8572. return (v ).value.indexOf(ctx.properties()[(k ).value]) >= 0;
  8573. }
  8574. ],
  8575. 'filter-in-large': [
  8576. BooleanType$8,
  8577. [StringType$8, array$5(ValueType$a)],
  8578. // assumes v is a array literal with values sorted in ascending order and of a single type
  8579. function (ctx, ref) {
  8580. var k = ref[0];
  8581. var v = ref[1];
  8582. return binarySearch(ctx.properties()[(k ).value], (v ).value, 0, (v ).value.length - 1);
  8583. }
  8584. ],
  8585. 'all': {
  8586. type: BooleanType$8,
  8587. overloads: [
  8588. [
  8589. [BooleanType$8, BooleanType$8],
  8590. function (ctx, ref) {
  8591. var a = ref[0];
  8592. var b = ref[1];
  8593. return a.evaluate(ctx) && b.evaluate(ctx);
  8594. }
  8595. ],
  8596. [
  8597. varargs(BooleanType$8),
  8598. function (ctx, args) {
  8599. for (var i = 0, list = args; i < list.length; i += 1) {
  8600. var arg = list[i];
  8601. if (!arg.evaluate(ctx)) {
  8602. return false;
  8603. }
  8604. }
  8605. return true;
  8606. }
  8607. ]
  8608. ]
  8609. },
  8610. 'any': {
  8611. type: BooleanType$8,
  8612. overloads: [
  8613. [
  8614. [BooleanType$8, BooleanType$8],
  8615. function (ctx, ref) {
  8616. var a = ref[0];
  8617. var b = ref[1];
  8618. return a.evaluate(ctx) || b.evaluate(ctx);
  8619. }
  8620. ],
  8621. [
  8622. varargs(BooleanType$8),
  8623. function (ctx, args) {
  8624. for (var i = 0, list = args; i < list.length; i += 1) {
  8625. var arg = list[i];
  8626. if (arg.evaluate(ctx)) {
  8627. return true;
  8628. }
  8629. }
  8630. return false;
  8631. }
  8632. ]
  8633. ]
  8634. },
  8635. '!': [
  8636. BooleanType$8,
  8637. [BooleanType$8],
  8638. function (ctx, ref) {
  8639. var b = ref[0];
  8640. return !b.evaluate(ctx);
  8641. }
  8642. ],
  8643. 'is-supported-script': [
  8644. BooleanType$8,
  8645. [StringType$8],
  8646. // At parse time this will always return true, so we need to exclude this expression with isGlobalPropertyConstant
  8647. function (ctx, ref) {
  8648. var s = ref[0];
  8649. var isSupportedScript = ctx.globals && ctx.globals.isSupportedScript;
  8650. if (isSupportedScript) {
  8651. return isSupportedScript(s.evaluate(ctx));
  8652. }
  8653. return true;
  8654. }
  8655. ],
  8656. 'upcase': [
  8657. StringType$8,
  8658. [StringType$8],
  8659. function (ctx, ref) {
  8660. var s = ref[0];
  8661. return s.evaluate(ctx).toUpperCase();
  8662. }
  8663. ],
  8664. 'downcase': [
  8665. StringType$8,
  8666. [StringType$8],
  8667. function (ctx, ref) {
  8668. var s = ref[0];
  8669. return s.evaluate(ctx).toLowerCase();
  8670. }
  8671. ],
  8672. 'concat': [
  8673. StringType$8,
  8674. varargs(ValueType$a),
  8675. function (ctx, args) {
  8676. return args.map(function (arg) {
  8677. return Values.toString$1(arg.evaluate(ctx));
  8678. }).join('');
  8679. }
  8680. ],
  8681. 'resolved-locale': [
  8682. StringType$8,
  8683. [CollatorType$3],
  8684. function (ctx, ref) {
  8685. var collator = ref[0];
  8686. return collator.evaluate(ctx).resolvedLocale();
  8687. }
  8688. ]
  8689. });
  8690. var StyleExpression$1 = function StyleExpression(expression, propertySpec) {
  8691. this.expression = expression;
  8692. this._warningHistory = {};
  8693. this._evaluator = new EvaluationContext();
  8694. this._defaultValue = propertySpec ? getDefaultValue(propertySpec) : null;
  8695. this._enumValues = propertySpec && propertySpec.type === 'enum' ? propertySpec.values : null;
  8696. };
  8697. StyleExpression$1.prototype.evaluateWithoutErrorHandling = function evaluateWithoutErrorHandling(globals, feature, featureState, availableImages, formattedSection) {
  8698. this._evaluator.globals = globals;
  8699. this._evaluator.feature = feature;
  8700. this._evaluator.featureState = featureState;
  8701. this._evaluator.availableImages = availableImages || null;
  8702. this._evaluator.formattedSection = formattedSection;
  8703. return this.expression.evaluate(this._evaluator);
  8704. };
  8705. StyleExpression$1.prototype.evaluate = function evaluate(globals, feature, featureState, availableImages, formattedSection) {
  8706. this._evaluator.globals = globals;
  8707. this._evaluator.feature = feature || null;
  8708. this._evaluator.featureState = featureState || null;
  8709. this._evaluator.availableImages = availableImages || null;
  8710. this._evaluator.formattedSection = formattedSection || null;
  8711. try {
  8712. var val = this.expression.evaluate(this._evaluator);
  8713. // eslint-disable-next-line no-self-compare
  8714. if (val === null || val === undefined || (typeof val === 'number' && val !== val)) {
  8715. return this._defaultValue;
  8716. }
  8717. if (this._enumValues && !(val in this._enumValues)) {
  8718. throw new RuntimeError(("Expected value to be one of " + (Object.keys(this._enumValues).map(function (v) {
  8719. return JSON.stringify(v);
  8720. }).join(', ')) + ", but found " + (JSON.stringify(val)) + " instead."));
  8721. }
  8722. return val;
  8723. } catch (e) {
  8724. if (!this._warningHistory[e.message]) {
  8725. this._warningHistory[e.message] = true;
  8726. if (typeof console !== 'undefined') {
  8727. console.warn(e.message);
  8728. }
  8729. }
  8730. return this._defaultValue;
  8731. }
  8732. };
  8733. function isFunction(value) {
  8734. return typeof value === 'object' && value !== null && !Array.isArray(value);
  8735. }
  8736. function getDefaultValue(spec) {
  8737. if (spec.type === 'color' && isFunction(spec.default)) {
  8738. // Special case for heatmap-color: it uses the 'default:' to define a
  8739. // default color ramp, but createExpression expects a simple value to fall
  8740. // back to in case of runtime errors
  8741. return new Color(0, 0, 0, 0);
  8742. } else if (spec.type === 'color') {
  8743. return Color.parse(spec.default) || null;
  8744. } else if (spec.default === undefined) {
  8745. return null;
  8746. } else {
  8747. return spec.default;
  8748. }
  8749. }
  8750. function Expression() {
  8751. }
  8752. function success(value) {
  8753. return {result: 'success', value: value};
  8754. }
  8755. function error(value) {
  8756. return {result: 'error', value: value};
  8757. }
  8758. Expression.isExpression = function (testExpression) {
  8759. return Array.isArray(testExpression) && testExpression.length > 0 &&
  8760. typeof testExpression[0] === 'string' && testExpression[0] in expressions;
  8761. };
  8762. var NumberType$b = {kind: 'number'};
  8763. var StringType$9 = {kind: 'string'};
  8764. var BooleanType$9 = {kind: 'boolean'};
  8765. var ColorType$6 = {kind: 'color'};
  8766. var ValueType$b = {kind: 'value'};
  8767. var FormattedType$3 = {kind: 'formatted'};
  8768. var ResolvedImageType$4 = {kind: 'resolvedImage'};
  8769. function array$6(itemType, N) {
  8770. return {
  8771. kind: 'array',
  8772. itemType: itemType,
  8773. N: N
  8774. };
  8775. }
  8776. function getExpectedType(spec) {
  8777. var types = {
  8778. color: ColorType$6,
  8779. string: StringType$9,
  8780. number: NumberType$b,
  8781. enum: StringType$9,
  8782. boolean: BooleanType$9,
  8783. formatted: FormattedType$3,
  8784. resolvedImage: ResolvedImageType$4
  8785. };
  8786. if (spec.type === 'array') {
  8787. return array$6(types[spec.value] || ValueType$b, spec.length);
  8788. }
  8789. return types[spec.type];
  8790. }
  8791. Expression.createExpression = function (expression, propertySpec) {
  8792. var parser = new ParsingContext(expressions, [], propertySpec ? getExpectedType(propertySpec) : undefined);
  8793. // For string-valued properties, coerce to string at the top level rather than asserting.
  8794. var parsed = parser.parse(expression, undefined, undefined, undefined,
  8795. propertySpec && propertySpec.type === 'string' ? {typeAnnotation: 'coerce'} : undefined);
  8796. if (!parsed) {
  8797. //assert_1(parser.errors.length > 0);
  8798. return error(parser.errors);
  8799. }
  8800. return success(new StyleExpression$1(parsed, propertySpec));
  8801. };
  8802. function isFunction$1(value) {
  8803. return typeof value === 'object' && value !== null && !Array.isArray(value);
  8804. }
  8805. function extend$1(output) {
  8806. var inputs = [], len = arguments.length - 1;
  8807. while (len-- > 0) inputs[ len ] = arguments[ len + 1 ];
  8808. for (var i = 0, list = inputs; i < list.length; i += 1) {
  8809. var input = list[i];
  8810. for (var k in input) {
  8811. output[k] = input[k];
  8812. }
  8813. }
  8814. return output;
  8815. }
  8816. function evaluateIdentityFunction(parameters, propertySpec, input) {
  8817. if (propertySpec.type === 'color') {
  8818. input = Color$1.parse(input);
  8819. } else if (propertySpec.type === 'formatted') {
  8820. input = Formatted.fromString(input.toString());
  8821. } else if (propertySpec.type === 'resolvedImage') {
  8822. input = ResolvedImage.fromString(input.toString());
  8823. } else if (getType(input) !== propertySpec.type && (propertySpec.type !== 'enum' || !propertySpec.values[input])) {
  8824. input = undefined;
  8825. }
  8826. return coalesce(input, parameters.default, propertySpec.default);
  8827. }
  8828. function createFunction(parameters, propertySpec) {
  8829. var isColor = propertySpec.type === 'color';
  8830. var zoomAndFeatureDependent = parameters.stops && typeof parameters.stops[0][0] === 'object';
  8831. var featureDependent = zoomAndFeatureDependent || parameters.property !== undefined;
  8832. var zoomDependent = zoomAndFeatureDependent || !featureDependent;
  8833. var type = parameters.type || (supportsInterpolation(propertySpec) ? 'exponential' : 'interval');
  8834. if (isColor) {
  8835. parameters = extend$1({}, parameters);
  8836. if (parameters.stops) {
  8837. parameters.stops = parameters.stops.map(function (stop) {
  8838. return [stop[0], Color$1.parse(stop[1])];
  8839. });
  8840. }
  8841. if (parameters.default) {
  8842. parameters.default = Color$1.parse(parameters.default);
  8843. } else {
  8844. parameters.default = Color$1.parse(propertySpec.default);
  8845. }
  8846. }
  8847. if (parameters.colorSpace && parameters.colorSpace !== 'rgb' && !colorSpaces[parameters.colorSpace]) { // eslint-disable-line import/namespace
  8848. throw new Error(("Unknown color space: " + (parameters.colorSpace)));
  8849. }
  8850. var innerFun;
  8851. var hashedStops;
  8852. var categoricalKeyType;
  8853. if (type === 'exponential') {
  8854. innerFun = evaluateExponentialFunction;
  8855. } else if (type === 'interval') {
  8856. innerFun = evaluateIntervalFunction;
  8857. } else if (type === 'categorical') {
  8858. innerFun = evaluateCategoricalFunction;
  8859. // For categorical functions, generate an Object as a hashmap of the stops for fast searching
  8860. hashedStops = Object.create(null);
  8861. for (var i = 0, list = parameters.stops; i < list.length; i += 1) {
  8862. var stop = list[i];
  8863. hashedStops[stop[0]] = stop[1];
  8864. }
  8865. // Infer key type based on first stop key-- used to encforce strict type checking later
  8866. categoricalKeyType = typeof parameters.stops[0][0];
  8867. } else if (type === 'identity') {
  8868. innerFun = evaluateIdentityFunction;
  8869. } else {
  8870. throw new Error(("Unknown function type \"" + type + "\""));
  8871. }
  8872. if (zoomAndFeatureDependent) {
  8873. var featureFunctions = {};
  8874. var zoomStops = [];
  8875. for (var s = 0; s < parameters.stops.length; s++) {
  8876. var stop$1 = parameters.stops[s];
  8877. var zoom = stop$1[0].zoom;
  8878. if (featureFunctions[zoom] === undefined) {
  8879. featureFunctions[zoom] = {
  8880. zoom: zoom,
  8881. type: parameters.type,
  8882. property: parameters.property,
  8883. default: parameters.default,
  8884. stops: []
  8885. };
  8886. zoomStops.push(zoom);
  8887. }
  8888. featureFunctions[zoom].stops.push([stop$1[0].value, stop$1[1]]);
  8889. }
  8890. var featureFunctionStops = [];
  8891. for (var i$1 = 0, list$1 = zoomStops; i$1 < list$1.length; i$1 += 1) {
  8892. var z = list$1[i$1];
  8893. featureFunctionStops.push([featureFunctions[z].zoom, createFunction(featureFunctions[z], propertySpec)]);
  8894. }
  8895. var interpolationType = {name: 'linear'};
  8896. return {
  8897. kind: 'composite',
  8898. interpolationType: interpolationType,
  8899. interpolationFactor: Interpolate.interpolationFactor.bind(undefined, interpolationType),
  8900. zoomStops: featureFunctionStops.map(function (s) {
  8901. return s[0];
  8902. }),
  8903. evaluate: function evaluate(ref, properties) {
  8904. var zoom = ref.zoom;
  8905. return evaluateExponentialFunction({
  8906. stops: featureFunctionStops,
  8907. base: parameters.base
  8908. }, propertySpec, zoom).evaluate(zoom, properties);
  8909. }
  8910. };
  8911. } else if (zoomDependent) {
  8912. var interpolationType$1 = type === 'exponential' ?
  8913. {name: 'exponential', base: parameters.base !== undefined ? parameters.base : 1} : null;
  8914. return {
  8915. kind: 'camera',
  8916. interpolationType: interpolationType$1,
  8917. interpolationFactor: Interpolate.interpolationFactor.bind(undefined, interpolationType$1),
  8918. zoomStops: parameters.stops.map(function (s) {
  8919. return s[0];
  8920. }),
  8921. evaluate: function (ref) {
  8922. var zoom = ref.zoom;
  8923. return innerFun(parameters, propertySpec, zoom, hashedStops, categoricalKeyType);
  8924. }
  8925. };
  8926. } else {
  8927. return {
  8928. kind: 'source',
  8929. evaluate: function evaluate(_, feature) {
  8930. var value = feature && feature.properties ? feature.properties[parameters.property] : undefined;
  8931. if (value === undefined) {
  8932. return coalesce(parameters.default, propertySpec.default);
  8933. }
  8934. return innerFun(parameters, propertySpec, value, hashedStops, categoricalKeyType);
  8935. }
  8936. };
  8937. }
  8938. }
  8939. function coalesce(a, b, c) {
  8940. if (a !== undefined) return a;
  8941. if (b !== undefined) return b;
  8942. if (c !== undefined) return c;
  8943. }
  8944. // serialization wrapper for old-style stop functions normalized to the
  8945. // expression interface
  8946. var StylePropertyFunction = function StylePropertyFunction(parameters, specification) {
  8947. this._parameters = parameters;
  8948. this._specification = specification;
  8949. extend$1(this, createFunction(this._parameters, this._specification));
  8950. };
  8951. StylePropertyFunction.deserialize = function deserialize(serialized) {
  8952. return ((new StylePropertyFunction(serialized._parameters, serialized._specification)) );
  8953. };
  8954. StylePropertyFunction.serialize = function serialize(input) {
  8955. return {
  8956. _parameters: input._parameters,
  8957. _specification: input._specification
  8958. };
  8959. };
  8960. Expression.normalizePropertyExpression = function (value, specification) {
  8961. if (isFunction$1(value)) {
  8962. return (new StylePropertyFunction(value, specification) );
  8963. } else if (Expression.isExpression(value)) {
  8964. var expression = createPropertyExpression(value, specification);
  8965. if (expression.result === 'error') {
  8966. // this should have been caught in validation
  8967. throw new Error(expression.value.map(function (err) {
  8968. return ((err.key) + ": " + (err.message));
  8969. }).join(', '));
  8970. }
  8971. return expression.value;
  8972. } else {
  8973. var constant = value;
  8974. if (typeof value === 'string' && specification.type === 'color') {
  8975. constant = Color$1.parse(value);
  8976. }
  8977. return {
  8978. kind: 'constant',
  8979. evaluate: function () {
  8980. return constant;
  8981. }
  8982. };
  8983. }
  8984. };
  8985. function featureFilter() {
  8986. }
  8987. featureFilter.isExpressionFilter = function (filter) {
  8988. if (filter === true || filter === false) {
  8989. return true;
  8990. }
  8991. if (!Array.isArray(filter) || filter.length === 0) {
  8992. return false;
  8993. }
  8994. switch (filter[0]) {
  8995. case 'has':
  8996. return filter.length >= 2 && filter[1] !== '$id' && filter[1] !== '$type';
  8997. case 'in':
  8998. return filter.length >= 3 && Array.isArray(filter[2]);
  8999. case '!in':
  9000. case '!has':
  9001. case 'none':
  9002. return false;
  9003. case '==':
  9004. case '!=':
  9005. case '>':
  9006. case '>=':
  9007. case '<':
  9008. case '<=':
  9009. case 'like':
  9010. return filter.length !== 3 || (Array.isArray(filter[1]) || Array.isArray(filter[2]));
  9011. case 'any':
  9012. case 'all':
  9013. for (var i = 0, list = filter.slice(1); i < list.length; i += 1) {
  9014. var f = list[i];
  9015. if (!featureFilter.isExpressionFilter(f) && typeof f !== 'boolean') {
  9016. return false;
  9017. }
  9018. }
  9019. return true;
  9020. default:
  9021. return true;
  9022. }
  9023. };
  9024. var filterSpec = {
  9025. 'type': 'boolean',
  9026. 'default': false,
  9027. 'transition': false,
  9028. 'property-type': 'data-driven',
  9029. 'expression': {
  9030. 'interpolated': false,
  9031. 'parameters': ['zoom', 'feature']
  9032. }
  9033. };
  9034. /**
  9035. * Given a filter expressed as nested arrays, return a new function
  9036. * that evaluates whether a given feature (with a .properties or .tags property)
  9037. * passes its test.
  9038. *
  9039. * @private
  9040. * @param {Array} filter mapbox gl filter
  9041. * @returns {Function} filter-evaluating function
  9042. */
  9043. featureFilter.createFilter = function (filter) {
  9044. if (filter === null || filter === undefined) {
  9045. return function () {
  9046. return true;
  9047. };
  9048. }
  9049. if (!featureFilter.isExpressionFilter(filter)) {
  9050. filter = convertFilter(filter);
  9051. }
  9052. var compiled = Expression.createExpression(filter, filterSpec);
  9053. if (compiled.result === 'error') {
  9054. throw new Error(compiled.value.map(function (err) {
  9055. return ((err.key) + ": " + (err.message));
  9056. }).join(', '));
  9057. } else {
  9058. return function (globalProperties, feature) {
  9059. return compiled.value.evaluate(globalProperties, feature);
  9060. };
  9061. }
  9062. };
  9063. // Comparison function to sort numbers and strings
  9064. function compare(a, b) {
  9065. return a < b ? -1 : a > b ? 1 : 0;
  9066. }
  9067. function convertFilter(filter) {
  9068. if (!filter) {
  9069. return true;
  9070. }
  9071. var op = filter[0];
  9072. if (filter.length <= 1) {
  9073. return (op !== 'any');
  9074. }
  9075. var converted =
  9076. op === '==' ? convertComparisonOp(filter[1], filter[2], '==') :
  9077. op === '!=' ? convertNegation(convertComparisonOp(filter[1], filter[2], '==')) :
  9078. op === '<' ||
  9079. op === '>' ||
  9080. op === '<=' ||
  9081. op === '>=' ? convertComparisonOp(filter[1], filter[2], op) :
  9082. op === 'any' ? convertDisjunctionOp(filter.slice(1)) :
  9083. op === 'all' ? ['all'].concat(filter.slice(1).map(convertFilter)) :
  9084. op === 'none' ? ['all'].concat(filter.slice(1).map(convertFilter).map(convertNegation)) :
  9085. op === 'in' ? convertInOp(filter[1], filter.slice(2)) :
  9086. op === '!in' ? convertNegation(convertInOp(filter[1], filter.slice(2))) :
  9087. op === 'has' ? convertHasOp(filter[1]) :
  9088. op === '!has' ? convertNegation(convertHasOp(filter[1])) :
  9089. op === 'like' ? convertComparisonOp(filter[1], filter[2], 'like') :
  9090. true;
  9091. return converted;
  9092. }
  9093. function convertComparisonOp(property, value, op) {
  9094. switch (property) {
  9095. case '$type':
  9096. return [("filter-type-" + op), value];
  9097. case '$id':
  9098. return [("filter-id-" + op), value];
  9099. default:
  9100. return [("filter-" + op), property, value];
  9101. }
  9102. }
  9103. function convertDisjunctionOp(filters) {
  9104. return ['any'].concat(filters.map(convertFilter));
  9105. }
  9106. function convertInOp(property, values) {
  9107. if (values.length === 0) {
  9108. return false;
  9109. }
  9110. switch (property) {
  9111. case '$type':
  9112. return ["filter-type-in", ['literal', values]];
  9113. case '$id':
  9114. return ["filter-id-in", ['literal', values]];
  9115. default:
  9116. if (values.length > 200 && !values.some(function (v) {
  9117. return typeof v !== typeof values[0];
  9118. })) {
  9119. return ['filter-in-large', property, ['literal', values.sort(compare)]];
  9120. } else {
  9121. return ['filter-in-small', property, ['literal', values]];
  9122. }
  9123. }
  9124. }
  9125. function convertHasOp(property) {
  9126. switch (property) {
  9127. case '$type':
  9128. return true;
  9129. case '$id':
  9130. return ["filter-has-id"];
  9131. default:
  9132. return ["filter-has", property];
  9133. }
  9134. }
  9135. function convertNegation(filter) {
  9136. return ['!', filter];
  9137. }
  9138. var FeatureIndexArray$1 = arrayTypes.FeatureIndexArray;
  9139. var FeatureIndex = function FeatureIndex(tileID, grid, featureIndexArray) {
  9140. //this.tileID = tileID;
  9141. this.x = tileID.x;
  9142. this.y = tileID.y;
  9143. this.z = tileID.z;
  9144. this.grid = grid || new GridIndex(EXTENT, 16, 0);
  9145. this.featureIndexArray = featureIndexArray || new FeatureIndexArray$1();
  9146. };
  9147. FeatureIndex.prototype.insert = function insert(feature, geometry, featureIndex, sourceLayerIndex, bucketIndex, is3D) {
  9148. var key = this.featureIndexArray.length;
  9149. this.featureIndexArray.emplaceBack(featureIndex, sourceLayerIndex, bucketIndex);
  9150. var grid = this.grid;
  9151. for (var r = 0; r < geometry.length; r++) {
  9152. var ring = geometry[r];
  9153. var bbox = [Infinity, Infinity, -Infinity, -Infinity];
  9154. for (var i = 0; i < ring.length; i++) {
  9155. var p = ring[i];
  9156. bbox[0] = Math.min(bbox[0], p.x);
  9157. bbox[1] = Math.min(bbox[1], p.y);
  9158. bbox[2] = Math.max(bbox[2], p.x);
  9159. bbox[3] = Math.max(bbox[3], p.y);
  9160. }
  9161. if (bbox[0] < EXTENT &&
  9162. bbox[1] < EXTENT &&
  9163. bbox[2] >= 0 &&
  9164. bbox[3] >= 0) {
  9165. grid.insert(key, bbox[0], bbox[1], bbox[2], bbox[3]);
  9166. }
  9167. }
  9168. };
  9169. FeatureIndex.prototype.loadVTLayers = function loadVTLayers() {
  9170. if (!this.vtLayers) {
  9171. this.vtLayers = new VectorTile(new pbf.Protobuf(this.rawTileData)).layers;
  9172. this.sourceLayerCoder = new DictionaryCoder(this.vtLayers ? Object.keys(this.vtLayers).sort() : ['_geojsonTileLayer']);
  9173. }
  9174. return this.vtLayers;
  9175. };
  9176. // Finds non-symbol features in this tile at a particular position.
  9177. FeatureIndex.prototype.query = function query(args, styleLayers, sourceFeatureState) {
  9178. var this$1 = this;
  9179. this.loadVTLayers();
  9180. var params = args.params || {},
  9181. pixelsToTileUnits = EXTENT / args.tileSize,
  9182. filter = featureFilter.createFilter(params.filter);
  9183. var queryGeometry = args.queryGeometry;
  9184. var queryPadding = 5;
  9185. var bounds = getBounds(queryGeometry);
  9186. var matching = this.grid.query(bounds.minX - queryPadding, bounds.minY - queryPadding, bounds.maxX + queryPadding, bounds.maxY + queryPadding);
  9187. matching.sort(topDownFeatureComparator);
  9188. var result = {};
  9189. var previousIndex;
  9190. var loop = function (k) {
  9191. var index = matching[k];
  9192. // don't check the same feature more than once
  9193. if (index === previousIndex) {
  9194. return;
  9195. }
  9196. previousIndex = index;
  9197. var match = this$1.featureIndexArray.get(index);
  9198. var featureGeometry = null;
  9199. this$1.loadMatchingFeature(
  9200. result,
  9201. match.bucketIndex,
  9202. match.sourceLayerIndex,
  9203. match.featureIndex,
  9204. filter,
  9205. params.layers,
  9206. styleLayers,
  9207. function (feature, styleLayer) {
  9208. if (!featureGeometry) {
  9209. featureGeometry = loadGeometry(feature);
  9210. }
  9211. var featureState = {};
  9212. // if (feature.id) {
  9213. // // `feature-state` expression evaluation requires feature state to be available
  9214. // featureState = sourceFeatureState.getState(styleLayer.sourceLayer || '_geojsonTileLayer', feature.id);
  9215. // }
  9216. return styleLayer.queryIntersectsFeature(queryGeometry, feature, featureState, featureGeometry, this$1.z, args.transform, pixelsToTileUnits, args.pixelPosMatrix);
  9217. }
  9218. );
  9219. };
  9220. for (var k = 0; k < matching.length; k++) loop(k);
  9221. return result;
  9222. };
  9223. FeatureIndex.prototype.loadMatchingFeature = function loadMatchingFeature(result, bucketIndex, sourceLayerIndex, featureIndex, filter, filterLayerIDs, styleLayers, intersectionTest) {
  9224. if(!defined.defined(bucketIndex) || !defined.defined(sourceLayerIndex) || !defined.defined(featureIndex)){
  9225. return;
  9226. }
  9227. var layerIDs = this.bucketLayerIDs[bucketIndex];
  9228. if (filterLayerIDs && !Util.arraysIntersect(filterLayerIDs, layerIDs)) {
  9229. return;
  9230. }
  9231. var sourceLayerName = this.sourceLayerCoder.decode(sourceLayerIndex);
  9232. var sourceLayer = this.vtLayers[sourceLayerName];
  9233. var feature = sourceLayer.feature(featureIndex);
  9234. if (!filter(new EvaluationParameters$1(this.z), feature)) {
  9235. return;
  9236. }
  9237. for (var l = 0; l < layerIDs.length; l++) {
  9238. var layerID = layerIDs[l];
  9239. if (filterLayerIDs && filterLayerIDs.indexOf(layerID) < 0) {
  9240. continue;
  9241. }
  9242. var styleLayer = styleLayers[layerID];
  9243. if (!styleLayer) {
  9244. continue;
  9245. }
  9246. var intersectionZ = !intersectionTest || intersectionTest(feature, styleLayer);
  9247. if (!intersectionZ) {
  9248. // Only applied for non-symbol features
  9249. continue;
  9250. }
  9251. // var geojsonFeature = new Feature(feature, this.z, this.x, this.y);
  9252. // (geojsonFeature ).layer = styleLayer.serialize();
  9253. feature.layer = styleLayer.serialize();
  9254. var layerResult = result[layerID];
  9255. if (layerResult === undefined) {
  9256. layerResult = result[layerID] = [];
  9257. }
  9258. layerResult.push({featureIndex: featureIndex, feature: feature, intersectionZ: intersectionZ});
  9259. }
  9260. };
  9261. // Given a set of symbol indexes that have already been looked up,
  9262. // return a matching set of GeoJSONFeatures
  9263. FeatureIndex.prototype.lookupSymbolFeatures = function lookupSymbolFeatures(symbolFeatureIndexes, bucketIndex, sourceLayerIndex, filterSpec, filterLayerIDs, styleLayers) {
  9264. var result = {};
  9265. this.loadVTLayers();
  9266. var filter = createFilter(filterSpec);
  9267. for (var i = 0, list = symbolFeatureIndexes; i < list.length; i += 1) {
  9268. var symbolFeatureIndex = list[i];
  9269. this.loadMatchingFeature(
  9270. result,
  9271. bucketIndex,
  9272. sourceLayerIndex,
  9273. symbolFeatureIndex,
  9274. filter,
  9275. filterLayerIDs,
  9276. styleLayers
  9277. );
  9278. }
  9279. return result;
  9280. };
  9281. FeatureIndex.prototype.hasLayer = function hasLayer(id) {
  9282. for (var i$1 = 0, list$1 = this.bucketLayerIDs; i$1 < list$1.length; i$1 += 1) {
  9283. var layerIDs = list$1[i$1];
  9284. for (var i = 0, list = layerIDs; i < list.length; i += 1) {
  9285. var layerID = list[i];
  9286. if (id === layerID) {
  9287. return true;
  9288. }
  9289. }
  9290. }
  9291. return false;
  9292. };
  9293. // register(
  9294. // 'FeatureIndex',
  9295. // FeatureIndex,
  9296. // {omit: ['rawTileData', 'sourceLayerCoder']}
  9297. // );
  9298. function getBounds(geometry) {
  9299. var minX = Infinity;
  9300. var minY = Infinity;
  9301. var maxX = -Infinity;
  9302. var maxY = -Infinity;
  9303. for (var i = 0, list = geometry; i < list.length; i += 1) {
  9304. var p = list[i];
  9305. minX = Math.min(minX, p.x);
  9306. minY = Math.min(minY, p.y);
  9307. maxX = Math.max(maxX, p.x);
  9308. maxY = Math.max(maxY, p.y);
  9309. }
  9310. return {minX: minX, minY: minY, maxX: maxX, maxY: maxY};
  9311. }
  9312. function topDownFeatureComparator(a, b) {
  9313. return b - a;
  9314. }
  9315. WebWorkerTransfer.register('FeatureIndex', FeatureIndex, {omit: ['rawTileData', 'sourceLayerCoder', 'vtLayers']});
  9316. const refProperties = ['type', 'source', 'source-layer', 'minzoom', 'maxzoom', 'filter', 'layout'];
  9317. function stringify(obj) {
  9318. var type = typeof obj;
  9319. if (type === 'number' || type === 'boolean' || type === 'string' || obj === undefined || obj === null)
  9320. { return JSON.stringify(obj); }
  9321. if (Array.isArray(obj)) {
  9322. var str$1 = '[';
  9323. for (var i$1 = 0, list = obj; i$1 < list.length; i$1 += 1) {
  9324. var val = list[i$1];
  9325. str$1 += (stringify(val)) + ",";
  9326. }
  9327. return (str$1 + "]");
  9328. }
  9329. var keys = Object.keys(obj).sort();
  9330. var str = '{';
  9331. for (var i = 0; i < keys.length; i++) {
  9332. str += (JSON.stringify(keys[i])) + ":" + (stringify(obj[keys[i]])) + ",";
  9333. }
  9334. return (str + "}");
  9335. }
  9336. function getKey(layer) {
  9337. var key = '';
  9338. for (var i = 0, list = refProperties; i < list.length; i += 1) {
  9339. var k = list[i];
  9340. key += "/" + (stringify(layer[k]));
  9341. }
  9342. return key;
  9343. }
  9344. /**
  9345. * Given an array of layers, return an array of arrays of layers where all
  9346. * layers in each group have identical layout-affecting properties. These
  9347. * are the properties that were formerly used by explicit `ref` mechanism
  9348. * for layers: 'type', 'source', 'source-layer', 'minzoom', 'maxzoom',
  9349. * 'filter', and 'layout'.
  9350. *
  9351. * The input is not modified. The output layers are references to the
  9352. * input layers.
  9353. *
  9354. * @private
  9355. * @param {Array<Layer>} layers
  9356. * @param {Object} [cachedKeys] - an object to keep already calculated keys.
  9357. * @returns {Array<Array<Layer>>}
  9358. */
  9359. function groupByLayout(layers, cachedKeys) {
  9360. var groups = {};
  9361. for (var i = 0; i < layers.length; i++) {
  9362. var k = (cachedKeys && cachedKeys[layers[i].id]) || getKey(layers[i]);
  9363. // update the cache if there is one
  9364. if (cachedKeys)
  9365. { cachedKeys[layers[i].id] = k; }
  9366. var group = groups[k];
  9367. if (!group) {
  9368. group = groups[k] = [];
  9369. }
  9370. group.push(layers[i]);
  9371. }
  9372. var result = [];
  9373. for (var k$1 in groups) {
  9374. result.push(groups[k$1]);
  9375. }
  9376. return result;
  9377. }
  9378. var layout$1 = createLayout([
  9379. {name: 'a_pos', components: 2, type: 'Int16'}
  9380. ], 4);
  9381. var members = layout$1.members;
  9382. function addCircleVertex(layoutVertexArray, x, y, extrudeX, extrudeY) {
  9383. layoutVertexArray.emplaceBack(
  9384. (x * 2) + ((extrudeX + 1) / 2),
  9385. (y * 2) + ((extrudeY + 1) / 2));
  9386. }
  9387. /**
  9388. * Circles are represented by two triangles.
  9389. *
  9390. * Each corner has a pos that is the center of the circle and an extrusion
  9391. * vector that is where it points.
  9392. * @private
  9393. */
  9394. var CircleBucket = function CircleBucket(options) {
  9395. this.zoom = options.zoom;
  9396. this.overscaling = options.overscaling;
  9397. this.layers = options.layers;
  9398. this.layerIds = this.layers.map(function (layer) {
  9399. return layer.id;
  9400. });
  9401. this.index = options.index;
  9402. this.hasPattern = false;
  9403. this.layoutVertexArray = new StructArrayLayout2i4();
  9404. this.indexArray = new StructArrayLayout3ui6();
  9405. this.segments = new SegmentVector();
  9406. this.programConfigurations = new ProgramConfigurationSet(members, options.layers, options.zoom);
  9407. this.stateDependentLayerIds = this.layers.filter(function (l) {
  9408. return l.isStateDependent();
  9409. }).map(function (l) {
  9410. return l.id;
  9411. });
  9412. };
  9413. CircleBucket.prototype.populate = function populate(features, options) {
  9414. var styleLayer = this.layers[0];
  9415. var bucketFeatures = [];
  9416. var circleSortKey = null;
  9417. // Heatmap layers are handled in this bucket and have no evaluated properties, so we check our access
  9418. if (styleLayer.type === 'circle') {
  9419. circleSortKey = ((styleLayer )).layout.get('circle-sort-key');
  9420. }
  9421. for (var i = 0, list = features; i < list.length; i += 1) {
  9422. var ref = list[i];
  9423. var feature = ref.feature;
  9424. var index = ref.index;
  9425. var sourceLayerIndex = ref.sourceLayerIndex;
  9426. if (this.layers[0]._featureFilter(new EvaluationParameters$1(0), feature)) {
  9427. var geometry = loadGeometry(feature);
  9428. var sortKey = circleSortKey ?
  9429. circleSortKey.evaluate(feature, {}) :
  9430. undefined;
  9431. var bucketFeature = {
  9432. id: feature.id,
  9433. properties: feature.properties,
  9434. type: feature.type,
  9435. sourceLayerIndex: sourceLayerIndex,
  9436. index: index,
  9437. geometry: geometry,
  9438. patterns: {},
  9439. sortKey: sortKey
  9440. };
  9441. bucketFeatures.push(bucketFeature);
  9442. }
  9443. }
  9444. if (circleSortKey) {
  9445. bucketFeatures.sort(function (a, b) {
  9446. // a.sortKey is always a number when in use
  9447. return ((a.sortKey ) ) - ((b.sortKey ) );
  9448. });
  9449. }
  9450. for (var i$1 = 0, list$1 = bucketFeatures; i$1 < list$1.length; i$1 += 1) {
  9451. var bucketFeature$1 = list$1[i$1];
  9452. var ref$1 = bucketFeature$1;
  9453. var geometry$1 = ref$1.geometry;
  9454. var index$1 = ref$1.index;
  9455. var sourceLayerIndex$1 = ref$1.sourceLayerIndex;
  9456. var feature$1 = features[index$1].feature;
  9457. this.addFeature(bucketFeature$1, geometry$1, index$1);
  9458. options.featureIndex.insert(feature$1, geometry$1, index$1, sourceLayerIndex$1, this.index);
  9459. }
  9460. };
  9461. CircleBucket.prototype.update = function update(states, vtLayer, imagePositions) {
  9462. if (!this.stateDependentLayers.length) {
  9463. return;
  9464. }
  9465. this.programConfigurations.updatePaintArrays(states, vtLayer, this.stateDependentLayers, imagePositions);
  9466. };
  9467. CircleBucket.prototype.isEmpty = function isEmpty() {
  9468. return this.layoutVertexArray.length === 0;
  9469. };
  9470. CircleBucket.prototype.uploadPending = function uploadPending() {
  9471. return !this.uploaded || this.programConfigurations.needsUpload;
  9472. };
  9473. CircleBucket.prototype.upload = function upload(context) {
  9474. if (!this.uploaded) {
  9475. this.layoutVertexBuffer = context.createVertexBuffer(this.layoutVertexArray, members);
  9476. this.indexBuffer = context.createIndexBuffer(this.indexArray);
  9477. }
  9478. this.programConfigurations.upload(context);
  9479. this.uploaded = true;
  9480. };
  9481. CircleBucket.prototype.destroy = function destroy() {
  9482. if (!this.layoutVertexBuffer) {
  9483. return;
  9484. }
  9485. this.layoutVertexBuffer.destroy();
  9486. this.indexBuffer.destroy();
  9487. this.programConfigurations.destroy();
  9488. this.segments.destroy();
  9489. };
  9490. CircleBucket.prototype.addFeature = function addFeature(feature, geometry, index) {
  9491. for (var i$1 = 0, list$1 = geometry; i$1 < list$1.length; i$1 += 1) {
  9492. var ring = list$1[i$1];
  9493. for (var i = 0, list = ring; i < list.length; i += 1) {
  9494. var point = list[i];
  9495. var x = point.x;
  9496. var y = point.y;
  9497. // Do not include points that are outside the tile boundaries.
  9498. if (x < 0 || x >= EXTENT || y < 0 || y >= EXTENT) {
  9499. continue;
  9500. }
  9501. // this geometry will be of the Point type, and we'll derive
  9502. // two triangles from it.
  9503. //
  9504. // ┌─────────┐
  9505. // │ 3 2 │
  9506. // │ │
  9507. // │ 0 1 │
  9508. // └─────────┘
  9509. var segment = this.segments.prepareSegment(4, this.layoutVertexArray, this.indexArray, feature.sortKey);
  9510. var index$1 = segment.vertexLength;
  9511. addCircleVertex(this.layoutVertexArray, x, y, -1, -1);
  9512. addCircleVertex(this.layoutVertexArray, x, y, 1, -1);
  9513. addCircleVertex(this.layoutVertexArray, x, y, 1, 1);
  9514. addCircleVertex(this.layoutVertexArray, x, y, -1, 1);
  9515. this.indexArray.emplaceBack(index$1, index$1 + 1, index$1 + 2);
  9516. this.indexArray.emplaceBack(index$1, index$1 + 3, index$1 + 2);
  9517. segment.vertexLength += 4;
  9518. segment.primitiveLength += 2;
  9519. }
  9520. }
  9521. this.programConfigurations.populatePaintArrays(this.layoutVertexArray.length, feature, index, {});
  9522. };
  9523. WebWorkerTransfer.register('CircleBucket', CircleBucket, {omit: ['layers']});
  9524. /**
  9525. * An implementation of `Property` for properties that do not permit data-driven (source or composite) expressions.
  9526. * This restriction allows us to declare statically that the result of possibly evaluating this kind of property
  9527. * is in fact always the scalar type `T`, and can be used without further evaluating the value on a per-feature basis.
  9528. *
  9529. * @private
  9530. */
  9531. var DataConstantProperty = function DataConstantProperty(specification) {
  9532. this.specification = specification;
  9533. };
  9534. DataConstantProperty.prototype.possiblyEvaluate = function possiblyEvaluate(value, parameters) {
  9535. //assert_1(!value.isDataDriven());
  9536. return value.expression.evaluate(parameters);
  9537. };
  9538. DataConstantProperty.prototype.interpolate = function interpolate$1(a, b, t) {
  9539. var interp = (interpolate )[this.specification.type];
  9540. if (interp) {
  9541. return interp(a, b, t);
  9542. } else {
  9543. return a;
  9544. }
  9545. };
  9546. WebWorkerTransfer.register('DataConstantProperty', DataConstantProperty);
  9547. /**
  9548. * An implementation of `Property` for properties that permit data-driven (source or composite) expressions.
  9549. * The result of possibly evaluating this kind of property is `PossiblyEvaluatedPropertyValue<T>`; obtaining
  9550. * a scalar value `T` requires further evaluation on a per-feature basis.
  9551. *
  9552. * @private
  9553. */
  9554. var DataDrivenProperty = function DataDrivenProperty(specification, overrides) {
  9555. this.specification = specification;
  9556. this.overrides = overrides;
  9557. };
  9558. DataDrivenProperty.prototype.possiblyEvaluate = function possiblyEvaluate(value, parameters, availableImages) {
  9559. if (value.expression.kind === 'constant' || value.expression.kind === 'camera') {
  9560. return new PossiblyEvaluatedPropertyValue$1(this, {kind: 'constant', value: value.expression.evaluate(parameters, (null ), {}, availableImages)}, parameters);
  9561. } else {
  9562. return new PossiblyEvaluatedPropertyValue$1(this, value.expression, parameters);
  9563. }
  9564. };
  9565. DataDrivenProperty.prototype.interpolate = function interpolate$2(a, b, t) {
  9566. // If either possibly-evaluated value is non-constant, give up: we aren't able to interpolate data-driven values.
  9567. if (a.value.kind !== 'constant' || b.value.kind !== 'constant') {
  9568. return a;
  9569. }
  9570. // Special case hack solely for fill-outline-color. The undefined value is subsequently handled in
  9571. // FillStyleLayer#recalculate, which sets fill-outline-color to the fill-color value if the former
  9572. // is a PossiblyEvaluatedPropertyValue containing a constant undefined value. In addition to the
  9573. // return value here, the other source of a PossiblyEvaluatedPropertyValue containing a constant
  9574. // undefined value is the "default value" for fill-outline-color held in
  9575. // `Properties#defaultPossiblyEvaluatedValues`, which serves as the prototype of
  9576. // `PossiblyEvaluated#_values`.
  9577. if (a.value.value === undefined || b.value.value === undefined) {
  9578. return new PossiblyEvaluatedPropertyValue$1(this, {kind: 'constant', value: (undefined )}, a.parameters);
  9579. }
  9580. var interp = (interpolate )[this.specification.type];
  9581. if (interp) {
  9582. return new PossiblyEvaluatedPropertyValue$1(this, {kind: 'constant', value: interp(a.value.value, b.value.value, t)}, a.parameters);
  9583. } else {
  9584. return a;
  9585. }
  9586. };
  9587. DataDrivenProperty.prototype.evaluate = function evaluate(value, parameters, feature, featureState, availableImages) {
  9588. if (value.kind === 'constant') {
  9589. return value.value;
  9590. } else {
  9591. return value.evaluate(parameters, feature, featureState, availableImages);
  9592. }
  9593. };
  9594. WebWorkerTransfer.register('DataDrivenProperty', DataDrivenProperty);
  9595. var PropertyValue = function PropertyValue(property, value) {
  9596. this.property = property;
  9597. this.value = value;
  9598. this.expression = Expression.normalizePropertyExpression(value === undefined ? property.specification.default : value, property.specification);
  9599. };
  9600. PropertyValue.prototype.isDataDriven = function isDataDriven() {
  9601. return this.expression.kind === 'source' || this.expression.kind === 'composite';
  9602. };
  9603. PropertyValue.prototype.possiblyEvaluate = function possiblyEvaluate(parameters, availableImages) {
  9604. return this.property.possiblyEvaluate(this, parameters, availableImages);
  9605. };
  9606. /**
  9607. * Given a value `t` that varies between 0 and 1, return
  9608. * an interpolation function that eases between 0 and 1 in a pleasing
  9609. * cubic in-out fashion.
  9610. *
  9611. * @private
  9612. */
  9613. function easeCubicInOut(t ) {
  9614. if (t <= 0) { return 0; }
  9615. if (t >= 1) { return 1; }
  9616. var t2 = t * t,
  9617. t3 = t2 * t;
  9618. return 4 * (t < 0.5 ? t3 : 3 * (t - t2) + t3 - 0.75);
  9619. }
  9620. /**
  9621. * `TransitioningPropertyValue` implements the first of two intermediate steps in the evaluation chain of a paint
  9622. * property value. In this step, transitions between old and new values are handled: as long as the transition is in
  9623. * progress, `TransitioningPropertyValue` maintains a reference to the prior value, and interpolates between it and
  9624. * the new value based on the current time and the configured transition duration and delay. The product is the next
  9625. * step in the evaluation chain: the "possibly evaluated" result type `R`. See below for more on this concept.
  9626. *
  9627. * @private
  9628. */
  9629. var TransitioningPropertyValue = function TransitioningPropertyValue(property, value, prior, transition, now) {
  9630. this.property = property;
  9631. this.value = value;
  9632. this.begin = now + transition.delay || 0;
  9633. this.end = this.begin + transition.duration || 0;
  9634. if (property.specification.transition && (transition.delay || transition.duration)) {
  9635. this.prior = prior;
  9636. }
  9637. };
  9638. TransitioningPropertyValue.prototype.possiblyEvaluate = function possiblyEvaluate(parameters, availableImages) {
  9639. var now = parameters.now || 0;
  9640. var finalValue = this.value.possiblyEvaluate(parameters, availableImages);
  9641. var prior = this.prior;
  9642. if (!prior) {
  9643. // No prior value.
  9644. return finalValue;
  9645. } else if (now > this.end) {
  9646. // Transition from prior value is now complete.
  9647. this.prior = null;
  9648. return finalValue;
  9649. } else if (this.value.isDataDriven()) {
  9650. // Transitions to data-driven properties are not supported.
  9651. // We snap immediately to the data-driven value so that, when we perform layout,
  9652. // we see the data-driven function and can use it to populate vertex buffers.
  9653. this.prior = null;
  9654. return finalValue;
  9655. } else if (now < this.begin) {
  9656. // Transition hasn't started yet.
  9657. return prior.possiblyEvaluate(parameters, availableImages);
  9658. } else {
  9659. // Interpolate between recursively-calculated prior value and final.
  9660. var t = (now - this.begin) / (this.end - this.begin);
  9661. return this.property.interpolate(prior.possiblyEvaluate(parameters, availableImages), finalValue, easeCubicInOut(t));
  9662. }
  9663. };
  9664. /**
  9665. * @module util
  9666. * @private
  9667. */
  9668. function Util$1() {
  9669. }
  9670. /**
  9671. * Given a value `t` that varies between 0 and 1, return
  9672. * an interpolation function that eases between 0 and 1 in a pleasing
  9673. * cubic in-out fashion.
  9674. *
  9675. * @private
  9676. */
  9677. Util$1.easeCubicInOut = function (t) {
  9678. if (t <= 0) {
  9679. return 0;
  9680. }
  9681. if (t >= 1) {
  9682. return 1;
  9683. }
  9684. var t2 = t * t,
  9685. t3 = t2 * t;
  9686. return 4 * (t < 0.5 ? t3 : 3 * (t - t2) + t3 - 0.75);
  9687. };
  9688. /*
  9689. * Call an asynchronous function on an array of arguments,
  9690. * calling `callback` with the completed results of all calls.
  9691. *
  9692. * @param array input to each call of the async function.
  9693. * @param fn an async function with signature (data, callback)
  9694. * @param callback a callback run after all async work is done.
  9695. * called with an array, containing the results of each async call.
  9696. * @private
  9697. */
  9698. Util$1.asyncAll = function (array, fn, callback) {
  9699. if (!array.length) {
  9700. return callback(null, []);
  9701. }
  9702. var remaining = array.length;
  9703. var results = new Array(array.length);
  9704. var error = null;
  9705. array.forEach(function (item, i) {
  9706. fn(item, function (err, result) {
  9707. if (err) {
  9708. error = err;
  9709. }
  9710. results[i] = ((result ) ); // https://github.com/facebook/flow/issues/2123
  9711. if (--remaining === 0) {
  9712. callback(error, results);
  9713. }
  9714. });
  9715. });
  9716. };
  9717. /**
  9718. * Given a destination object and optionally many source objects,
  9719. * copy all properties from the source objects into the destination.
  9720. * The last source object given overrides properties from previous
  9721. * source objects.
  9722. *
  9723. * @param dest destination object
  9724. * @param sources sources from which properties are pulled
  9725. * @private
  9726. */
  9727. Util$1.extend = function (dest) {
  9728. var sources = [], len = arguments.length - 1;
  9729. while (len-- > 0) sources[ len ] = arguments[ len + 1 ];
  9730. for (var i = 0, list = sources; i < list.length; i += 1) {
  9731. var src = list[i];
  9732. for (var k in src) {
  9733. dest[k] = src[k];
  9734. }
  9735. }
  9736. return dest;
  9737. };
  9738. var id$1 = 1;
  9739. /**
  9740. * Return a unique numeric id, starting at 1 and incrementing with
  9741. * each call.
  9742. *
  9743. * @returns unique numeric id.
  9744. * @private
  9745. */
  9746. Util$1.uniqueId = function () {
  9747. return id$1++;
  9748. };
  9749. /**
  9750. * Return a random UUID (v4). Taken from: https://gist.github.com/jed/982883
  9751. * @private
  9752. */
  9753. Util$1.uuid = function () {
  9754. function b(a) {
  9755. return a ? (a ^ Math.random() * 16 >> a / 4).toString(16) :
  9756. //$FlowFixMe: Flow doesn't like the implied array literal conversion here
  9757. ([1e7] + -[1e3] + -4e3 + -8e3 + -1e11).replace(/[018]/g, b);
  9758. }
  9759. return b();
  9760. };
  9761. /**
  9762. * Validate a string to match UUID(v4) of the
  9763. * form: xxxxxxxx-xxxx-4xxx-[89ab]xxx-xxxxxxxxxxxx
  9764. * @param str string to validate.
  9765. * @private
  9766. */
  9767. Util$1.validateUuid = function (str) {
  9768. return str ? /^[0-9a-f]{8}-[0-9a-f]{4}-[4][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(str) : false;
  9769. };
  9770. /**
  9771. * Given an array of member function names as strings, replace all of them
  9772. * with bound versions that will always refer to `context` as `this`. This
  9773. * is useful for classes where otherwise event bindings would reassign
  9774. * `this` to the evented object or some other value: this lets you ensure
  9775. * the `this` value always.
  9776. *
  9777. * @param fns list of member function names
  9778. * @param context the context value
  9779. * @example
  9780. * function MyClass() {
  9781. * bindAll(['ontimer'], this);
  9782. * this.name = 'Tom';
  9783. * }
  9784. * MyClass.prototype.ontimer = function() {
  9785. * alert(this.name);
  9786. * };
  9787. * var myClass = new MyClass();
  9788. * setTimeout(myClass.ontimer, 100);
  9789. * @private
  9790. */
  9791. Util$1.bindAll = function (fns, context) {
  9792. fns.forEach(function (fn) {
  9793. if (!context[fn]) {
  9794. return;
  9795. }
  9796. context[fn] = context[fn].bind(context);
  9797. });
  9798. };
  9799. /**
  9800. * Determine if a string ends with a particular substring
  9801. *
  9802. * @private
  9803. */
  9804. Util$1.endsWith = function (string, suffix) {
  9805. return string.indexOf(suffix, string.length - suffix.length) !== -1;
  9806. };
  9807. /**
  9808. * Create an object by mapping all the values of an existing object while
  9809. * preserving their keys.
  9810. *
  9811. * @private
  9812. */
  9813. Util$1.mapObject = function (input, iterator, context) {
  9814. var output = {};
  9815. for (var key in input) {
  9816. output[key] = iterator.call(context || this, input[key], key, input);
  9817. }
  9818. return output;
  9819. };
  9820. /**
  9821. * Create an object by filtering out values of an existing object.
  9822. *
  9823. * @private
  9824. */
  9825. Util$1.filterObject = function (input, iterator, context) {
  9826. var output = {};
  9827. for (var key in input) {
  9828. if (iterator.call(context || this, input[key], key, input)) {
  9829. output[key] = input[key];
  9830. }
  9831. }
  9832. return output;
  9833. };
  9834. /**
  9835. * Deeply clones two objects.
  9836. *
  9837. * @private
  9838. */
  9839. Util$1.clone = function (input) {
  9840. if (Array.isArray(input)) {
  9841. return input.map(Util$1.clone);
  9842. } else if (typeof input === 'object' && input) {
  9843. return ((Util$1.mapObject(input, Util$1.clone) ) );
  9844. } else {
  9845. return input;
  9846. }
  9847. };
  9848. Util$1.deepEqual = function (a, b) {
  9849. if (Array.isArray(a)) {
  9850. if (!Array.isArray(b) || a.length !== b.length) {
  9851. return false;
  9852. }
  9853. for (var i = 0; i < a.length; i++) {
  9854. if (!Util$1.deepEqual(a[i], b[i])) {
  9855. return false;
  9856. }
  9857. }
  9858. return true;
  9859. }
  9860. if (typeof a === 'object' && a !== null && b !== null) {
  9861. if (!(typeof b === 'object')) {
  9862. return false;
  9863. }
  9864. var keys = Object.keys(a);
  9865. if (keys.length !== Object.keys(b).length) {
  9866. return false;
  9867. }
  9868. for (var key in a) {
  9869. if (!Util$1.deepEqual(a[key], b[key])) {
  9870. return false;
  9871. }
  9872. }
  9873. return true;
  9874. }
  9875. return a === b;
  9876. };
  9877. /**
  9878. * Check if two arrays have at least one common element.
  9879. *
  9880. * @private
  9881. */
  9882. Util$1.arraysIntersect = function (a, b) {
  9883. for (var l = 0; l < a.length; l++) {
  9884. if (b.indexOf(a[l]) >= 0) {
  9885. return true;
  9886. }
  9887. }
  9888. return false;
  9889. };
  9890. /**
  9891. * Indicates if the provided Points are in a counter clockwise (true) or clockwise (false) order
  9892. *
  9893. * @private
  9894. * @returns true for a counter clockwise set of points
  9895. */
  9896. // http://bryceboe.com/2006/10/23/line-segment-intersection-algorithm/
  9897. Util$1.isCounterClockwise = function (a, b, c) {
  9898. return (c.y - a.y) * (b.x - a.x) > (b.y - a.y) * (c.x - a.x);
  9899. };
  9900. /* global self, WorkerGlobalScope */
  9901. /**
  9902. * Retuns true if the when run in the web-worker context.
  9903. *
  9904. * @private
  9905. * @returns {boolean}
  9906. */
  9907. Util$1.isWorker = function () {
  9908. return typeof WorkerGlobalScope !== 'undefined' && typeof self !== 'undefined' &&
  9909. self instanceof WorkerGlobalScope;
  9910. };
  9911. var _isSafari$1 = null;
  9912. /**
  9913. * Returns true when run in WebKit derived browsers.
  9914. * This is used as a workaround for a memory leak in Safari caused by using Transferable objects to
  9915. * transfer data between WebWorkers and the main thread.
  9916. * https://github.com/mapbox/mapbox-gl-js/issues/8771
  9917. *
  9918. * This should be removed once the underlying Safari issue is fixed.
  9919. *
  9920. * @private
  9921. * @param scope {WindowOrWorkerGlobalScope} Since this function is used both on the main thread and WebWorker context,
  9922. * let the calling scope pass in the global scope object.
  9923. * @returns {boolean}
  9924. */
  9925. Util$1.isSafari = function (scope) {
  9926. if (_isSafari$1 == null) {
  9927. var userAgent = scope.navigator ? scope.navigator.userAgent : null;
  9928. _isSafari$1 = !!scope.safari || !!(userAgent && (/\b(iPad|iPhone|iPod)\b/.test(userAgent) || (!!userAgent.match('Safari') && !userAgent.match('Chrome'))));
  9929. }
  9930. return _isSafari$1;
  9931. };
  9932. /**
  9933. * Replace tokens in a string template with values in an object
  9934. *
  9935. * @param properties a key/value relationship between tokens and replacements
  9936. * @param text the template string
  9937. * @returns the template with tokens replaced
  9938. * @private
  9939. */
  9940. Util$1.resolveTokens = function (properties, text) {
  9941. return text.replace(/{([^{}]+)}/g, function (match, key) {
  9942. return key in properties ? String(properties[key]) : '';
  9943. });
  9944. };
  9945. /**
  9946. * Paint properties are _transitionable_: they can change in a fluid manner, interpolating or cross-fading between
  9947. * old and new value. The duration of the transition, and the delay before it begins, is configurable.
  9948. *
  9949. * `TransitionablePropertyValue` is a compositional class that stores both the property value and that transition
  9950. * configuration.
  9951. *
  9952. * A `TransitionablePropertyValue` can calculate the next step in the evaluation chain for paint property values:
  9953. * `TransitioningPropertyValue`.
  9954. *
  9955. * @private
  9956. */
  9957. var TransitionablePropertyValue = function TransitionablePropertyValue(property) {
  9958. this.property = property;
  9959. this.value = new PropertyValue(property, undefined);
  9960. };
  9961. TransitionablePropertyValue.prototype.transitioned = function transitioned(parameters, prior) {
  9962. return new TransitioningPropertyValue(this.property, this.value, prior, // eslint-disable-line no-use-before-define
  9963. Util$1.extend({}, parameters.transition, this.transition), parameters.now);
  9964. };
  9965. TransitionablePropertyValue.prototype.untransitioned = function untransitioned() {
  9966. return new TransitioningPropertyValue(this.property, this.value, null, {}, 0); // eslint-disable-line no-use-before-define
  9967. };
  9968. /**
  9969. * A helper type: given an object type `Properties` whose values are each of type `Property<T, R>`, it calculates
  9970. * an object type with the same keys, and values of type `R`.
  9971. *
  9972. * For properties that don't allow data-driven values, `R` is a scalar type such as `number`, `string`, or `Color`.
  9973. * For data-driven properties, it is `PossiblyEvaluatedPropertyValue`. Critically, the type definitions are set up
  9974. * in a way that allows flow to know which of these two cases applies for any given property name, and if you attempt
  9975. * to use a `PossiblyEvaluatedPropertyValue` as if it was a scalar, or vice versa, you will get a type error. (However,
  9976. * there's at least one case in which flow fails to produce a type error that you should be aware of: in a context such
  9977. * as `layer.paint.get('foo-opacity') === 0`, if `foo-opacity` is data-driven, than the left-hand side is of type
  9978. * `PossiblyEvaluatedPropertyValue<number>`, but flow will not complain about comparing this to a number using `===`.
  9979. * See https://github.com/facebook/flow/issues/2359.)
  9980. *
  9981. * There's also a third, special case possiblity for `R`: for cross-faded properties, it's `?CrossFaded<T>`.
  9982. *
  9983. * @private
  9984. */
  9985. /**
  9986. * `Properties` holds objects containing default values for the layout or paint property set of a given
  9987. * layer type. These objects are immutable, and they are used as the prototypes for the `_values` members of
  9988. * `Transitionable`, `Transitioning`, `Layout`, and `PossiblyEvaluated`. This allows these classes to avoid
  9989. * doing work in the common case where a property has no explicit value set and should be considered to take
  9990. * on the default value: using `for (const property of Object.keys(this._values))`, they can iterate over
  9991. * only the _own_ properties of `_values`, skipping repeated calculation of transitions and possible/final
  9992. * evaluations for defaults, the result of which will always be the same.
  9993. *
  9994. * @private
  9995. */
  9996. var Properties = function Properties(properties) {
  9997. this.properties = properties;
  9998. this.defaultPropertyValues = ({} );
  9999. this.defaultTransitionablePropertyValues = ({} );
  10000. this.defaultTransitioningPropertyValues = ({} );
  10001. this.defaultPossiblyEvaluatedValues = ({} );
  10002. this.overridableProperties = ([] );
  10003. for (var property in properties) {
  10004. var prop = properties[property];
  10005. if (prop.specification.overridable) {
  10006. this.overridableProperties.push(property);
  10007. }
  10008. var defaultPropertyValue = this.defaultPropertyValues[property] =
  10009. new PropertyValue(prop, undefined);
  10010. var defaultTransitionablePropertyValue = this.defaultTransitionablePropertyValues[property] =
  10011. new TransitionablePropertyValue(prop);
  10012. this.defaultTransitioningPropertyValues[property] =
  10013. defaultTransitionablePropertyValue.untransitioned();
  10014. this.defaultPossiblyEvaluatedValues[property] =
  10015. defaultPropertyValue.possiblyEvaluate(({} ));
  10016. }
  10017. };
  10018. function QueryUtils() {
  10019. }
  10020. QueryUtils.getMaximumPaintValue = function (property, layer, bucket) {
  10021. var value = ((layer.paint).get(property)).value;
  10022. if (value.kind === 'constant') {
  10023. return value.value;
  10024. } else {
  10025. var binders = bucket.programConfigurations.get(layer.id).binders;
  10026. return binders[property].maxValue;
  10027. }
  10028. };
  10029. QueryUtils.translateDistance = function (translate) {
  10030. return Math.sqrt(translate[0] * translate[0] + translate[1] * translate[1]);
  10031. };
  10032. QueryUtils.translate = function (queryGeometry, translate, translateAnchor, bearing, pixelsToTileUnits) {
  10033. if (!translate[0] && !translate[1]) {
  10034. return queryGeometry;
  10035. }
  10036. var pt = Point.convert(translate)._mult(pixelsToTileUnits);
  10037. if (translateAnchor === "viewport") {
  10038. pt._rotate(-bearing);
  10039. }
  10040. var translated = [];
  10041. for (var i = 0; i < queryGeometry.length; i++) {
  10042. var point = queryGeometry[i];
  10043. translated.push(point.sub(pt));
  10044. }
  10045. return translated;
  10046. };
  10047. /**
  10048. * `PossiblyEvaluated` stores a map of all (property name, `R`) pairs for paint or layout properties of a
  10049. * given layer type.
  10050. * @private
  10051. */
  10052. var PossiblyEvaluated = function PossiblyEvaluated(properties) {
  10053. this._properties = properties;
  10054. this._values = (Object.create(properties.defaultPossiblyEvaluatedValues) );
  10055. };
  10056. PossiblyEvaluated.prototype.get = function get(name) {
  10057. return this._values[name];
  10058. };
  10059. /**
  10060. * Because layout properties are not transitionable, they have a simpler representation and evaluation chain than
  10061. * paint properties: `PropertyValue`s are possibly evaluated, producing possibly evaluated values, which are then
  10062. * fully evaluated.
  10063. *
  10064. * `Layout` stores a map of all (property name, `PropertyValue`) pairs for layout properties of a
  10065. * given layer type. It can calculate the possibly-evaluated values for all of them at once, producing a
  10066. * `PossiblyEvaluated` instance for the same set of properties.
  10067. *
  10068. * @private
  10069. */
  10070. var Layout = function Layout(properties ) {
  10071. this._properties = properties;
  10072. this._values = (Object.create(properties.defaultPropertyValues) );
  10073. };
  10074. Layout.prototype.getValue = function getValue (name ) {
  10075. return Util.clone(this._values[name].value);
  10076. };
  10077. Layout.prototype.setValue = function setValue (name , value ) {
  10078. this._values[name] = new PropertyValue(this._values[name].property, value === null ? undefined : Util.clone(value));
  10079. };
  10080. Layout.prototype.serialize = function serialize () {
  10081. var result = {};
  10082. for (var i = 0, list = Object.keys(this._values); i < list.length; i += 1) {
  10083. var property = list[i];
  10084. var value = this.getValue(property);
  10085. if (value !== undefined) {
  10086. result[property] = value;
  10087. }
  10088. }
  10089. return result;
  10090. };
  10091. Layout.prototype.possiblyEvaluate = function possiblyEvaluate (parameters , availableImages ) {
  10092. var result = new PossiblyEvaluated(this._properties); // eslint-disable-line no-use-before-define
  10093. for (var i = 0, list = Object.keys(this._values); i < list.length; i += 1) {
  10094. var property = list[i];
  10095. result._values[property] = this._values[property].possiblyEvaluate(parameters, availableImages);
  10096. }
  10097. return result;
  10098. };
  10099. // ------- Transitioning -------
  10100. /**
  10101. * A helper type: given an object type `Properties` whose values are each of type `Property<T, R>`, it calculates
  10102. * an object type with the same keys and values of type `TransitioningPropertyValue<T, R>`.
  10103. *
  10104. * @private
  10105. */
  10106. /**
  10107. * `Transitioning` stores a map of all (property name, `TransitioningPropertyValue`) pairs for paint properties of a
  10108. * given layer type. It can calculate the possibly-evaluated values for all of them at once, producing a
  10109. * `PossiblyEvaluated` instance for the same set of properties.
  10110. *
  10111. * @private
  10112. */
  10113. var Transitioning = function Transitioning(properties) {
  10114. this._properties = properties;
  10115. this._values = (Object.create(properties.defaultTransitioningPropertyValues) );
  10116. };
  10117. Transitioning.prototype.possiblyEvaluate = function possiblyEvaluate(parameters, availableImages) {
  10118. var result = new PossiblyEvaluated(this._properties); // eslint-disable-line no-use-before-define
  10119. for (var i = 0, list = Object.keys(this._values); i < list.length; i += 1) {
  10120. var property = list[i];
  10121. result._values[property] = this._values[property].possiblyEvaluate(parameters, availableImages);
  10122. }
  10123. return result;
  10124. };
  10125. Transitioning.prototype.hasTransition = function hasTransition() {
  10126. for (var i = 0, list = Object.keys(this._values); i < list.length; i += 1) {
  10127. var property = list[i];
  10128. if (this._values[property].prior) {
  10129. return true;
  10130. }
  10131. }
  10132. return false;
  10133. };
  10134. /**
  10135. * A helper type: given an object type `Properties` whose values are each of type `Property<T, R>`, it calculates
  10136. * an object type with the same keys and values of type `TransitionablePropertyValue<T, R>`.
  10137. *
  10138. * @private
  10139. */
  10140. /**
  10141. * `Transitionable` stores a map of all (property name, `TransitionablePropertyValue`) pairs for paint properties of a
  10142. * given layer type. It can calculate the `TransitioningPropertyValue`s for all of them at once, producing a
  10143. * `Transitioning` instance for the same set of properties.
  10144. *
  10145. * @private
  10146. */
  10147. var Transitionable = function Transitionable(properties) {
  10148. this._properties = properties;
  10149. this._values = (Object.create(properties.defaultTransitionablePropertyValues) );
  10150. };
  10151. Transitionable.prototype.getValue = function getValue(name) {
  10152. return Util.clone(this._values[name].value.value);
  10153. };
  10154. Transitionable.prototype.setValue = function setValue(name, value) {
  10155. if (!this._values.hasOwnProperty(name)) {
  10156. this._values[name] = new TransitionablePropertyValue(this._values[name].property);
  10157. }
  10158. // Note that we do not _remove_ an own property in the case where a value is being reset
  10159. // to the default: the transition might still be non-default.
  10160. this._values[name].value = new PropertyValue(this._values[name].property, value === null ? undefined : Util.clone(value));
  10161. };
  10162. Transitionable.prototype.getTransition = function getTransition(name) {
  10163. return Util.clone(this._values[name].transition);
  10164. };
  10165. Transitionable.prototype.setTransition = function setTransition(name, value) {
  10166. if (!this._values.hasOwnProperty(name)) {
  10167. this._values[name] = new TransitionablePropertyValue(this._values[name].property);
  10168. }
  10169. this._values[name].transition = Util.clone(value) || undefined;
  10170. };
  10171. Transitionable.prototype.serialize = function serialize() {
  10172. var result = {};
  10173. for (var i = 0, list = Object.keys(this._values); i < list.length; i += 1) {
  10174. var property = list[i];
  10175. var value = this.getValue(property);
  10176. if (value !== undefined) {
  10177. result[property] = value;
  10178. }
  10179. var transition = this.getTransition(property);
  10180. if (transition !== undefined) {
  10181. result[(property + "-transition")] = transition;
  10182. }
  10183. }
  10184. return result;
  10185. };
  10186. Transitionable.prototype.transitioned = function transitioned(parameters, prior) {
  10187. var result = new Transitioning(this._properties); // eslint-disable-line no-use-before-define
  10188. for (var i = 0, list = Object.keys(this._values); i < list.length; i += 1) {
  10189. var property = list[i];
  10190. result._values[property] = this._values[property].transitioned(parameters, prior._values[property]);
  10191. }
  10192. return result;
  10193. };
  10194. Transitionable.prototype.untransitioned = function untransitioned() {
  10195. var result = new Transitioning(this._properties); // eslint-disable-line no-use-before-define
  10196. for (var i = 0, list = Object.keys(this._values); i < list.length; i += 1) {
  10197. var property = list[i];
  10198. result._values[property] = this._values[property].untransitioned();
  10199. }
  10200. return result;
  10201. };
  10202. var TRANSITION_SUFFIX = '-transition';
  10203. function endsWith(string, suffix) {
  10204. return string.indexOf(suffix, string.length - suffix.length) !== -1;
  10205. }
  10206. function StyleLayer(layer, properties) {
  10207. //Evented.call(this);
  10208. this.id = layer.id;
  10209. this.type = layer.type;
  10210. // this._featureFilter = function () {
  10211. // return true;
  10212. // };
  10213. if (layer.type === 'custom') {
  10214. return;
  10215. }
  10216. layer = ((layer));
  10217. this.metadata = layer.metadata;
  10218. this.minzoom = layer.minzoom;
  10219. this.maxzoom = layer.maxzoom;
  10220. if (layer.type !== 'background') {
  10221. this.source = layer.source;
  10222. this.sourceLayer = layer['source-layer'];
  10223. this.filter = layer.filter;
  10224. }
  10225. if (properties.layout) {
  10226. this._unevaluatedLayout = new Layout(properties.layout);
  10227. }
  10228. if (properties.paint) {
  10229. this._transitionablePaint = new Transitionable(properties.paint);
  10230. for (var property in layer.paint) {
  10231. this.setPaintProperty(property, layer.paint[property], {validate: false});
  10232. }
  10233. for (var property$1 in layer.layout) {
  10234. this.setLayoutProperty(property$1, layer.layout[property$1], {validate: false});
  10235. }
  10236. this._transitioningPaint = this._transitionablePaint.untransitioned();
  10237. }
  10238. }
  10239. // if (Evented) StyleLayer.__proto__ = Evented;
  10240. // StyleLayer.prototype = Object.create(Evented && Evented.prototype);
  10241. // StyleLayer.prototype.constructor = StyleLayer;
  10242. StyleLayer.prototype.getCrossfadeParameters = function getCrossfadeParameters() {
  10243. return this._crossfadeParameters;
  10244. };
  10245. StyleLayer.prototype.getLayoutProperty = function getLayoutProperty(name) {
  10246. if (name === 'visibility') {
  10247. return this.visibility;
  10248. }
  10249. return this._unevaluatedLayout.getValue(name);
  10250. };
  10251. StyleLayer.prototype.setLayoutProperty = function setLayoutProperty(name, value, options) {
  10252. if (value !== null && value !== undefined) {
  10253. var key = "layers." + (this.id) + ".layout." + name;
  10254. // if (this._validate(validateLayoutProperty$1, key, name, value, options)) {
  10255. // return;
  10256. // }
  10257. }
  10258. if (name === 'visibility') {
  10259. this.visibility = value;
  10260. return;
  10261. }
  10262. this._unevaluatedLayout.setValue(name, value);
  10263. };
  10264. StyleLayer.prototype.getPaintProperty = function getPaintProperty(name) {
  10265. if (endsWith(name, TRANSITION_SUFFIX)) {
  10266. return this._transitionablePaint.getTransition(name.slice(0, -TRANSITION_SUFFIX.length));
  10267. } else {
  10268. return this._transitionablePaint.getValue(name);
  10269. }
  10270. };
  10271. StyleLayer.prototype.setPaintProperty = function setPaintProperty(name, value, options) {
  10272. if (value !== null && value !== undefined) {
  10273. var key = "layers." + (this.id) + ".paint." + name;
  10274. // if (this._validate(validatePaintProperty$1, key, name, value, options)) {
  10275. // return false;
  10276. // }
  10277. }
  10278. if (endsWith(name, TRANSITION_SUFFIX)) {
  10279. this._transitionablePaint.setTransition(name.slice(0, -TRANSITION_SUFFIX.length), (value ) || undefined);
  10280. return false;
  10281. } else {
  10282. var transitionable = this._transitionablePaint._values[name];
  10283. var isCrossFadedProperty = transitionable.property.specification["property-type"] === 'cross-faded-data-driven';
  10284. var wasDataDriven = transitionable.value.isDataDriven();
  10285. var oldValue = transitionable.value;
  10286. this._transitionablePaint.setValue(name, value);
  10287. this._handleSpecialPaintPropertyUpdate(name);
  10288. var newValue = this._transitionablePaint._values[name].value;
  10289. var isDataDriven = newValue.isDataDriven();
  10290. // if a cross-faded value is changed, we need to make sure the new icons get added to each tile's iconAtlas
  10291. // so a call to _updateLayer is necessary, and we return true from this function so it gets called in
  10292. // Style#setPaintProperty
  10293. return isDataDriven || wasDataDriven || isCrossFadedProperty || this._handleOverridablePaintPropertyUpdate(name, oldValue, newValue);
  10294. }
  10295. };
  10296. StyleLayer.prototype._handleSpecialPaintPropertyUpdate = function _handleSpecialPaintPropertyUpdate(_) {
  10297. // No-op; can be overridden by derived classes.
  10298. };
  10299. // eslint-disable-next-line no-unused-vars
  10300. StyleLayer.prototype._handleOverridablePaintPropertyUpdate = function _handleOverridablePaintPropertyUpdate(name, oldValue, newValue) {
  10301. // No-op; can be overridden by derived classes.
  10302. return false;
  10303. };
  10304. StyleLayer.prototype.isHidden = function isHidden(zoom) {
  10305. if (this.minzoom && zoom < this.minzoom) {
  10306. return true;
  10307. }
  10308. if (this.maxzoom && zoom >= this.maxzoom) {
  10309. return true;
  10310. }
  10311. return this.visibility === 'none';
  10312. };
  10313. StyleLayer.prototype.updateTransitions = function updateTransitions(parameters) {
  10314. this._transitioningPaint = this._transitionablePaint.transitioned(parameters, this._transitioningPaint);
  10315. };
  10316. StyleLayer.prototype.hasTransition = function hasTransition() {
  10317. return this._transitioningPaint.hasTransition();
  10318. };
  10319. StyleLayer.prototype.recalculate = function recalculate(parameters, availableImages) {
  10320. if (parameters.getCrossfadeParameters) {
  10321. this._crossfadeParameters = parameters.getCrossfadeParameters();
  10322. }
  10323. if (this._unevaluatedLayout) {
  10324. (this).layout = this._unevaluatedLayout.possiblyEvaluate(parameters, availableImages);
  10325. }
  10326. (this).paint = this._transitioningPaint.possiblyEvaluate(parameters, availableImages);
  10327. };
  10328. StyleLayer.prototype.serialize = function serialize() {
  10329. var output = {
  10330. 'id': this.id,
  10331. 'type': this.type,
  10332. 'source': this.source,
  10333. 'source-layer': this.sourceLayer,
  10334. 'metadata': this.metadata,
  10335. 'minzoom': this.minzoom,
  10336. 'maxzoom': this.maxzoom,
  10337. 'filter': this.filter,
  10338. 'layout': this._unevaluatedLayout && this._unevaluatedLayout.serialize(),
  10339. 'paint': this._transitionablePaint && this._transitionablePaint.serialize()
  10340. };
  10341. if (this.visibility) {
  10342. output.layout = output.layout || {};
  10343. output.layout.visibility = this.visibility;
  10344. }
  10345. return Util.filterObject(output, function (value, key) {
  10346. return value !== undefined && !(key === 'layout' && !Object.keys(value).length) && !(key === 'paint' && !Object.keys(value).length);
  10347. });
  10348. };
  10349. StyleLayer.prototype._validate = function _validate(validate, key, name, value, options) {
  10350. return true;
  10351. // if (options === void 0) options = {};
  10352. //
  10353. // if (options && options.validate === false) {
  10354. // return false;
  10355. // }
  10356. // return emitValidationErrors(this, validate.call(validateStyle, {
  10357. // key: key,
  10358. // layerType: this.type,
  10359. // objectKey: name,
  10360. // value: value,
  10361. // styleSpec: spec,
  10362. // // Workaround for https://github.com/mapbox/mapbox-gl-js/issues/2407
  10363. // style: {glyphs: true, sprite: true}
  10364. // }));
  10365. };
  10366. StyleLayer.prototype.is3D = function is3D() {
  10367. return false;
  10368. };
  10369. StyleLayer.prototype.isTileClipped = function isTileClipped() {
  10370. return false;
  10371. };
  10372. StyleLayer.prototype.hasOffscreenPass = function hasOffscreenPass() {
  10373. return false;
  10374. };
  10375. StyleLayer.prototype.resize = function resize() {
  10376. // noop
  10377. };
  10378. StyleLayer.prototype.isStateDependent = function isStateDependent() {
  10379. return true;
  10380. // for (var property in (this ).paint._values) {
  10381. // var value = (this ).paint.get(property);
  10382. // if (!(value instanceof PossiblyEvaluatedPropertyValue) || !supportsPropertyExpression(value.property.specification)) {
  10383. // continue;
  10384. // }
  10385. //
  10386. // if ((value.value.kind === 'source' || value.value.kind === 'composite') &&
  10387. // value.value.isStateDependent) {
  10388. // return true;
  10389. // }
  10390. // }
  10391. // return false;
  10392. };
  10393. var $version = 8;
  10394. var $root = {
  10395. version: {
  10396. required: true,
  10397. type: "enum",
  10398. values: [
  10399. 8
  10400. ]
  10401. },
  10402. name: {
  10403. type: "string"
  10404. },
  10405. metadata: {
  10406. type: "*"
  10407. },
  10408. center: {
  10409. type: "array",
  10410. value: "number"
  10411. },
  10412. zoom: {
  10413. type: "number"
  10414. },
  10415. bearing: {
  10416. type: "number",
  10417. "default": 0,
  10418. period: 360,
  10419. units: "degrees"
  10420. },
  10421. pitch: {
  10422. type: "number",
  10423. "default": 0,
  10424. units: "degrees"
  10425. },
  10426. light: {
  10427. type: "light"
  10428. },
  10429. sources: {
  10430. required: true,
  10431. type: "sources"
  10432. },
  10433. sprite: {
  10434. type: "string"
  10435. },
  10436. glyphs: {
  10437. type: "string"
  10438. },
  10439. transition: {
  10440. type: "transition"
  10441. },
  10442. layers: {
  10443. required: true,
  10444. type: "array",
  10445. value: "layer"
  10446. }
  10447. };
  10448. var sources = {
  10449. "*": {
  10450. type: "source"
  10451. }
  10452. };
  10453. var source = [
  10454. "source_vector",
  10455. "source_raster",
  10456. "source_raster_dem",
  10457. "source_geojson",
  10458. "source_video",
  10459. "source_image"
  10460. ];
  10461. var source_vector = {
  10462. type: {
  10463. required: true,
  10464. type: "enum",
  10465. values: {
  10466. vector: {
  10467. }
  10468. }
  10469. },
  10470. url: {
  10471. type: "string"
  10472. },
  10473. tiles: {
  10474. type: "array",
  10475. value: "string"
  10476. },
  10477. bounds: {
  10478. type: "array",
  10479. value: "number",
  10480. length: 4,
  10481. "default": [
  10482. -180,
  10483. -85.051129,
  10484. 180,
  10485. 85.051129
  10486. ]
  10487. },
  10488. scheme: {
  10489. type: "enum",
  10490. values: {
  10491. xyz: {
  10492. },
  10493. tms: {
  10494. }
  10495. },
  10496. "default": "xyz"
  10497. },
  10498. minzoom: {
  10499. type: "number",
  10500. "default": 0
  10501. },
  10502. maxzoom: {
  10503. type: "number",
  10504. "default": 22
  10505. },
  10506. attribution: {
  10507. type: "string"
  10508. },
  10509. "*": {
  10510. type: "*"
  10511. }
  10512. };
  10513. var source_raster = {
  10514. type: {
  10515. required: true,
  10516. type: "enum",
  10517. values: {
  10518. raster: {
  10519. }
  10520. }
  10521. },
  10522. url: {
  10523. type: "string"
  10524. },
  10525. tiles: {
  10526. type: "array",
  10527. value: "string"
  10528. },
  10529. bounds: {
  10530. type: "array",
  10531. value: "number",
  10532. length: 4,
  10533. "default": [
  10534. -180,
  10535. -85.051129,
  10536. 180,
  10537. 85.051129
  10538. ]
  10539. },
  10540. minzoom: {
  10541. type: "number",
  10542. "default": 0
  10543. },
  10544. maxzoom: {
  10545. type: "number",
  10546. "default": 22
  10547. },
  10548. tileSize: {
  10549. type: "number",
  10550. "default": 512,
  10551. units: "pixels"
  10552. },
  10553. scheme: {
  10554. type: "enum",
  10555. values: {
  10556. xyz: {
  10557. },
  10558. tms: {
  10559. }
  10560. },
  10561. "default": "xyz"
  10562. },
  10563. attribution: {
  10564. type: "string"
  10565. },
  10566. "*": {
  10567. type: "*"
  10568. }
  10569. };
  10570. var source_raster_dem = {
  10571. type: {
  10572. required: true,
  10573. type: "enum",
  10574. values: {
  10575. "raster-dem": {
  10576. }
  10577. }
  10578. },
  10579. url: {
  10580. type: "string"
  10581. },
  10582. tiles: {
  10583. type: "array",
  10584. value: "string"
  10585. },
  10586. bounds: {
  10587. type: "array",
  10588. value: "number",
  10589. length: 4,
  10590. "default": [
  10591. -180,
  10592. -85.051129,
  10593. 180,
  10594. 85.051129
  10595. ]
  10596. },
  10597. minzoom: {
  10598. type: "number",
  10599. "default": 0
  10600. },
  10601. maxzoom: {
  10602. type: "number",
  10603. "default": 22
  10604. },
  10605. tileSize: {
  10606. type: "number",
  10607. "default": 512,
  10608. units: "pixels"
  10609. },
  10610. attribution: {
  10611. type: "string"
  10612. },
  10613. encoding: {
  10614. type: "enum",
  10615. values: {
  10616. terrarium: {
  10617. },
  10618. mapbox: {
  10619. }
  10620. },
  10621. "default": "mapbox"
  10622. },
  10623. "*": {
  10624. type: "*"
  10625. }
  10626. };
  10627. var source_geojson = {
  10628. type: {
  10629. required: true,
  10630. type: "enum",
  10631. values: {
  10632. geojson: {
  10633. }
  10634. }
  10635. },
  10636. data: {
  10637. type: "*"
  10638. },
  10639. maxzoom: {
  10640. type: "number",
  10641. "default": 18
  10642. },
  10643. attribution: {
  10644. type: "string"
  10645. },
  10646. buffer: {
  10647. type: "number",
  10648. "default": 128,
  10649. maximum: 512,
  10650. minimum: 0
  10651. },
  10652. tolerance: {
  10653. type: "number",
  10654. "default": 0.375
  10655. },
  10656. cluster: {
  10657. type: "boolean",
  10658. "default": false
  10659. },
  10660. clusterRadius: {
  10661. type: "number",
  10662. "default": 50,
  10663. minimum: 0
  10664. },
  10665. clusterMaxZoom: {
  10666. type: "number"
  10667. },
  10668. clusterProperties: {
  10669. type: "*"
  10670. },
  10671. lineMetrics: {
  10672. type: "boolean",
  10673. "default": false
  10674. },
  10675. generateId: {
  10676. type: "boolean",
  10677. "default": false
  10678. }
  10679. };
  10680. var source_video = {
  10681. type: {
  10682. required: true,
  10683. type: "enum",
  10684. values: {
  10685. video: {
  10686. }
  10687. }
  10688. },
  10689. urls: {
  10690. required: true,
  10691. type: "array",
  10692. value: "string"
  10693. },
  10694. coordinates: {
  10695. required: true,
  10696. type: "array",
  10697. length: 4,
  10698. value: {
  10699. type: "array",
  10700. length: 2,
  10701. value: "number"
  10702. }
  10703. }
  10704. };
  10705. var source_image = {
  10706. type: {
  10707. required: true,
  10708. type: "enum",
  10709. values: {
  10710. image: {
  10711. }
  10712. }
  10713. },
  10714. url: {
  10715. required: true,
  10716. type: "string"
  10717. },
  10718. coordinates: {
  10719. required: true,
  10720. type: "array",
  10721. length: 4,
  10722. value: {
  10723. type: "array",
  10724. length: 2,
  10725. value: "number"
  10726. }
  10727. }
  10728. };
  10729. var layer = {
  10730. id: {
  10731. type: "string",
  10732. required: true
  10733. },
  10734. type: {
  10735. type: "enum",
  10736. values: {
  10737. fill: {
  10738. },
  10739. line: {
  10740. },
  10741. symbol: {
  10742. },
  10743. circle: {
  10744. },
  10745. heatmap: {
  10746. },
  10747. "fill-extrusion": {
  10748. },
  10749. raster: {
  10750. },
  10751. hillshade: {
  10752. },
  10753. background: {
  10754. }
  10755. },
  10756. required: true
  10757. },
  10758. metadata: {
  10759. type: "*"
  10760. },
  10761. source: {
  10762. type: "string"
  10763. },
  10764. "source-layer": {
  10765. type: "string"
  10766. },
  10767. minzoom: {
  10768. type: "number",
  10769. minimum: 0,
  10770. maximum: 24
  10771. },
  10772. maxzoom: {
  10773. type: "number",
  10774. minimum: 0,
  10775. maximum: 24
  10776. },
  10777. filter: {
  10778. type: "filter"
  10779. },
  10780. layout: {
  10781. type: "layout"
  10782. },
  10783. paint: {
  10784. type: "paint"
  10785. }
  10786. };
  10787. var layout = [
  10788. "layout_fill",
  10789. "layout_line",
  10790. "layout_circle",
  10791. "layout_heatmap",
  10792. "layout_fill-extrusion",
  10793. "layout_symbol",
  10794. "layout_raster",
  10795. "layout_hillshade",
  10796. "layout_background"
  10797. ];
  10798. var layout_background = {
  10799. visibility: {
  10800. type: "enum",
  10801. values: {
  10802. visible: {
  10803. },
  10804. none: {
  10805. }
  10806. },
  10807. "default": "visible",
  10808. "property-type": "constant"
  10809. }
  10810. };
  10811. var layout_fill = {
  10812. "fill-sort-key": {
  10813. type: "number",
  10814. expression: {
  10815. interpolated: false,
  10816. parameters: [
  10817. "zoom",
  10818. "feature"
  10819. ]
  10820. },
  10821. "property-type": "data-driven"
  10822. },
  10823. visibility: {
  10824. type: "enum",
  10825. values: {
  10826. visible: {
  10827. },
  10828. none: {
  10829. }
  10830. },
  10831. "default": "visible",
  10832. "property-type": "constant"
  10833. }
  10834. };
  10835. var layout_circle = {
  10836. "circle-sort-key": {
  10837. type: "number",
  10838. expression: {
  10839. interpolated: false,
  10840. parameters: [
  10841. "zoom",
  10842. "feature"
  10843. ]
  10844. },
  10845. "property-type": "data-driven"
  10846. },
  10847. visibility: {
  10848. type: "enum",
  10849. values: {
  10850. visible: {
  10851. },
  10852. none: {
  10853. }
  10854. },
  10855. "default": "visible",
  10856. "property-type": "constant"
  10857. }
  10858. };
  10859. var layout_heatmap = {
  10860. visibility: {
  10861. type: "enum",
  10862. values: {
  10863. visible: {
  10864. },
  10865. none: {
  10866. }
  10867. },
  10868. "default": "visible",
  10869. "property-type": "constant"
  10870. }
  10871. };
  10872. var layout_line = {
  10873. "line-cap": {
  10874. type: "enum",
  10875. values: {
  10876. butt: {
  10877. },
  10878. round: {
  10879. },
  10880. square: {
  10881. }
  10882. },
  10883. "default": "butt",
  10884. expression: {
  10885. interpolated: false,
  10886. parameters: [
  10887. "zoom"
  10888. ]
  10889. },
  10890. "property-type": "data-constant"
  10891. },
  10892. "line-join": {
  10893. type: "enum",
  10894. values: {
  10895. bevel: {
  10896. },
  10897. round: {
  10898. },
  10899. miter: {
  10900. }
  10901. },
  10902. "default": "miter",
  10903. expression: {
  10904. interpolated: false,
  10905. parameters: [
  10906. "zoom",
  10907. "feature"
  10908. ]
  10909. },
  10910. "property-type": "data-driven"
  10911. },
  10912. "line-miter-limit": {
  10913. type: "number",
  10914. "default": 2,
  10915. requires: [
  10916. {
  10917. "line-join": "miter"
  10918. }
  10919. ],
  10920. expression: {
  10921. interpolated: true,
  10922. parameters: [
  10923. "zoom"
  10924. ]
  10925. },
  10926. "property-type": "data-constant"
  10927. },
  10928. "line-round-limit": {
  10929. type: "number",
  10930. "default": 1.05,
  10931. requires: [
  10932. {
  10933. "line-join": "round"
  10934. }
  10935. ],
  10936. expression: {
  10937. interpolated: true,
  10938. parameters: [
  10939. "zoom"
  10940. ]
  10941. },
  10942. "property-type": "data-constant"
  10943. },
  10944. "line-sort-key": {
  10945. type: "number",
  10946. expression: {
  10947. interpolated: false,
  10948. parameters: [
  10949. "zoom",
  10950. "feature"
  10951. ]
  10952. },
  10953. "property-type": "data-driven"
  10954. },
  10955. visibility: {
  10956. type: "enum",
  10957. values: {
  10958. visible: {
  10959. },
  10960. none: {
  10961. }
  10962. },
  10963. "default": "visible",
  10964. "property-type": "constant"
  10965. }
  10966. };
  10967. var layout_symbol = {
  10968. "symbol-placement": {
  10969. type: "enum",
  10970. values: {
  10971. point: {
  10972. },
  10973. line: {
  10974. },
  10975. "line-center": {
  10976. }
  10977. },
  10978. "default": "point",
  10979. expression: {
  10980. interpolated: false,
  10981. parameters: [
  10982. "zoom"
  10983. ]
  10984. },
  10985. "property-type": "data-constant"
  10986. },
  10987. "symbol-spacing": {
  10988. type: "number",
  10989. "default": 250,
  10990. minimum: 1,
  10991. units: "pixels",
  10992. requires: [
  10993. {
  10994. "symbol-placement": "line"
  10995. }
  10996. ],
  10997. expression: {
  10998. interpolated: true,
  10999. parameters: [
  11000. "zoom"
  11001. ]
  11002. },
  11003. "property-type": "data-constant"
  11004. },
  11005. "symbol-avoid-edges": {
  11006. type: "boolean",
  11007. "default": false,
  11008. expression: {
  11009. interpolated: false,
  11010. parameters: [
  11011. "zoom"
  11012. ]
  11013. },
  11014. "property-type": "data-constant"
  11015. },
  11016. "symbol-sort-key": {
  11017. type: "number",
  11018. expression: {
  11019. interpolated: false,
  11020. parameters: [
  11021. "zoom",
  11022. "feature"
  11023. ]
  11024. },
  11025. "property-type": "data-driven"
  11026. },
  11027. "symbol-z-order": {
  11028. type: "enum",
  11029. values: {
  11030. auto: {
  11031. },
  11032. "viewport-y": {
  11033. },
  11034. source: {
  11035. }
  11036. },
  11037. "default": "auto",
  11038. expression: {
  11039. interpolated: false,
  11040. parameters: [
  11041. "zoom"
  11042. ]
  11043. },
  11044. "property-type": "data-constant"
  11045. },
  11046. "icon-allow-overlap": {
  11047. type: "boolean",
  11048. "default": false,
  11049. requires: [
  11050. "icon-image"
  11051. ],
  11052. expression: {
  11053. interpolated: false,
  11054. parameters: [
  11055. "zoom"
  11056. ]
  11057. },
  11058. "property-type": "data-constant"
  11059. },
  11060. "icon-ignore-placement": {
  11061. type: "boolean",
  11062. "default": false,
  11063. requires: [
  11064. "icon-image"
  11065. ],
  11066. expression: {
  11067. interpolated: false,
  11068. parameters: [
  11069. "zoom"
  11070. ]
  11071. },
  11072. "property-type": "data-constant"
  11073. },
  11074. "icon-optional": {
  11075. type: "boolean",
  11076. "default": false,
  11077. requires: [
  11078. "icon-image",
  11079. "text-field"
  11080. ],
  11081. expression: {
  11082. interpolated: false,
  11083. parameters: [
  11084. "zoom"
  11085. ]
  11086. },
  11087. "property-type": "data-constant"
  11088. },
  11089. "icon-rotation-alignment": {
  11090. type: "enum",
  11091. values: {
  11092. map: {
  11093. },
  11094. viewport: {
  11095. },
  11096. auto: {
  11097. }
  11098. },
  11099. "default": "auto",
  11100. requires: [
  11101. "icon-image"
  11102. ],
  11103. expression: {
  11104. interpolated: false,
  11105. parameters: [
  11106. "zoom"
  11107. ]
  11108. },
  11109. "property-type": "data-constant"
  11110. },
  11111. "icon-size": {
  11112. type: "number",
  11113. "default": 1,
  11114. minimum: 0,
  11115. units: "factor of the original icon size",
  11116. requires: [
  11117. "icon-image"
  11118. ],
  11119. expression: {
  11120. interpolated: true,
  11121. parameters: [
  11122. "zoom",
  11123. "feature"
  11124. ]
  11125. },
  11126. "property-type": "data-driven"
  11127. },
  11128. "icon-text-fit": {
  11129. type: "enum",
  11130. values: {
  11131. none: {
  11132. },
  11133. width: {
  11134. },
  11135. height: {
  11136. },
  11137. both: {
  11138. }
  11139. },
  11140. "default": "none",
  11141. requires: [
  11142. "icon-image",
  11143. "text-field"
  11144. ],
  11145. expression: {
  11146. interpolated: false,
  11147. parameters: [
  11148. "zoom"
  11149. ]
  11150. },
  11151. "property-type": "data-constant"
  11152. },
  11153. "icon-text-fit-padding": {
  11154. type: "array",
  11155. value: "number",
  11156. length: 4,
  11157. "default": [
  11158. 0,
  11159. 0,
  11160. 0,
  11161. 0
  11162. ],
  11163. units: "pixels",
  11164. requires: [
  11165. "icon-image",
  11166. "text-field",
  11167. {
  11168. "icon-text-fit": [
  11169. "both",
  11170. "width",
  11171. "height"
  11172. ]
  11173. }
  11174. ],
  11175. expression: {
  11176. interpolated: true,
  11177. parameters: [
  11178. "zoom"
  11179. ]
  11180. },
  11181. "property-type": "data-constant"
  11182. },
  11183. "icon-image": {
  11184. type: "resolvedImage",
  11185. tokens: true,
  11186. expression: {
  11187. interpolated: false,
  11188. parameters: [
  11189. "zoom",
  11190. "feature"
  11191. ]
  11192. },
  11193. "property-type": "data-driven"
  11194. },
  11195. "icon-rotate": {
  11196. type: "number",
  11197. "default": 0,
  11198. period: 360,
  11199. units: "degrees",
  11200. requires: [
  11201. "icon-image"
  11202. ],
  11203. expression: {
  11204. interpolated: true,
  11205. parameters: [
  11206. "zoom",
  11207. "feature"
  11208. ]
  11209. },
  11210. "property-type": "data-driven"
  11211. },
  11212. "icon-padding": {
  11213. type: "number",
  11214. "default": 2,
  11215. minimum: 0,
  11216. units: "pixels",
  11217. requires: [
  11218. "icon-image"
  11219. ],
  11220. expression: {
  11221. interpolated: true,
  11222. parameters: [
  11223. "zoom"
  11224. ]
  11225. },
  11226. "property-type": "data-constant"
  11227. },
  11228. "icon-keep-upright": {
  11229. type: "boolean",
  11230. "default": false,
  11231. requires: [
  11232. "icon-image",
  11233. {
  11234. "icon-rotation-alignment": "map"
  11235. },
  11236. {
  11237. "symbol-placement": [
  11238. "line",
  11239. "line-center"
  11240. ]
  11241. }
  11242. ],
  11243. expression: {
  11244. interpolated: false,
  11245. parameters: [
  11246. "zoom"
  11247. ]
  11248. },
  11249. "property-type": "data-constant"
  11250. },
  11251. "icon-offset": {
  11252. type: "array",
  11253. value: "number",
  11254. length: 2,
  11255. "default": [
  11256. 0,
  11257. 0
  11258. ],
  11259. requires: [
  11260. "icon-image"
  11261. ],
  11262. expression: {
  11263. interpolated: true,
  11264. parameters: [
  11265. "zoom",
  11266. "feature"
  11267. ]
  11268. },
  11269. "property-type": "data-driven"
  11270. },
  11271. "icon-anchor": {
  11272. type: "enum",
  11273. values: {
  11274. center: {
  11275. },
  11276. left: {
  11277. },
  11278. right: {
  11279. },
  11280. top: {
  11281. },
  11282. bottom: {
  11283. },
  11284. "top-left": {
  11285. },
  11286. "top-right": {
  11287. },
  11288. "bottom-left": {
  11289. },
  11290. "bottom-right": {
  11291. }
  11292. },
  11293. "default": "center",
  11294. requires: [
  11295. "icon-image"
  11296. ],
  11297. expression: {
  11298. interpolated: false,
  11299. parameters: [
  11300. "zoom",
  11301. "feature"
  11302. ]
  11303. },
  11304. "property-type": "data-driven"
  11305. },
  11306. "icon-pitch-alignment": {
  11307. type: "enum",
  11308. values: {
  11309. map: {
  11310. },
  11311. viewport: {
  11312. },
  11313. auto: {
  11314. }
  11315. },
  11316. "default": "auto",
  11317. requires: [
  11318. "icon-image"
  11319. ],
  11320. expression: {
  11321. interpolated: false,
  11322. parameters: [
  11323. "zoom"
  11324. ]
  11325. },
  11326. "property-type": "data-constant"
  11327. },
  11328. "text-pitch-alignment": {
  11329. type: "enum",
  11330. values: {
  11331. map: {
  11332. },
  11333. viewport: {
  11334. },
  11335. auto: {
  11336. }
  11337. },
  11338. "default": "auto",
  11339. requires: [
  11340. "text-field"
  11341. ],
  11342. expression: {
  11343. interpolated: false,
  11344. parameters: [
  11345. "zoom"
  11346. ]
  11347. },
  11348. "property-type": "data-constant"
  11349. },
  11350. "text-rotation-alignment": {
  11351. type: "enum",
  11352. values: {
  11353. map: {
  11354. },
  11355. viewport: {
  11356. },
  11357. auto: {
  11358. }
  11359. },
  11360. "default": "auto",
  11361. requires: [
  11362. "text-field"
  11363. ],
  11364. expression: {
  11365. interpolated: false,
  11366. parameters: [
  11367. "zoom"
  11368. ]
  11369. },
  11370. "property-type": "data-constant"
  11371. },
  11372. "text-field": {
  11373. type: "formatted",
  11374. "default": "",
  11375. tokens: true,
  11376. expression: {
  11377. interpolated: false,
  11378. parameters: [
  11379. "zoom",
  11380. "feature"
  11381. ]
  11382. },
  11383. "property-type": "data-driven"
  11384. },
  11385. "text-font": {
  11386. type: "array",
  11387. value: "string",
  11388. "default": [
  11389. "Open Sans Regular",
  11390. "Arial Unicode MS Regular"
  11391. ],
  11392. requires: [
  11393. "text-field"
  11394. ],
  11395. expression: {
  11396. interpolated: false,
  11397. parameters: [
  11398. "zoom",
  11399. "feature"
  11400. ]
  11401. },
  11402. "property-type": "data-driven"
  11403. },
  11404. "text-size": {
  11405. type: "number",
  11406. "default": 16,
  11407. minimum: 0,
  11408. units: "pixels",
  11409. requires: [
  11410. "text-field"
  11411. ],
  11412. expression: {
  11413. interpolated: true,
  11414. parameters: [
  11415. "zoom",
  11416. "feature"
  11417. ]
  11418. },
  11419. "property-type": "data-driven"
  11420. },
  11421. "text-max-width": {
  11422. type: "number",
  11423. "default": 10,
  11424. minimum: 0,
  11425. units: "ems",
  11426. requires: [
  11427. "text-field"
  11428. ],
  11429. expression: {
  11430. interpolated: true,
  11431. parameters: [
  11432. "zoom",
  11433. "feature"
  11434. ]
  11435. },
  11436. "property-type": "data-driven"
  11437. },
  11438. "text-line-height": {
  11439. type: "number",
  11440. "default": 1.2,
  11441. units: "ems",
  11442. requires: [
  11443. "text-field"
  11444. ],
  11445. expression: {
  11446. interpolated: true,
  11447. parameters: [
  11448. "zoom"
  11449. ]
  11450. },
  11451. "property-type": "data-constant"
  11452. },
  11453. "text-letter-spacing": {
  11454. type: "number",
  11455. "default": 0,
  11456. units: "ems",
  11457. requires: [
  11458. "text-field"
  11459. ],
  11460. expression: {
  11461. interpolated: true,
  11462. parameters: [
  11463. "zoom",
  11464. "feature"
  11465. ]
  11466. },
  11467. "property-type": "data-driven"
  11468. },
  11469. "text-justify": {
  11470. type: "enum",
  11471. values: {
  11472. auto: {
  11473. },
  11474. left: {
  11475. },
  11476. center: {
  11477. },
  11478. right: {
  11479. }
  11480. },
  11481. "default": "center",
  11482. requires: [
  11483. "text-field"
  11484. ],
  11485. expression: {
  11486. interpolated: false,
  11487. parameters: [
  11488. "zoom",
  11489. "feature"
  11490. ]
  11491. },
  11492. "property-type": "data-driven"
  11493. },
  11494. "text-radial-offset": {
  11495. type: "number",
  11496. units: "ems",
  11497. "default": 0,
  11498. requires: [
  11499. "text-field"
  11500. ],
  11501. "property-type": "data-driven",
  11502. expression: {
  11503. interpolated: true,
  11504. parameters: [
  11505. "zoom",
  11506. "feature"
  11507. ]
  11508. }
  11509. },
  11510. "text-variable-anchor": {
  11511. type: "array",
  11512. value: "enum",
  11513. values: {
  11514. center: {
  11515. },
  11516. left: {
  11517. },
  11518. right: {
  11519. },
  11520. top: {
  11521. },
  11522. bottom: {
  11523. },
  11524. "top-left": {
  11525. },
  11526. "top-right": {
  11527. },
  11528. "bottom-left": {
  11529. },
  11530. "bottom-right": {
  11531. }
  11532. },
  11533. requires: [
  11534. "text-field",
  11535. {
  11536. "symbol-placement": [
  11537. "point"
  11538. ]
  11539. }
  11540. ],
  11541. expression: {
  11542. interpolated: false,
  11543. parameters: [
  11544. "zoom"
  11545. ]
  11546. },
  11547. "property-type": "data-constant"
  11548. },
  11549. "text-anchor": {
  11550. type: "enum",
  11551. values: {
  11552. center: {
  11553. },
  11554. left: {
  11555. },
  11556. right: {
  11557. },
  11558. top: {
  11559. },
  11560. bottom: {
  11561. },
  11562. "top-left": {
  11563. },
  11564. "top-right": {
  11565. },
  11566. "bottom-left": {
  11567. },
  11568. "bottom-right": {
  11569. }
  11570. },
  11571. "default": "center",
  11572. requires: [
  11573. "text-field",
  11574. {
  11575. "!": "text-variable-anchor"
  11576. }
  11577. ],
  11578. expression: {
  11579. interpolated: false,
  11580. parameters: [
  11581. "zoom",
  11582. "feature"
  11583. ]
  11584. },
  11585. "property-type": "data-driven"
  11586. },
  11587. "text-max-angle": {
  11588. type: "number",
  11589. "default": 45,
  11590. units: "degrees",
  11591. requires: [
  11592. "text-field",
  11593. {
  11594. "symbol-placement": [
  11595. "line",
  11596. "line-center"
  11597. ]
  11598. }
  11599. ],
  11600. expression: {
  11601. interpolated: true,
  11602. parameters: [
  11603. "zoom"
  11604. ]
  11605. },
  11606. "property-type": "data-constant"
  11607. },
  11608. "text-writing-mode": {
  11609. type: "array",
  11610. value: "enum",
  11611. values: {
  11612. horizontal: {
  11613. },
  11614. vertical: {
  11615. }
  11616. },
  11617. requires: [
  11618. "text-field",
  11619. {
  11620. "symbol-placement": [
  11621. "point"
  11622. ]
  11623. }
  11624. ],
  11625. expression: {
  11626. interpolated: false,
  11627. parameters: [
  11628. "zoom"
  11629. ]
  11630. },
  11631. "property-type": "data-constant"
  11632. },
  11633. "text-rotate": {
  11634. type: "number",
  11635. "default": 0,
  11636. period: 360,
  11637. units: "degrees",
  11638. requires: [
  11639. "text-field"
  11640. ],
  11641. expression: {
  11642. interpolated: true,
  11643. parameters: [
  11644. "zoom",
  11645. "feature"
  11646. ]
  11647. },
  11648. "property-type": "data-driven"
  11649. },
  11650. "text-padding": {
  11651. type: "number",
  11652. "default": 2,
  11653. minimum: 0,
  11654. units: "pixels",
  11655. requires: [
  11656. "text-field"
  11657. ],
  11658. expression: {
  11659. interpolated: true,
  11660. parameters: [
  11661. "zoom"
  11662. ]
  11663. },
  11664. "property-type": "data-constant"
  11665. },
  11666. "text-keep-upright": {
  11667. type: "boolean",
  11668. "default": true,
  11669. requires: [
  11670. "text-field",
  11671. {
  11672. "text-rotation-alignment": "map"
  11673. },
  11674. {
  11675. "symbol-placement": [
  11676. "line",
  11677. "line-center"
  11678. ]
  11679. }
  11680. ],
  11681. expression: {
  11682. interpolated: false,
  11683. parameters: [
  11684. "zoom"
  11685. ]
  11686. },
  11687. "property-type": "data-constant"
  11688. },
  11689. "text-transform": {
  11690. type: "enum",
  11691. values: {
  11692. none: {
  11693. },
  11694. uppercase: {
  11695. },
  11696. lowercase: {
  11697. }
  11698. },
  11699. "default": "none",
  11700. requires: [
  11701. "text-field"
  11702. ],
  11703. expression: {
  11704. interpolated: false,
  11705. parameters: [
  11706. "zoom",
  11707. "feature"
  11708. ]
  11709. },
  11710. "property-type": "data-driven"
  11711. },
  11712. "text-offset": {
  11713. type: "array",
  11714. value: "number",
  11715. units: "ems",
  11716. length: 2,
  11717. "default": [
  11718. 0,
  11719. 0
  11720. ],
  11721. requires: [
  11722. "text-field",
  11723. {
  11724. "!": "text-radial-offset"
  11725. }
  11726. ],
  11727. expression: {
  11728. interpolated: true,
  11729. parameters: [
  11730. "zoom",
  11731. "feature"
  11732. ]
  11733. },
  11734. "property-type": "data-driven"
  11735. },
  11736. "text-allow-overlap": {
  11737. type: "boolean",
  11738. "default": false,
  11739. requires: [
  11740. "text-field"
  11741. ],
  11742. expression: {
  11743. interpolated: false,
  11744. parameters: [
  11745. "zoom"
  11746. ]
  11747. },
  11748. "property-type": "data-constant"
  11749. },
  11750. "text-ignore-placement": {
  11751. type: "boolean",
  11752. "default": false,
  11753. requires: [
  11754. "text-field"
  11755. ],
  11756. expression: {
  11757. interpolated: false,
  11758. parameters: [
  11759. "zoom"
  11760. ]
  11761. },
  11762. "property-type": "data-constant"
  11763. },
  11764. "text-optional": {
  11765. type: "boolean",
  11766. "default": false,
  11767. requires: [
  11768. "text-field",
  11769. "icon-image"
  11770. ],
  11771. expression: {
  11772. interpolated: false,
  11773. parameters: [
  11774. "zoom"
  11775. ]
  11776. },
  11777. "property-type": "data-constant"
  11778. },
  11779. visibility: {
  11780. type: "enum",
  11781. values: {
  11782. visible: {
  11783. },
  11784. none: {
  11785. }
  11786. },
  11787. "default": "visible",
  11788. "property-type": "constant"
  11789. }
  11790. };
  11791. var layout_raster = {
  11792. visibility: {
  11793. type: "enum",
  11794. values: {
  11795. visible: {
  11796. },
  11797. none: {
  11798. }
  11799. },
  11800. "default": "visible",
  11801. "property-type": "constant"
  11802. }
  11803. };
  11804. var layout_hillshade = {
  11805. visibility: {
  11806. type: "enum",
  11807. values: {
  11808. visible: {
  11809. },
  11810. none: {
  11811. }
  11812. },
  11813. "default": "visible",
  11814. "property-type": "constant"
  11815. }
  11816. };
  11817. var filter = {
  11818. type: "array",
  11819. value: "*"
  11820. };
  11821. var filter_operator = {
  11822. type: "enum",
  11823. values: {
  11824. "==": {
  11825. },
  11826. "!=": {
  11827. },
  11828. ">": {
  11829. },
  11830. ">=": {
  11831. },
  11832. "<": {
  11833. },
  11834. "<=": {
  11835. },
  11836. "in": {
  11837. },
  11838. "!in": {
  11839. },
  11840. all: {
  11841. },
  11842. any: {
  11843. },
  11844. none: {
  11845. },
  11846. has: {
  11847. },
  11848. "!has": {
  11849. }
  11850. }
  11851. };
  11852. var geometry_type = {
  11853. type: "enum",
  11854. values: {
  11855. Point: {
  11856. },
  11857. LineString: {
  11858. },
  11859. Polygon: {
  11860. }
  11861. }
  11862. };
  11863. var function_stop = {
  11864. type: "array",
  11865. minimum: 0,
  11866. maximum: 24,
  11867. value: [
  11868. "number",
  11869. "color"
  11870. ],
  11871. length: 2
  11872. };
  11873. var expression = {
  11874. type: "array",
  11875. value: "*",
  11876. minimum: 1
  11877. };
  11878. var expression_name = {
  11879. type: "enum",
  11880. values: {
  11881. "let": {
  11882. group: "Variable binding"
  11883. },
  11884. "var": {
  11885. group: "Variable binding"
  11886. },
  11887. literal: {
  11888. group: "Types"
  11889. },
  11890. array: {
  11891. group: "Types"
  11892. },
  11893. at: {
  11894. group: "Lookup"
  11895. },
  11896. "in": {
  11897. group: "Lookup"
  11898. },
  11899. "case": {
  11900. group: "Decision"
  11901. },
  11902. match: {
  11903. group: "Decision"
  11904. },
  11905. coalesce: {
  11906. group: "Decision"
  11907. },
  11908. step: {
  11909. group: "Ramps, scales, curves"
  11910. },
  11911. interpolate: {
  11912. group: "Ramps, scales, curves"
  11913. },
  11914. "interpolate-hcl": {
  11915. group: "Ramps, scales, curves"
  11916. },
  11917. "interpolate-lab": {
  11918. group: "Ramps, scales, curves"
  11919. },
  11920. ln2: {
  11921. group: "Math"
  11922. },
  11923. pi: {
  11924. group: "Math"
  11925. },
  11926. e: {
  11927. group: "Math"
  11928. },
  11929. "typeof": {
  11930. group: "Types"
  11931. },
  11932. string: {
  11933. group: "Types"
  11934. },
  11935. number: {
  11936. group: "Types"
  11937. },
  11938. boolean: {
  11939. group: "Types"
  11940. },
  11941. object: {
  11942. group: "Types"
  11943. },
  11944. collator: {
  11945. group: "Types"
  11946. },
  11947. format: {
  11948. group: "Types"
  11949. },
  11950. image: {
  11951. group: "Types"
  11952. },
  11953. "number-format": {
  11954. group: "Types"
  11955. },
  11956. "to-string": {
  11957. group: "Types"
  11958. },
  11959. "to-number": {
  11960. group: "Types"
  11961. },
  11962. "to-boolean": {
  11963. group: "Types"
  11964. },
  11965. "to-rgba": {
  11966. group: "Color"
  11967. },
  11968. "to-color": {
  11969. group: "Types"
  11970. },
  11971. rgb: {
  11972. group: "Color"
  11973. },
  11974. rgba: {
  11975. group: "Color"
  11976. },
  11977. get: {
  11978. group: "Lookup"
  11979. },
  11980. has: {
  11981. group: "Lookup"
  11982. },
  11983. length: {
  11984. group: "Lookup"
  11985. },
  11986. properties: {
  11987. group: "Feature data"
  11988. },
  11989. "feature-state": {
  11990. group: "Feature data"
  11991. },
  11992. "geometry-type": {
  11993. group: "Feature data"
  11994. },
  11995. id: {
  11996. group: "Feature data"
  11997. },
  11998. zoom: {
  11999. group: "Zoom"
  12000. },
  12001. "heatmap-density": {
  12002. group: "Heatmap"
  12003. },
  12004. "line-progress": {
  12005. group: "Feature data"
  12006. },
  12007. accumulated: {
  12008. group: "Feature data"
  12009. },
  12010. "+": {
  12011. group: "Math"
  12012. },
  12013. "*": {
  12014. group: "Math"
  12015. },
  12016. "-": {
  12017. group: "Math"
  12018. },
  12019. "/": {
  12020. group: "Math"
  12021. },
  12022. "%": {
  12023. group: "Math"
  12024. },
  12025. "^": {
  12026. group: "Math"
  12027. },
  12028. sqrt: {
  12029. group: "Math"
  12030. },
  12031. log10: {
  12032. group: "Math"
  12033. },
  12034. ln: {
  12035. group: "Math"
  12036. },
  12037. log2: {
  12038. group: "Math"
  12039. },
  12040. sin: {
  12041. group: "Math"
  12042. },
  12043. cos: {
  12044. group: "Math"
  12045. },
  12046. tan: {
  12047. group: "Math"
  12048. },
  12049. asin: {
  12050. group: "Math"
  12051. },
  12052. acos: {
  12053. group: "Math"
  12054. },
  12055. atan: {
  12056. group: "Math"
  12057. },
  12058. min: {
  12059. group: "Math"
  12060. },
  12061. max: {
  12062. group: "Math"
  12063. },
  12064. round: {
  12065. group: "Math"
  12066. },
  12067. abs: {
  12068. group: "Math"
  12069. },
  12070. ceil: {
  12071. group: "Math"
  12072. },
  12073. floor: {
  12074. group: "Math"
  12075. },
  12076. "==": {
  12077. group: "Decision"
  12078. },
  12079. "!=": {
  12080. group: "Decision"
  12081. },
  12082. ">": {
  12083. group: "Decision"
  12084. },
  12085. "<": {
  12086. group: "Decision"
  12087. },
  12088. ">=": {
  12089. group: "Decision"
  12090. },
  12091. "<=": {
  12092. group: "Decision"
  12093. },
  12094. all: {
  12095. group: "Decision"
  12096. },
  12097. any: {
  12098. group: "Decision"
  12099. },
  12100. "!": {
  12101. group: "Decision"
  12102. },
  12103. "is-supported-script": {
  12104. group: "String"
  12105. },
  12106. upcase: {
  12107. group: "String"
  12108. },
  12109. downcase: {
  12110. group: "String"
  12111. },
  12112. concat: {
  12113. group: "String"
  12114. },
  12115. "resolved-locale": {
  12116. group: "String"
  12117. }
  12118. }
  12119. };
  12120. var light = {
  12121. anchor: {
  12122. type: "enum",
  12123. "default": "viewport",
  12124. values: {
  12125. map: {
  12126. },
  12127. viewport: {
  12128. }
  12129. },
  12130. "property-type": "data-constant",
  12131. transition: false,
  12132. expression: {
  12133. interpolated: false,
  12134. parameters: [
  12135. "zoom"
  12136. ]
  12137. }
  12138. },
  12139. position: {
  12140. type: "array",
  12141. "default": [
  12142. 1.15,
  12143. 210,
  12144. 30
  12145. ],
  12146. length: 3,
  12147. value: "number",
  12148. "property-type": "data-constant",
  12149. transition: true,
  12150. expression: {
  12151. interpolated: true,
  12152. parameters: [
  12153. "zoom"
  12154. ]
  12155. }
  12156. },
  12157. color: {
  12158. type: "color",
  12159. "property-type": "data-constant",
  12160. "default": "#ffffff",
  12161. expression: {
  12162. interpolated: true,
  12163. parameters: [
  12164. "zoom"
  12165. ]
  12166. },
  12167. transition: true
  12168. },
  12169. intensity: {
  12170. type: "number",
  12171. "property-type": "data-constant",
  12172. "default": 0.5,
  12173. minimum: 0,
  12174. maximum: 1,
  12175. expression: {
  12176. interpolated: true,
  12177. parameters: [
  12178. "zoom"
  12179. ]
  12180. },
  12181. transition: true
  12182. }
  12183. };
  12184. var paint = [
  12185. "paint_fill",
  12186. "paint_line",
  12187. "paint_circle",
  12188. "paint_heatmap",
  12189. "paint_fill-extrusion",
  12190. "paint_symbol",
  12191. "paint_raster",
  12192. "paint_hillshade",
  12193. "paint_background"
  12194. ];
  12195. var paint_fill = {
  12196. "fill-antialias": {
  12197. type: "boolean",
  12198. "default": true,
  12199. expression: {
  12200. interpolated: false,
  12201. parameters: [
  12202. "zoom"
  12203. ]
  12204. },
  12205. "property-type": "data-constant"
  12206. },
  12207. "fill-opacity": {
  12208. type: "number",
  12209. "default": 1,
  12210. minimum: 0,
  12211. maximum: 1,
  12212. transition: true,
  12213. expression: {
  12214. interpolated: true,
  12215. parameters: [
  12216. "zoom",
  12217. "feature",
  12218. "feature-state"
  12219. ]
  12220. },
  12221. "property-type": "data-driven"
  12222. },
  12223. "fill-color": {
  12224. type: "color",
  12225. "default": "#000000",
  12226. transition: true,
  12227. requires: [
  12228. {
  12229. "!": "fill-pattern"
  12230. }
  12231. ],
  12232. expression: {
  12233. interpolated: true,
  12234. parameters: [
  12235. "zoom",
  12236. "feature",
  12237. "feature-state"
  12238. ]
  12239. },
  12240. "property-type": "data-driven"
  12241. },
  12242. "fill-outline-color": {
  12243. type: "color",
  12244. transition: true,
  12245. requires: [
  12246. {
  12247. "!": "fill-pattern"
  12248. },
  12249. {
  12250. "fill-antialias": true
  12251. }
  12252. ],
  12253. expression: {
  12254. interpolated: true,
  12255. parameters: [
  12256. "zoom",
  12257. "feature",
  12258. "feature-state"
  12259. ]
  12260. },
  12261. "property-type": "data-driven"
  12262. },
  12263. "fill-translate": {
  12264. type: "array",
  12265. value: "number",
  12266. length: 2,
  12267. "default": [
  12268. 0,
  12269. 0
  12270. ],
  12271. transition: true,
  12272. units: "pixels",
  12273. expression: {
  12274. interpolated: true,
  12275. parameters: [
  12276. "zoom"
  12277. ]
  12278. },
  12279. "property-type": "data-constant"
  12280. },
  12281. "fill-translate-anchor": {
  12282. type: "enum",
  12283. values: {
  12284. map: {
  12285. },
  12286. viewport: {
  12287. }
  12288. },
  12289. "default": "map",
  12290. requires: [
  12291. "fill-translate"
  12292. ],
  12293. expression: {
  12294. interpolated: false,
  12295. parameters: [
  12296. "zoom"
  12297. ]
  12298. },
  12299. "property-type": "data-constant"
  12300. },
  12301. "fill-pattern": {
  12302. type: "resolvedImage",
  12303. transition: true,
  12304. expression: {
  12305. interpolated: false,
  12306. parameters: [
  12307. "zoom",
  12308. "feature"
  12309. ]
  12310. },
  12311. "property-type": "cross-faded-data-driven"
  12312. }
  12313. };
  12314. var paint_line = {
  12315. "line-opacity": {
  12316. type: "number",
  12317. "default": 1,
  12318. minimum: 0,
  12319. maximum: 1,
  12320. transition: true,
  12321. expression: {
  12322. interpolated: true,
  12323. parameters: [
  12324. "zoom",
  12325. "feature",
  12326. "feature-state"
  12327. ]
  12328. },
  12329. "property-type": "data-driven"
  12330. },
  12331. "line-color": {
  12332. type: "color",
  12333. "default": "#000000",
  12334. transition: true,
  12335. requires: [
  12336. {
  12337. "!": "line-pattern"
  12338. }
  12339. ],
  12340. expression: {
  12341. interpolated: true,
  12342. parameters: [
  12343. "zoom",
  12344. "feature",
  12345. "feature-state"
  12346. ]
  12347. },
  12348. "property-type": "data-driven"
  12349. },
  12350. "line-translate": {
  12351. type: "array",
  12352. value: "number",
  12353. length: 2,
  12354. "default": [
  12355. 0,
  12356. 0
  12357. ],
  12358. transition: true,
  12359. units: "pixels",
  12360. expression: {
  12361. interpolated: true,
  12362. parameters: [
  12363. "zoom"
  12364. ]
  12365. },
  12366. "property-type": "data-constant"
  12367. },
  12368. "line-translate-anchor": {
  12369. type: "enum",
  12370. values: {
  12371. map: {
  12372. },
  12373. viewport: {
  12374. }
  12375. },
  12376. "default": "map",
  12377. requires: [
  12378. "line-translate"
  12379. ],
  12380. expression: {
  12381. interpolated: false,
  12382. parameters: [
  12383. "zoom"
  12384. ]
  12385. },
  12386. "property-type": "data-constant"
  12387. },
  12388. "line-width": {
  12389. type: "number",
  12390. "default": 1,
  12391. minimum: 0,
  12392. transition: true,
  12393. units: "pixels",
  12394. expression: {
  12395. interpolated: true,
  12396. parameters: [
  12397. "zoom",
  12398. "feature",
  12399. "feature-state"
  12400. ]
  12401. },
  12402. "property-type": "data-driven"
  12403. },
  12404. "line-gap-width": {
  12405. type: "number",
  12406. "default": 0,
  12407. minimum: 0,
  12408. transition: true,
  12409. units: "pixels",
  12410. expression: {
  12411. interpolated: true,
  12412. parameters: [
  12413. "zoom",
  12414. "feature",
  12415. "feature-state"
  12416. ]
  12417. },
  12418. "property-type": "data-driven"
  12419. },
  12420. "line-offset": {
  12421. type: "number",
  12422. "default": 0,
  12423. transition: true,
  12424. units: "pixels",
  12425. expression: {
  12426. interpolated: true,
  12427. parameters: [
  12428. "zoom",
  12429. "feature",
  12430. "feature-state"
  12431. ]
  12432. },
  12433. "property-type": "data-driven"
  12434. },
  12435. "line-blur": {
  12436. type: "number",
  12437. "default": 0,
  12438. minimum: 0,
  12439. transition: true,
  12440. units: "pixels",
  12441. expression: {
  12442. interpolated: true,
  12443. parameters: [
  12444. "zoom",
  12445. "feature",
  12446. "feature-state"
  12447. ]
  12448. },
  12449. "property-type": "data-driven"
  12450. },
  12451. "line-dasharray": {
  12452. type: "array",
  12453. value: "number",
  12454. minimum: 0,
  12455. transition: true,
  12456. units: "line widths",
  12457. requires: [
  12458. {
  12459. "!": "line-pattern"
  12460. }
  12461. ],
  12462. expression: {
  12463. interpolated: false,
  12464. parameters: [
  12465. "zoom"
  12466. ]
  12467. },
  12468. "property-type": "cross-faded"
  12469. },
  12470. "line-pattern": {
  12471. type: "resolvedImage",
  12472. transition: true,
  12473. expression: {
  12474. interpolated: false,
  12475. parameters: [
  12476. "zoom",
  12477. "feature"
  12478. ]
  12479. },
  12480. "property-type": "cross-faded-data-driven"
  12481. },
  12482. "line-gradient": {
  12483. type: "color",
  12484. transition: false,
  12485. requires: [
  12486. {
  12487. "!": "line-dasharray"
  12488. },
  12489. {
  12490. "!": "line-pattern"
  12491. },
  12492. {
  12493. source: "geojson",
  12494. has: {
  12495. lineMetrics: true
  12496. }
  12497. }
  12498. ],
  12499. expression: {
  12500. interpolated: true,
  12501. parameters: [
  12502. "line-progress"
  12503. ]
  12504. },
  12505. "property-type": "color-ramp"
  12506. }
  12507. };
  12508. var paint_circle = {
  12509. "circle-radius": {
  12510. type: "number",
  12511. "default": 5,
  12512. minimum: 0,
  12513. transition: true,
  12514. units: "pixels",
  12515. expression: {
  12516. interpolated: true,
  12517. parameters: [
  12518. "zoom",
  12519. "feature",
  12520. "feature-state"
  12521. ]
  12522. },
  12523. "property-type": "data-driven"
  12524. },
  12525. "circle-color": {
  12526. type: "color",
  12527. "default": "#000000",
  12528. transition: true,
  12529. expression: {
  12530. interpolated: true,
  12531. parameters: [
  12532. "zoom",
  12533. "feature",
  12534. "feature-state"
  12535. ]
  12536. },
  12537. "property-type": "data-driven"
  12538. },
  12539. "circle-blur": {
  12540. type: "number",
  12541. "default": 0,
  12542. transition: true,
  12543. expression: {
  12544. interpolated: true,
  12545. parameters: [
  12546. "zoom",
  12547. "feature",
  12548. "feature-state"
  12549. ]
  12550. },
  12551. "property-type": "data-driven"
  12552. },
  12553. "circle-opacity": {
  12554. type: "number",
  12555. "default": 1,
  12556. minimum: 0,
  12557. maximum: 1,
  12558. transition: true,
  12559. expression: {
  12560. interpolated: true,
  12561. parameters: [
  12562. "zoom",
  12563. "feature",
  12564. "feature-state"
  12565. ]
  12566. },
  12567. "property-type": "data-driven"
  12568. },
  12569. "circle-translate": {
  12570. type: "array",
  12571. value: "number",
  12572. length: 2,
  12573. "default": [
  12574. 0,
  12575. 0
  12576. ],
  12577. transition: true,
  12578. units: "pixels",
  12579. expression: {
  12580. interpolated: true,
  12581. parameters: [
  12582. "zoom"
  12583. ]
  12584. },
  12585. "property-type": "data-constant"
  12586. },
  12587. "circle-translate-anchor": {
  12588. type: "enum",
  12589. values: {
  12590. map: {
  12591. },
  12592. viewport: {
  12593. }
  12594. },
  12595. "default": "map",
  12596. requires: [
  12597. "circle-translate"
  12598. ],
  12599. expression: {
  12600. interpolated: false,
  12601. parameters: [
  12602. "zoom"
  12603. ]
  12604. },
  12605. "property-type": "data-constant"
  12606. },
  12607. "circle-pitch-scale": {
  12608. type: "enum",
  12609. values: {
  12610. map: {
  12611. },
  12612. viewport: {
  12613. }
  12614. },
  12615. "default": "map",
  12616. expression: {
  12617. interpolated: false,
  12618. parameters: [
  12619. "zoom"
  12620. ]
  12621. },
  12622. "property-type": "data-constant"
  12623. },
  12624. "circle-pitch-alignment": {
  12625. type: "enum",
  12626. values: {
  12627. map: {
  12628. },
  12629. viewport: {
  12630. }
  12631. },
  12632. "default": "viewport",
  12633. expression: {
  12634. interpolated: false,
  12635. parameters: [
  12636. "zoom"
  12637. ]
  12638. },
  12639. "property-type": "data-constant"
  12640. },
  12641. "circle-stroke-width": {
  12642. type: "number",
  12643. "default": 0,
  12644. minimum: 0,
  12645. transition: true,
  12646. units: "pixels",
  12647. expression: {
  12648. interpolated: true,
  12649. parameters: [
  12650. "zoom",
  12651. "feature",
  12652. "feature-state"
  12653. ]
  12654. },
  12655. "property-type": "data-driven"
  12656. },
  12657. "circle-stroke-color": {
  12658. type: "color",
  12659. "default": "#000000",
  12660. transition: true,
  12661. expression: {
  12662. interpolated: true,
  12663. parameters: [
  12664. "zoom",
  12665. "feature",
  12666. "feature-state"
  12667. ]
  12668. },
  12669. "property-type": "data-driven"
  12670. },
  12671. "circle-stroke-opacity": {
  12672. type: "number",
  12673. "default": 1,
  12674. minimum: 0,
  12675. maximum: 1,
  12676. transition: true,
  12677. expression: {
  12678. interpolated: true,
  12679. parameters: [
  12680. "zoom",
  12681. "feature",
  12682. "feature-state"
  12683. ]
  12684. },
  12685. "property-type": "data-driven"
  12686. }
  12687. };
  12688. var paint_heatmap = {
  12689. "heatmap-radius": {
  12690. type: "number",
  12691. "default": 30,
  12692. minimum: 1,
  12693. transition: true,
  12694. units: "pixels",
  12695. expression: {
  12696. interpolated: true,
  12697. parameters: [
  12698. "zoom",
  12699. "feature",
  12700. "feature-state"
  12701. ]
  12702. },
  12703. "property-type": "data-driven"
  12704. },
  12705. "heatmap-weight": {
  12706. type: "number",
  12707. "default": 1,
  12708. minimum: 0,
  12709. transition: false,
  12710. expression: {
  12711. interpolated: true,
  12712. parameters: [
  12713. "zoom",
  12714. "feature",
  12715. "feature-state"
  12716. ]
  12717. },
  12718. "property-type": "data-driven"
  12719. },
  12720. "heatmap-intensity": {
  12721. type: "number",
  12722. "default": 1,
  12723. minimum: 0,
  12724. transition: true,
  12725. expression: {
  12726. interpolated: true,
  12727. parameters: [
  12728. "zoom"
  12729. ]
  12730. },
  12731. "property-type": "data-constant"
  12732. },
  12733. "heatmap-color": {
  12734. type: "color",
  12735. "default": [
  12736. "interpolate",
  12737. [
  12738. "linear"
  12739. ],
  12740. [
  12741. "heatmap-density"
  12742. ],
  12743. 0,
  12744. "rgba(0, 0, 255, 0)",
  12745. 0.1,
  12746. "royalblue",
  12747. 0.3,
  12748. "cyan",
  12749. 0.5,
  12750. "lime",
  12751. 0.7,
  12752. "yellow",
  12753. 1,
  12754. "red"
  12755. ],
  12756. transition: false,
  12757. expression: {
  12758. interpolated: true,
  12759. parameters: [
  12760. "heatmap-density"
  12761. ]
  12762. },
  12763. "property-type": "color-ramp"
  12764. },
  12765. "heatmap-opacity": {
  12766. type: "number",
  12767. "default": 1,
  12768. minimum: 0,
  12769. maximum: 1,
  12770. transition: true,
  12771. expression: {
  12772. interpolated: true,
  12773. parameters: [
  12774. "zoom"
  12775. ]
  12776. },
  12777. "property-type": "data-constant"
  12778. }
  12779. };
  12780. var paint_symbol = {
  12781. "icon-opacity": {
  12782. type: "number",
  12783. "default": 1,
  12784. minimum: 0,
  12785. maximum: 1,
  12786. transition: true,
  12787. requires: [
  12788. "icon-image"
  12789. ],
  12790. expression: {
  12791. interpolated: true,
  12792. parameters: [
  12793. "zoom",
  12794. "feature",
  12795. "feature-state"
  12796. ]
  12797. },
  12798. "property-type": "data-driven"
  12799. },
  12800. "icon-color": {
  12801. type: "color",
  12802. "default": "#000000",
  12803. transition: true,
  12804. requires: [
  12805. "icon-image"
  12806. ],
  12807. expression: {
  12808. interpolated: true,
  12809. parameters: [
  12810. "zoom",
  12811. "feature",
  12812. "feature-state"
  12813. ]
  12814. },
  12815. "property-type": "data-driven"
  12816. },
  12817. "icon-halo-color": {
  12818. type: "color",
  12819. "default": "rgba(0, 0, 0, 0)",
  12820. transition: true,
  12821. requires: [
  12822. "icon-image"
  12823. ],
  12824. expression: {
  12825. interpolated: true,
  12826. parameters: [
  12827. "zoom",
  12828. "feature",
  12829. "feature-state"
  12830. ]
  12831. },
  12832. "property-type": "data-driven"
  12833. },
  12834. "icon-halo-width": {
  12835. type: "number",
  12836. "default": 0,
  12837. minimum: 0,
  12838. transition: true,
  12839. units: "pixels",
  12840. requires: [
  12841. "icon-image"
  12842. ],
  12843. expression: {
  12844. interpolated: true,
  12845. parameters: [
  12846. "zoom",
  12847. "feature",
  12848. "feature-state"
  12849. ]
  12850. },
  12851. "property-type": "data-driven"
  12852. },
  12853. "icon-halo-blur": {
  12854. type: "number",
  12855. "default": 0,
  12856. minimum: 0,
  12857. transition: true,
  12858. units: "pixels",
  12859. requires: [
  12860. "icon-image"
  12861. ],
  12862. expression: {
  12863. interpolated: true,
  12864. parameters: [
  12865. "zoom",
  12866. "feature",
  12867. "feature-state"
  12868. ]
  12869. },
  12870. "property-type": "data-driven"
  12871. },
  12872. "icon-translate": {
  12873. type: "array",
  12874. value: "number",
  12875. length: 2,
  12876. "default": [
  12877. 0,
  12878. 0
  12879. ],
  12880. transition: true,
  12881. units: "pixels",
  12882. requires: [
  12883. "icon-image"
  12884. ],
  12885. expression: {
  12886. interpolated: true,
  12887. parameters: [
  12888. "zoom"
  12889. ]
  12890. },
  12891. "property-type": "data-constant"
  12892. },
  12893. "icon-translate-anchor": {
  12894. type: "enum",
  12895. values: {
  12896. map: {
  12897. },
  12898. viewport: {
  12899. }
  12900. },
  12901. "default": "map",
  12902. requires: [
  12903. "icon-image",
  12904. "icon-translate"
  12905. ],
  12906. expression: {
  12907. interpolated: false,
  12908. parameters: [
  12909. "zoom"
  12910. ]
  12911. },
  12912. "property-type": "data-constant"
  12913. },
  12914. "text-opacity": {
  12915. type: "number",
  12916. "default": 1,
  12917. minimum: 0,
  12918. maximum: 1,
  12919. transition: true,
  12920. requires: [
  12921. "text-field"
  12922. ],
  12923. expression: {
  12924. interpolated: true,
  12925. parameters: [
  12926. "zoom",
  12927. "feature",
  12928. "feature-state"
  12929. ]
  12930. },
  12931. "property-type": "data-driven"
  12932. },
  12933. "text-color": {
  12934. type: "color",
  12935. "default": "#000000",
  12936. transition: true,
  12937. overridable: true,
  12938. requires: [
  12939. "text-field"
  12940. ],
  12941. expression: {
  12942. interpolated: true,
  12943. parameters: [
  12944. "zoom",
  12945. "feature",
  12946. "feature-state"
  12947. ]
  12948. },
  12949. "property-type": "data-driven"
  12950. },
  12951. "text-halo-color": {
  12952. type: "color",
  12953. "default": "rgba(0, 0, 0, 0)",
  12954. transition: true,
  12955. requires: [
  12956. "text-field"
  12957. ],
  12958. expression: {
  12959. interpolated: true,
  12960. parameters: [
  12961. "zoom",
  12962. "feature",
  12963. "feature-state"
  12964. ]
  12965. },
  12966. "property-type": "data-driven"
  12967. },
  12968. "text-halo-width": {
  12969. type: "number",
  12970. "default": 0,
  12971. minimum: 0,
  12972. transition: true,
  12973. units: "pixels",
  12974. requires: [
  12975. "text-field"
  12976. ],
  12977. expression: {
  12978. interpolated: true,
  12979. parameters: [
  12980. "zoom",
  12981. "feature",
  12982. "feature-state"
  12983. ]
  12984. },
  12985. "property-type": "data-driven"
  12986. },
  12987. "text-halo-blur": {
  12988. type: "number",
  12989. "default": 0,
  12990. minimum: 0,
  12991. transition: true,
  12992. units: "pixels",
  12993. requires: [
  12994. "text-field"
  12995. ],
  12996. expression: {
  12997. interpolated: true,
  12998. parameters: [
  12999. "zoom",
  13000. "feature",
  13001. "feature-state"
  13002. ]
  13003. },
  13004. "property-type": "data-driven"
  13005. },
  13006. "text-translate": {
  13007. type: "array",
  13008. value: "number",
  13009. length: 2,
  13010. "default": [
  13011. 0,
  13012. 0
  13013. ],
  13014. transition: true,
  13015. units: "pixels",
  13016. requires: [
  13017. "text-field"
  13018. ],
  13019. expression: {
  13020. interpolated: true,
  13021. parameters: [
  13022. "zoom"
  13023. ]
  13024. },
  13025. "property-type": "data-constant"
  13026. },
  13027. "text-translate-anchor": {
  13028. type: "enum",
  13029. values: {
  13030. map: {
  13031. },
  13032. viewport: {
  13033. }
  13034. },
  13035. "default": "map",
  13036. requires: [
  13037. "text-field",
  13038. "text-translate"
  13039. ],
  13040. expression: {
  13041. interpolated: false,
  13042. parameters: [
  13043. "zoom"
  13044. ]
  13045. },
  13046. "property-type": "data-constant"
  13047. }
  13048. };
  13049. var paint_raster = {
  13050. "raster-opacity": {
  13051. type: "number",
  13052. "default": 1,
  13053. minimum: 0,
  13054. maximum: 1,
  13055. transition: true,
  13056. expression: {
  13057. interpolated: true,
  13058. parameters: [
  13059. "zoom"
  13060. ]
  13061. },
  13062. "property-type": "data-constant"
  13063. },
  13064. "raster-hue-rotate": {
  13065. type: "number",
  13066. "default": 0,
  13067. period: 360,
  13068. transition: true,
  13069. units: "degrees",
  13070. expression: {
  13071. interpolated: true,
  13072. parameters: [
  13073. "zoom"
  13074. ]
  13075. },
  13076. "property-type": "data-constant"
  13077. },
  13078. "raster-brightness-min": {
  13079. type: "number",
  13080. "default": 0,
  13081. minimum: 0,
  13082. maximum: 1,
  13083. transition: true,
  13084. expression: {
  13085. interpolated: true,
  13086. parameters: [
  13087. "zoom"
  13088. ]
  13089. },
  13090. "property-type": "data-constant"
  13091. },
  13092. "raster-brightness-max": {
  13093. type: "number",
  13094. "default": 1,
  13095. minimum: 0,
  13096. maximum: 1,
  13097. transition: true,
  13098. expression: {
  13099. interpolated: true,
  13100. parameters: [
  13101. "zoom"
  13102. ]
  13103. },
  13104. "property-type": "data-constant"
  13105. },
  13106. "raster-saturation": {
  13107. type: "number",
  13108. "default": 0,
  13109. minimum: -1,
  13110. maximum: 1,
  13111. transition: true,
  13112. expression: {
  13113. interpolated: true,
  13114. parameters: [
  13115. "zoom"
  13116. ]
  13117. },
  13118. "property-type": "data-constant"
  13119. },
  13120. "raster-contrast": {
  13121. type: "number",
  13122. "default": 0,
  13123. minimum: -1,
  13124. maximum: 1,
  13125. transition: true,
  13126. expression: {
  13127. interpolated: true,
  13128. parameters: [
  13129. "zoom"
  13130. ]
  13131. },
  13132. "property-type": "data-constant"
  13133. },
  13134. "raster-resampling": {
  13135. type: "enum",
  13136. values: {
  13137. linear: {
  13138. },
  13139. nearest: {
  13140. }
  13141. },
  13142. "default": "linear",
  13143. expression: {
  13144. interpolated: false,
  13145. parameters: [
  13146. "zoom"
  13147. ]
  13148. },
  13149. "property-type": "data-constant"
  13150. },
  13151. "raster-fade-duration": {
  13152. type: "number",
  13153. "default": 300,
  13154. minimum: 0,
  13155. transition: false,
  13156. units: "milliseconds",
  13157. expression: {
  13158. interpolated: true,
  13159. parameters: [
  13160. "zoom"
  13161. ]
  13162. },
  13163. "property-type": "data-constant"
  13164. }
  13165. };
  13166. var paint_hillshade = {
  13167. "hillshade-illumination-direction": {
  13168. type: "number",
  13169. "default": 335,
  13170. minimum: 0,
  13171. maximum: 359,
  13172. transition: false,
  13173. expression: {
  13174. interpolated: true,
  13175. parameters: [
  13176. "zoom"
  13177. ]
  13178. },
  13179. "property-type": "data-constant"
  13180. },
  13181. "hillshade-illumination-anchor": {
  13182. type: "enum",
  13183. values: {
  13184. map: {
  13185. },
  13186. viewport: {
  13187. }
  13188. },
  13189. "default": "viewport",
  13190. expression: {
  13191. interpolated: false,
  13192. parameters: [
  13193. "zoom"
  13194. ]
  13195. },
  13196. "property-type": "data-constant"
  13197. },
  13198. "hillshade-exaggeration": {
  13199. type: "number",
  13200. "default": 0.5,
  13201. minimum: 0,
  13202. maximum: 1,
  13203. transition: true,
  13204. expression: {
  13205. interpolated: true,
  13206. parameters: [
  13207. "zoom"
  13208. ]
  13209. },
  13210. "property-type": "data-constant"
  13211. },
  13212. "hillshade-shadow-color": {
  13213. type: "color",
  13214. "default": "#000000",
  13215. transition: true,
  13216. expression: {
  13217. interpolated: true,
  13218. parameters: [
  13219. "zoom"
  13220. ]
  13221. },
  13222. "property-type": "data-constant"
  13223. },
  13224. "hillshade-highlight-color": {
  13225. type: "color",
  13226. "default": "#FFFFFF",
  13227. transition: true,
  13228. expression: {
  13229. interpolated: true,
  13230. parameters: [
  13231. "zoom"
  13232. ]
  13233. },
  13234. "property-type": "data-constant"
  13235. },
  13236. "hillshade-accent-color": {
  13237. type: "color",
  13238. "default": "#000000",
  13239. transition: true,
  13240. expression: {
  13241. interpolated: true,
  13242. parameters: [
  13243. "zoom"
  13244. ]
  13245. },
  13246. "property-type": "data-constant"
  13247. }
  13248. };
  13249. var paint_background = {
  13250. "background-color": {
  13251. type: "color",
  13252. "default": "#000000",
  13253. transition: true,
  13254. requires: [
  13255. {
  13256. "!": "background-pattern"
  13257. }
  13258. ],
  13259. expression: {
  13260. interpolated: true,
  13261. parameters: [
  13262. "zoom"
  13263. ]
  13264. },
  13265. "property-type": "data-constant"
  13266. },
  13267. "background-pattern": {
  13268. type: "resolvedImage",
  13269. transition: true,
  13270. expression: {
  13271. interpolated: false,
  13272. parameters: [
  13273. "zoom"
  13274. ]
  13275. },
  13276. "property-type": "cross-faded"
  13277. },
  13278. "background-opacity": {
  13279. type: "number",
  13280. "default": 1,
  13281. minimum: 0,
  13282. maximum: 1,
  13283. transition: true,
  13284. expression: {
  13285. interpolated: true,
  13286. parameters: [
  13287. "zoom"
  13288. ]
  13289. },
  13290. "property-type": "data-constant"
  13291. }
  13292. };
  13293. var transition = {
  13294. duration: {
  13295. type: "number",
  13296. "default": 300,
  13297. minimum: 0,
  13298. units: "milliseconds"
  13299. },
  13300. delay: {
  13301. type: "number",
  13302. "default": 0,
  13303. minimum: 0,
  13304. units: "milliseconds"
  13305. }
  13306. };
  13307. var StyleSpec = {
  13308. $version: $version,
  13309. $root: $root,
  13310. sources: sources,
  13311. source: source,
  13312. source_vector: source_vector,
  13313. source_raster: source_raster,
  13314. source_raster_dem: source_raster_dem,
  13315. source_geojson: source_geojson,
  13316. source_video: source_video,
  13317. source_image: source_image,
  13318. layer: layer,
  13319. layout: layout,
  13320. layout_background: layout_background,
  13321. layout_fill: layout_fill,
  13322. layout_circle: layout_circle,
  13323. layout_heatmap: layout_heatmap,
  13324. "layout_fill-extrusion": {
  13325. visibility: {
  13326. type: "enum",
  13327. values: {
  13328. visible: {
  13329. },
  13330. none: {
  13331. }
  13332. },
  13333. "default": "visible",
  13334. "property-type": "constant"
  13335. }
  13336. },
  13337. layout_line: layout_line,
  13338. layout_symbol: layout_symbol,
  13339. layout_raster: layout_raster,
  13340. layout_hillshade: layout_hillshade,
  13341. filter: filter,
  13342. filter_operator: filter_operator,
  13343. geometry_type: geometry_type,
  13344. "function": {
  13345. expression: {
  13346. type: "expression"
  13347. },
  13348. stops: {
  13349. type: "array",
  13350. value: "function_stop"
  13351. },
  13352. base: {
  13353. type: "number",
  13354. "default": 1,
  13355. minimum: 0
  13356. },
  13357. property: {
  13358. type: "string",
  13359. "default": "$zoom"
  13360. },
  13361. type: {
  13362. type: "enum",
  13363. values: {
  13364. identity: {
  13365. },
  13366. exponential: {
  13367. },
  13368. interval: {
  13369. },
  13370. categorical: {
  13371. }
  13372. },
  13373. "default": "exponential"
  13374. },
  13375. colorSpace: {
  13376. type: "enum",
  13377. values: {
  13378. rgb: {
  13379. },
  13380. lab: {
  13381. },
  13382. hcl: {
  13383. }
  13384. },
  13385. "default": "rgb"
  13386. },
  13387. "default": {
  13388. type: "*",
  13389. required: false
  13390. }
  13391. },
  13392. function_stop: function_stop,
  13393. expression: expression,
  13394. expression_name: expression_name,
  13395. light: light,
  13396. paint: paint,
  13397. paint_fill: paint_fill,
  13398. "paint_fill-extrusion": {
  13399. "fill-extrusion-opacity": {
  13400. type: "number",
  13401. "default": 1,
  13402. minimum: 0,
  13403. maximum: 1,
  13404. transition: true,
  13405. expression: {
  13406. interpolated: true,
  13407. parameters: [
  13408. "zoom"
  13409. ]
  13410. },
  13411. "property-type": "data-constant"
  13412. },
  13413. "fill-extrusion-color": {
  13414. type: "color",
  13415. "default": "#000000",
  13416. transition: true,
  13417. requires: [
  13418. {
  13419. "!": "fill-extrusion-pattern"
  13420. }
  13421. ],
  13422. expression: {
  13423. interpolated: true,
  13424. parameters: [
  13425. "zoom",
  13426. "feature",
  13427. "feature-state"
  13428. ]
  13429. },
  13430. "property-type": "data-driven"
  13431. },
  13432. "fill-extrusion-translate": {
  13433. type: "array",
  13434. value: "number",
  13435. length: 2,
  13436. "default": [
  13437. 0,
  13438. 0
  13439. ],
  13440. transition: true,
  13441. units: "pixels",
  13442. expression: {
  13443. interpolated: true,
  13444. parameters: [
  13445. "zoom"
  13446. ]
  13447. },
  13448. "property-type": "data-constant"
  13449. },
  13450. "fill-extrusion-translate-anchor": {
  13451. type: "enum",
  13452. values: {
  13453. map: {
  13454. },
  13455. viewport: {
  13456. }
  13457. },
  13458. "default": "map",
  13459. requires: [
  13460. "fill-extrusion-translate"
  13461. ],
  13462. expression: {
  13463. interpolated: false,
  13464. parameters: [
  13465. "zoom"
  13466. ]
  13467. },
  13468. "property-type": "data-constant"
  13469. },
  13470. "fill-extrusion-pattern": {
  13471. type: "resolvedImage",
  13472. transition: true,
  13473. expression: {
  13474. interpolated: false,
  13475. parameters: [
  13476. "zoom",
  13477. "feature"
  13478. ]
  13479. },
  13480. "property-type": "cross-faded-data-driven"
  13481. },
  13482. "fill-extrusion-height": {
  13483. type: "number",
  13484. "default": 0,
  13485. minimum: 0,
  13486. units: "meters",
  13487. transition: true,
  13488. expression: {
  13489. interpolated: true,
  13490. parameters: [
  13491. "zoom",
  13492. "feature",
  13493. "feature-state"
  13494. ]
  13495. },
  13496. "property-type": "data-driven"
  13497. },
  13498. "fill-extrusion-base": {
  13499. type: "number",
  13500. "default": 0,
  13501. minimum: 0,
  13502. units: "meters",
  13503. transition: true,
  13504. requires: [
  13505. "fill-extrusion-height"
  13506. ],
  13507. expression: {
  13508. interpolated: true,
  13509. parameters: [
  13510. "zoom",
  13511. "feature",
  13512. "feature-state"
  13513. ]
  13514. },
  13515. "property-type": "data-driven"
  13516. },
  13517. "fill-extrusion-vertical-gradient": {
  13518. type: "boolean",
  13519. "default": true,
  13520. transition: false,
  13521. expression: {
  13522. interpolated: false,
  13523. parameters: [
  13524. "zoom"
  13525. ]
  13526. },
  13527. "property-type": "data-constant"
  13528. }
  13529. },
  13530. paint_line: paint_line,
  13531. paint_circle: paint_circle,
  13532. paint_heatmap: paint_heatmap,
  13533. paint_symbol: paint_symbol,
  13534. paint_raster: paint_raster,
  13535. paint_hillshade: paint_hillshade,
  13536. paint_background: paint_background,
  13537. transition: transition,
  13538. "property-type": {
  13539. "data-driven": {
  13540. type: "property-type"
  13541. },
  13542. "cross-faded": {
  13543. type: "property-type"
  13544. },
  13545. "cross-faded-data-driven": {
  13546. type: "property-type"
  13547. },
  13548. "color-ramp": {
  13549. type: "property-type"
  13550. },
  13551. "data-constant": {
  13552. type: "property-type"
  13553. },
  13554. constant: {
  13555. type: "property-type"
  13556. }
  13557. }
  13558. };
  13559. function IntersectionTest() {
  13560. }
  13561. IntersectionTest.polygonIntersectsPolygon = function (polygonA, polygonB) {
  13562. for (var i = 0; i < polygonA.length; i++) {
  13563. if (polygonContainsPoint(polygonB, polygonA[i])) {
  13564. return true;
  13565. }
  13566. }
  13567. for (var i$1 = 0; i$1 < polygonB.length; i$1++) {
  13568. if (polygonContainsPoint(polygonA, polygonB[i$1])) {
  13569. return true;
  13570. }
  13571. }
  13572. if (lineIntersectsLine(polygonA, polygonB)) {
  13573. return true;
  13574. }
  13575. return false;
  13576. };
  13577. IntersectionTest.polygonIntersectsBufferedPoint = function (polygon, point, radius) {
  13578. if (polygonContainsPoint(polygon, point)) {
  13579. return true;
  13580. }
  13581. if (pointIntersectsBufferedLine(point, polygon, radius)) {
  13582. return true;
  13583. }
  13584. return false;
  13585. };
  13586. IntersectionTest.polygonIntersectsMultiPolygon = function (polygon, multiPolygon) {
  13587. if (polygon.length === 1) {
  13588. return multiPolygonContainsPoint(multiPolygon, polygon[0]);
  13589. }
  13590. for (var m = 0; m < multiPolygon.length; m++) {
  13591. var ring = multiPolygon[m];
  13592. for (var n = 0; n < ring.length; n++) {
  13593. if (polygonContainsPoint(polygon, ring[n])) {
  13594. return true;
  13595. }
  13596. }
  13597. }
  13598. for (var i = 0; i < polygon.length; i++) {
  13599. if (multiPolygonContainsPoint(multiPolygon, polygon[i])) {
  13600. return true;
  13601. }
  13602. }
  13603. for (var k = 0; k < multiPolygon.length; k++) {
  13604. if (lineIntersectsLine(polygon, multiPolygon[k])) {
  13605. return true;
  13606. }
  13607. }
  13608. return false;
  13609. };
  13610. IntersectionTest.polygonIntersectsBufferedMultiLine = function (polygon, multiLine, radius) {
  13611. for (var i = 0; i < multiLine.length; i++) {
  13612. var line = multiLine[i];
  13613. if (polygon.length >= 3) {
  13614. for (var k = 0; k < line.length; k++) {
  13615. if (polygonContainsPoint(polygon, line[k])) {
  13616. return true;
  13617. }
  13618. }
  13619. }
  13620. if (lineIntersectsBufferedLine(polygon, line, radius)) {
  13621. return true;
  13622. }
  13623. }
  13624. return false;
  13625. };
  13626. function lineIntersectsBufferedLine(lineA, lineB, radius) {
  13627. if (lineA.length > 1) {
  13628. if (lineIntersectsLine(lineA, lineB)) {
  13629. return true;
  13630. }
  13631. // Check whether any point in either line is within radius of the other line
  13632. for (var j = 0; j < lineB.length; j++) {
  13633. if (pointIntersectsBufferedLine(lineB[j], lineA, radius)) {
  13634. return true;
  13635. }
  13636. }
  13637. }
  13638. for (var k = 0; k < lineA.length; k++) {
  13639. if (pointIntersectsBufferedLine(lineA[k], lineB, radius)) {
  13640. return true;
  13641. }
  13642. }
  13643. return false;
  13644. }
  13645. function lineIntersectsLine(lineA, lineB) {
  13646. if (lineA.length === 0 || lineB.length === 0) {
  13647. return false;
  13648. }
  13649. for (var i = 0; i < lineA.length - 1; i++) {
  13650. var a0 = lineA[i];
  13651. var a1 = lineA[i + 1];
  13652. for (var j = 0; j < lineB.length - 1; j++) {
  13653. var b0 = lineB[j];
  13654. var b1 = lineB[j + 1];
  13655. if (lineSegmentIntersectsLineSegment(a0, a1, b0, b1)) {
  13656. return true;
  13657. }
  13658. }
  13659. }
  13660. return false;
  13661. }
  13662. function lineSegmentIntersectsLineSegment(a0, a1, b0, b1) {
  13663. return Util.isCounterClockwise(a0, b0, b1) !== Util.isCounterClockwise(a1, b0, b1) &&
  13664. Util.isCounterClockwise(a0, a1, b0) !== Util.isCounterClockwise(a0, a1, b1);
  13665. }
  13666. function pointIntersectsBufferedLine(p, line, radius) {
  13667. var radiusSquared = radius * radius;
  13668. if (line.length === 1) {
  13669. return p.distSqr(line[0]) < radiusSquared;
  13670. }
  13671. for (var i = 1; i < line.length; i++) {
  13672. // Find line segments that have a distance <= radius^2 to p
  13673. // In that case, we treat the line as "containing point p".
  13674. var v = line[i - 1], w = line[i];
  13675. if (IntersectionTest.distToSegmentSquared(p, v, w) < radiusSquared) {
  13676. return true;
  13677. }
  13678. }
  13679. return false;
  13680. }
  13681. // Code from http://stackoverflow.com/a/1501725/331379.
  13682. IntersectionTest.distToSegmentSquared = function (p, v, w) {
  13683. var l2 = v.distSqr(w);
  13684. if (l2 === 0) {
  13685. return p.distSqr(v);
  13686. }
  13687. var t = ((p.x - v.x) * (w.x - v.x) + (p.y - v.y) * (w.y - v.y)) / l2;
  13688. if (t < 0) {
  13689. return p.distSqr(v);
  13690. }
  13691. if (t > 1) {
  13692. return p.distSqr(w);
  13693. }
  13694. return p.distSqr(w.sub(v)._mult(t)._add(v));
  13695. };
  13696. // point in polygon ray casting algorithm
  13697. function multiPolygonContainsPoint(rings, p) {
  13698. var c = false,
  13699. ring, p1, p2;
  13700. for (var k = 0; k < rings.length; k++) {
  13701. ring = rings[k];
  13702. for (var i = 0, j = ring.length - 1; i < ring.length; j = i++) {
  13703. p1 = ring[i];
  13704. p2 = ring[j];
  13705. if (((p1.y > p.y) !== (p2.y > p.y)) && (p.x < (p2.x - p1.x) * (p.y - p1.y) / (p2.y - p1.y) + p1.x)) {
  13706. c = !c;
  13707. }
  13708. }
  13709. }
  13710. return c;
  13711. }
  13712. function polygonContainsPoint(ring, p) {
  13713. var c = false;
  13714. for (var i = 0, j = ring.length - 1; i < ring.length; j = i++) {
  13715. var p1 = ring[i];
  13716. var p2 = ring[j];
  13717. if (((p1.y > p.y) !== (p2.y > p.y)) && (p.x < (p2.x - p1.x) * (p.y - p1.y) / (p2.y - p1.y) + p1.x)) {
  13718. c = !c;
  13719. }
  13720. }
  13721. return c;
  13722. }
  13723. var layout$2 = new Properties({
  13724. "circle-sort-key": new DataDrivenProperty(StyleSpec["layout_circle"]["circle-sort-key"])
  13725. });
  13726. var paint$1 = new Properties({
  13727. "circle-radius": new DataDrivenProperty(StyleSpec["paint_circle"]["circle-radius"]),
  13728. "circle-color": new DataDrivenProperty(StyleSpec["paint_circle"]["circle-color"]),
  13729. "circle-blur": new DataDrivenProperty(StyleSpec["paint_circle"]["circle-blur"]),
  13730. "circle-opacity": new DataDrivenProperty(StyleSpec["paint_circle"]["circle-opacity"]),
  13731. "circle-translate": new DataConstantProperty(StyleSpec["paint_circle"]["circle-translate"]),
  13732. "circle-translate-anchor": new DataConstantProperty(StyleSpec["paint_circle"]["circle-translate-anchor"]),
  13733. "circle-pitch-scale": new DataConstantProperty(StyleSpec["paint_circle"]["circle-pitch-scale"]),
  13734. "circle-pitch-alignment": new DataConstantProperty(StyleSpec["paint_circle"]["circle-pitch-alignment"]),
  13735. "circle-stroke-width": new DataDrivenProperty(StyleSpec["paint_circle"]["circle-stroke-width"]),
  13736. "circle-stroke-color": new DataDrivenProperty(StyleSpec["paint_circle"]["circle-stroke-color"]),
  13737. "circle-stroke-opacity": new DataDrivenProperty(StyleSpec["paint_circle"]["circle-stroke-opacity"])
  13738. });
  13739. // Note: without adding the explicit type annotation, Flow infers weaker types
  13740. // for these objects from their use in the constructor to StyleLayer, as
  13741. // {layout?: Properties<...>, paint: Properties<...>}
  13742. var properties = ({ paint: paint$1, layout: layout$2 });
  13743. var CircleStyleLayer = /*@__PURE__*/(function (StyleLayer) {
  13744. function CircleStyleLayer(layer) {
  13745. StyleLayer.call(this, layer, properties);
  13746. }
  13747. if (StyleLayer) CircleStyleLayer.__proto__ = StyleLayer;
  13748. CircleStyleLayer.prototype = Object.create(StyleLayer && StyleLayer.prototype);
  13749. CircleStyleLayer.prototype.constructor = CircleStyleLayer;
  13750. CircleStyleLayer.prototype.createBucket = function createBucket(parameters) {
  13751. return new CircleBucket(parameters);
  13752. };
  13753. CircleStyleLayer.prototype.queryRadius = function queryRadius(bucket) {
  13754. var circleBucket = (bucket );
  13755. return QueryUtils.getMaximumPaintValue('circle-radius', this, circleBucket) +
  13756. QueryUtils.getMaximumPaintValue('circle-stroke-width', this, circleBucket) +
  13757. QueryUtils.translateDistance(this.paint.get('circle-translate'));
  13758. };
  13759. CircleStyleLayer.prototype.queryIntersectsFeature = function queryIntersectsFeature(queryGeometry, feature, featureState, geometry, zoom, transform, pixelsToTileUnits, pixelPosMatrix) {
  13760. pixelPosMatrix = createMat4();
  13761. var translatedPolygon = QueryUtils.translate(queryGeometry,
  13762. this.paint.get('circle-translate'),
  13763. this.paint.get('circle-translate-anchor'),
  13764. 0, pixelsToTileUnits);
  13765. var radius = this.paint.get('circle-radius').evaluate(feature, featureState);
  13766. var stroke = this.paint.get('circle-stroke-width').evaluate(feature, featureState);
  13767. var size = radius + stroke;
  13768. // For pitch-alignment: map, compare feature geometry to query geometry in the plane of the tile
  13769. // // Otherwise, compare geometry in the plane of the viewport
  13770. // // A circle with fixed scaling relative to the viewport gets larger in tile space as it moves into the distance
  13771. // // A circle with fixed scaling relative to the map gets smaller in viewport space as it moves into the distance
  13772. var alignWithMap = this.paint.get('circle-pitch-alignment') === 'map';
  13773. var transformedPolygon = alignWithMap ? translatedPolygon : projectQueryGeometry(translatedPolygon, pixelPosMatrix);
  13774. var transformedSize = alignWithMap ? size * pixelsToTileUnits : size;
  13775. for (var i$1 = 0, list$1 = geometry; i$1 < list$1.length; i$1 += 1) {
  13776. var ring = list$1[i$1];
  13777. for (var i = 0, list = ring; i < list.length; i += 1) {
  13778. var point = list[i];
  13779. var transformedPoint = alignWithMap ? point : projectPoint(point, pixelPosMatrix);
  13780. var adjustedSize = transformedSize;
  13781. var projectedCenter = transformMat4([], [point.x, point.y, 0, 1], pixelPosMatrix);
  13782. if (this.paint.get('circle-pitch-scale') === 'viewport' && this.paint.get('circle-pitch-alignment') === 'map') ; else if (this.paint.get('circle-pitch-scale') === 'map' && this.paint.get('circle-pitch-alignment') === 'viewport') ;
  13783. adjustedSize *= 10.0;
  13784. if (IntersectionTest.polygonIntersectsBufferedPoint(transformedPolygon, transformedPoint, adjustedSize)) {
  13785. return true;
  13786. }
  13787. }
  13788. }
  13789. return false;
  13790. };
  13791. return CircleStyleLayer;
  13792. }(StyleLayer));
  13793. function projectPoint(p, pixelPosMatrix) {
  13794. var point = transformMat4([], [p.x, p.y, 0, 1], pixelPosMatrix);
  13795. //return new pointGeometry(point[0] / point[3], point[1] / point[3]);
  13796. return new Point(point[0], point[1]);
  13797. }
  13798. function projectQueryGeometry(queryGeometry, pixelPosMatrix) {
  13799. return queryGeometry.map(function (p) {
  13800. return projectPoint(p, pixelPosMatrix);
  13801. });
  13802. }
  13803. function createMat4() {
  13804. var out = new Float32Array(16);
  13805. out[0] = 1;
  13806. out[5] = 1;
  13807. out[10] = 1;
  13808. out[15] = 1;
  13809. return out;
  13810. }
  13811. /**
  13812. * Transforms the vec3 with a mat4.
  13813. * 4th vector component is implicitly '1'
  13814. *
  13815. * @param {vec3} out the receiving vector
  13816. * @param {vec3} a the vector to transform
  13817. * @param {mat4} m matrix to transform with
  13818. * @returns {vec3} out
  13819. */
  13820. function transformMat4(out, a, m) {
  13821. var x = a[0],
  13822. y = a[1],
  13823. z = a[2];
  13824. var w = m[3] * x + m[7] * y + m[11] * z + m[15];
  13825. w = w || 1.0;
  13826. out[0] = (m[0] * x + m[4] * y + m[8] * z + m[12]) / w;
  13827. out[1] = (m[1] * x + m[5] * y + m[9] * z + m[13]) / w;
  13828. out[2] = (m[2] * x + m[6] * y + m[10] * z + m[14]) / w;
  13829. return out;
  13830. }
  13831. /**
  13832. * An implementation of `Property` for data driven `line-pattern` which are transitioned by cross-fading
  13833. * rather than interpolation.
  13834. *
  13835. * @private
  13836. */
  13837. var CrossFadedDataDrivenProperty = /*@__PURE__*/(function (DataDrivenProperty) {
  13838. function CrossFadedDataDrivenProperty() {
  13839. DataDrivenProperty.apply(this, arguments);
  13840. }
  13841. if (DataDrivenProperty) CrossFadedDataDrivenProperty.__proto__ = DataDrivenProperty;
  13842. CrossFadedDataDrivenProperty.prototype = Object.create(DataDrivenProperty && DataDrivenProperty.prototype);
  13843. CrossFadedDataDrivenProperty.prototype.constructor = CrossFadedDataDrivenProperty;
  13844. CrossFadedDataDrivenProperty.prototype.possiblyEvaluate = function possiblyEvaluate(value, parameters, availableImages) {
  13845. if (value.value === undefined) {
  13846. return new PossiblyEvaluatedPropertyValue$1(this, {kind: 'constant', value: undefined}, parameters);
  13847. } else if (value.expression.kind === 'constant') {
  13848. var evaluatedValue = value.expression.evaluate(parameters, (null ), {}, availableImages);
  13849. var isImageExpression = value.property.specification.type === 'resolvedImage';
  13850. var constantValue = isImageExpression && typeof evaluatedValue !== 'string' ? evaluatedValue.name : evaluatedValue;
  13851. var constant = this._calculate(constantValue, constantValue, constantValue, parameters);
  13852. return new PossiblyEvaluatedPropertyValue$1(this, {kind: 'constant', value: constant}, parameters);
  13853. } else if (value.expression.kind === 'camera') {
  13854. var cameraVal = this._calculate(
  13855. value.expression.evaluate({zoom: parameters.zoom - 1.0}),
  13856. value.expression.evaluate({zoom: parameters.zoom}),
  13857. value.expression.evaluate({zoom: parameters.zoom + 1.0}),
  13858. parameters);
  13859. return new PossiblyEvaluatedPropertyValue$1(this, {kind: 'constant', value: cameraVal}, parameters);
  13860. } else {
  13861. // source or composite expression
  13862. return new PossiblyEvaluatedPropertyValue$1(this, value.expression, parameters);
  13863. }
  13864. };
  13865. CrossFadedDataDrivenProperty.prototype.evaluate = function evaluate(value, globals, feature, featureState, availableImages) {
  13866. if (value.kind === 'source') {
  13867. var constant = value.evaluate(globals, feature, featureState, availableImages);
  13868. return this._calculate(constant, constant, constant, globals);
  13869. } else if (value.kind === 'composite') {
  13870. return this._calculate(
  13871. value.evaluate({zoom: Math.floor(globals.zoom) - 1.0}, feature, featureState),
  13872. value.evaluate({zoom: Math.floor(globals.zoom)}, feature, featureState),
  13873. value.evaluate({zoom: Math.floor(globals.zoom) + 1.0}, feature, featureState),
  13874. globals);
  13875. } else {
  13876. return value.value;
  13877. }
  13878. };
  13879. CrossFadedDataDrivenProperty.prototype._calculate = function _calculate(min, mid, max, parameters) {
  13880. var z = parameters.zoom;
  13881. return z > parameters.zoomHistory.lastIntegerZoom ? {from: min, to: mid} : {from: max, to: mid};
  13882. };
  13883. CrossFadedDataDrivenProperty.prototype.interpolate = function interpolate(a) {
  13884. return a;
  13885. };
  13886. return CrossFadedDataDrivenProperty;
  13887. }(DataDrivenProperty));
  13888. WebWorkerTransfer.register('DataDrivenProperty', DataDrivenProperty);
  13889. var layout$4 = new Properties({
  13890. "fill-sort-key": new DataDrivenProperty(StyleSpec["layout_fill"]["fill-sort-key"])
  13891. });
  13892. var paint$4 = new Properties({
  13893. "fill-antialias": new DataConstantProperty(StyleSpec["paint_fill"]["fill-antialias"]),
  13894. "fill-opacity": new DataDrivenProperty(StyleSpec["paint_fill"]["fill-opacity"]),
  13895. "fill-color": new DataDrivenProperty(StyleSpec["paint_fill"]["fill-color"]),
  13896. "fill-outline-color": new DataDrivenProperty(StyleSpec["paint_fill"]["fill-outline-color"]),
  13897. "fill-translate": new DataConstantProperty(StyleSpec["paint_fill"]["fill-translate"]),
  13898. "fill-translate-anchor": new DataConstantProperty(StyleSpec["paint_fill"]["fill-translate-anchor"]),
  13899. "fill-pattern": new CrossFadedDataDrivenProperty(StyleSpec["paint_fill"]["fill-pattern"]),
  13900. });
  13901. // Note: without adding the explicit type annotation, Flow infers weaker types
  13902. // for these objects from their use in the constructor to StyleLayer, as
  13903. // {layout?: Properties<...>, paint: Properties<...>}
  13904. var properties$3 = ({ paint: paint$4, layout: layout$4 }
  13905. );
  13906. var FillStyleLayer = /*@__PURE__*/(function (StyleLayer) {
  13907. function FillStyleLayer(layer) {
  13908. StyleLayer.call(this, layer, properties$3);
  13909. }
  13910. if (StyleLayer) FillStyleLayer.__proto__ = StyleLayer;
  13911. FillStyleLayer.prototype = Object.create(StyleLayer && StyleLayer.prototype);
  13912. FillStyleLayer.prototype.constructor = FillStyleLayer;
  13913. FillStyleLayer.prototype.recalculate = function recalculate(parameters, availableImages) {
  13914. StyleLayer.prototype.recalculate.call(this, parameters, availableImages);
  13915. var outlineColor = this.paint._values['fill-outline-color'];
  13916. if (outlineColor.value.kind === 'constant' && outlineColor.value.value === undefined) {
  13917. this.paint._values['fill-outline-color'] = this.paint._values['fill-color'];
  13918. }
  13919. };
  13920. FillStyleLayer.prototype.createBucket = function createBucket(parameters) {
  13921. return new FillBucket(parameters);
  13922. };
  13923. FillStyleLayer.prototype.queryRadius = function queryRadius() {
  13924. return QueryUtils.translateDistance(this.paint.get('fill-translate'));
  13925. };
  13926. FillStyleLayer.prototype.queryIntersectsFeature = function queryIntersectsFeature(queryGeometry, feature, featureState, geometry, zoom, transform, pixelsToTileUnits) {
  13927. var translatedPolygon = QueryUtils.translate(queryGeometry,
  13928. this.paint.get('fill-translate'),
  13929. this.paint.get('fill-translate-anchor'),
  13930. 0, pixelsToTileUnits);
  13931. return IntersectionTest.polygonIntersectsMultiPolygon(translatedPolygon, geometry);
  13932. };
  13933. FillStyleLayer.prototype.isTileClipped = function isTileClipped() {
  13934. return true;
  13935. };
  13936. return FillStyleLayer;
  13937. }(StyleLayer));
  13938. /**
  13939. * An implementation of `Property` for `*-pattern` and `line-dasharray`, which are transitioned by cross-fading
  13940. * rather than interpolation.
  13941. *
  13942. * @private
  13943. */
  13944. var CrossFadedProperty = function CrossFadedProperty(specification) {
  13945. this.specification = specification;
  13946. };
  13947. CrossFadedProperty.prototype.possiblyEvaluate = function possiblyEvaluate(value, parameters, availableImages) {
  13948. if (value.value === undefined) {
  13949. return undefined;
  13950. } else if (value.expression.kind === 'constant') {
  13951. var constant = value.expression.evaluate(parameters, (null ), {}, availableImages);
  13952. return this._calculate(constant, constant, constant, parameters);
  13953. } else {
  13954. //assert_1(!value.isDataDriven());
  13955. return this._calculate(
  13956. value.expression.evaluate(new EvaluationParameters(Math.floor(parameters.zoom - 1.0), parameters)),
  13957. value.expression.evaluate(new EvaluationParameters(Math.floor(parameters.zoom), parameters)),
  13958. value.expression.evaluate(new EvaluationParameters(Math.floor(parameters.zoom + 1.0), parameters)),
  13959. parameters);
  13960. }
  13961. };
  13962. CrossFadedProperty.prototype._calculate = function _calculate(min, mid, max, parameters) {
  13963. var z = parameters.zoom;
  13964. return z > parameters.zoomHistory.lastIntegerZoom ? {from: min, to: mid} : {from: max, to: mid};
  13965. };
  13966. CrossFadedProperty.prototype.interpolate = function interpolate(a) {
  13967. return a;
  13968. };
  13969. WebWorkerTransfer.register('CrossFadedProperty', CrossFadedProperty);
  13970. /**
  13971. * An implementation of `Property` for `heatmap-color` and `line-gradient`. Interpolation is a no-op, and
  13972. * evaluation returns a boolean value in order to indicate its presence, but the real
  13973. * evaluation happens in StyleLayer classes.
  13974. *
  13975. * @private
  13976. */
  13977. var ColorRampProperty = function ColorRampProperty(specification) {
  13978. this.specification = specification;
  13979. };
  13980. ColorRampProperty.prototype.possiblyEvaluate = function possiblyEvaluate(value, parameters, availableImages) {
  13981. return !!value.expression.evaluate(parameters, (null ), {}, availableImages);
  13982. };
  13983. ColorRampProperty.prototype.interpolate = function interpolate() {
  13984. return false;
  13985. };
  13986. WebWorkerTransfer.register('ColorRampProperty', ColorRampProperty);
  13987. var layout$6 = new Properties({
  13988. "line-cap": new DataConstantProperty(StyleSpec["layout_line"]["line-cap"]),
  13989. "line-join": new DataDrivenProperty(StyleSpec["layout_line"]["line-join"]),
  13990. "line-miter-limit": new DataConstantProperty(StyleSpec["layout_line"]["line-miter-limit"]),
  13991. "line-round-limit": new DataConstantProperty(StyleSpec["layout_line"]["line-round-limit"]),
  13992. "line-sort-key": new DataDrivenProperty(StyleSpec["layout_line"]["line-sort-key"])
  13993. });
  13994. var paint$6 = new Properties({
  13995. "line-opacity": new DataDrivenProperty(StyleSpec["paint_line"]["line-opacity"]),
  13996. "line-color": new DataDrivenProperty(StyleSpec["paint_line"]["line-color"]),
  13997. "line-translate": new DataConstantProperty(StyleSpec["paint_line"]["line-translate"]),
  13998. "line-translate-anchor": new DataConstantProperty(StyleSpec["paint_line"]["line-translate-anchor"]),
  13999. "line-width": new DataDrivenProperty(StyleSpec["paint_line"]["line-width"]),
  14000. "line-gap-width": new DataDrivenProperty(StyleSpec["paint_line"]["line-gap-width"]),
  14001. "line-offset": new DataDrivenProperty(StyleSpec["paint_line"]["line-offset"]),
  14002. "line-blur": new DataDrivenProperty(StyleSpec["paint_line"]["line-blur"]),
  14003. "line-dasharray": new CrossFadedProperty(StyleSpec["paint_line"]["line-dasharray"]),
  14004. "line-pattern": new CrossFadedDataDrivenProperty(StyleSpec["paint_line"]["line-pattern"]),
  14005. "line-gradient": new ColorRampProperty(StyleSpec["paint_line"]["line-gradient"])
  14006. });
  14007. // Note: without adding the explicit type annotation, Flow infers weaker types
  14008. // for these objects from their use in the constructor to StyleLayer, as
  14009. // {layout?: Properties<...>, paint: Properties<...>}
  14010. var properties$5 = ({ paint: paint$6, layout: layout$6 }
  14011. );
  14012. var LineFloorwidthProperty = /*@__PURE__*/(function (DataDrivenProperty) {
  14013. function LineFloorwidthProperty() {
  14014. DataDrivenProperty.apply(this, arguments);
  14015. }
  14016. if (DataDrivenProperty) LineFloorwidthProperty.__proto__ = DataDrivenProperty;
  14017. LineFloorwidthProperty.prototype = Object.create(DataDrivenProperty && DataDrivenProperty.prototype);
  14018. LineFloorwidthProperty.prototype.constructor = LineFloorwidthProperty;
  14019. LineFloorwidthProperty.prototype.possiblyEvaluate = function possiblyEvaluate(value, parameters) {
  14020. parameters = new EvaluationParameters$1(Math.floor(parameters.zoom), {
  14021. now: parameters.now,
  14022. fadeDuration: parameters.fadeDuration,
  14023. zoomHistory: parameters.zoomHistory,
  14024. transition: parameters.transition
  14025. });
  14026. return DataDrivenProperty.prototype.possiblyEvaluate.call(this, value, parameters);
  14027. };
  14028. LineFloorwidthProperty.prototype.evaluate = function evaluate(value, globals, feature, featureState) {
  14029. globals = extend({}, globals, {zoom: Math.floor(globals.zoom)});
  14030. return DataDrivenProperty.prototype.evaluate.call(this, value, globals, feature, featureState);
  14031. };
  14032. return LineFloorwidthProperty;
  14033. }(DataDrivenProperty));
  14034. var lineFloorwidthProperty = new LineFloorwidthProperty(properties$5.paint.properties['line-width'].specification);
  14035. lineFloorwidthProperty.useIntegerZoom = true;
  14036. var LineStyleLayer = /*@__PURE__*/(function (StyleLayer) {
  14037. function LineStyleLayer(layer) {
  14038. StyleLayer.call(this, layer, properties$5);
  14039. }
  14040. if (StyleLayer) LineStyleLayer.__proto__ = StyleLayer;
  14041. LineStyleLayer.prototype = Object.create(StyleLayer && StyleLayer.prototype);
  14042. LineStyleLayer.prototype.constructor = LineStyleLayer;
  14043. LineStyleLayer.prototype._handleSpecialPaintPropertyUpdate = function _handleSpecialPaintPropertyUpdate(name) {
  14044. if (name === 'line-gradient') {
  14045. this._updateGradient();
  14046. }
  14047. };
  14048. LineStyleLayer.prototype._updateGradient = function _updateGradient() {
  14049. var expression = this._transitionablePaint._values['line-gradient'].value.expression;
  14050. this.gradient = renderColorRamp(expression, 'lineProgress');
  14051. this.gradientTexture = null;
  14052. };
  14053. LineStyleLayer.prototype.recalculate = function recalculate(parameters, availableImages) {
  14054. StyleLayer.prototype.recalculate.call(this, parameters, availableImages);
  14055. (this.paint._values )['line-floorwidth'] =
  14056. lineFloorwidthProperty.possiblyEvaluate(this._transitioningPaint._values['line-width'].value, parameters);
  14057. };
  14058. LineStyleLayer.prototype.createBucket = function createBucket(parameters) {
  14059. return new LineBucket(parameters);
  14060. };
  14061. LineStyleLayer.prototype.queryRadius = function queryRadius(bucket) {
  14062. var lineBucket = (bucket );
  14063. var width = getLineWidth(
  14064. QueryUtils.getMaximumPaintValue('line-width', this, lineBucket),
  14065. QueryUtils.getMaximumPaintValue('line-gap-width', this, lineBucket));
  14066. var offset = QueryUtils.getMaximumPaintValue('line-offset', this, lineBucket);
  14067. return width / 2 + Math.abs(offset) + QueryUtils.translateDistance(this.paint.get('line-translate'));
  14068. };
  14069. LineStyleLayer.prototype.queryIntersectsFeature = function queryIntersectsFeature(queryGeometry, feature, featureState, geometry, zoom, transform, pixelsToTileUnits) {
  14070. var translatedPolygon = QueryUtils.translate(queryGeometry,
  14071. this.paint.get('line-translate'),
  14072. this.paint.get('line-translate-anchor'),
  14073. 0, pixelsToTileUnits);
  14074. var halfWidth = pixelsToTileUnits / 2 * getLineWidth(
  14075. this.paint.get('line-width').evaluate(feature, featureState),
  14076. this.paint.get('line-gap-width').evaluate(feature, featureState));
  14077. var lineOffset = this.paint.get('line-offset').evaluate(feature, featureState);
  14078. if (lineOffset) {
  14079. geometry = offsetLine(geometry, lineOffset * pixelsToTileUnits);
  14080. }
  14081. return IntersectionTest.polygonIntersectsBufferedMultiLine(translatedPolygon, geometry, halfWidth);
  14082. };
  14083. LineStyleLayer.prototype.isTileClipped = function isTileClipped() {
  14084. return true;
  14085. };
  14086. function getLineWidth(lineWidth, lineGapWidth) {
  14087. if (lineGapWidth > 0) {
  14088. return lineGapWidth + 2 * lineWidth;
  14089. } else {
  14090. return lineWidth;
  14091. }
  14092. }
  14093. function offsetLine(rings, offset) {
  14094. var newRings = [];
  14095. var zero = new Point(0, 0);
  14096. for (var k = 0; k < rings.length; k++) {
  14097. var ring = rings[k];
  14098. var newRing = [];
  14099. for (var i = 0; i < ring.length; i++) {
  14100. var a = ring[i - 1];
  14101. var b = ring[i];
  14102. var c = ring[i + 1];
  14103. var aToB = i === 0 ? zero : b.sub(a)._unit()._perp();
  14104. var bToC = i === ring.length - 1 ? zero : c.sub(b)._unit()._perp();
  14105. var extrude = aToB._add(bToC)._unit();
  14106. var cosHalfAngle = extrude.x * bToC.x + extrude.y * bToC.y;
  14107. extrude._mult(1 / cosHalfAngle);
  14108. newRing.push(extrude._mult(offset)._add(b));
  14109. }
  14110. newRings.push(newRing);
  14111. }
  14112. return newRings;
  14113. }
  14114. return LineStyleLayer;
  14115. }(StyleLayer));
  14116. function SymbolAttributes() {
  14117. }
  14118. SymbolAttributes.symbolLayoutAttributes = createLayout([
  14119. {name: 'a_pos_offset', components: 4, type: 'Int16'},
  14120. {name: 'a_data', components: 4, type: 'Uint16'},
  14121. {name: 'a_pixeloffset', components: 4, type: 'Int16'}
  14122. ], 4);
  14123. SymbolAttributes.dynamicLayoutAttributes = createLayout([
  14124. {name: 'a_projected_pos', components: 3, type: 'Float32'}
  14125. ], 4);
  14126. SymbolAttributes.placementOpacityAttributes = createLayout([
  14127. {name: 'a_fade_opacity', components: 1, type: 'Uint32'}
  14128. ], 4);
  14129. SymbolAttributes.collisionVertexAttributes = createLayout([
  14130. {name: 'a_placed', components: 2, type: 'Uint8'},
  14131. {name: 'a_shift', components: 2, type: 'Float32'}
  14132. ]);
  14133. SymbolAttributes.collisionBox = createLayout([
  14134. // the box is centered around the anchor point
  14135. {type: 'Int16', name: 'anchorPointX'},
  14136. {type: 'Int16', name: 'anchorPointY'},
  14137. // distances to the edges from the anchor
  14138. {type: 'Int16', name: 'x1'},
  14139. {type: 'Int16', name: 'y1'},
  14140. {type: 'Int16', name: 'x2'},
  14141. {type: 'Int16', name: 'y2'},
  14142. // the index of the feature in the original vectortile
  14143. {type: 'Uint32', name: 'featureIndex'},
  14144. // the source layer the feature appears in
  14145. {type: 'Uint16', name: 'sourceLayerIndex'},
  14146. // the bucket the feature appears in
  14147. {type: 'Uint16', name: 'bucketIndex'},
  14148. // collision circles for lines store their distance to the anchor in tile units
  14149. // so that they can be ignored if the projected label doesn't extend into
  14150. // the box area
  14151. {type: 'Int16', name: 'radius'},
  14152. {type: 'Int16', name: 'signedDistanceFromAnchor'}
  14153. ]);
  14154. SymbolAttributes.collisionBoxLayout = createLayout([ // used to render collision boxes for debugging purposes
  14155. {name: 'a_pos', components: 2, type: 'Int16'},
  14156. {name: 'a_anchor_pos', components: 2, type: 'Int16'},
  14157. {name: 'a_extrude', components: 2, type: 'Int16'}
  14158. ], 4);
  14159. SymbolAttributes.collisionCircleLayout = createLayout([ // used to render collision circles for debugging purposes
  14160. {name: 'a_pos', components: 2, type: 'Int16'},
  14161. {name: 'a_anchor_pos', components: 2, type: 'Int16'},
  14162. {name: 'a_extrude', components: 2, type: 'Int16'}
  14163. ], 4);
  14164. SymbolAttributes.placement = createLayout([
  14165. {type: 'Int16', name: 'anchorX'},
  14166. {type: 'Int16', name: 'anchorY'},
  14167. {type: 'Uint16', name: 'glyphStartIndex'},
  14168. {type: 'Uint16', name: 'numGlyphs'},
  14169. {type: 'Uint32', name: 'vertexStartIndex'},
  14170. {type: 'Uint32', name: 'lineStartIndex'},
  14171. {type: 'Uint32', name: 'lineLength'},
  14172. {type: 'Uint16', name: 'segment'},
  14173. {type: 'Uint16', name: 'lowerSize'},
  14174. {type: 'Uint16', name: 'upperSize'},
  14175. {type: 'Float32', name: 'lineOffsetX'},
  14176. {type: 'Float32', name: 'lineOffsetY'},
  14177. {type: 'Uint8', name: 'writingMode'},
  14178. {type: 'Uint8', name: 'placedOrientation'},
  14179. {type: 'Uint8', name: 'hidden'},
  14180. {type: 'Uint32', name: 'crossTileID'},
  14181. {type: 'Int16', name: 'associatedIconIndex'}
  14182. ]);
  14183. SymbolAttributes.symbolInstance = createLayout([
  14184. {type: 'Int16', name: 'anchorX'},
  14185. {type: 'Int16', name: 'anchorY'},
  14186. {type: 'Int16', name: 'rightJustifiedTextSymbolIndex'},
  14187. {type: 'Int16', name: 'centerJustifiedTextSymbolIndex'},
  14188. {type: 'Int16', name: 'leftJustifiedTextSymbolIndex'},
  14189. {type: 'Int16', name: 'verticalPlacedTextSymbolIndex'},
  14190. {type: 'Int16', name: 'placedIconSymbolIndex'},
  14191. {type: 'Int16', name: 'verticalPlacedIconSymbolIndex'},
  14192. {type: 'Uint16', name: 'key'},
  14193. {type: 'Uint16', name: 'textBoxStartIndex'},
  14194. {type: 'Uint16', name: 'textBoxEndIndex'},
  14195. {type: 'Uint16', name: 'verticalTextBoxStartIndex'},
  14196. {type: 'Uint16', name: 'verticalTextBoxEndIndex'},
  14197. {type: 'Uint16', name: 'iconBoxStartIndex'},
  14198. {type: 'Uint16', name: 'iconBoxEndIndex'},
  14199. {type: 'Uint16', name: 'verticalIconBoxStartIndex'},
  14200. {type: 'Uint16', name: 'verticalIconBoxEndIndex'},
  14201. {type: 'Uint16', name: 'featureIndex'},
  14202. {type: 'Uint16', name: 'numHorizontalGlyphVertices'},
  14203. {type: 'Uint16', name: 'numVerticalGlyphVertices'},
  14204. {type: 'Uint16', name: 'numIconVertices'},
  14205. {type: 'Uint16', name: 'numVerticalIconVertices'},
  14206. {type: 'Uint32', name: 'crossTileID'},
  14207. {type: 'Float32', name: 'textBoxScale'},
  14208. {type: 'Float32', components: 2, name: 'textOffset'}
  14209. ]);
  14210. SymbolAttributes.glyphOffset = createLayout([
  14211. {type: 'Float32', name: 'offsetX'}
  14212. ]);
  14213. SymbolAttributes.lineVertex = createLayout([
  14214. {type: 'Int16', name: 'x'},
  14215. {type: 'Int16', name: 'y'},
  14216. {type: 'Int16', name: 'tileUnitDistanceFromAnchor'}
  14217. ]);
  14218. function mergeLines(features) {
  14219. var leftIndex = {};
  14220. var rightIndex = {};
  14221. var mergedFeatures = [];
  14222. var mergedIndex = 0;
  14223. function add(k) {
  14224. mergedFeatures.push(features[k]);
  14225. mergedIndex++;
  14226. }
  14227. function mergeFromRight(leftKey, rightKey, geom) {
  14228. var i = rightIndex[leftKey];
  14229. delete rightIndex[leftKey];
  14230. rightIndex[rightKey] = i;
  14231. mergedFeatures[i].geometry[0].pop();
  14232. mergedFeatures[i].geometry[0] = mergedFeatures[i].geometry[0].concat(geom[0]);
  14233. return i;
  14234. }
  14235. function mergeFromLeft(leftKey, rightKey, geom) {
  14236. var i = leftIndex[rightKey];
  14237. delete leftIndex[rightKey];
  14238. leftIndex[leftKey] = i;
  14239. mergedFeatures[i].geometry[0].shift();
  14240. mergedFeatures[i].geometry[0] = geom[0].concat(mergedFeatures[i].geometry[0]);
  14241. return i;
  14242. }
  14243. function getKey(text, geom, onRight) {
  14244. var point = onRight ? geom[0][geom[0].length - 1] : geom[0][0];
  14245. return (text + ":" + (point.x) + ":" + (point.y));
  14246. }
  14247. for (var k = 0; k < features.length; k++) {
  14248. var feature = features[k];
  14249. var geom = feature.geometry;
  14250. var text = feature.text ? feature.text.toString() : null;
  14251. if (!text) {
  14252. add(k);
  14253. continue;
  14254. }
  14255. var leftKey = getKey(text, geom),
  14256. rightKey = getKey(text, geom, true);
  14257. if ((leftKey in rightIndex) && (rightKey in leftIndex) && (rightIndex[leftKey] !== leftIndex[rightKey])) {
  14258. // found lines with the same text adjacent to both ends of the current line, merge all three
  14259. var j = mergeFromLeft(leftKey, rightKey, geom);
  14260. var i = mergeFromRight(leftKey, rightKey, mergedFeatures[j].geometry);
  14261. delete leftIndex[leftKey];
  14262. delete rightIndex[rightKey];
  14263. rightIndex[getKey(text, mergedFeatures[i].geometry, true)] = i;
  14264. mergedFeatures[j].geometry = (null );
  14265. } else if (leftKey in rightIndex) {
  14266. // found mergeable line adjacent to the start of the current line, merge
  14267. mergeFromRight(leftKey, rightKey, geom);
  14268. } else if (rightKey in leftIndex) {
  14269. // found mergeable line adjacent to the end of the current line, merge
  14270. mergeFromLeft(leftKey, rightKey, geom);
  14271. } else {
  14272. // no adjacent lines, add as a new item
  14273. add(k);
  14274. leftIndex[leftKey] = mergedIndex - 1;
  14275. rightIndex[rightKey] = mergedIndex - 1;
  14276. }
  14277. }
  14278. return mergedFeatures.filter(function (f) {
  14279. return f.geometry;
  14280. });
  14281. }
  14282. var Shaping = function Shaping() {
  14283. };
  14284. Shaping.WritingMode = {
  14285. horizontal: 1,
  14286. vertical: 2,
  14287. horizontalOnly: 3
  14288. };
  14289. // The position of a glyph relative to the text's anchor point.
  14290. // A collection of positioned glyphs and some metadata
  14291. function isEmpty(positionedLines) {
  14292. for (var i = 0, list = positionedLines; i < list.length; i += 1) {
  14293. var line = list[i];
  14294. if (line.positionedGlyphs.length !== 0) {
  14295. return false;
  14296. }
  14297. }
  14298. return true;
  14299. }
  14300. // Max number of images in label is 6401 U+E000–U+F8FF that covers
  14301. // Basic Multilingual Plane Unicode Private Use Area (PUA).
  14302. var PUAbegin = 0xE000;
  14303. var PUAend = 0xF8FF;
  14304. var SectionOptions = function SectionOptions() {
  14305. this.scale = 1.0;
  14306. this.fontStack = "";
  14307. this.imageName = null;
  14308. };
  14309. SectionOptions.forText = function forText(scale, fontStack) {
  14310. var textOptions = new SectionOptions();
  14311. textOptions.scale = scale || 1;
  14312. textOptions.fontStack = fontStack;
  14313. return textOptions;
  14314. };
  14315. SectionOptions.forImage = function forImage(imageName) {
  14316. var imageOptions = new SectionOptions();
  14317. imageOptions.imageName = imageName;
  14318. return imageOptions;
  14319. };
  14320. var TaggedString = function TaggedString() {
  14321. this.text = "";
  14322. this.sectionIndex = [];
  14323. this.sections = [];
  14324. this.imageSectionID = null;
  14325. };
  14326. TaggedString.fromFeature = function fromFeature(text, defaultFontStack) {
  14327. var result = new TaggedString();
  14328. for (var i = 0; i < text.sections.length; i++) {
  14329. var section = text.sections[i];
  14330. if (!section.image) {
  14331. result.addTextSection(section, defaultFontStack);
  14332. } else {
  14333. result.addImageSection(section);
  14334. }
  14335. }
  14336. return result;
  14337. };
  14338. TaggedString.prototype.length = function length() {
  14339. return this.text.length;
  14340. };
  14341. TaggedString.prototype.getSection = function getSection(index) {
  14342. return this.sections[this.sectionIndex[index]];
  14343. };
  14344. TaggedString.prototype.getSectionIndex = function getSectionIndex(index) {
  14345. return this.sectionIndex[index];
  14346. };
  14347. TaggedString.prototype.getCharCode = function getCharCode(index) {
  14348. return this.text.charCodeAt(index);
  14349. };
  14350. TaggedString.prototype.verticalizePunctuation = function verticalizePunctuation$1() {
  14351. //this.text = verticalizePunctuation(this.text);
  14352. };
  14353. TaggedString.prototype.trim = function trim() {
  14354. var beginningWhitespace = 0;
  14355. for (var i = 0;
  14356. i < this.text.length && whitespace[this.text.charCodeAt(i)];
  14357. i++) {
  14358. beginningWhitespace++;
  14359. }
  14360. var trailingWhitespace = this.text.length;
  14361. for (var i$1 = this.text.length - 1;
  14362. i$1 >= 0 && i$1 >= beginningWhitespace && whitespace[this.text.charCodeAt(i$1)];
  14363. i$1--) {
  14364. trailingWhitespace--;
  14365. }
  14366. this.text = this.text.substring(beginningWhitespace, trailingWhitespace);
  14367. this.sectionIndex = this.sectionIndex.slice(beginningWhitespace, trailingWhitespace);
  14368. };
  14369. TaggedString.prototype.substring = function substring(start, end) {
  14370. var substring = new TaggedString();
  14371. substring.text = this.text.substring(start, end);
  14372. substring.sectionIndex = this.sectionIndex.slice(start, end);
  14373. substring.sections = this.sections;
  14374. return substring;
  14375. };
  14376. TaggedString.prototype.toString = function toString() {
  14377. return this.text;
  14378. };
  14379. TaggedString.prototype.getMaxScale = function getMaxScale() {
  14380. var this$1 = this;
  14381. return this.sectionIndex.reduce(function (max, index) {
  14382. return Math.max(max, this$1.sections[index].scale);
  14383. }, 0);
  14384. };
  14385. TaggedString.prototype.addTextSection = function addTextSection(section, defaultFontStack) {
  14386. this.text += section.text;
  14387. this.sections.push(SectionOptions.forText(section.scale, section.fontStack || defaultFontStack));
  14388. var index = this.sections.length - 1;
  14389. for (var i = 0; i < section.text.length; ++i) {
  14390. this.sectionIndex.push(index);
  14391. }
  14392. };
  14393. TaggedString.prototype.addImageSection = function addImageSection(section) {
  14394. var imageName = section.image ? section.image.name : '';
  14395. if (imageName.length === 0) {
  14396. //warnOnce("Can't add FormattedSection with an empty image.");
  14397. return;
  14398. }
  14399. var nextImageSectionCharCode = this.getNextImageSectionCharCode();
  14400. if (!nextImageSectionCharCode) {
  14401. //warnOnce(("Reached maximum number of images " + (PUAend - PUAbegin + 2)));
  14402. return;
  14403. }
  14404. this.text += String.fromCharCode(nextImageSectionCharCode);
  14405. this.sections.push(SectionOptions.forImage(imageName));
  14406. this.sectionIndex.push(this.sections.length - 1);
  14407. };
  14408. TaggedString.prototype.getNextImageSectionCharCode = function getNextImageSectionCharCode() {
  14409. if (!this.imageSectionID) {
  14410. this.imageSectionID = PUAbegin;
  14411. return this.imageSectionID;
  14412. }
  14413. if (this.imageSectionID >= PUAend) {
  14414. return null;
  14415. }
  14416. return ++this.imageSectionID;
  14417. };
  14418. function breakLines(input, lineBreakPoints) {
  14419. var lines = [];
  14420. var text = input.text;
  14421. var start = 0;
  14422. for (var i = 0, list = lineBreakPoints; i < list.length; i += 1) {
  14423. var lineBreak = list[i];
  14424. lines.push(input.substring(start, lineBreak));
  14425. start = lineBreak;
  14426. }
  14427. if (start < text.length) {
  14428. lines.push(input.substring(start, text.length));
  14429. }
  14430. return lines;
  14431. }
  14432. Shaping.shapeText = function(text, glyphMap, glyphPositions, imagePositions, defaultFontStack, maxWidth, lineHeight, textAnchor, textJustify, spacing, translate, writingMode, allowVerticalPlacement, symbolPlacement, layoutTextSize, layoutTextSizeThisZoom){
  14433. var logicalInput = TaggedString.fromFeature(text, defaultFontStack);
  14434. if (writingMode === Shaping.WritingMode.vertical) {
  14435. logicalInput.verticalizePunctuation();
  14436. }
  14437. var lines;
  14438. {
  14439. lines = breakLines(logicalInput, determineLineBreaks());
  14440. }
  14441. var positionedLines = [];
  14442. var shaping = {
  14443. positionedLines: positionedLines,
  14444. text: logicalInput.toString(),
  14445. top: translate[1],
  14446. bottom: translate[1],
  14447. left: translate[0],
  14448. right: translate[0],
  14449. writingMode: writingMode,
  14450. iconsInText: false,
  14451. verticalizable: false
  14452. };
  14453. if (isEmpty(positionedLines)) {
  14454. return false;
  14455. }
  14456. return shaping;
  14457. };
  14458. // using computed properties due to https://github.com/facebook/flow/issues/380
  14459. /* eslint no-useless-computed-key: 0 */
  14460. var whitespace = {};
  14461. whitespace[0x09] = true;
  14462. whitespace[0x0a] = true;
  14463. whitespace[0x0b] = true;
  14464. whitespace[0x0c] = true;
  14465. whitespace[0x0d] = true;
  14466. whitespace[0x20] = true;
  14467. function determineLineBreaks(logicalInput, spacing, maxWidth, glyphMap, imagePositions, symbolPlacement, layoutTextSize) {
  14468. // if (symbolPlacement !== 'point') {
  14469. // return [];
  14470. // }
  14471. //
  14472. // if (!logicalInput) {
  14473. // return [];
  14474. // }
  14475. //
  14476. // var potentialLineBreaks = [];
  14477. // var targetWidth = determineAverageLineWidth(logicalInput, spacing, maxWidth, glyphMap, imagePositions, layoutTextSize);
  14478. //
  14479. // var hasServerSuggestedBreakpoints = logicalInput.text.indexOf("\u200b") >= 0;
  14480. //
  14481. // var currentX = 0;
  14482. //
  14483. // for (var i = 0; i < logicalInput.length(); i++) {
  14484. // var section = logicalInput.getSection(i);
  14485. // var codePoint = logicalInput.getCharCode(i);
  14486. // if (!whitespace[codePoint]) {
  14487. // currentX += getGlyphAdvance(codePoint, section, glyphMap, imagePositions, spacing, layoutTextSize);
  14488. // }
  14489. //
  14490. // // Ideographic characters, spaces, and word-breaking punctuation that often appear without
  14491. // // surrounding spaces.
  14492. // if ((i < logicalInput.length() - 1)) {
  14493. // var ideographicBreak = charAllowsIdeographicBreaking(codePoint);
  14494. // if (breakable[codePoint] || ideographicBreak || section.imageName) {
  14495. //
  14496. // potentialLineBreaks.push(
  14497. // evaluateBreak(
  14498. // i + 1,
  14499. // currentX,
  14500. // targetWidth,
  14501. // potentialLineBreaks,
  14502. // calculatePenalty(codePoint, logicalInput.getCharCode(i + 1), ideographicBreak && hasServerSuggestedBreakpoints),
  14503. // false));
  14504. // }
  14505. // }
  14506. // }
  14507. //
  14508. // return leastBadBreaks(
  14509. // evaluateBreak(
  14510. // logicalInput.length(),
  14511. // currentX,
  14512. // targetWidth,
  14513. // potentialLineBreaks,
  14514. // 0,
  14515. // true));
  14516. }
  14517. function getAnchorAlignment(anchor) {
  14518. var horizontalAlign = 0.5, verticalAlign = 0.5;
  14519. switch (anchor) {
  14520. case 'right':
  14521. case 'top-right':
  14522. case 'bottom-right':
  14523. horizontalAlign = 1;
  14524. break;
  14525. case 'left':
  14526. case 'top-left':
  14527. case 'bottom-left':
  14528. horizontalAlign = 0;
  14529. break;
  14530. }
  14531. switch (anchor) {
  14532. case 'bottom':
  14533. case 'bottom-right':
  14534. case 'bottom-left':
  14535. verticalAlign = 1;
  14536. break;
  14537. case 'top':
  14538. case 'top-right':
  14539. case 'top-left':
  14540. verticalAlign = 0;
  14541. break;
  14542. }
  14543. return {horizontalAlign: horizontalAlign, verticalAlign: verticalAlign};
  14544. }
  14545. Shaping.shapeIcon = function(image, iconOffset, iconAnchor){
  14546. var ref = getAnchorAlignment(iconAnchor);
  14547. var horizontalAlign = ref.horizontalAlign;
  14548. var verticalAlign = ref.verticalAlign;
  14549. var dx = iconOffset[0];
  14550. var dy = iconOffset[1];
  14551. var x1 = dx - image.displaySize[0] * horizontalAlign;
  14552. var x2 = x1 + image.displaySize[0];
  14553. var y1 = dy - image.displaySize[1] * verticalAlign;
  14554. var y2 = y1 + image.displaySize[1];
  14555. return {image: image, top: y1, bottom: y2, left: x1, right: x2};
  14556. };
  14557. Shaping.fitIconToText = function(shapedIcon, shapedText, textFit, padding, iconOffset, fontScale){
  14558. // assert_1(textFit !== 'none');
  14559. // assert_1(Array.isArray(padding) && padding.length === 4);
  14560. // assert_1(Array.isArray(iconOffset) && iconOffset.length === 2);
  14561. var image = shapedIcon.image;
  14562. var collisionPadding;
  14563. if (image.content) {
  14564. var content = image.content;
  14565. var pixelRatio = image.pixelRatio || 1;
  14566. collisionPadding = [
  14567. content[0] / pixelRatio,
  14568. content[1] / pixelRatio,
  14569. image.displaySize[0] - content[2] / pixelRatio,
  14570. image.displaySize[1] - content[3] / pixelRatio
  14571. ];
  14572. }
  14573. // We don't respect the icon-anchor, because icon-text-fit is set. Instead,
  14574. // the icon will be centered on the text, then stretched in the given
  14575. // dimensions.
  14576. var textLeft = shapedText.left * fontScale;
  14577. var textRight = shapedText.right * fontScale;
  14578. var top, right, bottom, left;
  14579. if (textFit === 'width' || textFit === 'both') {
  14580. // Stretched horizontally to the text width
  14581. left = iconOffset[0] + textLeft - padding[3];
  14582. right = iconOffset[0] + textRight + padding[1];
  14583. } else {
  14584. // Centered on the text
  14585. left = iconOffset[0] + (textLeft + textRight - image.displaySize[0]) / 2;
  14586. right = left + image.displaySize[0];
  14587. }
  14588. var textTop = shapedText.top * fontScale;
  14589. var textBottom = shapedText.bottom * fontScale;
  14590. if (textFit === 'height' || textFit === 'both') {
  14591. // Stretched vertically to the text height
  14592. top = iconOffset[1] + textTop - padding[0];
  14593. bottom = iconOffset[1] + textBottom + padding[2];
  14594. } else {
  14595. // Centered on the text
  14596. top = iconOffset[1] + (textTop + textBottom - image.displaySize[1]) / 2;
  14597. bottom = top + image.displaySize[1];
  14598. }
  14599. return {image: image, top: top, right: right, bottom: bottom, left: left, collisionPadding: collisionPadding};
  14600. };
  14601. var SIZE_PACK_FACTOR = 128;
  14602. // For {text,icon}-size, get the bucket-level data that will be needed by
  14603. // the painter to set symbol-size-related uniforms
  14604. function getSizeData(tileZoom, value) {
  14605. var expression = value.expression;
  14606. if (expression.kind === 'constant') {
  14607. var layoutSize = expression.evaluate(new EvaluationParameters$1(tileZoom + 1));
  14608. return {kind: 'constant', layoutSize: layoutSize};
  14609. } else if (expression.kind === 'source') {
  14610. return {kind: 'source'};
  14611. } else {
  14612. var zoomStops = expression.zoomStops;
  14613. var interpolationType = expression.interpolationType;
  14614. // calculate covering zoom stops for zoom-dependent values
  14615. var lower = 0;
  14616. while (lower < zoomStops.length && zoomStops[lower] <= tileZoom) {
  14617. lower++;
  14618. }
  14619. lower = Math.max(0, lower - 1);
  14620. var upper = lower;
  14621. while (upper < zoomStops.length && zoomStops[upper] < tileZoom + 1) {
  14622. upper++;
  14623. }
  14624. upper = Math.min(zoomStops.length - 1, upper);
  14625. var minZoom = zoomStops[lower];
  14626. var maxZoom = zoomStops[upper];
  14627. // We'd like to be able to use CameraExpression or CompositeExpression in these
  14628. // return types rather than ExpressionSpecification, but the former are not
  14629. // transferrable across Web Worker boundaries.
  14630. if (expression.kind === 'composite') {
  14631. return {kind: 'composite', minZoom: minZoom, maxZoom: maxZoom, interpolationType: interpolationType};
  14632. }
  14633. // for camera functions, also save off the function values
  14634. // evaluated at the covering zoom levels
  14635. var minSize = expression.evaluate(new EvaluationParameters$1(minZoom));
  14636. var maxSize = expression.evaluate(new EvaluationParameters$1(maxZoom));
  14637. return {kind: 'camera', minZoom: minZoom, maxZoom: maxZoom, minSize: minSize, maxSize: maxSize, interpolationType: interpolationType};
  14638. }
  14639. }
  14640. function evaluateSizeForFeature(sizeData, ref, ref$1) {
  14641. var uSize = ref.uSize;
  14642. var uSizeT = ref.uSizeT;
  14643. var lowerSize = ref$1.lowerSize;
  14644. var upperSize = ref$1.upperSize;
  14645. if (sizeData.kind === 'source') {
  14646. return lowerSize / SIZE_PACK_FACTOR;
  14647. } else if (sizeData.kind === 'composite') {
  14648. return number(lowerSize / SIZE_PACK_FACTOR, upperSize / SIZE_PACK_FACTOR, uSizeT);
  14649. }
  14650. return uSize;
  14651. }
  14652. function evaluateSizeForZoom(sizeData, zoom) {
  14653. var uSizeT = 0;
  14654. var uSize = 0;
  14655. if (sizeData.kind === 'constant') {
  14656. uSize = sizeData.layoutSize;
  14657. } else if (sizeData.kind !== 'source') {
  14658. var interpolationType = sizeData.interpolationType;
  14659. var minZoom = sizeData.minZoom;
  14660. var maxZoom = sizeData.maxZoom;
  14661. // Even though we could get the exact value of the camera function
  14662. // at z = tr.zoom, we intentionally do not: instead, we interpolate
  14663. // between the camera function values at a pair of zoom stops covering
  14664. // [tileZoom, tileZoom + 1] in order to be consistent with this
  14665. // restriction on composite functions
  14666. // var t = !interpolationType ? 0 : clamp(
  14667. // Interpolate.interpolationFactor(interpolationType, zoom, minZoom, maxZoom), 0, 1);
  14668. var t = 0;
  14669. if (sizeData.kind === 'camera') {
  14670. uSize = number(sizeData.minSize, sizeData.maxSize, t);
  14671. } else {
  14672. uSizeT = t;
  14673. }
  14674. }
  14675. return {uSizeT: uSizeT, uSize: uSize};
  14676. }
  14677. var symbolSize = /*#__PURE__*/Object.freeze({
  14678. __proto__: null,
  14679. getSizeData: getSizeData,
  14680. evaluateSizeForFeature: evaluateSizeForFeature,
  14681. evaluateSizeForZoom: evaluateSizeForZoom,
  14682. SIZE_PACK_FACTOR: SIZE_PACK_FACTOR
  14683. });
  14684. function transformText(text, layer, feature) {
  14685. var transform = layer.layout.get('text-transform').evaluate(feature, {});
  14686. if (transform === 'uppercase') {
  14687. text = text.toLocaleUpperCase();
  14688. } else if (transform === 'lowercase') {
  14689. text = text.toLocaleLowerCase();
  14690. }
  14691. // if (plugin.applyArabicShaping) {
  14692. // text = plugin.applyArabicShaping(text);
  14693. // }
  14694. return text;
  14695. }
  14696. function transformText$1(text, layer, feature) {
  14697. text.sections.forEach(function (section) {
  14698. section.text = transformText(section.text, layer, feature);
  14699. });
  14700. return text;
  14701. }
  14702. // The following table comes from <http://www.unicode.org/Public/12.0.0/ucd/Blocks.txt>.
  14703. // Keep it synchronized with <http://www.unicode.org/Public/UCD/latest/ucd/Blocks.txt>.
  14704. var unicodeBlockLookup = {
  14705. // 'Basic Latin': (char) => char >= 0x0000 && char <= 0x007F,
  14706. 'Latin-1 Supplement': function (char) {
  14707. return char >= 0x0080 && char <= 0x00FF;
  14708. },
  14709. // 'Latin Extended-A': (char) => char >= 0x0100 && char <= 0x017F,
  14710. // 'Latin Extended-B': (char) => char >= 0x0180 && char <= 0x024F,
  14711. // 'IPA Extensions': (char) => char >= 0x0250 && char <= 0x02AF,
  14712. // 'Spacing Modifier Letters': (char) => char >= 0x02B0 && char <= 0x02FF,
  14713. // 'Combining Diacritical Marks': (char) => char >= 0x0300 && char <= 0x036F,
  14714. // 'Greek and Coptic': (char) => char >= 0x0370 && char <= 0x03FF,
  14715. // 'Cyrillic': (char) => char >= 0x0400 && char <= 0x04FF,
  14716. // 'Cyrillic Supplement': (char) => char >= 0x0500 && char <= 0x052F,
  14717. // 'Armenian': (char) => char >= 0x0530 && char <= 0x058F,
  14718. //'Hebrew': (char) => char >= 0x0590 && char <= 0x05FF,
  14719. 'Arabic': function (char) {
  14720. return char >= 0x0600 && char <= 0x06FF;
  14721. },
  14722. //'Syriac': (char) => char >= 0x0700 && char <= 0x074F,
  14723. 'Arabic Supplement': function (char) {
  14724. return char >= 0x0750 && char <= 0x077F;
  14725. },
  14726. // 'Thaana': (char) => char >= 0x0780 && char <= 0x07BF,
  14727. // 'NKo': (char) => char >= 0x07C0 && char <= 0x07FF,
  14728. // 'Samaritan': (char) => char >= 0x0800 && char <= 0x083F,
  14729. // 'Mandaic': (char) => char >= 0x0840 && char <= 0x085F,
  14730. // 'Syriac Supplement': (char) => char >= 0x0860 && char <= 0x086F,
  14731. 'Arabic Extended-A': function (char) {
  14732. return char >= 0x08A0 && char <= 0x08FF;
  14733. },
  14734. // 'Devanagari': (char) => char >= 0x0900 && char <= 0x097F,
  14735. // 'Bengali': (char) => char >= 0x0980 && char <= 0x09FF,
  14736. // 'Gurmukhi': (char) => char >= 0x0A00 && char <= 0x0A7F,
  14737. // 'Gujarati': (char) => char >= 0x0A80 && char <= 0x0AFF,
  14738. // 'Oriya': (char) => char >= 0x0B00 && char <= 0x0B7F,
  14739. // 'Tamil': (char) => char >= 0x0B80 && char <= 0x0BFF,
  14740. // 'Telugu': (char) => char >= 0x0C00 && char <= 0x0C7F,
  14741. // 'Kannada': (char) => char >= 0x0C80 && char <= 0x0CFF,
  14742. // 'Malayalam': (char) => char >= 0x0D00 && char <= 0x0D7F,
  14743. // 'Sinhala': (char) => char >= 0x0D80 && char <= 0x0DFF,
  14744. // 'Thai': (char) => char >= 0x0E00 && char <= 0x0E7F,
  14745. // 'Lao': (char) => char >= 0x0E80 && char <= 0x0EFF,
  14746. // 'Tibetan': (char) => char >= 0x0F00 && char <= 0x0FFF,
  14747. // 'Myanmar': (char) => char >= 0x1000 && char <= 0x109F,
  14748. // 'Georgian': (char) => char >= 0x10A0 && char <= 0x10FF,
  14749. 'Hangul Jamo': function (char) {
  14750. return char >= 0x1100 && char <= 0x11FF;
  14751. },
  14752. // 'Ethiopic': (char) => char >= 0x1200 && char <= 0x137F,
  14753. // 'Ethiopic Supplement': (char) => char >= 0x1380 && char <= 0x139F,
  14754. // 'Cherokee': (char) => char >= 0x13A0 && char <= 0x13FF,
  14755. 'Unified Canadian Aboriginal Syllabics': function (char) {
  14756. return char >= 0x1400 && char <= 0x167F;
  14757. },
  14758. // 'Ogham': (char) => char >= 0x1680 && char <= 0x169F,
  14759. // 'Runic': (char) => char >= 0x16A0 && char <= 0x16FF,
  14760. // 'Tagalog': (char) => char >= 0x1700 && char <= 0x171F,
  14761. // 'Hanunoo': (char) => char >= 0x1720 && char <= 0x173F,
  14762. // 'Buhid': (char) => char >= 0x1740 && char <= 0x175F,
  14763. // 'Tagbanwa': (char) => char >= 0x1760 && char <= 0x177F,
  14764. 'Khmer': function (char) {
  14765. return char >= 0x1780 && char <= 0x17FF;
  14766. },
  14767. // 'Mongolian': (char) => char >= 0x1800 && char <= 0x18AF,
  14768. 'Unified Canadian Aboriginal Syllabics Extended': function (char) {
  14769. return char >= 0x18B0 && char <= 0x18FF;
  14770. },
  14771. // 'Limbu': (char) => char >= 0x1900 && char <= 0x194F,
  14772. // 'Tai Le': (char) => char >= 0x1950 && char <= 0x197F,
  14773. // 'New Tai Lue': (char) => char >= 0x1980 && char <= 0x19DF,
  14774. // 'Khmer Symbols': (char) => char >= 0x19E0 && char <= 0x19FF,
  14775. // 'Buginese': (char) => char >= 0x1A00 && char <= 0x1A1F,
  14776. // 'Tai Tham': (char) => char >= 0x1A20 && char <= 0x1AAF,
  14777. // 'Combining Diacritical Marks Extended': (char) => char >= 0x1AB0 && char <= 0x1AFF,
  14778. // 'Balinese': (char) => char >= 0x1B00 && char <= 0x1B7F,
  14779. // 'Sundanese': (char) => char >= 0x1B80 && char <= 0x1BBF,
  14780. // 'Batak': (char) => char >= 0x1BC0 && char <= 0x1BFF,
  14781. // 'Lepcha': (char) => char >= 0x1C00 && char <= 0x1C4F,
  14782. // 'Ol Chiki': (char) => char >= 0x1C50 && char <= 0x1C7F,
  14783. // 'Cyrillic Extended-C': (char) => char >= 0x1C80 && char <= 0x1C8F,
  14784. // 'Georgian Extended': (char) => char >= 0x1C90 && char <= 0x1CBF,
  14785. // 'Sundanese Supplement': (char) => char >= 0x1CC0 && char <= 0x1CCF,
  14786. // 'Vedic Extensions': (char) => char >= 0x1CD0 && char <= 0x1CFF,
  14787. // 'Phonetic Extensions': (char) => char >= 0x1D00 && char <= 0x1D7F,
  14788. // 'Phonetic Extensions Supplement': (char) => char >= 0x1D80 && char <= 0x1DBF,
  14789. // 'Combining Diacritical Marks Supplement': (char) => char >= 0x1DC0 && char <= 0x1DFF,
  14790. // 'Latin Extended Additional': (char) => char >= 0x1E00 && char <= 0x1EFF,
  14791. // 'Greek Extended': (char) => char >= 0x1F00 && char <= 0x1FFF,
  14792. 'General Punctuation': function (char) {
  14793. return char >= 0x2000 && char <= 0x206F;
  14794. },
  14795. // 'Superscripts and Subscripts': (char) => char >= 0x2070 && char <= 0x209F,
  14796. // 'Currency Symbols': (char) => char >= 0x20A0 && char <= 0x20CF,
  14797. // 'Combining Diacritical Marks for Symbols': (char) => char >= 0x20D0 && char <= 0x20FF,
  14798. 'Letterlike Symbols': function (char) {
  14799. return char >= 0x2100 && char <= 0x214F;
  14800. },
  14801. 'Number Forms': function (char) {
  14802. return char >= 0x2150 && char <= 0x218F;
  14803. },
  14804. // 'Arrows': (char) => char >= 0x2190 && char <= 0x21FF,
  14805. // 'Mathematical Operators': (char) => char >= 0x2200 && char <= 0x22FF,
  14806. 'Miscellaneous Technical': function (char) {
  14807. return char >= 0x2300 && char <= 0x23FF;
  14808. },
  14809. 'Control Pictures': function (char) {
  14810. return char >= 0x2400 && char <= 0x243F;
  14811. },
  14812. 'Optical Character Recognition': function (char) {
  14813. return char >= 0x2440 && char <= 0x245F;
  14814. },
  14815. 'Enclosed Alphanumerics': function (char) {
  14816. return char >= 0x2460 && char <= 0x24FF;
  14817. },
  14818. // 'Box Drawing': (char) => char >= 0x2500 && char <= 0x257F,
  14819. // 'Block Elements': (char) => char >= 0x2580 && char <= 0x259F,
  14820. 'Geometric Shapes': function (char) {
  14821. return char >= 0x25A0 && char <= 0x25FF;
  14822. },
  14823. 'Miscellaneous Symbols': function (char) {
  14824. return char >= 0x2600 && char <= 0x26FF;
  14825. },
  14826. // 'Dingbats': (char) => char >= 0x2700 && char <= 0x27BF,
  14827. // 'Miscellaneous Mathematical Symbols-A': (char) => char >= 0x27C0 && char <= 0x27EF,
  14828. // 'Supplemental Arrows-A': (char) => char >= 0x27F0 && char <= 0x27FF,
  14829. // 'Braille Patterns': (char) => char >= 0x2800 && char <= 0x28FF,
  14830. // 'Supplemental Arrows-B': (char) => char >= 0x2900 && char <= 0x297F,
  14831. // 'Miscellaneous Mathematical Symbols-B': (char) => char >= 0x2980 && char <= 0x29FF,
  14832. // 'Supplemental Mathematical Operators': (char) => char >= 0x2A00 && char <= 0x2AFF,
  14833. 'Miscellaneous Symbols and Arrows': function (char) {
  14834. return char >= 0x2B00 && char <= 0x2BFF;
  14835. },
  14836. // 'Glagolitic': (char) => char >= 0x2C00 && char <= 0x2C5F,
  14837. // 'Latin Extended-C': (char) => char >= 0x2C60 && char <= 0x2C7F,
  14838. // 'Coptic': (char) => char >= 0x2C80 && char <= 0x2CFF,
  14839. // 'Georgian Supplement': (char) => char >= 0x2D00 && char <= 0x2D2F,
  14840. // 'Tifinagh': (char) => char >= 0x2D30 && char <= 0x2D7F,
  14841. // 'Ethiopic Extended': (char) => char >= 0x2D80 && char <= 0x2DDF,
  14842. // 'Cyrillic Extended-A': (char) => char >= 0x2DE0 && char <= 0x2DFF,
  14843. // 'Supplemental Punctuation': (char) => char >= 0x2E00 && char <= 0x2E7F,
  14844. 'CJK Radicals Supplement': function (char) {
  14845. return char >= 0x2E80 && char <= 0x2EFF;
  14846. },
  14847. 'Kangxi Radicals': function (char) {
  14848. return char >= 0x2F00 && char <= 0x2FDF;
  14849. },
  14850. 'Ideographic Description Characters': function (char) {
  14851. return char >= 0x2FF0 && char <= 0x2FFF;
  14852. },
  14853. 'CJK Symbols and Punctuation': function (char) {
  14854. return char >= 0x3000 && char <= 0x303F;
  14855. },
  14856. 'Hiragana': function (char) {
  14857. return char >= 0x3040 && char <= 0x309F;
  14858. },
  14859. 'Katakana': function (char) {
  14860. return char >= 0x30A0 && char <= 0x30FF;
  14861. },
  14862. 'Bopomofo': function (char) {
  14863. return char >= 0x3100 && char <= 0x312F;
  14864. },
  14865. 'Hangul Compatibility Jamo': function (char) {
  14866. return char >= 0x3130 && char <= 0x318F;
  14867. },
  14868. 'Kanbun': function (char) {
  14869. return char >= 0x3190 && char <= 0x319F;
  14870. },
  14871. 'Bopomofo Extended': function (char) {
  14872. return char >= 0x31A0 && char <= 0x31BF;
  14873. },
  14874. 'CJK Strokes': function (char) {
  14875. return char >= 0x31C0 && char <= 0x31EF;
  14876. },
  14877. 'Katakana Phonetic Extensions': function (char) {
  14878. return char >= 0x31F0 && char <= 0x31FF;
  14879. },
  14880. 'Enclosed CJK Letters and Months': function (char) {
  14881. return char >= 0x3200 && char <= 0x32FF;
  14882. },
  14883. 'CJK Compatibility': function (char) {
  14884. return char >= 0x3300 && char <= 0x33FF;
  14885. },
  14886. 'CJK Unified Ideographs Extension A': function (char) {
  14887. return char >= 0x3400 && char <= 0x4DBF;
  14888. },
  14889. 'Yijing Hexagram Symbols': function (char) {
  14890. return char >= 0x4DC0 && char <= 0x4DFF;
  14891. },
  14892. 'CJK Unified Ideographs': function (char) {
  14893. return char >= 0x4E00 && char <= 0x9FFF;
  14894. },
  14895. 'Yi Syllables': function (char) {
  14896. return char >= 0xA000 && char <= 0xA48F;
  14897. },
  14898. 'Yi Radicals': function (char) {
  14899. return char >= 0xA490 && char <= 0xA4CF;
  14900. },
  14901. // 'Lisu': (char) => char >= 0xA4D0 && char <= 0xA4FF,
  14902. // 'Vai': (char) => char >= 0xA500 && char <= 0xA63F,
  14903. // 'Cyrillic Extended-B': (char) => char >= 0xA640 && char <= 0xA69F,
  14904. // 'Bamum': (char) => char >= 0xA6A0 && char <= 0xA6FF,
  14905. // 'Modifier Tone Letters': (char) => char >= 0xA700 && char <= 0xA71F,
  14906. // 'Latin Extended-D': (char) => char >= 0xA720 && char <= 0xA7FF,
  14907. // 'Syloti Nagri': (char) => char >= 0xA800 && char <= 0xA82F,
  14908. // 'Common Indic Number Forms': (char) => char >= 0xA830 && char <= 0xA83F,
  14909. // 'Phags-pa': (char) => char >= 0xA840 && char <= 0xA87F,
  14910. // 'Saurashtra': (char) => char >= 0xA880 && char <= 0xA8DF,
  14911. // 'Devanagari Extended': (char) => char >= 0xA8E0 && char <= 0xA8FF,
  14912. // 'Kayah Li': (char) => char >= 0xA900 && char <= 0xA92F,
  14913. // 'Rejang': (char) => char >= 0xA930 && char <= 0xA95F,
  14914. 'Hangul Jamo Extended-A': function (char) {
  14915. return char >= 0xA960 && char <= 0xA97F;
  14916. },
  14917. // 'Javanese': (char) => char >= 0xA980 && char <= 0xA9DF,
  14918. // 'Myanmar Extended-B': (char) => char >= 0xA9E0 && char <= 0xA9FF,
  14919. // 'Cham': (char) => char >= 0xAA00 && char <= 0xAA5F,
  14920. // 'Myanmar Extended-A': (char) => char >= 0xAA60 && char <= 0xAA7F,
  14921. // 'Tai Viet': (char) => char >= 0xAA80 && char <= 0xAADF,
  14922. // 'Meetei Mayek Extensions': (char) => char >= 0xAAE0 && char <= 0xAAFF,
  14923. // 'Ethiopic Extended-A': (char) => char >= 0xAB00 && char <= 0xAB2F,
  14924. // 'Latin Extended-E': (char) => char >= 0xAB30 && char <= 0xAB6F,
  14925. // 'Cherokee Supplement': (char) => char >= 0xAB70 && char <= 0xABBF,
  14926. // 'Meetei Mayek': (char) => char >= 0xABC0 && char <= 0xABFF,
  14927. 'Hangul Syllables': function (char) {
  14928. return char >= 0xAC00 && char <= 0xD7AF;
  14929. },
  14930. 'Hangul Jamo Extended-B': function (char) {
  14931. return char >= 0xD7B0 && char <= 0xD7FF;
  14932. },
  14933. // 'High Surrogates': (char) => char >= 0xD800 && char <= 0xDB7F,
  14934. // 'High Private Use Surrogates': (char) => char >= 0xDB80 && char <= 0xDBFF,
  14935. // 'Low Surrogates': (char) => char >= 0xDC00 && char <= 0xDFFF,
  14936. 'Private Use Area': function (char) {
  14937. return char >= 0xE000 && char <= 0xF8FF;
  14938. },
  14939. 'CJK Compatibility Ideographs': function (char) {
  14940. return char >= 0xF900 && char <= 0xFAFF;
  14941. },
  14942. // 'Alphabetic Presentation Forms': (char) => char >= 0xFB00 && char <= 0xFB4F,
  14943. 'Arabic Presentation Forms-A': function (char) {
  14944. return char >= 0xFB50 && char <= 0xFDFF;
  14945. },
  14946. // 'Variation Selectors': (char) => char >= 0xFE00 && char <= 0xFE0F,
  14947. 'Vertical Forms': function (char) {
  14948. return char >= 0xFE10 && char <= 0xFE1F;
  14949. },
  14950. // 'Combining Half Marks': (char) => char >= 0xFE20 && char <= 0xFE2F,
  14951. 'CJK Compatibility Forms': function (char) {
  14952. return char >= 0xFE30 && char <= 0xFE4F;
  14953. },
  14954. 'Small Form Variants': function (char) {
  14955. return char >= 0xFE50 && char <= 0xFE6F;
  14956. },
  14957. 'Arabic Presentation Forms-B': function (char) {
  14958. return char >= 0xFE70 && char <= 0xFEFF;
  14959. },
  14960. 'Halfwidth and Fullwidth Forms': function (char) {
  14961. return char >= 0xFF00 && char <= 0xFFEF;
  14962. }
  14963. // 'Specials': (char) => char >= 0xFFF0 && char <= 0xFFFF,
  14964. // 'Linear B Syllabary': (char) => char >= 0x10000 && char <= 0x1007F,
  14965. // 'Linear B Ideograms': (char) => char >= 0x10080 && char <= 0x100FF,
  14966. // 'Aegean Numbers': (char) => char >= 0x10100 && char <= 0x1013F,
  14967. // 'Ancient Greek Numbers': (char) => char >= 0x10140 && char <= 0x1018F,
  14968. // 'Ancient Symbols': (char) => char >= 0x10190 && char <= 0x101CF,
  14969. // 'Phaistos Disc': (char) => char >= 0x101D0 && char <= 0x101FF,
  14970. // 'Lycian': (char) => char >= 0x10280 && char <= 0x1029F,
  14971. // 'Carian': (char) => char >= 0x102A0 && char <= 0x102DF,
  14972. // 'Coptic Epact Numbers': (char) => char >= 0x102E0 && char <= 0x102FF,
  14973. // 'Old Italic': (char) => char >= 0x10300 && char <= 0x1032F,
  14974. // 'Gothic': (char) => char >= 0x10330 && char <= 0x1034F,
  14975. // 'Old Permic': (char) => char >= 0x10350 && char <= 0x1037F,
  14976. // 'Ugaritic': (char) => char >= 0x10380 && char <= 0x1039F,
  14977. // 'Old Persian': (char) => char >= 0x103A0 && char <= 0x103DF,
  14978. // 'Deseret': (char) => char >= 0x10400 && char <= 0x1044F,
  14979. // 'Shavian': (char) => char >= 0x10450 && char <= 0x1047F,
  14980. // 'Osmanya': (char) => char >= 0x10480 && char <= 0x104AF,
  14981. // 'Osage': (char) => char >= 0x104B0 && char <= 0x104FF,
  14982. // 'Elbasan': (char) => char >= 0x10500 && char <= 0x1052F,
  14983. // 'Caucasian Albanian': (char) => char >= 0x10530 && char <= 0x1056F,
  14984. // 'Linear A': (char) => char >= 0x10600 && char <= 0x1077F,
  14985. // 'Cypriot Syllabary': (char) => char >= 0x10800 && char <= 0x1083F,
  14986. // 'Imperial Aramaic': (char) => char >= 0x10840 && char <= 0x1085F,
  14987. // 'Palmyrene': (char) => char >= 0x10860 && char <= 0x1087F,
  14988. // 'Nabataean': (char) => char >= 0x10880 && char <= 0x108AF,
  14989. // 'Hatran': (char) => char >= 0x108E0 && char <= 0x108FF,
  14990. // 'Phoenician': (char) => char >= 0x10900 && char <= 0x1091F,
  14991. // 'Lydian': (char) => char >= 0x10920 && char <= 0x1093F,
  14992. // 'Meroitic Hieroglyphs': (char) => char >= 0x10980 && char <= 0x1099F,
  14993. // 'Meroitic Cursive': (char) => char >= 0x109A0 && char <= 0x109FF,
  14994. // 'Kharoshthi': (char) => char >= 0x10A00 && char <= 0x10A5F,
  14995. // 'Old South Arabian': (char) => char >= 0x10A60 && char <= 0x10A7F,
  14996. // 'Old North Arabian': (char) => char >= 0x10A80 && char <= 0x10A9F,
  14997. // 'Manichaean': (char) => char >= 0x10AC0 && char <= 0x10AFF,
  14998. // 'Avestan': (char) => char >= 0x10B00 && char <= 0x10B3F,
  14999. // 'Inscriptional Parthian': (char) => char >= 0x10B40 && char <= 0x10B5F,
  15000. // 'Inscriptional Pahlavi': (char) => char >= 0x10B60 && char <= 0x10B7F,
  15001. // 'Psalter Pahlavi': (char) => char >= 0x10B80 && char <= 0x10BAF,
  15002. // 'Old Turkic': (char) => char >= 0x10C00 && char <= 0x10C4F,
  15003. // 'Old Hungarian': (char) => char >= 0x10C80 && char <= 0x10CFF,
  15004. // 'Hanifi Rohingya': (char) => char >= 0x10D00 && char <= 0x10D3F,
  15005. // 'Rumi Numeral Symbols': (char) => char >= 0x10E60 && char <= 0x10E7F,
  15006. // 'Old Sogdian': (char) => char >= 0x10F00 && char <= 0x10F2F,
  15007. // 'Sogdian': (char) => char >= 0x10F30 && char <= 0x10F6F,
  15008. // 'Elymaic': (char) => char >= 0x10FE0 && char <= 0x10FFF,
  15009. // 'Brahmi': (char) => char >= 0x11000 && char <= 0x1107F,
  15010. // 'Kaithi': (char) => char >= 0x11080 && char <= 0x110CF,
  15011. // 'Sora Sompeng': (char) => char >= 0x110D0 && char <= 0x110FF,
  15012. // 'Chakma': (char) => char >= 0x11100 && char <= 0x1114F,
  15013. // 'Mahajani': (char) => char >= 0x11150 && char <= 0x1117F,
  15014. // 'Sharada': (char) => char >= 0x11180 && char <= 0x111DF,
  15015. // 'Sinhala Archaic Numbers': (char) => char >= 0x111E0 && char <= 0x111FF,
  15016. // 'Khojki': (char) => char >= 0x11200 && char <= 0x1124F,
  15017. // 'Multani': (char) => char >= 0x11280 && char <= 0x112AF,
  15018. // 'Khudawadi': (char) => char >= 0x112B0 && char <= 0x112FF,
  15019. // 'Grantha': (char) => char >= 0x11300 && char <= 0x1137F,
  15020. // 'Newa': (char) => char >= 0x11400 && char <= 0x1147F,
  15021. // 'Tirhuta': (char) => char >= 0x11480 && char <= 0x114DF,
  15022. // 'Siddham': (char) => char >= 0x11580 && char <= 0x115FF,
  15023. // 'Modi': (char) => char >= 0x11600 && char <= 0x1165F,
  15024. // 'Mongolian Supplement': (char) => char >= 0x11660 && char <= 0x1167F,
  15025. // 'Takri': (char) => char >= 0x11680 && char <= 0x116CF,
  15026. // 'Ahom': (char) => char >= 0x11700 && char <= 0x1173F,
  15027. // 'Dogra': (char) => char >= 0x11800 && char <= 0x1184F,
  15028. // 'Warang Citi': (char) => char >= 0x118A0 && char <= 0x118FF,
  15029. // 'Nandinagari': (char) => char >= 0x119A0 && char <= 0x119FF,
  15030. // 'Zanabazar Square': (char) => char >= 0x11A00 && char <= 0x11A4F,
  15031. // 'Soyombo': (char) => char >= 0x11A50 && char <= 0x11AAF,
  15032. // 'Pau Cin Hau': (char) => char >= 0x11AC0 && char <= 0x11AFF,
  15033. // 'Bhaiksuki': (char) => char >= 0x11C00 && char <= 0x11C6F,
  15034. // 'Marchen': (char) => char >= 0x11C70 && char <= 0x11CBF,
  15035. // 'Masaram Gondi': (char) => char >= 0x11D00 && char <= 0x11D5F,
  15036. // 'Gunjala Gondi': (char) => char >= 0x11D60 && char <= 0x11DAF,
  15037. // 'Makasar': (char) => char >= 0x11EE0 && char <= 0x11EFF,
  15038. // 'Tamil Supplement': (char) => char >= 0x11FC0 && char <= 0x11FFF,
  15039. // 'Cuneiform': (char) => char >= 0x12000 && char <= 0x123FF,
  15040. // 'Cuneiform Numbers and Punctuation': (char) => char >= 0x12400 && char <= 0x1247F,
  15041. // 'Early Dynastic Cuneiform': (char) => char >= 0x12480 && char <= 0x1254F,
  15042. // 'Egyptian Hieroglyphs': (char) => char >= 0x13000 && char <= 0x1342F,
  15043. // 'Egyptian Hieroglyph Format Controls': (char) => char >= 0x13430 && char <= 0x1343F,
  15044. // 'Anatolian Hieroglyphs': (char) => char >= 0x14400 && char <= 0x1467F,
  15045. // 'Bamum Supplement': (char) => char >= 0x16800 && char <= 0x16A3F,
  15046. // 'Mro': (char) => char >= 0x16A40 && char <= 0x16A6F,
  15047. // 'Bassa Vah': (char) => char >= 0x16AD0 && char <= 0x16AFF,
  15048. // 'Pahawh Hmong': (char) => char >= 0x16B00 && char <= 0x16B8F,
  15049. // 'Medefaidrin': (char) => char >= 0x16E40 && char <= 0x16E9F,
  15050. // 'Miao': (char) => char >= 0x16F00 && char <= 0x16F9F,
  15051. // 'Ideographic Symbols and Punctuation': (char) => char >= 0x16FE0 && char <= 0x16FFF,
  15052. // 'Tangut': (char) => char >= 0x17000 && char <= 0x187FF,
  15053. // 'Tangut Components': (char) => char >= 0x18800 && char <= 0x18AFF,
  15054. // 'Kana Supplement': (char) => char >= 0x1B000 && char <= 0x1B0FF,
  15055. // 'Kana Extended-A': (char) => char >= 0x1B100 && char <= 0x1B12F,
  15056. // 'Small Kana Extension': (char) => char >= 0x1B130 && char <= 0x1B16F,
  15057. // 'Nushu': (char) => char >= 0x1B170 && char <= 0x1B2FF,
  15058. // 'Duployan': (char) => char >= 0x1BC00 && char <= 0x1BC9F,
  15059. // 'Shorthand Format Controls': (char) => char >= 0x1BCA0 && char <= 0x1BCAF,
  15060. // 'Byzantine Musical Symbols': (char) => char >= 0x1D000 && char <= 0x1D0FF,
  15061. // 'Musical Symbols': (char) => char >= 0x1D100 && char <= 0x1D1FF,
  15062. // 'Ancient Greek Musical Notation': (char) => char >= 0x1D200 && char <= 0x1D24F,
  15063. // 'Mayan Numerals': (char) => char >= 0x1D2E0 && char <= 0x1D2FF,
  15064. // 'Tai Xuan Jing Symbols': (char) => char >= 0x1D300 && char <= 0x1D35F,
  15065. // 'Counting Rod Numerals': (char) => char >= 0x1D360 && char <= 0x1D37F,
  15066. // 'Mathematical Alphanumeric Symbols': (char) => char >= 0x1D400 && char <= 0x1D7FF,
  15067. // 'Sutton SignWriting': (char) => char >= 0x1D800 && char <= 0x1DAAF,
  15068. // 'Glagolitic Supplement': (char) => char >= 0x1E000 && char <= 0x1E02F,
  15069. // 'Nyiakeng Puachue Hmong': (char) => char >= 0x1E100 && char <= 0x1E14F,
  15070. // 'Wancho': (char) => char >= 0x1E2C0 && char <= 0x1E2FF,
  15071. // 'Mende Kikakui': (char) => char >= 0x1E800 && char <= 0x1E8DF,
  15072. // 'Adlam': (char) => char >= 0x1E900 && char <= 0x1E95F,
  15073. // 'Indic Siyaq Numbers': (char) => char >= 0x1EC70 && char <= 0x1ECBF,
  15074. // 'Ottoman Siyaq Numbers': (char) => char >= 0x1ED00 && char <= 0x1ED4F,
  15075. // 'Arabic Mathematical Alphabetic Symbols': (char) => char >= 0x1EE00 && char <= 0x1EEFF,
  15076. // 'Mahjong Tiles': (char) => char >= 0x1F000 && char <= 0x1F02F,
  15077. // 'Domino Tiles': (char) => char >= 0x1F030 && char <= 0x1F09F,
  15078. // 'Playing Cards': (char) => char >= 0x1F0A0 && char <= 0x1F0FF,
  15079. // 'Enclosed Alphanumeric Supplement': (char) => char >= 0x1F100 && char <= 0x1F1FF,
  15080. // 'Enclosed Ideographic Supplement': (char) => char >= 0x1F200 && char <= 0x1F2FF,
  15081. // 'Miscellaneous Symbols and Pictographs': (char) => char >= 0x1F300 && char <= 0x1F5FF,
  15082. // 'Emoticons': (char) => char >= 0x1F600 && char <= 0x1F64F,
  15083. // 'Ornamental Dingbats': (char) => char >= 0x1F650 && char <= 0x1F67F,
  15084. // 'Transport and Map Symbols': (char) => char >= 0x1F680 && char <= 0x1F6FF,
  15085. // 'Alchemical Symbols': (char) => char >= 0x1F700 && char <= 0x1F77F,
  15086. // 'Geometric Shapes Extended': (char) => char >= 0x1F780 && char <= 0x1F7FF,
  15087. // 'Supplemental Arrows-C': (char) => char >= 0x1F800 && char <= 0x1F8FF,
  15088. // 'Supplemental Symbols and Pictographs': (char) => char >= 0x1F900 && char <= 0x1F9FF,
  15089. // 'Chess Symbols': (char) => char >= 0x1FA00 && char <= 0x1FA6F,
  15090. // 'Symbols and Pictographs Extended-A': (char) => char >= 0x1FA70 && char <= 0x1FAFF,
  15091. // 'CJK Unified Ideographs Extension B': (char) => char >= 0x20000 && char <= 0x2A6DF,
  15092. // 'CJK Unified Ideographs Extension C': (char) => char >= 0x2A700 && char <= 0x2B73F,
  15093. // 'CJK Unified Ideographs Extension D': (char) => char >= 0x2B740 && char <= 0x2B81F,
  15094. // 'CJK Unified Ideographs Extension E': (char) => char >= 0x2B820 && char <= 0x2CEAF,
  15095. // 'CJK Unified Ideographs Extension F': (char) => char >= 0x2CEB0 && char <= 0x2EBEF,
  15096. // 'CJK Compatibility Ideographs Supplement': (char) => char >= 0x2F800 && char <= 0x2FA1F,
  15097. // 'Tags': (char) => char >= 0xE0000 && char <= 0xE007F,
  15098. // 'Variation Selectors Supplement': (char) => char >= 0xE0100 && char <= 0xE01EF,
  15099. // 'Supplementary Private Use Area-A': (char) => char >= 0xF0000 && char <= 0xFFFFF,
  15100. // 'Supplementary Private Use Area-B': (char) => char >= 0x100000 && char <= 0x10FFFF,
  15101. };
  15102. var ScriptDetection = function ScriptDetection() {
  15103. };
  15104. ScriptDetection.allowsVerticalWritingMode = function(chars){
  15105. for (var i = 0, list = chars; i < list.length; i += 1) {
  15106. var char = list[i];
  15107. if (charHasUprightVerticalOrientation(char.charCodeAt(0))) {
  15108. return true;
  15109. }
  15110. }
  15111. return false;
  15112. };
  15113. ScriptDetection.allowsLetterSpacing = function(chars){
  15114. for (var i = 0, list = chars; i < list.length; i += 1) {
  15115. var char = list[i];
  15116. if (!charAllowsLetterSpacing(char.charCodeAt(0))) {
  15117. return false;
  15118. }
  15119. }
  15120. return true;
  15121. };
  15122. function charAllowsLetterSpacing(char) {
  15123. if (unicodeBlockLookup['Arabic'](char)) {
  15124. return false;
  15125. }
  15126. if (unicodeBlockLookup['Arabic Supplement'](char)) {
  15127. return false;
  15128. }
  15129. if (unicodeBlockLookup['Arabic Extended-A'](char)) {
  15130. return false;
  15131. }
  15132. if (unicodeBlockLookup['Arabic Presentation Forms-A'](char)) {
  15133. return false;
  15134. }
  15135. if (unicodeBlockLookup['Arabic Presentation Forms-B'](char)) {
  15136. return false;
  15137. }
  15138. return true;
  15139. }
  15140. // The following logic comes from
  15141. // <http://www.unicode.org/Public/12.0.0/ucd/VerticalOrientation.txt>.
  15142. // Keep it synchronized with
  15143. // <http://www.unicode.org/Public/UCD/latest/ucd/VerticalOrientation.txt>.
  15144. // The data file denotes with “U” or “Tu” any codepoint that may be drawn
  15145. // upright in vertical text but does not distinguish between upright and
  15146. // “neutral” characters.
  15147. // Blocks in the Unicode supplementary planes are excluded from this module due
  15148. // to <https://github.com/mapbox/mapbox-gl/issues/29>.
  15149. /**
  15150. * Returns true if the given Unicode codepoint identifies a character with
  15151. * upright orientation.
  15152. *
  15153. * A character has upright orientation if it is drawn upright (unrotated)
  15154. * whether the line is oriented horizontally or vertically, even if both
  15155. * adjacent characters can be rotated. For example, a Chinese character is
  15156. * always drawn upright. An uprightly oriented character causes an adjacent
  15157. * “neutral” character to be drawn upright as well.
  15158. * @private
  15159. */
  15160. function charHasUprightVerticalOrientation(char) {
  15161. if (char === 0x02EA /* modifier letter yin departing tone mark */ ||
  15162. char === 0x02EB /* modifier letter yang departing tone mark */) {
  15163. return true;
  15164. }
  15165. // Return early for characters outside all ranges whose characters remain
  15166. // upright in vertical writing mode.
  15167. if (char < 0x1100) {
  15168. return false;
  15169. }
  15170. if (unicodeBlockLookup['Bopomofo Extended'](char)) {
  15171. return true;
  15172. }
  15173. if (unicodeBlockLookup['Bopomofo'](char)) {
  15174. return true;
  15175. }
  15176. if (unicodeBlockLookup['CJK Compatibility Forms'](char)) {
  15177. if (!((char >= 0xFE49 /* dashed overline */ && char <= 0xFE4F) /* wavy low line */)) {
  15178. return true;
  15179. }
  15180. }
  15181. if (unicodeBlockLookup['CJK Compatibility Ideographs'](char)) {
  15182. return true;
  15183. }
  15184. if (unicodeBlockLookup['CJK Compatibility'](char)) {
  15185. return true;
  15186. }
  15187. if (unicodeBlockLookup['CJK Radicals Supplement'](char)) {
  15188. return true;
  15189. }
  15190. if (unicodeBlockLookup['CJK Strokes'](char)) {
  15191. return true;
  15192. }
  15193. if (unicodeBlockLookup['CJK Symbols and Punctuation'](char)) {
  15194. if (!((char >= 0x3008 /* left angle bracket */ && char <= 0x3011) /* right black lenticular bracket */) && !((char >= 0x3014 /* left tortoise shell bracket */ && char <= 0x301F) /* low double prime quotation mark */) &&
  15195. char !== 0x3030 /* wavy dash */) {
  15196. return true;
  15197. }
  15198. }
  15199. if (unicodeBlockLookup['CJK Unified Ideographs Extension A'](char)) {
  15200. return true;
  15201. }
  15202. if (unicodeBlockLookup['CJK Unified Ideographs'](char)) {
  15203. return true;
  15204. }
  15205. if (unicodeBlockLookup['Enclosed CJK Letters and Months'](char)) {
  15206. return true;
  15207. }
  15208. if (unicodeBlockLookup['Hangul Compatibility Jamo'](char)) {
  15209. return true;
  15210. }
  15211. if (unicodeBlockLookup['Hangul Jamo Extended-A'](char)) {
  15212. return true;
  15213. }
  15214. if (unicodeBlockLookup['Hangul Jamo Extended-B'](char)) {
  15215. return true;
  15216. }
  15217. if (unicodeBlockLookup['Hangul Jamo'](char)) {
  15218. return true;
  15219. }
  15220. if (unicodeBlockLookup['Hangul Syllables'](char)) {
  15221. return true;
  15222. }
  15223. if (unicodeBlockLookup['Hiragana'](char)) {
  15224. return true;
  15225. }
  15226. if (unicodeBlockLookup['Ideographic Description Characters'](char)) {
  15227. return true;
  15228. }
  15229. if (unicodeBlockLookup['Kanbun'](char)) {
  15230. return true;
  15231. }
  15232. if (unicodeBlockLookup['Kangxi Radicals'](char)) {
  15233. return true;
  15234. }
  15235. if (unicodeBlockLookup['Katakana Phonetic Extensions'](char)) {
  15236. return true;
  15237. }
  15238. if (unicodeBlockLookup['Katakana'](char)) {
  15239. if (char !== 0x30FC /* katakana-hiragana prolonged sound mark */) {
  15240. return true;
  15241. }
  15242. }
  15243. if (unicodeBlockLookup['Halfwidth and Fullwidth Forms'](char)) {
  15244. if (char !== 0xFF08 /* fullwidth left parenthesis */ &&
  15245. char !== 0xFF09 /* fullwidth right parenthesis */ &&
  15246. char !== 0xFF0D /* fullwidth hyphen-minus */ && !((char >= 0xFF1A /* fullwidth colon */ && char <= 0xFF1E) /* fullwidth greater-than sign */) &&
  15247. char !== 0xFF3B /* fullwidth left square bracket */ &&
  15248. char !== 0xFF3D /* fullwidth right square bracket */ &&
  15249. char !== 0xFF3F /* fullwidth low line */ && !(char >= 0xFF5B /* fullwidth left curly bracket */ && char <= 0xFFDF) &&
  15250. char !== 0xFFE3 /* fullwidth macron */ && !(char >= 0xFFE8 /* halfwidth forms light vertical */ && char <= 0xFFEF)) {
  15251. return true;
  15252. }
  15253. }
  15254. if (unicodeBlockLookup['Small Form Variants'](char)) {
  15255. if (!((char >= 0xFE58 /* small em dash */ && char <= 0xFE5E) /* small right tortoise shell bracket */) && !((char >= 0xFE63 /* small hyphen-minus */ && char <= 0xFE66) /* small equals sign */)) {
  15256. return true;
  15257. }
  15258. }
  15259. if (unicodeBlockLookup['Unified Canadian Aboriginal Syllabics'](char)) {
  15260. return true;
  15261. }
  15262. if (unicodeBlockLookup['Unified Canadian Aboriginal Syllabics Extended'](char)) {
  15263. return true;
  15264. }
  15265. if (unicodeBlockLookup['Vertical Forms'](char)) {
  15266. return true;
  15267. }
  15268. if (unicodeBlockLookup['Yijing Hexagram Symbols'](char)) {
  15269. return true;
  15270. }
  15271. if (unicodeBlockLookup['Yi Syllables'](char)) {
  15272. return true;
  15273. }
  15274. if (unicodeBlockLookup['Yi Radicals'](char)) {
  15275. return true;
  15276. }
  15277. return false;
  15278. }
  15279. function charInRTLScript(char) {
  15280. // Main blocks for Hebrew, Arabic, Thaana and other RTL scripts
  15281. return (char >= 0x0590 && char <= 0x08FF) ||
  15282. unicodeBlockLookup['Arabic Presentation Forms-A'](char) ||
  15283. unicodeBlockLookup['Arabic Presentation Forms-B'](char);
  15284. }
  15285. ScriptDetection.stringContainsRTLText = function(chars){
  15286. for (var i = 0, list = chars; i < list.length; i += 1) {
  15287. var char = list[i];
  15288. if (charInRTLScript(char.charCodeAt(0))) {
  15289. return true;
  15290. }
  15291. }
  15292. return false;
  15293. };
  15294. var vectorTileFeatureTypes$2 = ['Unknown', 'Point', 'LineString', 'Polygon'];
  15295. // Opacity arrays are frequently updated but don't contain a lot of information, so we pack them
  15296. // tight. Each Uint32 is actually four duplicate Uint8s for the four corners of a glyph
  15297. // 7 bits are for the current opacity, and the lowest bit is the target opacity
  15298. // actually defined in symbol_attributes.js
  15299. // const placementOpacityAttributes = [
  15300. // { name: 'a_fade_opacity', components: 1, type: 'Uint32' }
  15301. // ];
  15302. var shaderOpacityAttributes = [
  15303. {name: 'a_fade_opacity', components: 1, type: 'Uint8', offset: 0}
  15304. ];
  15305. function addVertex$1(array, anchorX, anchorY, ox, oy, tx, ty, sizeVertex, isSDF, pixelOffsetX, pixelOffsetY, minFontScaleX, minFontScaleY) {
  15306. var aSizeX = sizeVertex ? Math.min(MAX_PACKED_SIZE, Math.round(sizeVertex[0])) : 0;
  15307. var aSizeY = sizeVertex ? Math.min(MAX_PACKED_SIZE, Math.round(sizeVertex[1])) : 0;
  15308. array.emplaceBack(
  15309. // a_pos_offset
  15310. anchorX,
  15311. anchorY,
  15312. Math.round(ox * 32),
  15313. Math.round(oy * 32),
  15314. // a_data
  15315. tx, // x coordinate of symbol on glyph atlas texture
  15316. ty, // y coordinate of symbol on glyph atlas texture
  15317. (aSizeX << 1) + (isSDF ? 1 : 0),
  15318. aSizeY,
  15319. pixelOffsetX * 16,
  15320. pixelOffsetY * 16,
  15321. minFontScaleX * 256,
  15322. minFontScaleY * 256
  15323. );
  15324. }
  15325. function addDynamicAttributes(dynamicLayoutVertexArray, p, angle) {
  15326. dynamicLayoutVertexArray.emplaceBack(p.x, p.y, angle);
  15327. dynamicLayoutVertexArray.emplaceBack(p.x, p.y, angle);
  15328. dynamicLayoutVertexArray.emplaceBack(p.x, p.y, angle);
  15329. dynamicLayoutVertexArray.emplaceBack(p.x, p.y, angle);
  15330. }
  15331. function containsRTLText(formattedText) {
  15332. for (var i = 0, list = formattedText.sections; i < list.length; i += 1) {
  15333. var section = list[i];
  15334. if (ScriptDetection.stringContainsRTLText(section.text)) {
  15335. return true;
  15336. }
  15337. }
  15338. return false;
  15339. }
  15340. var SymbolBuffers = function SymbolBuffers(programConfigurations) {
  15341. this.layoutVertexArray = new StructArrayLayout4i4ui4i24();
  15342. this.indexArray = new StructArrayLayout3ui6();
  15343. this.programConfigurations = programConfigurations;
  15344. this.segments = new SegmentVector();
  15345. this.dynamicLayoutVertexArray = new StructArrayLayout3f12();
  15346. this.opacityVertexArray = new StructArrayLayout1ul4();
  15347. this.placedSymbolArray = new PlacedSymbolArray();
  15348. };
  15349. SymbolBuffers.prototype.upload = function upload(context, dynamicIndexBuffer, upload$1, update) {
  15350. if (upload$1) {
  15351. this.layoutVertexBuffer = context.createVertexBuffer(this.layoutVertexArray, SymbolAttributes.symbolLayoutAttributes.members);
  15352. this.indexBuffer = context.createIndexBuffer(this.indexArray, dynamicIndexBuffer);
  15353. this.dynamicLayoutVertexBuffer = context.createVertexBuffer(this.dynamicLayoutVertexArray, SymbolAttributes.dynamicLayoutAttributes.members, true);
  15354. this.opacityVertexBuffer = context.createVertexBuffer(this.opacityVertexArray, shaderOpacityAttributes, true);
  15355. // This is a performance hack so that we can write to opacityVertexArray with uint32s
  15356. // even though the shaders read uint8s
  15357. this.opacityVertexBuffer.itemSize = 1;
  15358. }
  15359. if (upload$1 || update) {
  15360. this.programConfigurations.upload(context);
  15361. }
  15362. };
  15363. SymbolBuffers.prototype.destroy = function destroy() {
  15364. if (!this.layoutVertexBuffer) {
  15365. return;
  15366. }
  15367. this.layoutVertexBuffer.destroy();
  15368. this.indexBuffer.destroy();
  15369. this.programConfigurations.destroy();
  15370. this.segments.destroy();
  15371. this.dynamicLayoutVertexBuffer.destroy();
  15372. this.opacityVertexBuffer.destroy();
  15373. };
  15374. SymbolBuffers.prototype.clear = function clear() {
  15375. };
  15376. WebWorkerTransfer.register('SymbolBuffers', SymbolBuffers);
  15377. var CollisionBuffers = function CollisionBuffers(LayoutArray, layoutAttributes, IndexArray) {
  15378. this.layoutVertexArray = new LayoutArray();
  15379. this.layoutAttributes = layoutAttributes;
  15380. this.indexArray = new IndexArray();
  15381. this.segments = new SegmentVector();
  15382. this.collisionVertexArray = new StructArrayLayout2ub2f12();
  15383. };
  15384. CollisionBuffers.prototype.upload = function upload(context) {
  15385. this.layoutVertexBuffer = context.createVertexBuffer(this.layoutVertexArray, this.layoutAttributes);
  15386. this.indexBuffer = context.createIndexBuffer(this.indexArray);
  15387. this.collisionVertexBuffer = context.createVertexBuffer(this.collisionVertexArray, collisionVertexAttributes.members, true);
  15388. };
  15389. CollisionBuffers.prototype.destroy = function destroy() {
  15390. if (!this.layoutVertexBuffer) {
  15391. return;
  15392. }
  15393. this.layoutVertexBuffer.destroy();
  15394. this.indexBuffer.destroy();
  15395. this.segments.destroy();
  15396. this.collisionVertexBuffer.destroy();
  15397. };
  15398. WebWorkerTransfer.register('CollisionBuffers', CollisionBuffers);
  15399. /**
  15400. * Unlike other buckets, which simply implement #addFeature with type-specific
  15401. * logic for (essentially) triangulating feature geometries, SymbolBucket
  15402. * requires specialized behavior:
  15403. *
  15404. * 1. WorkerTile#parse(), the logical owner of the bucket creation process,
  15405. * calls SymbolBucket#populate(), which resolves text and icon tokens on
  15406. * each feature, adds each glyphs and symbols needed to the passed-in
  15407. * collections options.glyphDependencies and options.iconDependencies, and
  15408. * stores the feature data for use in subsequent step (this.features).
  15409. *
  15410. * 2. WorkerTile asynchronously requests from the main thread all of the glyphs
  15411. * and icons needed (by this bucket and any others). When glyphs and icons
  15412. * have been received, the WorkerTile creates a CollisionIndex and invokes:
  15413. *
  15414. * 3. performSymbolLayout(bucket, stacks, icons) perform texts shaping and
  15415. * layout on a Symbol Bucket. This step populates:
  15416. * `this.symbolInstances`: metadata on generated symbols
  15417. * `this.collisionBoxArray`: collision data for use by foreground
  15418. * `this.text`: SymbolBuffers for text symbols
  15419. * `this.icons`: SymbolBuffers for icons
  15420. * `this.iconCollisionBox`: Debug SymbolBuffers for icon collision boxes
  15421. * `this.textCollisionBox`: Debug SymbolBuffers for text collision boxes
  15422. * `this.iconCollisionCircle`: Debug SymbolBuffers for icon collision circles
  15423. * `this.textCollisionCircle`: Debug SymbolBuffers for text collision circles
  15424. * The results are sent to the foreground for rendering
  15425. *
  15426. * 4. performSymbolPlacement(bucket, collisionIndex) is run on the foreground,
  15427. * and uses the CollisionIndex along with current camera settings to determine
  15428. * which symbols can actually show on the map. Collided symbols are hidden
  15429. * using a dynamic "OpacityVertexArray".
  15430. *
  15431. * @private
  15432. */
  15433. var SymbolBucket = function SymbolBucket(options) {
  15434. this.collisionBoxArray = options.collisionBoxArray;
  15435. this.zoom = options.zoom;
  15436. this.overscaling = options.overscaling;
  15437. this.layers = options.layers;
  15438. this.layerIds = this.layers.map(function (layer) {
  15439. return layer.id;
  15440. });
  15441. this.index = options.index;
  15442. this.pixelRatio = options.pixelRatio;
  15443. this.sourceLayerIndex = options.sourceLayerIndex;
  15444. this.hasPattern = false;
  15445. this.hasPaintOverrides = false;
  15446. this.hasRTLText = false;
  15447. var layer = this.layers[0];
  15448. var unevaluatedLayoutValues = layer._unevaluatedLayout._values;
  15449. this.textSizeData = symbolSize.getSizeData(this.zoom, unevaluatedLayoutValues['text-size']);
  15450. this.iconSizeData = symbolSize.getSizeData(this.zoom, unevaluatedLayoutValues['icon-size']);
  15451. var layout = this.layers[0].layout;
  15452. var sortKey = layout.get('symbol-sort-key');
  15453. var zOrder = layout.get('symbol-z-order');
  15454. this.sortFeaturesByKey = zOrder !== 'viewport-y' && sortKey.constantOr(1) !== undefined;
  15455. var zOrderByViewportY = zOrder === 'viewport-y' || (zOrder === 'auto' && !this.sortFeaturesByKey);
  15456. this.sortFeaturesByY = zOrderByViewportY && (layout.get('text-allow-overlap') || layout.get('icon-allow-overlap') ||
  15457. layout.get('text-ignore-placement') || layout.get('icon-ignore-placement'));
  15458. if (layout.get('symbol-placement') === 'point') {
  15459. this.writingModes = layout.get('text-writing-mode').map(function (wm) {
  15460. return Shaping.WritingMode[wm];
  15461. });
  15462. }
  15463. this.stateDependentLayerIds = this.layers.filter(function (l) {
  15464. return l.isStateDependent();
  15465. }).map(function (l) {
  15466. return l.id;
  15467. });
  15468. this.sourceID = options.sourceID;
  15469. };
  15470. SymbolBucket.prototype.createArrays = function createArrays() {
  15471. // var layout = this.layers[0].layout;
  15472. // //this.hasPaintOverrides = SymbolStyleLayer.hasPaintOverrides(layout);
  15473. // this.hasPaintOverrides = false;
  15474. //
  15475. // this.text = new SymbolBuffers(new ProgramConfigurationSet(SymbolAttributes.symbolLayoutAttributes.members, this.layers, this.zoom, function (property) {
  15476. // return /^text/.test(property);
  15477. // }));
  15478. // this.icon = new SymbolBuffers(new ProgramConfigurationSet(SymbolAttributes.symbolLayoutAttributes.members, this.layers, this.zoom, function (property) {
  15479. // return /^icon/.test(property);
  15480. // }));
  15481. //
  15482. // this.textCollisionBox = new CollisionBuffers(StructArrayLayout2i2i2i12, SymbolAttributes.collisionBoxLayout.members, StructArrayLayout2ui4);
  15483. // this.iconCollisionBox = new CollisionBuffers(StructArrayLayout2i2i2i12, SymbolAttributes.collisionBoxLayout.members, StructArrayLayout2ui4);
  15484. // this.textCollisionCircle = new CollisionBuffers(StructArrayLayout2i2i2i12, SymbolAttributes.collisionCircleLayout.members, StructArrayLayout3ui6);
  15485. // this.iconCollisionCircle = new CollisionBuffers(StructArrayLayout2i2i2i12, SymbolAttributes.collisionCircleLayout.members, StructArrayLayout3ui6);
  15486. //
  15487. // this.glyphOffsetArray = new GlyphOffsetArray();
  15488. // this.lineVertexArray = new SymbolLineVertexArray();
  15489. // this.symbolInstances = new SymbolInstanceArray();
  15490. };
  15491. SymbolBucket.prototype.calculateGlyphDependencies = function calculateGlyphDependencies(text, stack, textAlongLine, allowVerticalPlacement, doesAllowVerticalWritingMode) {
  15492. for (var i = 0; i < text.length; i++) {
  15493. stack[text.charCodeAt(i)] = true;
  15494. }
  15495. };
  15496. SymbolBucket.prototype.populate = function populate(features, options) {
  15497. var layer = this.layers[0];
  15498. var layout = layer.layout;
  15499. var textFont = layout.get('text-font');
  15500. var textField = layout.get('text-field');
  15501. var iconImage = layout.get('icon-image');
  15502. var hasText =
  15503. (textField.value.kind !== 'constant' ||
  15504. (textField.value.value instanceof Formatted$1 && !textField.value.value.isEmpty()) ||
  15505. textField.value.value.toString().length > 0) &&
  15506. (textFont.value.kind !== 'constant' || textFont.value.value.length > 0);
  15507. // we should always resolve the icon-image value if the property was defined in the style
  15508. // this allows us to fire the styleimagemissing event if image evaluation returns null
  15509. // the only way to distinguish between null returned from a coalesce statement with no valid images
  15510. // and null returned because icon-image wasn't defined is to check whether or not iconImage.parameters is an empty object
  15511. var hasIcon = (iconImage.value.kind !== 'constant' || !!iconImage.value.value) && Object.keys(iconImage.parameters).length > 0;
  15512. var symbolSortKey = layout.get('symbol-sort-key');
  15513. this.features = [];
  15514. if (!hasText && !hasIcon) {
  15515. return;
  15516. }
  15517. var icons = options.iconDependencies;
  15518. var stacks = options.glyphDependencies;
  15519. var availableImages = options.availableImages;
  15520. var globalProperties = new EvaluationParameters$1(this.zoom);
  15521. for (var i$1 = 0, list$1 = features; i$1 < list$1.length; i$1 += 1) {
  15522. var ref = list$1[i$1];
  15523. var feature = ref.feature;
  15524. var index = ref.index;
  15525. var sourceLayerIndex = ref.sourceLayerIndex;
  15526. if (!layer._featureFilter(globalProperties, feature)) {
  15527. continue;
  15528. }
  15529. var text = (void 0);
  15530. if (hasText) {
  15531. // Expression evaluation will automatically coerce to Formatted
  15532. // but plain string token evaluation skips that pathway so do the
  15533. // conversion here.
  15534. var resolvedTokens = layer.getValueAndResolveTokens('text-field', feature, availableImages);
  15535. var formattedText = Formatted$1.factory(resolvedTokens);
  15536. if (containsRTLText(formattedText)) {
  15537. this.hasRTLText = true;
  15538. }
  15539. if (
  15540. !this.hasRTLText || // non-rtl text so can proceed safely
  15541. getRTLTextPluginStatus() === 'unavailable' || // We don't intend to lazy-load the rtl text plugin, so proceed with incorrect shaping
  15542. this.hasRTLText && plugin.isParsed() // Use the rtlText plugin to shape text
  15543. ) {
  15544. text = transformText$1(formattedText, layer, feature);
  15545. }
  15546. }
  15547. var icon = (void 0);
  15548. if (hasIcon) {
  15549. // Expression evaluation will automatically coerce to Image
  15550. // but plain string token evaluation skips that pathway so do the
  15551. // conversion here.
  15552. var resolvedTokens$1 = layer.getValueAndResolveTokens('icon-image', feature, availableImages);
  15553. if (resolvedTokens$1 instanceof ResolvedImage$1) {
  15554. icon = resolvedTokens$1;
  15555. } else {
  15556. icon = ResolvedImage$1.fromString(resolvedTokens$1);
  15557. }
  15558. }
  15559. if (!text && !icon) {
  15560. continue;
  15561. }
  15562. var sortKey = this.sortFeaturesByKey ?
  15563. symbolSortKey.evaluate(feature, {}) :
  15564. undefined;
  15565. var symbolFeature = {
  15566. text: text,
  15567. icon: icon,
  15568. index: index,
  15569. sourceLayerIndex: sourceLayerIndex,
  15570. geometry: loadGeometry(feature),
  15571. properties: feature.properties,
  15572. type: vectorTileFeatureTypes$2[feature.type],
  15573. sortKey: sortKey
  15574. };
  15575. if (typeof feature.id !== 'undefined') {
  15576. symbolFeature.id = feature.id;
  15577. }
  15578. this.features.push(symbolFeature);
  15579. if (icon) {
  15580. icons[icon.name] = true;
  15581. }
  15582. if (text) {
  15583. var fontStack = textFont.evaluate(feature, {}).join(',');
  15584. var textAlongLine = layout.get('text-rotation-alignment') === 'map' && layout.get('symbol-placement') !== 'point';
  15585. this.allowVerticalPlacement = this.writingModes && this.writingModes.indexOf(Shaping.WritingMode.vertical) >= 0;
  15586. for (var i = 0, list = text.sections; i < list.length; i += 1) {
  15587. var section = list[i];
  15588. if (!section.image) {
  15589. var doesAllowVerticalWritingMode = ScriptDetection.allowsVerticalWritingMode(text.toString());
  15590. var sectionFont = section.fontStack || fontStack;
  15591. var sectionStack = stacks[sectionFont] = stacks[sectionFont] || {};
  15592. this.calculateGlyphDependencies(section.text, sectionStack, textAlongLine, this.allowVerticalPlacement, doesAllowVerticalWritingMode);
  15593. } else {
  15594. // Add section image to the list of dependencies.
  15595. icons[section.image.name] = true;
  15596. }
  15597. }
  15598. }
  15599. }
  15600. if (layout.get('symbol-placement') === 'line') {
  15601. // Merge adjacent lines with the same text to improve labelling.
  15602. // It's better to place labels on one long line than on many short segments.
  15603. this.features = mergeLines(this.features);
  15604. }
  15605. if (this.sortFeaturesByKey) {
  15606. this.features.sort(function (a, b) {
  15607. // a.sortKey is always a number when sortFeaturesByKey is true
  15608. return ((a.sortKey ) ) - ((b.sortKey ) );
  15609. });
  15610. }
  15611. };
  15612. SymbolBucket.prototype.update = function update(states, vtLayer, imagePositions) {
  15613. if (!this.stateDependentLayers.length) {
  15614. return;
  15615. }
  15616. this.text.programConfigurations.updatePaintArrays(states, vtLayer, this.layers, imagePositions);
  15617. this.icon.programConfigurations.updatePaintArrays(states, vtLayer, this.layers, imagePositions);
  15618. };
  15619. SymbolBucket.prototype.isEmpty = function isEmpty() {
  15620. // When the bucket encounters only rtl-text but the plugin isnt loaded, no symbol instances will be created.
  15621. // In order for the bucket to be serialized, and not discarded as an empty bucket both checks are necessary.
  15622. return this.symbolInstances.length === 0 && !this.hasRTLText;
  15623. };
  15624. SymbolBucket.prototype.uploadPending = function uploadPending() {
  15625. return !this.uploaded || this.text.programConfigurations.needsUpload || this.icon.programConfigurations.needsUpload;
  15626. };
  15627. SymbolBucket.prototype.upload = function upload(context) {
  15628. // if (!this.uploaded) {
  15629. // this.textCollisionBox.upload(context);
  15630. // this.iconCollisionBox.upload(context);
  15631. // this.textCollisionCircle.upload(context);
  15632. // this.iconCollisionCircle.upload(context);
  15633. // }
  15634. // this.text.upload(context, this.sortFeaturesByY, !this.uploaded, this.text.programConfigurations.needsUpload);
  15635. // this.icon.upload(context, this.sortFeaturesByY, !this.uploaded, this.icon.programConfigurations.needsUpload);
  15636. // this.uploaded = true;
  15637. };
  15638. SymbolBucket.prototype.destroy = function destroy() {
  15639. // this.text.destroy();
  15640. // this.icon.destroy();
  15641. // this.textCollisionBox.destroy();
  15642. // this.iconCollisionBox.destroy();
  15643. // this.textCollisionCircle.destroy();
  15644. // this.iconCollisionCircle.destroy();
  15645. };
  15646. SymbolBucket.prototype.clear = function clear() {
  15647. };
  15648. SymbolBucket.prototype.addToLineVertexArray = function addToLineVertexArray(anchor, line) {
  15649. var lineStartIndex = this.lineVertexArray.length;
  15650. if (anchor.segment !== undefined) {
  15651. var sumForwardLength = anchor.dist(line[anchor.segment + 1]);
  15652. var sumBackwardLength = anchor.dist(line[anchor.segment]);
  15653. var vertices = {};
  15654. for (var i = anchor.segment + 1; i < line.length; i++) {
  15655. vertices[i] = {x: line[i].x, y: line[i].y, tileUnitDistanceFromAnchor: sumForwardLength};
  15656. if (i < line.length - 1) {
  15657. sumForwardLength += line[i + 1].dist(line[i]);
  15658. }
  15659. }
  15660. for (var i$1 = anchor.segment || 0; i$1 >= 0; i$1--) {
  15661. vertices[i$1] = {x: line[i$1].x, y: line[i$1].y, tileUnitDistanceFromAnchor: sumBackwardLength};
  15662. if (i$1 > 0) {
  15663. sumBackwardLength += line[i$1 - 1].dist(line[i$1]);
  15664. }
  15665. }
  15666. for (var i$2 = 0; i$2 < line.length; i$2++) {
  15667. var vertex = vertices[i$2];
  15668. this.lineVertexArray.emplaceBack(vertex.x, vertex.y, vertex.tileUnitDistanceFromAnchor);
  15669. }
  15670. }
  15671. return {
  15672. lineStartIndex: lineStartIndex,
  15673. lineLength: this.lineVertexArray.length - lineStartIndex
  15674. };
  15675. };
  15676. SymbolBucket.prototype.addSymbols = function addSymbols(arrays, quads, sizeVertex, lineOffset, alongLine, feature, writingMode, labelAnchor, lineStartIndex, lineLength, associatedIconIndex) {
  15677. var this$1 = this;
  15678. var indexArray = arrays.indexArray;
  15679. var layoutVertexArray = arrays.layoutVertexArray;
  15680. var dynamicLayoutVertexArray = arrays.dynamicLayoutVertexArray;
  15681. var segment = arrays.segments.prepareSegment(4 * quads.length, arrays.layoutVertexArray, arrays.indexArray, feature.sortKey);
  15682. var glyphOffsetArrayStart = this.glyphOffsetArray.length;
  15683. var vertexStartIndex = segment.vertexLength;
  15684. var angle = (this.allowVerticalPlacement && writingMode === Shaping.WritingMode.vertical) ? Math.PI / 2 : 0;
  15685. var addSymbol = function (symbol) {
  15686. var tl = symbol.tl,
  15687. tr = symbol.tr,
  15688. bl = symbol.bl,
  15689. br = symbol.br,
  15690. tex = symbol.tex,
  15691. pixelOffsetTL = symbol.pixelOffsetTL,
  15692. pixelOffsetBR = symbol.pixelOffsetBR,
  15693. mfsx = symbol.minFontScaleX,
  15694. mfsy = symbol.minFontScaleY;
  15695. var index = segment.vertexLength;
  15696. var y = symbol.glyphOffset[1];
  15697. addVertex$1(layoutVertexArray, labelAnchor.x, labelAnchor.y, tl.x, y + tl.y, tex.x, tex.y, sizeVertex, symbol.isSDF, pixelOffsetTL.x, pixelOffsetTL.y, mfsx, mfsy);
  15698. addVertex$1(layoutVertexArray, labelAnchor.x, labelAnchor.y, tr.x, y + tr.y, tex.x + tex.w, tex.y, sizeVertex, symbol.isSDF, pixelOffsetBR.x, pixelOffsetTL.y, mfsx, mfsy);
  15699. addVertex$1(layoutVertexArray, labelAnchor.x, labelAnchor.y, bl.x, y + bl.y, tex.x, tex.y + tex.h, sizeVertex, symbol.isSDF, pixelOffsetTL.x, pixelOffsetBR.y, mfsx, mfsy);
  15700. addVertex$1(layoutVertexArray, labelAnchor.x, labelAnchor.y, br.x, y + br.y, tex.x + tex.w, tex.y + tex.h, sizeVertex, symbol.isSDF, pixelOffsetBR.x, pixelOffsetBR.y, mfsx, mfsy);
  15701. addDynamicAttributes(dynamicLayoutVertexArray, labelAnchor, angle);
  15702. indexArray.emplaceBack(index, index + 1, index + 2);
  15703. indexArray.emplaceBack(index + 1, index + 2, index + 3);
  15704. segment.vertexLength += 4;
  15705. segment.primitiveLength += 2;
  15706. this$1.glyphOffsetArray.emplaceBack(symbol.glyphOffset[0]);
  15707. };
  15708. if (feature.text && feature.text.sections) {
  15709. var sections = feature.text.sections;
  15710. if (this.hasPaintOverrides) {
  15711. var currentSectionIndex;
  15712. var populatePaintArrayForSection = function (sectionIndex, lastSection) {
  15713. if (currentSectionIndex !== undefined && (currentSectionIndex !== sectionIndex || lastSection)) {
  15714. arrays.programConfigurations.populatePaintArrays(arrays.layoutVertexArray.length, feature, feature.index, {}, sections[currentSectionIndex]);
  15715. }
  15716. currentSectionIndex = sectionIndex;
  15717. };
  15718. for (var i = 0, list = quads; i < list.length; i += 1) {
  15719. var symbol = list[i];
  15720. populatePaintArrayForSection(symbol.sectionIndex, false);
  15721. addSymbol(symbol);
  15722. }
  15723. // Populate paint arrays for the last section.
  15724. populatePaintArrayForSection(currentSectionIndex, true);
  15725. } else {
  15726. for (var i$1 = 0, list$1 = quads; i$1 < list$1.length; i$1 += 1) {
  15727. var symbol$1 = list$1[i$1];
  15728. addSymbol(symbol$1);
  15729. }
  15730. arrays.programConfigurations.populatePaintArrays(arrays.layoutVertexArray.length, feature, feature.index, {}, sections[0]);
  15731. }
  15732. } else {
  15733. for (var i$2 = 0, list$2 = quads; i$2 < list$2.length; i$2 += 1) {
  15734. var symbol$2 = list$2[i$2];
  15735. addSymbol(symbol$2);
  15736. }
  15737. arrays.programConfigurations.populatePaintArrays(arrays.layoutVertexArray.length, feature, feature.index, {});
  15738. }
  15739. arrays.placedSymbolArray.emplaceBack(labelAnchor.x, labelAnchor.y,
  15740. glyphOffsetArrayStart, this.glyphOffsetArray.length - glyphOffsetArrayStart, vertexStartIndex,
  15741. lineStartIndex, lineLength, (labelAnchor.segment ),
  15742. sizeVertex ? sizeVertex[0] : 0, sizeVertex ? sizeVertex[1] : 0,
  15743. lineOffset[0], lineOffset[1],
  15744. writingMode,
  15745. // placedOrientation is null initially; will be updated to horizontal(1)/vertical(2) if placed
  15746. 0,
  15747. (false ),
  15748. // The crossTileID is only filled/used on the foreground for dynamic text anchors
  15749. 0,
  15750. associatedIconIndex
  15751. );
  15752. };
  15753. SymbolBucket.prototype._addCollisionDebugVertex = function _addCollisionDebugVertex(layoutVertexArray, collisionVertexArray, point, anchorX, anchorY, extrude) {
  15754. collisionVertexArray.emplaceBack(0, 0);
  15755. return layoutVertexArray.emplaceBack(
  15756. // pos
  15757. point.x,
  15758. point.y,
  15759. // a_anchor_pos
  15760. anchorX,
  15761. anchorY,
  15762. // extrude
  15763. Math.round(extrude.x),
  15764. Math.round(extrude.y));
  15765. };
  15766. SymbolBucket.prototype.addCollisionDebugVertices = function addCollisionDebugVertices(x1, y1, x2, y2, arrays, boxAnchorPoint, symbolInstance, isCircle) {
  15767. var segment = arrays.segments.prepareSegment(4, arrays.layoutVertexArray, arrays.indexArray);
  15768. var index = segment.vertexLength;
  15769. var layoutVertexArray = arrays.layoutVertexArray;
  15770. var collisionVertexArray = arrays.collisionVertexArray;
  15771. var anchorX = symbolInstance.anchorX;
  15772. var anchorY = symbolInstance.anchorY;
  15773. this._addCollisionDebugVertex(layoutVertexArray, collisionVertexArray, boxAnchorPoint, anchorX, anchorY, new pointGeometry(x1, y1));
  15774. this._addCollisionDebugVertex(layoutVertexArray, collisionVertexArray, boxAnchorPoint, anchorX, anchorY, new pointGeometry(x2, y1));
  15775. this._addCollisionDebugVertex(layoutVertexArray, collisionVertexArray, boxAnchorPoint, anchorX, anchorY, new pointGeometry(x2, y2));
  15776. this._addCollisionDebugVertex(layoutVertexArray, collisionVertexArray, boxAnchorPoint, anchorX, anchorY, new pointGeometry(x1, y2));
  15777. segment.vertexLength += 4;
  15778. if (isCircle) {
  15779. var indexArray = (arrays.indexArray );
  15780. indexArray.emplaceBack(index, index + 1, index + 2);
  15781. indexArray.emplaceBack(index, index + 2, index + 3);
  15782. segment.primitiveLength += 2;
  15783. } else {
  15784. var indexArray$1 = (arrays.indexArray );
  15785. indexArray$1.emplaceBack(index, index + 1);
  15786. indexArray$1.emplaceBack(index + 1, index + 2);
  15787. indexArray$1.emplaceBack(index + 2, index + 3);
  15788. indexArray$1.emplaceBack(index + 3, index);
  15789. segment.primitiveLength += 4;
  15790. }
  15791. };
  15792. SymbolBucket.prototype.addDebugCollisionBoxes = function addDebugCollisionBoxes(startIndex, endIndex, symbolInstance, isText) {
  15793. for (var b = startIndex; b < endIndex; b++) {
  15794. var box = (this.collisionBoxArray.get(b) );
  15795. var x1 = box.x1;
  15796. var y1 = box.y1;
  15797. var x2 = box.x2;
  15798. var y2 = box.y2;
  15799. // If the radius > 0, this collision box is actually a circle
  15800. // The data we add to the buffers is exactly the same, but we'll render with a different shader.
  15801. var isCircle = box.radius > 0;
  15802. this.addCollisionDebugVertices(x1, y1, x2, y2, isCircle ?
  15803. (isText ? this.textCollisionCircle : this.iconCollisionCircle) : (isText ? this.textCollisionBox : this.iconCollisionBox),
  15804. box.anchorPoint, symbolInstance, isCircle);
  15805. }
  15806. };
  15807. SymbolBucket.prototype.generateCollisionDebugBuffers = function generateCollisionDebugBuffers() {
  15808. for (var i = 0; i < this.symbolInstances.length; i++) {
  15809. var symbolInstance = this.symbolInstances.get(i);
  15810. this.addDebugCollisionBoxes(symbolInstance.textBoxStartIndex, symbolInstance.textBoxEndIndex, symbolInstance, true);
  15811. this.addDebugCollisionBoxes(symbolInstance.verticalTextBoxStartIndex, symbolInstance.verticalTextBoxEndIndex, symbolInstance, true);
  15812. this.addDebugCollisionBoxes(symbolInstance.iconBoxStartIndex, symbolInstance.iconBoxEndIndex, symbolInstance, false);
  15813. this.addDebugCollisionBoxes(symbolInstance.verticalIconBoxStartIndex, symbolInstance.verticalIconBoxEndIndex, symbolInstance, false);
  15814. }
  15815. };
  15816. // These flat arrays are meant to be quicker to iterate over than the source
  15817. // CollisionBoxArray
  15818. SymbolBucket.prototype._deserializeCollisionBoxesForSymbol = function _deserializeCollisionBoxesForSymbol(collisionBoxArray, textStartIndex, textEndIndex, verticalTextStartIndex, verticalTextEndIndex, iconStartIndex, iconEndIndex, verticalIconStartIndex, verticalIconEndIndex) {
  15819. var collisionArrays = {};
  15820. for (var k = textStartIndex; k < textEndIndex; k++) {
  15821. var box = (collisionBoxArray.get(k) );
  15822. if (box.radius === 0) {
  15823. collisionArrays.textBox = {x1: box.x1, y1: box.y1, x2: box.x2, y2: box.y2, anchorPointX: box.anchorPointX, anchorPointY: box.anchorPointY};
  15824. collisionArrays.textFeatureIndex = box.featureIndex;
  15825. break; // Only one box allowed per instance
  15826. } else {
  15827. if (!collisionArrays.textCircles) {
  15828. collisionArrays.textCircles = [];
  15829. collisionArrays.textFeatureIndex = box.featureIndex;
  15830. }
  15831. var used = 1; // May be updated at collision detection time
  15832. collisionArrays.textCircles.push(box.anchorPointX, box.anchorPointY, box.radius, box.signedDistanceFromAnchor, used);
  15833. }
  15834. }
  15835. for (var k$1 = verticalTextStartIndex; k$1 < verticalTextEndIndex; k$1++) {
  15836. var box$1 = (collisionBoxArray.get(k$1) );
  15837. if (box$1.radius === 0) {
  15838. collisionArrays.verticalTextBox = {x1: box$1.x1, y1: box$1.y1, x2: box$1.x2, y2: box$1.y2, anchorPointX: box$1.anchorPointX, anchorPointY: box$1.anchorPointY};
  15839. collisionArrays.verticalTextFeatureIndex = box$1.featureIndex;
  15840. break; // Only one box allowed per instance
  15841. }
  15842. }
  15843. for (var k$2 = iconStartIndex; k$2 < iconEndIndex; k$2++) {
  15844. // An icon can only have one box now, so this indexing is a bit vestigial...
  15845. var box$2 = (collisionBoxArray.get(k$2) );
  15846. if (box$2.radius === 0) {
  15847. collisionArrays.iconBox = {x1: box$2.x1, y1: box$2.y1, x2: box$2.x2, y2: box$2.y2, anchorPointX: box$2.anchorPointX, anchorPointY: box$2.anchorPointY};
  15848. collisionArrays.iconFeatureIndex = box$2.featureIndex;
  15849. break; // Only one box allowed per instance
  15850. }
  15851. }
  15852. for (var k$3 = verticalIconStartIndex; k$3 < verticalIconEndIndex; k$3++) {
  15853. // An icon can only have one box now, so this indexing is a bit vestigial...
  15854. var box$3 = (collisionBoxArray.get(k$3) );
  15855. if (box$3.radius === 0) {
  15856. collisionArrays.verticalIconBox = {x1: box$3.x1, y1: box$3.y1, x2: box$3.x2, y2: box$3.y2, anchorPointX: box$3.anchorPointX, anchorPointY: box$3.anchorPointY};
  15857. collisionArrays.verticalIconFeatureIndex = box$3.featureIndex;
  15858. break; // Only one box allowed per instance
  15859. }
  15860. }
  15861. return collisionArrays;
  15862. };
  15863. SymbolBucket.prototype.deserializeCollisionBoxes = function deserializeCollisionBoxes(collisionBoxArray) {
  15864. this.collisionArrays = [];
  15865. for (var i = 0; i < this.symbolInstances.length; i++) {
  15866. var symbolInstance = this.symbolInstances.get(i);
  15867. this.collisionArrays.push(this._deserializeCollisionBoxesForSymbol(
  15868. collisionBoxArray,
  15869. symbolInstance.textBoxStartIndex,
  15870. symbolInstance.textBoxEndIndex,
  15871. symbolInstance.verticalTextBoxStartIndex,
  15872. symbolInstance.verticalTextBoxEndIndex,
  15873. symbolInstance.iconBoxStartIndex,
  15874. symbolInstance.iconBoxEndIndex,
  15875. symbolInstance.verticalIconBoxStartIndex,
  15876. symbolInstance.verticalIconBoxEndIndex
  15877. ));
  15878. }
  15879. };
  15880. SymbolBucket.prototype.hasTextData = function hasTextData() {
  15881. return this.text.segments.get().length > 0;
  15882. };
  15883. SymbolBucket.prototype.hasIconData = function hasIconData() {
  15884. return this.icon.segments.get().length > 0;
  15885. };
  15886. SymbolBucket.prototype.hasTextCollisionBoxData = function hasTextCollisionBoxData() {
  15887. return this.textCollisionBox.segments.get().length > 0;
  15888. };
  15889. SymbolBucket.prototype.hasIconCollisionBoxData = function hasIconCollisionBoxData() {
  15890. return this.iconCollisionBox.segments.get().length > 0;
  15891. };
  15892. SymbolBucket.prototype.hasTextCollisionCircleData = function hasTextCollisionCircleData() {
  15893. return this.textCollisionCircle.segments.get().length > 0;
  15894. };
  15895. SymbolBucket.prototype.hasIconCollisionCircleData = function hasIconCollisionCircleData() {
  15896. return this.iconCollisionCircle.segments.get().length > 0;
  15897. };
  15898. SymbolBucket.prototype.addIndicesForPlacedSymbol = function addIndicesForPlacedSymbol(iconOrText, placedSymbolIndex) {
  15899. var placedSymbol = iconOrText.placedSymbolArray.get(placedSymbolIndex);
  15900. var endIndex = placedSymbol.vertexStartIndex + placedSymbol.numGlyphs * 4;
  15901. for (var vertexIndex = placedSymbol.vertexStartIndex; vertexIndex < endIndex; vertexIndex += 4) {
  15902. iconOrText.indexArray.emplaceBack(vertexIndex, vertexIndex + 1, vertexIndex + 2);
  15903. iconOrText.indexArray.emplaceBack(vertexIndex + 1, vertexIndex + 2, vertexIndex + 3);
  15904. }
  15905. };
  15906. SymbolBucket.prototype.getSortedSymbolIndexes = function getSortedSymbolIndexes(angle) {
  15907. if (this.sortedAngle === angle && this.symbolInstanceIndexes !== undefined) {
  15908. return this.symbolInstanceIndexes;
  15909. }
  15910. var sin = Math.sin(angle);
  15911. var cos = Math.cos(angle);
  15912. var rotatedYs = [];
  15913. var featureIndexes = [];
  15914. var result = [];
  15915. for (var i = 0; i < this.symbolInstances.length; ++i) {
  15916. result.push(i);
  15917. var symbolInstance = this.symbolInstances.get(i);
  15918. rotatedYs.push(Math.round(sin * symbolInstance.anchorX + cos * symbolInstance.anchorY) | 0);
  15919. featureIndexes.push(symbolInstance.featureIndex);
  15920. }
  15921. result.sort(function (aIndex, bIndex) {
  15922. return (rotatedYs[aIndex] - rotatedYs[bIndex]) ||
  15923. (featureIndexes[bIndex] - featureIndexes[aIndex]);
  15924. });
  15925. return result;
  15926. };
  15927. SymbolBucket.prototype.sortFeatures = function sortFeatures(angle) {
  15928. var this$1 = this;
  15929. if (!this.sortFeaturesByY) {
  15930. return;
  15931. }
  15932. if (this.sortedAngle === angle) {
  15933. return;
  15934. }
  15935. // The current approach to sorting doesn't sort across segments so don't try.
  15936. // Sorting within segments separately seemed not to be worth the complexity.
  15937. if (this.text.segments.get().length > 1 || this.icon.segments.get().length > 1) {
  15938. return;
  15939. }
  15940. // If the symbols are allowed to overlap sort them by their vertical screen position.
  15941. // The index array buffer is rewritten to reference the (unchanged) vertices in the
  15942. // sorted order.
  15943. // To avoid sorting the actual symbolInstance array we sort an array of indexes.
  15944. this.symbolInstanceIndexes = this.getSortedSymbolIndexes(angle);
  15945. this.sortedAngle = angle;
  15946. this.text.indexArray.clear();
  15947. this.icon.indexArray.clear();
  15948. this.featureSortOrder = [];
  15949. for (var i$1 = 0, list = this.symbolInstanceIndexes; i$1 < list.length; i$1 += 1) {
  15950. var i = list[i$1];
  15951. var symbolInstance = this.symbolInstances.get(i);
  15952. this.featureSortOrder.push(symbolInstance.featureIndex);
  15953. [
  15954. symbolInstance.rightJustifiedTextSymbolIndex,
  15955. symbolInstance.centerJustifiedTextSymbolIndex,
  15956. symbolInstance.leftJustifiedTextSymbolIndex
  15957. ].forEach(function (index, i, array) {
  15958. // Only add a given index the first time it shows up,
  15959. // to avoid duplicate opacity entries when multiple justifications
  15960. // share the same glyphs.
  15961. if (index >= 0 && array.indexOf(index) === i) {
  15962. this$1.addIndicesForPlacedSymbol(this$1.text, index);
  15963. }
  15964. });
  15965. if (symbolInstance.verticalPlacedTextSymbolIndex >= 0) {
  15966. this.addIndicesForPlacedSymbol(this.text, symbolInstance.verticalPlacedTextSymbolIndex);
  15967. }
  15968. if (symbolInstance.placedIconSymbolIndex >= 0) {
  15969. this.addIndicesForPlacedSymbol(this.icon, symbolInstance.placedIconSymbolIndex);
  15970. }
  15971. if (symbolInstance.verticalPlacedIconSymbolIndex >= 0) {
  15972. this.addIndicesForPlacedSymbol(this.icon, symbolInstance.verticalPlacedIconSymbolIndex);
  15973. }
  15974. }
  15975. if (this.text.indexBuffer) {
  15976. this.text.indexBuffer.updateData(this.text.indexArray);
  15977. }
  15978. if (this.icon.indexBuffer) {
  15979. this.icon.indexBuffer.updateData(this.icon.indexArray);
  15980. }
  15981. };
  15982. WebWorkerTransfer.register('SymbolBucket', SymbolBucket, {
  15983. //omit: ['layers', 'collisionBoxArray', 'features', 'compareText']
  15984. omit: ['layers', 'collisionBoxArray', 'compareText']
  15985. });
  15986. // this constant is based on the size of StructArray indexes used in a symbol
  15987. // bucket--namely, glyphOffsetArrayStart
  15988. // eg the max valid UInt16 is 65,535
  15989. // See https://github.com/mapbox/mapbox-gl-js/issues/2907 for motivation
  15990. // lineStartIndex and textBoxStartIndex could potentially be concerns
  15991. // but we expect there to be many fewer boxes/lines than glyphs
  15992. SymbolBucket.MAX_GLYPHS = 65535;
  15993. SymbolBucket.addDynamicAttributes = addDynamicAttributes;
  15994. var ColorType$7 = {kind: 'color'};
  15995. var FormattedType$4 = {kind: 'formatted'};
  15996. var layout$7 = new Properties({
  15997. "symbol-placement": new DataConstantProperty(StyleSpec["layout_symbol"]["symbol-placement"]),
  15998. "symbol-spacing": new DataConstantProperty(StyleSpec["layout_symbol"]["symbol-spacing"]),
  15999. "symbol-avoid-edges": new DataConstantProperty(StyleSpec["layout_symbol"]["symbol-avoid-edges"]),
  16000. "symbol-sort-key": new DataDrivenProperty(StyleSpec["layout_symbol"]["symbol-sort-key"]),
  16001. "symbol-z-order": new DataConstantProperty(StyleSpec["layout_symbol"]["symbol-z-order"]),
  16002. "icon-allow-overlap": new DataConstantProperty(StyleSpec["layout_symbol"]["icon-allow-overlap"]),
  16003. "icon-ignore-placement": new DataConstantProperty(StyleSpec["layout_symbol"]["icon-ignore-placement"]),
  16004. "icon-optional": new DataConstantProperty(StyleSpec["layout_symbol"]["icon-optional"]),
  16005. "icon-rotation-alignment": new DataConstantProperty(StyleSpec["layout_symbol"]["icon-rotation-alignment"]),
  16006. "icon-size": new DataDrivenProperty(StyleSpec["layout_symbol"]["icon-size"]),
  16007. "icon-text-fit": new DataConstantProperty(StyleSpec["layout_symbol"]["icon-text-fit"]),
  16008. "icon-text-fit-padding": new DataConstantProperty(StyleSpec["layout_symbol"]["icon-text-fit-padding"]),
  16009. "icon-image": new DataDrivenProperty(StyleSpec["layout_symbol"]["icon-image"]),
  16010. "icon-rotate": new DataDrivenProperty(StyleSpec["layout_symbol"]["icon-rotate"]),
  16011. "icon-padding": new DataConstantProperty(StyleSpec["layout_symbol"]["icon-padding"]),
  16012. "icon-keep-upright": new DataConstantProperty(StyleSpec["layout_symbol"]["icon-keep-upright"]),
  16013. "icon-offset": new DataDrivenProperty(StyleSpec["layout_symbol"]["icon-offset"]),
  16014. "icon-anchor": new DataDrivenProperty(StyleSpec["layout_symbol"]["icon-anchor"]),
  16015. "icon-pitch-alignment": new DataConstantProperty(StyleSpec["layout_symbol"]["icon-pitch-alignment"]),
  16016. "text-pitch-alignment": new DataConstantProperty(StyleSpec["layout_symbol"]["text-pitch-alignment"]),
  16017. "text-rotation-alignment": new DataConstantProperty(StyleSpec["layout_symbol"]["text-rotation-alignment"]),
  16018. "text-field": new DataDrivenProperty(StyleSpec["layout_symbol"]["text-field"]),
  16019. "text-font": new DataDrivenProperty(StyleSpec["layout_symbol"]["text-font"]),
  16020. "text-size": new DataDrivenProperty(StyleSpec["layout_symbol"]["text-size"]),
  16021. "text-max-width": new DataDrivenProperty(StyleSpec["layout_symbol"]["text-max-width"]),
  16022. "text-line-height": new DataConstantProperty(StyleSpec["layout_symbol"]["text-line-height"]),
  16023. "text-letter-spacing": new DataDrivenProperty(StyleSpec["layout_symbol"]["text-letter-spacing"]),
  16024. "text-justify": new DataDrivenProperty(StyleSpec["layout_symbol"]["text-justify"]),
  16025. "text-radial-offset": new DataDrivenProperty(StyleSpec["layout_symbol"]["text-radial-offset"]),
  16026. "text-variable-anchor": new DataConstantProperty(StyleSpec["layout_symbol"]["text-variable-anchor"]),
  16027. "text-anchor": new DataDrivenProperty(StyleSpec["layout_symbol"]["text-anchor"]),
  16028. "text-max-angle": new DataConstantProperty(StyleSpec["layout_symbol"]["text-max-angle"]),
  16029. "text-writing-mode": new DataConstantProperty(StyleSpec["layout_symbol"]["text-writing-mode"]),
  16030. "text-rotate": new DataDrivenProperty(StyleSpec["layout_symbol"]["text-rotate"]),
  16031. "text-padding": new DataConstantProperty(StyleSpec["layout_symbol"]["text-padding"]),
  16032. "text-keep-upright": new DataConstantProperty(StyleSpec["layout_symbol"]["text-keep-upright"]),
  16033. "text-transform": new DataDrivenProperty(StyleSpec["layout_symbol"]["text-transform"]),
  16034. "text-offset": new DataDrivenProperty(StyleSpec["layout_symbol"]["text-offset"]),
  16035. "text-allow-overlap": new DataConstantProperty(StyleSpec["layout_symbol"]["text-allow-overlap"]),
  16036. "text-ignore-placement": new DataConstantProperty(StyleSpec["layout_symbol"]["text-ignore-placement"]),
  16037. "text-optional": new DataConstantProperty(StyleSpec["layout_symbol"]["text-optional"])
  16038. });
  16039. var paint$7 = new Properties({
  16040. "icon-opacity": new DataDrivenProperty(StyleSpec["paint_symbol"]["icon-opacity"]),
  16041. "icon-color": new DataDrivenProperty(StyleSpec["paint_symbol"]["icon-color"]),
  16042. "icon-halo-color": new DataDrivenProperty(StyleSpec["paint_symbol"]["icon-halo-color"]),
  16043. "icon-halo-width": new DataDrivenProperty(StyleSpec["paint_symbol"]["icon-halo-width"]),
  16044. "icon-halo-blur": new DataDrivenProperty(StyleSpec["paint_symbol"]["icon-halo-blur"]),
  16045. "icon-translate": new DataConstantProperty(StyleSpec["paint_symbol"]["icon-translate"]),
  16046. "icon-translate-anchor": new DataConstantProperty(StyleSpec["paint_symbol"]["icon-translate-anchor"]),
  16047. "text-opacity": new DataDrivenProperty(StyleSpec["paint_symbol"]["text-opacity"]),
  16048. "text-color": new DataDrivenProperty(StyleSpec["paint_symbol"]["text-color"], { runtimeType: ColorType$7, getOverride: function (o) {
  16049. return o.textColor;
  16050. }, hasOverride: function (o) {
  16051. return !!o.textColor;
  16052. } }),
  16053. "text-halo-color": new DataDrivenProperty(StyleSpec["paint_symbol"]["text-halo-color"]),
  16054. "text-halo-width": new DataDrivenProperty(StyleSpec["paint_symbol"]["text-halo-width"]),
  16055. "text-halo-blur": new DataDrivenProperty(StyleSpec["paint_symbol"]["text-halo-blur"]),
  16056. "text-translate": new DataConstantProperty(StyleSpec["paint_symbol"]["text-translate"]),
  16057. "text-translate-anchor": new DataConstantProperty(StyleSpec["paint_symbol"]["text-translate-anchor"])
  16058. });
  16059. // Note: without adding the explicit type annotation, Flow infers weaker types
  16060. // for these objects from their use in the constructor to StyleLayer, as
  16061. // {layout?: Properties<...>, paint: Properties<...>}
  16062. var properties$6 = ({ paint: paint$7, layout: layout$7 }
  16063. );
  16064. var SymbolStyleLayer = /*@__PURE__*/(function (StyleLayer) {
  16065. function SymbolStyleLayer(layer) {
  16066. StyleLayer.call(this, layer, properties$6);
  16067. }
  16068. if (StyleLayer) SymbolStyleLayer.__proto__ = StyleLayer;
  16069. SymbolStyleLayer.prototype = Object.create(StyleLayer && StyleLayer.prototype);
  16070. SymbolStyleLayer.prototype.constructor = SymbolStyleLayer;
  16071. SymbolStyleLayer.prototype.recalculate = function recalculate(parameters, availableImages) {
  16072. StyleLayer.prototype.recalculate.call(this, parameters, availableImages);
  16073. if (this.layout.get('icon-rotation-alignment') === 'auto') {
  16074. if (this.layout.get('symbol-placement') !== 'point') {
  16075. this.layout._values['icon-rotation-alignment'] = 'map';
  16076. } else {
  16077. this.layout._values['icon-rotation-alignment'] = 'viewport';
  16078. }
  16079. }
  16080. if (this.layout.get('text-rotation-alignment') === 'auto') {
  16081. if (this.layout.get('symbol-placement') !== 'point') {
  16082. this.layout._values['text-rotation-alignment'] = 'map';
  16083. } else {
  16084. this.layout._values['text-rotation-alignment'] = 'viewport';
  16085. }
  16086. }
  16087. // If unspecified, `*-pitch-alignment` inherits `*-rotation-alignment`
  16088. if (this.layout.get('text-pitch-alignment') === 'auto') {
  16089. this.layout._values['text-pitch-alignment'] = this.layout.get('text-rotation-alignment');
  16090. }
  16091. if (this.layout.get('icon-pitch-alignment') === 'auto') {
  16092. this.layout._values['icon-pitch-alignment'] = this.layout.get('icon-rotation-alignment');
  16093. }
  16094. if (this.layout.get('symbol-placement') === 'point') {
  16095. var writingModes = this.layout.get('text-writing-mode');
  16096. if (writingModes) {
  16097. // remove duplicates, preserving order
  16098. var deduped = [];
  16099. for (var i = 0, list = writingModes; i < list.length; i += 1) {
  16100. var m = list[i];
  16101. if (deduped.indexOf(m) < 0) {
  16102. deduped.push(m);
  16103. }
  16104. }
  16105. this.layout._values['text-writing-mode'] = deduped;
  16106. } else {
  16107. this.layout._values['text-writing-mode'] = ['horizontal'];
  16108. }
  16109. }
  16110. this._setPaintOverrides();
  16111. };
  16112. SymbolStyleLayer.prototype.getValueAndResolveTokens = function getValueAndResolveTokens(name, feature, availableImages) {
  16113. var value = this.layout.get(name).evaluate(feature, {}, availableImages);
  16114. var unevaluated = this._unevaluatedLayout._values[name];
  16115. if (!unevaluated.isDataDriven() && !Expression.isExpression(unevaluated.value) && value) {
  16116. return Util.resolveTokens(feature.properties, value);
  16117. }
  16118. return value;
  16119. };
  16120. SymbolStyleLayer.prototype.createBucket = function createBucket(parameters) {
  16121. return new SymbolBucket(parameters);
  16122. };
  16123. SymbolStyleLayer.prototype.queryRadius = function queryRadius() {
  16124. return 0;
  16125. };
  16126. SymbolStyleLayer.prototype.queryIntersectsFeature = function queryIntersectsFeature() {
  16127. assert_1(false); // Should take a different path in FeatureIndex
  16128. return false;
  16129. };
  16130. SymbolStyleLayer.prototype._setPaintOverrides = function _setPaintOverrides() {
  16131. for (var i = 0, list = properties$6.paint.overridableProperties; i < list.length; i += 1) {
  16132. var overridable = list[i];
  16133. if (!SymbolStyleLayer.hasPaintOverride(this.layout, overridable)) {
  16134. continue;
  16135. }
  16136. var overriden = this.paint.get(overridable);
  16137. var override = new FormatSectionOverride(overriden);
  16138. var styleExpression = new StyleExpression(override, overriden.property.specification);
  16139. var expression = null;
  16140. if (overriden.value.kind === 'constant' || overriden.value.kind === 'source') {
  16141. expression = (new ZoomConstantExpression('source', styleExpression) );
  16142. } else {
  16143. expression = (new ZoomDependentExpression('composite',
  16144. styleExpression,
  16145. overriden.value.zoomStops,
  16146. overriden.value._interpolationType) );
  16147. }
  16148. this.paint._values[overridable] = new PossiblyEvaluatedPropertyValue(overriden.property,
  16149. expression,
  16150. overriden.parameters);
  16151. }
  16152. };
  16153. SymbolStyleLayer.prototype._handleOverridablePaintPropertyUpdate = function _handleOverridablePaintPropertyUpdate(name, oldValue, newValue) {
  16154. if (!this.layout || oldValue.isDataDriven() || newValue.isDataDriven()) {
  16155. return false;
  16156. }
  16157. return SymbolStyleLayer.hasPaintOverride(this.layout, name);
  16158. };
  16159. SymbolStyleLayer.hasPaintOverride = function hasPaintOverride(layout, propertyName) {
  16160. var textField = layout.get('text-field');
  16161. var property = properties$6.paint.properties[propertyName];
  16162. var hasOverrides = false;
  16163. var checkSections = function (sections) {
  16164. for (var i = 0, list = sections; i < list.length; i += 1) {
  16165. var section = list[i];
  16166. if (property.overrides && property.overrides.hasOverride(section)) {
  16167. hasOverrides = true;
  16168. return;
  16169. }
  16170. }
  16171. };
  16172. if (textField.value.kind === 'constant' && textField.value.value instanceof Formatted$1) {
  16173. checkSections(textField.value.value.sections);
  16174. } else if (textField.value.kind === 'source') {
  16175. var checkExpression = function (expression) {
  16176. if (hasOverrides) {
  16177. return;
  16178. }
  16179. if (expression instanceof Literal && Values$1.typeOf(expression.value) === FormattedType$4) {
  16180. var formatted = ((expression.value) );
  16181. checkSections(formatted.sections);
  16182. } else if (expression instanceof FormatExpression$1) {
  16183. checkSections(expression.sections);
  16184. } else {
  16185. expression.eachChild(checkExpression);
  16186. }
  16187. };
  16188. var expr = ((textField.value) );
  16189. if (expr._styleExpression) {
  16190. checkExpression(expr._styleExpression.expression);
  16191. }
  16192. }
  16193. return hasOverrides;
  16194. };
  16195. SymbolStyleLayer.hasPaintOverrides = function hasPaintOverrides(layout) {
  16196. for (var i = 0, list = properties$6.paint.overridableProperties; i < list.length; i += 1) {
  16197. var overridable = list[i];
  16198. if (SymbolStyleLayer.hasPaintOverride(layout, overridable)) {
  16199. return true;
  16200. }
  16201. }
  16202. return false;
  16203. };
  16204. return SymbolStyleLayer;
  16205. }(StyleLayer));
  16206. var subclasses = {
  16207. circle: CircleStyleLayer,
  16208. fill: FillStyleLayer,
  16209. line: LineStyleLayer,
  16210. symbol : SymbolStyleLayer
  16211. };
  16212. function createStyleLayer(layer) {
  16213. if(subclasses[layer.type]){
  16214. return new subclasses[layer.type](layer);
  16215. }
  16216. else{
  16217. return null;
  16218. }
  16219. }
  16220. var StyleLayerIndex = function StyleLayerIndex(layerConfigs) {
  16221. this.keyCache = {};
  16222. if (layerConfigs) {
  16223. this.replace(layerConfigs);
  16224. }
  16225. };
  16226. StyleLayerIndex.prototype.replace = function replace (layerConfigs) {
  16227. this._layerConfigs = {};
  16228. this._layers = {};
  16229. this.update(layerConfigs, []);
  16230. };
  16231. function values(obj) {
  16232. var result = [];
  16233. for (var k in obj) {
  16234. result.push(obj[k]);
  16235. }
  16236. return result;
  16237. }
  16238. StyleLayerIndex.prototype.update = function update (layerConfigs, removedIds) {
  16239. var this$1 = this;
  16240. for (var i = 0, list = layerConfigs; i < list.length; i += 1) {
  16241. var layerConfig = list[i];
  16242. this._layerConfigs[layerConfig.id] = layerConfig;
  16243. var layer = createStyleLayer(layerConfig);
  16244. if(layer == null){
  16245. continue;
  16246. }
  16247. this._layers[layerConfig.id] = layer;
  16248. layer._featureFilter = featureFilter.createFilter(layer.filter);
  16249. if (this.keyCache[layerConfig.id])
  16250. { delete this.keyCache[layerConfig.id]; }
  16251. }
  16252. for (var i$1 = 0, list$1 = removedIds; i$1 < list$1.length; i$1 += 1) {
  16253. var id = list$1[i$1];
  16254. delete this.keyCache[id];
  16255. delete this._layerConfigs[id];
  16256. delete this._layers[id];
  16257. }
  16258. this.familiesBySource = {};
  16259. var groups = groupByLayout(values(this._layerConfigs), this.keyCache);
  16260. for (var i$2 = 0, list$2 = groups; i$2 < list$2.length; i$2 += 1) {
  16261. var layerConfigs$1 = list$2[i$2];
  16262. var layers = layerConfigs$1.map(function (layerConfig) { return this$1._layers[layerConfig.id]; });
  16263. var layer$1 = layers[0];
  16264. if (layer$1 == undefined || layer$1.visibility === 'none') {
  16265. continue;
  16266. }
  16267. var sourceId = layer$1.source || '';
  16268. var sourceGroup = this.familiesBySource[sourceId];
  16269. if (!sourceGroup) {
  16270. sourceGroup = this.familiesBySource[sourceId] = {};
  16271. }
  16272. var sourceLayerId = layer$1.sourceLayer;
  16273. var sourceLayerFamilies = sourceGroup[sourceLayerId];
  16274. if (!sourceLayerFamilies) {
  16275. sourceLayerFamilies = sourceGroup[sourceLayerId] = [];
  16276. }
  16277. sourceLayerFamilies.push(layers);
  16278. }
  16279. };
  16280. WebWorkerTransfer.register('FeatureIndex', FeatureIndex, {omit: ['rawTileData', 'sourceLayerCoder']});
  16281. function MVTWorkTile(parameters, transferableObjects) {
  16282. var pbfData = parameters.pbfData;
  16283. var layers = parameters.layers;
  16284. var imageMap = parameters.imageMap;
  16285. var serializeObj = WebWorkerTransfer.deserialize(parameters.serializeObj);
  16286. var featureIndex = serializeObj.featureIndex;
  16287. var zoom = parameters.tileID.z;
  16288. if(!when.defined(featureIndex)){
  16289. featureIndex = new FeatureIndex(parameters.tileID);
  16290. featureIndex.bucketLayerIDs = [];
  16291. }
  16292. var result = {};
  16293. try {
  16294. var styleIndexLayer = new StyleLayerIndex(layers);
  16295. var vectorTile = loadVectorTile(pbfData);
  16296. result = parse(vectorTile, styleIndexLayer, imageMap, featureIndex, zoom, parameters.indexData);
  16297. result = WebWorkerTransfer.serialize(result, transferableObjects);
  16298. }
  16299. catch (err) {
  16300. }
  16301. return result;
  16302. }
  16303. function loadVectorTile(rawData) {
  16304. if (!when.defined(rawData)) {
  16305. return;
  16306. }
  16307. return new VectorTile(new pbf.Protobuf(rawData));
  16308. }
  16309. function parse(vectorTile, layerIndex, imageMap, featureIndex, zoom, indexData) {
  16310. var sourceLayerCoder = new DictionaryCoder(Object.keys(vectorTile.layers).sort());
  16311. var buckets = {};
  16312. var options = {
  16313. featureIndex: featureIndex,
  16314. iconDependencies: {},
  16315. patternDependencies: {},
  16316. glyphDependencies: {},
  16317. //availableImages: availableImages
  16318. };
  16319. for (var source in layerIndex.familiesBySource) {
  16320. //if (source == "") continue;
  16321. var layerFamilies = layerIndex.familiesBySource[source];
  16322. for (var sourceLayerId in layerFamilies) {
  16323. var sourceLayer = vectorTile.layers[sourceLayerId];
  16324. if (!sourceLayer) {
  16325. continue;
  16326. }
  16327. var sourceLayerIndex = sourceLayerCoder.encode(sourceLayerId);
  16328. var features = [];
  16329. for (var index = 0; index < sourceLayer.length; index++) {
  16330. var feature = sourceLayer.feature(index);
  16331. features.push({feature: feature, index: index, sourceLayerIndex: sourceLayerIndex});
  16332. }
  16333. for (var i = 0, list = layerFamilies[sourceLayerId]; i < list.length; i += 1) {
  16334. var family = list[i];
  16335. var layer = family[0];
  16336. // if(defined(layer.minzoom) && zoom < Math.floor(layer.minzoom)){
  16337. // continue;
  16338. // }
  16339. // if(defined(layer.maxzoom) && zoom >= layer.maxzoom){
  16340. // continue;
  16341. // }
  16342. if (layer.visibility === 'none') {
  16343. continue;
  16344. }
  16345. //recalculateLayers(family, this.zoom, availableImages);
  16346. recalculateLayers(family, 0, null);
  16347. var bucket = buckets[layer.id] = layer.createBucket({
  16348. index: featureIndex.bucketLayerIDs.length,
  16349. layers: family,
  16350. // zoom: this.zoom,
  16351. // pixelRatio: this.pixelRatio,
  16352. // overscaling : this.overscaling,
  16353. // collisionBoxArray: this.collisionBoxArray,
  16354. sourceLayerIndex: sourceLayerIndex,
  16355. //sourceID: this.source
  16356. });
  16357. if (when.defined(indexData) && when.defined(indexData[layer.id])) {
  16358. options.indexData = indexData[layer.id];
  16359. }
  16360. bucket.populate(features, options);
  16361. featureIndex.bucketLayerIDs.push(family.map(function (l) { return l.id; }));
  16362. }
  16363. }
  16364. }
  16365. var imageAtlas = null;
  16366. for (var key in buckets) {
  16367. var bucket = buckets[key];
  16368. if (bucket.hasPattern &&
  16369. (bucket instanceof LineBucket || bucket instanceof FillBucket)) {
  16370. //recalculateLayers(bucket.layers, this.zoom, availableImages);
  16371. if(imageAtlas == null){
  16372. imageAtlas = new ImageAtlas({}, imageMap);
  16373. }
  16374. bucket.addFeatures(options, imageAtlas.patternPositions);
  16375. }
  16376. }
  16377. return {
  16378. buckets : buckets,
  16379. imageAtlas : imageAtlas,
  16380. featureIndex : featureIndex
  16381. };
  16382. }
  16383. function recalculateLayers(layers, zoom, availableImages) {
  16384. // Layers are shared and may have been used by a WorkerTile with a different zoom.
  16385. var parameters = new EvaluationParameters$1(zoom);
  16386. for (var i = 0, list = layers; i < list.length; i += 1) {
  16387. var layer = list[i];
  16388. layer.recalculate(parameters, availableImages);
  16389. }
  16390. }
  16391. var MVTWorkTile$1 = createTaskProcessorWorker(MVTWorkTile);
  16392. return MVTWorkTile$1;
  16393. });