MVTWorkTile.js 677 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647
  1. /**
  2. * Cesium - https://github.com/CesiumGS/cesium
  3. *
  4. * Copyright 2011-2020 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/CesiumGS/cesium/blob/master/LICENSE.md for full licensing details.
  22. */
  23. define(['./when-8d13db60', './createTaskProcessorWorker', './earcut-2.2.1-b404d9e6', './pbf-9fe59c76'], function (when, createTaskProcessorWorker, earcut2_2_1, 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. if(this.layoutVertexArray == null) {
  4281. return;
  4282. }
  4283. this.layoutVertexBuffer = context.createVertexBuffer(this.layoutVertexArray, members$3);
  4284. this.indexBuffer = context.createIndexBuffer(this.indexArray);
  4285. }
  4286. this.programConfigurations.upload(context);
  4287. this.uploaded = true;
  4288. };
  4289. LineBucket.prototype.destroy = function destroy() {
  4290. if (!this.layoutVertexBuffer) {
  4291. return;
  4292. }
  4293. this.layoutVertexBuffer.destroy();
  4294. this.indexBuffer.destroy();
  4295. this.programConfigurations.destroy();
  4296. this.segments.destroy();
  4297. };
  4298. LineBucket.prototype.clear = function clear() {
  4299. if (when.defined(this.layoutVertexArray)) {
  4300. this.layoutVertexArray = null;
  4301. }
  4302. if (when.defined(this.indexArray)) {
  4303. this.indexArray = null;
  4304. }
  4305. };
  4306. LineBucket.prototype.addFeature = function addFeature(feature, geometry, index, imagePositions) {
  4307. var layout = this.layers[0].layout;
  4308. var join = layout.get('line-join').evaluate(feature, {});
  4309. var cap = layout.get('line-cap');
  4310. var miterLimit = layout.get('line-miter-limit');
  4311. var roundLimit = layout.get('line-round-limit');
  4312. for (var i = 0, list = geometry; i < list.length; i += 1) {
  4313. var line = list[i];
  4314. this.addLine(line, feature, join, cap, miterLimit, roundLimit, index, imagePositions);
  4315. }
  4316. };
  4317. LineBucket.prototype.addLine = function addLine(vertices, feature, join, cap, miterLimit, roundLimit, index, imagePositions) {
  4318. this.distance = 0;
  4319. this.scaledDistance = 0;
  4320. this.totalDistance = 0;
  4321. if (!!feature.properties &&
  4322. feature.properties.hasOwnProperty('mapbox_clip_start') &&
  4323. feature.properties.hasOwnProperty('mapbox_clip_end')) {
  4324. this.clipStart = +feature.properties['mapbox_clip_start'];
  4325. this.clipEnd = +feature.properties['mapbox_clip_end'];
  4326. // Calculate the total distance, in tile units, of this tiled line feature
  4327. for (var i = 0; i < vertices.length - 1; i++) {
  4328. this.totalDistance += vertices[i].dist(vertices[i + 1]);
  4329. }
  4330. }
  4331. var isPolygon = VectorTileFeatureTypes[feature.type] === 'Polygon';
  4332. // If the line has duplicate vertices at the ends, adjust start/length to remove them.
  4333. var len = vertices.length;
  4334. while (len >= 2 && vertices[len - 1].equals(vertices[len - 2])) {
  4335. len--;
  4336. }
  4337. var first = 0;
  4338. while (first < len - 1 && vertices[first].equals(vertices[first + 1])) {
  4339. first++;
  4340. }
  4341. // Ignore invalid geometry.
  4342. if (len < (isPolygon ? 3 : 2)) {
  4343. return;
  4344. }
  4345. if (join === 'bevel') {
  4346. miterLimit = 1.05;
  4347. }
  4348. var sharpCornerOffset = this.overscaling <= 16 ?
  4349. SHARP_CORNER_OFFSET * EXTENT / (512 * this.overscaling) :
  4350. 0;
  4351. // we could be more precise, but it would only save a negligible amount of space
  4352. var segment = this.segments.prepareSegment(len * 10, this.layoutVertexArray, this.indexArray);
  4353. var currentVertex;
  4354. var prevVertex = ((undefined ) );
  4355. var nextVertex = ((undefined ) );
  4356. var prevNormal = ((undefined ) );
  4357. var nextNormal = ((undefined ) );
  4358. // the last two vertices added
  4359. this.e1 = this.e2 = -1;
  4360. if (isPolygon) {
  4361. currentVertex = vertices[len - 2];
  4362. nextNormal = vertices[first].sub(currentVertex)._unit()._perp();
  4363. }
  4364. for (var i$1 = first; i$1 < len; i$1++) {
  4365. nextVertex = isPolygon && i$1 === len - 1 ?
  4366. vertices[first + 1] : // if the line is closed, we treat the last vertex like the first
  4367. vertices[i$1 + 1]; // just the next vertex
  4368. // if two consecutive vertices exist, skip the current one
  4369. if (nextVertex && vertices[i$1].equals(nextVertex)) {
  4370. continue;
  4371. }
  4372. if (nextNormal) {
  4373. prevNormal = nextNormal;
  4374. }
  4375. if (currentVertex) {
  4376. prevVertex = currentVertex;
  4377. }
  4378. currentVertex = vertices[i$1];
  4379. // Calculate the normal towards the next vertex in this line. In case
  4380. // there is no next vertex, pretend that the line is continuing straight,
  4381. // meaning that we are just using the previous normal.
  4382. nextNormal = nextVertex ? nextVertex.sub(currentVertex)._unit()._perp() : prevNormal;
  4383. // If we still don't have a previous normal, this is the beginning of a
  4384. // non-closed line, so we're doing a straight "join".
  4385. prevNormal = prevNormal || nextNormal;
  4386. // Determine the normal of the join extrusion. It is the angle bisector
  4387. // of the segments between the previous line and the next line.
  4388. // In the case of 180° angles, the prev and next normals cancel each other out:
  4389. // prevNormal + nextNormal = (0, 0), its magnitude is 0, so the unit vector would be
  4390. // undefined. In that case, we're keeping the joinNormal at (0, 0), so that the cosHalfAngle
  4391. // below will also become 0 and miterLength will become Infinity.
  4392. var joinNormal = prevNormal.add(nextNormal);
  4393. if (joinNormal.x !== 0 || joinNormal.y !== 0) {
  4394. joinNormal._unit();
  4395. }
  4396. /* joinNormal prevNormal
  4397. * ↖ ↑
  4398. * .________. prevVertex
  4399. * |
  4400. * nextNormal ← | currentVertex
  4401. * |
  4402. * nextVertex !
  4403. *
  4404. */
  4405. // calculate cosines of the angle (and its half) using dot product
  4406. var cosAngle = prevNormal.x * nextNormal.x + prevNormal.y * nextNormal.y;
  4407. var cosHalfAngle = joinNormal.x * nextNormal.x + joinNormal.y * nextNormal.y;
  4408. // Calculate the length of the miter (the ratio of the miter to the width)
  4409. // as the inverse of cosine of the angle between next and join normals
  4410. var miterLength = cosHalfAngle !== 0 ? 1 / cosHalfAngle : Infinity;
  4411. // approximate angle from cosine
  4412. var approxAngle = 2 * Math.sqrt(2 - 2 * cosHalfAngle);
  4413. var isSharpCorner = cosHalfAngle < COS_HALF_SHARP_CORNER && prevVertex && nextVertex;
  4414. var lineTurnsLeft = prevNormal.x * nextNormal.y - prevNormal.y * nextNormal.x > 0;
  4415. if (isSharpCorner && i$1 > first) {
  4416. var prevSegmentLength = currentVertex.dist(prevVertex);
  4417. if (prevSegmentLength > 2 * sharpCornerOffset) {
  4418. var newPrevVertex = currentVertex.sub(currentVertex.sub(prevVertex)._mult(sharpCornerOffset / prevSegmentLength)._round());
  4419. this.updateDistance(prevVertex, newPrevVertex);
  4420. this.addCurrentVertex(newPrevVertex, prevNormal, 0, 0, segment);
  4421. prevVertex = newPrevVertex;
  4422. }
  4423. }
  4424. // The join if a middle vertex, otherwise the cap.
  4425. var middleVertex = prevVertex && nextVertex;
  4426. var currentJoin = middleVertex ? join : isPolygon ? 'butt' : cap;
  4427. if (middleVertex && currentJoin === 'round') {
  4428. if (miterLength < roundLimit) {
  4429. currentJoin = 'miter';
  4430. } else if (miterLength <= 2) {
  4431. currentJoin = 'fakeround';
  4432. }
  4433. }
  4434. if (currentJoin === 'miter' && miterLength > miterLimit) {
  4435. currentJoin = 'bevel';
  4436. }
  4437. if (currentJoin === 'bevel') {
  4438. // The maximum extrude length is 128 / 63 = 2 times the width of the line
  4439. // so if miterLength >= 2 we need to draw a different type of bevel here.
  4440. if (miterLength > 2) {
  4441. currentJoin = 'flipbevel';
  4442. }
  4443. // If the miterLength is really small and the line bevel wouldn't be visible,
  4444. // just draw a miter join to save a triangle.
  4445. if (miterLength < miterLimit) {
  4446. currentJoin = 'miter';
  4447. }
  4448. }
  4449. // Calculate how far along the line the currentVertex is
  4450. if (prevVertex) {
  4451. this.updateDistance(prevVertex, currentVertex);
  4452. }
  4453. if (currentJoin === 'miter') {
  4454. joinNormal._mult(miterLength);
  4455. this.addCurrentVertex(currentVertex, joinNormal, 0, 0, segment);
  4456. } else if (currentJoin === 'flipbevel') {
  4457. // miter is too big, flip the direction to make a beveled join
  4458. if (miterLength > 100) {
  4459. // Almost parallel lines
  4460. joinNormal = nextNormal.mult(-1);
  4461. } else {
  4462. var bevelLength = miterLength * prevNormal.add(nextNormal).mag() / prevNormal.sub(nextNormal).mag();
  4463. joinNormal._perp()._mult(bevelLength * (lineTurnsLeft ? -1 : 1));
  4464. }
  4465. this.addCurrentVertex(currentVertex, joinNormal, 0, 0, segment);
  4466. this.addCurrentVertex(currentVertex, joinNormal.mult(-1), 0, 0, segment);
  4467. } else if (currentJoin === 'bevel' || currentJoin === 'fakeround') {
  4468. var offset = -Math.sqrt(miterLength * miterLength - 1);
  4469. var offsetA = lineTurnsLeft ? offset : 0;
  4470. var offsetB = lineTurnsLeft ? 0 : offset;
  4471. // Close previous segment with a bevel
  4472. if (prevVertex) {
  4473. this.addCurrentVertex(currentVertex, prevNormal, offsetA, offsetB, segment);
  4474. }
  4475. if (currentJoin === 'fakeround') {
  4476. // The join angle is sharp enough that a round join would be visible.
  4477. // Bevel joins fill the gap between segments with a single pie slice triangle.
  4478. // Create a round join by adding multiple pie slices. The join isn't actually round, but
  4479. // it looks like it is at the sizes we render lines at.
  4480. // pick the number of triangles for approximating round join by based on the angle between normals
  4481. var n = Math.round((approxAngle * 180 / Math.PI) / DEG_PER_TRIANGLE);
  4482. for (var m = 1; m < n; m++) {
  4483. var t = m / n;
  4484. if (t !== 0.5) {
  4485. // approximate spherical interpolation https://observablehq.com/@mourner/approximating-geometric-slerp
  4486. var t2 = t - 0.5;
  4487. var A = 1.0904 + cosAngle * (-3.2452 + cosAngle * (3.55645 - cosAngle * 1.43519));
  4488. var B = 0.848013 + cosAngle * (-1.06021 + cosAngle * 0.215638);
  4489. t = t + t * t2 * (t - 1) * (A * t2 * t2 + B);
  4490. }
  4491. var extrude = nextNormal.sub(prevNormal)._mult(t)._add(prevNormal)._unit()._mult(lineTurnsLeft ? -1 : 1);
  4492. this.addHalfVertex(currentVertex, extrude.x, extrude.y, false, lineTurnsLeft, 0, segment);
  4493. }
  4494. }
  4495. if (nextVertex) {
  4496. // Start next segment
  4497. this.addCurrentVertex(currentVertex, nextNormal, -offsetA, -offsetB, segment);
  4498. }
  4499. } else if (currentJoin === 'butt') {
  4500. this.addCurrentVertex(currentVertex, joinNormal, 0, 0, segment); // butt cap
  4501. } else if (currentJoin === 'square') {
  4502. var offset$1 = prevVertex ? 1 : -1; // closing or starting square cap
  4503. this.addCurrentVertex(currentVertex, joinNormal, offset$1, offset$1, segment);
  4504. } else if (currentJoin === 'round') {
  4505. if (prevVertex) {
  4506. // Close previous segment with butt
  4507. this.addCurrentVertex(currentVertex, prevNormal, 0, 0, segment);
  4508. // Add round cap or linejoin at end of segment
  4509. this.addCurrentVertex(currentVertex, prevNormal, 1, 1, segment, true);
  4510. }
  4511. if (nextVertex) {
  4512. // Add round cap before first segment
  4513. this.addCurrentVertex(currentVertex, nextNormal, -1, -1, segment, true);
  4514. // Start next segment with a butt
  4515. this.addCurrentVertex(currentVertex, nextNormal, 0, 0, segment);
  4516. }
  4517. }
  4518. if (isSharpCorner && i$1 < len - 1) {
  4519. var nextSegmentLength = currentVertex.dist(nextVertex);
  4520. if (nextSegmentLength > 2 * sharpCornerOffset) {
  4521. var newCurrentVertex = currentVertex.add(nextVertex.sub(currentVertex)._mult(sharpCornerOffset / nextSegmentLength)._round());
  4522. this.updateDistance(currentVertex, newCurrentVertex);
  4523. this.addCurrentVertex(newCurrentVertex, nextNormal, 0, 0, segment);
  4524. currentVertex = newCurrentVertex;
  4525. }
  4526. }
  4527. }
  4528. this.programConfigurations.populatePaintArrays(this.layoutVertexArray.length, feature, index, imagePositions);
  4529. };
  4530. /**
  4531. * Add two vertices to the buffers.
  4532. *
  4533. * @param p the line vertex to add buffer vertices for
  4534. * @param normal vertex normal
  4535. * @param endLeft extrude to shift the left vertex along the line
  4536. * @param endRight extrude to shift the left vertex along the line
  4537. * @param segment the segment object to add the vertex to
  4538. * @param round whether this is a round cap
  4539. * @private
  4540. */
  4541. LineBucket.prototype.addCurrentVertex = function addCurrentVertex(p, normal, endLeft, endRight, segment, round) {
  4542. if (round === void 0) round = false;
  4543. // left and right extrude vectors, perpendicularly shifted by endLeft/endRight
  4544. var leftX = normal.x + normal.y * endLeft;
  4545. var leftY = normal.y - normal.x * endLeft;
  4546. var rightX = -normal.x + normal.y * endRight;
  4547. var rightY = -normal.y - normal.x * endRight;
  4548. this.addHalfVertex(p, leftX, leftY, round, false, endLeft, segment);
  4549. this.addHalfVertex(p, rightX, rightY, round, true, -endRight, segment);
  4550. // There is a maximum "distance along the line" that we can store in the buffers.
  4551. // When we get close to the distance, reset it to zero and add the vertex again with
  4552. // a distance of zero. The max distance is determined by the number of bits we allocate
  4553. // to `linesofar`.
  4554. if (this.distance > MAX_LINE_DISTANCE / 2 && this.totalDistance === 0) {
  4555. this.distance = 0;
  4556. this.addCurrentVertex(p, normal, endLeft, endRight, segment, round);
  4557. }
  4558. };
  4559. LineBucket.prototype.addHalfVertex = function addHalfVertex(ref, extrudeX, extrudeY, round, up, dir, segment) {
  4560. var x = ref.x;
  4561. var y = ref.y;
  4562. // scale down so that we can store longer distances while sacrificing precision.
  4563. var linesofar = this.scaledDistance * LINE_DISTANCE_SCALE;
  4564. this.layoutVertexArray.emplaceBack(
  4565. // a_pos_normal
  4566. // Encode round/up the least significant bits
  4567. (x << 1) + (round ? 1 : 0),
  4568. (y << 1) + (up ? 1 : 0),
  4569. // a_data
  4570. // add 128 to store a byte in an unsigned byte
  4571. Math.round(EXTRUDE_SCALE * extrudeX) + 128,
  4572. Math.round(EXTRUDE_SCALE * extrudeY) + 128,
  4573. // Encode the -1/0/1 direction value into the first two bits of .z of a_data.
  4574. // Combine it with the lower 6 bits of `linesofar` (shifted by 2 bites to make
  4575. // room for the direction value). The upper 8 bits of `linesofar` are placed in
  4576. // the `w` component.
  4577. ((dir === 0 ? 0 : (dir < 0 ? -1 : 1)) + 1) | ((linesofar & 0x3F) << 2),
  4578. linesofar >> 6);
  4579. var e = segment.vertexLength++;
  4580. if (this.e1 >= 0 && this.e2 >= 0) {
  4581. this.indexArray.emplaceBack(this.e1, this.e2, e);
  4582. segment.primitiveLength++;
  4583. }
  4584. if (up) {
  4585. this.e2 = e;
  4586. } else {
  4587. this.e1 = e;
  4588. }
  4589. };
  4590. LineBucket.prototype.updateDistance = function updateDistance(prev, next) {
  4591. this.distance += prev.dist(next);
  4592. // Knowing the ratio of the full linestring covered by this tiled feature, as well
  4593. // as the total distance (in tile units) of this tiled feature, and the distance
  4594. // (in tile units) of the current vertex, we can determine the relative distance
  4595. // of this vertex along the full linestring feature and scale it to [0, 2^15)
  4596. this.scaledDistance = this.totalDistance > 0 ?
  4597. (this.clipStart + (this.clipEnd - this.clipStart) * this.distance / this.totalDistance) * (MAX_LINE_DISTANCE - 1) :
  4598. this.distance;
  4599. };
  4600. WebWorkerTransfer.register('LineBucket', LineBucket, {omit: ['layers', 'patternFeatures']});
  4601. function quickselect(arr, k, left, right, compare) {
  4602. quickselectStep(arr, k, left || 0, right || (arr.length - 1), compare || defaultCompare);
  4603. }
  4604. function quickselectStep(arr, k, left, right, compare) {
  4605. while (right > left) {
  4606. if (right - left > 600) {
  4607. var n = right - left + 1;
  4608. var m = k - left + 1;
  4609. var z = Math.log(n);
  4610. var s = 0.5 * Math.exp(2 * z / 3);
  4611. var sd = 0.5 * Math.sqrt(z * s * (n - s) / n) * (m - n / 2 < 0 ? -1 : 1);
  4612. var newLeft = Math.max(left, Math.floor(k - m * s / n + sd));
  4613. var newRight = Math.min(right, Math.floor(k + (n - m) * s / n + sd));
  4614. quickselectStep(arr, k, newLeft, newRight, compare);
  4615. }
  4616. var t = arr[k];
  4617. var i = left;
  4618. var j = right;
  4619. swap$1(arr, left, k);
  4620. if (compare(arr[right], t) > 0) swap$1(arr, left, right);
  4621. while (i < j) {
  4622. swap$1(arr, i, j);
  4623. i++;
  4624. j--;
  4625. while (compare(arr[i], t) < 0) i++;
  4626. while (compare(arr[j], t) > 0) j--;
  4627. }
  4628. if (compare(arr[left], t) === 0) swap$1(arr, left, j);
  4629. else {
  4630. j++;
  4631. swap$1(arr, j, right);
  4632. }
  4633. if (j <= k) left = j + 1;
  4634. if (k <= j) right = j - 1;
  4635. }
  4636. }
  4637. function swap$1(arr, i, j) {
  4638. var tmp = arr[i];
  4639. arr[i] = arr[j];
  4640. arr[j] = tmp;
  4641. }
  4642. function defaultCompare(a, b) {
  4643. return a < b ? -1 : a > b ? 1 : 0;
  4644. }
  4645. /**
  4646. * Returns the signed area for the polygon ring. Postive areas are exterior rings and
  4647. * have a clockwise winding. Negative areas are interior rings and have a counter clockwise
  4648. * ordering.
  4649. *
  4650. * @private
  4651. * @param ring Exterior or interior ring
  4652. */
  4653. function calculateSignedArea(ring) {
  4654. var sum = 0;
  4655. for (var i = 0, len = ring.length, j = len - 1, p1 = (void 0), p2 = (void 0); i < len; j = i++) {
  4656. p1 = ring[i];
  4657. p2 = ring[j];
  4658. sum += (p2.x - p1.x) * (p1.y + p2.y);
  4659. }
  4660. return sum;
  4661. }
  4662. // classifies an array of rings into polygons with outer rings and holes
  4663. function classifyRings(rings, maxRings) {
  4664. var len = rings.length;
  4665. if (len <= 1) {
  4666. return [rings];
  4667. }
  4668. var polygons = [];
  4669. var polygon,
  4670. ccw;
  4671. for (var i = 0; i < len; i++) {
  4672. var area = calculateSignedArea(rings[i]);
  4673. if (area === 0) {
  4674. continue;
  4675. }
  4676. (rings[i] ).area = Math.abs(area);
  4677. if (ccw === undefined) {
  4678. ccw = area < 0;
  4679. }
  4680. if (ccw === area < 0) {
  4681. if (polygon) {
  4682. polygons.push(polygon);
  4683. }
  4684. polygon = [rings[i]];
  4685. } else {
  4686. (polygon ).push(rings[i]);
  4687. }
  4688. }
  4689. if (polygon) {
  4690. polygons.push(polygon);
  4691. }
  4692. // Earcut performance degrades with the # of rings in a polygon. For this
  4693. // reason, we limit strip out all but the `maxRings` largest rings.
  4694. if (maxRings > 1) {
  4695. for (var j = 0; j < polygons.length; j++) {
  4696. if (polygons[j].length <= maxRings) {
  4697. continue;
  4698. }
  4699. quickselect(polygons[j], maxRings, 1, polygons[j].length - 1, compareAreas);
  4700. polygons[j] = polygons[j].slice(0, maxRings);
  4701. }
  4702. }
  4703. return polygons;
  4704. }
  4705. function compareAreas(a, b) {
  4706. return b.area - a.area;
  4707. }
  4708. var StructArrayLayout2i4 = /*@__PURE__*/(function (StructArray) {
  4709. function StructArrayLayout2i4() {
  4710. StructArray.apply(this, arguments);
  4711. }
  4712. if (StructArray) StructArrayLayout2i4.__proto__ = StructArray;
  4713. StructArrayLayout2i4.prototype = Object.create(StructArray && StructArray.prototype);
  4714. StructArrayLayout2i4.prototype.constructor = StructArrayLayout2i4;
  4715. StructArrayLayout2i4.prototype._refreshViews = function _refreshViews() {
  4716. this.uint8 = new Uint8Array(this.arrayBuffer);
  4717. this.int16 = new Int16Array(this.arrayBuffer);
  4718. };
  4719. StructArrayLayout2i4.prototype.emplaceBack = function emplaceBack(v0, v1) {
  4720. var i = this.length;
  4721. this.resize(i + 1);
  4722. return this.emplace(i, v0, v1);
  4723. };
  4724. StructArrayLayout2i4.prototype.emplace = function emplace(i, v0, v1) {
  4725. var o2 = i * 2;
  4726. this.int16[o2 + 0] = v0;
  4727. this.int16[o2 + 1] = v1;
  4728. return i;
  4729. };
  4730. return StructArrayLayout2i4;
  4731. }(StructArray));
  4732. StructArrayLayout2i4.prototype.bytesPerElement = 4;
  4733. WebWorkerTransfer.register('StructArrayLayout2i4', StructArrayLayout2i4);
  4734. var StructArrayLayout2ui4 = /*@__PURE__*/(function (StructArray) {
  4735. function StructArrayLayout2ui4() {
  4736. StructArray.apply(this, arguments);
  4737. }
  4738. if (StructArray) StructArrayLayout2ui4.__proto__ = StructArray;
  4739. StructArrayLayout2ui4.prototype = Object.create(StructArray && StructArray.prototype);
  4740. StructArrayLayout2ui4.prototype.constructor = StructArrayLayout2ui4;
  4741. StructArrayLayout2ui4.prototype._refreshViews = function _refreshViews() {
  4742. this.uint8 = new Uint8Array(this.arrayBuffer);
  4743. this.uint16 = new Uint16Array(this.arrayBuffer);
  4744. };
  4745. StructArrayLayout2ui4.prototype.emplaceBack = function emplaceBack(v0, v1) {
  4746. var i = this.length;
  4747. this.resize(i + 1);
  4748. return this.emplace(i, v0, v1);
  4749. };
  4750. StructArrayLayout2ui4.prototype.emplace = function emplace(i, v0, v1) {
  4751. var o2 = i * 2;
  4752. this.uint16[o2 + 0] = v0;
  4753. this.uint16[o2 + 1] = v1;
  4754. return i;
  4755. };
  4756. return StructArrayLayout2ui4;
  4757. }(StructArray));
  4758. StructArrayLayout2ui4.prototype.bytesPerElement = 4;
  4759. WebWorkerTransfer.register('StructArrayLayout2ui4', StructArrayLayout2ui4);
  4760. function hasPattern(type, layers, options) {
  4761. var patterns = options.patternDependencies;
  4762. var hasPattern = false;
  4763. for (var i = 0, list = layers; i < list.length; i += 1) {
  4764. var layer = list[i];
  4765. var patternProperty = layer.paint.get((type + "-pattern"));
  4766. if (!patternProperty.isConstant()) {
  4767. hasPattern = true;
  4768. }
  4769. var constantPattern = patternProperty.constantOr(null);
  4770. if (constantPattern) {
  4771. hasPattern = true;
  4772. patterns[constantPattern.to] = true;
  4773. patterns[constantPattern.from] = true;
  4774. }
  4775. }
  4776. return hasPattern;
  4777. }
  4778. // Copyright 2010 The Emscripten Authors. All rights reserved.
  4779. // Emscripten is available under two separate licenses, the MIT license and the
  4780. // University of Illinois/NCSA Open Source License. Both these licenses can be
  4781. // found in the LICENSE file.
  4782. // The Module object: Our interface to the outside world. We import
  4783. // and export values on it. There are various ways Module can be used:
  4784. // 1. Not defined. We create it here
  4785. // 2. A function parameter, function(Module) { ..generated code.. }
  4786. // 3. pre-run appended it, var Module = {}; ..generated code..
  4787. // 4. External script tag defines var Module.
  4788. // We need to check if Module already exists (e.g. case 3 above).
  4789. // Substitution will be replaced with actual code on later stage of the build,
  4790. // this way Closure Compiler will not mangle it (e.g. case 4. above).
  4791. // Note that if you want to run closure, and also to use Module
  4792. // after the generated code, you will need to define var Module = {};
  4793. // before the code. Then that object will be used in the code, and you
  4794. // can continue to use Module afterwards as well.
  4795. if (typeof WebAssembly !== 'undefined') {
  4796. var Module = typeof Module !== 'undefined' ? Module : {};
  4797. // --pre-jses are emitted after the Module integration code, so that they can
  4798. // refer to Module (if they choose; they can also define Module)
  4799. // {{PRE_JSES}}
  4800. // Sometimes an existing Module object exists with properties
  4801. // meant to overwrite the default module functionality. Here
  4802. // we collect those properties and reapply _after_ we configure
  4803. // the current environment's defaults to avoid having to be so
  4804. // defensive during initialization.
  4805. var moduleOverrides = {};
  4806. var key;
  4807. for (key in Module) {
  4808. if (Module.hasOwnProperty(key)) {
  4809. moduleOverrides[key] = Module[key];
  4810. }
  4811. }
  4812. Module['arguments'] = [];
  4813. Module['thisProgram'] = './this.program';
  4814. Module['quit'] = function(status, toThrow) {
  4815. throw toThrow;
  4816. };
  4817. Module['preRun'] = [];
  4818. Module['postRun'] = [];
  4819. // Determine the runtime environment we are in. You can customize this by
  4820. // setting the ENVIRONMENT setting at compile time (see settings.js).
  4821. var ENVIRONMENT_IS_WEB = false;
  4822. var ENVIRONMENT_IS_WORKER = false;
  4823. var ENVIRONMENT_IS_NODE = false;
  4824. var ENVIRONMENT_HAS_NODE = false;
  4825. var ENVIRONMENT_IS_SHELL = false;
  4826. ENVIRONMENT_IS_WEB = typeof window === 'object';
  4827. ENVIRONMENT_IS_WORKER = typeof importScripts === 'function';
  4828. // A web environment like Electron.js can have Node enabled, so we must
  4829. // distinguish between Node-enabled environments and Node environments per se.
  4830. // This will allow the former to do things like mount NODEFS.
  4831. ENVIRONMENT_HAS_NODE = typeof process === 'object' && typeof require === 'function';
  4832. ENVIRONMENT_IS_NODE = ENVIRONMENT_HAS_NODE && !ENVIRONMENT_IS_WEB && !ENVIRONMENT_IS_WORKER;
  4833. ENVIRONMENT_IS_SHELL = !ENVIRONMENT_IS_WEB && !ENVIRONMENT_IS_NODE && !ENVIRONMENT_IS_WORKER;
  4834. if (Module['ENVIRONMENT']) {
  4835. 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)');
  4836. }
  4837. // Three configurations we can be running in:
  4838. // 1) We could be the application main() thread running in the main JS UI thread. (ENVIRONMENT_IS_WORKER == false and ENVIRONMENT_IS_PTHREAD == false)
  4839. // 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)
  4840. // 3) We could be an application pthread running in a worker. (ENVIRONMENT_IS_WORKER == true and ENVIRONMENT_IS_PTHREAD == true)
  4841. // `/` should be present at the end if `scriptDirectory` is not empty
  4842. var scriptDirectory = '';
  4843. function locateFile(path) {
  4844. if (Module['locateFile']) {
  4845. return Module['locateFile'](path, scriptDirectory);
  4846. } else {
  4847. return scriptDirectory + path;
  4848. }
  4849. }
  4850. if (ENVIRONMENT_IS_NODE) {
  4851. scriptDirectory = __dirname + '/';
  4852. // Expose functionality in the same simple way that the shells work
  4853. // Note that we pollute the global namespace here, otherwise we break in node
  4854. var nodeFS;
  4855. var nodePath;
  4856. Module['read'] = function shell_read(filename, binary) {
  4857. var ret;
  4858. if (!nodeFS) nodeFS = require('fs');
  4859. if (!nodePath) nodePath = require('path');
  4860. filename = nodePath['normalize'](filename);
  4861. ret = nodeFS['readFileSync'](filename);
  4862. return binary ? ret : ret.toString();
  4863. };
  4864. Module['readBinary'] = function readBinary(filename) {
  4865. var ret = Module['read'](filename, true);
  4866. if (!ret.buffer) {
  4867. ret = new Uint8Array(ret);
  4868. }
  4869. assert(ret.buffer);
  4870. return ret;
  4871. };
  4872. if (process['argv'].length > 1) {
  4873. Module['thisProgram'] = process['argv'][1].replace(/\\/g, '/');
  4874. }
  4875. Module['arguments'] = process['argv'].slice(2);
  4876. if (typeof module !== 'undefined') {
  4877. module['exports'] = Module;
  4878. }
  4879. process['on']('uncaughtException', function(ex) {
  4880. // suppress ExitStatus exceptions from showing an error
  4881. if (!(ex instanceof ExitStatus)) {
  4882. throw ex;
  4883. }
  4884. });
  4885. // Currently node will swallow unhandled rejections, but this behavior is
  4886. // deprecated, and in the future it will exit with error status.
  4887. process['on']('unhandledRejection', abort);
  4888. Module['quit'] = function(status) {
  4889. process['exit'](status);
  4890. };
  4891. Module['inspect'] = function () { return '[Emscripten Module object]'; };
  4892. } else
  4893. if (ENVIRONMENT_IS_SHELL) {
  4894. if (typeof read != 'undefined') {
  4895. Module['read'] = function shell_read(f) {
  4896. return read(f);
  4897. };
  4898. }
  4899. Module['readBinary'] = function readBinary(f) {
  4900. var data;
  4901. if (typeof readbuffer === 'function') {
  4902. return new Uint8Array(readbuffer(f));
  4903. }
  4904. data = read(f, 'binary');
  4905. assert(typeof data === 'object');
  4906. return data;
  4907. };
  4908. if (typeof scriptArgs != 'undefined') {
  4909. Module['arguments'] = scriptArgs;
  4910. } else if (typeof arguments != 'undefined') {
  4911. Module['arguments'] = arguments;
  4912. }
  4913. if (typeof quit === 'function') {
  4914. Module['quit'] = function(status) {
  4915. quit(status);
  4916. };
  4917. }
  4918. } else
  4919. if (ENVIRONMENT_IS_WEB || ENVIRONMENT_IS_WORKER) {
  4920. if (ENVIRONMENT_IS_WORKER) { // Check worker, not web, since window could be polyfilled
  4921. scriptDirectory = self.location.href;
  4922. } else if (document.currentScript) { // web
  4923. scriptDirectory = document.currentScript.src;
  4924. }
  4925. // blob urls look like blob:http://site.com/etc/etc and we cannot infer anything from them.
  4926. // otherwise, slice off the final part of the url to find the script directory.
  4927. // if scriptDirectory does not contain a slash, lastIndexOf will return -1,
  4928. // and scriptDirectory will correctly be replaced with an empty string.
  4929. if (scriptDirectory.indexOf('blob:') !== 0) {
  4930. scriptDirectory = scriptDirectory.substr(0, scriptDirectory.lastIndexOf('/')+1);
  4931. } else {
  4932. scriptDirectory = '';
  4933. }
  4934. Module['read'] = function shell_read(url) {
  4935. var xhr = new XMLHttpRequest();
  4936. xhr.open('GET', url, false);
  4937. xhr.send(null);
  4938. return xhr.responseText;
  4939. };
  4940. if (ENVIRONMENT_IS_WORKER) {
  4941. Module['readBinary'] = function readBinary(url) {
  4942. var xhr = new XMLHttpRequest();
  4943. xhr.open('GET', url, false);
  4944. xhr.responseType = 'arraybuffer';
  4945. xhr.send(null);
  4946. return new Uint8Array(xhr.response);
  4947. };
  4948. }
  4949. Module['readAsync'] = function readAsync(url, onload, onerror) {
  4950. var xhr = new XMLHttpRequest();
  4951. xhr.open('GET', url, true);
  4952. xhr.responseType = 'arraybuffer';
  4953. xhr.onload = function xhr_onload() {
  4954. if (xhr.status == 200 || (xhr.status == 0 && xhr.response)) { // file URLs can return 0
  4955. onload(xhr.response);
  4956. return;
  4957. }
  4958. onerror();
  4959. };
  4960. xhr.onerror = onerror;
  4961. xhr.send(null);
  4962. };
  4963. Module['setWindowTitle'] = function(title) { document.title = title; };
  4964. } else
  4965. {
  4966. throw new Error('environment detection error');
  4967. }
  4968. // Set up the out() and err() hooks, which are how we can print to stdout or
  4969. // stderr, respectively.
  4970. // If the user provided Module.print or printErr, use that. Otherwise,
  4971. // console.log is checked first, as 'print' on the web will open a print dialogue
  4972. // printErr is preferable to console.warn (works better in shells)
  4973. // bind(console) is necessary to fix IE/Edge closed dev tools panel behavior.
  4974. var out = Module['print'] || (typeof console !== 'undefined' ? console.log.bind(console) : (typeof print !== 'undefined' ? print : null));
  4975. var err = Module['printErr'] || (typeof printErr !== 'undefined' ? printErr : ((typeof console !== 'undefined' && console.warn.bind(console)) || out));
  4976. // Merge back in the overrides
  4977. for (key in moduleOverrides) {
  4978. if (moduleOverrides.hasOwnProperty(key)) {
  4979. Module[key] = moduleOverrides[key];
  4980. }
  4981. }
  4982. // Free the object hierarchy contained in the overrides, this lets the GC
  4983. // reclaim data used e.g. in memoryInitializerRequest, which is a large typed array.
  4984. moduleOverrides = undefined;
  4985. // perform assertions in shell.js after we set up out() and err(), as otherwise if an assertion fails it cannot print the message
  4986. assert(typeof Module['memoryInitializerPrefixURL'] === 'undefined', 'Module.memoryInitializerPrefixURL option was removed, use Module.locateFile instead');
  4987. assert(typeof Module['pthreadMainPrefixURL'] === 'undefined', 'Module.pthreadMainPrefixURL option was removed, use Module.locateFile instead');
  4988. assert(typeof Module['cdInitializerPrefixURL'] === 'undefined', 'Module.cdInitializerPrefixURL option was removed, use Module.locateFile instead');
  4989. assert(typeof Module['filePackagePrefixURL'] === 'undefined', 'Module.filePackagePrefixURL option was removed, use Module.locateFile instead');
  4990. // stack management, and other functionality that is provided by the compiled code,
  4991. // should not be used before it is ready
  4992. stackSave = stackRestore = stackAlloc = function() {
  4993. abort('cannot use the stack before compiled code is ready to run, and has provided stack access');
  4994. };
  4995. function warnOnce(text) {
  4996. if (!warnOnce.shown) warnOnce.shown = {};
  4997. if (!warnOnce.shown[text]) {
  4998. warnOnce.shown[text] = 1;
  4999. //err(text);
  5000. }
  5001. }
  5002. var asm2wasmImports = { // special asm2wasm imports
  5003. "f64-rem": function(x, y) {
  5004. return x % y;
  5005. },
  5006. "debugger": function() {
  5007. debugger;
  5008. }
  5009. };
  5010. var functionPointers = new Array(0);
  5011. var tempRet0 = 0;
  5012. var setTempRet0 = function(value) {
  5013. tempRet0 = value;
  5014. };
  5015. var getTempRet0 = function() {
  5016. return tempRet0;
  5017. };
  5018. // === Preamble library stuff ===
  5019. // Documentation for the public APIs defined in this file must be updated in:
  5020. // site/source/docs/api_reference/preamble.js.rst
  5021. // A prebuilt local version of the documentation is available at:
  5022. // site/build/text/docs/api_reference/preamble.js.txt
  5023. // You can also build docs locally as HTML or other formats in site/
  5024. // An online HTML version (which may be of a different version of Emscripten)
  5025. // is up at http://kripken.github.io/emscripten-site/docs/api_reference/preamble.js.html
  5026. if (typeof WebAssembly !== 'object') {
  5027. abort('No WebAssembly support found. Build with -s WASM=0 to target JavaScript instead.');
  5028. }
  5029. /** @type {function(number, string, boolean=)} */
  5030. function getValue(ptr, type, noSafe) {
  5031. type = type || 'i8';
  5032. if (type.charAt(type.length-1) === '*') type = 'i32'; // pointers are 32-bit
  5033. switch(type) {
  5034. case 'i1': return HEAP8[((ptr)>>0)];
  5035. case 'i8': return HEAP8[((ptr)>>0)];
  5036. case 'i16': return HEAP16[((ptr)>>1)];
  5037. case 'i32': return HEAP32[((ptr)>>2)];
  5038. case 'i64': return HEAP32[((ptr)>>2)];
  5039. case 'float': return HEAPF32[((ptr)>>2)];
  5040. case 'double': return HEAPF64[((ptr)>>3)];
  5041. default: abort('invalid type for getValue: ' + type);
  5042. }
  5043. return null;
  5044. }
  5045. // Wasm globals
  5046. var wasmMemory;
  5047. // Potentially used for direct table calls.
  5048. var wasmTable;
  5049. //========================================
  5050. // Runtime essentials
  5051. //========================================
  5052. // whether we are quitting the application. no code should run after this.
  5053. // set in exit() and abort()
  5054. var ABORT = false;
  5055. /** @type {function(*, string=)} */
  5056. function assert(condition, text) {
  5057. if (!condition) {
  5058. abort('Assertion failed: ' + text);
  5059. }
  5060. }
  5061. // Returns the C function with a specified identifier (for C++, you need to do manual name mangling)
  5062. function getCFunc(ident) {
  5063. var func = Module['_' + ident]; // closure exported function
  5064. assert(func, 'Cannot call unknown function ' + ident + ', make sure it is exported');
  5065. return func;
  5066. }
  5067. // C calling interface.
  5068. function ccall(ident, returnType, argTypes, args, opts) {
  5069. // For fast lookup of conversion functions
  5070. var toC = {
  5071. 'string': function(str) {
  5072. var ret = 0;
  5073. if (str !== null && str !== undefined && str !== 0) { // null string
  5074. // at most 4 bytes per UTF-8 code point, +1 for the trailing '\0'
  5075. var len = (str.length << 2) + 1;
  5076. ret = stackAlloc(len);
  5077. stringToUTF8(str, ret, len);
  5078. }
  5079. return ret;
  5080. },
  5081. 'array': function(arr) {
  5082. var ret = stackAlloc(arr.length);
  5083. writeArrayToMemory(arr, ret);
  5084. return ret;
  5085. }
  5086. };
  5087. function convertReturnValue(ret) {
  5088. if (returnType === 'string') return UTF8ToString(ret);
  5089. if (returnType === 'boolean') return Boolean(ret);
  5090. return ret;
  5091. }
  5092. var func = getCFunc(ident);
  5093. var cArgs = [];
  5094. var stack = 0;
  5095. assert(returnType !== 'array', 'Return type should not be "array".');
  5096. if (args) {
  5097. for (var i = 0; i < args.length; i++) {
  5098. var converter = toC[argTypes[i]];
  5099. if (converter) {
  5100. if (stack === 0) stack = stackSave();
  5101. cArgs[i] = converter(args[i]);
  5102. } else {
  5103. cArgs[i] = args[i];
  5104. }
  5105. }
  5106. }
  5107. var ret = func.apply(null, cArgs);
  5108. ret = convertReturnValue(ret);
  5109. if (stack !== 0) stackRestore(stack);
  5110. return ret;
  5111. }
  5112. function cwrap(ident, returnType, argTypes, opts) {
  5113. return function() {
  5114. return ccall(ident, returnType, argTypes, arguments);
  5115. }
  5116. }
  5117. // Given a pointer 'ptr' to a null-terminated UTF8-encoded string in the given array that contains uint8 values, returns
  5118. // a copy of that string as a Javascript String object.
  5119. var UTF8Decoder = typeof TextDecoder !== 'undefined' ? new TextDecoder('utf8') : undefined;
  5120. /**
  5121. * @param {number} idx
  5122. * @param {number=} maxBytesToRead
  5123. * @return {string}
  5124. */
  5125. function UTF8ArrayToString(u8Array, idx, maxBytesToRead) {
  5126. var endIdx = idx + maxBytesToRead;
  5127. var endPtr = idx;
  5128. // TextDecoder needs to know the byte length in advance, it doesn't stop on null terminator by itself.
  5129. // Also, use the length info to avoid running tiny strings through TextDecoder, since .subarray() allocates garbage.
  5130. // (As a tiny code save trick, compare endPtr against endIdx using a negation, so that undefined means Infinity)
  5131. while (u8Array[endPtr] && !(endPtr >= endIdx)) ++endPtr;
  5132. if (endPtr - idx > 16 && u8Array.subarray && UTF8Decoder) {
  5133. return UTF8Decoder.decode(u8Array.subarray(idx, endPtr));
  5134. } else {
  5135. var str = '';
  5136. // If building with TextDecoder, we have already computed the string length above, so test loop end condition against that
  5137. while (idx < endPtr) {
  5138. // For UTF8 byte structure, see:
  5139. // http://en.wikipedia.org/wiki/UTF-8#Description
  5140. // https://www.ietf.org/rfc/rfc2279.txt
  5141. // https://tools.ietf.org/html/rfc3629
  5142. var u0 = u8Array[idx++];
  5143. if (!(u0 & 0x80)) { str += String.fromCharCode(u0); continue; }
  5144. var u1 = u8Array[idx++] & 63;
  5145. if ((u0 & 0xE0) == 0xC0) { str += String.fromCharCode(((u0 & 31) << 6) | u1); continue; }
  5146. var u2 = u8Array[idx++] & 63;
  5147. if ((u0 & 0xF0) == 0xE0) {
  5148. u0 = ((u0 & 15) << 12) | (u1 << 6) | u2;
  5149. } else {
  5150. 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!');
  5151. u0 = ((u0 & 7) << 18) | (u1 << 12) | (u2 << 6) | (u8Array[idx++] & 63);
  5152. }
  5153. if (u0 < 0x10000) {
  5154. str += String.fromCharCode(u0);
  5155. } else {
  5156. var ch = u0 - 0x10000;
  5157. str += String.fromCharCode(0xD800 | (ch >> 10), 0xDC00 | (ch & 0x3FF));
  5158. }
  5159. }
  5160. }
  5161. return str;
  5162. }
  5163. // Given a pointer 'ptr' to a null-terminated UTF8-encoded string in the emscripten HEAP, returns a
  5164. // copy of that string as a Javascript String object.
  5165. // maxBytesToRead: an optional length that specifies the maximum number of bytes to read. You can omit
  5166. // this parameter to scan the string until the first \0 byte. If maxBytesToRead is
  5167. // passed, and the string at [ptr, ptr+maxBytesToReadr[ contains a null byte in the
  5168. // middle, then the string will cut short at that byte index (i.e. maxBytesToRead will
  5169. // not produce a string of exact length [ptr, ptr+maxBytesToRead[)
  5170. // N.B. mixing frequent uses of UTF8ToString() with and without maxBytesToRead may
  5171. // throw JS JIT optimizations off, so it is worth to consider consistently using one
  5172. // style or the other.
  5173. /**
  5174. * @param {number} ptr
  5175. * @param {number=} maxBytesToRead
  5176. * @return {string}
  5177. */
  5178. function UTF8ToString(ptr, maxBytesToRead) {
  5179. return ptr ? UTF8ArrayToString(HEAPU8, ptr, maxBytesToRead) : '';
  5180. }
  5181. // Copies the given Javascript String object 'str' to the given byte array at address 'outIdx',
  5182. // encoded in UTF8 form and null-terminated. The copy will require at most str.length*4+1 bytes of space in the HEAP.
  5183. // Use the function lengthBytesUTF8 to compute the exact number of bytes (excluding null terminator) that this function will write.
  5184. // Parameters:
  5185. // str: the Javascript string to copy.
  5186. // outU8Array: the array to copy to. Each index in this array is assumed to be one 8-byte element.
  5187. // outIdx: The starting offset in the array to begin the copying.
  5188. // maxBytesToWrite: The maximum number of bytes this function can write to the array.
  5189. // This count should include the null terminator,
  5190. // i.e. if maxBytesToWrite=1, only the null terminator will be written and nothing else.
  5191. // maxBytesToWrite=0 does not write any bytes to the output, not even the null terminator.
  5192. // Returns the number of bytes written, EXCLUDING the null terminator.
  5193. function stringToUTF8Array(str, outU8Array, outIdx, maxBytesToWrite) {
  5194. if (!(maxBytesToWrite > 0)) // Parameter maxBytesToWrite is not optional. Negative values, 0, null, undefined and false each don't write out any bytes.
  5195. return 0;
  5196. var startIdx = outIdx;
  5197. var endIdx = outIdx + maxBytesToWrite - 1; // -1 for string null terminator.
  5198. for (var i = 0; i < str.length; ++i) {
  5199. // 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.
  5200. // See http://unicode.org/faq/utf_bom.html#utf16-3
  5201. // 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
  5202. var u = str.charCodeAt(i); // possibly a lead surrogate
  5203. if (u >= 0xD800 && u <= 0xDFFF) {
  5204. var u1 = str.charCodeAt(++i);
  5205. u = 0x10000 + ((u & 0x3FF) << 10) | (u1 & 0x3FF);
  5206. }
  5207. if (u <= 0x7F) {
  5208. if (outIdx >= endIdx) break;
  5209. outU8Array[outIdx++] = u;
  5210. } else if (u <= 0x7FF) {
  5211. if (outIdx + 1 >= endIdx) break;
  5212. outU8Array[outIdx++] = 0xC0 | (u >> 6);
  5213. outU8Array[outIdx++] = 0x80 | (u & 63);
  5214. } else if (u <= 0xFFFF) {
  5215. if (outIdx + 2 >= endIdx) break;
  5216. outU8Array[outIdx++] = 0xE0 | (u >> 12);
  5217. outU8Array[outIdx++] = 0x80 | ((u >> 6) & 63);
  5218. outU8Array[outIdx++] = 0x80 | (u & 63);
  5219. } else {
  5220. if (outIdx + 3 >= endIdx) break;
  5221. 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).');
  5222. outU8Array[outIdx++] = 0xF0 | (u >> 18);
  5223. outU8Array[outIdx++] = 0x80 | ((u >> 12) & 63);
  5224. outU8Array[outIdx++] = 0x80 | ((u >> 6) & 63);
  5225. outU8Array[outIdx++] = 0x80 | (u & 63);
  5226. }
  5227. }
  5228. // Null-terminate the pointer to the buffer.
  5229. outU8Array[outIdx] = 0;
  5230. return outIdx - startIdx;
  5231. }
  5232. // Copies the given Javascript String object 'str' to the emscripten HEAP at address 'outPtr',
  5233. // null-terminated and encoded in UTF8 form. The copy will require at most str.length*4+1 bytes of space in the HEAP.
  5234. // Use the function lengthBytesUTF8 to compute the exact number of bytes (excluding null terminator) that this function will write.
  5235. // Returns the number of bytes written, EXCLUDING the null terminator.
  5236. function stringToUTF8(str, outPtr, maxBytesToWrite) {
  5237. assert(typeof maxBytesToWrite == 'number', 'stringToUTF8(str, outPtr, maxBytesToWrite) is missing the third parameter that specifies the length of the output buffer!');
  5238. return stringToUTF8Array(str, HEAPU8,outPtr, maxBytesToWrite);
  5239. }
  5240. // Given a pointer 'ptr' to a null-terminated UTF16LE-encoded string in the emscripten HEAP, returns
  5241. // a copy of that string as a Javascript String object.
  5242. var UTF16Decoder = typeof TextDecoder !== 'undefined' ? new TextDecoder('utf-16le') : undefined;
  5243. function writeArrayToMemory(array, buffer) {
  5244. assert(array.length >= 0, 'writeArrayToMemory array must have a length (should be an array or typed array)');
  5245. HEAP8.set(array, buffer);
  5246. }
  5247. function demangle(func) {
  5248. return func;
  5249. }
  5250. function demangleAll(text) {
  5251. var regex =
  5252. /__Z[\w\d_]+/g;
  5253. return text.replace(regex,
  5254. function(x) {
  5255. var y = demangle(x);
  5256. return x === y ? x : (y + ' [' + x + ']');
  5257. });
  5258. }
  5259. function jsStackTrace() {
  5260. var err = new Error();
  5261. if (!err.stack) {
  5262. // IE10+ special cases: It does have callstack info, but it is only populated if an Error object is thrown,
  5263. // so try that as a special-case.
  5264. try {
  5265. throw new Error(0);
  5266. } catch(e) {
  5267. err = e;
  5268. }
  5269. if (!err.stack) {
  5270. return '(no stack trace available)';
  5271. }
  5272. }
  5273. return err.stack.toString();
  5274. }
  5275. function stackTrace() {
  5276. var js = jsStackTrace();
  5277. if (Module['extraStackTrace']) js += '\n' + Module['extraStackTrace']();
  5278. return demangleAll(js);
  5279. }
  5280. var WASM_PAGE_SIZE = 65536;
  5281. function alignUp(x, multiple) {
  5282. if (x % multiple > 0) {
  5283. x += multiple - (x % multiple);
  5284. }
  5285. return x;
  5286. }
  5287. var /** @type {ArrayBuffer} */
  5288. buffer,
  5289. /** @type {Int8Array} */
  5290. HEAP8,
  5291. /** @type {Uint8Array} */
  5292. HEAPU8,
  5293. /** @type {Int16Array} */
  5294. HEAP16,
  5295. /** @type {Uint16Array} */
  5296. HEAPU16,
  5297. /** @type {Int32Array} */
  5298. HEAP32,
  5299. /** @type {Uint32Array} */
  5300. HEAPU32,
  5301. /** @type {Float32Array} */
  5302. HEAPF32,
  5303. /** @type {Float64Array} */
  5304. HEAPF64;
  5305. function updateGlobalBufferViews() {
  5306. Module['HEAP8'] = HEAP8 = new Int8Array(buffer);
  5307. Module['HEAP16'] = HEAP16 = new Int16Array(buffer);
  5308. Module['HEAP32'] = HEAP32 = new Int32Array(buffer);
  5309. Module['HEAPU8'] = HEAPU8 = new Uint8Array(buffer);
  5310. Module['HEAPU16'] = HEAPU16 = new Uint16Array(buffer);
  5311. Module['HEAPU32'] = HEAPU32 = new Uint32Array(buffer);
  5312. Module['HEAPF32'] = HEAPF32 = new Float32Array(buffer);
  5313. Module['HEAPF64'] = HEAPF64 = new Float64Array(buffer);
  5314. }
  5315. var STACK_BASE = 5872,
  5316. STACK_MAX = 5248752,
  5317. DYNAMIC_BASE = 5248752,
  5318. DYNAMICTOP_PTR = 5840;
  5319. assert(STACK_BASE % 16 === 0, 'stack must start aligned');
  5320. assert(DYNAMIC_BASE % 16 === 0, 'heap must start aligned');
  5321. var TOTAL_STACK = 5242880;
  5322. if (Module['TOTAL_STACK']) assert(TOTAL_STACK === Module['TOTAL_STACK'], 'the stack size can no longer be determined at runtime');
  5323. var INITIAL_TOTAL_MEMORY = Module['TOTAL_MEMORY'] || 16777216;
  5324. if (INITIAL_TOTAL_MEMORY < TOTAL_STACK) err('TOTAL_MEMORY should be larger than TOTAL_STACK, was ' + INITIAL_TOTAL_MEMORY + '! (TOTAL_STACK=' + TOTAL_STACK + ')');
  5325. // Initialize the runtime's memory
  5326. // check for full engine support (use string 'subarray' to avoid closure compiler confusion)
  5327. assert(typeof Int32Array !== 'undefined' && typeof Float64Array !== 'undefined' && Int32Array.prototype.subarray !== undefined && Int32Array.prototype.set !== undefined,
  5328. 'JS engine does not provide full typed array support');
  5329. // Use a provided buffer, if there is one, or else allocate a new one
  5330. if (Module['buffer']) {
  5331. buffer = Module['buffer'];
  5332. assert(buffer.byteLength === INITIAL_TOTAL_MEMORY, 'provided buffer should be ' + INITIAL_TOTAL_MEMORY + ' bytes, but it is ' + buffer.byteLength);
  5333. } else {
  5334. // Use a WebAssembly memory where available
  5335. if (typeof WebAssembly === 'object' && typeof WebAssembly.Memory === 'function') {
  5336. assert(INITIAL_TOTAL_MEMORY % WASM_PAGE_SIZE === 0);
  5337. wasmMemory = new WebAssembly.Memory({ 'initial': INITIAL_TOTAL_MEMORY / WASM_PAGE_SIZE });
  5338. buffer = wasmMemory.buffer;
  5339. } else
  5340. {
  5341. buffer = new ArrayBuffer(INITIAL_TOTAL_MEMORY);
  5342. }
  5343. assert(buffer.byteLength === INITIAL_TOTAL_MEMORY);
  5344. }
  5345. updateGlobalBufferViews();
  5346. HEAP32[DYNAMICTOP_PTR>>2] = DYNAMIC_BASE;
  5347. // Initializes the stack cookie. Called at the startup of main and at the startup of each thread in pthreads mode.
  5348. function writeStackCookie() {
  5349. assert((STACK_MAX & 3) == 0);
  5350. HEAPU32[(STACK_MAX >> 2)-1] = 0x02135467;
  5351. HEAPU32[(STACK_MAX >> 2)-2] = 0x89BACDFE;
  5352. }
  5353. function checkStackCookie() {
  5354. if (HEAPU32[(STACK_MAX >> 2)-1] != 0x02135467 || HEAPU32[(STACK_MAX >> 2)-2] != 0x89BACDFE) {
  5355. 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));
  5356. }
  5357. // Also test the global address 0 for integrity.
  5358. if (HEAP32[0] !== 0x63736d65 /* 'emsc' */) abort('Runtime error: The application has corrupted its heap memory area (address zero)!');
  5359. }
  5360. function abortStackOverflow(allocSize) {
  5361. abort('Stack overflow! Attempted to allocate ' + allocSize + ' bytes on the stack, but stack has only ' + (STACK_MAX - stackSave() + allocSize) + ' bytes available!');
  5362. }
  5363. HEAP32[0] = 0x63736d65; /* 'emsc' */
  5364. // Endianness check (note: assumes compiler arch was little-endian)
  5365. HEAP16[1] = 0x6373;
  5366. if (HEAPU8[2] !== 0x73 || HEAPU8[3] !== 0x63) throw 'Runtime error: expected the system to be little-endian!';
  5367. function callRuntimeCallbacks(callbacks) {
  5368. while(callbacks.length > 0) {
  5369. var callback = callbacks.shift();
  5370. if (typeof callback == 'function') {
  5371. callback();
  5372. continue;
  5373. }
  5374. var func = callback.func;
  5375. if (typeof func === 'number') {
  5376. if (callback.arg === undefined) {
  5377. Module['dynCall_v'](func);
  5378. } else {
  5379. Module['dynCall_vi'](func, callback.arg);
  5380. }
  5381. } else {
  5382. func(callback.arg === undefined ? null : callback.arg);
  5383. }
  5384. }
  5385. }
  5386. var __ATPRERUN__ = []; // functions called before the runtime is initialized
  5387. var __ATINIT__ = []; // functions called during startup
  5388. var __ATMAIN__ = []; // functions called when main() is to be run
  5389. var __ATPOSTRUN__ = []; // functions called after the main() is called
  5390. var runtimeInitialized = false;
  5391. var runtimeExited = false;
  5392. function preRun() {
  5393. // compatibility - merge in anything from Module['preRun'] at this time
  5394. if (Module['preRun']) {
  5395. if (typeof Module['preRun'] == 'function') Module['preRun'] = [Module['preRun']];
  5396. while (Module['preRun'].length) {
  5397. addOnPreRun(Module['preRun'].shift());
  5398. }
  5399. }
  5400. callRuntimeCallbacks(__ATPRERUN__);
  5401. }
  5402. function ensureInitRuntime() {
  5403. checkStackCookie();
  5404. if (runtimeInitialized) return;
  5405. runtimeInitialized = true;
  5406. callRuntimeCallbacks(__ATINIT__);
  5407. }
  5408. function preMain() {
  5409. checkStackCookie();
  5410. callRuntimeCallbacks(__ATMAIN__);
  5411. }
  5412. function postRun() {
  5413. checkStackCookie();
  5414. // compatibility - merge in anything from Module['postRun'] at this time
  5415. if (Module['postRun']) {
  5416. if (typeof Module['postRun'] == 'function') Module['postRun'] = [Module['postRun']];
  5417. while (Module['postRun'].length) {
  5418. addOnPostRun(Module['postRun'].shift());
  5419. }
  5420. }
  5421. callRuntimeCallbacks(__ATPOSTRUN__);
  5422. }
  5423. function addOnPreRun(cb) {
  5424. __ATPRERUN__.unshift(cb);
  5425. }
  5426. function addOnPostRun(cb) {
  5427. __ATPOSTRUN__.unshift(cb);
  5428. }
  5429. 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');
  5430. 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');
  5431. 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');
  5432. 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');
  5433. // A counter of dependencies for calling run(). If we need to
  5434. // do asynchronous work before running, increment this and
  5435. // decrement it. Incrementing must happen in a place like
  5436. // Module.preRun (used by emcc to add file preloading).
  5437. // Note that you can add dependencies in preRun, even though
  5438. // it happens right before run - run will be postponed until
  5439. // the dependencies are met.
  5440. var runDependencies = 0;
  5441. var runDependencyWatcher = null;
  5442. var dependenciesFulfilled = null; // overridden to take different actions when all run dependencies are fulfilled
  5443. var runDependencyTracking = {};
  5444. function addRunDependency(id) {
  5445. runDependencies++;
  5446. if (Module['monitorRunDependencies']) {
  5447. Module['monitorRunDependencies'](runDependencies);
  5448. }
  5449. if (id) {
  5450. assert(!runDependencyTracking[id]);
  5451. runDependencyTracking[id] = 1;
  5452. if (runDependencyWatcher === null && typeof setInterval !== 'undefined') {
  5453. // Check for missing dependencies every few seconds
  5454. runDependencyWatcher = setInterval(function() {
  5455. if (ABORT) {
  5456. clearInterval(runDependencyWatcher);
  5457. runDependencyWatcher = null;
  5458. return;
  5459. }
  5460. }, 10000);
  5461. }
  5462. }
  5463. }
  5464. function removeRunDependency(id) {
  5465. runDependencies--;
  5466. if (Module['monitorRunDependencies']) {
  5467. Module['monitorRunDependencies'](runDependencies);
  5468. }
  5469. if (id) {
  5470. assert(runDependencyTracking[id]);
  5471. delete runDependencyTracking[id];
  5472. }
  5473. if (runDependencies == 0) {
  5474. if (runDependencyWatcher !== null) {
  5475. clearInterval(runDependencyWatcher);
  5476. runDependencyWatcher = null;
  5477. }
  5478. if (dependenciesFulfilled) {
  5479. var callback = dependenciesFulfilled;
  5480. dependenciesFulfilled = null;
  5481. callback(); // can add another dependenciesFulfilled
  5482. }
  5483. }
  5484. }
  5485. Module["preloadedImages"] = {}; // maps url to image data
  5486. Module["preloadedAudios"] = {}; // maps url to audio data
  5487. // show errors on likely calls to FS when it was not included
  5488. var FS = {
  5489. error: function() {
  5490. 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');
  5491. },
  5492. init: function() { FS.error(); },
  5493. createDataFile: function() { FS.error(); },
  5494. createPreloadedFile: function() { FS.error(); },
  5495. createLazyFile: function() { FS.error(); },
  5496. open: function() { FS.error(); },
  5497. mkdev: function() { FS.error(); },
  5498. registerDevice: function() { FS.error(); },
  5499. analyzePath: function() { FS.error(); },
  5500. loadFilesFromDB: function() { FS.error(); },
  5501. ErrnoError: function ErrnoError() { FS.error(); },
  5502. };
  5503. Module['FS_createDataFile'] = FS.createDataFile;
  5504. Module['FS_createPreloadedFile'] = FS.createPreloadedFile;
  5505. // Copyright 2017 The Emscripten Authors. All rights reserved.
  5506. // Emscripten is available under two separate licenses, the MIT license and the
  5507. // University of Illinois/NCSA Open Source License. Both these licenses can be
  5508. // found in the LICENSE file.
  5509. // Prefix of data URIs emitted by SINGLE_FILE and related options.
  5510. var dataURIPrefix = 'data:application/octet-stream;base64,';
  5511. // Indicates whether filename is a base64 data URI.
  5512. function isDataURI(filename) {
  5513. return String.prototype.startsWith ?
  5514. filename.startsWith(dataURIPrefix) :
  5515. filename.indexOf(dataURIPrefix) === 0;
  5516. }
  5517. var wasmBinaryFile = 'ThirdParty/earcut.wasm';
  5518. if (!isDataURI(wasmBinaryFile)) {
  5519. wasmBinaryFile = locateFile(wasmBinaryFile);
  5520. }
  5521. function getBinary() {
  5522. try {
  5523. if (Module['wasmBinary']) {
  5524. return new Uint8Array(Module['wasmBinary']);
  5525. }
  5526. if (Module['readBinary']) {
  5527. return Module['readBinary'](wasmBinaryFile);
  5528. } else {
  5529. throw "both async and sync fetching of the wasm failed";
  5530. }
  5531. }
  5532. catch (err) {
  5533. abort(err);
  5534. }
  5535. }
  5536. function getBinaryPromise() {
  5537. // if we don't have the binary yet, and have the Fetch api, use that
  5538. // 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
  5539. if (!Module['wasmBinary'] && (ENVIRONMENT_IS_WEB || ENVIRONMENT_IS_WORKER) && typeof fetch === 'function') {
  5540. return fetch(wasmBinaryFile, { credentials: 'same-origin' }).then(function(response) {
  5541. if (!response['ok']) {
  5542. throw "failed to load wasm binary file at '" + wasmBinaryFile + "'";
  5543. }
  5544. return response['arrayBuffer']();
  5545. }).catch(function () {
  5546. return getBinary();
  5547. });
  5548. }
  5549. // Otherwise, getBinary should be able to get it synchronously
  5550. return new Promise(function(resolve, reject) {
  5551. resolve(getBinary());
  5552. });
  5553. }
  5554. // Create the wasm instance.
  5555. // Receives the wasm imports, returns the exports.
  5556. function createWasm(env) {
  5557. // prepare imports
  5558. var info = {
  5559. 'env': env
  5560. ,
  5561. 'global': {
  5562. 'NaN': NaN,
  5563. 'Infinity': Infinity
  5564. },
  5565. 'global.Math': Math,
  5566. 'asm2wasm': asm2wasmImports
  5567. };
  5568. // Load the wasm module and create an instance of using native support in the JS engine.
  5569. // handle a generated wasm instance, receiving its exports and
  5570. // performing other necessary setup
  5571. function receiveInstance(instance, module) {
  5572. var exports = instance.exports;
  5573. Module['asm'] = exports;
  5574. removeRunDependency('wasm-instantiate');
  5575. }
  5576. addRunDependency('wasm-instantiate');
  5577. // Async compilation can be confusing when an error on the page overwrites Module
  5578. // (for example, if the order of elements is wrong, and the one defining Module is
  5579. // later), so we save Module and check it later.
  5580. var trueModule = Module;
  5581. function receiveInstantiatedSource(output) {
  5582. // 'output' is a WebAssemblyInstantiatedSource object which has both the module and instance.
  5583. // receiveInstance() will swap in the exports (to Module.asm) so they can be called
  5584. assert(Module === trueModule, 'the Module object should not be replaced during async compilation - perhaps the order of HTML elements is wrong?');
  5585. trueModule = null;
  5586. // 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.
  5587. // When the regression is fixed, can restore the above USE_PTHREADS-enabled path.
  5588. receiveInstance(output['instance']);
  5589. }
  5590. function instantiateArrayBuffer(receiver) {
  5591. return getBinaryPromise().then(function(binary) {
  5592. return WebAssembly.instantiate(binary, info);
  5593. }).then(receiver, function(reason) {
  5594. //err('failed to asynchronously prepare wasm: ' + reason);
  5595. //abort(reason);
  5596. });
  5597. }
  5598. // Prefer streaming instantiation if available.
  5599. function instantiateAsync() {
  5600. if (!Module['wasmBinary'] &&
  5601. typeof WebAssembly.instantiateStreaming === 'function' &&
  5602. !isDataURI(wasmBinaryFile) &&
  5603. typeof fetch === 'function') {
  5604. fetch(wasmBinaryFile, { credentials: 'same-origin' }).then(function (response) {
  5605. return WebAssembly.instantiateStreaming(response, info)
  5606. .then(receiveInstantiatedSource, function(reason) {
  5607. // We expect the most common failure cause to be a bad MIME type for the binary,
  5608. // in which case falling back to ArrayBuffer instantiation should work.
  5609. //err('wasm streaming compile failed: ' + reason);
  5610. //err('falling back to ArrayBuffer instantiation');
  5611. instantiateArrayBuffer(receiveInstantiatedSource);
  5612. });
  5613. });
  5614. } else {
  5615. return instantiateArrayBuffer(receiveInstantiatedSource);
  5616. }
  5617. }
  5618. // User shell pages can write their own Module.instantiateWasm = function(imports, successCallback) callback
  5619. // to manually instantiate the Wasm module themselves. This allows pages to run the instantiation parallel
  5620. // to any other async startup actions they are performing.
  5621. if (Module['instantiateWasm']) {
  5622. try {
  5623. return Module['instantiateWasm'](info, receiveInstance);
  5624. } catch(e) {
  5625. //err('Module.instantiateWasm callback failed with error: ' + e);
  5626. return false;
  5627. }
  5628. }
  5629. instantiateAsync();
  5630. return {}; // no exports yet; we'll fill them in later
  5631. }
  5632. // Provide an "asm.js function" for the application, called to "link" the asm.js module. We instantiate
  5633. // the wasm module at that time, and it receives imports and provides exports and so forth, the app
  5634. // doesn't need to care that it is wasm or asm.js.
  5635. Module['asm'] = function(global, env, providedBuffer) {
  5636. // memory was already allocated (so js could use the buffer)
  5637. env['memory'] = wasmMemory
  5638. ;
  5639. // import table
  5640. env['table'] = wasmTable = new WebAssembly.Table({
  5641. 'initial': 260,
  5642. 'maximum': 260,
  5643. 'element': 'anyfunc'
  5644. });
  5645. // With the wasm backend __memory_base and __table_base and only needed for
  5646. // relocatable output.
  5647. env['__memory_base'] = 1024; // tell the memory segments where to place themselves
  5648. // table starts at 0 by default (even in dynamic linking, for the main module)
  5649. env['__table_base'] = 0;
  5650. var exports = createWasm(env);
  5651. assert(exports, 'binaryen setup failed (no wasm support?)');
  5652. return exports;
  5653. };
  5654. // STATICTOP = STATIC_BASE + 4848;
  5655. /* global initializers */ /*__ATINIT__.push();*/
  5656. /* no memory initializer */
  5657. var tempDoublePtr = 5856;
  5658. assert(tempDoublePtr % 8 == 0);
  5659. // {{PRE_LIBRARY}}
  5660. function ___cxa_allocate_exception(size) {
  5661. return _malloc(size);
  5662. }
  5663. var ___exception_infos={};
  5664. var ___exception_caught= [];
  5665. function ___exception_addRef(ptr) {
  5666. if (!ptr) return;
  5667. var info = ___exception_infos[ptr];
  5668. info.refcount++;
  5669. }
  5670. function ___exception_deAdjust(adjusted) {
  5671. if (!adjusted || ___exception_infos[adjusted]) return adjusted;
  5672. for (var key in ___exception_infos) {
  5673. 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
  5674. var adj = ___exception_infos[ptr].adjusted;
  5675. var len = adj.length;
  5676. for (var i = 0; i < len; i++) {
  5677. if (adj[i] === adjusted) {
  5678. return ptr;
  5679. }
  5680. }
  5681. }
  5682. return adjusted;
  5683. }function ___cxa_begin_catch(ptr) {
  5684. var info = ___exception_infos[ptr];
  5685. if (info && !info.caught) {
  5686. info.caught = true;
  5687. __ZSt18uncaught_exceptionv.uncaught_exception--;
  5688. }
  5689. if (info) info.rethrown = false;
  5690. ___exception_caught.push(ptr);
  5691. ___exception_addRef(___exception_deAdjust(ptr));
  5692. return ptr;
  5693. }
  5694. function ___cxa_throw(ptr, type, destructor) {
  5695. ___exception_infos[ptr] = {
  5696. ptr: ptr,
  5697. adjusted: [ptr],
  5698. type: type,
  5699. destructor: destructor,
  5700. refcount: 0,
  5701. caught: false,
  5702. rethrown: false
  5703. };
  5704. if (!("uncaught_exception" in __ZSt18uncaught_exceptionv)) {
  5705. __ZSt18uncaught_exceptionv.uncaught_exception = 1;
  5706. } else {
  5707. __ZSt18uncaught_exceptionv.uncaught_exception++;
  5708. }
  5709. 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.";
  5710. }
  5711. function ___cxa_uncaught_exception() {
  5712. return !!__ZSt18uncaught_exceptionv.uncaught_exception;
  5713. }
  5714. function ___gxx_personality_v0() {
  5715. }
  5716. function ___lock() {}
  5717. var SYSCALLS={buffers:[null,[],[]],printChar:function (stream, curr) {
  5718. var buffer = SYSCALLS.buffers[stream];
  5719. assert(buffer);
  5720. if (curr === 0 || curr === 10) {
  5721. (stream === 1 ? out : err)(UTF8ArrayToString(buffer, 0));
  5722. buffer.length = 0;
  5723. } else {
  5724. buffer.push(curr);
  5725. }
  5726. },varargs:0,get:function (varargs) {
  5727. SYSCALLS.varargs += 4;
  5728. var ret = HEAP32[(((SYSCALLS.varargs)-(4))>>2)];
  5729. return ret;
  5730. },getStr:function () {
  5731. var ret = UTF8ToString(SYSCALLS.get());
  5732. return ret;
  5733. },get64:function () {
  5734. var low = SYSCALLS.get(), high = SYSCALLS.get();
  5735. if (low >= 0) assert(high === 0);
  5736. else assert(high === -1);
  5737. return low;
  5738. },getZero:function () {
  5739. assert(SYSCALLS.get() === 0);
  5740. }};function ___syscall140(which, varargs) {SYSCALLS.varargs = varargs;
  5741. try {
  5742. // llseek
  5743. var stream = SYSCALLS.getStreamFromFD(), offset_high = SYSCALLS.get(), offset_low = SYSCALLS.get(), result = SYSCALLS.get(), whence = SYSCALLS.get();
  5744. abort('it should not be possible to operate on streams when !SYSCALLS_REQUIRE_FILESYSTEM');
  5745. return 0;
  5746. } catch (e) {
  5747. if (typeof FS === 'undefined' || !(e instanceof FS.ErrnoError)) abort(e);
  5748. return -e.errno;
  5749. }
  5750. }
  5751. function flush_NO_FILESYSTEM() {
  5752. // flush anything remaining in the buffers during shutdown
  5753. var fflush = Module["_fflush"];
  5754. if (fflush) fflush(0);
  5755. var buffers = SYSCALLS.buffers;
  5756. if (buffers[1].length) SYSCALLS.printChar(1, 10);
  5757. if (buffers[2].length) SYSCALLS.printChar(2, 10);
  5758. }function ___syscall146(which, varargs) {SYSCALLS.varargs = varargs;
  5759. try {
  5760. // writev
  5761. // hack to support printf in SYSCALLS_REQUIRE_FILESYSTEM=0
  5762. var stream = SYSCALLS.get(), iov = SYSCALLS.get(), iovcnt = SYSCALLS.get();
  5763. var ret = 0;
  5764. for (var i = 0; i < iovcnt; i++) {
  5765. var ptr = HEAP32[(((iov)+(i*8))>>2)];
  5766. var len = HEAP32[(((iov)+(i*8 + 4))>>2)];
  5767. for (var j = 0; j < len; j++) {
  5768. SYSCALLS.printChar(stream, HEAPU8[ptr+j]);
  5769. }
  5770. ret += len;
  5771. }
  5772. return ret;
  5773. } catch (e) {
  5774. if (typeof FS === 'undefined' || !(e instanceof FS.ErrnoError)) abort(e);
  5775. return -e.errno;
  5776. }
  5777. }
  5778. function ___syscall54(which, varargs) {SYSCALLS.varargs = varargs;
  5779. try {
  5780. // ioctl
  5781. return 0;
  5782. } catch (e) {
  5783. if (typeof FS === 'undefined' || !(e instanceof FS.ErrnoError)) abort(e);
  5784. return -e.errno;
  5785. }
  5786. }
  5787. function ___syscall6(which, varargs) {SYSCALLS.varargs = varargs;
  5788. try {
  5789. // close
  5790. var stream = SYSCALLS.getStreamFromFD();
  5791. abort('it should not be possible to operate on streams when !SYSCALLS_REQUIRE_FILESYSTEM');
  5792. return 0;
  5793. } catch (e) {
  5794. if (typeof FS === 'undefined' || !(e instanceof FS.ErrnoError)) abort(e);
  5795. return -e.errno;
  5796. }
  5797. }
  5798. function ___unlock() {}
  5799. function _abort() {
  5800. Module['abort']();
  5801. }
  5802. function _emscripten_get_heap_size() {
  5803. return HEAP8.length;
  5804. }
  5805. function _emscripten_memcpy_big(dest, src, num) {
  5806. HEAPU8.set(HEAPU8.subarray(src, src+num), dest);
  5807. }
  5808. function ___setErrNo(value) {
  5809. if (Module['___errno_location']) HEAP32[((Module['___errno_location']())>>2)]=value;
  5810. else //err('failed to set errno from JS');
  5811. return value;
  5812. }
  5813. function abortOnCannotGrowMemory(requestedSize) {
  5814. 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 ');
  5815. }
  5816. function emscripten_realloc_buffer(size) {
  5817. var PAGE_MULTIPLE = 65536;
  5818. size = alignUp(size, PAGE_MULTIPLE); // round up to wasm page size
  5819. var oldSize = buffer.byteLength;
  5820. // native wasm support
  5821. // note that this is *not* threadsafe. multiple threads can call .grow(), and each
  5822. // presents a delta, so in theory we may over-allocate here (e.g. if two threads
  5823. // ask to grow from 256MB to 512MB, we get 2 requests to add +256MB, and may end
  5824. // up growing to 768MB (even though we may have been able to make do with 512MB).
  5825. // TODO: consider decreasing the step sizes in emscripten_resize_heap
  5826. try {
  5827. var result = wasmMemory.grow((size - oldSize) / 65536); // .grow() takes a delta compared to the previous size
  5828. if (result !== (-1 | 0)) {
  5829. // success in native wasm memory growth, get the buffer from the memory
  5830. buffer = wasmMemory.buffer;
  5831. return true;
  5832. } else {
  5833. return false;
  5834. }
  5835. } catch(e) {
  5836. console.error('emscripten_realloc_buffer: Attempted to grow from ' + oldSize + ' bytes to ' + size + ' bytes, but got error: ' + e);
  5837. return false;
  5838. }
  5839. }function _emscripten_resize_heap(requestedSize) {
  5840. var oldSize = _emscripten_get_heap_size();
  5841. // With pthreads, races can happen (another thread might increase the size in between), so return a failure, and let the caller retry.
  5842. assert(requestedSize > oldSize);
  5843. var PAGE_MULTIPLE = 65536;
  5844. var LIMIT = 2147483648 - PAGE_MULTIPLE; // We can do one page short of 2GB as theoretical maximum.
  5845. if (requestedSize > LIMIT) {
  5846. //err('Cannot enlarge memory, asked to go up to ' + requestedSize + ' bytes, but the limit is ' + LIMIT + ' bytes!');
  5847. return false;
  5848. }
  5849. var MIN_TOTAL_MEMORY = 16777216;
  5850. var newSize = Math.max(oldSize, MIN_TOTAL_MEMORY); // So the loop below will not be infinite, and minimum asm.js memory size is 16MB.
  5851. // TODO: see realloc_buffer - for PTHREADS we may want to decrease these jumps
  5852. while (newSize < requestedSize) { // Keep incrementing the heap size as long as it's less than what is requested.
  5853. if (newSize <= 536870912) {
  5854. newSize = alignUp(2 * newSize, PAGE_MULTIPLE); // Simple heuristic: double until 1GB...
  5855. } else {
  5856. // ..., but after that, add smaller increments towards 2GB, which we cannot reach
  5857. newSize = Math.min(alignUp((3 * newSize + 2147483648) / 4, PAGE_MULTIPLE), LIMIT);
  5858. }
  5859. if (newSize === oldSize) {
  5860. 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);
  5861. }
  5862. }
  5863. if (!emscripten_realloc_buffer(newSize)) {
  5864. //err('Failed to grow the heap from ' + oldSize + ' bytes to ' + newSize + ' bytes, not enough memory!');
  5865. return false;
  5866. }
  5867. updateGlobalBufferViews();
  5868. return true;
  5869. }
  5870. // ASM_LIBRARY EXTERN PRIMITIVES: Math_max,Math_min,Int8Array,Int32Array
  5871. 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); }
  5872. 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); }
  5873. 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); }
  5874. 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); }
  5875. 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); }
  5876. 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); }
  5877. 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); }
  5878. 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); }
  5879. 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); }
  5880. 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); }
  5881. var asmGlobalArg = {};
  5882. var asmLibraryArg = {
  5883. "abort": abort,
  5884. "setTempRet0": setTempRet0,
  5885. "getTempRet0": getTempRet0,
  5886. "abortStackOverflow": abortStackOverflow,
  5887. "nullFunc_ii": nullFunc_ii,
  5888. "nullFunc_iidiiii": nullFunc_iidiiii,
  5889. "nullFunc_iiii": nullFunc_iiii,
  5890. "nullFunc_jiji": nullFunc_jiji,
  5891. "nullFunc_v": nullFunc_v,
  5892. "nullFunc_vi": nullFunc_vi,
  5893. "nullFunc_vii": nullFunc_vii,
  5894. "nullFunc_viiii": nullFunc_viiii,
  5895. "nullFunc_viiiii": nullFunc_viiiii,
  5896. "nullFunc_viiiiii": nullFunc_viiiiii,
  5897. "___cxa_allocate_exception": ___cxa_allocate_exception,
  5898. "___cxa_begin_catch": ___cxa_begin_catch,
  5899. "___cxa_throw": ___cxa_throw,
  5900. "___cxa_uncaught_exception": ___cxa_uncaught_exception,
  5901. "___exception_addRef": ___exception_addRef,
  5902. "___exception_deAdjust": ___exception_deAdjust,
  5903. "___gxx_personality_v0": ___gxx_personality_v0,
  5904. "___lock": ___lock,
  5905. "___setErrNo": ___setErrNo,
  5906. "___syscall140": ___syscall140,
  5907. "___syscall146": ___syscall146,
  5908. "___syscall54": ___syscall54,
  5909. "___syscall6": ___syscall6,
  5910. "___unlock": ___unlock,
  5911. "_abort": _abort,
  5912. "_emscripten_get_heap_size": _emscripten_get_heap_size,
  5913. "_emscripten_memcpy_big": _emscripten_memcpy_big,
  5914. "_emscripten_resize_heap": _emscripten_resize_heap,
  5915. "abortOnCannotGrowMemory": abortOnCannotGrowMemory,
  5916. "emscripten_realloc_buffer": emscripten_realloc_buffer,
  5917. "flush_NO_FILESYSTEM": flush_NO_FILESYSTEM,
  5918. "tempDoublePtr": tempDoublePtr,
  5919. "DYNAMICTOP_PTR": DYNAMICTOP_PTR
  5920. };
  5921. // EMSCRIPTEN_START_ASM
  5922. var asm =Module["asm"]// EMSCRIPTEN_END_ASM
  5923. (asmGlobalArg, asmLibraryArg, buffer);
  5924. var real___ZSt18uncaught_exceptionv = asm["__ZSt18uncaught_exceptionv"];
  5925. asm["__ZSt18uncaught_exceptionv"] = function() {
  5926. assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  5927. assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  5928. return real___ZSt18uncaught_exceptionv.apply(null, arguments);
  5929. };
  5930. var real____cxa_can_catch = asm["___cxa_can_catch"];
  5931. asm["___cxa_can_catch"] = function() {
  5932. assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  5933. assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  5934. return real____cxa_can_catch.apply(null, arguments);
  5935. };
  5936. var real____cxa_is_pointer_type = asm["___cxa_is_pointer_type"];
  5937. asm["___cxa_is_pointer_type"] = function() {
  5938. assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  5939. assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  5940. return real____cxa_is_pointer_type.apply(null, arguments);
  5941. };
  5942. var real____errno_location = asm["___errno_location"];
  5943. asm["___errno_location"] = function() {
  5944. assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  5945. assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  5946. return real____errno_location.apply(null, arguments);
  5947. };
  5948. var real__earcut = asm["_earcut"];
  5949. asm["_earcut"] = function() {
  5950. assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  5951. assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  5952. return real__earcut.apply(null, arguments);
  5953. };
  5954. var real__fflush = asm["_fflush"];
  5955. asm["_fflush"] = function() {
  5956. assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  5957. assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  5958. return real__fflush.apply(null, arguments);
  5959. };
  5960. var real__free = asm["_free"];
  5961. asm["_free"] = function() {
  5962. assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  5963. assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  5964. return real__free.apply(null, arguments);
  5965. };
  5966. var real__llvm_maxnum_f64 = asm["_llvm_maxnum_f64"];
  5967. asm["_llvm_maxnum_f64"] = function() {
  5968. assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  5969. assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  5970. return real__llvm_maxnum_f64.apply(null, arguments);
  5971. };
  5972. var real__llvm_minnum_f64 = asm["_llvm_minnum_f64"];
  5973. asm["_llvm_minnum_f64"] = function() {
  5974. assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  5975. assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  5976. return real__llvm_minnum_f64.apply(null, arguments);
  5977. };
  5978. var real__malloc = asm["_malloc"];
  5979. asm["_malloc"] = function() {
  5980. assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  5981. assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  5982. return real__malloc.apply(null, arguments);
  5983. };
  5984. var real__sbrk = asm["_sbrk"];
  5985. asm["_sbrk"] = function() {
  5986. assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  5987. assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  5988. return real__sbrk.apply(null, arguments);
  5989. };
  5990. var real_establishStackSpace = asm["establishStackSpace"];
  5991. asm["establishStackSpace"] = function() {
  5992. assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  5993. assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  5994. return real_establishStackSpace.apply(null, arguments);
  5995. };
  5996. var real_stackAlloc = asm["stackAlloc"];
  5997. asm["stackAlloc"] = function() {
  5998. assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  5999. assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  6000. return real_stackAlloc.apply(null, arguments);
  6001. };
  6002. var real_stackRestore = asm["stackRestore"];
  6003. asm["stackRestore"] = function() {
  6004. assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  6005. assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  6006. return real_stackRestore.apply(null, arguments);
  6007. };
  6008. var real_stackSave = asm["stackSave"];
  6009. asm["stackSave"] = function() {
  6010. assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  6011. assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  6012. return real_stackSave.apply(null, arguments);
  6013. };
  6014. Module["asm"] = asm;
  6015. var __ZSt18uncaught_exceptionv = Module["__ZSt18uncaught_exceptionv"] = function() {
  6016. assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  6017. assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  6018. return Module["asm"]["__ZSt18uncaught_exceptionv"].apply(null, arguments)
  6019. };
  6020. var ___cxa_can_catch = Module["___cxa_can_catch"] = function() {
  6021. assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  6022. assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  6023. return Module["asm"]["___cxa_can_catch"].apply(null, arguments)
  6024. };
  6025. var ___cxa_is_pointer_type = Module["___cxa_is_pointer_type"] = function() {
  6026. assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  6027. assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  6028. return Module["asm"]["___cxa_is_pointer_type"].apply(null, arguments)
  6029. };
  6030. var ___errno_location = Module["___errno_location"] = function() {
  6031. assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  6032. assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  6033. return Module["asm"]["___errno_location"].apply(null, arguments)
  6034. };
  6035. var _earcut = Module["_earcut"] = function() {
  6036. assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  6037. assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  6038. return Module["asm"]["_earcut"].apply(null, arguments)
  6039. };
  6040. var _emscripten_replace_memory = Module["_emscripten_replace_memory"] = function() {
  6041. assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  6042. assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  6043. return Module["asm"]["_emscripten_replace_memory"].apply(null, arguments)
  6044. };
  6045. var _fflush = Module["_fflush"] = function() {
  6046. assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  6047. assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  6048. return Module["asm"]["_fflush"].apply(null, arguments)
  6049. };
  6050. var _free = Module["_free"] = function() {
  6051. assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  6052. assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  6053. return Module["asm"]["_free"].apply(null, arguments)
  6054. };
  6055. var _llvm_maxnum_f64 = Module["_llvm_maxnum_f64"] = function() {
  6056. assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  6057. assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  6058. return Module["asm"]["_llvm_maxnum_f64"].apply(null, arguments)
  6059. };
  6060. var _llvm_minnum_f64 = Module["_llvm_minnum_f64"] = function() {
  6061. assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  6062. assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  6063. return Module["asm"]["_llvm_minnum_f64"].apply(null, arguments)
  6064. };
  6065. var _malloc = Module["_malloc"] = function() {
  6066. assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  6067. assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  6068. return Module["asm"]["_malloc"].apply(null, arguments)
  6069. };
  6070. var _memcpy = Module["_memcpy"] = function() {
  6071. assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  6072. assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  6073. return Module["asm"]["_memcpy"].apply(null, arguments)
  6074. };
  6075. var _memset = Module["_memset"] = function() {
  6076. assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  6077. assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  6078. return Module["asm"]["_memset"].apply(null, arguments)
  6079. };
  6080. var _sbrk = Module["_sbrk"] = function() {
  6081. assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  6082. assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  6083. return Module["asm"]["_sbrk"].apply(null, arguments)
  6084. };
  6085. var establishStackSpace = Module["establishStackSpace"] = function() {
  6086. assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  6087. assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  6088. return Module["asm"]["establishStackSpace"].apply(null, arguments)
  6089. };
  6090. var stackAlloc = Module["stackAlloc"] = function() {
  6091. assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  6092. assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  6093. return Module["asm"]["stackAlloc"].apply(null, arguments)
  6094. };
  6095. var stackRestore = Module["stackRestore"] = function() {
  6096. assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  6097. assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  6098. return Module["asm"]["stackRestore"].apply(null, arguments)
  6099. };
  6100. var stackSave = Module["stackSave"] = function() {
  6101. assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  6102. assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  6103. return Module["asm"]["stackSave"].apply(null, arguments)
  6104. };
  6105. var dynCall_ii = Module["dynCall_ii"] = function() {
  6106. assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  6107. assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  6108. return Module["asm"]["dynCall_ii"].apply(null, arguments)
  6109. };
  6110. var dynCall_iidiiii = Module["dynCall_iidiiii"] = function() {
  6111. assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  6112. assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  6113. return Module["asm"]["dynCall_iidiiii"].apply(null, arguments)
  6114. };
  6115. var dynCall_iiii = Module["dynCall_iiii"] = function() {
  6116. assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  6117. assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  6118. return Module["asm"]["dynCall_iiii"].apply(null, arguments)
  6119. };
  6120. var dynCall_jiji = Module["dynCall_jiji"] = function() {
  6121. assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  6122. assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  6123. return Module["asm"]["dynCall_jiji"].apply(null, arguments)
  6124. };
  6125. var dynCall_v = Module["dynCall_v"] = function() {
  6126. assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  6127. assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  6128. return Module["asm"]["dynCall_v"].apply(null, arguments)
  6129. };
  6130. var dynCall_vi = Module["dynCall_vi"] = function() {
  6131. assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  6132. assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  6133. return Module["asm"]["dynCall_vi"].apply(null, arguments)
  6134. };
  6135. var dynCall_vii = Module["dynCall_vii"] = function() {
  6136. assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  6137. assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  6138. return Module["asm"]["dynCall_vii"].apply(null, arguments)
  6139. };
  6140. var dynCall_viiii = Module["dynCall_viiii"] = function() {
  6141. assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  6142. assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  6143. return Module["asm"]["dynCall_viiii"].apply(null, arguments)
  6144. };
  6145. var dynCall_viiiii = Module["dynCall_viiiii"] = function() {
  6146. assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  6147. assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  6148. return Module["asm"]["dynCall_viiiii"].apply(null, arguments)
  6149. };
  6150. var dynCall_viiiiii = Module["dynCall_viiiiii"] = function() {
  6151. assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  6152. assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  6153. return Module["asm"]["dynCall_viiiiii"].apply(null, arguments)
  6154. };
  6155. // === Auto-generated postamble setup entry stuff ===
  6156. Module['asm'] = asm;
  6157. if (!Module["intArrayFromString"]) Module["intArrayFromString"] = function() { abort("'intArrayFromString' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6158. if (!Module["intArrayToString"]) Module["intArrayToString"] = function() { abort("'intArrayToString' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6159. Module["ccall"] = ccall;
  6160. Module["cwrap"] = cwrap;
  6161. if (!Module["setValue"]) Module["setValue"] = function() { abort("'setValue' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6162. Module["getValue"] = getValue;
  6163. if (!Module["allocate"]) Module["allocate"] = function() { abort("'allocate' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6164. 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"); };
  6165. if (!Module["AsciiToString"]) Module["AsciiToString"] = function() { abort("'AsciiToString' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6166. if (!Module["stringToAscii"]) Module["stringToAscii"] = function() { abort("'stringToAscii' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6167. if (!Module["UTF8ArrayToString"]) Module["UTF8ArrayToString"] = function() { abort("'UTF8ArrayToString' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6168. if (!Module["UTF8ToString"]) Module["UTF8ToString"] = function() { abort("'UTF8ToString' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6169. if (!Module["stringToUTF8Array"]) Module["stringToUTF8Array"] = function() { abort("'stringToUTF8Array' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6170. if (!Module["stringToUTF8"]) Module["stringToUTF8"] = function() { abort("'stringToUTF8' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6171. if (!Module["lengthBytesUTF8"]) Module["lengthBytesUTF8"] = function() { abort("'lengthBytesUTF8' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6172. if (!Module["UTF16ToString"]) Module["UTF16ToString"] = function() { abort("'UTF16ToString' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6173. if (!Module["stringToUTF16"]) Module["stringToUTF16"] = function() { abort("'stringToUTF16' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6174. if (!Module["lengthBytesUTF16"]) Module["lengthBytesUTF16"] = function() { abort("'lengthBytesUTF16' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6175. if (!Module["UTF32ToString"]) Module["UTF32ToString"] = function() { abort("'UTF32ToString' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6176. if (!Module["stringToUTF32"]) Module["stringToUTF32"] = function() { abort("'stringToUTF32' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6177. if (!Module["lengthBytesUTF32"]) Module["lengthBytesUTF32"] = function() { abort("'lengthBytesUTF32' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6178. if (!Module["allocateUTF8"]) Module["allocateUTF8"] = function() { abort("'allocateUTF8' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6179. if (!Module["stackTrace"]) Module["stackTrace"] = function() { abort("'stackTrace' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6180. if (!Module["addOnPreRun"]) Module["addOnPreRun"] = function() { abort("'addOnPreRun' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6181. if (!Module["addOnInit"]) Module["addOnInit"] = function() { abort("'addOnInit' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6182. if (!Module["addOnPreMain"]) Module["addOnPreMain"] = function() { abort("'addOnPreMain' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6183. if (!Module["addOnExit"]) Module["addOnExit"] = function() { abort("'addOnExit' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6184. if (!Module["addOnPostRun"]) Module["addOnPostRun"] = function() { abort("'addOnPostRun' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6185. if (!Module["writeStringToMemory"]) Module["writeStringToMemory"] = function() { abort("'writeStringToMemory' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6186. if (!Module["writeArrayToMemory"]) Module["writeArrayToMemory"] = function() { abort("'writeArrayToMemory' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6187. if (!Module["writeAsciiToMemory"]) Module["writeAsciiToMemory"] = function() { abort("'writeAsciiToMemory' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6188. 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"); };
  6189. 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"); };
  6190. if (!Module["ENV"]) Module["ENV"] = function() { abort("'ENV' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6191. if (!Module["FS"]) Module["FS"] = function() { abort("'FS' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6192. 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"); };
  6193. 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"); };
  6194. 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"); };
  6195. 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"); };
  6196. 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"); };
  6197. 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"); };
  6198. 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"); };
  6199. 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"); };
  6200. if (!Module["GL"]) Module["GL"] = function() { abort("'GL' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6201. if (!Module["dynamicAlloc"]) Module["dynamicAlloc"] = function() { abort("'dynamicAlloc' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6202. if (!Module["warnOnce"]) Module["warnOnce"] = function() { abort("'warnOnce' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6203. if (!Module["loadDynamicLibrary"]) Module["loadDynamicLibrary"] = function() { abort("'loadDynamicLibrary' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6204. if (!Module["loadWebAssemblyModule"]) Module["loadWebAssemblyModule"] = function() { abort("'loadWebAssemblyModule' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6205. if (!Module["getLEB"]) Module["getLEB"] = function() { abort("'getLEB' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6206. if (!Module["getFunctionTables"]) Module["getFunctionTables"] = function() { abort("'getFunctionTables' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6207. if (!Module["alignFunctionTables"]) Module["alignFunctionTables"] = function() { abort("'alignFunctionTables' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6208. if (!Module["registerFunctions"]) Module["registerFunctions"] = function() { abort("'registerFunctions' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6209. if (!Module["addFunction"]) Module["addFunction"] = function() { abort("'addFunction' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6210. if (!Module["removeFunction"]) Module["removeFunction"] = function() { abort("'removeFunction' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6211. if (!Module["getFuncWrapper"]) Module["getFuncWrapper"] = function() { abort("'getFuncWrapper' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6212. if (!Module["prettyPrint"]) Module["prettyPrint"] = function() { abort("'prettyPrint' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6213. if (!Module["makeBigInt"]) Module["makeBigInt"] = function() { abort("'makeBigInt' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6214. if (!Module["dynCall"]) Module["dynCall"] = function() { abort("'dynCall' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6215. if (!Module["getCompilerSetting"]) Module["getCompilerSetting"] = function() { abort("'getCompilerSetting' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6216. if (!Module["stackSave"]) Module["stackSave"] = function() { abort("'stackSave' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6217. if (!Module["stackRestore"]) Module["stackRestore"] = function() { abort("'stackRestore' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6218. if (!Module["stackAlloc"]) Module["stackAlloc"] = function() { abort("'stackAlloc' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6219. if (!Module["establishStackSpace"]) Module["establishStackSpace"] = function() { abort("'establishStackSpace' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6220. if (!Module["print"]) Module["print"] = function() { abort("'print' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6221. if (!Module["printErr"]) Module["printErr"] = function() { abort("'printErr' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6222. if (!Module["getTempRet0"]) Module["getTempRet0"] = function() { abort("'getTempRet0' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6223. if (!Module["setTempRet0"]) Module["setTempRet0"] = function() { abort("'setTempRet0' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6224. 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)"); } });
  6225. 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)"); } });
  6226. 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)"); } });
  6227. 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)"); } });
  6228. /**
  6229. * @constructor
  6230. * @extends {Error}
  6231. * @this {ExitStatus}
  6232. */
  6233. function ExitStatus(status) {
  6234. this.name = "ExitStatus";
  6235. this.message = "Program terminated with exit(" + status + ")";
  6236. this.status = status;
  6237. } ExitStatus.prototype = new Error();
  6238. ExitStatus.prototype.constructor = ExitStatus;
  6239. dependenciesFulfilled = function runCaller() {
  6240. // If run has never been called, and we should call run (INVOKE_RUN is true, and Module.noInitialRun is not false)
  6241. if (!Module['calledRun']) run();
  6242. if (!Module['calledRun']) dependenciesFulfilled = runCaller; // try this again later, after new deps are fulfilled
  6243. };
  6244. /** @type {function(Array=)} */
  6245. function run(args) {
  6246. args = args || Module['arguments'];
  6247. if (runDependencies > 0) {
  6248. return;
  6249. }
  6250. writeStackCookie();
  6251. preRun();
  6252. if (runDependencies > 0) return; // a preRun added a dependency, run will be called later
  6253. if (Module['calledRun']) return; // run may have just been called through dependencies being fulfilled just in this very frame
  6254. function doRun() {
  6255. if (Module['calledRun']) return; // run may have just been called while the async setStatus time below was happening
  6256. Module['calledRun'] = true;
  6257. if (ABORT) return;
  6258. ensureInitRuntime();
  6259. preMain();
  6260. if (Module['onRuntimeInitialized']) Module['onRuntimeInitialized']();
  6261. assert(!Module['_main'], 'compiled without a main, but one is present. if you added it from JS, use Module["onRuntimeInitialized"]');
  6262. postRun();
  6263. }
  6264. if (Module['setStatus']) {
  6265. Module['setStatus']('Running...');
  6266. setTimeout(function() {
  6267. setTimeout(function() {
  6268. Module['setStatus']('');
  6269. }, 1);
  6270. doRun();
  6271. }, 1);
  6272. } else {
  6273. doRun();
  6274. }
  6275. checkStackCookie();
  6276. }
  6277. Module['run'] = run;
  6278. var abortDecorators = [];
  6279. function abort(what) {
  6280. if (Module['onAbort']) {
  6281. Module['onAbort'](what);
  6282. }
  6283. if (what !== undefined) {
  6284. //out(what);
  6285. //err(what);
  6286. what = '"' + what + '"';
  6287. } else {
  6288. what = '';
  6289. }
  6290. ABORT = true;
  6291. var extra = '';
  6292. var output = 'abort(' + what + ') at ' + stackTrace() + extra;
  6293. if (abortDecorators) {
  6294. abortDecorators.forEach(function(decorator) {
  6295. output = decorator(output, what);
  6296. });
  6297. }
  6298. throw output;
  6299. }
  6300. Module['abort'] = abort;
  6301. if (Module['preInit']) {
  6302. if (typeof Module['preInit'] == 'function') Module['preInit'] = [Module['preInit']];
  6303. while (Module['preInit'].length > 0) {
  6304. Module['preInit'].pop()();
  6305. }
  6306. }
  6307. Module["noExitRuntime"] = true;
  6308. run();
  6309. } else {
  6310. var Module = null;
  6311. }
  6312. var earcutWasm = Module;
  6313. // {{MODULE_ADDITIONS}}
  6314. var earcutWasmReady = false;
  6315. if (when.defined(earcutWasm)) {
  6316. earcutWasm.onRuntimeInitialized = function () {
  6317. earcutWasmReady = true;
  6318. };
  6319. var earcutwasm = earcutWasm.cwrap('earcut','number',['number','number','number','number','number','number']);
  6320. }
  6321. var layout$3 = createLayout([
  6322. {name: 'a_pos', components: 2, type: 'Int16'}
  6323. ], 4);
  6324. var members$1 = layout$3.members;
  6325. var EARCUT_MAX_RINGS = 500;
  6326. var FillBucket = function FillBucket(options) {
  6327. this.zoom = options.zoom;
  6328. this.overscaling = options.overscaling;
  6329. this.layers = options.layers;
  6330. this.layerIds = this.layers.map(function (layer) {
  6331. return layer.id;
  6332. });
  6333. this.index = options.index;
  6334. this.hasPattern = false;
  6335. this.patternFeatures = [];
  6336. this.layoutVertexArray = new StructArrayLayout2i4();
  6337. this.indexArray = new StructArrayLayout3ui6();
  6338. this.indexArray2 = new StructArrayLayout2ui4();
  6339. this.programConfigurations = new ProgramConfigurationSet(members$1, options.layers, options.zoom);
  6340. this.segments = new SegmentVector();
  6341. this.segments2 = new SegmentVector();
  6342. this.stateDependentLayerIds = this.layers.filter(function (l) {
  6343. return l.isStateDependent();
  6344. }).map(function (l) {
  6345. return l.id;
  6346. });
  6347. };
  6348. FillBucket.prototype.populate = function populate(features, options) {
  6349. this.hasPattern = hasPattern('fill', this.layers, options);
  6350. var bucketFeatures = [];
  6351. for (var i = 0, list = features; i < list.length; i += 1) {
  6352. var ref = list[i];
  6353. var feature = ref.feature;
  6354. var index = ref.index;
  6355. var sourceLayerIndex = ref.sourceLayerIndex;
  6356. if (!this.layers[0]._featureFilter(new EvaluationParameters$1(0), feature)) {
  6357. continue;
  6358. }
  6359. var geometry = loadGeometry(feature);
  6360. var sortKey =
  6361. undefined;
  6362. var bucketFeature = {
  6363. id: feature.id,
  6364. properties: feature.properties,
  6365. type: feature.type,
  6366. sourceLayerIndex: sourceLayerIndex,
  6367. index: index,
  6368. geometry: geometry,
  6369. patterns: {},
  6370. sortKey: sortKey
  6371. };
  6372. bucketFeatures.push(bucketFeature);
  6373. }
  6374. for (var i$1 = 0, list$1 = bucketFeatures; i$1 < list$1.length; i$1 += 1) {
  6375. var bucketFeature$1 = list$1[i$1];
  6376. var ref$1 = bucketFeature$1;
  6377. var geometry$1 = ref$1.geometry;
  6378. var index$1 = ref$1.index;
  6379. var sourceLayerIndex$1 = ref$1.sourceLayerIndex;
  6380. if (this.hasPattern) {
  6381. var patternFeature = addPatternDependencies('fill', this.layers, bucketFeature$1, this.zoom, options);
  6382. // pattern features are added only once the pattern is loaded into the image atlas
  6383. // so are stored during populate until later updated with positions by tile worker in addFeatures
  6384. this.patternFeatures.push(patternFeature);
  6385. } else {
  6386. this.addFeature(bucketFeature$1, geometry$1, index$1, {}, options.indexData);
  6387. }
  6388. var feature$1 = features[index$1].feature;
  6389. options.featureIndex.insert(feature$1, geometry$1, index$1, sourceLayerIndex$1, this.index);
  6390. }
  6391. };
  6392. FillBucket.prototype.update = function update(states, vtLayer, imagePositions) {
  6393. if (!this.stateDependentLayers.length) {
  6394. return;
  6395. }
  6396. this.programConfigurations.updatePaintArrays(states, vtLayer, this.stateDependentLayers, imagePositions);
  6397. };
  6398. FillBucket.prototype.addFeatures = function addFeatures(options, imagePositions) {
  6399. for (var i = 0, list = this.patternFeatures; i < list.length; i += 1) {
  6400. var feature = list[i];
  6401. this.addFeature(feature, feature.geometry, feature.index, imagePositions);
  6402. }
  6403. };
  6404. FillBucket.prototype.isEmpty = function isEmpty() {
  6405. return this.layoutVertexArray.length === 0;
  6406. };
  6407. FillBucket.prototype.uploadPending = function uploadPending() {
  6408. return !this.uploaded || this.programConfigurations.needsUpload;
  6409. };
  6410. FillBucket.prototype.upload = function upload(context) {
  6411. if (!this.uploaded) {
  6412. if(this.layoutVertexArray == null) {
  6413. return;
  6414. }
  6415. this.layoutVertexBuffer = context.createVertexBuffer(this.layoutVertexArray, members$1);
  6416. this.indexBuffer = context.createIndexBuffer(this.indexArray);
  6417. this.indexBuffer2 = context.createIndexBuffer(this.indexArray2);
  6418. }
  6419. this.programConfigurations.upload(context);
  6420. this.uploaded = true;
  6421. };
  6422. FillBucket.prototype.destroy = function destroy() {
  6423. if (!this.layoutVertexBuffer) {
  6424. return;
  6425. }
  6426. this.layoutVertexBuffer.destroy();
  6427. this.indexBuffer.destroy();
  6428. this.indexBuffer2.destroy();
  6429. this.programConfigurations.destroy();
  6430. this.segments.destroy();
  6431. this.segments2.destroy();
  6432. };
  6433. FillBucket.prototype.clear = function clear() {
  6434. if (when.defined(this.layoutVertexArray)) {
  6435. this.layoutVertexArray = null;
  6436. }
  6437. if (when.defined(this.indexArray)) {
  6438. this.indexArray = null;
  6439. }
  6440. if (when.defined(this.indexArray2)) {
  6441. this.indexArray2 = null;
  6442. }
  6443. };
  6444. FillBucket.prototype.addFeature = function addFeature(feature, geometry, index, imagePositions, indexData) {
  6445. for (var i$4 = 0, list$2 = classifyRings(geometry, EARCUT_MAX_RINGS); i$4 < list$2.length; i$4 += 1) {
  6446. var polygon = list$2[i$4];
  6447. var numVertices = 0;
  6448. for (var i$2 = 0, list = polygon; i$2 < list.length; i$2 += 1) {
  6449. var ring = list[i$2];
  6450. numVertices += ring.length;
  6451. }
  6452. var triangleSegment = this.segments.prepareSegment(numVertices, this.layoutVertexArray, this.indexArray);
  6453. var triangleIndex = triangleSegment.vertexLength;
  6454. var flattened = [];
  6455. var holeIndices = [];
  6456. for (var i$3 = 0, list$1 = polygon; i$3 < list$1.length; i$3 += 1) {
  6457. var ring$1 = list$1[i$3];
  6458. if (ring$1.length === 0) {
  6459. continue;
  6460. }
  6461. if (ring$1 !== polygon[0]) {
  6462. holeIndices.push(flattened.length / 2);
  6463. }
  6464. var lineSegment = this.segments2.prepareSegment(ring$1.length, this.layoutVertexArray, this.indexArray2);
  6465. var lineIndex = lineSegment.vertexLength;
  6466. this.layoutVertexArray.emplaceBack(ring$1[0].x, ring$1[0].y);
  6467. this.indexArray2.emplaceBack(lineIndex + ring$1.length - 1, lineIndex);
  6468. flattened.push(ring$1[0].x);
  6469. flattened.push(ring$1[0].y);
  6470. for (var i = 1; i < ring$1.length; i++) {
  6471. this.layoutVertexArray.emplaceBack(ring$1[i].x, ring$1[i].y);
  6472. this.indexArray2.emplaceBack(lineIndex + i - 1, lineIndex + i);
  6473. flattened.push(ring$1[i].x);
  6474. flattened.push(ring$1[i].y);
  6475. }
  6476. lineSegment.vertexLength += ring$1.length;
  6477. lineSegment.primitiveLength += ring$1.length;
  6478. }
  6479. var indices;
  6480. if (when.defined(indexData) && when.defined(indexData[feature.id])) {
  6481. indices = indexData[feature.id];
  6482. } else if (earcutWasmReady === true) {
  6483. var data = new Int32Array(flattened);
  6484. var dataLength = data.length;
  6485. var offset = earcutWasm._malloc(Int32Array.BYTES_PER_ELEMENT * dataLength); //开辟内存
  6486. earcutWasm.HEAP32.set(data, offset / Int32Array.BYTES_PER_ELEMENT); //设置值
  6487. var hole = new Int32Array(holeIndices);
  6488. var holeLength = hole.length;
  6489. var offset1 = earcutWasm._malloc(Int32Array.BYTES_PER_ELEMENT * holeLength); //开辟内存
  6490. earcutWasm.HEAP32.set(hole, offset1 / Int32Array.BYTES_PER_ELEMENT); //设置值
  6491. var res = new Int32Array(dataLength * 10);
  6492. var offset2 = earcutWasm._malloc(Int32Array.BYTES_PER_ELEMENT * dataLength * 10); //开辟内存
  6493. earcutWasm.HEAP32.set(res, offset2 / Int32Array.BYTES_PER_ELEMENT);
  6494. var len = earcutwasm(offset, dataLength, offset1, holeLength, 2, offset2);
  6495. var result = new Int32Array(earcutWasm.HEAP32.buffer, offset2, len);
  6496. indices = new Int32Array(result);
  6497. earcutWasm._free(offset);
  6498. earcutWasm._free(offset1);
  6499. earcutWasm._free(offset2);
  6500. } else {
  6501. indices = earcut2_2_1.earcut(flattened, holeIndices);
  6502. }
  6503. for (var i$1 = 0; i$1 < indices.length; i$1 += 3) {
  6504. this.indexArray.emplaceBack(
  6505. triangleIndex + indices[i$1],
  6506. triangleIndex + indices[i$1 + 1],
  6507. triangleIndex + indices[i$1 + 2]);
  6508. }
  6509. triangleSegment.vertexLength += numVertices;
  6510. triangleSegment.primitiveLength += indices.length / 3;
  6511. }
  6512. this.programConfigurations.populatePaintArrays(this.layoutVertexArray.length, feature, index, imagePositions);
  6513. };
  6514. WebWorkerTransfer.register('FillBucket', FillBucket, {omit: ['layers', 'patternFeatures']});
  6515. var Struct = function Struct(structArray , index ) {
  6516. (this )._structArray = structArray;
  6517. this._pos1 = index * this.size;
  6518. this._pos2 = this._pos1 / 2;
  6519. this._pos4 = this._pos1 / 4;
  6520. this._pos8 = this._pos1 / 8;
  6521. };
  6522. var DEFAULT_CAPACITY$1 = 128;
  6523. var RESIZE_MULTIPLIER$1 = 5;
  6524. /**
  6525. * `StructArray` provides an abstraction over `ArrayBuffer` and `TypedArray`
  6526. * making it behave like an array of typed structs.
  6527. *
  6528. * Conceptually, a StructArray is comprised of elements, i.e., instances of its
  6529. * associated struct type. Each particular struct type, together with an
  6530. * alignment size, determines the memory layout of a StructArray whose elements
  6531. * are of that type. Thus, for each such layout that we need, we have
  6532. * a corrseponding StructArrayLayout class, inheriting from StructArray and
  6533. * implementing `emplaceBack()` and `_refreshViews()`.
  6534. *
  6535. * In some cases, where we need to access particular elements of a StructArray,
  6536. * we implement a more specific subclass that inherits from one of the
  6537. * StructArrayLayouts and adds a `get(i): T` accessor that returns a structured
  6538. * object whose properties are proxies into the underlying memory space for the
  6539. * i-th element. This affords the convience of working with (seemingly) plain
  6540. * Javascript objects without the overhead of serializing/deserializing them
  6541. * into ArrayBuffers for efficient web worker transfer.
  6542. *
  6543. * @private
  6544. */
  6545. var StructArray$1 = function StructArray() {
  6546. this.isTransferred = false;
  6547. this.capacity = -1;
  6548. this.resize(0);
  6549. };
  6550. /**
  6551. * Serialize a StructArray instance.Serializes both the raw data and the
  6552. * metadata needed to reconstruct the StructArray base class during
  6553. * deserialization.
  6554. */
  6555. StructArray$1.serialize = function serialize (array, transferables) {
  6556. //assert_1(!array.isTransferred);
  6557. if(array.isTransferred){
  6558. console.log("StructArray array.isTransferred.");
  6559. }
  6560. array._trim();
  6561. if (transferables) {
  6562. array.isTransferred = true;
  6563. transferables.push(array.arrayBuffer);
  6564. }
  6565. return {
  6566. length: array.length,
  6567. arrayBuffer: array.arrayBuffer,
  6568. };
  6569. };
  6570. StructArray$1.deserialize = function deserialize (input ) {
  6571. var structArray = Object.create(this.prototype);
  6572. structArray.arrayBuffer = input.arrayBuffer;
  6573. structArray.length = input.length;
  6574. structArray.capacity = input.arrayBuffer.byteLength / structArray.bytesPerElement;
  6575. structArray._refreshViews();
  6576. return structArray;
  6577. };
  6578. /**
  6579. * Resize the array to discard unused capacity.
  6580. */
  6581. StructArray$1.prototype._trim = function _trim () {
  6582. if (this.length !== this.capacity) {
  6583. this.capacity = this.length;
  6584. this.arrayBuffer = this.arrayBuffer.slice(0, this.length * this.bytesPerElement);
  6585. this._refreshViews();
  6586. }
  6587. };
  6588. /**
  6589. * Resets the the length of the array to 0 without de-allocating capcacity.
  6590. */
  6591. StructArray$1.prototype.clear = function clear () {
  6592. this.length = 0;
  6593. };
  6594. /**
  6595. * Resize the array.
  6596. * If `n` is greater than the current length then additional elements with undefined values are added.
  6597. * If `n` is less than the current length then the array will be reduced to the first `n` elements.
  6598. * @param {number} n The new size of the array.
  6599. */
  6600. StructArray$1.prototype.resize = function resize (n ) {
  6601. //assert_1(!this.isTransferred);
  6602. this.reserve(n);
  6603. this.length = n;
  6604. };
  6605. /**
  6606. * Indicate a planned increase in size, so that any necessary allocation may
  6607. * be done once, ahead of time.
  6608. * @param {number} n The expected size of the array.
  6609. */
  6610. StructArray$1.prototype.reserve = function reserve (n ) {
  6611. if (n > this.capacity) {
  6612. this.capacity = Math.max(n, Math.floor(this.capacity * RESIZE_MULTIPLIER$1), DEFAULT_CAPACITY$1);
  6613. this.arrayBuffer = new ArrayBuffer(this.capacity * this.bytesPerElement);
  6614. var oldUint8Array = this.uint8;
  6615. this._refreshViews();
  6616. if (oldUint8Array) { this.uint8.set(oldUint8Array); }
  6617. }
  6618. };
  6619. /**
  6620. * Create TypedArray views for the current ArrayBuffer.
  6621. */
  6622. StructArray$1.prototype._refreshViews = function _refreshViews () {
  6623. throw new Error('_refreshViews() must be implemented by each concrete StructArray layout');
  6624. };
  6625. /**
  6626. * Implementation of the StructArray layout:
  6627. * [0]: Uint32[1]
  6628. * [4]: Uint16[2]
  6629. *
  6630. * @private
  6631. */
  6632. var StructArrayLayout1ul2ui8 = /*@__PURE__*/(function (StructArray) {
  6633. function StructArrayLayout1ul2ui8 () {
  6634. StructArray.apply(this, arguments);
  6635. }
  6636. if ( StructArray ) StructArrayLayout1ul2ui8.__proto__ = StructArray;
  6637. StructArrayLayout1ul2ui8.prototype = Object.create( StructArray && StructArray.prototype );
  6638. StructArrayLayout1ul2ui8.prototype.constructor = StructArrayLayout1ul2ui8;
  6639. StructArrayLayout1ul2ui8.prototype._refreshViews = function _refreshViews () {
  6640. this.uint8 = new Uint8Array(this.arrayBuffer);
  6641. this.uint32 = new Uint32Array(this.arrayBuffer);
  6642. this.uint16 = new Uint16Array(this.arrayBuffer);
  6643. };
  6644. StructArrayLayout1ul2ui8.prototype.emplaceBack = function emplaceBack (v0 , v1 , v2 ) {
  6645. var i = this.length;
  6646. this.resize(i + 1);
  6647. return this.emplace(i, v0, v1, v2);
  6648. };
  6649. StructArrayLayout1ul2ui8.prototype.emplace = function emplace (i , v0 , v1 , v2 ) {
  6650. var o4 = i * 2;
  6651. var o2 = i * 4;
  6652. this.uint32[o4 + 0] = v0;
  6653. this.uint16[o2 + 2] = v1;
  6654. this.uint16[o2 + 3] = v2;
  6655. return i;
  6656. };
  6657. return StructArrayLayout1ul2ui8;
  6658. }(StructArray$1));
  6659. StructArrayLayout1ul2ui8.prototype.bytesPerElement = 8;
  6660. var FeatureIndexStruct = /*@__PURE__*/(function (Struct) {
  6661. function FeatureIndexStruct () {
  6662. Struct.apply(this, arguments);
  6663. }
  6664. if ( Struct ) FeatureIndexStruct.__proto__ = Struct;
  6665. FeatureIndexStruct.prototype = Object.create( Struct && Struct.prototype );
  6666. FeatureIndexStruct.prototype.constructor = FeatureIndexStruct;
  6667. var prototypeAccessors$5 = { featureIndex: { configurable: true },sourceLayerIndex: { configurable: true },bucketIndex: { configurable: true } };
  6668. prototypeAccessors$5.featureIndex.get = function () { return this._structArray.uint32[this._pos4 + 0]; };
  6669. prototypeAccessors$5.featureIndex.set = function (x ) { this._structArray.uint32[this._pos4 + 0] = x; };
  6670. prototypeAccessors$5.sourceLayerIndex.get = function () { return this._structArray.uint16[this._pos2 + 2]; };
  6671. prototypeAccessors$5.sourceLayerIndex.set = function (x ) { this._structArray.uint16[this._pos2 + 2] = x; };
  6672. prototypeAccessors$5.bucketIndex.get = function () { return this._structArray.uint16[this._pos2 + 3]; };
  6673. prototypeAccessors$5.bucketIndex.set = function (x ) { this._structArray.uint16[this._pos2 + 3] = x; };
  6674. Object.defineProperties( FeatureIndexStruct.prototype, prototypeAccessors$5 );
  6675. return FeatureIndexStruct;
  6676. }(Struct));
  6677. FeatureIndexStruct.prototype.size = 8;
  6678. /**
  6679. * @private
  6680. */
  6681. var FeatureIndexArray = /*@__PURE__*/(function (StructArrayLayout1ul2ui8) {
  6682. function FeatureIndexArray () {
  6683. StructArrayLayout1ul2ui8.apply(this, arguments);
  6684. }
  6685. if ( StructArrayLayout1ul2ui8 ) FeatureIndexArray.__proto__ = StructArrayLayout1ul2ui8;
  6686. FeatureIndexArray.prototype = Object.create( StructArrayLayout1ul2ui8 && StructArrayLayout1ul2ui8.prototype );
  6687. FeatureIndexArray.prototype.constructor = FeatureIndexArray;
  6688. FeatureIndexArray.prototype.get = function get (index ) {
  6689. //assert_1(!this.isTransferred);
  6690. return new FeatureIndexStruct(this, index);
  6691. };
  6692. return FeatureIndexArray;
  6693. }(StructArrayLayout1ul2ui8));
  6694. WebWorkerTransfer.register('FeatureIndexArray', FeatureIndexArray, {omit: ['layers', 'patternFeatures']});
  6695. var arrayTypes = {
  6696. FeatureIndexArray : FeatureIndexArray
  6697. };
  6698. /**
  6699. * A standalone point geometry with useful accessor, comparison, and
  6700. * modification methods.
  6701. *
  6702. * @class Point
  6703. * @param {Number} x the x-coordinate. this could be longitude or screen
  6704. * pixels, or any other sort of unit.
  6705. * @param {Number} y the y-coordinate. this could be latitude or screen
  6706. * pixels, or any other sort of unit.
  6707. * @example
  6708. * var point = new Point(-77, 38);
  6709. */
  6710. function Point(x, y) {
  6711. this.x = x;
  6712. this.y = y;
  6713. }
  6714. Point.prototype = {
  6715. /**
  6716. * Clone this point, returning a new point that can be modified
  6717. * without affecting the old one.
  6718. * @return {Point} the clone
  6719. */
  6720. clone: function() { return new Point(this.x, this.y); },
  6721. /**
  6722. * Add this point's x & y coordinates to another point,
  6723. * yielding a new point.
  6724. * @param {Point} p the other point
  6725. * @return {Point} output point
  6726. */
  6727. add: function(p) { return this.clone()._add(p); },
  6728. /**
  6729. * Subtract this point's x & y coordinates to from point,
  6730. * yielding a new point.
  6731. * @param {Point} p the other point
  6732. * @return {Point} output point
  6733. */
  6734. sub: function(p) { return this.clone()._sub(p); },
  6735. /**
  6736. * Multiply this point's x & y coordinates by point,
  6737. * yielding a new point.
  6738. * @param {Point} p the other point
  6739. * @return {Point} output point
  6740. */
  6741. multByPoint: function(p) { return this.clone()._multByPoint(p); },
  6742. /**
  6743. * Divide this point's x & y coordinates by point,
  6744. * yielding a new point.
  6745. * @param {Point} p the other point
  6746. * @return {Point} output point
  6747. */
  6748. divByPoint: function(p) { return this.clone()._divByPoint(p); },
  6749. /**
  6750. * Multiply this point's x & y coordinates by a factor,
  6751. * yielding a new point.
  6752. * @param {Point} k factor
  6753. * @return {Point} output point
  6754. */
  6755. mult: function(k) { return this.clone()._mult(k); },
  6756. /**
  6757. * Divide this point's x & y coordinates by a factor,
  6758. * yielding a new point.
  6759. * @param {Point} k factor
  6760. * @return {Point} output point
  6761. */
  6762. div: function(k) { return this.clone()._div(k); },
  6763. /**
  6764. * Rotate this point around the 0, 0 origin by an angle a,
  6765. * given in radians
  6766. * @param {Number} a angle to rotate around, in radians
  6767. * @return {Point} output point
  6768. */
  6769. rotate: function(a) { return this.clone()._rotate(a); },
  6770. /**
  6771. * Rotate this point around p point by an angle a,
  6772. * given in radians
  6773. * @param {Number} a angle to rotate around, in radians
  6774. * @param {Point} p Point to rotate around
  6775. * @return {Point} output point
  6776. */
  6777. rotateAround: function(a,p) { return this.clone()._rotateAround(a,p); },
  6778. /**
  6779. * Multiply this point by a 4x1 transformation matrix
  6780. * @param {Array<Number>} m transformation matrix
  6781. * @return {Point} output point
  6782. */
  6783. matMult: function(m) { return this.clone()._matMult(m); },
  6784. /**
  6785. * Calculate this point but as a unit vector from 0, 0, meaning
  6786. * that the distance from the resulting point to the 0, 0
  6787. * coordinate will be equal to 1 and the angle from the resulting
  6788. * point to the 0, 0 coordinate will be the same as before.
  6789. * @return {Point} unit vector point
  6790. */
  6791. unit: function() { return this.clone()._unit(); },
  6792. /**
  6793. * Compute a perpendicular point, where the new y coordinate
  6794. * is the old x coordinate and the new x coordinate is the old y
  6795. * coordinate multiplied by -1
  6796. * @return {Point} perpendicular point
  6797. */
  6798. perp: function() { return this.clone()._perp(); },
  6799. /**
  6800. * Return a version of this point with the x & y coordinates
  6801. * rounded to integers.
  6802. * @return {Point} rounded point
  6803. */
  6804. round: function() { return this.clone()._round(); },
  6805. /**
  6806. * Return the magitude of this point: this is the Euclidean
  6807. * distance from the 0, 0 coordinate to this point's x and y
  6808. * coordinates.
  6809. * @return {Number} magnitude
  6810. */
  6811. mag: function() {
  6812. return Math.sqrt(this.x * this.x + this.y * this.y);
  6813. },
  6814. /**
  6815. * Judge whether this point is equal to another point, returning
  6816. * true or false.
  6817. * @param {Point} other the other point
  6818. * @return {boolean} whether the points are equal
  6819. */
  6820. equals: function(other) {
  6821. return this.x === other.x &&
  6822. this.y === other.y;
  6823. },
  6824. /**
  6825. * Calculate the distance from this point to another point
  6826. * @param {Point} p the other point
  6827. * @return {Number} distance
  6828. */
  6829. dist: function(p) {
  6830. return Math.sqrt(this.distSqr(p));
  6831. },
  6832. /**
  6833. * Calculate the distance from this point to another point,
  6834. * without the square root step. Useful if you're comparing
  6835. * relative distances.
  6836. * @param {Point} p the other point
  6837. * @return {Number} distance
  6838. */
  6839. distSqr: function(p) {
  6840. var dx = p.x - this.x,
  6841. dy = p.y - this.y;
  6842. return dx * dx + dy * dy;
  6843. },
  6844. /**
  6845. * Get the angle from the 0, 0 coordinate to this point, in radians
  6846. * coordinates.
  6847. * @return {Number} angle
  6848. */
  6849. angle: function() {
  6850. return Math.atan2(this.y, this.x);
  6851. },
  6852. /**
  6853. * Get the angle from this point to another point, in radians
  6854. * @param {Point} b the other point
  6855. * @return {Number} angle
  6856. */
  6857. angleTo: function(b) {
  6858. return Math.atan2(this.y - b.y, this.x - b.x);
  6859. },
  6860. /**
  6861. * Get the angle between this point and another point, in radians
  6862. * @param {Point} b the other point
  6863. * @return {Number} angle
  6864. */
  6865. angleWith: function(b) {
  6866. return this.angleWithSep(b.x, b.y);
  6867. },
  6868. /*
  6869. * Find the angle of the two vectors, solving the formula for
  6870. * the cross product a x b = |a||b|sin(θ) for θ.
  6871. * @param {Number} x the x-coordinate
  6872. * @param {Number} y the y-coordinate
  6873. * @return {Number} the angle in radians
  6874. */
  6875. angleWithSep: function(x, y) {
  6876. return Math.atan2(
  6877. this.x * y - this.y * x,
  6878. this.x * x + this.y * y);
  6879. },
  6880. _matMult: function(m) {
  6881. var x = m[0] * this.x + m[1] * this.y,
  6882. y = m[2] * this.x + m[3] * this.y;
  6883. this.x = x;
  6884. this.y = y;
  6885. return this;
  6886. },
  6887. _add: function(p) {
  6888. this.x += p.x;
  6889. this.y += p.y;
  6890. return this;
  6891. },
  6892. _sub: function(p) {
  6893. this.x -= p.x;
  6894. this.y -= p.y;
  6895. return this;
  6896. },
  6897. _mult: function(k) {
  6898. this.x *= k;
  6899. this.y *= k;
  6900. return this;
  6901. },
  6902. _div: function(k) {
  6903. this.x /= k;
  6904. this.y /= k;
  6905. return this;
  6906. },
  6907. _multByPoint: function(p) {
  6908. this.x *= p.x;
  6909. this.y *= p.y;
  6910. return this;
  6911. },
  6912. _divByPoint: function(p) {
  6913. this.x /= p.x;
  6914. this.y /= p.y;
  6915. return this;
  6916. },
  6917. _unit: function() {
  6918. this._div(this.mag());
  6919. return this;
  6920. },
  6921. _perp: function() {
  6922. var y = this.y;
  6923. this.y = this.x;
  6924. this.x = -y;
  6925. return this;
  6926. },
  6927. _rotate: function(angle) {
  6928. var cos = Math.cos(angle),
  6929. sin = Math.sin(angle),
  6930. x = cos * this.x - sin * this.y,
  6931. y = sin * this.x + cos * this.y;
  6932. this.x = x;
  6933. this.y = y;
  6934. return this;
  6935. },
  6936. _rotateAround: function(angle, p) {
  6937. var cos = Math.cos(angle),
  6938. sin = Math.sin(angle),
  6939. x = p.x + cos * (this.x - p.x) - sin * (this.y - p.y),
  6940. y = p.y + sin * (this.x - p.x) + cos * (this.y - p.y);
  6941. this.x = x;
  6942. this.y = y;
  6943. return this;
  6944. },
  6945. _round: function() {
  6946. this.x = Math.round(this.x);
  6947. this.y = Math.round(this.y);
  6948. return this;
  6949. }
  6950. };
  6951. /**
  6952. * Construct a point from an array if necessary, otherwise if the input
  6953. * is already a Point, or an unknown type, return it unchanged
  6954. * @param {Array<Number>|Point|*} a any kind of input value
  6955. * @return {Point} constructed point, or passed-through value.
  6956. * @example
  6957. * // this
  6958. * var point = Point.convert([0, 1]);
  6959. * // is equivalent to
  6960. * var point = new Point(0, 1);
  6961. */
  6962. Point.convert = function (a) {
  6963. if (a instanceof Point) {
  6964. return a;
  6965. }
  6966. if (Array.isArray(a)) {
  6967. return new Point(a[0], a[1]);
  6968. }
  6969. return a;
  6970. };
  6971. function VectorTileFeature(pbf, end, extent, keys, values) {
  6972. // Public
  6973. this.properties = {};
  6974. this.extent = extent;
  6975. this.type = 0;
  6976. // Private
  6977. this._pbf = pbf;
  6978. this._geometry = -1;
  6979. this._keys = keys;
  6980. this._values = values;
  6981. pbf.readFields(readFeature, this, end);
  6982. }
  6983. function readFeature(tag, feature, pbf) {
  6984. if (tag == 1) feature.id = pbf.readVarint();
  6985. else if (tag == 2) readTag(pbf, feature);
  6986. else if (tag == 3) feature.type = pbf.readVarint();
  6987. else if (tag == 4) feature._geometry = pbf.pos;
  6988. }
  6989. function readTag(pbf, feature) {
  6990. var end = pbf.readVarint() + pbf.pos;
  6991. while (pbf.pos < end) {
  6992. var key = feature._keys[pbf.readVarint()],
  6993. value = feature._values[pbf.readVarint()];
  6994. feature.properties[key] = value;
  6995. }
  6996. }
  6997. VectorTileFeature.types = ['Unknown', 'Point', 'LineString', 'Polygon'];
  6998. VectorTileFeature.prototype.loadGeometry = function() {
  6999. var pbf = this._pbf;
  7000. pbf.pos = this._geometry;
  7001. var end = pbf.readVarint() + pbf.pos,
  7002. cmd = 1,
  7003. length = 0,
  7004. x = 0,
  7005. y = 0,
  7006. lines = [],
  7007. line;
  7008. while (pbf.pos < end) {
  7009. if (length <= 0) {
  7010. var cmdLen = pbf.readVarint();
  7011. cmd = cmdLen & 0x7;
  7012. length = cmdLen >> 3;
  7013. }
  7014. length--;
  7015. if (cmd === 1 || cmd === 2) {
  7016. x += pbf.readSVarint();
  7017. y += pbf.readSVarint();
  7018. if (cmd === 1) { // moveTo
  7019. if (line) lines.push(line);
  7020. line = [];
  7021. }
  7022. line.push(new Point(x, y));
  7023. } else if (cmd === 7) {
  7024. // Workaround for https://github.com/mapbox/mapnik-vector-tile/issues/90
  7025. if (line) {
  7026. line.push(line[0].clone()); // closePolygon
  7027. }
  7028. } else {
  7029. console.log('VectorTileFeature loadGeometry unknown command ' + cmd);
  7030. //throw new Error('unknown command ' + cmd);
  7031. }
  7032. }
  7033. if (line) lines.push(line);
  7034. return lines;
  7035. };
  7036. VectorTileFeature.prototype.bbox = function() {
  7037. var pbf = this._pbf;
  7038. pbf.pos = this._geometry;
  7039. var end = pbf.readVarint() + pbf.pos,
  7040. cmd = 1,
  7041. length = 0,
  7042. x = 0,
  7043. y = 0,
  7044. x1 = Infinity,
  7045. x2 = -Infinity,
  7046. y1 = Infinity,
  7047. y2 = -Infinity;
  7048. while (pbf.pos < end) {
  7049. if (length <= 0) {
  7050. var cmdLen = pbf.readVarint();
  7051. cmd = cmdLen & 0x7;
  7052. length = cmdLen >> 3;
  7053. }
  7054. length--;
  7055. if (cmd === 1 || cmd === 2) {
  7056. x += pbf.readSVarint();
  7057. y += pbf.readSVarint();
  7058. if (x < x1) x1 = x;
  7059. if (x > x2) x2 = x;
  7060. if (y < y1) y1 = y;
  7061. if (y > y2) y2 = y;
  7062. } else if (cmd !== 7) {
  7063. throw new Error('unknown command ' + cmd);
  7064. }
  7065. }
  7066. return [x1, y1, x2, y2];
  7067. };
  7068. VectorTileFeature.prototype.toGeoJSON = function(x, y, z) {
  7069. var size = this.extent * Math.pow(2, z),
  7070. x0 = this.extent * x,
  7071. y0 = this.extent * y,
  7072. coords = this.loadGeometry(),
  7073. type = VectorTileFeature.types[this.type],
  7074. i, j;
  7075. function project(line) {
  7076. for (var j = 0; j < line.length; j++) {
  7077. var p = line[j], y2 = 180 - (p.y + y0) * 360 / size;
  7078. line[j] = [
  7079. (p.x + x0) * 360 / size - 180,
  7080. 360 / Math.PI * Math.atan(Math.exp(y2 * Math.PI / 180)) - 90
  7081. ];
  7082. }
  7083. }
  7084. switch (this.type) {
  7085. case 1:
  7086. var points = [];
  7087. for (i = 0; i < coords.length; i++) {
  7088. points[i] = coords[i][0];
  7089. }
  7090. coords = points;
  7091. project(coords);
  7092. break;
  7093. case 2:
  7094. for (i = 0; i < coords.length; i++) {
  7095. project(coords[i]);
  7096. }
  7097. break;
  7098. case 3:
  7099. coords = classifyRings$1(coords);
  7100. for (i = 0; i < coords.length; i++) {
  7101. for (j = 0; j < coords[i].length; j++) {
  7102. project(coords[i][j]);
  7103. }
  7104. }
  7105. break;
  7106. }
  7107. if (coords.length === 1) {
  7108. coords = coords[0];
  7109. } else {
  7110. type = 'Multi' + type;
  7111. }
  7112. var result = {
  7113. type: "Feature",
  7114. geometry: {
  7115. type: type,
  7116. coordinates: coords
  7117. },
  7118. properties: this.properties
  7119. };
  7120. if ('id' in this) {
  7121. result.id = this.id;
  7122. }
  7123. return result;
  7124. };
  7125. // classifies an array of rings into polygons with outer rings and holes
  7126. function classifyRings$1(rings) {
  7127. var len = rings.length;
  7128. if (len <= 1) return [rings];
  7129. var polygons = [],
  7130. polygon,
  7131. ccw;
  7132. for (var i = 0; i < len; i++) {
  7133. var area = signedArea(rings[i]);
  7134. if (area === 0) continue;
  7135. if (ccw === undefined) ccw = area < 0;
  7136. if (ccw === area < 0) {
  7137. if (polygon) polygons.push(polygon);
  7138. polygon = [rings[i]];
  7139. } else {
  7140. polygon.push(rings[i]);
  7141. }
  7142. }
  7143. if (polygon) polygons.push(polygon);
  7144. return polygons;
  7145. }
  7146. function signedArea(ring) {
  7147. var sum = 0;
  7148. for (var i = 0, len = ring.length, j = len - 1, p1, p2; i < len; j = i++) {
  7149. p1 = ring[i];
  7150. p2 = ring[j];
  7151. sum += (p2.x - p1.x) * (p1.y + p2.y);
  7152. }
  7153. return sum;
  7154. }
  7155. function VectorTileLayer(pbf, end) {
  7156. // Public
  7157. this.version = 1;
  7158. this.name = null;
  7159. this.extent = 4096;
  7160. this.length = 0;
  7161. // Private
  7162. this._pbf = pbf;
  7163. this._keys = [];
  7164. this._values = [];
  7165. this._features = [];
  7166. pbf.readFields(readLayer, this, end);
  7167. this.length = this._features.length;
  7168. }
  7169. function readLayer(tag, layer, pbf) {
  7170. if (tag === 15) layer.version = pbf.readVarint();
  7171. else if (tag === 1) layer.name = pbf.readString();
  7172. else if (tag === 5) layer.extent = pbf.readVarint();
  7173. else if (tag === 2) layer._features.push(pbf.pos);
  7174. else if (tag === 3) layer._keys.push(pbf.readString());
  7175. else if (tag === 4) layer._values.push(readValueMessage(pbf));
  7176. }
  7177. function readValueMessage(pbf) {
  7178. var value = null,
  7179. end = pbf.readVarint() + pbf.pos;
  7180. while (pbf.pos < end) {
  7181. var tag = pbf.readVarint() >> 3;
  7182. value = tag === 1 ? pbf.readString() :
  7183. tag === 2 ? pbf.readFloat() :
  7184. tag === 3 ? pbf.readDouble() :
  7185. tag === 4 ? pbf.readVarint64() :
  7186. tag === 5 ? pbf.readVarint() :
  7187. tag === 6 ? pbf.readSVarint() :
  7188. tag === 7 ? pbf.readBoolean() : null;
  7189. }
  7190. return value;
  7191. }
  7192. // return feature `i` from this layer as a `VectorTileFeature`
  7193. VectorTileLayer.prototype.feature = function(i) {
  7194. if (i < 0 || i >= this._features.length) throw new Error('feature index out of bounds');
  7195. this._pbf.pos = this._features[i];
  7196. var end = this._pbf.readVarint() + this._pbf.pos;
  7197. return new VectorTileFeature(this._pbf, end, this.extent, this._keys, this._values);
  7198. };
  7199. function VectorTile(pbf, end) {
  7200. this.layers = pbf.readFields(readTile, {}, end);
  7201. }
  7202. function readTile(tag, layers, pbf) {
  7203. if (tag === 3) {
  7204. var layer = new VectorTileLayer(pbf, pbf.readVarint() + pbf.pos);
  7205. if (layer.length) layers[layer.name] = layer;
  7206. }
  7207. }
  7208. var NUM_PARAMS = 3;
  7209. function GridIndex(extent, n, padding) {
  7210. var cells = this.cells = [];
  7211. if (extent instanceof ArrayBuffer) {
  7212. this.arrayBuffer = extent;
  7213. var array = new Int32Array(this.arrayBuffer);
  7214. extent = array[0];
  7215. n = array[1];
  7216. padding = array[2];
  7217. this.d = n + 2 * padding;
  7218. for (var k = 0; k < this.d * this.d; k++) {
  7219. var start = array[NUM_PARAMS + k];
  7220. var end = array[NUM_PARAMS + k + 1];
  7221. cells.push(start === end ?
  7222. null :
  7223. array.subarray(start, end));
  7224. }
  7225. var keysOffset = array[NUM_PARAMS + cells.length];
  7226. var bboxesOffset = array[NUM_PARAMS + cells.length + 1];
  7227. this.keys = array.subarray(keysOffset, bboxesOffset);
  7228. this.bboxes = array.subarray(bboxesOffset);
  7229. this.insert = this._insertReadonly;
  7230. } else {
  7231. this.d = n + 2 * padding;
  7232. for (var i = 0; i < this.d * this.d; i++) {
  7233. cells.push([]);
  7234. }
  7235. this.keys = [];
  7236. this.bboxes = [];
  7237. }
  7238. this.n = n;
  7239. this.extent = extent;
  7240. this.padding = padding;
  7241. this.scale = n / extent;
  7242. this.uid = 0;
  7243. var p = (padding / n) * extent;
  7244. this.min = -p;
  7245. this.max = extent + p;
  7246. }
  7247. GridIndex.prototype.insert = function(key, x1, y1, x2, y2) {
  7248. this._forEachCell(x1, y1, x2, y2, this._insertCell, this.uid++);
  7249. this.keys.push(key);
  7250. this.bboxes.push(x1);
  7251. this.bboxes.push(y1);
  7252. this.bboxes.push(x2);
  7253. this.bboxes.push(y2);
  7254. };
  7255. GridIndex.prototype._insertReadonly = function() {
  7256. throw 'Cannot insert into a GridIndex created from an ArrayBuffer.';
  7257. };
  7258. GridIndex.prototype._insertCell = function(x1, y1, x2, y2, cellIndex, uid) {
  7259. this.cells[cellIndex].push(uid);
  7260. };
  7261. GridIndex.prototype.query = function(x1, y1, x2, y2, intersectionTest) {
  7262. var min = this.min;
  7263. var max = this.max;
  7264. if (x1 <= min && y1 <= min && max <= x2 && max <= y2 && !intersectionTest) {
  7265. // We use `Array#slice` because `this.keys` may be a `Int32Array` and
  7266. // some browsers (Safari and IE) do not support `TypedArray#slice`
  7267. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/slice#Browser_compatibility
  7268. return Array.prototype.slice.call(this.keys);
  7269. } else {
  7270. var result = [];
  7271. var seenUids = {};
  7272. this._forEachCell(x1, y1, x2, y2, this._queryCell, result, seenUids, intersectionTest);
  7273. return result;
  7274. }
  7275. };
  7276. GridIndex.prototype._queryCell = function(x1, y1, x2, y2, cellIndex, result, seenUids, intersectionTest) {
  7277. var cell = this.cells[cellIndex];
  7278. if (cell !== null) {
  7279. var keys = this.keys;
  7280. var bboxes = this.bboxes;
  7281. for (var u = 0; u < cell.length; u++) {
  7282. var uid = cell[u];
  7283. if (seenUids[uid] === undefined) {
  7284. var offset = uid * 4;
  7285. if (intersectionTest ?
  7286. intersectionTest(bboxes[offset + 0], bboxes[offset + 1], bboxes[offset + 2], bboxes[offset + 3]) :
  7287. ((x1 <= bboxes[offset + 2]) &&
  7288. (y1 <= bboxes[offset + 3]) &&
  7289. (x2 >= bboxes[offset + 0]) &&
  7290. (y2 >= bboxes[offset + 1]))) {
  7291. seenUids[uid] = true;
  7292. result.push(keys[uid]);
  7293. } else {
  7294. seenUids[uid] = false;
  7295. }
  7296. }
  7297. }
  7298. }
  7299. };
  7300. GridIndex.prototype._forEachCell = function(x1, y1, x2, y2, fn, arg1, arg2, intersectionTest) {
  7301. var cx1 = this._convertToCellCoord(x1);
  7302. var cy1 = this._convertToCellCoord(y1);
  7303. var cx2 = this._convertToCellCoord(x2);
  7304. var cy2 = this._convertToCellCoord(y2);
  7305. for (var x = cx1; x <= cx2; x++) {
  7306. for (var y = cy1; y <= cy2; y++) {
  7307. var cellIndex = this.d * y + x;
  7308. if (intersectionTest && !intersectionTest(
  7309. this._convertFromCellCoord(x),
  7310. this._convertFromCellCoord(y),
  7311. this._convertFromCellCoord(x + 1),
  7312. this._convertFromCellCoord(y + 1))) { continue; }
  7313. if (fn.call(this, x1, y1, x2, y2, cellIndex, arg1, arg2, intersectionTest)) { return; }
  7314. }
  7315. }
  7316. };
  7317. GridIndex.prototype._convertFromCellCoord = function(x) {
  7318. return (x - this.padding) / this.scale;
  7319. };
  7320. GridIndex.prototype._convertToCellCoord = function(x) {
  7321. return Math.max(0, Math.min(this.d - 1, Math.floor(x * this.scale) + this.padding));
  7322. };
  7323. GridIndex.prototype.toArrayBuffer = function() {
  7324. if (this.arrayBuffer) { return this.arrayBuffer; }
  7325. var cells = this.cells;
  7326. var metadataLength = NUM_PARAMS + this.cells.length + 1 + 1;
  7327. var totalCellLength = 0;
  7328. for (var i = 0; i < this.cells.length; i++) {
  7329. totalCellLength += this.cells[i].length;
  7330. }
  7331. var array = new Int32Array(metadataLength + totalCellLength + this.keys.length + this.bboxes.length);
  7332. array[0] = this.extent;
  7333. array[1] = this.n;
  7334. array[2] = this.padding;
  7335. var offset = metadataLength;
  7336. for (var k = 0; k < cells.length; k++) {
  7337. var cell = cells[k];
  7338. array[NUM_PARAMS + k] = offset;
  7339. array.set(cell, offset);
  7340. offset += cell.length;
  7341. }
  7342. array[NUM_PARAMS + cells.length] = offset;
  7343. array.set(this.keys, offset);
  7344. offset += this.keys.length;
  7345. array[NUM_PARAMS + cells.length + 1] = offset;
  7346. array.set(this.bboxes, offset);
  7347. offset += this.bboxes.length;
  7348. return array.buffer;
  7349. };
  7350. WebWorkerTransfer.register('GridIndex', GridIndex, {omit: ['layers', 'patternFeatures']});
  7351. /**
  7352. * @module util
  7353. * @private
  7354. */
  7355. function Util() {
  7356. }
  7357. /**
  7358. * Given a value `t` that varies between 0 and 1, return
  7359. * an interpolation function that eases between 0 and 1 in a pleasing
  7360. * cubic in-out fashion.
  7361. *
  7362. * @private
  7363. */
  7364. Util.easeCubicInOut = function (t) {
  7365. if (t <= 0) {
  7366. return 0;
  7367. }
  7368. if (t >= 1) {
  7369. return 1;
  7370. }
  7371. var t2 = t * t,
  7372. t3 = t2 * t;
  7373. return 4 * (t < 0.5 ? t3 : 3 * (t - t2) + t3 - 0.75);
  7374. };
  7375. /*
  7376. * Call an asynchronous function on an array of arguments,
  7377. * calling `callback` with the completed results of all calls.
  7378. *
  7379. * @param array input to each call of the async function.
  7380. * @param fn an async function with signature (data, callback)
  7381. * @param callback a callback run after all async work is done.
  7382. * called with an array, containing the results of each async call.
  7383. * @private
  7384. */
  7385. Util.asyncAll = function (array, fn, callback) {
  7386. if (!array.length) {
  7387. return callback(null, []);
  7388. }
  7389. var remaining = array.length;
  7390. var results = new Array(array.length);
  7391. var error = null;
  7392. array.forEach(function (item, i) {
  7393. fn(item, function (err, result) {
  7394. if (err) {
  7395. error = err;
  7396. }
  7397. results[i] = ((result ) ); // https://github.com/facebook/flow/issues/2123
  7398. if (--remaining === 0) {
  7399. callback(error, results);
  7400. }
  7401. });
  7402. });
  7403. };
  7404. /**
  7405. * Given a destination object and optionally many source objects,
  7406. * copy all properties from the source objects into the destination.
  7407. * The last source object given overrides properties from previous
  7408. * source objects.
  7409. *
  7410. * @param dest destination object
  7411. * @param sources sources from which properties are pulled
  7412. * @private
  7413. */
  7414. Util.extend = function (dest) {
  7415. var sources = [], len = arguments.length - 1;
  7416. while (len-- > 0) sources[ len ] = arguments[ len + 1 ];
  7417. for (var i = 0, list = sources; i < list.length; i += 1) {
  7418. var src = list[i];
  7419. for (var k in src) {
  7420. dest[k] = src[k];
  7421. }
  7422. }
  7423. return dest;
  7424. };
  7425. var id = 1;
  7426. /**
  7427. * Return a unique numeric id, starting at 1 and incrementing with
  7428. * each call.
  7429. *
  7430. * @returns unique numeric id.
  7431. * @private
  7432. */
  7433. Util.uniqueId = function () {
  7434. return id++;
  7435. };
  7436. /**
  7437. * Return a random UUID (v4). Taken from: https://gist.github.com/jed/982883
  7438. * @private
  7439. */
  7440. Util.uuid = function () {
  7441. function b(a) {
  7442. return a ? (a ^ Math.random() * 16 >> a / 4).toString(16) :
  7443. //$FlowFixMe: Flow doesn't like the implied array literal conversion here
  7444. ([1e7] + -[1e3] + -4e3 + -8e3 + -1e11).replace(/[018]/g, b);
  7445. }
  7446. return b();
  7447. };
  7448. /**
  7449. * Validate a string to match UUID(v4) of the
  7450. * form: xxxxxxxx-xxxx-4xxx-[89ab]xxx-xxxxxxxxxxxx
  7451. * @param str string to validate.
  7452. * @private
  7453. */
  7454. Util.validateUuid = function (str) {
  7455. 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;
  7456. };
  7457. /**
  7458. * Given an array of member function names as strings, replace all of them
  7459. * with bound versions that will always refer to `context` as `this`. This
  7460. * is useful for classes where otherwise event bindings would reassign
  7461. * `this` to the evented object or some other value: this lets you ensure
  7462. * the `this` value always.
  7463. *
  7464. * @param fns list of member function names
  7465. * @param context the context value
  7466. * @example
  7467. * function MyClass() {
  7468. * bindAll(['ontimer'], this);
  7469. * this.name = 'Tom';
  7470. * }
  7471. * MyClass.prototype.ontimer = function() {
  7472. * alert(this.name);
  7473. * };
  7474. * var myClass = new MyClass();
  7475. * setTimeout(myClass.ontimer, 100);
  7476. * @private
  7477. */
  7478. Util.bindAll = function (fns, context) {
  7479. fns.forEach(function (fn) {
  7480. if (!context[fn]) {
  7481. return;
  7482. }
  7483. context[fn] = context[fn].bind(context);
  7484. });
  7485. };
  7486. /**
  7487. * Determine if a string ends with a particular substring
  7488. *
  7489. * @private
  7490. */
  7491. Util.endsWith = function (string, suffix) {
  7492. return string.indexOf(suffix, string.length - suffix.length) !== -1;
  7493. };
  7494. /**
  7495. * Create an object by mapping all the values of an existing object while
  7496. * preserving their keys.
  7497. *
  7498. * @private
  7499. */
  7500. Util.mapObject = function (input, iterator, context) {
  7501. var output = {};
  7502. for (var key in input) {
  7503. output[key] = iterator.call(context || this, input[key], key, input);
  7504. }
  7505. return output;
  7506. };
  7507. /**
  7508. * Create an object by filtering out values of an existing object.
  7509. *
  7510. * @private
  7511. */
  7512. Util.filterObject = function (input, iterator, context) {
  7513. var output = {};
  7514. for (var key in input) {
  7515. if (iterator.call(context || this, input[key], key, input)) {
  7516. output[key] = input[key];
  7517. }
  7518. }
  7519. return output;
  7520. };
  7521. /**
  7522. * Deeply clones two objects.
  7523. *
  7524. * @private
  7525. */
  7526. Util.clone = function (input) {
  7527. if (Array.isArray(input)) {
  7528. return input.map(Util.clone);
  7529. } else if (typeof input === 'object' && input) {
  7530. return ((Util.mapObject(input, Util.clone) ) );
  7531. } else {
  7532. return input;
  7533. }
  7534. };
  7535. Util.deepEqual = function (a, b) {
  7536. if (Array.isArray(a)) {
  7537. if (!Array.isArray(b) || a.length !== b.length) {
  7538. return false;
  7539. }
  7540. for (var i = 0; i < a.length; i++) {
  7541. if (!Util.deepEqual(a[i], b[i])) {
  7542. return false;
  7543. }
  7544. }
  7545. return true;
  7546. }
  7547. if (typeof a === 'object' && a !== null && b !== null) {
  7548. if (!(typeof b === 'object')) {
  7549. return false;
  7550. }
  7551. var keys = Object.keys(a);
  7552. if (keys.length !== Object.keys(b).length) {
  7553. return false;
  7554. }
  7555. for (var key in a) {
  7556. if (!Util.deepEqual(a[key], b[key])) {
  7557. return false;
  7558. }
  7559. }
  7560. return true;
  7561. }
  7562. return a === b;
  7563. };
  7564. /**
  7565. * Check if two arrays have at least one common element.
  7566. *
  7567. * @private
  7568. */
  7569. Util.arraysIntersect = function (a, b) {
  7570. for (var l = 0; l < a.length; l++) {
  7571. if (b.indexOf(a[l]) >= 0) {
  7572. return true;
  7573. }
  7574. }
  7575. return false;
  7576. };
  7577. /**
  7578. * Indicates if the provided Points are in a counter clockwise (true) or clockwise (false) order
  7579. *
  7580. * @private
  7581. * @returns true for a counter clockwise set of points
  7582. */
  7583. // http://bryceboe.com/2006/10/23/line-segment-intersection-algorithm/
  7584. Util.isCounterClockwise = function (a, b, c) {
  7585. return (c.y - a.y) * (b.x - a.x) > (b.y - a.y) * (c.x - a.x);
  7586. };
  7587. /* global self, WorkerGlobalScope */
  7588. /**
  7589. * Retuns true if the when run in the web-worker context.
  7590. *
  7591. * @private
  7592. * @returns {boolean}
  7593. */
  7594. Util.isWorker = function () {
  7595. return typeof WorkerGlobalScope !== 'undefined' && typeof self !== 'undefined' &&
  7596. self instanceof WorkerGlobalScope;
  7597. };
  7598. var _isSafari = null;
  7599. /**
  7600. * Returns true when run in WebKit derived browsers.
  7601. * This is used as a workaround for a memory leak in Safari caused by using Transferable objects to
  7602. * transfer data between WebWorkers and the main thread.
  7603. * https://github.com/mapbox/mapbox-gl-js/issues/8771
  7604. *
  7605. * This should be removed once the underlying Safari issue is fixed.
  7606. *
  7607. * @private
  7608. * @param scope {WindowOrWorkerGlobalScope} Since this function is used both on the main thread and WebWorker context,
  7609. * let the calling scope pass in the global scope object.
  7610. * @returns {boolean}
  7611. */
  7612. Util.isSafari = function (scope) {
  7613. if (_isSafari == null) {
  7614. var userAgent = scope.navigator ? scope.navigator.userAgent : null;
  7615. _isSafari = !!scope.safari || !!(userAgent && (/\b(iPad|iPhone|iPod)\b/.test(userAgent) || (!!userAgent.match('Safari') && !userAgent.match('Chrome'))));
  7616. }
  7617. return _isSafari;
  7618. };
  7619. /**
  7620. * Replace tokens in a string template with values in an object
  7621. *
  7622. * @param properties a key/value relationship between tokens and replacements
  7623. * @param text the template string
  7624. * @returns the template with tokens replaced
  7625. * @private
  7626. */
  7627. Util.resolveTokens = function (properties, text) {
  7628. return text.replace(/{([^{}]+)}/g, function (match, key) {
  7629. return key in properties ? String(properties[key]) : '';
  7630. });
  7631. };
  7632. /**
  7633. * Tracks `let` bindings during expression parsing.
  7634. * @private
  7635. */
  7636. var Scope = function Scope(parent, bindings) {
  7637. if (bindings === void 0) bindings = [];
  7638. this.parent = parent;
  7639. this.bindings = {};
  7640. for (var i = 0, list = bindings; i < list.length; i += 1) {
  7641. var ref = list[i];
  7642. var name = ref[0];
  7643. var expression = ref[1];
  7644. this.bindings[name] = expression;
  7645. }
  7646. };
  7647. Scope.prototype.concat = function concat(bindings) {
  7648. return new Scope(this, bindings);
  7649. };
  7650. Scope.prototype.get = function get(name) {
  7651. if (this.bindings[name]) {
  7652. return this.bindings[name];
  7653. }
  7654. if (this.parent) {
  7655. return this.parent.get(name);
  7656. }
  7657. throw new Error((name + " not found in scope."));
  7658. };
  7659. Scope.prototype.has = function has(name) {
  7660. if (this.bindings[name]) {
  7661. return true;
  7662. }
  7663. return this.parent ? this.parent.has(name) : false;
  7664. };
  7665. var ParsingError = /*@__PURE__*/(function (Error) {
  7666. function ParsingError(key , message ) {
  7667. Error.call(this, message);
  7668. this.message = message;
  7669. this.key = key;
  7670. }
  7671. if ( Error ) ParsingError.__proto__ = Error;
  7672. ParsingError.prototype = Object.create( Error && Error.prototype );
  7673. ParsingError.prototype.constructor = ParsingError;
  7674. return ParsingError;
  7675. }(Error));
  7676. var geometryTypes = ['Unknown', 'Point', 'LineString', 'Polygon'];
  7677. var EvaluationContext = function EvaluationContext() {
  7678. this.globals = (null );
  7679. this.feature = null;
  7680. this.featureState = null;
  7681. this.formattedSection = null;
  7682. this._parseColorCache = {};
  7683. this.availableImages = null;
  7684. };
  7685. EvaluationContext.prototype.id = function id () {
  7686. return this.feature && 'id' in this.feature ? this.feature.id : null;
  7687. };
  7688. EvaluationContext.prototype.geometryType = function geometryType () {
  7689. return this.feature ? typeof this.feature.type === 'number' ? geometryTypes[this.feature.type] : this.feature.type : null;
  7690. };
  7691. EvaluationContext.prototype.properties = function properties () {
  7692. return this.feature && this.feature.properties || {};
  7693. };
  7694. EvaluationContext.prototype.parseColor = function parseColor (input ) {
  7695. var cached = this._parseColorCache[input];
  7696. if (!cached) {
  7697. cached = this._parseColorCache[input] = Color.parse(input);
  7698. }
  7699. return cached;
  7700. };
  7701. function isConstant() {
  7702. }
  7703. isConstant.isFeatureConstant = function(e){
  7704. if (e instanceof CompoundExpression) {
  7705. if (e.name === 'get' && e.args.length === 1) {
  7706. return false;
  7707. } else if (e.name === 'feature-state') {
  7708. return false;
  7709. } else if (e.name === 'has' && e.args.length === 1) {
  7710. return false;
  7711. } else if (
  7712. e.name === 'properties' ||
  7713. e.name === 'geometry-type' ||
  7714. e.name === 'id'
  7715. ) {
  7716. return false;
  7717. } else if (/^filter-/.test(e.name)) {
  7718. return false;
  7719. }
  7720. }
  7721. var result = true;
  7722. e.eachChild(function (arg) {
  7723. if (result && !isConstant.isFeatureConstant(arg)) {
  7724. result = false;
  7725. }
  7726. });
  7727. return result;
  7728. };
  7729. isConstant.isStateConstant = function(e){
  7730. if (e instanceof CompoundExpression) {
  7731. if (e.name === 'feature-state') {
  7732. return false;
  7733. }
  7734. }
  7735. var result = true;
  7736. e.eachChild(function (arg) {
  7737. if (result && !isConstant.isStateConstant(arg)) {
  7738. result = false;
  7739. }
  7740. });
  7741. return result;
  7742. };
  7743. isConstant.isGlobalPropertyConstant = function(e, properties){
  7744. if (e instanceof CompoundExpression && properties.indexOf(e.name) >= 0) {
  7745. return false;
  7746. }
  7747. var result = true;
  7748. e.eachChild(function (arg) {
  7749. if (result && !isConstant.isGlobalPropertyConstant(arg, properties)) {
  7750. result = false;
  7751. }
  7752. });
  7753. return result;
  7754. };
  7755. /**
  7756. * State associated parsing at a given point in an expression tree.
  7757. * @private
  7758. */
  7759. var ParsingContext = function ParsingContext(registry, path, expectedType, scope, errors) {
  7760. if (path === void 0) path = [];
  7761. if (scope === void 0) scope = new Scope();
  7762. if (errors === void 0) errors = [];
  7763. this.registry = registry;
  7764. this.path = path;
  7765. this.key = path.map(function (part) {
  7766. return ("[" + part + "]");
  7767. }).join('');
  7768. this.scope = scope;
  7769. this.errors = errors;
  7770. this.expectedType = expectedType;
  7771. };
  7772. /**
  7773. * @param expr the JSON expression to parse
  7774. * @param index the optional argument index if this expression is an argument of a parent expression that's being parsed
  7775. * @param options
  7776. * @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.
  7777. * @private
  7778. */
  7779. ParsingContext.prototype.parse = function parse(expr, index, expectedType, bindings, options) {
  7780. if (options === void 0) options = {};
  7781. if (index) {
  7782. return this.concat(index, expectedType, bindings)._parse(expr, options);
  7783. }
  7784. return this._parse(expr, options);
  7785. };
  7786. ParsingContext.prototype._parse = function _parse(expr, options) {
  7787. if (expr === null || typeof expr === 'string' || typeof expr === 'boolean' || typeof expr === 'number') {
  7788. expr = ['literal', expr];
  7789. }
  7790. function annotate(parsed, type, typeAnnotation) {
  7791. if (typeAnnotation === 'assert') {
  7792. return new Assertion(type, [parsed]);
  7793. } else if (typeAnnotation === 'coerce') {
  7794. return new Coercion(type, [parsed]);
  7795. } else {
  7796. return parsed;
  7797. }
  7798. }
  7799. if (Array.isArray(expr)) {
  7800. if (expr.length === 0) {
  7801. return this.error("Expected an array with at least one element. If you wanted a literal array, use [\"literal\", []].");
  7802. }
  7803. var op = expr[0];
  7804. if (typeof op !== 'string') {
  7805. this.error(("Expression name must be a string, but found " + (typeof op) + " instead. If you wanted a literal array, use [\"literal\", [...]]."), 0);
  7806. return null;
  7807. }
  7808. var Expr = this.registry[op];
  7809. if (Expr) {
  7810. var parsed = Expr.parse(expr, this);
  7811. if (!parsed) {
  7812. return null;
  7813. }
  7814. if (this.expectedType) {
  7815. var expected = this.expectedType;
  7816. var actual = parsed.type;
  7817. // When we expect a number, string, boolean, or array but have a value, wrap it in an assertion.
  7818. // When we expect a color or formatted string, but have a string or value, wrap it in a coercion.
  7819. // Otherwise, we do static type-checking.
  7820. //
  7821. // These behaviors are overridable for:
  7822. // * The "coalesce" operator, which needs to omit type annotations.
  7823. // * String-valued properties (e.g. `text-field`), where coercion is more convenient than assertion.
  7824. //
  7825. if ((expected.kind === 'string' || expected.kind === 'number' || expected.kind === 'boolean' || expected.kind === 'object' || expected.kind === 'array') && actual.kind === 'value') {
  7826. parsed = annotate(parsed, expected, options.typeAnnotation || 'assert');
  7827. } else if ((expected.kind === 'color' || expected.kind === 'formatted' || expected.kind === 'resolvedImage') && (actual.kind === 'value' || actual.kind === 'string')) {
  7828. parsed = annotate(parsed, expected, options.typeAnnotation || 'coerce');
  7829. } else if (this.checkSubtype(expected, actual)) {
  7830. return null;
  7831. }
  7832. }
  7833. // If an expression's arguments are all literals, we can evaluate
  7834. // it immediately and replace it with a literal value in the
  7835. // parsed/compiled result. Expressions that expect an image should
  7836. // not be resolved here so we can later get the available images.
  7837. if (!(parsed instanceof Literal) && (parsed.type.kind !== 'resolvedImage') && isConstant()) {
  7838. var ec = new EvaluationContext();
  7839. try {
  7840. parsed = new Literal(parsed.type, parsed.evaluate(ec));
  7841. } catch (e) {
  7842. this.error(e.message);
  7843. return null;
  7844. }
  7845. }
  7846. return parsed;
  7847. }
  7848. return this.error(("Unknown expression \"" + op + "\". If you wanted a literal array, use [\"literal\", [...]]."), 0);
  7849. } else if (typeof expr === 'undefined') {
  7850. return this.error("'undefined' value invalid. Use null instead.");
  7851. } else if (typeof expr === 'object') {
  7852. return this.error("Bare objects invalid. Use [\"literal\", {...}] instead.");
  7853. } else {
  7854. return this.error(("Expected an array, but found " + (typeof expr) + " instead."));
  7855. }
  7856. };
  7857. /**
  7858. * Returns a copy of this context suitable for parsing the subexpression at
  7859. * index `index`, optionally appending to 'let' binding map.
  7860. *
  7861. * Note that `errors` property, intended for collecting errors while
  7862. * parsing, is copied by reference rather than cloned.
  7863. * @private
  7864. */
  7865. ParsingContext.prototype.concat = function concat(index, expectedType, bindings) {
  7866. var path = typeof index === 'number' ? this.path.concat(index) : this.path;
  7867. var scope = bindings ? this.scope.concat(bindings) : this.scope;
  7868. return new ParsingContext(
  7869. this.registry,
  7870. path,
  7871. expectedType || null,
  7872. scope,
  7873. this.errors
  7874. );
  7875. };
  7876. /**
  7877. * Push a parsing (or type checking) error into the `this.errors`
  7878. * @param error The message
  7879. * @param keys Optionally specify the source of the error at a child
  7880. * of the current expression at `this.key`.
  7881. * @private
  7882. */
  7883. ParsingContext.prototype.error = function error(error$1) {
  7884. var keys = [], len = arguments.length - 1;
  7885. while (len-- > 0) keys[ len ] = arguments[ len + 1 ];
  7886. var key = "" + (this.key) + (keys.map(function (k) {
  7887. return ("[" + k + "]");
  7888. }).join(''));
  7889. this.errors.push(new ParsingError(key, error$1));
  7890. };
  7891. /**
  7892. * Returns null if `t` is a subtype of `expected`; otherwise returns an
  7893. * error message and also pushes it to `this.errors`.
  7894. */
  7895. ParsingContext.prototype.checkSubtype = function checkSubtype$1(expected, t) {
  7896. var error = checkSubtype(expected, t);
  7897. if (error) {
  7898. this.error(error);
  7899. }
  7900. return error;
  7901. };
  7902. function get(key, obj) {
  7903. const v = obj[key];
  7904. return typeof v === 'undefined' ? null : v;
  7905. }
  7906. var CompoundExpression$1 = function CompoundExpression(name, type, evaluate, args) {
  7907. this.name = name;
  7908. this.type = type;
  7909. this._evaluate = evaluate;
  7910. this.args = args;
  7911. };
  7912. CompoundExpression$1.prototype.evaluate = function evaluate(ctx, crossFields) {
  7913. return this._evaluate(ctx, this.args, crossFields);
  7914. };
  7915. CompoundExpression$1.prototype.eachChild = function eachChild(fn) {
  7916. this.args.forEach(fn);
  7917. };
  7918. CompoundExpression$1.prototype.possibleOutputs = function possibleOutputs() {
  7919. return [undefined];
  7920. };
  7921. CompoundExpression$1.prototype.serialize = function serialize() {
  7922. return [this.name].concat(this.args.map(function (arg) {
  7923. return arg.serialize();
  7924. }));
  7925. };
  7926. CompoundExpression$1.parse = function parse(args, context) {
  7927. var ref$1;
  7928. var op = (args[0] );
  7929. var definition = CompoundExpression$1.definitions[op];
  7930. if (!definition) {
  7931. return context.error(("Unknown expression \"" + op + "\". If you wanted a literal array, use [\"literal\", [...]]."), 0);
  7932. }
  7933. // Now check argument types against each signature
  7934. var type = Array.isArray(definition) ?
  7935. definition[0] : definition.type;
  7936. var availableOverloads = Array.isArray(definition) ?
  7937. [
  7938. [definition[1], definition[2]]
  7939. ] :
  7940. definition.overloads;
  7941. var overloads = availableOverloads.filter(function (ref) {
  7942. var signature = ref[0];
  7943. return (
  7944. !Array.isArray(signature) || // varags
  7945. signature.length === args.length - 1 // correct param count
  7946. );
  7947. });
  7948. var signatureContext = (null );
  7949. for (var i$3 = 0, list = overloads; i$3 < list.length; i$3 += 1) {
  7950. // Use a fresh context for each attempted signature so that, if
  7951. // we eventually succeed, we haven't polluted `context.errors`.
  7952. var ref = list[i$3];
  7953. var params = ref[0];
  7954. var evaluate = ref[1];
  7955. signatureContext = new ParsingContext(context.registry, context.path, null, context.scope);
  7956. // First parse all the args, potentially coercing to the
  7957. // types expected by this overload.
  7958. var parsedArgs = [];
  7959. var argParseFailed = false;
  7960. for (var i = 1; i < args.length; i++) {
  7961. var arg = args[i];
  7962. var expectedType = Array.isArray(params) ?
  7963. params[i - 1] :
  7964. params.type;
  7965. var parsed = signatureContext.parse(arg, 1 + parsedArgs.length, expectedType);
  7966. if (!parsed) {
  7967. argParseFailed = true;
  7968. break;
  7969. }
  7970. parsedArgs.push(parsed);
  7971. }
  7972. if (argParseFailed) {
  7973. // Couldn't coerce args of this overload to expected type, move
  7974. // on to next one.
  7975. continue;
  7976. }
  7977. if (Array.isArray(params)) {
  7978. if (params.length !== parsedArgs.length) {
  7979. signatureContext.error(("Expected " + (params.length) + " arguments, but found " + (parsedArgs.length) + " instead."));
  7980. continue;
  7981. }
  7982. }
  7983. for (var i$1 = 0; i$1 < parsedArgs.length; i$1++) {
  7984. var expected = Array.isArray(params) ? params[i$1] : params.type;
  7985. var arg$1 = parsedArgs[i$1];
  7986. signatureContext.concat(i$1 + 1).checkSubtype(expected, arg$1.type);
  7987. }
  7988. if (signatureContext.errors.length === 0) {
  7989. return new CompoundExpression$1(op, type, evaluate, parsedArgs);
  7990. }
  7991. }
  7992. //assert_1(!signatureContext || signatureContext.errors.length > 0);
  7993. if (overloads.length === 1) {
  7994. (ref$1 = context.errors).push.apply(ref$1, signatureContext.errors);
  7995. } else {
  7996. var expected$1 = overloads.length ? overloads : availableOverloads;
  7997. var signatures = expected$1
  7998. .map(function (ref) {
  7999. var params = ref[0];
  8000. return stringifySignature(params);
  8001. })
  8002. .join(' | ');
  8003. var actualTypes = [];
  8004. // For error message, re-parse arguments without trying to
  8005. // apply any coercions
  8006. for (var i$2 = 1; i$2 < args.length; i$2++) {
  8007. var parsed$1 = context.parse(args[i$2], 1 + actualTypes.length);
  8008. if (!parsed$1) {
  8009. return null;
  8010. }
  8011. actualTypes.push(toString(parsed$1.type));
  8012. }
  8013. context.error(("Expected arguments of type " + signatures + ", but found (" + (actualTypes.join(', ')) + ") instead."));
  8014. }
  8015. return null;
  8016. };
  8017. CompoundExpression$1.register = function register(registry, definitions) {
  8018. //assert_1(!CompoundExpression.definitions);
  8019. CompoundExpression$1.definitions = definitions;
  8020. for (var name in definitions) {
  8021. registry[name] = CompoundExpression$1;
  8022. }
  8023. };
  8024. function stringifySignature(signature) {
  8025. if (Array.isArray(signature)) {
  8026. return ("(" + (signature.map(toString).join(', ')) + ")");
  8027. } else {
  8028. return ("(" + (toString(signature.type)) + "...)");
  8029. }
  8030. }
  8031. var NumberType$a = {kind: 'number'};
  8032. var StringType$8 = {kind: 'string'};
  8033. var BooleanType$8 = {kind: 'boolean'};
  8034. var ColorType$5 = {kind: 'color'};
  8035. var ObjectType$3 = {kind: 'object'};
  8036. var ValueType$a = {kind: 'value'};
  8037. var ErrorType = {kind: 'error'};
  8038. var CollatorType$3 = {kind: 'collator'};
  8039. function array$5(itemType, N) {
  8040. return {
  8041. kind: 'array',
  8042. itemType: itemType,
  8043. N: N
  8044. };
  8045. }
  8046. function varargs(type) {
  8047. return {type: type};
  8048. }
  8049. function rgba(ctx, ref) {
  8050. var r = ref[0];
  8051. var g = ref[1];
  8052. var b = ref[2];
  8053. var a = ref[3];
  8054. r = r.evaluate(ctx);
  8055. g = g.evaluate(ctx);
  8056. b = b.evaluate(ctx);
  8057. var alpha = a ? a.evaluate(ctx) : 1;
  8058. var error = Values.validateRGBA(r, g, b, alpha);
  8059. if (error) {
  8060. throw new RuntimeError(error);
  8061. }
  8062. return new Color(r / 255 * alpha, g / 255 * alpha, b / 255 * alpha, alpha);
  8063. }
  8064. CompoundExpression$1.register(expressions, {
  8065. 'error': [
  8066. ErrorType,
  8067. [StringType$8],
  8068. function (ctx, ref) {
  8069. var v = ref[0];
  8070. throw new RuntimeError(v.evaluate(ctx));
  8071. }
  8072. ],
  8073. 'typeof': [
  8074. StringType$8,
  8075. [ValueType$a],
  8076. function (ctx, ref) {
  8077. var v = ref[0];
  8078. return toString(Values.typeOf(v.evaluate(ctx)));
  8079. }
  8080. ],
  8081. 'to-rgba': [
  8082. array$5(NumberType$a, 4),
  8083. [ColorType$5],
  8084. function (ctx, ref) {
  8085. var v = ref[0];
  8086. return v.evaluate(ctx).toArray();
  8087. }
  8088. ],
  8089. 'rgb': [
  8090. ColorType$5,
  8091. [NumberType$a, NumberType$a, NumberType$a],
  8092. rgba
  8093. ],
  8094. 'rgba': [
  8095. ColorType$5,
  8096. [NumberType$a, NumberType$a, NumberType$a, NumberType$a],
  8097. rgba
  8098. ],
  8099. 'has': {
  8100. type: BooleanType$8,
  8101. overloads: [
  8102. [
  8103. [StringType$8],
  8104. function (ctx, ref) {
  8105. var key = ref[0];
  8106. return has(key.evaluate(ctx), ctx.properties());
  8107. }
  8108. ],
  8109. [
  8110. [StringType$8, ObjectType$3],
  8111. function (ctx, ref) {
  8112. var key = ref[0];
  8113. var obj = ref[1];
  8114. return has(key.evaluate(ctx), obj.evaluate(ctx));
  8115. }
  8116. ]
  8117. ]
  8118. },
  8119. 'get': {
  8120. type: ValueType$a,
  8121. overloads: [
  8122. [
  8123. [StringType$8],
  8124. function (ctx, ref) {
  8125. var key = ref[0];
  8126. return get(key.evaluate(ctx), ctx.properties());
  8127. }
  8128. ],
  8129. [
  8130. [StringType$8, ObjectType$3],
  8131. function (ctx, ref) {
  8132. var key = ref[0];
  8133. var obj = ref[1];
  8134. return get(key.evaluate(ctx), obj.evaluate(ctx));
  8135. }
  8136. ]
  8137. ]
  8138. },
  8139. 'feature-state': [
  8140. ValueType$a,
  8141. [StringType$8],
  8142. function (ctx, ref) {
  8143. var key = ref[0];
  8144. return get(key.evaluate(ctx), ctx.featureState || {});
  8145. }
  8146. ],
  8147. 'properties': [
  8148. ObjectType$3,
  8149. [],
  8150. function (ctx) {
  8151. return ctx.properties();
  8152. }
  8153. ],
  8154. 'geometry-type': [
  8155. StringType$8,
  8156. [],
  8157. function (ctx) {
  8158. return ctx.geometryType();
  8159. }
  8160. ],
  8161. 'id': [
  8162. ValueType$a,
  8163. [],
  8164. function (ctx) {
  8165. return ctx.id();
  8166. }
  8167. ],
  8168. 'zoom': [
  8169. NumberType$a,
  8170. [],
  8171. function (ctx) {
  8172. return ctx.globals.zoom;
  8173. }
  8174. ],
  8175. 'heatmap-density': [
  8176. NumberType$a,
  8177. [],
  8178. function (ctx) {
  8179. return ctx.globals.heatmapDensity || 0;
  8180. }
  8181. ],
  8182. 'line-progress': [
  8183. NumberType$a,
  8184. [],
  8185. function (ctx) {
  8186. return ctx.globals.lineProgress || 0;
  8187. }
  8188. ],
  8189. 'accumulated': [
  8190. ValueType$a,
  8191. [],
  8192. function (ctx) {
  8193. return ctx.globals.accumulated === undefined ? null : ctx.globals.accumulated;
  8194. }
  8195. ],
  8196. '+': [
  8197. NumberType$a,
  8198. varargs(NumberType$a),
  8199. function (ctx, args) {
  8200. var result = 0;
  8201. for (var i = 0, list = args; i < list.length; i += 1) {
  8202. var arg = list[i];
  8203. result += arg.evaluate(ctx);
  8204. }
  8205. return result;
  8206. }
  8207. ],
  8208. '*': [
  8209. NumberType$a,
  8210. varargs(NumberType$a),
  8211. function (ctx, args) {
  8212. var result = 1;
  8213. for (var i = 0, list = args; i < list.length; i += 1) {
  8214. var arg = list[i];
  8215. result *= arg.evaluate(ctx);
  8216. }
  8217. return result;
  8218. }
  8219. ],
  8220. '-': {
  8221. type: NumberType$a,
  8222. overloads: [
  8223. [
  8224. [NumberType$a, NumberType$a],
  8225. function (ctx, ref) {
  8226. var a = ref[0];
  8227. var b = ref[1];
  8228. return a.evaluate(ctx) - b.evaluate(ctx);
  8229. }
  8230. ],
  8231. [
  8232. [NumberType$a],
  8233. function (ctx, ref) {
  8234. var a = ref[0];
  8235. return -a.evaluate(ctx);
  8236. }
  8237. ]
  8238. ]
  8239. },
  8240. '/': [
  8241. NumberType$a,
  8242. [NumberType$a, NumberType$a],
  8243. function (ctx, ref) {
  8244. var a = ref[0];
  8245. var b = ref[1];
  8246. return a.evaluate(ctx) / b.evaluate(ctx);
  8247. }
  8248. ],
  8249. '%': [
  8250. NumberType$a,
  8251. [NumberType$a, NumberType$a],
  8252. function (ctx, ref) {
  8253. var a = ref[0];
  8254. var b = ref[1];
  8255. return a.evaluate(ctx) % b.evaluate(ctx);
  8256. }
  8257. ],
  8258. 'ln2': [
  8259. NumberType$a,
  8260. [],
  8261. function () {
  8262. return Math.LN2;
  8263. }
  8264. ],
  8265. 'pi': [
  8266. NumberType$a,
  8267. [],
  8268. function () {
  8269. return Math.PI;
  8270. }
  8271. ],
  8272. 'e': [
  8273. NumberType$a,
  8274. [],
  8275. function () {
  8276. return Math.E;
  8277. }
  8278. ],
  8279. '^': [
  8280. NumberType$a,
  8281. [NumberType$a, NumberType$a],
  8282. function (ctx, ref) {
  8283. var b = ref[0];
  8284. var e = ref[1];
  8285. return Math.pow(b.evaluate(ctx), e.evaluate(ctx));
  8286. }
  8287. ],
  8288. 'sqrt': [
  8289. NumberType$a,
  8290. [NumberType$a],
  8291. function (ctx, ref) {
  8292. var x = ref[0];
  8293. return Math.sqrt(x.evaluate(ctx));
  8294. }
  8295. ],
  8296. 'log10': [
  8297. NumberType$a,
  8298. [NumberType$a],
  8299. function (ctx, ref) {
  8300. var n = ref[0];
  8301. return Math.log(n.evaluate(ctx)) / Math.LN10;
  8302. }
  8303. ],
  8304. 'ln': [
  8305. NumberType$a,
  8306. [NumberType$a],
  8307. function (ctx, ref) {
  8308. var n = ref[0];
  8309. return Math.log(n.evaluate(ctx));
  8310. }
  8311. ],
  8312. 'log2': [
  8313. NumberType$a,
  8314. [NumberType$a],
  8315. function (ctx, ref) {
  8316. var n = ref[0];
  8317. return Math.log(n.evaluate(ctx)) / Math.LN2;
  8318. }
  8319. ],
  8320. 'sin': [
  8321. NumberType$a,
  8322. [NumberType$a],
  8323. function (ctx, ref) {
  8324. var n = ref[0];
  8325. return Math.sin(n.evaluate(ctx));
  8326. }
  8327. ],
  8328. 'cos': [
  8329. NumberType$a,
  8330. [NumberType$a],
  8331. function (ctx, ref) {
  8332. var n = ref[0];
  8333. return Math.cos(n.evaluate(ctx));
  8334. }
  8335. ],
  8336. 'tan': [
  8337. NumberType$a,
  8338. [NumberType$a],
  8339. function (ctx, ref) {
  8340. var n = ref[0];
  8341. return Math.tan(n.evaluate(ctx));
  8342. }
  8343. ],
  8344. 'asin': [
  8345. NumberType$a,
  8346. [NumberType$a],
  8347. function (ctx, ref) {
  8348. var n = ref[0];
  8349. return Math.asin(n.evaluate(ctx));
  8350. }
  8351. ],
  8352. 'acos': [
  8353. NumberType$a,
  8354. [NumberType$a],
  8355. function (ctx, ref) {
  8356. var n = ref[0];
  8357. return Math.acos(n.evaluate(ctx));
  8358. }
  8359. ],
  8360. 'atan': [
  8361. NumberType$a,
  8362. [NumberType$a],
  8363. function (ctx, ref) {
  8364. var n = ref[0];
  8365. return Math.atan(n.evaluate(ctx));
  8366. }
  8367. ],
  8368. 'min': [
  8369. NumberType$a,
  8370. varargs(NumberType$a),
  8371. function (ctx, args) {
  8372. return Math.min.apply(Math, args.map(function (arg) {
  8373. return arg.evaluate(ctx);
  8374. }));
  8375. }
  8376. ],
  8377. 'max': [
  8378. NumberType$a,
  8379. varargs(NumberType$a),
  8380. function (ctx, args) {
  8381. return Math.max.apply(Math, args.map(function (arg) {
  8382. return arg.evaluate(ctx);
  8383. }));
  8384. }
  8385. ],
  8386. 'abs': [
  8387. NumberType$a,
  8388. [NumberType$a],
  8389. function (ctx, ref) {
  8390. var n = ref[0];
  8391. return Math.abs(n.evaluate(ctx));
  8392. }
  8393. ],
  8394. 'round': [
  8395. NumberType$a,
  8396. [NumberType$a],
  8397. function (ctx, ref) {
  8398. var n = ref[0];
  8399. var v = n.evaluate(ctx);
  8400. // Javascript's Math.round() rounds towards +Infinity for halfway
  8401. // values, even when they're negative. It's more common to round
  8402. // away from 0 (e.g., this is what python and C++ do)
  8403. return v < 0 ? -Math.round(-v) : Math.round(v);
  8404. }
  8405. ],
  8406. 'floor': [
  8407. NumberType$a,
  8408. [NumberType$a],
  8409. function (ctx, ref) {
  8410. var n = ref[0];
  8411. return Math.floor(n.evaluate(ctx));
  8412. }
  8413. ],
  8414. 'ceil': [
  8415. NumberType$a,
  8416. [NumberType$a],
  8417. function (ctx, ref) {
  8418. var n = ref[0];
  8419. return Math.ceil(n.evaluate(ctx));
  8420. }
  8421. ],
  8422. 'filter-==': [
  8423. BooleanType$8,
  8424. [StringType$8, ValueType$a],
  8425. function (ctx, ref, crossFields) {
  8426. var k = ref[0];
  8427. var v = ref[1];
  8428. if(!crossFields) {
  8429. return ctx.properties()[(k ).value] === (v ).value;
  8430. } else {
  8431. var a, b;
  8432. var kValue = (k ).value;
  8433. var vValue = (v ).value;
  8434. if(/(\S*)\s*([+-])\s*(\S*)/.test(kValue)) {
  8435. var group = kValue.match(/(\S*)\s*([+-])\s*(\S*)/);
  8436. var value1 = ctx.properties()[group[1]];
  8437. var op = group[2];
  8438. var value2 = ctx.properties()[group[3]];
  8439. switch (op) {
  8440. case "+":
  8441. a = value1 + value2;
  8442. break;
  8443. case "-":
  8444. a = value1 - value2;
  8445. break;
  8446. }
  8447. b = (v ).value;
  8448. return a === b;
  8449. } else if(/^(left|right)\s*\((.+)\s*,\s*(\d+)\)/.test(kValue)) {
  8450. var group1 = kValue.match(/^(left|right)\s*\((.+)\s*,\s*(\d+)\)/);
  8451. var substractOp1 = group1[1];
  8452. var value1 = ctx.properties()[group1[2]];
  8453. var substractNum1 = group1[3];
  8454. if(substractOp1 == "left") {
  8455. a = value1.substring(0, substractNum1);
  8456. } else {
  8457. a = value1.substring(value1.length - substractNum1);
  8458. }
  8459. if(/^(left|right)\s*\((.+)\s*,\s*(\d+)\)/.test(vValue)) {
  8460. var group2 = vValue.match(/^(left|right)\s*\((.+)\s*,\s*(\d+)\)/);
  8461. var substractOp2 = group2[1];
  8462. var value2 = ctx.properties()[group2[2]];
  8463. var substractNum2 = group2[3];
  8464. if(substractOp2 == "left") {
  8465. b = value2.substring(0, substractNum2);
  8466. } else {
  8467. b = value2.substring(value2.length - substractNum2);
  8468. }
  8469. } else {
  8470. b = (v ).value;
  8471. }
  8472. return a === b;
  8473. }else {
  8474. return ctx.properties()[(k ).value] === ctx.properties()[(v ).value];
  8475. }
  8476. }
  8477. }
  8478. ],
  8479. 'filter-id-==': [
  8480. BooleanType$8,
  8481. [ValueType$a],
  8482. function (ctx, ref) {
  8483. var v = ref[0];
  8484. return ctx.id() === (v ).value;
  8485. }
  8486. ],
  8487. 'filter-like': [
  8488. BooleanType$8,
  8489. [StringType$8, StringType$8],
  8490. function (ctx, ref) {
  8491. var a = ref[0].value;
  8492. var b = ref[1].value;
  8493. var properties = ctx.properties();
  8494. if(!(a in properties)) {
  8495. return false;
  8496. }
  8497. if(/^%.*[^%]$/.test(b)) { // 以百分号开头并且不以百分号结尾
  8498. b = b.replace("%", "");
  8499. return properties[a].endsWith(b);
  8500. } else if(/^(?!%).+%$/.test(b)) { // 以百分号结尾并且不以百分号开头
  8501. b = b.replace("%", "");
  8502. return properties[a].startsWith(b);
  8503. } else { // 百分号开头百分号结尾 or 不含百分号
  8504. b = b.replace(/%/g, "");
  8505. return (properties[a].indexOf(b)) > -1;
  8506. }
  8507. }
  8508. ],
  8509. 'filter-type-==': [
  8510. BooleanType$8,
  8511. [StringType$8],
  8512. function (ctx, ref) {
  8513. var v = ref[0];
  8514. return ctx.geometryType() === (v ).value;
  8515. }
  8516. ],
  8517. 'filter-<': [
  8518. BooleanType$8,
  8519. [StringType$8, ValueType$a],
  8520. function (ctx, ref, crossFields) {
  8521. var k = ref[0];
  8522. var v = ref[1];
  8523. var a, b;
  8524. var kValue = (k ).value;
  8525. var vValue = (v ).value;
  8526. if(/(\S*)\s*([+-])\s*(\S*)/.test(kValue)) {
  8527. var group = kValue.match(/(\S*)\s*([+-])\s*(\S*)/);
  8528. var value1 = ctx.properties()[group[1]];
  8529. var op = group[2];
  8530. var value2 = ctx.properties()[group[3]];
  8531. switch (op) {
  8532. case "+":
  8533. a = value1 + value2;
  8534. break;
  8535. case "-":
  8536. a = value1 - value2;
  8537. break;
  8538. }
  8539. b = (v ).value;
  8540. } else if(/^(left|right)\s*\((.+)\s*,\s*(\d+)\)/.test(kValue)) {
  8541. var group1 = kValue.match(/^(left|right)\s*\((.+)\s*,\s*(\d+)\)/);
  8542. var substractOp1 = group1[1];
  8543. var value1 = ctx.properties()[group1[2]];
  8544. var substractNum1 = group1[3];
  8545. if(substractOp1 == "left") {
  8546. a = value1.substring(0, substractNum1);
  8547. } else {
  8548. a = value1.substring(value1.length - substractNum1);
  8549. }
  8550. if(/^(left|right)\s*\((.+)\s*,\s*(\d+)\)/.test(vValue)) {
  8551. var group2 = vValue.match(/^(left|right)\s*\((.+)\s*,\s*(\d+)\)/);
  8552. var substractOp2 = group2[1];
  8553. var value2 = ctx.properties()[group2[2]];
  8554. var substractNum2 = group2[3];
  8555. if(substractOp2 == "left") {
  8556. b = value2.substring(0, substractNum2);
  8557. } else {
  8558. b = value2.substring(value2.length - substractNum2);
  8559. }
  8560. } else {
  8561. b = (v ).value;
  8562. }
  8563. }else {
  8564. a = ctx.properties()[(k ).value];
  8565. b = (v ).value;
  8566. if(crossFields) {
  8567. b = ctx.properties()[b];
  8568. }
  8569. }
  8570. if(typeof b === 'number' && !isNaN(Number(a))) {
  8571. a = Number(a);
  8572. }
  8573. return typeof a === typeof b && a < b;
  8574. }
  8575. ],
  8576. 'filter-id-<': [
  8577. BooleanType$8,
  8578. [ValueType$a],
  8579. function (ctx, ref) {
  8580. var v = ref[0];
  8581. var a = ctx.id();
  8582. var b = (v ).value;
  8583. return typeof a === typeof b && a < b;
  8584. }
  8585. ],
  8586. 'filter->': [
  8587. BooleanType$8,
  8588. [StringType$8, ValueType$a],
  8589. function (ctx, ref, crossFields) {
  8590. var k = ref[0];
  8591. var v = ref[1];
  8592. var a, b;
  8593. var kValue = (k ).value;
  8594. var vValue = (v ).value;
  8595. if(/(\S*)\s*([+-])\s*(\S*)/.test(kValue)) {
  8596. var group = kValue.match(/(\S*)\s*([+-])\s*(\S*)/);
  8597. var value1 = ctx.properties()[group[1]];
  8598. var op = group[2];
  8599. var value2 = ctx.properties()[group[3]];
  8600. switch (op) {
  8601. case "+":
  8602. a = value1 + value2;
  8603. break;
  8604. case "-":
  8605. a = value1 - value2;
  8606. break;
  8607. }
  8608. b = (v ).value;
  8609. } else if(/^(left|right)\s*\((.+)\s*,\s*(\d+)\)/.test(kValue)) {
  8610. var group1 = kValue.match(/^(left|right)\s*\((.+)\s*,\s*(\d+)\)/);
  8611. var substractOp1 = group1[1];
  8612. var value1 = ctx.properties()[group1[2]];
  8613. var substractNum1 = group1[3];
  8614. if(substractOp1 == "left") {
  8615. a = value1.substring(0, substractNum1);
  8616. } else {
  8617. a = value1.substring(value1.length - substractNum1);
  8618. }
  8619. if(/^(left|right)\s*\((.+)\s*,\s*(\d+)\)/.test(vValue)) {
  8620. var group2 = vValue.match(/^(left|right)\s*\((.+)\s*,\s*(\d+)\)/);
  8621. var substractOp2 = group2[1];
  8622. var value2 = ctx.properties()[group2[2]];
  8623. var substractNum2 = group2[3];
  8624. if(substractOp2 == "left") {
  8625. b = value2.substring(0, substractNum2);
  8626. } else {
  8627. b = value2.substring(value2.length - substractNum2);
  8628. }
  8629. } else {
  8630. b = (v ).value;
  8631. }
  8632. }else {
  8633. a = ctx.properties()[(k ).value];
  8634. b = (v ).value;
  8635. if(crossFields) {
  8636. b = ctx.properties()[b];
  8637. }
  8638. }
  8639. if(typeof b === 'number' && !isNaN(Number(a))) {
  8640. a = Number(a);
  8641. }
  8642. return typeof a === typeof b && a > b;
  8643. }
  8644. ],
  8645. 'filter-id->': [
  8646. BooleanType$8,
  8647. [ValueType$a],
  8648. function (ctx, ref) {
  8649. var v = ref[0];
  8650. var a = ctx.id();
  8651. var b = (v ).value;
  8652. return typeof a === typeof b && a > b;
  8653. }
  8654. ],
  8655. 'filter-<=': [
  8656. BooleanType$8,
  8657. [StringType$8, ValueType$a],
  8658. function (ctx, ref, crossFields) {
  8659. var k = ref[0];
  8660. var v = ref[1];
  8661. var a, b;
  8662. var kValue = (k ).value;
  8663. var vValue = (v ).value;
  8664. if(/(\S*)\s*([+-])\s*(\S*)/.test(kValue)) {
  8665. var group = kValue.match(/(\S*)\s*([+-])\s*(\S*)/);
  8666. var value1 = ctx.properties()[group[1]];
  8667. var op = group[2];
  8668. var value2 = ctx.properties()[group[3]];
  8669. switch (op) {
  8670. case "+":
  8671. a = value1 + value2;
  8672. break;
  8673. case "-":
  8674. a = value1 - value2;
  8675. break;
  8676. }
  8677. b = (v ).value;
  8678. } else if(/^(left|right)\s*\((.+)\s*,\s*(\d+)\)/.test(kValue)) {
  8679. var group1 = kValue.match(/^(left|right)\s*\((.+)\s*,\s*(\d+)\)/);
  8680. var substractOp1 = group1[1];
  8681. var value1 = ctx.properties()[group1[2]];
  8682. var substractNum1 = group1[3];
  8683. if(substractOp1 == "left") {
  8684. a = value1.substring(0, substractNum1);
  8685. } else {
  8686. a = value1.substring(value1.length - substractNum1);
  8687. }
  8688. if(/^(left|right)\s*\((.+)\s*,\s*(\d+)\)/.test(vValue)) {
  8689. var group2 = vValue.match(/^(left|right)\s*\((.+)\s*,\s*(\d+)\)/);
  8690. var substractOp2 = group2[1];
  8691. var value2 = ctx.properties()[group2[2]];
  8692. var substractNum2 = group2[3];
  8693. if(substractOp2 == "left") {
  8694. b = value2.substring(0, substractNum2);
  8695. } else {
  8696. b = value2.substring(value2.length - substractNum2);
  8697. }
  8698. } else {
  8699. b = (v ).value;
  8700. }
  8701. }else {
  8702. a = ctx.properties()[(k ).value];
  8703. b = (v ).value;
  8704. if(crossFields) {
  8705. b = ctx.properties()[b];
  8706. }
  8707. }
  8708. if(typeof b === 'number' && !isNaN(Number(a))) {
  8709. a = Number(a);
  8710. }
  8711. return typeof a === typeof b && a <= b;
  8712. }
  8713. ],
  8714. 'filter-id-<=': [
  8715. BooleanType$8,
  8716. [ValueType$a],
  8717. function (ctx, ref) {
  8718. var v = ref[0];
  8719. var a = ctx.id();
  8720. var b = (v ).value;
  8721. return typeof a === typeof b && a <= b;
  8722. }
  8723. ],
  8724. 'filter->=': [
  8725. BooleanType$8,
  8726. [StringType$8, ValueType$a],
  8727. function (ctx, ref, crossFields) {
  8728. var k = ref[0];
  8729. var v = ref[1];
  8730. var a, b;
  8731. var kValue = (k ).value;
  8732. var vValue = (v ).value;
  8733. if(/(\S*)\s*([+-])\s*(\S*)/.test(kValue)) {
  8734. var group = kValue.match(/(\S*)\s*([+-])\s*(\S*)/);
  8735. var value1 = ctx.properties()[group[1]];
  8736. var op = group[2];
  8737. var value2 = ctx.properties()[group[3]];
  8738. switch (op) {
  8739. case "+":
  8740. a = value1 + value2;
  8741. break;
  8742. case "-":
  8743. a = value1 - value2;
  8744. break;
  8745. }
  8746. b = (v ).value;
  8747. } else if(/^(left|right)\s*\((.+)\s*,\s*(\d+)\)/.test(kValue)) {
  8748. var group1 = kValue.match(/^(left|right)\s*\((.+)\s*,\s*(\d+)\)/);
  8749. var substractOp1 = group1[1];
  8750. var value1 = ctx.properties()[group1[2]];
  8751. var substractNum1 = group1[3];
  8752. if(substractOp1 == "left") {
  8753. a = value1.substring(0, substractNum1);
  8754. } else {
  8755. a = value1.substring(value1.length - substractNum1);
  8756. }
  8757. if(/^(left|right)\s*\((.+)\s*,\s*(\d+)\)/.test(vValue)) {
  8758. var group2 = vValue.match(/^(left|right)\s*\((.+)\s*,\s*(\d+)\)/);
  8759. var substractOp2 = group2[1];
  8760. var value2 = ctx.properties()[group2[2]];
  8761. var substractNum2 = group2[3];
  8762. if(substractOp2 == "left") {
  8763. b = value2.substring(0, substractNum2);
  8764. } else {
  8765. b = value2.substring(value2.length - substractNum2);
  8766. }
  8767. } else {
  8768. b = (v ).value;
  8769. }
  8770. }else {
  8771. a = ctx.properties()[(k ).value];
  8772. b = (v ).value;
  8773. if(crossFields) {
  8774. b = ctx.properties()[b];
  8775. }
  8776. }
  8777. if(typeof b === 'number' && !isNaN(Number(a))) {
  8778. a = Number(a);
  8779. }
  8780. return typeof a === typeof b && a >= b;
  8781. }
  8782. ],
  8783. 'filter-id->=': [
  8784. BooleanType$8,
  8785. [ValueType$a],
  8786. function (ctx, ref) {
  8787. var v = ref[0];
  8788. var a = ctx.id();
  8789. var b = (v ).value;
  8790. return typeof a === typeof b && a >= b;
  8791. }
  8792. ],
  8793. 'filter-has': [
  8794. BooleanType$8,
  8795. [ValueType$a],
  8796. function (ctx, ref) {
  8797. var k = ref[0];
  8798. return (k ).value in ctx.properties();
  8799. }
  8800. ],
  8801. 'filter-has-id': [
  8802. BooleanType$8,
  8803. [],
  8804. function (ctx) {
  8805. return ctx.id() !== null;
  8806. }
  8807. ],
  8808. 'filter-type-in': [
  8809. BooleanType$8,
  8810. [array$5(StringType$8)],
  8811. function (ctx, ref) {
  8812. var v = ref[0];
  8813. return (v ).value.indexOf(ctx.geometryType()) >= 0;
  8814. }
  8815. ],
  8816. 'filter-id-in': [
  8817. BooleanType$8,
  8818. [array$5(ValueType$a)],
  8819. function (ctx, ref) {
  8820. var v = ref[0];
  8821. return (v ).value.indexOf(ctx.id()) >= 0;
  8822. }
  8823. ],
  8824. 'filter-in-small': [
  8825. BooleanType$8,
  8826. [StringType$8, array$5(ValueType$a)],
  8827. // assumes v is an array literal
  8828. function (ctx, ref) {
  8829. var k = ref[0];
  8830. var v = ref[1];
  8831. return (v ).value.indexOf(ctx.properties()[(k ).value]) >= 0;
  8832. }
  8833. ],
  8834. 'filter-in-large': [
  8835. BooleanType$8,
  8836. [StringType$8, array$5(ValueType$a)],
  8837. // assumes v is a array literal with values sorted in ascending order and of a single type
  8838. function (ctx, ref) {
  8839. var k = ref[0];
  8840. var v = ref[1];
  8841. return binarySearch(ctx.properties()[(k ).value], (v ).value, 0, (v ).value.length - 1);
  8842. }
  8843. ],
  8844. 'all': {
  8845. type: BooleanType$8,
  8846. overloads: [
  8847. [
  8848. [BooleanType$8, BooleanType$8],
  8849. function (ctx, ref) {
  8850. var a = ref[0];
  8851. var b = ref[1];
  8852. return a.evaluate(ctx) && b.evaluate(ctx);
  8853. }
  8854. ],
  8855. [
  8856. varargs(BooleanType$8),
  8857. function (ctx, args) {
  8858. for (var i = 0, list = args; i < list.length; i += 1) {
  8859. var arg = list[i];
  8860. if (!arg.evaluate(ctx)) {
  8861. return false;
  8862. }
  8863. }
  8864. return true;
  8865. }
  8866. ]
  8867. ]
  8868. },
  8869. 'crossFields': {
  8870. type: BooleanType$8,
  8871. overloads: [
  8872. [
  8873. [BooleanType$8, BooleanType$8],
  8874. function (ctx, ref) {
  8875. var a = ref[0];
  8876. var b = ref[1];
  8877. return a.evaluate(ctx, true) && b.evaluate(ctx, true);
  8878. }
  8879. ],
  8880. [
  8881. varargs(BooleanType$8),
  8882. function (ctx, args) {
  8883. for (var i = 0, list = args; i < list.length; i += 1) {
  8884. var arg = list[i];
  8885. if (!arg.evaluate(ctx, true)) {
  8886. return false;
  8887. }
  8888. }
  8889. return true;
  8890. }
  8891. ]
  8892. ]
  8893. },
  8894. 'any': {
  8895. type: BooleanType$8,
  8896. overloads: [
  8897. [
  8898. [BooleanType$8, BooleanType$8],
  8899. function (ctx, ref) {
  8900. var a = ref[0];
  8901. var b = ref[1];
  8902. return a.evaluate(ctx) || b.evaluate(ctx);
  8903. }
  8904. ],
  8905. [
  8906. varargs(BooleanType$8),
  8907. function (ctx, args) {
  8908. for (var i = 0, list = args; i < list.length; i += 1) {
  8909. var arg = list[i];
  8910. if (arg.evaluate(ctx)) {
  8911. return true;
  8912. }
  8913. }
  8914. return false;
  8915. }
  8916. ]
  8917. ]
  8918. },
  8919. '!': [
  8920. BooleanType$8,
  8921. [BooleanType$8],
  8922. function (ctx, ref, crossFields) {
  8923. var b = ref[0];
  8924. return !b.evaluate(ctx, crossFields);
  8925. }
  8926. ],
  8927. 'is-supported-script': [
  8928. BooleanType$8,
  8929. [StringType$8],
  8930. // At parse time this will always return true, so we need to exclude this expression with isGlobalPropertyConstant
  8931. function (ctx, ref) {
  8932. var s = ref[0];
  8933. var isSupportedScript = ctx.globals && ctx.globals.isSupportedScript;
  8934. if (isSupportedScript) {
  8935. return isSupportedScript(s.evaluate(ctx));
  8936. }
  8937. return true;
  8938. }
  8939. ],
  8940. 'upcase': [
  8941. StringType$8,
  8942. [StringType$8],
  8943. function (ctx, ref) {
  8944. var s = ref[0];
  8945. return s.evaluate(ctx).toUpperCase();
  8946. }
  8947. ],
  8948. 'downcase': [
  8949. StringType$8,
  8950. [StringType$8],
  8951. function (ctx, ref) {
  8952. var s = ref[0];
  8953. return s.evaluate(ctx).toLowerCase();
  8954. }
  8955. ],
  8956. 'concat': [
  8957. StringType$8,
  8958. varargs(ValueType$a),
  8959. function (ctx, args) {
  8960. return args.map(function (arg) {
  8961. return Values.toString$1(arg.evaluate(ctx));
  8962. }).join('');
  8963. }
  8964. ],
  8965. 'resolved-locale': [
  8966. StringType$8,
  8967. [CollatorType$3],
  8968. function (ctx, ref) {
  8969. var collator = ref[0];
  8970. return collator.evaluate(ctx).resolvedLocale();
  8971. }
  8972. ]
  8973. });
  8974. var StyleExpression$1 = function StyleExpression(expression, propertySpec) {
  8975. this.expression = expression;
  8976. this._warningHistory = {};
  8977. this._evaluator = new EvaluationContext();
  8978. this._defaultValue = propertySpec ? getDefaultValue(propertySpec) : null;
  8979. this._enumValues = propertySpec && propertySpec.type === 'enum' ? propertySpec.values : null;
  8980. };
  8981. StyleExpression$1.prototype.evaluateWithoutErrorHandling = function evaluateWithoutErrorHandling(globals, feature, featureState, availableImages, formattedSection) {
  8982. this._evaluator.globals = globals;
  8983. this._evaluator.feature = feature;
  8984. this._evaluator.featureState = featureState;
  8985. this._evaluator.availableImages = availableImages || null;
  8986. this._evaluator.formattedSection = formattedSection;
  8987. return this.expression.evaluate(this._evaluator);
  8988. };
  8989. StyleExpression$1.prototype.evaluate = function evaluate(globals, feature, featureState, availableImages, formattedSection) {
  8990. this._evaluator.globals = globals;
  8991. this._evaluator.feature = feature || null;
  8992. this._evaluator.featureState = featureState || null;
  8993. this._evaluator.availableImages = availableImages || null;
  8994. this._evaluator.formattedSection = formattedSection || null;
  8995. try {
  8996. var val = this.expression.evaluate(this._evaluator);
  8997. // eslint-disable-next-line no-self-compare
  8998. if (val === null || val === undefined || (typeof val === 'number' && val !== val)) {
  8999. return this._defaultValue;
  9000. }
  9001. if (this._enumValues && !(val in this._enumValues)) {
  9002. throw new RuntimeError(("Expected value to be one of " + (Object.keys(this._enumValues).map(function (v) {
  9003. return JSON.stringify(v);
  9004. }).join(', ')) + ", but found " + (JSON.stringify(val)) + " instead."));
  9005. }
  9006. return val;
  9007. } catch (e) {
  9008. if (!this._warningHistory[e.message]) {
  9009. this._warningHistory[e.message] = true;
  9010. if (typeof console !== 'undefined') {
  9011. console.warn(e.message);
  9012. }
  9013. }
  9014. return this._defaultValue;
  9015. }
  9016. };
  9017. function isFunction(value) {
  9018. return typeof value === 'object' && value !== null && !Array.isArray(value);
  9019. }
  9020. function getDefaultValue(spec) {
  9021. if (spec.type === 'color' && isFunction(spec.default)) {
  9022. // Special case for heatmap-color: it uses the 'default:' to define a
  9023. // default color ramp, but createExpression expects a simple value to fall
  9024. // back to in case of runtime errors
  9025. return new Color(0, 0, 0, 0);
  9026. } else if (spec.type === 'color') {
  9027. return Color.parse(spec.default) || null;
  9028. } else if (spec.default === undefined) {
  9029. return null;
  9030. } else {
  9031. return spec.default;
  9032. }
  9033. }
  9034. function Expression() {
  9035. }
  9036. function success(value) {
  9037. return {result: 'success', value: value};
  9038. }
  9039. function error(value) {
  9040. return {result: 'error', value: value};
  9041. }
  9042. Expression.isExpression = function (testExpression) {
  9043. return Array.isArray(testExpression) && testExpression.length > 0 &&
  9044. typeof testExpression[0] === 'string' && testExpression[0] in expressions;
  9045. };
  9046. var NumberType$b = {kind: 'number'};
  9047. var StringType$9 = {kind: 'string'};
  9048. var BooleanType$9 = {kind: 'boolean'};
  9049. var ColorType$6 = {kind: 'color'};
  9050. var ValueType$b = {kind: 'value'};
  9051. var FormattedType$3 = {kind: 'formatted'};
  9052. var ResolvedImageType$4 = {kind: 'resolvedImage'};
  9053. function array$6(itemType, N) {
  9054. return {
  9055. kind: 'array',
  9056. itemType: itemType,
  9057. N: N
  9058. };
  9059. }
  9060. function getExpectedType(spec) {
  9061. var types = {
  9062. color: ColorType$6,
  9063. string: StringType$9,
  9064. number: NumberType$b,
  9065. enum: StringType$9,
  9066. boolean: BooleanType$9,
  9067. formatted: FormattedType$3,
  9068. resolvedImage: ResolvedImageType$4
  9069. };
  9070. if (spec.type === 'array') {
  9071. return array$6(types[spec.value] || ValueType$b, spec.length);
  9072. }
  9073. return types[spec.type];
  9074. }
  9075. Expression.createExpression = function (expression, propertySpec) {
  9076. var parser = new ParsingContext(expressions, [], propertySpec ? getExpectedType(propertySpec) : undefined);
  9077. // For string-valued properties, coerce to string at the top level rather than asserting.
  9078. var parsed = parser.parse(expression, undefined, undefined, undefined,
  9079. propertySpec && propertySpec.type === 'string' ? {typeAnnotation: 'coerce'} : undefined);
  9080. if (!parsed) {
  9081. //assert_1(parser.errors.length > 0);
  9082. return error(parser.errors);
  9083. }
  9084. return success(new StyleExpression$1(parsed, propertySpec));
  9085. };
  9086. function isFunction$1(value) {
  9087. return typeof value === 'object' && value !== null && !Array.isArray(value);
  9088. }
  9089. function extend$1(output) {
  9090. var inputs = [], len = arguments.length - 1;
  9091. while (len-- > 0) inputs[ len ] = arguments[ len + 1 ];
  9092. for (var i = 0, list = inputs; i < list.length; i += 1) {
  9093. var input = list[i];
  9094. for (var k in input) {
  9095. output[k] = input[k];
  9096. }
  9097. }
  9098. return output;
  9099. }
  9100. function evaluateIdentityFunction(parameters, propertySpec, input) {
  9101. if (propertySpec.type === 'color') {
  9102. input = Color$1.parse(input);
  9103. } else if (propertySpec.type === 'formatted') {
  9104. input = Formatted.fromString(input.toString());
  9105. } else if (propertySpec.type === 'resolvedImage') {
  9106. input = ResolvedImage.fromString(input.toString());
  9107. } else if (getType(input) !== propertySpec.type && (propertySpec.type !== 'enum' || !propertySpec.values[input])) {
  9108. input = undefined;
  9109. }
  9110. return coalesce(input, parameters.default, propertySpec.default);
  9111. }
  9112. function createFunction(parameters, propertySpec) {
  9113. var isColor = propertySpec.type === 'color';
  9114. var zoomAndFeatureDependent = parameters.stops && typeof parameters.stops[0][0] === 'object';
  9115. var featureDependent = zoomAndFeatureDependent || parameters.property !== undefined;
  9116. var zoomDependent = zoomAndFeatureDependent || !featureDependent;
  9117. var type = parameters.type || (supportsInterpolation(propertySpec) ? 'exponential' : 'interval');
  9118. if (isColor) {
  9119. parameters = extend$1({}, parameters);
  9120. if (parameters.stops) {
  9121. parameters.stops = parameters.stops.map(function (stop) {
  9122. return [stop[0], Color$1.parse(stop[1])];
  9123. });
  9124. }
  9125. if (parameters.default) {
  9126. parameters.default = Color$1.parse(parameters.default);
  9127. } else {
  9128. parameters.default = Color$1.parse(propertySpec.default);
  9129. }
  9130. }
  9131. if (parameters.colorSpace && parameters.colorSpace !== 'rgb' && !colorSpaces[parameters.colorSpace]) { // eslint-disable-line import/namespace
  9132. throw new Error(("Unknown color space: " + (parameters.colorSpace)));
  9133. }
  9134. var innerFun;
  9135. var hashedStops;
  9136. var categoricalKeyType;
  9137. if (type === 'exponential') {
  9138. innerFun = evaluateExponentialFunction;
  9139. } else if (type === 'interval') {
  9140. innerFun = evaluateIntervalFunction;
  9141. } else if (type === 'categorical') {
  9142. innerFun = evaluateCategoricalFunction;
  9143. // For categorical functions, generate an Object as a hashmap of the stops for fast searching
  9144. hashedStops = Object.create(null);
  9145. for (var i = 0, list = parameters.stops; i < list.length; i += 1) {
  9146. var stop = list[i];
  9147. hashedStops[stop[0]] = stop[1];
  9148. }
  9149. // Infer key type based on first stop key-- used to encforce strict type checking later
  9150. categoricalKeyType = typeof parameters.stops[0][0];
  9151. } else if (type === 'identity') {
  9152. innerFun = evaluateIdentityFunction;
  9153. } else {
  9154. throw new Error(("Unknown function type \"" + type + "\""));
  9155. }
  9156. if (zoomAndFeatureDependent) {
  9157. var featureFunctions = {};
  9158. var zoomStops = [];
  9159. for (var s = 0; s < parameters.stops.length; s++) {
  9160. var stop$1 = parameters.stops[s];
  9161. var zoom = stop$1[0].zoom;
  9162. if (featureFunctions[zoom] === undefined) {
  9163. featureFunctions[zoom] = {
  9164. zoom: zoom,
  9165. type: parameters.type,
  9166. property: parameters.property,
  9167. default: parameters.default,
  9168. stops: []
  9169. };
  9170. zoomStops.push(zoom);
  9171. }
  9172. featureFunctions[zoom].stops.push([stop$1[0].value, stop$1[1]]);
  9173. }
  9174. var featureFunctionStops = [];
  9175. for (var i$1 = 0, list$1 = zoomStops; i$1 < list$1.length; i$1 += 1) {
  9176. var z = list$1[i$1];
  9177. featureFunctionStops.push([featureFunctions[z].zoom, createFunction(featureFunctions[z], propertySpec)]);
  9178. }
  9179. var interpolationType = {name: 'linear'};
  9180. return {
  9181. kind: 'composite',
  9182. interpolationType: interpolationType,
  9183. interpolationFactor: Interpolate.interpolationFactor.bind(undefined, interpolationType),
  9184. zoomStops: featureFunctionStops.map(function (s) {
  9185. return s[0];
  9186. }),
  9187. evaluate: function evaluate(ref, properties) {
  9188. var zoom = ref.zoom;
  9189. return evaluateExponentialFunction({
  9190. stops: featureFunctionStops,
  9191. base: parameters.base
  9192. }, propertySpec, zoom).evaluate(zoom, properties);
  9193. }
  9194. };
  9195. } else if (zoomDependent) {
  9196. var interpolationType$1 = type === 'exponential' ?
  9197. {name: 'exponential', base: parameters.base !== undefined ? parameters.base : 1} : null;
  9198. return {
  9199. kind: 'camera',
  9200. interpolationType: interpolationType$1,
  9201. interpolationFactor: Interpolate.interpolationFactor.bind(undefined, interpolationType$1),
  9202. zoomStops: parameters.stops.map(function (s) {
  9203. return s[0];
  9204. }),
  9205. evaluate: function (ref) {
  9206. var zoom = ref.zoom;
  9207. return innerFun(parameters, propertySpec, zoom, hashedStops, categoricalKeyType);
  9208. }
  9209. };
  9210. } else {
  9211. return {
  9212. kind: 'source',
  9213. evaluate: function evaluate(_, feature) {
  9214. var value = feature && feature.properties ? feature.properties[parameters.property] : undefined;
  9215. if (value === undefined) {
  9216. return coalesce(parameters.default, propertySpec.default);
  9217. }
  9218. return innerFun(parameters, propertySpec, value, hashedStops, categoricalKeyType);
  9219. }
  9220. };
  9221. }
  9222. }
  9223. function coalesce(a, b, c) {
  9224. if (a !== undefined) return a;
  9225. if (b !== undefined) return b;
  9226. if (c !== undefined) return c;
  9227. }
  9228. // serialization wrapper for old-style stop functions normalized to the
  9229. // expression interface
  9230. var StylePropertyFunction = function StylePropertyFunction(parameters, specification) {
  9231. this._parameters = parameters;
  9232. this._specification = specification;
  9233. extend$1(this, createFunction(this._parameters, this._specification));
  9234. };
  9235. StylePropertyFunction.deserialize = function deserialize(serialized) {
  9236. return ((new StylePropertyFunction(serialized._parameters, serialized._specification)) );
  9237. };
  9238. StylePropertyFunction.serialize = function serialize(input) {
  9239. return {
  9240. _parameters: input._parameters,
  9241. _specification: input._specification
  9242. };
  9243. };
  9244. Expression.normalizePropertyExpression = function (value, specification) {
  9245. if (isFunction$1(value)) {
  9246. return (new StylePropertyFunction(value, specification) );
  9247. } else if (Expression.isExpression(value)) {
  9248. var expression = createPropertyExpression(value, specification);
  9249. if (expression.result === 'error') {
  9250. // this should have been caught in validation
  9251. throw new Error(expression.value.map(function (err) {
  9252. return ((err.key) + ": " + (err.message));
  9253. }).join(', '));
  9254. }
  9255. return expression.value;
  9256. } else {
  9257. var constant = value;
  9258. if (typeof value === 'string' && specification.type === 'color') {
  9259. constant = Color$1.parse(value);
  9260. }
  9261. return {
  9262. kind: 'constant',
  9263. evaluate: function () {
  9264. return constant;
  9265. }
  9266. };
  9267. }
  9268. };
  9269. function featureFilter() {
  9270. }
  9271. featureFilter.isExpressionFilter = function (filter) {
  9272. if (filter === true || filter === false) {
  9273. return true;
  9274. }
  9275. if (!Array.isArray(filter) || filter.length === 0) {
  9276. return false;
  9277. }
  9278. switch (filter[0]) {
  9279. case 'has':
  9280. return filter.length >= 2 && filter[1] !== '$id' && filter[1] !== '$type';
  9281. case 'in':
  9282. return filter.length >= 3 && Array.isArray(filter[2]);
  9283. case '!in':
  9284. case '!has':
  9285. case 'none':
  9286. case 'crossFields':
  9287. return false;
  9288. case '==':
  9289. case '!=':
  9290. case '>':
  9291. case '>=':
  9292. case '<':
  9293. case '<=':
  9294. case 'like':
  9295. case '!like':
  9296. return filter.length !== 3 || (Array.isArray(filter[1]) || Array.isArray(filter[2]));
  9297. case 'any':
  9298. case 'all':
  9299. for (var i = 0, list = filter.slice(1); i < list.length; i += 1) {
  9300. var f = list[i];
  9301. if (!featureFilter.isExpressionFilter(f) && typeof f !== 'boolean') {
  9302. return false;
  9303. }
  9304. }
  9305. return true;
  9306. default:
  9307. return true;
  9308. }
  9309. };
  9310. var filterSpec = {
  9311. 'type': 'boolean',
  9312. 'default': false,
  9313. 'transition': false,
  9314. 'property-type': 'data-driven',
  9315. 'expression': {
  9316. 'interpolated': false,
  9317. 'parameters': ['zoom', 'feature']
  9318. }
  9319. };
  9320. /**
  9321. * Given a filter expressed as nested arrays, return a new function
  9322. * that evaluates whether a given feature (with a .properties or .tags property)
  9323. * passes its test.
  9324. *
  9325. * @private
  9326. * @param {Array} filter mapbox gl filter
  9327. * @returns {Function} filter-evaluating function
  9328. */
  9329. featureFilter.createFilter = function (filter) {
  9330. if (filter === null || filter === undefined) {
  9331. return function () {
  9332. return true;
  9333. };
  9334. }
  9335. if (!featureFilter.isExpressionFilter(filter)) {
  9336. filter = convertFilter(filter);
  9337. }
  9338. var compiled = Expression.createExpression(filter, filterSpec);
  9339. if (compiled.result === 'error') {
  9340. throw new Error(compiled.value.map(function (err) {
  9341. return ((err.key) + ": " + (err.message));
  9342. }).join(', '));
  9343. } else {
  9344. return function (globalProperties, feature) {
  9345. return compiled.value.evaluate(globalProperties, feature);
  9346. };
  9347. }
  9348. };
  9349. // Comparison function to sort numbers and strings
  9350. function compare(a, b) {
  9351. return a < b ? -1 : a > b ? 1 : 0;
  9352. }
  9353. function convertFilter(filter) {
  9354. if (!filter) {
  9355. return true;
  9356. }
  9357. var op = filter[0];
  9358. if (filter.length <= 1) {
  9359. return (op !== 'any');
  9360. }
  9361. var converted =
  9362. op === '==' ? convertComparisonOp(filter[1], filter[2], '==') :
  9363. op === '!=' ? convertNegation(convertComparisonOp(filter[1], filter[2], '==')) :
  9364. op === '<' ||
  9365. op === '>' ||
  9366. op === '<=' ||
  9367. op === '>=' ? convertComparisonOp(filter[1], filter[2], op) :
  9368. op === 'any' ? convertDisjunctionOp(filter.slice(1)) :
  9369. op === 'all' ? ['all'].concat(filter.slice(1).map(convertFilter)) :
  9370. op === 'crossFields' ? ['crossFields'].concat(filter.slice(1).map(convertFilter)) :
  9371. op === 'none' ? ['all'].concat(filter.slice(1).map(convertFilter).map(convertNegation)) :
  9372. op === 'in' ? convertInOp(filter[1], filter.slice(2)) :
  9373. op === '!in' ? convertNegation(convertInOp(filter[1], filter.slice(2))) :
  9374. op === 'has' ? convertHasOp(filter[1]) :
  9375. op === '!has' ? convertNegation(convertHasOp(filter[1])) :
  9376. op === 'like' ? convertComparisonOp(filter[1], filter[2], 'like') :
  9377. op === '!like' ? convertNegation(convertComparisonOp(filter[1], filter[2], 'like')) :
  9378. true;
  9379. return converted;
  9380. }
  9381. function convertComparisonOp(property, value, op) {
  9382. switch (property) {
  9383. case '$type':
  9384. return [("filter-type-" + op), value];
  9385. case '$id':
  9386. return [("filter-id-" + op), value];
  9387. default:
  9388. return [("filter-" + op), property, value];
  9389. }
  9390. }
  9391. function convertDisjunctionOp(filters) {
  9392. return ['any'].concat(filters.map(convertFilter));
  9393. }
  9394. function convertInOp(property, values) {
  9395. if (values.length === 0) {
  9396. return false;
  9397. }
  9398. switch (property) {
  9399. case '$type':
  9400. return ["filter-type-in", ['literal', values]];
  9401. case '$id':
  9402. return ["filter-id-in", ['literal', values]];
  9403. default:
  9404. if (values.length > 200 && !values.some(function (v) {
  9405. return typeof v !== typeof values[0];
  9406. })) {
  9407. return ['filter-in-large', property, ['literal', values.sort(compare)]];
  9408. } else {
  9409. return ['filter-in-small', property, ['literal', values]];
  9410. }
  9411. }
  9412. }
  9413. function convertHasOp(property) {
  9414. switch (property) {
  9415. case '$type':
  9416. return true;
  9417. case '$id':
  9418. return ["filter-has-id"];
  9419. default:
  9420. return ["filter-has", property];
  9421. }
  9422. }
  9423. function convertNegation(filter) {
  9424. return ['!', filter];
  9425. }
  9426. var FeatureIndexArray$1 = arrayTypes.FeatureIndexArray;
  9427. var FeatureIndex = function FeatureIndex(tileID, grid, featureIndexArray) {
  9428. //this.tileID = tileID;
  9429. this.x = tileID.x;
  9430. this.y = tileID.y;
  9431. this.z = tileID.z;
  9432. this.grid = grid || new GridIndex(EXTENT, 16, 0);
  9433. this.featureIndexArray = featureIndexArray || new FeatureIndexArray$1();
  9434. };
  9435. FeatureIndex.prototype.insert = function insert(feature, geometry, featureIndex, sourceLayerIndex, bucketIndex, is3D, padding) {
  9436. var key = this.featureIndexArray.length;
  9437. this.featureIndexArray.emplaceBack(featureIndex, sourceLayerIndex, bucketIndex);
  9438. var grid = this.grid;
  9439. padding = padding || 0;
  9440. for (var r = 0; r < geometry.length; r++) {
  9441. var ring = geometry[r];
  9442. var bbox = [Infinity, Infinity, -Infinity, -Infinity];
  9443. for (var i = 0; i < ring.length; i++) {
  9444. var p = ring[i];
  9445. bbox[0] = Math.min(bbox[0], p.x);
  9446. bbox[1] = Math.min(bbox[1], p.y);
  9447. bbox[2] = Math.max(bbox[2], p.x);
  9448. bbox[3] = Math.max(bbox[3], p.y);
  9449. }
  9450. if (bbox[0] < EXTENT &&
  9451. bbox[1] < EXTENT &&
  9452. bbox[2] >= 0 &&
  9453. bbox[3] >= 0) {
  9454. grid.insert(key, bbox[0] - padding, bbox[1] - padding, bbox[2] + padding, bbox[3] + padding);
  9455. }
  9456. }
  9457. };
  9458. FeatureIndex.prototype.loadVTLayers = function loadVTLayers() {
  9459. if (!this.vtLayers) {
  9460. this.vtLayers = new VectorTile(new pbf.Protobuf(this.rawTileData)).layers;
  9461. this.sourceLayerCoder = new DictionaryCoder(this.vtLayers ? Object.keys(this.vtLayers).sort() : ['_geojsonTileLayer']);
  9462. }
  9463. return this.vtLayers;
  9464. };
  9465. // Finds non-symbol features in this tile at a particular position.
  9466. FeatureIndex.prototype.query = function query(args, styleLayers, sourceFeatureState) {
  9467. var this$1 = this;
  9468. this.loadVTLayers();
  9469. var params = args.params || {};
  9470. var pixelsToTileUnits = computePixelsToTileUnits(this.z, args.tileSize, params);
  9471. var filter = featureFilter.createFilter(params.filter);
  9472. var queryGeometry = args.queryGeometry;
  9473. var queryPadding = 5;
  9474. var bounds = getBounds(queryGeometry);
  9475. var matching = [];
  9476. if(when.defined(params.selectTolerance)){
  9477. queryPadding += pixelsToTileUnits * params.selectTolerance;
  9478. }
  9479. matching = this.grid.query(bounds.minX - queryPadding, bounds.minY - queryPadding, bounds.maxX + queryPadding, bounds.maxY + queryPadding);
  9480. matching.sort(topDownFeatureComparator);
  9481. var result = {};
  9482. var previousIndex;
  9483. var loop = function (k) {
  9484. var index = matching[k];
  9485. // don't check the same feature more than once
  9486. if (index === previousIndex) {
  9487. return;
  9488. }
  9489. previousIndex = index;
  9490. var match = this$1.featureIndexArray.get(index);
  9491. var featureGeometry = null;
  9492. this$1.loadMatchingFeature(
  9493. result,
  9494. match.bucketIndex,
  9495. match.sourceLayerIndex,
  9496. match.featureIndex,
  9497. filter,
  9498. params.layers,
  9499. styleLayers,
  9500. function (feature, styleLayer) {
  9501. if (!featureGeometry) {
  9502. featureGeometry = loadGeometry(feature);
  9503. }
  9504. var featureState = {};
  9505. // if (feature.id) {
  9506. // // `feature-state` expression evaluation requires feature state to be available
  9507. // featureState = sourceFeatureState.getState(styleLayer.sourceLayer || '_geojsonTileLayer', feature.id);
  9508. // }
  9509. return styleLayer.queryIntersectsFeature(queryGeometry, feature, featureState, featureGeometry, this$1.z, args.transform, pixelsToTileUnits, args.pixelPosMatrix, args.adjustScale);
  9510. }
  9511. );
  9512. };
  9513. for (var k = 0; k < matching.length; k++) loop(k);
  9514. return result;
  9515. };
  9516. FeatureIndex.prototype.loadMatchingFeature = function loadMatchingFeature(result, bucketIndex, sourceLayerIndex, featureIndex, filter, filterLayerIDs, styleLayers, intersectionTest) {
  9517. if(!when.defined(bucketIndex) || !when.defined(sourceLayerIndex) || !when.defined(featureIndex)){
  9518. return;
  9519. }
  9520. var layerIDs = this.bucketLayerIDs[bucketIndex];
  9521. if (filterLayerIDs && !Util.arraysIntersect(filterLayerIDs, layerIDs)) {
  9522. return;
  9523. }
  9524. var sourceLayerName = this.sourceLayerCoder.decode(sourceLayerIndex);
  9525. var sourceLayer = this.vtLayers[sourceLayerName];
  9526. var feature = sourceLayer.feature(featureIndex);
  9527. if (!filter(new EvaluationParameters$1(this.z), feature)) {
  9528. return;
  9529. }
  9530. for (var l = 0; l < layerIDs.length; l++) {
  9531. var layerID = layerIDs[l];
  9532. if (filterLayerIDs && filterLayerIDs.indexOf(layerID) < 0) {
  9533. continue;
  9534. }
  9535. var styleLayer = styleLayers[layerID];
  9536. if (!styleLayer) {
  9537. continue;
  9538. }
  9539. var intersectionZ = !intersectionTest || intersectionTest(feature, styleLayer);
  9540. if (!intersectionZ) {
  9541. // Only applied for non-symbol features
  9542. continue;
  9543. }
  9544. // var geojsonFeature = new Feature(feature, this.z, this.x, this.y);
  9545. // (geojsonFeature ).layer = styleLayer.serialize();
  9546. feature.layer = styleLayer.serialize();
  9547. var layerResult = result[layerID];
  9548. if (layerResult === undefined) {
  9549. layerResult = result[layerID] = [];
  9550. }
  9551. layerResult.push({featureIndex: featureIndex, feature: feature, intersectionZ: intersectionZ});
  9552. }
  9553. };
  9554. // Given a set of symbol indexes that have already been looked up,
  9555. // return a matching set of GeoJSONFeatures
  9556. FeatureIndex.prototype.lookupSymbolFeatures = function lookupSymbolFeatures(symbolFeatureIndexes, bucketIndex, sourceLayerIndex, filterSpec, filterLayerIDs, styleLayers) {
  9557. var result = {};
  9558. this.loadVTLayers();
  9559. var filter = createFilter(filterSpec);
  9560. for (var i = 0, list = symbolFeatureIndexes; i < list.length; i += 1) {
  9561. var symbolFeatureIndex = list[i];
  9562. this.loadMatchingFeature(
  9563. result,
  9564. bucketIndex,
  9565. sourceLayerIndex,
  9566. symbolFeatureIndex,
  9567. filter,
  9568. filterLayerIDs,
  9569. styleLayers
  9570. );
  9571. }
  9572. return result;
  9573. };
  9574. FeatureIndex.prototype.hasLayer = function hasLayer(id) {
  9575. for (var i$1 = 0, list$1 = this.bucketLayerIDs; i$1 < list$1.length; i$1 += 1) {
  9576. var layerIDs = list$1[i$1];
  9577. for (var i = 0, list = layerIDs; i < list.length; i += 1) {
  9578. var layerID = list[i];
  9579. if (id === layerID) {
  9580. return true;
  9581. }
  9582. }
  9583. }
  9584. return false;
  9585. };
  9586. // register(
  9587. // 'FeatureIndex',
  9588. // FeatureIndex,
  9589. // {omit: ['rawTileData', 'sourceLayerCoder']}
  9590. // );
  9591. function getBounds(geometry) {
  9592. var minX = Infinity;
  9593. var minY = Infinity;
  9594. var maxX = -Infinity;
  9595. var maxY = -Infinity;
  9596. for (var i = 0, list = geometry; i < list.length; i += 1) {
  9597. var p = list[i];
  9598. minX = Math.min(minX, p.x);
  9599. minY = Math.min(minY, p.y);
  9600. maxX = Math.max(maxX, p.x);
  9601. maxY = Math.max(maxY, p.y);
  9602. }
  9603. return {minX: minX, minY: minY, maxX: maxX, maxY: maxY};
  9604. }
  9605. function topDownFeatureComparator(a, b) {
  9606. return b - a;
  9607. }
  9608. function computePixelsToTileUnits(tileLevel, tileSize, options) {
  9609. if(when.defined(options) && options.realtime && when.defined(options.zoom)) {
  9610. var currentZoom = options.zoom;
  9611. var diff = currentZoom - tileLevel;
  9612. var result = (EXTENT / (tileSize * Math.pow(2, diff)));
  9613. // 线宽以512尺寸的切片大小为基准
  9614. result *= tileSize / 512;
  9615. return result;
  9616. } else {
  9617. return EXTENT / tileSize;
  9618. }
  9619. }
  9620. WebWorkerTransfer.register('FeatureIndex', FeatureIndex, {omit: ['rawTileData', 'sourceLayerCoder', 'vtLayers']});
  9621. const refProperties = ['type', 'source', 'source-layer', 'minzoom', 'maxzoom', 'filter', 'layout'];
  9622. function stringify(obj) {
  9623. var type = typeof obj;
  9624. if (type === 'number' || type === 'boolean' || type === 'string' || obj === undefined || obj === null)
  9625. { return JSON.stringify(obj); }
  9626. if (Array.isArray(obj)) {
  9627. var str$1 = '[';
  9628. for (var i$1 = 0, list = obj; i$1 < list.length; i$1 += 1) {
  9629. var val = list[i$1];
  9630. str$1 += (stringify(val)) + ",";
  9631. }
  9632. return (str$1 + "]");
  9633. }
  9634. var keys = Object.keys(obj).sort();
  9635. var str = '{';
  9636. for (var i = 0; i < keys.length; i++) {
  9637. str += (JSON.stringify(keys[i])) + ":" + (stringify(obj[keys[i]])) + ",";
  9638. }
  9639. return (str + "}");
  9640. }
  9641. function getKey(layer) {
  9642. var key = '';
  9643. for (var i = 0, list = refProperties; i < list.length; i += 1) {
  9644. var k = list[i];
  9645. key += "/" + (stringify(layer[k]));
  9646. }
  9647. return key;
  9648. }
  9649. /**
  9650. * Given an array of layers, return an array of arrays of layers where all
  9651. * layers in each group have identical layout-affecting properties. These
  9652. * are the properties that were formerly used by explicit `ref` mechanism
  9653. * for layers: 'type', 'source', 'source-layer', 'minzoom', 'maxzoom',
  9654. * 'filter', and 'layout'.
  9655. *
  9656. * The input is not modified. The output layers are references to the
  9657. * input layers.
  9658. *
  9659. * @private
  9660. * @param {Array<Layer>} layers
  9661. * @param {Object} [cachedKeys] - an object to keep already calculated keys.
  9662. * @returns {Array<Array<Layer>>}
  9663. */
  9664. function groupByLayout(layers, cachedKeys) {
  9665. var groups = {};
  9666. for (var i = 0; i < layers.length; i++) {
  9667. var k = (cachedKeys && cachedKeys[layers[i].id]) || getKey(layers[i]);
  9668. // update the cache if there is one
  9669. if (cachedKeys)
  9670. { cachedKeys[layers[i].id] = k; }
  9671. var group = groups[k];
  9672. if (!group) {
  9673. group = groups[k] = [];
  9674. }
  9675. group.push(layers[i]);
  9676. }
  9677. var result = [];
  9678. for (var k$1 in groups) {
  9679. result.push(groups[k$1]);
  9680. }
  9681. return result;
  9682. }
  9683. var layout$1 = createLayout([
  9684. {name: 'a_pos', components: 2, type: 'Int16'}
  9685. ], 4);
  9686. var members = layout$1.members;
  9687. function addCircleVertex(layoutVertexArray, x, y, extrudeX, extrudeY) {
  9688. layoutVertexArray.emplaceBack(
  9689. (x * 2) + ((extrudeX + 1) / 2),
  9690. (y * 2) + ((extrudeY + 1) / 2));
  9691. }
  9692. /**
  9693. * Circles are represented by two triangles.
  9694. *
  9695. * Each corner has a pos that is the center of the circle and an extrusion
  9696. * vector that is where it points.
  9697. * @private
  9698. */
  9699. var CircleBucket = function CircleBucket(options) {
  9700. this.zoom = options.zoom;
  9701. this.overscaling = options.overscaling;
  9702. this.layers = options.layers;
  9703. this.layerIds = this.layers.map(function (layer) {
  9704. return layer.id;
  9705. });
  9706. this.index = options.index;
  9707. this.hasPattern = false;
  9708. this.layoutVertexArray = new StructArrayLayout2i4();
  9709. this.indexArray = new StructArrayLayout3ui6();
  9710. this.segments = new SegmentVector();
  9711. this.programConfigurations = new ProgramConfigurationSet(members, options.layers, options.zoom);
  9712. this.stateDependentLayerIds = this.layers.filter(function (l) {
  9713. return l.isStateDependent();
  9714. }).map(function (l) {
  9715. return l.id;
  9716. });
  9717. };
  9718. CircleBucket.prototype.populate = function populate(features, options) {
  9719. var styleLayer = this.layers[0];
  9720. var bucketFeatures = [];
  9721. var circleSortKey = null;
  9722. // Heatmap layers are handled in this bucket and have no evaluated properties, so we check our access
  9723. if (styleLayer.type === 'circle') {
  9724. circleSortKey = ((styleLayer )).layout.get('circle-sort-key');
  9725. }
  9726. for (var i = 0, list = features; i < list.length; i += 1) {
  9727. var ref = list[i];
  9728. var feature = ref.feature;
  9729. var index = ref.index;
  9730. var sourceLayerIndex = ref.sourceLayerIndex;
  9731. var currentLayer = this.layers[sourceLayerIndex];
  9732. var pixelsToTileUnits = EXTENT / 512;
  9733. var circleRadius = currentLayer.paint.get('circle-radius').value.value * pixelsToTileUnits;
  9734. if (this.layers[0]._featureFilter(new EvaluationParameters$1(0), feature)) {
  9735. var geometry = loadGeometry(feature);
  9736. var sortKey = circleSortKey ?
  9737. circleSortKey.evaluate(feature, {}) :
  9738. undefined;
  9739. var bucketFeature = {
  9740. id: feature.id,
  9741. properties: feature.properties,
  9742. type: feature.type,
  9743. sourceLayerIndex: sourceLayerIndex,
  9744. index: index,
  9745. geometry: geometry,
  9746. patterns: {},
  9747. sortKey: sortKey,
  9748. circleRadius: circleRadius
  9749. };
  9750. bucketFeatures.push(bucketFeature);
  9751. }
  9752. }
  9753. if (circleSortKey) {
  9754. bucketFeatures.sort(function (a, b) {
  9755. // a.sortKey is always a number when in use
  9756. return ((a.sortKey ) ) - ((b.sortKey ) );
  9757. });
  9758. }
  9759. for (var i$1 = 0, list$1 = bucketFeatures; i$1 < list$1.length; i$1 += 1) {
  9760. var bucketFeature$1 = list$1[i$1];
  9761. var ref$1 = bucketFeature$1;
  9762. var geometry$1 = ref$1.geometry;
  9763. var index$1 = ref$1.index;
  9764. var sourceLayerIndex$1 = ref$1.sourceLayerIndex;
  9765. var feature$1 = features[index$1].feature;
  9766. this.addFeature(bucketFeature$1, geometry$1, index$1);
  9767. options.featureIndex.insert(feature$1, geometry$1, index$1, sourceLayerIndex$1, this.index, undefined, ref$1.circleRadius);
  9768. }
  9769. };
  9770. CircleBucket.prototype.update = function update(states, vtLayer, imagePositions) {
  9771. if (!this.stateDependentLayers.length) {
  9772. return;
  9773. }
  9774. this.programConfigurations.updatePaintArrays(states, vtLayer, this.stateDependentLayers, imagePositions);
  9775. };
  9776. CircleBucket.prototype.isEmpty = function isEmpty() {
  9777. return this.layoutVertexArray.length === 0;
  9778. };
  9779. CircleBucket.prototype.uploadPending = function uploadPending() {
  9780. return !this.uploaded || this.programConfigurations.needsUpload;
  9781. };
  9782. CircleBucket.prototype.upload = function upload(context) {
  9783. if (!this.uploaded) {
  9784. this.layoutVertexBuffer = context.createVertexBuffer(this.layoutVertexArray, members);
  9785. this.indexBuffer = context.createIndexBuffer(this.indexArray);
  9786. }
  9787. this.programConfigurations.upload(context);
  9788. this.uploaded = true;
  9789. };
  9790. CircleBucket.prototype.destroy = function destroy() {
  9791. if (!this.layoutVertexBuffer) {
  9792. return;
  9793. }
  9794. this.layoutVertexBuffer.destroy();
  9795. this.indexBuffer.destroy();
  9796. this.programConfigurations.destroy();
  9797. this.segments.destroy();
  9798. };
  9799. CircleBucket.prototype.clear = function clear() {
  9800. if (when.defined(this.layoutVertexArray)) {
  9801. this.layoutVertexArray = null;
  9802. }
  9803. if (when.defined(this.indexArray)) {
  9804. this.indexArray = null;
  9805. }
  9806. };
  9807. CircleBucket.prototype.addFeature = function addFeature(feature, geometry, index) {
  9808. for (var i$1 = 0, list$1 = geometry; i$1 < list$1.length; i$1 += 1) {
  9809. var ring = list$1[i$1];
  9810. for (var i = 0, list = ring; i < list.length; i += 1) {
  9811. var point = list[i];
  9812. var x = point.x;
  9813. var y = point.y;
  9814. // Do not include points that are outside the tile boundaries.
  9815. if (x < 0 || x >= EXTENT || y < 0 || y >= EXTENT) {
  9816. continue;
  9817. }
  9818. // this geometry will be of the Point type, and we'll derive
  9819. // two triangles from it.
  9820. //
  9821. // ┌─────────┐
  9822. // │ 3 2 │
  9823. // │ │
  9824. // │ 0 1 │
  9825. // └─────────┘
  9826. var segment = this.segments.prepareSegment(4, this.layoutVertexArray, this.indexArray, feature.sortKey);
  9827. var index$1 = segment.vertexLength;
  9828. addCircleVertex(this.layoutVertexArray, x, y, -1, -1);
  9829. addCircleVertex(this.layoutVertexArray, x, y, 1, -1);
  9830. addCircleVertex(this.layoutVertexArray, x, y, 1, 1);
  9831. addCircleVertex(this.layoutVertexArray, x, y, -1, 1);
  9832. this.indexArray.emplaceBack(index$1, index$1 + 1, index$1 + 2);
  9833. this.indexArray.emplaceBack(index$1, index$1 + 3, index$1 + 2);
  9834. segment.vertexLength += 4;
  9835. segment.primitiveLength += 2;
  9836. }
  9837. }
  9838. this.programConfigurations.populatePaintArrays(this.layoutVertexArray.length, feature, index, {});
  9839. };
  9840. WebWorkerTransfer.register('CircleBucket', CircleBucket, {omit: ['layers']});
  9841. /**
  9842. * An implementation of `Property` for properties that do not permit data-driven (source or composite) expressions.
  9843. * This restriction allows us to declare statically that the result of possibly evaluating this kind of property
  9844. * is in fact always the scalar type `T`, and can be used without further evaluating the value on a per-feature basis.
  9845. *
  9846. * @private
  9847. */
  9848. var DataConstantProperty = function DataConstantProperty(specification) {
  9849. this.specification = specification;
  9850. };
  9851. DataConstantProperty.prototype.possiblyEvaluate = function possiblyEvaluate(value, parameters) {
  9852. //assert_1(!value.isDataDriven());
  9853. return value.expression.evaluate(parameters);
  9854. };
  9855. DataConstantProperty.prototype.interpolate = function interpolate$1(a, b, t) {
  9856. var interp = (interpolate )[this.specification.type];
  9857. if (interp) {
  9858. return interp(a, b, t);
  9859. } else {
  9860. return a;
  9861. }
  9862. };
  9863. WebWorkerTransfer.register('DataConstantProperty', DataConstantProperty);
  9864. /**
  9865. * An implementation of `Property` for properties that permit data-driven (source or composite) expressions.
  9866. * The result of possibly evaluating this kind of property is `PossiblyEvaluatedPropertyValue<T>`; obtaining
  9867. * a scalar value `T` requires further evaluation on a per-feature basis.
  9868. *
  9869. * @private
  9870. */
  9871. var DataDrivenProperty = function DataDrivenProperty(specification, overrides) {
  9872. this.specification = specification;
  9873. this.overrides = overrides;
  9874. };
  9875. DataDrivenProperty.prototype.possiblyEvaluate = function possiblyEvaluate(value, parameters, availableImages) {
  9876. if (value.expression.kind === 'constant' || value.expression.kind === 'camera') {
  9877. return new PossiblyEvaluatedPropertyValue$1(this, {kind: 'constant', value: value.expression.evaluate(parameters, (null ), {}, availableImages)}, parameters);
  9878. } else {
  9879. return new PossiblyEvaluatedPropertyValue$1(this, value.expression, parameters);
  9880. }
  9881. };
  9882. DataDrivenProperty.prototype.interpolate = function interpolate$2(a, b, t) {
  9883. // If either possibly-evaluated value is non-constant, give up: we aren't able to interpolate data-driven values.
  9884. if (a.value.kind !== 'constant' || b.value.kind !== 'constant') {
  9885. return a;
  9886. }
  9887. // Special case hack solely for fill-outline-color. The undefined value is subsequently handled in
  9888. // FillStyleLayer#recalculate, which sets fill-outline-color to the fill-color value if the former
  9889. // is a PossiblyEvaluatedPropertyValue containing a constant undefined value. In addition to the
  9890. // return value here, the other source of a PossiblyEvaluatedPropertyValue containing a constant
  9891. // undefined value is the "default value" for fill-outline-color held in
  9892. // `Properties#defaultPossiblyEvaluatedValues`, which serves as the prototype of
  9893. // `PossiblyEvaluated#_values`.
  9894. if (a.value.value === undefined || b.value.value === undefined) {
  9895. return new PossiblyEvaluatedPropertyValue$1(this, {kind: 'constant', value: (undefined )}, a.parameters);
  9896. }
  9897. var interp = (interpolate )[this.specification.type];
  9898. if (interp) {
  9899. return new PossiblyEvaluatedPropertyValue$1(this, {kind: 'constant', value: interp(a.value.value, b.value.value, t)}, a.parameters);
  9900. } else {
  9901. return a;
  9902. }
  9903. };
  9904. DataDrivenProperty.prototype.evaluate = function evaluate(value, parameters, feature, featureState, availableImages) {
  9905. if (value.kind === 'constant') {
  9906. return value.value;
  9907. } else {
  9908. return value.evaluate(parameters, feature, featureState, availableImages);
  9909. }
  9910. };
  9911. WebWorkerTransfer.register('DataDrivenProperty', DataDrivenProperty);
  9912. var PropertyValue = function PropertyValue(property, value) {
  9913. this.property = property;
  9914. this.value = value;
  9915. this.expression = Expression.normalizePropertyExpression(value === undefined ? property.specification.default : value, property.specification);
  9916. };
  9917. PropertyValue.prototype.isDataDriven = function isDataDriven() {
  9918. return this.expression.kind === 'source' || this.expression.kind === 'composite';
  9919. };
  9920. PropertyValue.prototype.possiblyEvaluate = function possiblyEvaluate(parameters, availableImages) {
  9921. return this.property.possiblyEvaluate(this, parameters, availableImages);
  9922. };
  9923. /**
  9924. * Given a value `t` that varies between 0 and 1, return
  9925. * an interpolation function that eases between 0 and 1 in a pleasing
  9926. * cubic in-out fashion.
  9927. *
  9928. * @private
  9929. */
  9930. function easeCubicInOut(t ) {
  9931. if (t <= 0) { return 0; }
  9932. if (t >= 1) { return 1; }
  9933. var t2 = t * t,
  9934. t3 = t2 * t;
  9935. return 4 * (t < 0.5 ? t3 : 3 * (t - t2) + t3 - 0.75);
  9936. }
  9937. /**
  9938. * `TransitioningPropertyValue` implements the first of two intermediate steps in the evaluation chain of a paint
  9939. * property value. In this step, transitions between old and new values are handled: as long as the transition is in
  9940. * progress, `TransitioningPropertyValue` maintains a reference to the prior value, and interpolates between it and
  9941. * the new value based on the current time and the configured transition duration and delay. The product is the next
  9942. * step in the evaluation chain: the "possibly evaluated" result type `R`. See below for more on this concept.
  9943. *
  9944. * @private
  9945. */
  9946. var TransitioningPropertyValue = function TransitioningPropertyValue(property, value, prior, transition, now) {
  9947. this.property = property;
  9948. this.value = value;
  9949. this.begin = now + transition.delay || 0;
  9950. this.end = this.begin + transition.duration || 0;
  9951. if (property.specification.transition && (transition.delay || transition.duration)) {
  9952. this.prior = prior;
  9953. }
  9954. };
  9955. TransitioningPropertyValue.prototype.possiblyEvaluate = function possiblyEvaluate(parameters, availableImages) {
  9956. var now = parameters.now || 0;
  9957. var finalValue = this.value.possiblyEvaluate(parameters, availableImages);
  9958. var prior = this.prior;
  9959. if (!prior) {
  9960. // No prior value.
  9961. return finalValue;
  9962. } else if (now > this.end) {
  9963. // Transition from prior value is now complete.
  9964. this.prior = null;
  9965. return finalValue;
  9966. } else if (this.value.isDataDriven()) {
  9967. // Transitions to data-driven properties are not supported.
  9968. // We snap immediately to the data-driven value so that, when we perform layout,
  9969. // we see the data-driven function and can use it to populate vertex buffers.
  9970. this.prior = null;
  9971. return finalValue;
  9972. } else if (now < this.begin) {
  9973. // Transition hasn't started yet.
  9974. return prior.possiblyEvaluate(parameters, availableImages);
  9975. } else {
  9976. // Interpolate between recursively-calculated prior value and final.
  9977. var t = (now - this.begin) / (this.end - this.begin);
  9978. return this.property.interpolate(prior.possiblyEvaluate(parameters, availableImages), finalValue, easeCubicInOut(t));
  9979. }
  9980. };
  9981. /**
  9982. * Paint properties are _transitionable_: they can change in a fluid manner, interpolating or cross-fading between
  9983. * old and new value. The duration of the transition, and the delay before it begins, is configurable.
  9984. *
  9985. * `TransitionablePropertyValue` is a compositional class that stores both the property value and that transition
  9986. * configuration.
  9987. *
  9988. * A `TransitionablePropertyValue` can calculate the next step in the evaluation chain for paint property values:
  9989. * `TransitioningPropertyValue`.
  9990. *
  9991. * @private
  9992. */
  9993. var TransitionablePropertyValue = function TransitionablePropertyValue(property) {
  9994. this.property = property;
  9995. this.value = new PropertyValue(property, undefined);
  9996. };
  9997. TransitionablePropertyValue.prototype.transitioned = function transitioned(parameters, prior) {
  9998. return new TransitioningPropertyValue(this.property, this.value, prior, // eslint-disable-line no-use-before-define
  9999. Util.extend({}, parameters.transition, this.transition), parameters.now);
  10000. };
  10001. TransitionablePropertyValue.prototype.untransitioned = function untransitioned() {
  10002. return new TransitioningPropertyValue(this.property, this.value, null, {}, 0); // eslint-disable-line no-use-before-define
  10003. };
  10004. /**
  10005. * A helper type: given an object type `Properties` whose values are each of type `Property<T, R>`, it calculates
  10006. * an object type with the same keys, and values of type `R`.
  10007. *
  10008. * For properties that don't allow data-driven values, `R` is a scalar type such as `number`, `string`, or `Color`.
  10009. * For data-driven properties, it is `PossiblyEvaluatedPropertyValue`. Critically, the type definitions are set up
  10010. * in a way that allows flow to know which of these two cases applies for any given property name, and if you attempt
  10011. * to use a `PossiblyEvaluatedPropertyValue` as if it was a scalar, or vice versa, you will get a type error. (However,
  10012. * 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
  10013. * as `layer.paint.get('foo-opacity') === 0`, if `foo-opacity` is data-driven, than the left-hand side is of type
  10014. * `PossiblyEvaluatedPropertyValue<number>`, but flow will not complain about comparing this to a number using `===`.
  10015. * See https://github.com/facebook/flow/issues/2359.)
  10016. *
  10017. * There's also a third, special case possiblity for `R`: for cross-faded properties, it's `?CrossFaded<T>`.
  10018. *
  10019. * @private
  10020. */
  10021. /**
  10022. * `Properties` holds objects containing default values for the layout or paint property set of a given
  10023. * layer type. These objects are immutable, and they are used as the prototypes for the `_values` members of
  10024. * `Transitionable`, `Transitioning`, `Layout`, and `PossiblyEvaluated`. This allows these classes to avoid
  10025. * doing work in the common case where a property has no explicit value set and should be considered to take
  10026. * on the default value: using `for (const property of Object.keys(this._values))`, they can iterate over
  10027. * only the _own_ properties of `_values`, skipping repeated calculation of transitions and possible/final
  10028. * evaluations for defaults, the result of which will always be the same.
  10029. *
  10030. * @private
  10031. */
  10032. var Properties = function Properties(properties) {
  10033. this.properties = properties;
  10034. this.defaultPropertyValues = ({} );
  10035. this.defaultTransitionablePropertyValues = ({} );
  10036. this.defaultTransitioningPropertyValues = ({} );
  10037. this.defaultPossiblyEvaluatedValues = ({} );
  10038. this.overridableProperties = ([] );
  10039. for (var property in properties) {
  10040. var prop = properties[property];
  10041. if (prop.specification.overridable) {
  10042. this.overridableProperties.push(property);
  10043. }
  10044. var defaultPropertyValue = this.defaultPropertyValues[property] =
  10045. new PropertyValue(prop, undefined);
  10046. var defaultTransitionablePropertyValue = this.defaultTransitionablePropertyValues[property] =
  10047. new TransitionablePropertyValue(prop);
  10048. this.defaultTransitioningPropertyValues[property] =
  10049. defaultTransitionablePropertyValue.untransitioned();
  10050. this.defaultPossiblyEvaluatedValues[property] =
  10051. defaultPropertyValue.possiblyEvaluate(({} ));
  10052. }
  10053. };
  10054. function QueryUtils() {
  10055. }
  10056. QueryUtils.getMaximumPaintValue = function (property, layer, bucket) {
  10057. var value = ((layer.paint).get(property)).value;
  10058. if (value.kind === 'constant') {
  10059. return value.value;
  10060. } else {
  10061. var binders = bucket.programConfigurations.get(layer.id).binders;
  10062. return binders[property].maxValue;
  10063. }
  10064. };
  10065. QueryUtils.translateDistance = function (translate) {
  10066. return Math.sqrt(translate[0] * translate[0] + translate[1] * translate[1]);
  10067. };
  10068. QueryUtils.translate = function (queryGeometry, translate, translateAnchor, bearing, pixelsToTileUnits) {
  10069. if (!translate[0] && !translate[1]) {
  10070. return queryGeometry;
  10071. }
  10072. var pt = Point.convert(translate)._mult(pixelsToTileUnits);
  10073. if (translateAnchor === "viewport") {
  10074. pt._rotate(-bearing);
  10075. }
  10076. var translated = [];
  10077. for (var i = 0; i < queryGeometry.length; i++) {
  10078. var point = queryGeometry[i];
  10079. translated.push(point.sub(pt));
  10080. }
  10081. return translated;
  10082. };
  10083. /**
  10084. * `PossiblyEvaluated` stores a map of all (property name, `R`) pairs for paint or layout properties of a
  10085. * given layer type.
  10086. * @private
  10087. */
  10088. var PossiblyEvaluated = function PossiblyEvaluated(properties) {
  10089. this._properties = properties;
  10090. this._values = (Object.create(properties.defaultPossiblyEvaluatedValues) );
  10091. };
  10092. PossiblyEvaluated.prototype.get = function get(name) {
  10093. return this._values[name];
  10094. };
  10095. /**
  10096. * Because layout properties are not transitionable, they have a simpler representation and evaluation chain than
  10097. * paint properties: `PropertyValue`s are possibly evaluated, producing possibly evaluated values, which are then
  10098. * fully evaluated.
  10099. *
  10100. * `Layout` stores a map of all (property name, `PropertyValue`) pairs for layout properties of a
  10101. * given layer type. It can calculate the possibly-evaluated values for all of them at once, producing a
  10102. * `PossiblyEvaluated` instance for the same set of properties.
  10103. *
  10104. * @private
  10105. */
  10106. var Layout = function Layout(properties ) {
  10107. this._properties = properties;
  10108. this._values = (Object.create(properties.defaultPropertyValues) );
  10109. };
  10110. Layout.prototype.getValue = function getValue (name ) {
  10111. return Util.clone(this._values[name].value);
  10112. };
  10113. Layout.prototype.setValue = function setValue (name , value ) {
  10114. this._values[name] = new PropertyValue(this._values[name].property, value === null ? undefined : Util.clone(value));
  10115. };
  10116. Layout.prototype.serialize = function serialize () {
  10117. var result = {};
  10118. for (var i = 0, list = Object.keys(this._values); i < list.length; i += 1) {
  10119. var property = list[i];
  10120. var value = this.getValue(property);
  10121. if (value !== undefined) {
  10122. result[property] = value;
  10123. }
  10124. }
  10125. return result;
  10126. };
  10127. Layout.prototype.possiblyEvaluate = function possiblyEvaluate (parameters , availableImages ) {
  10128. var result = new PossiblyEvaluated(this._properties); // eslint-disable-line no-use-before-define
  10129. for (var i = 0, list = Object.keys(this._values); i < list.length; i += 1) {
  10130. var property = list[i];
  10131. result._values[property] = this._values[property].possiblyEvaluate(parameters, availableImages);
  10132. }
  10133. return result;
  10134. };
  10135. // ------- Transitioning -------
  10136. /**
  10137. * A helper type: given an object type `Properties` whose values are each of type `Property<T, R>`, it calculates
  10138. * an object type with the same keys and values of type `TransitioningPropertyValue<T, R>`.
  10139. *
  10140. * @private
  10141. */
  10142. /**
  10143. * `Transitioning` stores a map of all (property name, `TransitioningPropertyValue`) pairs for paint properties of a
  10144. * given layer type. It can calculate the possibly-evaluated values for all of them at once, producing a
  10145. * `PossiblyEvaluated` instance for the same set of properties.
  10146. *
  10147. * @private
  10148. */
  10149. var Transitioning = function Transitioning(properties) {
  10150. this._properties = properties;
  10151. this._values = (Object.create(properties.defaultTransitioningPropertyValues) );
  10152. };
  10153. Transitioning.prototype.possiblyEvaluate = function possiblyEvaluate(parameters, availableImages) {
  10154. var result = new PossiblyEvaluated(this._properties); // eslint-disable-line no-use-before-define
  10155. for (var i = 0, list = Object.keys(this._values); i < list.length; i += 1) {
  10156. var property = list[i];
  10157. result._values[property] = this._values[property].possiblyEvaluate(parameters, availableImages);
  10158. }
  10159. return result;
  10160. };
  10161. Transitioning.prototype.hasTransition = function hasTransition() {
  10162. for (var i = 0, list = Object.keys(this._values); i < list.length; i += 1) {
  10163. var property = list[i];
  10164. if (this._values[property].prior) {
  10165. return true;
  10166. }
  10167. }
  10168. return false;
  10169. };
  10170. /**
  10171. * A helper type: given an object type `Properties` whose values are each of type `Property<T, R>`, it calculates
  10172. * an object type with the same keys and values of type `TransitionablePropertyValue<T, R>`.
  10173. *
  10174. * @private
  10175. */
  10176. /**
  10177. * `Transitionable` stores a map of all (property name, `TransitionablePropertyValue`) pairs for paint properties of a
  10178. * given layer type. It can calculate the `TransitioningPropertyValue`s for all of them at once, producing a
  10179. * `Transitioning` instance for the same set of properties.
  10180. *
  10181. * @private
  10182. */
  10183. var Transitionable = function Transitionable(properties) {
  10184. this._properties = properties;
  10185. this._values = (Object.create(properties.defaultTransitionablePropertyValues) );
  10186. };
  10187. Transitionable.prototype.getValue = function getValue(name) {
  10188. return Util.clone(this._values[name].value.value);
  10189. };
  10190. Transitionable.prototype.setValue = function setValue(name, value) {
  10191. if (!this._values.hasOwnProperty(name)) {
  10192. this._values[name] = new TransitionablePropertyValue(this._values[name].property);
  10193. }
  10194. // Note that we do not _remove_ an own property in the case where a value is being reset
  10195. // to the default: the transition might still be non-default.
  10196. this._values[name].value = new PropertyValue(this._values[name].property, value === null ? undefined : Util.clone(value));
  10197. };
  10198. Transitionable.prototype.getTransition = function getTransition(name) {
  10199. return Util.clone(this._values[name].transition);
  10200. };
  10201. Transitionable.prototype.setTransition = function setTransition(name, value) {
  10202. if (!this._values.hasOwnProperty(name)) {
  10203. this._values[name] = new TransitionablePropertyValue(this._values[name].property);
  10204. }
  10205. this._values[name].transition = Util.clone(value) || undefined;
  10206. };
  10207. Transitionable.prototype.serialize = function serialize() {
  10208. var result = {};
  10209. for (var i = 0, list = Object.keys(this._values); i < list.length; i += 1) {
  10210. var property = list[i];
  10211. var value = this.getValue(property);
  10212. if (value !== undefined) {
  10213. result[property] = value;
  10214. }
  10215. var transition = this.getTransition(property);
  10216. if (transition !== undefined) {
  10217. result[(property + "-transition")] = transition;
  10218. }
  10219. }
  10220. return result;
  10221. };
  10222. Transitionable.prototype.transitioned = function transitioned(parameters, prior) {
  10223. var result = new Transitioning(this._properties); // eslint-disable-line no-use-before-define
  10224. for (var i = 0, list = Object.keys(this._values); i < list.length; i += 1) {
  10225. var property = list[i];
  10226. result._values[property] = this._values[property].transitioned(parameters, prior._values[property]);
  10227. }
  10228. return result;
  10229. };
  10230. Transitionable.prototype.untransitioned = function untransitioned() {
  10231. var result = new Transitioning(this._properties); // eslint-disable-line no-use-before-define
  10232. for (var i = 0, list = Object.keys(this._values); i < list.length; i += 1) {
  10233. var property = list[i];
  10234. result._values[property] = this._values[property].untransitioned();
  10235. }
  10236. return result;
  10237. };
  10238. var TRANSITION_SUFFIX = '-transition';
  10239. function endsWith(string, suffix) {
  10240. return string.indexOf(suffix, string.length - suffix.length) !== -1;
  10241. }
  10242. function StyleLayer(layer, properties) {
  10243. //Evented.call(this);
  10244. this.id = layer.id;
  10245. this.type = layer.type;
  10246. // this._featureFilter = function () {
  10247. // return true;
  10248. // };
  10249. if (layer.type === 'custom') {
  10250. return;
  10251. }
  10252. layer = ((layer));
  10253. this.metadata = layer.metadata;
  10254. this.minzoom = layer.minzoom;
  10255. this.maxzoom = layer.maxzoom;
  10256. if (layer.type !== 'background') {
  10257. this.source = layer.source;
  10258. this.sourceLayer = layer['source-layer'];
  10259. this.filter = layer.filter;
  10260. }
  10261. if (properties.layout) {
  10262. this._unevaluatedLayout = new Layout(properties.layout);
  10263. }
  10264. if (properties.paint) {
  10265. this._transitionablePaint = new Transitionable(properties.paint);
  10266. for (var property in layer.paint) {
  10267. this.setPaintProperty(property, layer.paint[property], {validate: false});
  10268. }
  10269. for (var property$1 in layer.layout) {
  10270. this.setLayoutProperty(property$1, layer.layout[property$1], {validate: false});
  10271. }
  10272. this._transitioningPaint = this._transitionablePaint.untransitioned();
  10273. }
  10274. }
  10275. // if (Evented) StyleLayer.__proto__ = Evented;
  10276. // StyleLayer.prototype = Object.create(Evented && Evented.prototype);
  10277. // StyleLayer.prototype.constructor = StyleLayer;
  10278. StyleLayer.prototype.getCrossfadeParameters = function getCrossfadeParameters() {
  10279. return this._crossfadeParameters;
  10280. };
  10281. StyleLayer.prototype.getLayoutProperty = function getLayoutProperty(name) {
  10282. if (name === 'visibility') {
  10283. return this.visibility;
  10284. }
  10285. return this._unevaluatedLayout.getValue(name);
  10286. };
  10287. StyleLayer.prototype.setLayoutProperty = function setLayoutProperty(name, value, options) {
  10288. if (value !== null && value !== undefined) {
  10289. var key = "layers." + (this.id) + ".layout." + name;
  10290. // if (this._validate(validateLayoutProperty$1, key, name, value, options)) {
  10291. // return;
  10292. // }
  10293. }
  10294. if (name === 'visibility') {
  10295. this.visibility = value;
  10296. return;
  10297. }
  10298. this._unevaluatedLayout.setValue(name, value);
  10299. };
  10300. StyleLayer.prototype.getPaintProperty = function getPaintProperty(name) {
  10301. if (endsWith(name, TRANSITION_SUFFIX)) {
  10302. return this._transitionablePaint.getTransition(name.slice(0, -TRANSITION_SUFFIX.length));
  10303. } else {
  10304. return this._transitionablePaint.getValue(name);
  10305. }
  10306. };
  10307. StyleLayer.prototype.setPaintProperty = function setPaintProperty(name, value, options) {
  10308. if (value !== null && value !== undefined) {
  10309. var key = "layers." + (this.id) + ".paint." + name;
  10310. // if (this._validate(validatePaintProperty$1, key, name, value, options)) {
  10311. // return false;
  10312. // }
  10313. }
  10314. if (endsWith(name, TRANSITION_SUFFIX)) {
  10315. this._transitionablePaint.setTransition(name.slice(0, -TRANSITION_SUFFIX.length), (value ) || undefined);
  10316. return false;
  10317. } else {
  10318. var transitionable = this._transitionablePaint._values[name];
  10319. var isCrossFadedProperty = transitionable.property.specification["property-type"] === 'cross-faded-data-driven';
  10320. var wasDataDriven = transitionable.value.isDataDriven();
  10321. var oldValue = transitionable.value;
  10322. this._transitionablePaint.setValue(name, value);
  10323. this._handleSpecialPaintPropertyUpdate(name);
  10324. var newValue = this._transitionablePaint._values[name].value;
  10325. var isDataDriven = newValue.isDataDriven();
  10326. // if a cross-faded value is changed, we need to make sure the new icons get added to each tile's iconAtlas
  10327. // so a call to _updateLayer is necessary, and we return true from this function so it gets called in
  10328. // Style#setPaintProperty
  10329. return isDataDriven || wasDataDriven || isCrossFadedProperty || this._handleOverridablePaintPropertyUpdate(name, oldValue, newValue);
  10330. }
  10331. };
  10332. StyleLayer.prototype._handleSpecialPaintPropertyUpdate = function _handleSpecialPaintPropertyUpdate(_) {
  10333. // No-op; can be overridden by derived classes.
  10334. };
  10335. // eslint-disable-next-line no-unused-vars
  10336. StyleLayer.prototype._handleOverridablePaintPropertyUpdate = function _handleOverridablePaintPropertyUpdate(name, oldValue, newValue) {
  10337. // No-op; can be overridden by derived classes.
  10338. return false;
  10339. };
  10340. StyleLayer.prototype.isHidden = function isHidden(zoom) {
  10341. if (this.minzoom && zoom < this.minzoom) {
  10342. return true;
  10343. }
  10344. if (this.maxzoom && zoom >= this.maxzoom) {
  10345. return true;
  10346. }
  10347. return this.visibility === 'none';
  10348. };
  10349. StyleLayer.prototype.updateTransitions = function updateTransitions(parameters) {
  10350. this._transitioningPaint = this._transitionablePaint.transitioned(parameters, this._transitioningPaint);
  10351. };
  10352. StyleLayer.prototype.hasTransition = function hasTransition() {
  10353. return this._transitioningPaint.hasTransition();
  10354. };
  10355. StyleLayer.prototype.recalculate = function recalculate(parameters, availableImages) {
  10356. if (parameters.getCrossfadeParameters) {
  10357. this._crossfadeParameters = parameters.getCrossfadeParameters();
  10358. }
  10359. if (this._unevaluatedLayout) {
  10360. (this).layout = this._unevaluatedLayout.possiblyEvaluate(parameters, availableImages);
  10361. }
  10362. (this).paint = this._transitioningPaint.possiblyEvaluate(parameters, availableImages);
  10363. };
  10364. StyleLayer.prototype.serialize = function serialize() {
  10365. var output = {
  10366. 'id': this.id,
  10367. 'type': this.type,
  10368. 'source': this.source,
  10369. 'source-layer': this.sourceLayer,
  10370. 'metadata': this.metadata,
  10371. 'minzoom': this.minzoom,
  10372. 'maxzoom': this.maxzoom,
  10373. 'filter': this.filter,
  10374. 'layout': this._unevaluatedLayout && this._unevaluatedLayout.serialize(),
  10375. 'paint': this._transitionablePaint && this._transitionablePaint.serialize()
  10376. };
  10377. if (this.visibility) {
  10378. output.layout = output.layout || {};
  10379. output.layout.visibility = this.visibility;
  10380. }
  10381. return Util.filterObject(output, function (value, key) {
  10382. return value !== undefined && !(key === 'layout' && !Object.keys(value).length) && !(key === 'paint' && !Object.keys(value).length);
  10383. });
  10384. };
  10385. StyleLayer.prototype._validate = function _validate(validate, key, name, value, options) {
  10386. return true;
  10387. // if (options === void 0) options = {};
  10388. //
  10389. // if (options && options.validate === false) {
  10390. // return false;
  10391. // }
  10392. // return emitValidationErrors(this, validate.call(validateStyle, {
  10393. // key: key,
  10394. // layerType: this.type,
  10395. // objectKey: name,
  10396. // value: value,
  10397. // styleSpec: spec,
  10398. // // Workaround for https://github.com/mapbox/mapbox-gl-js/issues/2407
  10399. // style: {glyphs: true, sprite: true}
  10400. // }));
  10401. };
  10402. StyleLayer.prototype.is3D = function is3D() {
  10403. return false;
  10404. };
  10405. StyleLayer.prototype.isTileClipped = function isTileClipped() {
  10406. return false;
  10407. };
  10408. StyleLayer.prototype.hasOffscreenPass = function hasOffscreenPass() {
  10409. return false;
  10410. };
  10411. StyleLayer.prototype.resize = function resize() {
  10412. // noop
  10413. };
  10414. StyleLayer.prototype.isStateDependent = function isStateDependent() {
  10415. return true;
  10416. // for (var property in (this ).paint._values) {
  10417. // var value = (this ).paint.get(property);
  10418. // if (!(value instanceof PossiblyEvaluatedPropertyValue) || !supportsPropertyExpression(value.property.specification)) {
  10419. // continue;
  10420. // }
  10421. //
  10422. // if ((value.value.kind === 'source' || value.value.kind === 'composite') &&
  10423. // value.value.isStateDependent) {
  10424. // return true;
  10425. // }
  10426. // }
  10427. // return false;
  10428. };
  10429. var $version = 8;
  10430. var $root = {
  10431. version: {
  10432. required: true,
  10433. type: "enum",
  10434. values: [
  10435. 8
  10436. ]
  10437. },
  10438. name: {
  10439. type: "string"
  10440. },
  10441. metadata: {
  10442. type: "*"
  10443. },
  10444. center: {
  10445. type: "array",
  10446. value: "number"
  10447. },
  10448. zoom: {
  10449. type: "number"
  10450. },
  10451. bearing: {
  10452. type: "number",
  10453. "default": 0,
  10454. period: 360,
  10455. units: "degrees"
  10456. },
  10457. pitch: {
  10458. type: "number",
  10459. "default": 0,
  10460. units: "degrees"
  10461. },
  10462. light: {
  10463. type: "light"
  10464. },
  10465. sources: {
  10466. required: true,
  10467. type: "sources"
  10468. },
  10469. sprite: {
  10470. type: "string"
  10471. },
  10472. glyphs: {
  10473. type: "string"
  10474. },
  10475. transition: {
  10476. type: "transition"
  10477. },
  10478. layers: {
  10479. required: true,
  10480. type: "array",
  10481. value: "layer"
  10482. }
  10483. };
  10484. var sources = {
  10485. "*": {
  10486. type: "source"
  10487. }
  10488. };
  10489. var source = [
  10490. "source_vector",
  10491. "source_raster",
  10492. "source_raster_dem",
  10493. "source_geojson",
  10494. "source_video",
  10495. "source_image"
  10496. ];
  10497. var source_vector = {
  10498. type: {
  10499. required: true,
  10500. type: "enum",
  10501. values: {
  10502. vector: {
  10503. }
  10504. }
  10505. },
  10506. url: {
  10507. type: "string"
  10508. },
  10509. tiles: {
  10510. type: "array",
  10511. value: "string"
  10512. },
  10513. bounds: {
  10514. type: "array",
  10515. value: "number",
  10516. length: 4,
  10517. "default": [
  10518. -180,
  10519. -85.051129,
  10520. 180,
  10521. 85.051129
  10522. ]
  10523. },
  10524. scheme: {
  10525. type: "enum",
  10526. values: {
  10527. xyz: {
  10528. },
  10529. tms: {
  10530. }
  10531. },
  10532. "default": "xyz"
  10533. },
  10534. minzoom: {
  10535. type: "number",
  10536. "default": 0
  10537. },
  10538. maxzoom: {
  10539. type: "number",
  10540. "default": 22
  10541. },
  10542. attribution: {
  10543. type: "string"
  10544. },
  10545. "*": {
  10546. type: "*"
  10547. }
  10548. };
  10549. var source_raster = {
  10550. type: {
  10551. required: true,
  10552. type: "enum",
  10553. values: {
  10554. raster: {
  10555. }
  10556. }
  10557. },
  10558. url: {
  10559. type: "string"
  10560. },
  10561. tiles: {
  10562. type: "array",
  10563. value: "string"
  10564. },
  10565. bounds: {
  10566. type: "array",
  10567. value: "number",
  10568. length: 4,
  10569. "default": [
  10570. -180,
  10571. -85.051129,
  10572. 180,
  10573. 85.051129
  10574. ]
  10575. },
  10576. minzoom: {
  10577. type: "number",
  10578. "default": 0
  10579. },
  10580. maxzoom: {
  10581. type: "number",
  10582. "default": 22
  10583. },
  10584. tileSize: {
  10585. type: "number",
  10586. "default": 512,
  10587. units: "pixels"
  10588. },
  10589. scheme: {
  10590. type: "enum",
  10591. values: {
  10592. xyz: {
  10593. },
  10594. tms: {
  10595. }
  10596. },
  10597. "default": "xyz"
  10598. },
  10599. attribution: {
  10600. type: "string"
  10601. },
  10602. "*": {
  10603. type: "*"
  10604. }
  10605. };
  10606. var source_raster_dem = {
  10607. type: {
  10608. required: true,
  10609. type: "enum",
  10610. values: {
  10611. "raster-dem": {
  10612. }
  10613. }
  10614. },
  10615. url: {
  10616. type: "string"
  10617. },
  10618. tiles: {
  10619. type: "array",
  10620. value: "string"
  10621. },
  10622. bounds: {
  10623. type: "array",
  10624. value: "number",
  10625. length: 4,
  10626. "default": [
  10627. -180,
  10628. -85.051129,
  10629. 180,
  10630. 85.051129
  10631. ]
  10632. },
  10633. minzoom: {
  10634. type: "number",
  10635. "default": 0
  10636. },
  10637. maxzoom: {
  10638. type: "number",
  10639. "default": 22
  10640. },
  10641. tileSize: {
  10642. type: "number",
  10643. "default": 512,
  10644. units: "pixels"
  10645. },
  10646. attribution: {
  10647. type: "string"
  10648. },
  10649. encoding: {
  10650. type: "enum",
  10651. values: {
  10652. terrarium: {
  10653. },
  10654. mapbox: {
  10655. }
  10656. },
  10657. "default": "mapbox"
  10658. },
  10659. "*": {
  10660. type: "*"
  10661. }
  10662. };
  10663. var source_geojson = {
  10664. type: {
  10665. required: true,
  10666. type: "enum",
  10667. values: {
  10668. geojson: {
  10669. }
  10670. }
  10671. },
  10672. data: {
  10673. type: "*"
  10674. },
  10675. maxzoom: {
  10676. type: "number",
  10677. "default": 18
  10678. },
  10679. attribution: {
  10680. type: "string"
  10681. },
  10682. buffer: {
  10683. type: "number",
  10684. "default": 128,
  10685. maximum: 512,
  10686. minimum: 0
  10687. },
  10688. tolerance: {
  10689. type: "number",
  10690. "default": 0.375
  10691. },
  10692. cluster: {
  10693. type: "boolean",
  10694. "default": false
  10695. },
  10696. clusterRadius: {
  10697. type: "number",
  10698. "default": 50,
  10699. minimum: 0
  10700. },
  10701. clusterMaxZoom: {
  10702. type: "number"
  10703. },
  10704. clusterProperties: {
  10705. type: "*"
  10706. },
  10707. lineMetrics: {
  10708. type: "boolean",
  10709. "default": false
  10710. },
  10711. generateId: {
  10712. type: "boolean",
  10713. "default": false
  10714. }
  10715. };
  10716. var source_video = {
  10717. type: {
  10718. required: true,
  10719. type: "enum",
  10720. values: {
  10721. video: {
  10722. }
  10723. }
  10724. },
  10725. urls: {
  10726. required: true,
  10727. type: "array",
  10728. value: "string"
  10729. },
  10730. coordinates: {
  10731. required: true,
  10732. type: "array",
  10733. length: 4,
  10734. value: {
  10735. type: "array",
  10736. length: 2,
  10737. value: "number"
  10738. }
  10739. }
  10740. };
  10741. var source_image = {
  10742. type: {
  10743. required: true,
  10744. type: "enum",
  10745. values: {
  10746. image: {
  10747. }
  10748. }
  10749. },
  10750. url: {
  10751. required: true,
  10752. type: "string"
  10753. },
  10754. coordinates: {
  10755. required: true,
  10756. type: "array",
  10757. length: 4,
  10758. value: {
  10759. type: "array",
  10760. length: 2,
  10761. value: "number"
  10762. }
  10763. }
  10764. };
  10765. var layer = {
  10766. id: {
  10767. type: "string",
  10768. required: true
  10769. },
  10770. type: {
  10771. type: "enum",
  10772. values: {
  10773. fill: {
  10774. },
  10775. line: {
  10776. },
  10777. symbol: {
  10778. },
  10779. circle: {
  10780. },
  10781. heatmap: {
  10782. },
  10783. "fill-extrusion": {
  10784. },
  10785. raster: {
  10786. },
  10787. hillshade: {
  10788. },
  10789. background: {
  10790. }
  10791. },
  10792. required: true
  10793. },
  10794. metadata: {
  10795. type: "*"
  10796. },
  10797. source: {
  10798. type: "string"
  10799. },
  10800. "source-layer": {
  10801. type: "string"
  10802. },
  10803. minzoom: {
  10804. type: "number",
  10805. minimum: 0,
  10806. maximum: 24
  10807. },
  10808. maxzoom: {
  10809. type: "number",
  10810. minimum: 0,
  10811. maximum: 24
  10812. },
  10813. filter: {
  10814. type: "filter"
  10815. },
  10816. layout: {
  10817. type: "layout"
  10818. },
  10819. paint: {
  10820. type: "paint"
  10821. }
  10822. };
  10823. var layout = [
  10824. "layout_fill",
  10825. "layout_line",
  10826. "layout_circle",
  10827. "layout_heatmap",
  10828. "layout_fill-extrusion",
  10829. "layout_symbol",
  10830. "layout_raster",
  10831. "layout_hillshade",
  10832. "layout_background"
  10833. ];
  10834. var layout_background = {
  10835. visibility: {
  10836. type: "enum",
  10837. values: {
  10838. visible: {
  10839. },
  10840. none: {
  10841. }
  10842. },
  10843. "default": "visible",
  10844. "property-type": "constant"
  10845. }
  10846. };
  10847. var layout_fill = {
  10848. "fill-sort-key": {
  10849. type: "number",
  10850. expression: {
  10851. interpolated: false,
  10852. parameters: [
  10853. "zoom",
  10854. "feature"
  10855. ]
  10856. },
  10857. "property-type": "data-driven"
  10858. },
  10859. visibility: {
  10860. type: "enum",
  10861. values: {
  10862. visible: {
  10863. },
  10864. none: {
  10865. }
  10866. },
  10867. "default": "visible",
  10868. "property-type": "constant"
  10869. }
  10870. };
  10871. var layout_circle = {
  10872. "circle-sort-key": {
  10873. type: "number",
  10874. expression: {
  10875. interpolated: false,
  10876. parameters: [
  10877. "zoom",
  10878. "feature"
  10879. ]
  10880. },
  10881. "property-type": "data-driven"
  10882. },
  10883. visibility: {
  10884. type: "enum",
  10885. values: {
  10886. visible: {
  10887. },
  10888. none: {
  10889. }
  10890. },
  10891. "default": "visible",
  10892. "property-type": "constant"
  10893. }
  10894. };
  10895. var layout_heatmap = {
  10896. visibility: {
  10897. type: "enum",
  10898. values: {
  10899. visible: {
  10900. },
  10901. none: {
  10902. }
  10903. },
  10904. "default": "visible",
  10905. "property-type": "constant"
  10906. }
  10907. };
  10908. var layout_line = {
  10909. "line-cap": {
  10910. type: "enum",
  10911. values: {
  10912. butt: {
  10913. },
  10914. round: {
  10915. },
  10916. square: {
  10917. }
  10918. },
  10919. "default": "butt",
  10920. expression: {
  10921. interpolated: false,
  10922. parameters: [
  10923. "zoom"
  10924. ]
  10925. },
  10926. "property-type": "data-constant"
  10927. },
  10928. "line-join": {
  10929. type: "enum",
  10930. values: {
  10931. bevel: {
  10932. },
  10933. round: {
  10934. },
  10935. miter: {
  10936. }
  10937. },
  10938. "default": "miter",
  10939. expression: {
  10940. interpolated: false,
  10941. parameters: [
  10942. "zoom",
  10943. "feature"
  10944. ]
  10945. },
  10946. "property-type": "data-driven"
  10947. },
  10948. "line-miter-limit": {
  10949. type: "number",
  10950. "default": 2,
  10951. requires: [
  10952. {
  10953. "line-join": "miter"
  10954. }
  10955. ],
  10956. expression: {
  10957. interpolated: true,
  10958. parameters: [
  10959. "zoom"
  10960. ]
  10961. },
  10962. "property-type": "data-constant"
  10963. },
  10964. "line-round-limit": {
  10965. type: "number",
  10966. "default": 1.05,
  10967. requires: [
  10968. {
  10969. "line-join": "round"
  10970. }
  10971. ],
  10972. expression: {
  10973. interpolated: true,
  10974. parameters: [
  10975. "zoom"
  10976. ]
  10977. },
  10978. "property-type": "data-constant"
  10979. },
  10980. "line-sort-key": {
  10981. type: "number",
  10982. expression: {
  10983. interpolated: false,
  10984. parameters: [
  10985. "zoom",
  10986. "feature"
  10987. ]
  10988. },
  10989. "property-type": "data-driven"
  10990. },
  10991. visibility: {
  10992. type: "enum",
  10993. values: {
  10994. visible: {
  10995. },
  10996. none: {
  10997. }
  10998. },
  10999. "default": "visible",
  11000. "property-type": "constant"
  11001. }
  11002. };
  11003. var layout_symbol = {
  11004. "symbol-placement": {
  11005. type: "enum",
  11006. values: {
  11007. point: {
  11008. },
  11009. line: {
  11010. },
  11011. "line-center": {
  11012. }
  11013. },
  11014. "default": "point",
  11015. expression: {
  11016. interpolated: false,
  11017. parameters: [
  11018. "zoom"
  11019. ]
  11020. },
  11021. "property-type": "data-constant"
  11022. },
  11023. "symbol-spacing": {
  11024. type: "number",
  11025. "default": 250,
  11026. minimum: 1,
  11027. units: "pixels",
  11028. requires: [
  11029. {
  11030. "symbol-placement": "line"
  11031. }
  11032. ],
  11033. expression: {
  11034. interpolated: true,
  11035. parameters: [
  11036. "zoom"
  11037. ]
  11038. },
  11039. "property-type": "data-constant"
  11040. },
  11041. "symbol-avoid-edges": {
  11042. type: "boolean",
  11043. "default": false,
  11044. expression: {
  11045. interpolated: false,
  11046. parameters: [
  11047. "zoom"
  11048. ]
  11049. },
  11050. "property-type": "data-constant"
  11051. },
  11052. "symbol-sort-key": {
  11053. type: "number",
  11054. expression: {
  11055. interpolated: false,
  11056. parameters: [
  11057. "zoom",
  11058. "feature"
  11059. ]
  11060. },
  11061. "property-type": "data-driven"
  11062. },
  11063. "symbol-z-order": {
  11064. type: "enum",
  11065. values: {
  11066. auto: {
  11067. },
  11068. "viewport-y": {
  11069. },
  11070. source: {
  11071. }
  11072. },
  11073. "default": "auto",
  11074. expression: {
  11075. interpolated: false,
  11076. parameters: [
  11077. "zoom"
  11078. ]
  11079. },
  11080. "property-type": "data-constant"
  11081. },
  11082. "icon-allow-overlap": {
  11083. type: "boolean",
  11084. "default": false,
  11085. requires: [
  11086. "icon-image"
  11087. ],
  11088. expression: {
  11089. interpolated: false,
  11090. parameters: [
  11091. "zoom"
  11092. ]
  11093. },
  11094. "property-type": "data-constant"
  11095. },
  11096. "icon-ignore-placement": {
  11097. type: "boolean",
  11098. "default": false,
  11099. requires: [
  11100. "icon-image"
  11101. ],
  11102. expression: {
  11103. interpolated: false,
  11104. parameters: [
  11105. "zoom"
  11106. ]
  11107. },
  11108. "property-type": "data-constant"
  11109. },
  11110. "icon-optional": {
  11111. type: "boolean",
  11112. "default": false,
  11113. requires: [
  11114. "icon-image",
  11115. "text-field"
  11116. ],
  11117. expression: {
  11118. interpolated: false,
  11119. parameters: [
  11120. "zoom"
  11121. ]
  11122. },
  11123. "property-type": "data-constant"
  11124. },
  11125. "icon-rotation-alignment": {
  11126. type: "enum",
  11127. values: {
  11128. map: {
  11129. },
  11130. viewport: {
  11131. },
  11132. auto: {
  11133. }
  11134. },
  11135. "default": "auto",
  11136. requires: [
  11137. "icon-image"
  11138. ],
  11139. expression: {
  11140. interpolated: false,
  11141. parameters: [
  11142. "zoom"
  11143. ]
  11144. },
  11145. "property-type": "data-constant"
  11146. },
  11147. "icon-size": {
  11148. type: "number",
  11149. "default": 1,
  11150. minimum: 0,
  11151. units: "factor of the original icon size",
  11152. requires: [
  11153. "icon-image"
  11154. ],
  11155. expression: {
  11156. interpolated: true,
  11157. parameters: [
  11158. "zoom",
  11159. "feature"
  11160. ]
  11161. },
  11162. "property-type": "data-driven"
  11163. },
  11164. "icon-text-fit": {
  11165. type: "enum",
  11166. values: {
  11167. none: {
  11168. },
  11169. width: {
  11170. },
  11171. height: {
  11172. },
  11173. both: {
  11174. }
  11175. },
  11176. "default": "none",
  11177. requires: [
  11178. "icon-image",
  11179. "text-field"
  11180. ],
  11181. expression: {
  11182. interpolated: false,
  11183. parameters: [
  11184. "zoom"
  11185. ]
  11186. },
  11187. "property-type": "data-constant"
  11188. },
  11189. "icon-text-fit-padding": {
  11190. type: "array",
  11191. value: "number",
  11192. length: 4,
  11193. "default": [
  11194. 0,
  11195. 0,
  11196. 0,
  11197. 0
  11198. ],
  11199. units: "pixels",
  11200. requires: [
  11201. "icon-image",
  11202. "text-field",
  11203. {
  11204. "icon-text-fit": [
  11205. "both",
  11206. "width",
  11207. "height"
  11208. ]
  11209. }
  11210. ],
  11211. expression: {
  11212. interpolated: true,
  11213. parameters: [
  11214. "zoom"
  11215. ]
  11216. },
  11217. "property-type": "data-constant"
  11218. },
  11219. "icon-image": {
  11220. type: "resolvedImage",
  11221. tokens: true,
  11222. expression: {
  11223. interpolated: false,
  11224. parameters: [
  11225. "zoom",
  11226. "feature"
  11227. ]
  11228. },
  11229. "property-type": "data-driven"
  11230. },
  11231. "icon-rotate": {
  11232. type: "number",
  11233. "default": 0,
  11234. period: 360,
  11235. units: "degrees",
  11236. requires: [
  11237. "icon-image"
  11238. ],
  11239. expression: {
  11240. interpolated: true,
  11241. parameters: [
  11242. "zoom",
  11243. "feature"
  11244. ]
  11245. },
  11246. "property-type": "data-driven"
  11247. },
  11248. "icon-padding": {
  11249. type: "number",
  11250. "default": 2,
  11251. minimum: 0,
  11252. units: "pixels",
  11253. requires: [
  11254. "icon-image"
  11255. ],
  11256. expression: {
  11257. interpolated: true,
  11258. parameters: [
  11259. "zoom"
  11260. ]
  11261. },
  11262. "property-type": "data-constant"
  11263. },
  11264. "icon-keep-upright": {
  11265. type: "boolean",
  11266. "default": false,
  11267. requires: [
  11268. "icon-image",
  11269. {
  11270. "icon-rotation-alignment": "map"
  11271. },
  11272. {
  11273. "symbol-placement": [
  11274. "line",
  11275. "line-center"
  11276. ]
  11277. }
  11278. ],
  11279. expression: {
  11280. interpolated: false,
  11281. parameters: [
  11282. "zoom"
  11283. ]
  11284. },
  11285. "property-type": "data-constant"
  11286. },
  11287. "icon-offset": {
  11288. type: "array",
  11289. value: "number",
  11290. length: 2,
  11291. "default": [
  11292. 0,
  11293. 0
  11294. ],
  11295. requires: [
  11296. "icon-image"
  11297. ],
  11298. expression: {
  11299. interpolated: true,
  11300. parameters: [
  11301. "zoom",
  11302. "feature"
  11303. ]
  11304. },
  11305. "property-type": "data-driven"
  11306. },
  11307. "icon-anchor": {
  11308. type: "enum",
  11309. values: {
  11310. center: {
  11311. },
  11312. left: {
  11313. },
  11314. right: {
  11315. },
  11316. top: {
  11317. },
  11318. bottom: {
  11319. },
  11320. "top-left": {
  11321. },
  11322. "top-right": {
  11323. },
  11324. "bottom-left": {
  11325. },
  11326. "bottom-right": {
  11327. }
  11328. },
  11329. "default": "center",
  11330. requires: [
  11331. "icon-image"
  11332. ],
  11333. expression: {
  11334. interpolated: false,
  11335. parameters: [
  11336. "zoom",
  11337. "feature"
  11338. ]
  11339. },
  11340. "property-type": "data-driven"
  11341. },
  11342. "icon-pitch-alignment": {
  11343. type: "enum",
  11344. values: {
  11345. map: {
  11346. },
  11347. viewport: {
  11348. },
  11349. auto: {
  11350. }
  11351. },
  11352. "default": "auto",
  11353. requires: [
  11354. "icon-image"
  11355. ],
  11356. expression: {
  11357. interpolated: false,
  11358. parameters: [
  11359. "zoom"
  11360. ]
  11361. },
  11362. "property-type": "data-constant"
  11363. },
  11364. "text-pitch-alignment": {
  11365. type: "enum",
  11366. values: {
  11367. map: {
  11368. },
  11369. viewport: {
  11370. },
  11371. auto: {
  11372. }
  11373. },
  11374. "default": "auto",
  11375. requires: [
  11376. "text-field"
  11377. ],
  11378. expression: {
  11379. interpolated: false,
  11380. parameters: [
  11381. "zoom"
  11382. ]
  11383. },
  11384. "property-type": "data-constant"
  11385. },
  11386. "text-rotation-alignment": {
  11387. type: "enum",
  11388. values: {
  11389. map: {
  11390. },
  11391. viewport: {
  11392. },
  11393. auto: {
  11394. }
  11395. },
  11396. "default": "auto",
  11397. requires: [
  11398. "text-field"
  11399. ],
  11400. expression: {
  11401. interpolated: false,
  11402. parameters: [
  11403. "zoom"
  11404. ]
  11405. },
  11406. "property-type": "data-constant"
  11407. },
  11408. "text-field": {
  11409. type: "formatted",
  11410. "default": "",
  11411. tokens: true,
  11412. expression: {
  11413. interpolated: false,
  11414. parameters: [
  11415. "zoom",
  11416. "feature"
  11417. ]
  11418. },
  11419. "property-type": "data-driven"
  11420. },
  11421. "text-font": {
  11422. type: "array",
  11423. value: "string",
  11424. "default": [
  11425. "Open Sans Regular",
  11426. "Arial Unicode MS Regular"
  11427. ],
  11428. requires: [
  11429. "text-field"
  11430. ],
  11431. expression: {
  11432. interpolated: false,
  11433. parameters: [
  11434. "zoom",
  11435. "feature"
  11436. ]
  11437. },
  11438. "property-type": "data-driven"
  11439. },
  11440. "text-size": {
  11441. type: "number",
  11442. "default": 16,
  11443. minimum: 0,
  11444. units: "pixels",
  11445. requires: [
  11446. "text-field"
  11447. ],
  11448. expression: {
  11449. interpolated: true,
  11450. parameters: [
  11451. "zoom",
  11452. "feature"
  11453. ]
  11454. },
  11455. "property-type": "data-driven"
  11456. },
  11457. "text-max-width": {
  11458. type: "number",
  11459. "default": 10,
  11460. minimum: 0,
  11461. units: "ems",
  11462. requires: [
  11463. "text-field"
  11464. ],
  11465. expression: {
  11466. interpolated: true,
  11467. parameters: [
  11468. "zoom",
  11469. "feature"
  11470. ]
  11471. },
  11472. "property-type": "data-driven"
  11473. },
  11474. "text-line-height": {
  11475. type: "number",
  11476. "default": 1.2,
  11477. units: "ems",
  11478. requires: [
  11479. "text-field"
  11480. ],
  11481. expression: {
  11482. interpolated: true,
  11483. parameters: [
  11484. "zoom"
  11485. ]
  11486. },
  11487. "property-type": "data-constant"
  11488. },
  11489. "text-letter-spacing": {
  11490. type: "number",
  11491. "default": 0,
  11492. units: "ems",
  11493. requires: [
  11494. "text-field"
  11495. ],
  11496. expression: {
  11497. interpolated: true,
  11498. parameters: [
  11499. "zoom",
  11500. "feature"
  11501. ]
  11502. },
  11503. "property-type": "data-driven"
  11504. },
  11505. "text-justify": {
  11506. type: "enum",
  11507. values: {
  11508. auto: {
  11509. },
  11510. left: {
  11511. },
  11512. center: {
  11513. },
  11514. right: {
  11515. }
  11516. },
  11517. "default": "center",
  11518. requires: [
  11519. "text-field"
  11520. ],
  11521. expression: {
  11522. interpolated: false,
  11523. parameters: [
  11524. "zoom",
  11525. "feature"
  11526. ]
  11527. },
  11528. "property-type": "data-driven"
  11529. },
  11530. "text-radial-offset": {
  11531. type: "number",
  11532. units: "ems",
  11533. "default": 0,
  11534. requires: [
  11535. "text-field"
  11536. ],
  11537. "property-type": "data-driven",
  11538. expression: {
  11539. interpolated: true,
  11540. parameters: [
  11541. "zoom",
  11542. "feature"
  11543. ]
  11544. }
  11545. },
  11546. "text-variable-anchor": {
  11547. type: "array",
  11548. value: "enum",
  11549. values: {
  11550. center: {
  11551. },
  11552. left: {
  11553. },
  11554. right: {
  11555. },
  11556. top: {
  11557. },
  11558. bottom: {
  11559. },
  11560. "top-left": {
  11561. },
  11562. "top-right": {
  11563. },
  11564. "bottom-left": {
  11565. },
  11566. "bottom-right": {
  11567. }
  11568. },
  11569. requires: [
  11570. "text-field",
  11571. {
  11572. "symbol-placement": [
  11573. "point"
  11574. ]
  11575. }
  11576. ],
  11577. expression: {
  11578. interpolated: false,
  11579. parameters: [
  11580. "zoom"
  11581. ]
  11582. },
  11583. "property-type": "data-constant"
  11584. },
  11585. "text-anchor": {
  11586. type: "enum",
  11587. values: {
  11588. center: {
  11589. },
  11590. left: {
  11591. },
  11592. right: {
  11593. },
  11594. top: {
  11595. },
  11596. bottom: {
  11597. },
  11598. "top-left": {
  11599. },
  11600. "top-right": {
  11601. },
  11602. "bottom-left": {
  11603. },
  11604. "bottom-right": {
  11605. }
  11606. },
  11607. "default": "center",
  11608. requires: [
  11609. "text-field",
  11610. {
  11611. "!": "text-variable-anchor"
  11612. }
  11613. ],
  11614. expression: {
  11615. interpolated: false,
  11616. parameters: [
  11617. "zoom",
  11618. "feature"
  11619. ]
  11620. },
  11621. "property-type": "data-driven"
  11622. },
  11623. "text-max-angle": {
  11624. type: "number",
  11625. "default": 45,
  11626. units: "degrees",
  11627. requires: [
  11628. "text-field",
  11629. {
  11630. "symbol-placement": [
  11631. "line",
  11632. "line-center"
  11633. ]
  11634. }
  11635. ],
  11636. expression: {
  11637. interpolated: true,
  11638. parameters: [
  11639. "zoom"
  11640. ]
  11641. },
  11642. "property-type": "data-constant"
  11643. },
  11644. "text-writing-mode": {
  11645. type: "array",
  11646. value: "enum",
  11647. values: {
  11648. horizontal: {
  11649. },
  11650. vertical: {
  11651. }
  11652. },
  11653. requires: [
  11654. "text-field",
  11655. {
  11656. "symbol-placement": [
  11657. "point"
  11658. ]
  11659. }
  11660. ],
  11661. expression: {
  11662. interpolated: false,
  11663. parameters: [
  11664. "zoom"
  11665. ]
  11666. },
  11667. "property-type": "data-constant"
  11668. },
  11669. "text-rotate": {
  11670. type: "number",
  11671. "default": 0,
  11672. period: 360,
  11673. units: "degrees",
  11674. requires: [
  11675. "text-field"
  11676. ],
  11677. expression: {
  11678. interpolated: true,
  11679. parameters: [
  11680. "zoom",
  11681. "feature"
  11682. ]
  11683. },
  11684. "property-type": "data-driven"
  11685. },
  11686. "text-padding": {
  11687. type: "number",
  11688. "default": 2,
  11689. minimum: 0,
  11690. units: "pixels",
  11691. requires: [
  11692. "text-field"
  11693. ],
  11694. expression: {
  11695. interpolated: true,
  11696. parameters: [
  11697. "zoom"
  11698. ]
  11699. },
  11700. "property-type": "data-constant"
  11701. },
  11702. "text-keep-upright": {
  11703. type: "boolean",
  11704. "default": true,
  11705. requires: [
  11706. "text-field",
  11707. {
  11708. "text-rotation-alignment": "map"
  11709. },
  11710. {
  11711. "symbol-placement": [
  11712. "line",
  11713. "line-center"
  11714. ]
  11715. }
  11716. ],
  11717. expression: {
  11718. interpolated: false,
  11719. parameters: [
  11720. "zoom"
  11721. ]
  11722. },
  11723. "property-type": "data-constant"
  11724. },
  11725. "text-transform": {
  11726. type: "enum",
  11727. values: {
  11728. none: {
  11729. },
  11730. uppercase: {
  11731. },
  11732. lowercase: {
  11733. }
  11734. },
  11735. "default": "none",
  11736. requires: [
  11737. "text-field"
  11738. ],
  11739. expression: {
  11740. interpolated: false,
  11741. parameters: [
  11742. "zoom",
  11743. "feature"
  11744. ]
  11745. },
  11746. "property-type": "data-driven"
  11747. },
  11748. "text-offset": {
  11749. type: "array",
  11750. value: "number",
  11751. units: "ems",
  11752. length: 2,
  11753. "default": [
  11754. 0,
  11755. 0
  11756. ],
  11757. requires: [
  11758. "text-field",
  11759. {
  11760. "!": "text-radial-offset"
  11761. }
  11762. ],
  11763. expression: {
  11764. interpolated: true,
  11765. parameters: [
  11766. "zoom",
  11767. "feature"
  11768. ]
  11769. },
  11770. "property-type": "data-driven"
  11771. },
  11772. "text-allow-overlap": {
  11773. type: "boolean",
  11774. "default": false,
  11775. requires: [
  11776. "text-field"
  11777. ],
  11778. expression: {
  11779. interpolated: false,
  11780. parameters: [
  11781. "zoom"
  11782. ]
  11783. },
  11784. "property-type": "data-constant"
  11785. },
  11786. "text-ignore-placement": {
  11787. type: "boolean",
  11788. "default": false,
  11789. requires: [
  11790. "text-field"
  11791. ],
  11792. expression: {
  11793. interpolated: false,
  11794. parameters: [
  11795. "zoom"
  11796. ]
  11797. },
  11798. "property-type": "data-constant"
  11799. },
  11800. "text-optional": {
  11801. type: "boolean",
  11802. "default": false,
  11803. requires: [
  11804. "text-field",
  11805. "icon-image"
  11806. ],
  11807. expression: {
  11808. interpolated: false,
  11809. parameters: [
  11810. "zoom"
  11811. ]
  11812. },
  11813. "property-type": "data-constant"
  11814. },
  11815. visibility: {
  11816. type: "enum",
  11817. values: {
  11818. visible: {
  11819. },
  11820. none: {
  11821. }
  11822. },
  11823. "default": "visible",
  11824. "property-type": "constant"
  11825. }
  11826. };
  11827. var layout_raster = {
  11828. visibility: {
  11829. type: "enum",
  11830. values: {
  11831. visible: {
  11832. },
  11833. none: {
  11834. }
  11835. },
  11836. "default": "visible",
  11837. "property-type": "constant"
  11838. }
  11839. };
  11840. var layout_hillshade = {
  11841. visibility: {
  11842. type: "enum",
  11843. values: {
  11844. visible: {
  11845. },
  11846. none: {
  11847. }
  11848. },
  11849. "default": "visible",
  11850. "property-type": "constant"
  11851. }
  11852. };
  11853. var filter = {
  11854. type: "array",
  11855. value: "*"
  11856. };
  11857. var filter_operator = {
  11858. type: "enum",
  11859. values: {
  11860. "==": {
  11861. },
  11862. "!=": {
  11863. },
  11864. ">": {
  11865. },
  11866. ">=": {
  11867. },
  11868. "<": {
  11869. },
  11870. "<=": {
  11871. },
  11872. "in": {
  11873. },
  11874. "!in": {
  11875. },
  11876. all: {
  11877. },
  11878. any: {
  11879. },
  11880. none: {
  11881. },
  11882. has: {
  11883. },
  11884. "!has": {
  11885. }
  11886. }
  11887. };
  11888. var geometry_type = {
  11889. type: "enum",
  11890. values: {
  11891. Point: {
  11892. },
  11893. LineString: {
  11894. },
  11895. Polygon: {
  11896. }
  11897. }
  11898. };
  11899. var function_stop = {
  11900. type: "array",
  11901. minimum: 0,
  11902. maximum: 24,
  11903. value: [
  11904. "number",
  11905. "color"
  11906. ],
  11907. length: 2
  11908. };
  11909. var expression = {
  11910. type: "array",
  11911. value: "*",
  11912. minimum: 1
  11913. };
  11914. var expression_name = {
  11915. type: "enum",
  11916. values: {
  11917. "let": {
  11918. group: "Variable binding"
  11919. },
  11920. "var": {
  11921. group: "Variable binding"
  11922. },
  11923. literal: {
  11924. group: "Types"
  11925. },
  11926. array: {
  11927. group: "Types"
  11928. },
  11929. at: {
  11930. group: "Lookup"
  11931. },
  11932. "in": {
  11933. group: "Lookup"
  11934. },
  11935. "case": {
  11936. group: "Decision"
  11937. },
  11938. match: {
  11939. group: "Decision"
  11940. },
  11941. coalesce: {
  11942. group: "Decision"
  11943. },
  11944. step: {
  11945. group: "Ramps, scales, curves"
  11946. },
  11947. interpolate: {
  11948. group: "Ramps, scales, curves"
  11949. },
  11950. "interpolate-hcl": {
  11951. group: "Ramps, scales, curves"
  11952. },
  11953. "interpolate-lab": {
  11954. group: "Ramps, scales, curves"
  11955. },
  11956. ln2: {
  11957. group: "Math"
  11958. },
  11959. pi: {
  11960. group: "Math"
  11961. },
  11962. e: {
  11963. group: "Math"
  11964. },
  11965. "typeof": {
  11966. group: "Types"
  11967. },
  11968. string: {
  11969. group: "Types"
  11970. },
  11971. number: {
  11972. group: "Types"
  11973. },
  11974. boolean: {
  11975. group: "Types"
  11976. },
  11977. object: {
  11978. group: "Types"
  11979. },
  11980. collator: {
  11981. group: "Types"
  11982. },
  11983. format: {
  11984. group: "Types"
  11985. },
  11986. image: {
  11987. group: "Types"
  11988. },
  11989. "number-format": {
  11990. group: "Types"
  11991. },
  11992. "to-string": {
  11993. group: "Types"
  11994. },
  11995. "to-number": {
  11996. group: "Types"
  11997. },
  11998. "to-boolean": {
  11999. group: "Types"
  12000. },
  12001. "to-rgba": {
  12002. group: "Color"
  12003. },
  12004. "to-color": {
  12005. group: "Types"
  12006. },
  12007. rgb: {
  12008. group: "Color"
  12009. },
  12010. rgba: {
  12011. group: "Color"
  12012. },
  12013. get: {
  12014. group: "Lookup"
  12015. },
  12016. has: {
  12017. group: "Lookup"
  12018. },
  12019. length: {
  12020. group: "Lookup"
  12021. },
  12022. properties: {
  12023. group: "Feature data"
  12024. },
  12025. "feature-state": {
  12026. group: "Feature data"
  12027. },
  12028. "geometry-type": {
  12029. group: "Feature data"
  12030. },
  12031. id: {
  12032. group: "Feature data"
  12033. },
  12034. zoom: {
  12035. group: "Zoom"
  12036. },
  12037. "heatmap-density": {
  12038. group: "Heatmap"
  12039. },
  12040. "line-progress": {
  12041. group: "Feature data"
  12042. },
  12043. accumulated: {
  12044. group: "Feature data"
  12045. },
  12046. "+": {
  12047. group: "Math"
  12048. },
  12049. "*": {
  12050. group: "Math"
  12051. },
  12052. "-": {
  12053. group: "Math"
  12054. },
  12055. "/": {
  12056. group: "Math"
  12057. },
  12058. "%": {
  12059. group: "Math"
  12060. },
  12061. "^": {
  12062. group: "Math"
  12063. },
  12064. sqrt: {
  12065. group: "Math"
  12066. },
  12067. log10: {
  12068. group: "Math"
  12069. },
  12070. ln: {
  12071. group: "Math"
  12072. },
  12073. log2: {
  12074. group: "Math"
  12075. },
  12076. sin: {
  12077. group: "Math"
  12078. },
  12079. cos: {
  12080. group: "Math"
  12081. },
  12082. tan: {
  12083. group: "Math"
  12084. },
  12085. asin: {
  12086. group: "Math"
  12087. },
  12088. acos: {
  12089. group: "Math"
  12090. },
  12091. atan: {
  12092. group: "Math"
  12093. },
  12094. min: {
  12095. group: "Math"
  12096. },
  12097. max: {
  12098. group: "Math"
  12099. },
  12100. round: {
  12101. group: "Math"
  12102. },
  12103. abs: {
  12104. group: "Math"
  12105. },
  12106. ceil: {
  12107. group: "Math"
  12108. },
  12109. floor: {
  12110. group: "Math"
  12111. },
  12112. "==": {
  12113. group: "Decision"
  12114. },
  12115. "!=": {
  12116. group: "Decision"
  12117. },
  12118. ">": {
  12119. group: "Decision"
  12120. },
  12121. "<": {
  12122. group: "Decision"
  12123. },
  12124. ">=": {
  12125. group: "Decision"
  12126. },
  12127. "<=": {
  12128. group: "Decision"
  12129. },
  12130. all: {
  12131. group: "Decision"
  12132. },
  12133. any: {
  12134. group: "Decision"
  12135. },
  12136. "!": {
  12137. group: "Decision"
  12138. },
  12139. "is-supported-script": {
  12140. group: "String"
  12141. },
  12142. upcase: {
  12143. group: "String"
  12144. },
  12145. downcase: {
  12146. group: "String"
  12147. },
  12148. concat: {
  12149. group: "String"
  12150. },
  12151. "resolved-locale": {
  12152. group: "String"
  12153. }
  12154. }
  12155. };
  12156. var light = {
  12157. anchor: {
  12158. type: "enum",
  12159. "default": "viewport",
  12160. values: {
  12161. map: {
  12162. },
  12163. viewport: {
  12164. }
  12165. },
  12166. "property-type": "data-constant",
  12167. transition: false,
  12168. expression: {
  12169. interpolated: false,
  12170. parameters: [
  12171. "zoom"
  12172. ]
  12173. }
  12174. },
  12175. position: {
  12176. type: "array",
  12177. "default": [
  12178. 1.15,
  12179. 210,
  12180. 30
  12181. ],
  12182. length: 3,
  12183. value: "number",
  12184. "property-type": "data-constant",
  12185. transition: true,
  12186. expression: {
  12187. interpolated: true,
  12188. parameters: [
  12189. "zoom"
  12190. ]
  12191. }
  12192. },
  12193. color: {
  12194. type: "color",
  12195. "property-type": "data-constant",
  12196. "default": "#ffffff",
  12197. expression: {
  12198. interpolated: true,
  12199. parameters: [
  12200. "zoom"
  12201. ]
  12202. },
  12203. transition: true
  12204. },
  12205. intensity: {
  12206. type: "number",
  12207. "property-type": "data-constant",
  12208. "default": 0.5,
  12209. minimum: 0,
  12210. maximum: 1,
  12211. expression: {
  12212. interpolated: true,
  12213. parameters: [
  12214. "zoom"
  12215. ]
  12216. },
  12217. transition: true
  12218. }
  12219. };
  12220. var paint = [
  12221. "paint_fill",
  12222. "paint_line",
  12223. "paint_circle",
  12224. "paint_heatmap",
  12225. "paint_fill-extrusion",
  12226. "paint_symbol",
  12227. "paint_raster",
  12228. "paint_hillshade",
  12229. "paint_background"
  12230. ];
  12231. var paint_fill = {
  12232. "fill-antialias": {
  12233. type: "boolean",
  12234. "default": true,
  12235. expression: {
  12236. interpolated: false,
  12237. parameters: [
  12238. "zoom"
  12239. ]
  12240. },
  12241. "property-type": "data-constant"
  12242. },
  12243. "fill-opacity": {
  12244. type: "number",
  12245. "default": 1,
  12246. minimum: 0,
  12247. maximum: 1,
  12248. transition: true,
  12249. expression: {
  12250. interpolated: true,
  12251. parameters: [
  12252. "zoom",
  12253. "feature",
  12254. "feature-state"
  12255. ]
  12256. },
  12257. "property-type": "data-driven"
  12258. },
  12259. "fill-color": {
  12260. type: "color",
  12261. "default": "#000000",
  12262. transition: true,
  12263. requires: [
  12264. {
  12265. "!": "fill-pattern"
  12266. }
  12267. ],
  12268. expression: {
  12269. interpolated: true,
  12270. parameters: [
  12271. "zoom",
  12272. "feature",
  12273. "feature-state"
  12274. ]
  12275. },
  12276. "property-type": "data-driven"
  12277. },
  12278. "fill-outline-color": {
  12279. type: "color",
  12280. transition: true,
  12281. requires: [
  12282. {
  12283. "!": "fill-pattern"
  12284. },
  12285. {
  12286. "fill-antialias": true
  12287. }
  12288. ],
  12289. expression: {
  12290. interpolated: true,
  12291. parameters: [
  12292. "zoom",
  12293. "feature",
  12294. "feature-state"
  12295. ]
  12296. },
  12297. "property-type": "data-driven"
  12298. },
  12299. "fill-translate": {
  12300. type: "array",
  12301. value: "number",
  12302. length: 2,
  12303. "default": [
  12304. 0,
  12305. 0
  12306. ],
  12307. transition: true,
  12308. units: "pixels",
  12309. expression: {
  12310. interpolated: true,
  12311. parameters: [
  12312. "zoom"
  12313. ]
  12314. },
  12315. "property-type": "data-constant"
  12316. },
  12317. "fill-translate-anchor": {
  12318. type: "enum",
  12319. values: {
  12320. map: {
  12321. },
  12322. viewport: {
  12323. }
  12324. },
  12325. "default": "map",
  12326. requires: [
  12327. "fill-translate"
  12328. ],
  12329. expression: {
  12330. interpolated: false,
  12331. parameters: [
  12332. "zoom"
  12333. ]
  12334. },
  12335. "property-type": "data-constant"
  12336. },
  12337. "fill-pattern": {
  12338. type: "resolvedImage",
  12339. transition: true,
  12340. expression: {
  12341. interpolated: false,
  12342. parameters: [
  12343. "zoom",
  12344. "feature"
  12345. ]
  12346. },
  12347. "property-type": "cross-faded-data-driven"
  12348. }
  12349. };
  12350. var paint_line = {
  12351. "line-opacity": {
  12352. type: "number",
  12353. "default": 1,
  12354. minimum: 0,
  12355. maximum: 1,
  12356. transition: true,
  12357. expression: {
  12358. interpolated: true,
  12359. parameters: [
  12360. "zoom",
  12361. "feature",
  12362. "feature-state"
  12363. ]
  12364. },
  12365. "property-type": "data-driven"
  12366. },
  12367. "line-color": {
  12368. type: "color",
  12369. "default": "#000000",
  12370. transition: true,
  12371. requires: [
  12372. {
  12373. "!": "line-pattern"
  12374. }
  12375. ],
  12376. expression: {
  12377. interpolated: true,
  12378. parameters: [
  12379. "zoom",
  12380. "feature",
  12381. "feature-state"
  12382. ]
  12383. },
  12384. "property-type": "data-driven"
  12385. },
  12386. "line-translate": {
  12387. type: "array",
  12388. value: "number",
  12389. length: 2,
  12390. "default": [
  12391. 0,
  12392. 0
  12393. ],
  12394. transition: true,
  12395. units: "pixels",
  12396. expression: {
  12397. interpolated: true,
  12398. parameters: [
  12399. "zoom"
  12400. ]
  12401. },
  12402. "property-type": "data-constant"
  12403. },
  12404. "line-translate-anchor": {
  12405. type: "enum",
  12406. values: {
  12407. map: {
  12408. },
  12409. viewport: {
  12410. }
  12411. },
  12412. "default": "map",
  12413. requires: [
  12414. "line-translate"
  12415. ],
  12416. expression: {
  12417. interpolated: false,
  12418. parameters: [
  12419. "zoom"
  12420. ]
  12421. },
  12422. "property-type": "data-constant"
  12423. },
  12424. "line-width": {
  12425. type: "number",
  12426. "default": 1,
  12427. minimum: 0,
  12428. transition: true,
  12429. units: "pixels",
  12430. expression: {
  12431. interpolated: true,
  12432. parameters: [
  12433. "zoom",
  12434. "feature",
  12435. "feature-state"
  12436. ]
  12437. },
  12438. "property-type": "data-driven"
  12439. },
  12440. "line-gap-width": {
  12441. type: "number",
  12442. "default": 0,
  12443. minimum: 0,
  12444. transition: true,
  12445. units: "pixels",
  12446. expression: {
  12447. interpolated: true,
  12448. parameters: [
  12449. "zoom",
  12450. "feature",
  12451. "feature-state"
  12452. ]
  12453. },
  12454. "property-type": "data-driven"
  12455. },
  12456. "line-offset": {
  12457. type: "number",
  12458. "default": 0,
  12459. transition: true,
  12460. units: "pixels",
  12461. expression: {
  12462. interpolated: true,
  12463. parameters: [
  12464. "zoom",
  12465. "feature",
  12466. "feature-state"
  12467. ]
  12468. },
  12469. "property-type": "data-driven"
  12470. },
  12471. "line-blur": {
  12472. type: "number",
  12473. "default": 0,
  12474. minimum: 0,
  12475. transition: true,
  12476. units: "pixels",
  12477. expression: {
  12478. interpolated: true,
  12479. parameters: [
  12480. "zoom",
  12481. "feature",
  12482. "feature-state"
  12483. ]
  12484. },
  12485. "property-type": "data-driven"
  12486. },
  12487. "line-dasharray": {
  12488. type: "array",
  12489. value: "number",
  12490. minimum: 0,
  12491. transition: true,
  12492. units: "line widths",
  12493. requires: [
  12494. {
  12495. "!": "line-pattern"
  12496. }
  12497. ],
  12498. expression: {
  12499. interpolated: false,
  12500. parameters: [
  12501. "zoom"
  12502. ]
  12503. },
  12504. "property-type": "cross-faded"
  12505. },
  12506. "line-pattern": {
  12507. type: "resolvedImage",
  12508. transition: true,
  12509. expression: {
  12510. interpolated: false,
  12511. parameters: [
  12512. "zoom",
  12513. "feature"
  12514. ]
  12515. },
  12516. "property-type": "cross-faded-data-driven"
  12517. },
  12518. "line-gradient": {
  12519. type: "color",
  12520. transition: false,
  12521. requires: [
  12522. {
  12523. "!": "line-dasharray"
  12524. },
  12525. {
  12526. "!": "line-pattern"
  12527. },
  12528. {
  12529. source: "geojson",
  12530. has: {
  12531. lineMetrics: true
  12532. }
  12533. }
  12534. ],
  12535. expression: {
  12536. interpolated: true,
  12537. parameters: [
  12538. "line-progress"
  12539. ]
  12540. },
  12541. "property-type": "color-ramp"
  12542. }
  12543. };
  12544. var paint_circle = {
  12545. "circle-radius": {
  12546. type: "number",
  12547. "default": 5,
  12548. minimum: 0,
  12549. transition: true,
  12550. units: "pixels",
  12551. expression: {
  12552. interpolated: true,
  12553. parameters: [
  12554. "zoom",
  12555. "feature",
  12556. "feature-state"
  12557. ]
  12558. },
  12559. "property-type": "data-driven"
  12560. },
  12561. "circle-color": {
  12562. type: "color",
  12563. "default": "#000000",
  12564. transition: true,
  12565. expression: {
  12566. interpolated: true,
  12567. parameters: [
  12568. "zoom",
  12569. "feature",
  12570. "feature-state"
  12571. ]
  12572. },
  12573. "property-type": "data-driven"
  12574. },
  12575. "circle-blur": {
  12576. type: "number",
  12577. "default": 0,
  12578. transition: true,
  12579. expression: {
  12580. interpolated: true,
  12581. parameters: [
  12582. "zoom",
  12583. "feature",
  12584. "feature-state"
  12585. ]
  12586. },
  12587. "property-type": "data-driven"
  12588. },
  12589. "circle-opacity": {
  12590. type: "number",
  12591. "default": 1,
  12592. minimum: 0,
  12593. maximum: 1,
  12594. transition: true,
  12595. expression: {
  12596. interpolated: true,
  12597. parameters: [
  12598. "zoom",
  12599. "feature",
  12600. "feature-state"
  12601. ]
  12602. },
  12603. "property-type": "data-driven"
  12604. },
  12605. "circle-translate": {
  12606. type: "array",
  12607. value: "number",
  12608. length: 2,
  12609. "default": [
  12610. 0,
  12611. 0
  12612. ],
  12613. transition: true,
  12614. units: "pixels",
  12615. expression: {
  12616. interpolated: true,
  12617. parameters: [
  12618. "zoom"
  12619. ]
  12620. },
  12621. "property-type": "data-constant"
  12622. },
  12623. "circle-translate-anchor": {
  12624. type: "enum",
  12625. values: {
  12626. map: {
  12627. },
  12628. viewport: {
  12629. }
  12630. },
  12631. "default": "map",
  12632. requires: [
  12633. "circle-translate"
  12634. ],
  12635. expression: {
  12636. interpolated: false,
  12637. parameters: [
  12638. "zoom"
  12639. ]
  12640. },
  12641. "property-type": "data-constant"
  12642. },
  12643. "circle-pitch-scale": {
  12644. type: "enum",
  12645. values: {
  12646. map: {
  12647. },
  12648. viewport: {
  12649. }
  12650. },
  12651. "default": "map",
  12652. expression: {
  12653. interpolated: false,
  12654. parameters: [
  12655. "zoom"
  12656. ]
  12657. },
  12658. "property-type": "data-constant"
  12659. },
  12660. "circle-pitch-alignment": {
  12661. type: "enum",
  12662. values: {
  12663. map: {
  12664. },
  12665. viewport: {
  12666. }
  12667. },
  12668. "default": "viewport",
  12669. expression: {
  12670. interpolated: false,
  12671. parameters: [
  12672. "zoom"
  12673. ]
  12674. },
  12675. "property-type": "data-constant"
  12676. },
  12677. "circle-stroke-width": {
  12678. type: "number",
  12679. "default": 0,
  12680. minimum: 0,
  12681. transition: true,
  12682. units: "pixels",
  12683. expression: {
  12684. interpolated: true,
  12685. parameters: [
  12686. "zoom",
  12687. "feature",
  12688. "feature-state"
  12689. ]
  12690. },
  12691. "property-type": "data-driven"
  12692. },
  12693. "circle-stroke-color": {
  12694. type: "color",
  12695. "default": "#000000",
  12696. transition: true,
  12697. expression: {
  12698. interpolated: true,
  12699. parameters: [
  12700. "zoom",
  12701. "feature",
  12702. "feature-state"
  12703. ]
  12704. },
  12705. "property-type": "data-driven"
  12706. },
  12707. "circle-stroke-opacity": {
  12708. type: "number",
  12709. "default": 1,
  12710. minimum: 0,
  12711. maximum: 1,
  12712. transition: true,
  12713. expression: {
  12714. interpolated: true,
  12715. parameters: [
  12716. "zoom",
  12717. "feature",
  12718. "feature-state"
  12719. ]
  12720. },
  12721. "property-type": "data-driven"
  12722. }
  12723. };
  12724. var paint_heatmap = {
  12725. "heatmap-radius": {
  12726. type: "number",
  12727. "default": 30,
  12728. minimum: 1,
  12729. transition: true,
  12730. units: "pixels",
  12731. expression: {
  12732. interpolated: true,
  12733. parameters: [
  12734. "zoom",
  12735. "feature",
  12736. "feature-state"
  12737. ]
  12738. },
  12739. "property-type": "data-driven"
  12740. },
  12741. "heatmap-weight": {
  12742. type: "number",
  12743. "default": 1,
  12744. minimum: 0,
  12745. transition: false,
  12746. expression: {
  12747. interpolated: true,
  12748. parameters: [
  12749. "zoom",
  12750. "feature",
  12751. "feature-state"
  12752. ]
  12753. },
  12754. "property-type": "data-driven"
  12755. },
  12756. "heatmap-intensity": {
  12757. type: "number",
  12758. "default": 1,
  12759. minimum: 0,
  12760. transition: true,
  12761. expression: {
  12762. interpolated: true,
  12763. parameters: [
  12764. "zoom"
  12765. ]
  12766. },
  12767. "property-type": "data-constant"
  12768. },
  12769. "heatmap-color": {
  12770. type: "color",
  12771. "default": [
  12772. "interpolate",
  12773. [
  12774. "linear"
  12775. ],
  12776. [
  12777. "heatmap-density"
  12778. ],
  12779. 0,
  12780. "rgba(0, 0, 255, 0)",
  12781. 0.1,
  12782. "royalblue",
  12783. 0.3,
  12784. "cyan",
  12785. 0.5,
  12786. "lime",
  12787. 0.7,
  12788. "yellow",
  12789. 1,
  12790. "red"
  12791. ],
  12792. transition: false,
  12793. expression: {
  12794. interpolated: true,
  12795. parameters: [
  12796. "heatmap-density"
  12797. ]
  12798. },
  12799. "property-type": "color-ramp"
  12800. },
  12801. "heatmap-opacity": {
  12802. type: "number",
  12803. "default": 1,
  12804. minimum: 0,
  12805. maximum: 1,
  12806. transition: true,
  12807. expression: {
  12808. interpolated: true,
  12809. parameters: [
  12810. "zoom"
  12811. ]
  12812. },
  12813. "property-type": "data-constant"
  12814. }
  12815. };
  12816. var paint_symbol = {
  12817. "icon-opacity": {
  12818. type: "number",
  12819. "default": 1,
  12820. minimum: 0,
  12821. maximum: 1,
  12822. transition: true,
  12823. requires: [
  12824. "icon-image"
  12825. ],
  12826. expression: {
  12827. interpolated: true,
  12828. parameters: [
  12829. "zoom",
  12830. "feature",
  12831. "feature-state"
  12832. ]
  12833. },
  12834. "property-type": "data-driven"
  12835. },
  12836. "icon-color": {
  12837. type: "color",
  12838. "default": "#000000",
  12839. transition: true,
  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-color": {
  12854. type: "color",
  12855. "default": "rgba(0, 0, 0, 0)",
  12856. transition: true,
  12857. requires: [
  12858. "icon-image"
  12859. ],
  12860. expression: {
  12861. interpolated: true,
  12862. parameters: [
  12863. "zoom",
  12864. "feature",
  12865. "feature-state"
  12866. ]
  12867. },
  12868. "property-type": "data-driven"
  12869. },
  12870. "icon-halo-width": {
  12871. type: "number",
  12872. "default": 0,
  12873. minimum: 0,
  12874. transition: true,
  12875. units: "pixels",
  12876. requires: [
  12877. "icon-image"
  12878. ],
  12879. expression: {
  12880. interpolated: true,
  12881. parameters: [
  12882. "zoom",
  12883. "feature",
  12884. "feature-state"
  12885. ]
  12886. },
  12887. "property-type": "data-driven"
  12888. },
  12889. "icon-halo-blur": {
  12890. type: "number",
  12891. "default": 0,
  12892. minimum: 0,
  12893. transition: true,
  12894. units: "pixels",
  12895. requires: [
  12896. "icon-image"
  12897. ],
  12898. expression: {
  12899. interpolated: true,
  12900. parameters: [
  12901. "zoom",
  12902. "feature",
  12903. "feature-state"
  12904. ]
  12905. },
  12906. "property-type": "data-driven"
  12907. },
  12908. "icon-translate": {
  12909. type: "array",
  12910. value: "number",
  12911. length: 2,
  12912. "default": [
  12913. 0,
  12914. 0
  12915. ],
  12916. transition: true,
  12917. units: "pixels",
  12918. requires: [
  12919. "icon-image"
  12920. ],
  12921. expression: {
  12922. interpolated: true,
  12923. parameters: [
  12924. "zoom"
  12925. ]
  12926. },
  12927. "property-type": "data-constant"
  12928. },
  12929. "icon-translate-anchor": {
  12930. type: "enum",
  12931. values: {
  12932. map: {
  12933. },
  12934. viewport: {
  12935. }
  12936. },
  12937. "default": "map",
  12938. requires: [
  12939. "icon-image",
  12940. "icon-translate"
  12941. ],
  12942. expression: {
  12943. interpolated: false,
  12944. parameters: [
  12945. "zoom"
  12946. ]
  12947. },
  12948. "property-type": "data-constant"
  12949. },
  12950. "text-opacity": {
  12951. type: "number",
  12952. "default": 1,
  12953. minimum: 0,
  12954. maximum: 1,
  12955. transition: true,
  12956. requires: [
  12957. "text-field"
  12958. ],
  12959. expression: {
  12960. interpolated: true,
  12961. parameters: [
  12962. "zoom",
  12963. "feature",
  12964. "feature-state"
  12965. ]
  12966. },
  12967. "property-type": "data-driven"
  12968. },
  12969. "text-color": {
  12970. type: "color",
  12971. "default": "#000000",
  12972. transition: true,
  12973. overridable: true,
  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-color": {
  12988. type: "color",
  12989. "default": "rgba(0, 0, 0, 0)",
  12990. transition: true,
  12991. requires: [
  12992. "text-field"
  12993. ],
  12994. expression: {
  12995. interpolated: true,
  12996. parameters: [
  12997. "zoom",
  12998. "feature",
  12999. "feature-state"
  13000. ]
  13001. },
  13002. "property-type": "data-driven"
  13003. },
  13004. "text-halo-width": {
  13005. type: "number",
  13006. "default": 0,
  13007. minimum: 0,
  13008. transition: true,
  13009. units: "pixels",
  13010. requires: [
  13011. "text-field"
  13012. ],
  13013. expression: {
  13014. interpolated: true,
  13015. parameters: [
  13016. "zoom",
  13017. "feature",
  13018. "feature-state"
  13019. ]
  13020. },
  13021. "property-type": "data-driven"
  13022. },
  13023. "text-halo-blur": {
  13024. type: "number",
  13025. "default": 0,
  13026. minimum: 0,
  13027. transition: true,
  13028. units: "pixels",
  13029. requires: [
  13030. "text-field"
  13031. ],
  13032. expression: {
  13033. interpolated: true,
  13034. parameters: [
  13035. "zoom",
  13036. "feature",
  13037. "feature-state"
  13038. ]
  13039. },
  13040. "property-type": "data-driven"
  13041. },
  13042. "text-translate": {
  13043. type: "array",
  13044. value: "number",
  13045. length: 2,
  13046. "default": [
  13047. 0,
  13048. 0
  13049. ],
  13050. transition: true,
  13051. units: "pixels",
  13052. requires: [
  13053. "text-field"
  13054. ],
  13055. expression: {
  13056. interpolated: true,
  13057. parameters: [
  13058. "zoom"
  13059. ]
  13060. },
  13061. "property-type": "data-constant"
  13062. },
  13063. "text-translate-anchor": {
  13064. type: "enum",
  13065. values: {
  13066. map: {
  13067. },
  13068. viewport: {
  13069. }
  13070. },
  13071. "default": "map",
  13072. requires: [
  13073. "text-field",
  13074. "text-translate"
  13075. ],
  13076. expression: {
  13077. interpolated: false,
  13078. parameters: [
  13079. "zoom"
  13080. ]
  13081. },
  13082. "property-type": "data-constant"
  13083. }
  13084. };
  13085. var paint_raster = {
  13086. "raster-opacity": {
  13087. type: "number",
  13088. "default": 1,
  13089. minimum: 0,
  13090. maximum: 1,
  13091. transition: true,
  13092. expression: {
  13093. interpolated: true,
  13094. parameters: [
  13095. "zoom"
  13096. ]
  13097. },
  13098. "property-type": "data-constant"
  13099. },
  13100. "raster-hue-rotate": {
  13101. type: "number",
  13102. "default": 0,
  13103. period: 360,
  13104. transition: true,
  13105. units: "degrees",
  13106. expression: {
  13107. interpolated: true,
  13108. parameters: [
  13109. "zoom"
  13110. ]
  13111. },
  13112. "property-type": "data-constant"
  13113. },
  13114. "raster-brightness-min": {
  13115. type: "number",
  13116. "default": 0,
  13117. minimum: 0,
  13118. maximum: 1,
  13119. transition: true,
  13120. expression: {
  13121. interpolated: true,
  13122. parameters: [
  13123. "zoom"
  13124. ]
  13125. },
  13126. "property-type": "data-constant"
  13127. },
  13128. "raster-brightness-max": {
  13129. type: "number",
  13130. "default": 1,
  13131. minimum: 0,
  13132. maximum: 1,
  13133. transition: true,
  13134. expression: {
  13135. interpolated: true,
  13136. parameters: [
  13137. "zoom"
  13138. ]
  13139. },
  13140. "property-type": "data-constant"
  13141. },
  13142. "raster-saturation": {
  13143. type: "number",
  13144. "default": 0,
  13145. minimum: -1,
  13146. maximum: 1,
  13147. transition: true,
  13148. expression: {
  13149. interpolated: true,
  13150. parameters: [
  13151. "zoom"
  13152. ]
  13153. },
  13154. "property-type": "data-constant"
  13155. },
  13156. "raster-contrast": {
  13157. type: "number",
  13158. "default": 0,
  13159. minimum: -1,
  13160. maximum: 1,
  13161. transition: true,
  13162. expression: {
  13163. interpolated: true,
  13164. parameters: [
  13165. "zoom"
  13166. ]
  13167. },
  13168. "property-type": "data-constant"
  13169. },
  13170. "raster-resampling": {
  13171. type: "enum",
  13172. values: {
  13173. linear: {
  13174. },
  13175. nearest: {
  13176. }
  13177. },
  13178. "default": "linear",
  13179. expression: {
  13180. interpolated: false,
  13181. parameters: [
  13182. "zoom"
  13183. ]
  13184. },
  13185. "property-type": "data-constant"
  13186. },
  13187. "raster-fade-duration": {
  13188. type: "number",
  13189. "default": 300,
  13190. minimum: 0,
  13191. transition: false,
  13192. units: "milliseconds",
  13193. expression: {
  13194. interpolated: true,
  13195. parameters: [
  13196. "zoom"
  13197. ]
  13198. },
  13199. "property-type": "data-constant"
  13200. }
  13201. };
  13202. var paint_hillshade = {
  13203. "hillshade-illumination-direction": {
  13204. type: "number",
  13205. "default": 335,
  13206. minimum: 0,
  13207. maximum: 359,
  13208. transition: false,
  13209. expression: {
  13210. interpolated: true,
  13211. parameters: [
  13212. "zoom"
  13213. ]
  13214. },
  13215. "property-type": "data-constant"
  13216. },
  13217. "hillshade-illumination-anchor": {
  13218. type: "enum",
  13219. values: {
  13220. map: {
  13221. },
  13222. viewport: {
  13223. }
  13224. },
  13225. "default": "viewport",
  13226. expression: {
  13227. interpolated: false,
  13228. parameters: [
  13229. "zoom"
  13230. ]
  13231. },
  13232. "property-type": "data-constant"
  13233. },
  13234. "hillshade-exaggeration": {
  13235. type: "number",
  13236. "default": 0.5,
  13237. minimum: 0,
  13238. maximum: 1,
  13239. transition: true,
  13240. expression: {
  13241. interpolated: true,
  13242. parameters: [
  13243. "zoom"
  13244. ]
  13245. },
  13246. "property-type": "data-constant"
  13247. },
  13248. "hillshade-shadow-color": {
  13249. type: "color",
  13250. "default": "#000000",
  13251. transition: true,
  13252. expression: {
  13253. interpolated: true,
  13254. parameters: [
  13255. "zoom"
  13256. ]
  13257. },
  13258. "property-type": "data-constant"
  13259. },
  13260. "hillshade-highlight-color": {
  13261. type: "color",
  13262. "default": "#FFFFFF",
  13263. transition: true,
  13264. expression: {
  13265. interpolated: true,
  13266. parameters: [
  13267. "zoom"
  13268. ]
  13269. },
  13270. "property-type": "data-constant"
  13271. },
  13272. "hillshade-accent-color": {
  13273. type: "color",
  13274. "default": "#000000",
  13275. transition: true,
  13276. expression: {
  13277. interpolated: true,
  13278. parameters: [
  13279. "zoom"
  13280. ]
  13281. },
  13282. "property-type": "data-constant"
  13283. }
  13284. };
  13285. var paint_background = {
  13286. "background-color": {
  13287. type: "color",
  13288. "default": "#000000",
  13289. transition: true,
  13290. requires: [
  13291. {
  13292. "!": "background-pattern"
  13293. }
  13294. ],
  13295. expression: {
  13296. interpolated: true,
  13297. parameters: [
  13298. "zoom"
  13299. ]
  13300. },
  13301. "property-type": "data-constant"
  13302. },
  13303. "background-pattern": {
  13304. type: "resolvedImage",
  13305. transition: true,
  13306. expression: {
  13307. interpolated: false,
  13308. parameters: [
  13309. "zoom"
  13310. ]
  13311. },
  13312. "property-type": "cross-faded"
  13313. },
  13314. "background-opacity": {
  13315. type: "number",
  13316. "default": 1,
  13317. minimum: 0,
  13318. maximum: 1,
  13319. transition: true,
  13320. expression: {
  13321. interpolated: true,
  13322. parameters: [
  13323. "zoom"
  13324. ]
  13325. },
  13326. "property-type": "data-constant"
  13327. }
  13328. };
  13329. var transition = {
  13330. duration: {
  13331. type: "number",
  13332. "default": 300,
  13333. minimum: 0,
  13334. units: "milliseconds"
  13335. },
  13336. delay: {
  13337. type: "number",
  13338. "default": 0,
  13339. minimum: 0,
  13340. units: "milliseconds"
  13341. }
  13342. };
  13343. var StyleSpec = {
  13344. $version: $version,
  13345. $root: $root,
  13346. sources: sources,
  13347. source: source,
  13348. source_vector: source_vector,
  13349. source_raster: source_raster,
  13350. source_raster_dem: source_raster_dem,
  13351. source_geojson: source_geojson,
  13352. source_video: source_video,
  13353. source_image: source_image,
  13354. layer: layer,
  13355. layout: layout,
  13356. layout_background: layout_background,
  13357. layout_fill: layout_fill,
  13358. layout_circle: layout_circle,
  13359. layout_heatmap: layout_heatmap,
  13360. "layout_fill-extrusion": {
  13361. visibility: {
  13362. type: "enum",
  13363. values: {
  13364. visible: {
  13365. },
  13366. none: {
  13367. }
  13368. },
  13369. "default": "visible",
  13370. "property-type": "constant"
  13371. }
  13372. },
  13373. layout_line: layout_line,
  13374. layout_symbol: layout_symbol,
  13375. layout_raster: layout_raster,
  13376. layout_hillshade: layout_hillshade,
  13377. filter: filter,
  13378. filter_operator: filter_operator,
  13379. geometry_type: geometry_type,
  13380. "function": {
  13381. expression: {
  13382. type: "expression"
  13383. },
  13384. stops: {
  13385. type: "array",
  13386. value: "function_stop"
  13387. },
  13388. base: {
  13389. type: "number",
  13390. "default": 1,
  13391. minimum: 0
  13392. },
  13393. property: {
  13394. type: "string",
  13395. "default": "$zoom"
  13396. },
  13397. type: {
  13398. type: "enum",
  13399. values: {
  13400. identity: {
  13401. },
  13402. exponential: {
  13403. },
  13404. interval: {
  13405. },
  13406. categorical: {
  13407. }
  13408. },
  13409. "default": "exponential"
  13410. },
  13411. colorSpace: {
  13412. type: "enum",
  13413. values: {
  13414. rgb: {
  13415. },
  13416. lab: {
  13417. },
  13418. hcl: {
  13419. }
  13420. },
  13421. "default": "rgb"
  13422. },
  13423. "default": {
  13424. type: "*",
  13425. required: false
  13426. }
  13427. },
  13428. function_stop: function_stop,
  13429. expression: expression,
  13430. expression_name: expression_name,
  13431. light: light,
  13432. paint: paint,
  13433. paint_fill: paint_fill,
  13434. "paint_fill-extrusion": {
  13435. "fill-extrusion-opacity": {
  13436. type: "number",
  13437. "default": 1,
  13438. minimum: 0,
  13439. maximum: 1,
  13440. transition: true,
  13441. expression: {
  13442. interpolated: true,
  13443. parameters: [
  13444. "zoom"
  13445. ]
  13446. },
  13447. "property-type": "data-constant"
  13448. },
  13449. "fill-extrusion-color": {
  13450. type: "color",
  13451. "default": "#000000",
  13452. transition: true,
  13453. requires: [
  13454. {
  13455. "!": "fill-extrusion-pattern"
  13456. }
  13457. ],
  13458. expression: {
  13459. interpolated: true,
  13460. parameters: [
  13461. "zoom",
  13462. "feature",
  13463. "feature-state"
  13464. ]
  13465. },
  13466. "property-type": "data-driven"
  13467. },
  13468. "fill-extrusion-translate": {
  13469. type: "array",
  13470. value: "number",
  13471. length: 2,
  13472. "default": [
  13473. 0,
  13474. 0
  13475. ],
  13476. transition: true,
  13477. units: "pixels",
  13478. expression: {
  13479. interpolated: true,
  13480. parameters: [
  13481. "zoom"
  13482. ]
  13483. },
  13484. "property-type": "data-constant"
  13485. },
  13486. "fill-extrusion-translate-anchor": {
  13487. type: "enum",
  13488. values: {
  13489. map: {
  13490. },
  13491. viewport: {
  13492. }
  13493. },
  13494. "default": "map",
  13495. requires: [
  13496. "fill-extrusion-translate"
  13497. ],
  13498. expression: {
  13499. interpolated: false,
  13500. parameters: [
  13501. "zoom"
  13502. ]
  13503. },
  13504. "property-type": "data-constant"
  13505. },
  13506. "fill-extrusion-pattern": {
  13507. type: "resolvedImage",
  13508. transition: true,
  13509. expression: {
  13510. interpolated: false,
  13511. parameters: [
  13512. "zoom",
  13513. "feature"
  13514. ]
  13515. },
  13516. "property-type": "cross-faded-data-driven"
  13517. },
  13518. "fill-extrusion-height": {
  13519. type: "number",
  13520. "default": 0,
  13521. minimum: 0,
  13522. units: "meters",
  13523. transition: true,
  13524. expression: {
  13525. interpolated: true,
  13526. parameters: [
  13527. "zoom",
  13528. "feature",
  13529. "feature-state"
  13530. ]
  13531. },
  13532. "property-type": "data-driven"
  13533. },
  13534. "fill-extrusion-base": {
  13535. type: "number",
  13536. "default": 0,
  13537. minimum: 0,
  13538. units: "meters",
  13539. transition: true,
  13540. requires: [
  13541. "fill-extrusion-height"
  13542. ],
  13543. expression: {
  13544. interpolated: true,
  13545. parameters: [
  13546. "zoom",
  13547. "feature",
  13548. "feature-state"
  13549. ]
  13550. },
  13551. "property-type": "data-driven"
  13552. },
  13553. "fill-extrusion-vertical-gradient": {
  13554. type: "boolean",
  13555. "default": true,
  13556. transition: false,
  13557. expression: {
  13558. interpolated: false,
  13559. parameters: [
  13560. "zoom"
  13561. ]
  13562. },
  13563. "property-type": "data-constant"
  13564. }
  13565. },
  13566. paint_line: paint_line,
  13567. paint_circle: paint_circle,
  13568. paint_heatmap: paint_heatmap,
  13569. paint_symbol: paint_symbol,
  13570. paint_raster: paint_raster,
  13571. paint_hillshade: paint_hillshade,
  13572. paint_background: paint_background,
  13573. transition: transition,
  13574. "property-type": {
  13575. "data-driven": {
  13576. type: "property-type"
  13577. },
  13578. "cross-faded": {
  13579. type: "property-type"
  13580. },
  13581. "cross-faded-data-driven": {
  13582. type: "property-type"
  13583. },
  13584. "color-ramp": {
  13585. type: "property-type"
  13586. },
  13587. "data-constant": {
  13588. type: "property-type"
  13589. },
  13590. constant: {
  13591. type: "property-type"
  13592. }
  13593. }
  13594. };
  13595. function IntersectionTest() {
  13596. }
  13597. IntersectionTest.polygonIntersectsPolygon = function (polygonA, polygonB) {
  13598. for (var i = 0; i < polygonA.length; i++) {
  13599. if (polygonContainsPoint(polygonB, polygonA[i])) {
  13600. return true;
  13601. }
  13602. }
  13603. for (var i$1 = 0; i$1 < polygonB.length; i$1++) {
  13604. if (polygonContainsPoint(polygonA, polygonB[i$1])) {
  13605. return true;
  13606. }
  13607. }
  13608. if (lineIntersectsLine(polygonA, polygonB)) {
  13609. return true;
  13610. }
  13611. return false;
  13612. };
  13613. IntersectionTest.polygonIntersectsBufferedPoint = function (polygon, point, radius) {
  13614. if (polygonContainsPoint(polygon, point)) {
  13615. return true;
  13616. }
  13617. if (pointIntersectsBufferedLine(point, polygon, radius)) {
  13618. return true;
  13619. }
  13620. return false;
  13621. };
  13622. IntersectionTest.polygonIntersectsMultiPolygon = function (polygon, multiPolygon) {
  13623. if (polygon.length === 1) {
  13624. return multiPolygonContainsPoint(multiPolygon, polygon[0]);
  13625. }
  13626. for (var m = 0; m < multiPolygon.length; m++) {
  13627. var ring = multiPolygon[m];
  13628. for (var n = 0; n < ring.length; n++) {
  13629. if (polygonContainsPoint(polygon, ring[n])) {
  13630. return true;
  13631. }
  13632. }
  13633. }
  13634. for (var i = 0; i < polygon.length; i++) {
  13635. if (multiPolygonContainsPoint(multiPolygon, polygon[i])) {
  13636. return true;
  13637. }
  13638. }
  13639. for (var k = 0; k < multiPolygon.length; k++) {
  13640. if (lineIntersectsLine(polygon, multiPolygon[k])) {
  13641. return true;
  13642. }
  13643. }
  13644. return false;
  13645. };
  13646. IntersectionTest.polygonIntersectsBufferedMultiLine = function (polygon, multiLine, radius) {
  13647. for (var i = 0; i < multiLine.length; i++) {
  13648. var line = multiLine[i];
  13649. if (polygon.length >= 3) {
  13650. for (var k = 0; k < line.length; k++) {
  13651. if (polygonContainsPoint(polygon, line[k])) {
  13652. return true;
  13653. }
  13654. }
  13655. }
  13656. if (lineIntersectsBufferedLine(polygon, line, radius)) {
  13657. return true;
  13658. }
  13659. }
  13660. return false;
  13661. };
  13662. function lineIntersectsBufferedLine(lineA, lineB, radius) {
  13663. if (lineA.length > 1) {
  13664. if (lineIntersectsLine(lineA, lineB)) {
  13665. return true;
  13666. }
  13667. // Check whether any point in either line is within radius of the other line
  13668. for (var j = 0; j < lineB.length; j++) {
  13669. if (pointIntersectsBufferedLine(lineB[j], lineA, radius)) {
  13670. return true;
  13671. }
  13672. }
  13673. }
  13674. for (var k = 0; k < lineA.length; k++) {
  13675. if (pointIntersectsBufferedLine(lineA[k], lineB, radius)) {
  13676. return true;
  13677. }
  13678. }
  13679. return false;
  13680. }
  13681. function lineIntersectsLine(lineA, lineB) {
  13682. if (lineA.length === 0 || lineB.length === 0) {
  13683. return false;
  13684. }
  13685. for (var i = 0; i < lineA.length - 1; i++) {
  13686. var a0 = lineA[i];
  13687. var a1 = lineA[i + 1];
  13688. for (var j = 0; j < lineB.length - 1; j++) {
  13689. var b0 = lineB[j];
  13690. var b1 = lineB[j + 1];
  13691. if (lineSegmentIntersectsLineSegment(a0, a1, b0, b1)) {
  13692. return true;
  13693. }
  13694. }
  13695. }
  13696. return false;
  13697. }
  13698. function lineSegmentIntersectsLineSegment(a0, a1, b0, b1) {
  13699. return Util.isCounterClockwise(a0, b0, b1) !== Util.isCounterClockwise(a1, b0, b1) &&
  13700. Util.isCounterClockwise(a0, a1, b0) !== Util.isCounterClockwise(a0, a1, b1);
  13701. }
  13702. function pointIntersectsBufferedLine(p, line, radius) {
  13703. var radiusSquared = radius * radius;
  13704. if (line.length === 1) {
  13705. return p.distSqr(line[0]) < radiusSquared;
  13706. }
  13707. for (var i = 1; i < line.length; i++) {
  13708. // Find line segments that have a distance <= radius^2 to p
  13709. // In that case, we treat the line as "containing point p".
  13710. var v = line[i - 1], w = line[i];
  13711. if (IntersectionTest.distToSegmentSquared(p, v, w) < radiusSquared) {
  13712. return true;
  13713. }
  13714. }
  13715. return false;
  13716. }
  13717. // Code from http://stackoverflow.com/a/1501725/331379.
  13718. IntersectionTest.distToSegmentSquared = function (p, v, w) {
  13719. var l2 = v.distSqr(w);
  13720. if (l2 === 0) {
  13721. return p.distSqr(v);
  13722. }
  13723. var t = ((p.x - v.x) * (w.x - v.x) + (p.y - v.y) * (w.y - v.y)) / l2;
  13724. if (t < 0) {
  13725. return p.distSqr(v);
  13726. }
  13727. if (t > 1) {
  13728. return p.distSqr(w);
  13729. }
  13730. return p.distSqr(w.sub(v)._mult(t)._add(v));
  13731. };
  13732. // point in polygon ray casting algorithm
  13733. function multiPolygonContainsPoint(rings, p) {
  13734. var c = false,
  13735. ring, p1, p2;
  13736. for (var k = 0; k < rings.length; k++) {
  13737. ring = rings[k];
  13738. for (var i = 0, j = ring.length - 1; i < ring.length; j = i++) {
  13739. p1 = ring[i];
  13740. p2 = ring[j];
  13741. 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)) {
  13742. c = !c;
  13743. }
  13744. }
  13745. }
  13746. return c;
  13747. }
  13748. function polygonContainsPoint(ring, p) {
  13749. var c = false;
  13750. for (var i = 0, j = ring.length - 1; i < ring.length; j = i++) {
  13751. var p1 = ring[i];
  13752. var p2 = ring[j];
  13753. 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)) {
  13754. c = !c;
  13755. }
  13756. }
  13757. return c;
  13758. }
  13759. var layout$2 = new Properties({
  13760. "circle-sort-key": new DataDrivenProperty(StyleSpec["layout_circle"]["circle-sort-key"])
  13761. });
  13762. var paint$1 = new Properties({
  13763. "circle-radius": new DataDrivenProperty(StyleSpec["paint_circle"]["circle-radius"]),
  13764. "circle-color": new DataDrivenProperty(StyleSpec["paint_circle"]["circle-color"]),
  13765. "circle-blur": new DataDrivenProperty(StyleSpec["paint_circle"]["circle-blur"]),
  13766. "circle-opacity": new DataDrivenProperty(StyleSpec["paint_circle"]["circle-opacity"]),
  13767. "circle-translate": new DataConstantProperty(StyleSpec["paint_circle"]["circle-translate"]),
  13768. "circle-translate-anchor": new DataConstantProperty(StyleSpec["paint_circle"]["circle-translate-anchor"]),
  13769. "circle-pitch-scale": new DataConstantProperty(StyleSpec["paint_circle"]["circle-pitch-scale"]),
  13770. "circle-pitch-alignment": new DataConstantProperty(StyleSpec["paint_circle"]["circle-pitch-alignment"]),
  13771. "circle-stroke-width": new DataDrivenProperty(StyleSpec["paint_circle"]["circle-stroke-width"]),
  13772. "circle-stroke-color": new DataDrivenProperty(StyleSpec["paint_circle"]["circle-stroke-color"]),
  13773. "circle-stroke-opacity": new DataDrivenProperty(StyleSpec["paint_circle"]["circle-stroke-opacity"])
  13774. });
  13775. // Note: without adding the explicit type annotation, Flow infers weaker types
  13776. // for these objects from their use in the constructor to StyleLayer, as
  13777. // {layout?: Properties<...>, paint: Properties<...>}
  13778. var properties = ({ paint: paint$1, layout: layout$2 });
  13779. var CircleStyleLayer = /*@__PURE__*/(function (StyleLayer) {
  13780. function CircleStyleLayer(layer) {
  13781. StyleLayer.call(this, layer, properties);
  13782. }
  13783. if (StyleLayer) CircleStyleLayer.__proto__ = StyleLayer;
  13784. CircleStyleLayer.prototype = Object.create(StyleLayer && StyleLayer.prototype);
  13785. CircleStyleLayer.prototype.constructor = CircleStyleLayer;
  13786. CircleStyleLayer.prototype.createBucket = function createBucket(parameters) {
  13787. return new CircleBucket(parameters);
  13788. };
  13789. CircleStyleLayer.prototype.queryRadius = function queryRadius(bucket) {
  13790. var circleBucket = (bucket );
  13791. return QueryUtils.getMaximumPaintValue('circle-radius', this, circleBucket) +
  13792. QueryUtils.getMaximumPaintValue('circle-stroke-width', this, circleBucket) +
  13793. QueryUtils.translateDistance(this.paint.get('circle-translate'));
  13794. };
  13795. CircleStyleLayer.prototype.queryIntersectsFeature = function queryIntersectsFeature(queryGeometry, feature, featureState, geometry, zoom, transform, pixelsToTileUnits, pixelPosMatrix, adjustedScale) {
  13796. pixelPosMatrix = createMat4();
  13797. var translatedPolygon = QueryUtils.translate(queryGeometry,
  13798. this.paint.get('circle-translate'),
  13799. this.paint.get('circle-translate-anchor'),
  13800. 0, pixelsToTileUnits);
  13801. var radius = this.paint.get('circle-radius').evaluate(feature, featureState);
  13802. var stroke = this.paint.get('circle-stroke-width').evaluate(feature, featureState);
  13803. var size = radius + stroke;
  13804. // For pitch-alignment: map, compare feature geometry to query geometry in the plane of the tile
  13805. // // Otherwise, compare geometry in the plane of the viewport
  13806. // // A circle with fixed scaling relative to the viewport gets larger in tile space as it moves into the distance
  13807. // // A circle with fixed scaling relative to the map gets smaller in viewport space as it moves into the distance
  13808. var alignWithMap = this.paint.get('circle-pitch-alignment') === 'map';
  13809. var transformedPolygon = alignWithMap ? translatedPolygon : projectQueryGeometry(translatedPolygon, pixelPosMatrix);
  13810. var transformedSize = alignWithMap ? size * pixelsToTileUnits : size;
  13811. for (var i$1 = 0, list$1 = geometry; i$1 < list$1.length; i$1 += 1) {
  13812. var ring = list$1[i$1];
  13813. for (var i = 0, list = ring; i < list.length; i += 1) {
  13814. var point = list[i];
  13815. var transformedPoint = alignWithMap ? point : projectPoint(point, pixelPosMatrix);
  13816. var adjustedSize = transformedSize;
  13817. var projectedCenter = transformMat4([], [point.x, point.y, 0, 1], pixelPosMatrix);
  13818. 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') ;
  13819. adjustedScale = when.defined(adjustedScale) ? adjustedScale : 10.0;
  13820. if (IntersectionTest.polygonIntersectsBufferedPoint(transformedPolygon, transformedPoint, adjustedSize * adjustedScale)) {
  13821. return true;
  13822. }
  13823. }
  13824. }
  13825. return false;
  13826. };
  13827. return CircleStyleLayer;
  13828. }(StyleLayer));
  13829. function projectPoint(p, pixelPosMatrix) {
  13830. var point = transformMat4([], [p.x, p.y, 0, 1], pixelPosMatrix);
  13831. //return new pointGeometry(point[0] / point[3], point[1] / point[3]);
  13832. return new Point(point[0], point[1]);
  13833. }
  13834. function projectQueryGeometry(queryGeometry, pixelPosMatrix) {
  13835. return queryGeometry.map(function (p) {
  13836. return projectPoint(p, pixelPosMatrix);
  13837. });
  13838. }
  13839. function createMat4() {
  13840. var out = new Float32Array(16);
  13841. out[0] = 1;
  13842. out[5] = 1;
  13843. out[10] = 1;
  13844. out[15] = 1;
  13845. return out;
  13846. }
  13847. /**
  13848. * Transforms the vec3 with a mat4.
  13849. * 4th vector component is implicitly '1'
  13850. *
  13851. * @param {vec3} out the receiving vector
  13852. * @param {vec3} a the vector to transform
  13853. * @param {mat4} m matrix to transform with
  13854. * @returns {vec3} out
  13855. */
  13856. function transformMat4(out, a, m) {
  13857. var x = a[0],
  13858. y = a[1],
  13859. z = a[2];
  13860. var w = m[3] * x + m[7] * y + m[11] * z + m[15];
  13861. w = w || 1.0;
  13862. out[0] = (m[0] * x + m[4] * y + m[8] * z + m[12]) / w;
  13863. out[1] = (m[1] * x + m[5] * y + m[9] * z + m[13]) / w;
  13864. out[2] = (m[2] * x + m[6] * y + m[10] * z + m[14]) / w;
  13865. return out;
  13866. }
  13867. /**
  13868. * An implementation of `Property` for data driven `line-pattern` which are transitioned by cross-fading
  13869. * rather than interpolation.
  13870. *
  13871. * @private
  13872. */
  13873. var CrossFadedDataDrivenProperty = /*@__PURE__*/(function (DataDrivenProperty) {
  13874. function CrossFadedDataDrivenProperty() {
  13875. DataDrivenProperty.apply(this, arguments);
  13876. }
  13877. if (DataDrivenProperty) CrossFadedDataDrivenProperty.__proto__ = DataDrivenProperty;
  13878. CrossFadedDataDrivenProperty.prototype = Object.create(DataDrivenProperty && DataDrivenProperty.prototype);
  13879. CrossFadedDataDrivenProperty.prototype.constructor = CrossFadedDataDrivenProperty;
  13880. CrossFadedDataDrivenProperty.prototype.possiblyEvaluate = function possiblyEvaluate(value, parameters, availableImages) {
  13881. if (value.value === undefined) {
  13882. return new PossiblyEvaluatedPropertyValue$1(this, {kind: 'constant', value: undefined}, parameters);
  13883. } else if (value.expression.kind === 'constant') {
  13884. var evaluatedValue = value.expression.evaluate(parameters, (null ), {}, availableImages);
  13885. var isImageExpression = value.property.specification.type === 'resolvedImage';
  13886. var constantValue = isImageExpression && typeof evaluatedValue !== 'string' ? evaluatedValue.name : evaluatedValue;
  13887. var constant = this._calculate(constantValue, constantValue, constantValue, parameters);
  13888. return new PossiblyEvaluatedPropertyValue$1(this, {kind: 'constant', value: constant}, parameters);
  13889. } else if (value.expression.kind === 'camera') {
  13890. var cameraVal = this._calculate(
  13891. value.expression.evaluate({zoom: parameters.zoom - 1.0}),
  13892. value.expression.evaluate({zoom: parameters.zoom}),
  13893. value.expression.evaluate({zoom: parameters.zoom + 1.0}),
  13894. parameters);
  13895. return new PossiblyEvaluatedPropertyValue$1(this, {kind: 'constant', value: cameraVal}, parameters);
  13896. } else {
  13897. // source or composite expression
  13898. return new PossiblyEvaluatedPropertyValue$1(this, value.expression, parameters);
  13899. }
  13900. };
  13901. CrossFadedDataDrivenProperty.prototype.evaluate = function evaluate(value, globals, feature, featureState, availableImages) {
  13902. if (value.kind === 'source') {
  13903. var constant = value.evaluate(globals, feature, featureState, availableImages);
  13904. return this._calculate(constant, constant, constant, globals);
  13905. } else if (value.kind === 'composite') {
  13906. return this._calculate(
  13907. value.evaluate({zoom: Math.floor(globals.zoom) - 1.0}, feature, featureState),
  13908. value.evaluate({zoom: Math.floor(globals.zoom)}, feature, featureState),
  13909. value.evaluate({zoom: Math.floor(globals.zoom) + 1.0}, feature, featureState),
  13910. globals);
  13911. } else {
  13912. return value.value;
  13913. }
  13914. };
  13915. CrossFadedDataDrivenProperty.prototype._calculate = function _calculate(min, mid, max, parameters) {
  13916. var z = parameters.zoom;
  13917. return z > parameters.zoomHistory.lastIntegerZoom ? {from: min, to: mid} : {from: max, to: mid};
  13918. };
  13919. CrossFadedDataDrivenProperty.prototype.interpolate = function interpolate(a) {
  13920. return a;
  13921. };
  13922. return CrossFadedDataDrivenProperty;
  13923. }(DataDrivenProperty));
  13924. WebWorkerTransfer.register('DataDrivenProperty', DataDrivenProperty);
  13925. var layout$4 = new Properties({
  13926. "fill-sort-key": new DataDrivenProperty(StyleSpec["layout_fill"]["fill-sort-key"])
  13927. });
  13928. var paint$4 = new Properties({
  13929. "fill-antialias": new DataConstantProperty(StyleSpec["paint_fill"]["fill-antialias"]),
  13930. "fill-opacity": new DataDrivenProperty(StyleSpec["paint_fill"]["fill-opacity"]),
  13931. "fill-color": new DataDrivenProperty(StyleSpec["paint_fill"]["fill-color"]),
  13932. "fill-outline-color": new DataDrivenProperty(StyleSpec["paint_fill"]["fill-outline-color"]),
  13933. "fill-translate": new DataConstantProperty(StyleSpec["paint_fill"]["fill-translate"]),
  13934. "fill-translate-anchor": new DataConstantProperty(StyleSpec["paint_fill"]["fill-translate-anchor"]),
  13935. "fill-pattern": new CrossFadedDataDrivenProperty(StyleSpec["paint_fill"]["fill-pattern"]),
  13936. });
  13937. // Note: without adding the explicit type annotation, Flow infers weaker types
  13938. // for these objects from their use in the constructor to StyleLayer, as
  13939. // {layout?: Properties<...>, paint: Properties<...>}
  13940. var properties$3 = ({ paint: paint$4, layout: layout$4 }
  13941. );
  13942. var FillStyleLayer = /*@__PURE__*/(function (StyleLayer) {
  13943. function FillStyleLayer(layer) {
  13944. StyleLayer.call(this, layer, properties$3);
  13945. }
  13946. if (StyleLayer) FillStyleLayer.__proto__ = StyleLayer;
  13947. FillStyleLayer.prototype = Object.create(StyleLayer && StyleLayer.prototype);
  13948. FillStyleLayer.prototype.constructor = FillStyleLayer;
  13949. FillStyleLayer.prototype.recalculate = function recalculate(parameters, availableImages) {
  13950. StyleLayer.prototype.recalculate.call(this, parameters, availableImages);
  13951. var outlineColor = this.paint._values['fill-outline-color'];
  13952. if (outlineColor.value.kind === 'constant' && outlineColor.value.value === undefined) {
  13953. this.paint._values['fill-outline-color'] = this.paint._values['fill-color'];
  13954. }
  13955. };
  13956. FillStyleLayer.prototype.createBucket = function createBucket(parameters) {
  13957. return new FillBucket(parameters);
  13958. };
  13959. FillStyleLayer.prototype.queryRadius = function queryRadius() {
  13960. return QueryUtils.translateDistance(this.paint.get('fill-translate'));
  13961. };
  13962. FillStyleLayer.prototype.queryIntersectsFeature = function queryIntersectsFeature(queryGeometry, feature, featureState, geometry, zoom, transform, pixelsToTileUnits) {
  13963. var translatedPolygon = QueryUtils.translate(queryGeometry,
  13964. this.paint.get('fill-translate'),
  13965. this.paint.get('fill-translate-anchor'),
  13966. 0, pixelsToTileUnits);
  13967. return IntersectionTest.polygonIntersectsMultiPolygon(translatedPolygon, geometry);
  13968. };
  13969. FillStyleLayer.prototype.isTileClipped = function isTileClipped() {
  13970. return true;
  13971. };
  13972. return FillStyleLayer;
  13973. }(StyleLayer));
  13974. /**
  13975. * An implementation of `Property` for `*-pattern` and `line-dasharray`, which are transitioned by cross-fading
  13976. * rather than interpolation.
  13977. *
  13978. * @private
  13979. */
  13980. var CrossFadedProperty = function CrossFadedProperty(specification) {
  13981. this.specification = specification;
  13982. };
  13983. CrossFadedProperty.prototype.possiblyEvaluate = function possiblyEvaluate(value, parameters, availableImages) {
  13984. if (value.value === undefined) {
  13985. return undefined;
  13986. } else if (value.expression.kind === 'constant') {
  13987. var constant = value.expression.evaluate(parameters, (null ), {}, availableImages);
  13988. return this._calculate(constant, constant, constant, parameters);
  13989. } else {
  13990. //assert_1(!value.isDataDriven());
  13991. return this._calculate(
  13992. value.expression.evaluate(new EvaluationParameters(Math.floor(parameters.zoom - 1.0), parameters)),
  13993. value.expression.evaluate(new EvaluationParameters(Math.floor(parameters.zoom), parameters)),
  13994. value.expression.evaluate(new EvaluationParameters(Math.floor(parameters.zoom + 1.0), parameters)),
  13995. parameters);
  13996. }
  13997. };
  13998. CrossFadedProperty.prototype._calculate = function _calculate(min, mid, max, parameters) {
  13999. var z = parameters.zoom;
  14000. return z > parameters.zoomHistory.lastIntegerZoom ? {from: min, to: mid} : {from: max, to: mid};
  14001. };
  14002. CrossFadedProperty.prototype.interpolate = function interpolate(a) {
  14003. return a;
  14004. };
  14005. WebWorkerTransfer.register('CrossFadedProperty', CrossFadedProperty);
  14006. /**
  14007. * An implementation of `Property` for `heatmap-color` and `line-gradient`. Interpolation is a no-op, and
  14008. * evaluation returns a boolean value in order to indicate its presence, but the real
  14009. * evaluation happens in StyleLayer classes.
  14010. *
  14011. * @private
  14012. */
  14013. var ColorRampProperty = function ColorRampProperty(specification) {
  14014. this.specification = specification;
  14015. };
  14016. ColorRampProperty.prototype.possiblyEvaluate = function possiblyEvaluate(value, parameters, availableImages) {
  14017. return !!value.expression.evaluate(parameters, (null ), {}, availableImages);
  14018. };
  14019. ColorRampProperty.prototype.interpolate = function interpolate() {
  14020. return false;
  14021. };
  14022. WebWorkerTransfer.register('ColorRampProperty', ColorRampProperty);
  14023. var layout$6 = new Properties({
  14024. "line-cap": new DataConstantProperty(StyleSpec["layout_line"]["line-cap"]),
  14025. "line-join": new DataDrivenProperty(StyleSpec["layout_line"]["line-join"]),
  14026. "line-miter-limit": new DataConstantProperty(StyleSpec["layout_line"]["line-miter-limit"]),
  14027. "line-round-limit": new DataConstantProperty(StyleSpec["layout_line"]["line-round-limit"]),
  14028. "line-sort-key": new DataDrivenProperty(StyleSpec["layout_line"]["line-sort-key"])
  14029. });
  14030. var paint$6 = new Properties({
  14031. "line-opacity": new DataDrivenProperty(StyleSpec["paint_line"]["line-opacity"]),
  14032. "line-color": new DataDrivenProperty(StyleSpec["paint_line"]["line-color"]),
  14033. "line-translate": new DataConstantProperty(StyleSpec["paint_line"]["line-translate"]),
  14034. "line-translate-anchor": new DataConstantProperty(StyleSpec["paint_line"]["line-translate-anchor"]),
  14035. "line-width": new DataDrivenProperty(StyleSpec["paint_line"]["line-width"]),
  14036. "line-gap-width": new DataDrivenProperty(StyleSpec["paint_line"]["line-gap-width"]),
  14037. "line-offset": new DataDrivenProperty(StyleSpec["paint_line"]["line-offset"]),
  14038. "line-blur": new DataDrivenProperty(StyleSpec["paint_line"]["line-blur"]),
  14039. "line-dasharray": new CrossFadedProperty(StyleSpec["paint_line"]["line-dasharray"]),
  14040. "line-pattern": new CrossFadedDataDrivenProperty(StyleSpec["paint_line"]["line-pattern"]),
  14041. "line-gradient": new ColorRampProperty(StyleSpec["paint_line"]["line-gradient"])
  14042. });
  14043. // Note: without adding the explicit type annotation, Flow infers weaker types
  14044. // for these objects from their use in the constructor to StyleLayer, as
  14045. // {layout?: Properties<...>, paint: Properties<...>}
  14046. var properties$5 = ({ paint: paint$6, layout: layout$6 }
  14047. );
  14048. var LineFloorwidthProperty = /*@__PURE__*/(function (DataDrivenProperty) {
  14049. function LineFloorwidthProperty() {
  14050. DataDrivenProperty.apply(this, arguments);
  14051. }
  14052. if (DataDrivenProperty) LineFloorwidthProperty.__proto__ = DataDrivenProperty;
  14053. LineFloorwidthProperty.prototype = Object.create(DataDrivenProperty && DataDrivenProperty.prototype);
  14054. LineFloorwidthProperty.prototype.constructor = LineFloorwidthProperty;
  14055. LineFloorwidthProperty.prototype.possiblyEvaluate = function possiblyEvaluate(value, parameters) {
  14056. parameters = new EvaluationParameters$1(Math.floor(parameters.zoom), {
  14057. now: parameters.now,
  14058. fadeDuration: parameters.fadeDuration,
  14059. zoomHistory: parameters.zoomHistory,
  14060. transition: parameters.transition
  14061. });
  14062. return DataDrivenProperty.prototype.possiblyEvaluate.call(this, value, parameters);
  14063. };
  14064. LineFloorwidthProperty.prototype.evaluate = function evaluate(value, globals, feature, featureState) {
  14065. globals = extend({}, globals, {zoom: Math.floor(globals.zoom)});
  14066. return DataDrivenProperty.prototype.evaluate.call(this, value, globals, feature, featureState);
  14067. };
  14068. return LineFloorwidthProperty;
  14069. }(DataDrivenProperty));
  14070. var lineFloorwidthProperty = new LineFloorwidthProperty(properties$5.paint.properties['line-width'].specification);
  14071. lineFloorwidthProperty.useIntegerZoom = true;
  14072. var LineStyleLayer = /*@__PURE__*/(function (StyleLayer) {
  14073. function LineStyleLayer(layer) {
  14074. StyleLayer.call(this, layer, properties$5);
  14075. }
  14076. if (StyleLayer) LineStyleLayer.__proto__ = StyleLayer;
  14077. LineStyleLayer.prototype = Object.create(StyleLayer && StyleLayer.prototype);
  14078. LineStyleLayer.prototype.constructor = LineStyleLayer;
  14079. LineStyleLayer.prototype._handleSpecialPaintPropertyUpdate = function _handleSpecialPaintPropertyUpdate(name) {
  14080. if (name === 'line-gradient') {
  14081. this._updateGradient();
  14082. }
  14083. };
  14084. LineStyleLayer.prototype._updateGradient = function _updateGradient() {
  14085. var expression = this._transitionablePaint._values['line-gradient'].value.expression;
  14086. this.gradient = renderColorRamp(expression, 'lineProgress');
  14087. this.gradientTexture = null;
  14088. };
  14089. LineStyleLayer.prototype.recalculate = function recalculate(parameters, availableImages) {
  14090. StyleLayer.prototype.recalculate.call(this, parameters, availableImages);
  14091. (this.paint._values )['line-floorwidth'] =
  14092. lineFloorwidthProperty.possiblyEvaluate(this._transitioningPaint._values['line-width'].value, parameters);
  14093. };
  14094. LineStyleLayer.prototype.createBucket = function createBucket(parameters) {
  14095. return new LineBucket(parameters);
  14096. };
  14097. LineStyleLayer.prototype.queryRadius = function queryRadius(bucket) {
  14098. var lineBucket = (bucket );
  14099. var width = getLineWidth(
  14100. QueryUtils.getMaximumPaintValue('line-width', this, lineBucket),
  14101. QueryUtils.getMaximumPaintValue('line-gap-width', this, lineBucket));
  14102. var offset = QueryUtils.getMaximumPaintValue('line-offset', this, lineBucket);
  14103. return width / 2 + Math.abs(offset) + QueryUtils.translateDistance(this.paint.get('line-translate'));
  14104. };
  14105. LineStyleLayer.prototype.queryIntersectsFeature = function queryIntersectsFeature(queryGeometry, feature, featureState, geometry, zoom, transform, pixelsToTileUnits) {
  14106. var translatedPolygon = QueryUtils.translate(queryGeometry,
  14107. this.paint.get('line-translate'),
  14108. this.paint.get('line-translate-anchor'),
  14109. 0, pixelsToTileUnits);
  14110. var evaluatedLineWidth = getLineWidth(
  14111. this.paint.get('line-width').evaluate(feature, featureState),
  14112. this.paint.get('line-gap-width').evaluate(feature, featureState));
  14113. evaluatedLineWidth = Math.max(evaluatedLineWidth, 5.0);
  14114. var halfWidth = pixelsToTileUnits / 2 * evaluatedLineWidth;
  14115. var lineOffset = this.paint.get('line-offset').evaluate(feature, featureState);
  14116. if (lineOffset) {
  14117. geometry = offsetLine(geometry, lineOffset * pixelsToTileUnits);
  14118. }
  14119. return IntersectionTest.polygonIntersectsBufferedMultiLine(translatedPolygon, geometry, halfWidth);
  14120. };
  14121. LineStyleLayer.prototype.isTileClipped = function isTileClipped() {
  14122. return true;
  14123. };
  14124. function getLineWidth(lineWidth, lineGapWidth) {
  14125. if (lineGapWidth > 0) {
  14126. return lineGapWidth + 2 * lineWidth;
  14127. } else {
  14128. return lineWidth;
  14129. }
  14130. }
  14131. function offsetLine(rings, offset) {
  14132. var newRings = [];
  14133. var zero = new Point(0, 0);
  14134. for (var k = 0; k < rings.length; k++) {
  14135. var ring = rings[k];
  14136. var newRing = [];
  14137. for (var i = 0; i < ring.length; i++) {
  14138. var a = ring[i - 1];
  14139. var b = ring[i];
  14140. var c = ring[i + 1];
  14141. var aToB = i === 0 ? zero : b.sub(a)._unit()._perp();
  14142. var bToC = i === ring.length - 1 ? zero : c.sub(b)._unit()._perp();
  14143. var extrude = aToB._add(bToC)._unit();
  14144. var cosHalfAngle = extrude.x * bToC.x + extrude.y * bToC.y;
  14145. extrude._mult(1 / cosHalfAngle);
  14146. newRing.push(extrude._mult(offset)._add(b));
  14147. }
  14148. newRings.push(newRing);
  14149. }
  14150. return newRings;
  14151. }
  14152. return LineStyleLayer;
  14153. }(StyleLayer));
  14154. function SymbolAttributes() {
  14155. }
  14156. SymbolAttributes.symbolLayoutAttributes = createLayout([
  14157. {name: 'a_pos_offset', components: 4, type: 'Int16'},
  14158. {name: 'a_data', components: 4, type: 'Uint16'},
  14159. {name: 'a_pixeloffset', components: 4, type: 'Int16'}
  14160. ], 4);
  14161. SymbolAttributes.dynamicLayoutAttributes = createLayout([
  14162. {name: 'a_projected_pos', components: 3, type: 'Float32'}
  14163. ], 4);
  14164. SymbolAttributes.placementOpacityAttributes = createLayout([
  14165. {name: 'a_fade_opacity', components: 1, type: 'Uint32'}
  14166. ], 4);
  14167. SymbolAttributes.collisionVertexAttributes = createLayout([
  14168. {name: 'a_placed', components: 2, type: 'Uint8'},
  14169. {name: 'a_shift', components: 2, type: 'Float32'}
  14170. ]);
  14171. SymbolAttributes.collisionBox = createLayout([
  14172. // the box is centered around the anchor point
  14173. {type: 'Int16', name: 'anchorPointX'},
  14174. {type: 'Int16', name: 'anchorPointY'},
  14175. // distances to the edges from the anchor
  14176. {type: 'Int16', name: 'x1'},
  14177. {type: 'Int16', name: 'y1'},
  14178. {type: 'Int16', name: 'x2'},
  14179. {type: 'Int16', name: 'y2'},
  14180. // the index of the feature in the original vectortile
  14181. {type: 'Uint32', name: 'featureIndex'},
  14182. // the source layer the feature appears in
  14183. {type: 'Uint16', name: 'sourceLayerIndex'},
  14184. // the bucket the feature appears in
  14185. {type: 'Uint16', name: 'bucketIndex'},
  14186. // collision circles for lines store their distance to the anchor in tile units
  14187. // so that they can be ignored if the projected label doesn't extend into
  14188. // the box area
  14189. {type: 'Int16', name: 'radius'},
  14190. {type: 'Int16', name: 'signedDistanceFromAnchor'}
  14191. ]);
  14192. SymbolAttributes.collisionBoxLayout = createLayout([ // used to render collision boxes for debugging purposes
  14193. {name: 'a_pos', components: 2, type: 'Int16'},
  14194. {name: 'a_anchor_pos', components: 2, type: 'Int16'},
  14195. {name: 'a_extrude', components: 2, type: 'Int16'}
  14196. ], 4);
  14197. SymbolAttributes.collisionCircleLayout = createLayout([ // used to render collision circles for debugging purposes
  14198. {name: 'a_pos', components: 2, type: 'Int16'},
  14199. {name: 'a_anchor_pos', components: 2, type: 'Int16'},
  14200. {name: 'a_extrude', components: 2, type: 'Int16'}
  14201. ], 4);
  14202. SymbolAttributes.placement = createLayout([
  14203. {type: 'Int16', name: 'anchorX'},
  14204. {type: 'Int16', name: 'anchorY'},
  14205. {type: 'Uint16', name: 'glyphStartIndex'},
  14206. {type: 'Uint16', name: 'numGlyphs'},
  14207. {type: 'Uint32', name: 'vertexStartIndex'},
  14208. {type: 'Uint32', name: 'lineStartIndex'},
  14209. {type: 'Uint32', name: 'lineLength'},
  14210. {type: 'Uint16', name: 'segment'},
  14211. {type: 'Uint16', name: 'lowerSize'},
  14212. {type: 'Uint16', name: 'upperSize'},
  14213. {type: 'Float32', name: 'lineOffsetX'},
  14214. {type: 'Float32', name: 'lineOffsetY'},
  14215. {type: 'Uint8', name: 'writingMode'},
  14216. {type: 'Uint8', name: 'placedOrientation'},
  14217. {type: 'Uint8', name: 'hidden'},
  14218. {type: 'Uint32', name: 'crossTileID'},
  14219. {type: 'Int16', name: 'associatedIconIndex'}
  14220. ]);
  14221. SymbolAttributes.symbolInstance = createLayout([
  14222. {type: 'Int16', name: 'anchorX'},
  14223. {type: 'Int16', name: 'anchorY'},
  14224. {type: 'Int16', name: 'rightJustifiedTextSymbolIndex'},
  14225. {type: 'Int16', name: 'centerJustifiedTextSymbolIndex'},
  14226. {type: 'Int16', name: 'leftJustifiedTextSymbolIndex'},
  14227. {type: 'Int16', name: 'verticalPlacedTextSymbolIndex'},
  14228. {type: 'Int16', name: 'placedIconSymbolIndex'},
  14229. {type: 'Int16', name: 'verticalPlacedIconSymbolIndex'},
  14230. {type: 'Uint16', name: 'key'},
  14231. {type: 'Uint16', name: 'textBoxStartIndex'},
  14232. {type: 'Uint16', name: 'textBoxEndIndex'},
  14233. {type: 'Uint16', name: 'verticalTextBoxStartIndex'},
  14234. {type: 'Uint16', name: 'verticalTextBoxEndIndex'},
  14235. {type: 'Uint16', name: 'iconBoxStartIndex'},
  14236. {type: 'Uint16', name: 'iconBoxEndIndex'},
  14237. {type: 'Uint16', name: 'verticalIconBoxStartIndex'},
  14238. {type: 'Uint16', name: 'verticalIconBoxEndIndex'},
  14239. {type: 'Uint16', name: 'featureIndex'},
  14240. {type: 'Uint16', name: 'numHorizontalGlyphVertices'},
  14241. {type: 'Uint16', name: 'numVerticalGlyphVertices'},
  14242. {type: 'Uint16', name: 'numIconVertices'},
  14243. {type: 'Uint16', name: 'numVerticalIconVertices'},
  14244. {type: 'Uint32', name: 'crossTileID'},
  14245. {type: 'Float32', name: 'textBoxScale'},
  14246. {type: 'Float32', components: 2, name: 'textOffset'}
  14247. ]);
  14248. SymbolAttributes.glyphOffset = createLayout([
  14249. {type: 'Float32', name: 'offsetX'}
  14250. ]);
  14251. SymbolAttributes.lineVertex = createLayout([
  14252. {type: 'Int16', name: 'x'},
  14253. {type: 'Int16', name: 'y'},
  14254. {type: 'Int16', name: 'tileUnitDistanceFromAnchor'}
  14255. ]);
  14256. function mergeLines(features) {
  14257. var leftIndex = {};
  14258. var rightIndex = {};
  14259. var mergedFeatures = [];
  14260. var mergedIndex = 0;
  14261. function add(k) {
  14262. mergedFeatures.push(features[k]);
  14263. mergedIndex++;
  14264. }
  14265. function mergeFromRight(leftKey, rightKey, geom) {
  14266. var i = rightIndex[leftKey];
  14267. delete rightIndex[leftKey];
  14268. rightIndex[rightKey] = i;
  14269. mergedFeatures[i].geometry[0].pop();
  14270. mergedFeatures[i].geometry[0] = mergedFeatures[i].geometry[0].concat(geom[0]);
  14271. return i;
  14272. }
  14273. function mergeFromLeft(leftKey, rightKey, geom) {
  14274. var i = leftIndex[rightKey];
  14275. delete leftIndex[rightKey];
  14276. leftIndex[leftKey] = i;
  14277. mergedFeatures[i].geometry[0].shift();
  14278. mergedFeatures[i].geometry[0] = geom[0].concat(mergedFeatures[i].geometry[0]);
  14279. return i;
  14280. }
  14281. function getKey(text, geom, onRight) {
  14282. var point = onRight ? geom[0][geom[0].length - 1] : geom[0][0];
  14283. return (text + ":" + (point.x) + ":" + (point.y));
  14284. }
  14285. for (var k = 0; k < features.length; k++) {
  14286. var feature = features[k];
  14287. var geom = feature.geometry;
  14288. var text = feature.text ? feature.text.toString() : null;
  14289. if (!text) {
  14290. add(k);
  14291. continue;
  14292. }
  14293. var leftKey = getKey(text, geom),
  14294. rightKey = getKey(text, geom, true);
  14295. if ((leftKey in rightIndex) && (rightKey in leftIndex) && (rightIndex[leftKey] !== leftIndex[rightKey])) {
  14296. // found lines with the same text adjacent to both ends of the current line, merge all three
  14297. var j = mergeFromLeft(leftKey, rightKey, geom);
  14298. var i = mergeFromRight(leftKey, rightKey, mergedFeatures[j].geometry);
  14299. delete leftIndex[leftKey];
  14300. delete rightIndex[rightKey];
  14301. rightIndex[getKey(text, mergedFeatures[i].geometry, true)] = i;
  14302. mergedFeatures[j].geometry = (null );
  14303. } else if (leftKey in rightIndex) {
  14304. // found mergeable line adjacent to the start of the current line, merge
  14305. mergeFromRight(leftKey, rightKey, geom);
  14306. } else if (rightKey in leftIndex) {
  14307. // found mergeable line adjacent to the end of the current line, merge
  14308. mergeFromLeft(leftKey, rightKey, geom);
  14309. } else {
  14310. // no adjacent lines, add as a new item
  14311. add(k);
  14312. leftIndex[leftKey] = mergedIndex - 1;
  14313. rightIndex[rightKey] = mergedIndex - 1;
  14314. }
  14315. }
  14316. return mergedFeatures.filter(function (f) {
  14317. return f.geometry;
  14318. });
  14319. }
  14320. var Shaping = function Shaping() {
  14321. };
  14322. Shaping.WritingMode = {
  14323. horizontal: 1,
  14324. vertical: 2,
  14325. horizontalOnly: 3
  14326. };
  14327. // The position of a glyph relative to the text's anchor point.
  14328. // A collection of positioned glyphs and some metadata
  14329. function isEmpty(positionedLines) {
  14330. for (var i = 0, list = positionedLines; i < list.length; i += 1) {
  14331. var line = list[i];
  14332. if (line.positionedGlyphs.length !== 0) {
  14333. return false;
  14334. }
  14335. }
  14336. return true;
  14337. }
  14338. // Max number of images in label is 6401 U+E000–U+F8FF that covers
  14339. // Basic Multilingual Plane Unicode Private Use Area (PUA).
  14340. var PUAbegin = 0xE000;
  14341. var PUAend = 0xF8FF;
  14342. var SectionOptions = function SectionOptions() {
  14343. this.scale = 1.0;
  14344. this.fontStack = "";
  14345. this.imageName = null;
  14346. };
  14347. SectionOptions.forText = function forText(scale, fontStack) {
  14348. var textOptions = new SectionOptions();
  14349. textOptions.scale = scale || 1;
  14350. textOptions.fontStack = fontStack;
  14351. return textOptions;
  14352. };
  14353. SectionOptions.forImage = function forImage(imageName) {
  14354. var imageOptions = new SectionOptions();
  14355. imageOptions.imageName = imageName;
  14356. return imageOptions;
  14357. };
  14358. var TaggedString = function TaggedString() {
  14359. this.text = "";
  14360. this.sectionIndex = [];
  14361. this.sections = [];
  14362. this.imageSectionID = null;
  14363. };
  14364. TaggedString.fromFeature = function fromFeature(text, defaultFontStack) {
  14365. var result = new TaggedString();
  14366. for (var i = 0; i < text.sections.length; i++) {
  14367. var section = text.sections[i];
  14368. if (!section.image) {
  14369. result.addTextSection(section, defaultFontStack);
  14370. } else {
  14371. result.addImageSection(section);
  14372. }
  14373. }
  14374. return result;
  14375. };
  14376. TaggedString.prototype.length = function length() {
  14377. return this.text.length;
  14378. };
  14379. TaggedString.prototype.getSection = function getSection(index) {
  14380. return this.sections[this.sectionIndex[index]];
  14381. };
  14382. TaggedString.prototype.getSectionIndex = function getSectionIndex(index) {
  14383. return this.sectionIndex[index];
  14384. };
  14385. TaggedString.prototype.getCharCode = function getCharCode(index) {
  14386. return this.text.charCodeAt(index);
  14387. };
  14388. TaggedString.prototype.verticalizePunctuation = function verticalizePunctuation$1() {
  14389. //this.text = verticalizePunctuation(this.text);
  14390. };
  14391. TaggedString.prototype.trim = function trim() {
  14392. var beginningWhitespace = 0;
  14393. for (var i = 0;
  14394. i < this.text.length && whitespace[this.text.charCodeAt(i)];
  14395. i++) {
  14396. beginningWhitespace++;
  14397. }
  14398. var trailingWhitespace = this.text.length;
  14399. for (var i$1 = this.text.length - 1;
  14400. i$1 >= 0 && i$1 >= beginningWhitespace && whitespace[this.text.charCodeAt(i$1)];
  14401. i$1--) {
  14402. trailingWhitespace--;
  14403. }
  14404. this.text = this.text.substring(beginningWhitespace, trailingWhitespace);
  14405. this.sectionIndex = this.sectionIndex.slice(beginningWhitespace, trailingWhitespace);
  14406. };
  14407. TaggedString.prototype.substring = function substring(start, end) {
  14408. var substring = new TaggedString();
  14409. substring.text = this.text.substring(start, end);
  14410. substring.sectionIndex = this.sectionIndex.slice(start, end);
  14411. substring.sections = this.sections;
  14412. return substring;
  14413. };
  14414. TaggedString.prototype.toString = function toString() {
  14415. return this.text;
  14416. };
  14417. TaggedString.prototype.getMaxScale = function getMaxScale() {
  14418. var this$1 = this;
  14419. return this.sectionIndex.reduce(function (max, index) {
  14420. return Math.max(max, this$1.sections[index].scale);
  14421. }, 0);
  14422. };
  14423. TaggedString.prototype.addTextSection = function addTextSection(section, defaultFontStack) {
  14424. this.text += section.text;
  14425. this.sections.push(SectionOptions.forText(section.scale, section.fontStack || defaultFontStack));
  14426. var index = this.sections.length - 1;
  14427. for (var i = 0; i < section.text.length; ++i) {
  14428. this.sectionIndex.push(index);
  14429. }
  14430. };
  14431. TaggedString.prototype.addImageSection = function addImageSection(section) {
  14432. var imageName = section.image ? section.image.name : '';
  14433. if (imageName.length === 0) {
  14434. //warnOnce("Can't add FormattedSection with an empty image.");
  14435. return;
  14436. }
  14437. var nextImageSectionCharCode = this.getNextImageSectionCharCode();
  14438. if (!nextImageSectionCharCode) {
  14439. //warnOnce(("Reached maximum number of images " + (PUAend - PUAbegin + 2)));
  14440. return;
  14441. }
  14442. this.text += String.fromCharCode(nextImageSectionCharCode);
  14443. this.sections.push(SectionOptions.forImage(imageName));
  14444. this.sectionIndex.push(this.sections.length - 1);
  14445. };
  14446. TaggedString.prototype.getNextImageSectionCharCode = function getNextImageSectionCharCode() {
  14447. if (!this.imageSectionID) {
  14448. this.imageSectionID = PUAbegin;
  14449. return this.imageSectionID;
  14450. }
  14451. if (this.imageSectionID >= PUAend) {
  14452. return null;
  14453. }
  14454. return ++this.imageSectionID;
  14455. };
  14456. function breakLines(input, lineBreakPoints) {
  14457. var lines = [];
  14458. var text = input.text;
  14459. var start = 0;
  14460. for (var i = 0, list = lineBreakPoints; i < list.length; i += 1) {
  14461. var lineBreak = list[i];
  14462. lines.push(input.substring(start, lineBreak));
  14463. start = lineBreak;
  14464. }
  14465. if (start < text.length) {
  14466. lines.push(input.substring(start, text.length));
  14467. }
  14468. return lines;
  14469. }
  14470. Shaping.shapeText = function(text, glyphMap, glyphPositions, imagePositions, defaultFontStack, maxWidth, lineHeight, textAnchor, textJustify, spacing, translate, writingMode, allowVerticalPlacement, symbolPlacement, layoutTextSize, layoutTextSizeThisZoom){
  14471. var logicalInput = TaggedString.fromFeature(text, defaultFontStack);
  14472. if (writingMode === Shaping.WritingMode.vertical) {
  14473. logicalInput.verticalizePunctuation();
  14474. }
  14475. var lines;
  14476. {
  14477. lines = breakLines(logicalInput, determineLineBreaks());
  14478. }
  14479. var positionedLines = [];
  14480. var shaping = {
  14481. positionedLines: positionedLines,
  14482. text: logicalInput.toString(),
  14483. top: translate[1],
  14484. bottom: translate[1],
  14485. left: translate[0],
  14486. right: translate[0],
  14487. writingMode: writingMode,
  14488. iconsInText: false,
  14489. verticalizable: false
  14490. };
  14491. if (isEmpty(positionedLines)) {
  14492. return false;
  14493. }
  14494. return shaping;
  14495. };
  14496. // using computed properties due to https://github.com/facebook/flow/issues/380
  14497. /* eslint no-useless-computed-key: 0 */
  14498. var whitespace = {};
  14499. whitespace[0x09] = true;
  14500. whitespace[0x0a] = true;
  14501. whitespace[0x0b] = true;
  14502. whitespace[0x0c] = true;
  14503. whitespace[0x0d] = true;
  14504. whitespace[0x20] = true;
  14505. function determineLineBreaks(logicalInput, spacing, maxWidth, glyphMap, imagePositions, symbolPlacement, layoutTextSize) {
  14506. // if (symbolPlacement !== 'point') {
  14507. // return [];
  14508. // }
  14509. //
  14510. // if (!logicalInput) {
  14511. // return [];
  14512. // }
  14513. //
  14514. // var potentialLineBreaks = [];
  14515. // var targetWidth = determineAverageLineWidth(logicalInput, spacing, maxWidth, glyphMap, imagePositions, layoutTextSize);
  14516. //
  14517. // var hasServerSuggestedBreakpoints = logicalInput.text.indexOf("\u200b") >= 0;
  14518. //
  14519. // var currentX = 0;
  14520. //
  14521. // for (var i = 0; i < logicalInput.length(); i++) {
  14522. // var section = logicalInput.getSection(i);
  14523. // var codePoint = logicalInput.getCharCode(i);
  14524. // if (!whitespace[codePoint]) {
  14525. // currentX += getGlyphAdvance(codePoint, section, glyphMap, imagePositions, spacing, layoutTextSize);
  14526. // }
  14527. //
  14528. // // Ideographic characters, spaces, and word-breaking punctuation that often appear without
  14529. // // surrounding spaces.
  14530. // if ((i < logicalInput.length() - 1)) {
  14531. // var ideographicBreak = charAllowsIdeographicBreaking(codePoint);
  14532. // if (breakable[codePoint] || ideographicBreak || section.imageName) {
  14533. //
  14534. // potentialLineBreaks.push(
  14535. // evaluateBreak(
  14536. // i + 1,
  14537. // currentX,
  14538. // targetWidth,
  14539. // potentialLineBreaks,
  14540. // calculatePenalty(codePoint, logicalInput.getCharCode(i + 1), ideographicBreak && hasServerSuggestedBreakpoints),
  14541. // false));
  14542. // }
  14543. // }
  14544. // }
  14545. //
  14546. // return leastBadBreaks(
  14547. // evaluateBreak(
  14548. // logicalInput.length(),
  14549. // currentX,
  14550. // targetWidth,
  14551. // potentialLineBreaks,
  14552. // 0,
  14553. // true));
  14554. }
  14555. function getAnchorAlignment(anchor) {
  14556. var horizontalAlign = 0.5, verticalAlign = 0.5;
  14557. switch (anchor) {
  14558. case 'right':
  14559. case 'top-right':
  14560. case 'bottom-right':
  14561. horizontalAlign = 1;
  14562. break;
  14563. case 'left':
  14564. case 'top-left':
  14565. case 'bottom-left':
  14566. horizontalAlign = 0;
  14567. break;
  14568. }
  14569. switch (anchor) {
  14570. case 'bottom':
  14571. case 'bottom-right':
  14572. case 'bottom-left':
  14573. verticalAlign = 1;
  14574. break;
  14575. case 'top':
  14576. case 'top-right':
  14577. case 'top-left':
  14578. verticalAlign = 0;
  14579. break;
  14580. }
  14581. return {horizontalAlign: horizontalAlign, verticalAlign: verticalAlign};
  14582. }
  14583. Shaping.shapeIcon = function(image, iconOffset, iconAnchor){
  14584. var ref = getAnchorAlignment(iconAnchor);
  14585. var horizontalAlign = ref.horizontalAlign;
  14586. var verticalAlign = ref.verticalAlign;
  14587. var dx = iconOffset[0];
  14588. var dy = iconOffset[1];
  14589. var x1 = dx - image.displaySize[0] * horizontalAlign;
  14590. var x2 = x1 + image.displaySize[0];
  14591. var y1 = dy - image.displaySize[1] * verticalAlign;
  14592. var y2 = y1 + image.displaySize[1];
  14593. return {image: image, top: y1, bottom: y2, left: x1, right: x2};
  14594. };
  14595. Shaping.fitIconToText = function(shapedIcon, shapedText, textFit, padding, iconOffset, fontScale){
  14596. // assert_1(textFit !== 'none');
  14597. // assert_1(Array.isArray(padding) && padding.length === 4);
  14598. // assert_1(Array.isArray(iconOffset) && iconOffset.length === 2);
  14599. var image = shapedIcon.image;
  14600. var collisionPadding;
  14601. if (image.content) {
  14602. var content = image.content;
  14603. var pixelRatio = image.pixelRatio || 1;
  14604. collisionPadding = [
  14605. content[0] / pixelRatio,
  14606. content[1] / pixelRatio,
  14607. image.displaySize[0] - content[2] / pixelRatio,
  14608. image.displaySize[1] - content[3] / pixelRatio
  14609. ];
  14610. }
  14611. // We don't respect the icon-anchor, because icon-text-fit is set. Instead,
  14612. // the icon will be centered on the text, then stretched in the given
  14613. // dimensions.
  14614. var textLeft = shapedText.left * fontScale;
  14615. var textRight = shapedText.right * fontScale;
  14616. var top, right, bottom, left;
  14617. if (textFit === 'width' || textFit === 'both') {
  14618. // Stretched horizontally to the text width
  14619. left = iconOffset[0] + textLeft - padding[3];
  14620. right = iconOffset[0] + textRight + padding[1];
  14621. } else {
  14622. // Centered on the text
  14623. left = iconOffset[0] + (textLeft + textRight - image.displaySize[0]) / 2;
  14624. right = left + image.displaySize[0];
  14625. }
  14626. var textTop = shapedText.top * fontScale;
  14627. var textBottom = shapedText.bottom * fontScale;
  14628. if (textFit === 'height' || textFit === 'both') {
  14629. // Stretched vertically to the text height
  14630. top = iconOffset[1] + textTop - padding[0];
  14631. bottom = iconOffset[1] + textBottom + padding[2];
  14632. } else {
  14633. // Centered on the text
  14634. top = iconOffset[1] + (textTop + textBottom - image.displaySize[1]) / 2;
  14635. bottom = top + image.displaySize[1];
  14636. }
  14637. return {image: image, top: top, right: right, bottom: bottom, left: left, collisionPadding: collisionPadding};
  14638. };
  14639. var SIZE_PACK_FACTOR = 128;
  14640. // For {text,icon}-size, get the bucket-level data that will be needed by
  14641. // the painter to set symbol-size-related uniforms
  14642. function getSizeData(tileZoom, value) {
  14643. var expression = value.expression;
  14644. if (expression.kind === 'constant') {
  14645. var layoutSize = expression.evaluate(new EvaluationParameters$1(tileZoom + 1));
  14646. return {kind: 'constant', layoutSize: layoutSize};
  14647. } else if (expression.kind === 'source') {
  14648. return {kind: 'source'};
  14649. } else {
  14650. var zoomStops = expression.zoomStops;
  14651. var interpolationType = expression.interpolationType;
  14652. // calculate covering zoom stops for zoom-dependent values
  14653. var lower = 0;
  14654. while (lower < zoomStops.length && zoomStops[lower] <= tileZoom) {
  14655. lower++;
  14656. }
  14657. lower = Math.max(0, lower - 1);
  14658. var upper = lower;
  14659. while (upper < zoomStops.length && zoomStops[upper] < tileZoom + 1) {
  14660. upper++;
  14661. }
  14662. upper = Math.min(zoomStops.length - 1, upper);
  14663. var minZoom = zoomStops[lower];
  14664. var maxZoom = zoomStops[upper];
  14665. // We'd like to be able to use CameraExpression or CompositeExpression in these
  14666. // return types rather than ExpressionSpecification, but the former are not
  14667. // transferrable across Web Worker boundaries.
  14668. if (expression.kind === 'composite') {
  14669. return {kind: 'composite', minZoom: minZoom, maxZoom: maxZoom, interpolationType: interpolationType};
  14670. }
  14671. // for camera functions, also save off the function values
  14672. // evaluated at the covering zoom levels
  14673. var minSize = expression.evaluate(new EvaluationParameters$1(minZoom));
  14674. var maxSize = expression.evaluate(new EvaluationParameters$1(maxZoom));
  14675. return {kind: 'camera', minZoom: minZoom, maxZoom: maxZoom, minSize: minSize, maxSize: maxSize, interpolationType: interpolationType};
  14676. }
  14677. }
  14678. function evaluateSizeForFeature(sizeData, ref, ref$1) {
  14679. var uSize = ref.uSize;
  14680. var uSizeT = ref.uSizeT;
  14681. var lowerSize = ref$1.lowerSize;
  14682. var upperSize = ref$1.upperSize;
  14683. if (sizeData.kind === 'source') {
  14684. return lowerSize / SIZE_PACK_FACTOR;
  14685. } else if (sizeData.kind === 'composite') {
  14686. return number(lowerSize / SIZE_PACK_FACTOR, upperSize / SIZE_PACK_FACTOR, uSizeT);
  14687. }
  14688. return uSize;
  14689. }
  14690. function evaluateSizeForZoom(sizeData, zoom) {
  14691. var uSizeT = 0;
  14692. var uSize = 0;
  14693. if (sizeData.kind === 'constant') {
  14694. uSize = sizeData.layoutSize;
  14695. } else if (sizeData.kind !== 'source') {
  14696. var interpolationType = sizeData.interpolationType;
  14697. var minZoom = sizeData.minZoom;
  14698. var maxZoom = sizeData.maxZoom;
  14699. // Even though we could get the exact value of the camera function
  14700. // at z = tr.zoom, we intentionally do not: instead, we interpolate
  14701. // between the camera function values at a pair of zoom stops covering
  14702. // [tileZoom, tileZoom + 1] in order to be consistent with this
  14703. // restriction on composite functions
  14704. // var t = !interpolationType ? 0 : clamp(
  14705. // Interpolate.interpolationFactor(interpolationType, zoom, minZoom, maxZoom), 0, 1);
  14706. var t = 0;
  14707. if (sizeData.kind === 'camera') {
  14708. uSize = number(sizeData.minSize, sizeData.maxSize, t);
  14709. } else {
  14710. uSizeT = t;
  14711. }
  14712. }
  14713. return {uSizeT: uSizeT, uSize: uSize};
  14714. }
  14715. var symbolSize = /*#__PURE__*/Object.freeze({
  14716. __proto__: null,
  14717. getSizeData: getSizeData,
  14718. evaluateSizeForFeature: evaluateSizeForFeature,
  14719. evaluateSizeForZoom: evaluateSizeForZoom,
  14720. SIZE_PACK_FACTOR: SIZE_PACK_FACTOR
  14721. });
  14722. function transformText(text, layer, feature) {
  14723. var transform = layer.layout.get('text-transform').evaluate(feature, {});
  14724. if (transform === 'uppercase') {
  14725. text = text.toLocaleUpperCase();
  14726. } else if (transform === 'lowercase') {
  14727. text = text.toLocaleLowerCase();
  14728. }
  14729. // if (plugin.applyArabicShaping) {
  14730. // text = plugin.applyArabicShaping(text);
  14731. // }
  14732. return text;
  14733. }
  14734. function transformText$1(text, layer, feature) {
  14735. text.sections.forEach(function (section) {
  14736. section.text = transformText(section.text, layer, feature);
  14737. });
  14738. return text;
  14739. }
  14740. // The following table comes from <http://www.unicode.org/Public/12.0.0/ucd/Blocks.txt>.
  14741. // Keep it synchronized with <http://www.unicode.org/Public/UCD/latest/ucd/Blocks.txt>.
  14742. var unicodeBlockLookup = {
  14743. // 'Basic Latin': (char) => char >= 0x0000 && char <= 0x007F,
  14744. 'Latin-1 Supplement': function (char) {
  14745. return char >= 0x0080 && char <= 0x00FF;
  14746. },
  14747. // 'Latin Extended-A': (char) => char >= 0x0100 && char <= 0x017F,
  14748. // 'Latin Extended-B': (char) => char >= 0x0180 && char <= 0x024F,
  14749. // 'IPA Extensions': (char) => char >= 0x0250 && char <= 0x02AF,
  14750. // 'Spacing Modifier Letters': (char) => char >= 0x02B0 && char <= 0x02FF,
  14751. // 'Combining Diacritical Marks': (char) => char >= 0x0300 && char <= 0x036F,
  14752. // 'Greek and Coptic': (char) => char >= 0x0370 && char <= 0x03FF,
  14753. // 'Cyrillic': (char) => char >= 0x0400 && char <= 0x04FF,
  14754. // 'Cyrillic Supplement': (char) => char >= 0x0500 && char <= 0x052F,
  14755. // 'Armenian': (char) => char >= 0x0530 && char <= 0x058F,
  14756. //'Hebrew': (char) => char >= 0x0590 && char <= 0x05FF,
  14757. 'Arabic': function (char) {
  14758. return char >= 0x0600 && char <= 0x06FF;
  14759. },
  14760. //'Syriac': (char) => char >= 0x0700 && char <= 0x074F,
  14761. 'Arabic Supplement': function (char) {
  14762. return char >= 0x0750 && char <= 0x077F;
  14763. },
  14764. // 'Thaana': (char) => char >= 0x0780 && char <= 0x07BF,
  14765. // 'NKo': (char) => char >= 0x07C0 && char <= 0x07FF,
  14766. // 'Samaritan': (char) => char >= 0x0800 && char <= 0x083F,
  14767. // 'Mandaic': (char) => char >= 0x0840 && char <= 0x085F,
  14768. // 'Syriac Supplement': (char) => char >= 0x0860 && char <= 0x086F,
  14769. 'Arabic Extended-A': function (char) {
  14770. return char >= 0x08A0 && char <= 0x08FF;
  14771. },
  14772. // 'Devanagari': (char) => char >= 0x0900 && char <= 0x097F,
  14773. // 'Bengali': (char) => char >= 0x0980 && char <= 0x09FF,
  14774. // 'Gurmukhi': (char) => char >= 0x0A00 && char <= 0x0A7F,
  14775. // 'Gujarati': (char) => char >= 0x0A80 && char <= 0x0AFF,
  14776. // 'Oriya': (char) => char >= 0x0B00 && char <= 0x0B7F,
  14777. // 'Tamil': (char) => char >= 0x0B80 && char <= 0x0BFF,
  14778. // 'Telugu': (char) => char >= 0x0C00 && char <= 0x0C7F,
  14779. // 'Kannada': (char) => char >= 0x0C80 && char <= 0x0CFF,
  14780. // 'Malayalam': (char) => char >= 0x0D00 && char <= 0x0D7F,
  14781. // 'Sinhala': (char) => char >= 0x0D80 && char <= 0x0DFF,
  14782. // 'Thai': (char) => char >= 0x0E00 && char <= 0x0E7F,
  14783. // 'Lao': (char) => char >= 0x0E80 && char <= 0x0EFF,
  14784. // 'Tibetan': (char) => char >= 0x0F00 && char <= 0x0FFF,
  14785. // 'Myanmar': (char) => char >= 0x1000 && char <= 0x109F,
  14786. // 'Georgian': (char) => char >= 0x10A0 && char <= 0x10FF,
  14787. 'Hangul Jamo': function (char) {
  14788. return char >= 0x1100 && char <= 0x11FF;
  14789. },
  14790. // 'Ethiopic': (char) => char >= 0x1200 && char <= 0x137F,
  14791. // 'Ethiopic Supplement': (char) => char >= 0x1380 && char <= 0x139F,
  14792. // 'Cherokee': (char) => char >= 0x13A0 && char <= 0x13FF,
  14793. 'Unified Canadian Aboriginal Syllabics': function (char) {
  14794. return char >= 0x1400 && char <= 0x167F;
  14795. },
  14796. // 'Ogham': (char) => char >= 0x1680 && char <= 0x169F,
  14797. // 'Runic': (char) => char >= 0x16A0 && char <= 0x16FF,
  14798. // 'Tagalog': (char) => char >= 0x1700 && char <= 0x171F,
  14799. // 'Hanunoo': (char) => char >= 0x1720 && char <= 0x173F,
  14800. // 'Buhid': (char) => char >= 0x1740 && char <= 0x175F,
  14801. // 'Tagbanwa': (char) => char >= 0x1760 && char <= 0x177F,
  14802. 'Khmer': function (char) {
  14803. return char >= 0x1780 && char <= 0x17FF;
  14804. },
  14805. // 'Mongolian': (char) => char >= 0x1800 && char <= 0x18AF,
  14806. 'Unified Canadian Aboriginal Syllabics Extended': function (char) {
  14807. return char >= 0x18B0 && char <= 0x18FF;
  14808. },
  14809. // 'Limbu': (char) => char >= 0x1900 && char <= 0x194F,
  14810. // 'Tai Le': (char) => char >= 0x1950 && char <= 0x197F,
  14811. // 'New Tai Lue': (char) => char >= 0x1980 && char <= 0x19DF,
  14812. // 'Khmer Symbols': (char) => char >= 0x19E0 && char <= 0x19FF,
  14813. // 'Buginese': (char) => char >= 0x1A00 && char <= 0x1A1F,
  14814. // 'Tai Tham': (char) => char >= 0x1A20 && char <= 0x1AAF,
  14815. // 'Combining Diacritical Marks Extended': (char) => char >= 0x1AB0 && char <= 0x1AFF,
  14816. // 'Balinese': (char) => char >= 0x1B00 && char <= 0x1B7F,
  14817. // 'Sundanese': (char) => char >= 0x1B80 && char <= 0x1BBF,
  14818. // 'Batak': (char) => char >= 0x1BC0 && char <= 0x1BFF,
  14819. // 'Lepcha': (char) => char >= 0x1C00 && char <= 0x1C4F,
  14820. // 'Ol Chiki': (char) => char >= 0x1C50 && char <= 0x1C7F,
  14821. // 'Cyrillic Extended-C': (char) => char >= 0x1C80 && char <= 0x1C8F,
  14822. // 'Georgian Extended': (char) => char >= 0x1C90 && char <= 0x1CBF,
  14823. // 'Sundanese Supplement': (char) => char >= 0x1CC0 && char <= 0x1CCF,
  14824. // 'Vedic Extensions': (char) => char >= 0x1CD0 && char <= 0x1CFF,
  14825. // 'Phonetic Extensions': (char) => char >= 0x1D00 && char <= 0x1D7F,
  14826. // 'Phonetic Extensions Supplement': (char) => char >= 0x1D80 && char <= 0x1DBF,
  14827. // 'Combining Diacritical Marks Supplement': (char) => char >= 0x1DC0 && char <= 0x1DFF,
  14828. // 'Latin Extended Additional': (char) => char >= 0x1E00 && char <= 0x1EFF,
  14829. // 'Greek Extended': (char) => char >= 0x1F00 && char <= 0x1FFF,
  14830. 'General Punctuation': function (char) {
  14831. return char >= 0x2000 && char <= 0x206F;
  14832. },
  14833. // 'Superscripts and Subscripts': (char) => char >= 0x2070 && char <= 0x209F,
  14834. // 'Currency Symbols': (char) => char >= 0x20A0 && char <= 0x20CF,
  14835. // 'Combining Diacritical Marks for Symbols': (char) => char >= 0x20D0 && char <= 0x20FF,
  14836. 'Letterlike Symbols': function (char) {
  14837. return char >= 0x2100 && char <= 0x214F;
  14838. },
  14839. 'Number Forms': function (char) {
  14840. return char >= 0x2150 && char <= 0x218F;
  14841. },
  14842. // 'Arrows': (char) => char >= 0x2190 && char <= 0x21FF,
  14843. // 'Mathematical Operators': (char) => char >= 0x2200 && char <= 0x22FF,
  14844. 'Miscellaneous Technical': function (char) {
  14845. return char >= 0x2300 && char <= 0x23FF;
  14846. },
  14847. 'Control Pictures': function (char) {
  14848. return char >= 0x2400 && char <= 0x243F;
  14849. },
  14850. 'Optical Character Recognition': function (char) {
  14851. return char >= 0x2440 && char <= 0x245F;
  14852. },
  14853. 'Enclosed Alphanumerics': function (char) {
  14854. return char >= 0x2460 && char <= 0x24FF;
  14855. },
  14856. // 'Box Drawing': (char) => char >= 0x2500 && char <= 0x257F,
  14857. // 'Block Elements': (char) => char >= 0x2580 && char <= 0x259F,
  14858. 'Geometric Shapes': function (char) {
  14859. return char >= 0x25A0 && char <= 0x25FF;
  14860. },
  14861. 'Miscellaneous Symbols': function (char) {
  14862. return char >= 0x2600 && char <= 0x26FF;
  14863. },
  14864. // 'Dingbats': (char) => char >= 0x2700 && char <= 0x27BF,
  14865. // 'Miscellaneous Mathematical Symbols-A': (char) => char >= 0x27C0 && char <= 0x27EF,
  14866. // 'Supplemental Arrows-A': (char) => char >= 0x27F0 && char <= 0x27FF,
  14867. // 'Braille Patterns': (char) => char >= 0x2800 && char <= 0x28FF,
  14868. // 'Supplemental Arrows-B': (char) => char >= 0x2900 && char <= 0x297F,
  14869. // 'Miscellaneous Mathematical Symbols-B': (char) => char >= 0x2980 && char <= 0x29FF,
  14870. // 'Supplemental Mathematical Operators': (char) => char >= 0x2A00 && char <= 0x2AFF,
  14871. 'Miscellaneous Symbols and Arrows': function (char) {
  14872. return char >= 0x2B00 && char <= 0x2BFF;
  14873. },
  14874. // 'Glagolitic': (char) => char >= 0x2C00 && char <= 0x2C5F,
  14875. // 'Latin Extended-C': (char) => char >= 0x2C60 && char <= 0x2C7F,
  14876. // 'Coptic': (char) => char >= 0x2C80 && char <= 0x2CFF,
  14877. // 'Georgian Supplement': (char) => char >= 0x2D00 && char <= 0x2D2F,
  14878. // 'Tifinagh': (char) => char >= 0x2D30 && char <= 0x2D7F,
  14879. // 'Ethiopic Extended': (char) => char >= 0x2D80 && char <= 0x2DDF,
  14880. // 'Cyrillic Extended-A': (char) => char >= 0x2DE0 && char <= 0x2DFF,
  14881. // 'Supplemental Punctuation': (char) => char >= 0x2E00 && char <= 0x2E7F,
  14882. 'CJK Radicals Supplement': function (char) {
  14883. return char >= 0x2E80 && char <= 0x2EFF;
  14884. },
  14885. 'Kangxi Radicals': function (char) {
  14886. return char >= 0x2F00 && char <= 0x2FDF;
  14887. },
  14888. 'Ideographic Description Characters': function (char) {
  14889. return char >= 0x2FF0 && char <= 0x2FFF;
  14890. },
  14891. 'CJK Symbols and Punctuation': function (char) {
  14892. return char >= 0x3000 && char <= 0x303F;
  14893. },
  14894. 'Hiragana': function (char) {
  14895. return char >= 0x3040 && char <= 0x309F;
  14896. },
  14897. 'Katakana': function (char) {
  14898. return char >= 0x30A0 && char <= 0x30FF;
  14899. },
  14900. 'Bopomofo': function (char) {
  14901. return char >= 0x3100 && char <= 0x312F;
  14902. },
  14903. 'Hangul Compatibility Jamo': function (char) {
  14904. return char >= 0x3130 && char <= 0x318F;
  14905. },
  14906. 'Kanbun': function (char) {
  14907. return char >= 0x3190 && char <= 0x319F;
  14908. },
  14909. 'Bopomofo Extended': function (char) {
  14910. return char >= 0x31A0 && char <= 0x31BF;
  14911. },
  14912. 'CJK Strokes': function (char) {
  14913. return char >= 0x31C0 && char <= 0x31EF;
  14914. },
  14915. 'Katakana Phonetic Extensions': function (char) {
  14916. return char >= 0x31F0 && char <= 0x31FF;
  14917. },
  14918. 'Enclosed CJK Letters and Months': function (char) {
  14919. return char >= 0x3200 && char <= 0x32FF;
  14920. },
  14921. 'CJK Compatibility': function (char) {
  14922. return char >= 0x3300 && char <= 0x33FF;
  14923. },
  14924. 'CJK Unified Ideographs Extension A': function (char) {
  14925. return char >= 0x3400 && char <= 0x4DBF;
  14926. },
  14927. 'Yijing Hexagram Symbols': function (char) {
  14928. return char >= 0x4DC0 && char <= 0x4DFF;
  14929. },
  14930. 'CJK Unified Ideographs': function (char) {
  14931. return char >= 0x4E00 && char <= 0x9FFF;
  14932. },
  14933. 'Yi Syllables': function (char) {
  14934. return char >= 0xA000 && char <= 0xA48F;
  14935. },
  14936. 'Yi Radicals': function (char) {
  14937. return char >= 0xA490 && char <= 0xA4CF;
  14938. },
  14939. // 'Lisu': (char) => char >= 0xA4D0 && char <= 0xA4FF,
  14940. // 'Vai': (char) => char >= 0xA500 && char <= 0xA63F,
  14941. // 'Cyrillic Extended-B': (char) => char >= 0xA640 && char <= 0xA69F,
  14942. // 'Bamum': (char) => char >= 0xA6A0 && char <= 0xA6FF,
  14943. // 'Modifier Tone Letters': (char) => char >= 0xA700 && char <= 0xA71F,
  14944. // 'Latin Extended-D': (char) => char >= 0xA720 && char <= 0xA7FF,
  14945. // 'Syloti Nagri': (char) => char >= 0xA800 && char <= 0xA82F,
  14946. // 'Common Indic Number Forms': (char) => char >= 0xA830 && char <= 0xA83F,
  14947. // 'Phags-pa': (char) => char >= 0xA840 && char <= 0xA87F,
  14948. // 'Saurashtra': (char) => char >= 0xA880 && char <= 0xA8DF,
  14949. // 'Devanagari Extended': (char) => char >= 0xA8E0 && char <= 0xA8FF,
  14950. // 'Kayah Li': (char) => char >= 0xA900 && char <= 0xA92F,
  14951. // 'Rejang': (char) => char >= 0xA930 && char <= 0xA95F,
  14952. 'Hangul Jamo Extended-A': function (char) {
  14953. return char >= 0xA960 && char <= 0xA97F;
  14954. },
  14955. // 'Javanese': (char) => char >= 0xA980 && char <= 0xA9DF,
  14956. // 'Myanmar Extended-B': (char) => char >= 0xA9E0 && char <= 0xA9FF,
  14957. // 'Cham': (char) => char >= 0xAA00 && char <= 0xAA5F,
  14958. // 'Myanmar Extended-A': (char) => char >= 0xAA60 && char <= 0xAA7F,
  14959. // 'Tai Viet': (char) => char >= 0xAA80 && char <= 0xAADF,
  14960. // 'Meetei Mayek Extensions': (char) => char >= 0xAAE0 && char <= 0xAAFF,
  14961. // 'Ethiopic Extended-A': (char) => char >= 0xAB00 && char <= 0xAB2F,
  14962. // 'Latin Extended-E': (char) => char >= 0xAB30 && char <= 0xAB6F,
  14963. // 'Cherokee Supplement': (char) => char >= 0xAB70 && char <= 0xABBF,
  14964. // 'Meetei Mayek': (char) => char >= 0xABC0 && char <= 0xABFF,
  14965. 'Hangul Syllables': function (char) {
  14966. return char >= 0xAC00 && char <= 0xD7AF;
  14967. },
  14968. 'Hangul Jamo Extended-B': function (char) {
  14969. return char >= 0xD7B0 && char <= 0xD7FF;
  14970. },
  14971. // 'High Surrogates': (char) => char >= 0xD800 && char <= 0xDB7F,
  14972. // 'High Private Use Surrogates': (char) => char >= 0xDB80 && char <= 0xDBFF,
  14973. // 'Low Surrogates': (char) => char >= 0xDC00 && char <= 0xDFFF,
  14974. 'Private Use Area': function (char) {
  14975. return char >= 0xE000 && char <= 0xF8FF;
  14976. },
  14977. 'CJK Compatibility Ideographs': function (char) {
  14978. return char >= 0xF900 && char <= 0xFAFF;
  14979. },
  14980. // 'Alphabetic Presentation Forms': (char) => char >= 0xFB00 && char <= 0xFB4F,
  14981. 'Arabic Presentation Forms-A': function (char) {
  14982. return char >= 0xFB50 && char <= 0xFDFF;
  14983. },
  14984. // 'Variation Selectors': (char) => char >= 0xFE00 && char <= 0xFE0F,
  14985. 'Vertical Forms': function (char) {
  14986. return char >= 0xFE10 && char <= 0xFE1F;
  14987. },
  14988. // 'Combining Half Marks': (char) => char >= 0xFE20 && char <= 0xFE2F,
  14989. 'CJK Compatibility Forms': function (char) {
  14990. return char >= 0xFE30 && char <= 0xFE4F;
  14991. },
  14992. 'Small Form Variants': function (char) {
  14993. return char >= 0xFE50 && char <= 0xFE6F;
  14994. },
  14995. 'Arabic Presentation Forms-B': function (char) {
  14996. return char >= 0xFE70 && char <= 0xFEFF;
  14997. },
  14998. 'Halfwidth and Fullwidth Forms': function (char) {
  14999. return char >= 0xFF00 && char <= 0xFFEF;
  15000. }
  15001. // 'Specials': (char) => char >= 0xFFF0 && char <= 0xFFFF,
  15002. // 'Linear B Syllabary': (char) => char >= 0x10000 && char <= 0x1007F,
  15003. // 'Linear B Ideograms': (char) => char >= 0x10080 && char <= 0x100FF,
  15004. // 'Aegean Numbers': (char) => char >= 0x10100 && char <= 0x1013F,
  15005. // 'Ancient Greek Numbers': (char) => char >= 0x10140 && char <= 0x1018F,
  15006. // 'Ancient Symbols': (char) => char >= 0x10190 && char <= 0x101CF,
  15007. // 'Phaistos Disc': (char) => char >= 0x101D0 && char <= 0x101FF,
  15008. // 'Lycian': (char) => char >= 0x10280 && char <= 0x1029F,
  15009. // 'Carian': (char) => char >= 0x102A0 && char <= 0x102DF,
  15010. // 'Coptic Epact Numbers': (char) => char >= 0x102E0 && char <= 0x102FF,
  15011. // 'Old Italic': (char) => char >= 0x10300 && char <= 0x1032F,
  15012. // 'Gothic': (char) => char >= 0x10330 && char <= 0x1034F,
  15013. // 'Old Permic': (char) => char >= 0x10350 && char <= 0x1037F,
  15014. // 'Ugaritic': (char) => char >= 0x10380 && char <= 0x1039F,
  15015. // 'Old Persian': (char) => char >= 0x103A0 && char <= 0x103DF,
  15016. // 'Deseret': (char) => char >= 0x10400 && char <= 0x1044F,
  15017. // 'Shavian': (char) => char >= 0x10450 && char <= 0x1047F,
  15018. // 'Osmanya': (char) => char >= 0x10480 && char <= 0x104AF,
  15019. // 'Osage': (char) => char >= 0x104B0 && char <= 0x104FF,
  15020. // 'Elbasan': (char) => char >= 0x10500 && char <= 0x1052F,
  15021. // 'Caucasian Albanian': (char) => char >= 0x10530 && char <= 0x1056F,
  15022. // 'Linear A': (char) => char >= 0x10600 && char <= 0x1077F,
  15023. // 'Cypriot Syllabary': (char) => char >= 0x10800 && char <= 0x1083F,
  15024. // 'Imperial Aramaic': (char) => char >= 0x10840 && char <= 0x1085F,
  15025. // 'Palmyrene': (char) => char >= 0x10860 && char <= 0x1087F,
  15026. // 'Nabataean': (char) => char >= 0x10880 && char <= 0x108AF,
  15027. // 'Hatran': (char) => char >= 0x108E0 && char <= 0x108FF,
  15028. // 'Phoenician': (char) => char >= 0x10900 && char <= 0x1091F,
  15029. // 'Lydian': (char) => char >= 0x10920 && char <= 0x1093F,
  15030. // 'Meroitic Hieroglyphs': (char) => char >= 0x10980 && char <= 0x1099F,
  15031. // 'Meroitic Cursive': (char) => char >= 0x109A0 && char <= 0x109FF,
  15032. // 'Kharoshthi': (char) => char >= 0x10A00 && char <= 0x10A5F,
  15033. // 'Old South Arabian': (char) => char >= 0x10A60 && char <= 0x10A7F,
  15034. // 'Old North Arabian': (char) => char >= 0x10A80 && char <= 0x10A9F,
  15035. // 'Manichaean': (char) => char >= 0x10AC0 && char <= 0x10AFF,
  15036. // 'Avestan': (char) => char >= 0x10B00 && char <= 0x10B3F,
  15037. // 'Inscriptional Parthian': (char) => char >= 0x10B40 && char <= 0x10B5F,
  15038. // 'Inscriptional Pahlavi': (char) => char >= 0x10B60 && char <= 0x10B7F,
  15039. // 'Psalter Pahlavi': (char) => char >= 0x10B80 && char <= 0x10BAF,
  15040. // 'Old Turkic': (char) => char >= 0x10C00 && char <= 0x10C4F,
  15041. // 'Old Hungarian': (char) => char >= 0x10C80 && char <= 0x10CFF,
  15042. // 'Hanifi Rohingya': (char) => char >= 0x10D00 && char <= 0x10D3F,
  15043. // 'Rumi Numeral Symbols': (char) => char >= 0x10E60 && char <= 0x10E7F,
  15044. // 'Old Sogdian': (char) => char >= 0x10F00 && char <= 0x10F2F,
  15045. // 'Sogdian': (char) => char >= 0x10F30 && char <= 0x10F6F,
  15046. // 'Elymaic': (char) => char >= 0x10FE0 && char <= 0x10FFF,
  15047. // 'Brahmi': (char) => char >= 0x11000 && char <= 0x1107F,
  15048. // 'Kaithi': (char) => char >= 0x11080 && char <= 0x110CF,
  15049. // 'Sora Sompeng': (char) => char >= 0x110D0 && char <= 0x110FF,
  15050. // 'Chakma': (char) => char >= 0x11100 && char <= 0x1114F,
  15051. // 'Mahajani': (char) => char >= 0x11150 && char <= 0x1117F,
  15052. // 'Sharada': (char) => char >= 0x11180 && char <= 0x111DF,
  15053. // 'Sinhala Archaic Numbers': (char) => char >= 0x111E0 && char <= 0x111FF,
  15054. // 'Khojki': (char) => char >= 0x11200 && char <= 0x1124F,
  15055. // 'Multani': (char) => char >= 0x11280 && char <= 0x112AF,
  15056. // 'Khudawadi': (char) => char >= 0x112B0 && char <= 0x112FF,
  15057. // 'Grantha': (char) => char >= 0x11300 && char <= 0x1137F,
  15058. // 'Newa': (char) => char >= 0x11400 && char <= 0x1147F,
  15059. // 'Tirhuta': (char) => char >= 0x11480 && char <= 0x114DF,
  15060. // 'Siddham': (char) => char >= 0x11580 && char <= 0x115FF,
  15061. // 'Modi': (char) => char >= 0x11600 && char <= 0x1165F,
  15062. // 'Mongolian Supplement': (char) => char >= 0x11660 && char <= 0x1167F,
  15063. // 'Takri': (char) => char >= 0x11680 && char <= 0x116CF,
  15064. // 'Ahom': (char) => char >= 0x11700 && char <= 0x1173F,
  15065. // 'Dogra': (char) => char >= 0x11800 && char <= 0x1184F,
  15066. // 'Warang Citi': (char) => char >= 0x118A0 && char <= 0x118FF,
  15067. // 'Nandinagari': (char) => char >= 0x119A0 && char <= 0x119FF,
  15068. // 'Zanabazar Square': (char) => char >= 0x11A00 && char <= 0x11A4F,
  15069. // 'Soyombo': (char) => char >= 0x11A50 && char <= 0x11AAF,
  15070. // 'Pau Cin Hau': (char) => char >= 0x11AC0 && char <= 0x11AFF,
  15071. // 'Bhaiksuki': (char) => char >= 0x11C00 && char <= 0x11C6F,
  15072. // 'Marchen': (char) => char >= 0x11C70 && char <= 0x11CBF,
  15073. // 'Masaram Gondi': (char) => char >= 0x11D00 && char <= 0x11D5F,
  15074. // 'Gunjala Gondi': (char) => char >= 0x11D60 && char <= 0x11DAF,
  15075. // 'Makasar': (char) => char >= 0x11EE0 && char <= 0x11EFF,
  15076. // 'Tamil Supplement': (char) => char >= 0x11FC0 && char <= 0x11FFF,
  15077. // 'Cuneiform': (char) => char >= 0x12000 && char <= 0x123FF,
  15078. // 'Cuneiform Numbers and Punctuation': (char) => char >= 0x12400 && char <= 0x1247F,
  15079. // 'Early Dynastic Cuneiform': (char) => char >= 0x12480 && char <= 0x1254F,
  15080. // 'Egyptian Hieroglyphs': (char) => char >= 0x13000 && char <= 0x1342F,
  15081. // 'Egyptian Hieroglyph Format Controls': (char) => char >= 0x13430 && char <= 0x1343F,
  15082. // 'Anatolian Hieroglyphs': (char) => char >= 0x14400 && char <= 0x1467F,
  15083. // 'Bamum Supplement': (char) => char >= 0x16800 && char <= 0x16A3F,
  15084. // 'Mro': (char) => char >= 0x16A40 && char <= 0x16A6F,
  15085. // 'Bassa Vah': (char) => char >= 0x16AD0 && char <= 0x16AFF,
  15086. // 'Pahawh Hmong': (char) => char >= 0x16B00 && char <= 0x16B8F,
  15087. // 'Medefaidrin': (char) => char >= 0x16E40 && char <= 0x16E9F,
  15088. // 'Miao': (char) => char >= 0x16F00 && char <= 0x16F9F,
  15089. // 'Ideographic Symbols and Punctuation': (char) => char >= 0x16FE0 && char <= 0x16FFF,
  15090. // 'Tangut': (char) => char >= 0x17000 && char <= 0x187FF,
  15091. // 'Tangut Components': (char) => char >= 0x18800 && char <= 0x18AFF,
  15092. // 'Kana Supplement': (char) => char >= 0x1B000 && char <= 0x1B0FF,
  15093. // 'Kana Extended-A': (char) => char >= 0x1B100 && char <= 0x1B12F,
  15094. // 'Small Kana Extension': (char) => char >= 0x1B130 && char <= 0x1B16F,
  15095. // 'Nushu': (char) => char >= 0x1B170 && char <= 0x1B2FF,
  15096. // 'Duployan': (char) => char >= 0x1BC00 && char <= 0x1BC9F,
  15097. // 'Shorthand Format Controls': (char) => char >= 0x1BCA0 && char <= 0x1BCAF,
  15098. // 'Byzantine Musical Symbols': (char) => char >= 0x1D000 && char <= 0x1D0FF,
  15099. // 'Musical Symbols': (char) => char >= 0x1D100 && char <= 0x1D1FF,
  15100. // 'Ancient Greek Musical Notation': (char) => char >= 0x1D200 && char <= 0x1D24F,
  15101. // 'Mayan Numerals': (char) => char >= 0x1D2E0 && char <= 0x1D2FF,
  15102. // 'Tai Xuan Jing Symbols': (char) => char >= 0x1D300 && char <= 0x1D35F,
  15103. // 'Counting Rod Numerals': (char) => char >= 0x1D360 && char <= 0x1D37F,
  15104. // 'Mathematical Alphanumeric Symbols': (char) => char >= 0x1D400 && char <= 0x1D7FF,
  15105. // 'Sutton SignWriting': (char) => char >= 0x1D800 && char <= 0x1DAAF,
  15106. // 'Glagolitic Supplement': (char) => char >= 0x1E000 && char <= 0x1E02F,
  15107. // 'Nyiakeng Puachue Hmong': (char) => char >= 0x1E100 && char <= 0x1E14F,
  15108. // 'Wancho': (char) => char >= 0x1E2C0 && char <= 0x1E2FF,
  15109. // 'Mende Kikakui': (char) => char >= 0x1E800 && char <= 0x1E8DF,
  15110. // 'Adlam': (char) => char >= 0x1E900 && char <= 0x1E95F,
  15111. // 'Indic Siyaq Numbers': (char) => char >= 0x1EC70 && char <= 0x1ECBF,
  15112. // 'Ottoman Siyaq Numbers': (char) => char >= 0x1ED00 && char <= 0x1ED4F,
  15113. // 'Arabic Mathematical Alphabetic Symbols': (char) => char >= 0x1EE00 && char <= 0x1EEFF,
  15114. // 'Mahjong Tiles': (char) => char >= 0x1F000 && char <= 0x1F02F,
  15115. // 'Domino Tiles': (char) => char >= 0x1F030 && char <= 0x1F09F,
  15116. // 'Playing Cards': (char) => char >= 0x1F0A0 && char <= 0x1F0FF,
  15117. // 'Enclosed Alphanumeric Supplement': (char) => char >= 0x1F100 && char <= 0x1F1FF,
  15118. // 'Enclosed Ideographic Supplement': (char) => char >= 0x1F200 && char <= 0x1F2FF,
  15119. // 'Miscellaneous Symbols and Pictographs': (char) => char >= 0x1F300 && char <= 0x1F5FF,
  15120. // 'Emoticons': (char) => char >= 0x1F600 && char <= 0x1F64F,
  15121. // 'Ornamental Dingbats': (char) => char >= 0x1F650 && char <= 0x1F67F,
  15122. // 'Transport and Map Symbols': (char) => char >= 0x1F680 && char <= 0x1F6FF,
  15123. // 'Alchemical Symbols': (char) => char >= 0x1F700 && char <= 0x1F77F,
  15124. // 'Geometric Shapes Extended': (char) => char >= 0x1F780 && char <= 0x1F7FF,
  15125. // 'Supplemental Arrows-C': (char) => char >= 0x1F800 && char <= 0x1F8FF,
  15126. // 'Supplemental Symbols and Pictographs': (char) => char >= 0x1F900 && char <= 0x1F9FF,
  15127. // 'Chess Symbols': (char) => char >= 0x1FA00 && char <= 0x1FA6F,
  15128. // 'Symbols and Pictographs Extended-A': (char) => char >= 0x1FA70 && char <= 0x1FAFF,
  15129. // 'CJK Unified Ideographs Extension B': (char) => char >= 0x20000 && char <= 0x2A6DF,
  15130. // 'CJK Unified Ideographs Extension C': (char) => char >= 0x2A700 && char <= 0x2B73F,
  15131. // 'CJK Unified Ideographs Extension D': (char) => char >= 0x2B740 && char <= 0x2B81F,
  15132. // 'CJK Unified Ideographs Extension E': (char) => char >= 0x2B820 && char <= 0x2CEAF,
  15133. // 'CJK Unified Ideographs Extension F': (char) => char >= 0x2CEB0 && char <= 0x2EBEF,
  15134. // 'CJK Compatibility Ideographs Supplement': (char) => char >= 0x2F800 && char <= 0x2FA1F,
  15135. // 'Tags': (char) => char >= 0xE0000 && char <= 0xE007F,
  15136. // 'Variation Selectors Supplement': (char) => char >= 0xE0100 && char <= 0xE01EF,
  15137. // 'Supplementary Private Use Area-A': (char) => char >= 0xF0000 && char <= 0xFFFFF,
  15138. // 'Supplementary Private Use Area-B': (char) => char >= 0x100000 && char <= 0x10FFFF,
  15139. };
  15140. var ScriptDetection = function ScriptDetection() {
  15141. };
  15142. ScriptDetection.allowsVerticalWritingMode = function(chars){
  15143. for (var i = 0, list = chars; i < list.length; i += 1) {
  15144. var char = list[i];
  15145. if (charHasUprightVerticalOrientation(char.charCodeAt(0))) {
  15146. return true;
  15147. }
  15148. }
  15149. return false;
  15150. };
  15151. ScriptDetection.allowsLetterSpacing = function(chars){
  15152. for (var i = 0, list = chars; i < list.length; i += 1) {
  15153. var char = list[i];
  15154. if (!charAllowsLetterSpacing(char.charCodeAt(0))) {
  15155. return false;
  15156. }
  15157. }
  15158. return true;
  15159. };
  15160. function charAllowsLetterSpacing(char) {
  15161. if (unicodeBlockLookup['Arabic'](char)) {
  15162. return false;
  15163. }
  15164. if (unicodeBlockLookup['Arabic Supplement'](char)) {
  15165. return false;
  15166. }
  15167. if (unicodeBlockLookup['Arabic Extended-A'](char)) {
  15168. return false;
  15169. }
  15170. if (unicodeBlockLookup['Arabic Presentation Forms-A'](char)) {
  15171. return false;
  15172. }
  15173. if (unicodeBlockLookup['Arabic Presentation Forms-B'](char)) {
  15174. return false;
  15175. }
  15176. return true;
  15177. }
  15178. // The following logic comes from
  15179. // <http://www.unicode.org/Public/12.0.0/ucd/VerticalOrientation.txt>.
  15180. // Keep it synchronized with
  15181. // <http://www.unicode.org/Public/UCD/latest/ucd/VerticalOrientation.txt>.
  15182. // The data file denotes with “U” or “Tu” any codepoint that may be drawn
  15183. // upright in vertical text but does not distinguish between upright and
  15184. // “neutral” characters.
  15185. // Blocks in the Unicode supplementary planes are excluded from this module due
  15186. // to <https://github.com/mapbox/mapbox-gl/issues/29>.
  15187. /**
  15188. * Returns true if the given Unicode codepoint identifies a character with
  15189. * upright orientation.
  15190. *
  15191. * A character has upright orientation if it is drawn upright (unrotated)
  15192. * whether the line is oriented horizontally or vertically, even if both
  15193. * adjacent characters can be rotated. For example, a Chinese character is
  15194. * always drawn upright. An uprightly oriented character causes an adjacent
  15195. * “neutral” character to be drawn upright as well.
  15196. * @private
  15197. */
  15198. function charHasUprightVerticalOrientation(char) {
  15199. if (char === 0x02EA /* modifier letter yin departing tone mark */ ||
  15200. char === 0x02EB /* modifier letter yang departing tone mark */) {
  15201. return true;
  15202. }
  15203. // Return early for characters outside all ranges whose characters remain
  15204. // upright in vertical writing mode.
  15205. if (char < 0x1100) {
  15206. return false;
  15207. }
  15208. if (unicodeBlockLookup['Bopomofo Extended'](char)) {
  15209. return true;
  15210. }
  15211. if (unicodeBlockLookup['Bopomofo'](char)) {
  15212. return true;
  15213. }
  15214. if (unicodeBlockLookup['CJK Compatibility Forms'](char)) {
  15215. if (!((char >= 0xFE49 /* dashed overline */ && char <= 0xFE4F) /* wavy low line */)) {
  15216. return true;
  15217. }
  15218. }
  15219. if (unicodeBlockLookup['CJK Compatibility Ideographs'](char)) {
  15220. return true;
  15221. }
  15222. if (unicodeBlockLookup['CJK Compatibility'](char)) {
  15223. return true;
  15224. }
  15225. if (unicodeBlockLookup['CJK Radicals Supplement'](char)) {
  15226. return true;
  15227. }
  15228. if (unicodeBlockLookup['CJK Strokes'](char)) {
  15229. return true;
  15230. }
  15231. if (unicodeBlockLookup['CJK Symbols and Punctuation'](char)) {
  15232. 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 */) &&
  15233. char !== 0x3030 /* wavy dash */) {
  15234. return true;
  15235. }
  15236. }
  15237. if (unicodeBlockLookup['CJK Unified Ideographs Extension A'](char)) {
  15238. return true;
  15239. }
  15240. if (unicodeBlockLookup['CJK Unified Ideographs'](char)) {
  15241. return true;
  15242. }
  15243. if (unicodeBlockLookup['Enclosed CJK Letters and Months'](char)) {
  15244. return true;
  15245. }
  15246. if (unicodeBlockLookup['Hangul Compatibility Jamo'](char)) {
  15247. return true;
  15248. }
  15249. if (unicodeBlockLookup['Hangul Jamo Extended-A'](char)) {
  15250. return true;
  15251. }
  15252. if (unicodeBlockLookup['Hangul Jamo Extended-B'](char)) {
  15253. return true;
  15254. }
  15255. if (unicodeBlockLookup['Hangul Jamo'](char)) {
  15256. return true;
  15257. }
  15258. if (unicodeBlockLookup['Hangul Syllables'](char)) {
  15259. return true;
  15260. }
  15261. if (unicodeBlockLookup['Hiragana'](char)) {
  15262. return true;
  15263. }
  15264. if (unicodeBlockLookup['Ideographic Description Characters'](char)) {
  15265. return true;
  15266. }
  15267. if (unicodeBlockLookup['Kanbun'](char)) {
  15268. return true;
  15269. }
  15270. if (unicodeBlockLookup['Kangxi Radicals'](char)) {
  15271. return true;
  15272. }
  15273. if (unicodeBlockLookup['Katakana Phonetic Extensions'](char)) {
  15274. return true;
  15275. }
  15276. if (unicodeBlockLookup['Katakana'](char)) {
  15277. if (char !== 0x30FC /* katakana-hiragana prolonged sound mark */) {
  15278. return true;
  15279. }
  15280. }
  15281. if (unicodeBlockLookup['Halfwidth and Fullwidth Forms'](char)) {
  15282. if (char !== 0xFF08 /* fullwidth left parenthesis */ &&
  15283. char !== 0xFF09 /* fullwidth right parenthesis */ &&
  15284. char !== 0xFF0D /* fullwidth hyphen-minus */ && !((char >= 0xFF1A /* fullwidth colon */ && char <= 0xFF1E) /* fullwidth greater-than sign */) &&
  15285. char !== 0xFF3B /* fullwidth left square bracket */ &&
  15286. char !== 0xFF3D /* fullwidth right square bracket */ &&
  15287. char !== 0xFF3F /* fullwidth low line */ && !(char >= 0xFF5B /* fullwidth left curly bracket */ && char <= 0xFFDF) &&
  15288. char !== 0xFFE3 /* fullwidth macron */ && !(char >= 0xFFE8 /* halfwidth forms light vertical */ && char <= 0xFFEF)) {
  15289. return true;
  15290. }
  15291. }
  15292. if (unicodeBlockLookup['Small Form Variants'](char)) {
  15293. if (!((char >= 0xFE58 /* small em dash */ && char <= 0xFE5E) /* small right tortoise shell bracket */) && !((char >= 0xFE63 /* small hyphen-minus */ && char <= 0xFE66) /* small equals sign */)) {
  15294. return true;
  15295. }
  15296. }
  15297. if (unicodeBlockLookup['Unified Canadian Aboriginal Syllabics'](char)) {
  15298. return true;
  15299. }
  15300. if (unicodeBlockLookup['Unified Canadian Aboriginal Syllabics Extended'](char)) {
  15301. return true;
  15302. }
  15303. if (unicodeBlockLookup['Vertical Forms'](char)) {
  15304. return true;
  15305. }
  15306. if (unicodeBlockLookup['Yijing Hexagram Symbols'](char)) {
  15307. return true;
  15308. }
  15309. if (unicodeBlockLookup['Yi Syllables'](char)) {
  15310. return true;
  15311. }
  15312. if (unicodeBlockLookup['Yi Radicals'](char)) {
  15313. return true;
  15314. }
  15315. return false;
  15316. }
  15317. function charInRTLScript(char) {
  15318. // Main blocks for Hebrew, Arabic, Thaana and other RTL scripts
  15319. return (char >= 0x0590 && char <= 0x08FF) ||
  15320. unicodeBlockLookup['Arabic Presentation Forms-A'](char) ||
  15321. unicodeBlockLookup['Arabic Presentation Forms-B'](char);
  15322. }
  15323. ScriptDetection.stringContainsRTLText = function(chars){
  15324. for (var i = 0, list = chars; i < list.length; i += 1) {
  15325. var char = list[i];
  15326. if (charInRTLScript(char.charCodeAt(0))) {
  15327. return true;
  15328. }
  15329. }
  15330. return false;
  15331. };
  15332. var vectorTileFeatureTypes$2 = ['Unknown', 'Point', 'LineString', 'Polygon'];
  15333. // Opacity arrays are frequently updated but don't contain a lot of information, so we pack them
  15334. // tight. Each Uint32 is actually four duplicate Uint8s for the four corners of a glyph
  15335. // 7 bits are for the current opacity, and the lowest bit is the target opacity
  15336. // actually defined in symbol_attributes.js
  15337. // const placementOpacityAttributes = [
  15338. // { name: 'a_fade_opacity', components: 1, type: 'Uint32' }
  15339. // ];
  15340. var shaderOpacityAttributes = [
  15341. {name: 'a_fade_opacity', components: 1, type: 'Uint8', offset: 0}
  15342. ];
  15343. function addVertex$1(array, anchorX, anchorY, ox, oy, tx, ty, sizeVertex, isSDF, pixelOffsetX, pixelOffsetY, minFontScaleX, minFontScaleY) {
  15344. var aSizeX = sizeVertex ? Math.min(MAX_PACKED_SIZE, Math.round(sizeVertex[0])) : 0;
  15345. var aSizeY = sizeVertex ? Math.min(MAX_PACKED_SIZE, Math.round(sizeVertex[1])) : 0;
  15346. array.emplaceBack(
  15347. // a_pos_offset
  15348. anchorX,
  15349. anchorY,
  15350. Math.round(ox * 32),
  15351. Math.round(oy * 32),
  15352. // a_data
  15353. tx, // x coordinate of symbol on glyph atlas texture
  15354. ty, // y coordinate of symbol on glyph atlas texture
  15355. (aSizeX << 1) + (isSDF ? 1 : 0),
  15356. aSizeY,
  15357. pixelOffsetX * 16,
  15358. pixelOffsetY * 16,
  15359. minFontScaleX * 256,
  15360. minFontScaleY * 256
  15361. );
  15362. }
  15363. function addDynamicAttributes(dynamicLayoutVertexArray, p, angle) {
  15364. dynamicLayoutVertexArray.emplaceBack(p.x, p.y, angle);
  15365. dynamicLayoutVertexArray.emplaceBack(p.x, p.y, angle);
  15366. dynamicLayoutVertexArray.emplaceBack(p.x, p.y, angle);
  15367. dynamicLayoutVertexArray.emplaceBack(p.x, p.y, angle);
  15368. }
  15369. function containsRTLText(formattedText) {
  15370. for (var i = 0, list = formattedText.sections; i < list.length; i += 1) {
  15371. var section = list[i];
  15372. if (ScriptDetection.stringContainsRTLText(section.text)) {
  15373. return true;
  15374. }
  15375. }
  15376. return false;
  15377. }
  15378. var SymbolBuffers = function SymbolBuffers(programConfigurations) {
  15379. this.layoutVertexArray = new StructArrayLayout4i4ui4i24();
  15380. this.indexArray = new StructArrayLayout3ui6();
  15381. this.programConfigurations = programConfigurations;
  15382. this.segments = new SegmentVector();
  15383. this.dynamicLayoutVertexArray = new StructArrayLayout3f12();
  15384. this.opacityVertexArray = new StructArrayLayout1ul4();
  15385. this.placedSymbolArray = new PlacedSymbolArray();
  15386. };
  15387. SymbolBuffers.prototype.upload = function upload(context, dynamicIndexBuffer, upload$1, update) {
  15388. if (upload$1) {
  15389. this.layoutVertexBuffer = context.createVertexBuffer(this.layoutVertexArray, SymbolAttributes.symbolLayoutAttributes.members);
  15390. this.indexBuffer = context.createIndexBuffer(this.indexArray, dynamicIndexBuffer);
  15391. this.dynamicLayoutVertexBuffer = context.createVertexBuffer(this.dynamicLayoutVertexArray, SymbolAttributes.dynamicLayoutAttributes.members, true);
  15392. this.opacityVertexBuffer = context.createVertexBuffer(this.opacityVertexArray, shaderOpacityAttributes, true);
  15393. // This is a performance hack so that we can write to opacityVertexArray with uint32s
  15394. // even though the shaders read uint8s
  15395. this.opacityVertexBuffer.itemSize = 1;
  15396. }
  15397. if (upload$1 || update) {
  15398. this.programConfigurations.upload(context);
  15399. }
  15400. };
  15401. SymbolBuffers.prototype.destroy = function destroy() {
  15402. if (!this.layoutVertexBuffer) {
  15403. return;
  15404. }
  15405. this.layoutVertexBuffer.destroy();
  15406. this.indexBuffer.destroy();
  15407. this.programConfigurations.destroy();
  15408. this.segments.destroy();
  15409. this.dynamicLayoutVertexBuffer.destroy();
  15410. this.opacityVertexBuffer.destroy();
  15411. };
  15412. SymbolBuffers.prototype.clear = function clear() {
  15413. };
  15414. WebWorkerTransfer.register('SymbolBuffers', SymbolBuffers);
  15415. var CollisionBuffers = function CollisionBuffers(LayoutArray, layoutAttributes, IndexArray) {
  15416. this.layoutVertexArray = new LayoutArray();
  15417. this.layoutAttributes = layoutAttributes;
  15418. this.indexArray = new IndexArray();
  15419. this.segments = new SegmentVector();
  15420. this.collisionVertexArray = new StructArrayLayout2ub2f12();
  15421. };
  15422. CollisionBuffers.prototype.upload = function upload(context) {
  15423. this.layoutVertexBuffer = context.createVertexBuffer(this.layoutVertexArray, this.layoutAttributes);
  15424. this.indexBuffer = context.createIndexBuffer(this.indexArray);
  15425. this.collisionVertexBuffer = context.createVertexBuffer(this.collisionVertexArray, collisionVertexAttributes.members, true);
  15426. };
  15427. CollisionBuffers.prototype.destroy = function destroy() {
  15428. if (!this.layoutVertexBuffer) {
  15429. return;
  15430. }
  15431. this.layoutVertexBuffer.destroy();
  15432. this.indexBuffer.destroy();
  15433. this.segments.destroy();
  15434. this.collisionVertexBuffer.destroy();
  15435. };
  15436. WebWorkerTransfer.register('CollisionBuffers', CollisionBuffers);
  15437. /**
  15438. * Unlike other buckets, which simply implement #addFeature with type-specific
  15439. * logic for (essentially) triangulating feature geometries, SymbolBucket
  15440. * requires specialized behavior:
  15441. *
  15442. * 1. WorkerTile#parse(), the logical owner of the bucket creation process,
  15443. * calls SymbolBucket#populate(), which resolves text and icon tokens on
  15444. * each feature, adds each glyphs and symbols needed to the passed-in
  15445. * collections options.glyphDependencies and options.iconDependencies, and
  15446. * stores the feature data for use in subsequent step (this.features).
  15447. *
  15448. * 2. WorkerTile asynchronously requests from the main thread all of the glyphs
  15449. * and icons needed (by this bucket and any others). When glyphs and icons
  15450. * have been received, the WorkerTile creates a CollisionIndex and invokes:
  15451. *
  15452. * 3. performSymbolLayout(bucket, stacks, icons) perform texts shaping and
  15453. * layout on a Symbol Bucket. This step populates:
  15454. * `this.symbolInstances`: metadata on generated symbols
  15455. * `this.collisionBoxArray`: collision data for use by foreground
  15456. * `this.text`: SymbolBuffers for text symbols
  15457. * `this.icons`: SymbolBuffers for icons
  15458. * `this.iconCollisionBox`: Debug SymbolBuffers for icon collision boxes
  15459. * `this.textCollisionBox`: Debug SymbolBuffers for text collision boxes
  15460. * `this.iconCollisionCircle`: Debug SymbolBuffers for icon collision circles
  15461. * `this.textCollisionCircle`: Debug SymbolBuffers for text collision circles
  15462. * The results are sent to the foreground for rendering
  15463. *
  15464. * 4. performSymbolPlacement(bucket, collisionIndex) is run on the foreground,
  15465. * and uses the CollisionIndex along with current camera settings to determine
  15466. * which symbols can actually show on the map. Collided symbols are hidden
  15467. * using a dynamic "OpacityVertexArray".
  15468. *
  15469. * @private
  15470. */
  15471. var SymbolBucket = function SymbolBucket(options) {
  15472. this.collisionBoxArray = options.collisionBoxArray;
  15473. this.zoom = options.zoom;
  15474. this.overscaling = options.overscaling;
  15475. this.layers = options.layers;
  15476. this.layerIds = this.layers.map(function (layer) {
  15477. return layer.id;
  15478. });
  15479. this.index = options.index;
  15480. this.pixelRatio = options.pixelRatio;
  15481. this.sourceLayerIndex = options.sourceLayerIndex;
  15482. this.hasPattern = false;
  15483. this.hasPaintOverrides = false;
  15484. this.hasRTLText = false;
  15485. var layer = this.layers[0];
  15486. var unevaluatedLayoutValues = layer._unevaluatedLayout._values;
  15487. this.textSizeData = symbolSize.getSizeData(this.zoom, unevaluatedLayoutValues['text-size']);
  15488. this.iconSizeData = symbolSize.getSizeData(this.zoom, unevaluatedLayoutValues['icon-size']);
  15489. var layout = this.layers[0].layout;
  15490. var sortKey = layout.get('symbol-sort-key');
  15491. var zOrder = layout.get('symbol-z-order');
  15492. this.sortFeaturesByKey = zOrder !== 'viewport-y' && sortKey.constantOr(1) !== undefined;
  15493. var zOrderByViewportY = zOrder === 'viewport-y' || (zOrder === 'auto' && !this.sortFeaturesByKey);
  15494. this.sortFeaturesByY = zOrderByViewportY && (layout.get('text-allow-overlap') || layout.get('icon-allow-overlap') ||
  15495. layout.get('text-ignore-placement') || layout.get('icon-ignore-placement'));
  15496. if (layout.get('symbol-placement') === 'point') {
  15497. this.writingModes = layout.get('text-writing-mode').map(function (wm) {
  15498. return Shaping.WritingMode[wm];
  15499. });
  15500. }
  15501. this.stateDependentLayerIds = this.layers.filter(function (l) {
  15502. return l.isStateDependent();
  15503. }).map(function (l) {
  15504. return l.id;
  15505. });
  15506. this.sourceID = options.sourceID;
  15507. };
  15508. SymbolBucket.prototype.createArrays = function createArrays() {
  15509. // var layout = this.layers[0].layout;
  15510. // //this.hasPaintOverrides = SymbolStyleLayer.hasPaintOverrides(layout);
  15511. // this.hasPaintOverrides = false;
  15512. //
  15513. // this.text = new SymbolBuffers(new ProgramConfigurationSet(SymbolAttributes.symbolLayoutAttributes.members, this.layers, this.zoom, function (property) {
  15514. // return /^text/.test(property);
  15515. // }));
  15516. // this.icon = new SymbolBuffers(new ProgramConfigurationSet(SymbolAttributes.symbolLayoutAttributes.members, this.layers, this.zoom, function (property) {
  15517. // return /^icon/.test(property);
  15518. // }));
  15519. //
  15520. // this.textCollisionBox = new CollisionBuffers(StructArrayLayout2i2i2i12, SymbolAttributes.collisionBoxLayout.members, StructArrayLayout2ui4);
  15521. // this.iconCollisionBox = new CollisionBuffers(StructArrayLayout2i2i2i12, SymbolAttributes.collisionBoxLayout.members, StructArrayLayout2ui4);
  15522. // this.textCollisionCircle = new CollisionBuffers(StructArrayLayout2i2i2i12, SymbolAttributes.collisionCircleLayout.members, StructArrayLayout3ui6);
  15523. // this.iconCollisionCircle = new CollisionBuffers(StructArrayLayout2i2i2i12, SymbolAttributes.collisionCircleLayout.members, StructArrayLayout3ui6);
  15524. //
  15525. // this.glyphOffsetArray = new GlyphOffsetArray();
  15526. // this.lineVertexArray = new SymbolLineVertexArray();
  15527. // this.symbolInstances = new SymbolInstanceArray();
  15528. };
  15529. SymbolBucket.prototype.calculateGlyphDependencies = function calculateGlyphDependencies(text, stack, textAlongLine, allowVerticalPlacement, doesAllowVerticalWritingMode) {
  15530. for (var i = 0; i < text.length; i++) {
  15531. stack[text.charCodeAt(i)] = true;
  15532. }
  15533. };
  15534. SymbolBucket.prototype.populate = function populate(features, options) {
  15535. var layer = this.layers[0];
  15536. var layout = layer.layout;
  15537. var textFont = layout.get('text-font');
  15538. var textField = layout.get('text-field');
  15539. var iconImage = layout.get('icon-image');
  15540. var hasText =
  15541. (textField.value.kind !== 'constant' ||
  15542. (textField.value.value instanceof Formatted$1 && !textField.value.value.isEmpty()) ||
  15543. textField.value.value.toString().length > 0) &&
  15544. (textFont.value.kind !== 'constant' || textFont.value.value.length > 0);
  15545. // we should always resolve the icon-image value if the property was defined in the style
  15546. // this allows us to fire the styleimagemissing event if image evaluation returns null
  15547. // the only way to distinguish between null returned from a coalesce statement with no valid images
  15548. // and null returned because icon-image wasn't defined is to check whether or not iconImage.parameters is an empty object
  15549. var hasIcon = (iconImage.value.kind !== 'constant' || !!iconImage.value.value) && Object.keys(iconImage.parameters).length > 0;
  15550. var symbolSortKey = layout.get('symbol-sort-key');
  15551. this.features = [];
  15552. if (!hasText && !hasIcon) {
  15553. return;
  15554. }
  15555. var icons = options.iconDependencies;
  15556. var stacks = options.glyphDependencies;
  15557. var availableImages = options.availableImages;
  15558. var globalProperties = new EvaluationParameters$1(this.zoom);
  15559. for (var i$1 = 0, list$1 = features; i$1 < list$1.length; i$1 += 1) {
  15560. var ref = list$1[i$1];
  15561. var feature = ref.feature;
  15562. var index = ref.index;
  15563. var sourceLayerIndex = ref.sourceLayerIndex;
  15564. if (!layer._featureFilter(globalProperties, feature)) {
  15565. continue;
  15566. }
  15567. var text = (void 0);
  15568. if (hasText) {
  15569. // Expression evaluation will automatically coerce to Formatted
  15570. // but plain string token evaluation skips that pathway so do the
  15571. // conversion here.
  15572. var resolvedTokens = layer.getValueAndResolveTokens('text-field', feature, availableImages);
  15573. var formattedText = Formatted$1.factory(resolvedTokens);
  15574. if (containsRTLText(formattedText)) {
  15575. this.hasRTLText = true;
  15576. }
  15577. if (
  15578. !this.hasRTLText || // non-rtl text so can proceed safely
  15579. getRTLTextPluginStatus() === 'unavailable' || // We don't intend to lazy-load the rtl text plugin, so proceed with incorrect shaping
  15580. this.hasRTLText && plugin.isParsed() // Use the rtlText plugin to shape text
  15581. ) {
  15582. text = transformText$1(formattedText, layer, feature);
  15583. }
  15584. }
  15585. var icon = (void 0);
  15586. if (hasIcon) {
  15587. // Expression evaluation will automatically coerce to Image
  15588. // but plain string token evaluation skips that pathway so do the
  15589. // conversion here.
  15590. var resolvedTokens$1 = layer.getValueAndResolveTokens('icon-image', feature, availableImages);
  15591. if (resolvedTokens$1 instanceof ResolvedImage$1) {
  15592. icon = resolvedTokens$1;
  15593. } else {
  15594. icon = ResolvedImage$1.fromString(resolvedTokens$1);
  15595. }
  15596. }
  15597. if (!text && !icon) {
  15598. continue;
  15599. }
  15600. var sortKey = this.sortFeaturesByKey ?
  15601. symbolSortKey.evaluate(feature, {}) :
  15602. undefined;
  15603. var symbolFeature = {
  15604. text: text,
  15605. icon: icon,
  15606. index: index,
  15607. sourceLayerIndex: sourceLayerIndex,
  15608. geometry: loadGeometry(feature),
  15609. properties: feature.properties,
  15610. type: vectorTileFeatureTypes$2[feature.type],
  15611. sortKey: sortKey
  15612. };
  15613. if (typeof feature.id !== 'undefined') {
  15614. symbolFeature.id = feature.id;
  15615. }
  15616. this.features.push(symbolFeature);
  15617. if (icon) {
  15618. icons[icon.name] = true;
  15619. }
  15620. if (text) {
  15621. var fontStack = textFont.evaluate(feature, {}).join(',');
  15622. var textAlongLine = layout.get('text-rotation-alignment') === 'map' && layout.get('symbol-placement') !== 'point';
  15623. this.allowVerticalPlacement = this.writingModes && this.writingModes.indexOf(Shaping.WritingMode.vertical) >= 0;
  15624. for (var i = 0, list = text.sections; i < list.length; i += 1) {
  15625. var section = list[i];
  15626. if (!section.image) {
  15627. var doesAllowVerticalWritingMode = ScriptDetection.allowsVerticalWritingMode(text.toString());
  15628. var sectionFont = section.fontStack || fontStack;
  15629. var sectionStack = stacks[sectionFont] = stacks[sectionFont] || {};
  15630. this.calculateGlyphDependencies(section.text, sectionStack, textAlongLine, this.allowVerticalPlacement, doesAllowVerticalWritingMode);
  15631. } else {
  15632. // Add section image to the list of dependencies.
  15633. icons[section.image.name] = true;
  15634. }
  15635. }
  15636. }
  15637. }
  15638. if (layout.get('symbol-placement') === 'line') {
  15639. // Merge adjacent lines with the same text to improve labelling.
  15640. // It's better to place labels on one long line than on many short segments.
  15641. this.features = mergeLines(this.features);
  15642. }
  15643. if (this.sortFeaturesByKey) {
  15644. this.features.sort(function (a, b) {
  15645. // a.sortKey is always a number when sortFeaturesByKey is true
  15646. return ((a.sortKey ) ) - ((b.sortKey ) );
  15647. });
  15648. }
  15649. };
  15650. SymbolBucket.prototype.update = function update(states, vtLayer, imagePositions) {
  15651. if (!this.stateDependentLayers.length) {
  15652. return;
  15653. }
  15654. this.text.programConfigurations.updatePaintArrays(states, vtLayer, this.layers, imagePositions);
  15655. this.icon.programConfigurations.updatePaintArrays(states, vtLayer, this.layers, imagePositions);
  15656. };
  15657. SymbolBucket.prototype.isEmpty = function isEmpty() {
  15658. // When the bucket encounters only rtl-text but the plugin isnt loaded, no symbol instances will be created.
  15659. // In order for the bucket to be serialized, and not discarded as an empty bucket both checks are necessary.
  15660. return this.symbolInstances.length === 0 && !this.hasRTLText;
  15661. };
  15662. SymbolBucket.prototype.uploadPending = function uploadPending() {
  15663. return !this.uploaded || this.text.programConfigurations.needsUpload || this.icon.programConfigurations.needsUpload;
  15664. };
  15665. SymbolBucket.prototype.upload = function upload(context) {
  15666. // if (!this.uploaded) {
  15667. // this.textCollisionBox.upload(context);
  15668. // this.iconCollisionBox.upload(context);
  15669. // this.textCollisionCircle.upload(context);
  15670. // this.iconCollisionCircle.upload(context);
  15671. // }
  15672. // this.text.upload(context, this.sortFeaturesByY, !this.uploaded, this.text.programConfigurations.needsUpload);
  15673. // this.icon.upload(context, this.sortFeaturesByY, !this.uploaded, this.icon.programConfigurations.needsUpload);
  15674. // this.uploaded = true;
  15675. };
  15676. SymbolBucket.prototype.destroy = function destroy() {
  15677. // this.text.destroy();
  15678. // this.icon.destroy();
  15679. // this.textCollisionBox.destroy();
  15680. // this.iconCollisionBox.destroy();
  15681. // this.textCollisionCircle.destroy();
  15682. // this.iconCollisionCircle.destroy();
  15683. };
  15684. SymbolBucket.prototype.clear = function clear() {
  15685. };
  15686. SymbolBucket.prototype.addToLineVertexArray = function addToLineVertexArray(anchor, line) {
  15687. var lineStartIndex = this.lineVertexArray.length;
  15688. if (anchor.segment !== undefined) {
  15689. var sumForwardLength = anchor.dist(line[anchor.segment + 1]);
  15690. var sumBackwardLength = anchor.dist(line[anchor.segment]);
  15691. var vertices = {};
  15692. for (var i = anchor.segment + 1; i < line.length; i++) {
  15693. vertices[i] = {x: line[i].x, y: line[i].y, tileUnitDistanceFromAnchor: sumForwardLength};
  15694. if (i < line.length - 1) {
  15695. sumForwardLength += line[i + 1].dist(line[i]);
  15696. }
  15697. }
  15698. for (var i$1 = anchor.segment || 0; i$1 >= 0; i$1--) {
  15699. vertices[i$1] = {x: line[i$1].x, y: line[i$1].y, tileUnitDistanceFromAnchor: sumBackwardLength};
  15700. if (i$1 > 0) {
  15701. sumBackwardLength += line[i$1 - 1].dist(line[i$1]);
  15702. }
  15703. }
  15704. for (var i$2 = 0; i$2 < line.length; i$2++) {
  15705. var vertex = vertices[i$2];
  15706. this.lineVertexArray.emplaceBack(vertex.x, vertex.y, vertex.tileUnitDistanceFromAnchor);
  15707. }
  15708. }
  15709. return {
  15710. lineStartIndex: lineStartIndex,
  15711. lineLength: this.lineVertexArray.length - lineStartIndex
  15712. };
  15713. };
  15714. SymbolBucket.prototype.addSymbols = function addSymbols(arrays, quads, sizeVertex, lineOffset, alongLine, feature, writingMode, labelAnchor, lineStartIndex, lineLength, associatedIconIndex) {
  15715. var this$1 = this;
  15716. var indexArray = arrays.indexArray;
  15717. var layoutVertexArray = arrays.layoutVertexArray;
  15718. var dynamicLayoutVertexArray = arrays.dynamicLayoutVertexArray;
  15719. var segment = arrays.segments.prepareSegment(4 * quads.length, arrays.layoutVertexArray, arrays.indexArray, feature.sortKey);
  15720. var glyphOffsetArrayStart = this.glyphOffsetArray.length;
  15721. var vertexStartIndex = segment.vertexLength;
  15722. var angle = (this.allowVerticalPlacement && writingMode === Shaping.WritingMode.vertical) ? Math.PI / 2 : 0;
  15723. var addSymbol = function (symbol) {
  15724. var tl = symbol.tl,
  15725. tr = symbol.tr,
  15726. bl = symbol.bl,
  15727. br = symbol.br,
  15728. tex = symbol.tex,
  15729. pixelOffsetTL = symbol.pixelOffsetTL,
  15730. pixelOffsetBR = symbol.pixelOffsetBR,
  15731. mfsx = symbol.minFontScaleX,
  15732. mfsy = symbol.minFontScaleY;
  15733. var index = segment.vertexLength;
  15734. var y = symbol.glyphOffset[1];
  15735. 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);
  15736. 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);
  15737. 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);
  15738. 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);
  15739. addDynamicAttributes(dynamicLayoutVertexArray, labelAnchor, angle);
  15740. indexArray.emplaceBack(index, index + 1, index + 2);
  15741. indexArray.emplaceBack(index + 1, index + 2, index + 3);
  15742. segment.vertexLength += 4;
  15743. segment.primitiveLength += 2;
  15744. this$1.glyphOffsetArray.emplaceBack(symbol.glyphOffset[0]);
  15745. };
  15746. if (feature.text && feature.text.sections) {
  15747. var sections = feature.text.sections;
  15748. if (this.hasPaintOverrides) {
  15749. var currentSectionIndex;
  15750. var populatePaintArrayForSection = function (sectionIndex, lastSection) {
  15751. if (currentSectionIndex !== undefined && (currentSectionIndex !== sectionIndex || lastSection)) {
  15752. arrays.programConfigurations.populatePaintArrays(arrays.layoutVertexArray.length, feature, feature.index, {}, sections[currentSectionIndex]);
  15753. }
  15754. currentSectionIndex = sectionIndex;
  15755. };
  15756. for (var i = 0, list = quads; i < list.length; i += 1) {
  15757. var symbol = list[i];
  15758. populatePaintArrayForSection(symbol.sectionIndex, false);
  15759. addSymbol(symbol);
  15760. }
  15761. // Populate paint arrays for the last section.
  15762. populatePaintArrayForSection(currentSectionIndex, true);
  15763. } else {
  15764. for (var i$1 = 0, list$1 = quads; i$1 < list$1.length; i$1 += 1) {
  15765. var symbol$1 = list$1[i$1];
  15766. addSymbol(symbol$1);
  15767. }
  15768. arrays.programConfigurations.populatePaintArrays(arrays.layoutVertexArray.length, feature, feature.index, {}, sections[0]);
  15769. }
  15770. } else {
  15771. for (var i$2 = 0, list$2 = quads; i$2 < list$2.length; i$2 += 1) {
  15772. var symbol$2 = list$2[i$2];
  15773. addSymbol(symbol$2);
  15774. }
  15775. arrays.programConfigurations.populatePaintArrays(arrays.layoutVertexArray.length, feature, feature.index, {});
  15776. }
  15777. arrays.placedSymbolArray.emplaceBack(labelAnchor.x, labelAnchor.y,
  15778. glyphOffsetArrayStart, this.glyphOffsetArray.length - glyphOffsetArrayStart, vertexStartIndex,
  15779. lineStartIndex, lineLength, (labelAnchor.segment ),
  15780. sizeVertex ? sizeVertex[0] : 0, sizeVertex ? sizeVertex[1] : 0,
  15781. lineOffset[0], lineOffset[1],
  15782. writingMode,
  15783. // placedOrientation is null initially; will be updated to horizontal(1)/vertical(2) if placed
  15784. 0,
  15785. (false ),
  15786. // The crossTileID is only filled/used on the foreground for dynamic text anchors
  15787. 0,
  15788. associatedIconIndex
  15789. );
  15790. };
  15791. SymbolBucket.prototype._addCollisionDebugVertex = function _addCollisionDebugVertex(layoutVertexArray, collisionVertexArray, point, anchorX, anchorY, extrude) {
  15792. collisionVertexArray.emplaceBack(0, 0);
  15793. return layoutVertexArray.emplaceBack(
  15794. // pos
  15795. point.x,
  15796. point.y,
  15797. // a_anchor_pos
  15798. anchorX,
  15799. anchorY,
  15800. // extrude
  15801. Math.round(extrude.x),
  15802. Math.round(extrude.y));
  15803. };
  15804. SymbolBucket.prototype.addCollisionDebugVertices = function addCollisionDebugVertices(x1, y1, x2, y2, arrays, boxAnchorPoint, symbolInstance, isCircle) {
  15805. var segment = arrays.segments.prepareSegment(4, arrays.layoutVertexArray, arrays.indexArray);
  15806. var index = segment.vertexLength;
  15807. var layoutVertexArray = arrays.layoutVertexArray;
  15808. var collisionVertexArray = arrays.collisionVertexArray;
  15809. var anchorX = symbolInstance.anchorX;
  15810. var anchorY = symbolInstance.anchorY;
  15811. this._addCollisionDebugVertex(layoutVertexArray, collisionVertexArray, boxAnchorPoint, anchorX, anchorY, new pointGeometry(x1, y1));
  15812. this._addCollisionDebugVertex(layoutVertexArray, collisionVertexArray, boxAnchorPoint, anchorX, anchorY, new pointGeometry(x2, y1));
  15813. this._addCollisionDebugVertex(layoutVertexArray, collisionVertexArray, boxAnchorPoint, anchorX, anchorY, new pointGeometry(x2, y2));
  15814. this._addCollisionDebugVertex(layoutVertexArray, collisionVertexArray, boxAnchorPoint, anchorX, anchorY, new pointGeometry(x1, y2));
  15815. segment.vertexLength += 4;
  15816. if (isCircle) {
  15817. var indexArray = (arrays.indexArray );
  15818. indexArray.emplaceBack(index, index + 1, index + 2);
  15819. indexArray.emplaceBack(index, index + 2, index + 3);
  15820. segment.primitiveLength += 2;
  15821. } else {
  15822. var indexArray$1 = (arrays.indexArray );
  15823. indexArray$1.emplaceBack(index, index + 1);
  15824. indexArray$1.emplaceBack(index + 1, index + 2);
  15825. indexArray$1.emplaceBack(index + 2, index + 3);
  15826. indexArray$1.emplaceBack(index + 3, index);
  15827. segment.primitiveLength += 4;
  15828. }
  15829. };
  15830. SymbolBucket.prototype.addDebugCollisionBoxes = function addDebugCollisionBoxes(startIndex, endIndex, symbolInstance, isText) {
  15831. for (var b = startIndex; b < endIndex; b++) {
  15832. var box = (this.collisionBoxArray.get(b) );
  15833. var x1 = box.x1;
  15834. var y1 = box.y1;
  15835. var x2 = box.x2;
  15836. var y2 = box.y2;
  15837. // If the radius > 0, this collision box is actually a circle
  15838. // The data we add to the buffers is exactly the same, but we'll render with a different shader.
  15839. var isCircle = box.radius > 0;
  15840. this.addCollisionDebugVertices(x1, y1, x2, y2, isCircle ?
  15841. (isText ? this.textCollisionCircle : this.iconCollisionCircle) : (isText ? this.textCollisionBox : this.iconCollisionBox),
  15842. box.anchorPoint, symbolInstance, isCircle);
  15843. }
  15844. };
  15845. SymbolBucket.prototype.generateCollisionDebugBuffers = function generateCollisionDebugBuffers() {
  15846. for (var i = 0; i < this.symbolInstances.length; i++) {
  15847. var symbolInstance = this.symbolInstances.get(i);
  15848. this.addDebugCollisionBoxes(symbolInstance.textBoxStartIndex, symbolInstance.textBoxEndIndex, symbolInstance, true);
  15849. this.addDebugCollisionBoxes(symbolInstance.verticalTextBoxStartIndex, symbolInstance.verticalTextBoxEndIndex, symbolInstance, true);
  15850. this.addDebugCollisionBoxes(symbolInstance.iconBoxStartIndex, symbolInstance.iconBoxEndIndex, symbolInstance, false);
  15851. this.addDebugCollisionBoxes(symbolInstance.verticalIconBoxStartIndex, symbolInstance.verticalIconBoxEndIndex, symbolInstance, false);
  15852. }
  15853. };
  15854. // These flat arrays are meant to be quicker to iterate over than the source
  15855. // CollisionBoxArray
  15856. SymbolBucket.prototype._deserializeCollisionBoxesForSymbol = function _deserializeCollisionBoxesForSymbol(collisionBoxArray, textStartIndex, textEndIndex, verticalTextStartIndex, verticalTextEndIndex, iconStartIndex, iconEndIndex, verticalIconStartIndex, verticalIconEndIndex) {
  15857. var collisionArrays = {};
  15858. for (var k = textStartIndex; k < textEndIndex; k++) {
  15859. var box = (collisionBoxArray.get(k) );
  15860. if (box.radius === 0) {
  15861. collisionArrays.textBox = {x1: box.x1, y1: box.y1, x2: box.x2, y2: box.y2, anchorPointX: box.anchorPointX, anchorPointY: box.anchorPointY};
  15862. collisionArrays.textFeatureIndex = box.featureIndex;
  15863. break; // Only one box allowed per instance
  15864. } else {
  15865. if (!collisionArrays.textCircles) {
  15866. collisionArrays.textCircles = [];
  15867. collisionArrays.textFeatureIndex = box.featureIndex;
  15868. }
  15869. var used = 1; // May be updated at collision detection time
  15870. collisionArrays.textCircles.push(box.anchorPointX, box.anchorPointY, box.radius, box.signedDistanceFromAnchor, used);
  15871. }
  15872. }
  15873. for (var k$1 = verticalTextStartIndex; k$1 < verticalTextEndIndex; k$1++) {
  15874. var box$1 = (collisionBoxArray.get(k$1) );
  15875. if (box$1.radius === 0) {
  15876. 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};
  15877. collisionArrays.verticalTextFeatureIndex = box$1.featureIndex;
  15878. break; // Only one box allowed per instance
  15879. }
  15880. }
  15881. for (var k$2 = iconStartIndex; k$2 < iconEndIndex; k$2++) {
  15882. // An icon can only have one box now, so this indexing is a bit vestigial...
  15883. var box$2 = (collisionBoxArray.get(k$2) );
  15884. if (box$2.radius === 0) {
  15885. 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};
  15886. collisionArrays.iconFeatureIndex = box$2.featureIndex;
  15887. break; // Only one box allowed per instance
  15888. }
  15889. }
  15890. for (var k$3 = verticalIconStartIndex; k$3 < verticalIconEndIndex; k$3++) {
  15891. // An icon can only have one box now, so this indexing is a bit vestigial...
  15892. var box$3 = (collisionBoxArray.get(k$3) );
  15893. if (box$3.radius === 0) {
  15894. 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};
  15895. collisionArrays.verticalIconFeatureIndex = box$3.featureIndex;
  15896. break; // Only one box allowed per instance
  15897. }
  15898. }
  15899. return collisionArrays;
  15900. };
  15901. SymbolBucket.prototype.deserializeCollisionBoxes = function deserializeCollisionBoxes(collisionBoxArray) {
  15902. this.collisionArrays = [];
  15903. for (var i = 0; i < this.symbolInstances.length; i++) {
  15904. var symbolInstance = this.symbolInstances.get(i);
  15905. this.collisionArrays.push(this._deserializeCollisionBoxesForSymbol(
  15906. collisionBoxArray,
  15907. symbolInstance.textBoxStartIndex,
  15908. symbolInstance.textBoxEndIndex,
  15909. symbolInstance.verticalTextBoxStartIndex,
  15910. symbolInstance.verticalTextBoxEndIndex,
  15911. symbolInstance.iconBoxStartIndex,
  15912. symbolInstance.iconBoxEndIndex,
  15913. symbolInstance.verticalIconBoxStartIndex,
  15914. symbolInstance.verticalIconBoxEndIndex
  15915. ));
  15916. }
  15917. };
  15918. SymbolBucket.prototype.hasTextData = function hasTextData() {
  15919. return this.text.segments.get().length > 0;
  15920. };
  15921. SymbolBucket.prototype.hasIconData = function hasIconData() {
  15922. return this.icon.segments.get().length > 0;
  15923. };
  15924. SymbolBucket.prototype.hasTextCollisionBoxData = function hasTextCollisionBoxData() {
  15925. return this.textCollisionBox.segments.get().length > 0;
  15926. };
  15927. SymbolBucket.prototype.hasIconCollisionBoxData = function hasIconCollisionBoxData() {
  15928. return this.iconCollisionBox.segments.get().length > 0;
  15929. };
  15930. SymbolBucket.prototype.hasTextCollisionCircleData = function hasTextCollisionCircleData() {
  15931. return this.textCollisionCircle.segments.get().length > 0;
  15932. };
  15933. SymbolBucket.prototype.hasIconCollisionCircleData = function hasIconCollisionCircleData() {
  15934. return this.iconCollisionCircle.segments.get().length > 0;
  15935. };
  15936. SymbolBucket.prototype.addIndicesForPlacedSymbol = function addIndicesForPlacedSymbol(iconOrText, placedSymbolIndex) {
  15937. var placedSymbol = iconOrText.placedSymbolArray.get(placedSymbolIndex);
  15938. var endIndex = placedSymbol.vertexStartIndex + placedSymbol.numGlyphs * 4;
  15939. for (var vertexIndex = placedSymbol.vertexStartIndex; vertexIndex < endIndex; vertexIndex += 4) {
  15940. iconOrText.indexArray.emplaceBack(vertexIndex, vertexIndex + 1, vertexIndex + 2);
  15941. iconOrText.indexArray.emplaceBack(vertexIndex + 1, vertexIndex + 2, vertexIndex + 3);
  15942. }
  15943. };
  15944. SymbolBucket.prototype.getSortedSymbolIndexes = function getSortedSymbolIndexes(angle) {
  15945. if (this.sortedAngle === angle && this.symbolInstanceIndexes !== undefined) {
  15946. return this.symbolInstanceIndexes;
  15947. }
  15948. var sin = Math.sin(angle);
  15949. var cos = Math.cos(angle);
  15950. var rotatedYs = [];
  15951. var featureIndexes = [];
  15952. var result = [];
  15953. for (var i = 0; i < this.symbolInstances.length; ++i) {
  15954. result.push(i);
  15955. var symbolInstance = this.symbolInstances.get(i);
  15956. rotatedYs.push(Math.round(sin * symbolInstance.anchorX + cos * symbolInstance.anchorY) | 0);
  15957. featureIndexes.push(symbolInstance.featureIndex);
  15958. }
  15959. result.sort(function (aIndex, bIndex) {
  15960. return (rotatedYs[aIndex] - rotatedYs[bIndex]) ||
  15961. (featureIndexes[bIndex] - featureIndexes[aIndex]);
  15962. });
  15963. return result;
  15964. };
  15965. SymbolBucket.prototype.sortFeatures = function sortFeatures(angle) {
  15966. var this$1 = this;
  15967. if (!this.sortFeaturesByY) {
  15968. return;
  15969. }
  15970. if (this.sortedAngle === angle) {
  15971. return;
  15972. }
  15973. // The current approach to sorting doesn't sort across segments so don't try.
  15974. // Sorting within segments separately seemed not to be worth the complexity.
  15975. if (this.text.segments.get().length > 1 || this.icon.segments.get().length > 1) {
  15976. return;
  15977. }
  15978. // If the symbols are allowed to overlap sort them by their vertical screen position.
  15979. // The index array buffer is rewritten to reference the (unchanged) vertices in the
  15980. // sorted order.
  15981. // To avoid sorting the actual symbolInstance array we sort an array of indexes.
  15982. this.symbolInstanceIndexes = this.getSortedSymbolIndexes(angle);
  15983. this.sortedAngle = angle;
  15984. this.text.indexArray.clear();
  15985. this.icon.indexArray.clear();
  15986. this.featureSortOrder = [];
  15987. for (var i$1 = 0, list = this.symbolInstanceIndexes; i$1 < list.length; i$1 += 1) {
  15988. var i = list[i$1];
  15989. var symbolInstance = this.symbolInstances.get(i);
  15990. this.featureSortOrder.push(symbolInstance.featureIndex);
  15991. [
  15992. symbolInstance.rightJustifiedTextSymbolIndex,
  15993. symbolInstance.centerJustifiedTextSymbolIndex,
  15994. symbolInstance.leftJustifiedTextSymbolIndex
  15995. ].forEach(function (index, i, array) {
  15996. // Only add a given index the first time it shows up,
  15997. // to avoid duplicate opacity entries when multiple justifications
  15998. // share the same glyphs.
  15999. if (index >= 0 && array.indexOf(index) === i) {
  16000. this$1.addIndicesForPlacedSymbol(this$1.text, index);
  16001. }
  16002. });
  16003. if (symbolInstance.verticalPlacedTextSymbolIndex >= 0) {
  16004. this.addIndicesForPlacedSymbol(this.text, symbolInstance.verticalPlacedTextSymbolIndex);
  16005. }
  16006. if (symbolInstance.placedIconSymbolIndex >= 0) {
  16007. this.addIndicesForPlacedSymbol(this.icon, symbolInstance.placedIconSymbolIndex);
  16008. }
  16009. if (symbolInstance.verticalPlacedIconSymbolIndex >= 0) {
  16010. this.addIndicesForPlacedSymbol(this.icon, symbolInstance.verticalPlacedIconSymbolIndex);
  16011. }
  16012. }
  16013. if (this.text.indexBuffer) {
  16014. this.text.indexBuffer.updateData(this.text.indexArray);
  16015. }
  16016. if (this.icon.indexBuffer) {
  16017. this.icon.indexBuffer.updateData(this.icon.indexArray);
  16018. }
  16019. };
  16020. WebWorkerTransfer.register('SymbolBucket', SymbolBucket, {
  16021. //omit: ['layers', 'collisionBoxArray', 'features', 'compareText']
  16022. omit: ['layers', 'collisionBoxArray', 'compareText']
  16023. });
  16024. // this constant is based on the size of StructArray indexes used in a symbol
  16025. // bucket--namely, glyphOffsetArrayStart
  16026. // eg the max valid UInt16 is 65,535
  16027. // See https://github.com/mapbox/mapbox-gl-js/issues/2907 for motivation
  16028. // lineStartIndex and textBoxStartIndex could potentially be concerns
  16029. // but we expect there to be many fewer boxes/lines than glyphs
  16030. SymbolBucket.MAX_GLYPHS = 65535;
  16031. SymbolBucket.addDynamicAttributes = addDynamicAttributes;
  16032. var ColorType$7 = {kind: 'color'};
  16033. var FormattedType$4 = {kind: 'formatted'};
  16034. var layout$7 = new Properties({
  16035. "symbol-placement": new DataConstantProperty(StyleSpec["layout_symbol"]["symbol-placement"]),
  16036. "symbol-spacing": new DataConstantProperty(StyleSpec["layout_symbol"]["symbol-spacing"]),
  16037. "symbol-avoid-edges": new DataConstantProperty(StyleSpec["layout_symbol"]["symbol-avoid-edges"]),
  16038. "symbol-sort-key": new DataDrivenProperty(StyleSpec["layout_symbol"]["symbol-sort-key"]),
  16039. "symbol-z-order": new DataConstantProperty(StyleSpec["layout_symbol"]["symbol-z-order"]),
  16040. "icon-allow-overlap": new DataConstantProperty(StyleSpec["layout_symbol"]["icon-allow-overlap"]),
  16041. "icon-ignore-placement": new DataConstantProperty(StyleSpec["layout_symbol"]["icon-ignore-placement"]),
  16042. "icon-optional": new DataConstantProperty(StyleSpec["layout_symbol"]["icon-optional"]),
  16043. "icon-rotation-alignment": new DataConstantProperty(StyleSpec["layout_symbol"]["icon-rotation-alignment"]),
  16044. "icon-size": new DataDrivenProperty(StyleSpec["layout_symbol"]["icon-size"]),
  16045. "icon-text-fit": new DataConstantProperty(StyleSpec["layout_symbol"]["icon-text-fit"]),
  16046. "icon-text-fit-padding": new DataConstantProperty(StyleSpec["layout_symbol"]["icon-text-fit-padding"]),
  16047. "icon-image": new DataDrivenProperty(StyleSpec["layout_symbol"]["icon-image"]),
  16048. "icon-rotate": new DataDrivenProperty(StyleSpec["layout_symbol"]["icon-rotate"]),
  16049. "icon-padding": new DataConstantProperty(StyleSpec["layout_symbol"]["icon-padding"]),
  16050. "icon-keep-upright": new DataConstantProperty(StyleSpec["layout_symbol"]["icon-keep-upright"]),
  16051. "icon-offset": new DataDrivenProperty(StyleSpec["layout_symbol"]["icon-offset"]),
  16052. "icon-anchor": new DataDrivenProperty(StyleSpec["layout_symbol"]["icon-anchor"]),
  16053. "icon-pitch-alignment": new DataConstantProperty(StyleSpec["layout_symbol"]["icon-pitch-alignment"]),
  16054. "text-pitch-alignment": new DataConstantProperty(StyleSpec["layout_symbol"]["text-pitch-alignment"]),
  16055. "text-rotation-alignment": new DataConstantProperty(StyleSpec["layout_symbol"]["text-rotation-alignment"]),
  16056. "text-field": new DataDrivenProperty(StyleSpec["layout_symbol"]["text-field"]),
  16057. "text-font": new DataDrivenProperty(StyleSpec["layout_symbol"]["text-font"]),
  16058. "text-size": new DataDrivenProperty(StyleSpec["layout_symbol"]["text-size"]),
  16059. "text-max-width": new DataDrivenProperty(StyleSpec["layout_symbol"]["text-max-width"]),
  16060. "text-line-height": new DataConstantProperty(StyleSpec["layout_symbol"]["text-line-height"]),
  16061. "text-letter-spacing": new DataDrivenProperty(StyleSpec["layout_symbol"]["text-letter-spacing"]),
  16062. "text-justify": new DataDrivenProperty(StyleSpec["layout_symbol"]["text-justify"]),
  16063. "text-radial-offset": new DataDrivenProperty(StyleSpec["layout_symbol"]["text-radial-offset"]),
  16064. "text-variable-anchor": new DataConstantProperty(StyleSpec["layout_symbol"]["text-variable-anchor"]),
  16065. "text-anchor": new DataDrivenProperty(StyleSpec["layout_symbol"]["text-anchor"]),
  16066. "text-max-angle": new DataConstantProperty(StyleSpec["layout_symbol"]["text-max-angle"]),
  16067. "text-writing-mode": new DataConstantProperty(StyleSpec["layout_symbol"]["text-writing-mode"]),
  16068. "text-rotate": new DataDrivenProperty(StyleSpec["layout_symbol"]["text-rotate"]),
  16069. "text-padding": new DataConstantProperty(StyleSpec["layout_symbol"]["text-padding"]),
  16070. "text-keep-upright": new DataConstantProperty(StyleSpec["layout_symbol"]["text-keep-upright"]),
  16071. "text-transform": new DataDrivenProperty(StyleSpec["layout_symbol"]["text-transform"]),
  16072. "text-offset": new DataDrivenProperty(StyleSpec["layout_symbol"]["text-offset"]),
  16073. "text-allow-overlap": new DataConstantProperty(StyleSpec["layout_symbol"]["text-allow-overlap"]),
  16074. "text-ignore-placement": new DataConstantProperty(StyleSpec["layout_symbol"]["text-ignore-placement"]),
  16075. "text-optional": new DataConstantProperty(StyleSpec["layout_symbol"]["text-optional"])
  16076. });
  16077. var paint$7 = new Properties({
  16078. "icon-opacity": new DataDrivenProperty(StyleSpec["paint_symbol"]["icon-opacity"]),
  16079. "icon-color": new DataDrivenProperty(StyleSpec["paint_symbol"]["icon-color"]),
  16080. "icon-halo-color": new DataDrivenProperty(StyleSpec["paint_symbol"]["icon-halo-color"]),
  16081. "icon-halo-width": new DataDrivenProperty(StyleSpec["paint_symbol"]["icon-halo-width"]),
  16082. "icon-halo-blur": new DataDrivenProperty(StyleSpec["paint_symbol"]["icon-halo-blur"]),
  16083. "icon-translate": new DataConstantProperty(StyleSpec["paint_symbol"]["icon-translate"]),
  16084. "icon-translate-anchor": new DataConstantProperty(StyleSpec["paint_symbol"]["icon-translate-anchor"]),
  16085. "text-opacity": new DataDrivenProperty(StyleSpec["paint_symbol"]["text-opacity"]),
  16086. "text-color": new DataDrivenProperty(StyleSpec["paint_symbol"]["text-color"], { runtimeType: ColorType$7, getOverride: function (o) {
  16087. return o.textColor;
  16088. }, hasOverride: function (o) {
  16089. return !!o.textColor;
  16090. } }),
  16091. "text-halo-color": new DataDrivenProperty(StyleSpec["paint_symbol"]["text-halo-color"]),
  16092. "text-halo-width": new DataDrivenProperty(StyleSpec["paint_symbol"]["text-halo-width"]),
  16093. "text-halo-blur": new DataDrivenProperty(StyleSpec["paint_symbol"]["text-halo-blur"]),
  16094. "text-translate": new DataConstantProperty(StyleSpec["paint_symbol"]["text-translate"]),
  16095. "text-translate-anchor": new DataConstantProperty(StyleSpec["paint_symbol"]["text-translate-anchor"])
  16096. });
  16097. // Note: without adding the explicit type annotation, Flow infers weaker types
  16098. // for these objects from their use in the constructor to StyleLayer, as
  16099. // {layout?: Properties<...>, paint: Properties<...>}
  16100. var properties$6 = ({ paint: paint$7, layout: layout$7 }
  16101. );
  16102. var SymbolStyleLayer = /*@__PURE__*/(function (StyleLayer) {
  16103. function SymbolStyleLayer(layer) {
  16104. StyleLayer.call(this, layer, properties$6);
  16105. }
  16106. if (StyleLayer) SymbolStyleLayer.__proto__ = StyleLayer;
  16107. SymbolStyleLayer.prototype = Object.create(StyleLayer && StyleLayer.prototype);
  16108. SymbolStyleLayer.prototype.constructor = SymbolStyleLayer;
  16109. SymbolStyleLayer.prototype.recalculate = function recalculate(parameters, availableImages) {
  16110. StyleLayer.prototype.recalculate.call(this, parameters, availableImages);
  16111. if (this.layout.get('icon-rotation-alignment') === 'auto') {
  16112. if (this.layout.get('symbol-placement') !== 'point') {
  16113. this.layout._values['icon-rotation-alignment'] = 'map';
  16114. } else {
  16115. this.layout._values['icon-rotation-alignment'] = 'viewport';
  16116. }
  16117. }
  16118. if (this.layout.get('text-rotation-alignment') === 'auto') {
  16119. if (this.layout.get('symbol-placement') !== 'point') {
  16120. this.layout._values['text-rotation-alignment'] = 'map';
  16121. } else {
  16122. this.layout._values['text-rotation-alignment'] = 'viewport';
  16123. }
  16124. }
  16125. // If unspecified, `*-pitch-alignment` inherits `*-rotation-alignment`
  16126. if (this.layout.get('text-pitch-alignment') === 'auto') {
  16127. this.layout._values['text-pitch-alignment'] = this.layout.get('text-rotation-alignment');
  16128. }
  16129. if (this.layout.get('icon-pitch-alignment') === 'auto') {
  16130. this.layout._values['icon-pitch-alignment'] = this.layout.get('icon-rotation-alignment');
  16131. }
  16132. if (this.layout.get('symbol-placement') === 'point') {
  16133. var writingModes = this.layout.get('text-writing-mode');
  16134. if (writingModes) {
  16135. // remove duplicates, preserving order
  16136. var deduped = [];
  16137. for (var i = 0, list = writingModes; i < list.length; i += 1) {
  16138. var m = list[i];
  16139. if (deduped.indexOf(m) < 0) {
  16140. deduped.push(m);
  16141. }
  16142. }
  16143. this.layout._values['text-writing-mode'] = deduped;
  16144. } else {
  16145. this.layout._values['text-writing-mode'] = ['horizontal'];
  16146. }
  16147. }
  16148. this._setPaintOverrides();
  16149. };
  16150. SymbolStyleLayer.prototype.getValueAndResolveTokens = function getValueAndResolveTokens(name, feature, availableImages) {
  16151. var value = this.layout.get(name).evaluate(feature, {}, availableImages);
  16152. var unevaluated = this._unevaluatedLayout._values[name];
  16153. if (!unevaluated.isDataDriven() && !Expression.isExpression(unevaluated.value) && value) {
  16154. return Util.resolveTokens(feature.properties, value);
  16155. }
  16156. return value;
  16157. };
  16158. SymbolStyleLayer.prototype.createBucket = function createBucket(parameters) {
  16159. return new SymbolBucket(parameters);
  16160. };
  16161. SymbolStyleLayer.prototype.queryRadius = function queryRadius() {
  16162. return 0;
  16163. };
  16164. SymbolStyleLayer.prototype.queryIntersectsFeature = function queryIntersectsFeature() {
  16165. assert_1(false); // Should take a different path in FeatureIndex
  16166. return false;
  16167. };
  16168. SymbolStyleLayer.prototype._setPaintOverrides = function _setPaintOverrides() {
  16169. for (var i = 0, list = properties$6.paint.overridableProperties; i < list.length; i += 1) {
  16170. var overridable = list[i];
  16171. if (!SymbolStyleLayer.hasPaintOverride(this.layout, overridable)) {
  16172. continue;
  16173. }
  16174. var overriden = this.paint.get(overridable);
  16175. var override = new FormatSectionOverride(overriden);
  16176. var styleExpression = new StyleExpression(override, overriden.property.specification);
  16177. var expression = null;
  16178. if (overriden.value.kind === 'constant' || overriden.value.kind === 'source') {
  16179. expression = (new ZoomConstantExpression('source', styleExpression) );
  16180. } else {
  16181. expression = (new ZoomDependentExpression('composite',
  16182. styleExpression,
  16183. overriden.value.zoomStops,
  16184. overriden.value._interpolationType) );
  16185. }
  16186. this.paint._values[overridable] = new PossiblyEvaluatedPropertyValue(overriden.property,
  16187. expression,
  16188. overriden.parameters);
  16189. }
  16190. };
  16191. SymbolStyleLayer.prototype._handleOverridablePaintPropertyUpdate = function _handleOverridablePaintPropertyUpdate(name, oldValue, newValue) {
  16192. if (!this.layout || oldValue.isDataDriven() || newValue.isDataDriven()) {
  16193. return false;
  16194. }
  16195. return SymbolStyleLayer.hasPaintOverride(this.layout, name);
  16196. };
  16197. SymbolStyleLayer.hasPaintOverride = function hasPaintOverride(layout, propertyName) {
  16198. var textField = layout.get('text-field');
  16199. var property = properties$6.paint.properties[propertyName];
  16200. var hasOverrides = false;
  16201. var checkSections = function (sections) {
  16202. for (var i = 0, list = sections; i < list.length; i += 1) {
  16203. var section = list[i];
  16204. if (property.overrides && property.overrides.hasOverride(section)) {
  16205. hasOverrides = true;
  16206. return;
  16207. }
  16208. }
  16209. };
  16210. if (textField.value.kind === 'constant' && textField.value.value instanceof Formatted$1) {
  16211. checkSections(textField.value.value.sections);
  16212. } else if (textField.value.kind === 'source') {
  16213. var checkExpression = function (expression) {
  16214. if (hasOverrides) {
  16215. return;
  16216. }
  16217. if (expression instanceof Literal && Values$1.typeOf(expression.value) === FormattedType$4) {
  16218. var formatted = ((expression.value) );
  16219. checkSections(formatted.sections);
  16220. } else if (expression instanceof FormatExpression$1) {
  16221. checkSections(expression.sections);
  16222. } else {
  16223. expression.eachChild(checkExpression);
  16224. }
  16225. };
  16226. var expr = ((textField.value) );
  16227. if (expr._styleExpression) {
  16228. checkExpression(expr._styleExpression.expression);
  16229. }
  16230. }
  16231. return hasOverrides;
  16232. };
  16233. SymbolStyleLayer.hasPaintOverrides = function hasPaintOverrides(layout) {
  16234. for (var i = 0, list = properties$6.paint.overridableProperties; i < list.length; i += 1) {
  16235. var overridable = list[i];
  16236. if (SymbolStyleLayer.hasPaintOverride(layout, overridable)) {
  16237. return true;
  16238. }
  16239. }
  16240. return false;
  16241. };
  16242. return SymbolStyleLayer;
  16243. }(StyleLayer));
  16244. var subclasses = {
  16245. circle: CircleStyleLayer,
  16246. fill: FillStyleLayer,
  16247. line: LineStyleLayer,
  16248. symbol : SymbolStyleLayer
  16249. };
  16250. function createStyleLayer(layer) {
  16251. if(subclasses[layer.type]){
  16252. return new subclasses[layer.type](layer);
  16253. }
  16254. else{
  16255. return null;
  16256. }
  16257. }
  16258. var StyleLayerIndex = function StyleLayerIndex(layerConfigs) {
  16259. this.keyCache = {};
  16260. if (layerConfigs) {
  16261. this.replace(layerConfigs);
  16262. }
  16263. };
  16264. StyleLayerIndex.prototype.replace = function replace (layerConfigs) {
  16265. this._layerConfigs = {};
  16266. this._layers = {};
  16267. this.update(layerConfigs, []);
  16268. };
  16269. function values(obj) {
  16270. var result = [];
  16271. for (var k in obj) {
  16272. result.push(obj[k]);
  16273. }
  16274. return result;
  16275. }
  16276. StyleLayerIndex.prototype.update = function update (layerConfigs, removedIds) {
  16277. var this$1 = this;
  16278. for (var i = 0, list = layerConfigs; i < list.length; i += 1) {
  16279. var layerConfig = list[i];
  16280. this._layerConfigs[layerConfig.id] = layerConfig;
  16281. var layer = createStyleLayer(layerConfig);
  16282. if(layer == null){
  16283. continue;
  16284. }
  16285. this._layers[layerConfig.id] = layer;
  16286. layer._featureFilter = featureFilter.createFilter(layer.filter);
  16287. if (this.keyCache[layerConfig.id])
  16288. { delete this.keyCache[layerConfig.id]; }
  16289. }
  16290. for (var i$1 = 0, list$1 = removedIds; i$1 < list$1.length; i$1 += 1) {
  16291. var id = list$1[i$1];
  16292. delete this.keyCache[id];
  16293. delete this._layerConfigs[id];
  16294. delete this._layers[id];
  16295. }
  16296. this.familiesBySource = {};
  16297. var groups = groupByLayout(values(this._layerConfigs), this.keyCache);
  16298. for (var i$2 = 0, list$2 = groups; i$2 < list$2.length; i$2 += 1) {
  16299. var layerConfigs$1 = list$2[i$2];
  16300. var layers = layerConfigs$1.map(function (layerConfig) { return this$1._layers[layerConfig.id]; });
  16301. var layer$1 = layers[0];
  16302. if (layer$1 == undefined || layer$1.visibility === 'none') {
  16303. continue;
  16304. }
  16305. var sourceId = layer$1.source || '';
  16306. var sourceGroup = this.familiesBySource[sourceId];
  16307. if (!sourceGroup) {
  16308. sourceGroup = this.familiesBySource[sourceId] = {};
  16309. }
  16310. var sourceLayerId = layer$1.sourceLayer;
  16311. var sourceLayerFamilies = sourceGroup[sourceLayerId];
  16312. if (!sourceLayerFamilies) {
  16313. sourceLayerFamilies = sourceGroup[sourceLayerId] = [];
  16314. }
  16315. sourceLayerFamilies.push(layers);
  16316. }
  16317. };
  16318. WebWorkerTransfer.register('FeatureIndex', FeatureIndex, {omit: ['rawTileData', 'sourceLayerCoder']});
  16319. function MVTWorkTile(parameters, transferableObjects) {
  16320. var pbfData = parameters.pbfData;
  16321. var layers = parameters.layers;
  16322. var imageMap = parameters.imageMap;
  16323. var serializeObj = WebWorkerTransfer.deserialize(parameters.serializeObj);
  16324. var featureIndex = serializeObj.featureIndex;
  16325. var zoom = parameters.tileID.z;
  16326. if(!when.defined(featureIndex)){
  16327. featureIndex = new FeatureIndex(parameters.tileID);
  16328. featureIndex.bucketLayerIDs = [];
  16329. }
  16330. var result = {};
  16331. try {
  16332. var styleIndexLayer = new StyleLayerIndex(layers);
  16333. var vectorTile = loadVectorTile(pbfData);
  16334. result = parse(vectorTile, styleIndexLayer, imageMap, featureIndex, zoom, parameters.indexData);
  16335. result = WebWorkerTransfer.serialize(result, transferableObjects);
  16336. }
  16337. catch (err) {
  16338. }
  16339. result.pickId = parameters.pickId;
  16340. return result;
  16341. }
  16342. function loadVectorTile(rawData) {
  16343. if (!when.defined(rawData)) {
  16344. return;
  16345. }
  16346. return new VectorTile(new pbf.Protobuf(rawData));
  16347. }
  16348. function parse(vectorTile, layerIndex, imageMap, featureIndex, zoom, indexData) {
  16349. var sourceLayerCoder = new DictionaryCoder(Object.keys(vectorTile.layers).sort());
  16350. var buckets = {};
  16351. var options = {
  16352. featureIndex: featureIndex,
  16353. iconDependencies: {},
  16354. patternDependencies: {},
  16355. glyphDependencies: {},
  16356. //availableImages: availableImages
  16357. };
  16358. for (var source in layerIndex.familiesBySource) {
  16359. //if (source == "") continue;
  16360. var layerFamilies = layerIndex.familiesBySource[source];
  16361. for (var sourceLayerId in layerFamilies) {
  16362. var sourceLayer = vectorTile.layers[sourceLayerId];
  16363. if (!sourceLayer) {
  16364. continue;
  16365. }
  16366. var sourceLayerIndex = sourceLayerCoder.encode(sourceLayerId);
  16367. var features = [];
  16368. for (var index = 0; index < sourceLayer.length; index++) {
  16369. var feature = sourceLayer.feature(index);
  16370. features.push({feature: feature, index: index, sourceLayerIndex: sourceLayerIndex});
  16371. }
  16372. for (var i = 0, list = layerFamilies[sourceLayerId]; i < list.length; i += 1) {
  16373. var family = list[i];
  16374. var layer = family[0];
  16375. // if(defined(layer.minzoom) && zoom < Math.floor(layer.minzoom)){
  16376. // continue;
  16377. // }
  16378. // if(defined(layer.maxzoom) && zoom >= layer.maxzoom){
  16379. // continue;
  16380. // }
  16381. if (layer.visibility === 'none') {
  16382. continue;
  16383. }
  16384. //recalculateLayers(family, this.zoom, availableImages);
  16385. recalculateLayers(family, 0, null);
  16386. var bucketName = layer.id;
  16387. var bucket = buckets[bucketName] = layer.createBucket({
  16388. index: featureIndex.bucketLayerIDs.length,
  16389. layers: family,
  16390. // zoom: this.zoom,
  16391. // pixelRatio: this.pixelRatio,
  16392. // overscaling : this.overscaling,
  16393. // collisionBoxArray: this.collisionBoxArray,
  16394. sourceLayerIndex: sourceLayerIndex,
  16395. //sourceID: this.source
  16396. });
  16397. if (when.defined(indexData) && when.defined(indexData[layer.id])) {
  16398. options.indexData = indexData[layer.id];
  16399. }
  16400. bucket.populate(features, options);
  16401. featureIndex.bucketLayerIDs.push(family.map(function (l) { return l.id; }));
  16402. }
  16403. }
  16404. }
  16405. var imageAtlas = null;
  16406. for (var key in buckets) {
  16407. var bucket = buckets[key];
  16408. if (bucket.hasPattern &&
  16409. (bucket instanceof LineBucket || bucket instanceof FillBucket)) {
  16410. //recalculateLayers(bucket.layers, this.zoom, availableImages);
  16411. if(imageAtlas == null){
  16412. imageAtlas = new ImageAtlas({}, imageMap);
  16413. }
  16414. bucket.addFeatures(options, imageAtlas.patternPositions);
  16415. }
  16416. }
  16417. return {
  16418. buckets : buckets,
  16419. imageAtlas : imageAtlas,
  16420. featureIndex : featureIndex
  16421. };
  16422. }
  16423. function recalculateLayers(layers, zoom, availableImages) {
  16424. // Layers are shared and may have been used by a WorkerTile with a different zoom.
  16425. var parameters = new EvaluationParameters$1(zoom);
  16426. for (var i = 0, list = layers; i < list.length; i += 1) {
  16427. var layer = list[i];
  16428. layer.recalculate(parameters, availableImages);
  16429. }
  16430. }
  16431. var MVTWorkTile$1 = createTaskProcessorWorker(MVTWorkTile);
  16432. return MVTWorkTile$1;
  16433. });