MVTWorkTile.js 690 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811188121881318814188151881618817188181881918820188211882218823188241882518826188271882818829188301883118832188331883418835188361883718838188391884018841188421884318844188451884618847188481884918850188511885218853188541885518856188571885818859188601886118862188631886418865188661886718868188691887018871188721887318874188751887618877188781887918880188811888218883188841888518886188871888818889188901889118892188931889418895188961889718898188991890018901189021890318904189051890618907189081890918910189111891218913189141891518916189171891818919189201892118922189231892418925189261892718928189291893018931189321893318934189351893618937189381893918940189411894218943189441894518946189471894818949189501895118952189531895418955189561895718958189591896018961189621896318964189651896618967189681896918970189711897218973189741897518976189771897818979189801898118982189831898418985189861898718988189891899018991189921899318994
  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) {
  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. var typeSize = sizeOf(member.type);
  62. var memberOffset = offset = align(offset, Math.max(alignment, typeSize));
  63. var components = member.components || 1;
  64. maxSize = Math.max(maxSize, typeSize);
  65. offset += typeSize * components;
  66. return {
  67. name: member.name,
  68. type: member.type,
  69. components: components,
  70. offset: memberOffset,
  71. };
  72. });
  73. var size = align(offset, Math.max(maxSize, alignment));
  74. return {
  75. members: layoutMembers,
  76. size: size,
  77. alignment: alignment
  78. };
  79. }
  80. function sizeOf(type) {
  81. return viewTypes[type].BYTES_PER_ELEMENT;
  82. }
  83. function align(offset, size) {
  84. return Math.ceil(offset / size) * size;
  85. }
  86. var IMAGE_PADDING = 1;
  87. var ImagePosition = function ImagePosition(paddedRect, ref) {
  88. var pixelRatio = ref.pixelRatio;
  89. var version = ref.version;
  90. var stretchX = ref.stretchX;
  91. var stretchY = ref.stretchY;
  92. var content = ref.content;
  93. this.paddedRect = paddedRect;
  94. this.pixelRatio = pixelRatio;
  95. this.stretchX = stretchX;
  96. this.stretchY = stretchY;
  97. this.content = content;
  98. this.version = version;
  99. };
  100. var prototypeAccessors = { tl: { configurable: true }, br: { configurable: true }, tlbr: { configurable: true }, displaySize: { configurable: true } };
  101. prototypeAccessors.tl.get = function () {
  102. return [
  103. this.paddedRect.x + IMAGE_PADDING,
  104. this.paddedRect.y + IMAGE_PADDING
  105. ];
  106. };
  107. prototypeAccessors.br.get = function () {
  108. return [
  109. this.paddedRect.x + this.paddedRect.w - IMAGE_PADDING,
  110. this.paddedRect.y + this.paddedRect.h - IMAGE_PADDING
  111. ];
  112. };
  113. prototypeAccessors.tlbr.get = function () {
  114. return this.tl.concat(this.br);
  115. };
  116. prototypeAccessors.displaySize.get = function () {
  117. return [
  118. (this.paddedRect.w - IMAGE_PADDING * 2) / this.pixelRatio,
  119. (this.paddedRect.h - IMAGE_PADDING * 2) / this.pixelRatio
  120. ];
  121. };
  122. Object.defineProperties(ImagePosition.prototype, prototypeAccessors);
  123. // Not premultiplied, because ImageData is not premultiplied.
  124. // UNPACK_PREMULTIPLY_ALPHA_WEBGL must be used when uploading to a texture.
  125. var RGBAImage = function RGBAImage(size, data) {
  126. createImage(this, size, 4, data);
  127. };
  128. RGBAImage.prototype.resize = function resize(size) {
  129. resizeImage(this, size, 4);
  130. };
  131. RGBAImage.prototype.replace = function replace(data, copy) {
  132. if (copy) {
  133. this.data.set(data);
  134. } else if (data instanceof Uint8ClampedArray) {
  135. this.data = new Uint8Array(data.buffer);
  136. } else {
  137. this.data = data;
  138. }
  139. };
  140. RGBAImage.prototype.clone = function clone() {
  141. return new RGBAImage({width: this.width, height: this.height}, new Uint8Array(this.data));
  142. };
  143. RGBAImage.copy = function copy(srcImg, dstImg, srcPt, dstPt, size) {
  144. copyImage(srcImg, dstImg, srcPt, dstPt, size, 4);
  145. };
  146. function createImage(image, ref, channels, data) {
  147. var width = ref.width;
  148. var height = ref.height;
  149. if (!data) {
  150. data = new Uint8Array(width * height * channels);
  151. } else if (data instanceof Uint8ClampedArray) {
  152. data = new Uint8Array(data.buffer);
  153. } else if (data.length !== width * height * channels) {
  154. throw new RangeError('mismatched image size');
  155. }
  156. image.width = width;
  157. image.height = height;
  158. image.data = data;
  159. return image;
  160. }
  161. function resizeImage(image, ref, channels) {
  162. var width = ref.width;
  163. var height = ref.height;
  164. if (width === image.width && height === image.height) {
  165. return;
  166. }
  167. var newImage = createImage({}, {width: width, height: height}, channels);
  168. copyImage(image, newImage, {x: 0, y: 0}, {x: 0, y: 0}, {
  169. width: Math.min(image.width, width),
  170. height: Math.min(image.height, height)
  171. }, channels);
  172. image.width = width;
  173. image.height = height;
  174. image.data = newImage.data;
  175. }
  176. function copyImage(srcImg, dstImg, srcPt, dstPt, size, channels) {
  177. if (size.width === 0 || size.height === 0) {
  178. return dstImg;
  179. }
  180. if (size.width > srcImg.width ||
  181. size.height > srcImg.height ||
  182. srcPt.x > srcImg.width - size.width ||
  183. srcPt.y > srcImg.height - size.height) {
  184. throw new RangeError('out of range source coordinates for image copy');
  185. }
  186. if (size.width > dstImg.width ||
  187. size.height > dstImg.height ||
  188. dstPt.x > dstImg.width - size.width ||
  189. dstPt.y > dstImg.height - size.height) {
  190. throw new RangeError('out of range destination coordinates for image copy');
  191. }
  192. var srcData = srcImg.data;
  193. var dstData = dstImg.data;
  194. for (var y = 0; y < size.height; y++) {
  195. var srcOffset = ((srcPt.y + y) * srcImg.width + srcPt.x) * channels;
  196. var dstOffset = ((dstPt.y + y) * dstImg.width + dstPt.x) * channels;
  197. for (var i = 0; i < size.width * channels; i++) {
  198. dstData[dstOffset + i] = srcData[srcOffset + i];
  199. }
  200. }
  201. return dstImg;
  202. }
  203. function potpack(boxes) {
  204. // calculate total box area and maximum box width
  205. var area = 0;
  206. var maxWidth = 0;
  207. for (var i$1 = 0, list = boxes; i$1 < list.length; i$1 += 1) {
  208. var box = list[i$1];
  209. area += box.w * box.h;
  210. maxWidth = Math.max(maxWidth, box.w);
  211. }
  212. // sort the boxes for insertion by height, descending
  213. boxes.sort(function (a, b) { return b.h - a.h; });
  214. // aim for a squarish resulting container,
  215. // slightly adjusted for sub-100% space utilization
  216. var startWidth = Math.max(Math.ceil(Math.sqrt(area / 0.95)), maxWidth);
  217. // start with a single empty space, unbounded at the bottom
  218. var spaces = [{x: 0, y: 0, w: startWidth, h: Infinity}];
  219. var width = 0;
  220. var height = 0;
  221. for (var i$2 = 0, list$1 = boxes; i$2 < list$1.length; i$2 += 1) {
  222. // look through spaces backwards so that we check smaller spaces first
  223. var box$1 = list$1[i$2];
  224. for (var i = spaces.length - 1; i >= 0; i--) {
  225. var space = spaces[i];
  226. // look for empty spaces that can accommodate the current box
  227. if (box$1.w > space.w || box$1.h > space.h) { continue; }
  228. // found the space; add the box to its top-left corner
  229. // |-------|-------|
  230. // | box | |
  231. // |_______| |
  232. // | space |
  233. // |_______________|
  234. box$1.x = space.x;
  235. box$1.y = space.y;
  236. height = Math.max(height, box$1.y + box$1.h);
  237. width = Math.max(width, box$1.x + box$1.w);
  238. if (box$1.w === space.w && box$1.h === space.h) {
  239. // space matches the box exactly; remove it
  240. var last = spaces.pop();
  241. if (i < spaces.length) { spaces[i] = last; }
  242. } else if (box$1.h === space.h) {
  243. // space matches the box height; update it accordingly
  244. // |-------|---------------|
  245. // | box | updated space |
  246. // |_______|_______________|
  247. space.x += box$1.w;
  248. space.w -= box$1.w;
  249. } else if (box$1.w === space.w) {
  250. // space matches the box width; update it accordingly
  251. // |---------------|
  252. // | box |
  253. // |_______________|
  254. // | updated space |
  255. // |_______________|
  256. space.y += box$1.h;
  257. space.h -= box$1.h;
  258. } else {
  259. // otherwise the box splits the space into two spaces
  260. // |-------|-----------|
  261. // | box | new space |
  262. // |_______|___________|
  263. // | updated space |
  264. // |___________________|
  265. spaces.push({
  266. x: space.x + box$1.w,
  267. y: space.y,
  268. w: space.w - box$1.w,
  269. h: box$1.h
  270. });
  271. space.y += box$1.h;
  272. space.h -= box$1.h;
  273. }
  274. break;
  275. }
  276. }
  277. return {
  278. w: width, // container width
  279. h: height, // container height
  280. fill: (area / (width * height)) || 0 // space utilization
  281. };
  282. }
  283. var IMAGE_PADDING$1 = 1;
  284. var ImageAtlas = function ImageAtlas(icons, patterns) {
  285. var iconPositions = {}, patternPositions = {};
  286. this.haveRenderCallbacks = [];
  287. var bins = [];
  288. this.addImages(icons, iconPositions, bins);
  289. this.addImages(patterns, patternPositions, bins);
  290. var ref = potpack(bins);
  291. var w = ref.w;
  292. var h = ref.h;
  293. var image = new RGBAImage({width: w || 1, height: h || 1});
  294. for (var id in icons) {
  295. var src = icons[id];
  296. var bin = iconPositions[id].paddedRect;
  297. RGBAImage.copy(src.data, image, {x: 0, y: 0}, {x: bin.x + IMAGE_PADDING$1, y: bin.y + IMAGE_PADDING$1}, src.data);
  298. }
  299. for (var id$1 in patterns) {
  300. var src$1 = patterns[id$1];
  301. var bin$1 = patternPositions[id$1].paddedRect;
  302. var x = bin$1.x + IMAGE_PADDING$1,
  303. y = bin$1.y + IMAGE_PADDING$1,
  304. w$1 = src$1.data.width,
  305. h$1 = src$1.data.height;
  306. RGBAImage.copy(src$1.data, image, {x: 0, y: 0}, {x: x, y: y}, src$1.data);
  307. // Add 1 pixel wrapped padding on each side of the image.
  308. RGBAImage.copy(src$1.data, image, {x: 0, y: h$1 - 1}, {x: x, y: y - 1}, {width: w$1, height: 1}); // T
  309. RGBAImage.copy(src$1.data, image, {x: 0, y: 0}, {x: x, y: y + h$1}, {width: w$1, height: 1}); // B
  310. RGBAImage.copy(src$1.data, image, {x: w$1 - 1, y: 0}, {x: x - 1, y: y}, {width: 1, height: h$1}); // L
  311. RGBAImage.copy(src$1.data, image, {x: 0, y: 0}, {x: x + w$1, y: y}, {width: 1, height: h$1}); // R
  312. }
  313. this.image = image;
  314. this.iconPositions = iconPositions;
  315. this.patternPositions = patternPositions;
  316. };
  317. ImageAtlas.prototype.addImages = function addImages(images, positions, bins) {
  318. for (var id in images) {
  319. var src = images[id];
  320. var bin = {
  321. x: 0,
  322. y: 0,
  323. w: src.data.width + 2 * IMAGE_PADDING$1,
  324. h: src.data.height + 2 * IMAGE_PADDING$1,
  325. };
  326. bins.push(bin);
  327. positions[id] = new ImagePosition(bin, src);
  328. if (src.hasRenderCallback) {
  329. this.haveRenderCallbacks.push(id);
  330. }
  331. }
  332. };
  333. ImageAtlas.prototype.patchUpdatedImages = function patchUpdatedImages(imageManager, texture) {
  334. imageManager.dispatchRenderCallbacks(this.haveRenderCallbacks);
  335. for (var name in imageManager.updatedImages) {
  336. this.patchUpdatedImage(this.iconPositions[name], imageManager.getImage(name), texture);
  337. this.patchUpdatedImage(this.patternPositions[name], imageManager.getImage(name), texture);
  338. }
  339. };
  340. ImageAtlas.prototype.patchUpdatedImage = function patchUpdatedImage(position, image, texture) {
  341. if (!position || !image) {
  342. return;
  343. }
  344. if (position.version === image.version) {
  345. return;
  346. }
  347. position.version = image.version;
  348. var ref = position.tl;
  349. var x = ref[0];
  350. var y = ref[1];
  351. texture.update(image.data, undefined, {x: x, y: y});
  352. };
  353. // http://www.w3.org/TR/css3-color/
  354. var kCSSColorTable = {
  355. "transparent": [0,0,0,0], "aliceblue": [240,248,255,1],
  356. "antiquewhite": [250,235,215,1], "aqua": [0,255,255,1],
  357. "aquamarine": [127,255,212,1], "azure": [240,255,255,1],
  358. "beige": [245,245,220,1], "bisque": [255,228,196,1],
  359. "black": [0,0,0,1], "blanchedalmond": [255,235,205,1],
  360. "blue": [0,0,255,1], "blueviolet": [138,43,226,1],
  361. "brown": [165,42,42,1], "burlywood": [222,184,135,1],
  362. "cadetblue": [95,158,160,1], "chartreuse": [127,255,0,1],
  363. "chocolate": [210,105,30,1], "coral": [255,127,80,1],
  364. "cornflowerblue": [100,149,237,1], "cornsilk": [255,248,220,1],
  365. "crimson": [220,20,60,1], "cyan": [0,255,255,1],
  366. "darkblue": [0,0,139,1], "darkcyan": [0,139,139,1],
  367. "darkgoldenrod": [184,134,11,1], "darkgray": [169,169,169,1],
  368. "darkgreen": [0,100,0,1], "darkgrey": [169,169,169,1],
  369. "darkkhaki": [189,183,107,1], "darkmagenta": [139,0,139,1],
  370. "darkolivegreen": [85,107,47,1], "darkorange": [255,140,0,1],
  371. "darkorchid": [153,50,204,1], "darkred": [139,0,0,1],
  372. "darksalmon": [233,150,122,1], "darkseagreen": [143,188,143,1],
  373. "darkslateblue": [72,61,139,1], "darkslategray": [47,79,79,1],
  374. "darkslategrey": [47,79,79,1], "darkturquoise": [0,206,209,1],
  375. "darkviolet": [148,0,211,1], "deeppink": [255,20,147,1],
  376. "deepskyblue": [0,191,255,1], "dimgray": [105,105,105,1],
  377. "dimgrey": [105,105,105,1], "dodgerblue": [30,144,255,1],
  378. "firebrick": [178,34,34,1], "floralwhite": [255,250,240,1],
  379. "forestgreen": [34,139,34,1], "fuchsia": [255,0,255,1],
  380. "gainsboro": [220,220,220,1], "ghostwhite": [248,248,255,1],
  381. "gold": [255,215,0,1], "goldenrod": [218,165,32,1],
  382. "gray": [128,128,128,1], "green": [0,128,0,1],
  383. "greenyellow": [173,255,47,1], "grey": [128,128,128,1],
  384. "honeydew": [240,255,240,1], "hotpink": [255,105,180,1],
  385. "indianred": [205,92,92,1], "indigo": [75,0,130,1],
  386. "ivory": [255,255,240,1], "khaki": [240,230,140,1],
  387. "lavender": [230,230,250,1], "lavenderblush": [255,240,245,1],
  388. "lawngreen": [124,252,0,1], "lemonchiffon": [255,250,205,1],
  389. "lightblue": [173,216,230,1], "lightcoral": [240,128,128,1],
  390. "lightcyan": [224,255,255,1], "lightgoldenrodyellow": [250,250,210,1],
  391. "lightgray": [211,211,211,1], "lightgreen": [144,238,144,1],
  392. "lightgrey": [211,211,211,1], "lightpink": [255,182,193,1],
  393. "lightsalmon": [255,160,122,1], "lightseagreen": [32,178,170,1],
  394. "lightskyblue": [135,206,250,1], "lightslategray": [119,136,153,1],
  395. "lightslategrey": [119,136,153,1], "lightsteelblue": [176,196,222,1],
  396. "lightyellow": [255,255,224,1], "lime": [0,255,0,1],
  397. "limegreen": [50,205,50,1], "linen": [250,240,230,1],
  398. "magenta": [255,0,255,1], "maroon": [128,0,0,1],
  399. "mediumaquamarine": [102,205,170,1], "mediumblue": [0,0,205,1],
  400. "mediumorchid": [186,85,211,1], "mediumpurple": [147,112,219,1],
  401. "mediumseagreen": [60,179,113,1], "mediumslateblue": [123,104,238,1],
  402. "mediumspringgreen": [0,250,154,1], "mediumturquoise": [72,209,204,1],
  403. "mediumvioletred": [199,21,133,1], "midnightblue": [25,25,112,1],
  404. "mintcream": [245,255,250,1], "mistyrose": [255,228,225,1],
  405. "moccasin": [255,228,181,1], "navajowhite": [255,222,173,1],
  406. "navy": [0,0,128,1], "oldlace": [253,245,230,1],
  407. "olive": [128,128,0,1], "olivedrab": [107,142,35,1],
  408. "orange": [255,165,0,1], "orangered": [255,69,0,1],
  409. "orchid": [218,112,214,1], "palegoldenrod": [238,232,170,1],
  410. "palegreen": [152,251,152,1], "paleturquoise": [175,238,238,1],
  411. "palevioletred": [219,112,147,1], "papayawhip": [255,239,213,1],
  412. "peachpuff": [255,218,185,1], "peru": [205,133,63,1],
  413. "pink": [255,192,203,1], "plum": [221,160,221,1],
  414. "powderblue": [176,224,230,1], "purple": [128,0,128,1],
  415. "rebeccapurple": [102,51,153,1],
  416. "red": [255,0,0,1], "rosybrown": [188,143,143,1],
  417. "royalblue": [65,105,225,1], "saddlebrown": [139,69,19,1],
  418. "salmon": [250,128,114,1], "sandybrown": [244,164,96,1],
  419. "seagreen": [46,139,87,1], "seashell": [255,245,238,1],
  420. "sienna": [160,82,45,1], "silver": [192,192,192,1],
  421. "skyblue": [135,206,235,1], "slateblue": [106,90,205,1],
  422. "slategray": [112,128,144,1], "slategrey": [112,128,144,1],
  423. "snow": [255,250,250,1], "springgreen": [0,255,127,1],
  424. "steelblue": [70,130,180,1], "tan": [210,180,140,1],
  425. "teal": [0,128,128,1], "thistle": [216,191,216,1],
  426. "tomato": [255,99,71,1], "turquoise": [64,224,208,1],
  427. "violet": [238,130,238,1], "wheat": [245,222,179,1],
  428. "white": [255,255,255,1], "whitesmoke": [245,245,245,1],
  429. "yellow": [255,255,0,1], "yellowgreen": [154,205,50,1]};
  430. function clamp_css_byte(i) { // Clamp to integer 0 .. 255.
  431. i = Math.round(i); // Seems to be what Chrome does (vs truncation).
  432. return i < 0 ? 0 : i > 255 ? 255 : i;
  433. }
  434. function clamp_css_float(f) { // Clamp to float 0.0 .. 1.0.
  435. return f < 0 ? 0 : f > 1 ? 1 : f;
  436. }
  437. function parse_css_int(str) { // int or percentage.
  438. if (str[str.length - 1] === '%')
  439. return clamp_css_byte(parseFloat(str) / 100 * 255);
  440. return clamp_css_byte(parseInt(str));
  441. }
  442. function parse_css_float(str) { // float or percentage.
  443. if (str[str.length - 1] === '%')
  444. return clamp_css_float(parseFloat(str) / 100);
  445. return clamp_css_float(parseFloat(str));
  446. }
  447. function css_hue_to_rgb(m1, m2, h) {
  448. if (h < 0) h += 1;
  449. else if (h > 1) h -= 1;
  450. if (h * 6 < 1) return m1 + (m2 - m1) * h * 6;
  451. if (h * 2 < 1) return m2;
  452. if (h * 3 < 2) return m1 + (m2 - m1) * (2/3 - h) * 6;
  453. return m1;
  454. }
  455. function parseCSSColor(css_str) {
  456. // Remove all whitespace, not compliant, but should just be more accepting.
  457. var str = css_str.replace(/ /g, '').toLowerCase();
  458. // Color keywords (and transparent) lookup.
  459. if (str in kCSSColorTable) return kCSSColorTable[str].slice(); // dup.
  460. // #abc and #abc123 syntax.
  461. if (str[0] === '#') {
  462. if (str.length === 4) {
  463. var iv = parseInt(str.substr(1), 16); // TODO(deanm): Stricter parsing.
  464. if (!(iv >= 0 && iv <= 0xfff)) return null; // Covers NaN.
  465. return [((iv & 0xf00) >> 4) | ((iv & 0xf00) >> 8),
  466. (iv & 0xf0) | ((iv & 0xf0) >> 4),
  467. (iv & 0xf) | ((iv & 0xf) << 4),
  468. 1];
  469. } else if (str.length === 7) {
  470. var iv = parseInt(str.substr(1), 16); // TODO(deanm): Stricter parsing.
  471. if (!(iv >= 0 && iv <= 0xffffff)) return null; // Covers NaN.
  472. return [(iv & 0xff0000) >> 16,
  473. (iv & 0xff00) >> 8,
  474. iv & 0xff,
  475. 1];
  476. }
  477. return null;
  478. }
  479. var op = str.indexOf('('), ep = str.indexOf(')');
  480. if (op !== -1 && ep + 1 === str.length) {
  481. var fname = str.substr(0, op);
  482. var params = str.substr(op+1, ep-(op+1)).split(',');
  483. var alpha = 1; // To allow case fallthrough.
  484. switch (fname) {
  485. case 'rgba':
  486. if (params.length !== 4) return null;
  487. alpha = parse_css_float(params.pop());
  488. // Fall through.
  489. case 'rgb':
  490. if (params.length !== 3) return null;
  491. return [parse_css_int(params[0]),
  492. parse_css_int(params[1]),
  493. parse_css_int(params[2]),
  494. alpha];
  495. case 'hsla':
  496. if (params.length !== 4) return null;
  497. alpha = parse_css_float(params.pop());
  498. // Fall through.
  499. case 'hsl':
  500. if (params.length !== 3) return null;
  501. var h = (((parseFloat(params[0]) % 360) + 360) % 360) / 360; // 0 .. 1
  502. // NOTE(deanm): According to the CSS spec s/l should only be
  503. // percentages, but we don't bother and let float or percentage.
  504. var s = parse_css_float(params[1]);
  505. var l = parse_css_float(params[2]);
  506. var m2 = l <= 0.5 ? l * (s + 1) : l + s - l * s;
  507. var m1 = l * 2 - m2;
  508. return [clamp_css_byte(css_hue_to_rgb(m1, m2, h+1/3) * 255),
  509. clamp_css_byte(css_hue_to_rgb(m1, m2, h) * 255),
  510. clamp_css_byte(css_hue_to_rgb(m1, m2, h-1/3) * 255),
  511. alpha];
  512. default:
  513. return null;
  514. }
  515. }
  516. return null;
  517. }
  518. /**
  519. * An RGBA color value. Create instances from color strings using the static
  520. * method `Color.parse`. The constructor accepts RGB channel values in the range
  521. * `[0, 1]`, premultiplied by A.
  522. *
  523. * @param {number} r The red channel.
  524. * @param {number} g The green channel.
  525. * @param {number} b The blue channel.
  526. * @param {number} a The alpha channel.
  527. * @private
  528. */
  529. var Color$1 = function Color(r, g, b, a) {
  530. if (a === void 0) a = 1;
  531. this.r = r;
  532. this.g = g;
  533. this.b = b;
  534. this.a = a;
  535. };
  536. /**
  537. * Parses valid CSS color strings and returns a `Color` instance.
  538. * @returns A `Color` instance, or `undefined` if the input is not a valid color string.
  539. */
  540. Color$1.parse = function parse(input) {
  541. if (!input) {
  542. return undefined;
  543. }
  544. if (input instanceof Color$1) {
  545. return input;
  546. }
  547. if (typeof input !== 'string') {
  548. return undefined;
  549. }
  550. var rgba = parseCSSColor(input);
  551. if (!rgba) {
  552. return undefined;
  553. }
  554. return new Color$1(
  555. rgba[0] / 255 * rgba[3],
  556. rgba[1] / 255 * rgba[3],
  557. rgba[2] / 255 * rgba[3],
  558. rgba[3]
  559. );
  560. };
  561. /**
  562. * Returns an RGBA string representing the color value.
  563. *
  564. * @returns An RGBA string.
  565. * @example
  566. * var purple = new Color.parse('purple');
  567. * purple.toString; // = "rgba(128,0,128,1)"
  568. * var translucentGreen = new Color.parse('rgba(26, 207, 26, .73)');
  569. * translucentGreen.toString(); // = "rgba(26,207,26,0.73)"
  570. */
  571. Color$1.prototype.toString = function toString() {
  572. var ref = this.toArray();
  573. var r = ref[0];
  574. var g = ref[1];
  575. var b = ref[2];
  576. var a = ref[3];
  577. return ("rgba(" + (Math.round(r)) + "," + (Math.round(g)) + "," + (Math.round(b)) + "," + a + ")");
  578. };
  579. Color$1.prototype.toArray = function toArray() {
  580. var ref = this;
  581. var r = ref.r;
  582. var g = ref.g;
  583. var b = ref.b;
  584. var a = ref.a;
  585. return a === 0 ? [0, 0, 0, 0] : [
  586. r * 255 / a,
  587. g * 255 / a,
  588. b * 255 / a,
  589. a
  590. ];
  591. };
  592. Color$1.black = new Color$1(0, 0, 0, 1);
  593. Color$1.white = new Color$1(1, 1, 1, 1);
  594. Color$1.transparent = new Color$1(0, 0, 0, 0);
  595. Color$1.red = new Color$1(1, 0, 0, 1);
  596. var NullType = {kind: 'null'};
  597. var NumberType = {kind: 'number'};
  598. var StringType = {kind: 'string'};
  599. var BooleanType = {kind: 'boolean'};
  600. var ColorType = {kind: 'color'};
  601. var ObjectType = {kind: 'object'};
  602. var ValueType = {kind: 'value'};
  603. var FormattedType = {kind: 'formatted'};
  604. var ResolvedImageType = {kind: 'resolvedImage'};
  605. function array(itemType, N) {
  606. return {
  607. kind: 'array',
  608. itemType: itemType,
  609. N: N
  610. };
  611. }
  612. function toString$1(type) {
  613. if (type.kind === 'array') {
  614. var itemType = toString$1(type.itemType);
  615. return typeof type.N === 'number' ?
  616. ("array<" + itemType + ", " + (type.N) + ">") :
  617. type.itemType.kind === 'value' ? 'array' : ("array<" + itemType + ">");
  618. } else {
  619. return type.kind;
  620. }
  621. }
  622. var valueMemberTypes = [
  623. NullType,
  624. NumberType,
  625. StringType,
  626. BooleanType,
  627. ColorType,
  628. FormattedType,
  629. ObjectType,
  630. array(ValueType),
  631. ResolvedImageType
  632. ];
  633. /**
  634. * Returns null if `t` is a subtype of `expected`; otherwise returns an
  635. * error message.
  636. * @private
  637. */
  638. function checkSubtype(expected, t) {
  639. if (t.kind === 'error') {
  640. // Error is a subtype of every type
  641. return null;
  642. } else if (expected.kind === 'array') {
  643. if (t.kind === 'array' &&
  644. ((t.N === 0 && t.itemType.kind === 'value') || !checkSubtype(expected.itemType, t.itemType)) &&
  645. (typeof expected.N !== 'number' || expected.N === t.N)) {
  646. return null;
  647. }
  648. } else if (expected.kind === t.kind) {
  649. return null;
  650. } else if (expected.kind === 'value') {
  651. for (var i = 0, list = valueMemberTypes; i < list.length; i += 1) {
  652. var memberType = list[i];
  653. if (!checkSubtype(memberType, t)) {
  654. return null;
  655. }
  656. }
  657. }
  658. return ("Expected " + (toString$1(expected)) + " but found " + (toString$1(t)) + " instead.");
  659. }
  660. var Collator = function Collator(caseSensitive , diacriticSensitive , locale ) {
  661. if (caseSensitive)
  662. { this.sensitivity = diacriticSensitive ? 'variant' : 'case'; }
  663. else
  664. { this.sensitivity = diacriticSensitive ? 'accent' : 'base'; }
  665. this.locale = locale;
  666. this.collator = new Intl.Collator(this.locale ? this.locale : [],
  667. {sensitivity: this.sensitivity, usage: 'search'});
  668. };
  669. Collator.prototype.compare = function compare (lhs , rhs ) {
  670. return this.collator.compare(lhs, rhs);
  671. };
  672. Collator.prototype.resolvedLocale = function resolvedLocale () {
  673. // We create a Collator without "usage: search" because we don't want
  674. // the search options encoded in our result (e.g. "en-u-co-search")
  675. return new Intl.Collator(this.locale ? this.locale : [])
  676. .resolvedOptions().locale;
  677. };
  678. var FormattedSection = function FormattedSection(text, image, scale, fontStack, textColor) {
  679. this.text = text;
  680. this.image = image;
  681. this.scale = scale;
  682. this.fontStack = fontStack;
  683. this.textColor = textColor;
  684. };
  685. var Formatted$1 = function Formatted(sections) {
  686. this.sections = sections;
  687. };
  688. Formatted$1.fromString = function fromString(unformatted) {
  689. return new Formatted$1([new FormattedSection(unformatted, null, null, null, null)]);
  690. };
  691. Formatted$1.prototype.isEmpty = function isEmpty() {
  692. if (this.sections.length === 0) {
  693. return true;
  694. }
  695. return !this.sections.some(function (section) {
  696. return section.text.length !== 0 ||
  697. (section.image && section.image.name.length !== 0);
  698. });
  699. };
  700. Formatted$1.factory = function factory(text) {
  701. if (text instanceof Formatted$1) {
  702. return text;
  703. } else {
  704. return Formatted$1.fromString(text);
  705. }
  706. };
  707. Formatted$1.prototype.toString = function toString() {
  708. if (this.sections.length === 0) {
  709. return '';
  710. }
  711. return this.sections.map(function (section) {
  712. return section.text;
  713. }).join('');
  714. };
  715. Formatted$1.prototype.serialize = function serialize() {
  716. var serialized = ["format"];
  717. for (var i = 0, list = this.sections; i < list.length; i += 1) {
  718. var section = list[i];
  719. if (section.image) {
  720. serialized.push(["image", section.image.name]);
  721. continue;
  722. }
  723. serialized.push(section.text);
  724. var options = {};
  725. if (section.fontStack) {
  726. options["text-font"] = ["literal", section.fontStack.split(',')];
  727. }
  728. if (section.scale) {
  729. options["font-scale"] = section.scale;
  730. }
  731. if (section.textColor) {
  732. options["text-color"] = (["rgba"] ).concat(section.textColor.toArray());
  733. }
  734. serialized.push(options);
  735. }
  736. return serialized;
  737. };
  738. var ResolvedImage$1 = function ResolvedImage(options) {
  739. this.name = options.name;
  740. this.available = options.available;
  741. };
  742. ResolvedImage$1.prototype.toString = function toString() {
  743. return this.name;
  744. };
  745. ResolvedImage$1.fromString = function fromString(name) {
  746. return new ResolvedImage$1({name: name, available: false});
  747. };
  748. ResolvedImage$1.prototype.serialize = function serialize() {
  749. return ["image", this.name];
  750. };
  751. var NullType$1 = {kind: 'null'};
  752. var NumberType$1 = {kind: 'number'};
  753. var StringType$1 = {kind: 'string'};
  754. var BooleanType$1 = {kind: 'boolean'};
  755. var ColorType$1 = {kind: 'color'};
  756. var ObjectType$1 = {kind: 'object'};
  757. var ValueType$1 = {kind: 'value'};
  758. var CollatorType = {kind: 'collator'};
  759. var FormattedType$1 = {kind: 'formatted'};
  760. var ResolvedImageType$1 = {kind: 'resolvedImage'};
  761. function array$1(itemType, N) {
  762. return {
  763. kind: 'array',
  764. itemType: itemType,
  765. N: N
  766. };
  767. }
  768. function Values$1() {
  769. }
  770. Values$1.validateRGBA = function(r, g, b, a){
  771. if (!(
  772. typeof r === 'number' && r >= 0 && r <= 255 &&
  773. typeof g === 'number' && g >= 0 && g <= 255 &&
  774. typeof b === 'number' && b >= 0 && b <= 255
  775. )) {
  776. var value = typeof a === 'number' ? [r, g, b, a] : [r, g, b];
  777. return ("Invalid rgba value [" + (value.join(', ')) + "]: 'r', 'g', and 'b' must be between 0 and 255.");
  778. }
  779. if (!(
  780. typeof a === 'undefined' || (typeof a === 'number' && a >= 0 && a <= 1)
  781. )) {
  782. return ("Invalid rgba value [" + ([r, g, b, a].join(', ')) + "]: 'a' must be between 0 and 1.");
  783. }
  784. return null;
  785. };
  786. Values$1.isValue = function(mixed){
  787. if (mixed === null) {
  788. return true;
  789. } else if (typeof mixed === 'string') {
  790. return true;
  791. } else if (typeof mixed === 'boolean') {
  792. return true;
  793. } else if (typeof mixed === 'number') {
  794. return true;
  795. } else if (mixed instanceof Color$1) {
  796. return true;
  797. } else if (mixed instanceof Collator) {
  798. return true;
  799. } else if (mixed instanceof Formatted$1) {
  800. return true;
  801. } else if (mixed instanceof ResolvedImage$1) {
  802. return true;
  803. } else if (Array.isArray(mixed)) {
  804. for (var i = 0, list = mixed; i < list.length; i += 1) {
  805. var item = list[i];
  806. if (!Values$1.isValue(item)) {
  807. return false;
  808. }
  809. }
  810. return true;
  811. } else if (typeof mixed === 'object') {
  812. for (var key in mixed) {
  813. if (!Values$1.isValue(mixed[key])) {
  814. return false;
  815. }
  816. }
  817. return true;
  818. } else {
  819. return false;
  820. }
  821. };
  822. Values$1.typeOf = function(value){
  823. if (value === null) {
  824. return NullType$1;
  825. } else if (typeof value === 'string') {
  826. return StringType$1;
  827. } else if (typeof value === 'boolean') {
  828. return BooleanType$1;
  829. } else if (typeof value === 'number') {
  830. return NumberType$1;
  831. } else if (value instanceof Color$1) {
  832. return ColorType$1;
  833. } else if (value instanceof Collator) {
  834. return CollatorType;
  835. } else if (value instanceof Formatted$1) {
  836. return FormattedType$1;
  837. } else if (value instanceof ResolvedImage$1) {
  838. return ResolvedImageType$1;
  839. } else if (Array.isArray(value)) {
  840. var length = value.length;
  841. var itemType;
  842. for (var i = 0, list = value; i < list.length; i += 1) {
  843. var item = list[i];
  844. var t = Values$1.typeOf(item);
  845. if (!itemType) {
  846. itemType = t;
  847. } else if (itemType === t) {
  848. continue;
  849. } else {
  850. itemType = ValueType$1;
  851. break;
  852. }
  853. }
  854. return array$1(itemType || ValueType$1, length);
  855. } else {
  856. return ObjectType$1;
  857. }
  858. };
  859. Values$1.toString$1 = function(value){
  860. var type = typeof value;
  861. if (value === null) {
  862. return '';
  863. } else if (type === 'string' || type === 'number' || type === 'boolean') {
  864. return String(value);
  865. } else if (value instanceof Color$1 || value instanceof Formatted$1 || value instanceof ResolvedImage$1) {
  866. return value.toString();
  867. } else {
  868. return JSON.stringify(value);
  869. }
  870. };
  871. var NumberType$2 = {kind: 'number'};
  872. var StringType$2 = {kind: 'string'};
  873. var BooleanType$2 = {kind: 'boolean'};
  874. var ObjectType$2 = {kind: 'object'};
  875. var ValueType$2 = {kind: 'value'};
  876. function array$2(itemType, N) {
  877. return {
  878. kind: 'array',
  879. itemType: itemType,
  880. N: N
  881. };
  882. }
  883. var types = {
  884. string: StringType$2,
  885. number: NumberType$2,
  886. boolean: BooleanType$2,
  887. object: ObjectType$2
  888. };
  889. var Assertion = function Assertion(type, args) {
  890. this.type = type;
  891. this.args = args;
  892. };
  893. Assertion.parse = function parse(args, context) {
  894. if (args.length < 2) {
  895. return context.error("Expected at least one argument.");
  896. }
  897. var i = 1;
  898. var type;
  899. var name = (args[0] );
  900. if (name === 'array') {
  901. var itemType;
  902. if (args.length > 2) {
  903. var type$1 = args[1];
  904. if (typeof type$1 !== 'string' || !(type$1 in types) || type$1 === 'object') {
  905. return context.error('The item type argument of "array" must be one of string, number, boolean', 1);
  906. }
  907. itemType = types[type$1];
  908. i++;
  909. } else {
  910. itemType = ValueType$2;
  911. }
  912. var N;
  913. if (args.length > 3) {
  914. if (args[2] !== null &&
  915. (typeof args[2] !== 'number' ||
  916. args[2] < 0 ||
  917. args[2] !== Math.floor(args[2]))
  918. ) {
  919. return context.error('The length argument to "array" must be a positive integer literal', 2);
  920. }
  921. N = args[2];
  922. i++;
  923. }
  924. type = array$2(itemType, N);
  925. } else {
  926. type = types[name];
  927. }
  928. var parsed = [];
  929. for (; i < args.length; i++) {
  930. var input = context.parse(args[i], i, ValueType$2);
  931. if (!input) {
  932. return null;
  933. }
  934. parsed.push(input);
  935. }
  936. return new Assertion(type, parsed);
  937. };
  938. Assertion.prototype.evaluate = function evaluate(ctx) {
  939. for (var i = 0; i < this.args.length; i++) {
  940. var value = this.args[i].evaluate(ctx);
  941. var error = checkSubtype(this.type, Values$1.typeOf(value));
  942. if (!error) {
  943. return value;
  944. } else if (i === this.args.length - 1) {
  945. throw new RuntimeError(("Expected value to be of type " + (toString(this.type)) + ", but found " + (toString(Values$1.typeOf(value))) + " instead."));
  946. }
  947. }
  948. return null;
  949. };
  950. Assertion.prototype.eachChild = function eachChild(fn) {
  951. this.args.forEach(fn);
  952. };
  953. Assertion.prototype.possibleOutputs = function possibleOutputs() {
  954. var ref;
  955. return (ref = []).concat.apply(ref, this.args.map(function (arg) {
  956. return arg.possibleOutputs();
  957. }));
  958. };
  959. Assertion.prototype.serialize = function serialize() {
  960. var type = this.type;
  961. var serialized = [type.kind];
  962. if (type.kind === 'array') {
  963. var itemType = type.itemType;
  964. if (itemType.kind === 'string' ||
  965. itemType.kind === 'number' ||
  966. itemType.kind === 'boolean') {
  967. serialized.push(itemType.kind);
  968. var N = type.N;
  969. if (typeof N === 'number' || this.args.length > 1) {
  970. serialized.push(N);
  971. }
  972. }
  973. }
  974. return serialized.concat(this.args.map(function (arg) {
  975. return arg.serialize();
  976. }));
  977. };
  978. var NumberType$3 = {kind: 'number'};
  979. var ValueType$3 = {kind: 'value'};
  980. function array$3(itemType, N) {
  981. return {
  982. kind: 'array',
  983. itemType: itemType,
  984. N: N
  985. };
  986. }
  987. var At = function At(type, index, input) {
  988. this.type = type;
  989. this.index = index;
  990. this.input = input;
  991. };
  992. At.parse = function parse(args, context) {
  993. if (args.length !== 3) {
  994. return context.error(("Expected 2 arguments, but found " + (args.length - 1) + " instead."));
  995. }
  996. var index = context.parse(args[1], 1, NumberType$3);
  997. var input = context.parse(args[2], 2, array$3(context.expectedType || ValueType$3));
  998. if (!index || !input) {
  999. return null;
  1000. }
  1001. var t = (input.type );
  1002. return new At(t.itemType, index, input);
  1003. };
  1004. At.prototype.evaluate = function evaluate(ctx) {
  1005. var index = ((this.index.evaluate(ctx) ) );
  1006. var array = ((this.input.evaluate(ctx) ) );
  1007. if (index < 0) {
  1008. throw new RuntimeError(("Array index out of bounds: " + index + " < 0."));
  1009. }
  1010. if (index >= array.length) {
  1011. throw new RuntimeError(("Array index out of bounds: " + index + " > " + (array.length - 1) + "."));
  1012. }
  1013. if (index !== Math.floor(index)) {
  1014. throw new RuntimeError(("Array index must be an integer, but found " + index + " instead."));
  1015. }
  1016. return array[index];
  1017. };
  1018. At.prototype.eachChild = function eachChild(fn) {
  1019. fn(this.index);
  1020. fn(this.input);
  1021. };
  1022. At.prototype.possibleOutputs = function possibleOutputs() {
  1023. return [undefined];
  1024. };
  1025. At.prototype.serialize = function serialize() {
  1026. return ["at", this.index.serialize(), this.input.serialize()];
  1027. };
  1028. var BooleanType$3 = {kind: 'boolean'};
  1029. var Case = function Case(type, branches, otherwise) {
  1030. this.type = type;
  1031. this.branches = branches;
  1032. this.otherwise = otherwise;
  1033. };
  1034. Case.parse = function parse(args, context) {
  1035. if (args.length < 4) {
  1036. return context.error(("Expected at least 3 arguments, but found only " + (args.length - 1) + "."));
  1037. }
  1038. if (args.length % 2 !== 0) {
  1039. return context.error("Expected an odd number of arguments.");
  1040. }
  1041. var outputType;
  1042. if (context.expectedType && context.expectedType.kind !== 'value') {
  1043. outputType = context.expectedType;
  1044. }
  1045. var branches = [];
  1046. for (var i = 1; i < args.length - 1; i += 2) {
  1047. var test = context.parse(args[i], i, BooleanType$3);
  1048. if (!test) {
  1049. return null;
  1050. }
  1051. var result = context.parse(args[i + 1], i + 1, outputType);
  1052. if (!result) {
  1053. return null;
  1054. }
  1055. branches.push([test, result]);
  1056. outputType = outputType || result.type;
  1057. }
  1058. var otherwise = context.parse(args[args.length - 1], args.length - 1, outputType);
  1059. if (!otherwise) {
  1060. return null;
  1061. }
  1062. return new Case((outputType ), branches, otherwise);
  1063. };
  1064. Case.prototype.evaluate = function evaluate(ctx) {
  1065. for (var i = 0, list = this.branches; i < list.length; i += 1) {
  1066. var ref = list[i];
  1067. var test = ref[0];
  1068. var expression = ref[1];
  1069. if (test.evaluate(ctx)) {
  1070. return expression.evaluate(ctx);
  1071. }
  1072. }
  1073. return this.otherwise.evaluate(ctx);
  1074. };
  1075. Case.prototype.eachChild = function eachChild(fn) {
  1076. for (var i = 0, list = this.branches; i < list.length; i += 1) {
  1077. var ref = list[i];
  1078. var test = ref[0];
  1079. var expression = ref[1];
  1080. fn(test);
  1081. fn(expression);
  1082. }
  1083. fn(this.otherwise);
  1084. };
  1085. Case.prototype.possibleOutputs = function possibleOutputs() {
  1086. var ref;
  1087. return (ref = [])
  1088. .concat.apply(ref, this.branches.map(function (ref) {
  1089. var _ = ref[0];
  1090. var out = ref[1];
  1091. return out.possibleOutputs();
  1092. }))
  1093. .concat(this.otherwise.possibleOutputs());
  1094. };
  1095. Case.prototype.serialize = function serialize() {
  1096. var serialized = ["case"];
  1097. this.eachChild(function (child) {
  1098. serialized.push(child.serialize());
  1099. });
  1100. return serialized;
  1101. };
  1102. var ValueType$4 = {kind: 'value'};
  1103. var Coalesce = function Coalesce(type, args) {
  1104. this.type = type;
  1105. this.args = args;
  1106. };
  1107. Coalesce.parse = function parse(args, context) {
  1108. if (args.length < 2) {
  1109. return context.error("Expectected at least one argument.");
  1110. }
  1111. var outputType = (null );
  1112. var expectedType = context.expectedType;
  1113. if (expectedType && expectedType.kind !== 'value') {
  1114. outputType = expectedType;
  1115. }
  1116. var parsedArgs = [];
  1117. for (var i = 0, list = args.slice(1); i < list.length; i += 1) {
  1118. var arg = list[i];
  1119. var parsed = context.parse(arg, 1 + parsedArgs.length, outputType, undefined, {typeAnnotation: 'omit'});
  1120. if (!parsed) {
  1121. return null;
  1122. }
  1123. outputType = outputType || parsed.type;
  1124. parsedArgs.push(parsed);
  1125. }
  1126. // Above, we parse arguments without inferred type annotation so that
  1127. // they don't produce a runtime error for `null` input, which would
  1128. // preempt the desired null-coalescing behavior.
  1129. // Thus, if any of our arguments would have needed an annotation, we
  1130. // need to wrap the enclosing coalesce expression with it instead.
  1131. var needsAnnotation = expectedType &&
  1132. parsedArgs.some(function (arg) {
  1133. return checkSubtype(expectedType, arg.type);
  1134. });
  1135. return needsAnnotation ?
  1136. new Coalesce(ValueType$4, parsedArgs) :
  1137. new Coalesce((outputType ), parsedArgs);
  1138. };
  1139. Coalesce.prototype.evaluate = function evaluate(ctx) {
  1140. var result = null;
  1141. var argCount = 0;
  1142. var requestedImageName;
  1143. for (var i = 0, list = this.args; i < list.length; i += 1) {
  1144. var arg = list[i];
  1145. argCount++;
  1146. result = arg.evaluate(ctx);
  1147. // we need to keep track of the first requested image in a coalesce statement
  1148. // if coalesce can't find a valid image, we return the first image name so styleimagemissing can fire
  1149. if (result && result instanceof ResolvedImage$1 && !result.available) {
  1150. if (!requestedImageName) {
  1151. requestedImageName = result.name;
  1152. }
  1153. result = null;
  1154. if (argCount === this.args.length) {
  1155. result = requestedImageName;
  1156. }
  1157. }
  1158. if (result !== null) {
  1159. break;
  1160. }
  1161. }
  1162. return result;
  1163. };
  1164. Coalesce.prototype.eachChild = function eachChild(fn) {
  1165. this.args.forEach(fn);
  1166. };
  1167. Coalesce.prototype.possibleOutputs = function possibleOutputs() {
  1168. var ref;
  1169. return (ref = []).concat.apply(ref, this.args.map(function (arg) {
  1170. return arg.possibleOutputs();
  1171. }));
  1172. };
  1173. Coalesce.prototype.serialize = function serialize() {
  1174. var serialized = ["coalesce"];
  1175. this.eachChild(function (child) {
  1176. serialized.push(child.serialize());
  1177. });
  1178. return serialized;
  1179. };
  1180. var NumberType$4 = {kind: 'number'};
  1181. var StringType$3 = {kind: 'string'};
  1182. var BooleanType$4 = {kind: 'boolean'};
  1183. var ColorType$2 = {kind: 'color'};
  1184. var ValueType$5 = {kind: 'value'};
  1185. var types$1 = {
  1186. 'to-boolean': BooleanType$4,
  1187. 'to-color': ColorType$2,
  1188. 'to-number': NumberType$4,
  1189. 'to-string': StringType$3
  1190. };
  1191. /**
  1192. * Special form for error-coalescing coercion expressions "to-number",
  1193. * "to-color". Since these coercions can fail at runtime, they accept multiple
  1194. * arguments, only evaluating one at a time until one succeeds.
  1195. *
  1196. * @private
  1197. */
  1198. var Coercion = function Coercion(type, args) {
  1199. this.type = type;
  1200. this.args = args;
  1201. };
  1202. Coercion.parse = function parse(args, context) {
  1203. if (args.length < 2) {
  1204. return context.error("Expected at least one argument.");
  1205. }
  1206. var name = (args[0] );
  1207. if ((name === 'to-boolean' || name === 'to-string') && args.length !== 2) {
  1208. return context.error("Expected one argument.");
  1209. }
  1210. var type = types$1[name];
  1211. var parsed = [];
  1212. for (var i = 1; i < args.length; i++) {
  1213. var input = context.parse(args[i], i, ValueType$5);
  1214. if (!input) {
  1215. return null;
  1216. }
  1217. parsed.push(input);
  1218. }
  1219. return new Coercion(type, parsed);
  1220. };
  1221. Coercion.prototype.evaluate = function evaluate(ctx) {
  1222. if (this.type.kind === 'boolean') {
  1223. return Boolean(this.args[0].evaluate(ctx));
  1224. } else if (this.type.kind === 'color') {
  1225. var input;
  1226. var error;
  1227. for (var i = 0, list = this.args; i < list.length; i += 1) {
  1228. var arg = list[i];
  1229. input = arg.evaluate(ctx);
  1230. error = null;
  1231. if (input instanceof Color) {
  1232. return input;
  1233. } else if (typeof input === 'string') {
  1234. var c = ctx.parseColor(input);
  1235. if (c) {
  1236. return c;
  1237. }
  1238. } else if (Array.isArray(input)) {
  1239. if (input.length < 3 || input.length > 4) {
  1240. error = "Invalid rbga value " + (JSON.stringify(input)) + ": expected an array containing either three or four numeric values.";
  1241. } else {
  1242. error = validateRGBA(input[0], input[1], input[2], input[3]);
  1243. }
  1244. if (!error) {
  1245. return new Color((input[0] ) / 255, (input[1] ) / 255, (input[2] ) / 255, (input[3] ));
  1246. }
  1247. }
  1248. }
  1249. throw new RuntimeError(error || ("Could not parse color from value '" + (typeof input === 'string' ? input : String(JSON.stringify(input))) + "'"));
  1250. } else if (this.type.kind === 'number') {
  1251. var value = null;
  1252. for (var i$1 = 0, list$1 = this.args; i$1 < list$1.length; i$1 += 1) {
  1253. var arg$1 = list$1[i$1];
  1254. value = arg$1.evaluate(ctx);
  1255. if (value === null) {
  1256. return 0;
  1257. }
  1258. var num = Number(value);
  1259. if (isNaN(num)) {
  1260. continue;
  1261. }
  1262. return num;
  1263. }
  1264. throw new RuntimeError(("Could not convert " + (JSON.stringify(value)) + " to number."));
  1265. } else if (this.type.kind === 'formatted') {
  1266. // There is no explicit 'to-formatted' but this coercion can be implicitly
  1267. // created by properties that expect the 'formatted' type.
  1268. return Formatted.fromString(Values$1.toString$1(this.args[0].evaluate(ctx)));
  1269. } else if (this.type.kind === 'resolvedImage') {
  1270. return ResolvedImage$1.fromString(Values$1.toString$1(this.args[0].evaluate(ctx)));
  1271. } else {
  1272. return Values$1.toString$1(this.args[0].evaluate(ctx));
  1273. }
  1274. };
  1275. Coercion.prototype.eachChild = function eachChild(fn) {
  1276. this.args.forEach(fn);
  1277. };
  1278. Coercion.prototype.possibleOutputs = function possibleOutputs() {
  1279. var ref;
  1280. return (ref = []).concat.apply(ref, this.args.map(function (arg) {
  1281. return arg.possibleOutputs();
  1282. }));
  1283. };
  1284. Coercion.prototype.serialize = function serialize() {
  1285. if (this.type.kind === 'formatted') {
  1286. return new FormatExpression([
  1287. {content: this.args[0], scale: null, font: null, textColor: null}
  1288. ]).serialize();
  1289. }
  1290. if (this.type.kind === 'resolvedImage') {
  1291. return new ImageExpression(this.args[0]).serialize();
  1292. }
  1293. var serialized = [("to-" + (this.type.kind))];
  1294. this.eachChild(function (child) {
  1295. serialized.push(child.serialize());
  1296. });
  1297. return serialized;
  1298. };
  1299. var StringType$4 = {kind: 'string'};
  1300. var BooleanType$5 = {kind: 'boolean'};
  1301. var CollatorType$1 = {kind: 'collator'};
  1302. var CollatorExpression = function CollatorExpression(caseSensitive, diacriticSensitive, locale) {
  1303. this.type = CollatorType$1;
  1304. this.locale = locale;
  1305. this.caseSensitive = caseSensitive;
  1306. this.diacriticSensitive = diacriticSensitive;
  1307. };
  1308. CollatorExpression.parse = function parse(args, context) {
  1309. if (args.length !== 2) {
  1310. return context.error("Expected one argument.");
  1311. }
  1312. var options = (args[1] );
  1313. if (typeof options !== "object" || Array.isArray(options)) {
  1314. return context.error("Collator options argument must be an object.");
  1315. }
  1316. var caseSensitive = context.parse(
  1317. options['case-sensitive'] === undefined ? false : options['case-sensitive'], 1, BooleanType$5);
  1318. if (!caseSensitive) {
  1319. return null;
  1320. }
  1321. var diacriticSensitive = context.parse(
  1322. options['diacritic-sensitive'] === undefined ? false : options['diacritic-sensitive'], 1, BooleanType$5);
  1323. if (!diacriticSensitive) {
  1324. return null;
  1325. }
  1326. var locale = null;
  1327. if (options['locale']) {
  1328. locale = context.parse(options['locale'], 1, StringType$4);
  1329. if (!locale) {
  1330. return null;
  1331. }
  1332. }
  1333. return new CollatorExpression(caseSensitive, diacriticSensitive, locale);
  1334. };
  1335. CollatorExpression.prototype.evaluate = function evaluate(ctx) {
  1336. return new Collator(this.caseSensitive.evaluate(ctx), this.diacriticSensitive.evaluate(ctx), this.locale ? this.locale.evaluate(ctx) : null);
  1337. };
  1338. CollatorExpression.prototype.eachChild = function eachChild(fn) {
  1339. fn(this.caseSensitive);
  1340. fn(this.diacriticSensitive);
  1341. if (this.locale) {
  1342. fn(this.locale);
  1343. }
  1344. };
  1345. CollatorExpression.prototype.possibleOutputs = function possibleOutputs() {
  1346. // Technically the set of possible outputs is the combinatoric set of Collators produced
  1347. // by all possibleOutputs of locale/caseSensitive/diacriticSensitive
  1348. // But for the primary use of Collators in comparison operators, we ignore the Collator's
  1349. // possibleOutputs anyway, so we can get away with leaving this undefined for now.
  1350. return [undefined];
  1351. };
  1352. CollatorExpression.prototype.serialize = function serialize() {
  1353. var options = {};
  1354. options['case-sensitive'] = this.caseSensitive.serialize();
  1355. options['diacritic-sensitive'] = this.diacriticSensitive.serialize();
  1356. if (this.locale) {
  1357. options['locale'] = this.locale.serialize();
  1358. }
  1359. return ["collator", options];
  1360. };
  1361. var BooleanType$6 = {kind: 'boolean'};
  1362. var ValueType$6 = {kind: 'value'};
  1363. var CollatorType$2 = {kind: 'collator'};
  1364. function isComparableType$1(op, type) {
  1365. if (op === '==' || op === '!=') {
  1366. // equality operator
  1367. return type.kind === 'boolean' ||
  1368. type.kind === 'string' ||
  1369. type.kind === 'number' ||
  1370. type.kind === 'null' ||
  1371. type.kind === 'value';
  1372. } else {
  1373. // ordering operator
  1374. return type.kind === 'string' ||
  1375. type.kind === 'number' ||
  1376. type.kind === 'value';
  1377. }
  1378. }
  1379. function eq(ctx, a, b) {
  1380. return a === b;
  1381. }
  1382. function neq(ctx, a, b) {
  1383. return a !== b;
  1384. }
  1385. function lt(ctx, a, b) {
  1386. return a < b;
  1387. }
  1388. function gt(ctx, a, b) {
  1389. return a > b;
  1390. }
  1391. function lteq(ctx, a, b) {
  1392. return a <= b;
  1393. }
  1394. function gteq(ctx, a, b) {
  1395. return a >= b;
  1396. }
  1397. function eqCollate(ctx, a, b, c) {
  1398. return c.compare(a, b) === 0;
  1399. }
  1400. function neqCollate(ctx, a, b, c) {
  1401. return !eqCollate(ctx, a, b, c);
  1402. }
  1403. function ltCollate(ctx, a, b, c) {
  1404. return c.compare(a, b) < 0;
  1405. }
  1406. function gtCollate(ctx, a, b, c) {
  1407. return c.compare(a, b) > 0;
  1408. }
  1409. function lteqCollate(ctx, a, b, c) {
  1410. return c.compare(a, b) <= 0;
  1411. }
  1412. function gteqCollate(ctx, a, b, c) {
  1413. return c.compare(a, b) >= 0;
  1414. }
  1415. /**
  1416. * Special form for comparison operators, implementing the signatures:
  1417. * - (T, T, ?Collator) => boolean
  1418. * - (T, value, ?Collator) => boolean
  1419. * - (value, T, ?Collator) => boolean
  1420. *
  1421. * For inequalities, T must be either value, string, or number. For ==/!=, it
  1422. * can also be boolean or null.
  1423. *
  1424. * Equality semantics are equivalent to Javascript's strict equality (===/!==)
  1425. * -- i.e., when the arguments' types don't match, == evaluates to false, != to
  1426. * true.
  1427. *
  1428. * When types don't match in an ordering comparison, a runtime error is thrown.
  1429. *
  1430. * @private
  1431. */
  1432. function makeComparison(op, compareBasic, compareWithCollator) {
  1433. var isOrderComparison = op !== '==' && op !== '!=';
  1434. return /*@__PURE__*/(function () {
  1435. function Comparison(lhs, rhs, collator) {
  1436. this.type = BooleanType$6;
  1437. this.lhs = lhs;
  1438. this.rhs = rhs;
  1439. this.collator = collator;
  1440. this.hasUntypedArgument = lhs.type.kind === 'value' || rhs.type.kind === 'value';
  1441. }
  1442. Comparison.parse = function parse(args, context) {
  1443. if (args.length !== 3 && args.length !== 4) {
  1444. return context.error("Expected two or three arguments.");
  1445. }
  1446. var op = (args[0] );
  1447. var lhs = context.parse(args[1], 1, ValueType$6);
  1448. if (!lhs) {
  1449. return null;
  1450. }
  1451. if (!isComparableType$1(op, lhs.type)) {
  1452. return context.concat(1).error(("\"" + op + "\" comparisons are not supported for type '" + (toString(lhs.type)) + "'."));
  1453. }
  1454. var rhs = context.parse(args[2], 2, ValueType$6);
  1455. if (!rhs) {
  1456. return null;
  1457. }
  1458. if (!isComparableType$1(op, rhs.type)) {
  1459. return context.concat(2).error(("\"" + op + "\" comparisons are not supported for type '" + (toString(rhs.type)) + "'."));
  1460. }
  1461. if (
  1462. lhs.type.kind !== rhs.type.kind &&
  1463. lhs.type.kind !== 'value' &&
  1464. rhs.type.kind !== 'value'
  1465. ) {
  1466. return context.error(("Cannot compare types '" + (toString(lhs.type)) + "' and '" + (toString(rhs.type)) + "'."));
  1467. }
  1468. if (isOrderComparison) {
  1469. // typing rules specific to less/greater than operators
  1470. if (lhs.type.kind === 'value' && rhs.type.kind !== 'value') {
  1471. // (value, T)
  1472. lhs = new Assertion(rhs.type, [lhs]);
  1473. } else if (lhs.type.kind !== 'value' && rhs.type.kind === 'value') {
  1474. // (T, value)
  1475. rhs = new Assertion(lhs.type, [rhs]);
  1476. }
  1477. }
  1478. var collator = null;
  1479. if (args.length === 4) {
  1480. if (
  1481. lhs.type.kind !== 'string' &&
  1482. rhs.type.kind !== 'string' &&
  1483. lhs.type.kind !== 'value' &&
  1484. rhs.type.kind !== 'value'
  1485. ) {
  1486. return context.error("Cannot use collator to compare non-string types.");
  1487. }
  1488. collator = context.parse(args[3], 3, CollatorType$2);
  1489. if (!collator) {
  1490. return null;
  1491. }
  1492. }
  1493. return new Comparison(lhs, rhs, collator);
  1494. };
  1495. Comparison.prototype.evaluate = function evaluate(ctx) {
  1496. var lhs = this.lhs.evaluate(ctx);
  1497. var rhs = this.rhs.evaluate(ctx);
  1498. if (isOrderComparison && this.hasUntypedArgument) {
  1499. var lt = Values$1.typeOf(lhs);
  1500. var rt = Values$1.typeOf(rhs);
  1501. // check that type is string or number, and equal
  1502. if (lt.kind !== rt.kind || !(lt.kind === 'string' || lt.kind === 'number')) {
  1503. throw new RuntimeError(("Expected arguments for \"" + op + "\" to be (string, string) or (number, number), but found (" + (lt.kind) + ", " + (rt.kind) + ") instead."));
  1504. }
  1505. }
  1506. if (this.collator && !isOrderComparison && this.hasUntypedArgument) {
  1507. var lt$1 = Values$1.typeOf(lhs);
  1508. var rt$1 = Values$1.typeOf(rhs);
  1509. if (lt$1.kind !== 'string' || rt$1.kind !== 'string') {
  1510. return compareBasic(ctx, lhs, rhs);
  1511. }
  1512. }
  1513. return this.collator ?
  1514. compareWithCollator(ctx, lhs, rhs, this.collator.evaluate(ctx)) :
  1515. compareBasic(ctx, lhs, rhs);
  1516. };
  1517. Comparison.prototype.eachChild = function eachChild(fn) {
  1518. fn(this.lhs);
  1519. fn(this.rhs);
  1520. if (this.collator) {
  1521. fn(this.collator);
  1522. }
  1523. };
  1524. Comparison.prototype.possibleOutputs = function possibleOutputs() {
  1525. return [true, false];
  1526. };
  1527. Comparison.prototype.serialize = function serialize() {
  1528. var serialized = [op];
  1529. this.eachChild(function (child) {
  1530. serialized.push(child.serialize());
  1531. });
  1532. return serialized;
  1533. };
  1534. return Comparison;
  1535. }());
  1536. }
  1537. var ComparisonEnum = {
  1538. };
  1539. ComparisonEnum.Equals = makeComparison('==', eq, eqCollate);
  1540. ComparisonEnum.NotEquals = makeComparison('!=', neq, neqCollate);
  1541. ComparisonEnum.LessThan = makeComparison('<', lt, ltCollate);
  1542. ComparisonEnum.GreaterThan = makeComparison('>', gt, gtCollate);
  1543. ComparisonEnum.LessThanOrEqual = makeComparison('<=', lteq, lteqCollate);
  1544. ComparisonEnum.GreaterThanOrEqual = makeComparison('>=', gteq, gteqCollate);
  1545. var NumberType$5 = {kind: 'number'};
  1546. var StringType$5 = {kind: 'string'};
  1547. var ColorType$3 = {kind: 'color'};
  1548. var ValueType$7 = {kind: 'value'};
  1549. var FormattedType$2 = {kind: 'formatted'};
  1550. var ResolvedImageType$2 = {kind: 'resolvedImage'};
  1551. function array$4(itemType, N) {
  1552. return {
  1553. kind: 'array',
  1554. itemType: itemType,
  1555. N: N
  1556. };
  1557. }
  1558. var FormatExpression$1 = function FormatExpression(sections) {
  1559. this.type = FormattedType$2;
  1560. this.sections = sections;
  1561. };
  1562. FormatExpression$1.parse = function parse(args, context) {
  1563. if (args.length < 2) {
  1564. return context.error("Expected at least one argument.");
  1565. }
  1566. var firstArg = args[1];
  1567. if (!Array.isArray(firstArg) && typeof firstArg === 'object') {
  1568. return context.error("First argument must be an image or text section.");
  1569. }
  1570. var sections = [];
  1571. var nextTokenMayBeObject = false;
  1572. for (var i = 1; i <= args.length - 1; ++i) {
  1573. var arg = (args[i] );
  1574. if (nextTokenMayBeObject && typeof arg === "object" && !Array.isArray(arg)) {
  1575. nextTokenMayBeObject = false;
  1576. var scale = null;
  1577. if (arg['font-scale']) {
  1578. scale = context.parse(arg['font-scale'], 1, NumberType$5);
  1579. if (!scale) {
  1580. return null;
  1581. }
  1582. }
  1583. var font = null;
  1584. if (arg['text-font']) {
  1585. font = context.parse(arg['text-font'], 1, array$4(StringType$5));
  1586. if (!font) {
  1587. return null;
  1588. }
  1589. }
  1590. var textColor = null;
  1591. if (arg['text-color']) {
  1592. textColor = context.parse(arg['text-color'], 1, ColorType$3);
  1593. if (!textColor) {
  1594. return null;
  1595. }
  1596. }
  1597. var lastExpression = sections[sections.length - 1];
  1598. lastExpression.scale = scale;
  1599. lastExpression.font = font;
  1600. lastExpression.textColor = textColor;
  1601. } else {
  1602. var content = context.parse(args[i], 1, ValueType$7);
  1603. if (!content) {
  1604. return null;
  1605. }
  1606. var kind = content.type.kind;
  1607. if (kind !== 'string' && kind !== 'value' && kind !== 'null' && kind !== 'resolvedImage') {
  1608. return context.error("Formatted text type must be 'string', 'value', 'image' or 'null'.");
  1609. }
  1610. nextTokenMayBeObject = true;
  1611. sections.push({content: content, scale: null, font: null, textColor: null});
  1612. }
  1613. }
  1614. return new FormatExpression$1(sections);
  1615. };
  1616. FormatExpression$1.prototype.evaluate = function evaluate(ctx) {
  1617. var evaluateSection = function (section) {
  1618. var evaluatedContent = section.content.evaluate(ctx);
  1619. if (Values$1.typeOf(evaluatedContent) === ResolvedImageType$2) {
  1620. return new FormattedSection('', evaluatedContent, null, null, null);
  1621. }
  1622. return new FormattedSection(
  1623. Values$1.toString$1(evaluatedContent),
  1624. null,
  1625. section.scale ? section.scale.evaluate(ctx) : null,
  1626. section.font ? section.font.evaluate(ctx).join(',') : null,
  1627. section.textColor ? section.textColor.evaluate(ctx) : null
  1628. );
  1629. };
  1630. return new Formatted$1(this.sections.map(evaluateSection));
  1631. };
  1632. FormatExpression$1.prototype.eachChild = function eachChild(fn) {
  1633. for (var i = 0, list = this.sections; i < list.length; i += 1) {
  1634. var section = list[i];
  1635. fn(section.content);
  1636. if (section.scale) {
  1637. fn(section.scale);
  1638. }
  1639. if (section.font) {
  1640. fn(section.font);
  1641. }
  1642. if (section.textColor) {
  1643. fn(section.textColor);
  1644. }
  1645. }
  1646. };
  1647. FormatExpression$1.prototype.possibleOutputs = function possibleOutputs() {
  1648. // Technically the combinatoric set of all children
  1649. // Usually, this.text will be undefined anyway
  1650. return [undefined];
  1651. };
  1652. FormatExpression$1.prototype.serialize = function serialize() {
  1653. var serialized = ["format"];
  1654. for (var i = 0, list = this.sections; i < list.length; i += 1) {
  1655. var section = list[i];
  1656. serialized.push(section.content.serialize());
  1657. var options = {};
  1658. if (section.scale) {
  1659. options['font-scale'] = section.scale.serialize();
  1660. }
  1661. if (section.font) {
  1662. options['text-font'] = section.font.serialize();
  1663. }
  1664. if (section.textColor) {
  1665. options['text-color'] = section.textColor.serialize();
  1666. }
  1667. serialized.push(options);
  1668. }
  1669. return serialized;
  1670. };
  1671. var StringType$6 = {kind: 'string'};
  1672. var ResolvedImageType$3 = {kind: 'resolvedImage'};
  1673. var ImageExpression$1 = function ImageExpression(input) {
  1674. this.type = ResolvedImageType$3;
  1675. this.input = input;
  1676. };
  1677. ImageExpression$1.parse = function parse(args, context) {
  1678. if (args.length !== 2) {
  1679. return context.error("Expected two arguments.");
  1680. }
  1681. var name = context.parse(args[1], 1, StringType$6);
  1682. if (!name) {
  1683. return context.error("No image name provided.");
  1684. }
  1685. return new ImageExpression$1(name);
  1686. };
  1687. ImageExpression$1.prototype.evaluate = function evaluate(ctx) {
  1688. var evaluatedImageName = this.input.evaluate(ctx);
  1689. var available = false;
  1690. if (ctx.availableImages && ctx.availableImages.indexOf(evaluatedImageName) > -1) {
  1691. available = true;
  1692. }
  1693. return new ResolvedImage$1({name: evaluatedImageName, available: available});
  1694. };
  1695. ImageExpression$1.prototype.eachChild = function eachChild(fn) {
  1696. fn(this.input);
  1697. };
  1698. ImageExpression$1.prototype.possibleOutputs = function possibleOutputs() {
  1699. // The output of image is determined by the list of available images in the evaluation context
  1700. return [undefined];
  1701. };
  1702. ImageExpression$1.prototype.serialize = function serialize() {
  1703. return ["image", this.input.serialize()];
  1704. };
  1705. var Interpolate = function Interpolate(type, operator, interpolation, input, stops) {
  1706. this.type = type;
  1707. this.operator = operator;
  1708. this.interpolation = interpolation;
  1709. this.input = input;
  1710. this.labels = [];
  1711. this.outputs = [];
  1712. for (var i = 0, list = stops; i < list.length; i += 1) {
  1713. var ref = list[i];
  1714. var label = ref[0];
  1715. var expression = ref[1];
  1716. this.labels.push(label);
  1717. this.outputs.push(expression);
  1718. }
  1719. };
  1720. var NumberType$6 = {kind: 'number'};
  1721. var ColorType$4 = {kind: 'color'};
  1722. Interpolate.interpolationFactor = function interpolationFactor(interpolation, input, lower, upper) {
  1723. var t = 0;
  1724. if (interpolation.name === 'exponential') {
  1725. t = exponentialInterpolation(input, interpolation.base, lower, upper);
  1726. } else if (interpolation.name === 'linear') {
  1727. t = exponentialInterpolation(input, 1, lower, upper);
  1728. } else if (interpolation.name === 'cubic-bezier') {
  1729. var c = interpolation.controlPoints;
  1730. var ub = new unitbezier(c[0], c[1], c[2], c[3]);
  1731. t = ub.solve(exponentialInterpolation(input, 1, lower, upper));
  1732. }
  1733. return t;
  1734. };
  1735. Interpolate.parse = function parse(args, context) {
  1736. var operator = args[0];
  1737. var interpolation = args[1];
  1738. var input = args[2];
  1739. var rest = args.slice(3);
  1740. if (!Array.isArray(interpolation) || interpolation.length === 0) {
  1741. return context.error("Expected an interpolation type expression.", 1);
  1742. }
  1743. if (interpolation[0] === 'linear') {
  1744. interpolation = {name: 'linear'};
  1745. } else if (interpolation[0] === 'exponential') {
  1746. var base = interpolation[1];
  1747. if (typeof base !== 'number') {
  1748. return context.error("Exponential interpolation requires a numeric base.", 1, 1);
  1749. }
  1750. interpolation = {
  1751. name: 'exponential',
  1752. base: base
  1753. };
  1754. } else if (interpolation[0] === 'cubic-bezier') {
  1755. var controlPoints = interpolation.slice(1);
  1756. if (
  1757. controlPoints.length !== 4 ||
  1758. controlPoints.some(function (t) {
  1759. return typeof t !== 'number' || t < 0 || t > 1;
  1760. })
  1761. ) {
  1762. return context.error('Cubic bezier interpolation requires four numeric arguments with values between 0 and 1.', 1);
  1763. }
  1764. interpolation = {
  1765. name: 'cubic-bezier',
  1766. controlPoints: (controlPoints )
  1767. };
  1768. } else {
  1769. return context.error(("Unknown interpolation type " + (String(interpolation[0]))), 1, 0);
  1770. }
  1771. if (args.length - 1 < 4) {
  1772. return context.error(("Expected at least 4 arguments, but found only " + (args.length - 1) + "."));
  1773. }
  1774. if ((args.length - 1) % 2 !== 0) {
  1775. return context.error("Expected an even number of arguments.");
  1776. }
  1777. input = context.parse(input, 2, NumberType$6);
  1778. if (!input) {
  1779. return null;
  1780. }
  1781. var stops = [];
  1782. var outputType = (null );
  1783. if (operator === 'interpolate-hcl' || operator === 'interpolate-lab') {
  1784. outputType = ColorType$4;
  1785. } else if (context.expectedType && context.expectedType.kind !== 'value') {
  1786. outputType = context.expectedType;
  1787. }
  1788. for (var i = 0; i < rest.length; i += 2) {
  1789. var label = rest[i];
  1790. var value = rest[i + 1];
  1791. var labelKey = i + 3;
  1792. var valueKey = i + 4;
  1793. if (typeof label !== 'number') {
  1794. return context.error('Input/output pairs for "interpolate" expressions must be defined using literal numeric values (not computed expressions) for the input values.', labelKey);
  1795. }
  1796. if (stops.length && stops[stops.length - 1][0] >= label) {
  1797. return context.error('Input/output pairs for "interpolate" expressions must be arranged with input values in strictly ascending order.', labelKey);
  1798. }
  1799. var parsed = context.parse(value, valueKey, outputType);
  1800. if (!parsed) {
  1801. return null;
  1802. }
  1803. outputType = outputType || parsed.type;
  1804. stops.push([label, parsed]);
  1805. }
  1806. if (outputType.kind !== 'number' &&
  1807. outputType.kind !== 'color' && !(
  1808. outputType.kind === 'array' &&
  1809. outputType.itemType.kind === 'number' &&
  1810. typeof outputType.N === 'number'
  1811. )
  1812. ) {
  1813. return context.error(("Type " + (toString(outputType)) + " is not interpolatable."));
  1814. }
  1815. return new Interpolate(outputType, (operator ), interpolation, input, stops);
  1816. };
  1817. Interpolate.prototype.evaluate = function evaluate(ctx) {
  1818. var labels = this.labels;
  1819. var outputs = this.outputs;
  1820. if (labels.length === 1) {
  1821. return outputs[0].evaluate(ctx);
  1822. }
  1823. var value = ((this.input.evaluate(ctx) ) );
  1824. if (value <= labels[0]) {
  1825. return outputs[0].evaluate(ctx);
  1826. }
  1827. var stopCount = labels.length;
  1828. if (value >= labels[stopCount - 1]) {
  1829. return outputs[stopCount - 1].evaluate(ctx);
  1830. }
  1831. var index = findStopLessThanOrEqualTo(labels, value);
  1832. var lower = labels[index];
  1833. var upper = labels[index + 1];
  1834. var t = Interpolate.interpolationFactor(this.interpolation, value, lower, upper);
  1835. var outputLower = outputs[index].evaluate(ctx);
  1836. var outputUpper = outputs[index + 1].evaluate(ctx);
  1837. if (this.operator === 'interpolate') {
  1838. return (interpolate[this.type.kind.toLowerCase()] )(outputLower, outputUpper, t); // eslint-disable-line import/namespace
  1839. } else if (this.operator === 'interpolate-hcl') {
  1840. return hcl.reverse(hcl.interpolate(hcl.forward(outputLower), hcl.forward(outputUpper), t));
  1841. } else {
  1842. return lab.reverse(lab.interpolate(lab.forward(outputLower), lab.forward(outputUpper), t));
  1843. }
  1844. };
  1845. Interpolate.prototype.eachChild = function eachChild(fn) {
  1846. fn(this.input);
  1847. for (var i = 0, list = this.outputs; i < list.length; i += 1) {
  1848. var expression = list[i];
  1849. fn(expression);
  1850. }
  1851. };
  1852. Interpolate.prototype.possibleOutputs = function possibleOutputs() {
  1853. var ref;
  1854. return (ref = []).concat.apply(ref, this.outputs.map(function (output) {
  1855. return output.possibleOutputs();
  1856. }));
  1857. };
  1858. Interpolate.prototype.serialize = function serialize() {
  1859. var interpolation;
  1860. if (this.interpolation.name === 'linear') {
  1861. interpolation = ["linear"];
  1862. } else if (this.interpolation.name === 'exponential') {
  1863. if (this.interpolation.base === 1) {
  1864. interpolation = ["linear"];
  1865. } else {
  1866. interpolation = ["exponential", this.interpolation.base];
  1867. }
  1868. } else {
  1869. interpolation = ["cubic-bezier" ].concat(this.interpolation.controlPoints);
  1870. }
  1871. var serialized = [this.operator, interpolation, this.input.serialize()];
  1872. for (var i = 0; i < this.labels.length; i++) {
  1873. serialized.push(
  1874. this.labels[i],
  1875. this.outputs[i].serialize()
  1876. );
  1877. }
  1878. return serialized;
  1879. };
  1880. /**
  1881. * Returns a ratio that can be used to interpolate between exponential function
  1882. * stops.
  1883. * 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,
  1884. * and `a` and `b` are constants affording sufficient degrees of freedom to fit
  1885. * the function to the given stops.
  1886. *
  1887. * Here's a bit of algebra that lets us compute `f(x)` directly from the stop
  1888. * values without explicitly solving for `a` and `b`:
  1889. *
  1890. * First stop value: `f(x0) = y0 = a * base^x0 + b`
  1891. * Second stop value: `f(x1) = y1 = a * base^x1 + b`
  1892. * => `y1 - y0 = a(base^x1 - base^x0)`
  1893. * => `a = (y1 - y0)/(base^x1 - base^x0)`
  1894. *
  1895. * Desired value: `f(x) = y = a * base^x + b`
  1896. * => `f(x) = y0 + a * (base^x - base^x0)`
  1897. *
  1898. * From the above, we can replace the `a` in `a * (base^x - base^x0)` and do a
  1899. * little algebra:
  1900. * ```
  1901. * a * (base^x - base^x0) = (y1 - y0)/(base^x1 - base^x0) * (base^x - base^x0)
  1902. * = (y1 - y0) * (base^x - base^x0) / (base^x1 - base^x0)
  1903. * ```
  1904. *
  1905. * If we let `(base^x - base^x0) / (base^x1 base^x0)`, then we have
  1906. * `f(x) = y0 + (y1 - y0) * ratio`. In other words, `ratio` may be treated as
  1907. * an interpolation factor between the two stops' output values.
  1908. *
  1909. * (Note: a slightly different form for `ratio`,
  1910. * `(base^(x-x0) - 1) / (base^(x1-x0) - 1) `, is equivalent, but requires fewer
  1911. * expensive `Math.pow()` operations.)
  1912. *
  1913. * @private
  1914. */
  1915. function exponentialInterpolation(input, base, lowerValue, upperValue) {
  1916. var difference = upperValue - lowerValue;
  1917. var progress = input - lowerValue;
  1918. if (difference === 0) {
  1919. return 0;
  1920. } else if (base === 1) {
  1921. return progress / difference;
  1922. } else {
  1923. return (Math.pow(base, progress) - 1) / (Math.pow(base, difference) - 1);
  1924. }
  1925. }
  1926. var BooleanType$7 = {kind: 'boolean'};
  1927. var ValueType$8 = {kind: 'value'};
  1928. function isComparableType(type) {
  1929. return type.kind === 'boolean' ||
  1930. type.kind === 'string' ||
  1931. type.kind === 'number' ||
  1932. type.kind === 'null' ||
  1933. type.kind === 'value';
  1934. }
  1935. function isComparableRuntimeValue(needle) {
  1936. return typeof needle === 'boolean' ||
  1937. typeof needle === 'string' ||
  1938. typeof needle === 'number';
  1939. }
  1940. function isSearchableRuntimeValue(haystack) {
  1941. return Array.isArray(haystack) ||
  1942. typeof haystack === 'string';
  1943. }
  1944. var In = function In(needle, haystack) {
  1945. this.type = BooleanType$7;
  1946. this.needle = needle;
  1947. this.haystack = haystack;
  1948. };
  1949. In.parse = function parse(args, context) {
  1950. if (args.length !== 3) {
  1951. return context.error(("Expected 2 arguments, but found " + (args.length - 1) + " instead."));
  1952. }
  1953. var needle = context.parse(args[1], 1, ValueType$8);
  1954. var haystack = context.parse(args[2], 2, ValueType$8);
  1955. if (!needle || !haystack) {
  1956. return null;
  1957. }
  1958. if (!isComparableType(needle.type)) {
  1959. return context.error(("Expected first argument to be of type boolean, string, number or null, but found " + (toString(needle.type)) + " instead"));
  1960. }
  1961. return new In(needle, haystack);
  1962. };
  1963. In.prototype.evaluate = function evaluate(ctx) {
  1964. var needle = (this.needle.evaluate(ctx) );
  1965. var haystack = (this.haystack.evaluate(ctx) );
  1966. if (!needle || !haystack) {
  1967. return false;
  1968. }
  1969. if (!isComparableRuntimeValue(needle)) {
  1970. throw new RuntimeError(("Expected first argument to be of type boolean, string or number, but found " + (toString(typeOf(needle))) + " instead."));
  1971. }
  1972. if (!isSearchableRuntimeValue(haystack)) {
  1973. throw new RuntimeError(("Expected second argument to be of type array or string, but found " + (toString(typeOf(haystack))) + " instead."));
  1974. }
  1975. return haystack.indexOf(needle) >= 0;
  1976. };
  1977. In.prototype.eachChild = function eachChild(fn) {
  1978. fn(this.needle);
  1979. fn(this.haystack);
  1980. };
  1981. In.prototype.possibleOutputs = function possibleOutputs() {
  1982. return [true, false];
  1983. };
  1984. In.prototype.serialize = function serialize() {
  1985. return ["in", this.needle.serialize(), this.haystack.serialize()];
  1986. };
  1987. var Let = function Let(bindings, result) {
  1988. this.type = result.type;
  1989. this.bindings = [].concat(bindings);
  1990. this.result = result;
  1991. };
  1992. Let.prototype.evaluate = function evaluate(ctx) {
  1993. return this.result.evaluate(ctx);
  1994. };
  1995. Let.prototype.eachChild = function eachChild(fn) {
  1996. for (var i = 0, list = this.bindings; i < list.length; i += 1) {
  1997. var binding = list[i];
  1998. fn(binding[1]);
  1999. }
  2000. fn(this.result);
  2001. };
  2002. Let.parse = function parse(args, context) {
  2003. if (args.length < 4) {
  2004. return context.error(("Expected at least 3 arguments, but found " + (args.length - 1) + " instead."));
  2005. }
  2006. var bindings = [];
  2007. for (var i = 1; i < args.length - 1; i += 2) {
  2008. var name = args[i];
  2009. if (typeof name !== 'string') {
  2010. return context.error(("Expected string, but found " + (typeof name) + " instead."), i);
  2011. }
  2012. if (/[^a-zA-Z0-9_]/.test(name)) {
  2013. return context.error("Variable names must contain only alphanumeric characters or '_'.", i);
  2014. }
  2015. var value = context.parse(args[i + 1], i + 1);
  2016. if (!value) {
  2017. return null;
  2018. }
  2019. bindings.push([name, value]);
  2020. }
  2021. var result = context.parse(args[args.length - 1], args.length - 1, context.expectedType, bindings);
  2022. if (!result) {
  2023. return null;
  2024. }
  2025. return new Let(bindings, result);
  2026. };
  2027. Let.prototype.possibleOutputs = function possibleOutputs() {
  2028. return this.result.possibleOutputs();
  2029. };
  2030. Let.prototype.serialize = function serialize() {
  2031. var serialized = ["let"];
  2032. for (var i = 0, list = this.bindings; i < list.length; i += 1) {
  2033. var ref = list[i];
  2034. var name = ref[0];
  2035. var expr = ref[1];
  2036. serialized.push(name, expr.serialize());
  2037. }
  2038. serialized.push(this.result.serialize());
  2039. return serialized;
  2040. };
  2041. var NumberType$7 = {kind: 'number'};
  2042. var Length = function Length(input) {
  2043. this.type = NumberType$7;
  2044. this.input = input;
  2045. };
  2046. Length.parse = function parse(args, context) {
  2047. if (args.length !== 2) {
  2048. return context.error(("Expected 1 argument, but found " + (args.length - 1) + " instead."));
  2049. }
  2050. var input = context.parse(args[1], 1);
  2051. if (!input) {
  2052. return null;
  2053. }
  2054. if (input.type.kind !== 'array' && input.type.kind !== 'string' && input.type.kind !== 'value') {
  2055. return context.error(("Expected argument of type string or array, but found " + (toString(input.type)) + " instead."));
  2056. }
  2057. return new Length(input);
  2058. };
  2059. Length.prototype.evaluate = function evaluate(ctx) {
  2060. var input = this.input.evaluate(ctx);
  2061. if (typeof input === 'string') {
  2062. return input.length;
  2063. } else if (Array.isArray(input)) {
  2064. return input.length;
  2065. } else {
  2066. throw new RuntimeError(("Expected value to be of type string or array, but found " + (toString(typeOf(input))) + " instead."));
  2067. }
  2068. };
  2069. Length.prototype.eachChild = function eachChild(fn) {
  2070. fn(this.input);
  2071. };
  2072. Length.prototype.possibleOutputs = function possibleOutputs() {
  2073. return [undefined];
  2074. };
  2075. Length.prototype.serialize = function serialize() {
  2076. var serialized = ["length"];
  2077. this.eachChild(function (child) {
  2078. serialized.push(child.serialize());
  2079. });
  2080. return serialized;
  2081. };
  2082. var Literal = function Literal(type, value) {
  2083. this.type = type;
  2084. this.value = value;
  2085. };
  2086. Literal.parse = function parse(args, context) {
  2087. if (args.length !== 2) {
  2088. return context.error(("'literal' expression requires exactly one argument, but found " + (args.length - 1) + " instead."));
  2089. }
  2090. if (!Values$1.isValue(args[1])) {
  2091. return context.error("invalid value");
  2092. }
  2093. var value = (args[1] );
  2094. var type = Values$1.typeOf(value);
  2095. // special case: infer the item type if possible for zero-length arrays
  2096. var expected = context.expectedType;
  2097. if (
  2098. type.kind === 'array' &&
  2099. type.N === 0 &&
  2100. expected &&
  2101. expected.kind === 'array' &&
  2102. (typeof expected.N !== 'number' || expected.N === 0)
  2103. ) {
  2104. type = expected;
  2105. }
  2106. return new Literal(type, value);
  2107. };
  2108. Literal.prototype.evaluate = function evaluate() {
  2109. return this.value;
  2110. };
  2111. Literal.prototype.eachChild = function eachChild() {
  2112. };
  2113. Literal.prototype.possibleOutputs = function possibleOutputs() {
  2114. return [this.value];
  2115. };
  2116. Literal.prototype.serialize = function serialize() {
  2117. if (this.type.kind === 'array' || this.type.kind === 'object') {
  2118. return ["literal", this.value];
  2119. } else if (this.value instanceof Color) {
  2120. // Constant-folding can generate Literal expressions that you
  2121. // couldn't actually generate with a "literal" expression,
  2122. // so we have to implement an equivalent serialization here
  2123. return ["rgba"].concat(this.value.toArray());
  2124. } else if (this.value instanceof Formatted$1) {
  2125. // Same as Color
  2126. return this.value.serialize();
  2127. } else {
  2128. return (this.value );
  2129. }
  2130. };
  2131. var ValueType$9 = {kind: 'value'};
  2132. // Map input label values to output expression index
  2133. var Match = function Match(inputType, outputType, input, cases, outputs, otherwise) {
  2134. this.inputType = inputType;
  2135. this.type = outputType;
  2136. this.input = input;
  2137. this.cases = cases;
  2138. this.outputs = outputs;
  2139. this.otherwise = otherwise;
  2140. };
  2141. Match.parse = function parse(args, context) {
  2142. if (args.length < 5) {
  2143. return context.error(("Expected at least 4 arguments, but found only " + (args.length - 1) + "."));
  2144. }
  2145. if (args.length % 2 !== 1) {
  2146. return context.error("Expected an even number of arguments.");
  2147. }
  2148. var inputType;
  2149. var outputType;
  2150. if (context.expectedType && context.expectedType.kind !== 'value') {
  2151. outputType = context.expectedType;
  2152. }
  2153. var cases = {};
  2154. var outputs = [];
  2155. for (var i = 2; i < args.length - 1; i += 2) {
  2156. var labels = args[i];
  2157. var value = args[i + 1];
  2158. if (!Array.isArray(labels)) {
  2159. labels = [labels];
  2160. }
  2161. var labelContext = context.concat(i);
  2162. if (labels.length === 0) {
  2163. return labelContext.error('Expected at least one branch label.');
  2164. }
  2165. for (var i$1 = 0, list = labels; i$1 < list.length; i$1 += 1) {
  2166. var label = list[i$1];
  2167. if (typeof label !== 'number' && typeof label !== 'string') {
  2168. return labelContext.error("Branch labels must be numbers or strings.");
  2169. } else if (typeof label === 'number' && Math.abs(label) > Number.MAX_SAFE_INTEGER) {
  2170. return labelContext.error(("Branch labels must be integers no larger than " + (Number.MAX_SAFE_INTEGER) + "."));
  2171. } else if (typeof label === 'number' && Math.floor(label) !== label) {
  2172. return labelContext.error("Numeric branch labels must be integer values.");
  2173. } else if (!inputType) {
  2174. inputType = Values$1.typeOf(label);
  2175. } else if (labelContext.checkSubtype(inputType, Values$1.typeOf(label))) {
  2176. return null;
  2177. }
  2178. if (typeof cases[String(label)] !== 'undefined') {
  2179. return labelContext.error('Branch labels must be unique.');
  2180. }
  2181. cases[String(label)] = outputs.length;
  2182. }
  2183. var result = context.parse(value, i, outputType);
  2184. if (!result) {
  2185. return null;
  2186. }
  2187. outputType = outputType || result.type;
  2188. outputs.push(result);
  2189. }
  2190. var input = context.parse(args[1], 1, ValueType$9);
  2191. if (!input) {
  2192. return null;
  2193. }
  2194. var otherwise = context.parse(args[args.length - 1], args.length - 1, outputType);
  2195. if (!otherwise) {
  2196. return null;
  2197. }
  2198. if (input.type.kind !== 'value' && context.concat(1).checkSubtype((inputType ), input.type)) {
  2199. return null;
  2200. }
  2201. return new Match((inputType ), (outputType ), input, cases, outputs, otherwise);
  2202. };
  2203. Match.prototype.evaluate = function evaluate(ctx) {
  2204. var input = (this.input.evaluate(ctx) );
  2205. var output = (Values$1.typeOf(input) === this.inputType && this.outputs[this.cases[input]]) || this.otherwise;
  2206. return output.evaluate(ctx);
  2207. };
  2208. Match.prototype.eachChild = function eachChild(fn) {
  2209. fn(this.input);
  2210. this.outputs.forEach(fn);
  2211. fn(this.otherwise);
  2212. };
  2213. Match.prototype.possibleOutputs = function possibleOutputs() {
  2214. var ref;
  2215. return (ref = [])
  2216. .concat.apply(ref, this.outputs.map(function (out) {
  2217. return out.possibleOutputs();
  2218. }))
  2219. .concat(this.otherwise.possibleOutputs());
  2220. };
  2221. Match.prototype.serialize = function serialize() {
  2222. var this$1 = this;
  2223. var serialized = ["match", this.input.serialize()];
  2224. // Sort so serialization has an arbitrary defined order, even though
  2225. // branch order doesn't affect evaluation
  2226. var sortedLabels = Object.keys(this.cases).sort();
  2227. // Group branches by unique match expression to support condensed
  2228. // serializations of the form [case1, case2, ...] -> matchExpression
  2229. var groupedByOutput = [];
  2230. var outputLookup = {}; // lookup index into groupedByOutput for a given output expression
  2231. for (var i = 0, list = sortedLabels; i < list.length; i += 1) {
  2232. var label = list[i];
  2233. var outputIndex = outputLookup[this.cases[label]];
  2234. if (outputIndex === undefined) {
  2235. // First time seeing this output, add it to the end of the grouped list
  2236. outputLookup[this.cases[label]] = groupedByOutput.length;
  2237. groupedByOutput.push([this.cases[label], [label]]);
  2238. } else {
  2239. // We've seen this expression before, add the label to that output's group
  2240. groupedByOutput[outputIndex][1].push(label);
  2241. }
  2242. }
  2243. var coerceLabel = function (label) {
  2244. return this$1.inputType.kind === 'number' ? Number(label) : label;
  2245. };
  2246. for (var i$1 = 0, list$1 = groupedByOutput; i$1 < list$1.length; i$1 += 1) {
  2247. var ref = list$1[i$1];
  2248. var outputIndex = ref[0];
  2249. var labels = ref[1];
  2250. if (labels.length === 1) {
  2251. // Only a single label matches this output expression
  2252. serialized.push(coerceLabel(labels[0]));
  2253. } else {
  2254. // Array of literal labels pointing to this output expression
  2255. serialized.push(labels.map(coerceLabel));
  2256. }
  2257. serialized.push(this.outputs[outputIndex$1].serialize());
  2258. }
  2259. serialized.push(this.otherwise.serialize());
  2260. return serialized;
  2261. };
  2262. var NumberType$8 = {kind: 'number'};
  2263. var StringType$7 = {kind: 'string'};
  2264. var NumberFormat = function NumberFormat(number, locale, currency, minFractionDigits, maxFractionDigits) {
  2265. this.type = StringType$7;
  2266. this.number = number;
  2267. this.locale = locale;
  2268. this.currency = currency;
  2269. this.minFractionDigits = minFractionDigits;
  2270. this.maxFractionDigits = maxFractionDigits;
  2271. };
  2272. NumberFormat.parse = function parse(args, context) {
  2273. if (args.length !== 3) {
  2274. return context.error("Expected two arguments.");
  2275. }
  2276. var number = context.parse(args[1], 1, NumberType$8);
  2277. if (!number) {
  2278. return null;
  2279. }
  2280. var options = (args[2] );
  2281. if (typeof options !== "object" || Array.isArray(options)) {
  2282. return context.error("NumberFormat options argument must be an object.");
  2283. }
  2284. var locale = null;
  2285. if (options['locale']) {
  2286. locale = context.parse(options['locale'], 1, StringType$7);
  2287. if (!locale) {
  2288. return null;
  2289. }
  2290. }
  2291. var currency = null;
  2292. if (options['currency']) {
  2293. currency = context.parse(options['currency'], 1, StringType$7);
  2294. if (!currency) {
  2295. return null;
  2296. }
  2297. }
  2298. var minFractionDigits = null;
  2299. if (options['min-fraction-digits']) {
  2300. minFractionDigits = context.parse(options['min-fraction-digits'], 1, NumberType$8);
  2301. if (!minFractionDigits) {
  2302. return null;
  2303. }
  2304. }
  2305. var maxFractionDigits = null;
  2306. if (options['max-fraction-digits']) {
  2307. maxFractionDigits = context.parse(options['max-fraction-digits'], 1, NumberType$8);
  2308. if (!maxFractionDigits) {
  2309. return null;
  2310. }
  2311. }
  2312. return new NumberFormat(number, locale, currency, minFractionDigits, maxFractionDigits);
  2313. };
  2314. NumberFormat.prototype.evaluate = function evaluate(ctx) {
  2315. return new Intl.NumberFormat(this.locale ? this.locale.evaluate(ctx) : [],
  2316. {
  2317. style: this.currency ? "currency" : "decimal",
  2318. currency: this.currency ? this.currency.evaluate(ctx) : undefined,
  2319. minimumFractionDigits: this.minFractionDigits ? this.minFractionDigits.evaluate(ctx) : undefined,
  2320. maximumFractionDigits: this.maxFractionDigits ? this.maxFractionDigits.evaluate(ctx) : undefined,
  2321. }).format(this.number.evaluate(ctx));
  2322. };
  2323. NumberFormat.prototype.eachChild = function eachChild(fn) {
  2324. fn(this.number);
  2325. if (this.locale) {
  2326. fn(this.locale);
  2327. }
  2328. if (this.currency) {
  2329. fn(this.currency);
  2330. }
  2331. if (this.minFractionDigits) {
  2332. fn(this.minFractionDigits);
  2333. }
  2334. if (this.maxFractionDigits) {
  2335. fn(this.maxFractionDigits);
  2336. }
  2337. };
  2338. NumberFormat.prototype.possibleOutputs = function possibleOutputs() {
  2339. return [undefined];
  2340. };
  2341. NumberFormat.prototype.serialize = function serialize() {
  2342. var options = {};
  2343. if (this.locale) {
  2344. options['locale'] = this.locale.serialize();
  2345. }
  2346. if (this.currency) {
  2347. options['currency'] = this.currency.serialize();
  2348. }
  2349. if (this.minFractionDigits) {
  2350. options['min-fraction-digits'] = this.minFractionDigits.serialize();
  2351. }
  2352. if (this.maxFractionDigits) {
  2353. options['max-fraction-digits'] = this.maxFractionDigits.serialize();
  2354. }
  2355. return ["number-format", this.number.serialize(), options];
  2356. };
  2357. /**
  2358. * Returns the index of the last stop <= input, or 0 if it doesn't exist.
  2359. * @private
  2360. */
  2361. function findStopLessThanOrEqualTo$1(stops, input) {
  2362. var lastIndex = stops.length - 1;
  2363. var lowerIndex = 0;
  2364. var upperIndex = lastIndex;
  2365. var currentIndex = 0;
  2366. var currentValue, nextValue;
  2367. while (lowerIndex <= upperIndex) {
  2368. currentIndex = Math.floor((lowerIndex + upperIndex) / 2);
  2369. currentValue = stops[currentIndex];
  2370. nextValue = stops[currentIndex + 1];
  2371. if (currentValue <= input) {
  2372. if (currentIndex === lastIndex || input < nextValue) { // Search complete
  2373. return currentIndex;
  2374. }
  2375. lowerIndex = currentIndex + 1;
  2376. } else if (currentValue > input) {
  2377. upperIndex = currentIndex - 1;
  2378. } else {
  2379. throw new RuntimeError('Input is not a number.');
  2380. }
  2381. }
  2382. return 0;
  2383. }
  2384. var NumberType$9 = {kind: 'number'};
  2385. var Step = function Step(type, input, stops) {
  2386. this.type = type;
  2387. this.input = input;
  2388. this.labels = [];
  2389. this.outputs = [];
  2390. for (var i = 0, list = stops; i < list.length; i += 1) {
  2391. var ref = list[i];
  2392. var label = ref[0];
  2393. var expression = ref[1];
  2394. this.labels.push(label);
  2395. this.outputs.push(expression);
  2396. }
  2397. };
  2398. Step.parse = function parse(args, context) {
  2399. if (args.length - 1 < 4) {
  2400. return context.error(("Expected at least 4 arguments, but found only " + (args.length - 1) + "."));
  2401. }
  2402. if ((args.length - 1) % 2 !== 0) {
  2403. return context.error("Expected an even number of arguments.");
  2404. }
  2405. var input = context.parse(args[1], 1, NumberType$9);
  2406. if (!input) {
  2407. return null;
  2408. }
  2409. var stops = [];
  2410. var outputType = (null );
  2411. if (context.expectedType && context.expectedType.kind !== 'value') {
  2412. outputType = context.expectedType;
  2413. }
  2414. for (var i = 1; i < args.length; i += 2) {
  2415. var label = i === 1 ? -Infinity : args[i];
  2416. var value = args[i + 1];
  2417. var labelKey = i;
  2418. var valueKey = i + 1;
  2419. if (typeof label !== 'number') {
  2420. return context.error('Input/output pairs for "step" expressions must be defined using literal numeric values (not computed expressions) for the input values.', labelKey);
  2421. }
  2422. if (stops.length && stops[stops.length - 1][0] >= label) {
  2423. return context.error('Input/output pairs for "step" expressions must be arranged with input values in strictly ascending order.', labelKey);
  2424. }
  2425. var parsed = context.parse(value, valueKey, outputType);
  2426. if (!parsed) {
  2427. return null;
  2428. }
  2429. outputType = outputType || parsed.type;
  2430. stops.push([label, parsed]);
  2431. }
  2432. return new Step(outputType, input, stops);
  2433. };
  2434. Step.prototype.evaluate = function evaluate(ctx) {
  2435. var labels = this.labels;
  2436. var outputs = this.outputs;
  2437. if (labels.length === 1) {
  2438. return outputs[0].evaluate(ctx);
  2439. }
  2440. var value = ((this.input.evaluate(ctx) ) );
  2441. if (value <= labels[0]) {
  2442. return outputs[0].evaluate(ctx);
  2443. }
  2444. var stopCount = labels.length;
  2445. if (value >= labels[stopCount - 1]) {
  2446. return outputs[stopCount - 1].evaluate(ctx);
  2447. }
  2448. var index = findStopLessThanOrEqualTo$1(labels, value);
  2449. return outputs[index].evaluate(ctx);
  2450. };
  2451. Step.prototype.eachChild = function eachChild(fn) {
  2452. fn(this.input);
  2453. for (var i = 0, list = this.outputs; i < list.length; i += 1) {
  2454. var expression = list[i];
  2455. fn(expression);
  2456. }
  2457. };
  2458. Step.prototype.possibleOutputs = function possibleOutputs() {
  2459. var ref;
  2460. return (ref = []).concat.apply(ref, this.outputs.map(function (output) {
  2461. return output.possibleOutputs();
  2462. }));
  2463. };
  2464. Step.prototype.serialize = function serialize() {
  2465. var serialized = ["step", this.input.serialize()];
  2466. for (var i = 0; i < this.labels.length; i++) {
  2467. if (i > 0) {
  2468. serialized.push(this.labels[i]);
  2469. }
  2470. serialized.push(this.outputs[i].serialize());
  2471. }
  2472. return serialized;
  2473. };
  2474. var Var = function Var(name, boundExpression) {
  2475. this.type = boundExpression.type;
  2476. this.name = name;
  2477. this.boundExpression = boundExpression;
  2478. };
  2479. Var.parse = function parse(args, context) {
  2480. if (args.length !== 2 || typeof args[1] !== 'string') {
  2481. return context.error("'var' expression requires exactly one string literal argument.");
  2482. }
  2483. var name = args[1];
  2484. if (!context.scope.has(name)) {
  2485. return context.error(("Unknown variable \"" + name + "\". Make sure \"" + name + "\" has been bound in an enclosing \"let\" expression before using it."), 1);
  2486. }
  2487. return new Var(name, context.scope.get(name));
  2488. };
  2489. Var.prototype.evaluate = function evaluate(ctx) {
  2490. return this.boundExpression.evaluate(ctx);
  2491. };
  2492. Var.prototype.eachChild = function eachChild() {
  2493. };
  2494. Var.prototype.possibleOutputs = function possibleOutputs() {
  2495. return [undefined];
  2496. };
  2497. Var.prototype.serialize = function serialize() {
  2498. return ["var", this.name];
  2499. };
  2500. var expressions = {
  2501. // special forms
  2502. '==': ComparisonEnum.Equals,
  2503. '!=': ComparisonEnum.NotEquals,
  2504. '>': ComparisonEnum.GreaterThan,
  2505. '<': ComparisonEnum.LessThan,
  2506. '>=': ComparisonEnum.GreaterThanOrEqual,
  2507. '<=': ComparisonEnum.LessThanOrEqual,
  2508. 'array': Assertion,
  2509. 'at': At,
  2510. 'boolean': Assertion,
  2511. 'case': Case,
  2512. 'coalesce': Coalesce,
  2513. 'collator': CollatorExpression,
  2514. 'format': FormatExpression$1,
  2515. 'image': ImageExpression$1,
  2516. 'in': In,
  2517. 'interpolate': Interpolate,
  2518. 'interpolate-hcl': Interpolate,
  2519. 'interpolate-lab': Interpolate,
  2520. 'length': Length,
  2521. 'let': Let,
  2522. 'literal': Literal,
  2523. 'match': Match,
  2524. 'number': Assertion,
  2525. 'number-format': NumberFormat,
  2526. 'object': Assertion,
  2527. 'step': Step,
  2528. 'string': Assertion,
  2529. 'to-boolean': Coercion,
  2530. 'to-color': Coercion,
  2531. 'to-number': Coercion,
  2532. 'to-string': Coercion,
  2533. 'var': Var
  2534. };
  2535. function WebWorkerTransfer() {
  2536. }
  2537. var registry = {};
  2538. /**
  2539. * Register the given class as serializable.
  2540. *
  2541. * @param options
  2542. * @param options.omit List of properties to omit from serialization (e.g., cached/computed properties)
  2543. * @param options.shallow List of properties that should be serialized by a simple shallow copy, rather than by a recursive call to serialize().
  2544. *
  2545. * @private
  2546. */
  2547. WebWorkerTransfer.register = function (name, klass, options) {
  2548. if (options === void 0) options = {};
  2549. //assert(!registry[name], (name + " is already registered."));
  2550. (Object.defineProperty )(klass, '_classRegistryKey', {
  2551. value: name,
  2552. writeable: false
  2553. });
  2554. registry[name] = {
  2555. klass: klass,
  2556. omit: options.omit || [],
  2557. shallow: options.shallow || []
  2558. };
  2559. };
  2560. WebWorkerTransfer.register('Object', Object);
  2561. // gridIndex.serialize = function serialize(grid, transferables) {
  2562. // var buffer = grid.toArrayBuffer();
  2563. // if (transferables) {
  2564. // transferables.push(buffer);
  2565. // }
  2566. // return {buffer: buffer};
  2567. // };
  2568. //
  2569. // gridIndex.deserialize = function deserialize(serialized) {
  2570. // return new gridIndex(serialized.buffer);
  2571. // };
  2572. // register('Grid', gridIndex);
  2573. WebWorkerTransfer.register('Color', Color$1);
  2574. //WebWorkerTransfer.register('Error', Error);
  2575. WebWorkerTransfer.register('ResolvedImage', ResolvedImage$1);
  2576. WebWorkerTransfer.register('ImageAtlas', ImageAtlas);
  2577. WebWorkerTransfer.register('ImagePosition', ImagePosition);
  2578. WebWorkerTransfer.register('RGBAImage', RGBAImage);
  2579. WebWorkerTransfer.register('Formatted', Formatted$1);
  2580. WebWorkerTransfer.register('FormattedSection', FormattedSection);
  2581. // WebWorkerTransfer.register('StylePropertyFunction', StylePropertyFunction);
  2582. // WebWorkerTransfer.register('StyleExpression', StyleExpression, {omit: ['_evaluator']});
  2583. //
  2584. // WebWorkerTransfer.register('ZoomDependentExpression', ZoomDependentExpression);
  2585. // WebWorkerTransfer.register('ZoomConstantExpression', ZoomConstantExpression);
  2586. // WebWorkerTransfer.register('CompoundExpression', CompoundExpression, {omit: ['_evaluate']});
  2587. for (var name$1 in expressions) {
  2588. if ((expressions[name$1] )._classRegistryKey) {
  2589. continue;
  2590. }
  2591. WebWorkerTransfer.register(("Expression_" + name$1), expressions[name$1]);
  2592. }
  2593. function isArrayBuffer(val) {
  2594. return val && typeof ArrayBuffer !== 'undefined' &&
  2595. (val instanceof ArrayBuffer || (val.constructor && val.constructor.name === 'ArrayBuffer'));
  2596. }
  2597. /**
  2598. * Serialize the given object for transfer to or from a web worker.
  2599. *
  2600. * For non-builtin types, recursively serialize each property (possibly
  2601. * omitting certain properties - see register()), and package the result along
  2602. * with the constructor's `name` so that the appropriate constructor can be
  2603. * looked up in `deserialize()`.
  2604. *
  2605. * If a `transferables` array is provided, add any transferable objects (i.e.,
  2606. * any ArrayBuffers or ArrayBuffer views) to the list. (If a copy is needed,
  2607. * this should happen in the client code, before using serialize().)
  2608. *
  2609. * @private
  2610. */
  2611. WebWorkerTransfer.serialize = function (input, transferables) {
  2612. if (input === null ||
  2613. input === undefined ||
  2614. typeof input === 'boolean' ||
  2615. typeof input === 'number' ||
  2616. typeof input === 'string' ||
  2617. input instanceof Boolean ||
  2618. input instanceof Number ||
  2619. input instanceof String ||
  2620. input instanceof Date ||
  2621. input instanceof RegExp) {
  2622. return input;
  2623. }
  2624. if (isArrayBuffer(input)) {
  2625. if (transferables) {
  2626. transferables.push(((input ) ));
  2627. }
  2628. return input;
  2629. }
  2630. if (ArrayBuffer.isView(input)) {
  2631. var view = (input );
  2632. if (transferables) {
  2633. transferables.push(view.buffer);
  2634. }
  2635. return view;
  2636. }
  2637. if (input instanceof ImageData) {
  2638. if (transferables) {
  2639. transferables.push(input.data.buffer);
  2640. }
  2641. return input;
  2642. }
  2643. if (Array.isArray(input)) {
  2644. var serialized = [];
  2645. for (var i = 0, list = input; i < list.length; i += 1) {
  2646. var item = list[i];
  2647. serialized.push(WebWorkerTransfer.serialize(item, transferables));
  2648. }
  2649. return serialized;
  2650. }
  2651. if (typeof input === 'object') {
  2652. var klass = (input.constructor );
  2653. var name = klass._classRegistryKey;
  2654. if (!name) {
  2655. throw new Error("can't serialize object of unregistered class");
  2656. }
  2657. //assert(registry[name]);
  2658. var properties = klass.serialize ?
  2659. // (Temporary workaround) allow a class to provide static
  2660. // `serialize()` and `deserialize()` methods to bypass the generic
  2661. // approach.
  2662. // This temporary workaround lets us use the generic serialization
  2663. // approach for objects whose members include instances of dynamic
  2664. // StructArray types. Once we refactor StructArray to be static,
  2665. // we can remove this complexity.
  2666. (klass.serialize(input, transferables) ) : {};
  2667. if (!klass.serialize) {
  2668. for (var key in input) {
  2669. // any cast due to https://github.com/facebook/flow/issues/5393
  2670. if (!(input ).hasOwnProperty(key)) {
  2671. continue;
  2672. }
  2673. if (registry[name].omit.indexOf(key) >= 0) {
  2674. continue;
  2675. }
  2676. var property = (input )[key];
  2677. if(typeof property == "function") {
  2678. continue;
  2679. }
  2680. properties[key] = registry[name].shallow.indexOf(key) >= 0 ?
  2681. property :
  2682. WebWorkerTransfer.serialize(property, transferables);
  2683. }
  2684. if (input instanceof Error) {
  2685. properties.message = input.message;
  2686. }
  2687. }
  2688. if (properties.$name) {
  2689. throw new Error('$name property is reserved for worker serialization logic.');
  2690. }
  2691. if (name !== 'Object') {
  2692. properties.$name = name;
  2693. }
  2694. return properties;
  2695. }
  2696. throw new Error(("can't serialize object of type " + (typeof input)));
  2697. };
  2698. WebWorkerTransfer.deserialize = function (input) {
  2699. if (input === null ||
  2700. input === undefined ||
  2701. typeof input === 'boolean' ||
  2702. typeof input === 'number' ||
  2703. typeof input === 'string' ||
  2704. input instanceof Boolean ||
  2705. input instanceof Number ||
  2706. input instanceof String ||
  2707. input instanceof Date ||
  2708. input instanceof RegExp ||
  2709. isArrayBuffer(input) ||
  2710. ArrayBuffer.isView(input) ||
  2711. input instanceof ImageData) {
  2712. return input;
  2713. }
  2714. if (Array.isArray(input)) {
  2715. return input.map(WebWorkerTransfer.deserialize);
  2716. }
  2717. if (typeof input === 'object') {
  2718. var name = (input ).$name || 'Object';
  2719. var ref = registry[name];
  2720. var klass = ref.klass;
  2721. if (!klass) {
  2722. throw new Error(("can't deserialize unregistered class " + name));
  2723. }
  2724. if (klass.deserialize) {
  2725. return (klass.deserialize )(input);
  2726. }
  2727. var result = Object.create(klass.prototype);
  2728. for (var i = 0, list = Object.keys(input); i < list.length; i += 1) {
  2729. var key = list[i];
  2730. if (key === '$name') {
  2731. continue;
  2732. }
  2733. var value = (input )[key];
  2734. result[key] = registry[name].shallow.indexOf(key) >= 0 ? value : WebWorkerTransfer.deserialize(value);
  2735. }
  2736. return result;
  2737. }
  2738. throw new Error(("can't deserialize object of type " + (typeof input)));
  2739. };
  2740. var ZoomHistory = function ZoomHistory() {
  2741. this.first = true;
  2742. };
  2743. ZoomHistory.prototype.update = function update (z , now ) {
  2744. var floorZ = Math.floor(z);
  2745. if (this.first) {
  2746. this.first = false;
  2747. this.lastIntegerZoom = floorZ;
  2748. this.lastIntegerZoomTime = 0;
  2749. this.lastZoom = z;
  2750. this.lastFloorZoom = floorZ;
  2751. return true;
  2752. }
  2753. if (this.lastFloorZoom > floorZ) {
  2754. this.lastIntegerZoom = floorZ + 1;
  2755. this.lastIntegerZoomTime = now;
  2756. } else if (this.lastFloorZoom < floorZ) {
  2757. this.lastIntegerZoom = floorZ;
  2758. this.lastIntegerZoomTime = now;
  2759. }
  2760. if (z !== this.lastZoom) {
  2761. this.lastZoom = z;
  2762. this.lastFloorZoom = floorZ;
  2763. return true;
  2764. }
  2765. return false;
  2766. };
  2767. var EvaluationParameters$1 = function EvaluationParameters(zoom, options) {
  2768. this.zoom = zoom;
  2769. if (options) {
  2770. this.now = options.now;
  2771. this.fadeDuration = options.fadeDuration;
  2772. this.zoomHistory = options.zoomHistory;
  2773. this.transition = options.transition;
  2774. } else {
  2775. this.now = 0;
  2776. this.fadeDuration = 0;
  2777. this.zoomHistory = new ZoomHistory();
  2778. this.transition = {};
  2779. }
  2780. };
  2781. EvaluationParameters$1.prototype.isSupportedScript = function isSupportedScript(str) {
  2782. return false;
  2783. //return isStringInSupportedScript(str, plugin.isLoaded());
  2784. };
  2785. EvaluationParameters$1.prototype.crossFadingFactor = function crossFadingFactor() {
  2786. if (this.fadeDuration === 0) {
  2787. return 1;
  2788. } else {
  2789. return Math.min((this.now - this.zoomHistory.lastIntegerZoomTime) / this.fadeDuration, 1);
  2790. }
  2791. };
  2792. EvaluationParameters$1.prototype.getCrossfadeParameters = function getCrossfadeParameters() {
  2793. var z = this.zoom;
  2794. var fraction = z - Math.floor(z);
  2795. var t = this.crossFadingFactor();
  2796. return z > this.zoomHistory.lastIntegerZoom ?
  2797. {fromScale: 2, toScale: 1, t: fraction + (1 - fraction) * t} :
  2798. {fromScale: 0.5, toScale: 1, t: 1 - (1 - t) * fraction};
  2799. };
  2800. var EXTENT = 8192;
  2801. function clamp(n, min, max) {
  2802. return Math.min(max, Math.max(min, n));
  2803. }
  2804. // These bounds define the minimum and maximum supported coordinate values.
  2805. // While visible coordinates are within [0, EXTENT], tiles may theoretically
  2806. // contain cordinates within [-Infinity, Infinity]. Our range is limited by the
  2807. // number of bits used to represent the coordinate.
  2808. function createBounds(bits) {
  2809. return {
  2810. min: -1 * Math.pow(2, bits - 1),
  2811. max: Math.pow(2, bits - 1) - 1
  2812. };
  2813. }
  2814. var bounds = createBounds(15);
  2815. /**
  2816. * Loads a geometry from a VectorTileFeature and scales it to the common extent
  2817. * used internally.
  2818. * @param {VectorTileFeature} feature
  2819. * @private
  2820. */
  2821. function loadGeometry(feature) {
  2822. var scale = EXTENT / feature.extent;
  2823. var geometry = feature.loadGeometry();
  2824. for (var r = 0; r < geometry.length; r++) {
  2825. var ring = geometry[r];
  2826. for (var p = 0; p < ring.length; p++) {
  2827. var point = ring[p];
  2828. // round here because mapbox-gl-native uses integers to represent
  2829. // points and we need to do the same to avoid renering differences.
  2830. point.x = Math.round(point.x * scale);
  2831. // 因为绘制到纹理上颠倒了,所以在这里取反
  2832. point.y = EXTENT - Math.round(point.y * scale);
  2833. if (point.x < bounds.min || point.x > bounds.max || point.y < bounds.min || point.y > bounds.max) {
  2834. //warnOnce('Geometry exceeds allowed extent, reduce your vector tile buffer size');
  2835. point.x = clamp(point.x, bounds.min, bounds.max);
  2836. point.y = clamp(point.y, bounds.min, bounds.max);
  2837. }
  2838. }
  2839. }
  2840. return geometry;
  2841. }
  2842. var SegmentVector = function SegmentVector(segments) {
  2843. if (segments === void 0) segments = [];
  2844. this.segments = segments;
  2845. };
  2846. SegmentVector.prototype.prepareSegment = function prepareSegment(numVertices, layoutVertexArray, indexArray, sortKey) {
  2847. var segment = this.segments[this.segments.length - 1];
  2848. if (!segment || segment.vertexLength + numVertices > SegmentVector.MAX_VERTEX_ARRAY_LENGTH || segment.sortKey !== sortKey) {
  2849. segment = ({
  2850. vertexOffset: layoutVertexArray.length,
  2851. primitiveOffset: indexArray.length,
  2852. vertexLength: 0,
  2853. primitiveLength: 0
  2854. } );
  2855. if (sortKey !== undefined) {
  2856. segment.sortKey = sortKey;
  2857. }
  2858. this.segments.push(segment);
  2859. }
  2860. return segment;
  2861. };
  2862. SegmentVector.prototype.get = function get() {
  2863. return this.segments;
  2864. };
  2865. SegmentVector.prototype.destroy = function destroy() {
  2866. for (var i = 0, list = this.segments; i < list.length; i += 1) {
  2867. var segment = list[i];
  2868. for (var k in segment.vaos) {
  2869. segment.vaos[k].destroy();
  2870. }
  2871. }
  2872. };
  2873. SegmentVector.simpleSegment = function simpleSegment(vertexOffset, primitiveOffset, vertexLength, primitiveLength) {
  2874. return new SegmentVector([
  2875. {
  2876. vertexOffset: vertexOffset,
  2877. primitiveOffset: primitiveOffset,
  2878. vertexLength: vertexLength,
  2879. primitiveLength: primitiveLength,
  2880. vaos: {},
  2881. sortKey: 0
  2882. }
  2883. ]);
  2884. };
  2885. /*
  2886. * The maximum size of a vertex array. This limit is imposed by WebGL's 16 bit
  2887. * addressing of vertex buffers.
  2888. * @private
  2889. * @readonly
  2890. */
  2891. SegmentVector.MAX_VERTEX_ARRAY_LENGTH = Math.pow(2, 16) - 1;
  2892. WebWorkerTransfer.register('SegmentVector', SegmentVector);
  2893. /**
  2894. * @private
  2895. */
  2896. var DEFAULT_CAPACITY = 128;
  2897. var RESIZE_MULTIPLIER = 5;
  2898. /**
  2899. * `StructArray` provides an abstraction over `ArrayBuffer` and `TypedArray`
  2900. * making it behave like an array of typed structs.
  2901. *
  2902. * Conceptually, a StructArray is comprised of elements, i.e., instances of its
  2903. * associated struct type. Each particular struct type, together with an
  2904. * alignment size, determines the memory layout of a StructArray whose elements
  2905. * are of that type. Thus, for each such layout that we need, we have
  2906. * a corrseponding StructArrayLayout class, inheriting from StructArray and
  2907. * implementing `emplaceBack()` and `_refreshViews()`.
  2908. *
  2909. * In some cases, where we need to access particular elements of a StructArray,
  2910. * we implement a more specific subclass that inherits from one of the
  2911. * StructArrayLayouts and adds a `get(i): T` accessor that returns a structured
  2912. * object whose properties are proxies into the underlying memory space for the
  2913. * i-th element. This affords the convience of working with (seemingly) plain
  2914. * Javascript objects without the overhead of serializing/deserializing them
  2915. * into ArrayBuffers for efficient web worker transfer.
  2916. *
  2917. * @private
  2918. */
  2919. var StructArray = function StructArray() {
  2920. this.isTransferred = false;
  2921. this.capacity = -1;
  2922. this.resize(0);
  2923. };
  2924. /**
  2925. * Serialize a StructArray instance.Serializes both the raw data and the
  2926. * metadata needed to reconstruct the StructArray base class during
  2927. * deserialization.
  2928. */
  2929. StructArray.serialize = function serialize(array, transferables) {
  2930. if(array.isTransferred){
  2931. console.log("StructArray array.isTransferred.");
  2932. }
  2933. array._trim();
  2934. if (transferables) {
  2935. array.isTransferred = true;
  2936. transferables.push(array.arrayBuffer);
  2937. }
  2938. return {
  2939. length: array.length,
  2940. arrayBuffer: array.arrayBuffer,
  2941. };
  2942. };
  2943. StructArray.deserialize = function deserialize(input) {
  2944. var structArray = Object.create(this.prototype);
  2945. structArray.arrayBuffer = input.arrayBuffer;
  2946. structArray.length = input.length;
  2947. structArray.capacity = input.arrayBuffer.byteLength / structArray.bytesPerElement;
  2948. structArray._refreshViews();
  2949. return structArray;
  2950. };
  2951. /**
  2952. * Resize the array to discard unused capacity.
  2953. */
  2954. StructArray.prototype._trim = function _trim() {
  2955. if (this.length !== this.capacity) {
  2956. this.capacity = this.length;
  2957. this.arrayBuffer = this.arrayBuffer.slice(0, this.length * this.bytesPerElement);
  2958. this._refreshViews();
  2959. }
  2960. };
  2961. /**
  2962. * Resets the the length of the array to 0 without de-allocating capcacity.
  2963. */
  2964. StructArray.prototype.clear = function clear() {
  2965. this.length = 0;
  2966. };
  2967. /**
  2968. * Resize the array.
  2969. * If `n` is greater than the current length then additional elements with undefined values are added.
  2970. * If `n` is less than the current length then the array will be reduced to the first `n` elements.
  2971. * @param {number} n The new size of the array.
  2972. */
  2973. StructArray.prototype.resize = function resize(n) {
  2974. this.reserve(n);
  2975. this.length = n;
  2976. };
  2977. /**
  2978. * Indicate a planned increase in size, so that any necessary allocation may
  2979. * be done once, ahead of time.
  2980. * @param {number} n The expected size of the array.
  2981. */
  2982. StructArray.prototype.reserve = function reserve(n) {
  2983. if (n > this.capacity) {
  2984. this.capacity = Math.max(n, Math.floor(this.capacity * RESIZE_MULTIPLIER), DEFAULT_CAPACITY);
  2985. this.arrayBuffer = new ArrayBuffer(this.capacity * this.bytesPerElement);
  2986. var oldUint8Array = this.uint8;
  2987. this._refreshViews();
  2988. if (oldUint8Array) {
  2989. this.uint8.set(oldUint8Array);
  2990. }
  2991. }
  2992. };
  2993. /**
  2994. * Create TypedArray views for the current ArrayBuffer.
  2995. */
  2996. StructArray.prototype._refreshViews = function _refreshViews() {
  2997. throw new Error('_refreshViews() must be implemented by each concrete StructArray layout');
  2998. };
  2999. /**
  3000. * Implementation of the StructArray layout:
  3001. * [0]: Int16[2]
  3002. * [4]: Uint8[4]
  3003. *
  3004. * @private
  3005. */
  3006. var StructArrayLayout2i4ub8 = /*@__PURE__*/(function (StructArray) {
  3007. function StructArrayLayout2i4ub8() {
  3008. StructArray.apply(this, arguments);
  3009. }
  3010. if (StructArray) StructArrayLayout2i4ub8.__proto__ = StructArray;
  3011. StructArrayLayout2i4ub8.prototype = Object.create(StructArray && StructArray.prototype);
  3012. StructArrayLayout2i4ub8.prototype.constructor = StructArrayLayout2i4ub8;
  3013. StructArrayLayout2i4ub8.prototype._refreshViews = function _refreshViews() {
  3014. this.uint8 = new Uint8Array(this.arrayBuffer);
  3015. this.int16 = new Int16Array(this.arrayBuffer);
  3016. };
  3017. StructArrayLayout2i4ub8.prototype.emplaceBack = function emplaceBack(v0, v1, v2, v3, v4, v5) {
  3018. var i = this.length;
  3019. this.resize(i + 1);
  3020. return this.emplace(i, v0, v1, v2, v3, v4, v5);
  3021. };
  3022. StructArrayLayout2i4ub8.prototype.emplace = function emplace(i, v0, v1, v2, v3, v4, v5) {
  3023. var o2 = i * 4;
  3024. var o1 = i * 8;
  3025. this.int16[o2 + 0] = v0;
  3026. this.int16[o2 + 1] = v1;
  3027. this.uint8[o1 + 4] = v2;
  3028. this.uint8[o1 + 5] = v3;
  3029. this.uint8[o1 + 6] = v4;
  3030. this.uint8[o1 + 7] = v5;
  3031. return i;
  3032. };
  3033. return StructArrayLayout2i4ub8;
  3034. }(StructArray));
  3035. StructArrayLayout2i4ub8.prototype.bytesPerElement = 8;
  3036. WebWorkerTransfer.register('StructArrayLayout2i4ub8', StructArrayLayout2i4ub8);
  3037. /**
  3038. * Implementation of the StructArray layout:
  3039. * [0]: Uint16[3]
  3040. *
  3041. * @private
  3042. */
  3043. var StructArrayLayout3ui6 = /*@__PURE__*/(function (StructArray) {
  3044. function StructArrayLayout3ui6() {
  3045. StructArray.apply(this, arguments);
  3046. }
  3047. if (StructArray) StructArrayLayout3ui6.__proto__ = StructArray;
  3048. StructArrayLayout3ui6.prototype = Object.create(StructArray && StructArray.prototype);
  3049. StructArrayLayout3ui6.prototype.constructor = StructArrayLayout3ui6;
  3050. StructArrayLayout3ui6.prototype._refreshViews = function _refreshViews() {
  3051. this.uint8 = new Uint8Array(this.arrayBuffer);
  3052. this.uint16 = new Uint16Array(this.arrayBuffer);
  3053. };
  3054. StructArrayLayout3ui6.prototype.emplaceBack = function emplaceBack(v0, v1, v2) {
  3055. var i = this.length;
  3056. this.resize(i + 1);
  3057. return this.emplace(i, v0, v1, v2);
  3058. };
  3059. StructArrayLayout3ui6.prototype.emplace = function emplace(i, v0, v1, v2) {
  3060. var o2 = i * 3;
  3061. this.uint16[o2 + 0] = v0;
  3062. this.uint16[o2 + 1] = v1;
  3063. this.uint16[o2 + 2] = v2;
  3064. return i;
  3065. };
  3066. return StructArrayLayout3ui6;
  3067. }(StructArray));
  3068. StructArrayLayout3ui6.prototype.bytesPerElement = 6;
  3069. WebWorkerTransfer.register('StructArrayLayout3ui6', StructArrayLayout3ui6);
  3070. // A transferable data structure that maps feature ids to their indices and buffer offsets
  3071. var FeaturePositionMap = function FeaturePositionMap() {
  3072. this.ids = [];
  3073. this.positions = [];
  3074. this.indexed = false;
  3075. };
  3076. FeaturePositionMap.prototype.add = function add(id, index, start, end) {
  3077. this.ids.push(id);
  3078. this.positions.push(index, start, end);
  3079. };
  3080. FeaturePositionMap.prototype.getPositions = function getPositions(id) {
  3081. // binary search for the first occurrence of id in this.ids;
  3082. // relies on ids/positions being sorted by id, which happens in serialization
  3083. var i = 0;
  3084. var j = this.ids.length - 1;
  3085. while (i < j) {
  3086. var m = (i + j) >> 1;
  3087. if (this.ids[m] >= id) {
  3088. j = m;
  3089. } else {
  3090. i = m + 1;
  3091. }
  3092. }
  3093. var positions = [];
  3094. while (this.ids[i] === id) {
  3095. var index = this.positions[3 * i];
  3096. var start = this.positions[3 * i + 1];
  3097. var end = this.positions[3 * i + 2];
  3098. positions.push({index: index, start: start, end: end});
  3099. i++;
  3100. }
  3101. return positions;
  3102. };
  3103. FeaturePositionMap.serialize = function serialize(map, transferables) {
  3104. var ids = new Float64Array(map.ids);
  3105. var positions = new Uint32Array(map.positions);
  3106. sort(ids, positions, 0, ids.length - 1);
  3107. if (transferables) {
  3108. transferables.push(ids.buffer, positions.buffer);
  3109. }
  3110. return {ids: ids, positions: positions};
  3111. };
  3112. FeaturePositionMap.deserialize = function deserialize(obj) {
  3113. var map = new FeaturePositionMap();
  3114. // after transferring, we only use these arrays statically (no pushes),
  3115. // so TypedArray vs Array distinction that flow points out doesn't matter
  3116. map.ids = (obj.ids );
  3117. map.positions = (obj.positions );
  3118. map.indexed = true;
  3119. return map;
  3120. };
  3121. // custom quicksort that sorts ids, indices and offsets together (by ids)
  3122. function sort(ids, positions, left, right) {
  3123. if (left >= right) {
  3124. return;
  3125. }
  3126. var pivot = ids[(left + right) >> 1];
  3127. var i = left - 1;
  3128. var j = right + 1;
  3129. while (true) {
  3130. do {
  3131. i++;
  3132. } while (ids[i] < pivot);
  3133. do {
  3134. j--;
  3135. } while (ids[j] > pivot);
  3136. if (i >= j) {
  3137. break;
  3138. }
  3139. swap(ids, i, j);
  3140. swap(positions, 3 * i, 3 * j);
  3141. swap(positions, 3 * i + 1, 3 * j + 1);
  3142. swap(positions, 3 * i + 2, 3 * j + 2);
  3143. }
  3144. sort(ids, positions, left, j);
  3145. sort(ids, positions, j + 1, right);
  3146. }
  3147. function swap(arr, i, j) {
  3148. var tmp = arr[i];
  3149. arr[i] = arr[j];
  3150. arr[j] = tmp;
  3151. }
  3152. WebWorkerTransfer.register('FeaturePositionMap', FeaturePositionMap);
  3153. /**
  3154. * `PossiblyEvaluatedPropertyValue` is used for data-driven paint and layout property values. It holds a
  3155. * `PossiblyEvaluatedValue` and the `GlobalProperties` that were used to generate it. You're not allowed to supply
  3156. * a different set of `GlobalProperties` when performing the final evaluation because they would be ignored in the
  3157. * case where the input value was a constant or camera function.
  3158. *
  3159. * @private
  3160. */
  3161. var PossiblyEvaluatedPropertyValue$1 = function PossiblyEvaluatedPropertyValue(property, value, parameters) {
  3162. this.property = property;
  3163. this.value = value;
  3164. this.parameters = parameters;
  3165. };
  3166. PossiblyEvaluatedPropertyValue$1.prototype.isConstant = function isConstant() {
  3167. return this.value.kind === 'constant';
  3168. };
  3169. PossiblyEvaluatedPropertyValue$1.prototype.constantOr = function constantOr(value) {
  3170. if (this.value.kind === 'constant') {
  3171. return this.value.value;
  3172. } else {
  3173. return value;
  3174. }
  3175. };
  3176. PossiblyEvaluatedPropertyValue$1.prototype.evaluate = function evaluate(feature, featureState, availableImages) {
  3177. return this.property.evaluate(this.value, this.parameters, feature, featureState, availableImages);
  3178. };
  3179. function Supports() {
  3180. }
  3181. Supports.supportsPropertyExpression = function (spec) {
  3182. return spec['property-type'] === 'data-driven' || spec['property-type'] === 'cross-faded-data-driven';
  3183. };
  3184. Supports.supportsZoomExpression = function (spec) {
  3185. return !!spec.expression && spec.expression.parameters.indexOf('zoom') > -1;
  3186. };
  3187. Supports.supportsInterpolation = function (spec) {
  3188. return !!spec.expression && spec.expression.interpolated;
  3189. };
  3190. var UniformType = {};
  3191. var Uniform = function Uniform(context, location) {
  3192. this.gl = context.gl;
  3193. this.location = location;
  3194. };
  3195. UniformType.Uniform1i = /*@__PURE__*/(function (Uniform) {
  3196. function Uniform1i(context, location) {
  3197. Uniform.call(this, context, location);
  3198. this.current = 0;
  3199. }
  3200. if (Uniform) Uniform1i.__proto__ = Uniform;
  3201. Uniform1i.prototype = Object.create(Uniform && Uniform.prototype);
  3202. Uniform1i.prototype.constructor = Uniform1i;
  3203. Uniform1i.prototype.set = function set(v) {
  3204. if (this.current !== v) {
  3205. this.current = v;
  3206. this.gl.uniform1i(this.location, v);
  3207. }
  3208. };
  3209. return Uniform1i;
  3210. }(Uniform));
  3211. UniformType.Uniform1f = /*@__PURE__*/(function (Uniform) {
  3212. function Uniform1f(context, location) {
  3213. Uniform.call(this, context, location);
  3214. this.current = 0;
  3215. }
  3216. if (Uniform) Uniform1f.__proto__ = Uniform;
  3217. Uniform1f.prototype = Object.create(Uniform && Uniform.prototype);
  3218. Uniform1f.prototype.constructor = Uniform1f;
  3219. Uniform1f.prototype.set = function set(v) {
  3220. if (this.current !== v) {
  3221. this.current = v;
  3222. this.gl.uniform1f(this.location, v);
  3223. }
  3224. };
  3225. return Uniform1f;
  3226. }(Uniform));
  3227. UniformType.Uniform2f = /*@__PURE__*/(function (Uniform) {
  3228. function Uniform2f(context, location) {
  3229. Uniform.call(this, context, location);
  3230. this.current = [0, 0];
  3231. }
  3232. if (Uniform) Uniform2f.__proto__ = Uniform;
  3233. Uniform2f.prototype = Object.create(Uniform && Uniform.prototype);
  3234. Uniform2f.prototype.constructor = Uniform2f;
  3235. Uniform2f.prototype.set = function set(v) {
  3236. if (v[0] !== this.current[0] || v[1] !== this.current[1]) {
  3237. this.current = v;
  3238. this.gl.uniform2f(this.location, v[0], v[1]);
  3239. }
  3240. };
  3241. return Uniform2f;
  3242. }(Uniform));
  3243. UniformType.Uniform3f = /*@__PURE__*/(function (Uniform) {
  3244. function Uniform3f(context, location) {
  3245. Uniform.call(this, context, location);
  3246. this.current = [0, 0, 0];
  3247. }
  3248. if (Uniform) Uniform3f.__proto__ = Uniform;
  3249. Uniform3f.prototype = Object.create(Uniform && Uniform.prototype);
  3250. Uniform3f.prototype.constructor = Uniform3f;
  3251. Uniform3f.prototype.set = function set(v) {
  3252. if (v[0] !== this.current[0] || v[1] !== this.current[1] || v[2] !== this.current[2]) {
  3253. this.current = v;
  3254. this.gl.uniform3f(this.location, v[0], v[1], v[2]);
  3255. }
  3256. };
  3257. return Uniform3f;
  3258. }(Uniform));
  3259. UniformType.Uniform4f = /*@__PURE__*/(function (Uniform) {
  3260. function Uniform4f(context, location) {
  3261. Uniform.call(this, context, location);
  3262. this.current = [0, 0, 0, 0];
  3263. }
  3264. if (Uniform) Uniform4f.__proto__ = Uniform;
  3265. Uniform4f.prototype = Object.create(Uniform && Uniform.prototype);
  3266. Uniform4f.prototype.constructor = Uniform4f;
  3267. Uniform4f.prototype.set = function set(v) {
  3268. if (v[0] !== this.current[0] || v[1] !== this.current[1] ||
  3269. v[2] !== this.current[2] || v[3] !== this.current[3]) {
  3270. this.current = v;
  3271. this.gl.uniform4f(this.location, v[0], v[1], v[2], v[3]);
  3272. }
  3273. };
  3274. return Uniform4f;
  3275. }(Uniform));
  3276. UniformType.UniformColor = /*@__PURE__*/(function (Uniform) {
  3277. function UniformColor(context, location) {
  3278. Uniform.call(this, context, location);
  3279. this.current = Color$1.transparent;
  3280. }
  3281. if (Uniform) UniformColor.__proto__ = Uniform;
  3282. UniformColor.prototype = Object.create(Uniform && Uniform.prototype);
  3283. UniformColor.prototype.constructor = UniformColor;
  3284. UniformColor.prototype.set = function set(v) {
  3285. if (v.r !== this.current.r || v.g !== this.current.g ||
  3286. v.b !== this.current.b || v.a !== this.current.a) {
  3287. this.current = v;
  3288. this.gl.uniform4f(this.location, v.r, v.g, v.b, v.a);
  3289. }
  3290. };
  3291. return UniformColor;
  3292. }(Uniform));
  3293. var emptyMat4 = new Float32Array(16);
  3294. UniformType.UniformMatrix4f = /*@__PURE__*/(function (Uniform) {
  3295. function UniformMatrix4f(context, location) {
  3296. Uniform.call(this, context, location);
  3297. this.current = emptyMat4;
  3298. }
  3299. if (Uniform) UniformMatrix4f.__proto__ = Uniform;
  3300. UniformMatrix4f.prototype = Object.create(Uniform && Uniform.prototype);
  3301. UniformMatrix4f.prototype.constructor = UniformMatrix4f;
  3302. UniformMatrix4f.prototype.set = function set(v) {
  3303. this.gl.uniformMatrix4fv(this.location, false, v);
  3304. // The vast majority of matrix comparisons that will trip this set
  3305. // happen at i=12 or i=0, so we check those first to avoid lots of
  3306. // unnecessary iteration:
  3307. // if (v[12] !== this.current[12] || v[0] !== this.current[0]) {
  3308. // this.current = v;
  3309. // this.gl.uniformMatrix4fv(this.location, false, v);
  3310. // return;
  3311. // }
  3312. // for (var i = 1; i < 16; i++) {
  3313. // if (v[i] !== this.current[i]) {
  3314. // this.current = v;
  3315. // this.gl.uniformMatrix4fv(this.location, false, v);
  3316. // break;
  3317. // }
  3318. // }
  3319. };
  3320. return UniformMatrix4f;
  3321. }(Uniform));
  3322. /**
  3323. * Implementation of the StructArray layout:
  3324. * [0]: Uint16[8]
  3325. *
  3326. * @private
  3327. */
  3328. var StructArrayLayout8ui16 = /*@__PURE__*/(function (StructArray) {
  3329. function StructArrayLayout8ui16() {
  3330. StructArray.apply(this, arguments);
  3331. }
  3332. if (StructArray) StructArrayLayout8ui16.__proto__ = StructArray;
  3333. StructArrayLayout8ui16.prototype = Object.create(StructArray && StructArray.prototype);
  3334. StructArrayLayout8ui16.prototype.constructor = StructArrayLayout8ui16;
  3335. StructArrayLayout8ui16.prototype._refreshViews = function _refreshViews() {
  3336. this.uint8 = new Uint8Array(this.arrayBuffer);
  3337. this.uint16 = new Uint16Array(this.arrayBuffer);
  3338. };
  3339. StructArrayLayout8ui16.prototype.emplaceBack = function emplaceBack(v0, v1, v2, v3, v4, v5, v6, v7) {
  3340. var i = this.length;
  3341. this.resize(i + 1);
  3342. return this.emplace(i, v0, v1, v2, v3, v4, v5, v6, v7);
  3343. };
  3344. StructArrayLayout8ui16.prototype.emplace = function emplace(i, v0, v1, v2, v3, v4, v5, v6, v7) {
  3345. var o2 = i * 8;
  3346. this.uint16[o2 + 0] = v0;
  3347. this.uint16[o2 + 1] = v1;
  3348. this.uint16[o2 + 2] = v2;
  3349. this.uint16[o2 + 3] = v3;
  3350. this.uint16[o2 + 4] = v4;
  3351. this.uint16[o2 + 5] = v5;
  3352. this.uint16[o2 + 6] = v6;
  3353. this.uint16[o2 + 7] = v7;
  3354. return i;
  3355. };
  3356. return StructArrayLayout8ui16;
  3357. }(StructArray));
  3358. StructArrayLayout8ui16.prototype.bytesPerElement = 16;
  3359. WebWorkerTransfer.register('StructArrayLayout8ui16', StructArrayLayout8ui16);
  3360. /**
  3361. * Implementation of the StructArray layout:
  3362. * [0]: Float32[2]
  3363. *
  3364. * @private
  3365. */
  3366. var StructArrayLayout2f8 = /*@__PURE__*/(function (StructArray) {
  3367. function StructArrayLayout2f8() {
  3368. StructArray.apply(this, arguments);
  3369. }
  3370. if (StructArray) StructArrayLayout2f8.__proto__ = StructArray;
  3371. StructArrayLayout2f8.prototype = Object.create(StructArray && StructArray.prototype);
  3372. StructArrayLayout2f8.prototype.constructor = StructArrayLayout2f8;
  3373. StructArrayLayout2f8.prototype._refreshViews = function _refreshViews() {
  3374. this.uint8 = new Uint8Array(this.arrayBuffer);
  3375. this.float32 = new Float32Array(this.arrayBuffer);
  3376. };
  3377. StructArrayLayout2f8.prototype.emplaceBack = function emplaceBack(v0, v1) {
  3378. var i = this.length;
  3379. this.resize(i + 1);
  3380. return this.emplace(i, v0, v1);
  3381. };
  3382. StructArrayLayout2f8.prototype.emplace = function emplace(i, v0, v1) {
  3383. var o4 = i * 2;
  3384. this.float32[o4 + 0] = v0;
  3385. this.float32[o4 + 1] = v1;
  3386. return i;
  3387. };
  3388. return StructArrayLayout2f8;
  3389. }(StructArray));
  3390. StructArrayLayout2f8.prototype.bytesPerElement = 8;
  3391. WebWorkerTransfer.register('StructArrayLayout2f8', StructArrayLayout2f8);
  3392. /**
  3393. * Implementation of the StructArray layout:
  3394. * [0]: Float32[4]
  3395. *
  3396. * @private
  3397. */
  3398. var StructArrayLayout4f16 = /*@__PURE__*/(function (StructArray) {
  3399. function StructArrayLayout4f16() {
  3400. StructArray.apply(this, arguments);
  3401. }
  3402. if (StructArray) StructArrayLayout4f16.__proto__ = StructArray;
  3403. StructArrayLayout4f16.prototype = Object.create(StructArray && StructArray.prototype);
  3404. StructArrayLayout4f16.prototype.constructor = StructArrayLayout4f16;
  3405. StructArrayLayout4f16.prototype._refreshViews = function _refreshViews() {
  3406. this.uint8 = new Uint8Array(this.arrayBuffer);
  3407. this.float32 = new Float32Array(this.arrayBuffer);
  3408. };
  3409. StructArrayLayout4f16.prototype.emplaceBack = function emplaceBack(v0, v1, v2, v3) {
  3410. var i = this.length;
  3411. this.resize(i + 1);
  3412. return this.emplace(i, v0, v1, v2, v3);
  3413. };
  3414. StructArrayLayout4f16.prototype.emplace = function emplace(i, v0, v1, v2, v3) {
  3415. var o4 = i * 4;
  3416. this.float32[o4 + 0] = v0;
  3417. this.float32[o4 + 1] = v1;
  3418. this.float32[o4 + 2] = v2;
  3419. this.float32[o4 + 3] = v3;
  3420. return i;
  3421. };
  3422. return StructArrayLayout4f16;
  3423. }(StructArray));
  3424. StructArrayLayout4f16.prototype.bytesPerElement = 16;
  3425. WebWorkerTransfer.register('StructArrayLayout4f16', StructArrayLayout4f16);
  3426. /**
  3427. * Implementation of the StructArray layout:
  3428. * [0]: Float32[1]
  3429. *
  3430. * @private
  3431. */
  3432. var StructArrayLayout1f4 = /*@__PURE__*/(function (StructArray) {
  3433. function StructArrayLayout1f4() {
  3434. StructArray.apply(this, arguments);
  3435. }
  3436. if (StructArray) StructArrayLayout1f4.__proto__ = StructArray;
  3437. StructArrayLayout1f4.prototype = Object.create(StructArray && StructArray.prototype);
  3438. StructArrayLayout1f4.prototype.constructor = StructArrayLayout1f4;
  3439. StructArrayLayout1f4.prototype._refreshViews = function _refreshViews() {
  3440. this.uint8 = new Uint8Array(this.arrayBuffer);
  3441. this.float32 = new Float32Array(this.arrayBuffer);
  3442. };
  3443. StructArrayLayout1f4.prototype.emplaceBack = function emplaceBack(v0) {
  3444. var i = this.length;
  3445. this.resize(i + 1);
  3446. return this.emplace(i, v0);
  3447. };
  3448. StructArrayLayout1f4.prototype.emplace = function emplace(i, v0) {
  3449. var o4 = i * 1;
  3450. this.float32[o4 + 0] = v0;
  3451. return i;
  3452. };
  3453. return StructArrayLayout1f4;
  3454. }(StructArray));
  3455. StructArrayLayout1f4.prototype.bytesPerElement = 4;
  3456. WebWorkerTransfer.register('StructArrayLayout1f4', StructArrayLayout1f4);
  3457. function clamp$1(n, min, max) {
  3458. return Math.min(max, Math.max(min, n));
  3459. }
  3460. function packUint8ToFloat(a, b) {
  3461. // coerce a and b to 8-bit ints
  3462. a = clamp$1(Math.floor(a), 0, 255);
  3463. b = clamp$1(Math.floor(b), 0, 255);
  3464. return 256 * a + b;
  3465. }
  3466. function packColor(color) {
  3467. return [
  3468. packUint8ToFloat(255 * color.r, 255 * color.g),
  3469. packUint8ToFloat(255 * color.b, 255 * color.a)
  3470. ];
  3471. }
  3472. var ConstantBinder = function ConstantBinder(value, names, type) {
  3473. this.value = value;
  3474. this.names = names;
  3475. this.uniformNames = this.names.map(function (name) {
  3476. return ("u_" + name);
  3477. });
  3478. this.type = type;
  3479. this.maxValue = -Infinity;
  3480. };
  3481. ConstantBinder.prototype.defines = function defines() {
  3482. return this.names.map(function (name) {
  3483. return ("#define HAS_UNIFORM_u_" + name);
  3484. });
  3485. };
  3486. ConstantBinder.prototype.setConstantPatternPositions = function setConstantPatternPositions() {
  3487. };
  3488. ConstantBinder.prototype.populatePaintArray = function populatePaintArray() {
  3489. };
  3490. ConstantBinder.prototype.updatePaintArray = function updatePaintArray() {
  3491. };
  3492. ConstantBinder.prototype.upload = function upload() {
  3493. };
  3494. ConstantBinder.prototype.destroy = function destroy() {
  3495. };
  3496. ConstantBinder.prototype.setUniforms = function setUniforms(context, uniform, globals, currentValue) {
  3497. uniform.set(currentValue.constantOr(this.value));
  3498. };
  3499. ConstantBinder.prototype.getBinding = function getBinding(context, location) {
  3500. return (this.type === 'color') ?
  3501. new UniformType.UniformColor(context, location) :
  3502. new UniformType.Uniform1f(context, location);
  3503. };
  3504. ConstantBinder.serialize = function serialize$1(binder) {
  3505. var value = binder.value;
  3506. var names = binder.names;
  3507. var type = binder.type;
  3508. return {value: WebWorkerTransfer.serialize(value), names: names, type: type};
  3509. };
  3510. ConstantBinder.deserialize = function deserialize$1(serialized) {
  3511. var value = serialized.value;
  3512. var names = serialized.names;
  3513. var type = serialized.type;
  3514. return new ConstantBinder(WebWorkerTransfer.deserialize(value), names, type);
  3515. };
  3516. var CrossFadedConstantBinder = function CrossFadedConstantBinder(value, names, type) {
  3517. this.value = value;
  3518. this.names = names;
  3519. this.uniformNames = this.names.map(function (name) {
  3520. return ("u_" + name);
  3521. });
  3522. this.type = type;
  3523. this.maxValue = -Infinity;
  3524. this.patternPositions = {patternTo: null, patternFrom: null};
  3525. };
  3526. CrossFadedConstantBinder.prototype.defines = function defines() {
  3527. return this.names.map(function (name) {
  3528. return ("#define HAS_UNIFORM_u_" + name);
  3529. });
  3530. };
  3531. CrossFadedConstantBinder.prototype.populatePaintArray = function populatePaintArray() {
  3532. };
  3533. CrossFadedConstantBinder.prototype.updatePaintArray = function updatePaintArray() {
  3534. };
  3535. CrossFadedConstantBinder.prototype.upload = function upload() {
  3536. };
  3537. CrossFadedConstantBinder.prototype.destroy = function destroy() {
  3538. };
  3539. CrossFadedConstantBinder.prototype.setConstantPatternPositions = function setConstantPatternPositions(posTo, posFrom) {
  3540. this.patternPositions.patternTo = posTo.tlbr;
  3541. this.patternPositions.patternFrom = posFrom.tlbr;
  3542. };
  3543. CrossFadedConstantBinder.prototype.setUniforms = function setUniforms(context, uniform, globals, currentValue, uniformName) {
  3544. var pos = this.patternPositions;
  3545. if (uniformName === "u_pattern_to" && pos.patternTo) {
  3546. uniform.set(pos.patternTo);
  3547. }
  3548. if (uniformName === "u_pattern_from" && pos.patternFrom) {
  3549. uniform.set(pos.patternFrom);
  3550. }
  3551. };
  3552. CrossFadedConstantBinder.prototype.getBinding = function getBinding(context, location) {
  3553. return new UniformType.Uniform4f(context, location);
  3554. };
  3555. var SourceExpressionBinder = function SourceExpressionBinder(expression, names, type, PaintVertexArray) {
  3556. this.expression = expression;
  3557. this.names = names;
  3558. this.type = type;
  3559. this.uniformNames = this.names.map(function (name) {
  3560. return ("a_" + name);
  3561. });
  3562. this.maxValue = -Infinity;
  3563. this.paintVertexAttributes = names.map(function (name) {
  3564. return ({
  3565. name: ("a_" + name),
  3566. type: 'Float32',
  3567. components: type === 'color' ? 2 : 1,
  3568. offset: 0
  3569. });
  3570. }
  3571. );
  3572. this.paintVertexArray = new PaintVertexArray();
  3573. };
  3574. SourceExpressionBinder.prototype.defines = function defines() {
  3575. return [];
  3576. };
  3577. SourceExpressionBinder.prototype.setConstantPatternPositions = function setConstantPatternPositions() {
  3578. };
  3579. SourceExpressionBinder.prototype.populatePaintArray = function populatePaintArray(newLength, feature, imagePositions, formattedSection) {
  3580. var paintArray = this.paintVertexArray;
  3581. var start = paintArray.length;
  3582. paintArray.reserve(newLength);
  3583. var value = this.expression.evaluate(new EvaluationParameters(0), feature, {}, [], formattedSection);
  3584. if (this.type === 'color') {
  3585. var color = packColor(value);
  3586. for (var i = start; i < newLength; i++) {
  3587. paintArray.emplaceBack(color[0], color[1]);
  3588. }
  3589. } else {
  3590. for (var i$1 = start; i$1 < newLength; i$1++) {
  3591. paintArray.emplaceBack(value);
  3592. }
  3593. this.maxValue = Math.max(this.maxValue, value);
  3594. }
  3595. };
  3596. SourceExpressionBinder.prototype.updatePaintArray = function updatePaintArray(start, end, feature, featureState) {
  3597. var paintArray = this.paintVertexArray;
  3598. var value = this.expression.evaluate({zoom: 0}, feature, featureState);
  3599. if (this.type === 'color') {
  3600. var color = packColor(value);
  3601. for (var i = start; i < end; i++) {
  3602. paintArray.emplace(i, color[0], color[1]);
  3603. }
  3604. } else {
  3605. for (var i$1 = start; i$1 < end; i$1++) {
  3606. paintArray.emplace(i$1, value);
  3607. }
  3608. this.maxValue = Math.max(this.maxValue, value);
  3609. }
  3610. };
  3611. SourceExpressionBinder.prototype.upload = function upload(context) {
  3612. if (this.paintVertexArray && this.paintVertexArray.arrayBuffer) {
  3613. if (this.paintVertexBuffer && this.paintVertexBuffer.buffer) {
  3614. this.paintVertexBuffer.updateData(this.paintVertexArray);
  3615. } else {
  3616. this.paintVertexBuffer = context.createVertexBuffer(this.paintVertexArray, this.paintVertexAttributes, this.expression.isStateDependent);
  3617. }
  3618. }
  3619. };
  3620. SourceExpressionBinder.prototype.destroy = function destroy() {
  3621. if (this.paintVertexBuffer) {
  3622. this.paintVertexBuffer.destroy();
  3623. }
  3624. };
  3625. SourceExpressionBinder.prototype.setUniforms = function setUniforms(context, uniform) {
  3626. uniform.set(0);
  3627. };
  3628. SourceExpressionBinder.prototype.getBinding = function getBinding(context, location) {
  3629. return new UniformType.Uniform1f(context, location);
  3630. };
  3631. var CompositeExpressionBinder = function CompositeExpressionBinder(expression, names, type, useIntegerZoom, zoom, layout) {
  3632. this.expression = expression;
  3633. this.names = names;
  3634. this.uniformNames = this.names.map(function (name) {
  3635. return ("u_" + name + "_t");
  3636. });
  3637. this.type = type;
  3638. this.useIntegerZoom = useIntegerZoom;
  3639. this.zoom = zoom;
  3640. this.maxValue = -Infinity;
  3641. var PaintVertexArray = layout;
  3642. this.paintVertexAttributes = names.map(function (name) {
  3643. return {
  3644. name: ("a_" + name),
  3645. type: 'Float32',
  3646. components: type === 'color' ? 4 : 2,
  3647. offset: 0
  3648. };
  3649. });
  3650. this.paintVertexArray = new PaintVertexArray();
  3651. };
  3652. CompositeExpressionBinder.prototype.defines = function defines() {
  3653. return [];
  3654. };
  3655. CompositeExpressionBinder.prototype.setConstantPatternPositions = function setConstantPatternPositions() {
  3656. };
  3657. CompositeExpressionBinder.prototype.populatePaintArray = function populatePaintArray(newLength, feature, imagePositions, formattedSection) {
  3658. var paintArray = this.paintVertexArray;
  3659. var start = paintArray.length;
  3660. paintArray.reserve(newLength);
  3661. var min = this.expression.evaluate(new EvaluationParameters(this.zoom), feature, {}, [], formattedSection);
  3662. var max = this.expression.evaluate(new EvaluationParameters(this.zoom + 1), feature, {}, [], formattedSection);
  3663. if (this.type === 'color') {
  3664. var minColor = packColor(min);
  3665. var maxColor = packColor(max);
  3666. for (var i = start; i < newLength; i++) {
  3667. paintArray.emplaceBack(minColor[0], minColor[1], maxColor[0], maxColor[1]);
  3668. }
  3669. } else {
  3670. for (var i$1 = start; i$1 < newLength; i$1++) {
  3671. paintArray.emplaceBack(min, max);
  3672. }
  3673. this.maxValue = Math.max(this.maxValue, min, max);
  3674. }
  3675. };
  3676. CompositeExpressionBinder.prototype.updatePaintArray = function updatePaintArray(start, end, feature, featureState) {
  3677. var paintArray = this.paintVertexArray;
  3678. var min = this.expression.evaluate({zoom: this.zoom}, feature, featureState);
  3679. var max = this.expression.evaluate({zoom: this.zoom + 1}, feature, featureState);
  3680. if (this.type === 'color') {
  3681. var minColor = packColor(min);
  3682. var maxColor = packColor(max);
  3683. for (var i = start; i < end; i++) {
  3684. paintArray.emplace(i, minColor[0], minColor[1], maxColor[0], maxColor[1]);
  3685. }
  3686. } else {
  3687. for (var i$1 = start; i$1 < end; i$1++) {
  3688. paintArray.emplace(i$1, min, max);
  3689. }
  3690. this.maxValue = Math.max(this.maxValue, min, max);
  3691. }
  3692. };
  3693. CompositeExpressionBinder.prototype.upload = function upload(context) {
  3694. if (this.paintVertexArray && this.paintVertexArray.arrayBuffer) {
  3695. if (this.paintVertexBuffer && this.paintVertexBuffer.buffer) {
  3696. this.paintVertexBuffer.updateData(this.paintVertexArray);
  3697. } else {
  3698. this.paintVertexBuffer = context.createVertexBuffer(this.paintVertexArray, this.paintVertexAttributes, this.expression.isStateDependent);
  3699. }
  3700. }
  3701. };
  3702. CompositeExpressionBinder.prototype.destroy = function destroy() {
  3703. if (this.paintVertexBuffer) {
  3704. this.paintVertexBuffer.destroy();
  3705. }
  3706. };
  3707. CompositeExpressionBinder.prototype.interpolationFactor = function interpolationFactor(currentZoom) {
  3708. if (this.useIntegerZoom) {
  3709. currentZoom = Math.floor(currentZoom);
  3710. }
  3711. return clamp$1(this.expression.interpolationFactor(currentZoom, this.zoom, this.zoom + 1), 0, 1);
  3712. };
  3713. CompositeExpressionBinder.prototype.setUniforms = function setUniforms(context, uniform, globals) {
  3714. uniform.set(this.interpolationFactor(globals.zoom));
  3715. };
  3716. CompositeExpressionBinder.prototype.getBinding = function getBinding(context, location) {
  3717. return new UniformType.Uniform1f(context, location);
  3718. };
  3719. var CrossFadedCompositeBinder = function CrossFadedCompositeBinder(expression, names, type, useIntegerZoom, zoom, PaintVertexArray, layerId) {
  3720. this.expression = expression;
  3721. this.names = names;
  3722. this.type = type;
  3723. this.uniformNames = this.names.map(function (name) {
  3724. return ("u_" + name + "_t");
  3725. });
  3726. this.useIntegerZoom = useIntegerZoom;
  3727. this.zoom = zoom;
  3728. this.maxValue = -Infinity;
  3729. this.layerId = layerId;
  3730. this.paintVertexAttributes = names.map(function (name) {
  3731. return ({
  3732. name: ("a_" + name),
  3733. type: 'Uint16',
  3734. components: 4,
  3735. offset: 0
  3736. });
  3737. }
  3738. );
  3739. this.zoomInPaintVertexArray = new PaintVertexArray();
  3740. this.zoomOutPaintVertexArray = new PaintVertexArray();
  3741. };
  3742. CrossFadedCompositeBinder.prototype.defines = function defines() {
  3743. return [];
  3744. };
  3745. CrossFadedCompositeBinder.prototype.setConstantPatternPositions = function setConstantPatternPositions() {
  3746. };
  3747. CrossFadedCompositeBinder.prototype.populatePaintArray = function populatePaintArray(length, feature, imagePositions) {
  3748. // We populate two paint arrays because, for cross-faded properties, we don't know which direction
  3749. // we're cross-fading to at layout time. In order to keep vertex attributes to a minimum and not pass
  3750. // unnecessary vertex data to the shaders, we determine which to upload at draw time.
  3751. var zoomInArray = this.zoomInPaintVertexArray;
  3752. var zoomOutArray = this.zoomOutPaintVertexArray;
  3753. var ref = this;
  3754. var layerId = ref.layerId;
  3755. var start = zoomInArray.length;
  3756. zoomInArray.reserve(length);
  3757. zoomOutArray.reserve(length);
  3758. if (imagePositions && feature.patterns && feature.patterns[layerId]) {
  3759. var ref$1 = feature.patterns[layerId];
  3760. var min = ref$1.min;
  3761. var mid = ref$1.mid;
  3762. var max = ref$1.max;
  3763. var imageMin = imagePositions[min];
  3764. var imageMid = imagePositions[mid];
  3765. var imageMax = imagePositions[max];
  3766. if (!imageMin || !imageMid || !imageMax) {
  3767. return;
  3768. }
  3769. for (var i = start; i < length; i++) {
  3770. zoomInArray.emplaceBack(
  3771. imageMid.tl[0], imageMid.tl[1], imageMid.br[0], imageMid.br[1],
  3772. imageMin.tl[0], imageMin.tl[1], imageMin.br[0], imageMin.br[1]
  3773. );
  3774. zoomOutArray.emplaceBack(
  3775. imageMid.tl[0], imageMid.tl[1], imageMid.br[0], imageMid.br[1],
  3776. imageMax.tl[0], imageMax.tl[1], imageMax.br[0], imageMax.br[1]
  3777. );
  3778. }
  3779. }
  3780. };
  3781. CrossFadedCompositeBinder.prototype.updatePaintArray = function updatePaintArray(start, end, feature, featureState, imagePositions) {
  3782. // We populate two paint arrays because, for cross-faded properties, we don't know which direction
  3783. // we're cross-fading to at layout time. In order to keep vertex attributes to a minimum and not pass
  3784. // unnecessary vertex data to the shaders, we determine which to upload at draw time.
  3785. var zoomInArray = this.zoomInPaintVertexArray;
  3786. var zoomOutArray = this.zoomOutPaintVertexArray;
  3787. var ref = this;
  3788. var layerId = ref.layerId;
  3789. if (imagePositions && feature.patterns && feature.patterns[layerId]) {
  3790. var ref$1 = feature.patterns[layerId];
  3791. var min = ref$1.min;
  3792. var mid = ref$1.mid;
  3793. var max = ref$1.max;
  3794. var imageMin = imagePositions[min];
  3795. var imageMid = imagePositions[mid];
  3796. var imageMax = imagePositions[max];
  3797. if (!imageMin || !imageMid || !imageMax) {
  3798. return;
  3799. }
  3800. for (var i = start; i < end; i++) {
  3801. zoomInArray.emplace(i,
  3802. imageMid.tl[0], imageMid.tl[1], imageMid.br[0], imageMid.br[1],
  3803. imageMin.tl[0], imageMin.tl[1], imageMin.br[0], imageMin.br[1]
  3804. );
  3805. zoomOutArray.emplace(i,
  3806. imageMid.tl[0], imageMid.tl[1], imageMid.br[0], imageMid.br[1],
  3807. imageMax.tl[0], imageMax.tl[1], imageMax.br[0], imageMax.br[1]
  3808. );
  3809. }
  3810. }
  3811. };
  3812. CrossFadedCompositeBinder.prototype.upload = function upload(context) {
  3813. if (this.zoomInPaintVertexArray && this.zoomInPaintVertexArray.arrayBuffer && this.zoomOutPaintVertexArray && this.zoomOutPaintVertexArray.arrayBuffer) {
  3814. this.zoomInPaintVertexBuffer = context.createVertexBuffer(this.zoomInPaintVertexArray, this.paintVertexAttributes, this.expression.isStateDependent);
  3815. this.zoomOutPaintVertexBuffer = context.createVertexBuffer(this.zoomOutPaintVertexArray, this.paintVertexAttributes, this.expression.isStateDependent);
  3816. }
  3817. };
  3818. CrossFadedCompositeBinder.prototype.destroy = function destroy() {
  3819. if (this.zoomOutPaintVertexBuffer) {
  3820. this.zoomOutPaintVertexBuffer.destroy();
  3821. }
  3822. if (this.zoomInPaintVertexBuffer) {
  3823. this.zoomInPaintVertexBuffer.destroy();
  3824. }
  3825. };
  3826. CrossFadedCompositeBinder.prototype.setUniforms = function setUniforms(context, uniform) {
  3827. uniform.set(0);
  3828. };
  3829. CrossFadedCompositeBinder.prototype.getBinding = function getBinding(context, location) {
  3830. return new Uniform1f(context, location);
  3831. };
  3832. /**
  3833. * ProgramConfiguration contains the logic for binding style layer properties and tile
  3834. * layer feature data into GL program uniforms and vertex attributes.
  3835. *
  3836. * Non-data-driven property values are bound to shader uniforms. Data-driven property
  3837. * values are bound to vertex attributes. In order to support a uniform GLSL syntax over
  3838. * both, [Mapbox GL Shaders](https://github.com/mapbox/mapbox-gl-shaders) defines a `#pragma`
  3839. * abstraction, which ProgramConfiguration is responsible for implementing. At runtime,
  3840. * it examines the attributes of a particular layer, combines this with fixed knowledge
  3841. * about how layers of the particular type are implemented, and determines which uniforms
  3842. * and vertex attributes will be required. It can then substitute the appropriate text
  3843. * into the shader source code, create and link a program, and bind the uniforms and
  3844. * vertex attributes in preparation for drawing.
  3845. *
  3846. * When a vector tile is parsed, this same configuration information is used to
  3847. * populate the attribute buffers needed for data-driven styling using the zoom
  3848. * level and feature property data.
  3849. *
  3850. * @private
  3851. */
  3852. var ProgramConfiguration = function ProgramConfiguration() {
  3853. this.binders = {};
  3854. this.cacheKey = '';
  3855. this._buffers = [];
  3856. };
  3857. ProgramConfiguration.createDynamic = function createDynamic(layer, zoom, filterProperties) {
  3858. var self = new ProgramConfiguration();
  3859. var keys = [];
  3860. for (var property in layer.paint._values) {
  3861. if (!filterProperties(property)) {
  3862. continue;
  3863. }
  3864. var value = layer.paint.get(property);
  3865. if (!(value instanceof PossiblyEvaluatedPropertyValue$1) || !Supports.supportsPropertyExpression(value.property.specification)) {
  3866. continue;
  3867. }
  3868. var names = paintAttributeNames(property, layer.type);
  3869. var type = value.property.specification.type;
  3870. var useIntegerZoom = value.property.useIntegerZoom;
  3871. var isCrossFaded = value.property.specification['property-type'] === 'cross-faded' ||
  3872. value.property.specification['property-type'] === 'cross-faded-data-driven';
  3873. if (isCrossFaded) {
  3874. if (value.value.kind === 'constant') {
  3875. self.binders[property] = new CrossFadedConstantBinder(value.value.value, names, type);
  3876. keys.push(("/u_" + property));
  3877. } else {
  3878. var StructArrayLayout = layoutType(property, type, 'source');
  3879. self.binders[property] = new CrossFadedCompositeBinder(value.value, names, type, useIntegerZoom, zoom, StructArrayLayout, layer.id);
  3880. keys.push(("/a_" + property));
  3881. }
  3882. } else if (value.value.kind === 'constant') {
  3883. self.binders[property] = new ConstantBinder(value.value.value, names, type);
  3884. keys.push(("/u_" + property));
  3885. } else if (value.value.kind === 'source') {
  3886. var StructArrayLayout$1 = layoutType(property, type, 'source');
  3887. self.binders[property] = new SourceExpressionBinder(value.value, names, type, StructArrayLayout$1);
  3888. keys.push(("/a_" + property));
  3889. } else {
  3890. var StructArrayLayout$2 = layoutType(property, type, 'composite');
  3891. self.binders[property] = new CompositeExpressionBinder(value.value, names, type, useIntegerZoom, zoom, StructArrayLayout$2);
  3892. keys.push(("/z_" + property));
  3893. }
  3894. }
  3895. self.cacheKey = keys.sort().join('');
  3896. return self;
  3897. };
  3898. ProgramConfiguration.prototype.populatePaintArrays = function populatePaintArrays(newLength, feature, index, imagePositions, formattedSection) {
  3899. for (var property in this.binders) {
  3900. var binder = this.binders[property];
  3901. binder.populatePaintArray(newLength, feature, imagePositions, formattedSection);
  3902. }
  3903. };
  3904. ProgramConfiguration.prototype.setConstantPatternPositions = function setConstantPatternPositions(posTo, posFrom) {
  3905. for (var property in this.binders) {
  3906. var binder = this.binders[property];
  3907. binder.setConstantPatternPositions(posTo, posFrom);
  3908. }
  3909. };
  3910. ProgramConfiguration.prototype.updatePaintArrays = function updatePaintArrays(featureStates, featureMap, vtLayer, layer, imagePositions) {
  3911. var dirty = false;
  3912. for (var id in featureStates) {
  3913. var positions = featureMap.getPositions(+id);
  3914. for (var i = 0, list = positions; i < list.length; i += 1) {
  3915. var pos = list[i];
  3916. var feature = vtLayer.feature(pos.index);
  3917. for (var property in this.binders) {
  3918. var binder = this.binders[property];
  3919. if (binder instanceof ConstantBinder || binder instanceof CrossFadedConstantBinder) {
  3920. continue;
  3921. }
  3922. if ((binder ).expression.isStateDependent === true) {
  3923. //AHM: Remove after https://github.com/mapbox/mapbox-gl-js/issues/6255
  3924. var value = layer.paint.get(property);
  3925. (binder ).expression = value.value;
  3926. binder.updatePaintArray(pos.start, pos.end, feature, featureStates[id], imagePositions);
  3927. dirty = true;
  3928. }
  3929. }
  3930. }
  3931. }
  3932. return dirty;
  3933. };
  3934. ProgramConfiguration.prototype.defines = function defines() {
  3935. var result = [];
  3936. for (var property in this.binders) {
  3937. result.push.apply(result, this.binders[property].defines());
  3938. }
  3939. return result;
  3940. };
  3941. ProgramConfiguration.prototype.getPaintVertexBuffers = function getPaintVertexBuffers() {
  3942. return this._buffers;
  3943. };
  3944. ProgramConfiguration.prototype.getUniforms = function getUniforms(context, locations) {
  3945. var uniforms = [];
  3946. for (var property in this.binders) {
  3947. var binder = this.binders[property];
  3948. for (var i = 0, list = binder.uniformNames; i < list.length; i += 1) {
  3949. var name = list[i];
  3950. if (locations[name]) {
  3951. var binding = binder.getBinding(context, locations[name]);
  3952. uniforms.push({name: name, property: property, binding: binding});
  3953. }
  3954. }
  3955. }
  3956. return uniforms;
  3957. };
  3958. ProgramConfiguration.prototype.setUniforms = function setUniforms(context, binderUniforms, properties, globals) {
  3959. // Uniform state bindings are owned by the Program, but we set them
  3960. // from within the ProgramConfiguraton's binder members.
  3961. for (var i = 0, list = binderUniforms; i < list.length; i += 1) {
  3962. var ref = list[i];
  3963. var name = ref.name;
  3964. var property = ref.property;
  3965. var binding = ref.binding;
  3966. this.binders[property].setUniforms(context, binding, globals, properties.get(property), name);
  3967. }
  3968. };
  3969. ProgramConfiguration.prototype.updatePatternPaintBuffers = function updatePatternPaintBuffers(crossfade) {
  3970. var buffers = [];
  3971. for (var property in this.binders) {
  3972. var binder = this.binders[property];
  3973. if (binder instanceof CrossFadedCompositeBinder) {
  3974. var patternVertexBuffer = crossfade.fromScale === 2 ? binder.zoomInPaintVertexBuffer : binder.zoomOutPaintVertexBuffer;
  3975. if (patternVertexBuffer) {
  3976. buffers.push(patternVertexBuffer);
  3977. }
  3978. } else if ((binder instanceof SourceExpressionBinder ||
  3979. binder instanceof CompositeExpressionBinder) &&
  3980. binder.paintVertexBuffer
  3981. ) {
  3982. buffers.push(binder.paintVertexBuffer);
  3983. }
  3984. }
  3985. this._buffers = buffers;
  3986. };
  3987. ProgramConfiguration.prototype.upload = function upload(context) {
  3988. for (var property in this.binders) {
  3989. this.binders[property].upload(context);
  3990. }
  3991. var buffers = [];
  3992. for (var property$1 in this.binders) {
  3993. var binder = this.binders[property$1];
  3994. if ((binder instanceof SourceExpressionBinder ||
  3995. binder instanceof CompositeExpressionBinder) &&
  3996. binder.paintVertexBuffer
  3997. ) {
  3998. buffers.push(binder.paintVertexBuffer);
  3999. }
  4000. }
  4001. this._buffers = buffers;
  4002. };
  4003. ProgramConfiguration.prototype.destroy = function destroy() {
  4004. for (var property in this.binders) {
  4005. this.binders[property].destroy();
  4006. }
  4007. };
  4008. function paintAttributeNames(property, type) {
  4009. var attributeNameExceptions = {
  4010. 'text-opacity': ['opacity'],
  4011. 'icon-opacity': ['opacity'],
  4012. 'text-color': ['fill_color'],
  4013. 'icon-color': ['fill_color'],
  4014. 'text-halo-color': ['halo_color'],
  4015. 'icon-halo-color': ['halo_color'],
  4016. 'text-halo-blur': ['halo_blur'],
  4017. 'text-show-background': ['show-background'],
  4018. 'icon-halo-blur': ['halo_blur'],
  4019. 'text-halo-width': ['halo_width'],
  4020. 'icon-halo-width': ['halo_width'],
  4021. 'line-gap-width': ['gapwidth'],
  4022. 'line-pattern': ['pattern_to', 'pattern_from'],
  4023. 'fill-pattern': ['pattern_to', 'pattern_from'],
  4024. 'fill-extrusion-pattern': ['pattern_to', 'pattern_from'],
  4025. };
  4026. return attributeNameExceptions[property] ||
  4027. [property.replace((type + "-"), '').replace(/-/g, '_')];
  4028. }
  4029. function getLayoutException(property) {
  4030. var propertyExceptions = {
  4031. 'line-pattern': {
  4032. 'source': StructArrayLayout8ui16,
  4033. 'composite': StructArrayLayout8ui16
  4034. },
  4035. 'fill-pattern': {
  4036. 'source': StructArrayLayout8ui16,
  4037. 'composite': StructArrayLayout8ui16
  4038. },
  4039. 'fill-extrusion-pattern': {
  4040. 'source': StructArrayLayout8ui16,
  4041. 'composite': StructArrayLayout8ui16
  4042. }
  4043. };
  4044. return propertyExceptions[property];
  4045. }
  4046. function layoutType(property, type, binderType) {
  4047. var defaultLayouts = {
  4048. 'color': {
  4049. 'source': StructArrayLayout2f8,
  4050. 'composite': StructArrayLayout4f16
  4051. },
  4052. 'number': {
  4053. 'source': StructArrayLayout1f4,
  4054. 'composite': StructArrayLayout2f8
  4055. }
  4056. };
  4057. var layoutException = getLayoutException(property);
  4058. return layoutException && layoutException[binderType] ||
  4059. defaultLayouts[type][binderType];
  4060. }
  4061. WebWorkerTransfer.register('ConstantBinder', ConstantBinder);
  4062. WebWorkerTransfer.register('CrossFadedConstantBinder', CrossFadedConstantBinder);
  4063. WebWorkerTransfer.register('SourceExpressionBinder', SourceExpressionBinder);
  4064. WebWorkerTransfer.register('CrossFadedCompositeBinder', CrossFadedCompositeBinder);
  4065. WebWorkerTransfer.register('CompositeExpressionBinder', CompositeExpressionBinder);
  4066. WebWorkerTransfer.register('ProgramConfiguration', ProgramConfiguration, {omit: ['_buffers']});
  4067. var ProgramConfigurationSet = function ProgramConfigurationSet(layoutAttributes, layers, zoom, filterProperties) {
  4068. if (filterProperties === void 0) filterProperties = function () {
  4069. return true;
  4070. };
  4071. this.programConfigurations = {};
  4072. for (var i = 0, list = layers; i < list.length; i += 1) {
  4073. var layer = list[i];
  4074. this.programConfigurations[layer.id] = ProgramConfiguration.createDynamic(layer, zoom, filterProperties);
  4075. this.programConfigurations[layer.id].layoutAttributes = layoutAttributes;
  4076. }
  4077. this.needsUpload = false;
  4078. this._featureMap = new FeaturePositionMap();
  4079. this._bufferOffset = 0;
  4080. };
  4081. ProgramConfigurationSet.prototype.populatePaintArrays = function populatePaintArrays(length, feature, index, imagePositions, formattedSection) {
  4082. for (var key in this.programConfigurations) {
  4083. this.programConfigurations[key].populatePaintArrays(length, feature, index, imagePositions, formattedSection);
  4084. }
  4085. if (feature.id !== undefined) {
  4086. this._featureMap.add(+feature.id, index, this._bufferOffset, length);
  4087. }
  4088. this._bufferOffset = length;
  4089. this.needsUpload = true;
  4090. };
  4091. ProgramConfigurationSet.prototype.updatePaintArrays = function updatePaintArrays(featureStates, vtLayer, layers, imagePositions) {
  4092. for (var i = 0, list = layers; i < list.length; i += 1) {
  4093. var layer = list[i];
  4094. this.needsUpload = this.programConfigurations[layer.id].updatePaintArrays(featureStates, this._featureMap, vtLayer, layer, imagePositions) || this.needsUpload;
  4095. }
  4096. };
  4097. ProgramConfigurationSet.prototype.get = function get(layerId) {
  4098. return this.programConfigurations[layerId];
  4099. };
  4100. ProgramConfigurationSet.prototype.upload = function upload(context) {
  4101. if (!this.needsUpload) {
  4102. return;
  4103. }
  4104. for (var layerId in this.programConfigurations) {
  4105. this.programConfigurations[layerId].upload(context);
  4106. }
  4107. this.needsUpload = false;
  4108. };
  4109. ProgramConfigurationSet.prototype.destroy = function destroy() {
  4110. for (var layerId in this.programConfigurations) {
  4111. this.programConfigurations[layerId].destroy();
  4112. }
  4113. };
  4114. WebWorkerTransfer.register('ProgramConfigurationSet', ProgramConfigurationSet);
  4115. function addPatternDependencies(type, layers, patternFeature, zoom, options) {
  4116. var patterns = options.patternDependencies;
  4117. for (var i = 0, list = layers; i < list.length; i += 1) {
  4118. var layer = list[i];
  4119. var patternProperty = layer.paint.get((type + "-pattern"));
  4120. var patternPropertyValue = patternProperty.value;
  4121. if (patternPropertyValue.kind !== "constant") {
  4122. var min = patternPropertyValue.evaluate({zoom: zoom - 1}, patternFeature, {}, options.availableImages);
  4123. var mid = patternPropertyValue.evaluate({zoom: zoom}, patternFeature, {}, options.availableImages);
  4124. var max = patternPropertyValue.evaluate({zoom: zoom + 1}, patternFeature, {}, options.availableImages);
  4125. min = min && min.name ? min.name : min;
  4126. mid = mid && mid.name ? mid.name : mid;
  4127. max = max && max.name ? max.name : max;
  4128. // add to patternDependencies
  4129. patterns[min] = true;
  4130. patterns[mid] = true;
  4131. patterns[max] = true;
  4132. // save for layout
  4133. patternFeature.patterns[layer.id] = {min: min, mid: mid, max: max};
  4134. }
  4135. }
  4136. return patternFeature;
  4137. }
  4138. var VectorTileFeatureTypes = ['Unknown', 'Point', 'LineString', 'Polygon'];
  4139. var lineLayoutAttributes = createLayout([
  4140. {name: 'a_pos_normal', components: 2, type: 'Int16'},
  4141. {name: 'a_data', components: 4, type: 'Uint8'}
  4142. ], 4);
  4143. var members$3 = lineLayoutAttributes.members;
  4144. // NOTE ON EXTRUDE SCALE:
  4145. // scale the extrusion vector so that the normal length is this value.
  4146. // contains the "texture" normals (-1..1). this is distinct from the extrude
  4147. // normals for line joins, because the x-value remains 0 for the texture
  4148. // normal array, while the extrude normal actually moves the vertex to create
  4149. // the acute/bevelled line join.
  4150. var EXTRUDE_SCALE = 63;
  4151. /*
  4152. * Sharp corners cause dashed lines to tilt because the distance along the line
  4153. * is the same at both the inner and outer corners. To improve the appearance of
  4154. * dashed lines we add extra points near sharp corners so that a smaller part
  4155. * of the line is tilted.
  4156. *
  4157. * COS_HALF_SHARP_CORNER controls how sharp a corner has to be for us to add an
  4158. * extra vertex. The default is 75 degrees.
  4159. *
  4160. * The newly created vertices are placed SHARP_CORNER_OFFSET pixels from the corner.
  4161. */
  4162. var COS_HALF_SHARP_CORNER = Math.cos(75 / 2 * (Math.PI / 180));
  4163. var SHARP_CORNER_OFFSET = 15;
  4164. // Angle per triangle for approximating round line joins.
  4165. var DEG_PER_TRIANGLE = 20;
  4166. // The number of bits that is used to store the line distance in the buffer.
  4167. var LINE_DISTANCE_BUFFER_BITS = 15;
  4168. // We don't have enough bits for the line distance as we'd like to have, so
  4169. // use this value to scale the line distance (in tile units) down to a smaller
  4170. // value. This lets us store longer distances while sacrificing precision.
  4171. var LINE_DISTANCE_SCALE = 1 / 2;
  4172. // The maximum line distance, in tile units, that fits in the buffer.
  4173. var MAX_LINE_DISTANCE = Math.pow(2, LINE_DISTANCE_BUFFER_BITS - 1) / LINE_DISTANCE_SCALE;
  4174. /**
  4175. * @private
  4176. */
  4177. var LineBucket = function LineBucket(options) {
  4178. this.zoom = options.zoom;
  4179. this.overscaling = options.overscaling;
  4180. this.layers = options.layers;
  4181. this.layerIds = this.layers.map(function (layer) {
  4182. return layer.id;
  4183. });
  4184. this.index = options.index;
  4185. this.hasPattern = false;
  4186. this.patternFeatures = [];
  4187. this.layoutVertexArray = new StructArrayLayout2i4ub8();
  4188. this.indexArray = new StructArrayLayout3ui6();
  4189. this.programConfigurations = new ProgramConfigurationSet(members$3, options.layers, options.zoom);
  4190. this.segments = new SegmentVector();
  4191. this.stateDependentLayerIds = this.layers.filter(function (l) {
  4192. return l.isStateDependent();
  4193. }).map(function (l) {
  4194. return l.id;
  4195. });
  4196. };
  4197. LineBucket.prototype.populate = function populate(features, options) {
  4198. //this.hasPattern = hasPattern('line', this.layers, options);
  4199. this.hasPattern = false;
  4200. var lineSortKey = this.layers[0].layout.get('line-sort-key');
  4201. var bucketFeatures = [];
  4202. for (var i = 0, list = features; i < list.length; i += 1) {
  4203. var ref = list[i];
  4204. var feature = ref.feature;
  4205. var index = ref.index;
  4206. var sourceLayerIndex = ref.sourceLayerIndex;
  4207. if (!this.layers[0]._featureFilter(new EvaluationParameters$1(0), feature)) {
  4208. continue;
  4209. }
  4210. var geometry = loadGeometry(feature);
  4211. var sortKey = lineSortKey ?
  4212. lineSortKey.evaluate(feature, {}) :
  4213. undefined;
  4214. var bucketFeature = {
  4215. id: feature.id,
  4216. properties: feature.properties,
  4217. type: feature.type,
  4218. sourceLayerIndex: sourceLayerIndex,
  4219. index: index,
  4220. geometry: geometry,
  4221. patterns: {},
  4222. sortKey: sortKey
  4223. };
  4224. bucketFeatures.push(bucketFeature);
  4225. }
  4226. if (lineSortKey) {
  4227. bucketFeatures.sort(function (a, b) {
  4228. // a.sortKey is always a number when in use
  4229. return ((a.sortKey ) ) - ((b.sortKey ) );
  4230. });
  4231. }
  4232. for (var i$1 = 0, list$1 = bucketFeatures; i$1 < list$1.length; i$1 += 1) {
  4233. var bucketFeature$1 = list$1[i$1];
  4234. var ref$1 = bucketFeature$1;
  4235. var geometry$1 = ref$1.geometry;
  4236. var index$1 = ref$1.index;
  4237. var sourceLayerIndex$1 = ref$1.sourceLayerIndex;
  4238. if (this.hasPattern) {
  4239. var patternBucketFeature = addPatternDependencies('line', this.layers, bucketFeature$1, this.zoom, options);
  4240. // pattern features are added only once the pattern is loaded into the image atlas
  4241. // so are stored during populate until later updated with positions by tile worker in addFeatures
  4242. this.patternFeatures.push(patternBucketFeature);
  4243. } else {
  4244. this.addFeature(bucketFeature$1, geometry$1, index$1, {});
  4245. }
  4246. var feature$1 = features[index$1].feature;
  4247. options.featureIndex.insert(feature$1, geometry$1, index$1, sourceLayerIndex$1, this.index);
  4248. }
  4249. };
  4250. LineBucket.prototype.update = function update(states, vtLayer, imagePositions) {
  4251. if (!this.stateDependentLayers.length) {
  4252. return;
  4253. }
  4254. this.programConfigurations.updatePaintArrays(states, vtLayer, this.stateDependentLayers, imagePositions);
  4255. };
  4256. LineBucket.prototype.addFeatures = function addFeatures(options, imagePositions) {
  4257. for (var i = 0, list = this.patternFeatures; i < list.length; i += 1) {
  4258. var feature = list[i];
  4259. this.addFeature(feature, feature.geometry, feature.index, imagePositions);
  4260. }
  4261. };
  4262. LineBucket.prototype.isEmpty = function isEmpty() {
  4263. return this.layoutVertexArray.length === 0;
  4264. };
  4265. LineBucket.prototype.uploadPending = function uploadPending() {
  4266. return !this.uploaded || this.programConfigurations.needsUpload;
  4267. };
  4268. LineBucket.prototype.upload = function upload(context) {
  4269. if (!this.uploaded) {
  4270. if(this.layoutVertexArray == null) {
  4271. return;
  4272. }
  4273. this.layoutVertexBuffer = context.createVertexBuffer(this.layoutVertexArray, members$3);
  4274. this.indexBuffer = context.createIndexBuffer(this.indexArray);
  4275. }
  4276. this.programConfigurations.upload(context);
  4277. this.uploaded = true;
  4278. };
  4279. LineBucket.prototype.destroy = function destroy() {
  4280. if (!this.layoutVertexBuffer) {
  4281. return;
  4282. }
  4283. this.layoutVertexBuffer.destroy();
  4284. this.indexBuffer.destroy();
  4285. this.programConfigurations.destroy();
  4286. this.segments.destroy();
  4287. };
  4288. LineBucket.prototype.clear = function clear() {
  4289. if (when.defined(this.layoutVertexArray)) {
  4290. this.layoutVertexArray = null;
  4291. }
  4292. if (when.defined(this.indexArray)) {
  4293. this.indexArray = null;
  4294. }
  4295. };
  4296. LineBucket.prototype.addFeature = function addFeature(feature, geometry, index, imagePositions) {
  4297. var layout = this.layers[0].layout;
  4298. var join = layout.get('line-join').evaluate(feature, {});
  4299. var cap = layout.get('line-cap');
  4300. var miterLimit = layout.get('line-miter-limit');
  4301. var roundLimit = layout.get('line-round-limit');
  4302. for (var i = 0, list = geometry; i < list.length; i += 1) {
  4303. var line = list[i];
  4304. this.addLine(line, feature, join, cap, miterLimit, roundLimit, index, imagePositions);
  4305. }
  4306. };
  4307. LineBucket.prototype.addLine = function addLine(vertices, feature, join, cap, miterLimit, roundLimit, index, imagePositions) {
  4308. this.distance = 0;
  4309. this.scaledDistance = 0;
  4310. this.totalDistance = 0;
  4311. if (!!feature.properties &&
  4312. feature.properties.hasOwnProperty('mapbox_clip_start') &&
  4313. feature.properties.hasOwnProperty('mapbox_clip_end')) {
  4314. this.clipStart = +feature.properties['mapbox_clip_start'];
  4315. this.clipEnd = +feature.properties['mapbox_clip_end'];
  4316. // Calculate the total distance, in tile units, of this tiled line feature
  4317. for (var i = 0; i < vertices.length - 1; i++) {
  4318. this.totalDistance += vertices[i].dist(vertices[i + 1]);
  4319. }
  4320. }
  4321. var isPolygon = VectorTileFeatureTypes[feature.type] === 'Polygon';
  4322. // If the line has duplicate vertices at the ends, adjust start/length to remove them.
  4323. var len = vertices.length;
  4324. while (len >= 2 && vertices[len - 1].equals(vertices[len - 2])) {
  4325. len--;
  4326. }
  4327. var first = 0;
  4328. while (first < len - 1 && vertices[first].equals(vertices[first + 1])) {
  4329. first++;
  4330. }
  4331. // Ignore invalid geometry.
  4332. if (len < (isPolygon ? 3 : 2)) {
  4333. return;
  4334. }
  4335. if (join === 'bevel') {
  4336. miterLimit = 1.05;
  4337. }
  4338. var sharpCornerOffset = this.overscaling <= 16 ?
  4339. SHARP_CORNER_OFFSET * EXTENT / (512 * this.overscaling) :
  4340. 0;
  4341. // we could be more precise, but it would only save a negligible amount of space
  4342. var segment = this.segments.prepareSegment(len * 10, this.layoutVertexArray, this.indexArray);
  4343. var currentVertex;
  4344. var prevVertex = ((undefined ) );
  4345. var nextVertex = ((undefined ) );
  4346. var prevNormal = ((undefined ) );
  4347. var nextNormal = ((undefined ) );
  4348. // the last two vertices added
  4349. this.e1 = this.e2 = -1;
  4350. if (isPolygon) {
  4351. currentVertex = vertices[len - 2];
  4352. nextNormal = vertices[first].sub(currentVertex)._unit()._perp();
  4353. }
  4354. for (var i$1 = first; i$1 < len; i$1++) {
  4355. nextVertex = isPolygon && i$1 === len - 1 ?
  4356. vertices[first + 1] : // if the line is closed, we treat the last vertex like the first
  4357. vertices[i$1 + 1]; // just the next vertex
  4358. // if two consecutive vertices exist, skip the current one
  4359. if (nextVertex && vertices[i$1].equals(nextVertex)) {
  4360. continue;
  4361. }
  4362. if (nextNormal) {
  4363. prevNormal = nextNormal;
  4364. }
  4365. if (currentVertex) {
  4366. prevVertex = currentVertex;
  4367. }
  4368. currentVertex = vertices[i$1];
  4369. // Calculate the normal towards the next vertex in this line. In case
  4370. // there is no next vertex, pretend that the line is continuing straight,
  4371. // meaning that we are just using the previous normal.
  4372. nextNormal = nextVertex ? nextVertex.sub(currentVertex)._unit()._perp() : prevNormal;
  4373. // If we still don't have a previous normal, this is the beginning of a
  4374. // non-closed line, so we're doing a straight "join".
  4375. prevNormal = prevNormal || nextNormal;
  4376. // Determine the normal of the join extrusion. It is the angle bisector
  4377. // of the segments between the previous line and the next line.
  4378. // In the case of 180° angles, the prev and next normals cancel each other out:
  4379. // prevNormal + nextNormal = (0, 0), its magnitude is 0, so the unit vector would be
  4380. // undefined. In that case, we're keeping the joinNormal at (0, 0), so that the cosHalfAngle
  4381. // below will also become 0 and miterLength will become Infinity.
  4382. var joinNormal = prevNormal.add(nextNormal);
  4383. if (joinNormal.x !== 0 || joinNormal.y !== 0) {
  4384. joinNormal._unit();
  4385. }
  4386. /* joinNormal prevNormal
  4387. * ↖ ↑
  4388. * .________. prevVertex
  4389. * |
  4390. * nextNormal ← | currentVertex
  4391. * |
  4392. * nextVertex !
  4393. *
  4394. */
  4395. // calculate cosines of the angle (and its half) using dot product
  4396. var cosAngle = prevNormal.x * nextNormal.x + prevNormal.y * nextNormal.y;
  4397. var cosHalfAngle = joinNormal.x * nextNormal.x + joinNormal.y * nextNormal.y;
  4398. // Calculate the length of the miter (the ratio of the miter to the width)
  4399. // as the inverse of cosine of the angle between next and join normals
  4400. var miterLength = cosHalfAngle !== 0 ? 1 / cosHalfAngle : Infinity;
  4401. // approximate angle from cosine
  4402. var approxAngle = 2 * Math.sqrt(2 - 2 * cosHalfAngle);
  4403. var isSharpCorner = cosHalfAngle < COS_HALF_SHARP_CORNER && prevVertex && nextVertex;
  4404. var lineTurnsLeft = prevNormal.x * nextNormal.y - prevNormal.y * nextNormal.x > 0;
  4405. if (isSharpCorner && i$1 > first) {
  4406. var prevSegmentLength = currentVertex.dist(prevVertex);
  4407. if (prevSegmentLength > 2 * sharpCornerOffset) {
  4408. var newPrevVertex = currentVertex.sub(currentVertex.sub(prevVertex)._mult(sharpCornerOffset / prevSegmentLength)._round());
  4409. this.updateDistance(prevVertex, newPrevVertex);
  4410. this.addCurrentVertex(newPrevVertex, prevNormal, 0, 0, segment);
  4411. prevVertex = newPrevVertex;
  4412. }
  4413. }
  4414. // The join if a middle vertex, otherwise the cap.
  4415. var middleVertex = prevVertex && nextVertex;
  4416. var currentJoin = middleVertex ? join : isPolygon ? 'butt' : cap;
  4417. if (middleVertex && currentJoin === 'round') {
  4418. if (miterLength < roundLimit) {
  4419. currentJoin = 'miter';
  4420. } else if (miterLength <= 2) {
  4421. currentJoin = 'fakeround';
  4422. }
  4423. }
  4424. if (currentJoin === 'miter' && miterLength > miterLimit) {
  4425. currentJoin = 'bevel';
  4426. }
  4427. if (currentJoin === 'bevel') {
  4428. // The maximum extrude length is 128 / 63 = 2 times the width of the line
  4429. // so if miterLength >= 2 we need to draw a different type of bevel here.
  4430. if (miterLength > 2) {
  4431. currentJoin = 'flipbevel';
  4432. }
  4433. // If the miterLength is really small and the line bevel wouldn't be visible,
  4434. // just draw a miter join to save a triangle.
  4435. if (miterLength < miterLimit) {
  4436. currentJoin = 'miter';
  4437. }
  4438. }
  4439. // Calculate how far along the line the currentVertex is
  4440. if (prevVertex) {
  4441. this.updateDistance(prevVertex, currentVertex);
  4442. }
  4443. if (currentJoin === 'miter') {
  4444. joinNormal._mult(miterLength);
  4445. this.addCurrentVertex(currentVertex, joinNormal, 0, 0, segment);
  4446. } else if (currentJoin === 'flipbevel') {
  4447. // miter is too big, flip the direction to make a beveled join
  4448. if (miterLength > 100) {
  4449. // Almost parallel lines
  4450. joinNormal = nextNormal.mult(-1);
  4451. } else {
  4452. var bevelLength = miterLength * prevNormal.add(nextNormal).mag() / prevNormal.sub(nextNormal).mag();
  4453. joinNormal._perp()._mult(bevelLength * (lineTurnsLeft ? -1 : 1));
  4454. }
  4455. this.addCurrentVertex(currentVertex, joinNormal, 0, 0, segment);
  4456. this.addCurrentVertex(currentVertex, joinNormal.mult(-1), 0, 0, segment);
  4457. } else if (currentJoin === 'bevel' || currentJoin === 'fakeround') {
  4458. var offset = -Math.sqrt(miterLength * miterLength - 1);
  4459. var offsetA = lineTurnsLeft ? offset : 0;
  4460. var offsetB = lineTurnsLeft ? 0 : offset;
  4461. // Close previous segment with a bevel
  4462. if (prevVertex) {
  4463. this.addCurrentVertex(currentVertex, prevNormal, offsetA, offsetB, segment);
  4464. }
  4465. if (currentJoin === 'fakeround') {
  4466. // The join angle is sharp enough that a round join would be visible.
  4467. // Bevel joins fill the gap between segments with a single pie slice triangle.
  4468. // Create a round join by adding multiple pie slices. The join isn't actually round, but
  4469. // it looks like it is at the sizes we render lines at.
  4470. // pick the number of triangles for approximating round join by based on the angle between normals
  4471. var n = Math.round((approxAngle * 180 / Math.PI) / DEG_PER_TRIANGLE);
  4472. for (var m = 1; m < n; m++) {
  4473. var t = m / n;
  4474. if (t !== 0.5) {
  4475. // approximate spherical interpolation https://observablehq.com/@mourner/approximating-geometric-slerp
  4476. var t2 = t - 0.5;
  4477. var A = 1.0904 + cosAngle * (-3.2452 + cosAngle * (3.55645 - cosAngle * 1.43519));
  4478. var B = 0.848013 + cosAngle * (-1.06021 + cosAngle * 0.215638);
  4479. t = t + t * t2 * (t - 1) * (A * t2 * t2 + B);
  4480. }
  4481. var extrude = nextNormal.sub(prevNormal)._mult(t)._add(prevNormal)._unit()._mult(lineTurnsLeft ? -1 : 1);
  4482. this.addHalfVertex(currentVertex, extrude.x, extrude.y, false, lineTurnsLeft, 0, segment);
  4483. }
  4484. }
  4485. if (nextVertex) {
  4486. // Start next segment
  4487. this.addCurrentVertex(currentVertex, nextNormal, -offsetA, -offsetB, segment);
  4488. }
  4489. } else if (currentJoin === 'butt') {
  4490. this.addCurrentVertex(currentVertex, joinNormal, 0, 0, segment); // butt cap
  4491. } else if (currentJoin === 'square') {
  4492. var offset$1 = prevVertex ? 1 : -1; // closing or starting square cap
  4493. this.addCurrentVertex(currentVertex, joinNormal, offset$1, offset$1, segment);
  4494. } else if (currentJoin === 'round') {
  4495. if (prevVertex) {
  4496. // Close previous segment with butt
  4497. this.addCurrentVertex(currentVertex, prevNormal, 0, 0, segment);
  4498. // Add round cap or linejoin at end of segment
  4499. this.addCurrentVertex(currentVertex, prevNormal, 1, 1, segment, true);
  4500. }
  4501. if (nextVertex) {
  4502. // Add round cap before first segment
  4503. this.addCurrentVertex(currentVertex, nextNormal, -1, -1, segment, true);
  4504. // Start next segment with a butt
  4505. this.addCurrentVertex(currentVertex, nextNormal, 0, 0, segment);
  4506. }
  4507. }
  4508. if (isSharpCorner && i$1 < len - 1) {
  4509. var nextSegmentLength = currentVertex.dist(nextVertex);
  4510. if (nextSegmentLength > 2 * sharpCornerOffset) {
  4511. var newCurrentVertex = currentVertex.add(nextVertex.sub(currentVertex)._mult(sharpCornerOffset / nextSegmentLength)._round());
  4512. this.updateDistance(currentVertex, newCurrentVertex);
  4513. this.addCurrentVertex(newCurrentVertex, nextNormal, 0, 0, segment);
  4514. currentVertex = newCurrentVertex;
  4515. }
  4516. }
  4517. }
  4518. this.programConfigurations.populatePaintArrays(this.layoutVertexArray.length, feature, index, imagePositions);
  4519. };
  4520. /**
  4521. * Add two vertices to the buffers.
  4522. *
  4523. * @param p the line vertex to add buffer vertices for
  4524. * @param normal vertex normal
  4525. * @param endLeft extrude to shift the left vertex along the line
  4526. * @param endRight extrude to shift the left vertex along the line
  4527. * @param segment the segment object to add the vertex to
  4528. * @param round whether this is a round cap
  4529. * @private
  4530. */
  4531. LineBucket.prototype.addCurrentVertex = function addCurrentVertex(p, normal, endLeft, endRight, segment, round) {
  4532. if (round === void 0) round = false;
  4533. // left and right extrude vectors, perpendicularly shifted by endLeft/endRight
  4534. var leftX = normal.x + normal.y * endLeft;
  4535. var leftY = normal.y - normal.x * endLeft;
  4536. var rightX = -normal.x + normal.y * endRight;
  4537. var rightY = -normal.y - normal.x * endRight;
  4538. this.addHalfVertex(p, leftX, leftY, round, false, endLeft, segment);
  4539. this.addHalfVertex(p, rightX, rightY, round, true, -endRight, segment);
  4540. // There is a maximum "distance along the line" that we can store in the buffers.
  4541. // When we get close to the distance, reset it to zero and add the vertex again with
  4542. // a distance of zero. The max distance is determined by the number of bits we allocate
  4543. // to `linesofar`.
  4544. if (this.distance > MAX_LINE_DISTANCE / 2 && this.totalDistance === 0) {
  4545. this.distance = 0;
  4546. this.addCurrentVertex(p, normal, endLeft, endRight, segment, round);
  4547. }
  4548. };
  4549. LineBucket.prototype.addHalfVertex = function addHalfVertex(ref, extrudeX, extrudeY, round, up, dir, segment) {
  4550. var x = ref.x;
  4551. var y = ref.y;
  4552. // scale down so that we can store longer distances while sacrificing precision.
  4553. var linesofar = this.scaledDistance * LINE_DISTANCE_SCALE;
  4554. this.layoutVertexArray.emplaceBack(
  4555. // a_pos_normal
  4556. // Encode round/up the least significant bits
  4557. (x << 1) + (round ? 1 : 0),
  4558. (y << 1) + (up ? 1 : 0),
  4559. // a_data
  4560. // add 128 to store a byte in an unsigned byte
  4561. Math.round(EXTRUDE_SCALE * extrudeX) + 128,
  4562. Math.round(EXTRUDE_SCALE * extrudeY) + 128,
  4563. // Encode the -1/0/1 direction value into the first two bits of .z of a_data.
  4564. // Combine it with the lower 6 bits of `linesofar` (shifted by 2 bites to make
  4565. // room for the direction value). The upper 8 bits of `linesofar` are placed in
  4566. // the `w` component.
  4567. ((dir === 0 ? 0 : (dir < 0 ? -1 : 1)) + 1) | ((linesofar & 0x3F) << 2),
  4568. linesofar >> 6);
  4569. var e = segment.vertexLength++;
  4570. if (this.e1 >= 0 && this.e2 >= 0) {
  4571. this.indexArray.emplaceBack(this.e1, this.e2, e);
  4572. segment.primitiveLength++;
  4573. }
  4574. if (up) {
  4575. this.e2 = e;
  4576. } else {
  4577. this.e1 = e;
  4578. }
  4579. };
  4580. LineBucket.prototype.updateDistance = function updateDistance(prev, next) {
  4581. this.distance += prev.dist(next);
  4582. // Knowing the ratio of the full linestring covered by this tiled feature, as well
  4583. // as the total distance (in tile units) of this tiled feature, and the distance
  4584. // (in tile units) of the current vertex, we can determine the relative distance
  4585. // of this vertex along the full linestring feature and scale it to [0, 2^15)
  4586. this.scaledDistance = this.totalDistance > 0 ?
  4587. (this.clipStart + (this.clipEnd - this.clipStart) * this.distance / this.totalDistance) * (MAX_LINE_DISTANCE - 1) :
  4588. this.distance;
  4589. };
  4590. WebWorkerTransfer.register('LineBucket', LineBucket, {omit: ['layers', 'patternFeatures']});
  4591. function quickselect(arr, k, left, right, compare) {
  4592. quickselectStep(arr, k, left || 0, right || (arr.length - 1), compare || defaultCompare);
  4593. }
  4594. function quickselectStep(arr, k, left, right, compare) {
  4595. while (right > left) {
  4596. if (right - left > 600) {
  4597. var n = right - left + 1;
  4598. var m = k - left + 1;
  4599. var z = Math.log(n);
  4600. var s = 0.5 * Math.exp(2 * z / 3);
  4601. var sd = 0.5 * Math.sqrt(z * s * (n - s) / n) * (m - n / 2 < 0 ? -1 : 1);
  4602. var newLeft = Math.max(left, Math.floor(k - m * s / n + sd));
  4603. var newRight = Math.min(right, Math.floor(k + (n - m) * s / n + sd));
  4604. quickselectStep(arr, k, newLeft, newRight, compare);
  4605. }
  4606. var t = arr[k];
  4607. var i = left;
  4608. var j = right;
  4609. swap$1(arr, left, k);
  4610. if (compare(arr[right], t) > 0) swap$1(arr, left, right);
  4611. while (i < j) {
  4612. swap$1(arr, i, j);
  4613. i++;
  4614. j--;
  4615. while (compare(arr[i], t) < 0) i++;
  4616. while (compare(arr[j], t) > 0) j--;
  4617. }
  4618. if (compare(arr[left], t) === 0) swap$1(arr, left, j);
  4619. else {
  4620. j++;
  4621. swap$1(arr, j, right);
  4622. }
  4623. if (j <= k) left = j + 1;
  4624. if (k <= j) right = j - 1;
  4625. }
  4626. }
  4627. function swap$1(arr, i, j) {
  4628. var tmp = arr[i];
  4629. arr[i] = arr[j];
  4630. arr[j] = tmp;
  4631. }
  4632. function defaultCompare(a, b) {
  4633. return a < b ? -1 : a > b ? 1 : 0;
  4634. }
  4635. /**
  4636. * Returns the signed area for the polygon ring. Postive areas are exterior rings and
  4637. * have a clockwise winding. Negative areas are interior rings and have a counter clockwise
  4638. * ordering.
  4639. *
  4640. * @private
  4641. * @param ring Exterior or interior ring
  4642. */
  4643. function calculateSignedArea(ring) {
  4644. var sum = 0;
  4645. for (var i = 0, len = ring.length, j = len - 1, p1 = (void 0), p2 = (void 0); i < len; j = i++) {
  4646. p1 = ring[i];
  4647. p2 = ring[j];
  4648. sum += (p2.x - p1.x) * (p1.y + p2.y);
  4649. }
  4650. return sum;
  4651. }
  4652. // classifies an array of rings into polygons with outer rings and holes
  4653. function classifyRings(rings, maxRings) {
  4654. var len = rings.length;
  4655. if (len <= 1) {
  4656. return [rings];
  4657. }
  4658. var polygons = [];
  4659. var polygon,
  4660. ccw;
  4661. for (var i = 0; i < len; i++) {
  4662. var area = calculateSignedArea(rings[i]);
  4663. if (area === 0) {
  4664. continue;
  4665. }
  4666. (rings[i] ).area = Math.abs(area);
  4667. if (ccw === undefined) {
  4668. ccw = area < 0;
  4669. }
  4670. if (ccw === area < 0) {
  4671. if (polygon) {
  4672. polygons.push(polygon);
  4673. }
  4674. polygon = [rings[i]];
  4675. } else {
  4676. (polygon ).push(rings[i]);
  4677. }
  4678. }
  4679. if (polygon) {
  4680. polygons.push(polygon);
  4681. }
  4682. // Earcut performance degrades with the # of rings in a polygon. For this
  4683. // reason, we limit strip out all but the `maxRings` largest rings.
  4684. if (maxRings > 1) {
  4685. for (var j = 0; j < polygons.length; j++) {
  4686. if (polygons[j].length <= maxRings) {
  4687. continue;
  4688. }
  4689. quickselect(polygons[j], maxRings, 1, polygons[j].length - 1, compareAreas);
  4690. polygons[j] = polygons[j].slice(0, maxRings);
  4691. }
  4692. }
  4693. return polygons;
  4694. }
  4695. function compareAreas(a, b) {
  4696. return b.area - a.area;
  4697. }
  4698. var StructArrayLayout2i4 = /*@__PURE__*/(function (StructArray) {
  4699. function StructArrayLayout2i4() {
  4700. StructArray.apply(this, arguments);
  4701. }
  4702. if (StructArray) StructArrayLayout2i4.__proto__ = StructArray;
  4703. StructArrayLayout2i4.prototype = Object.create(StructArray && StructArray.prototype);
  4704. StructArrayLayout2i4.prototype.constructor = StructArrayLayout2i4;
  4705. StructArrayLayout2i4.prototype._refreshViews = function _refreshViews() {
  4706. this.uint8 = new Uint8Array(this.arrayBuffer);
  4707. this.int16 = new Int16Array(this.arrayBuffer);
  4708. };
  4709. StructArrayLayout2i4.prototype.emplaceBack = function emplaceBack(v0, v1) {
  4710. var i = this.length;
  4711. this.resize(i + 1);
  4712. return this.emplace(i, v0, v1);
  4713. };
  4714. StructArrayLayout2i4.prototype.emplace = function emplace(i, v0, v1) {
  4715. var o2 = i * 2;
  4716. this.int16[o2 + 0] = v0;
  4717. this.int16[o2 + 1] = v1;
  4718. return i;
  4719. };
  4720. return StructArrayLayout2i4;
  4721. }(StructArray));
  4722. StructArrayLayout2i4.prototype.bytesPerElement = 4;
  4723. WebWorkerTransfer.register('StructArrayLayout2i4', StructArrayLayout2i4);
  4724. var StructArrayLayout2ui4 = /*@__PURE__*/(function (StructArray) {
  4725. function StructArrayLayout2ui4() {
  4726. StructArray.apply(this, arguments);
  4727. }
  4728. if (StructArray) StructArrayLayout2ui4.__proto__ = StructArray;
  4729. StructArrayLayout2ui4.prototype = Object.create(StructArray && StructArray.prototype);
  4730. StructArrayLayout2ui4.prototype.constructor = StructArrayLayout2ui4;
  4731. StructArrayLayout2ui4.prototype._refreshViews = function _refreshViews() {
  4732. this.uint8 = new Uint8Array(this.arrayBuffer);
  4733. this.uint16 = new Uint16Array(this.arrayBuffer);
  4734. };
  4735. StructArrayLayout2ui4.prototype.emplaceBack = function emplaceBack(v0, v1) {
  4736. var i = this.length;
  4737. this.resize(i + 1);
  4738. return this.emplace(i, v0, v1);
  4739. };
  4740. StructArrayLayout2ui4.prototype.emplace = function emplace(i, v0, v1) {
  4741. var o2 = i * 2;
  4742. this.uint16[o2 + 0] = v0;
  4743. this.uint16[o2 + 1] = v1;
  4744. return i;
  4745. };
  4746. return StructArrayLayout2ui4;
  4747. }(StructArray));
  4748. StructArrayLayout2ui4.prototype.bytesPerElement = 4;
  4749. WebWorkerTransfer.register('StructArrayLayout2ui4', StructArrayLayout2ui4);
  4750. function hasPattern(type, layers, options) {
  4751. var patterns = options.patternDependencies;
  4752. var hasPattern = false;
  4753. for (var i = 0, list = layers; i < list.length; i += 1) {
  4754. var layer = list[i];
  4755. var patternProperty = layer.paint.get((type + "-pattern"));
  4756. if (!patternProperty.isConstant()) {
  4757. hasPattern = true;
  4758. }
  4759. var constantPattern = patternProperty.constantOr(null);
  4760. if (constantPattern) {
  4761. hasPattern = true;
  4762. patterns[constantPattern.to] = true;
  4763. patterns[constantPattern.from] = true;
  4764. }
  4765. }
  4766. return hasPattern;
  4767. }
  4768. // Copyright 2010 The Emscripten Authors. All rights reserved.
  4769. // Emscripten is available under two separate licenses, the MIT license and the
  4770. // University of Illinois/NCSA Open Source License. Both these licenses can be
  4771. // found in the LICENSE file.
  4772. // The Module object: Our interface to the outside world. We import
  4773. // and export values on it. There are various ways Module can be used:
  4774. // 1. Not defined. We create it here
  4775. // 2. A function parameter, function(Module) { ..generated code.. }
  4776. // 3. pre-run appended it, var Module = {}; ..generated code..
  4777. // 4. External script tag defines var Module.
  4778. // We need to check if Module already exists (e.g. case 3 above).
  4779. // Substitution will be replaced with actual code on later stage of the build,
  4780. // this way Closure Compiler will not mangle it (e.g. case 4. above).
  4781. // Note that if you want to run closure, and also to use Module
  4782. // after the generated code, you will need to define var Module = {};
  4783. // before the code. Then that object will be used in the code, and you
  4784. // can continue to use Module afterwards as well.
  4785. if (typeof WebAssembly !== 'undefined') {
  4786. var Module = typeof Module !== 'undefined' ? Module : {};
  4787. // --pre-jses are emitted after the Module integration code, so that they can
  4788. // refer to Module (if they choose; they can also define Module)
  4789. // {{PRE_JSES}}
  4790. // Sometimes an existing Module object exists with properties
  4791. // meant to overwrite the default module functionality. Here
  4792. // we collect those properties and reapply _after_ we configure
  4793. // the current environment's defaults to avoid having to be so
  4794. // defensive during initialization.
  4795. var moduleOverrides = {};
  4796. var key;
  4797. for (key in Module) {
  4798. if (Module.hasOwnProperty(key)) {
  4799. moduleOverrides[key] = Module[key];
  4800. }
  4801. }
  4802. Module['arguments'] = [];
  4803. Module['thisProgram'] = './this.program';
  4804. Module['quit'] = function(status, toThrow) {
  4805. throw toThrow;
  4806. };
  4807. Module['preRun'] = [];
  4808. Module['postRun'] = [];
  4809. // Determine the runtime environment we are in. You can customize this by
  4810. // setting the ENVIRONMENT setting at compile time (see settings.js).
  4811. var ENVIRONMENT_IS_WEB = false;
  4812. var ENVIRONMENT_IS_WORKER = false;
  4813. var ENVIRONMENT_IS_NODE = false;
  4814. var ENVIRONMENT_HAS_NODE = false;
  4815. var ENVIRONMENT_IS_SHELL = false;
  4816. ENVIRONMENT_IS_WEB = typeof window === 'object';
  4817. ENVIRONMENT_IS_WORKER = typeof importScripts === 'function';
  4818. // A web environment like Electron.js can have Node enabled, so we must
  4819. // distinguish between Node-enabled environments and Node environments per se.
  4820. // This will allow the former to do things like mount NODEFS.
  4821. ENVIRONMENT_HAS_NODE = typeof process === 'object' && typeof require === 'function';
  4822. ENVIRONMENT_IS_NODE = ENVIRONMENT_HAS_NODE && !ENVIRONMENT_IS_WEB && !ENVIRONMENT_IS_WORKER;
  4823. ENVIRONMENT_IS_SHELL = !ENVIRONMENT_IS_WEB && !ENVIRONMENT_IS_NODE && !ENVIRONMENT_IS_WORKER;
  4824. if (Module['ENVIRONMENT']) {
  4825. 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)');
  4826. }
  4827. // Three configurations we can be running in:
  4828. // 1) We could be the application main() thread running in the main JS UI thread. (ENVIRONMENT_IS_WORKER == false and ENVIRONMENT_IS_PTHREAD == false)
  4829. // 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)
  4830. // 3) We could be an application pthread running in a worker. (ENVIRONMENT_IS_WORKER == true and ENVIRONMENT_IS_PTHREAD == true)
  4831. // `/` should be present at the end if `scriptDirectory` is not empty
  4832. var scriptDirectory = '';
  4833. function locateFile(path) {
  4834. if (Module['locateFile']) {
  4835. return Module['locateFile'](path, scriptDirectory);
  4836. } else {
  4837. return scriptDirectory + path;
  4838. }
  4839. }
  4840. if (ENVIRONMENT_IS_NODE) {
  4841. scriptDirectory = __dirname + '/';
  4842. // Expose functionality in the same simple way that the shells work
  4843. // Note that we pollute the global namespace here, otherwise we break in node
  4844. var nodeFS;
  4845. var nodePath;
  4846. Module['read'] = function shell_read(filename, binary) {
  4847. var ret;
  4848. if (!nodeFS) nodeFS = require('fs');
  4849. if (!nodePath) nodePath = require('path');
  4850. filename = nodePath['normalize'](filename);
  4851. ret = nodeFS['readFileSync'](filename);
  4852. return binary ? ret : ret.toString();
  4853. };
  4854. Module['readBinary'] = function readBinary(filename) {
  4855. var ret = Module['read'](filename, true);
  4856. if (!ret.buffer) {
  4857. ret = new Uint8Array(ret);
  4858. }
  4859. assert$1(ret.buffer);
  4860. return ret;
  4861. };
  4862. if (process['argv'].length > 1) {
  4863. Module['thisProgram'] = process['argv'][1].replace(/\\/g, '/');
  4864. }
  4865. Module['arguments'] = process['argv'].slice(2);
  4866. if (typeof module !== 'undefined') {
  4867. module['exports'] = Module;
  4868. }
  4869. process['on']('uncaughtException', function(ex) {
  4870. // suppress ExitStatus exceptions from showing an error
  4871. if (!(ex instanceof ExitStatus)) {
  4872. throw ex;
  4873. }
  4874. });
  4875. // Currently node will swallow unhandled rejections, but this behavior is
  4876. // deprecated, and in the future it will exit with error status.
  4877. process['on']('unhandledRejection', abort);
  4878. Module['quit'] = function(status) {
  4879. process['exit'](status);
  4880. };
  4881. Module['inspect'] = function () { return '[Emscripten Module object]'; };
  4882. } else
  4883. if (ENVIRONMENT_IS_SHELL) {
  4884. if (typeof read != 'undefined') {
  4885. Module['read'] = function shell_read(f) {
  4886. return read(f);
  4887. };
  4888. }
  4889. Module['readBinary'] = function readBinary(f) {
  4890. var data;
  4891. if (typeof readbuffer === 'function') {
  4892. return new Uint8Array(readbuffer(f));
  4893. }
  4894. data = read(f, 'binary');
  4895. assert$1(typeof data === 'object');
  4896. return data;
  4897. };
  4898. if (typeof scriptArgs != 'undefined') {
  4899. Module['arguments'] = scriptArgs;
  4900. } else if (typeof arguments != 'undefined') {
  4901. Module['arguments'] = arguments;
  4902. }
  4903. if (typeof quit === 'function') {
  4904. Module['quit'] = function(status) {
  4905. quit(status);
  4906. };
  4907. }
  4908. } else
  4909. if (ENVIRONMENT_IS_WEB || ENVIRONMENT_IS_WORKER) {
  4910. if (ENVIRONMENT_IS_WORKER) { // Check worker, not web, since window could be polyfilled
  4911. scriptDirectory = self.location.href;
  4912. } else if (document.currentScript) { // web
  4913. scriptDirectory = document.currentScript.src;
  4914. }
  4915. // blob urls look like blob:http://site.com/etc/etc and we cannot infer anything from them.
  4916. // otherwise, slice off the final part of the url to find the script directory.
  4917. // if scriptDirectory does not contain a slash, lastIndexOf will return -1,
  4918. // and scriptDirectory will correctly be replaced with an empty string.
  4919. if (scriptDirectory.indexOf('blob:') !== 0) {
  4920. scriptDirectory = scriptDirectory.substr(0, scriptDirectory.lastIndexOf('/')+1);
  4921. } else {
  4922. scriptDirectory = '';
  4923. }
  4924. Module['read'] = function shell_read(url) {
  4925. var xhr = new XMLHttpRequest();
  4926. xhr.open('GET', url, false);
  4927. xhr.send(null);
  4928. return xhr.responseText;
  4929. };
  4930. if (ENVIRONMENT_IS_WORKER) {
  4931. Module['readBinary'] = function readBinary(url) {
  4932. var xhr = new XMLHttpRequest();
  4933. xhr.open('GET', url, false);
  4934. xhr.responseType = 'arraybuffer';
  4935. xhr.send(null);
  4936. return new Uint8Array(xhr.response);
  4937. };
  4938. }
  4939. Module['readAsync'] = function readAsync(url, onload, onerror) {
  4940. var xhr = new XMLHttpRequest();
  4941. xhr.open('GET', url, true);
  4942. xhr.responseType = 'arraybuffer';
  4943. xhr.onload = function xhr_onload() {
  4944. if (xhr.status == 200 || (xhr.status == 0 && xhr.response)) { // file URLs can return 0
  4945. onload(xhr.response);
  4946. return;
  4947. }
  4948. onerror();
  4949. };
  4950. xhr.onerror = onerror;
  4951. xhr.send(null);
  4952. };
  4953. Module['setWindowTitle'] = function(title) { document.title = title; };
  4954. } else
  4955. {
  4956. throw new Error('environment detection error');
  4957. }
  4958. // Set up the out() and err() hooks, which are how we can print to stdout or
  4959. // stderr, respectively.
  4960. // If the user provided Module.print or printErr, use that. Otherwise,
  4961. // console.log is checked first, as 'print' on the web will open a print dialogue
  4962. // printErr is preferable to console.warn (works better in shells)
  4963. // bind(console) is necessary to fix IE/Edge closed dev tools panel behavior.
  4964. var out = Module['print'] || (typeof console !== 'undefined' ? console.log.bind(console) : (typeof print !== 'undefined' ? print : null));
  4965. var err = Module['printErr'] || (typeof printErr !== 'undefined' ? printErr : ((typeof console !== 'undefined' && console.warn.bind(console)) || out));
  4966. // Merge back in the overrides
  4967. for (key in moduleOverrides) {
  4968. if (moduleOverrides.hasOwnProperty(key)) {
  4969. Module[key] = moduleOverrides[key];
  4970. }
  4971. }
  4972. // Free the object hierarchy contained in the overrides, this lets the GC
  4973. // reclaim data used e.g. in memoryInitializerRequest, which is a large typed array.
  4974. moduleOverrides = undefined;
  4975. // perform assertions in shell.js after we set up out() and err(), as otherwise if an assertion fails it cannot print the message
  4976. assert$1(typeof Module['memoryInitializerPrefixURL'] === 'undefined', 'Module.memoryInitializerPrefixURL option was removed, use Module.locateFile instead');
  4977. assert$1(typeof Module['pthreadMainPrefixURL'] === 'undefined', 'Module.pthreadMainPrefixURL option was removed, use Module.locateFile instead');
  4978. assert$1(typeof Module['cdInitializerPrefixURL'] === 'undefined', 'Module.cdInitializerPrefixURL option was removed, use Module.locateFile instead');
  4979. assert$1(typeof Module['filePackagePrefixURL'] === 'undefined', 'Module.filePackagePrefixURL option was removed, use Module.locateFile instead');
  4980. // stack management, and other functionality that is provided by the compiled code,
  4981. // should not be used before it is ready
  4982. stackSave = stackRestore = stackAlloc = function() {
  4983. abort('cannot use the stack before compiled code is ready to run, and has provided stack access');
  4984. };
  4985. function warnOnce(text) {
  4986. if (!warnOnce.shown) warnOnce.shown = {};
  4987. if (!warnOnce.shown[text]) {
  4988. warnOnce.shown[text] = 1;
  4989. //err(text);
  4990. }
  4991. }
  4992. var asm2wasmImports = { // special asm2wasm imports
  4993. "f64-rem": function(x, y) {
  4994. return x % y;
  4995. },
  4996. "debugger": function() {
  4997. debugger;
  4998. }
  4999. };
  5000. var functionPointers = new Array(0);
  5001. var tempRet0 = 0;
  5002. var setTempRet0 = function(value) {
  5003. tempRet0 = value;
  5004. };
  5005. var getTempRet0 = function() {
  5006. return tempRet0;
  5007. };
  5008. // === Preamble library stuff ===
  5009. // Documentation for the public APIs defined in this file must be updated in:
  5010. // site/source/docs/api_reference/preamble.js.rst
  5011. // A prebuilt local version of the documentation is available at:
  5012. // site/build/text/docs/api_reference/preamble.js.txt
  5013. // You can also build docs locally as HTML or other formats in site/
  5014. // An online HTML version (which may be of a different version of Emscripten)
  5015. // is up at http://kripken.github.io/emscripten-site/docs/api_reference/preamble.js.html
  5016. if (typeof WebAssembly !== 'object') {
  5017. abort('No WebAssembly support found. Build with -s WASM=0 to target JavaScript instead.');
  5018. }
  5019. /** @type {function(number, string, boolean=)} */
  5020. function getValue(ptr, type, noSafe) {
  5021. type = type || 'i8';
  5022. if (type.charAt(type.length-1) === '*') type = 'i32'; // pointers are 32-bit
  5023. switch(type) {
  5024. case 'i1': return HEAP8[((ptr)>>0)];
  5025. case 'i8': return HEAP8[((ptr)>>0)];
  5026. case 'i16': return HEAP16[((ptr)>>1)];
  5027. case 'i32': return HEAP32[((ptr)>>2)];
  5028. case 'i64': return HEAP32[((ptr)>>2)];
  5029. case 'float': return HEAPF32[((ptr)>>2)];
  5030. case 'double': return HEAPF64[((ptr)>>3)];
  5031. default: abort('invalid type for getValue: ' + type);
  5032. }
  5033. return null;
  5034. }
  5035. // Wasm globals
  5036. var wasmMemory;
  5037. // Potentially used for direct table calls.
  5038. var wasmTable;
  5039. //========================================
  5040. // Runtime essentials
  5041. //========================================
  5042. // whether we are quitting the application. no code should run after this.
  5043. // set in exit() and abort()
  5044. var ABORT = false;
  5045. /** @type {function(*, string=)} */
  5046. function assert$1(condition, text) {
  5047. if (!condition) {
  5048. abort('Assertion failed: ' + text);
  5049. }
  5050. }
  5051. // Returns the C function with a specified identifier (for C++, you need to do manual name mangling)
  5052. function getCFunc(ident) {
  5053. var func = Module['_' + ident]; // closure exported function
  5054. assert$1(func, 'Cannot call unknown function ' + ident + ', make sure it is exported');
  5055. return func;
  5056. }
  5057. // C calling interface.
  5058. function ccall(ident, returnType, argTypes, args, opts) {
  5059. // For fast lookup of conversion functions
  5060. var toC = {
  5061. 'string': function(str) {
  5062. var ret = 0;
  5063. if (str !== null && str !== undefined && str !== 0) { // null string
  5064. // at most 4 bytes per UTF-8 code point, +1 for the trailing '\0'
  5065. var len = (str.length << 2) + 1;
  5066. ret = stackAlloc(len);
  5067. stringToUTF8(str, ret, len);
  5068. }
  5069. return ret;
  5070. },
  5071. 'array': function(arr) {
  5072. var ret = stackAlloc(arr.length);
  5073. writeArrayToMemory(arr, ret);
  5074. return ret;
  5075. }
  5076. };
  5077. function convertReturnValue(ret) {
  5078. if (returnType === 'string') return UTF8ToString(ret);
  5079. if (returnType === 'boolean') return Boolean(ret);
  5080. return ret;
  5081. }
  5082. var func = getCFunc(ident);
  5083. var cArgs = [];
  5084. var stack = 0;
  5085. assert$1(returnType !== 'array', 'Return type should not be "array".');
  5086. if (args) {
  5087. for (var i = 0; i < args.length; i++) {
  5088. var converter = toC[argTypes[i]];
  5089. if (converter) {
  5090. if (stack === 0) stack = stackSave();
  5091. cArgs[i] = converter(args[i]);
  5092. } else {
  5093. cArgs[i] = args[i];
  5094. }
  5095. }
  5096. }
  5097. var ret = func.apply(null, cArgs);
  5098. ret = convertReturnValue(ret);
  5099. if (stack !== 0) stackRestore(stack);
  5100. return ret;
  5101. }
  5102. function cwrap(ident, returnType, argTypes, opts) {
  5103. return function() {
  5104. return ccall(ident, returnType, argTypes, arguments);
  5105. }
  5106. }
  5107. // Given a pointer 'ptr' to a null-terminated UTF8-encoded string in the given array that contains uint8 values, returns
  5108. // a copy of that string as a Javascript String object.
  5109. var UTF8Decoder = typeof TextDecoder !== 'undefined' ? new TextDecoder('utf8') : undefined;
  5110. /**
  5111. * @param {number} idx
  5112. * @param {number=} maxBytesToRead
  5113. * @return {string}
  5114. */
  5115. function UTF8ArrayToString(u8Array, idx, maxBytesToRead) {
  5116. var endIdx = idx + maxBytesToRead;
  5117. var endPtr = idx;
  5118. // TextDecoder needs to know the byte length in advance, it doesn't stop on null terminator by itself.
  5119. // Also, use the length info to avoid running tiny strings through TextDecoder, since .subarray() allocates garbage.
  5120. // (As a tiny code save trick, compare endPtr against endIdx using a negation, so that undefined means Infinity)
  5121. while (u8Array[endPtr] && !(endPtr >= endIdx)) ++endPtr;
  5122. if (endPtr - idx > 16 && u8Array.subarray && UTF8Decoder) {
  5123. return UTF8Decoder.decode(u8Array.subarray(idx, endPtr));
  5124. } else {
  5125. var str = '';
  5126. // If building with TextDecoder, we have already computed the string length above, so test loop end condition against that
  5127. while (idx < endPtr) {
  5128. // For UTF8 byte structure, see:
  5129. // http://en.wikipedia.org/wiki/UTF-8#Description
  5130. // https://www.ietf.org/rfc/rfc2279.txt
  5131. // https://tools.ietf.org/html/rfc3629
  5132. var u0 = u8Array[idx++];
  5133. if (!(u0 & 0x80)) { str += String.fromCharCode(u0); continue; }
  5134. var u1 = u8Array[idx++] & 63;
  5135. if ((u0 & 0xE0) == 0xC0) { str += String.fromCharCode(((u0 & 31) << 6) | u1); continue; }
  5136. var u2 = u8Array[idx++] & 63;
  5137. if ((u0 & 0xF0) == 0xE0) {
  5138. u0 = ((u0 & 15) << 12) | (u1 << 6) | u2;
  5139. } else {
  5140. 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!');
  5141. u0 = ((u0 & 7) << 18) | (u1 << 12) | (u2 << 6) | (u8Array[idx++] & 63);
  5142. }
  5143. if (u0 < 0x10000) {
  5144. str += String.fromCharCode(u0);
  5145. } else {
  5146. var ch = u0 - 0x10000;
  5147. str += String.fromCharCode(0xD800 | (ch >> 10), 0xDC00 | (ch & 0x3FF));
  5148. }
  5149. }
  5150. }
  5151. return str;
  5152. }
  5153. // Given a pointer 'ptr' to a null-terminated UTF8-encoded string in the emscripten HEAP, returns a
  5154. // copy of that string as a Javascript String object.
  5155. // maxBytesToRead: an optional length that specifies the maximum number of bytes to read. You can omit
  5156. // this parameter to scan the string until the first \0 byte. If maxBytesToRead is
  5157. // passed, and the string at [ptr, ptr+maxBytesToReadr[ contains a null byte in the
  5158. // middle, then the string will cut short at that byte index (i.e. maxBytesToRead will
  5159. // not produce a string of exact length [ptr, ptr+maxBytesToRead[)
  5160. // N.B. mixing frequent uses of UTF8ToString() with and without maxBytesToRead may
  5161. // throw JS JIT optimizations off, so it is worth to consider consistently using one
  5162. // style or the other.
  5163. /**
  5164. * @param {number} ptr
  5165. * @param {number=} maxBytesToRead
  5166. * @return {string}
  5167. */
  5168. function UTF8ToString(ptr, maxBytesToRead) {
  5169. return ptr ? UTF8ArrayToString(HEAPU8, ptr, maxBytesToRead) : '';
  5170. }
  5171. // Copies the given Javascript String object 'str' to the given byte array at address 'outIdx',
  5172. // encoded in UTF8 form and null-terminated. The copy will require at most str.length*4+1 bytes of space in the HEAP.
  5173. // Use the function lengthBytesUTF8 to compute the exact number of bytes (excluding null terminator) that this function will write.
  5174. // Parameters:
  5175. // str: the Javascript string to copy.
  5176. // outU8Array: the array to copy to. Each index in this array is assumed to be one 8-byte element.
  5177. // outIdx: The starting offset in the array to begin the copying.
  5178. // maxBytesToWrite: The maximum number of bytes this function can write to the array.
  5179. // This count should include the null terminator,
  5180. // i.e. if maxBytesToWrite=1, only the null terminator will be written and nothing else.
  5181. // maxBytesToWrite=0 does not write any bytes to the output, not even the null terminator.
  5182. // Returns the number of bytes written, EXCLUDING the null terminator.
  5183. function stringToUTF8Array(str, outU8Array, outIdx, maxBytesToWrite) {
  5184. if (!(maxBytesToWrite > 0)) // Parameter maxBytesToWrite is not optional. Negative values, 0, null, undefined and false each don't write out any bytes.
  5185. return 0;
  5186. var startIdx = outIdx;
  5187. var endIdx = outIdx + maxBytesToWrite - 1; // -1 for string null terminator.
  5188. for (var i = 0; i < str.length; ++i) {
  5189. // 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.
  5190. // See http://unicode.org/faq/utf_bom.html#utf16-3
  5191. // 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
  5192. var u = str.charCodeAt(i); // possibly a lead surrogate
  5193. if (u >= 0xD800 && u <= 0xDFFF) {
  5194. var u1 = str.charCodeAt(++i);
  5195. u = 0x10000 + ((u & 0x3FF) << 10) | (u1 & 0x3FF);
  5196. }
  5197. if (u <= 0x7F) {
  5198. if (outIdx >= endIdx) break;
  5199. outU8Array[outIdx++] = u;
  5200. } else if (u <= 0x7FF) {
  5201. if (outIdx + 1 >= endIdx) break;
  5202. outU8Array[outIdx++] = 0xC0 | (u >> 6);
  5203. outU8Array[outIdx++] = 0x80 | (u & 63);
  5204. } else if (u <= 0xFFFF) {
  5205. if (outIdx + 2 >= endIdx) break;
  5206. outU8Array[outIdx++] = 0xE0 | (u >> 12);
  5207. outU8Array[outIdx++] = 0x80 | ((u >> 6) & 63);
  5208. outU8Array[outIdx++] = 0x80 | (u & 63);
  5209. } else {
  5210. if (outIdx + 3 >= endIdx) break;
  5211. 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).');
  5212. outU8Array[outIdx++] = 0xF0 | (u >> 18);
  5213. outU8Array[outIdx++] = 0x80 | ((u >> 12) & 63);
  5214. outU8Array[outIdx++] = 0x80 | ((u >> 6) & 63);
  5215. outU8Array[outIdx++] = 0x80 | (u & 63);
  5216. }
  5217. }
  5218. // Null-terminate the pointer to the buffer.
  5219. outU8Array[outIdx] = 0;
  5220. return outIdx - startIdx;
  5221. }
  5222. // Copies the given Javascript String object 'str' to the emscripten HEAP at address 'outPtr',
  5223. // null-terminated and encoded in UTF8 form. The copy will require at most str.length*4+1 bytes of space in the HEAP.
  5224. // Use the function lengthBytesUTF8 to compute the exact number of bytes (excluding null terminator) that this function will write.
  5225. // Returns the number of bytes written, EXCLUDING the null terminator.
  5226. function stringToUTF8(str, outPtr, maxBytesToWrite) {
  5227. assert$1(typeof maxBytesToWrite == 'number', 'stringToUTF8(str, outPtr, maxBytesToWrite) is missing the third parameter that specifies the length of the output buffer!');
  5228. return stringToUTF8Array(str, HEAPU8,outPtr, maxBytesToWrite);
  5229. }
  5230. // Given a pointer 'ptr' to a null-terminated UTF16LE-encoded string in the emscripten HEAP, returns
  5231. // a copy of that string as a Javascript String object.
  5232. var UTF16Decoder = typeof TextDecoder !== 'undefined' ? new TextDecoder('utf-16le') : undefined;
  5233. function writeArrayToMemory(array, buffer) {
  5234. assert$1(array.length >= 0, 'writeArrayToMemory array must have a length (should be an array or typed array)');
  5235. HEAP8.set(array, buffer);
  5236. }
  5237. function demangle(func) {
  5238. return func;
  5239. }
  5240. function demangleAll(text) {
  5241. var regex =
  5242. /__Z[\w\d_]+/g;
  5243. return text.replace(regex,
  5244. function(x) {
  5245. var y = demangle(x);
  5246. return x === y ? x : (y + ' [' + x + ']');
  5247. });
  5248. }
  5249. function jsStackTrace() {
  5250. var err = new Error();
  5251. if (!err.stack) {
  5252. // IE10+ special cases: It does have callstack info, but it is only populated if an Error object is thrown,
  5253. // so try that as a special-case.
  5254. try {
  5255. throw new Error(0);
  5256. } catch(e) {
  5257. err = e;
  5258. }
  5259. if (!err.stack) {
  5260. return '(no stack trace available)';
  5261. }
  5262. }
  5263. return err.stack.toString();
  5264. }
  5265. function stackTrace() {
  5266. var js = jsStackTrace();
  5267. if (Module['extraStackTrace']) js += '\n' + Module['extraStackTrace']();
  5268. return demangleAll(js);
  5269. }
  5270. var WASM_PAGE_SIZE = 65536;
  5271. function alignUp(x, multiple) {
  5272. if (x % multiple > 0) {
  5273. x += multiple - (x % multiple);
  5274. }
  5275. return x;
  5276. }
  5277. var /** @type {ArrayBuffer} */
  5278. buffer,
  5279. /** @type {Int8Array} */
  5280. HEAP8,
  5281. /** @type {Uint8Array} */
  5282. HEAPU8,
  5283. /** @type {Int16Array} */
  5284. HEAP16,
  5285. /** @type {Uint16Array} */
  5286. HEAPU16,
  5287. /** @type {Int32Array} */
  5288. HEAP32,
  5289. /** @type {Uint32Array} */
  5290. HEAPU32,
  5291. /** @type {Float32Array} */
  5292. HEAPF32,
  5293. /** @type {Float64Array} */
  5294. HEAPF64;
  5295. function updateGlobalBufferViews() {
  5296. Module['HEAP8'] = HEAP8 = new Int8Array(buffer);
  5297. Module['HEAP16'] = HEAP16 = new Int16Array(buffer);
  5298. Module['HEAP32'] = HEAP32 = new Int32Array(buffer);
  5299. Module['HEAPU8'] = HEAPU8 = new Uint8Array(buffer);
  5300. Module['HEAPU16'] = HEAPU16 = new Uint16Array(buffer);
  5301. Module['HEAPU32'] = HEAPU32 = new Uint32Array(buffer);
  5302. Module['HEAPF32'] = HEAPF32 = new Float32Array(buffer);
  5303. Module['HEAPF64'] = HEAPF64 = new Float64Array(buffer);
  5304. }
  5305. var STACK_BASE = 5872,
  5306. STACK_MAX = 5248752,
  5307. DYNAMIC_BASE = 5248752,
  5308. DYNAMICTOP_PTR = 5840;
  5309. assert$1(STACK_BASE % 16 === 0, 'stack must start aligned');
  5310. assert$1(DYNAMIC_BASE % 16 === 0, 'heap must start aligned');
  5311. var TOTAL_STACK = 5242880;
  5312. if (Module['TOTAL_STACK']) assert$1(TOTAL_STACK === Module['TOTAL_STACK'], 'the stack size can no longer be determined at runtime');
  5313. var INITIAL_TOTAL_MEMORY = Module['TOTAL_MEMORY'] || 16777216;
  5314. if (INITIAL_TOTAL_MEMORY < TOTAL_STACK) err('TOTAL_MEMORY should be larger than TOTAL_STACK, was ' + INITIAL_TOTAL_MEMORY + '! (TOTAL_STACK=' + TOTAL_STACK + ')');
  5315. // Initialize the runtime's memory
  5316. // check for full engine support (use string 'subarray' to avoid closure compiler confusion)
  5317. assert$1(typeof Int32Array !== 'undefined' && typeof Float64Array !== 'undefined' && Int32Array.prototype.subarray !== undefined && Int32Array.prototype.set !== undefined,
  5318. 'JS engine does not provide full typed array support');
  5319. // Use a provided buffer, if there is one, or else allocate a new one
  5320. if (Module['buffer']) {
  5321. buffer = Module['buffer'];
  5322. assert$1(buffer.byteLength === INITIAL_TOTAL_MEMORY, 'provided buffer should be ' + INITIAL_TOTAL_MEMORY + ' bytes, but it is ' + buffer.byteLength);
  5323. } else {
  5324. // Use a WebAssembly memory where available
  5325. if (typeof WebAssembly === 'object' && typeof WebAssembly.Memory === 'function') {
  5326. assert$1(INITIAL_TOTAL_MEMORY % WASM_PAGE_SIZE === 0);
  5327. wasmMemory = new WebAssembly.Memory({ 'initial': INITIAL_TOTAL_MEMORY / WASM_PAGE_SIZE });
  5328. buffer = wasmMemory.buffer;
  5329. } else
  5330. {
  5331. buffer = new ArrayBuffer(INITIAL_TOTAL_MEMORY);
  5332. }
  5333. assert$1(buffer.byteLength === INITIAL_TOTAL_MEMORY);
  5334. }
  5335. updateGlobalBufferViews();
  5336. HEAP32[DYNAMICTOP_PTR>>2] = DYNAMIC_BASE;
  5337. // Initializes the stack cookie. Called at the startup of main and at the startup of each thread in pthreads mode.
  5338. function writeStackCookie() {
  5339. assert$1((STACK_MAX & 3) == 0);
  5340. HEAPU32[(STACK_MAX >> 2)-1] = 0x02135467;
  5341. HEAPU32[(STACK_MAX >> 2)-2] = 0x89BACDFE;
  5342. }
  5343. function checkStackCookie() {
  5344. if (HEAPU32[(STACK_MAX >> 2)-1] != 0x02135467 || HEAPU32[(STACK_MAX >> 2)-2] != 0x89BACDFE) {
  5345. 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));
  5346. }
  5347. // Also test the global address 0 for integrity.
  5348. if (HEAP32[0] !== 0x63736d65 /* 'emsc' */) abort('Runtime error: The application has corrupted its heap memory area (address zero)!');
  5349. }
  5350. function abortStackOverflow(allocSize) {
  5351. abort('Stack overflow! Attempted to allocate ' + allocSize + ' bytes on the stack, but stack has only ' + (STACK_MAX - stackSave() + allocSize) + ' bytes available!');
  5352. }
  5353. HEAP32[0] = 0x63736d65; /* 'emsc' */
  5354. // Endianness check (note: assumes compiler arch was little-endian)
  5355. HEAP16[1] = 0x6373;
  5356. if (HEAPU8[2] !== 0x73 || HEAPU8[3] !== 0x63) throw 'Runtime error: expected the system to be little-endian!';
  5357. function callRuntimeCallbacks(callbacks) {
  5358. while(callbacks.length > 0) {
  5359. var callback = callbacks.shift();
  5360. if (typeof callback == 'function') {
  5361. callback();
  5362. continue;
  5363. }
  5364. var func = callback.func;
  5365. if (typeof func === 'number') {
  5366. if (callback.arg === undefined) {
  5367. Module['dynCall_v'](func);
  5368. } else {
  5369. Module['dynCall_vi'](func, callback.arg);
  5370. }
  5371. } else {
  5372. func(callback.arg === undefined ? null : callback.arg);
  5373. }
  5374. }
  5375. }
  5376. var __ATPRERUN__ = []; // functions called before the runtime is initialized
  5377. var __ATINIT__ = []; // functions called during startup
  5378. var __ATMAIN__ = []; // functions called when main() is to be run
  5379. var __ATPOSTRUN__ = []; // functions called after the main() is called
  5380. var runtimeInitialized = false;
  5381. var runtimeExited = false;
  5382. function preRun() {
  5383. // compatibility - merge in anything from Module['preRun'] at this time
  5384. if (Module['preRun']) {
  5385. if (typeof Module['preRun'] == 'function') Module['preRun'] = [Module['preRun']];
  5386. while (Module['preRun'].length) {
  5387. addOnPreRun(Module['preRun'].shift());
  5388. }
  5389. }
  5390. callRuntimeCallbacks(__ATPRERUN__);
  5391. }
  5392. function ensureInitRuntime() {
  5393. checkStackCookie();
  5394. if (runtimeInitialized) return;
  5395. runtimeInitialized = true;
  5396. callRuntimeCallbacks(__ATINIT__);
  5397. }
  5398. function preMain() {
  5399. checkStackCookie();
  5400. callRuntimeCallbacks(__ATMAIN__);
  5401. }
  5402. function postRun() {
  5403. checkStackCookie();
  5404. // compatibility - merge in anything from Module['postRun'] at this time
  5405. if (Module['postRun']) {
  5406. if (typeof Module['postRun'] == 'function') Module['postRun'] = [Module['postRun']];
  5407. while (Module['postRun'].length) {
  5408. addOnPostRun(Module['postRun'].shift());
  5409. }
  5410. }
  5411. callRuntimeCallbacks(__ATPOSTRUN__);
  5412. }
  5413. function addOnPreRun(cb) {
  5414. __ATPRERUN__.unshift(cb);
  5415. }
  5416. function addOnPostRun(cb) {
  5417. __ATPOSTRUN__.unshift(cb);
  5418. }
  5419. assert$1(Math.imul, 'This browser does not support Math.imul(), build with LEGACY_VM_SUPPORT or POLYFILL_OLD_MATH_FUNCTIONS to add in a polyfill');
  5420. assert$1(Math.fround, 'This browser does not support Math.fround(), build with LEGACY_VM_SUPPORT or POLYFILL_OLD_MATH_FUNCTIONS to add in a polyfill');
  5421. assert$1(Math.clz32, 'This browser does not support Math.clz32(), build with LEGACY_VM_SUPPORT or POLYFILL_OLD_MATH_FUNCTIONS to add in a polyfill');
  5422. assert$1(Math.trunc, 'This browser does not support Math.trunc(), build with LEGACY_VM_SUPPORT or POLYFILL_OLD_MATH_FUNCTIONS to add in a polyfill');
  5423. // A counter of dependencies for calling run(). If we need to
  5424. // do asynchronous work before running, increment this and
  5425. // decrement it. Incrementing must happen in a place like
  5426. // Module.preRun (used by emcc to add file preloading).
  5427. // Note that you can add dependencies in preRun, even though
  5428. // it happens right before run - run will be postponed until
  5429. // the dependencies are met.
  5430. var runDependencies = 0;
  5431. var runDependencyWatcher = null;
  5432. var dependenciesFulfilled = null; // overridden to take different actions when all run dependencies are fulfilled
  5433. var runDependencyTracking = {};
  5434. function addRunDependency(id) {
  5435. runDependencies++;
  5436. if (Module['monitorRunDependencies']) {
  5437. Module['monitorRunDependencies'](runDependencies);
  5438. }
  5439. if (id) {
  5440. assert$1(!runDependencyTracking[id]);
  5441. runDependencyTracking[id] = 1;
  5442. if (runDependencyWatcher === null && typeof setInterval !== 'undefined') {
  5443. // Check for missing dependencies every few seconds
  5444. runDependencyWatcher = setInterval(function() {
  5445. if (ABORT) {
  5446. clearInterval(runDependencyWatcher);
  5447. runDependencyWatcher = null;
  5448. return;
  5449. }
  5450. }, 10000);
  5451. }
  5452. }
  5453. }
  5454. function removeRunDependency(id) {
  5455. runDependencies--;
  5456. if (Module['monitorRunDependencies']) {
  5457. Module['monitorRunDependencies'](runDependencies);
  5458. }
  5459. if (id) {
  5460. assert$1(runDependencyTracking[id]);
  5461. delete runDependencyTracking[id];
  5462. }
  5463. if (runDependencies == 0) {
  5464. if (runDependencyWatcher !== null) {
  5465. clearInterval(runDependencyWatcher);
  5466. runDependencyWatcher = null;
  5467. }
  5468. if (dependenciesFulfilled) {
  5469. var callback = dependenciesFulfilled;
  5470. dependenciesFulfilled = null;
  5471. callback(); // can add another dependenciesFulfilled
  5472. }
  5473. }
  5474. }
  5475. Module["preloadedImages"] = {}; // maps url to image data
  5476. Module["preloadedAudios"] = {}; // maps url to audio data
  5477. // show errors on likely calls to FS when it was not included
  5478. var FS = {
  5479. error: function() {
  5480. 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');
  5481. },
  5482. init: function() { FS.error(); },
  5483. createDataFile: function() { FS.error(); },
  5484. createPreloadedFile: function() { FS.error(); },
  5485. createLazyFile: function() { FS.error(); },
  5486. open: function() { FS.error(); },
  5487. mkdev: function() { FS.error(); },
  5488. registerDevice: function() { FS.error(); },
  5489. analyzePath: function() { FS.error(); },
  5490. loadFilesFromDB: function() { FS.error(); },
  5491. ErrnoError: function ErrnoError() { FS.error(); },
  5492. };
  5493. Module['FS_createDataFile'] = FS.createDataFile;
  5494. Module['FS_createPreloadedFile'] = FS.createPreloadedFile;
  5495. // Copyright 2017 The Emscripten Authors. All rights reserved.
  5496. // Emscripten is available under two separate licenses, the MIT license and the
  5497. // University of Illinois/NCSA Open Source License. Both these licenses can be
  5498. // found in the LICENSE file.
  5499. // Prefix of data URIs emitted by SINGLE_FILE and related options.
  5500. var dataURIPrefix = 'data:application/octet-stream;base64,';
  5501. // Indicates whether filename is a base64 data URI.
  5502. function isDataURI(filename) {
  5503. return String.prototype.startsWith ?
  5504. filename.startsWith(dataURIPrefix) :
  5505. filename.indexOf(dataURIPrefix) === 0;
  5506. }
  5507. var wasmBinaryFile = 'ThirdParty/earcut.wasm';
  5508. if (!isDataURI(wasmBinaryFile)) {
  5509. wasmBinaryFile = locateFile(wasmBinaryFile);
  5510. }
  5511. function getBinary() {
  5512. try {
  5513. if (Module['wasmBinary']) {
  5514. return new Uint8Array(Module['wasmBinary']);
  5515. }
  5516. if (Module['readBinary']) {
  5517. return Module['readBinary'](wasmBinaryFile);
  5518. } else {
  5519. throw "both async and sync fetching of the wasm failed";
  5520. }
  5521. }
  5522. catch (err) {
  5523. abort(err);
  5524. }
  5525. }
  5526. function getBinaryPromise() {
  5527. // if we don't have the binary yet, and have the Fetch api, use that
  5528. // 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
  5529. if (!Module['wasmBinary'] && (ENVIRONMENT_IS_WEB || ENVIRONMENT_IS_WORKER) && typeof fetch === 'function') {
  5530. return fetch(wasmBinaryFile, { credentials: 'same-origin' }).then(function(response) {
  5531. if (!response['ok']) {
  5532. throw "failed to load wasm binary file at '" + wasmBinaryFile + "'";
  5533. }
  5534. return response['arrayBuffer']();
  5535. }).catch(function () {
  5536. return getBinary();
  5537. });
  5538. }
  5539. // Otherwise, getBinary should be able to get it synchronously
  5540. return new Promise(function(resolve, reject) {
  5541. resolve(getBinary());
  5542. });
  5543. }
  5544. // Create the wasm instance.
  5545. // Receives the wasm imports, returns the exports.
  5546. function createWasm(env) {
  5547. // prepare imports
  5548. var info = {
  5549. 'env': env
  5550. ,
  5551. 'global': {
  5552. 'NaN': NaN,
  5553. 'Infinity': Infinity
  5554. },
  5555. 'global.Math': Math,
  5556. 'asm2wasm': asm2wasmImports
  5557. };
  5558. // Load the wasm module and create an instance of using native support in the JS engine.
  5559. // handle a generated wasm instance, receiving its exports and
  5560. // performing other necessary setup
  5561. function receiveInstance(instance, module) {
  5562. var exports = instance.exports;
  5563. Module['asm'] = exports;
  5564. removeRunDependency('wasm-instantiate');
  5565. }
  5566. addRunDependency('wasm-instantiate');
  5567. // Async compilation can be confusing when an error on the page overwrites Module
  5568. // (for example, if the order of elements is wrong, and the one defining Module is
  5569. // later), so we save Module and check it later.
  5570. var trueModule = Module;
  5571. function receiveInstantiatedSource(output) {
  5572. // 'output' is a WebAssemblyInstantiatedSource object which has both the module and instance.
  5573. // receiveInstance() will swap in the exports (to Module.asm) so they can be called
  5574. assert$1(Module === trueModule, 'the Module object should not be replaced during async compilation - perhaps the order of HTML elements is wrong?');
  5575. trueModule = null;
  5576. // 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.
  5577. // When the regression is fixed, can restore the above USE_PTHREADS-enabled path.
  5578. receiveInstance(output['instance']);
  5579. }
  5580. function instantiateArrayBuffer(receiver) {
  5581. return getBinaryPromise().then(function(binary) {
  5582. return WebAssembly.instantiate(binary, info);
  5583. }).then(receiver, function(reason) {
  5584. //err('failed to asynchronously prepare wasm: ' + reason);
  5585. //abort(reason);
  5586. });
  5587. }
  5588. // Prefer streaming instantiation if available.
  5589. function instantiateAsync() {
  5590. if (!Module['wasmBinary'] &&
  5591. typeof WebAssembly.instantiateStreaming === 'function' &&
  5592. !isDataURI(wasmBinaryFile) &&
  5593. typeof fetch === 'function') {
  5594. fetch(wasmBinaryFile, { credentials: 'same-origin' }).then(function (response) {
  5595. return WebAssembly.instantiateStreaming(response, info)
  5596. .then(receiveInstantiatedSource, function(reason) {
  5597. // We expect the most common failure cause to be a bad MIME type for the binary,
  5598. // in which case falling back to ArrayBuffer instantiation should work.
  5599. //err('wasm streaming compile failed: ' + reason);
  5600. //err('falling back to ArrayBuffer instantiation');
  5601. instantiateArrayBuffer(receiveInstantiatedSource);
  5602. });
  5603. });
  5604. } else {
  5605. return instantiateArrayBuffer(receiveInstantiatedSource);
  5606. }
  5607. }
  5608. // User shell pages can write their own Module.instantiateWasm = function(imports, successCallback) callback
  5609. // to manually instantiate the Wasm module themselves. This allows pages to run the instantiation parallel
  5610. // to any other async startup actions they are performing.
  5611. if (Module['instantiateWasm']) {
  5612. try {
  5613. return Module['instantiateWasm'](info, receiveInstance);
  5614. } catch(e) {
  5615. //err('Module.instantiateWasm callback failed with error: ' + e);
  5616. return false;
  5617. }
  5618. }
  5619. instantiateAsync();
  5620. return {}; // no exports yet; we'll fill them in later
  5621. }
  5622. // Provide an "asm.js function" for the application, called to "link" the asm.js module. We instantiate
  5623. // the wasm module at that time, and it receives imports and provides exports and so forth, the app
  5624. // doesn't need to care that it is wasm or asm.js.
  5625. Module['asm'] = function(global, env, providedBuffer) {
  5626. // memory was already allocated (so js could use the buffer)
  5627. env['memory'] = wasmMemory
  5628. ;
  5629. // import table
  5630. env['table'] = wasmTable = new WebAssembly.Table({
  5631. 'initial': 260,
  5632. 'maximum': 260,
  5633. 'element': 'anyfunc'
  5634. });
  5635. // With the wasm backend __memory_base and __table_base and only needed for
  5636. // relocatable output.
  5637. env['__memory_base'] = 1024; // tell the memory segments where to place themselves
  5638. // table starts at 0 by default (even in dynamic linking, for the main module)
  5639. env['__table_base'] = 0;
  5640. var exports = createWasm(env);
  5641. assert$1(exports, 'binaryen setup failed (no wasm support?)');
  5642. return exports;
  5643. };
  5644. // STATICTOP = STATIC_BASE + 4848;
  5645. /* global initializers */ /*__ATINIT__.push();*/
  5646. /* no memory initializer */
  5647. var tempDoublePtr = 5856;
  5648. assert$1(tempDoublePtr % 8 == 0);
  5649. // {{PRE_LIBRARY}}
  5650. function ___cxa_allocate_exception(size) {
  5651. return _malloc(size);
  5652. }
  5653. var ___exception_infos={};
  5654. var ___exception_caught= [];
  5655. function ___exception_addRef(ptr) {
  5656. if (!ptr) return;
  5657. var info = ___exception_infos[ptr];
  5658. info.refcount++;
  5659. }
  5660. function ___exception_deAdjust(adjusted) {
  5661. if (!adjusted || ___exception_infos[adjusted]) return adjusted;
  5662. for (var key in ___exception_infos) {
  5663. 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
  5664. var adj = ___exception_infos[ptr].adjusted;
  5665. var len = adj.length;
  5666. for (var i = 0; i < len; i++) {
  5667. if (adj[i] === adjusted) {
  5668. return ptr;
  5669. }
  5670. }
  5671. }
  5672. return adjusted;
  5673. }function ___cxa_begin_catch(ptr) {
  5674. var info = ___exception_infos[ptr];
  5675. if (info && !info.caught) {
  5676. info.caught = true;
  5677. __ZSt18uncaught_exceptionv.uncaught_exception--;
  5678. }
  5679. if (info) info.rethrown = false;
  5680. ___exception_caught.push(ptr);
  5681. ___exception_addRef(___exception_deAdjust(ptr));
  5682. return ptr;
  5683. }
  5684. function ___cxa_throw(ptr, type, destructor) {
  5685. ___exception_infos[ptr] = {
  5686. ptr: ptr,
  5687. adjusted: [ptr],
  5688. type: type,
  5689. destructor: destructor,
  5690. refcount: 0,
  5691. caught: false,
  5692. rethrown: false
  5693. };
  5694. if (!("uncaught_exception" in __ZSt18uncaught_exceptionv)) {
  5695. __ZSt18uncaught_exceptionv.uncaught_exception = 1;
  5696. } else {
  5697. __ZSt18uncaught_exceptionv.uncaught_exception++;
  5698. }
  5699. 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.";
  5700. }
  5701. function ___cxa_uncaught_exception() {
  5702. return !!__ZSt18uncaught_exceptionv.uncaught_exception;
  5703. }
  5704. function ___gxx_personality_v0() {
  5705. }
  5706. function ___lock() {}
  5707. var SYSCALLS={buffers:[null,[],[]],printChar:function (stream, curr) {
  5708. var buffer = SYSCALLS.buffers[stream];
  5709. assert$1(buffer);
  5710. if (curr === 0 || curr === 10) {
  5711. (stream === 1 ? out : err)(UTF8ArrayToString(buffer, 0));
  5712. buffer.length = 0;
  5713. } else {
  5714. buffer.push(curr);
  5715. }
  5716. },varargs:0,get:function (varargs) {
  5717. SYSCALLS.varargs += 4;
  5718. var ret = HEAP32[(((SYSCALLS.varargs)-(4))>>2)];
  5719. return ret;
  5720. },getStr:function () {
  5721. var ret = UTF8ToString(SYSCALLS.get());
  5722. return ret;
  5723. },get64:function () {
  5724. var low = SYSCALLS.get(), high = SYSCALLS.get();
  5725. if (low >= 0) assert$1(high === 0);
  5726. else assert$1(high === -1);
  5727. return low;
  5728. },getZero:function () {
  5729. assert$1(SYSCALLS.get() === 0);
  5730. }};function ___syscall140(which, varargs) {SYSCALLS.varargs = varargs;
  5731. try {
  5732. // llseek
  5733. var stream = SYSCALLS.getStreamFromFD(), offset_high = SYSCALLS.get(), offset_low = SYSCALLS.get(), result = SYSCALLS.get(), whence = SYSCALLS.get();
  5734. abort('it should not be possible to operate on streams when !SYSCALLS_REQUIRE_FILESYSTEM');
  5735. return 0;
  5736. } catch (e) {
  5737. if (typeof FS === 'undefined' || !(e instanceof FS.ErrnoError)) abort(e);
  5738. return -e.errno;
  5739. }
  5740. }
  5741. function flush_NO_FILESYSTEM() {
  5742. // flush anything remaining in the buffers during shutdown
  5743. var fflush = Module["_fflush"];
  5744. if (fflush) fflush(0);
  5745. var buffers = SYSCALLS.buffers;
  5746. if (buffers[1].length) SYSCALLS.printChar(1, 10);
  5747. if (buffers[2].length) SYSCALLS.printChar(2, 10);
  5748. }function ___syscall146(which, varargs) {SYSCALLS.varargs = varargs;
  5749. try {
  5750. // writev
  5751. // hack to support printf in SYSCALLS_REQUIRE_FILESYSTEM=0
  5752. var stream = SYSCALLS.get(), iov = SYSCALLS.get(), iovcnt = SYSCALLS.get();
  5753. var ret = 0;
  5754. for (var i = 0; i < iovcnt; i++) {
  5755. var ptr = HEAP32[(((iov)+(i*8))>>2)];
  5756. var len = HEAP32[(((iov)+(i*8 + 4))>>2)];
  5757. for (var j = 0; j < len; j++) {
  5758. SYSCALLS.printChar(stream, HEAPU8[ptr+j]);
  5759. }
  5760. ret += len;
  5761. }
  5762. return ret;
  5763. } catch (e) {
  5764. if (typeof FS === 'undefined' || !(e instanceof FS.ErrnoError)) abort(e);
  5765. return -e.errno;
  5766. }
  5767. }
  5768. function ___syscall54(which, varargs) {SYSCALLS.varargs = varargs;
  5769. try {
  5770. // ioctl
  5771. return 0;
  5772. } catch (e) {
  5773. if (typeof FS === 'undefined' || !(e instanceof FS.ErrnoError)) abort(e);
  5774. return -e.errno;
  5775. }
  5776. }
  5777. function ___syscall6(which, varargs) {SYSCALLS.varargs = varargs;
  5778. try {
  5779. // close
  5780. var stream = SYSCALLS.getStreamFromFD();
  5781. abort('it should not be possible to operate on streams when !SYSCALLS_REQUIRE_FILESYSTEM');
  5782. return 0;
  5783. } catch (e) {
  5784. if (typeof FS === 'undefined' || !(e instanceof FS.ErrnoError)) abort(e);
  5785. return -e.errno;
  5786. }
  5787. }
  5788. function ___unlock() {}
  5789. function _abort() {
  5790. Module['abort']();
  5791. }
  5792. function _emscripten_get_heap_size() {
  5793. return HEAP8.length;
  5794. }
  5795. function _emscripten_memcpy_big(dest, src, num) {
  5796. HEAPU8.set(HEAPU8.subarray(src, src+num), dest);
  5797. }
  5798. function ___setErrNo(value) {
  5799. if (Module['___errno_location']) HEAP32[((Module['___errno_location']())>>2)]=value;
  5800. else //err('failed to set errno from JS');
  5801. return value;
  5802. }
  5803. function abortOnCannotGrowMemory(requestedSize) {
  5804. 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 ');
  5805. }
  5806. function emscripten_realloc_buffer(size) {
  5807. var PAGE_MULTIPLE = 65536;
  5808. size = alignUp(size, PAGE_MULTIPLE); // round up to wasm page size
  5809. var oldSize = buffer.byteLength;
  5810. // native wasm support
  5811. // note that this is *not* threadsafe. multiple threads can call .grow(), and each
  5812. // presents a delta, so in theory we may over-allocate here (e.g. if two threads
  5813. // ask to grow from 256MB to 512MB, we get 2 requests to add +256MB, and may end
  5814. // up growing to 768MB (even though we may have been able to make do with 512MB).
  5815. // TODO: consider decreasing the step sizes in emscripten_resize_heap
  5816. try {
  5817. var result = wasmMemory.grow((size - oldSize) / 65536); // .grow() takes a delta compared to the previous size
  5818. if (result !== (-1 | 0)) {
  5819. // success in native wasm memory growth, get the buffer from the memory
  5820. buffer = wasmMemory.buffer;
  5821. return true;
  5822. } else {
  5823. return false;
  5824. }
  5825. } catch(e) {
  5826. console.error('emscripten_realloc_buffer: Attempted to grow from ' + oldSize + ' bytes to ' + size + ' bytes, but got error: ' + e);
  5827. return false;
  5828. }
  5829. }function _emscripten_resize_heap(requestedSize) {
  5830. var oldSize = _emscripten_get_heap_size();
  5831. // With pthreads, races can happen (another thread might increase the size in between), so return a failure, and let the caller retry.
  5832. assert$1(requestedSize > oldSize);
  5833. var PAGE_MULTIPLE = 65536;
  5834. var LIMIT = 2147483648 - PAGE_MULTIPLE; // We can do one page short of 2GB as theoretical maximum.
  5835. if (requestedSize > LIMIT) {
  5836. //err('Cannot enlarge memory, asked to go up to ' + requestedSize + ' bytes, but the limit is ' + LIMIT + ' bytes!');
  5837. return false;
  5838. }
  5839. var MIN_TOTAL_MEMORY = 16777216;
  5840. var newSize = Math.max(oldSize, MIN_TOTAL_MEMORY); // So the loop below will not be infinite, and minimum asm.js memory size is 16MB.
  5841. // TODO: see realloc_buffer - for PTHREADS we may want to decrease these jumps
  5842. while (newSize < requestedSize) { // Keep incrementing the heap size as long as it's less than what is requested.
  5843. if (newSize <= 536870912) {
  5844. newSize = alignUp(2 * newSize, PAGE_MULTIPLE); // Simple heuristic: double until 1GB...
  5845. } else {
  5846. // ..., but after that, add smaller increments towards 2GB, which we cannot reach
  5847. newSize = Math.min(alignUp((3 * newSize + 2147483648) / 4, PAGE_MULTIPLE), LIMIT);
  5848. }
  5849. if (newSize === oldSize) {
  5850. 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);
  5851. }
  5852. }
  5853. if (!emscripten_realloc_buffer(newSize)) {
  5854. //err('Failed to grow the heap from ' + oldSize + ' bytes to ' + newSize + ' bytes, not enough memory!');
  5855. return false;
  5856. }
  5857. updateGlobalBufferViews();
  5858. return true;
  5859. }
  5860. // ASM_LIBRARY EXTERN PRIMITIVES: Math_max,Math_min,Int8Array,Int32Array
  5861. 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); }
  5862. 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); }
  5863. 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); }
  5864. 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); }
  5865. 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); }
  5866. 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); }
  5867. 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); }
  5868. 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); }
  5869. 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); }
  5870. 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); }
  5871. var asmGlobalArg = {};
  5872. var asmLibraryArg = {
  5873. "abort": abort,
  5874. "setTempRet0": setTempRet0,
  5875. "getTempRet0": getTempRet0,
  5876. "abortStackOverflow": abortStackOverflow,
  5877. "nullFunc_ii": nullFunc_ii,
  5878. "nullFunc_iidiiii": nullFunc_iidiiii,
  5879. "nullFunc_iiii": nullFunc_iiii,
  5880. "nullFunc_jiji": nullFunc_jiji,
  5881. "nullFunc_v": nullFunc_v,
  5882. "nullFunc_vi": nullFunc_vi,
  5883. "nullFunc_vii": nullFunc_vii,
  5884. "nullFunc_viiii": nullFunc_viiii,
  5885. "nullFunc_viiiii": nullFunc_viiiii,
  5886. "nullFunc_viiiiii": nullFunc_viiiiii,
  5887. "___cxa_allocate_exception": ___cxa_allocate_exception,
  5888. "___cxa_begin_catch": ___cxa_begin_catch,
  5889. "___cxa_throw": ___cxa_throw,
  5890. "___cxa_uncaught_exception": ___cxa_uncaught_exception,
  5891. "___exception_addRef": ___exception_addRef,
  5892. "___exception_deAdjust": ___exception_deAdjust,
  5893. "___gxx_personality_v0": ___gxx_personality_v0,
  5894. "___lock": ___lock,
  5895. "___setErrNo": ___setErrNo,
  5896. "___syscall140": ___syscall140,
  5897. "___syscall146": ___syscall146,
  5898. "___syscall54": ___syscall54,
  5899. "___syscall6": ___syscall6,
  5900. "___unlock": ___unlock,
  5901. "_abort": _abort,
  5902. "_emscripten_get_heap_size": _emscripten_get_heap_size,
  5903. "_emscripten_memcpy_big": _emscripten_memcpy_big,
  5904. "_emscripten_resize_heap": _emscripten_resize_heap,
  5905. "abortOnCannotGrowMemory": abortOnCannotGrowMemory,
  5906. "emscripten_realloc_buffer": emscripten_realloc_buffer,
  5907. "flush_NO_FILESYSTEM": flush_NO_FILESYSTEM,
  5908. "tempDoublePtr": tempDoublePtr,
  5909. "DYNAMICTOP_PTR": DYNAMICTOP_PTR
  5910. };
  5911. // EMSCRIPTEN_START_ASM
  5912. var asm =Module["asm"]// EMSCRIPTEN_END_ASM
  5913. (asmGlobalArg, asmLibraryArg, buffer);
  5914. var real___ZSt18uncaught_exceptionv = asm["__ZSt18uncaught_exceptionv"];
  5915. asm["__ZSt18uncaught_exceptionv"] = function() {
  5916. assert$1(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  5917. assert$1(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  5918. return real___ZSt18uncaught_exceptionv.apply(null, arguments);
  5919. };
  5920. var real____cxa_can_catch = asm["___cxa_can_catch"];
  5921. asm["___cxa_can_catch"] = function() {
  5922. assert$1(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  5923. assert$1(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  5924. return real____cxa_can_catch.apply(null, arguments);
  5925. };
  5926. var real____cxa_is_pointer_type = asm["___cxa_is_pointer_type"];
  5927. asm["___cxa_is_pointer_type"] = function() {
  5928. assert$1(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  5929. assert$1(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  5930. return real____cxa_is_pointer_type.apply(null, arguments);
  5931. };
  5932. var real____errno_location = asm["___errno_location"];
  5933. asm["___errno_location"] = function() {
  5934. assert$1(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  5935. assert$1(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  5936. return real____errno_location.apply(null, arguments);
  5937. };
  5938. var real__earcut = asm["_earcut"];
  5939. asm["_earcut"] = function() {
  5940. assert$1(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  5941. assert$1(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  5942. return real__earcut.apply(null, arguments);
  5943. };
  5944. var real__fflush = asm["_fflush"];
  5945. asm["_fflush"] = function() {
  5946. assert$1(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  5947. assert$1(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  5948. return real__fflush.apply(null, arguments);
  5949. };
  5950. var real__free = asm["_free"];
  5951. asm["_free"] = function() {
  5952. assert$1(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  5953. assert$1(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  5954. return real__free.apply(null, arguments);
  5955. };
  5956. var real__llvm_maxnum_f64 = asm["_llvm_maxnum_f64"];
  5957. asm["_llvm_maxnum_f64"] = function() {
  5958. assert$1(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  5959. assert$1(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  5960. return real__llvm_maxnum_f64.apply(null, arguments);
  5961. };
  5962. var real__llvm_minnum_f64 = asm["_llvm_minnum_f64"];
  5963. asm["_llvm_minnum_f64"] = function() {
  5964. assert$1(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  5965. assert$1(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  5966. return real__llvm_minnum_f64.apply(null, arguments);
  5967. };
  5968. var real__malloc = asm["_malloc"];
  5969. asm["_malloc"] = function() {
  5970. assert$1(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  5971. assert$1(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  5972. return real__malloc.apply(null, arguments);
  5973. };
  5974. var real__sbrk = asm["_sbrk"];
  5975. asm["_sbrk"] = function() {
  5976. assert$1(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  5977. assert$1(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  5978. return real__sbrk.apply(null, arguments);
  5979. };
  5980. var real_establishStackSpace = asm["establishStackSpace"];
  5981. asm["establishStackSpace"] = function() {
  5982. assert$1(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  5983. assert$1(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  5984. return real_establishStackSpace.apply(null, arguments);
  5985. };
  5986. var real_stackAlloc = asm["stackAlloc"];
  5987. asm["stackAlloc"] = function() {
  5988. assert$1(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  5989. assert$1(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  5990. return real_stackAlloc.apply(null, arguments);
  5991. };
  5992. var real_stackRestore = asm["stackRestore"];
  5993. asm["stackRestore"] = function() {
  5994. assert$1(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  5995. assert$1(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  5996. return real_stackRestore.apply(null, arguments);
  5997. };
  5998. var real_stackSave = asm["stackSave"];
  5999. asm["stackSave"] = function() {
  6000. assert$1(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  6001. assert$1(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  6002. return real_stackSave.apply(null, arguments);
  6003. };
  6004. Module["asm"] = asm;
  6005. var __ZSt18uncaught_exceptionv = Module["__ZSt18uncaught_exceptionv"] = function() {
  6006. assert$1(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  6007. assert$1(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  6008. return Module["asm"]["__ZSt18uncaught_exceptionv"].apply(null, arguments)
  6009. };
  6010. var ___cxa_can_catch = Module["___cxa_can_catch"] = function() {
  6011. assert$1(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  6012. assert$1(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  6013. return Module["asm"]["___cxa_can_catch"].apply(null, arguments)
  6014. };
  6015. var ___cxa_is_pointer_type = Module["___cxa_is_pointer_type"] = function() {
  6016. assert$1(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  6017. assert$1(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  6018. return Module["asm"]["___cxa_is_pointer_type"].apply(null, arguments)
  6019. };
  6020. var ___errno_location = Module["___errno_location"] = function() {
  6021. assert$1(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  6022. assert$1(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  6023. return Module["asm"]["___errno_location"].apply(null, arguments)
  6024. };
  6025. var _earcut = Module["_earcut"] = function() {
  6026. assert$1(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  6027. assert$1(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  6028. return Module["asm"]["_earcut"].apply(null, arguments)
  6029. };
  6030. var _emscripten_replace_memory = Module["_emscripten_replace_memory"] = function() {
  6031. assert$1(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  6032. assert$1(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  6033. return Module["asm"]["_emscripten_replace_memory"].apply(null, arguments)
  6034. };
  6035. var _fflush = Module["_fflush"] = function() {
  6036. assert$1(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  6037. assert$1(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  6038. return Module["asm"]["_fflush"].apply(null, arguments)
  6039. };
  6040. var _free = Module["_free"] = function() {
  6041. assert$1(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  6042. assert$1(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  6043. return Module["asm"]["_free"].apply(null, arguments)
  6044. };
  6045. var _llvm_maxnum_f64 = Module["_llvm_maxnum_f64"] = function() {
  6046. assert$1(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  6047. assert$1(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  6048. return Module["asm"]["_llvm_maxnum_f64"].apply(null, arguments)
  6049. };
  6050. var _llvm_minnum_f64 = Module["_llvm_minnum_f64"] = function() {
  6051. assert$1(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  6052. assert$1(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  6053. return Module["asm"]["_llvm_minnum_f64"].apply(null, arguments)
  6054. };
  6055. var _malloc = Module["_malloc"] = function() {
  6056. assert$1(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  6057. assert$1(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  6058. return Module["asm"]["_malloc"].apply(null, arguments)
  6059. };
  6060. var _memcpy = Module["_memcpy"] = function() {
  6061. assert$1(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  6062. assert$1(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  6063. return Module["asm"]["_memcpy"].apply(null, arguments)
  6064. };
  6065. var _memset = Module["_memset"] = function() {
  6066. assert$1(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  6067. assert$1(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  6068. return Module["asm"]["_memset"].apply(null, arguments)
  6069. };
  6070. var _sbrk = Module["_sbrk"] = function() {
  6071. assert$1(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  6072. assert$1(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  6073. return Module["asm"]["_sbrk"].apply(null, arguments)
  6074. };
  6075. var establishStackSpace = Module["establishStackSpace"] = function() {
  6076. assert$1(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  6077. assert$1(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  6078. return Module["asm"]["establishStackSpace"].apply(null, arguments)
  6079. };
  6080. var stackAlloc = Module["stackAlloc"] = function() {
  6081. assert$1(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  6082. assert$1(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  6083. return Module["asm"]["stackAlloc"].apply(null, arguments)
  6084. };
  6085. var stackRestore = Module["stackRestore"] = function() {
  6086. assert$1(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  6087. assert$1(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  6088. return Module["asm"]["stackRestore"].apply(null, arguments)
  6089. };
  6090. var stackSave = Module["stackSave"] = function() {
  6091. assert$1(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  6092. assert$1(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  6093. return Module["asm"]["stackSave"].apply(null, arguments)
  6094. };
  6095. var dynCall_ii = Module["dynCall_ii"] = function() {
  6096. assert$1(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  6097. assert$1(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  6098. return Module["asm"]["dynCall_ii"].apply(null, arguments)
  6099. };
  6100. var dynCall_iidiiii = Module["dynCall_iidiiii"] = function() {
  6101. assert$1(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  6102. assert$1(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  6103. return Module["asm"]["dynCall_iidiiii"].apply(null, arguments)
  6104. };
  6105. var dynCall_iiii = Module["dynCall_iiii"] = function() {
  6106. assert$1(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  6107. assert$1(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  6108. return Module["asm"]["dynCall_iiii"].apply(null, arguments)
  6109. };
  6110. var dynCall_jiji = Module["dynCall_jiji"] = function() {
  6111. assert$1(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  6112. assert$1(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  6113. return Module["asm"]["dynCall_jiji"].apply(null, arguments)
  6114. };
  6115. var dynCall_v = Module["dynCall_v"] = function() {
  6116. assert$1(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  6117. assert$1(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  6118. return Module["asm"]["dynCall_v"].apply(null, arguments)
  6119. };
  6120. var dynCall_vi = Module["dynCall_vi"] = function() {
  6121. assert$1(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  6122. assert$1(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  6123. return Module["asm"]["dynCall_vi"].apply(null, arguments)
  6124. };
  6125. var dynCall_vii = Module["dynCall_vii"] = function() {
  6126. assert$1(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  6127. assert$1(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  6128. return Module["asm"]["dynCall_vii"].apply(null, arguments)
  6129. };
  6130. var dynCall_viiii = Module["dynCall_viiii"] = function() {
  6131. assert$1(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  6132. assert$1(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  6133. return Module["asm"]["dynCall_viiii"].apply(null, arguments)
  6134. };
  6135. var dynCall_viiiii = Module["dynCall_viiiii"] = function() {
  6136. assert$1(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  6137. assert$1(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  6138. return Module["asm"]["dynCall_viiiii"].apply(null, arguments)
  6139. };
  6140. var dynCall_viiiiii = Module["dynCall_viiiiii"] = function() {
  6141. assert$1(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
  6142. assert$1(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
  6143. return Module["asm"]["dynCall_viiiiii"].apply(null, arguments)
  6144. };
  6145. // === Auto-generated postamble setup entry stuff ===
  6146. Module['asm'] = asm;
  6147. if (!Module["intArrayFromString"]) Module["intArrayFromString"] = function() { abort("'intArrayFromString' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6148. if (!Module["intArrayToString"]) Module["intArrayToString"] = function() { abort("'intArrayToString' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6149. Module["ccall"] = ccall;
  6150. Module["cwrap"] = cwrap;
  6151. if (!Module["setValue"]) Module["setValue"] = function() { abort("'setValue' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6152. Module["getValue"] = getValue;
  6153. if (!Module["allocate"]) Module["allocate"] = function() { abort("'allocate' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6154. 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"); };
  6155. if (!Module["AsciiToString"]) Module["AsciiToString"] = function() { abort("'AsciiToString' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6156. if (!Module["stringToAscii"]) Module["stringToAscii"] = function() { abort("'stringToAscii' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6157. if (!Module["UTF8ArrayToString"]) Module["UTF8ArrayToString"] = function() { abort("'UTF8ArrayToString' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6158. if (!Module["UTF8ToString"]) Module["UTF8ToString"] = function() { abort("'UTF8ToString' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6159. if (!Module["stringToUTF8Array"]) Module["stringToUTF8Array"] = function() { abort("'stringToUTF8Array' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6160. if (!Module["stringToUTF8"]) Module["stringToUTF8"] = function() { abort("'stringToUTF8' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6161. if (!Module["lengthBytesUTF8"]) Module["lengthBytesUTF8"] = function() { abort("'lengthBytesUTF8' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6162. if (!Module["UTF16ToString"]) Module["UTF16ToString"] = function() { abort("'UTF16ToString' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6163. if (!Module["stringToUTF16"]) Module["stringToUTF16"] = function() { abort("'stringToUTF16' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6164. if (!Module["lengthBytesUTF16"]) Module["lengthBytesUTF16"] = function() { abort("'lengthBytesUTF16' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6165. if (!Module["UTF32ToString"]) Module["UTF32ToString"] = function() { abort("'UTF32ToString' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6166. if (!Module["stringToUTF32"]) Module["stringToUTF32"] = function() { abort("'stringToUTF32' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6167. if (!Module["lengthBytesUTF32"]) Module["lengthBytesUTF32"] = function() { abort("'lengthBytesUTF32' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6168. if (!Module["allocateUTF8"]) Module["allocateUTF8"] = function() { abort("'allocateUTF8' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6169. if (!Module["stackTrace"]) Module["stackTrace"] = function() { abort("'stackTrace' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6170. if (!Module["addOnPreRun"]) Module["addOnPreRun"] = function() { abort("'addOnPreRun' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6171. if (!Module["addOnInit"]) Module["addOnInit"] = function() { abort("'addOnInit' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6172. if (!Module["addOnPreMain"]) Module["addOnPreMain"] = function() { abort("'addOnPreMain' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6173. if (!Module["addOnExit"]) Module["addOnExit"] = function() { abort("'addOnExit' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6174. if (!Module["addOnPostRun"]) Module["addOnPostRun"] = function() { abort("'addOnPostRun' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6175. if (!Module["writeStringToMemory"]) Module["writeStringToMemory"] = function() { abort("'writeStringToMemory' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6176. if (!Module["writeArrayToMemory"]) Module["writeArrayToMemory"] = function() { abort("'writeArrayToMemory' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6177. if (!Module["writeAsciiToMemory"]) Module["writeAsciiToMemory"] = function() { abort("'writeAsciiToMemory' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6178. 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"); };
  6179. 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"); };
  6180. if (!Module["ENV"]) Module["ENV"] = function() { abort("'ENV' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6181. if (!Module["FS"]) Module["FS"] = function() { abort("'FS' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6182. 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"); };
  6183. 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"); };
  6184. 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"); };
  6185. 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"); };
  6186. 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"); };
  6187. 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"); };
  6188. 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"); };
  6189. 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"); };
  6190. if (!Module["GL"]) Module["GL"] = function() { abort("'GL' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6191. if (!Module["dynamicAlloc"]) Module["dynamicAlloc"] = function() { abort("'dynamicAlloc' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6192. if (!Module["warnOnce"]) Module["warnOnce"] = function() { abort("'warnOnce' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6193. if (!Module["loadDynamicLibrary"]) Module["loadDynamicLibrary"] = function() { abort("'loadDynamicLibrary' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6194. if (!Module["loadWebAssemblyModule"]) Module["loadWebAssemblyModule"] = function() { abort("'loadWebAssemblyModule' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6195. if (!Module["getLEB"]) Module["getLEB"] = function() { abort("'getLEB' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6196. if (!Module["getFunctionTables"]) Module["getFunctionTables"] = function() { abort("'getFunctionTables' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6197. if (!Module["alignFunctionTables"]) Module["alignFunctionTables"] = function() { abort("'alignFunctionTables' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6198. if (!Module["registerFunctions"]) Module["registerFunctions"] = function() { abort("'registerFunctions' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6199. if (!Module["addFunction"]) Module["addFunction"] = function() { abort("'addFunction' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6200. if (!Module["removeFunction"]) Module["removeFunction"] = function() { abort("'removeFunction' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6201. if (!Module["getFuncWrapper"]) Module["getFuncWrapper"] = function() { abort("'getFuncWrapper' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6202. if (!Module["prettyPrint"]) Module["prettyPrint"] = function() { abort("'prettyPrint' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6203. if (!Module["makeBigInt"]) Module["makeBigInt"] = function() { abort("'makeBigInt' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6204. if (!Module["dynCall"]) Module["dynCall"] = function() { abort("'dynCall' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6205. if (!Module["getCompilerSetting"]) Module["getCompilerSetting"] = function() { abort("'getCompilerSetting' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6206. if (!Module["stackSave"]) Module["stackSave"] = function() { abort("'stackSave' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6207. if (!Module["stackRestore"]) Module["stackRestore"] = function() { abort("'stackRestore' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6208. if (!Module["stackAlloc"]) Module["stackAlloc"] = function() { abort("'stackAlloc' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6209. if (!Module["establishStackSpace"]) Module["establishStackSpace"] = function() { abort("'establishStackSpace' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6210. if (!Module["print"]) Module["print"] = function() { abort("'print' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6211. if (!Module["printErr"]) Module["printErr"] = function() { abort("'printErr' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6212. if (!Module["getTempRet0"]) Module["getTempRet0"] = function() { abort("'getTempRet0' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6213. if (!Module["setTempRet0"]) Module["setTempRet0"] = function() { abort("'setTempRet0' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)"); };
  6214. 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)"); } });
  6215. 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)"); } });
  6216. 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)"); } });
  6217. 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)"); } });
  6218. /**
  6219. * @constructor
  6220. * @extends {Error}
  6221. * @this {ExitStatus}
  6222. */
  6223. function ExitStatus(status) {
  6224. this.name = "ExitStatus";
  6225. this.message = "Program terminated with exit(" + status + ")";
  6226. this.status = status;
  6227. } ExitStatus.prototype = new Error();
  6228. ExitStatus.prototype.constructor = ExitStatus;
  6229. dependenciesFulfilled = function runCaller() {
  6230. // If run has never been called, and we should call run (INVOKE_RUN is true, and Module.noInitialRun is not false)
  6231. if (!Module['calledRun']) run();
  6232. if (!Module['calledRun']) dependenciesFulfilled = runCaller; // try this again later, after new deps are fulfilled
  6233. };
  6234. /** @type {function(Array=)} */
  6235. function run(args) {
  6236. args = args || Module['arguments'];
  6237. if (runDependencies > 0) {
  6238. return;
  6239. }
  6240. writeStackCookie();
  6241. preRun();
  6242. if (runDependencies > 0) return; // a preRun added a dependency, run will be called later
  6243. if (Module['calledRun']) return; // run may have just been called through dependencies being fulfilled just in this very frame
  6244. function doRun() {
  6245. if (Module['calledRun']) return; // run may have just been called while the async setStatus time below was happening
  6246. Module['calledRun'] = true;
  6247. if (ABORT) return;
  6248. ensureInitRuntime();
  6249. preMain();
  6250. if (Module['onRuntimeInitialized']) Module['onRuntimeInitialized']();
  6251. assert$1(!Module['_main'], 'compiled without a main, but one is present. if you added it from JS, use Module["onRuntimeInitialized"]');
  6252. postRun();
  6253. }
  6254. if (Module['setStatus']) {
  6255. Module['setStatus']('Running...');
  6256. setTimeout(function() {
  6257. setTimeout(function() {
  6258. Module['setStatus']('');
  6259. }, 1);
  6260. doRun();
  6261. }, 1);
  6262. } else {
  6263. doRun();
  6264. }
  6265. checkStackCookie();
  6266. }
  6267. Module['run'] = run;
  6268. var abortDecorators = [];
  6269. function abort(what) {
  6270. if (Module['onAbort']) {
  6271. Module['onAbort'](what);
  6272. }
  6273. if (what !== undefined) {
  6274. //out(what);
  6275. //err(what);
  6276. what = '"' + what + '"';
  6277. } else {
  6278. what = '';
  6279. }
  6280. ABORT = true;
  6281. var extra = '';
  6282. var output = 'abort(' + what + ') at ' + stackTrace() + extra;
  6283. if (abortDecorators) {
  6284. abortDecorators.forEach(function(decorator) {
  6285. output = decorator(output, what);
  6286. });
  6287. }
  6288. throw output;
  6289. }
  6290. Module['abort'] = abort;
  6291. if (Module['preInit']) {
  6292. if (typeof Module['preInit'] == 'function') Module['preInit'] = [Module['preInit']];
  6293. while (Module['preInit'].length > 0) {
  6294. Module['preInit'].pop()();
  6295. }
  6296. }
  6297. Module["noExitRuntime"] = true;
  6298. run();
  6299. } else {
  6300. var Module = null;
  6301. }
  6302. var earcutWasm = Module;
  6303. // {{MODULE_ADDITIONS}}
  6304. var earcutWasmReady = false;
  6305. if (when.defined(earcutWasm)) {
  6306. earcutWasm.onRuntimeInitialized = function () {
  6307. earcutWasmReady = true;
  6308. };
  6309. var earcutwasm = earcutWasm.cwrap('earcut','number',['number','number','number','number','number','number']);
  6310. }
  6311. var layout$3 = createLayout([
  6312. {name: 'a_pos', components: 2, type: 'Int16'}
  6313. ], 4);
  6314. var members$1 = layout$3.members;
  6315. var EARCUT_MAX_RINGS = 500;
  6316. var FillBucket = function FillBucket(options) {
  6317. this.zoom = options.zoom;
  6318. this.overscaling = options.overscaling;
  6319. this.layers = options.layers;
  6320. this.layerIds = this.layers.map(function (layer) {
  6321. return layer.id;
  6322. });
  6323. this.index = options.index;
  6324. this.hasPattern = false;
  6325. this.patternFeatures = [];
  6326. this.layoutVertexArray = new StructArrayLayout2i4();
  6327. this.indexArray = new StructArrayLayout3ui6();
  6328. this.indexArray2 = new StructArrayLayout2ui4();
  6329. this.programConfigurations = new ProgramConfigurationSet(members$1, options.layers, options.zoom);
  6330. this.segments = new SegmentVector();
  6331. this.segments2 = new SegmentVector();
  6332. this.stateDependentLayerIds = this.layers.filter(function (l) {
  6333. return l.isStateDependent();
  6334. }).map(function (l) {
  6335. return l.id;
  6336. });
  6337. };
  6338. FillBucket.prototype.populate = function populate(features, options) {
  6339. this.hasPattern = hasPattern('fill', this.layers, options);
  6340. var bucketFeatures = [];
  6341. for (var i = 0, list = features; i < list.length; i += 1) {
  6342. var ref = list[i];
  6343. var feature = ref.feature;
  6344. var index = ref.index;
  6345. var sourceLayerIndex = ref.sourceLayerIndex;
  6346. if (!this.layers[0]._featureFilter(new EvaluationParameters$1(0), feature)) {
  6347. continue;
  6348. }
  6349. var geometry = loadGeometry(feature);
  6350. var sortKey =
  6351. undefined;
  6352. var bucketFeature = {
  6353. id: feature.id,
  6354. properties: feature.properties,
  6355. type: feature.type,
  6356. sourceLayerIndex: sourceLayerIndex,
  6357. index: index,
  6358. geometry: geometry,
  6359. patterns: {},
  6360. sortKey: sortKey
  6361. };
  6362. bucketFeatures.push(bucketFeature);
  6363. }
  6364. for (var i$1 = 0, list$1 = bucketFeatures; i$1 < list$1.length; i$1 += 1) {
  6365. var bucketFeature$1 = list$1[i$1];
  6366. var ref$1 = bucketFeature$1;
  6367. var geometry$1 = ref$1.geometry;
  6368. var index$1 = ref$1.index;
  6369. var sourceLayerIndex$1 = ref$1.sourceLayerIndex;
  6370. if (this.hasPattern) {
  6371. var patternFeature = addPatternDependencies('fill', this.layers, bucketFeature$1, this.zoom, options);
  6372. // pattern features are added only once the pattern is loaded into the image atlas
  6373. // so are stored during populate until later updated with positions by tile worker in addFeatures
  6374. this.patternFeatures.push(patternFeature);
  6375. } else {
  6376. this.addFeature(bucketFeature$1, geometry$1, index$1, {}, options.indexData);
  6377. }
  6378. var feature$1 = features[index$1].feature;
  6379. options.featureIndex.insert(feature$1, geometry$1, index$1, sourceLayerIndex$1, this.index);
  6380. }
  6381. };
  6382. FillBucket.prototype.update = function update(states, vtLayer, imagePositions) {
  6383. if (!this.stateDependentLayers.length) {
  6384. return;
  6385. }
  6386. this.programConfigurations.updatePaintArrays(states, vtLayer, this.stateDependentLayers, imagePositions);
  6387. };
  6388. FillBucket.prototype.addFeatures = function addFeatures(options, imagePositions) {
  6389. for (var i = 0, list = this.patternFeatures; i < list.length; i += 1) {
  6390. var feature = list[i];
  6391. this.addFeature(feature, feature.geometry, feature.index, imagePositions);
  6392. }
  6393. };
  6394. FillBucket.prototype.isEmpty = function isEmpty() {
  6395. return this.layoutVertexArray.length === 0;
  6396. };
  6397. FillBucket.prototype.uploadPending = function uploadPending() {
  6398. return !this.uploaded || this.programConfigurations.needsUpload;
  6399. };
  6400. FillBucket.prototype.upload = function upload(context) {
  6401. if (!this.uploaded) {
  6402. if(this.layoutVertexArray == null) {
  6403. return;
  6404. }
  6405. this.layoutVertexBuffer = context.createVertexBuffer(this.layoutVertexArray, members$1);
  6406. this.indexBuffer = context.createIndexBuffer(this.indexArray);
  6407. this.indexBuffer2 = context.createIndexBuffer(this.indexArray2);
  6408. }
  6409. this.programConfigurations.upload(context);
  6410. this.uploaded = true;
  6411. };
  6412. FillBucket.prototype.destroy = function destroy() {
  6413. if (!this.layoutVertexBuffer) {
  6414. return;
  6415. }
  6416. this.layoutVertexBuffer.destroy();
  6417. this.indexBuffer.destroy();
  6418. this.indexBuffer2.destroy();
  6419. this.programConfigurations.destroy();
  6420. this.segments.destroy();
  6421. this.segments2.destroy();
  6422. };
  6423. FillBucket.prototype.clear = function clear() {
  6424. if (when.defined(this.layoutVertexArray)) {
  6425. this.layoutVertexArray = null;
  6426. }
  6427. if (when.defined(this.indexArray)) {
  6428. this.indexArray = null;
  6429. }
  6430. if (when.defined(this.indexArray2)) {
  6431. this.indexArray2 = null;
  6432. }
  6433. };
  6434. FillBucket.prototype.addFeature = function addFeature(feature, geometry, index, imagePositions, indexData) {
  6435. for (var i$4 = 0, list$2 = classifyRings(geometry, EARCUT_MAX_RINGS); i$4 < list$2.length; i$4 += 1) {
  6436. var polygon = list$2[i$4];
  6437. var numVertices = 0;
  6438. for (var i$2 = 0, list = polygon; i$2 < list.length; i$2 += 1) {
  6439. var ring = list[i$2];
  6440. numVertices += ring.length;
  6441. }
  6442. var triangleSegment = this.segments.prepareSegment(numVertices, this.layoutVertexArray, this.indexArray);
  6443. var triangleIndex = triangleSegment.vertexLength;
  6444. var flattened = [];
  6445. var holeIndices = [];
  6446. for (var i$3 = 0, list$1 = polygon; i$3 < list$1.length; i$3 += 1) {
  6447. var ring$1 = list$1[i$3];
  6448. if (ring$1.length === 0) {
  6449. continue;
  6450. }
  6451. if (ring$1 !== polygon[0]) {
  6452. holeIndices.push(flattened.length / 2);
  6453. }
  6454. var lineSegment = this.segments2.prepareSegment(ring$1.length, this.layoutVertexArray, this.indexArray2);
  6455. var lineIndex = lineSegment.vertexLength;
  6456. this.layoutVertexArray.emplaceBack(ring$1[0].x, ring$1[0].y);
  6457. this.indexArray2.emplaceBack(lineIndex + ring$1.length - 1, lineIndex);
  6458. flattened.push(ring$1[0].x);
  6459. flattened.push(ring$1[0].y);
  6460. for (var i = 1; i < ring$1.length; i++) {
  6461. this.layoutVertexArray.emplaceBack(ring$1[i].x, ring$1[i].y);
  6462. this.indexArray2.emplaceBack(lineIndex + i - 1, lineIndex + i);
  6463. flattened.push(ring$1[i].x);
  6464. flattened.push(ring$1[i].y);
  6465. }
  6466. lineSegment.vertexLength += ring$1.length;
  6467. lineSegment.primitiveLength += ring$1.length;
  6468. }
  6469. var indices;
  6470. if (when.defined(indexData) && when.defined(indexData[feature.id])) {
  6471. indices = indexData[feature.id];
  6472. } else if (earcutWasmReady === true) {
  6473. var data = new Int32Array(flattened);
  6474. var dataLength = data.length;
  6475. var offset = earcutWasm._malloc(Int32Array.BYTES_PER_ELEMENT * dataLength); //开辟内存
  6476. earcutWasm.HEAP32.set(data, offset / Int32Array.BYTES_PER_ELEMENT); //设置值
  6477. var hole = new Int32Array(holeIndices);
  6478. var holeLength = hole.length;
  6479. var offset1 = earcutWasm._malloc(Int32Array.BYTES_PER_ELEMENT * holeLength); //开辟内存
  6480. earcutWasm.HEAP32.set(hole, offset1 / Int32Array.BYTES_PER_ELEMENT); //设置值
  6481. var res = new Int32Array(dataLength * 10);
  6482. var offset2 = earcutWasm._malloc(Int32Array.BYTES_PER_ELEMENT * dataLength * 10); //开辟内存
  6483. earcutWasm.HEAP32.set(res, offset2 / Int32Array.BYTES_PER_ELEMENT);
  6484. var len = earcutwasm(offset, dataLength, offset1, holeLength, 2, offset2);
  6485. var result = new Int32Array(earcutWasm.HEAP32.buffer, offset2, len);
  6486. indices = new Int32Array(result);
  6487. earcutWasm._free(offset);
  6488. earcutWasm._free(offset1);
  6489. earcutWasm._free(offset2);
  6490. } else {
  6491. indices = earcut2_2_1.earcut(flattened, holeIndices);
  6492. }
  6493. for (var i$1 = 0; i$1 < indices.length; i$1 += 3) {
  6494. this.indexArray.emplaceBack(
  6495. triangleIndex + indices[i$1],
  6496. triangleIndex + indices[i$1 + 1],
  6497. triangleIndex + indices[i$1 + 2]);
  6498. }
  6499. triangleSegment.vertexLength += numVertices;
  6500. triangleSegment.primitiveLength += indices.length / 3;
  6501. }
  6502. this.programConfigurations.populatePaintArrays(this.layoutVertexArray.length, feature, index, imagePositions);
  6503. };
  6504. WebWorkerTransfer.register('FillBucket', FillBucket, {omit: ['layers', 'patternFeatures']});
  6505. var Struct = function Struct(structArray , index ) {
  6506. (this )._structArray = structArray;
  6507. this._pos1 = index * this.size;
  6508. this._pos2 = this._pos1 / 2;
  6509. this._pos4 = this._pos1 / 4;
  6510. this._pos8 = this._pos1 / 8;
  6511. };
  6512. var DEFAULT_CAPACITY$1 = 128;
  6513. var RESIZE_MULTIPLIER$1 = 5;
  6514. /**
  6515. * `StructArray` provides an abstraction over `ArrayBuffer` and `TypedArray`
  6516. * making it behave like an array of typed structs.
  6517. *
  6518. * Conceptually, a StructArray is comprised of elements, i.e., instances of its
  6519. * associated struct type. Each particular struct type, together with an
  6520. * alignment size, determines the memory layout of a StructArray whose elements
  6521. * are of that type. Thus, for each such layout that we need, we have
  6522. * a corrseponding StructArrayLayout class, inheriting from StructArray and
  6523. * implementing `emplaceBack()` and `_refreshViews()`.
  6524. *
  6525. * In some cases, where we need to access particular elements of a StructArray,
  6526. * we implement a more specific subclass that inherits from one of the
  6527. * StructArrayLayouts and adds a `get(i): T` accessor that returns a structured
  6528. * object whose properties are proxies into the underlying memory space for the
  6529. * i-th element. This affords the convience of working with (seemingly) plain
  6530. * Javascript objects without the overhead of serializing/deserializing them
  6531. * into ArrayBuffers for efficient web worker transfer.
  6532. *
  6533. * @private
  6534. */
  6535. var StructArray$1 = function StructArray() {
  6536. this.isTransferred = false;
  6537. this.capacity = -1;
  6538. this.resize(0);
  6539. };
  6540. /**
  6541. * Serialize a StructArray instance.Serializes both the raw data and the
  6542. * metadata needed to reconstruct the StructArray base class during
  6543. * deserialization.
  6544. */
  6545. StructArray$1.serialize = function serialize (array, transferables) {
  6546. if(array.isTransferred){
  6547. console.log("StructArray array.isTransferred.");
  6548. }
  6549. array._trim();
  6550. if (transferables) {
  6551. array.isTransferred = true;
  6552. transferables.push(array.arrayBuffer);
  6553. }
  6554. return {
  6555. length: array.length,
  6556. arrayBuffer: array.arrayBuffer,
  6557. };
  6558. };
  6559. StructArray$1.deserialize = function deserialize (input ) {
  6560. var structArray = Object.create(this.prototype);
  6561. structArray.arrayBuffer = input.arrayBuffer;
  6562. structArray.length = input.length;
  6563. structArray.capacity = input.arrayBuffer.byteLength / structArray.bytesPerElement;
  6564. structArray._refreshViews();
  6565. return structArray;
  6566. };
  6567. /**
  6568. * Resize the array to discard unused capacity.
  6569. */
  6570. StructArray$1.prototype._trim = function _trim () {
  6571. if (this.length !== this.capacity) {
  6572. this.capacity = this.length;
  6573. this.arrayBuffer = this.arrayBuffer.slice(0, this.length * this.bytesPerElement);
  6574. this._refreshViews();
  6575. }
  6576. };
  6577. /**
  6578. * Resets the the length of the array to 0 without de-allocating capcacity.
  6579. */
  6580. StructArray$1.prototype.clear = function clear () {
  6581. this.length = 0;
  6582. };
  6583. /**
  6584. * Resize the array.
  6585. * If `n` is greater than the current length then additional elements with undefined values are added.
  6586. * If `n` is less than the current length then the array will be reduced to the first `n` elements.
  6587. * @param {number} n The new size of the array.
  6588. */
  6589. StructArray$1.prototype.resize = function resize (n ) {
  6590. this.reserve(n);
  6591. this.length = n;
  6592. };
  6593. /**
  6594. * Indicate a planned increase in size, so that any necessary allocation may
  6595. * be done once, ahead of time.
  6596. * @param {number} n The expected size of the array.
  6597. */
  6598. StructArray$1.prototype.reserve = function reserve (n ) {
  6599. if (n > this.capacity) {
  6600. this.capacity = Math.max(n, Math.floor(this.capacity * RESIZE_MULTIPLIER$1), DEFAULT_CAPACITY$1);
  6601. this.arrayBuffer = new ArrayBuffer(this.capacity * this.bytesPerElement);
  6602. var oldUint8Array = this.uint8;
  6603. this._refreshViews();
  6604. if (oldUint8Array) { this.uint8.set(oldUint8Array); }
  6605. }
  6606. };
  6607. /**
  6608. * Create TypedArray views for the current ArrayBuffer.
  6609. */
  6610. StructArray$1.prototype._refreshViews = function _refreshViews () {
  6611. throw new Error('_refreshViews() must be implemented by each concrete StructArray layout');
  6612. };
  6613. /**
  6614. * Implementation of the StructArray layout:
  6615. * [0]: Uint32[1]
  6616. * [4]: Uint16[2]
  6617. *
  6618. * @private
  6619. */
  6620. var StructArrayLayout1ul2ui8 = /*@__PURE__*/(function (StructArray) {
  6621. function StructArrayLayout1ul2ui8 () {
  6622. StructArray.apply(this, arguments);
  6623. }
  6624. if ( StructArray ) StructArrayLayout1ul2ui8.__proto__ = StructArray;
  6625. StructArrayLayout1ul2ui8.prototype = Object.create( StructArray && StructArray.prototype );
  6626. StructArrayLayout1ul2ui8.prototype.constructor = StructArrayLayout1ul2ui8;
  6627. StructArrayLayout1ul2ui8.prototype._refreshViews = function _refreshViews () {
  6628. this.uint8 = new Uint8Array(this.arrayBuffer);
  6629. this.uint32 = new Uint32Array(this.arrayBuffer);
  6630. this.uint16 = new Uint16Array(this.arrayBuffer);
  6631. };
  6632. StructArrayLayout1ul2ui8.prototype.emplaceBack = function emplaceBack (v0 , v1 , v2 ) {
  6633. var i = this.length;
  6634. this.resize(i + 1);
  6635. return this.emplace(i, v0, v1, v2);
  6636. };
  6637. StructArrayLayout1ul2ui8.prototype.emplace = function emplace (i , v0 , v1 , v2 ) {
  6638. var o4 = i * 2;
  6639. var o2 = i * 4;
  6640. this.uint32[o4 + 0] = v0;
  6641. this.uint16[o2 + 2] = v1;
  6642. this.uint16[o2 + 3] = v2;
  6643. return i;
  6644. };
  6645. return StructArrayLayout1ul2ui8;
  6646. }(StructArray$1));
  6647. StructArrayLayout1ul2ui8.prototype.bytesPerElement = 8;
  6648. var FeatureIndexStruct = /*@__PURE__*/(function (Struct) {
  6649. function FeatureIndexStruct () {
  6650. Struct.apply(this, arguments);
  6651. }
  6652. if ( Struct ) FeatureIndexStruct.__proto__ = Struct;
  6653. FeatureIndexStruct.prototype = Object.create( Struct && Struct.prototype );
  6654. FeatureIndexStruct.prototype.constructor = FeatureIndexStruct;
  6655. var prototypeAccessors$5 = { featureIndex: { configurable: true },sourceLayerIndex: { configurable: true },bucketIndex: { configurable: true } };
  6656. prototypeAccessors$5.featureIndex.get = function () { return this._structArray.uint32[this._pos4 + 0]; };
  6657. prototypeAccessors$5.featureIndex.set = function (x ) { this._structArray.uint32[this._pos4 + 0] = x; };
  6658. prototypeAccessors$5.sourceLayerIndex.get = function () { return this._structArray.uint16[this._pos2 + 2]; };
  6659. prototypeAccessors$5.sourceLayerIndex.set = function (x ) { this._structArray.uint16[this._pos2 + 2] = x; };
  6660. prototypeAccessors$5.bucketIndex.get = function () { return this._structArray.uint16[this._pos2 + 3]; };
  6661. prototypeAccessors$5.bucketIndex.set = function (x ) { this._structArray.uint16[this._pos2 + 3] = x; };
  6662. Object.defineProperties( FeatureIndexStruct.prototype, prototypeAccessors$5 );
  6663. return FeatureIndexStruct;
  6664. }(Struct));
  6665. FeatureIndexStruct.prototype.size = 8;
  6666. /**
  6667. * @private
  6668. */
  6669. var FeatureIndexArray = /*@__PURE__*/(function (StructArrayLayout1ul2ui8) {
  6670. function FeatureIndexArray () {
  6671. StructArrayLayout1ul2ui8.apply(this, arguments);
  6672. }
  6673. if ( StructArrayLayout1ul2ui8 ) FeatureIndexArray.__proto__ = StructArrayLayout1ul2ui8;
  6674. FeatureIndexArray.prototype = Object.create( StructArrayLayout1ul2ui8 && StructArrayLayout1ul2ui8.prototype );
  6675. FeatureIndexArray.prototype.constructor = FeatureIndexArray;
  6676. FeatureIndexArray.prototype.get = function get (index ) {
  6677. return new FeatureIndexStruct(this, index);
  6678. };
  6679. return FeatureIndexArray;
  6680. }(StructArrayLayout1ul2ui8));
  6681. WebWorkerTransfer.register('FeatureIndexArray', FeatureIndexArray, {omit: ['layers', 'patternFeatures']});
  6682. var arrayTypes = {
  6683. FeatureIndexArray : FeatureIndexArray
  6684. };
  6685. /**
  6686. * A standalone point geometry with useful accessor, comparison, and
  6687. * modification methods.
  6688. *
  6689. * @class Point
  6690. * @param {Number} x the x-coordinate. this could be longitude or screen
  6691. * pixels, or any other sort of unit.
  6692. * @param {Number} y the y-coordinate. this could be latitude or screen
  6693. * pixels, or any other sort of unit.
  6694. * @example
  6695. * var point = new Point(-77, 38);
  6696. */
  6697. function Point(x, y) {
  6698. this.x = x;
  6699. this.y = y;
  6700. }
  6701. Point.prototype = {
  6702. /**
  6703. * Clone this point, returning a new point that can be modified
  6704. * without affecting the old one.
  6705. * @return {Point} the clone
  6706. */
  6707. clone: function() { return new Point(this.x, this.y); },
  6708. /**
  6709. * Add this point's x & y coordinates to another point,
  6710. * yielding a new point.
  6711. * @param {Point} p the other point
  6712. * @return {Point} output point
  6713. */
  6714. add: function(p) { return this.clone()._add(p); },
  6715. /**
  6716. * Subtract this point's x & y coordinates to from point,
  6717. * yielding a new point.
  6718. * @param {Point} p the other point
  6719. * @return {Point} output point
  6720. */
  6721. sub: function(p) { return this.clone()._sub(p); },
  6722. /**
  6723. * Multiply this point's x & y coordinates by point,
  6724. * yielding a new point.
  6725. * @param {Point} p the other point
  6726. * @return {Point} output point
  6727. */
  6728. multByPoint: function(p) { return this.clone()._multByPoint(p); },
  6729. /**
  6730. * Divide this point's x & y coordinates by point,
  6731. * yielding a new point.
  6732. * @param {Point} p the other point
  6733. * @return {Point} output point
  6734. */
  6735. divByPoint: function(p) { return this.clone()._divByPoint(p); },
  6736. /**
  6737. * Multiply this point's x & y coordinates by a factor,
  6738. * yielding a new point.
  6739. * @param {Point} k factor
  6740. * @return {Point} output point
  6741. */
  6742. mult: function(k) { return this.clone()._mult(k); },
  6743. /**
  6744. * Divide this point's x & y coordinates by a factor,
  6745. * yielding a new point.
  6746. * @param {Point} k factor
  6747. * @return {Point} output point
  6748. */
  6749. div: function(k) { return this.clone()._div(k); },
  6750. /**
  6751. * Rotate this point around the 0, 0 origin by an angle a,
  6752. * given in radians
  6753. * @param {Number} a angle to rotate around, in radians
  6754. * @return {Point} output point
  6755. */
  6756. rotate: function(a) { return this.clone()._rotate(a); },
  6757. /**
  6758. * Rotate this point around p point by an angle a,
  6759. * given in radians
  6760. * @param {Number} a angle to rotate around, in radians
  6761. * @param {Point} p Point to rotate around
  6762. * @return {Point} output point
  6763. */
  6764. rotateAround: function(a,p) { return this.clone()._rotateAround(a,p); },
  6765. /**
  6766. * Multiply this point by a 4x1 transformation matrix
  6767. * @param {Array<Number>} m transformation matrix
  6768. * @return {Point} output point
  6769. */
  6770. matMult: function(m) { return this.clone()._matMult(m); },
  6771. /**
  6772. * Calculate this point but as a unit vector from 0, 0, meaning
  6773. * that the distance from the resulting point to the 0, 0
  6774. * coordinate will be equal to 1 and the angle from the resulting
  6775. * point to the 0, 0 coordinate will be the same as before.
  6776. * @return {Point} unit vector point
  6777. */
  6778. unit: function() { return this.clone()._unit(); },
  6779. /**
  6780. * Compute a perpendicular point, where the new y coordinate
  6781. * is the old x coordinate and the new x coordinate is the old y
  6782. * coordinate multiplied by -1
  6783. * @return {Point} perpendicular point
  6784. */
  6785. perp: function() { return this.clone()._perp(); },
  6786. /**
  6787. * Return a version of this point with the x & y coordinates
  6788. * rounded to integers.
  6789. * @return {Point} rounded point
  6790. */
  6791. round: function() { return this.clone()._round(); },
  6792. /**
  6793. * Return the magitude of this point: this is the Euclidean
  6794. * distance from the 0, 0 coordinate to this point's x and y
  6795. * coordinates.
  6796. * @return {Number} magnitude
  6797. */
  6798. mag: function() {
  6799. return Math.sqrt(this.x * this.x + this.y * this.y);
  6800. },
  6801. /**
  6802. * Judge whether this point is equal to another point, returning
  6803. * true or false.
  6804. * @param {Point} other the other point
  6805. * @return {boolean} whether the points are equal
  6806. */
  6807. equals: function(other) {
  6808. return this.x === other.x &&
  6809. this.y === other.y;
  6810. },
  6811. /**
  6812. * Calculate the distance from this point to another point
  6813. * @param {Point} p the other point
  6814. * @return {Number} distance
  6815. */
  6816. dist: function(p) {
  6817. return Math.sqrt(this.distSqr(p));
  6818. },
  6819. /**
  6820. * Calculate the distance from this point to another point,
  6821. * without the square root step. Useful if you're comparing
  6822. * relative distances.
  6823. * @param {Point} p the other point
  6824. * @return {Number} distance
  6825. */
  6826. distSqr: function(p) {
  6827. var dx = p.x - this.x,
  6828. dy = p.y - this.y;
  6829. return dx * dx + dy * dy;
  6830. },
  6831. /**
  6832. * Get the angle from the 0, 0 coordinate to this point, in radians
  6833. * coordinates.
  6834. * @return {Number} angle
  6835. */
  6836. angle: function() {
  6837. return Math.atan2(this.y, this.x);
  6838. },
  6839. /**
  6840. * Get the angle from this point to another point, in radians
  6841. * @param {Point} b the other point
  6842. * @return {Number} angle
  6843. */
  6844. angleTo: function(b) {
  6845. return Math.atan2(this.y - b.y, this.x - b.x);
  6846. },
  6847. /**
  6848. * Get the angle between this point and another point, in radians
  6849. * @param {Point} b the other point
  6850. * @return {Number} angle
  6851. */
  6852. angleWith: function(b) {
  6853. return this.angleWithSep(b.x, b.y);
  6854. },
  6855. /*
  6856. * Find the angle of the two vectors, solving the formula for
  6857. * the cross product a x b = |a||b|sin(θ) for θ.
  6858. * @param {Number} x the x-coordinate
  6859. * @param {Number} y the y-coordinate
  6860. * @return {Number} the angle in radians
  6861. */
  6862. angleWithSep: function(x, y) {
  6863. return Math.atan2(
  6864. this.x * y - this.y * x,
  6865. this.x * x + this.y * y);
  6866. },
  6867. _matMult: function(m) {
  6868. var x = m[0] * this.x + m[1] * this.y,
  6869. y = m[2] * this.x + m[3] * this.y;
  6870. this.x = x;
  6871. this.y = y;
  6872. return this;
  6873. },
  6874. _add: function(p) {
  6875. this.x += p.x;
  6876. this.y += p.y;
  6877. return this;
  6878. },
  6879. _sub: function(p) {
  6880. this.x -= p.x;
  6881. this.y -= p.y;
  6882. return this;
  6883. },
  6884. _mult: function(k) {
  6885. this.x *= k;
  6886. this.y *= k;
  6887. return this;
  6888. },
  6889. _div: function(k) {
  6890. this.x /= k;
  6891. this.y /= k;
  6892. return this;
  6893. },
  6894. _multByPoint: function(p) {
  6895. this.x *= p.x;
  6896. this.y *= p.y;
  6897. return this;
  6898. },
  6899. _divByPoint: function(p) {
  6900. this.x /= p.x;
  6901. this.y /= p.y;
  6902. return this;
  6903. },
  6904. _unit: function() {
  6905. this._div(this.mag());
  6906. return this;
  6907. },
  6908. _perp: function() {
  6909. var y = this.y;
  6910. this.y = this.x;
  6911. this.x = -y;
  6912. return this;
  6913. },
  6914. _rotate: function(angle) {
  6915. var cos = Math.cos(angle),
  6916. sin = Math.sin(angle),
  6917. x = cos * this.x - sin * this.y,
  6918. y = sin * this.x + cos * this.y;
  6919. this.x = x;
  6920. this.y = y;
  6921. return this;
  6922. },
  6923. _rotateAround: function(angle, p) {
  6924. var cos = Math.cos(angle),
  6925. sin = Math.sin(angle),
  6926. x = p.x + cos * (this.x - p.x) - sin * (this.y - p.y),
  6927. y = p.y + sin * (this.x - p.x) + cos * (this.y - p.y);
  6928. this.x = x;
  6929. this.y = y;
  6930. return this;
  6931. },
  6932. _round: function() {
  6933. this.x = Math.round(this.x);
  6934. this.y = Math.round(this.y);
  6935. return this;
  6936. }
  6937. };
  6938. /**
  6939. * Construct a point from an array if necessary, otherwise if the input
  6940. * is already a Point, or an unknown type, return it unchanged
  6941. * @param {Array<Number>|Point|*} a any kind of input value
  6942. * @return {Point} constructed point, or passed-through value.
  6943. * @example
  6944. * // this
  6945. * var point = Point.convert([0, 1]);
  6946. * // is equivalent to
  6947. * var point = new Point(0, 1);
  6948. */
  6949. Point.convert = function (a) {
  6950. if (a instanceof Point) {
  6951. return a;
  6952. }
  6953. if (Array.isArray(a)) {
  6954. return new Point(a[0], a[1]);
  6955. }
  6956. return a;
  6957. };
  6958. function VectorTileFeature(pbf, end, extent, keys, values) {
  6959. // Public
  6960. this.properties = {};
  6961. this.extent = extent;
  6962. this.type = 0;
  6963. // Private
  6964. this._pbf = pbf;
  6965. this._geometry = -1;
  6966. this._keys = keys;
  6967. this._values = values;
  6968. pbf.readFields(readFeature, this, end);
  6969. }
  6970. function readFeature(tag, feature, pbf) {
  6971. if (tag == 1) feature.id = pbf.readVarint();
  6972. else if (tag == 2) readTag(pbf, feature);
  6973. else if (tag == 3) feature.type = pbf.readVarint();
  6974. else if (tag == 4) feature._geometry = pbf.pos;
  6975. }
  6976. function readTag(pbf, feature) {
  6977. var end = pbf.readVarint() + pbf.pos;
  6978. while (pbf.pos < end) {
  6979. var key = feature._keys[pbf.readVarint()],
  6980. value = feature._values[pbf.readVarint()];
  6981. feature.properties[key] = value;
  6982. }
  6983. }
  6984. VectorTileFeature.types = ['Unknown', 'Point', 'LineString', 'Polygon'];
  6985. VectorTileFeature.prototype.loadGeometry = function() {
  6986. var pbf = this._pbf;
  6987. pbf.pos = this._geometry;
  6988. var end = pbf.readVarint() + pbf.pos,
  6989. cmd = 1,
  6990. length = 0,
  6991. x = 0,
  6992. y = 0,
  6993. lines = [],
  6994. line;
  6995. while (pbf.pos < end) {
  6996. if (length <= 0) {
  6997. var cmdLen = pbf.readVarint();
  6998. cmd = cmdLen & 0x7;
  6999. length = cmdLen >> 3;
  7000. }
  7001. length--;
  7002. if (cmd === 1 || cmd === 2) {
  7003. x += pbf.readSVarint();
  7004. y += pbf.readSVarint();
  7005. if (cmd === 1) { // moveTo
  7006. if (line) lines.push(line);
  7007. line = [];
  7008. }
  7009. line.push(new Point(x, y));
  7010. } else if (cmd === 7) {
  7011. // Workaround for https://github.com/mapbox/mapnik-vector-tile/issues/90
  7012. if (line) {
  7013. line.push(line[0].clone()); // closePolygon
  7014. }
  7015. } else {
  7016. console.log('VectorTileFeature loadGeometry unknown command ' + cmd);
  7017. //throw new Error('unknown command ' + cmd);
  7018. }
  7019. }
  7020. if (line) lines.push(line);
  7021. return lines;
  7022. };
  7023. VectorTileFeature.prototype.bbox = function() {
  7024. var pbf = this._pbf;
  7025. pbf.pos = this._geometry;
  7026. var end = pbf.readVarint() + pbf.pos,
  7027. cmd = 1,
  7028. length = 0,
  7029. x = 0,
  7030. y = 0,
  7031. x1 = Infinity,
  7032. x2 = -Infinity,
  7033. y1 = Infinity,
  7034. y2 = -Infinity;
  7035. while (pbf.pos < end) {
  7036. if (length <= 0) {
  7037. var cmdLen = pbf.readVarint();
  7038. cmd = cmdLen & 0x7;
  7039. length = cmdLen >> 3;
  7040. }
  7041. length--;
  7042. if (cmd === 1 || cmd === 2) {
  7043. x += pbf.readSVarint();
  7044. y += pbf.readSVarint();
  7045. if (x < x1) x1 = x;
  7046. if (x > x2) x2 = x;
  7047. if (y < y1) y1 = y;
  7048. if (y > y2) y2 = y;
  7049. } else if (cmd !== 7) {
  7050. throw new Error('unknown command ' + cmd);
  7051. }
  7052. }
  7053. return [x1, y1, x2, y2];
  7054. };
  7055. VectorTileFeature.prototype.toGeoJSON = function(x, y, z) {
  7056. var size = this.extent * Math.pow(2, z),
  7057. x0 = this.extent * x,
  7058. y0 = this.extent * y,
  7059. coords = this.loadGeometry(),
  7060. type = VectorTileFeature.types[this.type],
  7061. i, j;
  7062. function project(line) {
  7063. for (var j = 0; j < line.length; j++) {
  7064. var p = line[j], y2 = 180 - (p.y + y0) * 360 / size;
  7065. line[j] = [
  7066. (p.x + x0) * 360 / size - 180,
  7067. 360 / Math.PI * Math.atan(Math.exp(y2 * Math.PI / 180)) - 90
  7068. ];
  7069. }
  7070. }
  7071. switch (this.type) {
  7072. case 1:
  7073. var points = [];
  7074. for (i = 0; i < coords.length; i++) {
  7075. points[i] = coords[i][0];
  7076. }
  7077. coords = points;
  7078. project(coords);
  7079. break;
  7080. case 2:
  7081. for (i = 0; i < coords.length; i++) {
  7082. project(coords[i]);
  7083. }
  7084. break;
  7085. case 3:
  7086. coords = classifyRings$1(coords);
  7087. for (i = 0; i < coords.length; i++) {
  7088. for (j = 0; j < coords[i].length; j++) {
  7089. project(coords[i][j]);
  7090. }
  7091. }
  7092. break;
  7093. }
  7094. if (coords.length === 1) {
  7095. coords = coords[0];
  7096. } else {
  7097. type = 'Multi' + type;
  7098. }
  7099. var result = {
  7100. type: "Feature",
  7101. geometry: {
  7102. type: type,
  7103. coordinates: coords
  7104. },
  7105. properties: this.properties
  7106. };
  7107. if ('id' in this) {
  7108. result.id = this.id;
  7109. }
  7110. return result;
  7111. };
  7112. // classifies an array of rings into polygons with outer rings and holes
  7113. function classifyRings$1(rings) {
  7114. var len = rings.length;
  7115. if (len <= 1) return [rings];
  7116. var polygons = [],
  7117. polygon,
  7118. ccw;
  7119. for (var i = 0; i < len; i++) {
  7120. var area = signedArea(rings[i]);
  7121. if (area === 0) continue;
  7122. if (ccw === undefined) ccw = area < 0;
  7123. if (ccw === area < 0) {
  7124. if (polygon) polygons.push(polygon);
  7125. polygon = [rings[i]];
  7126. } else {
  7127. polygon.push(rings[i]);
  7128. }
  7129. }
  7130. if (polygon) polygons.push(polygon);
  7131. return polygons;
  7132. }
  7133. function signedArea(ring) {
  7134. var sum = 0;
  7135. for (var i = 0, len = ring.length, j = len - 1, p1, p2; i < len; j = i++) {
  7136. p1 = ring[i];
  7137. p2 = ring[j];
  7138. sum += (p2.x - p1.x) * (p1.y + p2.y);
  7139. }
  7140. return sum;
  7141. }
  7142. function VectorTileLayer(pbf, end) {
  7143. // Public
  7144. this.version = 1;
  7145. this.name = null;
  7146. this.extent = 4096;
  7147. this.length = 0;
  7148. // Private
  7149. this._pbf = pbf;
  7150. this._keys = [];
  7151. this._values = [];
  7152. this._features = [];
  7153. pbf.readFields(readLayer, this, end);
  7154. this.length = this._features.length;
  7155. }
  7156. function readLayer(tag, layer, pbf) {
  7157. if (tag === 15) layer.version = pbf.readVarint();
  7158. else if (tag === 1) layer.name = pbf.readString();
  7159. else if (tag === 5) layer.extent = pbf.readVarint();
  7160. else if (tag === 2) layer._features.push(pbf.pos);
  7161. else if (tag === 3) layer._keys.push(pbf.readString());
  7162. else if (tag === 4) layer._values.push(readValueMessage(pbf));
  7163. }
  7164. function readValueMessage(pbf) {
  7165. var value = null,
  7166. end = pbf.readVarint() + pbf.pos;
  7167. while (pbf.pos < end) {
  7168. var tag = pbf.readVarint() >> 3;
  7169. value = tag === 1 ? pbf.readString() :
  7170. tag === 2 ? pbf.readFloat() :
  7171. tag === 3 ? pbf.readDouble() :
  7172. tag === 4 ? pbf.readVarint64() :
  7173. tag === 5 ? pbf.readVarint() :
  7174. tag === 6 ? pbf.readSVarint() :
  7175. tag === 7 ? pbf.readBoolean() : null;
  7176. }
  7177. return value;
  7178. }
  7179. // return feature `i` from this layer as a `VectorTileFeature`
  7180. VectorTileLayer.prototype.feature = function(i) {
  7181. if (i < 0 || i >= this._features.length) throw new Error('feature index out of bounds');
  7182. this._pbf.pos = this._features[i];
  7183. var end = this._pbf.readVarint() + this._pbf.pos;
  7184. return new VectorTileFeature(this._pbf, end, this.extent, this._keys, this._values);
  7185. };
  7186. function VectorTile(pbf, end) {
  7187. this.layers = pbf.readFields(readTile, {}, end);
  7188. }
  7189. function readTile(tag, layers, pbf) {
  7190. if (tag === 3) {
  7191. var layer = new VectorTileLayer(pbf, pbf.readVarint() + pbf.pos);
  7192. if (layer.length) layers[layer.name] = layer;
  7193. }
  7194. }
  7195. var NUM_PARAMS = 3;
  7196. function GridIndex(extent, n, padding) {
  7197. var cells = this.cells = [];
  7198. if (extent instanceof ArrayBuffer) {
  7199. this.arrayBuffer = extent;
  7200. var array = new Int32Array(this.arrayBuffer);
  7201. extent = array[0];
  7202. n = array[1];
  7203. padding = array[2];
  7204. this.d = n + 2 * padding;
  7205. for (var k = 0; k < this.d * this.d; k++) {
  7206. var start = array[NUM_PARAMS + k];
  7207. var end = array[NUM_PARAMS + k + 1];
  7208. cells.push(start === end ?
  7209. null :
  7210. array.subarray(start, end));
  7211. }
  7212. var keysOffset = array[NUM_PARAMS + cells.length];
  7213. var bboxesOffset = array[NUM_PARAMS + cells.length + 1];
  7214. this.keys = array.subarray(keysOffset, bboxesOffset);
  7215. this.bboxes = array.subarray(bboxesOffset);
  7216. this.insert = this._insertReadonly;
  7217. } else {
  7218. this.d = n + 2 * padding;
  7219. for (var i = 0; i < this.d * this.d; i++) {
  7220. cells.push([]);
  7221. }
  7222. this.keys = [];
  7223. this.bboxes = [];
  7224. }
  7225. this.n = n;
  7226. this.extent = extent;
  7227. this.padding = padding;
  7228. this.scale = n / extent;
  7229. this.uid = 0;
  7230. var p = (padding / n) * extent;
  7231. this.min = -p;
  7232. this.max = extent + p;
  7233. }
  7234. GridIndex.prototype.insert = function(key, x1, y1, x2, y2) {
  7235. this._forEachCell(x1, y1, x2, y2, this._insertCell, this.uid++);
  7236. this.keys.push(key);
  7237. this.bboxes.push(x1);
  7238. this.bboxes.push(y1);
  7239. this.bboxes.push(x2);
  7240. this.bboxes.push(y2);
  7241. };
  7242. GridIndex.prototype._insertReadonly = function() {
  7243. throw 'Cannot insert into a GridIndex created from an ArrayBuffer.';
  7244. };
  7245. GridIndex.prototype._insertCell = function(x1, y1, x2, y2, cellIndex, uid) {
  7246. this.cells[cellIndex].push(uid);
  7247. };
  7248. GridIndex.prototype.query = function(x1, y1, x2, y2, intersectionTest) {
  7249. var min = this.min;
  7250. var max = this.max;
  7251. if (x1 <= min && y1 <= min && max <= x2 && max <= y2 && !intersectionTest) {
  7252. // We use `Array#slice` because `this.keys` may be a `Int32Array` and
  7253. // some browsers (Safari and IE) do not support `TypedArray#slice`
  7254. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/slice#Browser_compatibility
  7255. return Array.prototype.slice.call(this.keys);
  7256. } else {
  7257. var result = [];
  7258. var seenUids = {};
  7259. this._forEachCell(x1, y1, x2, y2, this._queryCell, result, seenUids, intersectionTest);
  7260. return result;
  7261. }
  7262. };
  7263. GridIndex.prototype._queryCell = function(x1, y1, x2, y2, cellIndex, result, seenUids, intersectionTest) {
  7264. var cell = this.cells[cellIndex];
  7265. if (cell !== null) {
  7266. var keys = this.keys;
  7267. var bboxes = this.bboxes;
  7268. for (var u = 0; u < cell.length; u++) {
  7269. var uid = cell[u];
  7270. if (seenUids[uid] === undefined) {
  7271. var offset = uid * 4;
  7272. if (intersectionTest ?
  7273. intersectionTest(bboxes[offset + 0], bboxes[offset + 1], bboxes[offset + 2], bboxes[offset + 3]) :
  7274. ((x1 <= bboxes[offset + 2]) &&
  7275. (y1 <= bboxes[offset + 3]) &&
  7276. (x2 >= bboxes[offset + 0]) &&
  7277. (y2 >= bboxes[offset + 1]))) {
  7278. seenUids[uid] = true;
  7279. result.push(keys[uid]);
  7280. } else {
  7281. seenUids[uid] = false;
  7282. }
  7283. }
  7284. }
  7285. }
  7286. };
  7287. GridIndex.prototype._forEachCell = function(x1, y1, x2, y2, fn, arg1, arg2, intersectionTest) {
  7288. var cx1 = this._convertToCellCoord(x1);
  7289. var cy1 = this._convertToCellCoord(y1);
  7290. var cx2 = this._convertToCellCoord(x2);
  7291. var cy2 = this._convertToCellCoord(y2);
  7292. for (var x = cx1; x <= cx2; x++) {
  7293. for (var y = cy1; y <= cy2; y++) {
  7294. var cellIndex = this.d * y + x;
  7295. if (intersectionTest && !intersectionTest(
  7296. this._convertFromCellCoord(x),
  7297. this._convertFromCellCoord(y),
  7298. this._convertFromCellCoord(x + 1),
  7299. this._convertFromCellCoord(y + 1))) { continue; }
  7300. if (fn.call(this, x1, y1, x2, y2, cellIndex, arg1, arg2, intersectionTest)) { return; }
  7301. }
  7302. }
  7303. };
  7304. GridIndex.prototype._convertFromCellCoord = function(x) {
  7305. return (x - this.padding) / this.scale;
  7306. };
  7307. GridIndex.prototype._convertToCellCoord = function(x) {
  7308. return Math.max(0, Math.min(this.d - 1, Math.floor(x * this.scale) + this.padding));
  7309. };
  7310. GridIndex.prototype.toArrayBuffer = function() {
  7311. if (this.arrayBuffer) { return this.arrayBuffer; }
  7312. var cells = this.cells;
  7313. var metadataLength = NUM_PARAMS + this.cells.length + 1 + 1;
  7314. var totalCellLength = 0;
  7315. for (var i = 0; i < this.cells.length; i++) {
  7316. totalCellLength += this.cells[i].length;
  7317. }
  7318. var array = new Int32Array(metadataLength + totalCellLength + this.keys.length + this.bboxes.length);
  7319. array[0] = this.extent;
  7320. array[1] = this.n;
  7321. array[2] = this.padding;
  7322. var offset = metadataLength;
  7323. for (var k = 0; k < cells.length; k++) {
  7324. var cell = cells[k];
  7325. array[NUM_PARAMS + k] = offset;
  7326. array.set(cell, offset);
  7327. offset += cell.length;
  7328. }
  7329. array[NUM_PARAMS + cells.length] = offset;
  7330. array.set(this.keys, offset);
  7331. offset += this.keys.length;
  7332. array[NUM_PARAMS + cells.length + 1] = offset;
  7333. array.set(this.bboxes, offset);
  7334. offset += this.bboxes.length;
  7335. return array.buffer;
  7336. };
  7337. WebWorkerTransfer.register('GridIndex', GridIndex, {omit: ['layers', 'patternFeatures']});
  7338. /**
  7339. * @module util
  7340. * @private
  7341. */
  7342. function Util() {
  7343. }
  7344. /**
  7345. * Given a value `t` that varies between 0 and 1, return
  7346. * an interpolation function that eases between 0 and 1 in a pleasing
  7347. * cubic in-out fashion.
  7348. *
  7349. * @private
  7350. */
  7351. Util.easeCubicInOut = function (t) {
  7352. if (t <= 0) {
  7353. return 0;
  7354. }
  7355. if (t >= 1) {
  7356. return 1;
  7357. }
  7358. var t2 = t * t,
  7359. t3 = t2 * t;
  7360. return 4 * (t < 0.5 ? t3 : 3 * (t - t2) + t3 - 0.75);
  7361. };
  7362. /*
  7363. * Call an asynchronous function on an array of arguments,
  7364. * calling `callback` with the completed results of all calls.
  7365. *
  7366. * @param array input to each call of the async function.
  7367. * @param fn an async function with signature (data, callback)
  7368. * @param callback a callback run after all async work is done.
  7369. * called with an array, containing the results of each async call.
  7370. * @private
  7371. */
  7372. Util.asyncAll = function (array, fn, callback) {
  7373. if (!array.length) {
  7374. return callback(null, []);
  7375. }
  7376. var remaining = array.length;
  7377. var results = new Array(array.length);
  7378. var error = null;
  7379. array.forEach(function (item, i) {
  7380. fn(item, function (err, result) {
  7381. if (err) {
  7382. error = err;
  7383. }
  7384. results[i] = ((result ) ); // https://github.com/facebook/flow/issues/2123
  7385. if (--remaining === 0) {
  7386. callback(error, results);
  7387. }
  7388. });
  7389. });
  7390. };
  7391. /**
  7392. * Given a destination object and optionally many source objects,
  7393. * copy all properties from the source objects into the destination.
  7394. * The last source object given overrides properties from previous
  7395. * source objects.
  7396. *
  7397. * @param dest destination object
  7398. * @param sources sources from which properties are pulled
  7399. * @private
  7400. */
  7401. Util.extend = function (dest) {
  7402. var sources = [], len = arguments.length - 1;
  7403. while (len-- > 0) sources[ len ] = arguments[ len + 1 ];
  7404. for (var i = 0, list = sources; i < list.length; i += 1) {
  7405. var src = list[i];
  7406. for (var k in src) {
  7407. dest[k] = src[k];
  7408. }
  7409. }
  7410. return dest;
  7411. };
  7412. var id = 1;
  7413. /**
  7414. * Return a unique numeric id, starting at 1 and incrementing with
  7415. * each call.
  7416. *
  7417. * @returns unique numeric id.
  7418. * @private
  7419. */
  7420. Util.uniqueId = function () {
  7421. return id++;
  7422. };
  7423. /**
  7424. * Return a random UUID (v4). Taken from: https://gist.github.com/jed/982883
  7425. * @private
  7426. */
  7427. Util.uuid = function () {
  7428. function b(a) {
  7429. return a ? (a ^ Math.random() * 16 >> a / 4).toString(16) :
  7430. //$FlowFixMe: Flow doesn't like the implied array literal conversion here
  7431. ([1e7] + -[1e3] + -4e3 + -8e3 + -1e11).replace(/[018]/g, b);
  7432. }
  7433. return b();
  7434. };
  7435. /**
  7436. * Validate a string to match UUID(v4) of the
  7437. * form: xxxxxxxx-xxxx-4xxx-[89ab]xxx-xxxxxxxxxxxx
  7438. * @param str string to validate.
  7439. * @private
  7440. */
  7441. Util.validateUuid = function (str) {
  7442. 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;
  7443. };
  7444. /**
  7445. * Given an array of member function names as strings, replace all of them
  7446. * with bound versions that will always refer to `context` as `this`. This
  7447. * is useful for classes where otherwise event bindings would reassign
  7448. * `this` to the evented object or some other value: this lets you ensure
  7449. * the `this` value always.
  7450. *
  7451. * @param fns list of member function names
  7452. * @param context the context value
  7453. * @example
  7454. * function MyClass() {
  7455. * bindAll(['ontimer'], this);
  7456. * this.name = 'Tom';
  7457. * }
  7458. * MyClass.prototype.ontimer = function() {
  7459. * alert(this.name);
  7460. * };
  7461. * var myClass = new MyClass();
  7462. * setTimeout(myClass.ontimer, 100);
  7463. * @private
  7464. */
  7465. Util.bindAll = function (fns, context) {
  7466. fns.forEach(function (fn) {
  7467. if (!context[fn]) {
  7468. return;
  7469. }
  7470. context[fn] = context[fn].bind(context);
  7471. });
  7472. };
  7473. /**
  7474. * Determine if a string ends with a particular substring
  7475. *
  7476. * @private
  7477. */
  7478. Util.endsWith = function (string, suffix) {
  7479. return string.indexOf(suffix, string.length - suffix.length) !== -1;
  7480. };
  7481. /**
  7482. * Create an object by mapping all the values of an existing object while
  7483. * preserving their keys.
  7484. *
  7485. * @private
  7486. */
  7487. Util.mapObject = function (input, iterator, context) {
  7488. var output = {};
  7489. for (var key in input) {
  7490. output[key] = iterator.call(context || this, input[key], key, input);
  7491. }
  7492. return output;
  7493. };
  7494. /**
  7495. * Create an object by filtering out values of an existing object.
  7496. *
  7497. * @private
  7498. */
  7499. Util.filterObject = function (input, iterator, context) {
  7500. var output = {};
  7501. for (var key in input) {
  7502. if (iterator.call(context || this, input[key], key, input)) {
  7503. output[key] = input[key];
  7504. }
  7505. }
  7506. return output;
  7507. };
  7508. /**
  7509. * Deeply clones two objects.
  7510. *
  7511. * @private
  7512. */
  7513. Util.clone = function (input) {
  7514. if (Array.isArray(input)) {
  7515. return input.map(Util.clone);
  7516. } else if (typeof input === 'object' && input) {
  7517. return ((Util.mapObject(input, Util.clone) ) );
  7518. } else {
  7519. return input;
  7520. }
  7521. };
  7522. Util.deepEqual = function (a, b) {
  7523. if (Array.isArray(a)) {
  7524. if (!Array.isArray(b) || a.length !== b.length) {
  7525. return false;
  7526. }
  7527. for (var i = 0; i < a.length; i++) {
  7528. if (!Util.deepEqual(a[i], b[i])) {
  7529. return false;
  7530. }
  7531. }
  7532. return true;
  7533. }
  7534. if (typeof a === 'object' && a !== null && b !== null) {
  7535. if (!(typeof b === 'object')) {
  7536. return false;
  7537. }
  7538. var keys = Object.keys(a);
  7539. if (keys.length !== Object.keys(b).length) {
  7540. return false;
  7541. }
  7542. for (var key in a) {
  7543. if (!Util.deepEqual(a[key], b[key])) {
  7544. return false;
  7545. }
  7546. }
  7547. return true;
  7548. }
  7549. return a === b;
  7550. };
  7551. /**
  7552. * Check if two arrays have at least one common element.
  7553. *
  7554. * @private
  7555. */
  7556. Util.arraysIntersect = function (a, b) {
  7557. for (var l = 0; l < a.length; l++) {
  7558. if (b.indexOf(a[l]) >= 0) {
  7559. return true;
  7560. }
  7561. }
  7562. return false;
  7563. };
  7564. /**
  7565. * Indicates if the provided Points are in a counter clockwise (true) or clockwise (false) order
  7566. *
  7567. * @private
  7568. * @returns true for a counter clockwise set of points
  7569. */
  7570. // http://bryceboe.com/2006/10/23/line-segment-intersection-algorithm/
  7571. Util.isCounterClockwise = function (a, b, c) {
  7572. return (c.y - a.y) * (b.x - a.x) > (b.y - a.y) * (c.x - a.x);
  7573. };
  7574. /* global self, WorkerGlobalScope */
  7575. /**
  7576. * Retuns true if the when run in the web-worker context.
  7577. *
  7578. * @private
  7579. * @returns {boolean}
  7580. */
  7581. Util.isWorker = function () {
  7582. return typeof WorkerGlobalScope !== 'undefined' && typeof self !== 'undefined' &&
  7583. self instanceof WorkerGlobalScope;
  7584. };
  7585. var _isSafari = null;
  7586. /**
  7587. * Returns true when run in WebKit derived browsers.
  7588. * This is used as a workaround for a memory leak in Safari caused by using Transferable objects to
  7589. * transfer data between WebWorkers and the main thread.
  7590. * https://github.com/mapbox/mapbox-gl-js/issues/8771
  7591. *
  7592. * This should be removed once the underlying Safari issue is fixed.
  7593. *
  7594. * @private
  7595. * @param scope {WindowOrWorkerGlobalScope} Since this function is used both on the main thread and WebWorker context,
  7596. * let the calling scope pass in the global scope object.
  7597. * @returns {boolean}
  7598. */
  7599. Util.isSafari = function (scope) {
  7600. if (_isSafari == null) {
  7601. var userAgent = scope.navigator ? scope.navigator.userAgent : null;
  7602. _isSafari = !!scope.safari || !!(userAgent && (/\b(iPad|iPhone|iPod)\b/.test(userAgent) || (!!userAgent.match('Safari') && !userAgent.match('Chrome'))));
  7603. }
  7604. return _isSafari;
  7605. };
  7606. /**
  7607. * Replace tokens in a string template with values in an object
  7608. *
  7609. * @param properties a key/value relationship between tokens and replacements
  7610. * @param text the template string
  7611. * @returns the template with tokens replaced
  7612. * @private
  7613. */
  7614. Util.resolveTokens = function (properties, text) {
  7615. return text.replace(/{([^{}]+)}/g, function (match, key) {
  7616. return key in properties ? String(properties[key]) : '';
  7617. });
  7618. };
  7619. /**
  7620. * Tracks `let` bindings during expression parsing.
  7621. * @private
  7622. */
  7623. var Scope = function Scope(parent, bindings) {
  7624. if (bindings === void 0) bindings = [];
  7625. this.parent = parent;
  7626. this.bindings = {};
  7627. for (var i = 0, list = bindings; i < list.length; i += 1) {
  7628. var ref = list[i];
  7629. var name = ref[0];
  7630. var expression = ref[1];
  7631. this.bindings[name] = expression;
  7632. }
  7633. };
  7634. Scope.prototype.concat = function concat(bindings) {
  7635. return new Scope(this, bindings);
  7636. };
  7637. Scope.prototype.get = function get(name) {
  7638. if (this.bindings[name]) {
  7639. return this.bindings[name];
  7640. }
  7641. if (this.parent) {
  7642. return this.parent.get(name);
  7643. }
  7644. throw new Error((name + " not found in scope."));
  7645. };
  7646. Scope.prototype.has = function has(name) {
  7647. if (this.bindings[name]) {
  7648. return true;
  7649. }
  7650. return this.parent ? this.parent.has(name) : false;
  7651. };
  7652. var ParsingError = /*@__PURE__*/(function (Error) {
  7653. function ParsingError(key , message ) {
  7654. Error.call(this, message);
  7655. this.message = message;
  7656. this.key = key;
  7657. }
  7658. if ( Error ) ParsingError.__proto__ = Error;
  7659. ParsingError.prototype = Object.create( Error && Error.prototype );
  7660. ParsingError.prototype.constructor = ParsingError;
  7661. return ParsingError;
  7662. }(Error));
  7663. var geometryTypes = ['Unknown', 'Point', 'LineString', 'Polygon'];
  7664. var EvaluationContext = function EvaluationContext() {
  7665. this.globals = (null );
  7666. this.feature = null;
  7667. this.featureState = null;
  7668. this.formattedSection = null;
  7669. this._parseColorCache = {};
  7670. this.availableImages = null;
  7671. };
  7672. EvaluationContext.prototype.id = function id () {
  7673. return this.feature && 'id' in this.feature ? this.feature.id : null;
  7674. };
  7675. EvaluationContext.prototype.geometryType = function geometryType () {
  7676. return this.feature ? typeof this.feature.type === 'number' ? geometryTypes[this.feature.type] : this.feature.type : null;
  7677. };
  7678. EvaluationContext.prototype.properties = function properties () {
  7679. return this.feature && this.feature.properties || {};
  7680. };
  7681. EvaluationContext.prototype.parseColor = function parseColor (input ) {
  7682. var cached = this._parseColorCache[input];
  7683. if (!cached) {
  7684. cached = this._parseColorCache[input] = Color.parse(input);
  7685. }
  7686. return cached;
  7687. };
  7688. WebWorkerTransfer.register('EvaluationContext', EvaluationContext);
  7689. function isConstant() {
  7690. }
  7691. isConstant.isFeatureConstant = function(e){
  7692. var CompoundExpression = ParsingContext.CompoundExpression;
  7693. if (e instanceof CompoundExpression) {
  7694. if (e.name === 'get' && e.args.length === 1) {
  7695. return false;
  7696. } else if (e.name === 'feature-state') {
  7697. return false;
  7698. } else if (e.name === 'has' && e.args.length === 1) {
  7699. return false;
  7700. } else if (
  7701. e.name === 'properties' ||
  7702. e.name === 'geometry-type' ||
  7703. e.name === 'id'
  7704. ) {
  7705. return false;
  7706. } else if (/^filter-/.test(e.name)) {
  7707. return false;
  7708. }
  7709. }
  7710. var result = true;
  7711. e.eachChild(function (arg) {
  7712. if (result && !isConstant.isFeatureConstant(arg)) {
  7713. result = false;
  7714. }
  7715. });
  7716. return result;
  7717. };
  7718. isConstant.isStateConstant = function(e){
  7719. var CompoundExpression = ParsingContext.CompoundExpression;
  7720. if (e instanceof CompoundExpression) {
  7721. if (e.name === 'feature-state') {
  7722. return false;
  7723. }
  7724. }
  7725. var result = true;
  7726. e.eachChild(function (arg) {
  7727. if (result && !isConstant.isStateConstant(arg)) {
  7728. result = false;
  7729. }
  7730. });
  7731. return result;
  7732. };
  7733. isConstant.isGlobalPropertyConstant = function(e, properties){
  7734. var CompoundExpression = ParsingContext.CompoundExpression;
  7735. if (e instanceof CompoundExpression && properties.indexOf(e.name) >= 0) {
  7736. return false;
  7737. }
  7738. var result = true;
  7739. e.eachChild(function (arg) {
  7740. if (result && !isConstant.isGlobalPropertyConstant(arg, properties)) {
  7741. result = false;
  7742. }
  7743. });
  7744. return result;
  7745. };
  7746. /**
  7747. * State associated parsing at a given point in an expression tree.
  7748. * @private
  7749. */
  7750. var ParsingContext = function ParsingContext(registry, path, expectedType, scope, errors) {
  7751. if (path === void 0) path = [];
  7752. if (scope === void 0) scope = new Scope();
  7753. if (errors === void 0) errors = [];
  7754. this.registry = registry;
  7755. this.path = path;
  7756. this.key = path.map(function (part) {
  7757. return ("[" + part + "]");
  7758. }).join('');
  7759. this.scope = scope;
  7760. this.errors = errors;
  7761. this.expectedType = expectedType;
  7762. };
  7763. /**
  7764. * @param expr the JSON expression to parse
  7765. * @param index the optional argument index if this expression is an argument of a parent expression that's being parsed
  7766. * @param options
  7767. * @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.
  7768. * @private
  7769. */
  7770. ParsingContext.prototype.parse = function parse(expr, index, expectedType, bindings, options) {
  7771. if (options === void 0) options = {};
  7772. if (index) {
  7773. return this.concat(index, expectedType, bindings)._parse(expr, options);
  7774. }
  7775. return this._parse(expr, options);
  7776. };
  7777. ParsingContext.prototype._parse = function _parse(expr, options) {
  7778. if (expr === null || typeof expr === 'string' || typeof expr === 'boolean' || typeof expr === 'number') {
  7779. expr = ['literal', expr];
  7780. }
  7781. function annotate(parsed, type, typeAnnotation) {
  7782. if (typeAnnotation === 'assert') {
  7783. return new Assertion(type, [parsed]);
  7784. } else if (typeAnnotation === 'coerce') {
  7785. return new Coercion(type, [parsed]);
  7786. } else {
  7787. return parsed;
  7788. }
  7789. }
  7790. if (Array.isArray(expr)) {
  7791. if (expr.length === 0) {
  7792. return this.error("Expected an array with at least one element. If you wanted a literal array, use [\"literal\", []].");
  7793. }
  7794. var op = expr[0];
  7795. if (typeof op !== 'string') {
  7796. this.error(("Expression name must be a string, but found " + (typeof op) + " instead. If you wanted a literal array, use [\"literal\", [...]]."), 0);
  7797. return null;
  7798. }
  7799. var Expr = this.registry[op];
  7800. if (Expr) {
  7801. var parsed = Expr.parse(expr, this);
  7802. if (!parsed) {
  7803. return null;
  7804. }
  7805. if (this.expectedType) {
  7806. var expected = this.expectedType;
  7807. var actual = parsed.type;
  7808. // When we expect a number, string, boolean, or array but have a value, wrap it in an assertion.
  7809. // When we expect a color or formatted string, but have a string or value, wrap it in a coercion.
  7810. // Otherwise, we do static type-checking.
  7811. //
  7812. // These behaviors are overridable for:
  7813. // * The "coalesce" operator, which needs to omit type annotations.
  7814. // * String-valued properties (e.g. `text-field`), where coercion is more convenient than assertion.
  7815. //
  7816. if ((expected.kind === 'string' || expected.kind === 'number' || expected.kind === 'boolean' || expected.kind === 'object' || expected.kind === 'array') && actual.kind === 'value') {
  7817. parsed = annotate(parsed, expected, options.typeAnnotation || 'assert');
  7818. } else if ((expected.kind === 'color' || expected.kind === 'formatted' || expected.kind === 'resolvedImage') && (actual.kind === 'value' || actual.kind === 'string')) {
  7819. parsed = annotate(parsed, expected, options.typeAnnotation || 'coerce');
  7820. } else if (this.checkSubtype(expected, actual)) {
  7821. return null;
  7822. }
  7823. }
  7824. // If an expression's arguments are all literals, we can evaluate
  7825. // it immediately and replace it with a literal value in the
  7826. // parsed/compiled result. Expressions that expect an image should
  7827. // not be resolved here so we can later get the available images.
  7828. if (!(parsed instanceof Literal) && (parsed.type.kind !== 'resolvedImage') && isConstant()) {
  7829. var ec = new EvaluationContext();
  7830. try {
  7831. parsed = new Literal(parsed.type, parsed.evaluate(ec));
  7832. } catch (e) {
  7833. this.error(e.message);
  7834. return null;
  7835. }
  7836. }
  7837. return parsed;
  7838. }
  7839. return this.error(("Unknown expression \"" + op + "\". If you wanted a literal array, use [\"literal\", [...]]."), 0);
  7840. } else if (typeof expr === 'undefined') {
  7841. return this.error("'undefined' value invalid. Use null instead.");
  7842. } else if (typeof expr === 'object') {
  7843. return this.error("Bare objects invalid. Use [\"literal\", {...}] instead.");
  7844. } else {
  7845. return this.error(("Expected an array, but found " + (typeof expr) + " instead."));
  7846. }
  7847. };
  7848. /**
  7849. * Returns a copy of this context suitable for parsing the subexpression at
  7850. * index `index`, optionally appending to 'let' binding map.
  7851. *
  7852. * Note that `errors` property, intended for collecting errors while
  7853. * parsing, is copied by reference rather than cloned.
  7854. * @private
  7855. */
  7856. ParsingContext.prototype.concat = function concat(index, expectedType, bindings) {
  7857. var path = typeof index === 'number' ? this.path.concat(index) : this.path;
  7858. var scope = bindings ? this.scope.concat(bindings) : this.scope;
  7859. return new ParsingContext(
  7860. this.registry,
  7861. path,
  7862. expectedType || null,
  7863. scope,
  7864. this.errors
  7865. );
  7866. };
  7867. /**
  7868. * Push a parsing (or type checking) error into the `this.errors`
  7869. * @param error The message
  7870. * @param keys Optionally specify the source of the error at a child
  7871. * of the current expression at `this.key`.
  7872. * @private
  7873. */
  7874. ParsingContext.prototype.error = function error(error$1) {
  7875. var keys = [], len = arguments.length - 1;
  7876. while (len-- > 0) keys[ len ] = arguments[ len + 1 ];
  7877. var key = "" + (this.key) + (keys.map(function (k) {
  7878. return ("[" + k + "]");
  7879. }).join(''));
  7880. this.errors.push(new ParsingError(key, error$1));
  7881. };
  7882. /**
  7883. * Returns null if `t` is a subtype of `expected`; otherwise returns an
  7884. * error message and also pushes it to `this.errors`.
  7885. */
  7886. ParsingContext.prototype.checkSubtype = function checkSubtype$1(expected, t) {
  7887. var error = checkSubtype(expected, t);
  7888. if (error) {
  7889. this.error(error);
  7890. }
  7891. return error;
  7892. };
  7893. function get(key, obj) {
  7894. const v = obj[key];
  7895. return typeof v === 'undefined' ? null : v;
  7896. }
  7897. var CompoundExpression = function CompoundExpression(name, type, evaluate, args) {
  7898. this.name = name;
  7899. this.type = type;
  7900. this._evaluate = evaluate;
  7901. this.args = args;
  7902. };
  7903. CompoundExpression.prototype.evaluate = function evaluate(ctx, crossFields) {
  7904. return this._evaluate(ctx, this.args, crossFields);
  7905. };
  7906. CompoundExpression.prototype.eachChild = function eachChild(fn) {
  7907. this.args.forEach(fn);
  7908. };
  7909. CompoundExpression.prototype.possibleOutputs = function possibleOutputs() {
  7910. return [undefined];
  7911. };
  7912. CompoundExpression.prototype.serialize = function serialize() {
  7913. return [this.name].concat(this.args.map(function (arg) {
  7914. return arg.serialize();
  7915. }));
  7916. };
  7917. CompoundExpression.parse = function parse(args, context) {
  7918. var ref$1;
  7919. var op = (args[0] );
  7920. var definition = CompoundExpression.definitions[op];
  7921. if (!definition) {
  7922. return context.error(("Unknown expression \"" + op + "\". If you wanted a literal array, use [\"literal\", [...]]."), 0);
  7923. }
  7924. // Now check argument types against each signature
  7925. var type = Array.isArray(definition) ?
  7926. definition[0] : definition.type;
  7927. var availableOverloads = Array.isArray(definition) ?
  7928. [
  7929. [definition[1], definition[2]]
  7930. ] :
  7931. definition.overloads;
  7932. var overloads = availableOverloads.filter(function (ref) {
  7933. var signature = ref[0];
  7934. return (
  7935. !Array.isArray(signature) || // varags
  7936. signature.length === args.length - 1 // correct param count
  7937. );
  7938. });
  7939. var signatureContext = (null );
  7940. for (var i$3 = 0, list = overloads; i$3 < list.length; i$3 += 1) {
  7941. // Use a fresh context for each attempted signature so that, if
  7942. // we eventually succeed, we haven't polluted `context.errors`.
  7943. var ref = list[i$3];
  7944. var params = ref[0];
  7945. var evaluate = ref[1];
  7946. signatureContext = new ParsingContext(context.registry, context.path, null, context.scope);
  7947. // First parse all the args, potentially coercing to the
  7948. // types expected by this overload.
  7949. var parsedArgs = [];
  7950. var argParseFailed = false;
  7951. for (var i = 1; i < args.length; i++) {
  7952. var arg = args[i];
  7953. var expectedType = Array.isArray(params) ?
  7954. params[i - 1] :
  7955. params.type;
  7956. var parsed = signatureContext.parse(arg, 1 + parsedArgs.length, expectedType);
  7957. if (!parsed) {
  7958. argParseFailed = true;
  7959. break;
  7960. }
  7961. parsedArgs.push(parsed);
  7962. }
  7963. if (argParseFailed) {
  7964. // Couldn't coerce args of this overload to expected type, move
  7965. // on to next one.
  7966. continue;
  7967. }
  7968. if (Array.isArray(params)) {
  7969. if (params.length !== parsedArgs.length) {
  7970. signatureContext.error(("Expected " + (params.length) + " arguments, but found " + (parsedArgs.length) + " instead."));
  7971. continue;
  7972. }
  7973. }
  7974. for (var i$1 = 0; i$1 < parsedArgs.length; i$1++) {
  7975. var expected = Array.isArray(params) ? params[i$1] : params.type;
  7976. var arg$1 = parsedArgs[i$1];
  7977. signatureContext.concat(i$1 + 1).checkSubtype(expected, arg$1.type);
  7978. }
  7979. if (signatureContext.errors.length === 0) {
  7980. return new CompoundExpression(op, type, evaluate, parsedArgs);
  7981. }
  7982. }
  7983. if (overloads.length === 1) {
  7984. (ref$1 = context.errors).push.apply(ref$1, signatureContext.errors);
  7985. } else {
  7986. var expected$1 = overloads.length ? overloads : availableOverloads;
  7987. var signatures = expected$1
  7988. .map(function (ref) {
  7989. var params = ref[0];
  7990. return stringifySignature(params);
  7991. })
  7992. .join(' | ');
  7993. var actualTypes = [];
  7994. // For error message, re-parse arguments without trying to
  7995. // apply any coercions
  7996. for (var i$2 = 1; i$2 < args.length; i$2++) {
  7997. var parsed$1 = context.parse(args[i$2], 1 + actualTypes.length);
  7998. if (!parsed$1) {
  7999. return null;
  8000. }
  8001. actualTypes.push(toString(parsed$1.type));
  8002. }
  8003. context.error(("Expected arguments of type " + signatures + ", but found (" + (actualTypes.join(', ')) + ") instead."));
  8004. }
  8005. return null;
  8006. };
  8007. CompoundExpression.register = function register(registry, definitions) {
  8008. CompoundExpression.definitions = definitions;
  8009. for (var name in definitions) {
  8010. registry[name] = CompoundExpression;
  8011. }
  8012. };
  8013. WebWorkerTransfer.register('CompoundExpression', CompoundExpression);
  8014. function stringifySignature(signature) {
  8015. if (Array.isArray(signature)) {
  8016. return ("(" + (signature.map(toString).join(', ')) + ")");
  8017. } else {
  8018. return ("(" + (toString(signature.type)) + "...)");
  8019. }
  8020. }
  8021. var NumberType$a = {kind: 'number'};
  8022. var StringType$8 = {kind: 'string'};
  8023. var BooleanType$8 = {kind: 'boolean'};
  8024. var ColorType$5 = {kind: 'color'};
  8025. var ObjectType$3 = {kind: 'object'};
  8026. var ValueType$a = {kind: 'value'};
  8027. var ErrorType = {kind: 'error'};
  8028. var CollatorType$3 = {kind: 'collator'};
  8029. function array$5(itemType, N) {
  8030. return {
  8031. kind: 'array',
  8032. itemType: itemType,
  8033. N: N
  8034. };
  8035. }
  8036. function varargs(type) {
  8037. return {type: type};
  8038. }
  8039. function rgba(ctx, ref) {
  8040. var r = ref[0];
  8041. var g = ref[1];
  8042. var b = ref[2];
  8043. var a = ref[3];
  8044. r = r.evaluate(ctx);
  8045. g = g.evaluate(ctx);
  8046. b = b.evaluate(ctx);
  8047. var alpha = a ? a.evaluate(ctx) : 1;
  8048. var error = Values.validateRGBA(r, g, b, alpha);
  8049. if (error) {
  8050. throw new RuntimeError(error);
  8051. }
  8052. return new Color(r / 255 * alpha, g / 255 * alpha, b / 255 * alpha, alpha);
  8053. }
  8054. CompoundExpression.register(expressions, {
  8055. 'error': [
  8056. ErrorType,
  8057. [StringType$8],
  8058. function (ctx, ref) {
  8059. var v = ref[0];
  8060. throw new RuntimeError(v.evaluate(ctx));
  8061. }
  8062. ],
  8063. 'typeof': [
  8064. StringType$8,
  8065. [ValueType$a],
  8066. function (ctx, ref) {
  8067. var v = ref[0];
  8068. return toString(Values.typeOf(v.evaluate(ctx)));
  8069. }
  8070. ],
  8071. 'to-rgba': [
  8072. array$5(NumberType$a, 4),
  8073. [ColorType$5],
  8074. function (ctx, ref) {
  8075. var v = ref[0];
  8076. return v.evaluate(ctx).toArray();
  8077. }
  8078. ],
  8079. 'rgb': [
  8080. ColorType$5,
  8081. [NumberType$a, NumberType$a, NumberType$a],
  8082. rgba
  8083. ],
  8084. 'rgba': [
  8085. ColorType$5,
  8086. [NumberType$a, NumberType$a, NumberType$a, NumberType$a],
  8087. rgba
  8088. ],
  8089. 'has': {
  8090. type: BooleanType$8,
  8091. overloads: [
  8092. [
  8093. [StringType$8],
  8094. function (ctx, ref) {
  8095. var key = ref[0];
  8096. return has(key.evaluate(ctx), ctx.properties());
  8097. }
  8098. ],
  8099. [
  8100. [StringType$8, ObjectType$3],
  8101. function (ctx, ref) {
  8102. var key = ref[0];
  8103. var obj = ref[1];
  8104. return has(key.evaluate(ctx), obj.evaluate(ctx));
  8105. }
  8106. ]
  8107. ]
  8108. },
  8109. 'get': {
  8110. type: ValueType$a,
  8111. overloads: [
  8112. [
  8113. [StringType$8],
  8114. function (ctx, ref) {
  8115. var key = ref[0];
  8116. return get(key.evaluate(ctx), ctx.properties());
  8117. }
  8118. ],
  8119. [
  8120. [StringType$8, ObjectType$3],
  8121. function (ctx, ref) {
  8122. var key = ref[0];
  8123. var obj = ref[1];
  8124. return get(key.evaluate(ctx), obj.evaluate(ctx));
  8125. }
  8126. ]
  8127. ]
  8128. },
  8129. 'feature-state': [
  8130. ValueType$a,
  8131. [StringType$8],
  8132. function (ctx, ref) {
  8133. var key = ref[0];
  8134. return get(key.evaluate(ctx), ctx.featureState || {});
  8135. }
  8136. ],
  8137. 'properties': [
  8138. ObjectType$3,
  8139. [],
  8140. function (ctx) {
  8141. return ctx.properties();
  8142. }
  8143. ],
  8144. 'geometry-type': [
  8145. StringType$8,
  8146. [],
  8147. function (ctx) {
  8148. return ctx.geometryType();
  8149. }
  8150. ],
  8151. 'id': [
  8152. ValueType$a,
  8153. [],
  8154. function (ctx) {
  8155. return ctx.id();
  8156. }
  8157. ],
  8158. 'zoom': [
  8159. NumberType$a,
  8160. [],
  8161. function (ctx) {
  8162. return ctx.globals.zoom;
  8163. }
  8164. ],
  8165. 'heatmap-density': [
  8166. NumberType$a,
  8167. [],
  8168. function (ctx) {
  8169. return ctx.globals.heatmapDensity || 0;
  8170. }
  8171. ],
  8172. 'line-progress': [
  8173. NumberType$a,
  8174. [],
  8175. function (ctx) {
  8176. return ctx.globals.lineProgress || 0;
  8177. }
  8178. ],
  8179. 'accumulated': [
  8180. ValueType$a,
  8181. [],
  8182. function (ctx) {
  8183. return ctx.globals.accumulated === undefined ? null : ctx.globals.accumulated;
  8184. }
  8185. ],
  8186. '+': [
  8187. NumberType$a,
  8188. varargs(NumberType$a),
  8189. function (ctx, args) {
  8190. var result = 0;
  8191. for (var i = 0, list = args; i < list.length; i += 1) {
  8192. var arg = list[i];
  8193. result += arg.evaluate(ctx);
  8194. }
  8195. return result;
  8196. }
  8197. ],
  8198. '*': [
  8199. NumberType$a,
  8200. varargs(NumberType$a),
  8201. function (ctx, args) {
  8202. var result = 1;
  8203. for (var i = 0, list = args; i < list.length; i += 1) {
  8204. var arg = list[i];
  8205. result *= arg.evaluate(ctx);
  8206. }
  8207. return result;
  8208. }
  8209. ],
  8210. '-': {
  8211. type: NumberType$a,
  8212. overloads: [
  8213. [
  8214. [NumberType$a, NumberType$a],
  8215. function (ctx, ref) {
  8216. var a = ref[0];
  8217. var b = ref[1];
  8218. return a.evaluate(ctx) - b.evaluate(ctx);
  8219. }
  8220. ],
  8221. [
  8222. [NumberType$a],
  8223. function (ctx, ref) {
  8224. var a = ref[0];
  8225. return -a.evaluate(ctx);
  8226. }
  8227. ]
  8228. ]
  8229. },
  8230. '/': [
  8231. NumberType$a,
  8232. [NumberType$a, NumberType$a],
  8233. function (ctx, ref) {
  8234. var a = ref[0];
  8235. var b = ref[1];
  8236. return a.evaluate(ctx) / b.evaluate(ctx);
  8237. }
  8238. ],
  8239. '%': [
  8240. NumberType$a,
  8241. [NumberType$a, NumberType$a],
  8242. function (ctx, ref) {
  8243. var a = ref[0];
  8244. var b = ref[1];
  8245. return a.evaluate(ctx) % b.evaluate(ctx);
  8246. }
  8247. ],
  8248. 'ln2': [
  8249. NumberType$a,
  8250. [],
  8251. function () {
  8252. return Math.LN2;
  8253. }
  8254. ],
  8255. 'pi': [
  8256. NumberType$a,
  8257. [],
  8258. function () {
  8259. return Math.PI;
  8260. }
  8261. ],
  8262. 'e': [
  8263. NumberType$a,
  8264. [],
  8265. function () {
  8266. return Math.E;
  8267. }
  8268. ],
  8269. '^': [
  8270. NumberType$a,
  8271. [NumberType$a, NumberType$a],
  8272. function (ctx, ref) {
  8273. var b = ref[0];
  8274. var e = ref[1];
  8275. return Math.pow(b.evaluate(ctx), e.evaluate(ctx));
  8276. }
  8277. ],
  8278. 'sqrt': [
  8279. NumberType$a,
  8280. [NumberType$a],
  8281. function (ctx, ref) {
  8282. var x = ref[0];
  8283. return Math.sqrt(x.evaluate(ctx));
  8284. }
  8285. ],
  8286. 'log10': [
  8287. NumberType$a,
  8288. [NumberType$a],
  8289. function (ctx, ref) {
  8290. var n = ref[0];
  8291. return Math.log(n.evaluate(ctx)) / Math.LN10;
  8292. }
  8293. ],
  8294. 'ln': [
  8295. NumberType$a,
  8296. [NumberType$a],
  8297. function (ctx, ref) {
  8298. var n = ref[0];
  8299. return Math.log(n.evaluate(ctx));
  8300. }
  8301. ],
  8302. 'log2': [
  8303. NumberType$a,
  8304. [NumberType$a],
  8305. function (ctx, ref) {
  8306. var n = ref[0];
  8307. return Math.log(n.evaluate(ctx)) / Math.LN2;
  8308. }
  8309. ],
  8310. 'sin': [
  8311. NumberType$a,
  8312. [NumberType$a],
  8313. function (ctx, ref) {
  8314. var n = ref[0];
  8315. return Math.sin(n.evaluate(ctx));
  8316. }
  8317. ],
  8318. 'cos': [
  8319. NumberType$a,
  8320. [NumberType$a],
  8321. function (ctx, ref) {
  8322. var n = ref[0];
  8323. return Math.cos(n.evaluate(ctx));
  8324. }
  8325. ],
  8326. 'tan': [
  8327. NumberType$a,
  8328. [NumberType$a],
  8329. function (ctx, ref) {
  8330. var n = ref[0];
  8331. return Math.tan(n.evaluate(ctx));
  8332. }
  8333. ],
  8334. 'asin': [
  8335. NumberType$a,
  8336. [NumberType$a],
  8337. function (ctx, ref) {
  8338. var n = ref[0];
  8339. return Math.asin(n.evaluate(ctx));
  8340. }
  8341. ],
  8342. 'acos': [
  8343. NumberType$a,
  8344. [NumberType$a],
  8345. function (ctx, ref) {
  8346. var n = ref[0];
  8347. return Math.acos(n.evaluate(ctx));
  8348. }
  8349. ],
  8350. 'atan': [
  8351. NumberType$a,
  8352. [NumberType$a],
  8353. function (ctx, ref) {
  8354. var n = ref[0];
  8355. return Math.atan(n.evaluate(ctx));
  8356. }
  8357. ],
  8358. 'min': [
  8359. NumberType$a,
  8360. varargs(NumberType$a),
  8361. function (ctx, args) {
  8362. return Math.min.apply(Math, args.map(function (arg) {
  8363. return arg.evaluate(ctx);
  8364. }));
  8365. }
  8366. ],
  8367. 'max': [
  8368. NumberType$a,
  8369. varargs(NumberType$a),
  8370. function (ctx, args) {
  8371. return Math.max.apply(Math, args.map(function (arg) {
  8372. return arg.evaluate(ctx);
  8373. }));
  8374. }
  8375. ],
  8376. 'abs': [
  8377. NumberType$a,
  8378. [NumberType$a],
  8379. function (ctx, ref) {
  8380. var n = ref[0];
  8381. return Math.abs(n.evaluate(ctx));
  8382. }
  8383. ],
  8384. 'round': [
  8385. NumberType$a,
  8386. [NumberType$a],
  8387. function (ctx, ref) {
  8388. var n = ref[0];
  8389. var v = n.evaluate(ctx);
  8390. // Javascript's Math.round() rounds towards +Infinity for halfway
  8391. // values, even when they're negative. It's more common to round
  8392. // away from 0 (e.g., this is what python and C++ do)
  8393. return v < 0 ? -Math.round(-v) : Math.round(v);
  8394. }
  8395. ],
  8396. 'floor': [
  8397. NumberType$a,
  8398. [NumberType$a],
  8399. function (ctx, ref) {
  8400. var n = ref[0];
  8401. return Math.floor(n.evaluate(ctx));
  8402. }
  8403. ],
  8404. 'ceil': [
  8405. NumberType$a,
  8406. [NumberType$a],
  8407. function (ctx, ref) {
  8408. var n = ref[0];
  8409. return Math.ceil(n.evaluate(ctx));
  8410. }
  8411. ],
  8412. 'filter-==': [
  8413. BooleanType$8,
  8414. [StringType$8, ValueType$a],
  8415. function (ctx, ref, crossFields) {
  8416. var k = ref[0];
  8417. var v = ref[1];
  8418. if(!crossFields) {
  8419. return ctx.properties()[(k ).value] === (v ).value;
  8420. } else {
  8421. var a, b;
  8422. var kValue = (k ).value;
  8423. var vValue = (v ).value;
  8424. if(/(\S*)\s*([+-])\s*(\S*)/.test(kValue)) {
  8425. var group = kValue.match(/(\S*)\s*([+-])\s*(\S*)/);
  8426. var value1 = ctx.properties()[group[1]];
  8427. var op = group[2];
  8428. var value2 = ctx.properties()[group[3]];
  8429. switch (op) {
  8430. case "+":
  8431. a = value1 + value2;
  8432. break;
  8433. case "-":
  8434. a = value1 - value2;
  8435. break;
  8436. }
  8437. b = (v ).value;
  8438. return a === b;
  8439. } else if(/^(left|right)\s*\((.+)\s*,\s*(\d+)\)/.test(kValue)) {
  8440. var group1 = kValue.match(/^(left|right)\s*\((.+)\s*,\s*(\d+)\)/);
  8441. var substractOp1 = group1[1];
  8442. var value1 = ctx.properties()[group1[2]];
  8443. var substractNum1 = group1[3];
  8444. if(substractOp1 == "left") {
  8445. a = value1.substring(0, substractNum1);
  8446. } else {
  8447. a = value1.substring(value1.length - substractNum1);
  8448. }
  8449. if(/^(left|right)\s*\((.+)\s*,\s*(\d+)\)/.test(vValue)) {
  8450. var group2 = vValue.match(/^(left|right)\s*\((.+)\s*,\s*(\d+)\)/);
  8451. var substractOp2 = group2[1];
  8452. var value2 = ctx.properties()[group2[2]];
  8453. var substractNum2 = group2[3];
  8454. if(substractOp2 == "left") {
  8455. b = value2.substring(0, substractNum2);
  8456. } else {
  8457. b = value2.substring(value2.length - substractNum2);
  8458. }
  8459. } else {
  8460. b = (v ).value;
  8461. }
  8462. return a === b;
  8463. }else {
  8464. return ctx.properties()[(k ).value] === ctx.properties()[(v ).value];
  8465. }
  8466. }
  8467. }
  8468. ],
  8469. 'filter-id-==': [
  8470. BooleanType$8,
  8471. [ValueType$a],
  8472. function (ctx, ref) {
  8473. var v = ref[0];
  8474. return ctx.id() === (v ).value;
  8475. }
  8476. ],
  8477. 'filter-like': [
  8478. BooleanType$8,
  8479. [StringType$8, StringType$8],
  8480. function (ctx, ref) {
  8481. var a = ref[0].value;
  8482. var b = ref[1].value;
  8483. var properties = ctx.properties();
  8484. if(!(a in properties)) {
  8485. return false;
  8486. }
  8487. if(/^%.*[^%]$/.test(b)) { // 以百分号开头并且不以百分号结尾
  8488. b = b.replace("%", "");
  8489. return properties[a].endsWith(b);
  8490. } else if(/^(?!%).+%$/.test(b)) { // 以百分号结尾并且不以百分号开头
  8491. b = b.replace("%", "");
  8492. return properties[a].startsWith(b);
  8493. } else { // 百分号开头百分号结尾 or 不含百分号
  8494. b = b.replace(/%/g, "");
  8495. return (properties[a].indexOf(b)) > -1;
  8496. }
  8497. }
  8498. ],
  8499. 'filter-type-==': [
  8500. BooleanType$8,
  8501. [StringType$8],
  8502. function (ctx, ref) {
  8503. var v = ref[0];
  8504. return ctx.geometryType() === (v ).value;
  8505. }
  8506. ],
  8507. 'filter-<': [
  8508. BooleanType$8,
  8509. [StringType$8, ValueType$a],
  8510. function (ctx, ref, crossFields) {
  8511. var k = ref[0];
  8512. var v = ref[1];
  8513. var a, b;
  8514. var kValue = (k ).value;
  8515. var vValue = (v ).value;
  8516. if(/(\S*)\s*([+-])\s*(\S*)/.test(kValue)) {
  8517. var group = kValue.match(/(\S*)\s*([+-])\s*(\S*)/);
  8518. var value1 = ctx.properties()[group[1]];
  8519. var op = group[2];
  8520. var value2 = ctx.properties()[group[3]];
  8521. switch (op) {
  8522. case "+":
  8523. a = value1 + value2;
  8524. break;
  8525. case "-":
  8526. a = value1 - value2;
  8527. break;
  8528. }
  8529. b = (v ).value;
  8530. } else if(/^(left|right)\s*\((.+)\s*,\s*(\d+)\)/.test(kValue)) {
  8531. var group1 = kValue.match(/^(left|right)\s*\((.+)\s*,\s*(\d+)\)/);
  8532. var substractOp1 = group1[1];
  8533. var value1 = ctx.properties()[group1[2]];
  8534. var substractNum1 = group1[3];
  8535. if(substractOp1 == "left") {
  8536. a = value1.substring(0, substractNum1);
  8537. } else {
  8538. a = value1.substring(value1.length - substractNum1);
  8539. }
  8540. if(/^(left|right)\s*\((.+)\s*,\s*(\d+)\)/.test(vValue)) {
  8541. var group2 = vValue.match(/^(left|right)\s*\((.+)\s*,\s*(\d+)\)/);
  8542. var substractOp2 = group2[1];
  8543. var value2 = ctx.properties()[group2[2]];
  8544. var substractNum2 = group2[3];
  8545. if(substractOp2 == "left") {
  8546. b = value2.substring(0, substractNum2);
  8547. } else {
  8548. b = value2.substring(value2.length - substractNum2);
  8549. }
  8550. } else {
  8551. b = (v ).value;
  8552. }
  8553. }else {
  8554. a = ctx.properties()[(k ).value];
  8555. b = (v ).value;
  8556. if(crossFields) {
  8557. b = ctx.properties()[b];
  8558. }
  8559. }
  8560. if(typeof b === 'number' && !isNaN(Number(a))) {
  8561. a = Number(a);
  8562. }
  8563. return typeof a === typeof b && a < b;
  8564. }
  8565. ],
  8566. 'filter-id-<': [
  8567. BooleanType$8,
  8568. [ValueType$a],
  8569. function (ctx, ref) {
  8570. var v = ref[0];
  8571. var a = ctx.id();
  8572. var b = (v ).value;
  8573. return typeof a === typeof b && a < b;
  8574. }
  8575. ],
  8576. 'filter->': [
  8577. BooleanType$8,
  8578. [StringType$8, ValueType$a],
  8579. function (ctx, ref, crossFields) {
  8580. var k = ref[0];
  8581. var v = ref[1];
  8582. var a, b;
  8583. var kValue = (k ).value;
  8584. var vValue = (v ).value;
  8585. if(/(\S*)\s*([+-])\s*(\S*)/.test(kValue)) {
  8586. var group = kValue.match(/(\S*)\s*([+-])\s*(\S*)/);
  8587. var value1 = ctx.properties()[group[1]];
  8588. var op = group[2];
  8589. var value2 = ctx.properties()[group[3]];
  8590. switch (op) {
  8591. case "+":
  8592. a = value1 + value2;
  8593. break;
  8594. case "-":
  8595. a = value1 - value2;
  8596. break;
  8597. }
  8598. b = (v ).value;
  8599. } else if(/^(left|right)\s*\((.+)\s*,\s*(\d+)\)/.test(kValue)) {
  8600. var group1 = kValue.match(/^(left|right)\s*\((.+)\s*,\s*(\d+)\)/);
  8601. var substractOp1 = group1[1];
  8602. var value1 = ctx.properties()[group1[2]];
  8603. var substractNum1 = group1[3];
  8604. if(substractOp1 == "left") {
  8605. a = value1.substring(0, substractNum1);
  8606. } else {
  8607. a = value1.substring(value1.length - substractNum1);
  8608. }
  8609. if(/^(left|right)\s*\((.+)\s*,\s*(\d+)\)/.test(vValue)) {
  8610. var group2 = vValue.match(/^(left|right)\s*\((.+)\s*,\s*(\d+)\)/);
  8611. var substractOp2 = group2[1];
  8612. var value2 = ctx.properties()[group2[2]];
  8613. var substractNum2 = group2[3];
  8614. if(substractOp2 == "left") {
  8615. b = value2.substring(0, substractNum2);
  8616. } else {
  8617. b = value2.substring(value2.length - substractNum2);
  8618. }
  8619. } else {
  8620. b = (v ).value;
  8621. }
  8622. }else {
  8623. a = ctx.properties()[(k ).value];
  8624. b = (v ).value;
  8625. if(crossFields) {
  8626. b = ctx.properties()[b];
  8627. }
  8628. }
  8629. if(typeof b === 'number' && !isNaN(Number(a))) {
  8630. a = Number(a);
  8631. }
  8632. return typeof a === typeof b && a > b;
  8633. }
  8634. ],
  8635. 'filter-id->': [
  8636. BooleanType$8,
  8637. [ValueType$a],
  8638. function (ctx, ref) {
  8639. var v = ref[0];
  8640. var a = ctx.id();
  8641. var b = (v ).value;
  8642. return typeof a === typeof b && a > b;
  8643. }
  8644. ],
  8645. 'filter-<=': [
  8646. BooleanType$8,
  8647. [StringType$8, ValueType$a],
  8648. function (ctx, ref, crossFields) {
  8649. var k = ref[0];
  8650. var v = ref[1];
  8651. var a, b;
  8652. var kValue = (k ).value;
  8653. var vValue = (v ).value;
  8654. if(/(\S*)\s*([+-])\s*(\S*)/.test(kValue)) {
  8655. var group = kValue.match(/(\S*)\s*([+-])\s*(\S*)/);
  8656. var value1 = ctx.properties()[group[1]];
  8657. var op = group[2];
  8658. var value2 = ctx.properties()[group[3]];
  8659. switch (op) {
  8660. case "+":
  8661. a = value1 + value2;
  8662. break;
  8663. case "-":
  8664. a = value1 - value2;
  8665. break;
  8666. }
  8667. b = (v ).value;
  8668. } else if(/^(left|right)\s*\((.+)\s*,\s*(\d+)\)/.test(kValue)) {
  8669. var group1 = kValue.match(/^(left|right)\s*\((.+)\s*,\s*(\d+)\)/);
  8670. var substractOp1 = group1[1];
  8671. var value1 = ctx.properties()[group1[2]];
  8672. var substractNum1 = group1[3];
  8673. if(substractOp1 == "left") {
  8674. a = value1.substring(0, substractNum1);
  8675. } else {
  8676. a = value1.substring(value1.length - substractNum1);
  8677. }
  8678. if(/^(left|right)\s*\((.+)\s*,\s*(\d+)\)/.test(vValue)) {
  8679. var group2 = vValue.match(/^(left|right)\s*\((.+)\s*,\s*(\d+)\)/);
  8680. var substractOp2 = group2[1];
  8681. var value2 = ctx.properties()[group2[2]];
  8682. var substractNum2 = group2[3];
  8683. if(substractOp2 == "left") {
  8684. b = value2.substring(0, substractNum2);
  8685. } else {
  8686. b = value2.substring(value2.length - substractNum2);
  8687. }
  8688. } else {
  8689. b = (v ).value;
  8690. }
  8691. }else {
  8692. a = ctx.properties()[(k ).value];
  8693. b = (v ).value;
  8694. if(crossFields) {
  8695. b = ctx.properties()[b];
  8696. }
  8697. }
  8698. if(typeof b === 'number' && !isNaN(Number(a))) {
  8699. a = Number(a);
  8700. }
  8701. return typeof a === typeof b && a <= b;
  8702. }
  8703. ],
  8704. 'filter-id-<=': [
  8705. BooleanType$8,
  8706. [ValueType$a],
  8707. function (ctx, ref) {
  8708. var v = ref[0];
  8709. var a = ctx.id();
  8710. var b = (v ).value;
  8711. return typeof a === typeof b && a <= b;
  8712. }
  8713. ],
  8714. 'filter->=': [
  8715. BooleanType$8,
  8716. [StringType$8, ValueType$a],
  8717. function (ctx, ref, crossFields) {
  8718. var k = ref[0];
  8719. var v = ref[1];
  8720. var a, b;
  8721. var kValue = (k ).value;
  8722. var vValue = (v ).value;
  8723. if(/(\S*)\s*([+-])\s*(\S*)/.test(kValue)) {
  8724. var group = kValue.match(/(\S*)\s*([+-])\s*(\S*)/);
  8725. var value1 = ctx.properties()[group[1]];
  8726. var op = group[2];
  8727. var value2 = ctx.properties()[group[3]];
  8728. switch (op) {
  8729. case "+":
  8730. a = value1 + value2;
  8731. break;
  8732. case "-":
  8733. a = value1 - value2;
  8734. break;
  8735. }
  8736. b = (v ).value;
  8737. } else if(/^(left|right)\s*\((.+)\s*,\s*(\d+)\)/.test(kValue)) {
  8738. var group1 = kValue.match(/^(left|right)\s*\((.+)\s*,\s*(\d+)\)/);
  8739. var substractOp1 = group1[1];
  8740. var value1 = ctx.properties()[group1[2]];
  8741. var substractNum1 = group1[3];
  8742. if(substractOp1 == "left") {
  8743. a = value1.substring(0, substractNum1);
  8744. } else {
  8745. a = value1.substring(value1.length - substractNum1);
  8746. }
  8747. if(/^(left|right)\s*\((.+)\s*,\s*(\d+)\)/.test(vValue)) {
  8748. var group2 = vValue.match(/^(left|right)\s*\((.+)\s*,\s*(\d+)\)/);
  8749. var substractOp2 = group2[1];
  8750. var value2 = ctx.properties()[group2[2]];
  8751. var substractNum2 = group2[3];
  8752. if(substractOp2 == "left") {
  8753. b = value2.substring(0, substractNum2);
  8754. } else {
  8755. b = value2.substring(value2.length - substractNum2);
  8756. }
  8757. } else {
  8758. b = (v ).value;
  8759. }
  8760. }else {
  8761. a = ctx.properties()[(k ).value];
  8762. b = (v ).value;
  8763. if(crossFields) {
  8764. b = ctx.properties()[b];
  8765. }
  8766. }
  8767. if(typeof b === 'number' && !isNaN(Number(a))) {
  8768. a = Number(a);
  8769. }
  8770. return typeof a === typeof b && a >= b;
  8771. }
  8772. ],
  8773. 'filter-id->=': [
  8774. BooleanType$8,
  8775. [ValueType$a],
  8776. function (ctx, ref) {
  8777. var v = ref[0];
  8778. var a = ctx.id();
  8779. var b = (v ).value;
  8780. return typeof a === typeof b && a >= b;
  8781. }
  8782. ],
  8783. 'filter-has': [
  8784. BooleanType$8,
  8785. [ValueType$a],
  8786. function (ctx, ref) {
  8787. var k = ref[0];
  8788. return (k ).value in ctx.properties();
  8789. }
  8790. ],
  8791. 'filter-has-id': [
  8792. BooleanType$8,
  8793. [],
  8794. function (ctx) {
  8795. return ctx.id() !== null;
  8796. }
  8797. ],
  8798. 'filter-type-in': [
  8799. BooleanType$8,
  8800. [array$5(StringType$8)],
  8801. function (ctx, ref) {
  8802. var v = ref[0];
  8803. return (v ).value.indexOf(ctx.geometryType()) >= 0;
  8804. }
  8805. ],
  8806. 'filter-id-in': [
  8807. BooleanType$8,
  8808. [array$5(ValueType$a)],
  8809. function (ctx, ref) {
  8810. var v = ref[0];
  8811. return (v ).value.indexOf(ctx.id()) >= 0;
  8812. }
  8813. ],
  8814. 'filter-in-small': [
  8815. BooleanType$8,
  8816. [StringType$8, array$5(ValueType$a)],
  8817. // assumes v is an array literal
  8818. function (ctx, ref) {
  8819. var k = ref[0];
  8820. var v = ref[1];
  8821. return (v ).value.indexOf(ctx.properties()[(k ).value]) >= 0;
  8822. }
  8823. ],
  8824. 'filter-in-large': [
  8825. BooleanType$8,
  8826. [StringType$8, array$5(ValueType$a)],
  8827. // assumes v is a array literal with values sorted in ascending order and of a single type
  8828. function (ctx, ref) {
  8829. var k = ref[0];
  8830. var v = ref[1];
  8831. return binarySearch(ctx.properties()[(k ).value], (v ).value, 0, (v ).value.length - 1);
  8832. }
  8833. ],
  8834. 'all': {
  8835. type: BooleanType$8,
  8836. overloads: [
  8837. [
  8838. [BooleanType$8, BooleanType$8],
  8839. function (ctx, ref) {
  8840. var a = ref[0];
  8841. var b = ref[1];
  8842. return a.evaluate(ctx) && b.evaluate(ctx);
  8843. }
  8844. ],
  8845. [
  8846. varargs(BooleanType$8),
  8847. function (ctx, args) {
  8848. for (var i = 0, list = args; i < list.length; i += 1) {
  8849. var arg = list[i];
  8850. if (!arg.evaluate(ctx)) {
  8851. return false;
  8852. }
  8853. }
  8854. return true;
  8855. }
  8856. ]
  8857. ]
  8858. },
  8859. 'crossFields': {
  8860. type: BooleanType$8,
  8861. overloads: [
  8862. [
  8863. [BooleanType$8, BooleanType$8],
  8864. function (ctx, ref) {
  8865. var a = ref[0];
  8866. var b = ref[1];
  8867. return a.evaluate(ctx, true) && b.evaluate(ctx, true);
  8868. }
  8869. ],
  8870. [
  8871. varargs(BooleanType$8),
  8872. function (ctx, args) {
  8873. for (var i = 0, list = args; i < list.length; i += 1) {
  8874. var arg = list[i];
  8875. if (!arg.evaluate(ctx, true)) {
  8876. return false;
  8877. }
  8878. }
  8879. return true;
  8880. }
  8881. ]
  8882. ]
  8883. },
  8884. 'any': {
  8885. type: BooleanType$8,
  8886. overloads: [
  8887. [
  8888. [BooleanType$8, BooleanType$8],
  8889. function (ctx, ref) {
  8890. var a = ref[0];
  8891. var b = ref[1];
  8892. return a.evaluate(ctx) || b.evaluate(ctx);
  8893. }
  8894. ],
  8895. [
  8896. varargs(BooleanType$8),
  8897. function (ctx, args) {
  8898. for (var i = 0, list = args; i < list.length; i += 1) {
  8899. var arg = list[i];
  8900. if (arg.evaluate(ctx)) {
  8901. return true;
  8902. }
  8903. }
  8904. return false;
  8905. }
  8906. ]
  8907. ]
  8908. },
  8909. '!': [
  8910. BooleanType$8,
  8911. [BooleanType$8],
  8912. function (ctx, ref, crossFields) {
  8913. var b = ref[0];
  8914. return !b.evaluate(ctx, crossFields);
  8915. }
  8916. ],
  8917. 'is-supported-script': [
  8918. BooleanType$8,
  8919. [StringType$8],
  8920. // At parse time this will always return true, so we need to exclude this expression with isGlobalPropertyConstant
  8921. function (ctx, ref) {
  8922. var s = ref[0];
  8923. var isSupportedScript = ctx.globals && ctx.globals.isSupportedScript;
  8924. if (isSupportedScript) {
  8925. return isSupportedScript(s.evaluate(ctx));
  8926. }
  8927. return true;
  8928. }
  8929. ],
  8930. 'upcase': [
  8931. StringType$8,
  8932. [StringType$8],
  8933. function (ctx, ref) {
  8934. var s = ref[0];
  8935. return s.evaluate(ctx).toUpperCase();
  8936. }
  8937. ],
  8938. 'downcase': [
  8939. StringType$8,
  8940. [StringType$8],
  8941. function (ctx, ref) {
  8942. var s = ref[0];
  8943. return s.evaluate(ctx).toLowerCase();
  8944. }
  8945. ],
  8946. 'concat': [
  8947. StringType$8,
  8948. varargs(ValueType$a),
  8949. function (ctx, args) {
  8950. return args.map(function (arg) {
  8951. return Values.toString$1(arg.evaluate(ctx));
  8952. }).join('');
  8953. }
  8954. ],
  8955. 'resolved-locale': [
  8956. StringType$8,
  8957. [CollatorType$3],
  8958. function (ctx, ref) {
  8959. var collator = ref[0];
  8960. return collator.evaluate(ctx).resolvedLocale();
  8961. }
  8962. ]
  8963. });
  8964. ParsingContext.CompoundExpression = CompoundExpression;
  8965. var StyleExpression = function StyleExpression(expression, propertySpec) {
  8966. this.expression = expression;
  8967. this._warningHistory = {};
  8968. this._evaluator = new EvaluationContext();
  8969. this._defaultValue = propertySpec ? getDefaultValue(propertySpec) : null;
  8970. this._enumValues = propertySpec && propertySpec.type === 'enum' ? propertySpec.values : null;
  8971. };
  8972. StyleExpression.prototype.evaluateWithoutErrorHandling = function evaluateWithoutErrorHandling(globals, feature, featureState, availableImages, formattedSection) {
  8973. this._evaluator.globals = globals;
  8974. this._evaluator.feature = feature;
  8975. this._evaluator.featureState = featureState;
  8976. this._evaluator.availableImages = availableImages || null;
  8977. this._evaluator.formattedSection = formattedSection;
  8978. return this.expression.evaluate(this._evaluator);
  8979. };
  8980. StyleExpression.prototype.evaluate = function evaluate(globals, feature, featureState, availableImages, formattedSection) {
  8981. this._evaluator.globals = globals;
  8982. this._evaluator.feature = feature || null;
  8983. this._evaluator.featureState = featureState || null;
  8984. this._evaluator.availableImages = availableImages || null;
  8985. this._evaluator.formattedSection = formattedSection || null;
  8986. try {
  8987. var val = this.expression.evaluate(this._evaluator);
  8988. // eslint-disable-next-line no-self-compare
  8989. if (val === null || val === undefined || (typeof val === 'number' && val !== val)) {
  8990. return this._defaultValue;
  8991. }
  8992. if (this._enumValues && !(val in this._enumValues)) {
  8993. throw new RuntimeError(("Expected value to be one of " + (Object.keys(this._enumValues).map(function (v) {
  8994. return JSON.stringify(v);
  8995. }).join(', ')) + ", but found " + (JSON.stringify(val)) + " instead."));
  8996. }
  8997. return val;
  8998. } catch (e) {
  8999. if (!this._warningHistory[e.message]) {
  9000. this._warningHistory[e.message] = true;
  9001. if (typeof console !== 'undefined') {
  9002. console.warn(e.message);
  9003. }
  9004. }
  9005. return this._defaultValue;
  9006. }
  9007. };
  9008. WebWorkerTransfer.register('StyleExpression', StyleExpression);
  9009. function isFunction(value) {
  9010. return typeof value === 'object' && value !== null && !Array.isArray(value);
  9011. }
  9012. function getDefaultValue(spec) {
  9013. if (spec.type === 'color' && isFunction(spec.default)) {
  9014. // Special case for heatmap-color: it uses the 'default:' to define a
  9015. // default color ramp, but createExpression expects a simple value to fall
  9016. // back to in case of runtime errors
  9017. return new Color(0, 0, 0, 0);
  9018. } else if (spec.type === 'color') {
  9019. return Color.parse(spec.default) || null;
  9020. } else if (spec.default === undefined) {
  9021. return null;
  9022. } else {
  9023. return spec.default;
  9024. }
  9025. }
  9026. // Constants
  9027. var Xn = 0.950470, // D65 standard referent
  9028. Yn = 1,
  9029. Zn = 1.088830,
  9030. t0 = 4 / 29,
  9031. t1 = 6 / 29,
  9032. t2 = 3 * t1 * t1,
  9033. t3 = t1 * t1 * t1,
  9034. deg2rad = Math.PI / 180,
  9035. rad2deg = 180 / Math.PI;
  9036. // Utilities
  9037. function xyz2lab(t) {
  9038. return t > t3 ? Math.pow(t, 1 / 3) : t / t2 + t0;
  9039. }
  9040. function lab2xyz(t) {
  9041. return t > t1 ? t * t * t : t2 * (t - t0);
  9042. }
  9043. function xyz2rgb(x) {
  9044. return 255 * (x <= 0.0031308 ? 12.92 * x : 1.055 * Math.pow(x, 1 / 2.4) - 0.055);
  9045. }
  9046. function rgb2xyz(x) {
  9047. x /= 255;
  9048. return x <= 0.04045 ? x / 12.92 : Math.pow((x + 0.055) / 1.055, 2.4);
  9049. }
  9050. // LAB
  9051. function rgbToLab(rgbColor) {
  9052. var b = rgb2xyz(rgbColor.r),
  9053. a = rgb2xyz(rgbColor.g),
  9054. l = rgb2xyz(rgbColor.b),
  9055. x = xyz2lab((0.4124564 * b + 0.3575761 * a + 0.1804375 * l) / Xn),
  9056. y = xyz2lab((0.2126729 * b + 0.7151522 * a + 0.0721750 * l) / Yn),
  9057. z = xyz2lab((0.0193339 * b + 0.1191920 * a + 0.9503041 * l) / Zn);
  9058. return {
  9059. l: 116 * y - 16,
  9060. a: 500 * (x - y),
  9061. b: 200 * (y - z),
  9062. alpha: rgbColor.a
  9063. };
  9064. }
  9065. function labToRgb(labColor) {
  9066. var y = (labColor.l + 16) / 116,
  9067. x = isNaN(labColor.a) ? y : y + labColor.a / 500,
  9068. z = isNaN(labColor.b) ? y : y - labColor.b / 200;
  9069. y = Yn * lab2xyz(y);
  9070. x = Xn * lab2xyz(x);
  9071. z = Zn * lab2xyz(z);
  9072. return new Color(
  9073. xyz2rgb(3.2404542 * x - 1.5371385 * y - 0.4985314 * z), // D65 -> sRGB
  9074. xyz2rgb(-0.9692660 * x + 1.8760108 * y + 0.0415560 * z),
  9075. xyz2rgb(0.0556434 * x - 0.2040259 * y + 1.0572252 * z),
  9076. labColor.alpha
  9077. );
  9078. }
  9079. function interpolateLab(from, to, t) {
  9080. return {
  9081. l: number(from.l, to.l, t),
  9082. a: number(from.a, to.a, t),
  9083. b: number(from.b, to.b, t),
  9084. alpha: number(from.alpha, to.alpha, t)
  9085. };
  9086. }
  9087. // HCL
  9088. function rgbToHcl(rgbColor) {
  9089. var ref = rgbToLab(rgbColor);
  9090. var l = ref.l;
  9091. var a = ref.a;
  9092. var b = ref.b;
  9093. var h = Math.atan2(b, a) * rad2deg;
  9094. return {
  9095. h: h < 0 ? h + 360 : h,
  9096. c: Math.sqrt(a * a + b * b),
  9097. l: l,
  9098. alpha: rgbColor.a
  9099. };
  9100. }
  9101. function hclToRgb(hclColor) {
  9102. var h = hclColor.h * deg2rad,
  9103. c = hclColor.c,
  9104. l = hclColor.l;
  9105. return labToRgb({
  9106. l: l,
  9107. a: Math.cos(h) * c,
  9108. b: Math.sin(h) * c,
  9109. alpha: hclColor.alpha
  9110. });
  9111. }
  9112. function interpolateHue(a, b, t) {
  9113. var d = b - a;
  9114. return a + t * (d > 180 || d < -180 ? d - 360 * Math.round(d / 360) : d);
  9115. }
  9116. function interpolateHcl(from, to, t) {
  9117. return {
  9118. h: interpolateHue(from.h, to.h, t),
  9119. c: number(from.c, to.c, t),
  9120. l: number(from.l, to.l, t),
  9121. alpha: number(from.alpha, to.alpha, t)
  9122. };
  9123. }
  9124. var lab$1 = {
  9125. forward: rgbToLab,
  9126. reverse: labToRgb,
  9127. interpolate: interpolateLab
  9128. };
  9129. var hcl$1 = {
  9130. forward: rgbToHcl,
  9131. reverse: hclToRgb,
  9132. interpolate: interpolateHcl
  9133. };
  9134. var colorSpaces = /*#__PURE__*/Object.freeze({
  9135. __proto__: null,
  9136. lab: lab$1,
  9137. hcl: hcl$1
  9138. });
  9139. function Expression() {
  9140. }
  9141. function success(value) {
  9142. return {result: 'success', value: value};
  9143. }
  9144. function error(value) {
  9145. return {result: 'error', value: value};
  9146. }
  9147. Expression.isExpression = function (testExpression) {
  9148. return Array.isArray(testExpression) && testExpression.length > 0 &&
  9149. typeof testExpression[0] === 'string' && testExpression[0] in expressions;
  9150. };
  9151. var NumberType$b = {kind: 'number'};
  9152. var StringType$9 = {kind: 'string'};
  9153. var BooleanType$9 = {kind: 'boolean'};
  9154. var ColorType$6 = {kind: 'color'};
  9155. var ValueType$b = {kind: 'value'};
  9156. var FormattedType$3 = {kind: 'formatted'};
  9157. var ResolvedImageType$4 = {kind: 'resolvedImage'};
  9158. function array$6(itemType, N) {
  9159. return {
  9160. kind: 'array',
  9161. itemType: itemType,
  9162. N: N
  9163. };
  9164. }
  9165. // Zoom-dependent expressions may only use ["zoom"] as the input to a top-level "step" or "interpolate"
  9166. // expression (collectively referred to as a "curve"). The curve may be wrapped in one or more "let" or
  9167. // "coalesce" expressions.
  9168. function findZoomCurve(expression) {
  9169. var result = null;
  9170. if (expression instanceof Let) {
  9171. result = findZoomCurve(expression.result);
  9172. } else if (expression instanceof Coalesce) {
  9173. for (var arg of expression.args) {
  9174. result = findZoomCurve(arg);
  9175. if (result) {
  9176. break;
  9177. }
  9178. }
  9179. } else if ((expression instanceof Step || expression instanceof Interpolate) &&
  9180. expression.input instanceof ParsingContext.CompoundExpression &&
  9181. expression.input.name === 'zoom') {
  9182. result = expression;
  9183. }
  9184. if (result instanceof ParsingError) {
  9185. return result;
  9186. }
  9187. expression.eachChild((child) => {
  9188. var childResult = findZoomCurve(child);
  9189. if (childResult instanceof ParsingError) {
  9190. result = childResult;
  9191. } else if (!result && childResult) {
  9192. result = new ParsingError('', '"zoom" expression may only be used as input to a top-level "step" or "interpolate" expression.');
  9193. } else if (result && childResult && result !== childResult) {
  9194. result = new ParsingError('', 'Only one zoom-based "step" or "interpolate" subexpression may be used in an expression.');
  9195. }
  9196. });
  9197. return result;
  9198. }
  9199. function getExpectedType(spec) {
  9200. var types = {
  9201. color: ColorType$6,
  9202. string: StringType$9,
  9203. number: NumberType$b,
  9204. enum: StringType$9,
  9205. boolean: BooleanType$9,
  9206. formatted: FormattedType$3,
  9207. resolvedImage: ResolvedImageType$4
  9208. };
  9209. if (spec.type === 'array') {
  9210. return array$6(types[spec.value] || ValueType$b, spec.length);
  9211. }
  9212. return types[spec.type];
  9213. }
  9214. Expression.createExpression = function (expression, propertySpec) {
  9215. var parser = new ParsingContext(expressions, [], propertySpec ? getExpectedType(propertySpec) : undefined);
  9216. // For string-valued properties, coerce to string at the top level rather than asserting.
  9217. var parsed = parser.parse(expression, undefined, undefined, undefined,
  9218. propertySpec && propertySpec.type === 'string' ? {typeAnnotation: 'coerce'} : undefined);
  9219. if (!parsed) {
  9220. return error(parser.errors);
  9221. }
  9222. return success(new StyleExpression(parsed, propertySpec));
  9223. };
  9224. function isFunction$1(value) {
  9225. return typeof value === 'object' && value !== null && !Array.isArray(value);
  9226. }
  9227. function identityFunction(x) {
  9228. return x;
  9229. }
  9230. function extend$1(output) {
  9231. var inputs = [], len = arguments.length - 1;
  9232. while (len-- > 0) inputs[ len ] = arguments[ len + 1 ];
  9233. for (var i = 0, list = inputs; i < list.length; i += 1) {
  9234. var input = list[i];
  9235. for (var k in input) {
  9236. output[k] = input[k];
  9237. }
  9238. }
  9239. return output;
  9240. }
  9241. function evaluateExponentialFunction(parameters, propertySpec, input) {
  9242. var base = parameters.base !== undefined ? parameters.base : 1;
  9243. // Edge cases
  9244. if (getType(input) !== 'number') return coalesce(parameters.default, propertySpec.default);
  9245. var n = parameters.stops.length;
  9246. if (n === 1) return parameters.stops[0][1];
  9247. if (input <= parameters.stops[0][0]) return parameters.stops[0][1];
  9248. if (input >= parameters.stops[n - 1][0]) return parameters.stops[n - 1][1];
  9249. var index = findStopLessThanOrEqualTo$1(parameters.stops.map((stop) => stop[0]), input);
  9250. var t = interpolationFactor(
  9251. input, base,
  9252. parameters.stops[index][0],
  9253. parameters.stops[index + 1][0]);
  9254. var outputLower = parameters.stops[index][1];
  9255. var outputUpper = parameters.stops[index + 1][1];
  9256. var interp = interpolate[propertySpec.type] || identityFunction; // eslint-disable-line import/namespace
  9257. if (parameters.colorSpace && parameters.colorSpace !== 'rgb') {
  9258. var colorspace = colorSpaces[parameters.colorSpace]; // eslint-disable-line import/namespace
  9259. interp = (a, b) => colorspace.reverse(colorspace.interpolate(colorspace.forward(a), colorspace.forward(b), t));
  9260. }
  9261. if (typeof outputLower.evaluate === 'function') {
  9262. return {
  9263. evaluate(...args) {
  9264. var evaluatedLower = outputLower.evaluate.apply(undefined, args);
  9265. var evaluatedUpper = outputUpper.evaluate.apply(undefined, args);
  9266. // Special case for fill-outline-color, which has no spec default.
  9267. if (evaluatedLower === undefined || evaluatedUpper === undefined) {
  9268. return undefined;
  9269. }
  9270. return interp(evaluatedLower, evaluatedUpper, t);
  9271. }
  9272. };
  9273. }
  9274. return interp(outputLower, outputUpper, t);
  9275. }
  9276. function evaluateIdentityFunction(parameters, propertySpec, input) {
  9277. if (propertySpec.type === 'color') {
  9278. input = Color$1.parse(input);
  9279. } else if (propertySpec.type === 'formatted') {
  9280. input = Formatted.fromString(input.toString());
  9281. } else if (propertySpec.type === 'resolvedImage') {
  9282. input = ResolvedImage.fromString(input.toString());
  9283. } else if (getType(input) !== propertySpec.type && (propertySpec.type !== 'enum' || !propertySpec.values[input])) {
  9284. input = undefined;
  9285. }
  9286. return coalesce(input, parameters.default, propertySpec.default);
  9287. }
  9288. function createExpression(expression, propertySpec) {
  9289. var parser = new ParsingContext(expressions, [], propertySpec ? getExpectedType(propertySpec) : undefined);
  9290. // For string-valued properties, coerce to string at the top level rather than asserting.
  9291. var parsed = parser.parse(expression, undefined, undefined, undefined,
  9292. propertySpec && propertySpec.type === 'string' ? {typeAnnotation: 'coerce'} : undefined);
  9293. if (!parsed) {
  9294. assert(parser.errors.length > 0);
  9295. return error(parser.errors);
  9296. }
  9297. return success(new StyleExpression(parsed, propertySpec));
  9298. }
  9299. function ZoomConstantExpression(kind, expression) {
  9300. this.kind = kind;
  9301. this._styleExpression = expression;
  9302. this.isStateDependent = kind !== ('constant') && !isConstant.isStateConstant(expression.expression);
  9303. }
  9304. ZoomConstantExpression.prototype.evaluateWithoutErrorHandling = function(globals, feature, featureState, canonical, availableImages, formattedSection) {
  9305. return this._styleExpression.evaluateWithoutErrorHandling(globals, feature, featureState, canonical, availableImages, formattedSection);
  9306. };
  9307. ZoomConstantExpression.prototype.evaluate = function(globals, feature, featureState, canonical, availableImages, formattedSection) {
  9308. return this._styleExpression.evaluate(globals, feature, featureState, canonical, availableImages, formattedSection);
  9309. };
  9310. WebWorkerTransfer.register('ZoomConstantExpression', ZoomConstantExpression);
  9311. function ZoomDependentExpression(kind, expression, zoomStops, interpolationType) {
  9312. this.kind = kind;
  9313. this.zoomStops = zoomStops;
  9314. this._styleExpression = expression;
  9315. this.isStateDependent = kind !== ('camera') && !isConstant.isStateConstant(expression.expression);
  9316. this.interpolationType = interpolationType;
  9317. }
  9318. ZoomDependentExpression.prototype.evaluateWithoutErrorHandling = function(globals, feature, featureState, canonical, availableImages, formattedSection) {
  9319. return this._styleExpression.evaluateWithoutErrorHandling(globals, feature, featureState, canonical, availableImages, formattedSection);
  9320. };
  9321. ZoomDependentExpression.prototype.evaluate = function(globals, feature, featureState, canonical, availableImages, formattedSection) {
  9322. return this._styleExpression.evaluate(globals, feature, featureState, canonical, availableImages, formattedSection);
  9323. };
  9324. ZoomDependentExpression.prototype.interpolationFactor = function(input, lower, upper) {
  9325. if (this.interpolationType) {
  9326. return Interpolate.interpolationFactor(this.interpolationType, input, lower, upper);
  9327. } else {
  9328. return 0;
  9329. }
  9330. };
  9331. WebWorkerTransfer.register('ZoomDependentExpression', ZoomDependentExpression);
  9332. function createPropertyExpression(expression, propertySpec) {
  9333. expression = createExpression(expression, propertySpec);
  9334. if (expression.result === 'error') {
  9335. return expression;
  9336. }
  9337. var parsed = expression.value.expression;
  9338. var isFeatureConstant = isConstant.isFeatureConstant(parsed);
  9339. if (!isFeatureConstant && !Supports.supportsPropertyExpression(propertySpec)) {
  9340. return error([new ParsingError('', 'data expressions not supported')]);
  9341. }
  9342. var isZoomConstant = isConstant.isGlobalPropertyConstant(parsed, ['zoom']);
  9343. if (!isZoomConstant && !Supports.supportsZoomExpression(propertySpec)) {
  9344. return error([new ParsingError('', 'zoom expressions not supported')]);
  9345. }
  9346. var zoomCurve = findZoomCurve(parsed);
  9347. if (!zoomCurve && !isZoomConstant) {
  9348. return error([new ParsingError('', '"zoom" expression may only be used as input to a top-level "step" or "interpolate" expression.')]);
  9349. } else if (zoomCurve instanceof ParsingError) {
  9350. return error([zoomCurve]);
  9351. } else if (zoomCurve instanceof Interpolate && !Supports.supportsInterpolation(propertySpec)) {
  9352. return error([new ParsingError('', '"interpolate" expressions cannot be used with this property')]);
  9353. }
  9354. if (!zoomCurve) {
  9355. return success(isFeatureConstant ?
  9356. new ZoomConstantExpression('constant', expression.value) :
  9357. new ZoomConstantExpression('source', expression.value));
  9358. }
  9359. var interpolationType = zoomCurve instanceof Interpolate ? zoomCurve.interpolation : undefined;
  9360. return success(isFeatureConstant ?
  9361. new ZoomDependentExpression('camera', expression.value, zoomCurve.labels, interpolationType) :
  9362. new ZoomDependentExpression('composite', expression.value, zoomCurve.labels, interpolationType));
  9363. }
  9364. function createFunction(parameters, propertySpec) {
  9365. var isColor = propertySpec.type === 'color';
  9366. var zoomAndFeatureDependent = parameters.stops && typeof parameters.stops[0][0] === 'object';
  9367. var featureDependent = zoomAndFeatureDependent || parameters.property !== undefined;
  9368. var zoomDependent = zoomAndFeatureDependent || !featureDependent;
  9369. var type = parameters.type || (Supports.supportsInterpolation(propertySpec) ? 'exponential' : 'interval');
  9370. if (isColor) {
  9371. parameters = extend$1({}, parameters);
  9372. if (parameters.stops) {
  9373. parameters.stops = parameters.stops.map(function (stop) {
  9374. return [stop[0], Color$1.parse(stop[1])];
  9375. });
  9376. }
  9377. if (parameters.default) {
  9378. parameters.default = Color$1.parse(parameters.default);
  9379. } else {
  9380. parameters.default = Color$1.parse(propertySpec.default);
  9381. }
  9382. }
  9383. if (parameters.colorSpace && parameters.colorSpace !== 'rgb' && !colorSpaces[parameters.colorSpace]) { // eslint-disable-line import/namespace
  9384. throw new Error(("Unknown color space: " + (parameters.colorSpace)));
  9385. }
  9386. var innerFun;
  9387. var hashedStops;
  9388. var categoricalKeyType;
  9389. if (type === 'exponential') {
  9390. innerFun = evaluateExponentialFunction;
  9391. } else if (type === 'interval') {
  9392. innerFun = evaluateIntervalFunction;
  9393. } else if (type === 'categorical') {
  9394. innerFun = evaluateCategoricalFunction;
  9395. // For categorical functions, generate an Object as a hashmap of the stops for fast searching
  9396. hashedStops = Object.create(null);
  9397. for (var i = 0, list = parameters.stops; i < list.length; i += 1) {
  9398. var stop = list[i];
  9399. hashedStops[stop[0]] = stop[1];
  9400. }
  9401. // Infer key type based on first stop key-- used to encforce strict type checking later
  9402. categoricalKeyType = typeof parameters.stops[0][0];
  9403. } else if (type === 'identity') {
  9404. innerFun = evaluateIdentityFunction;
  9405. } else {
  9406. throw new Error(("Unknown function type \"" + type + "\""));
  9407. }
  9408. if (zoomAndFeatureDependent) {
  9409. var featureFunctions = {};
  9410. var zoomStops = [];
  9411. for (var s = 0; s < parameters.stops.length; s++) {
  9412. var stop$1 = parameters.stops[s];
  9413. var zoom = stop$1[0].zoom;
  9414. if (featureFunctions[zoom] === undefined) {
  9415. featureFunctions[zoom] = {
  9416. zoom: zoom,
  9417. type: parameters.type,
  9418. property: parameters.property,
  9419. default: parameters.default,
  9420. stops: []
  9421. };
  9422. zoomStops.push(zoom);
  9423. }
  9424. featureFunctions[zoom].stops.push([stop$1[0].value, stop$1[1]]);
  9425. }
  9426. var featureFunctionStops = [];
  9427. for (var i$1 = 0, list$1 = zoomStops; i$1 < list$1.length; i$1 += 1) {
  9428. var z = list$1[i$1];
  9429. featureFunctionStops.push([featureFunctions[z].zoom, createFunction(featureFunctions[z], propertySpec)]);
  9430. }
  9431. var interpolationType = {name: 'linear'};
  9432. return {
  9433. kind: 'composite',
  9434. interpolationType: interpolationType,
  9435. interpolationFactor: Interpolate.interpolationFactor.bind(undefined, interpolationType),
  9436. zoomStops: featureFunctionStops.map(function (s) {
  9437. return s[0];
  9438. }),
  9439. evaluate: function evaluate(ref, properties) {
  9440. var zoom = ref.zoom;
  9441. return evaluateExponentialFunction({
  9442. stops: featureFunctionStops,
  9443. base: parameters.base
  9444. }, propertySpec, zoom).evaluate(zoom, properties);
  9445. }
  9446. };
  9447. } else if (zoomDependent) {
  9448. var interpolationType$1 = type === 'exponential' ?
  9449. {name: 'exponential', base: parameters.base !== undefined ? parameters.base : 1} : null;
  9450. return {
  9451. kind: 'camera',
  9452. interpolationType: interpolationType$1,
  9453. interpolationFactor: Interpolate.interpolationFactor.bind(undefined, interpolationType$1),
  9454. zoomStops: parameters.stops.map(function (s) {
  9455. return s[0];
  9456. }),
  9457. evaluate: function (ref) {
  9458. var zoom = ref.zoom;
  9459. return innerFun(parameters, propertySpec, zoom, hashedStops, categoricalKeyType);
  9460. }
  9461. };
  9462. } else {
  9463. return {
  9464. kind: 'source',
  9465. evaluate: function evaluate(_, feature) {
  9466. var value = feature && feature.properties ? feature.properties[parameters.property] : undefined;
  9467. if (value === undefined) {
  9468. return coalesce(parameters.default, propertySpec.default);
  9469. }
  9470. return innerFun(parameters, propertySpec, value, hashedStops, categoricalKeyType);
  9471. }
  9472. };
  9473. }
  9474. }
  9475. function coalesce(a, b, c) {
  9476. if (a !== undefined) return a;
  9477. if (b !== undefined) return b;
  9478. if (c !== undefined) return c;
  9479. }
  9480. function interpolationFactor(input, base, lowerValue, upperValue) {
  9481. var difference = upperValue - lowerValue;
  9482. var progress = input - lowerValue;
  9483. if (difference === 0) {
  9484. return 0;
  9485. } else if (base === 1) {
  9486. return progress / difference;
  9487. } else {
  9488. return (Math.pow(base, progress) - 1) / (Math.pow(base, difference) - 1);
  9489. }
  9490. }
  9491. // serialization wrapper for old-style stop functions normalized to the
  9492. // expression interface
  9493. var StylePropertyFunction = function StylePropertyFunction(parameters, specification) {
  9494. this._parameters = parameters;
  9495. this._specification = specification;
  9496. extend$1(this, createFunction(this._parameters, this._specification));
  9497. };
  9498. StylePropertyFunction.deserialize = function deserialize(serialized) {
  9499. return ((new StylePropertyFunction(serialized._parameters, serialized._specification)) );
  9500. };
  9501. StylePropertyFunction.serialize = function serialize(input) {
  9502. return {
  9503. _parameters: input._parameters,
  9504. _specification: input._specification
  9505. };
  9506. };
  9507. Expression.normalizePropertyExpression = function (value, specification) {
  9508. if (isFunction$1(value)) {
  9509. return (new StylePropertyFunction(value, specification) );
  9510. } else if (Expression.isExpression(value)) {
  9511. var expression = createPropertyExpression(value, specification);
  9512. if (expression.result === 'error') {
  9513. // this should have been caught in validation
  9514. throw new Error(expression.value.map(function (err) {
  9515. return ((err.key) + ": " + (err.message));
  9516. }).join(', '));
  9517. }
  9518. return expression.value;
  9519. } else {
  9520. var constant = value;
  9521. if (typeof value === 'string' && specification.type === 'color') {
  9522. constant = Color$1.parse(value);
  9523. }
  9524. return {
  9525. kind: 'constant',
  9526. evaluate: function () {
  9527. return constant;
  9528. }
  9529. };
  9530. }
  9531. };
  9532. function getType(val) {
  9533. if (val instanceof Number) {
  9534. return 'number';
  9535. } else if (val instanceof String) {
  9536. return 'string';
  9537. } else if (val instanceof Boolean) {
  9538. return 'boolean';
  9539. } else if (Array.isArray(val)) {
  9540. return 'array';
  9541. } else if (val === null) {
  9542. return 'null';
  9543. } else {
  9544. return typeof val;
  9545. }
  9546. }
  9547. function featureFilter() {
  9548. }
  9549. featureFilter.isExpressionFilter = function (filter) {
  9550. if (filter === true || filter === false) {
  9551. return true;
  9552. }
  9553. if (!Array.isArray(filter) || filter.length === 0) {
  9554. return false;
  9555. }
  9556. switch (filter[0]) {
  9557. case 'has':
  9558. return filter.length >= 2 && filter[1] !== '$id' && filter[1] !== '$type';
  9559. case 'in':
  9560. return filter.length >= 3 && Array.isArray(filter[2]);
  9561. case '!in':
  9562. case '!has':
  9563. case 'none':
  9564. case 'crossFields':
  9565. return false;
  9566. case '==':
  9567. case '!=':
  9568. case '>':
  9569. case '>=':
  9570. case '<':
  9571. case '<=':
  9572. case 'like':
  9573. case '!like':
  9574. return filter.length !== 3 || (Array.isArray(filter[1]) || Array.isArray(filter[2]));
  9575. case 'any':
  9576. case 'all':
  9577. for (var i = 0, list = filter.slice(1); i < list.length; i += 1) {
  9578. var f = list[i];
  9579. if (!featureFilter.isExpressionFilter(f) && typeof f !== 'boolean') {
  9580. return false;
  9581. }
  9582. }
  9583. return true;
  9584. default:
  9585. return true;
  9586. }
  9587. };
  9588. var filterSpec = {
  9589. 'type': 'boolean',
  9590. 'default': false,
  9591. 'transition': false,
  9592. 'property-type': 'data-driven',
  9593. 'expression': {
  9594. 'interpolated': false,
  9595. 'parameters': ['zoom', 'feature']
  9596. }
  9597. };
  9598. /**
  9599. * Given a filter expressed as nested arrays, return a new function
  9600. * that evaluates whether a given feature (with a .properties or .tags property)
  9601. * passes its test.
  9602. *
  9603. * @private
  9604. * @param {Array} filter mapbox gl filter
  9605. * @returns {Function} filter-evaluating function
  9606. */
  9607. featureFilter.createFilter = function (filter) {
  9608. if (filter === null || filter === undefined) {
  9609. return function () {
  9610. return true;
  9611. };
  9612. }
  9613. if (!featureFilter.isExpressionFilter(filter)) {
  9614. filter = convertFilter(filter);
  9615. }
  9616. var compiled = Expression.createExpression(filter, filterSpec);
  9617. if (compiled.result === 'error') {
  9618. throw new Error(compiled.value.map(function (err) {
  9619. return ((err.key) + ": " + (err.message));
  9620. }).join(', '));
  9621. } else {
  9622. return function (globalProperties, feature) {
  9623. return compiled.value.evaluate(globalProperties, feature);
  9624. };
  9625. }
  9626. };
  9627. // Comparison function to sort numbers and strings
  9628. function compare(a, b) {
  9629. return a < b ? -1 : a > b ? 1 : 0;
  9630. }
  9631. function convertFilter(filter) {
  9632. if (!filter) {
  9633. return true;
  9634. }
  9635. var op = filter[0];
  9636. if (filter.length <= 1) {
  9637. return (op !== 'any');
  9638. }
  9639. var converted =
  9640. op === '==' ? convertComparisonOp(filter[1], filter[2], '==') :
  9641. op === '!=' ? convertNegation(convertComparisonOp(filter[1], filter[2], '==')) :
  9642. op === '<' ||
  9643. op === '>' ||
  9644. op === '<=' ||
  9645. op === '>=' ? convertComparisonOp(filter[1], filter[2], op) :
  9646. op === 'any' ? convertDisjunctionOp(filter.slice(1)) :
  9647. op === 'all' ? ['all'].concat(filter.slice(1).map(convertFilter)) :
  9648. op === 'crossFields' ? ['crossFields'].concat(filter.slice(1).map(convertFilter)) :
  9649. op === 'none' ? ['all'].concat(filter.slice(1).map(convertFilter).map(convertNegation)) :
  9650. op === 'in' ? convertInOp(filter[1], filter.slice(2)) :
  9651. op === '!in' ? convertNegation(convertInOp(filter[1], filter.slice(2))) :
  9652. op === 'has' ? convertHasOp(filter[1]) :
  9653. op === '!has' ? convertNegation(convertHasOp(filter[1])) :
  9654. op === 'like' ? convertComparisonOp(filter[1], filter[2], 'like') :
  9655. op === '!like' ? convertNegation(convertComparisonOp(filter[1], filter[2], 'like')) :
  9656. true;
  9657. return converted;
  9658. }
  9659. function convertComparisonOp(property, value, op) {
  9660. switch (property) {
  9661. case '$type':
  9662. return [("filter-type-" + op), value];
  9663. case '$id':
  9664. return [("filter-id-" + op), value];
  9665. default:
  9666. return [("filter-" + op), property, value];
  9667. }
  9668. }
  9669. function convertDisjunctionOp(filters) {
  9670. return ['any'].concat(filters.map(convertFilter));
  9671. }
  9672. function convertInOp(property, values) {
  9673. if (values.length === 0) {
  9674. return false;
  9675. }
  9676. switch (property) {
  9677. case '$type':
  9678. return ["filter-type-in", ['literal', values]];
  9679. case '$id':
  9680. return ["filter-id-in", ['literal', values]];
  9681. default:
  9682. if (values.length > 200 && !values.some(function (v) {
  9683. return typeof v !== typeof values[0];
  9684. })) {
  9685. return ['filter-in-large', property, ['literal', values.sort(compare)]];
  9686. } else {
  9687. return ['filter-in-small', property, ['literal', values]];
  9688. }
  9689. }
  9690. }
  9691. function convertHasOp(property) {
  9692. switch (property) {
  9693. case '$type':
  9694. return true;
  9695. case '$id':
  9696. return ["filter-has-id"];
  9697. default:
  9698. return ["filter-has", property];
  9699. }
  9700. }
  9701. function convertNegation(filter) {
  9702. return ['!', filter];
  9703. }
  9704. var FeatureIndexArray$1 = arrayTypes.FeatureIndexArray;
  9705. var FeatureIndex = function FeatureIndex(tileID, grid, featureIndexArray) {
  9706. //this.tileID = tileID;
  9707. this.x = tileID.x;
  9708. this.y = tileID.y;
  9709. this.z = tileID.z;
  9710. this.grid = grid || new GridIndex(EXTENT, 16, 0);
  9711. this.featureIndexArray = featureIndexArray || new FeatureIndexArray$1();
  9712. };
  9713. FeatureIndex.prototype.insert = function insert(feature, geometry, featureIndex, sourceLayerIndex, bucketIndex, is3D, padding) {
  9714. var key = this.featureIndexArray.length;
  9715. this.featureIndexArray.emplaceBack(featureIndex, sourceLayerIndex, bucketIndex);
  9716. var grid = this.grid;
  9717. padding = padding || 0;
  9718. for (var r = 0; r < geometry.length; r++) {
  9719. var ring = geometry[r];
  9720. var bbox = [Infinity, Infinity, -Infinity, -Infinity];
  9721. for (var i = 0; i < ring.length; i++) {
  9722. var p = ring[i];
  9723. bbox[0] = Math.min(bbox[0], p.x);
  9724. bbox[1] = Math.min(bbox[1], p.y);
  9725. bbox[2] = Math.max(bbox[2], p.x);
  9726. bbox[3] = Math.max(bbox[3], p.y);
  9727. }
  9728. if (bbox[0] < EXTENT &&
  9729. bbox[1] < EXTENT &&
  9730. bbox[2] >= 0 &&
  9731. bbox[3] >= 0) {
  9732. grid.insert(key, bbox[0] - padding, bbox[1] - padding, bbox[2] + padding, bbox[3] + padding);
  9733. }
  9734. }
  9735. };
  9736. FeatureIndex.prototype.loadVTLayers = function loadVTLayers() {
  9737. if (!this.vtLayers) {
  9738. this.vtLayers = new VectorTile(new pbf.Protobuf(this.rawTileData)).layers;
  9739. this.sourceLayerCoder = new DictionaryCoder(this.vtLayers ? Object.keys(this.vtLayers).sort() : ['_geojsonTileLayer']);
  9740. }
  9741. return this.vtLayers;
  9742. };
  9743. // Finds non-symbol features in this tile at a particular position.
  9744. FeatureIndex.prototype.query = function query(args, styleLayers, sourceFeatureState) {
  9745. var this$1 = this;
  9746. this.loadVTLayers();
  9747. var params = args.params || {};
  9748. var pixelsToTileUnits = computePixelsToTileUnits(this.z, args.tileSize, params);
  9749. var filter = featureFilter.createFilter(params.filter);
  9750. var queryGeometry = args.queryGeometry;
  9751. var queryPadding = 5;
  9752. var bounds = getBounds(queryGeometry);
  9753. var matching = [];
  9754. if(when.defined(params.selectTolerance)){
  9755. queryPadding += pixelsToTileUnits * params.selectTolerance;
  9756. }
  9757. matching = this.grid.query(bounds.minX - queryPadding, bounds.minY - queryPadding, bounds.maxX + queryPadding, bounds.maxY + queryPadding);
  9758. matching.sort(topDownFeatureComparator);
  9759. var result = {};
  9760. var previousIndex;
  9761. var loop = function (k) {
  9762. var index = matching[k];
  9763. // don't check the same feature more than once
  9764. if (index === previousIndex) {
  9765. return;
  9766. }
  9767. previousIndex = index;
  9768. var match = this$1.featureIndexArray.get(index);
  9769. var featureGeometry = null;
  9770. this$1.loadMatchingFeature(
  9771. result,
  9772. match.bucketIndex,
  9773. match.sourceLayerIndex,
  9774. match.featureIndex,
  9775. filter,
  9776. params.layers,
  9777. styleLayers,
  9778. function (feature, styleLayer) {
  9779. if (!featureGeometry) {
  9780. featureGeometry = loadGeometry(feature);
  9781. }
  9782. var featureState = {};
  9783. // if (feature.id) {
  9784. // // `feature-state` expression evaluation requires feature state to be available
  9785. // featureState = sourceFeatureState.getState(styleLayer.sourceLayer || '_geojsonTileLayer', feature.id);
  9786. // }
  9787. return styleLayer.queryIntersectsFeature(queryGeometry, feature, featureState, featureGeometry, this$1.z, args.transform, pixelsToTileUnits, args.pixelPosMatrix, args.adjustScale);
  9788. }
  9789. );
  9790. };
  9791. for (var k = 0; k < matching.length; k++) loop(k);
  9792. return result;
  9793. };
  9794. FeatureIndex.prototype.loadMatchingFeature = function loadMatchingFeature(result, bucketIndex, sourceLayerIndex, featureIndex, filter, filterLayerIDs, styleLayers, intersectionTest) {
  9795. if(!when.defined(bucketIndex) || !when.defined(sourceLayerIndex) || !when.defined(featureIndex)){
  9796. return;
  9797. }
  9798. var layerIDs = this.bucketLayerIDs[bucketIndex];
  9799. if (filterLayerIDs && !Util.arraysIntersect(filterLayerIDs, layerIDs)) {
  9800. return;
  9801. }
  9802. var sourceLayerName = this.sourceLayerCoder.decode(sourceLayerIndex);
  9803. var sourceLayer = this.vtLayers[sourceLayerName];
  9804. var feature = sourceLayer.feature(featureIndex);
  9805. if (!filter(new EvaluationParameters$1(this.z), feature)) {
  9806. return;
  9807. }
  9808. for (var l = 0; l < layerIDs.length; l++) {
  9809. var layerID = layerIDs[l];
  9810. if (filterLayerIDs && filterLayerIDs.indexOf(layerID) < 0) {
  9811. continue;
  9812. }
  9813. var styleLayer = styleLayers[layerID];
  9814. if (!styleLayer) {
  9815. continue;
  9816. }
  9817. var intersectionZ = !intersectionTest || intersectionTest(feature, styleLayer);
  9818. if (!intersectionZ) {
  9819. // Only applied for non-symbol features
  9820. continue;
  9821. }
  9822. // var geojsonFeature = new Feature(feature, this.z, this.x, this.y);
  9823. // (geojsonFeature ).layer = styleLayer.serialize();
  9824. feature.layer = styleLayer.serialize();
  9825. var layerResult = result[layerID];
  9826. if (layerResult === undefined) {
  9827. layerResult = result[layerID] = [];
  9828. }
  9829. layerResult.push({featureIndex: featureIndex, feature: feature, intersectionZ: intersectionZ});
  9830. }
  9831. };
  9832. // Given a set of symbol indexes that have already been looked up,
  9833. // return a matching set of GeoJSONFeatures
  9834. FeatureIndex.prototype.lookupSymbolFeatures = function lookupSymbolFeatures(symbolFeatureIndexes, bucketIndex, sourceLayerIndex, filterSpec, filterLayerIDs, styleLayers) {
  9835. var result = {};
  9836. this.loadVTLayers();
  9837. var filter = createFilter(filterSpec);
  9838. for (var i = 0, list = symbolFeatureIndexes; i < list.length; i += 1) {
  9839. var symbolFeatureIndex = list[i];
  9840. this.loadMatchingFeature(
  9841. result,
  9842. bucketIndex,
  9843. sourceLayerIndex,
  9844. symbolFeatureIndex,
  9845. filter,
  9846. filterLayerIDs,
  9847. styleLayers
  9848. );
  9849. }
  9850. return result;
  9851. };
  9852. FeatureIndex.prototype.hasLayer = function hasLayer(id) {
  9853. for (var i$1 = 0, list$1 = this.bucketLayerIDs; i$1 < list$1.length; i$1 += 1) {
  9854. var layerIDs = list$1[i$1];
  9855. for (var i = 0, list = layerIDs; i < list.length; i += 1) {
  9856. var layerID = list[i];
  9857. if (id === layerID) {
  9858. return true;
  9859. }
  9860. }
  9861. }
  9862. return false;
  9863. };
  9864. // register(
  9865. // 'FeatureIndex',
  9866. // FeatureIndex,
  9867. // {omit: ['rawTileData', 'sourceLayerCoder']}
  9868. // );
  9869. function getBounds(geometry) {
  9870. var minX = Infinity;
  9871. var minY = Infinity;
  9872. var maxX = -Infinity;
  9873. var maxY = -Infinity;
  9874. for (var i = 0, list = geometry; i < list.length; i += 1) {
  9875. var p = list[i];
  9876. minX = Math.min(minX, p.x);
  9877. minY = Math.min(minY, p.y);
  9878. maxX = Math.max(maxX, p.x);
  9879. maxY = Math.max(maxY, p.y);
  9880. }
  9881. return {minX: minX, minY: minY, maxX: maxX, maxY: maxY};
  9882. }
  9883. function topDownFeatureComparator(a, b) {
  9884. return b - a;
  9885. }
  9886. function computePixelsToTileUnits(tileLevel, tileSize, options) {
  9887. if(when.defined(options) && options.realtime && when.defined(options.zoom)) {
  9888. var currentZoom = options.zoom;
  9889. var diff = currentZoom - tileLevel;
  9890. var result = (EXTENT / (tileSize * Math.pow(2, diff)));
  9891. // 线宽以512尺寸的切片大小为基准
  9892. result *= tileSize / 512;
  9893. return result;
  9894. } else {
  9895. return EXTENT / tileSize;
  9896. }
  9897. }
  9898. WebWorkerTransfer.register('FeatureIndex', FeatureIndex, {omit: ['rawTileData', 'sourceLayerCoder', 'vtLayers']});
  9899. const refProperties = ['type', 'source', 'source-layer', 'minzoom', 'maxzoom', 'filter', 'layout'];
  9900. function stringify(obj) {
  9901. var type = typeof obj;
  9902. if (type === 'number' || type === 'boolean' || type === 'string' || obj === undefined || obj === null)
  9903. { return JSON.stringify(obj); }
  9904. if (Array.isArray(obj)) {
  9905. var str$1 = '[';
  9906. for (var i$1 = 0, list = obj; i$1 < list.length; i$1 += 1) {
  9907. var val = list[i$1];
  9908. str$1 += (stringify(val)) + ",";
  9909. }
  9910. return (str$1 + "]");
  9911. }
  9912. var keys = Object.keys(obj).sort();
  9913. var str = '{';
  9914. for (var i = 0; i < keys.length; i++) {
  9915. str += (JSON.stringify(keys[i])) + ":" + (stringify(obj[keys[i]])) + ",";
  9916. }
  9917. return (str + "}");
  9918. }
  9919. function getKey(layer) {
  9920. var key = '';
  9921. for (var i = 0, list = refProperties; i < list.length; i += 1) {
  9922. var k = list[i];
  9923. key += "/" + (stringify(layer[k]));
  9924. }
  9925. return key;
  9926. }
  9927. /**
  9928. * Given an array of layers, return an array of arrays of layers where all
  9929. * layers in each group have identical layout-affecting properties. These
  9930. * are the properties that were formerly used by explicit `ref` mechanism
  9931. * for layers: 'type', 'source', 'source-layer', 'minzoom', 'maxzoom',
  9932. * 'filter', and 'layout'.
  9933. *
  9934. * The input is not modified. The output layers are references to the
  9935. * input layers.
  9936. *
  9937. * @private
  9938. * @param {Array<Layer>} layers
  9939. * @param {Object} [cachedKeys] - an object to keep already calculated keys.
  9940. * @returns {Array<Array<Layer>>}
  9941. */
  9942. function groupByLayout(layers, cachedKeys) {
  9943. var groups = {};
  9944. for (var i = 0; i < layers.length; i++) {
  9945. var k = (cachedKeys && cachedKeys[layers[i].id]) || getKey(layers[i]);
  9946. // update the cache if there is one
  9947. if (cachedKeys)
  9948. { cachedKeys[layers[i].id] = k; }
  9949. var group = groups[k];
  9950. if (!group) {
  9951. group = groups[k] = [];
  9952. }
  9953. group.push(layers[i]);
  9954. }
  9955. var result = [];
  9956. for (var k$1 in groups) {
  9957. result.push(groups[k$1]);
  9958. }
  9959. return result;
  9960. }
  9961. var layout$1 = createLayout([
  9962. {name: 'a_pos', components: 2, type: 'Int16'}
  9963. ], 4);
  9964. var members = layout$1.members;
  9965. function addCircleVertex(layoutVertexArray, x, y, extrudeX, extrudeY) {
  9966. layoutVertexArray.emplaceBack(
  9967. (x * 2) + ((extrudeX + 1) / 2),
  9968. (y * 2) + ((extrudeY + 1) / 2));
  9969. }
  9970. /**
  9971. * Circles are represented by two triangles.
  9972. *
  9973. * Each corner has a pos that is the center of the circle and an extrusion
  9974. * vector that is where it points.
  9975. * @private
  9976. */
  9977. var CircleBucket = function CircleBucket(options) {
  9978. this.zoom = options.zoom;
  9979. this.overscaling = options.overscaling;
  9980. this.layers = options.layers;
  9981. this._sourceLayerIds = {};
  9982. var that = this;
  9983. this.layerIds = this.layers.map(function (layer, index) {
  9984. that._sourceLayerIds[layer.sourceLayer] = index;
  9985. return layer.sourceLayer;
  9986. });
  9987. this.index = options.index;
  9988. this.hasPattern = false;
  9989. this.layoutVertexArray = new StructArrayLayout2i4();
  9990. this.indexArray = new StructArrayLayout3ui6();
  9991. this.segments = new SegmentVector();
  9992. this.programConfigurations = new ProgramConfigurationSet(members, options.layers, options.zoom);
  9993. this.stateDependentLayerIds = this.layers.filter(function (l) {
  9994. return l.isStateDependent();
  9995. }).map(function (l) {
  9996. return l.id;
  9997. });
  9998. };
  9999. CircleBucket.prototype.populate = function populate(features, options) {
  10000. var styleLayer = this.layers[0];
  10001. var bucketFeatures = [];
  10002. var circleSortKey = null;
  10003. // Heatmap layers are handled in this bucket and have no evaluated properties, so we check our access
  10004. if (styleLayer.type === 'circle') {
  10005. circleSortKey = ((styleLayer )).layout.get('circle-sort-key');
  10006. }
  10007. for (var i = 0, list = features; i < list.length; i += 1) {
  10008. var ref = list[i];
  10009. var feature = ref.feature;
  10010. var index = ref.index;
  10011. var sourceLayerIndex = ref.sourceLayerIndex;
  10012. var sourceLayerId = ref.sourceLayerId;
  10013. var currentLayerIndex = this._sourceLayerIds[sourceLayerId];
  10014. var currentLayer = this.layers[currentLayerIndex];
  10015. if(!currentLayer) {
  10016. continue;
  10017. }
  10018. var pixelsToTileUnits = EXTENT / 512;
  10019. var circleRadius = currentLayer.paint.get('circle-radius').value.value * pixelsToTileUnits;
  10020. if (this.layers[0]._featureFilter(new EvaluationParameters$1(0), feature)) {
  10021. var geometry = loadGeometry(feature);
  10022. var sortKey = circleSortKey ?
  10023. circleSortKey.evaluate(feature, {}) :
  10024. undefined;
  10025. var bucketFeature = {
  10026. id: feature.id,
  10027. properties: feature.properties,
  10028. type: feature.type,
  10029. sourceLayerIndex: sourceLayerIndex,
  10030. index: index,
  10031. geometry: geometry,
  10032. patterns: {},
  10033. sortKey: sortKey,
  10034. circleRadius: circleRadius
  10035. };
  10036. bucketFeatures.push(bucketFeature);
  10037. }
  10038. }
  10039. if (circleSortKey) {
  10040. bucketFeatures.sort(function (a, b) {
  10041. // a.sortKey is always a number when in use
  10042. return ((a.sortKey ) ) - ((b.sortKey ) );
  10043. });
  10044. }
  10045. for (var i$1 = 0, list$1 = bucketFeatures; i$1 < list$1.length; i$1 += 1) {
  10046. var bucketFeature$1 = list$1[i$1];
  10047. var ref$1 = bucketFeature$1;
  10048. var geometry$1 = ref$1.geometry;
  10049. var index$1 = ref$1.index;
  10050. var sourceLayerIndex$1 = ref$1.sourceLayerIndex;
  10051. var feature$1 = features[index$1].feature;
  10052. this.addFeature(bucketFeature$1, geometry$1, index$1);
  10053. options.featureIndex.insert(feature$1, geometry$1, index$1, sourceLayerIndex$1, this.index, undefined, ref$1.circleRadius);
  10054. }
  10055. };
  10056. CircleBucket.prototype.update = function update(states, vtLayer, imagePositions) {
  10057. if (!this.stateDependentLayers.length) {
  10058. return;
  10059. }
  10060. this.programConfigurations.updatePaintArrays(states, vtLayer, this.stateDependentLayers, imagePositions);
  10061. };
  10062. CircleBucket.prototype.isEmpty = function isEmpty() {
  10063. return this.layoutVertexArray.length === 0;
  10064. };
  10065. CircleBucket.prototype.uploadPending = function uploadPending() {
  10066. return !this.uploaded || this.programConfigurations.needsUpload;
  10067. };
  10068. CircleBucket.prototype.upload = function upload(context) {
  10069. if (!this.uploaded) {
  10070. this.layoutVertexBuffer = context.createVertexBuffer(this.layoutVertexArray, members);
  10071. this.indexBuffer = context.createIndexBuffer(this.indexArray);
  10072. }
  10073. this.programConfigurations.upload(context);
  10074. this.uploaded = true;
  10075. };
  10076. CircleBucket.prototype.destroy = function destroy() {
  10077. if (!this.layoutVertexBuffer) {
  10078. return;
  10079. }
  10080. this.layoutVertexBuffer.destroy();
  10081. this.indexBuffer.destroy();
  10082. this.programConfigurations.destroy();
  10083. this.segments.destroy();
  10084. };
  10085. CircleBucket.prototype.clear = function clear() {
  10086. if (when.defined(this.layoutVertexArray)) {
  10087. this.layoutVertexArray = null;
  10088. }
  10089. if (when.defined(this.indexArray)) {
  10090. this.indexArray = null;
  10091. }
  10092. };
  10093. CircleBucket.prototype.addFeature = function addFeature(feature, geometry, index) {
  10094. for (var i$1 = 0, list$1 = geometry; i$1 < list$1.length; i$1 += 1) {
  10095. var ring = list$1[i$1];
  10096. for (var i = 0, list = ring; i < list.length; i += 1) {
  10097. var point = list[i];
  10098. var x = point.x;
  10099. var y = point.y;
  10100. // Do not include points that are outside the tile boundaries.
  10101. if (x < 0 || x >= EXTENT || y < 0 || y >= EXTENT) {
  10102. continue;
  10103. }
  10104. // this geometry will be of the Point type, and we'll derive
  10105. // two triangles from it.
  10106. //
  10107. // ┌─────────┐
  10108. // │ 3 2 │
  10109. // │ │
  10110. // │ 0 1 │
  10111. // └─────────┘
  10112. var segment = this.segments.prepareSegment(4, this.layoutVertexArray, this.indexArray, feature.sortKey);
  10113. var index$1 = segment.vertexLength;
  10114. addCircleVertex(this.layoutVertexArray, x, y, -1, -1);
  10115. addCircleVertex(this.layoutVertexArray, x, y, 1, -1);
  10116. addCircleVertex(this.layoutVertexArray, x, y, 1, 1);
  10117. addCircleVertex(this.layoutVertexArray, x, y, -1, 1);
  10118. this.indexArray.emplaceBack(index$1, index$1 + 1, index$1 + 2);
  10119. this.indexArray.emplaceBack(index$1, index$1 + 3, index$1 + 2);
  10120. segment.vertexLength += 4;
  10121. segment.primitiveLength += 2;
  10122. }
  10123. }
  10124. this.programConfigurations.populatePaintArrays(this.layoutVertexArray.length, feature, index, {});
  10125. };
  10126. WebWorkerTransfer.register('CircleBucket', CircleBucket, {omit: ['layers']});
  10127. /**
  10128. * An implementation of `Property` for properties that do not permit data-driven (source or composite) expressions.
  10129. * This restriction allows us to declare statically that the result of possibly evaluating this kind of property
  10130. * is in fact always the scalar type `T`, and can be used without further evaluating the value on a per-feature basis.
  10131. *
  10132. * @private
  10133. */
  10134. var DataConstantProperty = function DataConstantProperty(specification) {
  10135. this.specification = specification;
  10136. };
  10137. DataConstantProperty.prototype.possiblyEvaluate = function possiblyEvaluate(value, parameters) {
  10138. return value.expression.evaluate(parameters);
  10139. };
  10140. DataConstantProperty.prototype.interpolate = function interpolate$1(a, b, t) {
  10141. var interp = (interpolate )[this.specification.type];
  10142. if (interp) {
  10143. return interp(a, b, t);
  10144. } else {
  10145. return a;
  10146. }
  10147. };
  10148. WebWorkerTransfer.register('DataConstantProperty', DataConstantProperty);
  10149. /**
  10150. * An implementation of `Property` for properties that permit data-driven (source or composite) expressions.
  10151. * The result of possibly evaluating this kind of property is `PossiblyEvaluatedPropertyValue<T>`; obtaining
  10152. * a scalar value `T` requires further evaluation on a per-feature basis.
  10153. *
  10154. * @private
  10155. */
  10156. var DataDrivenProperty = function DataDrivenProperty(specification, overrides) {
  10157. this.specification = specification;
  10158. this.overrides = overrides;
  10159. };
  10160. DataDrivenProperty.prototype.possiblyEvaluate = function possiblyEvaluate(value, parameters, availableImages) {
  10161. if (value.expression.kind === 'constant' || value.expression.kind === 'camera') {
  10162. return new PossiblyEvaluatedPropertyValue$1(this, {kind: 'constant', value: value.expression.evaluate(parameters, (null ), {}, availableImages)}, parameters);
  10163. } else {
  10164. return new PossiblyEvaluatedPropertyValue$1(this, value.expression, parameters);
  10165. }
  10166. };
  10167. DataDrivenProperty.prototype.interpolate = function interpolate$2(a, b, t) {
  10168. // If either possibly-evaluated value is non-constant, give up: we aren't able to interpolate data-driven values.
  10169. if (a.value.kind !== 'constant' || b.value.kind !== 'constant') {
  10170. return a;
  10171. }
  10172. // Special case hack solely for fill-outline-color. The undefined value is subsequently handled in
  10173. // FillStyleLayer#recalculate, which sets fill-outline-color to the fill-color value if the former
  10174. // is a PossiblyEvaluatedPropertyValue containing a constant undefined value. In addition to the
  10175. // return value here, the other source of a PossiblyEvaluatedPropertyValue containing a constant
  10176. // undefined value is the "default value" for fill-outline-color held in
  10177. // `Properties#defaultPossiblyEvaluatedValues`, which serves as the prototype of
  10178. // `PossiblyEvaluated#_values`.
  10179. if (a.value.value === undefined || b.value.value === undefined) {
  10180. return new PossiblyEvaluatedPropertyValue$1(this, {kind: 'constant', value: (undefined )}, a.parameters);
  10181. }
  10182. var interp = (interpolate )[this.specification.type];
  10183. if (interp) {
  10184. return new PossiblyEvaluatedPropertyValue$1(this, {kind: 'constant', value: interp(a.value.value, b.value.value, t)}, a.parameters);
  10185. } else {
  10186. return a;
  10187. }
  10188. };
  10189. DataDrivenProperty.prototype.evaluate = function evaluate(value, parameters, feature, featureState, availableImages) {
  10190. if (value.kind === 'constant') {
  10191. return value.value;
  10192. } else {
  10193. return value.evaluate(parameters, feature, featureState, availableImages);
  10194. }
  10195. };
  10196. WebWorkerTransfer.register('DataDrivenProperty', DataDrivenProperty);
  10197. var PropertyValue = function PropertyValue(property, value) {
  10198. this.property = property;
  10199. this.value = value;
  10200. this.expression = Expression.normalizePropertyExpression(value === undefined ? property.specification.default : value, property.specification);
  10201. };
  10202. PropertyValue.prototype.isDataDriven = function isDataDriven() {
  10203. return this.expression.kind === 'source' || this.expression.kind === 'composite';
  10204. };
  10205. PropertyValue.prototype.possiblyEvaluate = function possiblyEvaluate(parameters, availableImages) {
  10206. return this.property.possiblyEvaluate(this, parameters, availableImages);
  10207. };
  10208. /**
  10209. * Given a value `t` that varies between 0 and 1, return
  10210. * an interpolation function that eases between 0 and 1 in a pleasing
  10211. * cubic in-out fashion.
  10212. *
  10213. * @private
  10214. */
  10215. function easeCubicInOut(t ) {
  10216. if (t <= 0) { return 0; }
  10217. if (t >= 1) { return 1; }
  10218. var t2 = t * t,
  10219. t3 = t2 * t;
  10220. return 4 * (t < 0.5 ? t3 : 3 * (t - t2) + t3 - 0.75);
  10221. }
  10222. /**
  10223. * `TransitioningPropertyValue` implements the first of two intermediate steps in the evaluation chain of a paint
  10224. * property value. In this step, transitions between old and new values are handled: as long as the transition is in
  10225. * progress, `TransitioningPropertyValue` maintains a reference to the prior value, and interpolates between it and
  10226. * the new value based on the current time and the configured transition duration and delay. The product is the next
  10227. * step in the evaluation chain: the "possibly evaluated" result type `R`. See below for more on this concept.
  10228. *
  10229. * @private
  10230. */
  10231. var TransitioningPropertyValue = function TransitioningPropertyValue(property, value, prior, transition, now) {
  10232. this.property = property;
  10233. this.value = value;
  10234. this.begin = now + transition.delay || 0;
  10235. this.end = this.begin + transition.duration || 0;
  10236. if (property.specification.transition && (transition.delay || transition.duration)) {
  10237. this.prior = prior;
  10238. }
  10239. };
  10240. TransitioningPropertyValue.prototype.possiblyEvaluate = function possiblyEvaluate(parameters, availableImages) {
  10241. var now = parameters.now || 0;
  10242. var finalValue = this.value.possiblyEvaluate(parameters, availableImages);
  10243. var prior = this.prior;
  10244. if (!prior) {
  10245. // No prior value.
  10246. return finalValue;
  10247. } else if (now > this.end) {
  10248. // Transition from prior value is now complete.
  10249. this.prior = null;
  10250. return finalValue;
  10251. } else if (this.value.isDataDriven()) {
  10252. // Transitions to data-driven properties are not supported.
  10253. // We snap immediately to the data-driven value so that, when we perform layout,
  10254. // we see the data-driven function and can use it to populate vertex buffers.
  10255. this.prior = null;
  10256. return finalValue;
  10257. } else if (now < this.begin) {
  10258. // Transition hasn't started yet.
  10259. return prior.possiblyEvaluate(parameters, availableImages);
  10260. } else {
  10261. // Interpolate between recursively-calculated prior value and final.
  10262. var t = (now - this.begin) / (this.end - this.begin);
  10263. return this.property.interpolate(prior.possiblyEvaluate(parameters, availableImages), finalValue, easeCubicInOut(t));
  10264. }
  10265. };
  10266. /**
  10267. * Paint properties are _transitionable_: they can change in a fluid manner, interpolating or cross-fading between
  10268. * old and new value. The duration of the transition, and the delay before it begins, is configurable.
  10269. *
  10270. * `TransitionablePropertyValue` is a compositional class that stores both the property value and that transition
  10271. * configuration.
  10272. *
  10273. * A `TransitionablePropertyValue` can calculate the next step in the evaluation chain for paint property values:
  10274. * `TransitioningPropertyValue`.
  10275. *
  10276. * @private
  10277. */
  10278. var TransitionablePropertyValue = function TransitionablePropertyValue(property) {
  10279. this.property = property;
  10280. this.value = new PropertyValue(property, undefined);
  10281. };
  10282. TransitionablePropertyValue.prototype.transitioned = function transitioned(parameters, prior) {
  10283. return new TransitioningPropertyValue(this.property, this.value, prior, // eslint-disable-line no-use-before-define
  10284. Util.extend({}, parameters.transition, this.transition), parameters.now);
  10285. };
  10286. TransitionablePropertyValue.prototype.untransitioned = function untransitioned() {
  10287. return new TransitioningPropertyValue(this.property, this.value, null, {}, 0); // eslint-disable-line no-use-before-define
  10288. };
  10289. /**
  10290. * A helper type: given an object type `Properties` whose values are each of type `Property<T, R>`, it calculates
  10291. * an object type with the same keys, and values of type `R`.
  10292. *
  10293. * For properties that don't allow data-driven values, `R` is a scalar type such as `number`, `string`, or `Color`.
  10294. * For data-driven properties, it is `PossiblyEvaluatedPropertyValue`. Critically, the type definitions are set up
  10295. * in a way that allows flow to know which of these two cases applies for any given property name, and if you attempt
  10296. * to use a `PossiblyEvaluatedPropertyValue` as if it was a scalar, or vice versa, you will get a type error. (However,
  10297. * 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
  10298. * as `layer.paint.get('foo-opacity') === 0`, if `foo-opacity` is data-driven, than the left-hand side is of type
  10299. * `PossiblyEvaluatedPropertyValue<number>`, but flow will not complain about comparing this to a number using `===`.
  10300. * See https://github.com/facebook/flow/issues/2359.)
  10301. *
  10302. * There's also a third, special case possiblity for `R`: for cross-faded properties, it's `?CrossFaded<T>`.
  10303. *
  10304. * @private
  10305. */
  10306. /**
  10307. * `Properties` holds objects containing default values for the layout or paint property set of a given
  10308. * layer type. These objects are immutable, and they are used as the prototypes for the `_values` members of
  10309. * `Transitionable`, `Transitioning`, `Layout`, and `PossiblyEvaluated`. This allows these classes to avoid
  10310. * doing work in the common case where a property has no explicit value set and should be considered to take
  10311. * on the default value: using `for (const property of Object.keys(this._values))`, they can iterate over
  10312. * only the _own_ properties of `_values`, skipping repeated calculation of transitions and possible/final
  10313. * evaluations for defaults, the result of which will always be the same.
  10314. *
  10315. * @private
  10316. */
  10317. var Properties = function Properties(properties) {
  10318. this.properties = properties;
  10319. this.defaultPropertyValues = ({} );
  10320. this.defaultTransitionablePropertyValues = ({} );
  10321. this.defaultTransitioningPropertyValues = ({} );
  10322. this.defaultPossiblyEvaluatedValues = ({} );
  10323. this.overridableProperties = ([] );
  10324. for (var property in properties) {
  10325. var prop = properties[property];
  10326. if (prop.specification.overridable) {
  10327. this.overridableProperties.push(property);
  10328. }
  10329. var defaultPropertyValue = this.defaultPropertyValues[property] =
  10330. new PropertyValue(prop, undefined);
  10331. var defaultTransitionablePropertyValue = this.defaultTransitionablePropertyValues[property] =
  10332. new TransitionablePropertyValue(prop);
  10333. this.defaultTransitioningPropertyValues[property] =
  10334. defaultTransitionablePropertyValue.untransitioned();
  10335. this.defaultPossiblyEvaluatedValues[property] =
  10336. defaultPropertyValue.possiblyEvaluate(({} ));
  10337. }
  10338. };
  10339. function QueryUtils() {
  10340. }
  10341. QueryUtils.getMaximumPaintValue = function (property, layer, bucket) {
  10342. var value = ((layer.paint).get(property)).value;
  10343. if (value.kind === 'constant') {
  10344. return value.value;
  10345. } else {
  10346. var binders = bucket.programConfigurations.get(layer.id).binders;
  10347. return binders[property].maxValue;
  10348. }
  10349. };
  10350. QueryUtils.translateDistance = function (translate) {
  10351. return Math.sqrt(translate[0] * translate[0] + translate[1] * translate[1]);
  10352. };
  10353. QueryUtils.translate = function (queryGeometry, translate, translateAnchor, bearing, pixelsToTileUnits) {
  10354. if (!translate[0] && !translate[1]) {
  10355. return queryGeometry;
  10356. }
  10357. var pt = Point.convert(translate)._mult(pixelsToTileUnits);
  10358. if (translateAnchor === "viewport") {
  10359. pt._rotate(-bearing);
  10360. }
  10361. var translated = [];
  10362. for (var i = 0; i < queryGeometry.length; i++) {
  10363. var point = queryGeometry[i];
  10364. translated.push(point.sub(pt));
  10365. }
  10366. return translated;
  10367. };
  10368. /**
  10369. * `PossiblyEvaluated` stores a map of all (property name, `R`) pairs for paint or layout properties of a
  10370. * given layer type.
  10371. * @private
  10372. */
  10373. var PossiblyEvaluated = function PossiblyEvaluated(properties) {
  10374. this._properties = properties;
  10375. this._values = (Object.create(properties.defaultPossiblyEvaluatedValues) );
  10376. };
  10377. PossiblyEvaluated.prototype.get = function get(name) {
  10378. return this._values[name];
  10379. };
  10380. /**
  10381. * Because layout properties are not transitionable, they have a simpler representation and evaluation chain than
  10382. * paint properties: `PropertyValue`s are possibly evaluated, producing possibly evaluated values, which are then
  10383. * fully evaluated.
  10384. *
  10385. * `Layout` stores a map of all (property name, `PropertyValue`) pairs for layout properties of a
  10386. * given layer type. It can calculate the possibly-evaluated values for all of them at once, producing a
  10387. * `PossiblyEvaluated` instance for the same set of properties.
  10388. *
  10389. * @private
  10390. */
  10391. var Layout = function Layout(properties ) {
  10392. this._properties = properties;
  10393. this._values = (Object.create(properties.defaultPropertyValues) );
  10394. };
  10395. Layout.prototype.getValue = function getValue (name ) {
  10396. return Util.clone(this._values[name].value);
  10397. };
  10398. Layout.prototype.setValue = function setValue (name , value ) {
  10399. this._values[name] = new PropertyValue(this._values[name].property, value === null ? undefined : Util.clone(value));
  10400. };
  10401. Layout.prototype.serialize = function serialize () {
  10402. var result = {};
  10403. for (var i = 0, list = Object.keys(this._values); i < list.length; i += 1) {
  10404. var property = list[i];
  10405. var value = this.getValue(property);
  10406. if (value !== undefined) {
  10407. result[property] = value;
  10408. }
  10409. }
  10410. return result;
  10411. };
  10412. Layout.prototype.possiblyEvaluate = function possiblyEvaluate (parameters , availableImages ) {
  10413. var result = new PossiblyEvaluated(this._properties); // eslint-disable-line no-use-before-define
  10414. for (var i = 0, list = Object.keys(this._values); i < list.length; i += 1) {
  10415. var property = list[i];
  10416. result._values[property] = this._values[property].possiblyEvaluate(parameters, availableImages);
  10417. }
  10418. return result;
  10419. };
  10420. // ------- Transitioning -------
  10421. /**
  10422. * A helper type: given an object type `Properties` whose values are each of type `Property<T, R>`, it calculates
  10423. * an object type with the same keys and values of type `TransitioningPropertyValue<T, R>`.
  10424. *
  10425. * @private
  10426. */
  10427. /**
  10428. * `Transitioning` stores a map of all (property name, `TransitioningPropertyValue`) pairs for paint properties of a
  10429. * given layer type. It can calculate the possibly-evaluated values for all of them at once, producing a
  10430. * `PossiblyEvaluated` instance for the same set of properties.
  10431. *
  10432. * @private
  10433. */
  10434. var Transitioning = function Transitioning(properties) {
  10435. this._properties = properties;
  10436. this._values = (Object.create(properties.defaultTransitioningPropertyValues) );
  10437. };
  10438. Transitioning.prototype.possiblyEvaluate = function possiblyEvaluate(parameters, availableImages) {
  10439. var result = new PossiblyEvaluated(this._properties); // eslint-disable-line no-use-before-define
  10440. for (var i = 0, list = Object.keys(this._values); i < list.length; i += 1) {
  10441. var property = list[i];
  10442. result._values[property] = this._values[property].possiblyEvaluate(parameters, availableImages);
  10443. }
  10444. return result;
  10445. };
  10446. Transitioning.prototype.hasTransition = function hasTransition() {
  10447. for (var i = 0, list = Object.keys(this._values); i < list.length; i += 1) {
  10448. var property = list[i];
  10449. if (this._values[property].prior) {
  10450. return true;
  10451. }
  10452. }
  10453. return false;
  10454. };
  10455. /**
  10456. * A helper type: given an object type `Properties` whose values are each of type `Property<T, R>`, it calculates
  10457. * an object type with the same keys and values of type `TransitionablePropertyValue<T, R>`.
  10458. *
  10459. * @private
  10460. */
  10461. /**
  10462. * `Transitionable` stores a map of all (property name, `TransitionablePropertyValue`) pairs for paint properties of a
  10463. * given layer type. It can calculate the `TransitioningPropertyValue`s for all of them at once, producing a
  10464. * `Transitioning` instance for the same set of properties.
  10465. *
  10466. * @private
  10467. */
  10468. var Transitionable = function Transitionable(properties) {
  10469. this._properties = properties;
  10470. this._values = (Object.create(properties.defaultTransitionablePropertyValues) );
  10471. };
  10472. Transitionable.prototype.getValue = function getValue(name) {
  10473. return Util.clone(this._values[name].value.value);
  10474. };
  10475. Transitionable.prototype.setValue = function setValue(name, value) {
  10476. if (!this._values.hasOwnProperty(name)) {
  10477. this._values[name] = new TransitionablePropertyValue(this._values[name].property);
  10478. }
  10479. // Note that we do not _remove_ an own property in the case where a value is being reset
  10480. // to the default: the transition might still be non-default.
  10481. this._values[name].value = new PropertyValue(this._values[name].property, value === null ? undefined : Util.clone(value));
  10482. };
  10483. Transitionable.prototype.getTransition = function getTransition(name) {
  10484. return Util.clone(this._values[name].transition);
  10485. };
  10486. Transitionable.prototype.setTransition = function setTransition(name, value) {
  10487. if (!this._values.hasOwnProperty(name)) {
  10488. this._values[name] = new TransitionablePropertyValue(this._values[name].property);
  10489. }
  10490. this._values[name].transition = Util.clone(value) || undefined;
  10491. };
  10492. Transitionable.prototype.serialize = function serialize() {
  10493. var result = {};
  10494. for (var i = 0, list = Object.keys(this._values); i < list.length; i += 1) {
  10495. var property = list[i];
  10496. var value = this.getValue(property);
  10497. if (value !== undefined) {
  10498. result[property] = value;
  10499. }
  10500. var transition = this.getTransition(property);
  10501. if (transition !== undefined) {
  10502. result[(property + "-transition")] = transition;
  10503. }
  10504. }
  10505. return result;
  10506. };
  10507. Transitionable.prototype.transitioned = function transitioned(parameters, prior) {
  10508. var result = new Transitioning(this._properties); // eslint-disable-line no-use-before-define
  10509. for (var i = 0, list = Object.keys(this._values); i < list.length; i += 1) {
  10510. var property = list[i];
  10511. result._values[property] = this._values[property].transitioned(parameters, prior._values[property]);
  10512. }
  10513. return result;
  10514. };
  10515. Transitionable.prototype.untransitioned = function untransitioned() {
  10516. var result = new Transitioning(this._properties); // eslint-disable-line no-use-before-define
  10517. for (var i = 0, list = Object.keys(this._values); i < list.length; i += 1) {
  10518. var property = list[i];
  10519. result._values[property] = this._values[property].untransitioned();
  10520. }
  10521. return result;
  10522. };
  10523. var TRANSITION_SUFFIX = '-transition';
  10524. function endsWith(string, suffix) {
  10525. return string.indexOf(suffix, string.length - suffix.length) !== -1;
  10526. }
  10527. function StyleLayer(layer, properties) {
  10528. //Evented.call(this);
  10529. this.id = layer.id;
  10530. this.type = layer.type;
  10531. // this._featureFilter = function () {
  10532. // return true;
  10533. // };
  10534. if (layer.type === 'custom') {
  10535. return;
  10536. }
  10537. layer = ((layer));
  10538. this.metadata = layer.metadata;
  10539. this.minzoom = layer.minzoom;
  10540. this.maxzoom = layer.maxzoom;
  10541. if (layer.type !== 'background') {
  10542. this.source = layer.source;
  10543. this.sourceLayer = layer['source-layer'];
  10544. this.filter = layer.filter;
  10545. }
  10546. if (properties.layout) {
  10547. this._unevaluatedLayout = new Layout(properties.layout);
  10548. }
  10549. if (properties.paint) {
  10550. this._transitionablePaint = new Transitionable(properties.paint);
  10551. for (var property in layer.paint) {
  10552. this.setPaintProperty(property, layer.paint[property], {validate: false});
  10553. }
  10554. for (var property$1 in layer.layout) {
  10555. this.setLayoutProperty(property$1, layer.layout[property$1], {validate: false});
  10556. }
  10557. this._transitioningPaint = this._transitionablePaint.untransitioned();
  10558. }
  10559. }
  10560. // if (Evented) StyleLayer.__proto__ = Evented;
  10561. // StyleLayer.prototype = Object.create(Evented && Evented.prototype);
  10562. // StyleLayer.prototype.constructor = StyleLayer;
  10563. StyleLayer.prototype.getCrossfadeParameters = function getCrossfadeParameters() {
  10564. return this._crossfadeParameters;
  10565. };
  10566. StyleLayer.prototype.getLayoutProperty = function getLayoutProperty(name) {
  10567. if (name === 'visibility') {
  10568. return this.visibility;
  10569. }
  10570. return this._unevaluatedLayout.getValue(name);
  10571. };
  10572. StyleLayer.prototype.setLayoutProperty = function setLayoutProperty(name, value, options) {
  10573. if (value !== null && value !== undefined) {
  10574. var key = "layers." + (this.id) + ".layout." + name;
  10575. // if (this._validate(validateLayoutProperty$1, key, name, value, options)) {
  10576. // return;
  10577. // }
  10578. }
  10579. if (name === 'visibility') {
  10580. this.visibility = value;
  10581. if(this.config && this.config.layout) {
  10582. this.config.layout.visibility = value;
  10583. }
  10584. return;
  10585. }
  10586. this._unevaluatedLayout.setValue(name, value);
  10587. };
  10588. StyleLayer.prototype.getPaintProperty = function getPaintProperty(name) {
  10589. if (endsWith(name, TRANSITION_SUFFIX)) {
  10590. return this._transitionablePaint.getTransition(name.slice(0, -TRANSITION_SUFFIX.length));
  10591. } else {
  10592. return this._transitionablePaint.getValue(name);
  10593. }
  10594. };
  10595. StyleLayer.prototype.setPaintProperty = function setPaintProperty(name, value, options) {
  10596. if (value !== null && value !== undefined) {
  10597. var key = "layers." + (this.id) + ".paint." + name;
  10598. // if (this._validate(validatePaintProperty$1, key, name, value, options)) {
  10599. // return false;
  10600. // }
  10601. }
  10602. if (endsWith(name, TRANSITION_SUFFIX)) {
  10603. this._transitionablePaint.setTransition(name.slice(0, -TRANSITION_SUFFIX.length), (value ) || undefined);
  10604. return false;
  10605. } else {
  10606. var transitionable = this._transitionablePaint._values[name];
  10607. var isCrossFadedProperty = transitionable.property.specification["property-type"] === 'cross-faded-data-driven';
  10608. var wasDataDriven = transitionable.value.isDataDriven();
  10609. var oldValue = transitionable.value;
  10610. this._transitionablePaint.setValue(name, value);
  10611. this._handleSpecialPaintPropertyUpdate(name);
  10612. var newValue = this._transitionablePaint._values[name].value;
  10613. var isDataDriven = newValue.isDataDriven();
  10614. // if a cross-faded value is changed, we need to make sure the new icons get added to each tile's iconAtlas
  10615. // so a call to _updateLayer is necessary, and we return true from this function so it gets called in
  10616. // Style#setPaintProperty
  10617. return isDataDriven || wasDataDriven || isCrossFadedProperty || this._handleOverridablePaintPropertyUpdate(name, oldValue, newValue);
  10618. }
  10619. };
  10620. StyleLayer.prototype._handleSpecialPaintPropertyUpdate = function _handleSpecialPaintPropertyUpdate(_) {
  10621. // No-op; can be overridden by derived classes.
  10622. };
  10623. // eslint-disable-next-line no-unused-vars
  10624. StyleLayer.prototype._handleOverridablePaintPropertyUpdate = function _handleOverridablePaintPropertyUpdate(name, oldValue, newValue) {
  10625. // No-op; can be overridden by derived classes.
  10626. return false;
  10627. };
  10628. StyleLayer.prototype.isHidden = function isHidden(zoom) {
  10629. if (this.minzoom && zoom < this.minzoom) {
  10630. return true;
  10631. }
  10632. if (this.maxzoom && zoom >= this.maxzoom) {
  10633. return true;
  10634. }
  10635. return this.visibility === 'none';
  10636. };
  10637. StyleLayer.prototype.updateTransitions = function updateTransitions(parameters) {
  10638. this._transitioningPaint = this._transitionablePaint.transitioned(parameters, this._transitioningPaint);
  10639. };
  10640. StyleLayer.prototype.hasTransition = function hasTransition() {
  10641. return this._transitioningPaint.hasTransition();
  10642. };
  10643. StyleLayer.prototype.recalculate = function recalculate(parameters, availableImages) {
  10644. if (parameters.getCrossfadeParameters) {
  10645. this._crossfadeParameters = parameters.getCrossfadeParameters();
  10646. }
  10647. if (this._unevaluatedLayout) {
  10648. (this).layout = this._unevaluatedLayout.possiblyEvaluate(parameters, availableImages);
  10649. }
  10650. (this).paint = this._transitioningPaint.possiblyEvaluate(parameters, availableImages);
  10651. };
  10652. StyleLayer.prototype.serialize = function serialize() {
  10653. var output = {
  10654. 'id': this.id,
  10655. 'type': this.type,
  10656. 'source': this.source,
  10657. 'source-layer': this.sourceLayer,
  10658. 'metadata': this.metadata,
  10659. 'minzoom': this.minzoom,
  10660. 'maxzoom': this.maxzoom,
  10661. 'filter': this.filter,
  10662. 'layout': this._unevaluatedLayout && this._unevaluatedLayout.serialize(),
  10663. 'paint': this._transitionablePaint && this._transitionablePaint.serialize()
  10664. };
  10665. if (this.visibility) {
  10666. output.layout = output.layout || {};
  10667. output.layout.visibility = this.visibility;
  10668. }
  10669. return Util.filterObject(output, function (value, key) {
  10670. return value !== undefined && !(key === 'layout' && !Object.keys(value).length) && !(key === 'paint' && !Object.keys(value).length);
  10671. });
  10672. };
  10673. StyleLayer.prototype._validate = function _validate(validate, key, name, value, options) {
  10674. return true;
  10675. // if (options === void 0) options = {};
  10676. //
  10677. // if (options && options.validate === false) {
  10678. // return false;
  10679. // }
  10680. // return emitValidationErrors(this, validate.call(validateStyle, {
  10681. // key: key,
  10682. // layerType: this.type,
  10683. // objectKey: name,
  10684. // value: value,
  10685. // styleSpec: spec,
  10686. // // Workaround for https://github.com/mapbox/mapbox-gl-js/issues/2407
  10687. // style: {glyphs: true, sprite: true}
  10688. // }));
  10689. };
  10690. StyleLayer.prototype.is3D = function is3D() {
  10691. return false;
  10692. };
  10693. StyleLayer.prototype.isTileClipped = function isTileClipped() {
  10694. return false;
  10695. };
  10696. StyleLayer.prototype.hasOffscreenPass = function hasOffscreenPass() {
  10697. return false;
  10698. };
  10699. StyleLayer.prototype.resize = function resize() {
  10700. // noop
  10701. };
  10702. StyleLayer.prototype.isStateDependent = function isStateDependent() {
  10703. return true;
  10704. // for (var property in (this ).paint._values) {
  10705. // var value = (this ).paint.get(property);
  10706. // if (!(value instanceof PossiblyEvaluatedPropertyValue) || !supportsPropertyExpression(value.property.specification)) {
  10707. // continue;
  10708. // }
  10709. //
  10710. // if ((value.value.kind === 'source' || value.value.kind === 'composite') &&
  10711. // value.value.isStateDependent) {
  10712. // return true;
  10713. // }
  10714. // }
  10715. // return false;
  10716. };
  10717. var $version = 8;
  10718. var $root = {
  10719. version: {
  10720. required: true,
  10721. type: "enum",
  10722. values: [
  10723. 8
  10724. ]
  10725. },
  10726. name: {
  10727. type: "string"
  10728. },
  10729. metadata: {
  10730. type: "*"
  10731. },
  10732. center: {
  10733. type: "array",
  10734. value: "number"
  10735. },
  10736. zoom: {
  10737. type: "number"
  10738. },
  10739. bearing: {
  10740. type: "number",
  10741. "default": 0,
  10742. period: 360,
  10743. units: "degrees"
  10744. },
  10745. pitch: {
  10746. type: "number",
  10747. "default": 0,
  10748. units: "degrees"
  10749. },
  10750. light: {
  10751. type: "light"
  10752. },
  10753. sources: {
  10754. required: true,
  10755. type: "sources"
  10756. },
  10757. sprite: {
  10758. type: "string"
  10759. },
  10760. glyphs: {
  10761. type: "string"
  10762. },
  10763. transition: {
  10764. type: "transition"
  10765. },
  10766. layers: {
  10767. required: true,
  10768. type: "array",
  10769. value: "layer"
  10770. }
  10771. };
  10772. var sources = {
  10773. "*": {
  10774. type: "source"
  10775. }
  10776. };
  10777. var source = [
  10778. "source_vector",
  10779. "source_raster",
  10780. "source_raster_dem",
  10781. "source_geojson",
  10782. "source_video",
  10783. "source_image"
  10784. ];
  10785. var source_vector = {
  10786. type: {
  10787. required: true,
  10788. type: "enum",
  10789. values: {
  10790. vector: {
  10791. }
  10792. }
  10793. },
  10794. url: {
  10795. type: "string"
  10796. },
  10797. tiles: {
  10798. type: "array",
  10799. value: "string"
  10800. },
  10801. bounds: {
  10802. type: "array",
  10803. value: "number",
  10804. length: 4,
  10805. "default": [
  10806. -180,
  10807. -85.051129,
  10808. 180,
  10809. 85.051129
  10810. ]
  10811. },
  10812. scheme: {
  10813. type: "enum",
  10814. values: {
  10815. xyz: {
  10816. },
  10817. tms: {
  10818. }
  10819. },
  10820. "default": "xyz"
  10821. },
  10822. minzoom: {
  10823. type: "number",
  10824. "default": 0
  10825. },
  10826. maxzoom: {
  10827. type: "number",
  10828. "default": 22
  10829. },
  10830. attribution: {
  10831. type: "string"
  10832. },
  10833. "*": {
  10834. type: "*"
  10835. }
  10836. };
  10837. var source_raster = {
  10838. type: {
  10839. required: true,
  10840. type: "enum",
  10841. values: {
  10842. raster: {
  10843. }
  10844. }
  10845. },
  10846. url: {
  10847. type: "string"
  10848. },
  10849. tiles: {
  10850. type: "array",
  10851. value: "string"
  10852. },
  10853. bounds: {
  10854. type: "array",
  10855. value: "number",
  10856. length: 4,
  10857. "default": [
  10858. -180,
  10859. -85.051129,
  10860. 180,
  10861. 85.051129
  10862. ]
  10863. },
  10864. minzoom: {
  10865. type: "number",
  10866. "default": 0
  10867. },
  10868. maxzoom: {
  10869. type: "number",
  10870. "default": 22
  10871. },
  10872. tileSize: {
  10873. type: "number",
  10874. "default": 512,
  10875. units: "pixels"
  10876. },
  10877. scheme: {
  10878. type: "enum",
  10879. values: {
  10880. xyz: {
  10881. },
  10882. tms: {
  10883. }
  10884. },
  10885. "default": "xyz"
  10886. },
  10887. attribution: {
  10888. type: "string"
  10889. },
  10890. "*": {
  10891. type: "*"
  10892. }
  10893. };
  10894. var source_raster_dem = {
  10895. type: {
  10896. required: true,
  10897. type: "enum",
  10898. values: {
  10899. "raster-dem": {
  10900. }
  10901. }
  10902. },
  10903. url: {
  10904. type: "string"
  10905. },
  10906. tiles: {
  10907. type: "array",
  10908. value: "string"
  10909. },
  10910. bounds: {
  10911. type: "array",
  10912. value: "number",
  10913. length: 4,
  10914. "default": [
  10915. -180,
  10916. -85.051129,
  10917. 180,
  10918. 85.051129
  10919. ]
  10920. },
  10921. minzoom: {
  10922. type: "number",
  10923. "default": 0
  10924. },
  10925. maxzoom: {
  10926. type: "number",
  10927. "default": 22
  10928. },
  10929. tileSize: {
  10930. type: "number",
  10931. "default": 512,
  10932. units: "pixels"
  10933. },
  10934. attribution: {
  10935. type: "string"
  10936. },
  10937. encoding: {
  10938. type: "enum",
  10939. values: {
  10940. terrarium: {
  10941. },
  10942. mapbox: {
  10943. }
  10944. },
  10945. "default": "mapbox"
  10946. },
  10947. "*": {
  10948. type: "*"
  10949. }
  10950. };
  10951. var source_geojson = {
  10952. type: {
  10953. required: true,
  10954. type: "enum",
  10955. values: {
  10956. geojson: {
  10957. }
  10958. }
  10959. },
  10960. data: {
  10961. type: "*"
  10962. },
  10963. maxzoom: {
  10964. type: "number",
  10965. "default": 18
  10966. },
  10967. attribution: {
  10968. type: "string"
  10969. },
  10970. buffer: {
  10971. type: "number",
  10972. "default": 128,
  10973. maximum: 512,
  10974. minimum: 0
  10975. },
  10976. tolerance: {
  10977. type: "number",
  10978. "default": 0.375
  10979. },
  10980. cluster: {
  10981. type: "boolean",
  10982. "default": false
  10983. },
  10984. clusterRadius: {
  10985. type: "number",
  10986. "default": 50,
  10987. minimum: 0
  10988. },
  10989. clusterMaxZoom: {
  10990. type: "number"
  10991. },
  10992. clusterProperties: {
  10993. type: "*"
  10994. },
  10995. lineMetrics: {
  10996. type: "boolean",
  10997. "default": false
  10998. },
  10999. generateId: {
  11000. type: "boolean",
  11001. "default": false
  11002. }
  11003. };
  11004. var source_video = {
  11005. type: {
  11006. required: true,
  11007. type: "enum",
  11008. values: {
  11009. video: {
  11010. }
  11011. }
  11012. },
  11013. urls: {
  11014. required: true,
  11015. type: "array",
  11016. value: "string"
  11017. },
  11018. coordinates: {
  11019. required: true,
  11020. type: "array",
  11021. length: 4,
  11022. value: {
  11023. type: "array",
  11024. length: 2,
  11025. value: "number"
  11026. }
  11027. }
  11028. };
  11029. var source_image = {
  11030. type: {
  11031. required: true,
  11032. type: "enum",
  11033. values: {
  11034. image: {
  11035. }
  11036. }
  11037. },
  11038. url: {
  11039. required: true,
  11040. type: "string"
  11041. },
  11042. coordinates: {
  11043. required: true,
  11044. type: "array",
  11045. length: 4,
  11046. value: {
  11047. type: "array",
  11048. length: 2,
  11049. value: "number"
  11050. }
  11051. }
  11052. };
  11053. var layer = {
  11054. id: {
  11055. type: "string",
  11056. required: true
  11057. },
  11058. type: {
  11059. type: "enum",
  11060. values: {
  11061. fill: {
  11062. },
  11063. line: {
  11064. },
  11065. symbol: {
  11066. },
  11067. circle: {
  11068. },
  11069. heatmap: {
  11070. },
  11071. "fill-extrusion": {
  11072. },
  11073. raster: {
  11074. },
  11075. hillshade: {
  11076. },
  11077. background: {
  11078. }
  11079. },
  11080. required: true
  11081. },
  11082. metadata: {
  11083. type: "*"
  11084. },
  11085. source: {
  11086. type: "string"
  11087. },
  11088. "source-layer": {
  11089. type: "string"
  11090. },
  11091. minzoom: {
  11092. type: "number",
  11093. minimum: 0,
  11094. maximum: 24
  11095. },
  11096. maxzoom: {
  11097. type: "number",
  11098. minimum: 0,
  11099. maximum: 24
  11100. },
  11101. filter: {
  11102. type: "filter"
  11103. },
  11104. layout: {
  11105. type: "layout"
  11106. },
  11107. paint: {
  11108. type: "paint"
  11109. }
  11110. };
  11111. var layout = [
  11112. "layout_fill",
  11113. "layout_line",
  11114. "layout_circle",
  11115. "layout_heatmap",
  11116. "layout_fill-extrusion",
  11117. "layout_symbol",
  11118. "layout_raster",
  11119. "layout_hillshade",
  11120. "layout_background"
  11121. ];
  11122. var layout_background = {
  11123. visibility: {
  11124. type: "enum",
  11125. values: {
  11126. visible: {
  11127. },
  11128. none: {
  11129. }
  11130. },
  11131. "default": "visible",
  11132. "property-type": "constant"
  11133. }
  11134. };
  11135. var layout_fill = {
  11136. "fill-sort-key": {
  11137. type: "number",
  11138. expression: {
  11139. interpolated: false,
  11140. parameters: [
  11141. "zoom",
  11142. "feature"
  11143. ]
  11144. },
  11145. "property-type": "data-driven"
  11146. },
  11147. visibility: {
  11148. type: "enum",
  11149. values: {
  11150. visible: {
  11151. },
  11152. none: {
  11153. }
  11154. },
  11155. "default": "visible",
  11156. "property-type": "constant"
  11157. }
  11158. };
  11159. var layout_circle = {
  11160. "circle-sort-key": {
  11161. type: "number",
  11162. expression: {
  11163. interpolated: false,
  11164. parameters: [
  11165. "zoom",
  11166. "feature"
  11167. ]
  11168. },
  11169. "property-type": "data-driven"
  11170. },
  11171. visibility: {
  11172. type: "enum",
  11173. values: {
  11174. visible: {
  11175. },
  11176. none: {
  11177. }
  11178. },
  11179. "default": "visible",
  11180. "property-type": "constant"
  11181. }
  11182. };
  11183. var layout_heatmap = {
  11184. visibility: {
  11185. type: "enum",
  11186. values: {
  11187. visible: {
  11188. },
  11189. none: {
  11190. }
  11191. },
  11192. "default": "visible",
  11193. "property-type": "constant"
  11194. }
  11195. };
  11196. var layout_line = {
  11197. "line-cap": {
  11198. type: "enum",
  11199. values: {
  11200. butt: {
  11201. },
  11202. round: {
  11203. },
  11204. square: {
  11205. }
  11206. },
  11207. "default": "butt",
  11208. expression: {
  11209. interpolated: false,
  11210. parameters: [
  11211. "zoom"
  11212. ]
  11213. },
  11214. "property-type": "data-constant"
  11215. },
  11216. "line-join": {
  11217. type: "enum",
  11218. values: {
  11219. bevel: {
  11220. },
  11221. round: {
  11222. },
  11223. miter: {
  11224. }
  11225. },
  11226. "default": "miter",
  11227. expression: {
  11228. interpolated: false,
  11229. parameters: [
  11230. "zoom",
  11231. "feature"
  11232. ]
  11233. },
  11234. "property-type": "data-driven"
  11235. },
  11236. "line-miter-limit": {
  11237. type: "number",
  11238. "default": 2,
  11239. requires: [
  11240. {
  11241. "line-join": "miter"
  11242. }
  11243. ],
  11244. expression: {
  11245. interpolated: true,
  11246. parameters: [
  11247. "zoom"
  11248. ]
  11249. },
  11250. "property-type": "data-constant"
  11251. },
  11252. "line-round-limit": {
  11253. type: "number",
  11254. "default": 1.05,
  11255. requires: [
  11256. {
  11257. "line-join": "round"
  11258. }
  11259. ],
  11260. expression: {
  11261. interpolated: true,
  11262. parameters: [
  11263. "zoom"
  11264. ]
  11265. },
  11266. "property-type": "data-constant"
  11267. },
  11268. "line-sort-key": {
  11269. type: "number",
  11270. expression: {
  11271. interpolated: false,
  11272. parameters: [
  11273. "zoom",
  11274. "feature"
  11275. ]
  11276. },
  11277. "property-type": "data-driven"
  11278. },
  11279. visibility: {
  11280. type: "enum",
  11281. values: {
  11282. visible: {
  11283. },
  11284. none: {
  11285. }
  11286. },
  11287. "default": "visible",
  11288. "property-type": "constant"
  11289. }
  11290. };
  11291. var layout_symbol = {
  11292. "symbol-placement": {
  11293. type: "enum",
  11294. values: {
  11295. point: {
  11296. },
  11297. line: {
  11298. },
  11299. "line-center": {
  11300. }
  11301. },
  11302. "default": "point",
  11303. expression: {
  11304. interpolated: false,
  11305. parameters: [
  11306. "zoom"
  11307. ]
  11308. },
  11309. "property-type": "data-constant"
  11310. },
  11311. "symbol-spacing": {
  11312. type: "number",
  11313. "default": 250,
  11314. minimum: 1,
  11315. units: "pixels",
  11316. requires: [
  11317. {
  11318. "symbol-placement": "line"
  11319. }
  11320. ],
  11321. expression: {
  11322. interpolated: true,
  11323. parameters: [
  11324. "zoom"
  11325. ]
  11326. },
  11327. "property-type": "data-constant"
  11328. },
  11329. "symbol-avoid-edges": {
  11330. type: "boolean",
  11331. "default": false,
  11332. expression: {
  11333. interpolated: false,
  11334. parameters: [
  11335. "zoom"
  11336. ]
  11337. },
  11338. "property-type": "data-constant"
  11339. },
  11340. "symbol-sort-key": {
  11341. type: "number",
  11342. expression: {
  11343. interpolated: false,
  11344. parameters: [
  11345. "zoom",
  11346. "feature"
  11347. ]
  11348. },
  11349. "property-type": "data-driven"
  11350. },
  11351. "symbol-z-order": {
  11352. type: "enum",
  11353. values: {
  11354. auto: {
  11355. },
  11356. "viewport-y": {
  11357. },
  11358. source: {
  11359. }
  11360. },
  11361. "default": "auto",
  11362. expression: {
  11363. interpolated: false,
  11364. parameters: [
  11365. "zoom"
  11366. ]
  11367. },
  11368. "property-type": "data-constant"
  11369. },
  11370. "icon-allow-overlap": {
  11371. type: "boolean",
  11372. "default": false,
  11373. requires: [
  11374. "icon-image"
  11375. ],
  11376. expression: {
  11377. interpolated: false,
  11378. parameters: [
  11379. "zoom"
  11380. ]
  11381. },
  11382. "property-type": "data-constant"
  11383. },
  11384. "icon-ignore-placement": {
  11385. type: "boolean",
  11386. "default": false,
  11387. requires: [
  11388. "icon-image"
  11389. ],
  11390. expression: {
  11391. interpolated: false,
  11392. parameters: [
  11393. "zoom"
  11394. ]
  11395. },
  11396. "property-type": "data-constant"
  11397. },
  11398. "icon-optional": {
  11399. type: "boolean",
  11400. "default": false,
  11401. requires: [
  11402. "icon-image",
  11403. "text-field"
  11404. ],
  11405. expression: {
  11406. interpolated: false,
  11407. parameters: [
  11408. "zoom"
  11409. ]
  11410. },
  11411. "property-type": "data-constant"
  11412. },
  11413. "icon-rotation-alignment": {
  11414. type: "enum",
  11415. values: {
  11416. map: {
  11417. },
  11418. viewport: {
  11419. },
  11420. auto: {
  11421. }
  11422. },
  11423. "default": "auto",
  11424. requires: [
  11425. "icon-image"
  11426. ],
  11427. expression: {
  11428. interpolated: false,
  11429. parameters: [
  11430. "zoom"
  11431. ]
  11432. },
  11433. "property-type": "data-constant"
  11434. },
  11435. "icon-size": {
  11436. type: "number",
  11437. "default": 1,
  11438. minimum: 0,
  11439. units: "factor of the original icon size",
  11440. requires: [
  11441. "icon-image"
  11442. ],
  11443. expression: {
  11444. interpolated: true,
  11445. parameters: [
  11446. "zoom",
  11447. "feature"
  11448. ]
  11449. },
  11450. "property-type": "data-driven"
  11451. },
  11452. "icon-text-fit": {
  11453. type: "enum",
  11454. values: {
  11455. none: {
  11456. },
  11457. width: {
  11458. },
  11459. height: {
  11460. },
  11461. both: {
  11462. }
  11463. },
  11464. "default": "none",
  11465. requires: [
  11466. "icon-image",
  11467. "text-field"
  11468. ],
  11469. expression: {
  11470. interpolated: false,
  11471. parameters: [
  11472. "zoom"
  11473. ]
  11474. },
  11475. "property-type": "data-constant"
  11476. },
  11477. "icon-text-fit-padding": {
  11478. type: "array",
  11479. value: "number",
  11480. length: 4,
  11481. "default": [
  11482. 0,
  11483. 0,
  11484. 0,
  11485. 0
  11486. ],
  11487. units: "pixels",
  11488. requires: [
  11489. "icon-image",
  11490. "text-field",
  11491. {
  11492. "icon-text-fit": [
  11493. "both",
  11494. "width",
  11495. "height"
  11496. ]
  11497. }
  11498. ],
  11499. expression: {
  11500. interpolated: true,
  11501. parameters: [
  11502. "zoom"
  11503. ]
  11504. },
  11505. "property-type": "data-constant"
  11506. },
  11507. "icon-image": {
  11508. type: "resolvedImage",
  11509. tokens: true,
  11510. expression: {
  11511. interpolated: false,
  11512. parameters: [
  11513. "zoom",
  11514. "feature"
  11515. ]
  11516. },
  11517. "property-type": "data-driven"
  11518. },
  11519. "icon-rotate": {
  11520. type: "number",
  11521. "default": 0,
  11522. period: 360,
  11523. units: "degrees",
  11524. requires: [
  11525. "icon-image"
  11526. ],
  11527. expression: {
  11528. interpolated: true,
  11529. parameters: [
  11530. "zoom",
  11531. "feature"
  11532. ]
  11533. },
  11534. "property-type": "data-driven"
  11535. },
  11536. "icon-padding": {
  11537. type: "number",
  11538. "default": 2,
  11539. minimum: 0,
  11540. units: "pixels",
  11541. requires: [
  11542. "icon-image"
  11543. ],
  11544. expression: {
  11545. interpolated: true,
  11546. parameters: [
  11547. "zoom"
  11548. ]
  11549. },
  11550. "property-type": "data-constant"
  11551. },
  11552. "icon-keep-upright": {
  11553. type: "boolean",
  11554. "default": false,
  11555. requires: [
  11556. "icon-image",
  11557. {
  11558. "icon-rotation-alignment": "map"
  11559. },
  11560. {
  11561. "symbol-placement": [
  11562. "line",
  11563. "line-center"
  11564. ]
  11565. }
  11566. ],
  11567. expression: {
  11568. interpolated: false,
  11569. parameters: [
  11570. "zoom"
  11571. ]
  11572. },
  11573. "property-type": "data-constant"
  11574. },
  11575. "icon-offset": {
  11576. type: "array",
  11577. value: "number",
  11578. length: 2,
  11579. "default": [
  11580. 0,
  11581. 0
  11582. ],
  11583. requires: [
  11584. "icon-image"
  11585. ],
  11586. expression: {
  11587. interpolated: true,
  11588. parameters: [
  11589. "zoom",
  11590. "feature"
  11591. ]
  11592. },
  11593. "property-type": "data-driven"
  11594. },
  11595. "icon-anchor": {
  11596. type: "enum",
  11597. values: {
  11598. center: {
  11599. },
  11600. left: {
  11601. },
  11602. right: {
  11603. },
  11604. top: {
  11605. },
  11606. bottom: {
  11607. },
  11608. "top-left": {
  11609. },
  11610. "top-right": {
  11611. },
  11612. "bottom-left": {
  11613. },
  11614. "bottom-right": {
  11615. }
  11616. },
  11617. "default": "center",
  11618. requires: [
  11619. "icon-image"
  11620. ],
  11621. expression: {
  11622. interpolated: false,
  11623. parameters: [
  11624. "zoom",
  11625. "feature"
  11626. ]
  11627. },
  11628. "property-type": "data-driven"
  11629. },
  11630. "icon-pitch-alignment": {
  11631. type: "enum",
  11632. values: {
  11633. map: {
  11634. },
  11635. viewport: {
  11636. },
  11637. auto: {
  11638. }
  11639. },
  11640. "default": "auto",
  11641. requires: [
  11642. "icon-image"
  11643. ],
  11644. expression: {
  11645. interpolated: false,
  11646. parameters: [
  11647. "zoom"
  11648. ]
  11649. },
  11650. "property-type": "data-constant"
  11651. },
  11652. "text-pitch-alignment": {
  11653. type: "enum",
  11654. values: {
  11655. map: {
  11656. },
  11657. viewport: {
  11658. },
  11659. auto: {
  11660. }
  11661. },
  11662. "default": "auto",
  11663. requires: [
  11664. "text-field"
  11665. ],
  11666. expression: {
  11667. interpolated: false,
  11668. parameters: [
  11669. "zoom"
  11670. ]
  11671. },
  11672. "property-type": "data-constant"
  11673. },
  11674. "text-rotation-alignment": {
  11675. type: "enum",
  11676. values: {
  11677. map: {
  11678. },
  11679. viewport: {
  11680. },
  11681. auto: {
  11682. }
  11683. },
  11684. "default": "auto",
  11685. requires: [
  11686. "text-field"
  11687. ],
  11688. expression: {
  11689. interpolated: false,
  11690. parameters: [
  11691. "zoom"
  11692. ]
  11693. },
  11694. "property-type": "data-constant"
  11695. },
  11696. "text-field": {
  11697. type: "formatted",
  11698. "default": "",
  11699. tokens: true,
  11700. expression: {
  11701. interpolated: false,
  11702. parameters: [
  11703. "zoom",
  11704. "feature"
  11705. ]
  11706. },
  11707. "property-type": "data-driven"
  11708. },
  11709. "text-font": {
  11710. type: "array",
  11711. value: "string",
  11712. "default": [
  11713. "Open Sans Regular",
  11714. "Arial Unicode MS Regular"
  11715. ],
  11716. requires: [
  11717. "text-field"
  11718. ],
  11719. expression: {
  11720. interpolated: false,
  11721. parameters: [
  11722. "zoom",
  11723. "feature"
  11724. ]
  11725. },
  11726. "property-type": "data-driven"
  11727. },
  11728. "text-size": {
  11729. type: "number",
  11730. "default": 16,
  11731. minimum: 0,
  11732. units: "pixels",
  11733. requires: [
  11734. "text-field"
  11735. ],
  11736. expression: {
  11737. interpolated: true,
  11738. parameters: [
  11739. "zoom",
  11740. "feature"
  11741. ]
  11742. },
  11743. "property-type": "data-driven"
  11744. },
  11745. "text-max-width": {
  11746. type: "number",
  11747. "default": 10,
  11748. minimum: 0,
  11749. units: "ems",
  11750. requires: [
  11751. "text-field"
  11752. ],
  11753. expression: {
  11754. interpolated: true,
  11755. parameters: [
  11756. "zoom",
  11757. "feature"
  11758. ]
  11759. },
  11760. "property-type": "data-driven"
  11761. },
  11762. "text-line-height": {
  11763. type: "number",
  11764. "default": 1.2,
  11765. units: "ems",
  11766. requires: [
  11767. "text-field"
  11768. ],
  11769. expression: {
  11770. interpolated: true,
  11771. parameters: [
  11772. "zoom"
  11773. ]
  11774. },
  11775. "property-type": "data-constant"
  11776. },
  11777. "text-letter-spacing": {
  11778. type: "number",
  11779. "default": 0,
  11780. units: "ems",
  11781. requires: [
  11782. "text-field"
  11783. ],
  11784. expression: {
  11785. interpolated: true,
  11786. parameters: [
  11787. "zoom",
  11788. "feature"
  11789. ]
  11790. },
  11791. "property-type": "data-driven"
  11792. },
  11793. "text-justify": {
  11794. type: "enum",
  11795. values: {
  11796. auto: {
  11797. },
  11798. left: {
  11799. },
  11800. center: {
  11801. },
  11802. right: {
  11803. }
  11804. },
  11805. "default": "center",
  11806. requires: [
  11807. "text-field"
  11808. ],
  11809. expression: {
  11810. interpolated: false,
  11811. parameters: [
  11812. "zoom",
  11813. "feature"
  11814. ]
  11815. },
  11816. "property-type": "data-driven"
  11817. },
  11818. "text-radial-offset": {
  11819. type: "number",
  11820. units: "ems",
  11821. "default": 0,
  11822. requires: [
  11823. "text-field"
  11824. ],
  11825. "property-type": "data-driven",
  11826. expression: {
  11827. interpolated: true,
  11828. parameters: [
  11829. "zoom",
  11830. "feature"
  11831. ]
  11832. }
  11833. },
  11834. "text-variable-anchor": {
  11835. type: "array",
  11836. value: "enum",
  11837. values: {
  11838. center: {
  11839. },
  11840. left: {
  11841. },
  11842. right: {
  11843. },
  11844. top: {
  11845. },
  11846. bottom: {
  11847. },
  11848. "top-left": {
  11849. },
  11850. "top-right": {
  11851. },
  11852. "bottom-left": {
  11853. },
  11854. "bottom-right": {
  11855. }
  11856. },
  11857. requires: [
  11858. "text-field",
  11859. {
  11860. "symbol-placement": [
  11861. "point"
  11862. ]
  11863. }
  11864. ],
  11865. expression: {
  11866. interpolated: false,
  11867. parameters: [
  11868. "zoom"
  11869. ]
  11870. },
  11871. "property-type": "data-constant"
  11872. },
  11873. "text-anchor": {
  11874. type: "enum",
  11875. values: {
  11876. center: {
  11877. },
  11878. left: {
  11879. },
  11880. right: {
  11881. },
  11882. top: {
  11883. },
  11884. bottom: {
  11885. },
  11886. "top-left": {
  11887. },
  11888. "top-right": {
  11889. },
  11890. "bottom-left": {
  11891. },
  11892. "bottom-right": {
  11893. }
  11894. },
  11895. "default": "center",
  11896. requires: [
  11897. "text-field",
  11898. {
  11899. "!": "text-variable-anchor"
  11900. }
  11901. ],
  11902. expression: {
  11903. interpolated: false,
  11904. parameters: [
  11905. "zoom",
  11906. "feature"
  11907. ]
  11908. },
  11909. "property-type": "data-driven"
  11910. },
  11911. "text-max-angle": {
  11912. type: "number",
  11913. "default": 45,
  11914. units: "degrees",
  11915. requires: [
  11916. "text-field",
  11917. {
  11918. "symbol-placement": [
  11919. "line",
  11920. "line-center"
  11921. ]
  11922. }
  11923. ],
  11924. expression: {
  11925. interpolated: true,
  11926. parameters: [
  11927. "zoom"
  11928. ]
  11929. },
  11930. "property-type": "data-constant"
  11931. },
  11932. "text-writing-mode": {
  11933. type: "array",
  11934. value: "enum",
  11935. values: {
  11936. horizontal: {
  11937. },
  11938. vertical: {
  11939. }
  11940. },
  11941. requires: [
  11942. "text-field",
  11943. {
  11944. "symbol-placement": [
  11945. "point"
  11946. ]
  11947. }
  11948. ],
  11949. expression: {
  11950. interpolated: false,
  11951. parameters: [
  11952. "zoom"
  11953. ]
  11954. },
  11955. "property-type": "data-constant"
  11956. },
  11957. "text-rotate": {
  11958. type: "number",
  11959. "default": 0,
  11960. period: 360,
  11961. units: "degrees",
  11962. requires: [
  11963. "text-field"
  11964. ],
  11965. expression: {
  11966. interpolated: true,
  11967. parameters: [
  11968. "zoom",
  11969. "feature"
  11970. ]
  11971. },
  11972. "property-type": "data-driven"
  11973. },
  11974. "text-padding": {
  11975. type: "number",
  11976. "default": 2,
  11977. minimum: 0,
  11978. units: "pixels",
  11979. requires: [
  11980. "text-field"
  11981. ],
  11982. expression: {
  11983. interpolated: true,
  11984. parameters: [
  11985. "zoom"
  11986. ]
  11987. },
  11988. "property-type": "data-constant"
  11989. },
  11990. "text-keep-upright": {
  11991. type: "boolean",
  11992. "default": true,
  11993. requires: [
  11994. "text-field",
  11995. {
  11996. "text-rotation-alignment": "map"
  11997. },
  11998. {
  11999. "symbol-placement": [
  12000. "line",
  12001. "line-center"
  12002. ]
  12003. }
  12004. ],
  12005. expression: {
  12006. interpolated: false,
  12007. parameters: [
  12008. "zoom"
  12009. ]
  12010. },
  12011. "property-type": "data-constant"
  12012. },
  12013. "text-transform": {
  12014. type: "enum",
  12015. values: {
  12016. none: {
  12017. },
  12018. uppercase: {
  12019. },
  12020. lowercase: {
  12021. }
  12022. },
  12023. "default": "none",
  12024. requires: [
  12025. "text-field"
  12026. ],
  12027. expression: {
  12028. interpolated: false,
  12029. parameters: [
  12030. "zoom",
  12031. "feature"
  12032. ]
  12033. },
  12034. "property-type": "data-driven"
  12035. },
  12036. "text-offset": {
  12037. type: "array",
  12038. value: "number",
  12039. units: "ems",
  12040. length: 2,
  12041. "default": [
  12042. 0,
  12043. 0
  12044. ],
  12045. requires: [
  12046. "text-field",
  12047. {
  12048. "!": "text-radial-offset"
  12049. }
  12050. ],
  12051. expression: {
  12052. interpolated: true,
  12053. parameters: [
  12054. "zoom",
  12055. "feature"
  12056. ]
  12057. },
  12058. "property-type": "data-driven"
  12059. },
  12060. "text-allow-overlap": {
  12061. type: "boolean",
  12062. "default": false,
  12063. requires: [
  12064. "text-field"
  12065. ],
  12066. expression: {
  12067. interpolated: false,
  12068. parameters: [
  12069. "zoom"
  12070. ]
  12071. },
  12072. "property-type": "data-constant"
  12073. },
  12074. "text-ignore-placement": {
  12075. type: "boolean",
  12076. "default": false,
  12077. requires: [
  12078. "text-field"
  12079. ],
  12080. expression: {
  12081. interpolated: false,
  12082. parameters: [
  12083. "zoom"
  12084. ]
  12085. },
  12086. "property-type": "data-constant"
  12087. },
  12088. "text-optional": {
  12089. type: "boolean",
  12090. "default": false,
  12091. requires: [
  12092. "text-field",
  12093. "icon-image"
  12094. ],
  12095. expression: {
  12096. interpolated: false,
  12097. parameters: [
  12098. "zoom"
  12099. ]
  12100. },
  12101. "property-type": "data-constant"
  12102. },
  12103. visibility: {
  12104. type: "enum",
  12105. values: {
  12106. visible: {
  12107. },
  12108. none: {
  12109. }
  12110. },
  12111. "default": "visible",
  12112. "property-type": "constant"
  12113. }
  12114. };
  12115. var layout_raster = {
  12116. visibility: {
  12117. type: "enum",
  12118. values: {
  12119. visible: {
  12120. },
  12121. none: {
  12122. }
  12123. },
  12124. "default": "visible",
  12125. "property-type": "constant"
  12126. }
  12127. };
  12128. var layout_hillshade = {
  12129. visibility: {
  12130. type: "enum",
  12131. values: {
  12132. visible: {
  12133. },
  12134. none: {
  12135. }
  12136. },
  12137. "default": "visible",
  12138. "property-type": "constant"
  12139. }
  12140. };
  12141. var filter = {
  12142. type: "array",
  12143. value: "*"
  12144. };
  12145. var filter_operator = {
  12146. type: "enum",
  12147. values: {
  12148. "==": {
  12149. },
  12150. "!=": {
  12151. },
  12152. ">": {
  12153. },
  12154. ">=": {
  12155. },
  12156. "<": {
  12157. },
  12158. "<=": {
  12159. },
  12160. "in": {
  12161. },
  12162. "!in": {
  12163. },
  12164. all: {
  12165. },
  12166. any: {
  12167. },
  12168. none: {
  12169. },
  12170. has: {
  12171. },
  12172. "!has": {
  12173. }
  12174. }
  12175. };
  12176. var geometry_type = {
  12177. type: "enum",
  12178. values: {
  12179. Point: {
  12180. },
  12181. LineString: {
  12182. },
  12183. Polygon: {
  12184. }
  12185. }
  12186. };
  12187. var function_stop = {
  12188. type: "array",
  12189. minimum: 0,
  12190. maximum: 24,
  12191. value: [
  12192. "number",
  12193. "color"
  12194. ],
  12195. length: 2
  12196. };
  12197. var expression = {
  12198. type: "array",
  12199. value: "*",
  12200. minimum: 1
  12201. };
  12202. var expression_name = {
  12203. type: "enum",
  12204. values: {
  12205. "let": {
  12206. group: "Variable binding"
  12207. },
  12208. "var": {
  12209. group: "Variable binding"
  12210. },
  12211. literal: {
  12212. group: "Types"
  12213. },
  12214. array: {
  12215. group: "Types"
  12216. },
  12217. at: {
  12218. group: "Lookup"
  12219. },
  12220. "in": {
  12221. group: "Lookup"
  12222. },
  12223. "case": {
  12224. group: "Decision"
  12225. },
  12226. match: {
  12227. group: "Decision"
  12228. },
  12229. coalesce: {
  12230. group: "Decision"
  12231. },
  12232. step: {
  12233. group: "Ramps, scales, curves"
  12234. },
  12235. interpolate: {
  12236. group: "Ramps, scales, curves"
  12237. },
  12238. "interpolate-hcl": {
  12239. group: "Ramps, scales, curves"
  12240. },
  12241. "interpolate-lab": {
  12242. group: "Ramps, scales, curves"
  12243. },
  12244. ln2: {
  12245. group: "Math"
  12246. },
  12247. pi: {
  12248. group: "Math"
  12249. },
  12250. e: {
  12251. group: "Math"
  12252. },
  12253. "typeof": {
  12254. group: "Types"
  12255. },
  12256. string: {
  12257. group: "Types"
  12258. },
  12259. number: {
  12260. group: "Types"
  12261. },
  12262. boolean: {
  12263. group: "Types"
  12264. },
  12265. object: {
  12266. group: "Types"
  12267. },
  12268. collator: {
  12269. group: "Types"
  12270. },
  12271. format: {
  12272. group: "Types"
  12273. },
  12274. image: {
  12275. group: "Types"
  12276. },
  12277. "number-format": {
  12278. group: "Types"
  12279. },
  12280. "to-string": {
  12281. group: "Types"
  12282. },
  12283. "to-number": {
  12284. group: "Types"
  12285. },
  12286. "to-boolean": {
  12287. group: "Types"
  12288. },
  12289. "to-rgba": {
  12290. group: "Color"
  12291. },
  12292. "to-color": {
  12293. group: "Types"
  12294. },
  12295. rgb: {
  12296. group: "Color"
  12297. },
  12298. rgba: {
  12299. group: "Color"
  12300. },
  12301. get: {
  12302. group: "Lookup"
  12303. },
  12304. has: {
  12305. group: "Lookup"
  12306. },
  12307. length: {
  12308. group: "Lookup"
  12309. },
  12310. properties: {
  12311. group: "Feature data"
  12312. },
  12313. "feature-state": {
  12314. group: "Feature data"
  12315. },
  12316. "geometry-type": {
  12317. group: "Feature data"
  12318. },
  12319. id: {
  12320. group: "Feature data"
  12321. },
  12322. zoom: {
  12323. group: "Zoom"
  12324. },
  12325. "heatmap-density": {
  12326. group: "Heatmap"
  12327. },
  12328. "line-progress": {
  12329. group: "Feature data"
  12330. },
  12331. accumulated: {
  12332. group: "Feature data"
  12333. },
  12334. "+": {
  12335. group: "Math"
  12336. },
  12337. "*": {
  12338. group: "Math"
  12339. },
  12340. "-": {
  12341. group: "Math"
  12342. },
  12343. "/": {
  12344. group: "Math"
  12345. },
  12346. "%": {
  12347. group: "Math"
  12348. },
  12349. "^": {
  12350. group: "Math"
  12351. },
  12352. sqrt: {
  12353. group: "Math"
  12354. },
  12355. log10: {
  12356. group: "Math"
  12357. },
  12358. ln: {
  12359. group: "Math"
  12360. },
  12361. log2: {
  12362. group: "Math"
  12363. },
  12364. sin: {
  12365. group: "Math"
  12366. },
  12367. cos: {
  12368. group: "Math"
  12369. },
  12370. tan: {
  12371. group: "Math"
  12372. },
  12373. asin: {
  12374. group: "Math"
  12375. },
  12376. acos: {
  12377. group: "Math"
  12378. },
  12379. atan: {
  12380. group: "Math"
  12381. },
  12382. min: {
  12383. group: "Math"
  12384. },
  12385. max: {
  12386. group: "Math"
  12387. },
  12388. round: {
  12389. group: "Math"
  12390. },
  12391. abs: {
  12392. group: "Math"
  12393. },
  12394. ceil: {
  12395. group: "Math"
  12396. },
  12397. floor: {
  12398. group: "Math"
  12399. },
  12400. "==": {
  12401. group: "Decision"
  12402. },
  12403. "!=": {
  12404. group: "Decision"
  12405. },
  12406. ">": {
  12407. group: "Decision"
  12408. },
  12409. "<": {
  12410. group: "Decision"
  12411. },
  12412. ">=": {
  12413. group: "Decision"
  12414. },
  12415. "<=": {
  12416. group: "Decision"
  12417. },
  12418. all: {
  12419. group: "Decision"
  12420. },
  12421. any: {
  12422. group: "Decision"
  12423. },
  12424. "!": {
  12425. group: "Decision"
  12426. },
  12427. "is-supported-script": {
  12428. group: "String"
  12429. },
  12430. upcase: {
  12431. group: "String"
  12432. },
  12433. downcase: {
  12434. group: "String"
  12435. },
  12436. concat: {
  12437. group: "String"
  12438. },
  12439. "resolved-locale": {
  12440. group: "String"
  12441. }
  12442. }
  12443. };
  12444. var light = {
  12445. anchor: {
  12446. type: "enum",
  12447. "default": "viewport",
  12448. values: {
  12449. map: {
  12450. },
  12451. viewport: {
  12452. }
  12453. },
  12454. "property-type": "data-constant",
  12455. transition: false,
  12456. expression: {
  12457. interpolated: false,
  12458. parameters: [
  12459. "zoom"
  12460. ]
  12461. }
  12462. },
  12463. position: {
  12464. type: "array",
  12465. "default": [
  12466. 1.15,
  12467. 210,
  12468. 30
  12469. ],
  12470. length: 3,
  12471. value: "number",
  12472. "property-type": "data-constant",
  12473. transition: true,
  12474. expression: {
  12475. interpolated: true,
  12476. parameters: [
  12477. "zoom"
  12478. ]
  12479. }
  12480. },
  12481. color: {
  12482. type: "color",
  12483. "property-type": "data-constant",
  12484. "default": "#ffffff",
  12485. expression: {
  12486. interpolated: true,
  12487. parameters: [
  12488. "zoom"
  12489. ]
  12490. },
  12491. transition: true
  12492. },
  12493. intensity: {
  12494. type: "number",
  12495. "property-type": "data-constant",
  12496. "default": 0.5,
  12497. minimum: 0,
  12498. maximum: 1,
  12499. expression: {
  12500. interpolated: true,
  12501. parameters: [
  12502. "zoom"
  12503. ]
  12504. },
  12505. transition: true
  12506. }
  12507. };
  12508. var paint = [
  12509. "paint_fill",
  12510. "paint_line",
  12511. "paint_circle",
  12512. "paint_heatmap",
  12513. "paint_fill-extrusion",
  12514. "paint_symbol",
  12515. "paint_raster",
  12516. "paint_hillshade",
  12517. "paint_background"
  12518. ];
  12519. var paint_fill = {
  12520. "fill-antialias": {
  12521. type: "boolean",
  12522. "default": true,
  12523. expression: {
  12524. interpolated: false,
  12525. parameters: [
  12526. "zoom"
  12527. ]
  12528. },
  12529. "property-type": "data-constant"
  12530. },
  12531. "fill-opacity": {
  12532. type: "number",
  12533. "default": 1,
  12534. minimum: 0,
  12535. maximum: 1,
  12536. transition: true,
  12537. expression: {
  12538. interpolated: true,
  12539. parameters: [
  12540. "zoom",
  12541. "feature",
  12542. "feature-state"
  12543. ]
  12544. },
  12545. "property-type": "data-driven"
  12546. },
  12547. "fill-color": {
  12548. type: "color",
  12549. "default": "#000000",
  12550. transition: true,
  12551. requires: [
  12552. {
  12553. "!": "fill-pattern"
  12554. }
  12555. ],
  12556. expression: {
  12557. interpolated: true,
  12558. parameters: [
  12559. "zoom",
  12560. "feature",
  12561. "feature-state"
  12562. ]
  12563. },
  12564. "property-type": "data-driven"
  12565. },
  12566. "fill-outline-color": {
  12567. type: "color",
  12568. transition: true,
  12569. requires: [
  12570. {
  12571. "!": "fill-pattern"
  12572. },
  12573. {
  12574. "fill-antialias": true
  12575. }
  12576. ],
  12577. expression: {
  12578. interpolated: true,
  12579. parameters: [
  12580. "zoom",
  12581. "feature",
  12582. "feature-state"
  12583. ]
  12584. },
  12585. "property-type": "data-driven"
  12586. },
  12587. "fill-translate": {
  12588. type: "array",
  12589. value: "number",
  12590. length: 2,
  12591. "default": [
  12592. 0,
  12593. 0
  12594. ],
  12595. transition: true,
  12596. units: "pixels",
  12597. expression: {
  12598. interpolated: true,
  12599. parameters: [
  12600. "zoom"
  12601. ]
  12602. },
  12603. "property-type": "data-constant"
  12604. },
  12605. "fill-translate-anchor": {
  12606. type: "enum",
  12607. values: {
  12608. map: {
  12609. },
  12610. viewport: {
  12611. }
  12612. },
  12613. "default": "map",
  12614. requires: [
  12615. "fill-translate"
  12616. ],
  12617. expression: {
  12618. interpolated: false,
  12619. parameters: [
  12620. "zoom"
  12621. ]
  12622. },
  12623. "property-type": "data-constant"
  12624. },
  12625. "fill-pattern": {
  12626. type: "resolvedImage",
  12627. transition: true,
  12628. expression: {
  12629. interpolated: false,
  12630. parameters: [
  12631. "zoom",
  12632. "feature"
  12633. ]
  12634. },
  12635. "property-type": "cross-faded-data-driven"
  12636. }
  12637. };
  12638. var paint_line = {
  12639. "line-opacity": {
  12640. type: "number",
  12641. "default": 1,
  12642. minimum: 0,
  12643. maximum: 1,
  12644. transition: true,
  12645. expression: {
  12646. interpolated: true,
  12647. parameters: [
  12648. "zoom",
  12649. "feature",
  12650. "feature-state"
  12651. ]
  12652. },
  12653. "property-type": "data-driven"
  12654. },
  12655. "line-color": {
  12656. type: "color",
  12657. "default": "#000000",
  12658. transition: true,
  12659. requires: [
  12660. {
  12661. "!": "line-pattern"
  12662. }
  12663. ],
  12664. expression: {
  12665. interpolated: true,
  12666. parameters: [
  12667. "zoom",
  12668. "feature",
  12669. "feature-state"
  12670. ]
  12671. },
  12672. "property-type": "data-driven"
  12673. },
  12674. "line-translate": {
  12675. type: "array",
  12676. value: "number",
  12677. length: 2,
  12678. "default": [
  12679. 0,
  12680. 0
  12681. ],
  12682. transition: true,
  12683. units: "pixels",
  12684. expression: {
  12685. interpolated: true,
  12686. parameters: [
  12687. "zoom"
  12688. ]
  12689. },
  12690. "property-type": "data-constant"
  12691. },
  12692. "line-translate-anchor": {
  12693. type: "enum",
  12694. values: {
  12695. map: {
  12696. },
  12697. viewport: {
  12698. }
  12699. },
  12700. "default": "map",
  12701. requires: [
  12702. "line-translate"
  12703. ],
  12704. expression: {
  12705. interpolated: false,
  12706. parameters: [
  12707. "zoom"
  12708. ]
  12709. },
  12710. "property-type": "data-constant"
  12711. },
  12712. "line-width": {
  12713. type: "number",
  12714. "default": 1,
  12715. minimum: 0,
  12716. transition: true,
  12717. units: "pixels",
  12718. expression: {
  12719. interpolated: true,
  12720. parameters: [
  12721. "zoom",
  12722. "feature",
  12723. "feature-state"
  12724. ]
  12725. },
  12726. "property-type": "data-driven"
  12727. },
  12728. "line-gap-width": {
  12729. type: "number",
  12730. "default": 0,
  12731. minimum: 0,
  12732. transition: true,
  12733. units: "pixels",
  12734. expression: {
  12735. interpolated: true,
  12736. parameters: [
  12737. "zoom",
  12738. "feature",
  12739. "feature-state"
  12740. ]
  12741. },
  12742. "property-type": "data-driven"
  12743. },
  12744. "line-offset": {
  12745. type: "number",
  12746. "default": 0,
  12747. transition: true,
  12748. units: "pixels",
  12749. expression: {
  12750. interpolated: true,
  12751. parameters: [
  12752. "zoom",
  12753. "feature",
  12754. "feature-state"
  12755. ]
  12756. },
  12757. "property-type": "data-driven"
  12758. },
  12759. "line-blur": {
  12760. type: "number",
  12761. "default": 0,
  12762. minimum: 0,
  12763. transition: true,
  12764. units: "pixels",
  12765. expression: {
  12766. interpolated: true,
  12767. parameters: [
  12768. "zoom",
  12769. "feature",
  12770. "feature-state"
  12771. ]
  12772. },
  12773. "property-type": "data-driven"
  12774. },
  12775. "line-dasharray": {
  12776. type: "array",
  12777. value: "number",
  12778. minimum: 0,
  12779. transition: true,
  12780. units: "line widths",
  12781. requires: [
  12782. {
  12783. "!": "line-pattern"
  12784. }
  12785. ],
  12786. expression: {
  12787. interpolated: false,
  12788. parameters: [
  12789. "zoom"
  12790. ]
  12791. },
  12792. "property-type": "cross-faded"
  12793. },
  12794. "line-pattern": {
  12795. type: "resolvedImage",
  12796. transition: true,
  12797. expression: {
  12798. interpolated: false,
  12799. parameters: [
  12800. "zoom",
  12801. "feature"
  12802. ]
  12803. },
  12804. "property-type": "cross-faded-data-driven"
  12805. },
  12806. "line-gradient": {
  12807. type: "color",
  12808. transition: false,
  12809. requires: [
  12810. {
  12811. "!": "line-dasharray"
  12812. },
  12813. {
  12814. "!": "line-pattern"
  12815. },
  12816. {
  12817. source: "geojson",
  12818. has: {
  12819. lineMetrics: true
  12820. }
  12821. }
  12822. ],
  12823. expression: {
  12824. interpolated: true,
  12825. parameters: [
  12826. "line-progress"
  12827. ]
  12828. },
  12829. "property-type": "color-ramp"
  12830. }
  12831. };
  12832. var paint_circle = {
  12833. "circle-radius": {
  12834. type: "number",
  12835. "default": 5,
  12836. minimum: 0,
  12837. transition: true,
  12838. units: "pixels",
  12839. expression: {
  12840. interpolated: true,
  12841. parameters: [
  12842. "zoom",
  12843. "feature",
  12844. "feature-state"
  12845. ]
  12846. },
  12847. "property-type": "data-driven"
  12848. },
  12849. "circle-color": {
  12850. type: "color",
  12851. "default": "#000000",
  12852. transition: true,
  12853. expression: {
  12854. interpolated: true,
  12855. parameters: [
  12856. "zoom",
  12857. "feature",
  12858. "feature-state"
  12859. ]
  12860. },
  12861. "property-type": "data-driven"
  12862. },
  12863. "circle-blur": {
  12864. type: "number",
  12865. "default": 0,
  12866. transition: true,
  12867. expression: {
  12868. interpolated: true,
  12869. parameters: [
  12870. "zoom",
  12871. "feature",
  12872. "feature-state"
  12873. ]
  12874. },
  12875. "property-type": "data-driven"
  12876. },
  12877. "circle-opacity": {
  12878. type: "number",
  12879. "default": 1,
  12880. minimum: 0,
  12881. maximum: 1,
  12882. transition: true,
  12883. expression: {
  12884. interpolated: true,
  12885. parameters: [
  12886. "zoom",
  12887. "feature",
  12888. "feature-state"
  12889. ]
  12890. },
  12891. "property-type": "data-driven"
  12892. },
  12893. "circle-translate": {
  12894. type: "array",
  12895. value: "number",
  12896. length: 2,
  12897. "default": [
  12898. 0,
  12899. 0
  12900. ],
  12901. transition: true,
  12902. units: "pixels",
  12903. expression: {
  12904. interpolated: true,
  12905. parameters: [
  12906. "zoom"
  12907. ]
  12908. },
  12909. "property-type": "data-constant"
  12910. },
  12911. "circle-translate-anchor": {
  12912. type: "enum",
  12913. values: {
  12914. map: {
  12915. },
  12916. viewport: {
  12917. }
  12918. },
  12919. "default": "map",
  12920. requires: [
  12921. "circle-translate"
  12922. ],
  12923. expression: {
  12924. interpolated: false,
  12925. parameters: [
  12926. "zoom"
  12927. ]
  12928. },
  12929. "property-type": "data-constant"
  12930. },
  12931. "circle-pitch-scale": {
  12932. type: "enum",
  12933. values: {
  12934. map: {
  12935. },
  12936. viewport: {
  12937. }
  12938. },
  12939. "default": "map",
  12940. expression: {
  12941. interpolated: false,
  12942. parameters: [
  12943. "zoom"
  12944. ]
  12945. },
  12946. "property-type": "data-constant"
  12947. },
  12948. "circle-pitch-alignment": {
  12949. type: "enum",
  12950. values: {
  12951. map: {
  12952. },
  12953. viewport: {
  12954. }
  12955. },
  12956. "default": "viewport",
  12957. expression: {
  12958. interpolated: false,
  12959. parameters: [
  12960. "zoom"
  12961. ]
  12962. },
  12963. "property-type": "data-constant"
  12964. },
  12965. "circle-stroke-width": {
  12966. type: "number",
  12967. "default": 0,
  12968. minimum: 0,
  12969. transition: true,
  12970. units: "pixels",
  12971. expression: {
  12972. interpolated: true,
  12973. parameters: [
  12974. "zoom",
  12975. "feature",
  12976. "feature-state"
  12977. ]
  12978. },
  12979. "property-type": "data-driven"
  12980. },
  12981. "circle-stroke-color": {
  12982. type: "color",
  12983. "default": "#000000",
  12984. transition: true,
  12985. expression: {
  12986. interpolated: true,
  12987. parameters: [
  12988. "zoom",
  12989. "feature",
  12990. "feature-state"
  12991. ]
  12992. },
  12993. "property-type": "data-driven"
  12994. },
  12995. "circle-stroke-opacity": {
  12996. type: "number",
  12997. "default": 1,
  12998. minimum: 0,
  12999. maximum: 1,
  13000. transition: true,
  13001. expression: {
  13002. interpolated: true,
  13003. parameters: [
  13004. "zoom",
  13005. "feature",
  13006. "feature-state"
  13007. ]
  13008. },
  13009. "property-type": "data-driven"
  13010. }
  13011. };
  13012. var paint_heatmap = {
  13013. "heatmap-radius": {
  13014. type: "number",
  13015. "default": 30,
  13016. minimum: 1,
  13017. transition: true,
  13018. units: "pixels",
  13019. expression: {
  13020. interpolated: true,
  13021. parameters: [
  13022. "zoom",
  13023. "feature",
  13024. "feature-state"
  13025. ]
  13026. },
  13027. "property-type": "data-driven"
  13028. },
  13029. "heatmap-weight": {
  13030. type: "number",
  13031. "default": 1,
  13032. minimum: 0,
  13033. transition: false,
  13034. expression: {
  13035. interpolated: true,
  13036. parameters: [
  13037. "zoom",
  13038. "feature",
  13039. "feature-state"
  13040. ]
  13041. },
  13042. "property-type": "data-driven"
  13043. },
  13044. "heatmap-intensity": {
  13045. type: "number",
  13046. "default": 1,
  13047. minimum: 0,
  13048. transition: true,
  13049. expression: {
  13050. interpolated: true,
  13051. parameters: [
  13052. "zoom"
  13053. ]
  13054. },
  13055. "property-type": "data-constant"
  13056. },
  13057. "heatmap-color": {
  13058. type: "color",
  13059. "default": [
  13060. "interpolate",
  13061. [
  13062. "linear"
  13063. ],
  13064. [
  13065. "heatmap-density"
  13066. ],
  13067. 0,
  13068. "rgba(0, 0, 255, 0)",
  13069. 0.1,
  13070. "royalblue",
  13071. 0.3,
  13072. "cyan",
  13073. 0.5,
  13074. "lime",
  13075. 0.7,
  13076. "yellow",
  13077. 1,
  13078. "red"
  13079. ],
  13080. transition: false,
  13081. expression: {
  13082. interpolated: true,
  13083. parameters: [
  13084. "heatmap-density"
  13085. ]
  13086. },
  13087. "property-type": "color-ramp"
  13088. },
  13089. "heatmap-opacity": {
  13090. type: "number",
  13091. "default": 1,
  13092. minimum: 0,
  13093. maximum: 1,
  13094. transition: true,
  13095. expression: {
  13096. interpolated: true,
  13097. parameters: [
  13098. "zoom"
  13099. ]
  13100. },
  13101. "property-type": "data-constant"
  13102. }
  13103. };
  13104. var paint_symbol = {
  13105. "icon-opacity": {
  13106. type: "number",
  13107. "default": 1,
  13108. minimum: 0,
  13109. maximum: 1,
  13110. transition: true,
  13111. requires: [
  13112. "icon-image"
  13113. ],
  13114. expression: {
  13115. interpolated: true,
  13116. parameters: [
  13117. "zoom",
  13118. "feature",
  13119. "feature-state"
  13120. ]
  13121. },
  13122. "property-type": "data-driven"
  13123. },
  13124. "icon-color": {
  13125. type: "color",
  13126. "default": "#000000",
  13127. transition: true,
  13128. requires: [
  13129. "icon-image"
  13130. ],
  13131. expression: {
  13132. interpolated: true,
  13133. parameters: [
  13134. "zoom",
  13135. "feature",
  13136. "feature-state"
  13137. ]
  13138. },
  13139. "property-type": "data-driven"
  13140. },
  13141. "icon-halo-color": {
  13142. type: "color",
  13143. "default": "rgba(0, 0, 0, 0)",
  13144. transition: true,
  13145. requires: [
  13146. "icon-image"
  13147. ],
  13148. expression: {
  13149. interpolated: true,
  13150. parameters: [
  13151. "zoom",
  13152. "feature",
  13153. "feature-state"
  13154. ]
  13155. },
  13156. "property-type": "data-driven"
  13157. },
  13158. "icon-halo-width": {
  13159. type: "number",
  13160. "default": 0,
  13161. minimum: 0,
  13162. transition: true,
  13163. units: "pixels",
  13164. requires: [
  13165. "icon-image"
  13166. ],
  13167. expression: {
  13168. interpolated: true,
  13169. parameters: [
  13170. "zoom",
  13171. "feature",
  13172. "feature-state"
  13173. ]
  13174. },
  13175. "property-type": "data-driven"
  13176. },
  13177. "icon-halo-blur": {
  13178. type: "number",
  13179. "default": 0,
  13180. minimum: 0,
  13181. transition: true,
  13182. units: "pixels",
  13183. requires: [
  13184. "icon-image"
  13185. ],
  13186. expression: {
  13187. interpolated: true,
  13188. parameters: [
  13189. "zoom",
  13190. "feature",
  13191. "feature-state"
  13192. ]
  13193. },
  13194. "property-type": "data-driven"
  13195. },
  13196. "icon-translate": {
  13197. type: "array",
  13198. value: "number",
  13199. length: 2,
  13200. "default": [
  13201. 0,
  13202. 0
  13203. ],
  13204. transition: true,
  13205. units: "pixels",
  13206. requires: [
  13207. "icon-image"
  13208. ],
  13209. expression: {
  13210. interpolated: true,
  13211. parameters: [
  13212. "zoom"
  13213. ]
  13214. },
  13215. "property-type": "data-constant"
  13216. },
  13217. "icon-translate-anchor": {
  13218. type: "enum",
  13219. values: {
  13220. map: {
  13221. },
  13222. viewport: {
  13223. }
  13224. },
  13225. "default": "map",
  13226. requires: [
  13227. "icon-image",
  13228. "icon-translate"
  13229. ],
  13230. expression: {
  13231. interpolated: false,
  13232. parameters: [
  13233. "zoom"
  13234. ]
  13235. },
  13236. "property-type": "data-constant"
  13237. },
  13238. "text-opacity": {
  13239. type: "number",
  13240. "default": 1,
  13241. minimum: 0,
  13242. maximum: 1,
  13243. transition: true,
  13244. requires: [
  13245. "text-field"
  13246. ],
  13247. expression: {
  13248. interpolated: true,
  13249. parameters: [
  13250. "zoom",
  13251. "feature",
  13252. "feature-state"
  13253. ]
  13254. },
  13255. "property-type": "data-driven"
  13256. },
  13257. "text-color": {
  13258. type: "color",
  13259. "default": "#000000",
  13260. transition: true,
  13261. overridable: true,
  13262. requires: [
  13263. "text-field"
  13264. ],
  13265. expression: {
  13266. interpolated: true,
  13267. parameters: [
  13268. "zoom",
  13269. "feature",
  13270. "feature-state"
  13271. ]
  13272. },
  13273. "property-type": "data-driven"
  13274. },
  13275. "text-halo-color": {
  13276. type: "color",
  13277. "default": "rgba(0, 0, 0, 0)",
  13278. transition: true,
  13279. requires: [
  13280. "text-field"
  13281. ],
  13282. expression: {
  13283. interpolated: true,
  13284. parameters: [
  13285. "zoom",
  13286. "feature",
  13287. "feature-state"
  13288. ]
  13289. },
  13290. "property-type": "data-driven"
  13291. },
  13292. "text-halo-width": {
  13293. type: "number",
  13294. "default": 0,
  13295. minimum: 0,
  13296. transition: true,
  13297. units: "pixels",
  13298. requires: [
  13299. "text-field"
  13300. ],
  13301. expression: {
  13302. interpolated: true,
  13303. parameters: [
  13304. "zoom",
  13305. "feature",
  13306. "feature-state"
  13307. ]
  13308. },
  13309. "property-type": "data-driven"
  13310. },
  13311. "text-show-background": {
  13312. type: "boolean",
  13313. "default": false,
  13314. transition: false,
  13315. expression: {
  13316. interpolated: false,
  13317. parameters: [
  13318. "zoom"
  13319. ]
  13320. },
  13321. "property-type": "data-constant"
  13322. },
  13323. "text-halo-blur": {
  13324. type: "number",
  13325. "default": 0,
  13326. minimum: 0,
  13327. transition: true,
  13328. units: "pixels",
  13329. requires: [
  13330. "text-field"
  13331. ],
  13332. expression: {
  13333. interpolated: true,
  13334. parameters: [
  13335. "zoom",
  13336. "feature",
  13337. "feature-state"
  13338. ]
  13339. },
  13340. "property-type": "data-driven"
  13341. },
  13342. "text-translate": {
  13343. type: "array",
  13344. value: "number",
  13345. length: 2,
  13346. "default": [
  13347. 0,
  13348. 0
  13349. ],
  13350. transition: true,
  13351. units: "pixels",
  13352. requires: [
  13353. "text-field"
  13354. ],
  13355. expression: {
  13356. interpolated: true,
  13357. parameters: [
  13358. "zoom"
  13359. ]
  13360. },
  13361. "property-type": "data-constant"
  13362. },
  13363. "text-translate-anchor": {
  13364. type: "enum",
  13365. values: {
  13366. map: {
  13367. },
  13368. viewport: {
  13369. }
  13370. },
  13371. "default": "map",
  13372. requires: [
  13373. "text-field",
  13374. "text-translate"
  13375. ],
  13376. expression: {
  13377. interpolated: false,
  13378. parameters: [
  13379. "zoom"
  13380. ]
  13381. },
  13382. "property-type": "data-constant"
  13383. }
  13384. };
  13385. var paint_raster = {
  13386. "raster-opacity": {
  13387. type: "number",
  13388. "default": 1,
  13389. minimum: 0,
  13390. maximum: 1,
  13391. transition: true,
  13392. expression: {
  13393. interpolated: true,
  13394. parameters: [
  13395. "zoom"
  13396. ]
  13397. },
  13398. "property-type": "data-constant"
  13399. },
  13400. "raster-hue-rotate": {
  13401. type: "number",
  13402. "default": 0,
  13403. period: 360,
  13404. transition: true,
  13405. units: "degrees",
  13406. expression: {
  13407. interpolated: true,
  13408. parameters: [
  13409. "zoom"
  13410. ]
  13411. },
  13412. "property-type": "data-constant"
  13413. },
  13414. "raster-brightness-min": {
  13415. type: "number",
  13416. "default": 0,
  13417. minimum: 0,
  13418. maximum: 1,
  13419. transition: true,
  13420. expression: {
  13421. interpolated: true,
  13422. parameters: [
  13423. "zoom"
  13424. ]
  13425. },
  13426. "property-type": "data-constant"
  13427. },
  13428. "raster-brightness-max": {
  13429. type: "number",
  13430. "default": 1,
  13431. minimum: 0,
  13432. maximum: 1,
  13433. transition: true,
  13434. expression: {
  13435. interpolated: true,
  13436. parameters: [
  13437. "zoom"
  13438. ]
  13439. },
  13440. "property-type": "data-constant"
  13441. },
  13442. "raster-saturation": {
  13443. type: "number",
  13444. "default": 0,
  13445. minimum: -1,
  13446. maximum: 1,
  13447. transition: true,
  13448. expression: {
  13449. interpolated: true,
  13450. parameters: [
  13451. "zoom"
  13452. ]
  13453. },
  13454. "property-type": "data-constant"
  13455. },
  13456. "raster-contrast": {
  13457. type: "number",
  13458. "default": 0,
  13459. minimum: -1,
  13460. maximum: 1,
  13461. transition: true,
  13462. expression: {
  13463. interpolated: true,
  13464. parameters: [
  13465. "zoom"
  13466. ]
  13467. },
  13468. "property-type": "data-constant"
  13469. },
  13470. "raster-resampling": {
  13471. type: "enum",
  13472. values: {
  13473. linear: {
  13474. },
  13475. nearest: {
  13476. }
  13477. },
  13478. "default": "linear",
  13479. expression: {
  13480. interpolated: false,
  13481. parameters: [
  13482. "zoom"
  13483. ]
  13484. },
  13485. "property-type": "data-constant"
  13486. },
  13487. "raster-fade-duration": {
  13488. type: "number",
  13489. "default": 300,
  13490. minimum: 0,
  13491. transition: false,
  13492. units: "milliseconds",
  13493. expression: {
  13494. interpolated: true,
  13495. parameters: [
  13496. "zoom"
  13497. ]
  13498. },
  13499. "property-type": "data-constant"
  13500. }
  13501. };
  13502. var paint_hillshade = {
  13503. "hillshade-illumination-direction": {
  13504. type: "number",
  13505. "default": 335,
  13506. minimum: 0,
  13507. maximum: 359,
  13508. transition: false,
  13509. expression: {
  13510. interpolated: true,
  13511. parameters: [
  13512. "zoom"
  13513. ]
  13514. },
  13515. "property-type": "data-constant"
  13516. },
  13517. "hillshade-illumination-anchor": {
  13518. type: "enum",
  13519. values: {
  13520. map: {
  13521. },
  13522. viewport: {
  13523. }
  13524. },
  13525. "default": "viewport",
  13526. expression: {
  13527. interpolated: false,
  13528. parameters: [
  13529. "zoom"
  13530. ]
  13531. },
  13532. "property-type": "data-constant"
  13533. },
  13534. "hillshade-exaggeration": {
  13535. type: "number",
  13536. "default": 0.5,
  13537. minimum: 0,
  13538. maximum: 1,
  13539. transition: true,
  13540. expression: {
  13541. interpolated: true,
  13542. parameters: [
  13543. "zoom"
  13544. ]
  13545. },
  13546. "property-type": "data-constant"
  13547. },
  13548. "hillshade-shadow-color": {
  13549. type: "color",
  13550. "default": "#000000",
  13551. transition: true,
  13552. expression: {
  13553. interpolated: true,
  13554. parameters: [
  13555. "zoom"
  13556. ]
  13557. },
  13558. "property-type": "data-constant"
  13559. },
  13560. "hillshade-highlight-color": {
  13561. type: "color",
  13562. "default": "#FFFFFF",
  13563. transition: true,
  13564. expression: {
  13565. interpolated: true,
  13566. parameters: [
  13567. "zoom"
  13568. ]
  13569. },
  13570. "property-type": "data-constant"
  13571. },
  13572. "hillshade-accent-color": {
  13573. type: "color",
  13574. "default": "#000000",
  13575. transition: true,
  13576. expression: {
  13577. interpolated: true,
  13578. parameters: [
  13579. "zoom"
  13580. ]
  13581. },
  13582. "property-type": "data-constant"
  13583. }
  13584. };
  13585. var paint_background = {
  13586. "background-color": {
  13587. type: "color",
  13588. "default": "#000000",
  13589. transition: true,
  13590. requires: [
  13591. {
  13592. "!": "background-pattern"
  13593. }
  13594. ],
  13595. expression: {
  13596. interpolated: true,
  13597. parameters: [
  13598. "zoom"
  13599. ]
  13600. },
  13601. "property-type": "data-constant"
  13602. },
  13603. "background-pattern": {
  13604. type: "resolvedImage",
  13605. transition: true,
  13606. expression: {
  13607. interpolated: false,
  13608. parameters: [
  13609. "zoom"
  13610. ]
  13611. },
  13612. "property-type": "cross-faded"
  13613. },
  13614. "background-opacity": {
  13615. type: "number",
  13616. "default": 1,
  13617. minimum: 0,
  13618. maximum: 1,
  13619. transition: true,
  13620. expression: {
  13621. interpolated: true,
  13622. parameters: [
  13623. "zoom"
  13624. ]
  13625. },
  13626. "property-type": "data-constant"
  13627. }
  13628. };
  13629. var transition = {
  13630. duration: {
  13631. type: "number",
  13632. "default": 300,
  13633. minimum: 0,
  13634. units: "milliseconds"
  13635. },
  13636. delay: {
  13637. type: "number",
  13638. "default": 0,
  13639. minimum: 0,
  13640. units: "milliseconds"
  13641. }
  13642. };
  13643. var StyleSpec = {
  13644. $version: $version,
  13645. $root: $root,
  13646. sources: sources,
  13647. source: source,
  13648. source_vector: source_vector,
  13649. source_raster: source_raster,
  13650. source_raster_dem: source_raster_dem,
  13651. source_geojson: source_geojson,
  13652. source_video: source_video,
  13653. source_image: source_image,
  13654. layer: layer,
  13655. layout: layout,
  13656. layout_background: layout_background,
  13657. layout_fill: layout_fill,
  13658. layout_circle: layout_circle,
  13659. layout_heatmap: layout_heatmap,
  13660. "layout_fill-extrusion": {
  13661. visibility: {
  13662. type: "enum",
  13663. values: {
  13664. visible: {
  13665. },
  13666. none: {
  13667. }
  13668. },
  13669. "default": "visible",
  13670. "property-type": "constant"
  13671. }
  13672. },
  13673. layout_line: layout_line,
  13674. layout_symbol: layout_symbol,
  13675. layout_raster: layout_raster,
  13676. layout_hillshade: layout_hillshade,
  13677. filter: filter,
  13678. filter_operator: filter_operator,
  13679. geometry_type: geometry_type,
  13680. "function": {
  13681. expression: {
  13682. type: "expression"
  13683. },
  13684. stops: {
  13685. type: "array",
  13686. value: "function_stop"
  13687. },
  13688. base: {
  13689. type: "number",
  13690. "default": 1,
  13691. minimum: 0
  13692. },
  13693. property: {
  13694. type: "string",
  13695. "default": "$zoom"
  13696. },
  13697. type: {
  13698. type: "enum",
  13699. values: {
  13700. identity: {
  13701. },
  13702. exponential: {
  13703. },
  13704. interval: {
  13705. },
  13706. categorical: {
  13707. }
  13708. },
  13709. "default": "exponential"
  13710. },
  13711. colorSpace: {
  13712. type: "enum",
  13713. values: {
  13714. rgb: {
  13715. },
  13716. lab: {
  13717. },
  13718. hcl: {
  13719. }
  13720. },
  13721. "default": "rgb"
  13722. },
  13723. "default": {
  13724. type: "*",
  13725. required: false
  13726. }
  13727. },
  13728. function_stop: function_stop,
  13729. expression: expression,
  13730. expression_name: expression_name,
  13731. light: light,
  13732. paint: paint,
  13733. paint_fill: paint_fill,
  13734. "paint_fill-extrusion": {
  13735. "fill-extrusion-opacity": {
  13736. type: "number",
  13737. "default": 1,
  13738. minimum: 0,
  13739. maximum: 1,
  13740. transition: true,
  13741. expression: {
  13742. interpolated: true,
  13743. parameters: [
  13744. "zoom"
  13745. ]
  13746. },
  13747. "property-type": "data-constant"
  13748. },
  13749. "fill-extrusion-color": {
  13750. type: "color",
  13751. "default": "#000000",
  13752. transition: true,
  13753. requires: [
  13754. {
  13755. "!": "fill-extrusion-pattern"
  13756. }
  13757. ],
  13758. expression: {
  13759. interpolated: true,
  13760. parameters: [
  13761. "zoom",
  13762. "feature",
  13763. "feature-state"
  13764. ]
  13765. },
  13766. "property-type": "data-driven"
  13767. },
  13768. "fill-extrusion-translate": {
  13769. type: "array",
  13770. value: "number",
  13771. length: 2,
  13772. "default": [
  13773. 0,
  13774. 0
  13775. ],
  13776. transition: true,
  13777. units: "pixels",
  13778. expression: {
  13779. interpolated: true,
  13780. parameters: [
  13781. "zoom"
  13782. ]
  13783. },
  13784. "property-type": "data-constant"
  13785. },
  13786. "fill-extrusion-translate-anchor": {
  13787. type: "enum",
  13788. values: {
  13789. map: {
  13790. },
  13791. viewport: {
  13792. }
  13793. },
  13794. "default": "map",
  13795. requires: [
  13796. "fill-extrusion-translate"
  13797. ],
  13798. expression: {
  13799. interpolated: false,
  13800. parameters: [
  13801. "zoom"
  13802. ]
  13803. },
  13804. "property-type": "data-constant"
  13805. },
  13806. "fill-extrusion-pattern": {
  13807. type: "resolvedImage",
  13808. transition: true,
  13809. expression: {
  13810. interpolated: false,
  13811. parameters: [
  13812. "zoom",
  13813. "feature"
  13814. ]
  13815. },
  13816. "property-type": "cross-faded-data-driven"
  13817. },
  13818. "fill-extrusion-height": {
  13819. type: "number",
  13820. "default": 0,
  13821. minimum: 0,
  13822. units: "meters",
  13823. transition: true,
  13824. expression: {
  13825. interpolated: true,
  13826. parameters: [
  13827. "zoom",
  13828. "feature",
  13829. "feature-state"
  13830. ]
  13831. },
  13832. "property-type": "data-driven"
  13833. },
  13834. "fill-extrusion-base": {
  13835. type: "number",
  13836. "default": 0,
  13837. minimum: 0,
  13838. units: "meters",
  13839. transition: true,
  13840. requires: [
  13841. "fill-extrusion-height"
  13842. ],
  13843. expression: {
  13844. interpolated: true,
  13845. parameters: [
  13846. "zoom",
  13847. "feature",
  13848. "feature-state"
  13849. ]
  13850. },
  13851. "property-type": "data-driven"
  13852. },
  13853. "fill-extrusion-vertical-gradient": {
  13854. type: "boolean",
  13855. "default": true,
  13856. transition: false,
  13857. expression: {
  13858. interpolated: false,
  13859. parameters: [
  13860. "zoom"
  13861. ]
  13862. },
  13863. "property-type": "data-constant"
  13864. }
  13865. },
  13866. paint_line: paint_line,
  13867. paint_circle: paint_circle,
  13868. paint_heatmap: paint_heatmap,
  13869. paint_symbol: paint_symbol,
  13870. paint_raster: paint_raster,
  13871. paint_hillshade: paint_hillshade,
  13872. paint_background: paint_background,
  13873. transition: transition,
  13874. "property-type": {
  13875. "data-driven": {
  13876. type: "property-type"
  13877. },
  13878. "cross-faded": {
  13879. type: "property-type"
  13880. },
  13881. "cross-faded-data-driven": {
  13882. type: "property-type"
  13883. },
  13884. "color-ramp": {
  13885. type: "property-type"
  13886. },
  13887. "data-constant": {
  13888. type: "property-type"
  13889. },
  13890. constant: {
  13891. type: "property-type"
  13892. }
  13893. }
  13894. };
  13895. function IntersectionTest() {
  13896. }
  13897. IntersectionTest.polygonIntersectsPolygon = function (polygonA, polygonB) {
  13898. for (var i = 0; i < polygonA.length; i++) {
  13899. if (polygonContainsPoint(polygonB, polygonA[i])) {
  13900. return true;
  13901. }
  13902. }
  13903. for (var i$1 = 0; i$1 < polygonB.length; i$1++) {
  13904. if (polygonContainsPoint(polygonA, polygonB[i$1])) {
  13905. return true;
  13906. }
  13907. }
  13908. if (lineIntersectsLine(polygonA, polygonB)) {
  13909. return true;
  13910. }
  13911. return false;
  13912. };
  13913. IntersectionTest.polygonIntersectsBufferedPoint = function (polygon, point, radius) {
  13914. if (polygonContainsPoint(polygon, point)) {
  13915. return true;
  13916. }
  13917. if (pointIntersectsBufferedLine(point, polygon, radius)) {
  13918. return true;
  13919. }
  13920. return false;
  13921. };
  13922. IntersectionTest.polygonIntersectsMultiPolygon = function (polygon, multiPolygon) {
  13923. if (polygon.length === 1) {
  13924. return multiPolygonContainsPoint(multiPolygon, polygon[0]);
  13925. }
  13926. for (var m = 0; m < multiPolygon.length; m++) {
  13927. var ring = multiPolygon[m];
  13928. for (var n = 0; n < ring.length; n++) {
  13929. if (polygonContainsPoint(polygon, ring[n])) {
  13930. return true;
  13931. }
  13932. }
  13933. }
  13934. for (var i = 0; i < polygon.length; i++) {
  13935. if (multiPolygonContainsPoint(multiPolygon, polygon[i])) {
  13936. return true;
  13937. }
  13938. }
  13939. for (var k = 0; k < multiPolygon.length; k++) {
  13940. if (lineIntersectsLine(polygon, multiPolygon[k])) {
  13941. return true;
  13942. }
  13943. }
  13944. return false;
  13945. };
  13946. IntersectionTest.polygonIntersectsBufferedMultiLine = function (polygon, multiLine, radius) {
  13947. for (var i = 0; i < multiLine.length; i++) {
  13948. var line = multiLine[i];
  13949. if (polygon.length >= 3) {
  13950. for (var k = 0; k < line.length; k++) {
  13951. if (polygonContainsPoint(polygon, line[k])) {
  13952. return true;
  13953. }
  13954. }
  13955. }
  13956. if (lineIntersectsBufferedLine(polygon, line, radius)) {
  13957. return true;
  13958. }
  13959. }
  13960. return false;
  13961. };
  13962. function lineIntersectsBufferedLine(lineA, lineB, radius) {
  13963. if (lineA.length > 1) {
  13964. if (lineIntersectsLine(lineA, lineB)) {
  13965. return true;
  13966. }
  13967. // Check whether any point in either line is within radius of the other line
  13968. for (var j = 0; j < lineB.length; j++) {
  13969. if (pointIntersectsBufferedLine(lineB[j], lineA, radius)) {
  13970. return true;
  13971. }
  13972. }
  13973. }
  13974. for (var k = 0; k < lineA.length; k++) {
  13975. if (pointIntersectsBufferedLine(lineA[k], lineB, radius)) {
  13976. return true;
  13977. }
  13978. }
  13979. return false;
  13980. }
  13981. function lineIntersectsLine(lineA, lineB) {
  13982. if (lineA.length === 0 || lineB.length === 0) {
  13983. return false;
  13984. }
  13985. for (var i = 0; i < lineA.length - 1; i++) {
  13986. var a0 = lineA[i];
  13987. var a1 = lineA[i + 1];
  13988. for (var j = 0; j < lineB.length - 1; j++) {
  13989. var b0 = lineB[j];
  13990. var b1 = lineB[j + 1];
  13991. if (lineSegmentIntersectsLineSegment(a0, a1, b0, b1)) {
  13992. return true;
  13993. }
  13994. }
  13995. }
  13996. return false;
  13997. }
  13998. function lineSegmentIntersectsLineSegment(a0, a1, b0, b1) {
  13999. return Util.isCounterClockwise(a0, b0, b1) !== Util.isCounterClockwise(a1, b0, b1) &&
  14000. Util.isCounterClockwise(a0, a1, b0) !== Util.isCounterClockwise(a0, a1, b1);
  14001. }
  14002. function pointIntersectsBufferedLine(p, line, radius) {
  14003. var radiusSquared = radius * radius;
  14004. if (line.length === 1) {
  14005. return p.distSqr(line[0]) < radiusSquared;
  14006. }
  14007. for (var i = 1; i < line.length; i++) {
  14008. // Find line segments that have a distance <= radius^2 to p
  14009. // In that case, we treat the line as "containing point p".
  14010. var v = line[i - 1], w = line[i];
  14011. if (IntersectionTest.distToSegmentSquared(p, v, w) < radiusSquared) {
  14012. return true;
  14013. }
  14014. }
  14015. return false;
  14016. }
  14017. // Code from http://stackoverflow.com/a/1501725/331379.
  14018. IntersectionTest.distToSegmentSquared = function (p, v, w) {
  14019. var l2 = v.distSqr(w);
  14020. if (l2 === 0) {
  14021. return p.distSqr(v);
  14022. }
  14023. var t = ((p.x - v.x) * (w.x - v.x) + (p.y - v.y) * (w.y - v.y)) / l2;
  14024. if (t < 0) {
  14025. return p.distSqr(v);
  14026. }
  14027. if (t > 1) {
  14028. return p.distSqr(w);
  14029. }
  14030. return p.distSqr(w.sub(v)._mult(t)._add(v));
  14031. };
  14032. // point in polygon ray casting algorithm
  14033. function multiPolygonContainsPoint(rings, p) {
  14034. var c = false,
  14035. ring, p1, p2;
  14036. for (var k = 0; k < rings.length; k++) {
  14037. ring = rings[k];
  14038. for (var i = 0, j = ring.length - 1; i < ring.length; j = i++) {
  14039. p1 = ring[i];
  14040. p2 = ring[j];
  14041. 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)) {
  14042. c = !c;
  14043. }
  14044. }
  14045. }
  14046. return c;
  14047. }
  14048. function polygonContainsPoint(ring, p) {
  14049. var c = false;
  14050. for (var i = 0, j = ring.length - 1; i < ring.length; j = i++) {
  14051. var p1 = ring[i];
  14052. var p2 = ring[j];
  14053. 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)) {
  14054. c = !c;
  14055. }
  14056. }
  14057. return c;
  14058. }
  14059. var layout$2 = new Properties({
  14060. "circle-sort-key": new DataDrivenProperty(StyleSpec["layout_circle"]["circle-sort-key"])
  14061. });
  14062. var paint$1 = new Properties({
  14063. "circle-radius": new DataDrivenProperty(StyleSpec["paint_circle"]["circle-radius"]),
  14064. "circle-color": new DataDrivenProperty(StyleSpec["paint_circle"]["circle-color"]),
  14065. "circle-blur": new DataDrivenProperty(StyleSpec["paint_circle"]["circle-blur"]),
  14066. "circle-opacity": new DataDrivenProperty(StyleSpec["paint_circle"]["circle-opacity"]),
  14067. "circle-translate": new DataConstantProperty(StyleSpec["paint_circle"]["circle-translate"]),
  14068. "circle-translate-anchor": new DataConstantProperty(StyleSpec["paint_circle"]["circle-translate-anchor"]),
  14069. "circle-pitch-scale": new DataConstantProperty(StyleSpec["paint_circle"]["circle-pitch-scale"]),
  14070. "circle-pitch-alignment": new DataConstantProperty(StyleSpec["paint_circle"]["circle-pitch-alignment"]),
  14071. "circle-stroke-width": new DataDrivenProperty(StyleSpec["paint_circle"]["circle-stroke-width"]),
  14072. "circle-stroke-color": new DataDrivenProperty(StyleSpec["paint_circle"]["circle-stroke-color"]),
  14073. "circle-stroke-opacity": new DataDrivenProperty(StyleSpec["paint_circle"]["circle-stroke-opacity"])
  14074. });
  14075. // Note: without adding the explicit type annotation, Flow infers weaker types
  14076. // for these objects from their use in the constructor to StyleLayer, as
  14077. // {layout?: Properties<...>, paint: Properties<...>}
  14078. var properties = ({ paint: paint$1, layout: layout$2 });
  14079. var CircleStyleLayer = /*@__PURE__*/(function (StyleLayer) {
  14080. function CircleStyleLayer(layer) {
  14081. StyleLayer.call(this, layer, properties);
  14082. }
  14083. if (StyleLayer) CircleStyleLayer.__proto__ = StyleLayer;
  14084. CircleStyleLayer.prototype = Object.create(StyleLayer && StyleLayer.prototype);
  14085. CircleStyleLayer.prototype.constructor = CircleStyleLayer;
  14086. CircleStyleLayer.prototype.createBucket = function createBucket(parameters) {
  14087. return new CircleBucket(parameters);
  14088. };
  14089. CircleStyleLayer.prototype.queryRadius = function queryRadius(bucket) {
  14090. var circleBucket = (bucket );
  14091. return QueryUtils.getMaximumPaintValue('circle-radius', this, circleBucket) +
  14092. QueryUtils.getMaximumPaintValue('circle-stroke-width', this, circleBucket) +
  14093. QueryUtils.translateDistance(this.paint.get('circle-translate'));
  14094. };
  14095. CircleStyleLayer.prototype.queryIntersectsFeature = function queryIntersectsFeature(queryGeometry, feature, featureState, geometry, zoom, transform, pixelsToTileUnits, pixelPosMatrix, adjustedScale) {
  14096. pixelPosMatrix = createMat4();
  14097. var translatedPolygon = QueryUtils.translate(queryGeometry,
  14098. this.paint.get('circle-translate'),
  14099. this.paint.get('circle-translate-anchor'),
  14100. 0, pixelsToTileUnits);
  14101. var radius = this.paint.get('circle-radius').evaluate(feature, featureState);
  14102. var stroke = this.paint.get('circle-stroke-width').evaluate(feature, featureState);
  14103. var size = radius + stroke;
  14104. // For pitch-alignment: map, compare feature geometry to query geometry in the plane of the tile
  14105. // // Otherwise, compare geometry in the plane of the viewport
  14106. // // A circle with fixed scaling relative to the viewport gets larger in tile space as it moves into the distance
  14107. // // A circle with fixed scaling relative to the map gets smaller in viewport space as it moves into the distance
  14108. var alignWithMap = this.paint.get('circle-pitch-alignment') === 'map';
  14109. var transformedPolygon = alignWithMap ? translatedPolygon : projectQueryGeometry(translatedPolygon, pixelPosMatrix);
  14110. var transformedSize = alignWithMap ? size * pixelsToTileUnits : size;
  14111. for (var i$1 = 0, list$1 = geometry; i$1 < list$1.length; i$1 += 1) {
  14112. var ring = list$1[i$1];
  14113. for (var i = 0, list = ring; i < list.length; i += 1) {
  14114. var point = list[i];
  14115. var transformedPoint = alignWithMap ? point : projectPoint(point, pixelPosMatrix);
  14116. var adjustedSize = transformedSize;
  14117. var projectedCenter = transformMat4([], [point.x, point.y, 0, 1], pixelPosMatrix);
  14118. 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') ;
  14119. adjustedScale = when.defined(adjustedScale) ? adjustedScale : 10.0;
  14120. if (IntersectionTest.polygonIntersectsBufferedPoint(transformedPolygon, transformedPoint, adjustedSize * adjustedScale)) {
  14121. return true;
  14122. }
  14123. }
  14124. }
  14125. return false;
  14126. };
  14127. return CircleStyleLayer;
  14128. }(StyleLayer));
  14129. function projectPoint(p, pixelPosMatrix) {
  14130. var point = transformMat4([], [p.x, p.y, 0, 1], pixelPosMatrix);
  14131. //return new pointGeometry(point[0] / point[3], point[1] / point[3]);
  14132. return new Point(point[0], point[1]);
  14133. }
  14134. function projectQueryGeometry(queryGeometry, pixelPosMatrix) {
  14135. return queryGeometry.map(function (p) {
  14136. return projectPoint(p, pixelPosMatrix);
  14137. });
  14138. }
  14139. function createMat4() {
  14140. var out = new Float32Array(16);
  14141. out[0] = 1;
  14142. out[5] = 1;
  14143. out[10] = 1;
  14144. out[15] = 1;
  14145. return out;
  14146. }
  14147. /**
  14148. * Transforms the vec3 with a mat4.
  14149. * 4th vector component is implicitly '1'
  14150. *
  14151. * @param {vec3} out the receiving vector
  14152. * @param {vec3} a the vector to transform
  14153. * @param {mat4} m matrix to transform with
  14154. * @returns {vec3} out
  14155. */
  14156. function transformMat4(out, a, m) {
  14157. var x = a[0],
  14158. y = a[1],
  14159. z = a[2];
  14160. var w = m[3] * x + m[7] * y + m[11] * z + m[15];
  14161. w = w || 1.0;
  14162. out[0] = (m[0] * x + m[4] * y + m[8] * z + m[12]) / w;
  14163. out[1] = (m[1] * x + m[5] * y + m[9] * z + m[13]) / w;
  14164. out[2] = (m[2] * x + m[6] * y + m[10] * z + m[14]) / w;
  14165. return out;
  14166. }
  14167. /**
  14168. * An implementation of `Property` for data driven `line-pattern` which are transitioned by cross-fading
  14169. * rather than interpolation.
  14170. *
  14171. * @private
  14172. */
  14173. var CrossFadedDataDrivenProperty = /*@__PURE__*/(function (DataDrivenProperty) {
  14174. function CrossFadedDataDrivenProperty() {
  14175. DataDrivenProperty.apply(this, arguments);
  14176. }
  14177. if (DataDrivenProperty) CrossFadedDataDrivenProperty.__proto__ = DataDrivenProperty;
  14178. CrossFadedDataDrivenProperty.prototype = Object.create(DataDrivenProperty && DataDrivenProperty.prototype);
  14179. CrossFadedDataDrivenProperty.prototype.constructor = CrossFadedDataDrivenProperty;
  14180. CrossFadedDataDrivenProperty.prototype.possiblyEvaluate = function possiblyEvaluate(value, parameters, availableImages) {
  14181. if (value.value === undefined) {
  14182. return new PossiblyEvaluatedPropertyValue$1(this, {kind: 'constant', value: undefined}, parameters);
  14183. } else if (value.expression.kind === 'constant') {
  14184. var evaluatedValue = value.expression.evaluate(parameters, (null ), {}, availableImages);
  14185. var isImageExpression = value.property.specification.type === 'resolvedImage';
  14186. var constantValue = isImageExpression && typeof evaluatedValue !== 'string' ? evaluatedValue.name : evaluatedValue;
  14187. var constant = this._calculate(constantValue, constantValue, constantValue, parameters);
  14188. return new PossiblyEvaluatedPropertyValue$1(this, {kind: 'constant', value: constant}, parameters);
  14189. } else if (value.expression.kind === 'camera') {
  14190. var cameraVal = this._calculate(
  14191. value.expression.evaluate({zoom: parameters.zoom - 1.0}),
  14192. value.expression.evaluate({zoom: parameters.zoom}),
  14193. value.expression.evaluate({zoom: parameters.zoom + 1.0}),
  14194. parameters);
  14195. return new PossiblyEvaluatedPropertyValue$1(this, {kind: 'constant', value: cameraVal}, parameters);
  14196. } else {
  14197. // source or composite expression
  14198. return new PossiblyEvaluatedPropertyValue$1(this, value.expression, parameters);
  14199. }
  14200. };
  14201. CrossFadedDataDrivenProperty.prototype.evaluate = function evaluate(value, globals, feature, featureState, availableImages) {
  14202. if (value.kind === 'source') {
  14203. var constant = value.evaluate(globals, feature, featureState, availableImages);
  14204. return this._calculate(constant, constant, constant, globals);
  14205. } else if (value.kind === 'composite') {
  14206. return this._calculate(
  14207. value.evaluate({zoom: Math.floor(globals.zoom) - 1.0}, feature, featureState),
  14208. value.evaluate({zoom: Math.floor(globals.zoom)}, feature, featureState),
  14209. value.evaluate({zoom: Math.floor(globals.zoom) + 1.0}, feature, featureState),
  14210. globals);
  14211. } else {
  14212. return value.value;
  14213. }
  14214. };
  14215. CrossFadedDataDrivenProperty.prototype._calculate = function _calculate(min, mid, max, parameters) {
  14216. var z = parameters.zoom;
  14217. return z > parameters.zoomHistory.lastIntegerZoom ? {from: min, to: mid} : {from: max, to: mid};
  14218. };
  14219. CrossFadedDataDrivenProperty.prototype.interpolate = function interpolate(a) {
  14220. return a;
  14221. };
  14222. return CrossFadedDataDrivenProperty;
  14223. }(DataDrivenProperty));
  14224. WebWorkerTransfer.register('DataDrivenProperty', DataDrivenProperty);
  14225. var layout$4 = new Properties({
  14226. "fill-sort-key": new DataDrivenProperty(StyleSpec["layout_fill"]["fill-sort-key"])
  14227. });
  14228. var paint$4 = new Properties({
  14229. "fill-antialias": new DataConstantProperty(StyleSpec["paint_fill"]["fill-antialias"]),
  14230. "fill-opacity": new DataDrivenProperty(StyleSpec["paint_fill"]["fill-opacity"]),
  14231. "fill-color": new DataDrivenProperty(StyleSpec["paint_fill"]["fill-color"]),
  14232. "fill-outline-color": new DataDrivenProperty(StyleSpec["paint_fill"]["fill-outline-color"]),
  14233. "fill-translate": new DataConstantProperty(StyleSpec["paint_fill"]["fill-translate"]),
  14234. "fill-translate-anchor": new DataConstantProperty(StyleSpec["paint_fill"]["fill-translate-anchor"]),
  14235. "fill-pattern": new CrossFadedDataDrivenProperty(StyleSpec["paint_fill"]["fill-pattern"]),
  14236. });
  14237. // Note: without adding the explicit type annotation, Flow infers weaker types
  14238. // for these objects from their use in the constructor to StyleLayer, as
  14239. // {layout?: Properties<...>, paint: Properties<...>}
  14240. var properties$3 = ({ paint: paint$4, layout: layout$4 }
  14241. );
  14242. var FillStyleLayer = /*@__PURE__*/(function (StyleLayer) {
  14243. function FillStyleLayer(layer) {
  14244. StyleLayer.call(this, layer, properties$3);
  14245. }
  14246. if (StyleLayer) FillStyleLayer.__proto__ = StyleLayer;
  14247. FillStyleLayer.prototype = Object.create(StyleLayer && StyleLayer.prototype);
  14248. FillStyleLayer.prototype.constructor = FillStyleLayer;
  14249. FillStyleLayer.prototype.recalculate = function recalculate(parameters, availableImages) {
  14250. StyleLayer.prototype.recalculate.call(this, parameters, availableImages);
  14251. var outlineColor = this.paint._values['fill-outline-color'];
  14252. if (outlineColor.value.kind === 'constant' && outlineColor.value.value === undefined) {
  14253. this.paint._values['fill-outline-color'] = this.paint._values['fill-color'];
  14254. }
  14255. };
  14256. FillStyleLayer.prototype.createBucket = function createBucket(parameters) {
  14257. return new FillBucket(parameters);
  14258. };
  14259. FillStyleLayer.prototype.queryRadius = function queryRadius() {
  14260. return QueryUtils.translateDistance(this.paint.get('fill-translate'));
  14261. };
  14262. FillStyleLayer.prototype.queryIntersectsFeature = function queryIntersectsFeature(queryGeometry, feature, featureState, geometry, zoom, transform, pixelsToTileUnits) {
  14263. var translatedPolygon = QueryUtils.translate(queryGeometry,
  14264. this.paint.get('fill-translate'),
  14265. this.paint.get('fill-translate-anchor'),
  14266. 0, pixelsToTileUnits);
  14267. return IntersectionTest.polygonIntersectsMultiPolygon(translatedPolygon, geometry);
  14268. };
  14269. FillStyleLayer.prototype.isTileClipped = function isTileClipped() {
  14270. return true;
  14271. };
  14272. return FillStyleLayer;
  14273. }(StyleLayer));
  14274. /**
  14275. * An implementation of `Property` for `*-pattern` and `line-dasharray`, which are transitioned by cross-fading
  14276. * rather than interpolation.
  14277. *
  14278. * @private
  14279. */
  14280. var CrossFadedProperty = function CrossFadedProperty(specification) {
  14281. this.specification = specification;
  14282. };
  14283. CrossFadedProperty.prototype.possiblyEvaluate = function possiblyEvaluate(value, parameters, availableImages) {
  14284. if (value.value === undefined) {
  14285. return undefined;
  14286. } else if (value.expression.kind === 'constant') {
  14287. var constant = value.expression.evaluate(parameters, (null ), {}, availableImages);
  14288. return this._calculate(constant, constant, constant, parameters);
  14289. } else {
  14290. return this._calculate(
  14291. value.expression.evaluate(new EvaluationParameters(Math.floor(parameters.zoom - 1.0), parameters)),
  14292. value.expression.evaluate(new EvaluationParameters(Math.floor(parameters.zoom), parameters)),
  14293. value.expression.evaluate(new EvaluationParameters(Math.floor(parameters.zoom + 1.0), parameters)),
  14294. parameters);
  14295. }
  14296. };
  14297. CrossFadedProperty.prototype._calculate = function _calculate(min, mid, max, parameters) {
  14298. var z = parameters.zoom;
  14299. return z > parameters.zoomHistory.lastIntegerZoom ? {from: min, to: mid} : {from: max, to: mid};
  14300. };
  14301. CrossFadedProperty.prototype.interpolate = function interpolate(a) {
  14302. return a;
  14303. };
  14304. WebWorkerTransfer.register('CrossFadedProperty', CrossFadedProperty);
  14305. /**
  14306. * An implementation of `Property` for `heatmap-color` and `line-gradient`. Interpolation is a no-op, and
  14307. * evaluation returns a boolean value in order to indicate its presence, but the real
  14308. * evaluation happens in StyleLayer classes.
  14309. *
  14310. * @private
  14311. */
  14312. var ColorRampProperty = function ColorRampProperty(specification) {
  14313. this.specification = specification;
  14314. };
  14315. ColorRampProperty.prototype.possiblyEvaluate = function possiblyEvaluate(value, parameters, availableImages) {
  14316. return !!value.expression.evaluate(parameters, (null ), {}, availableImages);
  14317. };
  14318. ColorRampProperty.prototype.interpolate = function interpolate() {
  14319. return false;
  14320. };
  14321. WebWorkerTransfer.register('ColorRampProperty', ColorRampProperty);
  14322. var layout$6 = new Properties({
  14323. "line-cap": new DataConstantProperty(StyleSpec["layout_line"]["line-cap"]),
  14324. "line-join": new DataDrivenProperty(StyleSpec["layout_line"]["line-join"]),
  14325. "line-miter-limit": new DataConstantProperty(StyleSpec["layout_line"]["line-miter-limit"]),
  14326. "line-round-limit": new DataConstantProperty(StyleSpec["layout_line"]["line-round-limit"]),
  14327. "line-sort-key": new DataDrivenProperty(StyleSpec["layout_line"]["line-sort-key"])
  14328. });
  14329. var paint$6 = new Properties({
  14330. "line-opacity": new DataDrivenProperty(StyleSpec["paint_line"]["line-opacity"]),
  14331. "line-color": new DataDrivenProperty(StyleSpec["paint_line"]["line-color"]),
  14332. "line-translate": new DataConstantProperty(StyleSpec["paint_line"]["line-translate"]),
  14333. "line-translate-anchor": new DataConstantProperty(StyleSpec["paint_line"]["line-translate-anchor"]),
  14334. "line-width": new DataDrivenProperty(StyleSpec["paint_line"]["line-width"]),
  14335. "line-gap-width": new DataDrivenProperty(StyleSpec["paint_line"]["line-gap-width"]),
  14336. "line-offset": new DataDrivenProperty(StyleSpec["paint_line"]["line-offset"]),
  14337. "line-blur": new DataDrivenProperty(StyleSpec["paint_line"]["line-blur"]),
  14338. "line-dasharray": new CrossFadedProperty(StyleSpec["paint_line"]["line-dasharray"]),
  14339. "line-pattern": new CrossFadedDataDrivenProperty(StyleSpec["paint_line"]["line-pattern"]),
  14340. "line-gradient": new ColorRampProperty(StyleSpec["paint_line"]["line-gradient"])
  14341. });
  14342. // Note: without adding the explicit type annotation, Flow infers weaker types
  14343. // for these objects from their use in the constructor to StyleLayer, as
  14344. // {layout?: Properties<...>, paint: Properties<...>}
  14345. var properties$5 = ({ paint: paint$6, layout: layout$6 }
  14346. );
  14347. var LineFloorwidthProperty = /*@__PURE__*/(function (DataDrivenProperty) {
  14348. function LineFloorwidthProperty() {
  14349. DataDrivenProperty.apply(this, arguments);
  14350. }
  14351. if (DataDrivenProperty) LineFloorwidthProperty.__proto__ = DataDrivenProperty;
  14352. LineFloorwidthProperty.prototype = Object.create(DataDrivenProperty && DataDrivenProperty.prototype);
  14353. LineFloorwidthProperty.prototype.constructor = LineFloorwidthProperty;
  14354. LineFloorwidthProperty.prototype.possiblyEvaluate = function possiblyEvaluate(value, parameters) {
  14355. parameters = new EvaluationParameters$1(Math.floor(parameters.zoom), {
  14356. now: parameters.now,
  14357. fadeDuration: parameters.fadeDuration,
  14358. zoomHistory: parameters.zoomHistory,
  14359. transition: parameters.transition
  14360. });
  14361. return DataDrivenProperty.prototype.possiblyEvaluate.call(this, value, parameters);
  14362. };
  14363. LineFloorwidthProperty.prototype.evaluate = function evaluate(value, globals, feature, featureState) {
  14364. globals = extend({}, globals, {zoom: Math.floor(globals.zoom)});
  14365. return DataDrivenProperty.prototype.evaluate.call(this, value, globals, feature, featureState);
  14366. };
  14367. return LineFloorwidthProperty;
  14368. }(DataDrivenProperty));
  14369. var lineFloorwidthProperty = new LineFloorwidthProperty(properties$5.paint.properties['line-width'].specification);
  14370. lineFloorwidthProperty.useIntegerZoom = true;
  14371. var LineStyleLayer = /*@__PURE__*/(function (StyleLayer) {
  14372. function LineStyleLayer(layer) {
  14373. StyleLayer.call(this, layer, properties$5);
  14374. }
  14375. if (StyleLayer) LineStyleLayer.__proto__ = StyleLayer;
  14376. LineStyleLayer.prototype = Object.create(StyleLayer && StyleLayer.prototype);
  14377. LineStyleLayer.prototype.constructor = LineStyleLayer;
  14378. LineStyleLayer.prototype._handleSpecialPaintPropertyUpdate = function _handleSpecialPaintPropertyUpdate(name) {
  14379. if (name === 'line-gradient') {
  14380. this._updateGradient();
  14381. }
  14382. };
  14383. LineStyleLayer.prototype._updateGradient = function _updateGradient() {
  14384. var expression = this._transitionablePaint._values['line-gradient'].value.expression;
  14385. this.gradient = renderColorRamp(expression, 'lineProgress');
  14386. this.gradientTexture = null;
  14387. };
  14388. LineStyleLayer.prototype.recalculate = function recalculate(parameters, availableImages) {
  14389. StyleLayer.prototype.recalculate.call(this, parameters, availableImages);
  14390. (this.paint._values )['line-floorwidth'] =
  14391. lineFloorwidthProperty.possiblyEvaluate(this._transitioningPaint._values['line-width'].value, parameters);
  14392. };
  14393. LineStyleLayer.prototype.createBucket = function createBucket(parameters) {
  14394. return new LineBucket(parameters);
  14395. };
  14396. LineStyleLayer.prototype.queryRadius = function queryRadius(bucket) {
  14397. var lineBucket = (bucket );
  14398. var width = getLineWidth(
  14399. QueryUtils.getMaximumPaintValue('line-width', this, lineBucket),
  14400. QueryUtils.getMaximumPaintValue('line-gap-width', this, lineBucket));
  14401. var offset = QueryUtils.getMaximumPaintValue('line-offset', this, lineBucket);
  14402. return width / 2 + Math.abs(offset) + QueryUtils.translateDistance(this.paint.get('line-translate'));
  14403. };
  14404. LineStyleLayer.prototype.queryIntersectsFeature = function queryIntersectsFeature(queryGeometry, feature, featureState, geometry, zoom, transform, pixelsToTileUnits) {
  14405. var translatedPolygon = QueryUtils.translate(queryGeometry,
  14406. this.paint.get('line-translate'),
  14407. this.paint.get('line-translate-anchor'),
  14408. 0, pixelsToTileUnits);
  14409. var evaluatedLineWidth = getLineWidth(
  14410. this.paint.get('line-width').evaluate(feature, featureState),
  14411. this.paint.get('line-gap-width').evaluate(feature, featureState));
  14412. evaluatedLineWidth = Math.max(evaluatedLineWidth, 5.0);
  14413. var halfWidth = pixelsToTileUnits / 2 * evaluatedLineWidth;
  14414. var lineOffset = this.paint.get('line-offset').evaluate(feature, featureState);
  14415. if (lineOffset) {
  14416. geometry = offsetLine(geometry, lineOffset * pixelsToTileUnits);
  14417. }
  14418. return IntersectionTest.polygonIntersectsBufferedMultiLine(translatedPolygon, geometry, halfWidth);
  14419. };
  14420. LineStyleLayer.prototype.isTileClipped = function isTileClipped() {
  14421. return true;
  14422. };
  14423. function getLineWidth(lineWidth, lineGapWidth) {
  14424. if (lineGapWidth > 0) {
  14425. return lineGapWidth + 2 * lineWidth;
  14426. } else {
  14427. return lineWidth;
  14428. }
  14429. }
  14430. function offsetLine(rings, offset) {
  14431. var newRings = [];
  14432. var zero = new Point(0, 0);
  14433. for (var k = 0; k < rings.length; k++) {
  14434. var ring = rings[k];
  14435. var newRing = [];
  14436. for (var i = 0; i < ring.length; i++) {
  14437. var a = ring[i - 1];
  14438. var b = ring[i];
  14439. var c = ring[i + 1];
  14440. var aToB = i === 0 ? zero : b.sub(a)._unit()._perp();
  14441. var bToC = i === ring.length - 1 ? zero : c.sub(b)._unit()._perp();
  14442. var extrude = aToB._add(bToC)._unit();
  14443. var cosHalfAngle = extrude.x * bToC.x + extrude.y * bToC.y;
  14444. extrude._mult(1 / cosHalfAngle);
  14445. newRing.push(extrude._mult(offset)._add(b));
  14446. }
  14447. newRings.push(newRing);
  14448. }
  14449. return newRings;
  14450. }
  14451. return LineStyleLayer;
  14452. }(StyleLayer));
  14453. function SymbolAttributes() {
  14454. }
  14455. SymbolAttributes.symbolLayoutAttributes = createLayout([
  14456. {name: 'a_pos_offset', components: 4, type: 'Int16'},
  14457. {name: 'a_data', components: 4, type: 'Uint16'},
  14458. {name: 'a_pixeloffset', components: 4, type: 'Int16'}
  14459. ], 4);
  14460. SymbolAttributes.dynamicLayoutAttributes = createLayout([
  14461. {name: 'a_projected_pos', components: 3, type: 'Float32'}
  14462. ], 4);
  14463. SymbolAttributes.placementOpacityAttributes = createLayout([
  14464. {name: 'a_fade_opacity', components: 1, type: 'Uint32'}
  14465. ], 4);
  14466. SymbolAttributes.collisionVertexAttributes = createLayout([
  14467. {name: 'a_placed', components: 2, type: 'Uint8'},
  14468. {name: 'a_shift', components: 2, type: 'Float32'}
  14469. ]);
  14470. SymbolAttributes.collisionBox = createLayout([
  14471. // the box is centered around the anchor point
  14472. {type: 'Int16', name: 'anchorPointX'},
  14473. {type: 'Int16', name: 'anchorPointY'},
  14474. // distances to the edges from the anchor
  14475. {type: 'Int16', name: 'x1'},
  14476. {type: 'Int16', name: 'y1'},
  14477. {type: 'Int16', name: 'x2'},
  14478. {type: 'Int16', name: 'y2'},
  14479. // the index of the feature in the original vectortile
  14480. {type: 'Uint32', name: 'featureIndex'},
  14481. // the source layer the feature appears in
  14482. {type: 'Uint16', name: 'sourceLayerIndex'},
  14483. // the bucket the feature appears in
  14484. {type: 'Uint16', name: 'bucketIndex'},
  14485. // collision circles for lines store their distance to the anchor in tile units
  14486. // so that they can be ignored if the projected label doesn't extend into
  14487. // the box area
  14488. {type: 'Int16', name: 'radius'},
  14489. {type: 'Int16', name: 'signedDistanceFromAnchor'}
  14490. ]);
  14491. SymbolAttributes.collisionBoxLayout = createLayout([ // used to render collision boxes for debugging purposes
  14492. {name: 'a_pos', components: 2, type: 'Int16'},
  14493. {name: 'a_anchor_pos', components: 2, type: 'Int16'},
  14494. {name: 'a_extrude', components: 2, type: 'Int16'}
  14495. ], 4);
  14496. SymbolAttributes.collisionCircleLayout = createLayout([ // used to render collision circles for debugging purposes
  14497. {name: 'a_pos', components: 2, type: 'Int16'},
  14498. {name: 'a_anchor_pos', components: 2, type: 'Int16'},
  14499. {name: 'a_extrude', components: 2, type: 'Int16'}
  14500. ], 4);
  14501. SymbolAttributes.placement = createLayout([
  14502. {type: 'Int16', name: 'anchorX'},
  14503. {type: 'Int16', name: 'anchorY'},
  14504. {type: 'Uint16', name: 'glyphStartIndex'},
  14505. {type: 'Uint16', name: 'numGlyphs'},
  14506. {type: 'Uint32', name: 'vertexStartIndex'},
  14507. {type: 'Uint32', name: 'lineStartIndex'},
  14508. {type: 'Uint32', name: 'lineLength'},
  14509. {type: 'Uint16', name: 'segment'},
  14510. {type: 'Uint16', name: 'lowerSize'},
  14511. {type: 'Uint16', name: 'upperSize'},
  14512. {type: 'Float32', name: 'lineOffsetX'},
  14513. {type: 'Float32', name: 'lineOffsetY'},
  14514. {type: 'Uint8', name: 'writingMode'},
  14515. {type: 'Uint8', name: 'placedOrientation'},
  14516. {type: 'Uint8', name: 'hidden'},
  14517. {type: 'Uint32', name: 'crossTileID'},
  14518. {type: 'Int16', name: 'associatedIconIndex'}
  14519. ]);
  14520. SymbolAttributes.symbolInstance = createLayout([
  14521. {type: 'Int16', name: 'anchorX'},
  14522. {type: 'Int16', name: 'anchorY'},
  14523. {type: 'Int16', name: 'rightJustifiedTextSymbolIndex'},
  14524. {type: 'Int16', name: 'centerJustifiedTextSymbolIndex'},
  14525. {type: 'Int16', name: 'leftJustifiedTextSymbolIndex'},
  14526. {type: 'Int16', name: 'verticalPlacedTextSymbolIndex'},
  14527. {type: 'Int16', name: 'placedIconSymbolIndex'},
  14528. {type: 'Int16', name: 'verticalPlacedIconSymbolIndex'},
  14529. {type: 'Uint16', name: 'key'},
  14530. {type: 'Uint16', name: 'textBoxStartIndex'},
  14531. {type: 'Uint16', name: 'textBoxEndIndex'},
  14532. {type: 'Uint16', name: 'verticalTextBoxStartIndex'},
  14533. {type: 'Uint16', name: 'verticalTextBoxEndIndex'},
  14534. {type: 'Uint16', name: 'iconBoxStartIndex'},
  14535. {type: 'Uint16', name: 'iconBoxEndIndex'},
  14536. {type: 'Uint16', name: 'verticalIconBoxStartIndex'},
  14537. {type: 'Uint16', name: 'verticalIconBoxEndIndex'},
  14538. {type: 'Uint16', name: 'featureIndex'},
  14539. {type: 'Uint16', name: 'numHorizontalGlyphVertices'},
  14540. {type: 'Uint16', name: 'numVerticalGlyphVertices'},
  14541. {type: 'Uint16', name: 'numIconVertices'},
  14542. {type: 'Uint16', name: 'numVerticalIconVertices'},
  14543. {type: 'Uint32', name: 'crossTileID'},
  14544. {type: 'Float32', name: 'textBoxScale'},
  14545. {type: 'Float32', components: 2, name: 'textOffset'}
  14546. ]);
  14547. SymbolAttributes.glyphOffset = createLayout([
  14548. {type: 'Float32', name: 'offsetX'}
  14549. ]);
  14550. SymbolAttributes.lineVertex = createLayout([
  14551. {type: 'Int16', name: 'x'},
  14552. {type: 'Int16', name: 'y'},
  14553. {type: 'Int16', name: 'tileUnitDistanceFromAnchor'}
  14554. ]);
  14555. function mergeLines(features) {
  14556. var leftIndex = {};
  14557. var rightIndex = {};
  14558. var mergedFeatures = [];
  14559. var mergedIndex = 0;
  14560. function add(k) {
  14561. mergedFeatures.push(features[k]);
  14562. mergedIndex++;
  14563. }
  14564. function mergeFromRight(leftKey, rightKey, geom) {
  14565. var i = rightIndex[leftKey];
  14566. delete rightIndex[leftKey];
  14567. rightIndex[rightKey] = i;
  14568. mergedFeatures[i].geometry[0].pop();
  14569. mergedFeatures[i].geometry[0] = mergedFeatures[i].geometry[0].concat(geom[0]);
  14570. return i;
  14571. }
  14572. function mergeFromLeft(leftKey, rightKey, geom) {
  14573. var i = leftIndex[rightKey];
  14574. delete leftIndex[rightKey];
  14575. leftIndex[leftKey] = i;
  14576. mergedFeatures[i].geometry[0].shift();
  14577. mergedFeatures[i].geometry[0] = geom[0].concat(mergedFeatures[i].geometry[0]);
  14578. return i;
  14579. }
  14580. function getKey(text, geom, onRight) {
  14581. var point = onRight ? geom[0][geom[0].length - 1] : geom[0][0];
  14582. return (text + ":" + (point.x) + ":" + (point.y));
  14583. }
  14584. for (var k = 0; k < features.length; k++) {
  14585. var feature = features[k];
  14586. var geom = feature.geometry;
  14587. var text = feature.text ? feature.text.toString() : null;
  14588. if (!text) {
  14589. add(k);
  14590. continue;
  14591. }
  14592. var leftKey = getKey(text, geom),
  14593. rightKey = getKey(text, geom, true);
  14594. if ((leftKey in rightIndex) && (rightKey in leftIndex) && (rightIndex[leftKey] !== leftIndex[rightKey])) {
  14595. // found lines with the same text adjacent to both ends of the current line, merge all three
  14596. var j = mergeFromLeft(leftKey, rightKey, geom);
  14597. var i = mergeFromRight(leftKey, rightKey, mergedFeatures[j].geometry);
  14598. delete leftIndex[leftKey];
  14599. delete rightIndex[rightKey];
  14600. rightIndex[getKey(text, mergedFeatures[i].geometry, true)] = i;
  14601. mergedFeatures[j].geometry = (null );
  14602. } else if (leftKey in rightIndex) {
  14603. // found mergeable line adjacent to the start of the current line, merge
  14604. mergeFromRight(leftKey, rightKey, geom);
  14605. } else if (rightKey in leftIndex) {
  14606. // found mergeable line adjacent to the end of the current line, merge
  14607. mergeFromLeft(leftKey, rightKey, geom);
  14608. } else {
  14609. // no adjacent lines, add as a new item
  14610. add(k);
  14611. leftIndex[leftKey] = mergedIndex - 1;
  14612. rightIndex[rightKey] = mergedIndex - 1;
  14613. }
  14614. }
  14615. return mergedFeatures.filter(function (f) {
  14616. return f.geometry;
  14617. });
  14618. }
  14619. var Shaping = function Shaping() {
  14620. };
  14621. Shaping.WritingMode = {
  14622. horizontal: 1,
  14623. vertical: 2,
  14624. horizontalOnly: 3
  14625. };
  14626. // The position of a glyph relative to the text's anchor point.
  14627. // A collection of positioned glyphs and some metadata
  14628. function isEmpty(positionedLines) {
  14629. for (var i = 0, list = positionedLines; i < list.length; i += 1) {
  14630. var line = list[i];
  14631. if (line.positionedGlyphs.length !== 0) {
  14632. return false;
  14633. }
  14634. }
  14635. return true;
  14636. }
  14637. // Max number of images in label is 6401 U+E000–U+F8FF that covers
  14638. // Basic Multilingual Plane Unicode Private Use Area (PUA).
  14639. var PUAbegin = 0xE000;
  14640. var PUAend = 0xF8FF;
  14641. var SectionOptions = function SectionOptions() {
  14642. this.scale = 1.0;
  14643. this.fontStack = "";
  14644. this.imageName = null;
  14645. };
  14646. SectionOptions.forText = function forText(scale, fontStack) {
  14647. var textOptions = new SectionOptions();
  14648. textOptions.scale = scale || 1;
  14649. textOptions.fontStack = fontStack;
  14650. return textOptions;
  14651. };
  14652. SectionOptions.forImage = function forImage(imageName) {
  14653. var imageOptions = new SectionOptions();
  14654. imageOptions.imageName = imageName;
  14655. return imageOptions;
  14656. };
  14657. var TaggedString = function TaggedString() {
  14658. this.text = "";
  14659. this.sectionIndex = [];
  14660. this.sections = [];
  14661. this.imageSectionID = null;
  14662. };
  14663. TaggedString.fromFeature = function fromFeature(text, defaultFontStack) {
  14664. var result = new TaggedString();
  14665. for (var i = 0; i < text.sections.length; i++) {
  14666. var section = text.sections[i];
  14667. if (!section.image) {
  14668. result.addTextSection(section, defaultFontStack);
  14669. } else {
  14670. result.addImageSection(section);
  14671. }
  14672. }
  14673. return result;
  14674. };
  14675. TaggedString.prototype.length = function length() {
  14676. return this.text.length;
  14677. };
  14678. TaggedString.prototype.getSection = function getSection(index) {
  14679. return this.sections[this.sectionIndex[index]];
  14680. };
  14681. TaggedString.prototype.getSectionIndex = function getSectionIndex(index) {
  14682. return this.sectionIndex[index];
  14683. };
  14684. TaggedString.prototype.getCharCode = function getCharCode(index) {
  14685. return this.text.charCodeAt(index);
  14686. };
  14687. TaggedString.prototype.verticalizePunctuation = function verticalizePunctuation$1() {
  14688. //this.text = verticalizePunctuation(this.text);
  14689. };
  14690. TaggedString.prototype.trim = function trim() {
  14691. var beginningWhitespace = 0;
  14692. for (var i = 0;
  14693. i < this.text.length && whitespace[this.text.charCodeAt(i)];
  14694. i++) {
  14695. beginningWhitespace++;
  14696. }
  14697. var trailingWhitespace = this.text.length;
  14698. for (var i$1 = this.text.length - 1;
  14699. i$1 >= 0 && i$1 >= beginningWhitespace && whitespace[this.text.charCodeAt(i$1)];
  14700. i$1--) {
  14701. trailingWhitespace--;
  14702. }
  14703. this.text = this.text.substring(beginningWhitespace, trailingWhitespace);
  14704. this.sectionIndex = this.sectionIndex.slice(beginningWhitespace, trailingWhitespace);
  14705. };
  14706. TaggedString.prototype.substring = function substring(start, end) {
  14707. var substring = new TaggedString();
  14708. substring.text = this.text.substring(start, end);
  14709. substring.sectionIndex = this.sectionIndex.slice(start, end);
  14710. substring.sections = this.sections;
  14711. return substring;
  14712. };
  14713. TaggedString.prototype.toString = function toString() {
  14714. return this.text;
  14715. };
  14716. TaggedString.prototype.getMaxScale = function getMaxScale() {
  14717. var this$1 = this;
  14718. return this.sectionIndex.reduce(function (max, index) {
  14719. return Math.max(max, this$1.sections[index].scale);
  14720. }, 0);
  14721. };
  14722. TaggedString.prototype.addTextSection = function addTextSection(section, defaultFontStack) {
  14723. this.text += section.text;
  14724. this.sections.push(SectionOptions.forText(section.scale, section.fontStack || defaultFontStack));
  14725. var index = this.sections.length - 1;
  14726. for (var i = 0; i < section.text.length; ++i) {
  14727. this.sectionIndex.push(index);
  14728. }
  14729. };
  14730. TaggedString.prototype.addImageSection = function addImageSection(section) {
  14731. var imageName = section.image ? section.image.name : '';
  14732. if (imageName.length === 0) {
  14733. //warnOnce("Can't add FormattedSection with an empty image.");
  14734. return;
  14735. }
  14736. var nextImageSectionCharCode = this.getNextImageSectionCharCode();
  14737. if (!nextImageSectionCharCode) {
  14738. //warnOnce(("Reached maximum number of images " + (PUAend - PUAbegin + 2)));
  14739. return;
  14740. }
  14741. this.text += String.fromCharCode(nextImageSectionCharCode);
  14742. this.sections.push(SectionOptions.forImage(imageName));
  14743. this.sectionIndex.push(this.sections.length - 1);
  14744. };
  14745. TaggedString.prototype.getNextImageSectionCharCode = function getNextImageSectionCharCode() {
  14746. if (!this.imageSectionID) {
  14747. this.imageSectionID = PUAbegin;
  14748. return this.imageSectionID;
  14749. }
  14750. if (this.imageSectionID >= PUAend) {
  14751. return null;
  14752. }
  14753. return ++this.imageSectionID;
  14754. };
  14755. function breakLines(input, lineBreakPoints) {
  14756. var lines = [];
  14757. var text = input.text;
  14758. var start = 0;
  14759. for (var i = 0, list = lineBreakPoints; i < list.length; i += 1) {
  14760. var lineBreak = list[i];
  14761. lines.push(input.substring(start, lineBreak));
  14762. start = lineBreak;
  14763. }
  14764. if (start < text.length) {
  14765. lines.push(input.substring(start, text.length));
  14766. }
  14767. return lines;
  14768. }
  14769. Shaping.shapeText = function(text, glyphMap, glyphPositions, imagePositions, defaultFontStack, maxWidth, lineHeight, textAnchor, textJustify, spacing, translate, writingMode, allowVerticalPlacement, symbolPlacement, layoutTextSize, layoutTextSizeThisZoom){
  14770. var logicalInput = TaggedString.fromFeature(text, defaultFontStack);
  14771. if (writingMode === Shaping.WritingMode.vertical) {
  14772. logicalInput.verticalizePunctuation();
  14773. }
  14774. var lines;
  14775. {
  14776. lines = breakLines(logicalInput, determineLineBreaks());
  14777. }
  14778. var positionedLines = [];
  14779. var shaping = {
  14780. positionedLines: positionedLines,
  14781. text: logicalInput.toString(),
  14782. top: translate[1],
  14783. bottom: translate[1],
  14784. left: translate[0],
  14785. right: translate[0],
  14786. writingMode: writingMode,
  14787. iconsInText: false,
  14788. verticalizable: false
  14789. };
  14790. if (isEmpty(positionedLines)) {
  14791. return false;
  14792. }
  14793. return shaping;
  14794. };
  14795. // using computed properties due to https://github.com/facebook/flow/issues/380
  14796. /* eslint no-useless-computed-key: 0 */
  14797. var whitespace = {};
  14798. whitespace[0x09] = true;
  14799. whitespace[0x0a] = true;
  14800. whitespace[0x0b] = true;
  14801. whitespace[0x0c] = true;
  14802. whitespace[0x0d] = true;
  14803. whitespace[0x20] = true;
  14804. function determineLineBreaks(logicalInput, spacing, maxWidth, glyphMap, imagePositions, symbolPlacement, layoutTextSize) {
  14805. // if (symbolPlacement !== 'point') {
  14806. // return [];
  14807. // }
  14808. //
  14809. // if (!logicalInput) {
  14810. // return [];
  14811. // }
  14812. //
  14813. // var potentialLineBreaks = [];
  14814. // var targetWidth = determineAverageLineWidth(logicalInput, spacing, maxWidth, glyphMap, imagePositions, layoutTextSize);
  14815. //
  14816. // var hasServerSuggestedBreakpoints = logicalInput.text.indexOf("\u200b") >= 0;
  14817. //
  14818. // var currentX = 0;
  14819. //
  14820. // for (var i = 0; i < logicalInput.length(); i++) {
  14821. // var section = logicalInput.getSection(i);
  14822. // var codePoint = logicalInput.getCharCode(i);
  14823. // if (!whitespace[codePoint]) {
  14824. // currentX += getGlyphAdvance(codePoint, section, glyphMap, imagePositions, spacing, layoutTextSize);
  14825. // }
  14826. //
  14827. // // Ideographic characters, spaces, and word-breaking punctuation that often appear without
  14828. // // surrounding spaces.
  14829. // if ((i < logicalInput.length() - 1)) {
  14830. // var ideographicBreak = charAllowsIdeographicBreaking(codePoint);
  14831. // if (breakable[codePoint] || ideographicBreak || section.imageName) {
  14832. //
  14833. // potentialLineBreaks.push(
  14834. // evaluateBreak(
  14835. // i + 1,
  14836. // currentX,
  14837. // targetWidth,
  14838. // potentialLineBreaks,
  14839. // calculatePenalty(codePoint, logicalInput.getCharCode(i + 1), ideographicBreak && hasServerSuggestedBreakpoints),
  14840. // false));
  14841. // }
  14842. // }
  14843. // }
  14844. //
  14845. // return leastBadBreaks(
  14846. // evaluateBreak(
  14847. // logicalInput.length(),
  14848. // currentX,
  14849. // targetWidth,
  14850. // potentialLineBreaks,
  14851. // 0,
  14852. // true));
  14853. }
  14854. function getAnchorAlignment(anchor) {
  14855. var horizontalAlign = 0.5, verticalAlign = 0.5;
  14856. switch (anchor) {
  14857. case 'right':
  14858. case 'top-right':
  14859. case 'bottom-right':
  14860. horizontalAlign = 1;
  14861. break;
  14862. case 'left':
  14863. case 'top-left':
  14864. case 'bottom-left':
  14865. horizontalAlign = 0;
  14866. break;
  14867. }
  14868. switch (anchor) {
  14869. case 'bottom':
  14870. case 'bottom-right':
  14871. case 'bottom-left':
  14872. verticalAlign = 1;
  14873. break;
  14874. case 'top':
  14875. case 'top-right':
  14876. case 'top-left':
  14877. verticalAlign = 0;
  14878. break;
  14879. }
  14880. return {horizontalAlign: horizontalAlign, verticalAlign: verticalAlign};
  14881. }
  14882. Shaping.shapeIcon = function(image, iconOffset, iconAnchor){
  14883. var ref = getAnchorAlignment(iconAnchor);
  14884. var horizontalAlign = ref.horizontalAlign;
  14885. var verticalAlign = ref.verticalAlign;
  14886. var dx = iconOffset[0];
  14887. var dy = iconOffset[1];
  14888. var x1 = dx - image.displaySize[0] * horizontalAlign;
  14889. var x2 = x1 + image.displaySize[0];
  14890. var y1 = dy - image.displaySize[1] * verticalAlign;
  14891. var y2 = y1 + image.displaySize[1];
  14892. return {image: image, top: y1, bottom: y2, left: x1, right: x2};
  14893. };
  14894. Shaping.fitIconToText = function(shapedIcon, shapedText, textFit, padding, iconOffset, fontScale){
  14895. var image = shapedIcon.image;
  14896. var collisionPadding;
  14897. if (image.content) {
  14898. var content = image.content;
  14899. var pixelRatio = image.pixelRatio || 1;
  14900. collisionPadding = [
  14901. content[0] / pixelRatio,
  14902. content[1] / pixelRatio,
  14903. image.displaySize[0] - content[2] / pixelRatio,
  14904. image.displaySize[1] - content[3] / pixelRatio
  14905. ];
  14906. }
  14907. // We don't respect the icon-anchor, because icon-text-fit is set. Instead,
  14908. // the icon will be centered on the text, then stretched in the given
  14909. // dimensions.
  14910. var textLeft = shapedText.left * fontScale;
  14911. var textRight = shapedText.right * fontScale;
  14912. var top, right, bottom, left;
  14913. if (textFit === 'width' || textFit === 'both') {
  14914. // Stretched horizontally to the text width
  14915. left = iconOffset[0] + textLeft - padding[3];
  14916. right = iconOffset[0] + textRight + padding[1];
  14917. } else {
  14918. // Centered on the text
  14919. left = iconOffset[0] + (textLeft + textRight - image.displaySize[0]) / 2;
  14920. right = left + image.displaySize[0];
  14921. }
  14922. var textTop = shapedText.top * fontScale;
  14923. var textBottom = shapedText.bottom * fontScale;
  14924. if (textFit === 'height' || textFit === 'both') {
  14925. // Stretched vertically to the text height
  14926. top = iconOffset[1] + textTop - padding[0];
  14927. bottom = iconOffset[1] + textBottom + padding[2];
  14928. } else {
  14929. // Centered on the text
  14930. top = iconOffset[1] + (textTop + textBottom - image.displaySize[1]) / 2;
  14931. bottom = top + image.displaySize[1];
  14932. }
  14933. return {image: image, top: top, right: right, bottom: bottom, left: left, collisionPadding: collisionPadding};
  14934. };
  14935. var SIZE_PACK_FACTOR = 128;
  14936. // For {text,icon}-size, get the bucket-level data that will be needed by
  14937. // the painter to set symbol-size-related uniforms
  14938. function getSizeData(tileZoom, value) {
  14939. var expression = value.expression;
  14940. if (expression.kind === 'constant') {
  14941. var layoutSize = expression.evaluate(new EvaluationParameters$1(tileZoom + 1));
  14942. return {kind: 'constant', layoutSize: layoutSize};
  14943. } else if (expression.kind === 'source') {
  14944. return {kind: 'source'};
  14945. } else {
  14946. var zoomStops = expression.zoomStops;
  14947. var interpolationType = expression.interpolationType;
  14948. // calculate covering zoom stops for zoom-dependent values
  14949. var lower = 0;
  14950. while (lower < zoomStops.length && zoomStops[lower] <= tileZoom) {
  14951. lower++;
  14952. }
  14953. lower = Math.max(0, lower - 1);
  14954. var upper = lower;
  14955. while (upper < zoomStops.length && zoomStops[upper] < tileZoom + 1) {
  14956. upper++;
  14957. }
  14958. upper = Math.min(zoomStops.length - 1, upper);
  14959. var minZoom = zoomStops[lower];
  14960. var maxZoom = zoomStops[upper];
  14961. // We'd like to be able to use CameraExpression or CompositeExpression in these
  14962. // return types rather than ExpressionSpecification, but the former are not
  14963. // transferrable across Web Worker boundaries.
  14964. if (expression.kind === 'composite') {
  14965. return {kind: 'composite', minZoom: minZoom, maxZoom: maxZoom, interpolationType: interpolationType};
  14966. }
  14967. // for camera functions, also save off the function values
  14968. // evaluated at the covering zoom levels
  14969. var minSize = expression.evaluate(new EvaluationParameters$1(minZoom));
  14970. var maxSize = expression.evaluate(new EvaluationParameters$1(maxZoom));
  14971. return {kind: 'camera', minZoom: minZoom, maxZoom: maxZoom, minSize: minSize, maxSize: maxSize, interpolationType: interpolationType};
  14972. }
  14973. }
  14974. function evaluateSizeForFeature(sizeData, ref, ref$1) {
  14975. var uSize = ref.uSize;
  14976. var uSizeT = ref.uSizeT;
  14977. var lowerSize = ref$1.lowerSize;
  14978. var upperSize = ref$1.upperSize;
  14979. if (sizeData.kind === 'source') {
  14980. return lowerSize / SIZE_PACK_FACTOR;
  14981. } else if (sizeData.kind === 'composite') {
  14982. return number(lowerSize / SIZE_PACK_FACTOR, upperSize / SIZE_PACK_FACTOR, uSizeT);
  14983. }
  14984. return uSize;
  14985. }
  14986. function evaluateSizeForZoom(sizeData, zoom) {
  14987. var uSizeT = 0;
  14988. var uSize = 0;
  14989. if (sizeData.kind === 'constant') {
  14990. uSize = sizeData.layoutSize;
  14991. } else if (sizeData.kind !== 'source') {
  14992. var interpolationType = sizeData.interpolationType;
  14993. var minZoom = sizeData.minZoom;
  14994. var maxZoom = sizeData.maxZoom;
  14995. // Even though we could get the exact value of the camera function
  14996. // at z = tr.zoom, we intentionally do not: instead, we interpolate
  14997. // between the camera function values at a pair of zoom stops covering
  14998. // [tileZoom, tileZoom + 1] in order to be consistent with this
  14999. // restriction on composite functions
  15000. // var t = !interpolationType ? 0 : clamp(
  15001. // Interpolate.interpolationFactor(interpolationType, zoom, minZoom, maxZoom), 0, 1);
  15002. var t = 0;
  15003. if (sizeData.kind === 'camera') {
  15004. uSize = number(sizeData.minSize, sizeData.maxSize, t);
  15005. } else {
  15006. uSizeT = t;
  15007. }
  15008. }
  15009. return {uSizeT: uSizeT, uSize: uSize};
  15010. }
  15011. var symbolSize = /*#__PURE__*/Object.freeze({
  15012. __proto__: null,
  15013. getSizeData: getSizeData,
  15014. evaluateSizeForFeature: evaluateSizeForFeature,
  15015. evaluateSizeForZoom: evaluateSizeForZoom,
  15016. SIZE_PACK_FACTOR: SIZE_PACK_FACTOR
  15017. });
  15018. function transformText(text, layer, feature) {
  15019. var transform = layer.layout.get('text-transform').evaluate(feature, {});
  15020. if (transform === 'uppercase') {
  15021. text = text.toLocaleUpperCase();
  15022. } else if (transform === 'lowercase') {
  15023. text = text.toLocaleLowerCase();
  15024. }
  15025. // if (plugin.applyArabicShaping) {
  15026. // text = plugin.applyArabicShaping(text);
  15027. // }
  15028. return text;
  15029. }
  15030. function transformText$1(text, layer, feature) {
  15031. text.sections.forEach(function (section) {
  15032. section.text = transformText(section.text, layer, feature);
  15033. });
  15034. return text;
  15035. }
  15036. // The following table comes from <http://www.unicode.org/Public/12.0.0/ucd/Blocks.txt>.
  15037. // Keep it synchronized with <http://www.unicode.org/Public/UCD/latest/ucd/Blocks.txt>.
  15038. var unicodeBlockLookup = {
  15039. // 'Basic Latin': (char) => char >= 0x0000 && char <= 0x007F,
  15040. 'Latin-1 Supplement': function (char) {
  15041. return char >= 0x0080 && char <= 0x00FF;
  15042. },
  15043. // 'Latin Extended-A': (char) => char >= 0x0100 && char <= 0x017F,
  15044. // 'Latin Extended-B': (char) => char >= 0x0180 && char <= 0x024F,
  15045. // 'IPA Extensions': (char) => char >= 0x0250 && char <= 0x02AF,
  15046. // 'Spacing Modifier Letters': (char) => char >= 0x02B0 && char <= 0x02FF,
  15047. // 'Combining Diacritical Marks': (char) => char >= 0x0300 && char <= 0x036F,
  15048. // 'Greek and Coptic': (char) => char >= 0x0370 && char <= 0x03FF,
  15049. // 'Cyrillic': (char) => char >= 0x0400 && char <= 0x04FF,
  15050. // 'Cyrillic Supplement': (char) => char >= 0x0500 && char <= 0x052F,
  15051. // 'Armenian': (char) => char >= 0x0530 && char <= 0x058F,
  15052. //'Hebrew': (char) => char >= 0x0590 && char <= 0x05FF,
  15053. 'Arabic': function (char) {
  15054. return char >= 0x0600 && char <= 0x06FF;
  15055. },
  15056. //'Syriac': (char) => char >= 0x0700 && char <= 0x074F,
  15057. 'Arabic Supplement': function (char) {
  15058. return char >= 0x0750 && char <= 0x077F;
  15059. },
  15060. // 'Thaana': (char) => char >= 0x0780 && char <= 0x07BF,
  15061. // 'NKo': (char) => char >= 0x07C0 && char <= 0x07FF,
  15062. // 'Samaritan': (char) => char >= 0x0800 && char <= 0x083F,
  15063. // 'Mandaic': (char) => char >= 0x0840 && char <= 0x085F,
  15064. // 'Syriac Supplement': (char) => char >= 0x0860 && char <= 0x086F,
  15065. 'Arabic Extended-A': function (char) {
  15066. return char >= 0x08A0 && char <= 0x08FF;
  15067. },
  15068. // 'Devanagari': (char) => char >= 0x0900 && char <= 0x097F,
  15069. // 'Bengali': (char) => char >= 0x0980 && char <= 0x09FF,
  15070. // 'Gurmukhi': (char) => char >= 0x0A00 && char <= 0x0A7F,
  15071. // 'Gujarati': (char) => char >= 0x0A80 && char <= 0x0AFF,
  15072. // 'Oriya': (char) => char >= 0x0B00 && char <= 0x0B7F,
  15073. // 'Tamil': (char) => char >= 0x0B80 && char <= 0x0BFF,
  15074. // 'Telugu': (char) => char >= 0x0C00 && char <= 0x0C7F,
  15075. // 'Kannada': (char) => char >= 0x0C80 && char <= 0x0CFF,
  15076. // 'Malayalam': (char) => char >= 0x0D00 && char <= 0x0D7F,
  15077. // 'Sinhala': (char) => char >= 0x0D80 && char <= 0x0DFF,
  15078. // 'Thai': (char) => char >= 0x0E00 && char <= 0x0E7F,
  15079. // 'Lao': (char) => char >= 0x0E80 && char <= 0x0EFF,
  15080. // 'Tibetan': (char) => char >= 0x0F00 && char <= 0x0FFF,
  15081. // 'Myanmar': (char) => char >= 0x1000 && char <= 0x109F,
  15082. // 'Georgian': (char) => char >= 0x10A0 && char <= 0x10FF,
  15083. 'Hangul Jamo': function (char) {
  15084. return char >= 0x1100 && char <= 0x11FF;
  15085. },
  15086. // 'Ethiopic': (char) => char >= 0x1200 && char <= 0x137F,
  15087. // 'Ethiopic Supplement': (char) => char >= 0x1380 && char <= 0x139F,
  15088. // 'Cherokee': (char) => char >= 0x13A0 && char <= 0x13FF,
  15089. 'Unified Canadian Aboriginal Syllabics': function (char) {
  15090. return char >= 0x1400 && char <= 0x167F;
  15091. },
  15092. // 'Ogham': (char) => char >= 0x1680 && char <= 0x169F,
  15093. // 'Runic': (char) => char >= 0x16A0 && char <= 0x16FF,
  15094. // 'Tagalog': (char) => char >= 0x1700 && char <= 0x171F,
  15095. // 'Hanunoo': (char) => char >= 0x1720 && char <= 0x173F,
  15096. // 'Buhid': (char) => char >= 0x1740 && char <= 0x175F,
  15097. // 'Tagbanwa': (char) => char >= 0x1760 && char <= 0x177F,
  15098. 'Khmer': function (char) {
  15099. return char >= 0x1780 && char <= 0x17FF;
  15100. },
  15101. // 'Mongolian': (char) => char >= 0x1800 && char <= 0x18AF,
  15102. 'Unified Canadian Aboriginal Syllabics Extended': function (char) {
  15103. return char >= 0x18B0 && char <= 0x18FF;
  15104. },
  15105. // 'Limbu': (char) => char >= 0x1900 && char <= 0x194F,
  15106. // 'Tai Le': (char) => char >= 0x1950 && char <= 0x197F,
  15107. // 'New Tai Lue': (char) => char >= 0x1980 && char <= 0x19DF,
  15108. // 'Khmer Symbols': (char) => char >= 0x19E0 && char <= 0x19FF,
  15109. // 'Buginese': (char) => char >= 0x1A00 && char <= 0x1A1F,
  15110. // 'Tai Tham': (char) => char >= 0x1A20 && char <= 0x1AAF,
  15111. // 'Combining Diacritical Marks Extended': (char) => char >= 0x1AB0 && char <= 0x1AFF,
  15112. // 'Balinese': (char) => char >= 0x1B00 && char <= 0x1B7F,
  15113. // 'Sundanese': (char) => char >= 0x1B80 && char <= 0x1BBF,
  15114. // 'Batak': (char) => char >= 0x1BC0 && char <= 0x1BFF,
  15115. // 'Lepcha': (char) => char >= 0x1C00 && char <= 0x1C4F,
  15116. // 'Ol Chiki': (char) => char >= 0x1C50 && char <= 0x1C7F,
  15117. // 'Cyrillic Extended-C': (char) => char >= 0x1C80 && char <= 0x1C8F,
  15118. // 'Georgian Extended': (char) => char >= 0x1C90 && char <= 0x1CBF,
  15119. // 'Sundanese Supplement': (char) => char >= 0x1CC0 && char <= 0x1CCF,
  15120. // 'Vedic Extensions': (char) => char >= 0x1CD0 && char <= 0x1CFF,
  15121. // 'Phonetic Extensions': (char) => char >= 0x1D00 && char <= 0x1D7F,
  15122. // 'Phonetic Extensions Supplement': (char) => char >= 0x1D80 && char <= 0x1DBF,
  15123. // 'Combining Diacritical Marks Supplement': (char) => char >= 0x1DC0 && char <= 0x1DFF,
  15124. // 'Latin Extended Additional': (char) => char >= 0x1E00 && char <= 0x1EFF,
  15125. // 'Greek Extended': (char) => char >= 0x1F00 && char <= 0x1FFF,
  15126. 'General Punctuation': function (char) {
  15127. return char >= 0x2000 && char <= 0x206F;
  15128. },
  15129. // 'Superscripts and Subscripts': (char) => char >= 0x2070 && char <= 0x209F,
  15130. // 'Currency Symbols': (char) => char >= 0x20A0 && char <= 0x20CF,
  15131. // 'Combining Diacritical Marks for Symbols': (char) => char >= 0x20D0 && char <= 0x20FF,
  15132. 'Letterlike Symbols': function (char) {
  15133. return char >= 0x2100 && char <= 0x214F;
  15134. },
  15135. 'Number Forms': function (char) {
  15136. return char >= 0x2150 && char <= 0x218F;
  15137. },
  15138. // 'Arrows': (char) => char >= 0x2190 && char <= 0x21FF,
  15139. // 'Mathematical Operators': (char) => char >= 0x2200 && char <= 0x22FF,
  15140. 'Miscellaneous Technical': function (char) {
  15141. return char >= 0x2300 && char <= 0x23FF;
  15142. },
  15143. 'Control Pictures': function (char) {
  15144. return char >= 0x2400 && char <= 0x243F;
  15145. },
  15146. 'Optical Character Recognition': function (char) {
  15147. return char >= 0x2440 && char <= 0x245F;
  15148. },
  15149. 'Enclosed Alphanumerics': function (char) {
  15150. return char >= 0x2460 && char <= 0x24FF;
  15151. },
  15152. // 'Box Drawing': (char) => char >= 0x2500 && char <= 0x257F,
  15153. // 'Block Elements': (char) => char >= 0x2580 && char <= 0x259F,
  15154. 'Geometric Shapes': function (char) {
  15155. return char >= 0x25A0 && char <= 0x25FF;
  15156. },
  15157. 'Miscellaneous Symbols': function (char) {
  15158. return char >= 0x2600 && char <= 0x26FF;
  15159. },
  15160. // 'Dingbats': (char) => char >= 0x2700 && char <= 0x27BF,
  15161. // 'Miscellaneous Mathematical Symbols-A': (char) => char >= 0x27C0 && char <= 0x27EF,
  15162. // 'Supplemental Arrows-A': (char) => char >= 0x27F0 && char <= 0x27FF,
  15163. // 'Braille Patterns': (char) => char >= 0x2800 && char <= 0x28FF,
  15164. // 'Supplemental Arrows-B': (char) => char >= 0x2900 && char <= 0x297F,
  15165. // 'Miscellaneous Mathematical Symbols-B': (char) => char >= 0x2980 && char <= 0x29FF,
  15166. // 'Supplemental Mathematical Operators': (char) => char >= 0x2A00 && char <= 0x2AFF,
  15167. 'Miscellaneous Symbols and Arrows': function (char) {
  15168. return char >= 0x2B00 && char <= 0x2BFF;
  15169. },
  15170. // 'Glagolitic': (char) => char >= 0x2C00 && char <= 0x2C5F,
  15171. // 'Latin Extended-C': (char) => char >= 0x2C60 && char <= 0x2C7F,
  15172. // 'Coptic': (char) => char >= 0x2C80 && char <= 0x2CFF,
  15173. // 'Georgian Supplement': (char) => char >= 0x2D00 && char <= 0x2D2F,
  15174. // 'Tifinagh': (char) => char >= 0x2D30 && char <= 0x2D7F,
  15175. // 'Ethiopic Extended': (char) => char >= 0x2D80 && char <= 0x2DDF,
  15176. // 'Cyrillic Extended-A': (char) => char >= 0x2DE0 && char <= 0x2DFF,
  15177. // 'Supplemental Punctuation': (char) => char >= 0x2E00 && char <= 0x2E7F,
  15178. 'CJK Radicals Supplement': function (char) {
  15179. return char >= 0x2E80 && char <= 0x2EFF;
  15180. },
  15181. 'Kangxi Radicals': function (char) {
  15182. return char >= 0x2F00 && char <= 0x2FDF;
  15183. },
  15184. 'Ideographic Description Characters': function (char) {
  15185. return char >= 0x2FF0 && char <= 0x2FFF;
  15186. },
  15187. 'CJK Symbols and Punctuation': function (char) {
  15188. return char >= 0x3000 && char <= 0x303F;
  15189. },
  15190. 'Hiragana': function (char) {
  15191. return char >= 0x3040 && char <= 0x309F;
  15192. },
  15193. 'Katakana': function (char) {
  15194. return char >= 0x30A0 && char <= 0x30FF;
  15195. },
  15196. 'Bopomofo': function (char) {
  15197. return char >= 0x3100 && char <= 0x312F;
  15198. },
  15199. 'Hangul Compatibility Jamo': function (char) {
  15200. return char >= 0x3130 && char <= 0x318F;
  15201. },
  15202. 'Kanbun': function (char) {
  15203. return char >= 0x3190 && char <= 0x319F;
  15204. },
  15205. 'Bopomofo Extended': function (char) {
  15206. return char >= 0x31A0 && char <= 0x31BF;
  15207. },
  15208. 'CJK Strokes': function (char) {
  15209. return char >= 0x31C0 && char <= 0x31EF;
  15210. },
  15211. 'Katakana Phonetic Extensions': function (char) {
  15212. return char >= 0x31F0 && char <= 0x31FF;
  15213. },
  15214. 'Enclosed CJK Letters and Months': function (char) {
  15215. return char >= 0x3200 && char <= 0x32FF;
  15216. },
  15217. 'CJK Compatibility': function (char) {
  15218. return char >= 0x3300 && char <= 0x33FF;
  15219. },
  15220. 'CJK Unified Ideographs Extension A': function (char) {
  15221. return char >= 0x3400 && char <= 0x4DBF;
  15222. },
  15223. 'Yijing Hexagram Symbols': function (char) {
  15224. return char >= 0x4DC0 && char <= 0x4DFF;
  15225. },
  15226. 'CJK Unified Ideographs': function (char) {
  15227. return char >= 0x4E00 && char <= 0x9FFF;
  15228. },
  15229. 'Yi Syllables': function (char) {
  15230. return char >= 0xA000 && char <= 0xA48F;
  15231. },
  15232. 'Yi Radicals': function (char) {
  15233. return char >= 0xA490 && char <= 0xA4CF;
  15234. },
  15235. // 'Lisu': (char) => char >= 0xA4D0 && char <= 0xA4FF,
  15236. // 'Vai': (char) => char >= 0xA500 && char <= 0xA63F,
  15237. // 'Cyrillic Extended-B': (char) => char >= 0xA640 && char <= 0xA69F,
  15238. // 'Bamum': (char) => char >= 0xA6A0 && char <= 0xA6FF,
  15239. // 'Modifier Tone Letters': (char) => char >= 0xA700 && char <= 0xA71F,
  15240. // 'Latin Extended-D': (char) => char >= 0xA720 && char <= 0xA7FF,
  15241. // 'Syloti Nagri': (char) => char >= 0xA800 && char <= 0xA82F,
  15242. // 'Common Indic Number Forms': (char) => char >= 0xA830 && char <= 0xA83F,
  15243. // 'Phags-pa': (char) => char >= 0xA840 && char <= 0xA87F,
  15244. // 'Saurashtra': (char) => char >= 0xA880 && char <= 0xA8DF,
  15245. // 'Devanagari Extended': (char) => char >= 0xA8E0 && char <= 0xA8FF,
  15246. // 'Kayah Li': (char) => char >= 0xA900 && char <= 0xA92F,
  15247. // 'Rejang': (char) => char >= 0xA930 && char <= 0xA95F,
  15248. 'Hangul Jamo Extended-A': function (char) {
  15249. return char >= 0xA960 && char <= 0xA97F;
  15250. },
  15251. // 'Javanese': (char) => char >= 0xA980 && char <= 0xA9DF,
  15252. // 'Myanmar Extended-B': (char) => char >= 0xA9E0 && char <= 0xA9FF,
  15253. // 'Cham': (char) => char >= 0xAA00 && char <= 0xAA5F,
  15254. // 'Myanmar Extended-A': (char) => char >= 0xAA60 && char <= 0xAA7F,
  15255. // 'Tai Viet': (char) => char >= 0xAA80 && char <= 0xAADF,
  15256. // 'Meetei Mayek Extensions': (char) => char >= 0xAAE0 && char <= 0xAAFF,
  15257. // 'Ethiopic Extended-A': (char) => char >= 0xAB00 && char <= 0xAB2F,
  15258. // 'Latin Extended-E': (char) => char >= 0xAB30 && char <= 0xAB6F,
  15259. // 'Cherokee Supplement': (char) => char >= 0xAB70 && char <= 0xABBF,
  15260. // 'Meetei Mayek': (char) => char >= 0xABC0 && char <= 0xABFF,
  15261. 'Hangul Syllables': function (char) {
  15262. return char >= 0xAC00 && char <= 0xD7AF;
  15263. },
  15264. 'Hangul Jamo Extended-B': function (char) {
  15265. return char >= 0xD7B0 && char <= 0xD7FF;
  15266. },
  15267. // 'High Surrogates': (char) => char >= 0xD800 && char <= 0xDB7F,
  15268. // 'High Private Use Surrogates': (char) => char >= 0xDB80 && char <= 0xDBFF,
  15269. // 'Low Surrogates': (char) => char >= 0xDC00 && char <= 0xDFFF,
  15270. 'Private Use Area': function (char) {
  15271. return char >= 0xE000 && char <= 0xF8FF;
  15272. },
  15273. 'CJK Compatibility Ideographs': function (char) {
  15274. return char >= 0xF900 && char <= 0xFAFF;
  15275. },
  15276. // 'Alphabetic Presentation Forms': (char) => char >= 0xFB00 && char <= 0xFB4F,
  15277. 'Arabic Presentation Forms-A': function (char) {
  15278. return char >= 0xFB50 && char <= 0xFDFF;
  15279. },
  15280. // 'Variation Selectors': (char) => char >= 0xFE00 && char <= 0xFE0F,
  15281. 'Vertical Forms': function (char) {
  15282. return char >= 0xFE10 && char <= 0xFE1F;
  15283. },
  15284. // 'Combining Half Marks': (char) => char >= 0xFE20 && char <= 0xFE2F,
  15285. 'CJK Compatibility Forms': function (char) {
  15286. return char >= 0xFE30 && char <= 0xFE4F;
  15287. },
  15288. 'Small Form Variants': function (char) {
  15289. return char >= 0xFE50 && char <= 0xFE6F;
  15290. },
  15291. 'Arabic Presentation Forms-B': function (char) {
  15292. return char >= 0xFE70 && char <= 0xFEFF;
  15293. },
  15294. 'Halfwidth and Fullwidth Forms': function (char) {
  15295. return char >= 0xFF00 && char <= 0xFFEF;
  15296. }
  15297. // 'Specials': (char) => char >= 0xFFF0 && char <= 0xFFFF,
  15298. // 'Linear B Syllabary': (char) => char >= 0x10000 && char <= 0x1007F,
  15299. // 'Linear B Ideograms': (char) => char >= 0x10080 && char <= 0x100FF,
  15300. // 'Aegean Numbers': (char) => char >= 0x10100 && char <= 0x1013F,
  15301. // 'Ancient Greek Numbers': (char) => char >= 0x10140 && char <= 0x1018F,
  15302. // 'Ancient Symbols': (char) => char >= 0x10190 && char <= 0x101CF,
  15303. // 'Phaistos Disc': (char) => char >= 0x101D0 && char <= 0x101FF,
  15304. // 'Lycian': (char) => char >= 0x10280 && char <= 0x1029F,
  15305. // 'Carian': (char) => char >= 0x102A0 && char <= 0x102DF,
  15306. // 'Coptic Epact Numbers': (char) => char >= 0x102E0 && char <= 0x102FF,
  15307. // 'Old Italic': (char) => char >= 0x10300 && char <= 0x1032F,
  15308. // 'Gothic': (char) => char >= 0x10330 && char <= 0x1034F,
  15309. // 'Old Permic': (char) => char >= 0x10350 && char <= 0x1037F,
  15310. // 'Ugaritic': (char) => char >= 0x10380 && char <= 0x1039F,
  15311. // 'Old Persian': (char) => char >= 0x103A0 && char <= 0x103DF,
  15312. // 'Deseret': (char) => char >= 0x10400 && char <= 0x1044F,
  15313. // 'Shavian': (char) => char >= 0x10450 && char <= 0x1047F,
  15314. // 'Osmanya': (char) => char >= 0x10480 && char <= 0x104AF,
  15315. // 'Osage': (char) => char >= 0x104B0 && char <= 0x104FF,
  15316. // 'Elbasan': (char) => char >= 0x10500 && char <= 0x1052F,
  15317. // 'Caucasian Albanian': (char) => char >= 0x10530 && char <= 0x1056F,
  15318. // 'Linear A': (char) => char >= 0x10600 && char <= 0x1077F,
  15319. // 'Cypriot Syllabary': (char) => char >= 0x10800 && char <= 0x1083F,
  15320. // 'Imperial Aramaic': (char) => char >= 0x10840 && char <= 0x1085F,
  15321. // 'Palmyrene': (char) => char >= 0x10860 && char <= 0x1087F,
  15322. // 'Nabataean': (char) => char >= 0x10880 && char <= 0x108AF,
  15323. // 'Hatran': (char) => char >= 0x108E0 && char <= 0x108FF,
  15324. // 'Phoenician': (char) => char >= 0x10900 && char <= 0x1091F,
  15325. // 'Lydian': (char) => char >= 0x10920 && char <= 0x1093F,
  15326. // 'Meroitic Hieroglyphs': (char) => char >= 0x10980 && char <= 0x1099F,
  15327. // 'Meroitic Cursive': (char) => char >= 0x109A0 && char <= 0x109FF,
  15328. // 'Kharoshthi': (char) => char >= 0x10A00 && char <= 0x10A5F,
  15329. // 'Old South Arabian': (char) => char >= 0x10A60 && char <= 0x10A7F,
  15330. // 'Old North Arabian': (char) => char >= 0x10A80 && char <= 0x10A9F,
  15331. // 'Manichaean': (char) => char >= 0x10AC0 && char <= 0x10AFF,
  15332. // 'Avestan': (char) => char >= 0x10B00 && char <= 0x10B3F,
  15333. // 'Inscriptional Parthian': (char) => char >= 0x10B40 && char <= 0x10B5F,
  15334. // 'Inscriptional Pahlavi': (char) => char >= 0x10B60 && char <= 0x10B7F,
  15335. // 'Psalter Pahlavi': (char) => char >= 0x10B80 && char <= 0x10BAF,
  15336. // 'Old Turkic': (char) => char >= 0x10C00 && char <= 0x10C4F,
  15337. // 'Old Hungarian': (char) => char >= 0x10C80 && char <= 0x10CFF,
  15338. // 'Hanifi Rohingya': (char) => char >= 0x10D00 && char <= 0x10D3F,
  15339. // 'Rumi Numeral Symbols': (char) => char >= 0x10E60 && char <= 0x10E7F,
  15340. // 'Old Sogdian': (char) => char >= 0x10F00 && char <= 0x10F2F,
  15341. // 'Sogdian': (char) => char >= 0x10F30 && char <= 0x10F6F,
  15342. // 'Elymaic': (char) => char >= 0x10FE0 && char <= 0x10FFF,
  15343. // 'Brahmi': (char) => char >= 0x11000 && char <= 0x1107F,
  15344. // 'Kaithi': (char) => char >= 0x11080 && char <= 0x110CF,
  15345. // 'Sora Sompeng': (char) => char >= 0x110D0 && char <= 0x110FF,
  15346. // 'Chakma': (char) => char >= 0x11100 && char <= 0x1114F,
  15347. // 'Mahajani': (char) => char >= 0x11150 && char <= 0x1117F,
  15348. // 'Sharada': (char) => char >= 0x11180 && char <= 0x111DF,
  15349. // 'Sinhala Archaic Numbers': (char) => char >= 0x111E0 && char <= 0x111FF,
  15350. // 'Khojki': (char) => char >= 0x11200 && char <= 0x1124F,
  15351. // 'Multani': (char) => char >= 0x11280 && char <= 0x112AF,
  15352. // 'Khudawadi': (char) => char >= 0x112B0 && char <= 0x112FF,
  15353. // 'Grantha': (char) => char >= 0x11300 && char <= 0x1137F,
  15354. // 'Newa': (char) => char >= 0x11400 && char <= 0x1147F,
  15355. // 'Tirhuta': (char) => char >= 0x11480 && char <= 0x114DF,
  15356. // 'Siddham': (char) => char >= 0x11580 && char <= 0x115FF,
  15357. // 'Modi': (char) => char >= 0x11600 && char <= 0x1165F,
  15358. // 'Mongolian Supplement': (char) => char >= 0x11660 && char <= 0x1167F,
  15359. // 'Takri': (char) => char >= 0x11680 && char <= 0x116CF,
  15360. // 'Ahom': (char) => char >= 0x11700 && char <= 0x1173F,
  15361. // 'Dogra': (char) => char >= 0x11800 && char <= 0x1184F,
  15362. // 'Warang Citi': (char) => char >= 0x118A0 && char <= 0x118FF,
  15363. // 'Nandinagari': (char) => char >= 0x119A0 && char <= 0x119FF,
  15364. // 'Zanabazar Square': (char) => char >= 0x11A00 && char <= 0x11A4F,
  15365. // 'Soyombo': (char) => char >= 0x11A50 && char <= 0x11AAF,
  15366. // 'Pau Cin Hau': (char) => char >= 0x11AC0 && char <= 0x11AFF,
  15367. // 'Bhaiksuki': (char) => char >= 0x11C00 && char <= 0x11C6F,
  15368. // 'Marchen': (char) => char >= 0x11C70 && char <= 0x11CBF,
  15369. // 'Masaram Gondi': (char) => char >= 0x11D00 && char <= 0x11D5F,
  15370. // 'Gunjala Gondi': (char) => char >= 0x11D60 && char <= 0x11DAF,
  15371. // 'Makasar': (char) => char >= 0x11EE0 && char <= 0x11EFF,
  15372. // 'Tamil Supplement': (char) => char >= 0x11FC0 && char <= 0x11FFF,
  15373. // 'Cuneiform': (char) => char >= 0x12000 && char <= 0x123FF,
  15374. // 'Cuneiform Numbers and Punctuation': (char) => char >= 0x12400 && char <= 0x1247F,
  15375. // 'Early Dynastic Cuneiform': (char) => char >= 0x12480 && char <= 0x1254F,
  15376. // 'Egyptian Hieroglyphs': (char) => char >= 0x13000 && char <= 0x1342F,
  15377. // 'Egyptian Hieroglyph Format Controls': (char) => char >= 0x13430 && char <= 0x1343F,
  15378. // 'Anatolian Hieroglyphs': (char) => char >= 0x14400 && char <= 0x1467F,
  15379. // 'Bamum Supplement': (char) => char >= 0x16800 && char <= 0x16A3F,
  15380. // 'Mro': (char) => char >= 0x16A40 && char <= 0x16A6F,
  15381. // 'Bassa Vah': (char) => char >= 0x16AD0 && char <= 0x16AFF,
  15382. // 'Pahawh Hmong': (char) => char >= 0x16B00 && char <= 0x16B8F,
  15383. // 'Medefaidrin': (char) => char >= 0x16E40 && char <= 0x16E9F,
  15384. // 'Miao': (char) => char >= 0x16F00 && char <= 0x16F9F,
  15385. // 'Ideographic Symbols and Punctuation': (char) => char >= 0x16FE0 && char <= 0x16FFF,
  15386. // 'Tangut': (char) => char >= 0x17000 && char <= 0x187FF,
  15387. // 'Tangut Components': (char) => char >= 0x18800 && char <= 0x18AFF,
  15388. // 'Kana Supplement': (char) => char >= 0x1B000 && char <= 0x1B0FF,
  15389. // 'Kana Extended-A': (char) => char >= 0x1B100 && char <= 0x1B12F,
  15390. // 'Small Kana Extension': (char) => char >= 0x1B130 && char <= 0x1B16F,
  15391. // 'Nushu': (char) => char >= 0x1B170 && char <= 0x1B2FF,
  15392. // 'Duployan': (char) => char >= 0x1BC00 && char <= 0x1BC9F,
  15393. // 'Shorthand Format Controls': (char) => char >= 0x1BCA0 && char <= 0x1BCAF,
  15394. // 'Byzantine Musical Symbols': (char) => char >= 0x1D000 && char <= 0x1D0FF,
  15395. // 'Musical Symbols': (char) => char >= 0x1D100 && char <= 0x1D1FF,
  15396. // 'Ancient Greek Musical Notation': (char) => char >= 0x1D200 && char <= 0x1D24F,
  15397. // 'Mayan Numerals': (char) => char >= 0x1D2E0 && char <= 0x1D2FF,
  15398. // 'Tai Xuan Jing Symbols': (char) => char >= 0x1D300 && char <= 0x1D35F,
  15399. // 'Counting Rod Numerals': (char) => char >= 0x1D360 && char <= 0x1D37F,
  15400. // 'Mathematical Alphanumeric Symbols': (char) => char >= 0x1D400 && char <= 0x1D7FF,
  15401. // 'Sutton SignWriting': (char) => char >= 0x1D800 && char <= 0x1DAAF,
  15402. // 'Glagolitic Supplement': (char) => char >= 0x1E000 && char <= 0x1E02F,
  15403. // 'Nyiakeng Puachue Hmong': (char) => char >= 0x1E100 && char <= 0x1E14F,
  15404. // 'Wancho': (char) => char >= 0x1E2C0 && char <= 0x1E2FF,
  15405. // 'Mende Kikakui': (char) => char >= 0x1E800 && char <= 0x1E8DF,
  15406. // 'Adlam': (char) => char >= 0x1E900 && char <= 0x1E95F,
  15407. // 'Indic Siyaq Numbers': (char) => char >= 0x1EC70 && char <= 0x1ECBF,
  15408. // 'Ottoman Siyaq Numbers': (char) => char >= 0x1ED00 && char <= 0x1ED4F,
  15409. // 'Arabic Mathematical Alphabetic Symbols': (char) => char >= 0x1EE00 && char <= 0x1EEFF,
  15410. // 'Mahjong Tiles': (char) => char >= 0x1F000 && char <= 0x1F02F,
  15411. // 'Domino Tiles': (char) => char >= 0x1F030 && char <= 0x1F09F,
  15412. // 'Playing Cards': (char) => char >= 0x1F0A0 && char <= 0x1F0FF,
  15413. // 'Enclosed Alphanumeric Supplement': (char) => char >= 0x1F100 && char <= 0x1F1FF,
  15414. // 'Enclosed Ideographic Supplement': (char) => char >= 0x1F200 && char <= 0x1F2FF,
  15415. // 'Miscellaneous Symbols and Pictographs': (char) => char >= 0x1F300 && char <= 0x1F5FF,
  15416. // 'Emoticons': (char) => char >= 0x1F600 && char <= 0x1F64F,
  15417. // 'Ornamental Dingbats': (char) => char >= 0x1F650 && char <= 0x1F67F,
  15418. // 'Transport and Map Symbols': (char) => char >= 0x1F680 && char <= 0x1F6FF,
  15419. // 'Alchemical Symbols': (char) => char >= 0x1F700 && char <= 0x1F77F,
  15420. // 'Geometric Shapes Extended': (char) => char >= 0x1F780 && char <= 0x1F7FF,
  15421. // 'Supplemental Arrows-C': (char) => char >= 0x1F800 && char <= 0x1F8FF,
  15422. // 'Supplemental Symbols and Pictographs': (char) => char >= 0x1F900 && char <= 0x1F9FF,
  15423. // 'Chess Symbols': (char) => char >= 0x1FA00 && char <= 0x1FA6F,
  15424. // 'Symbols and Pictographs Extended-A': (char) => char >= 0x1FA70 && char <= 0x1FAFF,
  15425. // 'CJK Unified Ideographs Extension B': (char) => char >= 0x20000 && char <= 0x2A6DF,
  15426. // 'CJK Unified Ideographs Extension C': (char) => char >= 0x2A700 && char <= 0x2B73F,
  15427. // 'CJK Unified Ideographs Extension D': (char) => char >= 0x2B740 && char <= 0x2B81F,
  15428. // 'CJK Unified Ideographs Extension E': (char) => char >= 0x2B820 && char <= 0x2CEAF,
  15429. // 'CJK Unified Ideographs Extension F': (char) => char >= 0x2CEB0 && char <= 0x2EBEF,
  15430. // 'CJK Compatibility Ideographs Supplement': (char) => char >= 0x2F800 && char <= 0x2FA1F,
  15431. // 'Tags': (char) => char >= 0xE0000 && char <= 0xE007F,
  15432. // 'Variation Selectors Supplement': (char) => char >= 0xE0100 && char <= 0xE01EF,
  15433. // 'Supplementary Private Use Area-A': (char) => char >= 0xF0000 && char <= 0xFFFFF,
  15434. // 'Supplementary Private Use Area-B': (char) => char >= 0x100000 && char <= 0x10FFFF,
  15435. };
  15436. var ScriptDetection = function ScriptDetection() {
  15437. };
  15438. ScriptDetection.allowsVerticalWritingMode = function(chars){
  15439. for (var i = 0, list = chars; i < list.length; i += 1) {
  15440. var char = list[i];
  15441. if (charHasUprightVerticalOrientation(char.charCodeAt(0))) {
  15442. return true;
  15443. }
  15444. }
  15445. return false;
  15446. };
  15447. ScriptDetection.allowsLetterSpacing = function(chars){
  15448. for (var i = 0, list = chars; i < list.length; i += 1) {
  15449. var char = list[i];
  15450. if (!charAllowsLetterSpacing(char.charCodeAt(0))) {
  15451. return false;
  15452. }
  15453. }
  15454. return true;
  15455. };
  15456. function charAllowsLetterSpacing(char) {
  15457. if (unicodeBlockLookup['Arabic'](char)) {
  15458. return false;
  15459. }
  15460. if (unicodeBlockLookup['Arabic Supplement'](char)) {
  15461. return false;
  15462. }
  15463. if (unicodeBlockLookup['Arabic Extended-A'](char)) {
  15464. return false;
  15465. }
  15466. if (unicodeBlockLookup['Arabic Presentation Forms-A'](char)) {
  15467. return false;
  15468. }
  15469. if (unicodeBlockLookup['Arabic Presentation Forms-B'](char)) {
  15470. return false;
  15471. }
  15472. return true;
  15473. }
  15474. // The following logic comes from
  15475. // <http://www.unicode.org/Public/12.0.0/ucd/VerticalOrientation.txt>.
  15476. // Keep it synchronized with
  15477. // <http://www.unicode.org/Public/UCD/latest/ucd/VerticalOrientation.txt>.
  15478. // The data file denotes with “U” or “Tu” any codepoint that may be drawn
  15479. // upright in vertical text but does not distinguish between upright and
  15480. // “neutral” characters.
  15481. // Blocks in the Unicode supplementary planes are excluded from this module due
  15482. // to <https://github.com/mapbox/mapbox-gl/issues/29>.
  15483. /**
  15484. * Returns true if the given Unicode codepoint identifies a character with
  15485. * upright orientation.
  15486. *
  15487. * A character has upright orientation if it is drawn upright (unrotated)
  15488. * whether the line is oriented horizontally or vertically, even if both
  15489. * adjacent characters can be rotated. For example, a Chinese character is
  15490. * always drawn upright. An uprightly oriented character causes an adjacent
  15491. * “neutral” character to be drawn upright as well.
  15492. * @private
  15493. */
  15494. function charHasUprightVerticalOrientation(char) {
  15495. if (char === 0x02EA /* modifier letter yin departing tone mark */ ||
  15496. char === 0x02EB /* modifier letter yang departing tone mark */) {
  15497. return true;
  15498. }
  15499. // Return early for characters outside all ranges whose characters remain
  15500. // upright in vertical writing mode.
  15501. if (char < 0x1100) {
  15502. return false;
  15503. }
  15504. if (unicodeBlockLookup['Bopomofo Extended'](char)) {
  15505. return true;
  15506. }
  15507. if (unicodeBlockLookup['Bopomofo'](char)) {
  15508. return true;
  15509. }
  15510. if (unicodeBlockLookup['CJK Compatibility Forms'](char)) {
  15511. if (!((char >= 0xFE49 /* dashed overline */ && char <= 0xFE4F) /* wavy low line */)) {
  15512. return true;
  15513. }
  15514. }
  15515. if (unicodeBlockLookup['CJK Compatibility Ideographs'](char)) {
  15516. return true;
  15517. }
  15518. if (unicodeBlockLookup['CJK Compatibility'](char)) {
  15519. return true;
  15520. }
  15521. if (unicodeBlockLookup['CJK Radicals Supplement'](char)) {
  15522. return true;
  15523. }
  15524. if (unicodeBlockLookup['CJK Strokes'](char)) {
  15525. return true;
  15526. }
  15527. if (unicodeBlockLookup['CJK Symbols and Punctuation'](char)) {
  15528. 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 */) &&
  15529. char !== 0x3030 /* wavy dash */) {
  15530. return true;
  15531. }
  15532. }
  15533. if (unicodeBlockLookup['CJK Unified Ideographs Extension A'](char)) {
  15534. return true;
  15535. }
  15536. if (unicodeBlockLookup['CJK Unified Ideographs'](char)) {
  15537. return true;
  15538. }
  15539. if (unicodeBlockLookup['Enclosed CJK Letters and Months'](char)) {
  15540. return true;
  15541. }
  15542. if (unicodeBlockLookup['Hangul Compatibility Jamo'](char)) {
  15543. return true;
  15544. }
  15545. if (unicodeBlockLookup['Hangul Jamo Extended-A'](char)) {
  15546. return true;
  15547. }
  15548. if (unicodeBlockLookup['Hangul Jamo Extended-B'](char)) {
  15549. return true;
  15550. }
  15551. if (unicodeBlockLookup['Hangul Jamo'](char)) {
  15552. return true;
  15553. }
  15554. if (unicodeBlockLookup['Hangul Syllables'](char)) {
  15555. return true;
  15556. }
  15557. if (unicodeBlockLookup['Hiragana'](char)) {
  15558. return true;
  15559. }
  15560. if (unicodeBlockLookup['Ideographic Description Characters'](char)) {
  15561. return true;
  15562. }
  15563. if (unicodeBlockLookup['Kanbun'](char)) {
  15564. return true;
  15565. }
  15566. if (unicodeBlockLookup['Kangxi Radicals'](char)) {
  15567. return true;
  15568. }
  15569. if (unicodeBlockLookup['Katakana Phonetic Extensions'](char)) {
  15570. return true;
  15571. }
  15572. if (unicodeBlockLookup['Katakana'](char)) {
  15573. if (char !== 0x30FC /* katakana-hiragana prolonged sound mark */) {
  15574. return true;
  15575. }
  15576. }
  15577. if (unicodeBlockLookup['Halfwidth and Fullwidth Forms'](char)) {
  15578. if (char !== 0xFF08 /* fullwidth left parenthesis */ &&
  15579. char !== 0xFF09 /* fullwidth right parenthesis */ &&
  15580. char !== 0xFF0D /* fullwidth hyphen-minus */ && !((char >= 0xFF1A /* fullwidth colon */ && char <= 0xFF1E) /* fullwidth greater-than sign */) &&
  15581. char !== 0xFF3B /* fullwidth left square bracket */ &&
  15582. char !== 0xFF3D /* fullwidth right square bracket */ &&
  15583. char !== 0xFF3F /* fullwidth low line */ && !(char >= 0xFF5B /* fullwidth left curly bracket */ && char <= 0xFFDF) &&
  15584. char !== 0xFFE3 /* fullwidth macron */ && !(char >= 0xFFE8 /* halfwidth forms light vertical */ && char <= 0xFFEF)) {
  15585. return true;
  15586. }
  15587. }
  15588. if (unicodeBlockLookup['Small Form Variants'](char)) {
  15589. if (!((char >= 0xFE58 /* small em dash */ && char <= 0xFE5E) /* small right tortoise shell bracket */) && !((char >= 0xFE63 /* small hyphen-minus */ && char <= 0xFE66) /* small equals sign */)) {
  15590. return true;
  15591. }
  15592. }
  15593. if (unicodeBlockLookup['Unified Canadian Aboriginal Syllabics'](char)) {
  15594. return true;
  15595. }
  15596. if (unicodeBlockLookup['Unified Canadian Aboriginal Syllabics Extended'](char)) {
  15597. return true;
  15598. }
  15599. if (unicodeBlockLookup['Vertical Forms'](char)) {
  15600. return true;
  15601. }
  15602. if (unicodeBlockLookup['Yijing Hexagram Symbols'](char)) {
  15603. return true;
  15604. }
  15605. if (unicodeBlockLookup['Yi Syllables'](char)) {
  15606. return true;
  15607. }
  15608. if (unicodeBlockLookup['Yi Radicals'](char)) {
  15609. return true;
  15610. }
  15611. return false;
  15612. }
  15613. function charInRTLScript(char) {
  15614. // Main blocks for Hebrew, Arabic, Thaana and other RTL scripts
  15615. return (char >= 0x0590 && char <= 0x08FF) ||
  15616. unicodeBlockLookup['Arabic Presentation Forms-A'](char) ||
  15617. unicodeBlockLookup['Arabic Presentation Forms-B'](char);
  15618. }
  15619. ScriptDetection.stringContainsRTLText = function(chars){
  15620. for (var i = 0, list = chars; i < list.length; i += 1) {
  15621. var char = list[i];
  15622. if (charInRTLScript(char.charCodeAt(0))) {
  15623. return true;
  15624. }
  15625. }
  15626. return false;
  15627. };
  15628. var vectorTileFeatureTypes$2 = ['Unknown', 'Point', 'LineString', 'Polygon'];
  15629. // Opacity arrays are frequently updated but don't contain a lot of information, so we pack them
  15630. // tight. Each Uint32 is actually four duplicate Uint8s for the four corners of a glyph
  15631. // 7 bits are for the current opacity, and the lowest bit is the target opacity
  15632. // actually defined in symbol_attributes.js
  15633. // const placementOpacityAttributes = [
  15634. // { name: 'a_fade_opacity', components: 1, type: 'Uint32' }
  15635. // ];
  15636. var shaderOpacityAttributes = [
  15637. {name: 'a_fade_opacity', components: 1, type: 'Uint8', offset: 0}
  15638. ];
  15639. function addVertex$1(array, anchorX, anchorY, ox, oy, tx, ty, sizeVertex, isSDF, pixelOffsetX, pixelOffsetY, minFontScaleX, minFontScaleY) {
  15640. var aSizeX = sizeVertex ? Math.min(MAX_PACKED_SIZE, Math.round(sizeVertex[0])) : 0;
  15641. var aSizeY = sizeVertex ? Math.min(MAX_PACKED_SIZE, Math.round(sizeVertex[1])) : 0;
  15642. array.emplaceBack(
  15643. // a_pos_offset
  15644. anchorX,
  15645. anchorY,
  15646. Math.round(ox * 32),
  15647. Math.round(oy * 32),
  15648. // a_data
  15649. tx, // x coordinate of symbol on glyph atlas texture
  15650. ty, // y coordinate of symbol on glyph atlas texture
  15651. (aSizeX << 1) + (isSDF ? 1 : 0),
  15652. aSizeY,
  15653. pixelOffsetX * 16,
  15654. pixelOffsetY * 16,
  15655. minFontScaleX * 256,
  15656. minFontScaleY * 256
  15657. );
  15658. }
  15659. function addDynamicAttributes(dynamicLayoutVertexArray, p, angle) {
  15660. dynamicLayoutVertexArray.emplaceBack(p.x, p.y, angle);
  15661. dynamicLayoutVertexArray.emplaceBack(p.x, p.y, angle);
  15662. dynamicLayoutVertexArray.emplaceBack(p.x, p.y, angle);
  15663. dynamicLayoutVertexArray.emplaceBack(p.x, p.y, angle);
  15664. }
  15665. function containsRTLText(formattedText) {
  15666. for (var i = 0, list = formattedText.sections; i < list.length; i += 1) {
  15667. var section = list[i];
  15668. if (ScriptDetection.stringContainsRTLText(section.text)) {
  15669. return true;
  15670. }
  15671. }
  15672. return false;
  15673. }
  15674. var SymbolBuffers = function SymbolBuffers(programConfigurations) {
  15675. this.layoutVertexArray = new StructArrayLayout4i4ui4i24();
  15676. this.indexArray = new StructArrayLayout3ui6();
  15677. this.programConfigurations = programConfigurations;
  15678. this.segments = new SegmentVector();
  15679. this.dynamicLayoutVertexArray = new StructArrayLayout3f12();
  15680. this.opacityVertexArray = new StructArrayLayout1ul4();
  15681. this.placedSymbolArray = new PlacedSymbolArray();
  15682. };
  15683. SymbolBuffers.prototype.upload = function upload(context, dynamicIndexBuffer, upload$1, update) {
  15684. if (upload$1) {
  15685. this.layoutVertexBuffer = context.createVertexBuffer(this.layoutVertexArray, SymbolAttributes.symbolLayoutAttributes.members);
  15686. this.indexBuffer = context.createIndexBuffer(this.indexArray, dynamicIndexBuffer);
  15687. this.dynamicLayoutVertexBuffer = context.createVertexBuffer(this.dynamicLayoutVertexArray, SymbolAttributes.dynamicLayoutAttributes.members, true);
  15688. this.opacityVertexBuffer = context.createVertexBuffer(this.opacityVertexArray, shaderOpacityAttributes, true);
  15689. // This is a performance hack so that we can write to opacityVertexArray with uint32s
  15690. // even though the shaders read uint8s
  15691. this.opacityVertexBuffer.itemSize = 1;
  15692. }
  15693. if (upload$1 || update) {
  15694. this.programConfigurations.upload(context);
  15695. }
  15696. };
  15697. SymbolBuffers.prototype.destroy = function destroy() {
  15698. if (!this.layoutVertexBuffer) {
  15699. return;
  15700. }
  15701. this.layoutVertexBuffer.destroy();
  15702. this.indexBuffer.destroy();
  15703. this.programConfigurations.destroy();
  15704. this.segments.destroy();
  15705. this.dynamicLayoutVertexBuffer.destroy();
  15706. this.opacityVertexBuffer.destroy();
  15707. };
  15708. SymbolBuffers.prototype.clear = function clear() {
  15709. };
  15710. WebWorkerTransfer.register('SymbolBuffers', SymbolBuffers);
  15711. var CollisionBuffers = function CollisionBuffers(LayoutArray, layoutAttributes, IndexArray) {
  15712. this.layoutVertexArray = new LayoutArray();
  15713. this.layoutAttributes = layoutAttributes;
  15714. this.indexArray = new IndexArray();
  15715. this.segments = new SegmentVector();
  15716. this.collisionVertexArray = new StructArrayLayout2ub2f12();
  15717. };
  15718. CollisionBuffers.prototype.upload = function upload(context) {
  15719. this.layoutVertexBuffer = context.createVertexBuffer(this.layoutVertexArray, this.layoutAttributes);
  15720. this.indexBuffer = context.createIndexBuffer(this.indexArray);
  15721. this.collisionVertexBuffer = context.createVertexBuffer(this.collisionVertexArray, collisionVertexAttributes.members, true);
  15722. };
  15723. CollisionBuffers.prototype.destroy = function destroy() {
  15724. if (!this.layoutVertexBuffer) {
  15725. return;
  15726. }
  15727. this.layoutVertexBuffer.destroy();
  15728. this.indexBuffer.destroy();
  15729. this.segments.destroy();
  15730. this.collisionVertexBuffer.destroy();
  15731. };
  15732. WebWorkerTransfer.register('CollisionBuffers', CollisionBuffers);
  15733. /**
  15734. * Unlike other buckets, which simply implement #addFeature with type-specific
  15735. * logic for (essentially) triangulating feature geometries, SymbolBucket
  15736. * requires specialized behavior:
  15737. *
  15738. * 1. WorkerTile#parse(), the logical owner of the bucket creation process,
  15739. * calls SymbolBucket#populate(), which resolves text and icon tokens on
  15740. * each feature, adds each glyphs and symbols needed to the passed-in
  15741. * collections options.glyphDependencies and options.iconDependencies, and
  15742. * stores the feature data for use in subsequent step (this.features).
  15743. *
  15744. * 2. WorkerTile asynchronously requests from the main thread all of the glyphs
  15745. * and icons needed (by this bucket and any others). When glyphs and icons
  15746. * have been received, the WorkerTile creates a CollisionIndex and invokes:
  15747. *
  15748. * 3. performSymbolLayout(bucket, stacks, icons) perform texts shaping and
  15749. * layout on a Symbol Bucket. This step populates:
  15750. * `this.symbolInstances`: metadata on generated symbols
  15751. * `this.collisionBoxArray`: collision data for use by foreground
  15752. * `this.text`: SymbolBuffers for text symbols
  15753. * `this.icons`: SymbolBuffers for icons
  15754. * `this.iconCollisionBox`: Debug SymbolBuffers for icon collision boxes
  15755. * `this.textCollisionBox`: Debug SymbolBuffers for text collision boxes
  15756. * `this.iconCollisionCircle`: Debug SymbolBuffers for icon collision circles
  15757. * `this.textCollisionCircle`: Debug SymbolBuffers for text collision circles
  15758. * The results are sent to the foreground for rendering
  15759. *
  15760. * 4. performSymbolPlacement(bucket, collisionIndex) is run on the foreground,
  15761. * and uses the CollisionIndex along with current camera settings to determine
  15762. * which symbols can actually show on the map. Collided symbols are hidden
  15763. * using a dynamic "OpacityVertexArray".
  15764. *
  15765. * @private
  15766. */
  15767. var SymbolBucket = function SymbolBucket(options) {
  15768. this.collisionBoxArray = options.collisionBoxArray;
  15769. this.zoom = options.zoom;
  15770. this.overscaling = options.overscaling;
  15771. this.layers = options.layers;
  15772. this.layerIds = this.layers.map(function (layer) {
  15773. return layer.id;
  15774. });
  15775. this.index = options.index;
  15776. this.pixelRatio = options.pixelRatio;
  15777. this.sourceLayerIndex = options.sourceLayerIndex;
  15778. this.hasPattern = false;
  15779. this.hasPaintOverrides = false;
  15780. this.hasRTLText = false;
  15781. var layer = this.layers[0];
  15782. var unevaluatedLayoutValues = layer._unevaluatedLayout._values;
  15783. this.textSizeData = symbolSize.getSizeData(this.zoom, unevaluatedLayoutValues['text-size']);
  15784. this.iconSizeData = symbolSize.getSizeData(this.zoom, unevaluatedLayoutValues['icon-size']);
  15785. var layout = this.layers[0].layout;
  15786. var sortKey = layout.get('symbol-sort-key');
  15787. var zOrder = layout.get('symbol-z-order');
  15788. this.sortFeaturesByKey = zOrder !== 'viewport-y' && sortKey.constantOr(1) !== undefined;
  15789. var zOrderByViewportY = zOrder === 'viewport-y' || (zOrder === 'auto' && !this.sortFeaturesByKey);
  15790. this.sortFeaturesByY = zOrderByViewportY && (layout.get('text-allow-overlap') || layout.get('icon-allow-overlap') ||
  15791. layout.get('text-ignore-placement') || layout.get('icon-ignore-placement'));
  15792. if (layout.get('symbol-placement') === 'point') {
  15793. this.writingModes = layout.get('text-writing-mode').map(function (wm) {
  15794. return Shaping.WritingMode[wm];
  15795. });
  15796. }
  15797. this.stateDependentLayerIds = this.layers.filter(function (l) {
  15798. return l.isStateDependent();
  15799. }).map(function (l) {
  15800. return l.id;
  15801. });
  15802. this.sourceID = options.sourceID;
  15803. };
  15804. SymbolBucket.prototype.createArrays = function createArrays() {
  15805. // var layout = this.layers[0].layout;
  15806. // //this.hasPaintOverrides = SymbolStyleLayer.hasPaintOverrides(layout);
  15807. // this.hasPaintOverrides = false;
  15808. //
  15809. // this.text = new SymbolBuffers(new ProgramConfigurationSet(SymbolAttributes.symbolLayoutAttributes.members, this.layers, this.zoom, function (property) {
  15810. // return /^text/.test(property);
  15811. // }));
  15812. // this.icon = new SymbolBuffers(new ProgramConfigurationSet(SymbolAttributes.symbolLayoutAttributes.members, this.layers, this.zoom, function (property) {
  15813. // return /^icon/.test(property);
  15814. // }));
  15815. //
  15816. // this.textCollisionBox = new CollisionBuffers(StructArrayLayout2i2i2i12, SymbolAttributes.collisionBoxLayout.members, StructArrayLayout2ui4);
  15817. // this.iconCollisionBox = new CollisionBuffers(StructArrayLayout2i2i2i12, SymbolAttributes.collisionBoxLayout.members, StructArrayLayout2ui4);
  15818. // this.textCollisionCircle = new CollisionBuffers(StructArrayLayout2i2i2i12, SymbolAttributes.collisionCircleLayout.members, StructArrayLayout3ui6);
  15819. // this.iconCollisionCircle = new CollisionBuffers(StructArrayLayout2i2i2i12, SymbolAttributes.collisionCircleLayout.members, StructArrayLayout3ui6);
  15820. //
  15821. // this.glyphOffsetArray = new GlyphOffsetArray();
  15822. // this.lineVertexArray = new SymbolLineVertexArray();
  15823. // this.symbolInstances = new SymbolInstanceArray();
  15824. };
  15825. SymbolBucket.prototype.calculateGlyphDependencies = function calculateGlyphDependencies(text, stack, textAlongLine, allowVerticalPlacement, doesAllowVerticalWritingMode) {
  15826. for (var i = 0; i < text.length; i++) {
  15827. stack[text.charCodeAt(i)] = true;
  15828. }
  15829. };
  15830. SymbolBucket.prototype.populate = function populate(features, options) {
  15831. var layer = this.layers[0];
  15832. var layout = layer.layout;
  15833. var textFont = layout.get('text-font');
  15834. var textField = layout.get('text-field');
  15835. var iconImage = layout.get('icon-image');
  15836. var hasText =
  15837. (textField.value.kind !== 'constant' ||
  15838. (textField.value.value instanceof Formatted$1 && !textField.value.value.isEmpty()) ||
  15839. textField.value.value.toString().length > 0) &&
  15840. (textFont.value.kind !== 'constant' || textFont.value.value.length > 0);
  15841. // we should always resolve the icon-image value if the property was defined in the style
  15842. // this allows us to fire the styleimagemissing event if image evaluation returns null
  15843. // the only way to distinguish between null returned from a coalesce statement with no valid images
  15844. // and null returned because icon-image wasn't defined is to check whether or not iconImage.parameters is an empty object
  15845. var hasIcon = (iconImage.value.kind !== 'constant' || !!iconImage.value.value) && Object.keys(iconImage.parameters).length > 0;
  15846. var symbolSortKey = layout.get('symbol-sort-key');
  15847. this.features = [];
  15848. if (!hasText && !hasIcon) {
  15849. return;
  15850. }
  15851. var icons = options.iconDependencies;
  15852. var stacks = options.glyphDependencies;
  15853. var availableImages = options.availableImages;
  15854. var globalProperties = new EvaluationParameters$1(this.zoom);
  15855. for (var i$1 = 0, list$1 = features; i$1 < list$1.length; i$1 += 1) {
  15856. var ref = list$1[i$1];
  15857. var feature = ref.feature;
  15858. var index = ref.index;
  15859. var sourceLayerIndex = ref.sourceLayerIndex;
  15860. if (!layer._featureFilter(globalProperties, feature)) {
  15861. continue;
  15862. }
  15863. var text = (void 0);
  15864. if (hasText) {
  15865. // Expression evaluation will automatically coerce to Formatted
  15866. // but plain string token evaluation skips that pathway so do the
  15867. // conversion here.
  15868. var resolvedTokens = layer.getValueAndResolveTokens('text-field', feature, availableImages);
  15869. var formattedText = Formatted$1.factory(resolvedTokens);
  15870. if (containsRTLText(formattedText)) {
  15871. this.hasRTLText = true;
  15872. }
  15873. if (
  15874. !this.hasRTLText || // non-rtl text so can proceed safely
  15875. getRTLTextPluginStatus() === 'unavailable' || // We don't intend to lazy-load the rtl text plugin, so proceed with incorrect shaping
  15876. this.hasRTLText && plugin.isParsed() // Use the rtlText plugin to shape text
  15877. ) {
  15878. text = transformText$1(formattedText, layer, feature);
  15879. }
  15880. }
  15881. var icon = (void 0);
  15882. if (hasIcon) {
  15883. // Expression evaluation will automatically coerce to Image
  15884. // but plain string token evaluation skips that pathway so do the
  15885. // conversion here.
  15886. var resolvedTokens$1 = layer.getValueAndResolveTokens('icon-image', feature, availableImages);
  15887. if (resolvedTokens$1 instanceof ResolvedImage$1) {
  15888. icon = resolvedTokens$1;
  15889. } else {
  15890. icon = ResolvedImage$1.fromString(resolvedTokens$1);
  15891. }
  15892. }
  15893. if (!text && !icon) {
  15894. continue;
  15895. }
  15896. var sortKey = this.sortFeaturesByKey ?
  15897. symbolSortKey.evaluate(feature, {}) :
  15898. undefined;
  15899. var symbolFeature = {
  15900. text: text,
  15901. icon: icon,
  15902. index: index,
  15903. sourceLayerIndex: sourceLayerIndex,
  15904. geometry: loadGeometry(feature),
  15905. properties: feature.properties,
  15906. type: vectorTileFeatureTypes$2[feature.type],
  15907. sortKey: sortKey
  15908. };
  15909. if (typeof feature.id !== 'undefined') {
  15910. symbolFeature.id = feature.id;
  15911. }
  15912. this.features.push(symbolFeature);
  15913. if (icon) {
  15914. icons[icon.name] = true;
  15915. }
  15916. if (text) {
  15917. var fontStack = textFont.evaluate(feature, {}).join(',');
  15918. var textAlongLine = layout.get('text-rotation-alignment') === 'map' && layout.get('symbol-placement') !== 'point';
  15919. this.allowVerticalPlacement = this.writingModes && this.writingModes.indexOf(Shaping.WritingMode.vertical) >= 0;
  15920. for (var i = 0, list = text.sections; i < list.length; i += 1) {
  15921. var section = list[i];
  15922. if (!section.image) {
  15923. var doesAllowVerticalWritingMode = ScriptDetection.allowsVerticalWritingMode(text.toString());
  15924. var sectionFont = section.fontStack || fontStack;
  15925. var sectionStack = stacks[sectionFont] = stacks[sectionFont] || {};
  15926. this.calculateGlyphDependencies(section.text, sectionStack, textAlongLine, this.allowVerticalPlacement, doesAllowVerticalWritingMode);
  15927. } else {
  15928. // Add section image to the list of dependencies.
  15929. icons[section.image.name] = true;
  15930. }
  15931. }
  15932. }
  15933. }
  15934. if (layout.get('symbol-placement') === 'line') {
  15935. // Merge adjacent lines with the same text to improve labelling.
  15936. // It's better to place labels on one long line than on many short segments.
  15937. this.features = mergeLines(this.features);
  15938. }
  15939. if (this.sortFeaturesByKey) {
  15940. this.features.sort(function (a, b) {
  15941. // a.sortKey is always a number when sortFeaturesByKey is true
  15942. return ((a.sortKey ) ) - ((b.sortKey ) );
  15943. });
  15944. }
  15945. };
  15946. SymbolBucket.prototype.update = function update(states, vtLayer, imagePositions) {
  15947. if (!this.stateDependentLayers.length) {
  15948. return;
  15949. }
  15950. this.text.programConfigurations.updatePaintArrays(states, vtLayer, this.layers, imagePositions);
  15951. this.icon.programConfigurations.updatePaintArrays(states, vtLayer, this.layers, imagePositions);
  15952. };
  15953. SymbolBucket.prototype.isEmpty = function isEmpty() {
  15954. // When the bucket encounters only rtl-text but the plugin isnt loaded, no symbol instances will be created.
  15955. // In order for the bucket to be serialized, and not discarded as an empty bucket both checks are necessary.
  15956. return this.symbolInstances.length === 0 && !this.hasRTLText;
  15957. };
  15958. SymbolBucket.prototype.uploadPending = function uploadPending() {
  15959. return !this.uploaded || this.text.programConfigurations.needsUpload || this.icon.programConfigurations.needsUpload;
  15960. };
  15961. SymbolBucket.prototype.upload = function upload(context) {
  15962. // if (!this.uploaded) {
  15963. // this.textCollisionBox.upload(context);
  15964. // this.iconCollisionBox.upload(context);
  15965. // this.textCollisionCircle.upload(context);
  15966. // this.iconCollisionCircle.upload(context);
  15967. // }
  15968. // this.text.upload(context, this.sortFeaturesByY, !this.uploaded, this.text.programConfigurations.needsUpload);
  15969. // this.icon.upload(context, this.sortFeaturesByY, !this.uploaded, this.icon.programConfigurations.needsUpload);
  15970. // this.uploaded = true;
  15971. };
  15972. SymbolBucket.prototype.destroy = function destroy() {
  15973. // this.text.destroy();
  15974. // this.icon.destroy();
  15975. // this.textCollisionBox.destroy();
  15976. // this.iconCollisionBox.destroy();
  15977. // this.textCollisionCircle.destroy();
  15978. // this.iconCollisionCircle.destroy();
  15979. };
  15980. SymbolBucket.prototype.clear = function clear() {
  15981. };
  15982. SymbolBucket.prototype.addToLineVertexArray = function addToLineVertexArray(anchor, line) {
  15983. var lineStartIndex = this.lineVertexArray.length;
  15984. if (anchor.segment !== undefined) {
  15985. var sumForwardLength = anchor.dist(line[anchor.segment + 1]);
  15986. var sumBackwardLength = anchor.dist(line[anchor.segment]);
  15987. var vertices = {};
  15988. for (var i = anchor.segment + 1; i < line.length; i++) {
  15989. vertices[i] = {x: line[i].x, y: line[i].y, tileUnitDistanceFromAnchor: sumForwardLength};
  15990. if (i < line.length - 1) {
  15991. sumForwardLength += line[i + 1].dist(line[i]);
  15992. }
  15993. }
  15994. for (var i$1 = anchor.segment || 0; i$1 >= 0; i$1--) {
  15995. vertices[i$1] = {x: line[i$1].x, y: line[i$1].y, tileUnitDistanceFromAnchor: sumBackwardLength};
  15996. if (i$1 > 0) {
  15997. sumBackwardLength += line[i$1 - 1].dist(line[i$1]);
  15998. }
  15999. }
  16000. for (var i$2 = 0; i$2 < line.length; i$2++) {
  16001. var vertex = vertices[i$2];
  16002. this.lineVertexArray.emplaceBack(vertex.x, vertex.y, vertex.tileUnitDistanceFromAnchor);
  16003. }
  16004. }
  16005. return {
  16006. lineStartIndex: lineStartIndex,
  16007. lineLength: this.lineVertexArray.length - lineStartIndex
  16008. };
  16009. };
  16010. SymbolBucket.prototype.addSymbols = function addSymbols(arrays, quads, sizeVertex, lineOffset, alongLine, feature, writingMode, labelAnchor, lineStartIndex, lineLength, associatedIconIndex) {
  16011. var this$1 = this;
  16012. var indexArray = arrays.indexArray;
  16013. var layoutVertexArray = arrays.layoutVertexArray;
  16014. var dynamicLayoutVertexArray = arrays.dynamicLayoutVertexArray;
  16015. var segment = arrays.segments.prepareSegment(4 * quads.length, arrays.layoutVertexArray, arrays.indexArray, feature.sortKey);
  16016. var glyphOffsetArrayStart = this.glyphOffsetArray.length;
  16017. var vertexStartIndex = segment.vertexLength;
  16018. var angle = (this.allowVerticalPlacement && writingMode === Shaping.WritingMode.vertical) ? Math.PI / 2 : 0;
  16019. var addSymbol = function (symbol) {
  16020. var tl = symbol.tl,
  16021. tr = symbol.tr,
  16022. bl = symbol.bl,
  16023. br = symbol.br,
  16024. tex = symbol.tex,
  16025. pixelOffsetTL = symbol.pixelOffsetTL,
  16026. pixelOffsetBR = symbol.pixelOffsetBR,
  16027. mfsx = symbol.minFontScaleX,
  16028. mfsy = symbol.minFontScaleY;
  16029. var index = segment.vertexLength;
  16030. var y = symbol.glyphOffset[1];
  16031. 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);
  16032. 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);
  16033. 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);
  16034. 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);
  16035. addDynamicAttributes(dynamicLayoutVertexArray, labelAnchor, angle);
  16036. indexArray.emplaceBack(index, index + 1, index + 2);
  16037. indexArray.emplaceBack(index + 1, index + 2, index + 3);
  16038. segment.vertexLength += 4;
  16039. segment.primitiveLength += 2;
  16040. this$1.glyphOffsetArray.emplaceBack(symbol.glyphOffset[0]);
  16041. };
  16042. if (feature.text && feature.text.sections) {
  16043. var sections = feature.text.sections;
  16044. if (this.hasPaintOverrides) {
  16045. var currentSectionIndex;
  16046. var populatePaintArrayForSection = function (sectionIndex, lastSection) {
  16047. if (currentSectionIndex !== undefined && (currentSectionIndex !== sectionIndex || lastSection)) {
  16048. arrays.programConfigurations.populatePaintArrays(arrays.layoutVertexArray.length, feature, feature.index, {}, sections[currentSectionIndex]);
  16049. }
  16050. currentSectionIndex = sectionIndex;
  16051. };
  16052. for (var i = 0, list = quads; i < list.length; i += 1) {
  16053. var symbol = list[i];
  16054. populatePaintArrayForSection(symbol.sectionIndex, false);
  16055. addSymbol(symbol);
  16056. }
  16057. // Populate paint arrays for the last section.
  16058. populatePaintArrayForSection(currentSectionIndex, true);
  16059. } else {
  16060. for (var i$1 = 0, list$1 = quads; i$1 < list$1.length; i$1 += 1) {
  16061. var symbol$1 = list$1[i$1];
  16062. addSymbol(symbol$1);
  16063. }
  16064. arrays.programConfigurations.populatePaintArrays(arrays.layoutVertexArray.length, feature, feature.index, {}, sections[0]);
  16065. }
  16066. } else {
  16067. for (var i$2 = 0, list$2 = quads; i$2 < list$2.length; i$2 += 1) {
  16068. var symbol$2 = list$2[i$2];
  16069. addSymbol(symbol$2);
  16070. }
  16071. arrays.programConfigurations.populatePaintArrays(arrays.layoutVertexArray.length, feature, feature.index, {});
  16072. }
  16073. arrays.placedSymbolArray.emplaceBack(labelAnchor.x, labelAnchor.y,
  16074. glyphOffsetArrayStart, this.glyphOffsetArray.length - glyphOffsetArrayStart, vertexStartIndex,
  16075. lineStartIndex, lineLength, (labelAnchor.segment ),
  16076. sizeVertex ? sizeVertex[0] : 0, sizeVertex ? sizeVertex[1] : 0,
  16077. lineOffset[0], lineOffset[1],
  16078. writingMode,
  16079. // placedOrientation is null initially; will be updated to horizontal(1)/vertical(2) if placed
  16080. 0,
  16081. (false ),
  16082. // The crossTileID is only filled/used on the foreground for dynamic text anchors
  16083. 0,
  16084. associatedIconIndex
  16085. );
  16086. };
  16087. SymbolBucket.prototype._addCollisionDebugVertex = function _addCollisionDebugVertex(layoutVertexArray, collisionVertexArray, point, anchorX, anchorY, extrude) {
  16088. collisionVertexArray.emplaceBack(0, 0);
  16089. return layoutVertexArray.emplaceBack(
  16090. // pos
  16091. point.x,
  16092. point.y,
  16093. // a_anchor_pos
  16094. anchorX,
  16095. anchorY,
  16096. // extrude
  16097. Math.round(extrude.x),
  16098. Math.round(extrude.y));
  16099. };
  16100. SymbolBucket.prototype.addCollisionDebugVertices = function addCollisionDebugVertices(x1, y1, x2, y2, arrays, boxAnchorPoint, symbolInstance, isCircle) {
  16101. var segment = arrays.segments.prepareSegment(4, arrays.layoutVertexArray, arrays.indexArray);
  16102. var index = segment.vertexLength;
  16103. var layoutVertexArray = arrays.layoutVertexArray;
  16104. var collisionVertexArray = arrays.collisionVertexArray;
  16105. var anchorX = symbolInstance.anchorX;
  16106. var anchorY = symbolInstance.anchorY;
  16107. this._addCollisionDebugVertex(layoutVertexArray, collisionVertexArray, boxAnchorPoint, anchorX, anchorY, new pointGeometry(x1, y1));
  16108. this._addCollisionDebugVertex(layoutVertexArray, collisionVertexArray, boxAnchorPoint, anchorX, anchorY, new pointGeometry(x2, y1));
  16109. this._addCollisionDebugVertex(layoutVertexArray, collisionVertexArray, boxAnchorPoint, anchorX, anchorY, new pointGeometry(x2, y2));
  16110. this._addCollisionDebugVertex(layoutVertexArray, collisionVertexArray, boxAnchorPoint, anchorX, anchorY, new pointGeometry(x1, y2));
  16111. segment.vertexLength += 4;
  16112. if (isCircle) {
  16113. var indexArray = (arrays.indexArray );
  16114. indexArray.emplaceBack(index, index + 1, index + 2);
  16115. indexArray.emplaceBack(index, index + 2, index + 3);
  16116. segment.primitiveLength += 2;
  16117. } else {
  16118. var indexArray$1 = (arrays.indexArray );
  16119. indexArray$1.emplaceBack(index, index + 1);
  16120. indexArray$1.emplaceBack(index + 1, index + 2);
  16121. indexArray$1.emplaceBack(index + 2, index + 3);
  16122. indexArray$1.emplaceBack(index + 3, index);
  16123. segment.primitiveLength += 4;
  16124. }
  16125. };
  16126. SymbolBucket.prototype.addDebugCollisionBoxes = function addDebugCollisionBoxes(startIndex, endIndex, symbolInstance, isText) {
  16127. for (var b = startIndex; b < endIndex; b++) {
  16128. var box = (this.collisionBoxArray.get(b) );
  16129. var x1 = box.x1;
  16130. var y1 = box.y1;
  16131. var x2 = box.x2;
  16132. var y2 = box.y2;
  16133. // If the radius > 0, this collision box is actually a circle
  16134. // The data we add to the buffers is exactly the same, but we'll render with a different shader.
  16135. var isCircle = box.radius > 0;
  16136. this.addCollisionDebugVertices(x1, y1, x2, y2, isCircle ?
  16137. (isText ? this.textCollisionCircle : this.iconCollisionCircle) : (isText ? this.textCollisionBox : this.iconCollisionBox),
  16138. box.anchorPoint, symbolInstance, isCircle);
  16139. }
  16140. };
  16141. SymbolBucket.prototype.generateCollisionDebugBuffers = function generateCollisionDebugBuffers() {
  16142. for (var i = 0; i < this.symbolInstances.length; i++) {
  16143. var symbolInstance = this.symbolInstances.get(i);
  16144. this.addDebugCollisionBoxes(symbolInstance.textBoxStartIndex, symbolInstance.textBoxEndIndex, symbolInstance, true);
  16145. this.addDebugCollisionBoxes(symbolInstance.verticalTextBoxStartIndex, symbolInstance.verticalTextBoxEndIndex, symbolInstance, true);
  16146. this.addDebugCollisionBoxes(symbolInstance.iconBoxStartIndex, symbolInstance.iconBoxEndIndex, symbolInstance, false);
  16147. this.addDebugCollisionBoxes(symbolInstance.verticalIconBoxStartIndex, symbolInstance.verticalIconBoxEndIndex, symbolInstance, false);
  16148. }
  16149. };
  16150. // These flat arrays are meant to be quicker to iterate over than the source
  16151. // CollisionBoxArray
  16152. SymbolBucket.prototype._deserializeCollisionBoxesForSymbol = function _deserializeCollisionBoxesForSymbol(collisionBoxArray, textStartIndex, textEndIndex, verticalTextStartIndex, verticalTextEndIndex, iconStartIndex, iconEndIndex, verticalIconStartIndex, verticalIconEndIndex) {
  16153. var collisionArrays = {};
  16154. for (var k = textStartIndex; k < textEndIndex; k++) {
  16155. var box = (collisionBoxArray.get(k) );
  16156. if (box.radius === 0) {
  16157. collisionArrays.textBox = {x1: box.x1, y1: box.y1, x2: box.x2, y2: box.y2, anchorPointX: box.anchorPointX, anchorPointY: box.anchorPointY};
  16158. collisionArrays.textFeatureIndex = box.featureIndex;
  16159. break; // Only one box allowed per instance
  16160. } else {
  16161. if (!collisionArrays.textCircles) {
  16162. collisionArrays.textCircles = [];
  16163. collisionArrays.textFeatureIndex = box.featureIndex;
  16164. }
  16165. var used = 1; // May be updated at collision detection time
  16166. collisionArrays.textCircles.push(box.anchorPointX, box.anchorPointY, box.radius, box.signedDistanceFromAnchor, used);
  16167. }
  16168. }
  16169. for (var k$1 = verticalTextStartIndex; k$1 < verticalTextEndIndex; k$1++) {
  16170. var box$1 = (collisionBoxArray.get(k$1) );
  16171. if (box$1.radius === 0) {
  16172. 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};
  16173. collisionArrays.verticalTextFeatureIndex = box$1.featureIndex;
  16174. break; // Only one box allowed per instance
  16175. }
  16176. }
  16177. for (var k$2 = iconStartIndex; k$2 < iconEndIndex; k$2++) {
  16178. // An icon can only have one box now, so this indexing is a bit vestigial...
  16179. var box$2 = (collisionBoxArray.get(k$2) );
  16180. if (box$2.radius === 0) {
  16181. 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};
  16182. collisionArrays.iconFeatureIndex = box$2.featureIndex;
  16183. break; // Only one box allowed per instance
  16184. }
  16185. }
  16186. for (var k$3 = verticalIconStartIndex; k$3 < verticalIconEndIndex; k$3++) {
  16187. // An icon can only have one box now, so this indexing is a bit vestigial...
  16188. var box$3 = (collisionBoxArray.get(k$3) );
  16189. if (box$3.radius === 0) {
  16190. 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};
  16191. collisionArrays.verticalIconFeatureIndex = box$3.featureIndex;
  16192. break; // Only one box allowed per instance
  16193. }
  16194. }
  16195. return collisionArrays;
  16196. };
  16197. SymbolBucket.prototype.deserializeCollisionBoxes = function deserializeCollisionBoxes(collisionBoxArray) {
  16198. this.collisionArrays = [];
  16199. for (var i = 0; i < this.symbolInstances.length; i++) {
  16200. var symbolInstance = this.symbolInstances.get(i);
  16201. this.collisionArrays.push(this._deserializeCollisionBoxesForSymbol(
  16202. collisionBoxArray,
  16203. symbolInstance.textBoxStartIndex,
  16204. symbolInstance.textBoxEndIndex,
  16205. symbolInstance.verticalTextBoxStartIndex,
  16206. symbolInstance.verticalTextBoxEndIndex,
  16207. symbolInstance.iconBoxStartIndex,
  16208. symbolInstance.iconBoxEndIndex,
  16209. symbolInstance.verticalIconBoxStartIndex,
  16210. symbolInstance.verticalIconBoxEndIndex
  16211. ));
  16212. }
  16213. };
  16214. SymbolBucket.prototype.hasTextData = function hasTextData() {
  16215. return this.text.segments.get().length > 0;
  16216. };
  16217. SymbolBucket.prototype.hasIconData = function hasIconData() {
  16218. return this.icon.segments.get().length > 0;
  16219. };
  16220. SymbolBucket.prototype.hasTextCollisionBoxData = function hasTextCollisionBoxData() {
  16221. return this.textCollisionBox.segments.get().length > 0;
  16222. };
  16223. SymbolBucket.prototype.hasIconCollisionBoxData = function hasIconCollisionBoxData() {
  16224. return this.iconCollisionBox.segments.get().length > 0;
  16225. };
  16226. SymbolBucket.prototype.hasTextCollisionCircleData = function hasTextCollisionCircleData() {
  16227. return this.textCollisionCircle.segments.get().length > 0;
  16228. };
  16229. SymbolBucket.prototype.hasIconCollisionCircleData = function hasIconCollisionCircleData() {
  16230. return this.iconCollisionCircle.segments.get().length > 0;
  16231. };
  16232. SymbolBucket.prototype.addIndicesForPlacedSymbol = function addIndicesForPlacedSymbol(iconOrText, placedSymbolIndex) {
  16233. var placedSymbol = iconOrText.placedSymbolArray.get(placedSymbolIndex);
  16234. var endIndex = placedSymbol.vertexStartIndex + placedSymbol.numGlyphs * 4;
  16235. for (var vertexIndex = placedSymbol.vertexStartIndex; vertexIndex < endIndex; vertexIndex += 4) {
  16236. iconOrText.indexArray.emplaceBack(vertexIndex, vertexIndex + 1, vertexIndex + 2);
  16237. iconOrText.indexArray.emplaceBack(vertexIndex + 1, vertexIndex + 2, vertexIndex + 3);
  16238. }
  16239. };
  16240. SymbolBucket.prototype.getSortedSymbolIndexes = function getSortedSymbolIndexes(angle) {
  16241. if (this.sortedAngle === angle && this.symbolInstanceIndexes !== undefined) {
  16242. return this.symbolInstanceIndexes;
  16243. }
  16244. var sin = Math.sin(angle);
  16245. var cos = Math.cos(angle);
  16246. var rotatedYs = [];
  16247. var featureIndexes = [];
  16248. var result = [];
  16249. for (var i = 0; i < this.symbolInstances.length; ++i) {
  16250. result.push(i);
  16251. var symbolInstance = this.symbolInstances.get(i);
  16252. rotatedYs.push(Math.round(sin * symbolInstance.anchorX + cos * symbolInstance.anchorY) | 0);
  16253. featureIndexes.push(symbolInstance.featureIndex);
  16254. }
  16255. result.sort(function (aIndex, bIndex) {
  16256. return (rotatedYs[aIndex] - rotatedYs[bIndex]) ||
  16257. (featureIndexes[bIndex] - featureIndexes[aIndex]);
  16258. });
  16259. return result;
  16260. };
  16261. SymbolBucket.prototype.sortFeatures = function sortFeatures(angle) {
  16262. var this$1 = this;
  16263. if (!this.sortFeaturesByY) {
  16264. return;
  16265. }
  16266. if (this.sortedAngle === angle) {
  16267. return;
  16268. }
  16269. // The current approach to sorting doesn't sort across segments so don't try.
  16270. // Sorting within segments separately seemed not to be worth the complexity.
  16271. if (this.text.segments.get().length > 1 || this.icon.segments.get().length > 1) {
  16272. return;
  16273. }
  16274. // If the symbols are allowed to overlap sort them by their vertical screen position.
  16275. // The index array buffer is rewritten to reference the (unchanged) vertices in the
  16276. // sorted order.
  16277. // To avoid sorting the actual symbolInstance array we sort an array of indexes.
  16278. this.symbolInstanceIndexes = this.getSortedSymbolIndexes(angle);
  16279. this.sortedAngle = angle;
  16280. this.text.indexArray.clear();
  16281. this.icon.indexArray.clear();
  16282. this.featureSortOrder = [];
  16283. for (var i$1 = 0, list = this.symbolInstanceIndexes; i$1 < list.length; i$1 += 1) {
  16284. var i = list[i$1];
  16285. var symbolInstance = this.symbolInstances.get(i);
  16286. this.featureSortOrder.push(symbolInstance.featureIndex);
  16287. [
  16288. symbolInstance.rightJustifiedTextSymbolIndex,
  16289. symbolInstance.centerJustifiedTextSymbolIndex,
  16290. symbolInstance.leftJustifiedTextSymbolIndex
  16291. ].forEach(function (index, i, array) {
  16292. // Only add a given index the first time it shows up,
  16293. // to avoid duplicate opacity entries when multiple justifications
  16294. // share the same glyphs.
  16295. if (index >= 0 && array.indexOf(index) === i) {
  16296. this$1.addIndicesForPlacedSymbol(this$1.text, index);
  16297. }
  16298. });
  16299. if (symbolInstance.verticalPlacedTextSymbolIndex >= 0) {
  16300. this.addIndicesForPlacedSymbol(this.text, symbolInstance.verticalPlacedTextSymbolIndex);
  16301. }
  16302. if (symbolInstance.placedIconSymbolIndex >= 0) {
  16303. this.addIndicesForPlacedSymbol(this.icon, symbolInstance.placedIconSymbolIndex);
  16304. }
  16305. if (symbolInstance.verticalPlacedIconSymbolIndex >= 0) {
  16306. this.addIndicesForPlacedSymbol(this.icon, symbolInstance.verticalPlacedIconSymbolIndex);
  16307. }
  16308. }
  16309. if (this.text.indexBuffer) {
  16310. this.text.indexBuffer.updateData(this.text.indexArray);
  16311. }
  16312. if (this.icon.indexBuffer) {
  16313. this.icon.indexBuffer.updateData(this.icon.indexArray);
  16314. }
  16315. };
  16316. WebWorkerTransfer.register('SymbolBucket', SymbolBucket, {
  16317. //omit: ['layers', 'collisionBoxArray', 'features', 'compareText']
  16318. omit: ['layers', 'collisionBoxArray', 'compareText']
  16319. });
  16320. // this constant is based on the size of StructArray indexes used in a symbol
  16321. // bucket--namely, glyphOffsetArrayStart
  16322. // eg the max valid UInt16 is 65,535
  16323. // See https://github.com/mapbox/mapbox-gl-js/issues/2907 for motivation
  16324. // lineStartIndex and textBoxStartIndex could potentially be concerns
  16325. // but we expect there to be many fewer boxes/lines than glyphs
  16326. SymbolBucket.MAX_GLYPHS = 65535;
  16327. SymbolBucket.addDynamicAttributes = addDynamicAttributes;
  16328. var ColorType$7 = {kind: 'color'};
  16329. var FormattedType$4 = {kind: 'formatted'};
  16330. var layout$7 = new Properties({
  16331. "symbol-placement": new DataConstantProperty(StyleSpec["layout_symbol"]["symbol-placement"]),
  16332. "symbol-spacing": new DataConstantProperty(StyleSpec["layout_symbol"]["symbol-spacing"]),
  16333. "symbol-avoid-edges": new DataConstantProperty(StyleSpec["layout_symbol"]["symbol-avoid-edges"]),
  16334. "symbol-sort-key": new DataDrivenProperty(StyleSpec["layout_symbol"]["symbol-sort-key"]),
  16335. "symbol-z-order": new DataConstantProperty(StyleSpec["layout_symbol"]["symbol-z-order"]),
  16336. "icon-allow-overlap": new DataConstantProperty(StyleSpec["layout_symbol"]["icon-allow-overlap"]),
  16337. "icon-ignore-placement": new DataConstantProperty(StyleSpec["layout_symbol"]["icon-ignore-placement"]),
  16338. "icon-optional": new DataConstantProperty(StyleSpec["layout_symbol"]["icon-optional"]),
  16339. "icon-rotation-alignment": new DataConstantProperty(StyleSpec["layout_symbol"]["icon-rotation-alignment"]),
  16340. "icon-size": new DataDrivenProperty(StyleSpec["layout_symbol"]["icon-size"]),
  16341. "icon-text-fit": new DataConstantProperty(StyleSpec["layout_symbol"]["icon-text-fit"]),
  16342. "icon-text-fit-padding": new DataConstantProperty(StyleSpec["layout_symbol"]["icon-text-fit-padding"]),
  16343. "icon-image": new DataDrivenProperty(StyleSpec["layout_symbol"]["icon-image"]),
  16344. "icon-rotate": new DataDrivenProperty(StyleSpec["layout_symbol"]["icon-rotate"]),
  16345. "icon-padding": new DataConstantProperty(StyleSpec["layout_symbol"]["icon-padding"]),
  16346. "icon-keep-upright": new DataConstantProperty(StyleSpec["layout_symbol"]["icon-keep-upright"]),
  16347. "icon-offset": new DataDrivenProperty(StyleSpec["layout_symbol"]["icon-offset"]),
  16348. "icon-anchor": new DataDrivenProperty(StyleSpec["layout_symbol"]["icon-anchor"]),
  16349. "icon-pitch-alignment": new DataConstantProperty(StyleSpec["layout_symbol"]["icon-pitch-alignment"]),
  16350. "text-pitch-alignment": new DataConstantProperty(StyleSpec["layout_symbol"]["text-pitch-alignment"]),
  16351. "text-rotation-alignment": new DataConstantProperty(StyleSpec["layout_symbol"]["text-rotation-alignment"]),
  16352. "text-field": new DataDrivenProperty(StyleSpec["layout_symbol"]["text-field"]),
  16353. "text-font": new DataDrivenProperty(StyleSpec["layout_symbol"]["text-font"]),
  16354. "text-size": new DataDrivenProperty(StyleSpec["layout_symbol"]["text-size"]),
  16355. "text-max-width": new DataDrivenProperty(StyleSpec["layout_symbol"]["text-max-width"]),
  16356. "text-line-height": new DataConstantProperty(StyleSpec["layout_symbol"]["text-line-height"]),
  16357. "text-letter-spacing": new DataDrivenProperty(StyleSpec["layout_symbol"]["text-letter-spacing"]),
  16358. "text-justify": new DataDrivenProperty(StyleSpec["layout_symbol"]["text-justify"]),
  16359. "text-radial-offset": new DataDrivenProperty(StyleSpec["layout_symbol"]["text-radial-offset"]),
  16360. "text-variable-anchor": new DataConstantProperty(StyleSpec["layout_symbol"]["text-variable-anchor"]),
  16361. "text-anchor": new DataDrivenProperty(StyleSpec["layout_symbol"]["text-anchor"]),
  16362. "text-max-angle": new DataConstantProperty(StyleSpec["layout_symbol"]["text-max-angle"]),
  16363. "text-writing-mode": new DataConstantProperty(StyleSpec["layout_symbol"]["text-writing-mode"]),
  16364. "text-rotate": new DataDrivenProperty(StyleSpec["layout_symbol"]["text-rotate"]),
  16365. "text-padding": new DataConstantProperty(StyleSpec["layout_symbol"]["text-padding"]),
  16366. "text-keep-upright": new DataConstantProperty(StyleSpec["layout_symbol"]["text-keep-upright"]),
  16367. "text-transform": new DataDrivenProperty(StyleSpec["layout_symbol"]["text-transform"]),
  16368. "text-offset": new DataDrivenProperty(StyleSpec["layout_symbol"]["text-offset"]),
  16369. "text-allow-overlap": new DataConstantProperty(StyleSpec["layout_symbol"]["text-allow-overlap"]),
  16370. "text-ignore-placement": new DataConstantProperty(StyleSpec["layout_symbol"]["text-ignore-placement"]),
  16371. "text-optional": new DataConstantProperty(StyleSpec["layout_symbol"]["text-optional"])
  16372. });
  16373. var paint$7 = new Properties({
  16374. "icon-opacity": new DataDrivenProperty(StyleSpec["paint_symbol"]["icon-opacity"]),
  16375. "icon-color": new DataDrivenProperty(StyleSpec["paint_symbol"]["icon-color"]),
  16376. "icon-halo-color": new DataDrivenProperty(StyleSpec["paint_symbol"]["icon-halo-color"]),
  16377. "icon-halo-width": new DataDrivenProperty(StyleSpec["paint_symbol"]["icon-halo-width"]),
  16378. "icon-halo-blur": new DataDrivenProperty(StyleSpec["paint_symbol"]["icon-halo-blur"]),
  16379. "icon-translate": new DataConstantProperty(StyleSpec["paint_symbol"]["icon-translate"]),
  16380. "icon-translate-anchor": new DataConstantProperty(StyleSpec["paint_symbol"]["icon-translate-anchor"]),
  16381. "text-opacity": new DataDrivenProperty(StyleSpec["paint_symbol"]["text-opacity"]),
  16382. "text-color": new DataDrivenProperty(StyleSpec["paint_symbol"]["text-color"], { runtimeType: ColorType$7, getOverride: function (o) {
  16383. return o.textColor;
  16384. }, hasOverride: function (o) {
  16385. return !!o.textColor;
  16386. } }),
  16387. "text-halo-color": new DataDrivenProperty(StyleSpec["paint_symbol"]["text-halo-color"]),
  16388. "text-halo-width": new DataDrivenProperty(StyleSpec["paint_symbol"]["text-halo-width"]),
  16389. "text-halo-blur": new DataDrivenProperty(StyleSpec["paint_symbol"]["text-halo-blur"]),
  16390. "text-show-background": new DataDrivenProperty(StyleSpec["paint_symbol"]["text-show-background"]),
  16391. "text-translate": new DataConstantProperty(StyleSpec["paint_symbol"]["text-translate"]),
  16392. "text-translate-anchor": new DataConstantProperty(StyleSpec["paint_symbol"]["text-translate-anchor"])
  16393. });
  16394. // Note: without adding the explicit type annotation, Flow infers weaker types
  16395. // for these objects from their use in the constructor to StyleLayer, as
  16396. // {layout?: Properties<...>, paint: Properties<...>}
  16397. var properties$6 = ({ paint: paint$7, layout: layout$7 }
  16398. );
  16399. var SymbolStyleLayer = /*@__PURE__*/(function (StyleLayer) {
  16400. function SymbolStyleLayer(layer) {
  16401. StyleLayer.call(this, layer, properties$6);
  16402. }
  16403. if (StyleLayer) SymbolStyleLayer.__proto__ = StyleLayer;
  16404. SymbolStyleLayer.prototype = Object.create(StyleLayer && StyleLayer.prototype);
  16405. SymbolStyleLayer.prototype.constructor = SymbolStyleLayer;
  16406. SymbolStyleLayer.prototype.recalculate = function recalculate(parameters, availableImages) {
  16407. StyleLayer.prototype.recalculate.call(this, parameters, availableImages);
  16408. if (this.layout.get('icon-rotation-alignment') === 'auto') {
  16409. if (this.layout.get('symbol-placement') !== 'point') {
  16410. this.layout._values['icon-rotation-alignment'] = 'map';
  16411. } else {
  16412. this.layout._values['icon-rotation-alignment'] = 'viewport';
  16413. }
  16414. }
  16415. if (this.layout.get('text-rotation-alignment') === 'auto') {
  16416. if (this.layout.get('symbol-placement') !== 'point') {
  16417. this.layout._values['text-rotation-alignment'] = 'map';
  16418. } else {
  16419. this.layout._values['text-rotation-alignment'] = 'viewport';
  16420. }
  16421. }
  16422. // If unspecified, `*-pitch-alignment` inherits `*-rotation-alignment`
  16423. if (this.layout.get('text-pitch-alignment') === 'auto') {
  16424. this.layout._values['text-pitch-alignment'] = this.layout.get('text-rotation-alignment');
  16425. }
  16426. if (this.layout.get('icon-pitch-alignment') === 'auto') {
  16427. this.layout._values['icon-pitch-alignment'] = this.layout.get('icon-rotation-alignment');
  16428. }
  16429. if (this.layout.get('symbol-placement') === 'point') {
  16430. var writingModes = this.layout.get('text-writing-mode');
  16431. if (writingModes) {
  16432. // remove duplicates, preserving order
  16433. var deduped = [];
  16434. for (var i = 0, list = writingModes; i < list.length; i += 1) {
  16435. var m = list[i];
  16436. if (deduped.indexOf(m) < 0) {
  16437. deduped.push(m);
  16438. }
  16439. }
  16440. this.layout._values['text-writing-mode'] = deduped;
  16441. } else {
  16442. this.layout._values['text-writing-mode'] = ['horizontal'];
  16443. }
  16444. }
  16445. this._setPaintOverrides();
  16446. };
  16447. SymbolStyleLayer.prototype.getValueAndResolveTokens = function getValueAndResolveTokens(name, feature, availableImages) {
  16448. var value = this.layout.get(name).evaluate(feature, {}, availableImages);
  16449. var unevaluated = this._unevaluatedLayout._values[name];
  16450. if (!unevaluated.isDataDriven() && !Expression.isExpression(unevaluated.value) && value) {
  16451. return Util.resolveTokens(feature.properties, value);
  16452. }
  16453. return value;
  16454. };
  16455. SymbolStyleLayer.prototype.createBucket = function createBucket(parameters) {
  16456. return new SymbolBucket(parameters);
  16457. };
  16458. SymbolStyleLayer.prototype.queryRadius = function queryRadius() {
  16459. return 0;
  16460. };
  16461. SymbolStyleLayer.prototype.queryIntersectsFeature = function queryIntersectsFeature() {
  16462. return false;
  16463. };
  16464. SymbolStyleLayer.prototype._setPaintOverrides = function _setPaintOverrides() {
  16465. for (var i = 0, list = properties$6.paint.overridableProperties; i < list.length; i += 1) {
  16466. var overridable = list[i];
  16467. if (!SymbolStyleLayer.hasPaintOverride(this.layout, overridable)) {
  16468. continue;
  16469. }
  16470. var overriden = this.paint.get(overridable);
  16471. var override = new FormatSectionOverride(overriden);
  16472. // var styleExpression = new StyleExpression(override, overriden.property.specification);
  16473. var expression = null;
  16474. if (overriden.value.kind === 'constant' || overriden.value.kind === 'source') ;
  16475. this.paint._values[overridable] = new PossiblyEvaluatedPropertyValue(overriden.property,
  16476. expression,
  16477. overriden.parameters);
  16478. }
  16479. };
  16480. SymbolStyleLayer.prototype._handleOverridablePaintPropertyUpdate = function _handleOverridablePaintPropertyUpdate(name, oldValue, newValue) {
  16481. if (!this.layout || oldValue.isDataDriven() || newValue.isDataDriven()) {
  16482. return false;
  16483. }
  16484. return SymbolStyleLayer.hasPaintOverride(this.layout, name);
  16485. };
  16486. SymbolStyleLayer.hasPaintOverride = function hasPaintOverride(layout, propertyName) {
  16487. var textField = layout.get('text-field');
  16488. var property = properties$6.paint.properties[propertyName];
  16489. var hasOverrides = false;
  16490. var checkSections = function (sections) {
  16491. for (var i = 0, list = sections; i < list.length; i += 1) {
  16492. var section = list[i];
  16493. if (property.overrides && property.overrides.hasOverride(section)) {
  16494. hasOverrides = true;
  16495. return;
  16496. }
  16497. }
  16498. };
  16499. if (textField.value.kind === 'constant' && textField.value.value instanceof Formatted$1) {
  16500. checkSections(textField.value.value.sections);
  16501. } else if (textField.value.kind === 'source') {
  16502. var checkExpression = function (expression) {
  16503. if (hasOverrides) {
  16504. return;
  16505. }
  16506. if (expression instanceof Literal && Values$1.typeOf(expression.value) === FormattedType$4) {
  16507. var formatted = ((expression.value) );
  16508. checkSections(formatted.sections);
  16509. } else if (expression instanceof FormatExpression$1) {
  16510. checkSections(expression.sections);
  16511. } else {
  16512. expression.eachChild(checkExpression);
  16513. }
  16514. };
  16515. var expr = ((textField.value) );
  16516. if (expr._styleExpression) {
  16517. checkExpression(expr._styleExpression.expression);
  16518. }
  16519. }
  16520. return hasOverrides;
  16521. };
  16522. SymbolStyleLayer.hasPaintOverrides = function hasPaintOverrides(layout) {
  16523. for (var i = 0, list = properties$6.paint.overridableProperties; i < list.length; i += 1) {
  16524. var overridable = list[i];
  16525. if (SymbolStyleLayer.hasPaintOverride(layout, overridable)) {
  16526. return true;
  16527. }
  16528. }
  16529. return false;
  16530. };
  16531. return SymbolStyleLayer;
  16532. }(StyleLayer));
  16533. var subclasses = {
  16534. circle: CircleStyleLayer,
  16535. fill: FillStyleLayer,
  16536. line: LineStyleLayer,
  16537. symbol : SymbolStyleLayer
  16538. };
  16539. function createStyleLayer(layer) {
  16540. if(subclasses[layer.type]){
  16541. return new subclasses[layer.type](layer);
  16542. }
  16543. else{
  16544. return null;
  16545. }
  16546. }
  16547. var StyleLayerIndex = function StyleLayerIndex(layerConfigs) {
  16548. this.keyCache = {};
  16549. if (layerConfigs) {
  16550. this.replace(layerConfigs);
  16551. }
  16552. };
  16553. StyleLayerIndex.prototype.replace = function replace (layerConfigs) {
  16554. this._layerConfigs = {};
  16555. this._layers = {};
  16556. this.update(layerConfigs, []);
  16557. };
  16558. function values(obj) {
  16559. var result = [];
  16560. for (var k in obj) {
  16561. result.push(obj[k]);
  16562. }
  16563. return result;
  16564. }
  16565. StyleLayerIndex.prototype.update = function update (layerConfigs, removedIds) {
  16566. var this$1 = this;
  16567. for (var i = 0, list = layerConfigs; i < list.length; i += 1) {
  16568. var layerConfig = list[i];
  16569. this._layerConfigs[layerConfig.id] = layerConfig;
  16570. var layer = createStyleLayer(layerConfig);
  16571. if(layer == null){
  16572. continue;
  16573. }
  16574. this._layers[layerConfig.id] = layer;
  16575. layer._featureFilter = featureFilter.createFilter(layer.filter);
  16576. if (this.keyCache[layerConfig.id])
  16577. { delete this.keyCache[layerConfig.id]; }
  16578. }
  16579. for (var i$1 = 0, list$1 = removedIds; i$1 < list$1.length; i$1 += 1) {
  16580. var id = list$1[i$1];
  16581. delete this.keyCache[id];
  16582. delete this._layerConfigs[id];
  16583. delete this._layers[id];
  16584. }
  16585. this.familiesBySource = {};
  16586. var groups = groupByLayout(values(this._layerConfigs), this.keyCache);
  16587. for (var i$2 = 0, list$2 = groups; i$2 < list$2.length; i$2 += 1) {
  16588. var layerConfigs$1 = list$2[i$2];
  16589. var layers = layerConfigs$1.map(function (layerConfig) { return this$1._layers[layerConfig.id]; });
  16590. var layer$1 = layers[0];
  16591. if (layer$1 == undefined || layer$1.visibility === 'none') {
  16592. continue;
  16593. }
  16594. var sourceId = layer$1.source || '';
  16595. var sourceGroup = this.familiesBySource[sourceId];
  16596. if (!sourceGroup) {
  16597. sourceGroup = this.familiesBySource[sourceId] = {};
  16598. }
  16599. var sourceLayerId = layer$1.sourceLayer;
  16600. var sourceLayerFamilies = sourceGroup[sourceLayerId];
  16601. if (!sourceLayerFamilies) {
  16602. sourceLayerFamilies = sourceGroup[sourceLayerId] = [];
  16603. }
  16604. sourceLayerFamilies.push(layers);
  16605. }
  16606. };
  16607. WebWorkerTransfer.register('FeatureIndex', FeatureIndex, {omit: ['rawTileData', 'sourceLayerCoder']});
  16608. function MVTWorkTile(parameters, transferableObjects) {
  16609. var pbfData = parameters.pbfData;
  16610. var layers = parameters.layers;
  16611. var imageMap = parameters.imageMap;
  16612. var serializeObj = WebWorkerTransfer.deserialize(parameters.serializeObj);
  16613. var featureIndex = serializeObj.featureIndex;
  16614. var zoom = parameters.tileID.z;
  16615. if(!when.defined(featureIndex)){
  16616. featureIndex = new FeatureIndex(parameters.tileID);
  16617. featureIndex.bucketLayerIDs = [];
  16618. }
  16619. var result = {};
  16620. try {
  16621. var styleIndexLayer = new StyleLayerIndex(layers);
  16622. var vectorTile = loadVectorTile(pbfData);
  16623. result = parse(vectorTile, styleIndexLayer, imageMap, featureIndex, zoom, parameters.indexData);
  16624. result = WebWorkerTransfer.serialize(result, transferableObjects);
  16625. }
  16626. catch (err) {
  16627. }
  16628. result.pickId = parameters.pickId;
  16629. return result;
  16630. }
  16631. function loadVectorTile(rawData) {
  16632. if (!when.defined(rawData)) {
  16633. return;
  16634. }
  16635. return new VectorTile(new pbf.Protobuf(rawData));
  16636. }
  16637. function parse(vectorTile, layerIndex, imageMap, featureIndex, zoom, indexData) {
  16638. var sourceLayerCoder = new DictionaryCoder(Object.keys(vectorTile.layers).sort());
  16639. var buckets = {};
  16640. var options = {
  16641. featureIndex: featureIndex,
  16642. iconDependencies: {},
  16643. patternDependencies: {},
  16644. glyphDependencies: {},
  16645. //availableImages: availableImages
  16646. };
  16647. for (var source in layerIndex.familiesBySource) {
  16648. //if (source == "") continue;
  16649. var layerFamilies = layerIndex.familiesBySource[source];
  16650. for (var sourceLayerId in layerFamilies) {
  16651. var sourceLayer = vectorTile.layers[sourceLayerId];
  16652. if (!sourceLayer) {
  16653. continue;
  16654. }
  16655. var sourceLayerIndex = sourceLayerCoder.encode(sourceLayerId);
  16656. var features = [];
  16657. for (var index = 0; index < sourceLayer.length; index++) {
  16658. var feature = sourceLayer.feature(index);
  16659. features.push({feature: feature, index: index, sourceLayerIndex: sourceLayerIndex, sourceLayerId: sourceLayerId});
  16660. }
  16661. for (var i = 0, list = layerFamilies[sourceLayerId]; i < list.length; i += 1) {
  16662. var family = list[i];
  16663. var layer = family[0];
  16664. // if(defined(layer.minzoom) && zoom < Math.floor(layer.minzoom)){
  16665. // continue;
  16666. // }
  16667. // if(defined(layer.maxzoom) && zoom >= layer.maxzoom){
  16668. // continue;
  16669. // }
  16670. if (layer.visibility === 'none') {
  16671. continue;
  16672. }
  16673. //recalculateLayers(family, this.zoom, availableImages);
  16674. recalculateLayers(family, 0, null);
  16675. var bucketName = layer.id;
  16676. var bucket = buckets[bucketName] = layer.createBucket({
  16677. index: featureIndex.bucketLayerIDs.length,
  16678. layers: family,
  16679. // zoom: this.zoom,
  16680. // pixelRatio: this.pixelRatio,
  16681. // overscaling : this.overscaling,
  16682. // collisionBoxArray: this.collisionBoxArray,
  16683. sourceLayerIndex: sourceLayerIndex,
  16684. //sourceID: this.source
  16685. });
  16686. if (when.defined(indexData) && when.defined(indexData[layer.id])) {
  16687. options.indexData = indexData[layer.id];
  16688. }
  16689. bucket.populate(features, options);
  16690. featureIndex.bucketLayerIDs.push(family.map(function (l) { return l.id; }));
  16691. }
  16692. }
  16693. }
  16694. var imageAtlas = null;
  16695. for (var key in buckets) {
  16696. var bucket = buckets[key];
  16697. if (bucket.hasPattern &&
  16698. (bucket instanceof LineBucket || bucket instanceof FillBucket)) {
  16699. //recalculateLayers(bucket.layers, this.zoom, availableImages);
  16700. if(imageAtlas == null){
  16701. imageAtlas = new ImageAtlas({}, imageMap);
  16702. }
  16703. bucket.addFeatures(options, imageAtlas.patternPositions);
  16704. }
  16705. }
  16706. return {
  16707. buckets : buckets,
  16708. imageAtlas : imageAtlas,
  16709. featureIndex : featureIndex
  16710. };
  16711. }
  16712. function recalculateLayers(layers, zoom, availableImages) {
  16713. // Layers are shared and may have been used by a WorkerTile with a different zoom.
  16714. var parameters = new EvaluationParameters$1(zoom);
  16715. for (var i = 0, list = layers; i < list.length; i += 1) {
  16716. var layer = list[i];
  16717. layer.recalculate(parameters, availableImages);
  16718. }
  16719. }
  16720. var MVTWorkTile$1 = createTaskProcessorWorker(MVTWorkTile);
  16721. return MVTWorkTile$1;
  16722. });