gonzales.js 548 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811188121881318814188151881618817188181881918820188211882218823188241882518826188271882818829188301883118832188331883418835188361883718838188391884018841188421884318844188451884618847188481884918850188511885218853188541885518856188571885818859188601886118862188631886418865188661886718868188691887018871188721887318874188751887618877188781887918880188811888218883188841888518886188871888818889188901889118892188931889418895188961889718898188991890018901189021890318904189051890618907189081890918910189111891218913189141891518916189171891818919189201892118922189231892418925189261892718928189291893018931189321893318934189351893618937189381893918940189411894218943189441894518946189471894818949189501895118952189531895418955189561895718958189591896018961189621896318964189651896618967189681896918970189711897218973189741897518976189771897818979189801898118982189831898418985189861898718988189891899018991189921899318994189951899618997189981899919000190011900219003190041900519006190071900819009190101901119012190131901419015190161901719018190191902019021190221902319024190251902619027190281902919030190311903219033190341903519036190371903819039190401904119042190431904419045190461904719048190491905019051190521905319054190551905619057190581905919060190611906219063190641906519066190671906819069190701907119072190731907419075190761907719078190791908019081190821908319084190851908619087190881908919090190911909219093190941909519096190971909819099191001910119102191031910419105191061910719108191091911019111191121911319114191151911619117191181911919120191211912219123191241912519126191271912819129191301913119132191331913419135191361913719138191391914019141191421914319144191451914619147191481914919150191511915219153191541915519156191571915819159191601916119162191631916419165191661916719168191691917019171191721917319174191751917619177191781917919180191811918219183191841918519186191871918819189191901919119192191931919419195191961919719198191991920019201192021920319204192051920619207192081920919210192111921219213192141921519216192171921819219192201922119222192231922419225192261922719228192291923019231192321923319234192351923619237192381923919240192411924219243192441924519246192471924819249192501925119252192531925419255192561925719258192591926019261192621926319264192651926619267192681926919270192711927219273192741927519276192771927819279192801928119282192831928419285192861928719288192891929019291192921929319294192951929619297192981929919300193011930219303193041930519306193071930819309193101931119312193131931419315193161931719318193191932019321193221932319324193251932619327193281932919330193311933219333193341933519336193371933819339193401934119342193431934419345193461934719348193491935019351193521935319354193551935619357193581935919360193611936219363193641936519366193671936819369193701937119372193731937419375193761937719378193791938019381193821938319384193851938619387193881938919390193911939219393193941939519396193971939819399194001940119402194031940419405194061940719408194091941019411194121941319414194151941619417194181941919420194211942219423194241942519426194271942819429194301943119432194331943419435194361943719438194391944019441194421944319444194451944619447194481944919450194511945219453194541945519456194571945819459194601946119462194631946419465194661946719468194691947019471194721947319474194751947619477194781947919480194811948219483194841948519486194871948819489194901949119492194931949419495194961949719498194991950019501195021950319504195051950619507195081950919510195111951219513195141951519516195171951819519195201952119522195231952419525195261952719528195291953019531195321953319534195351953619537195381953919540195411954219543195441954519546195471954819549195501955119552195531955419555195561955719558195591956019561195621956319564195651956619567195681956919570195711957219573195741957519576195771957819579195801958119582195831958419585195861958719588195891959019591195921959319594195951959619597195981959919600196011960219603196041960519606196071960819609196101961119612196131961419615196161961719618196191962019621196221962319624196251962619627196281962919630196311963219633196341963519636196371963819639196401964119642196431964419645196461964719648196491965019651196521965319654196551965619657196581965919660196611966219663196641966519666196671966819669196701967119672196731967419675196761967719678196791968019681196821968319684196851968619687196881968919690196911969219693196941969519696196971969819699197001970119702197031970419705197061970719708197091971019711197121971319714197151971619717197181971919720197211972219723197241972519726197271972819729197301973119732197331973419735197361973719738197391974019741197421974319744197451974619747197481974919750197511975219753197541975519756197571975819759197601976119762197631976419765197661976719768197691977019771197721977319774197751977619777197781977919780197811978219783197841978519786197871978819789197901979119792197931979419795197961979719798197991980019801198021980319804198051980619807198081980919810198111981219813198141981519816198171981819819198201982119822198231982419825198261982719828198291983019831198321983319834198351983619837198381983919840198411984219843198441984519846198471984819849198501985119852198531985419855198561985719858198591986019861198621986319864198651986619867198681986919870198711987219873198741987519876198771987819879198801988119882198831988419885198861988719888198891989019891198921989319894198951989619897198981989919900199011990219903199041990519906199071990819909199101991119912199131991419915199161991719918199191992019921199221992319924199251992619927199281992919930199311993219933199341993519936199371993819939199401994119942199431994419945199461994719948199491995019951199521995319954199551995619957199581995919960199611996219963199641996519966199671996819969199701997119972199731997419975199761997719978199791998019981199821998319984199851998619987199881998919990199911999219993199941999519996199971999819999200002000120002200032000420005200062000720008200092001020011200122001320014200152001620017200182001920020200212002220023200242002520026200272002820029200302003120032200332003420035200362003720038200392004020041200422004320044200452004620047200482004920050200512005220053200542005520056200572005820059200602006120062200632006420065200662006720068200692007020071200722007320074200752007620077200782007920080200812008220083200842008520086200872008820089200902009120092200932009420095200962009720098200992010020101201022010320104201052010620107201082010920110201112011220113201142011520116201172011820119201202012120122201232012420125201262012720128201292013020131201322013320134201352013620137201382013920140201412014220143201442014520146201472014820149201502015120152201532015420155201562015720158201592016020161201622016320164201652016620167201682016920170201712017220173201742017520176201772017820179201802018120182201832018420185201862018720188201892019020191201922019320194201952019620197201982019920200202012020220203202042020520206202072020820209202102021120212202132021420215202162021720218202192022020221202222022320224202252022620227202282022920230202312023220233202342023520236202372023820239202402024120242202432024420245202462024720248202492025020251202522025320254202552025620257202582025920260202612026220263202642026520266202672026820269202702027120272202732027420275202762027720278202792028020281202822028320284202852028620287202882028920290202912029220293202942029520296202972029820299203002030120302203032030420305203062030720308203092031020311203122031320314203152031620317203182031920320203212032220323203242032520326203272032820329203302033120332203332033420335203362033720338203392034020341203422034320344203452034620347203482034920350203512035220353203542035520356203572035820359203602036120362203632036420365203662036720368203692037020371203722037320374203752037620377203782037920380203812038220383203842038520386203872038820389203902039120392203932039420395203962039720398203992040020401204022040320404204052040620407204082040920410204112041220413204142041520416204172041820419204202042120422204232042420425204262042720428204292043020431204322043320434204352043620437204382043920440204412044220443204442044520446204472044820449204502045120452204532045420455204562045720458204592046020461204622046320464204652046620467204682046920470204712047220473204742047520476204772047820479204802048120482204832048420485204862048720488204892049020491204922049320494204952049620497204982049920500205012050220503205042050520506205072050820509205102051120512205132051420515205162051720518205192052020521205222052320524205252052620527205282052920530205312053220533205342053520536205372053820539205402054120542205432054420545205462054720548205492055020551205522055320554205552055620557205582055920560205612056220563205642056520566205672056820569205702057120572205732057420575205762057720578205792058020581205822058320584205852058620587205882058920590205912059220593205942059520596205972059820599206002060120602206032060420605206062060720608206092061020611206122061320614206152061620617206182061920620206212062220623206242062520626206272062820629206302063120632206332063420635206362063720638206392064020641206422064320644206452064620647206482064920650206512065220653206542065520656206572065820659206602066120662206632066420665206662066720668206692067020671206722067320674206752067620677206782067920680206812068220683206842068520686206872068820689206902069120692206932069420695206962069720698206992070020701207022070320704207052070620707207082070920710207112071220713207142071520716207172071820719207202072120722207232072420725207262072720728207292073020731207322073320734207352073620737207382073920740207412074220743207442074520746207472074820749207502075120752207532075420755207562075720758207592076020761207622076320764207652076620767207682076920770207712077220773207742077520776207772077820779207802078120782207832078420785207862078720788207892079020791207922079320794207952079620797207982079920800208012080220803208042080520806208072080820809208102081120812208132081420815208162081720818208192082020821208222082320824208252082620827208282082920830208312083220833208342083520836208372083820839208402084120842208432084420845208462084720848208492085020851208522085320854208552085620857208582085920860208612086220863208642086520866208672086820869208702087120872208732087420875208762087720878208792088020881208822088320884208852088620887208882088920890208912089220893208942089520896208972089820899209002090120902209032090420905209062090720908209092091020911209122091320914209152091620917209182091920920209212092220923209242092520926209272092820929209302093120932209332093420935209362093720938209392094020941209422094320944209452094620947209482094920950209512095220953209542095520956209572095820959209602096120962209632096420965209662096720968209692097020971209722097320974209752097620977209782097920980209812098220983209842098520986209872098820989209902099120992209932099420995209962099720998209992100021001210022100321004210052100621007210082100921010210112101221013210142101521016210172101821019210202102121022210232102421025210262102721028210292103021031210322103321034210352103621037210382103921040210412104221043210442104521046210472104821049210502105121052210532105421055210562105721058210592106021061210622106321064210652106621067210682106921070210712107221073210742107521076210772107821079210802108121082210832108421085210862108721088210892109021091210922109321094210952109621097210982109921100211012110221103211042110521106211072110821109211102111121112211132111421115211162111721118211192112021121211222112321124211252112621127211282112921130211312113221133211342113521136211372113821139211402114121142211432114421145211462114721148211492115021151211522115321154211552115621157211582115921160211612116221163211642116521166211672116821169211702117121172211732117421175211762117721178211792118021181211822118321184211852118621187211882118921190211912119221193211942119521196211972119821199212002120121202212032120421205212062120721208212092121021211212122121321214212152121621217212182121921220212212122221223212242122521226212272122821229212302123121232212332123421235212362123721238212392124021241212422124321244212452124621247212482124921250212512125221253212542125521256212572125821259212602126121262212632126421265212662126721268212692127021271212722127321274212752127621277212782127921280212812128221283212842128521286212872128821289212902129121292212932129421295212962129721298212992130021301213022130321304213052130621307213082130921310213112131221313213142131521316213172131821319213202132121322213232132421325213262132721328213292133021331213322133321334213352133621337213382133921340213412134221343213442134521346213472134821349213502135121352213532135421355213562135721358213592136021361213622136321364213652136621367213682136921370213712137221373213742137521376213772137821379213802138121382213832138421385213862138721388213892139021391213922139321394213952139621397213982139921400214012140221403214042140521406214072140821409214102141121412214132141421415214162141721418214192142021421214222142321424214252142621427214282142921430214312143221433214342143521436214372143821439214402144121442214432144421445214462144721448214492145021451214522145321454214552145621457214582145921460214612146221463214642146521466214672146821469214702147121472214732147421475214762147721478214792148021481214822148321484214852148621487214882148921490214912149221493214942149521496214972149821499215002150121502215032150421505215062150721508215092151021511215122151321514215152151621517215182151921520215212152221523215242152521526215272152821529215302153121532215332153421535215362153721538215392154021541215422154321544215452154621547215482154921550215512155221553215542155521556215572155821559215602156121562215632156421565215662156721568215692157021571215722157321574215752157621577215782157921580215812158221583215842158521586215872158821589215902159121592215932159421595215962159721598215992160021601216022160321604216052160621607216082160921610216112161221613216142161521616216172161821619216202162121622216232162421625216262162721628216292163021631216322163321634216352163621637216382163921640216412164221643216442164521646216472164821649216502165121652216532165421655216562165721658216592166021661216622166321664216652166621667216682166921670216712167221673216742167521676216772167821679216802168121682216832168421685216862168721688216892169021691216922169321694216952169621697216982169921700217012170221703217042170521706217072170821709217102171121712217132171421715217162171721718217192172021721217222172321724217252172621727217282172921730217312173221733217342173521736217372173821739217402174121742217432174421745217462174721748217492175021751217522175321754217552175621757217582175921760217612176221763217642176521766217672176821769217702177121772217732177421775217762177721778217792178021781217822178321784217852178621787217882178921790217912179221793217942179521796217972179821799218002180121802218032180421805218062180721808218092181021811218122181321814218152181621817218182181921820218212182221823218242182521826218272182821829218302183121832218332183421835218362183721838218392184021841218422184321844218452184621847218482184921850218512185221853218542185521856218572185821859218602186121862218632186421865218662186721868218692187021871218722187321874218752187621877218782187921880218812188221883218842188521886218872188821889218902189121892218932189421895218962189721898218992190021901219022190321904219052190621907219082190921910219112191221913219142191521916219172191821919219202192121922219232192421925219262192721928219292193021931219322193321934219352193621937219382193921940219412194221943219442194521946219472194821949219502195121952219532195421955219562195721958219592196021961219622196321964219652196621967219682196921970219712197221973219742197521976219772197821979219802198121982219832198421985219862198721988219892199021991219922199321994219952199621997219982199922000220012200222003220042200522006220072200822009220102201122012220132201422015220162201722018220192202022021220222202322024220252202622027220282202922030220312203222033220342203522036220372203822039220402204122042220432204422045220462204722048220492205022051220522205322054220552205622057220582205922060220612206222063220642206522066220672206822069220702207122072220732207422075220762207722078220792208022081220822208322084220852208622087220882208922090220912209222093220942209522096220972209822099221002210122102221032210422105221062210722108221092211022111221122211322114221152211622117221182211922120221212212222123221242212522126221272212822129221302213122132221332213422135221362213722138221392214022141221422214322144221452214622147221482214922150221512215222153221542215522156221572215822159221602216122162221632216422165221662216722168221692217022171221722217322174221752217622177221782217922180221812218222183221842218522186221872218822189221902219122192221932219422195221962219722198221992220022201222022220322204222052220622207222082220922210222112221222213222142221522216222172221822219222202222122222222232222422225222262222722228222292223022231222322223322234222352223622237222382223922240222412224222243222442224522246222472224822249222502225122252222532225422255222562225722258222592226022261222622226322264222652226622267222682226922270222712227222273222742227522276222772227822279222802228122282222832228422285222862228722288222892229022291222922229322294222952229622297222982229922300223012230222303223042230522306223072230822309223102231122312223132231422315223162231722318223192232022321223222232322324223252232622327223282232922330223312233222333223342233522336223372233822339223402234122342223432234422345223462234722348223492235022351223522235322354223552235622357223582235922360223612236222363223642236522366223672236822369223702237122372223732237422375223762237722378223792238022381223822238322384223852238622387223882238922390223912239222393223942239522396223972239822399224002240122402224032240422405224062240722408224092241022411224122241322414224152241622417224182241922420224212242222423224242242522426224272242822429224302243122432224332243422435
  1. (function webpackUniversalModuleDefinition(root, factory) {
  2. if(typeof exports === 'object' && typeof module === 'object')
  3. module.exports = factory();
  4. else if(typeof define === 'function' && define.amd)
  5. define([], factory);
  6. else if(typeof exports === 'object')
  7. exports["gonzales"] = factory();
  8. else
  9. root["gonzales"] = factory();
  10. })(this, function() {
  11. return /******/ (function(modules) { // webpackBootstrap
  12. /******/ // The module cache
  13. /******/ var installedModules = {};
  14. /******/ // The require function
  15. /******/ function __webpack_require__(moduleId) {
  16. /******/ // Check if module is in cache
  17. /******/ if(installedModules[moduleId])
  18. /******/ return installedModules[moduleId].exports;
  19. /******/ // Create a new module (and put it into the cache)
  20. /******/ var module = installedModules[moduleId] = {
  21. /******/ exports: {},
  22. /******/ id: moduleId,
  23. /******/ loaded: false
  24. /******/ };
  25. /******/ // Execute the module function
  26. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  27. /******/ // Flag the module as loaded
  28. /******/ module.loaded = true;
  29. /******/ // Return the exports of the module
  30. /******/ return module.exports;
  31. /******/ }
  32. /******/ // expose the modules object (__webpack_modules__)
  33. /******/ __webpack_require__.m = modules;
  34. /******/ // expose the module cache
  35. /******/ __webpack_require__.c = installedModules;
  36. /******/ // __webpack_public_path__
  37. /******/ __webpack_require__.p = "";
  38. /******/ // Load entry module and return exports
  39. /******/ return __webpack_require__(0);
  40. /******/ })
  41. /************************************************************************/
  42. /******/ ([
  43. /* 0 */
  44. /***/ (function(module, exports, __webpack_require__) {
  45. 'use strict';
  46. var Node = __webpack_require__(1);
  47. var parse = __webpack_require__(7);
  48. module.exports = {
  49. createNode: function createNode(options) {
  50. return new Node(options);
  51. },
  52. parse: parse
  53. };
  54. /***/ }),
  55. /* 1 */
  56. /***/ (function(module, exports, __webpack_require__) {
  57. 'use strict';
  58. /**
  59. * @param {string} type
  60. * @param {array|string} content
  61. * @param {number} line
  62. * @param {number} column
  63. * @constructor
  64. */
  65. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  66. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  67. var Node = function () {
  68. function Node(options) {
  69. _classCallCheck(this, Node);
  70. this.type = options.type;
  71. this.content = options.content;
  72. this.syntax = options.syntax;
  73. if (options.start) this.start = options.start;
  74. if (options.end) this.end = options.end;
  75. }
  76. /**
  77. * @param {String} type Node type
  78. * @return {Boolean} Whether there is a child node of given type
  79. */
  80. Node.prototype.contains = function contains(type) {
  81. if (!Array.isArray(this.content)) {
  82. return false;
  83. }
  84. return this.content.some(function (node) {
  85. return node.type === type;
  86. });
  87. };
  88. /**
  89. * @param {String} type Node type
  90. * @param {Function} callback Function to call for every found node
  91. */
  92. Node.prototype.eachFor = function eachFor(type, callback) {
  93. if (!Array.isArray(this.content)) return;
  94. if (typeof type !== 'string') {
  95. callback = type;
  96. type = null;
  97. }
  98. var l = this.content.length;
  99. var breakLoop;
  100. for (var i = l; i--;) {
  101. if (breakLoop === null) break;
  102. if (!type || this.content[i] && this.content[i].type === type) breakLoop = callback(this.content[i], i, this);
  103. }
  104. if (breakLoop === null) return null;
  105. };
  106. /**
  107. * @param {String} type
  108. * @return {?Node} First child node or `null` if nothing's been found.
  109. */
  110. Node.prototype.first = function first(type) {
  111. if (!Array.isArray(this.content)) return null;
  112. if (!type) return this.content[0];
  113. var i = 0;
  114. var l = this.content.length;
  115. for (; i < l; i++) {
  116. if (this.content[i].type === type) return this.content[i];
  117. }
  118. return null;
  119. };
  120. /**
  121. * @param {String} type Node type
  122. * @param {Function} callback Function to call for every found node
  123. */
  124. Node.prototype.forEach = function forEach(type, callback) {
  125. if (!Array.isArray(this.content)) return;
  126. if (typeof type !== 'string') {
  127. callback = type;
  128. type = null;
  129. }
  130. var i = 0;
  131. var l = this.content.length;
  132. var breakLoop;
  133. for (; i < l; i++) {
  134. if (breakLoop === null) break;
  135. if (!type || this.content[i] && this.content[i].type === type) breakLoop = callback(this.content[i], i, this);
  136. }
  137. if (breakLoop === null) return null;
  138. };
  139. /**
  140. * @param {Number} index
  141. * @return {?Node}
  142. */
  143. Node.prototype.get = function get(index) {
  144. if (!Array.isArray(this.content)) return null;
  145. var node = this.content[index];
  146. return node ? node : null;
  147. };
  148. /**
  149. * @param {Number} index
  150. * @param {Node} node
  151. */
  152. Node.prototype.insert = function insert(index, node) {
  153. if (!Array.isArray(this.content)) return;
  154. this.content.splice(index, 0, node);
  155. };
  156. /**
  157. * @param {String} type
  158. * @return {Boolean} Whether the node is of given type
  159. */
  160. Node.prototype.is = function is(type) {
  161. return this.type === type;
  162. };
  163. /**
  164. * @param {String} type
  165. * @return {?Node} Last child node or `null` if nothing's been found.
  166. */
  167. Node.prototype.last = function last(type) {
  168. if (!Array.isArray(this.content)) return null;
  169. var i = this.content.length;
  170. if (!type) return this.content[i - 1];
  171. for (; i--;) {
  172. if (this.content[i].type === type) return this.content[i];
  173. }
  174. return null;
  175. };
  176. /**
  177. * Number of child nodes.
  178. * @type {number}
  179. */
  180. /**
  181. * @param {Number} index
  182. * @return {Node}
  183. */
  184. Node.prototype.removeChild = function removeChild(index) {
  185. if (!Array.isArray(this.content)) return;
  186. var removedChild = this.content.splice(index, 1);
  187. return removedChild;
  188. };
  189. Node.prototype.toJson = function toJson() {
  190. return JSON.stringify(this, false, 2);
  191. };
  192. Node.prototype.toString = function toString() {
  193. var stringify = void 0;
  194. try {
  195. stringify = __webpack_require__(2)("./" + this.syntax + '/stringify');
  196. } catch (e) {
  197. var message = 'Syntax "' + this.syntax + '" is not supported yet, sorry';
  198. return console.error(message);
  199. }
  200. return stringify(this);
  201. };
  202. /**
  203. * @param {Function} callback
  204. */
  205. Node.prototype.traverse = function traverse(callback, index) {
  206. var level = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
  207. var parent = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;
  208. var breakLoop;
  209. var x;
  210. level++;
  211. callback(this, index, parent, level);
  212. if (!Array.isArray(this.content)) return;
  213. for (var i = 0, l = this.content.length; i < l; i++) {
  214. breakLoop = this.content[i].traverse(callback, i, level, this);
  215. if (breakLoop === null) break;
  216. // If some nodes were removed or added:
  217. if (x = this.content.length - l) {
  218. l += x;
  219. i += x;
  220. }
  221. }
  222. if (breakLoop === null) return null;
  223. };
  224. Node.prototype.traverseByType = function traverseByType(type, callback) {
  225. this.traverse(function (node) {
  226. if (node.type === type) callback.apply(node, arguments);
  227. });
  228. };
  229. Node.prototype.traverseByTypes = function traverseByTypes(types, callback) {
  230. this.traverse(function (node) {
  231. if (types.indexOf(node.type) !== -1) callback.apply(node, arguments);
  232. });
  233. };
  234. _createClass(Node, [{
  235. key: 'length',
  236. get: function get() {
  237. if (!Array.isArray(this.content)) return 0;
  238. return this.content.length;
  239. }
  240. }]);
  241. return Node;
  242. }();
  243. module.exports = Node;
  244. /***/ }),
  245. /* 2 */
  246. /***/ (function(module, exports, __webpack_require__) {
  247. var map = {
  248. "./css/stringify": 3,
  249. "./less/stringify": 4,
  250. "./sass/stringify": 5,
  251. "./scss/stringify": 6
  252. };
  253. function webpackContext(req) {
  254. return __webpack_require__(webpackContextResolve(req));
  255. };
  256. function webpackContextResolve(req) {
  257. return map[req] || (function() { throw new Error("Cannot find module '" + req + "'.") }());
  258. };
  259. webpackContext.keys = function webpackContextKeys() {
  260. return Object.keys(map);
  261. };
  262. webpackContext.resolve = webpackContextResolve;
  263. module.exports = webpackContext;
  264. webpackContext.id = 2;
  265. /***/ }),
  266. /* 3 */
  267. /***/ (function(module, exports) {
  268. 'use strict';
  269. module.exports = function stringify(tree) {
  270. // TODO: Better error message
  271. if (!tree) throw new Error('We need tree to translate');
  272. function _t(tree) {
  273. var type = tree.type;
  274. if (_unique[type]) return _unique[type](tree);
  275. if (typeof tree.content === 'string') return tree.content;
  276. if (Array.isArray(tree.content)) return _composite(tree.content);
  277. return '';
  278. }
  279. function _composite(t, i) {
  280. if (!t) return '';
  281. var s = '';
  282. i = i || 0;
  283. for (; i < t.length; i++) {
  284. s += _t(t[i]);
  285. }return s;
  286. }
  287. var _unique = {
  288. 'arguments': function _arguments(t) {
  289. return '(' + _composite(t.content) + ')';
  290. },
  291. 'atkeyword': function atkeyword(t) {
  292. return '@' + _composite(t.content);
  293. },
  294. 'attributeSelector': function attributeSelector(t) {
  295. return '[' + _composite(t.content) + ']';
  296. },
  297. 'block': function block(t) {
  298. return '{' + _composite(t.content) + '}';
  299. },
  300. 'brackets': function brackets(t) {
  301. return '[' + _composite(t.content) + ']';
  302. },
  303. 'class': function _class(t) {
  304. return '.' + _composite(t.content);
  305. },
  306. 'color': function color(t) {
  307. return '#' + t.content;
  308. },
  309. 'customProperty': function customProperty(t) {
  310. return '--' + t.content;
  311. },
  312. 'expression': function expression(t) {
  313. return 'expression(' + t.content + ')';
  314. },
  315. 'id': function id(t) {
  316. return '#' + _composite(t.content);
  317. },
  318. 'multilineComment': function multilineComment(t) {
  319. return '/*' + t.content + '*/';
  320. },
  321. 'nthSelector': function nthSelector(t) {
  322. return ':' + _t(t.content[0]) + '(' + _composite(t.content.slice(1)) + ')';
  323. },
  324. 'parentheses': function parentheses(t) {
  325. return '(' + _composite(t.content) + ')';
  326. },
  327. 'percentage': function percentage(t) {
  328. return _composite(t.content) + '%';
  329. },
  330. 'pseudoClass': function pseudoClass(t) {
  331. return ':' + _composite(t.content);
  332. },
  333. 'pseudoElement': function pseudoElement(t) {
  334. return '::' + _composite(t.content);
  335. },
  336. 'universalSelector': function universalSelector(t) {
  337. return _composite(t.content) + '*';
  338. },
  339. 'uri': function uri(t) {
  340. return 'url(' + _composite(t.content) + ')';
  341. }
  342. };
  343. return _t(tree);
  344. };
  345. /***/ }),
  346. /* 4 */
  347. /***/ (function(module, exports) {
  348. 'use strict';
  349. module.exports = function stringify(tree) {
  350. // TODO: Better error message
  351. if (!tree) throw new Error('We need tree to translate');
  352. function _t(tree) {
  353. var type = tree.type;
  354. if (_unique[type]) return _unique[type](tree);
  355. if (typeof tree.content === 'string') return tree.content;
  356. if (Array.isArray(tree.content)) return _composite(tree.content);
  357. return '';
  358. }
  359. function _composite(t, i) {
  360. if (!t) return '';
  361. var s = '';
  362. i = i || 0;
  363. for (; i < t.length; i++) {
  364. s += _t(t[i]);
  365. }return s;
  366. }
  367. var _unique = {
  368. 'arguments': function _arguments(t) {
  369. return '(' + _composite(t.content) + ')';
  370. },
  371. 'atkeyword': function atkeyword(t) {
  372. return '@' + _composite(t.content);
  373. },
  374. 'attributeSelector': function attributeSelector(t) {
  375. return '[' + _composite(t.content) + ']';
  376. },
  377. 'block': function block(t) {
  378. return '{' + _composite(t.content) + '}';
  379. },
  380. 'brackets': function brackets(t) {
  381. return '[' + _composite(t.content) + ']';
  382. },
  383. 'class': function _class(t) {
  384. return '.' + _composite(t.content);
  385. },
  386. 'color': function color(t) {
  387. return '#' + t.content;
  388. },
  389. 'escapedString': function escapedString(t) {
  390. return '~' + t.content;
  391. },
  392. 'expression': function expression(t) {
  393. return 'expression(' + t.content + ')';
  394. },
  395. 'id': function id(t) {
  396. return '#' + _composite(t.content);
  397. },
  398. 'interpolatedVariable': function interpolatedVariable(t) {
  399. return '@{' + _composite(t.content) + '}';
  400. },
  401. 'multilineComment': function multilineComment(t) {
  402. return '/*' + t.content + '*/';
  403. },
  404. 'nthSelector': function nthSelector(t) {
  405. return ':' + _t(t.content[0]) + '(' + _composite(t.content.slice(1)) + ')';
  406. },
  407. 'parentheses': function parentheses(t) {
  408. return '(' + _composite(t.content) + ')';
  409. },
  410. 'percentage': function percentage(t) {
  411. return _composite(t.content) + '%';
  412. },
  413. 'pseudoClass': function pseudoClass(t) {
  414. return ':' + _composite(t.content);
  415. },
  416. 'pseudoElement': function pseudoElement(t) {
  417. return '::' + _composite(t.content);
  418. },
  419. 'singlelineComment': function singlelineComment(t) {
  420. return '/' + '/' + t.content;
  421. },
  422. 'universalSelector': function universalSelector(t) {
  423. return _composite(t.content) + '*';
  424. },
  425. 'uri': function uri(t) {
  426. return 'url(' + _composite(t.content) + ')';
  427. },
  428. 'variable': function variable(t) {
  429. return '@' + _composite(t.content);
  430. },
  431. 'variablesList': function variablesList(t) {
  432. return _composite(t.content) + '...';
  433. }
  434. };
  435. return _t(tree);
  436. };
  437. /***/ }),
  438. /* 5 */
  439. /***/ (function(module, exports) {
  440. 'use strict';
  441. module.exports = function stringify(tree) {
  442. // TODO: Better error message
  443. if (!tree) throw new Error('We need tree to translate');
  444. function _t(tree) {
  445. var type = tree.type;
  446. if (_unique[type]) return _unique[type](tree);
  447. if (typeof tree.content === 'string') return tree.content;
  448. if (Array.isArray(tree.content)) return _composite(tree.content);
  449. return '';
  450. }
  451. function _composite(t, i) {
  452. if (!t) return '';
  453. var s = '';
  454. i = i || 0;
  455. for (; i < t.length; i++) {
  456. s += _t(t[i]);
  457. }return s;
  458. }
  459. var _unique = {
  460. 'arguments': function _arguments(t) {
  461. return '(' + _composite(t.content) + ')';
  462. },
  463. 'atkeyword': function atkeyword(t) {
  464. return '@' + _composite(t.content);
  465. },
  466. 'attributeSelector': function attributeSelector(t) {
  467. return '[' + _composite(t.content) + ']';
  468. },
  469. 'block': function block(t) {
  470. return _composite(t.content);
  471. },
  472. 'brackets': function brackets(t) {
  473. return '[' + _composite(t.content) + ']';
  474. },
  475. 'class': function _class(t) {
  476. return '.' + _composite(t.content);
  477. },
  478. 'color': function color(t) {
  479. return '#' + t.content;
  480. },
  481. 'customProperty': function customProperty(t) {
  482. return '--' + t.content;
  483. },
  484. 'expression': function expression(t) {
  485. return 'expression(' + t.content + ')';
  486. },
  487. 'functionsList': function functionsList(t) {
  488. return _composite(t.content) + '...';
  489. },
  490. 'id': function id(t) {
  491. return '#' + _composite(t.content);
  492. },
  493. 'interpolation': function interpolation(t) {
  494. return '#{' + _composite(t.content) + '}';
  495. },
  496. 'multilineComment': function multilineComment(t) {
  497. var lines = t.content.split('\n');
  498. var close = '';
  499. if (lines.length > 1) {
  500. var lastLine = lines[lines.length - 1];
  501. if (lastLine.length < t.end.column) {
  502. close = '*/';
  503. }
  504. } else if (t.content.length + 4 === t.end.column - t.start.column + 1) {
  505. close = '*/';
  506. }
  507. return '/*' + t.content + close;
  508. },
  509. 'nthSelector': function nthSelector(t) {
  510. return ':' + _t(t.content[0]) + '(' + _composite(t.content.slice(1)) + ')';
  511. },
  512. 'parentheses': function parentheses(t) {
  513. return '(' + _composite(t.content) + ')';
  514. },
  515. 'percentage': function percentage(t) {
  516. return _composite(t.content) + '%';
  517. },
  518. 'placeholder': function placeholder(t) {
  519. return '%' + _composite(t.content);
  520. },
  521. 'pseudoClass': function pseudoClass(t) {
  522. return ':' + _composite(t.content);
  523. },
  524. 'pseudoElement': function pseudoElement(t) {
  525. return '::' + _composite(t.content);
  526. },
  527. 'singlelineComment': function singlelineComment(t) {
  528. return '/' + '/' + t.content;
  529. },
  530. 'universalSelector': function universalSelector(t) {
  531. return _composite(t.content) + '*';
  532. },
  533. 'uri': function uri(t) {
  534. return 'url(' + _composite(t.content) + ')';
  535. },
  536. 'variable': function variable(t) {
  537. return '$' + _composite(t.content);
  538. },
  539. 'variablesList': function variablesList(t) {
  540. return _composite(t.content) + '...';
  541. }
  542. };
  543. return _t(tree);
  544. };
  545. /***/ }),
  546. /* 6 */
  547. /***/ (function(module, exports) {
  548. 'use strict';
  549. module.exports = function stringify(tree) {
  550. // TODO: Better error message
  551. if (!tree) throw new Error('We need tree to translate');
  552. function _t(tree) {
  553. var type = tree.type;
  554. if (_unique[type]) return _unique[type](tree);
  555. if (typeof tree.content === 'string') return tree.content;
  556. if (Array.isArray(tree.content)) return _composite(tree.content);
  557. return '';
  558. }
  559. function _composite(t, i) {
  560. if (!t) return '';
  561. var s = '';
  562. i = i || 0;
  563. for (; i < t.length; i++) {
  564. s += _t(t[i]);
  565. }return s;
  566. }
  567. var _unique = {
  568. 'arguments': function _arguments(t) {
  569. return '(' + _composite(t.content) + ')';
  570. },
  571. 'atkeyword': function atkeyword(t) {
  572. return '@' + _composite(t.content);
  573. },
  574. 'attributeSelector': function attributeSelector(t) {
  575. return '[' + _composite(t.content) + ']';
  576. },
  577. 'block': function block(t) {
  578. return '{' + _composite(t.content) + '}';
  579. },
  580. 'brackets': function brackets(t) {
  581. return '[' + _composite(t.content) + ']';
  582. },
  583. 'class': function _class(t) {
  584. return '.' + _composite(t.content);
  585. },
  586. 'color': function color(t) {
  587. return '#' + t.content;
  588. },
  589. 'customProperty': function customProperty(t) {
  590. return '--' + t.content;
  591. },
  592. 'expression': function expression(t) {
  593. return 'expression(' + t.content + ')';
  594. },
  595. 'functionsList': function functionsList(t) {
  596. return _composite(t.content) + '...';
  597. },
  598. 'id': function id(t) {
  599. return '#' + _composite(t.content);
  600. },
  601. 'interpolation': function interpolation(t) {
  602. return '#{' + _composite(t.content) + '}';
  603. },
  604. 'multilineComment': function multilineComment(t) {
  605. return '/*' + t.content + '*/';
  606. },
  607. 'nthSelector': function nthSelector(t) {
  608. return ':' + _t(t.content[0]) + '(' + _composite(t.content.slice(1)) + ')';
  609. },
  610. 'parentheses': function parentheses(t) {
  611. return '(' + _composite(t.content) + ')';
  612. },
  613. 'percentage': function percentage(t) {
  614. return _composite(t.content) + '%';
  615. },
  616. 'placeholder': function placeholder(t) {
  617. return '%' + _composite(t.content);
  618. },
  619. 'pseudoClass': function pseudoClass(t) {
  620. return ':' + _composite(t.content);
  621. },
  622. 'pseudoElement': function pseudoElement(t) {
  623. return '::' + _composite(t.content);
  624. },
  625. 'singlelineComment': function singlelineComment(t) {
  626. return '/' + '/' + t.content;
  627. },
  628. 'universalSelector': function universalSelector(t) {
  629. return _composite(t.content) + '*';
  630. },
  631. 'uri': function uri(t) {
  632. return 'url(' + _composite(t.content) + ')';
  633. },
  634. 'variable': function variable(t) {
  635. return '$' + _composite(t.content);
  636. },
  637. 'variablesList': function variablesList(t) {
  638. return _composite(t.content) + '...';
  639. }
  640. };
  641. return _t(tree);
  642. };
  643. /***/ }),
  644. /* 7 */
  645. /***/ (function(module, exports, __webpack_require__) {
  646. 'use strict';
  647. var ParsingError = __webpack_require__(8);
  648. var syntaxes = __webpack_require__(10);
  649. var isInteger = Number.isInteger || function (value) {
  650. return typeof value === 'number' && Math.floor(value) === value;
  651. };
  652. /**
  653. * @param {String} css
  654. * @param {Object} options
  655. * @return {Object} AST
  656. */
  657. function parser(css, options) {
  658. if (typeof css !== 'string') throw new Error('Please, pass a string to parse');else if (!css) return __webpack_require__(29)();
  659. var syntax = options && options.syntax || 'css';
  660. var context = options && options.context || 'stylesheet';
  661. var tabSize = options && options.tabSize;
  662. if (!isInteger(tabSize) || tabSize < 1) tabSize = 1;
  663. var syntaxParser = syntaxes[syntax];
  664. if (!syntaxParser) {
  665. var message = 'Syntax "' + syntax + '" is not supported yet, sorry';
  666. return console.error(message);
  667. }
  668. var getTokens = syntaxParser.tokenizer;
  669. var mark = syntaxParser.mark;
  670. var parse = syntaxParser.parse;
  671. var tokens = getTokens(css, tabSize);
  672. mark(tokens);
  673. var ast;
  674. try {
  675. ast = parse(tokens, context);
  676. } catch (e) {
  677. if (!e.syntax) throw e;
  678. throw new ParsingError(e, css);
  679. }
  680. return ast;
  681. }
  682. module.exports = parser;
  683. /***/ }),
  684. /* 8 */
  685. /***/ (function(module, exports, __webpack_require__) {
  686. 'use strict';
  687. var parserPackage = __webpack_require__(9);
  688. /**
  689. * @param {Error} e
  690. * @param {String} css
  691. */
  692. function ParsingError(e, css) {
  693. this.line = e.line;
  694. this.syntax = e.syntax;
  695. this.css_ = css;
  696. }
  697. ParsingError.prototype = {
  698. /**
  699. * @type {String}
  700. * @private
  701. */
  702. customMessage_: '',
  703. /**
  704. * @type {Number}
  705. */
  706. line: null,
  707. /**
  708. * @type {String}
  709. */
  710. name: 'Parsing error',
  711. /**
  712. * @type {String}
  713. */
  714. syntax: null,
  715. /**
  716. * @type {String}
  717. */
  718. version: parserPackage.version,
  719. /**
  720. * @type {String}
  721. */
  722. get context() {
  723. var LINES_AROUND = 2;
  724. var result = [];
  725. var currentLineNumber = this.line;
  726. var start = currentLineNumber - 1 - LINES_AROUND;
  727. var end = currentLineNumber + LINES_AROUND;
  728. var lines = this.css_.split(/\r\n|\r|\n/);
  729. for (var i = start; i < end; i++) {
  730. var line = lines[i];
  731. if (!line) continue;
  732. var ln = i + 1;
  733. var mark = ln === currentLineNumber ? '*' : ' ';
  734. result.push(ln + mark + '| ' + line);
  735. }
  736. return result.join('\n');
  737. },
  738. /**
  739. * @type {String}
  740. */
  741. get message() {
  742. if (this.customMessage_) {
  743. return this.customMessage_;
  744. } else {
  745. var message = 'Please check validity of the block';
  746. if (typeof this.line === 'number') message += ' starting from line #' + this.line;
  747. return message;
  748. }
  749. },
  750. set message(message) {
  751. this.customMessage_ = message;
  752. },
  753. /**
  754. * @return {String}
  755. */
  756. toString: function toString() {
  757. return [this.name + ': ' + this.message, '', this.context, '', 'Syntax: ' + this.syntax, 'Gonzales PE version: ' + this.version].join('\n');
  758. }
  759. };
  760. module.exports = ParsingError;
  761. /***/ }),
  762. /* 9 */
  763. /***/ (function(module, exports) {
  764. module.exports = {"name":"gonzales-pe","description":"Gonzales Preprocessor Edition (fast CSS parser)","version":"4.3.0","homepage":"http://github.com/tonyganch/gonzales-pe","bugs":"http://github.com/tonyganch/gonzales-pe/issues","license":"MIT","author":{"name":"Tony Ganch","email":"tonyganch+github@gmail.com","url":"http://tonyganch.com"},"main":"./lib/gonzales","repository":{"type":"git","url":"http://github.com/tonyganch/gonzales-pe.git"},"scripts":{"autofix-tests":"bash ./scripts/build.sh && bash ./scripts/autofix-tests.sh","build":"bash ./scripts/build.sh","init":"bash ./scripts/init.sh","lint":"bash ./scripts/lint.sh","log":"bash ./scripts/log.sh","prepublishOnly":"bash ./scripts/build.sh","test":"bash ./scripts/test.sh","watch":"bash ./scripts/watch.sh"},"bin":{"gonzales":"./bin/gonzales.js"},"dependencies":{"minimist":"^1.2.5"},"devDependencies":{"babel-core":"^6.18.2","babel-loader":"^6.2.7","babel-plugin-add-module-exports":"^0.2.1","babel-preset-es2015":"^6.18.0","coffee-script":"~1.7.1","eslint":"^3.0.0","jscs":"2.1.0","jshint":"2.10.2","json-loader":"^0.5.3","mocha":"2.2.x","webpack":"^1.12.2","webpack-closure-compiler":"^2.0.2"},"engines":{"node":">=0.6.0"},"files":["MIT-LICENSE.txt","bin/gonzales.js","lib/gonzales.js"]}
  765. /***/ }),
  766. /* 10 */
  767. /***/ (function(module, exports, __webpack_require__) {
  768. 'use strict';
  769. module.exports = {
  770. css: __webpack_require__(11),
  771. less: __webpack_require__(17),
  772. sass: __webpack_require__(21),
  773. scss: __webpack_require__(25)
  774. };
  775. /***/ }),
  776. /* 11 */
  777. /***/ (function(module, exports, __webpack_require__) {
  778. 'use strict';
  779. exports.__esModule = true;
  780. exports.default = {
  781. mark: __webpack_require__(12),
  782. parse: __webpack_require__(14),
  783. stringify: __webpack_require__(3),
  784. tokenizer: __webpack_require__(16)
  785. };
  786. module.exports = exports['default'];
  787. /***/ }),
  788. /* 12 */
  789. /***/ (function(module, exports, __webpack_require__) {
  790. 'use strict';
  791. var TokenType = __webpack_require__(13);
  792. /**
  793. * Mark whitespaces and comments
  794. * @param {Array} tokens
  795. */
  796. function markSpacesAndComments(tokens) {
  797. var tokensLength = tokens.length;
  798. var spaces = [-1, -1];
  799. var type; // Current token's type
  800. // For every token in the token list, mark spaces and line breaks
  801. // as spaces (set both `ws` and `sc` flags). Mark multiline comments
  802. // with `sc` flag.
  803. // If there are several spaces or tabs or line breaks or multiline
  804. // comments in a row, group them: take the last one's index number
  805. // and save it to the first token in the group as a reference:
  806. // e.g., `ws_last = 7` for a group of whitespaces or `sc_last = 9`
  807. // for a group of whitespaces and comments.
  808. for (var i = 0; i < tokensLength; i++) {
  809. type = tokens[i].type;
  810. if (type === TokenType.Space || type === TokenType.Tab || type === TokenType.Newline) {
  811. markSpace(tokens, i, spaces);
  812. } else if (type === TokenType.CommentML) {
  813. markComment(tokens, i, spaces);
  814. } else {
  815. markEndOfSpacesAndComments(tokens, i, spaces);
  816. }
  817. }
  818. markEndOfSpacesAndComments(tokens, i, spaces);
  819. }
  820. function markSpace(tokens, i, spaces) {
  821. var token = tokens[i];
  822. token.ws = true;
  823. token.sc = true;
  824. if (spaces[0] === -1) spaces[0] = i;
  825. if (spaces[1] === -1) spaces[1] = i;
  826. }
  827. function markComment(tokens, i, spaces) {
  828. var ws = spaces[0];
  829. tokens[i].sc = true;
  830. if (ws !== -1) {
  831. tokens[ws].ws_last = i - 1;
  832. spaces[0] = -1;
  833. }
  834. }
  835. function markEndOfSpacesAndComments(tokens, i, spaces) {
  836. var ws = spaces[0];
  837. var sc = spaces[1];
  838. if (ws !== -1) {
  839. tokens[ws].ws_last = i - 1;
  840. spaces[0] = -1;
  841. }
  842. if (sc !== -1) {
  843. tokens[sc].sc_last = i - 1;
  844. spaces[1] = -1;
  845. }
  846. }
  847. /**
  848. * Pair brackets
  849. * @param {Array} tokens
  850. */
  851. function markBrackets(tokens) {
  852. var tokensLength = tokens.length;
  853. var ps = []; // Parentheses
  854. var sbs = []; // Square brackets
  855. var cbs = []; // Curly brackets
  856. var t = void 0; // Current token
  857. // For every token in the token list, if we meet an opening (left)
  858. // bracket, push its index number to a corresponding array.
  859. // If we then meet a closing (right) bracket, look at the corresponding
  860. // array. If there are any elements (records about previously met
  861. // left brackets), take a token of the last left bracket (take
  862. // the last index number from the array and find a token with
  863. // this index number) and save right bracket's index as a reference:
  864. for (var i = 0; i < tokensLength; i++) {
  865. t = tokens[i];
  866. var type = t.type;
  867. if (type === TokenType.LeftParenthesis) {
  868. ps.push(i);
  869. } else if (type === TokenType.RightParenthesis) {
  870. if (ps.length) {
  871. t.left = ps.pop();
  872. tokens[t.left].right = i;
  873. }
  874. } else if (type === TokenType.LeftSquareBracket) {
  875. sbs.push(i);
  876. } else if (type === TokenType.RightSquareBracket) {
  877. if (sbs.length) {
  878. t.left = sbs.pop();
  879. tokens[t.left].right = i;
  880. }
  881. } else if (type === TokenType.LeftCurlyBracket) {
  882. cbs.push(i);
  883. } else if (type === TokenType.RightCurlyBracket) {
  884. if (cbs.length) {
  885. t.left = cbs.pop();
  886. tokens[t.left].right = i;
  887. }
  888. }
  889. }
  890. }
  891. /**
  892. * @param {Array} tokens
  893. */
  894. function markTokens(tokens) {
  895. // Mark paired brackets:
  896. markBrackets(tokens);
  897. // Mark whitespaces and comments:
  898. markSpacesAndComments(tokens);
  899. }
  900. module.exports = markTokens;
  901. /***/ }),
  902. /* 13 */
  903. /***/ (function(module, exports) {
  904. // jscs:disable
  905. 'use strict';
  906. module.exports = {
  907. StringSQ: 'StringSQ',
  908. StringDQ: 'StringDQ',
  909. CommentML: 'CommentML',
  910. CommentSL: 'CommentSL',
  911. Newline: 'Newline',
  912. Space: 'Space',
  913. Tab: 'Tab',
  914. ExclamationMark: 'ExclamationMark', // !
  915. QuotationMark: 'QuotationMark', // "
  916. NumberSign: 'NumberSign', // #
  917. DollarSign: 'DollarSign', // $
  918. PercentSign: 'PercentSign', // %
  919. Ampersand: 'Ampersand', // &
  920. Apostrophe: 'Apostrophe', // '
  921. LeftParenthesis: 'LeftParenthesis', // (
  922. RightParenthesis: 'RightParenthesis', // )
  923. Asterisk: 'Asterisk', // *
  924. PlusSign: 'PlusSign', // +
  925. Comma: 'Comma', // ,
  926. HyphenMinus: 'HyphenMinus', // -
  927. FullStop: 'FullStop', // .
  928. Solidus: 'Solidus', // /
  929. Colon: 'Colon', // :
  930. Semicolon: 'Semicolon', // ;
  931. LessThanSign: 'LessThanSign', // <
  932. EqualsSign: 'EqualsSign', // =
  933. EqualitySign: 'EqualitySign', // ==
  934. InequalitySign: 'InequalitySign', // !=
  935. GreaterThanSign: 'GreaterThanSign', // >
  936. QuestionMark: 'QuestionMark', // ?
  937. CommercialAt: 'CommercialAt', // @
  938. LeftSquareBracket: 'LeftSquareBracket', // [
  939. ReverseSolidus: 'ReverseSolidus', // \
  940. RightSquareBracket: 'RightSquareBracket', // ]
  941. CircumflexAccent: 'CircumflexAccent', // ^
  942. LowLine: 'LowLine', // _
  943. LeftCurlyBracket: 'LeftCurlyBracket', // {
  944. VerticalLine: 'VerticalLine', // |
  945. RightCurlyBracket: 'RightCurlyBracket', // }
  946. Tilde: 'Tilde', // ~
  947. Identifier: 'Identifier',
  948. DecimalNumber: 'DecimalNumber'
  949. };
  950. /***/ }),
  951. /* 14 */
  952. /***/ (function(module, exports, __webpack_require__) {
  953. 'use strict';
  954. var Node = __webpack_require__(1);
  955. var NodeType = __webpack_require__(15);
  956. var TokenType = __webpack_require__(13);
  957. /**
  958. * @type {Array}
  959. */
  960. var tokens = void 0;
  961. /**
  962. * @type {Number}
  963. */
  964. var tokensLength = void 0;
  965. /**
  966. * @type {Number}
  967. */
  968. var pos = void 0;
  969. var contexts = {
  970. 'atkeyword': function atkeyword() {
  971. return checkAtkeyword(pos) && getAtkeyword();
  972. },
  973. 'atrule': function atrule() {
  974. return checkAtrule(pos) && getAtrule();
  975. },
  976. 'attributeSelector': function attributeSelector() {
  977. return checkAttributeSelector(pos) && getAttributeSelector();
  978. },
  979. 'block': function block() {
  980. return checkBlock(pos) && getBlock();
  981. },
  982. 'brackets': function brackets() {
  983. return checkBrackets(pos) && getBrackets();
  984. },
  985. 'class': function _class() {
  986. return checkClass(pos) && getClass();
  987. },
  988. 'combinator': function combinator() {
  989. return checkCombinator(pos) && getCombinator();
  990. },
  991. 'commentML': function commentML() {
  992. return checkCommentML(pos) && getCommentML();
  993. },
  994. 'declaration': function declaration() {
  995. return checkDeclaration(pos) && getDeclaration();
  996. },
  997. 'declDelim': function declDelim() {
  998. return checkDeclDelim(pos) && getDeclDelim();
  999. },
  1000. 'delim': function delim() {
  1001. return checkDelim(pos) && getDelim();
  1002. },
  1003. 'dimension': function dimension() {
  1004. return checkDimension(pos) && getDimension();
  1005. },
  1006. 'expression': function expression() {
  1007. return checkExpression(pos) && getExpression();
  1008. },
  1009. 'function': function _function() {
  1010. return checkFunction(pos) && getFunction();
  1011. },
  1012. 'ident': function ident() {
  1013. return checkIdent(pos) && getIdent();
  1014. },
  1015. 'important': function important() {
  1016. return checkImportant(pos) && getImportant();
  1017. },
  1018. 'namespace': function namespace() {
  1019. return checkNamespace(pos) && getNamespace();
  1020. },
  1021. 'number': function number() {
  1022. return checkNumber(pos) && getNumber();
  1023. },
  1024. 'operator': function operator() {
  1025. return checkOperator(pos) && getOperator();
  1026. },
  1027. 'parentheses': function parentheses() {
  1028. return checkParentheses(pos) && getParentheses();
  1029. },
  1030. 'percentage': function percentage() {
  1031. return checkPercentage(pos) && getPercentage();
  1032. },
  1033. 'progid': function progid() {
  1034. return checkProgid(pos) && getProgid();
  1035. },
  1036. 'property': function property() {
  1037. return checkProperty(pos) && getProperty();
  1038. },
  1039. 'propertyDelim': function propertyDelim() {
  1040. return checkPropertyDelim(pos) && getPropertyDelim();
  1041. },
  1042. 'pseudoc': function pseudoc() {
  1043. return checkPseudoc(pos) && getPseudoc();
  1044. },
  1045. 'pseudoe': function pseudoe() {
  1046. return checkPseudoe(pos) && getPseudoe();
  1047. },
  1048. 'ruleset': function ruleset() {
  1049. return checkRuleset(pos) && getRuleset();
  1050. },
  1051. 's': function s() {
  1052. return checkS(pos) && getS();
  1053. },
  1054. 'selector': function selector() {
  1055. return checkSelector(pos) && getSelector();
  1056. },
  1057. 'shash': function shash() {
  1058. return checkShash(pos) && getShash();
  1059. },
  1060. 'string': function string() {
  1061. return checkString(pos) && getString();
  1062. },
  1063. 'stylesheet': function stylesheet() {
  1064. return checkStylesheet(pos) && getStylesheet();
  1065. },
  1066. 'unary': function unary() {
  1067. return checkUnary(pos) && getUnary();
  1068. },
  1069. 'unicodeRange': function unicodeRange() {
  1070. return checkUnicodeRange(pos) && getUnicodeRange();
  1071. },
  1072. 'universalSelector': function universalSelector() {
  1073. return checkUniversalSelector(pos) && getUniversalSelector();
  1074. },
  1075. 'urange': function urange() {
  1076. return checkUrange(pos) && getUrange();
  1077. },
  1078. 'uri': function uri() {
  1079. return checkUri(pos) && getUri();
  1080. },
  1081. 'value': function value() {
  1082. return checkValue(pos) && getValue();
  1083. },
  1084. 'vhash': function vhash() {
  1085. return checkVhash(pos) && getVhash();
  1086. }
  1087. };
  1088. /**
  1089. * Stop parsing and display error
  1090. * @param {Number=} i Token's index number
  1091. */
  1092. function throwError(i) {
  1093. var ln = tokens[i].ln;
  1094. throw { line: ln, syntax: 'css' };
  1095. }
  1096. /**
  1097. * @param {Object} exclude
  1098. * @param {Number} i Token's index number
  1099. * @return {Number}
  1100. */
  1101. function checkExcluding(exclude, i) {
  1102. var start = i;
  1103. while (i < tokensLength) {
  1104. if (exclude[tokens[i++].type]) break;
  1105. }
  1106. return i - start - 2;
  1107. }
  1108. /**
  1109. * @param {Number} start
  1110. * @param {Number} finish
  1111. * @return {String}
  1112. */
  1113. function joinValues(start, finish) {
  1114. var s = '';
  1115. for (var i = start; i < finish + 1; i++) {
  1116. s += tokens[i].value;
  1117. }
  1118. return s;
  1119. }
  1120. /**
  1121. * @param {Number} start
  1122. * @param {Number} num
  1123. * @return {String}
  1124. */
  1125. function joinValues2(start, num) {
  1126. if (start + num - 1 >= tokensLength) return;
  1127. var s = '';
  1128. for (var i = 0; i < num; i++) {
  1129. s += tokens[start + i].value;
  1130. }
  1131. return s;
  1132. }
  1133. function getLastPosition(content, line, column, colOffset) {
  1134. return typeof content === 'string' ? getLastPositionForString(content, line, column, colOffset) : getLastPositionForArray(content, line, column, colOffset);
  1135. }
  1136. function getLastPositionForString(content, line, column, colOffset) {
  1137. var position = [];
  1138. if (!content) {
  1139. position = [line, column];
  1140. if (colOffset) position[1] += colOffset - 1;
  1141. return position;
  1142. }
  1143. var lastLinebreak = content.lastIndexOf('\n');
  1144. var endsWithLinebreak = lastLinebreak === content.length - 1;
  1145. var splitContent = content.split('\n');
  1146. var linebreaksCount = splitContent.length - 1;
  1147. var prevLinebreak = linebreaksCount === 0 || linebreaksCount === 1 ? -1 : content.length - splitContent[linebreaksCount - 1].length - 2;
  1148. // Line:
  1149. var offset = endsWithLinebreak ? linebreaksCount - 1 : linebreaksCount;
  1150. position[0] = line + offset;
  1151. // Column:
  1152. if (endsWithLinebreak) {
  1153. offset = prevLinebreak !== -1 ? content.length - prevLinebreak : content.length - 1;
  1154. } else {
  1155. offset = linebreaksCount !== 0 ? content.length - lastLinebreak - column - 1 : content.length - 1;
  1156. }
  1157. position[1] = column + offset;
  1158. if (!colOffset) return position;
  1159. if (endsWithLinebreak) {
  1160. position[0]++;
  1161. position[1] = colOffset;
  1162. } else {
  1163. position[1] += colOffset;
  1164. }
  1165. return position;
  1166. }
  1167. function getLastPositionForArray(content, line, column, colOffset) {
  1168. var position = void 0;
  1169. if (content.length === 0) {
  1170. position = [line, column];
  1171. } else {
  1172. var c = content[content.length - 1];
  1173. if (c.hasOwnProperty('end')) {
  1174. position = [c.end.line, c.end.column];
  1175. } else {
  1176. position = getLastPosition(c.content, line, column);
  1177. }
  1178. }
  1179. if (!colOffset) return position;
  1180. if (tokens[pos - 1] && tokens[pos - 1].type !== 'Newline') {
  1181. position[1] += colOffset;
  1182. } else {
  1183. position[0]++;
  1184. position[1] = 1;
  1185. }
  1186. return position;
  1187. }
  1188. function newNode(type, content, line, column, end) {
  1189. if (!end) end = getLastPosition(content, line, column);
  1190. return new Node({
  1191. type: type,
  1192. content: content,
  1193. start: {
  1194. line: line,
  1195. column: column
  1196. },
  1197. end: {
  1198. line: end[0],
  1199. column: end[1]
  1200. },
  1201. syntax: 'css'
  1202. });
  1203. }
  1204. /**
  1205. * @param {Number} i Token's index number
  1206. * @return {Number}
  1207. */
  1208. function checkAny(i) {
  1209. var l = void 0;
  1210. if (l = checkBrackets(i)) tokens[i].any_child = 1;else if (l = checkParentheses(i)) tokens[i].any_child = 2;else if (l = checkString(i)) tokens[i].any_child = 3;else if (l = checkPercentage(i)) tokens[i].any_child = 4;else if (l = checkDimension(i)) tokens[i].any_child = 5;else if (l = checkUnicodeRange(i)) tokens[i].any_child = 13;else if (l = checkNumber(i)) tokens[i].any_child = 6;else if (l = checkUri(i)) tokens[i].any_child = 7;else if (l = checkExpression(i)) tokens[i].any_child = 8;else if (l = checkFunction(i)) tokens[i].any_child = 9;else if (l = checkIdent(i)) tokens[i].any_child = 10;else if (l = checkClass(i)) tokens[i].any_child = 11;else if (l = checkUnary(i)) tokens[i].any_child = 12;
  1211. return l;
  1212. }
  1213. /**
  1214. * @return {Node}
  1215. */
  1216. function getAny() {
  1217. var childType = tokens[pos].any_child;
  1218. if (childType === 1) return getBrackets();
  1219. if (childType === 2) return getParentheses();
  1220. if (childType === 3) return getString();
  1221. if (childType === 4) return getPercentage();
  1222. if (childType === 5) return getDimension();
  1223. if (childType === 13) return getUnicodeRange();
  1224. if (childType === 6) return getNumber();
  1225. if (childType === 7) return getUri();
  1226. if (childType === 8) return getExpression();
  1227. if (childType === 9) return getFunction();
  1228. if (childType === 10) return getIdent();
  1229. if (childType === 11) return getClass();
  1230. if (childType === 12) return getUnary();
  1231. }
  1232. /**
  1233. * @return {Node}
  1234. */
  1235. function getArguments() {
  1236. var type = NodeType.ArgumentsType;
  1237. var token = tokens[pos];
  1238. var line = token.ln;
  1239. var column = token.col;
  1240. var content = [];
  1241. var body = void 0;
  1242. // Skip `(`.
  1243. pos++;
  1244. while (pos < tokensLength && tokens[pos].type !== TokenType.RightParenthesis) {
  1245. if (checkDeclaration(pos)) content.push(getDeclaration());else if (checkArgument(pos)) {
  1246. body = getArgument();
  1247. if (typeof body.content === 'string') content.push(body);else content = content.concat(body);
  1248. } else if (checkClass(pos)) content.push(getClass());else throwError(pos);
  1249. }
  1250. var end = getLastPosition(content, line, column, 1);
  1251. // Skip `)`.
  1252. pos++;
  1253. return newNode(type, content, line, column, end);
  1254. }
  1255. /**
  1256. * @param {Number} i Token's index number
  1257. * @return {Number}
  1258. */
  1259. function checkArgument(i) {
  1260. var l = void 0;
  1261. if (l = checkVhash(i)) tokens[i].argument_child = 1;else if (l = checkCustomProperty(i)) tokens[i].argument_child = 2;else if (l = checkAny(i)) tokens[i].argument_child = 3;else if (l = checkSC(i)) tokens[i].argument_child = 4;else if (l = checkOperator(i)) tokens[i].argument_child = 5;
  1262. return l;
  1263. }
  1264. /**
  1265. * @return {Node}
  1266. */
  1267. function getArgument() {
  1268. var childType = tokens[pos].argument_child;
  1269. if (childType === 1) return getVhash();
  1270. if (childType === 2) return getCustomProperty();
  1271. if (childType === 3) return getAny();
  1272. if (childType === 4) return getSC();
  1273. if (childType === 5) return getOperator();
  1274. }
  1275. /**
  1276. * Check if token is part of an @-word (e.g. `@import`, `@include`)
  1277. * @param {Number} i Token's index number
  1278. * @return {Number}
  1279. */
  1280. function checkAtkeyword(i) {
  1281. var l = void 0;
  1282. // Check that token is `@`:
  1283. if (i >= tokensLength || tokens[i++].type !== TokenType.CommercialAt) return 0;
  1284. return (l = checkIdent(i)) ? l + 1 : 0;
  1285. }
  1286. /**
  1287. * Get node with @-word
  1288. * @return {Node}
  1289. */
  1290. function getAtkeyword() {
  1291. var type = NodeType.AtkeywordType;
  1292. var token = tokens[pos];
  1293. var line = token.ln;
  1294. var column = token.col;
  1295. // Skip `@`.
  1296. pos++;
  1297. var content = [getIdent()];
  1298. return newNode(type, content, line, column);
  1299. }
  1300. /**
  1301. * Check if token is a part of an @-rule
  1302. * @param {Number} i Token's index number
  1303. * @return {Number} Length of @-rule
  1304. */
  1305. function checkAtrule(i) {
  1306. var l = void 0;
  1307. if (i >= tokensLength) return 0;
  1308. // If token already has a record of being part of an @-rule,
  1309. // return the @-rule's length:
  1310. if (tokens[i].atrule_l !== undefined) return tokens[i].atrule_l;
  1311. // If token is part of an @-rule, save the rule's type to token.
  1312. // @keyframes:
  1313. if (l = checkKeyframesRule(i)) tokens[i].atrule_type = 4;
  1314. // @-rule with ruleset:
  1315. else if (l = checkAtruler(i)) tokens[i].atrule_type = 1;
  1316. // Block @-rule:
  1317. else if (l = checkAtruleb(i)) tokens[i].atrule_type = 2;
  1318. // Single-line @-rule:
  1319. else if (l = checkAtrules(i)) tokens[i].atrule_type = 3;else return 0;
  1320. // If token is part of an @-rule, save the rule's length to token:
  1321. tokens[i].atrule_l = l;
  1322. return l;
  1323. }
  1324. /**
  1325. * Get node with @-rule
  1326. * @return {Node}
  1327. */
  1328. function getAtrule() {
  1329. var childType = tokens[pos].atrule_type;
  1330. if (childType === 1) return getAtruler(); // @-rule with ruleset
  1331. if (childType === 2) return getAtruleb(); // Block @-rule
  1332. if (childType === 3) return getAtrules(); // Single-line @-rule
  1333. if (childType === 4) return getKeyframesRule();
  1334. }
  1335. /**
  1336. * Check if token is part of a block @-rule
  1337. * @param {Number} i Token's index number
  1338. * @return {Number} Length of the @-rule
  1339. */
  1340. function checkAtruleb(i) {
  1341. var start = i;
  1342. var l = void 0;
  1343. if (i >= tokensLength) return 0;
  1344. if (l = checkAtkeyword(i)) i += l;else return 0;
  1345. if (l = checkTsets(i)) i += l;
  1346. if (l = checkBlock(i)) i += l;else return 0;
  1347. return i - start;
  1348. }
  1349. /**
  1350. * Get node with a block @-rule
  1351. * @return {Node}
  1352. */
  1353. function getAtruleb() {
  1354. var type = NodeType.AtruleType;
  1355. var token = tokens[pos];
  1356. var line = token.ln;
  1357. var column = token.col;
  1358. var content = [].concat(getAtkeyword(), getTsets(), getBlock());
  1359. return newNode(type, content, line, column);
  1360. }
  1361. /**
  1362. * Check if token is part of an @-rule with ruleset
  1363. * @param {Number} i Token's index number
  1364. * @return {Number} Length of the @-rule
  1365. */
  1366. function checkAtruler(i) {
  1367. var start = i;
  1368. var l = void 0;
  1369. if (i >= tokensLength) return 0;
  1370. if (l = checkAtkeyword(i)) i += l;else return 0;
  1371. if (l = checkTsets(i)) i += l;
  1372. if (i < tokensLength && tokens[i].type === TokenType.LeftCurlyBracket) i++;else return 0;
  1373. if (l = checkAtrulers(i)) i += l;
  1374. if (i < tokensLength && tokens[i].type === TokenType.RightCurlyBracket) i++;else return 0;
  1375. return i - start;
  1376. }
  1377. /**
  1378. * Get node with an @-rule with ruleset
  1379. * @return {Node}
  1380. */
  1381. function getAtruler() {
  1382. var type = NodeType.AtruleType;
  1383. var token = tokens[pos];
  1384. var line = token.ln;
  1385. var column = token.col;
  1386. var content = [].concat(getAtkeyword(), getTsets(), getAtrulers());
  1387. return newNode(type, content, line, column);
  1388. }
  1389. /**
  1390. * @param {Number} i Token's index number
  1391. * @return {Number}
  1392. */
  1393. function checkAtrulers(i) {
  1394. var start = i;
  1395. var l = void 0;
  1396. if (i >= tokensLength) return 0;
  1397. if (l = checkSC(i)) i += l;
  1398. while (i < tokensLength) {
  1399. if (l = checkSC(i)) tokens[i].atrulers_child = 1;else if (l = checkAtrule(i)) tokens[i].atrulers_child = 2;else if (l = checkRuleset(i)) tokens[i].atrulers_child = 3;else break;
  1400. i += l;
  1401. }
  1402. if (i < tokensLength) tokens[i].atrulers_end = 1;
  1403. if (l = checkSC(i)) i += l;
  1404. return i - start;
  1405. }
  1406. /**
  1407. * @return {Node}
  1408. */
  1409. function getAtrulers() {
  1410. var type = NodeType.BlockType;
  1411. var token = tokens[pos];
  1412. var line = token.ln;
  1413. var column = token.col;
  1414. var content = [];
  1415. // Skip `{`.
  1416. pos++;
  1417. content = content.concat(getSC());
  1418. while (pos < tokensLength && !tokens[pos].atrulers_end) {
  1419. var childType = tokens[pos].atrulers_child;
  1420. if (childType === 1) content = content.concat(getSC());else if (childType === 2) content.push(getAtrule());else if (childType === 3) content.push(getRuleset());else break;
  1421. }
  1422. content = content.concat(getSC());
  1423. var end = getLastPosition(content, line, column, 1);
  1424. // Skip `}`.
  1425. pos++;
  1426. return newNode(type, content, line, column, end);
  1427. }
  1428. /**
  1429. * @param {Number} i Token's index number
  1430. * @return {Number}
  1431. */
  1432. function checkAtrules(i) {
  1433. var start = i;
  1434. var l = void 0;
  1435. if (i >= tokensLength) return 0;
  1436. if (l = checkAtkeyword(i)) i += l;else return 0;
  1437. if (l = checkTsets(i)) i += l;
  1438. return i - start;
  1439. }
  1440. /**
  1441. * @return {Node}
  1442. */
  1443. function getAtrules() {
  1444. var type = NodeType.AtruleType;
  1445. var token = tokens[pos];
  1446. var line = token.ln;
  1447. var column = token.col;
  1448. var content = [].concat(getAtkeyword(), getTsets());
  1449. return newNode(type, content, line, column);
  1450. }
  1451. /**
  1452. * Check if token is part of a block (e.g. `{...}`).
  1453. * @param {Number} i Token's index number
  1454. * @return {Number} Length of the block
  1455. */
  1456. function checkBlock(i) {
  1457. return i < tokensLength && tokens[i].type === TokenType.LeftCurlyBracket ? tokens[i].right - i + 1 : 0;
  1458. }
  1459. /**
  1460. * Get node with a block
  1461. * @return {Node}
  1462. */
  1463. function getBlock() {
  1464. var type = NodeType.BlockType;
  1465. var token = tokens[pos];
  1466. var line = token.ln;
  1467. var column = token.col;
  1468. var end = tokens[pos].right;
  1469. var content = [];
  1470. // Skip `{`.
  1471. pos++;
  1472. while (pos < end) {
  1473. if (checkBlockdecl(pos)) content = content.concat(getBlockdecl());else throwError(pos);
  1474. }
  1475. var end_ = getLastPosition(content, line, column, 1);
  1476. pos = end + 1;
  1477. return newNode(type, content, line, column, end_);
  1478. }
  1479. /**
  1480. * Check if token is part of a declaration (property-value pair)
  1481. * @param {Number} i Token's index number
  1482. * @return {Number} Length of the declaration
  1483. */
  1484. function checkBlockdecl(i) {
  1485. var l = void 0;
  1486. if (i >= tokensLength) return 0;
  1487. if (l = checkBlockdecl1(i)) tokens[i].bd_type = 1;else if (l = checkBlockdecl2(i)) tokens[i].bd_type = 2;else if (l = checkBlockdecl3(i)) tokens[i].bd_type = 3;else if (l = checkBlockdecl4(i)) tokens[i].bd_type = 4;else return 0;
  1488. return l;
  1489. }
  1490. /**
  1491. * @return {Array}
  1492. */
  1493. function getBlockdecl() {
  1494. var childType = tokens[pos].bd_type;
  1495. if (childType === 1) return getBlockdecl1();
  1496. if (childType === 2) return getBlockdecl2();
  1497. if (childType === 3) return getBlockdecl3();
  1498. if (childType === 4) return getBlockdecl4();
  1499. }
  1500. /**
  1501. * @param {Number} i Token's index number
  1502. * @return {Number}
  1503. */
  1504. function checkBlockdecl1(i) {
  1505. var start = i;
  1506. var l = void 0;
  1507. if (l = checkSC(i)) i += l;
  1508. if (l = checkDeclaration(i)) tokens[i].bd_kind = 1;else if (l = checkAtrule(i)) tokens[i].bd_kind = 2;else return 0;
  1509. i += l;
  1510. if (l = checkSC(i)) i += l;
  1511. if (i < tokensLength && (l = checkDeclDelim(i))) i += l;else return 0;
  1512. if (l = checkSC(i)) i += l;else return 0;
  1513. return i - start;
  1514. }
  1515. /**
  1516. * @return {Array}
  1517. */
  1518. function getBlockdecl1() {
  1519. var sc = getSC();
  1520. var content = void 0;
  1521. switch (tokens[pos].bd_kind) {
  1522. case 1:
  1523. content = getDeclaration();
  1524. break;
  1525. case 2:
  1526. content = getAtrule();
  1527. break;
  1528. }
  1529. return sc.concat(content, getSC(), getDeclDelim(), getSC());
  1530. }
  1531. /**
  1532. * @param {Number} i Token's index number
  1533. * @return {Number}
  1534. */
  1535. function checkBlockdecl2(i) {
  1536. var start = i;
  1537. var l = void 0;
  1538. if (l = checkSC(i)) i += l;
  1539. if (l = checkDeclaration(i)) tokens[i].bd_kind = 1;else if (l = checkAtrule(i)) tokens[i].bd_kind = 2;else return 0;
  1540. i += l;
  1541. if (l = checkSC(i)) i += l;
  1542. return i - start;
  1543. }
  1544. /**
  1545. * @return {Array}
  1546. */
  1547. function getBlockdecl2() {
  1548. var sc = getSC();
  1549. var content = void 0;
  1550. switch (tokens[pos].bd_kind) {
  1551. case 1:
  1552. content = getDeclaration();
  1553. break;
  1554. case 2:
  1555. content = getAtrule();
  1556. break;
  1557. }
  1558. return sc.concat(content, getSC());
  1559. }
  1560. /**
  1561. * @param {Number} i Token's index number
  1562. * @return {Number}
  1563. */
  1564. function checkBlockdecl3(i) {
  1565. var start = i;
  1566. var l = void 0;
  1567. if (l = checkSC(i)) i += l;
  1568. if (l = checkDeclDelim(i)) i += l;else return 0;
  1569. if (l = checkSC(i)) i += l;
  1570. return i - start;
  1571. }
  1572. /**
  1573. * @return {Array}
  1574. */
  1575. function getBlockdecl3() {
  1576. return [].concat(getSC(), getDeclDelim(), getSC());
  1577. }
  1578. /**
  1579. * @param {Number} i Token's index number
  1580. * @return {Number}
  1581. */
  1582. function checkBlockdecl4(i) {
  1583. return checkSC(i);
  1584. }
  1585. /**
  1586. * @return {Array}
  1587. */
  1588. function getBlockdecl4() {
  1589. return getSC();
  1590. }
  1591. /**
  1592. * Check if token is part of text inside square brackets, e.g. `[1]`
  1593. * @param {Number} i Token's index number
  1594. * @return {Number}
  1595. */
  1596. function checkBrackets(i) {
  1597. if (i >= tokensLength) return 0;
  1598. var start = i;
  1599. // Skip `[`.
  1600. if (tokens[i].type === TokenType.LeftSquareBracket) i++;else return 0;
  1601. if (i < tokens[start].right) {
  1602. var l = checkTsets(i);
  1603. if (l) i += l;else return 0;
  1604. }
  1605. // Skip `]`.
  1606. i++;
  1607. return i - start;
  1608. }
  1609. /**
  1610. * Get node with text inside square brackets, e.g. `[1]`
  1611. * @return {Node}
  1612. */
  1613. function getBrackets() {
  1614. var type = NodeType.BracketsType;
  1615. var token = tokens[pos];
  1616. var line = token.ln;
  1617. var column = token.col;
  1618. var right = token.right;
  1619. var content = [];
  1620. // Skip `[`.
  1621. pos++;
  1622. if (pos < right) {
  1623. content = getTsets();
  1624. }
  1625. var end = getLastPosition(content, line, column, 1);
  1626. // Skip `]`.
  1627. pos++;
  1628. return newNode(type, content, line, column, end);
  1629. }
  1630. /**
  1631. * Check if token is part of a class selector (e.g. `.abc`)
  1632. * @param {Number} i Token's index number
  1633. * @return {Number} Length of the class selector
  1634. */
  1635. function checkClass(i) {
  1636. var start = i;
  1637. var l = void 0;
  1638. if (i >= tokensLength) return 0;
  1639. if (tokens[i].class_l) return tokens[i].class_l;
  1640. // Skip `.`.
  1641. if (tokens[i].type === TokenType.FullStop) i++;else return 0;
  1642. if (l = checkIdent(i)) {
  1643. tokens[start].class_l = l + 1;
  1644. i += l;
  1645. } else return 0;
  1646. tokens[start].classEnd = i;
  1647. return i - start;
  1648. }
  1649. /**
  1650. * Get node with a class selector
  1651. * @return {Node}
  1652. */
  1653. function getClass() {
  1654. var type = NodeType.ClassType;
  1655. var token = tokens[pos];
  1656. var line = token.ln;
  1657. var column = token.col;
  1658. // Skip `.`
  1659. pos++;
  1660. var content = [getIdent()];
  1661. return newNode(type, content, line, column);
  1662. }
  1663. function checkCombinator(i) {
  1664. if (i >= tokensLength) return 0;
  1665. var l = void 0;
  1666. if (l = checkCombinator1(i)) tokens[i].combinatorType = 1;else if (l = checkCombinator2(i)) tokens[i].combinatorType = 2;else if (l = checkCombinator3(i)) tokens[i].combinatorType = 3;else if (l = checkCombinator4(i)) tokens[i].combinatorType = 4;
  1667. return l;
  1668. }
  1669. function getCombinator() {
  1670. var type = tokens[pos].combinatorType;
  1671. if (type === 1) return getCombinator1();
  1672. if (type === 2) return getCombinator2();
  1673. if (type === 3) return getCombinator3();
  1674. if (type === 4) return getCombinator4();
  1675. }
  1676. /**
  1677. * (1) `>>>`
  1678. *
  1679. * @param {Number} i
  1680. * @return {Number}
  1681. */
  1682. function checkCombinator1(i) {
  1683. if (i < tokensLength && tokens[i++].type === TokenType.GreaterThanSign && i < tokensLength && tokens[i++].type === TokenType.GreaterThanSign && i < tokensLength && tokens[i++].type === TokenType.GreaterThanSign) return 3;
  1684. return 0;
  1685. }
  1686. /**
  1687. * @return {Node}
  1688. */
  1689. function getCombinator1() {
  1690. var type = NodeType.CombinatorType;
  1691. var token = tokens[pos];
  1692. var line = token.ln;
  1693. var column = token.col;
  1694. var content = '>>>';
  1695. // Skip combinator
  1696. pos += 3;
  1697. return newNode(type, content, line, column);
  1698. }
  1699. /**
  1700. * (1) `||`
  1701. * (2) `>>`
  1702. *
  1703. * @param {Number} i
  1704. * @return {Number}
  1705. */
  1706. function checkCombinator2(i) {
  1707. if (i + 1 >= tokensLength) return 0;
  1708. if (tokens[i].type === TokenType.VerticalLine && tokens[i + 1].type === TokenType.VerticalLine) return 2;
  1709. if (tokens[i].type === TokenType.GreaterThanSign && tokens[i + 1].type === TokenType.GreaterThanSign) return 2;
  1710. return 0;
  1711. }
  1712. /**
  1713. * @return {Node}
  1714. */
  1715. function getCombinator2() {
  1716. var type = NodeType.CombinatorType;
  1717. var token = tokens[pos];
  1718. var line = token.ln;
  1719. var column = token.col;
  1720. var content = '' + token.value + tokens[pos + 1].value;
  1721. // Skip combinator
  1722. pos += 2;
  1723. return newNode(type, content, line, column);
  1724. }
  1725. /**
  1726. * (1) `>`
  1727. * (2) `+`
  1728. * (3) `~`
  1729. *
  1730. * @param {Number} i
  1731. * @return {Number}
  1732. */
  1733. function checkCombinator3(i) {
  1734. var type = tokens[i].type;
  1735. if (type === TokenType.PlusSign || type === TokenType.GreaterThanSign || type === TokenType.Tilde) return 1;else return 0;
  1736. }
  1737. /**
  1738. * @return {Node}
  1739. */
  1740. function getCombinator3() {
  1741. var type = NodeType.CombinatorType;
  1742. var token = tokens[pos];
  1743. var line = token.ln;
  1744. var column = token.col;
  1745. var content = token.value;
  1746. // Skip combinator
  1747. pos++;
  1748. return newNode(type, content, line, column);
  1749. }
  1750. /**
  1751. * (1) `/panda/`
  1752. */
  1753. function checkCombinator4(i) {
  1754. var start = i;
  1755. if (tokens[i].type === TokenType.Solidus) i++;else return 0;
  1756. var l = void 0;
  1757. if (l = checkIdent(i)) i += l;else return 0;
  1758. if (tokens[i].type === TokenType.Solidus) i++;else return 0;
  1759. return i - start;
  1760. }
  1761. /**
  1762. * @return {Node}
  1763. */
  1764. function getCombinator4() {
  1765. var type = NodeType.CombinatorType;
  1766. var token = tokens[pos];
  1767. var line = token.ln;
  1768. var column = token.col;
  1769. // Skip `/`.
  1770. pos++;
  1771. var ident = getIdent();
  1772. // Skip `/`.
  1773. pos++;
  1774. var content = '/' + ident.content + '/';
  1775. return newNode(type, content, line, column);
  1776. }
  1777. /**
  1778. * Check if token is a multiline comment.
  1779. * @param {Number} i Token's index number
  1780. * @return {Number} `1` if token is a multiline comment, otherwise `0`
  1781. */
  1782. function checkCommentML(i) {
  1783. return i < tokensLength && tokens[i].type === TokenType.CommentML ? 1 : 0;
  1784. }
  1785. /**
  1786. * Get node with a multiline comment
  1787. * @return {Node}
  1788. */
  1789. function getCommentML() {
  1790. var type = NodeType.CommentMLType;
  1791. var token = tokens[pos];
  1792. var line = token.ln;
  1793. var column = token.col;
  1794. var content = tokens[pos].value.substring(2);
  1795. var l = content.length;
  1796. if (content.charAt(l - 2) === '*' && content.charAt(l - 1) === '/') content = content.substring(0, l - 2);
  1797. var end = getLastPosition(content, line, column, 2);
  1798. if (end[0] === line) end[1] += 2;
  1799. pos++;
  1800. return newNode(type, content, line, column, end);
  1801. }
  1802. /**
  1803. * Check if token is part of a declaration (property-value pair)
  1804. * @param {Number} i Token's index number
  1805. * @return {Number} Length of the declaration
  1806. */
  1807. function checkDeclaration(i) {
  1808. var start = i;
  1809. var l = void 0;
  1810. if (i >= tokensLength) return 0;
  1811. if (l = checkProperty(i)) i += l;else return 0;
  1812. if (l = checkSC(i)) i += l;
  1813. if (l = checkPropertyDelim(i)) i++;else return 0;
  1814. if (l = checkSC(i)) i += l;
  1815. if (l = checkValue(i)) i += l;else return 0;
  1816. return i - start;
  1817. }
  1818. /**
  1819. * Get node with a declaration
  1820. * @return {Node}
  1821. */
  1822. function getDeclaration() {
  1823. var type = NodeType.DeclarationType;
  1824. var token = tokens[pos];
  1825. var line = token.ln;
  1826. var column = token.col;
  1827. var content = [].concat(getProperty(), getSC(), getPropertyDelim(), getSC(), getValue());
  1828. return newNode(type, content, line, column);
  1829. }
  1830. /**
  1831. * Check if token is a semicolon
  1832. * @param {Number} i Token's index number
  1833. * @return {Number} `1` if token is a semicolon, otherwise `0`
  1834. */
  1835. function checkDeclDelim(i) {
  1836. return i < tokensLength && tokens[i].type === TokenType.Semicolon ? 1 : 0;
  1837. }
  1838. /**
  1839. * Get node with a semicolon
  1840. * @return {Node}
  1841. */
  1842. function getDeclDelim() {
  1843. var type = NodeType.DeclDelimType;
  1844. var token = tokens[pos];
  1845. var line = token.ln;
  1846. var column = token.col;
  1847. var content = ';';
  1848. pos++;
  1849. return newNode(type, content, line, column);
  1850. }
  1851. /**
  1852. * Check if token is a comma
  1853. * @param {Number} i Token's index number
  1854. * @return {Number} `1` if token is a comma, otherwise `0`
  1855. */
  1856. function checkDelim(i) {
  1857. return i < tokensLength && tokens[i].type === TokenType.Comma ? 1 : 0;
  1858. }
  1859. /**
  1860. * Get node with a comma
  1861. * @return {Node}
  1862. */
  1863. function getDelim() {
  1864. var type = NodeType.DelimType;
  1865. var token = tokens[pos];
  1866. var line = token.ln;
  1867. var column = token.col;
  1868. var content = ',';
  1869. pos++;
  1870. return newNode(type, content, line, column);
  1871. }
  1872. /**
  1873. * Check if token is part of a number with dimension unit (e.g. `10px`)
  1874. * @param {Number} i Token's index number
  1875. * @return {Number}
  1876. */
  1877. function checkDimension(i) {
  1878. var ln = checkNumber(i);
  1879. var li = void 0;
  1880. if (i >= tokensLength || !ln || i + ln >= tokensLength) return 0;
  1881. return (li = checkUnit(i + ln)) ? ln + li : 0;
  1882. }
  1883. /**
  1884. * Get node of a number with dimension unit
  1885. * @return {Node}
  1886. */
  1887. function getDimension() {
  1888. var type = NodeType.DimensionType;
  1889. var token = tokens[pos];
  1890. var line = token.ln;
  1891. var column = token.col;
  1892. var content = [getNumber(), getUnit()];
  1893. return newNode(type, content, line, column);
  1894. }
  1895. /**
  1896. * @param {Number} i Token's index number
  1897. * @return {Number}
  1898. */
  1899. function checkExpression(i) {
  1900. var start = i;
  1901. if (i >= tokensLength || tokens[i++].value !== 'expression' || i >= tokensLength || tokens[i].type !== TokenType.LeftParenthesis) {
  1902. return 0;
  1903. }
  1904. return tokens[i].right - start + 1;
  1905. }
  1906. /**
  1907. * @return {Node}
  1908. */
  1909. function getExpression() {
  1910. var type = NodeType.ExpressionType;
  1911. var token = tokens[pos];
  1912. var line = token.ln;
  1913. var column = token.col;
  1914. pos++;
  1915. var content = joinValues(pos + 1, tokens[pos].right - 1);
  1916. var end = getLastPosition(content, line, column, 1);
  1917. if (end[0] === line) end[1] += 11;
  1918. pos = tokens[pos].right + 1;
  1919. return newNode(type, content, line, column, end);
  1920. }
  1921. /**
  1922. * @param {Number} i Token's index number
  1923. * @return {Number}
  1924. */
  1925. function checkFunction(i) {
  1926. var start = i;
  1927. var l = void 0;
  1928. if (i >= tokensLength) return 0;
  1929. if (l = checkIdent(i)) i += l;else return 0;
  1930. return i < tokensLength && tokens[i].type === TokenType.LeftParenthesis ? tokens[i].right - start + 1 : 0;
  1931. }
  1932. /**
  1933. * @return {Node}
  1934. */
  1935. function getFunction() {
  1936. var type = NodeType.FunctionType;
  1937. var token = tokens[pos];
  1938. var line = token.ln;
  1939. var column = token.col;
  1940. var content = [].concat(getIdent(), getArguments());
  1941. return newNode(type, content, line, column);
  1942. }
  1943. /**
  1944. * Check if token is part of an identifierю
  1945. * Grammar from CSS spec:
  1946. * h [0-9a-f]
  1947. * nonascii [\240-\377]
  1948. * unicode \\{h}{1,6}(\r\n|[ \t\r\n\f])?
  1949. * escape {unicode}|\\[^\r\n\f0-9a-f]
  1950. * nmstart [_a-z]|{nonascii}|{escape}
  1951. * nmchar [_a-z0-9-]|{nonascii}|{escape}
  1952. * ident -?{nmstart}{nmchar}*
  1953. *
  1954. * @param {number} i Token's index number
  1955. * @return {number} Length of the identifier
  1956. */
  1957. function checkIdent(i) {
  1958. var start = i;
  1959. if (i >= tokensLength) return 0;
  1960. if (tokens[i].type === TokenType.HyphenMinus) i++;
  1961. if (tokens[i].type === TokenType.LowLine || tokens[i].type === TokenType.Identifier) i++;else return 0;
  1962. for (; i < tokensLength; i++) {
  1963. if (tokens[i].type !== TokenType.HyphenMinus && tokens[i].type !== TokenType.LowLine && tokens[i].type !== TokenType.Identifier && tokens[i].type !== TokenType.DecimalNumber) break;
  1964. }
  1965. tokens[start].ident_last = i - 1;
  1966. return i - start;
  1967. }
  1968. /**
  1969. * Get node with an identifier
  1970. * @return {Node}
  1971. */
  1972. function getIdent() {
  1973. var type = NodeType.IdentType;
  1974. var token = tokens[pos];
  1975. var line = token.ln;
  1976. var column = token.col;
  1977. var content = joinValues(pos, tokens[pos].ident_last);
  1978. pos = tokens[pos].ident_last + 1;
  1979. return newNode(type, content, line, column);
  1980. }
  1981. /**
  1982. * Check if token is part of `!important` word
  1983. * @param {Number} i Token's index number
  1984. * @return {Number}
  1985. */
  1986. function checkImportant(i) {
  1987. var start = i;
  1988. var l = void 0;
  1989. if (i >= tokensLength || tokens[i++].type !== TokenType.ExclamationMark) return 0;
  1990. if (l = checkSC(i)) i += l;
  1991. if (tokens[i].value === 'important') {
  1992. tokens[start].importantEnd = i;
  1993. return i - start + 1;
  1994. } else {
  1995. return 0;
  1996. }
  1997. }
  1998. /**
  1999. * Get node with `!important` word
  2000. * @return {Node}
  2001. */
  2002. function getImportant() {
  2003. var type = NodeType.ImportantType;
  2004. var token = tokens[pos];
  2005. var line = token.ln;
  2006. var column = token.col;
  2007. var content = joinValues(pos, token.importantEnd);
  2008. pos = token.importantEnd + 1;
  2009. return newNode(type, content, line, column);
  2010. }
  2011. /**
  2012. * Check a single keyframe block - `5% {}`
  2013. * @param {Number} i
  2014. * @returns {Number}
  2015. */
  2016. function checkKeyframesBlock(i) {
  2017. var start = i;
  2018. var l = void 0;
  2019. if (i >= tokensLength) return 0;
  2020. if (l = checkKeyframesSelectorsGroup(i)) i += l;else return 0;
  2021. if (l = checkSC(i)) i += l;
  2022. if (l = checkBlock(i)) i += l;else return 0;
  2023. return i - start;
  2024. }
  2025. /**
  2026. * Get a single keyframe block - `5% {}`
  2027. * @returns {Node}
  2028. */
  2029. function getKeyframesBlock() {
  2030. var type = NodeType.RulesetType;
  2031. var token = tokens[pos];
  2032. var line = token.ln;
  2033. var column = token.col;
  2034. var content = [].concat(getKeyframesSelectorsGroup(), getSC(), getBlock());
  2035. return newNode(type, content, line, column);
  2036. }
  2037. /**
  2038. * Check all keyframe blocks - `5% {} 100% {}`
  2039. * @param {Number} i
  2040. * @returns {Number}
  2041. */
  2042. function checkKeyframesBlocks(i) {
  2043. var start = i;
  2044. var l = void 0;
  2045. if (i < tokensLength && tokens[i].type === TokenType.LeftCurlyBracket) i++;else return 0;
  2046. if (l = checkSC(i)) i += l;
  2047. if (l = checkKeyframesBlock(i)) i += l;else return 0;
  2048. while (tokens[i].type !== TokenType.RightCurlyBracket) {
  2049. if (l = checkSC(i)) i += l;else if (l = checkKeyframesBlock(i)) i += l;else break;
  2050. }
  2051. if (i < tokensLength && tokens[i].type === TokenType.RightCurlyBracket) i++;else return 0;
  2052. return i - start;
  2053. }
  2054. /**
  2055. * Get all keyframe blocks - `5% {} 100% {}`
  2056. * @returns {Node}
  2057. */
  2058. function getKeyframesBlocks() {
  2059. var type = NodeType.BlockType;
  2060. var token = tokens[pos];
  2061. var line = token.ln;
  2062. var column = token.col;
  2063. var keyframesBlocksEnd = token.right;
  2064. var content = [];
  2065. // Skip `{`.
  2066. pos++;
  2067. while (pos < keyframesBlocksEnd) {
  2068. if (checkSC(pos)) content = content.concat(getSC());else if (checkKeyframesBlock(pos)) content.push(getKeyframesBlock());
  2069. }
  2070. var end = getLastPosition(content, line, column, 1);
  2071. // Skip `}`.
  2072. pos++;
  2073. return newNode(type, content, line, column, end);
  2074. }
  2075. /**
  2076. * Check if token is part of a @keyframes rule.
  2077. * @param {Number} i Token's index number
  2078. * @return {Number} Length of the @keyframes rule
  2079. */
  2080. function checkKeyframesRule(i) {
  2081. var start = i;
  2082. var l = void 0;
  2083. if (i >= tokensLength) return 0;
  2084. if (l = checkAtkeyword(i)) i += l;else return 0;
  2085. var atruleName = joinValues2(i - l, l);
  2086. if (atruleName.toLowerCase().indexOf('keyframes') === -1) return 0;
  2087. if (l = checkSC(i)) i += l;else return 0;
  2088. if (l = checkIdent(i)) i += l;else return 0;
  2089. if (l = checkSC(i)) i += l;
  2090. if (l = checkKeyframesBlocks(i)) i += l;else return 0;
  2091. return i - start;
  2092. }
  2093. /**
  2094. * @return {Node}
  2095. */
  2096. function getKeyframesRule() {
  2097. var type = NodeType.AtruleType;
  2098. var token = tokens[pos];
  2099. var line = token.ln;
  2100. var column = token.col;
  2101. var content = [].concat(getAtkeyword(), getSC(), getIdent(), getSC(), getKeyframesBlocks());
  2102. return newNode(type, content, line, column);
  2103. }
  2104. /**
  2105. * Check a single keyframe selector - `5%`, `from` etc
  2106. * @param {Number} i
  2107. * @returns {Number}
  2108. */
  2109. function checkKeyframesSelector(i) {
  2110. var start = i;
  2111. var l = void 0;
  2112. if (i >= tokensLength) return 0;
  2113. if (l = checkIdent(i)) {
  2114. // Valid selectors are only `from` and `to`.
  2115. var selector = joinValues2(i, l);
  2116. if (selector !== 'from' && selector !== 'to') return 0;
  2117. i += l;
  2118. tokens[start].keyframesSelectorType = 1;
  2119. } else if (l = checkPercentage(i)) {
  2120. i += l;
  2121. tokens[start].keyframesSelectorType = 2;
  2122. } else {
  2123. return 0;
  2124. }
  2125. return i - start;
  2126. }
  2127. /**
  2128. * Get a single keyframe selector
  2129. * @returns {Node}
  2130. */
  2131. function getKeyframesSelector() {
  2132. var keyframesSelectorType = NodeType.KeyframesSelectorType;
  2133. var selectorType = NodeType.SelectorType;
  2134. var token = tokens[pos];
  2135. var line = token.ln;
  2136. var column = token.col;
  2137. var content = [];
  2138. if (token.keyframesSelectorType === 1) {
  2139. content.push(getIdent());
  2140. } else {
  2141. content.push(getPercentage());
  2142. }
  2143. var keyframesSelector = newNode(keyframesSelectorType, content, line, column);
  2144. return newNode(selectorType, [keyframesSelector], line, column);
  2145. }
  2146. /**
  2147. * Check the keyframe's selector groups
  2148. * @param {Number} i
  2149. * @returns {Number}
  2150. */
  2151. function checkKeyframesSelectorsGroup(i) {
  2152. var start = i;
  2153. var l = void 0;
  2154. if (l = checkKeyframesSelector(i)) i += l;else return 0;
  2155. while (i < tokensLength) {
  2156. var spaceBefore = checkSC(i);
  2157. var comma = checkDelim(i + spaceBefore);
  2158. if (!comma) break;
  2159. var spaceAfter = checkSC(i + spaceBefore + comma);
  2160. if (l = checkKeyframesSelector(i + spaceBefore + comma + spaceAfter)) {
  2161. i += spaceBefore + comma + spaceAfter + l;
  2162. } else break;
  2163. }
  2164. tokens[start].selectorsGroupEnd = i;
  2165. return i - start;
  2166. }
  2167. /**
  2168. * Get the keyframe's selector groups
  2169. * @returns {Array} An array of keyframe selectors
  2170. */
  2171. function getKeyframesSelectorsGroup() {
  2172. var selectorsGroup = [];
  2173. var selectorsGroupEnd = tokens[pos].selectorsGroupEnd;
  2174. selectorsGroup.push(getKeyframesSelector());
  2175. while (pos < selectorsGroupEnd) {
  2176. selectorsGroup = selectorsGroup.concat(getSC(), getDelim(), getSC(), getKeyframesSelector());
  2177. }
  2178. return selectorsGroup;
  2179. }
  2180. /**
  2181. * Check if token is a namespace sign (`|`)
  2182. * @param {Number} i Token's index number
  2183. * @return {Number} `1` if token is `|`, `0` if not
  2184. */
  2185. function checkNamespace(i) {
  2186. return i < tokensLength && tokens[i].type === TokenType.VerticalLine ? 1 : 0;
  2187. }
  2188. /**
  2189. * Get node with a namespace sign
  2190. * @return {Node}
  2191. */
  2192. function getNamespace() {
  2193. var type = NodeType.NamespaceType;
  2194. var token = tokens[pos];
  2195. var line = token.ln;
  2196. var column = token.col;
  2197. var content = '|';
  2198. pos++;
  2199. return newNode(type, content, line, column);
  2200. }
  2201. /**
  2202. * @param {Number} i Token's index number
  2203. * @return {Number}
  2204. */
  2205. function checkNmName2(i) {
  2206. if (tokens[i].type === TokenType.Identifier) return 1;else if (tokens[i].type !== TokenType.DecimalNumber) return 0;
  2207. i++;
  2208. return i < tokensLength && tokens[i].type === TokenType.Identifier ? 2 : 1;
  2209. }
  2210. /**
  2211. * @return {String}
  2212. */
  2213. function getNmName2() {
  2214. var s = tokens[pos].value;
  2215. if (tokens[pos++].type === TokenType.DecimalNumber && pos < tokensLength && tokens[pos].type === TokenType.Identifier) s += tokens[pos++].value;
  2216. return s;
  2217. }
  2218. /**
  2219. * Check if token is part of a number
  2220. * @param {Number} i Token's index number
  2221. * @return {Number} Length of number
  2222. */
  2223. function checkNumber(i) {
  2224. if (i >= tokensLength) return 0;
  2225. if (tokens[i].number_l) return tokens[i].number_l;
  2226. // `10`:
  2227. if (i < tokensLength && tokens[i].type === TokenType.DecimalNumber && (!tokens[i + 1] || tokens[i + 1] && tokens[i + 1].type !== TokenType.FullStop)) {
  2228. tokens[i].number_l = 1;
  2229. return 1;
  2230. }
  2231. // `10.`:
  2232. if (i < tokensLength && tokens[i].type === TokenType.DecimalNumber && tokens[i + 1] && tokens[i + 1].type === TokenType.FullStop && (!tokens[i + 2] || tokens[i + 2].type !== TokenType.DecimalNumber)) {
  2233. tokens[i].number_l = 2;
  2234. return 2;
  2235. }
  2236. // `.10`:
  2237. if (i < tokensLength && tokens[i].type === TokenType.FullStop && tokens[i + 1].type === TokenType.DecimalNumber) {
  2238. tokens[i].number_l = 2;
  2239. return 2;
  2240. }
  2241. // `10.10`:
  2242. if (i < tokensLength && tokens[i].type === TokenType.DecimalNumber && tokens[i + 1] && tokens[i + 1].type === TokenType.FullStop && tokens[i + 2] && tokens[i + 2].type === TokenType.DecimalNumber) {
  2243. tokens[i].number_l = 3;
  2244. return 3;
  2245. }
  2246. return 0;
  2247. }
  2248. /**
  2249. * Get node with number
  2250. * @return {Node}
  2251. */
  2252. function getNumber() {
  2253. var type = NodeType.NumberType;
  2254. var token = tokens[pos];
  2255. var line = token.ln;
  2256. var column = token.col;
  2257. var l = tokens[pos].number_l;
  2258. var content = '';
  2259. for (var j = 0; j < l; j++) {
  2260. content += tokens[pos + j].value;
  2261. }
  2262. pos += l;
  2263. return newNode(type, content, line, column);
  2264. }
  2265. /**
  2266. * Check if token is an operator (`/`, `,`, `:`, `=`, `*`).
  2267. * @param {Number} i Token's index number
  2268. * @return {Number} `1` if token is an operator, otherwise `0`
  2269. */
  2270. function checkOperator(i) {
  2271. if (i >= tokensLength) return 0;
  2272. switch (tokens[i].type) {
  2273. case TokenType.Solidus:
  2274. case TokenType.Comma:
  2275. case TokenType.Colon:
  2276. case TokenType.EqualsSign:
  2277. case TokenType.Asterisk:
  2278. return 1;
  2279. }
  2280. return 0;
  2281. }
  2282. /**
  2283. * Get node with an operator
  2284. * @return {Node}
  2285. */
  2286. function getOperator() {
  2287. var type = NodeType.OperatorType;
  2288. var token = tokens[pos];
  2289. var line = token.ln;
  2290. var column = token.col;
  2291. var content = token.value;
  2292. pos++;
  2293. return newNode(type, content, line, column);
  2294. }
  2295. /**
  2296. * Check if token is part of text inside parentheses, e.g. `(1)`
  2297. * @param {Number} i Token's index number
  2298. * @return {Number}
  2299. */
  2300. function checkParentheses(i) {
  2301. if (i >= tokensLength) return 0;
  2302. var start = i;
  2303. var right = tokens[i].right;
  2304. // Skip `(`.
  2305. if (tokens[i].type === TokenType.LeftParenthesis) i++;else return 0;
  2306. if (i < right) {
  2307. var l = checkTsets(i);
  2308. if (l) i += l;else return 0;
  2309. }
  2310. // Skip `)`.
  2311. i++;
  2312. return i - start;
  2313. }
  2314. /**
  2315. * Get node with text inside parentheses, e.g. `(1)`
  2316. * @return {Node}
  2317. */
  2318. function getParentheses() {
  2319. var type = NodeType.ParenthesesType;
  2320. var token = tokens[pos];
  2321. var line = token.ln;
  2322. var column = token.col;
  2323. var right = token.right;
  2324. var content = [];
  2325. // Skip `(`.
  2326. pos++;
  2327. if (pos < right) {
  2328. content = getTsets();
  2329. }
  2330. var end = getLastPosition(content, line, column, 1);
  2331. // Skip `)`.
  2332. pos++;
  2333. return newNode(type, content, line, column, end);
  2334. }
  2335. /**
  2336. * Check if token is part of a number with percent sign (e.g. `10%`)
  2337. * @param {Number} i Token's index number
  2338. * @return {Number}
  2339. */
  2340. function checkPercentage(i) {
  2341. var start = i;
  2342. var l = void 0;
  2343. if (i >= tokensLength) return 0;
  2344. if (l = checkNumber(i)) i += l;else return 0;
  2345. if (i >= tokensLength) return 0;
  2346. // Skip `%`.
  2347. if (tokens[i].type === TokenType.PercentSign) i++;else return 0;
  2348. return i - start;
  2349. }
  2350. /**
  2351. * Get node of number with percent sign
  2352. * @return {Node}
  2353. */
  2354. function getPercentage() {
  2355. var type = NodeType.PercentageType;
  2356. var token = tokens[pos];
  2357. var line = token.ln;
  2358. var column = token.col;
  2359. var content = [getNumber()];
  2360. var end = getLastPosition(content, line, column, 1);
  2361. // Skip `%`.
  2362. pos++;
  2363. return newNode(type, content, line, column, end);
  2364. }
  2365. /**
  2366. * @param {Number} i Token's index number
  2367. * @return {Number}
  2368. */
  2369. function checkProgid(i) {
  2370. var start = i;
  2371. var l = void 0;
  2372. if (i >= tokensLength) return 0;
  2373. if (joinValues2(i, 6) === 'progid:DXImageTransform.Microsoft.') i += 6;else return 0;
  2374. if (l = checkIdent(i)) i += l;else return 0;
  2375. if (l = checkSC(i)) i += l;
  2376. if (tokens[i].type === TokenType.LeftParenthesis) {
  2377. tokens[start].progid_end = tokens[i].right;
  2378. i = tokens[i].right + 1;
  2379. } else return 0;
  2380. return i - start;
  2381. }
  2382. /**
  2383. * @return {Node}
  2384. */
  2385. function getProgid() {
  2386. var type = NodeType.ProgidType;
  2387. var token = tokens[pos];
  2388. var line = token.ln;
  2389. var column = token.col;
  2390. var progid_end = token.progid_end;
  2391. var content = joinValues(pos, progid_end);
  2392. pos = progid_end + 1;
  2393. return newNode(type, content, line, column);
  2394. }
  2395. /**
  2396. * Check if token is part of a property
  2397. * @param {Number} i Token's index number
  2398. * @return {Number} Length of the property
  2399. */
  2400. function checkProperty(i) {
  2401. var start = i;
  2402. var l = void 0;
  2403. if (l = checkProperty1(i)) tokens[start].propertyType = 1;else if (l = checkProperty2(i)) tokens[start].propertyType = 2;
  2404. return l;
  2405. }
  2406. /**
  2407. * Get node with a property
  2408. * @return {Node}
  2409. */
  2410. function getProperty() {
  2411. var type = tokens[pos].propertyType;
  2412. if (type === 1) return getProperty1();
  2413. if (type === 2) return getProperty2();
  2414. }
  2415. /**
  2416. * Check if token is part of a property
  2417. * @param {Number} i Token's index number
  2418. * @return {Number} Length of the property
  2419. */
  2420. function checkProperty1(i) {
  2421. var start = i;
  2422. var l = void 0;
  2423. if (i >= tokensLength) return 0;
  2424. if (l = checkIdent(i)) i += l;else return 0;
  2425. return i - start;
  2426. }
  2427. /**
  2428. * Get node with a property
  2429. * @return {Node}
  2430. */
  2431. function getProperty1() {
  2432. var type = NodeType.PropertyType;
  2433. var token = tokens[pos];
  2434. var line = token.ln;
  2435. var column = token.col;
  2436. var content = [getIdent()];
  2437. return newNode(type, content, line, column);
  2438. }
  2439. /**
  2440. * Check if token is part of a custom property
  2441. * @param {Number} i Token's index number
  2442. * @return {Number} Length of the property
  2443. */
  2444. function checkProperty2(i) {
  2445. return checkCustomProperty(i);
  2446. }
  2447. /**
  2448. * Get node with a custom property
  2449. * @return {Node}
  2450. */
  2451. function getProperty2() {
  2452. return getCustomProperty();
  2453. }
  2454. /**
  2455. * Check if token is part of a custom property
  2456. * @param {Number} i Token's index number
  2457. * @return {Number} Length of the property
  2458. */
  2459. function checkCustomProperty(i) {
  2460. var start = i;
  2461. var l = void 0;
  2462. if (i >= tokensLength) return 0;
  2463. if (tokens[i].type !== TokenType.HyphenMinus || tokens[i + 1] && tokens[i + 1].type !== TokenType.HyphenMinus) return 0;
  2464. // Skip `--`
  2465. i += 2;
  2466. if (l = checkIdent(i)) i += l;else return 0;
  2467. return i - start;
  2468. }
  2469. /**
  2470. * Get node with a custom property
  2471. * @return {Node}
  2472. */
  2473. function getCustomProperty() {
  2474. var type = NodeType.CustomPropertyType;
  2475. var token = tokens[pos];
  2476. var line = token.ln;
  2477. var column = token.col;
  2478. // Skip `--`
  2479. pos += 2;
  2480. var content = [getIdent()];
  2481. return newNode(type, content, line, column);
  2482. }
  2483. /**
  2484. * Check if token is a colon
  2485. * @param {Number} i Token's index number
  2486. * @return {Number} `1` if token is a colon, otherwise `0`
  2487. */
  2488. function checkPropertyDelim(i) {
  2489. return i < tokensLength && tokens[i].type === TokenType.Colon ? 1 : 0;
  2490. }
  2491. /**
  2492. * Get node with a colon
  2493. * @return {Node}
  2494. */
  2495. function getPropertyDelim() {
  2496. var type = NodeType.PropertyDelimType;
  2497. var token = tokens[pos];
  2498. var line = token.ln;
  2499. var column = token.col;
  2500. var content = ':';
  2501. // Skip `:`.
  2502. pos++;
  2503. return newNode(type, content, line, column);
  2504. }
  2505. /**
  2506. * @param {Number} i Token's index number
  2507. * @return {Number}
  2508. */
  2509. function checkPseudo(i) {
  2510. return checkPseudoe(i) || checkPseudoc(i);
  2511. }
  2512. /**
  2513. * @return {Node}
  2514. */
  2515. function getPseudo() {
  2516. if (checkPseudoe(pos)) return getPseudoe();
  2517. if (checkPseudoc(pos)) return getPseudoc();
  2518. }
  2519. /**
  2520. * @param {Number} i Token's index number
  2521. * @return {Number}
  2522. */
  2523. function checkPseudoe(i) {
  2524. var l = void 0;
  2525. // Check `::`
  2526. if (i >= tokensLength || tokens[i].type !== TokenType.Colon || i >= tokensLength || tokens[i + 1].type !== TokenType.Colon) return 0;
  2527. if (l = checkPseudoElement1(i)) tokens[i].pseudoElementType = 1;else if (l = checkPseudoElement2(i)) tokens[i].pseudoElementType = 2;else return 0;
  2528. return l;
  2529. }
  2530. /**
  2531. * @return {Node}
  2532. */
  2533. function getPseudoe() {
  2534. var childType = tokens[pos].pseudoElementType;
  2535. if (childType === 1) return getPseudoElement1();
  2536. if (childType === 2) return getPseudoElement2();
  2537. }
  2538. /**
  2539. * (1) `::slotted(selector)`
  2540. * (2) `::slotted(selector, selector)`
  2541. */
  2542. function checkPseudoElement1(i) {
  2543. var start = i;
  2544. var l = void 0;
  2545. // Skip `::`.
  2546. i += 2;
  2547. if (i >= tokensLength) return 0;
  2548. if (l = checkIdent(i)) i += l;else return 0;
  2549. if (i >= tokensLength || tokens[i].type !== TokenType.LeftParenthesis) return 0;
  2550. var right = tokens[i].right;
  2551. // Skip `(`.
  2552. i++;
  2553. if (l = checkSC(i)) i += l;
  2554. if (l = checkSelectorsGroup(i)) i += l;else return 0;
  2555. if (l = checkSC(i)) i += l;
  2556. if (i !== right) return 0;
  2557. // Skip `)`.
  2558. i++;
  2559. return i - start;
  2560. }
  2561. /**
  2562. * (1) `::slotted(selector)`
  2563. * (2) `::slotted(selector, selector)`
  2564. */
  2565. function getPseudoElement1() {
  2566. var type = NodeType.PseudoeType;
  2567. var token = tokens[pos];
  2568. var line = token.ln;
  2569. var column = token.col;
  2570. var content = [];
  2571. // Skip `::`.
  2572. pos += 2;
  2573. content.push(getIdent());
  2574. {
  2575. var _type = NodeType.ArgumentsType;
  2576. var _token = tokens[pos];
  2577. var _line = _token.ln;
  2578. var _column = _token.col;
  2579. // Skip `(`.
  2580. pos++;
  2581. var selectorContent = [].concat(getSC(), getSelectorsGroup(), getSC());
  2582. var end = getLastPosition(selectorContent, _line, _column, 1);
  2583. var args = newNode(_type, selectorContent, _line, _column, end);
  2584. content.push(args);
  2585. // Skip `)`.
  2586. pos++;
  2587. }
  2588. return newNode(type, content, line, column);
  2589. }
  2590. function checkPseudoElement2(i) {
  2591. var start = i;
  2592. var l = void 0;
  2593. // Skip `::`.
  2594. i += 2;
  2595. if (l = checkIdent(i)) i += l;else return 0;
  2596. return i - start;
  2597. }
  2598. /**
  2599. * @return {Node}
  2600. */
  2601. function getPseudoElement2() {
  2602. var type = NodeType.PseudoeType;
  2603. var token = tokens[pos];
  2604. var line = token.ln;
  2605. var column = token.col;
  2606. // Skip `::`.
  2607. pos += 2;
  2608. var content = [getIdent()];
  2609. return newNode(type, content, line, column);
  2610. }
  2611. /**
  2612. * @param {Number} i Token's index number
  2613. * @return {Number}
  2614. */
  2615. function checkPseudoc(i) {
  2616. var l = void 0;
  2617. if (i >= tokensLength || tokens[i].type !== TokenType.Colon) return 0;
  2618. if (l = checkPseudoClass1(i)) tokens[i].pseudoClassType = 1;else if (l = checkPseudoClass2(i)) tokens[i].pseudoClassType = 2;else if (l = checkPseudoClass3(i)) tokens[i].pseudoClassType = 3;else if (l = checkPseudoClass4(i)) tokens[i].pseudoClassType = 4;else if (l = checkPseudoClass5(i)) tokens[i].pseudoClassType = 5;else if (l = checkPseudoClass6(i)) tokens[i].pseudoClassType = 6;else return 0;
  2619. return l;
  2620. }
  2621. /**
  2622. * @return {Node}
  2623. */
  2624. function getPseudoc() {
  2625. var childType = tokens[pos].pseudoClassType;
  2626. if (childType === 1) return getPseudoClass1();
  2627. if (childType === 2) return getPseudoClass2();
  2628. if (childType === 3) return getPseudoClass3();
  2629. if (childType === 4) return getPseudoClass4();
  2630. if (childType === 5) return getPseudoClass5();
  2631. if (childType === 6) return getPseudoClass6();
  2632. }
  2633. /**
  2634. * (1) `:panda(selector)`
  2635. * (2) `:panda(selector, selector)`
  2636. */
  2637. function checkPseudoClass1(i) {
  2638. var start = i;
  2639. var l = void 0;
  2640. // Skip `:`.
  2641. i++;
  2642. if (i >= tokensLength) return 0;
  2643. if (l = checkIdent(i)) i += l;else return 0;
  2644. if (i >= tokensLength || tokens[i].type !== TokenType.LeftParenthesis) return 0;
  2645. var right = tokens[i].right;
  2646. // Skip `(`.
  2647. i++;
  2648. if (l = checkSC(i)) i += l;
  2649. if (l = checkSelectorsGroup(i)) i += l;else return 0;
  2650. if (l = checkSC(i)) i += l;
  2651. if (i !== right) return 0;
  2652. // Skip `)`.
  2653. i++;
  2654. return i - start;
  2655. }
  2656. /**
  2657. * (-) `:not(panda)`
  2658. */
  2659. function getPseudoClass1() {
  2660. var type = NodeType.PseudocType;
  2661. var token = tokens[pos];
  2662. var line = token.ln;
  2663. var column = token.col;
  2664. var content = [];
  2665. // Skip `:`.
  2666. pos++;
  2667. content.push(getIdent());
  2668. {
  2669. var _type2 = NodeType.ArgumentsType;
  2670. var _token2 = tokens[pos];
  2671. var _line2 = _token2.ln;
  2672. var _column2 = _token2.col;
  2673. // Skip `(`.
  2674. pos++;
  2675. var selectorContent = [].concat(getSC(), getSelectorsGroup(), getSC());
  2676. var end = getLastPosition(selectorContent, _line2, _column2, 1);
  2677. var args = newNode(_type2, selectorContent, _line2, _column2, end);
  2678. content.push(args);
  2679. // Skip `)`.
  2680. pos++;
  2681. }
  2682. return newNode(type, content, line, column);
  2683. }
  2684. /**
  2685. * (1) `:nth-child(odd)`
  2686. * (2) `:nth-child(even)`
  2687. * (3) `:lang(de-DE)`
  2688. */
  2689. function checkPseudoClass2(i) {
  2690. var start = i;
  2691. var l = void 0;
  2692. // Skip `:`.
  2693. i++;
  2694. if (i >= tokensLength) return 0;
  2695. if (l = checkIdent(i)) i += l;else return 0;
  2696. if (i >= tokensLength || tokens[i].type !== TokenType.LeftParenthesis) return 0;
  2697. var right = tokens[i].right;
  2698. // Skip `(`.
  2699. i++;
  2700. if (l = checkSC(i)) i += l;
  2701. if (l = checkIdent(i)) i += l;else return 0;
  2702. if (l = checkSC(i)) i += l;
  2703. if (i !== right) return 0;
  2704. // Skip `)`.
  2705. i++;
  2706. return i - start;
  2707. }
  2708. function getPseudoClass2() {
  2709. var type = NodeType.PseudocType;
  2710. var token = tokens[pos];
  2711. var line = token.ln;
  2712. var column = token.col;
  2713. var content = [];
  2714. // Skip `:`.
  2715. pos++;
  2716. content.push(getIdent());
  2717. // Skip `(`.
  2718. pos++;
  2719. var l = tokens[pos].ln;
  2720. var c = tokens[pos].col;
  2721. var value = [].concat(getSC(), getIdent(), getSC());
  2722. var end = getLastPosition(value, l, c, 1);
  2723. var args = newNode(NodeType.ArgumentsType, value, l, c, end);
  2724. content.push(args);
  2725. // Skip `)`.
  2726. pos++;
  2727. return newNode(type, content, line, column);
  2728. }
  2729. /**
  2730. * (-) `:nth-child(-3n + 2)`
  2731. */
  2732. function checkPseudoClass3(i) {
  2733. var start = i;
  2734. var l = void 0;
  2735. // Skip `:`.
  2736. i++;
  2737. if (i >= tokensLength) return 0;
  2738. if (l = checkIdent(i)) i += l;else return 0;
  2739. if (i >= tokensLength || tokens[i].type !== TokenType.LeftParenthesis) return 0;
  2740. var right = tokens[i].right;
  2741. // Skip `(`.
  2742. i++;
  2743. if (l = checkSC(i)) i += l;
  2744. if (l = checkUnary(i)) i += l;
  2745. if (i >= tokensLength) return 0;
  2746. if (tokens[i].type === TokenType.DecimalNumber) i++;
  2747. if (i >= tokensLength) return 0;
  2748. if (tokens[i].value === 'n') i++;else return 0;
  2749. if (l = checkSC(i)) i += l;
  2750. if (i >= tokensLength) return 0;
  2751. if (tokens[i].type === TokenType.PlusSign || tokens[i].type === TokenType.HyphenMinus) i++;else return 0;
  2752. if (l = checkSC(i)) i += l;
  2753. if (tokens[i].type === TokenType.DecimalNumber) i++;else return 0;
  2754. if (l = checkSC(i)) i += l;
  2755. if (i !== right) return 0;
  2756. // Skip `)`.
  2757. i++;
  2758. return i - start;
  2759. }
  2760. function getPseudoClass3() {
  2761. var type = NodeType.PseudocType;
  2762. var token = tokens[pos];
  2763. var line = token.ln;
  2764. var column = token.col;
  2765. var content = [];
  2766. // Skip `:`.
  2767. pos++;
  2768. content.push(getIdent());
  2769. var l = tokens[pos].ln;
  2770. var c = tokens[pos].col;
  2771. var value = [];
  2772. // Skip `(`.
  2773. pos++;
  2774. value = value.concat(getSC());
  2775. if (checkUnary(pos)) value.push(getUnary());
  2776. if (checkNumber(pos)) value.push(getNumber());
  2777. {
  2778. var _l = tokens[pos].ln;
  2779. var _c = tokens[pos].col;
  2780. var _content = tokens[pos].value;
  2781. var ident = newNode(NodeType.IdentType, _content, _l, _c);
  2782. value.push(ident);
  2783. pos++;
  2784. }
  2785. value = value.concat(getSC());
  2786. if (checkUnary(pos)) value.push(getUnary());
  2787. value = value.concat(getSC());
  2788. if (checkNumber(pos)) value.push(getNumber());
  2789. value = value.concat(getSC());
  2790. var end = getLastPosition(value, l, c, 1);
  2791. var args = newNode(NodeType.ArgumentsType, value, l, c, end);
  2792. content.push(args);
  2793. // Skip `)`.
  2794. pos++;
  2795. return newNode(type, content, line, column);
  2796. }
  2797. /**
  2798. * (-) `:nth-child(-3n)`
  2799. */
  2800. function checkPseudoClass4(i) {
  2801. var start = i;
  2802. var l = void 0;
  2803. // Skip `:`.
  2804. i++;
  2805. if (i >= tokensLength) return 0;
  2806. if (l = checkIdent(i)) i += l;else return 0;
  2807. if (i >= tokensLength) return 0;
  2808. if (tokens[i].type !== TokenType.LeftParenthesis) return 0;
  2809. var right = tokens[i].right;
  2810. // Skip `(`.
  2811. i++;
  2812. if (l = checkSC(i)) i += l;
  2813. if (l = checkUnary(i)) i += l;
  2814. if (tokens[i].type === TokenType.DecimalNumber) i++;
  2815. if (tokens[i].value === 'n') i++;else return 0;
  2816. if (l = checkSC(i)) i += l;
  2817. if (i !== right) return 0;
  2818. // Skip `)`.
  2819. i++;
  2820. return i - start;
  2821. }
  2822. function getPseudoClass4() {
  2823. var type = NodeType.PseudocType;
  2824. var token = tokens[pos];
  2825. var line = token.ln;
  2826. var column = token.col;
  2827. var content = [];
  2828. // Skip `:`.
  2829. pos++;
  2830. content.push(getIdent());
  2831. var l = tokens[pos].ln;
  2832. var c = tokens[pos].col;
  2833. var value = [];
  2834. // Skip `(`.
  2835. pos++;
  2836. value = value.concat(getSC());
  2837. if (checkUnary(pos)) value.push(getUnary());
  2838. if (checkNumber(pos)) value.push(getNumber());
  2839. if (checkIdent(pos)) value.push(getIdent());
  2840. value = value.concat(getSC());
  2841. var end = getLastPosition(value, l, c, 1);
  2842. var args = newNode(NodeType.ArgumentsType, value, l, c, end);
  2843. content.push(args);
  2844. // Skip `)`.
  2845. pos++;
  2846. return newNode(type, content, line, column);
  2847. }
  2848. /**
  2849. * (-) `:nth-child(+8)`
  2850. */
  2851. function checkPseudoClass5(i) {
  2852. var start = i;
  2853. var l = void 0;
  2854. // Skip `:`.
  2855. i++;
  2856. if (i >= tokensLength) return 0;
  2857. if (l = checkIdent(i)) i += l;else return 0;
  2858. if (i >= tokensLength) return 0;
  2859. if (tokens[i].type !== TokenType.LeftParenthesis) return 0;
  2860. var right = tokens[i].right;
  2861. // Skip `(`.
  2862. i++;
  2863. if (l = checkSC(i)) i += l;
  2864. if (l = checkUnary(i)) i += l;
  2865. if (tokens[i].type === TokenType.DecimalNumber) i++;else return 0;
  2866. if (l = checkSC(i)) i += l;
  2867. if (i !== right) return 0;
  2868. // Skip `)`.
  2869. i++;
  2870. return i - start;
  2871. }
  2872. function getPseudoClass5() {
  2873. var type = NodeType.PseudocType;
  2874. var token = tokens[pos];
  2875. var line = token.ln;
  2876. var column = token.col;
  2877. var content = [];
  2878. // Skip `:`.
  2879. pos++;
  2880. content.push(getIdent());
  2881. var l = tokens[pos].ln;
  2882. var c = tokens[pos].col;
  2883. var value = [];
  2884. // Skip `(`.
  2885. pos++;
  2886. value = value.concat(getSC());
  2887. if (checkUnary(pos)) value.push(getUnary());
  2888. if (checkNumber(pos)) value.push(getNumber());
  2889. value = value.concat(getSC());
  2890. var end = getLastPosition(value, l, c, 1);
  2891. var args = newNode(NodeType.ArgumentsType, value, l, c, end);
  2892. content.push(args);
  2893. // Skip `)`.
  2894. pos++;
  2895. return newNode(type, content, line, column);
  2896. }
  2897. /**
  2898. * (-) `:checked`
  2899. */
  2900. function checkPseudoClass6(i) {
  2901. var start = i;
  2902. var l = void 0;
  2903. // Skip `:`.
  2904. i++;
  2905. if (i >= tokensLength) return 0;
  2906. if (l = checkIdent(i)) i += l;else return 0;
  2907. return i - start;
  2908. }
  2909. function getPseudoClass6() {
  2910. var type = NodeType.PseudocType;
  2911. var token = tokens[pos];
  2912. var line = token.ln;
  2913. var column = token.col;
  2914. // Skip `:`.
  2915. pos++;
  2916. var content = [getIdent()];
  2917. return newNode(type, content, line, column);
  2918. }
  2919. /**
  2920. * @param {Number} i Token's index number
  2921. * @return {Number}
  2922. */
  2923. function checkRuleset(i) {
  2924. var start = i;
  2925. var l = void 0;
  2926. if (i >= tokensLength) return 0;
  2927. if (l = checkSelectorsGroup(i)) i += l;else return 0;
  2928. if (l = checkSC(i)) i += l;
  2929. if (l = checkBlock(i)) i += l;else return 0;
  2930. return i - start;
  2931. }
  2932. /**
  2933. * @return {Node}
  2934. */
  2935. function getRuleset() {
  2936. var type = NodeType.RulesetType;
  2937. var token = tokens[pos];
  2938. var line = token.ln;
  2939. var column = token.col;
  2940. var content = [].concat(getSelectorsGroup(), getSC(), getBlock());
  2941. return newNode(type, content, line, column);
  2942. }
  2943. /**
  2944. * Check if token is marked as a space (if it's a space or a tab
  2945. * or a line break).
  2946. * @param {Number} i
  2947. * @return {Number} Number of spaces in a row starting with the given token.
  2948. */
  2949. function checkS(i) {
  2950. return i < tokensLength && tokens[i].ws ? tokens[i].ws_last - i + 1 : 0;
  2951. }
  2952. /**
  2953. * Get node with spaces
  2954. * @return {Node}
  2955. */
  2956. function getS() {
  2957. var type = NodeType.SType;
  2958. var token = tokens[pos];
  2959. var line = token.ln;
  2960. var column = token.col;
  2961. var content = joinValues(pos, tokens[pos].ws_last);
  2962. pos = tokens[pos].ws_last + 1;
  2963. return newNode(type, content, line, column);
  2964. }
  2965. /**
  2966. * Check if token is a space or a comment.
  2967. * @param {Number} i Token's index number
  2968. * @return {Number} Number of similar (space or comment) tokens
  2969. * in a row starting with the given token.
  2970. */
  2971. function checkSC(i) {
  2972. if (i >= tokensLength) return 0;
  2973. var l = void 0;
  2974. var lsc = 0;
  2975. while (i < tokensLength) {
  2976. if (l = checkS(i)) tokens[i].sc_child = 1;else if (l = checkCommentML(i)) tokens[i].sc_child = 2;else break;
  2977. i += l;
  2978. lsc += l;
  2979. }
  2980. return lsc || 0;
  2981. }
  2982. /**
  2983. * Get node with spaces and comments
  2984. * @return {Array}
  2985. */
  2986. function getSC() {
  2987. var sc = [];
  2988. if (pos >= tokensLength) return sc;
  2989. while (pos < tokensLength) {
  2990. var childType = tokens[pos].sc_child;
  2991. if (childType === 1) sc.push(getS());else if (childType === 2) sc.push(getCommentML());else break;
  2992. }
  2993. return sc;
  2994. }
  2995. /**
  2996. * Check if token is part of a hexadecimal number (e.g. `#fff`) inside
  2997. * a simple selector
  2998. * @param {Number} i Token's index number
  2999. * @return {Number}
  3000. */
  3001. function checkShash(i) {
  3002. var start = i;
  3003. var l = void 0;
  3004. if (i >= tokensLength) return 0;
  3005. if (tokens[i].type === TokenType.NumberSign) i++;else return 0;
  3006. if (l = checkIdent(i)) i += l;else return 0;
  3007. return i - start;
  3008. }
  3009. /**
  3010. * Get node with a hexadecimal number (e.g. `#fff`) inside a simple
  3011. * selector
  3012. * @return {Node}
  3013. */
  3014. function getShash() {
  3015. var type = NodeType.ShashType;
  3016. var token = tokens[pos];
  3017. var line = token.ln;
  3018. var column = token.col;
  3019. // Skip `#`.
  3020. pos++;
  3021. var content = [getIdent()];
  3022. return newNode(type, content, line, column);
  3023. }
  3024. /**
  3025. * Check if token is part of a string (text wrapped in quotes)
  3026. * @param {Number} i Token's index number
  3027. * @return {Number} `1` if token is part of a string, `0` if not
  3028. */
  3029. function checkString(i) {
  3030. if (i >= tokensLength) return 0;
  3031. if (tokens[i].type === TokenType.StringSQ || tokens[i].type === TokenType.StringDQ) {
  3032. return 1;
  3033. }
  3034. return 0;
  3035. }
  3036. /**
  3037. * Get string's node
  3038. * @return {Array} `['string', x]` where `x` is a string (including
  3039. * quotes).
  3040. */
  3041. function getString() {
  3042. var type = NodeType.StringType;
  3043. var token = tokens[pos];
  3044. var line = token.ln;
  3045. var column = token.col;
  3046. var content = token.value;
  3047. pos++;
  3048. return newNode(type, content, line, column);
  3049. }
  3050. /**
  3051. * Validate stylesheet: it should consist of any number (0 or more) of
  3052. * rulesets (sets of rules with selectors), @-rules, whitespaces or
  3053. * comments.
  3054. * @param {Number} i Token's index number
  3055. * @return {Number}
  3056. */
  3057. function checkStylesheet(i) {
  3058. var start = i;
  3059. var l = void 0;
  3060. while (i < tokensLength) {
  3061. if (l = checkSC(i)) tokens[i].stylesheet_child = 1;else if (l = checkRuleset(i)) tokens[i].stylesheet_child = 2;else if (l = checkAtrule(i)) tokens[i].stylesheet_child = 3;else if (l = checkDeclDelim(i)) tokens[i].stylesheet_child = 4;else throwError(i);
  3062. i += l;
  3063. }
  3064. return i - start;
  3065. }
  3066. /**
  3067. * @return {Array} `['stylesheet', x]` where `x` is all stylesheet's
  3068. * nodes.
  3069. */
  3070. function getStylesheet() {
  3071. var type = NodeType.StylesheetType;
  3072. var token = tokens[pos];
  3073. var line = token.ln;
  3074. var column = token.col;
  3075. var content = [];
  3076. while (pos < tokensLength) {
  3077. var childType = tokens[pos].stylesheet_child;
  3078. if (childType === 1) content = content.concat(getSC());
  3079. if (childType === 2) content.push(getRuleset());
  3080. if (childType === 3) content.push(getAtrule());
  3081. if (childType === 4) content.push(getDeclDelim());
  3082. }
  3083. return newNode(type, content, line, column);
  3084. }
  3085. /**
  3086. * @param {Number} i Token's index number
  3087. * @return {Number}
  3088. */
  3089. function checkTset(i) {
  3090. var l = void 0;
  3091. if (l = checkVhash(i)) tokens[i].tset_child = 1;else if (l = checkAny(i)) tokens[i].tset_child = 2;else if (l = checkSC(i)) tokens[i].tset_child = 3;else if (l = checkOperator(i)) tokens[i].tset_child = 4;
  3092. return l;
  3093. }
  3094. /**
  3095. * @return {Array}
  3096. */
  3097. function getTset() {
  3098. var childType = tokens[pos].tset_child;
  3099. if (childType === 1) return getVhash();
  3100. if (childType === 2) return getAny();
  3101. if (childType === 3) return getSC();
  3102. if (childType === 4) return getOperator();
  3103. }
  3104. /**
  3105. * @param {Number} i Token's index number
  3106. * @return {Number}
  3107. */
  3108. function checkTsets(i) {
  3109. var start = i;
  3110. var l = void 0;
  3111. if (i >= tokensLength) return 0;
  3112. while (l = checkTset(i)) {
  3113. i += l;
  3114. }
  3115. tokens[start].tsets_end = i;
  3116. return i - start;
  3117. }
  3118. /**
  3119. * @return {Array}
  3120. */
  3121. function getTsets() {
  3122. var content = [];
  3123. var t = void 0;
  3124. if (pos >= tokensLength) return content;
  3125. var end = tokens[pos].tsets_end;
  3126. while (pos < end) {
  3127. t = getTset();
  3128. if (typeof t.content === 'string') content.push(t);else content = content.concat(t);
  3129. }
  3130. return content;
  3131. }
  3132. /**
  3133. * Check if token is an unary (arithmetical) sign (`+` or `-`)
  3134. * @param {Number} i Token's index number
  3135. * @return {Number} `1` if token is an unary sign, `0` if not
  3136. */
  3137. function checkUnary(i) {
  3138. if (i >= tokensLength) return 0;
  3139. if (tokens[i].type === TokenType.HyphenMinus || tokens[i].type === TokenType.PlusSign) {
  3140. return 1;
  3141. }
  3142. return 0;
  3143. }
  3144. /**
  3145. * Get node with an unary (arithmetical) sign (`+` or `-`)
  3146. * @return {Array} `['unary', x]` where `x` is an unary sign
  3147. * converted to string.
  3148. */
  3149. function getUnary() {
  3150. var type = NodeType.OperatorType;
  3151. var token = tokens[pos];
  3152. var line = token.ln;
  3153. var column = token.col;
  3154. var content = token.value;
  3155. pos++;
  3156. return newNode(type, content, line, column);
  3157. }
  3158. /**
  3159. * Check if token is a unicode range (single or multiple <urange> nodes)
  3160. * @param {number} i Token's index
  3161. * @return {number} Unicode range node's length
  3162. */
  3163. function checkUnicodeRange(i) {
  3164. var start = i;
  3165. var l = void 0;
  3166. if (i >= tokensLength) return 0;
  3167. if (l = checkUrange(i)) i += l;else return 0;
  3168. while (i < tokensLength) {
  3169. var spaceBefore = checkSC(i);
  3170. var comma = checkDelim(i + spaceBefore);
  3171. if (!comma) break;
  3172. var spaceAfter = checkSC(i + spaceBefore + comma);
  3173. if (l = checkUrange(i + spaceBefore + comma + spaceAfter)) {
  3174. i += spaceBefore + comma + spaceAfter + l;
  3175. } else break;
  3176. }
  3177. return i - start;
  3178. }
  3179. /**
  3180. * Get a unicode range node
  3181. * @return {Node}
  3182. */
  3183. function getUnicodeRange() {
  3184. var type = NodeType.UnicodeRangeType;
  3185. var token = tokens[pos];
  3186. var line = token.ln;
  3187. var column = token.col;
  3188. var content = [];
  3189. while (pos < tokensLength) {
  3190. if (checkSC(pos)) content = content.concat(getSC());else if (checkDelim(pos)) content.push(getDelim());else if (checkUrange(pos)) content.push(getUrange());else break;
  3191. }
  3192. return newNode(type, content, line, column);
  3193. }
  3194. /**
  3195. * Check if token is unit
  3196. * @param {Number} i Token's index number
  3197. * @return {Number}
  3198. */
  3199. function checkUnit(i) {
  3200. var units = ['em', 'ex', 'ch', 'rem', 'vh', 'vw', 'vmin', 'vmax', 'px', 'mm', 'q', 'cm', 'in', 'pt', 'pc', 'deg', 'grad', 'rad', 'turn', 's', 'ms', 'Hz', 'kHz', 'dpi', 'dpcm', 'dppx'];
  3201. return units.indexOf(tokens[i].value) !== -1 ? 1 : 0;
  3202. }
  3203. /**
  3204. * Get unit node of type ident
  3205. * @return {Node} An ident node containing the unit value
  3206. */
  3207. function getUnit() {
  3208. var type = NodeType.IdentType;
  3209. var token = tokens[pos];
  3210. var line = token.ln;
  3211. var column = token.col;
  3212. var content = token.value;
  3213. pos++;
  3214. return newNode(type, content, line, column);
  3215. }
  3216. /**
  3217. * Check if token is a u-range (part of a unicode-range)
  3218. * (1) `U+416`
  3219. * (2) `U+400-4ff`
  3220. * (3) `U+4??`
  3221. * @param {number} i Token's index
  3222. * @return {number} Urange node's length
  3223. */
  3224. function checkUrange(i) {
  3225. var start = i;
  3226. var l = void 0;
  3227. if (i >= tokensLength) return 0;
  3228. // Check for unicode prefix (u+ or U+)
  3229. if (tokens[i].value === 'U' || tokens[i].value === 'u') i += 1;else return 0;
  3230. if (i >= tokensLength) return 0;
  3231. if (tokens[i].value === '+') i += 1;else return 0;
  3232. while (i < tokensLength) {
  3233. if (l = checkIdent(i)) i += l;else if (l = checkNumber(i)) i += l;else if (l = checkUnary(i)) i += l;else if (l = _checkUnicodeWildcard(i)) i += l;else break;
  3234. }
  3235. tokens[start].urangeEnd = i - 1;
  3236. return i - start;
  3237. }
  3238. /**
  3239. * Get a u-range node (part of a unicode-range)
  3240. * @return {Node}
  3241. */
  3242. function getUrange() {
  3243. var startPos = pos;
  3244. var type = NodeType.UrangeType;
  3245. var token = tokens[pos];
  3246. var line = token.ln;
  3247. var column = token.col;
  3248. var content = [];
  3249. content = joinValues(startPos, tokens[startPos].urangeEnd);
  3250. pos = tokens[startPos].urangeEnd + 1;
  3251. return newNode(type, content, line, column);
  3252. }
  3253. /**
  3254. * Check for unicode wildcard characters `?`
  3255. * @param {number} i Token's index
  3256. * @return {number} Wildcard length
  3257. */
  3258. function _checkUnicodeWildcard(i) {
  3259. var start = i;
  3260. if (i >= tokensLength) return 0;
  3261. while (i < tokensLength) {
  3262. if (tokens[i].type === TokenType.QuestionMark) i += 1;else break;
  3263. }
  3264. return i - start;
  3265. }
  3266. /**
  3267. * Check if token is part of URI (e.g. `url('/css/styles.css')`)
  3268. * @param {Number} i Token's index number
  3269. * @return {Number} Length of URI
  3270. */
  3271. function checkUri(i) {
  3272. var start = i;
  3273. if (i >= tokensLength || tokens[i].value !== 'url') return 0;
  3274. // Skip `url`.
  3275. i++;
  3276. if (i >= tokensLength || tokens[i].type !== TokenType.LeftParenthesis) return 0;
  3277. return tokens[i].right - start + 1;
  3278. }
  3279. /**
  3280. * Get node with URI
  3281. * @return {Array} `['uri', x]` where `x` is URI's nodes (without `url`
  3282. * and braces, e.g. `['string', ''/css/styles.css'']`).
  3283. */
  3284. function getUri() {
  3285. var startPos = pos;
  3286. var uriExcluding = {};
  3287. var uri = void 0;
  3288. var l = void 0;
  3289. var raw = void 0;
  3290. var rawContent = void 0;
  3291. var t = void 0;
  3292. pos += 2;
  3293. uriExcluding[TokenType.Space] = 1;
  3294. uriExcluding[TokenType.Tab] = 1;
  3295. uriExcluding[TokenType.Newline] = 1;
  3296. uriExcluding[TokenType.LeftParenthesis] = 1;
  3297. uriExcluding[TokenType.RightParenthesis] = 1;
  3298. if (checkUri1(pos)) {
  3299. uri = [].concat(getSC(), getString(), getSC());
  3300. } else {
  3301. uri = checkSC(pos) ? getSC() : [];
  3302. l = checkExcluding(uriExcluding, pos);
  3303. rawContent = joinValues(pos, pos + l);
  3304. t = tokens[pos];
  3305. raw = newNode(NodeType.RawType, rawContent, t.ln, t.col);
  3306. uri.push(raw);
  3307. pos += l + 1;
  3308. if (checkSC(pos)) uri = uri.concat(getSC());
  3309. }
  3310. t = tokens[startPos];
  3311. var line = t.ln;
  3312. var column = t.col;
  3313. var end = getLastPosition(uri, line, column, 1);
  3314. pos++;
  3315. return newNode(NodeType.UriType, uri, line, column, end);
  3316. }
  3317. /**
  3318. * @param {Number} i Token's index number
  3319. * @return {Number}
  3320. */
  3321. function checkUri1(i) {
  3322. var start = i;
  3323. var l = void 0;
  3324. if (i >= tokensLength) return 0;
  3325. if (l = checkSC(i)) i += l;
  3326. if (tokens[i].type !== TokenType.StringDQ && tokens[i].type !== TokenType.StringSQ) return 0;
  3327. i++;
  3328. if (l = checkSC(i)) i += l;
  3329. return i - start;
  3330. }
  3331. /**
  3332. * Check if token is part of a value
  3333. * @param {Number} i Token's index number
  3334. * @return {Number} Length of the value
  3335. */
  3336. function checkValue(i) {
  3337. var start = i;
  3338. var l = void 0;
  3339. var s = void 0;
  3340. var _i = void 0;
  3341. while (i < tokensLength) {
  3342. s = checkSC(i);
  3343. _i = i + s;
  3344. if (l = _checkValue(_i)) i += l + s;else break;
  3345. }
  3346. tokens[start].value_end = i;
  3347. return i - start;
  3348. }
  3349. /**
  3350. * @return {Array}
  3351. */
  3352. function getValue() {
  3353. var type = NodeType.ValueType;
  3354. var token = tokens[pos];
  3355. var line = token.ln;
  3356. var column = token.col;
  3357. var end = tokens[pos].value_end;
  3358. var content = [];
  3359. while (pos < end) {
  3360. if (tokens[pos].value_child) content.push(_getValue());else content = content.concat(getSC());
  3361. }
  3362. return newNode(type, content, line, column);
  3363. }
  3364. /**
  3365. * @param {Number} i Token's index number
  3366. * @return {Number}
  3367. */
  3368. function _checkValue(i) {
  3369. var l = void 0;
  3370. if (l = checkProgid(i)) tokens[i].value_child = 1;else if (l = checkVhash(i)) tokens[i].value_child = 2;else if (l = checkAny(i)) tokens[i].value_child = 3;else if (l = checkOperator(i)) tokens[i].value_child = 4;else if (l = checkImportant(i)) tokens[i].value_child = 5;
  3371. return l;
  3372. }
  3373. /**
  3374. * @return {Array}
  3375. */
  3376. function _getValue() {
  3377. var childType = tokens[pos].value_child;
  3378. if (childType === 1) return getProgid();
  3379. if (childType === 2) return getVhash();
  3380. if (childType === 3) return getAny();
  3381. if (childType === 4) return getOperator();
  3382. if (childType === 5) return getImportant();
  3383. }
  3384. /**
  3385. * Check if token is part of a hexadecimal number (e.g. `#fff`) inside
  3386. * some value
  3387. * @param {Number} i Token's index number
  3388. * @return {Number}
  3389. */
  3390. function checkVhash(i) {
  3391. var start = i;
  3392. var l = void 0;
  3393. if (i >= tokensLength) return 0;
  3394. // Skip `#`.
  3395. if (tokens[i].type === TokenType.NumberSign) i++;else return 0;
  3396. if (l = checkNmName2(i)) i += l;else return 0;
  3397. return i - start;
  3398. }
  3399. /**
  3400. * Get node with a hexadecimal number (e.g. `#fff`) inside some value
  3401. * @return {Array} `['vhash', x]` where `x` is a hexadecimal number
  3402. * converted to string (without `#`, e.g. `'fff'`).
  3403. */
  3404. function getVhash() {
  3405. var type = NodeType.VhashType;
  3406. var token = tokens[pos];
  3407. var line = token.ln;
  3408. var column = token.col;
  3409. // Skip `#`.
  3410. pos++;
  3411. var content = getNmName2();
  3412. var end = getLastPosition(content, line, column + 1);
  3413. return newNode(type, content, line, column, end);
  3414. }
  3415. function checkSelectorsGroup(i) {
  3416. if (i >= tokensLength) return 0;
  3417. var start = i;
  3418. var l = void 0;
  3419. var selectorCounter = 0;
  3420. var delimCounter = 0;
  3421. if (l = checkSelector(i)) {
  3422. i += l;
  3423. selectorCounter++;
  3424. } else return 0;
  3425. while (i < tokensLength) {
  3426. var tempStart = i;
  3427. var tempIndex = i;
  3428. var tempLength = void 0;
  3429. var spaceBefore = checkSC(tempIndex);
  3430. if (tempLength = checkDelim(tempIndex + spaceBefore)) {
  3431. tempIndex += spaceBefore + tempLength;
  3432. delimCounter++;
  3433. if (tempLength = checkSC(tempIndex)) tempIndex += tempLength;
  3434. if (tempLength = checkSelector(tempIndex)) {
  3435. tempIndex += tempLength;
  3436. selectorCounter++;
  3437. }
  3438. } else break;
  3439. i += tempIndex - tempStart;
  3440. }
  3441. tokens[start].selectorsGroupEnd = i;
  3442. tokens[start].selectorsGroupSelectorCount = selectorCounter;
  3443. tokens[start].selectorsGroupDelimCount = delimCounter;
  3444. return i - start;
  3445. }
  3446. function getSelectorsGroup() {
  3447. var selectorsGroup = [];
  3448. var selectorCounter = 0;
  3449. var delimCounter = 0;
  3450. var selectorsGroupEnd = tokens[pos].selectorsGroupEnd;
  3451. var selectorCount = tokens[pos].selectorsGroupSelectorCount;
  3452. var delimCount = tokens[pos].selectorsGroupDelimCount;
  3453. selectorsGroup.push(getSelector());
  3454. selectorCounter++;
  3455. while (pos < selectorsGroupEnd) {
  3456. if (delimCounter < delimCount) {
  3457. selectorsGroup = selectorsGroup.concat(getSC());
  3458. selectorsGroup = selectorsGroup.concat(getDelim());
  3459. delimCounter++;
  3460. selectorsGroup = selectorsGroup.concat(getSC());
  3461. if (selectorCounter < selectorCount) {
  3462. selectorsGroup = selectorsGroup.concat(getSelector());
  3463. selectorCounter++;
  3464. }
  3465. }
  3466. }
  3467. return selectorsGroup;
  3468. }
  3469. function checkSelector(i) {
  3470. if (i >= tokensLength) return 0;
  3471. var start = i;
  3472. var l = void 0;
  3473. if (l = checkCompoundSelector(i)) i += l;else return 0;
  3474. while (i < tokensLength) {
  3475. var spaceBefore = checkSC(i);
  3476. var comma = checkCombinator(i + spaceBefore);
  3477. if (!spaceBefore && !comma) break;
  3478. var spaceAfter = checkSC(i + spaceBefore + comma);
  3479. if (l = checkCompoundSelector(i + spaceBefore + comma + spaceAfter)) {
  3480. i += spaceBefore + comma + spaceAfter + l;
  3481. } else break;
  3482. }
  3483. tokens[start].selectorEnd = i;
  3484. return i - start;
  3485. }
  3486. function getSelector() {
  3487. var type = NodeType.SelectorType;
  3488. var token = tokens[pos];
  3489. var line = token.ln;
  3490. var column = token.col;
  3491. var selectorEnd = token.selectorEnd;
  3492. var content = getCompoundSelector();
  3493. while (pos < selectorEnd) {
  3494. content = content.concat(getSC());
  3495. if (checkCombinator(pos)) content.push(getCombinator());
  3496. content = content.concat(getSC(), getCompoundSelector());
  3497. }
  3498. return newNode(type, content, line, column);
  3499. }
  3500. function checkCompoundSelector(i) {
  3501. var l = void 0;
  3502. if (l = checkCompoundSelector1(i)) {
  3503. tokens[i].compoundSelectorType = 1;
  3504. } else if (l = checkCompoundSelector2(i)) {
  3505. tokens[i].compoundSelectorType = 2;
  3506. }
  3507. return l;
  3508. }
  3509. function getCompoundSelector() {
  3510. var type = tokens[pos].compoundSelectorType;
  3511. if (type === 1) return getCompoundSelector1();
  3512. if (type === 2) return getCompoundSelector2();
  3513. }
  3514. function checkCompoundSelector1(i) {
  3515. if (i >= tokensLength) return 0;
  3516. var start = i;
  3517. var l = void 0;
  3518. if (l = checkUniversalSelector(i) || checkTypeSelector(i)) i += l;else return 0;
  3519. while (i < tokensLength) {
  3520. var _l2 = checkShash(i) || checkClass(i) || checkAttributeSelector(i) || checkPseudo(i);
  3521. if (_l2) i += _l2;else break;
  3522. }
  3523. tokens[start].compoundSelectorEnd = i;
  3524. return i - start;
  3525. }
  3526. function getCompoundSelector1() {
  3527. var sequence = [];
  3528. var compoundSelectorEnd = tokens[pos].compoundSelectorEnd;
  3529. if (checkUniversalSelector(pos)) sequence.push(getUniversalSelector());else sequence.push(getTypeSelector());
  3530. while (pos < compoundSelectorEnd) {
  3531. if (checkShash(pos)) sequence.push(getShash());else if (checkClass(pos)) sequence.push(getClass());else if (checkAttributeSelector(pos)) sequence.push(getAttributeSelector());else if (checkPseudo(pos)) sequence.push(getPseudo());
  3532. }
  3533. return sequence;
  3534. }
  3535. function checkCompoundSelector2(i) {
  3536. if (i >= tokensLength) return 0;
  3537. var start = i;
  3538. while (i < tokensLength) {
  3539. var l = checkShash(i) || checkClass(i) || checkAttributeSelector(i) || checkPseudo(i);
  3540. if (l) i += l;else break;
  3541. }
  3542. tokens[start].compoundSelectorEnd = i;
  3543. return i - start;
  3544. }
  3545. function getCompoundSelector2() {
  3546. var sequence = [];
  3547. var compoundSelectorEnd = tokens[pos].compoundSelectorEnd;
  3548. while (pos < compoundSelectorEnd) {
  3549. if (checkShash(pos)) sequence.push(getShash());else if (checkClass(pos)) sequence.push(getClass());else if (checkAttributeSelector(pos)) sequence.push(getAttributeSelector());else if (checkPseudo(pos)) sequence.push(getPseudo());else break;
  3550. }
  3551. return sequence;
  3552. }
  3553. function checkUniversalSelector(i) {
  3554. if (i >= tokensLength) return 0;
  3555. var start = i;
  3556. var l = void 0;
  3557. if (l = checkNamePrefix(i)) i += l;
  3558. if (tokens[i].type === TokenType.Asterisk) i++;else return 0;
  3559. return i - start;
  3560. }
  3561. function getUniversalSelector() {
  3562. var type = NodeType.UniversalSelectorType;
  3563. var token = tokens[pos];
  3564. var line = token.ln;
  3565. var column = token.col;
  3566. var content = [];
  3567. var end = void 0;
  3568. if (checkNamePrefix(pos)) {
  3569. content.push(getNamePrefix());
  3570. end = getLastPosition(content, line, column, 1);
  3571. }
  3572. pos++;
  3573. return newNode(type, content, line, column, end);
  3574. }
  3575. function checkTypeSelector(i) {
  3576. if (i >= tokensLength) return 0;
  3577. var start = i;
  3578. var l = void 0;
  3579. if (l = checkNamePrefix(i)) i += l;
  3580. if (l = checkIdent(i)) i += l;else return 0;
  3581. return i - start;
  3582. }
  3583. function getTypeSelector() {
  3584. var type = NodeType.TypeSelectorType;
  3585. var token = tokens[pos];
  3586. var line = token.ln;
  3587. var column = token.col;
  3588. var content = [];
  3589. if (checkNamePrefix(pos)) content.push(getNamePrefix());
  3590. content.push(getIdent());
  3591. return newNode(type, content, line, column);
  3592. }
  3593. function checkAttributeSelector(i) {
  3594. var l = void 0;
  3595. if (l = checkAttributeSelector1(i)) tokens[i].attributeSelectorType = 1;else if (l = checkAttributeSelector2(i)) tokens[i].attributeSelectorType = 2;
  3596. return l;
  3597. }
  3598. function getAttributeSelector() {
  3599. var type = tokens[pos].attributeSelectorType;
  3600. if (type === 1) return getAttributeSelector1();else return getAttributeSelector2();
  3601. }
  3602. /**
  3603. * (1) `[panda=nani]`
  3604. * (2) `[panda='nani']`
  3605. * (3) `[panda='nani' i]`
  3606. *
  3607. */
  3608. function checkAttributeSelector1(i) {
  3609. var start = i;
  3610. if (tokens[i].type === TokenType.LeftSquareBracket) i++;else return 0;
  3611. var l = void 0;
  3612. if (l = checkSC(i)) i += l;
  3613. if (l = checkAttributeName(i)) i += l;else return 0;
  3614. if (l = checkSC(i)) i += l;
  3615. if (l = checkAttributeMatch(i)) i += l;else return 0;
  3616. if (l = checkSC(i)) i += l;
  3617. if (l = checkAttributeValue(i)) i += l;else return 0;
  3618. if (l = checkSC(i)) i += l;
  3619. if (l = checkAttributeFlags(i)) {
  3620. i += l;
  3621. if (l = checkSC(i)) i += l;
  3622. }
  3623. if (tokens[i].type === TokenType.RightSquareBracket) i++;else return 0;
  3624. return i - start;
  3625. }
  3626. function getAttributeSelector1() {
  3627. var type = NodeType.AttributeSelectorType;
  3628. var token = tokens[pos];
  3629. var line = token.ln;
  3630. var column = token.col;
  3631. var content = [];
  3632. // Skip `[`.
  3633. pos++;
  3634. content = content.concat(getSC(), getAttributeName(), getSC(), getAttributeMatch(), getSC(), getAttributeValue(), getSC());
  3635. if (checkAttributeFlags(pos)) {
  3636. content.push(getAttributeFlags());
  3637. content = content.concat(getSC());
  3638. }
  3639. // Skip `]`.
  3640. pos++;
  3641. var end = getLastPosition(content, line, column, 1);
  3642. return newNode(type, content, line, column, end);
  3643. }
  3644. /**
  3645. * (1) `[panda]`
  3646. */
  3647. function checkAttributeSelector2(i) {
  3648. var start = i;
  3649. if (tokens[i].type === TokenType.LeftSquareBracket) i++;else return 0;
  3650. var l = void 0;
  3651. if (l = checkSC(i)) i += l;
  3652. if (l = checkAttributeName(i)) i += l;else return 0;
  3653. if (l = checkSC(i)) i += l;
  3654. if (tokens[i].type === TokenType.RightSquareBracket) i++;else return 0;
  3655. return i - start;
  3656. }
  3657. function getAttributeSelector2() {
  3658. var type = NodeType.AttributeSelectorType;
  3659. var token = tokens[pos];
  3660. var line = token.ln;
  3661. var column = token.col;
  3662. var content = [];
  3663. // Skip `[`.
  3664. pos++;
  3665. content = content.concat(getSC(), getAttributeName(), getSC());
  3666. // Skip `]`.
  3667. pos++;
  3668. var end = getLastPosition(content, line, column, 1);
  3669. return newNode(type, content, line, column, end);
  3670. }
  3671. function checkAttributeName(i) {
  3672. var start = i;
  3673. var l = void 0;
  3674. if (l = checkNamePrefix(i)) i += l;
  3675. if (l = checkIdent(i)) i += l;else return 0;
  3676. return i - start;
  3677. }
  3678. function getAttributeName() {
  3679. var type = NodeType.AttributeNameType;
  3680. var token = tokens[pos];
  3681. var line = token.ln;
  3682. var column = token.col;
  3683. var content = [];
  3684. if (checkNamePrefix(pos)) content.push(getNamePrefix());
  3685. content.push(getIdent());
  3686. return newNode(type, content, line, column);
  3687. }
  3688. function checkAttributeMatch(i) {
  3689. var l = void 0;
  3690. if (l = checkAttributeMatch1(i)) tokens[i].attributeMatchType = 1;else if (l = checkAttributeMatch2(i)) tokens[i].attributeMatchType = 2;
  3691. return l;
  3692. }
  3693. function getAttributeMatch() {
  3694. var type = tokens[pos].attributeMatchType;
  3695. if (type === 1) return getAttributeMatch1();else return getAttributeMatch2();
  3696. }
  3697. function checkAttributeMatch1(i) {
  3698. var start = i;
  3699. var type = tokens[i].type;
  3700. if (type === TokenType.Tilde || type === TokenType.VerticalLine || type === TokenType.CircumflexAccent || type === TokenType.DollarSign || type === TokenType.Asterisk) i++;else return 0;
  3701. if (tokens[i].type === TokenType.EqualsSign) i++;else return 0;
  3702. return i - start;
  3703. }
  3704. function getAttributeMatch1() {
  3705. var type = NodeType.AttributeMatchType;
  3706. var token = tokens[pos];
  3707. var line = token.ln;
  3708. var column = token.col;
  3709. var content = tokens[pos].value + tokens[pos + 1].value;
  3710. pos += 2;
  3711. return newNode(type, content, line, column);
  3712. }
  3713. function checkAttributeMatch2(i) {
  3714. if (tokens[i].type === TokenType.EqualsSign) return 1;else return 0;
  3715. }
  3716. function getAttributeMatch2() {
  3717. var type = NodeType.AttributeMatchType;
  3718. var token = tokens[pos];
  3719. var line = token.ln;
  3720. var column = token.col;
  3721. var content = '=';
  3722. pos++;
  3723. return newNode(type, content, line, column);
  3724. }
  3725. function checkAttributeValue(i) {
  3726. return checkString(i) || checkIdent(i);
  3727. }
  3728. function getAttributeValue() {
  3729. var type = NodeType.AttributeValueType;
  3730. var token = tokens[pos];
  3731. var line = token.ln;
  3732. var column = token.col;
  3733. var content = [];
  3734. if (checkString(pos)) content.push(getString());else content.push(getIdent());
  3735. return newNode(type, content, line, column);
  3736. }
  3737. function checkAttributeFlags(i) {
  3738. return checkIdent(i);
  3739. }
  3740. function getAttributeFlags() {
  3741. var type = NodeType.AttributeFlagsType;
  3742. var token = tokens[pos];
  3743. var line = token.ln;
  3744. var column = token.col;
  3745. var content = [getIdent()];
  3746. return newNode(type, content, line, column);
  3747. }
  3748. function checkNamePrefix(i) {
  3749. if (i >= tokensLength) return 0;
  3750. var l = void 0;
  3751. if (l = checkNamePrefix1(i)) tokens[i].namePrefixType = 1;else if (l = checkNamePrefix2(i)) tokens[i].namePrefixType = 2;
  3752. return l;
  3753. }
  3754. function getNamePrefix() {
  3755. var type = tokens[pos].namePrefixType;
  3756. if (type === 1) return getNamePrefix1();else return getNamePrefix2();
  3757. }
  3758. /**
  3759. * (1) `panda|`
  3760. * (2) `panda<comment>|`
  3761. */
  3762. function checkNamePrefix1(i) {
  3763. var start = i;
  3764. var l = void 0;
  3765. if (l = checkNamespacePrefix(i)) i += l;else return 0;
  3766. if (l = checkCommentML(i)) i += l;
  3767. if (l = checkNamespaceSeparator(i)) i += l;else return 0;
  3768. return i - start;
  3769. }
  3770. function getNamePrefix1() {
  3771. var type = NodeType.NamePrefixType;
  3772. var token = tokens[pos];
  3773. var line = token.ln;
  3774. var column = token.col;
  3775. var content = [];
  3776. content.push(getNamespacePrefix());
  3777. if (checkCommentML(pos)) content.push(getCommentML());
  3778. content.push(getNamespaceSeparator());
  3779. return newNode(type, content, line, column);
  3780. }
  3781. /**
  3782. * (1) `|`
  3783. */
  3784. function checkNamePrefix2(i) {
  3785. return checkNamespaceSeparator(i);
  3786. }
  3787. function getNamePrefix2() {
  3788. var type = NodeType.NamePrefixType;
  3789. var token = tokens[pos];
  3790. var line = token.ln;
  3791. var column = token.col;
  3792. var content = [getNamespaceSeparator()];
  3793. return newNode(type, content, line, column);
  3794. }
  3795. /**
  3796. * (1) `*`
  3797. * (2) `panda`
  3798. */
  3799. function checkNamespacePrefix(i) {
  3800. if (i >= tokensLength) return 0;
  3801. var l = void 0;
  3802. if (tokens[i].type === TokenType.Asterisk) return 1;else if (l = checkIdent(i)) return l;else return 0;
  3803. }
  3804. function getNamespacePrefix() {
  3805. var type = NodeType.NamespacePrefixType;
  3806. var token = tokens[pos];
  3807. var line = token.ln;
  3808. var column = token.col;
  3809. var content = [];
  3810. if (token.type === TokenType.Asterisk) {
  3811. var asteriskNode = newNode(NodeType.IdentType, '*', line, column);
  3812. content.push(asteriskNode);
  3813. pos++;
  3814. } else if (checkIdent(pos)) content.push(getIdent());
  3815. return newNode(type, content, line, column);
  3816. }
  3817. /**
  3818. * (1) `|`
  3819. */
  3820. function checkNamespaceSeparator(i) {
  3821. if (i >= tokensLength) return 0;
  3822. if (tokens[i].type !== TokenType.VerticalLine) return 0;
  3823. // Return false if `|=` - [attr|=value]
  3824. if (tokens[i + 1] && tokens[i + 1].type === TokenType.EqualsSign) return 0;
  3825. return 1;
  3826. }
  3827. function getNamespaceSeparator() {
  3828. var type = NodeType.NamespaceSeparatorType;
  3829. var token = tokens[pos];
  3830. var line = token.ln;
  3831. var column = token.col;
  3832. var content = '|';
  3833. pos++;
  3834. return newNode(type, content, line, column);
  3835. }
  3836. module.exports = function (_tokens, context) {
  3837. tokens = _tokens;
  3838. tokensLength = tokens.length;
  3839. pos = 0;
  3840. return contexts[context]();
  3841. };
  3842. /***/ }),
  3843. /* 15 */
  3844. /***/ (function(module, exports) {
  3845. 'use strict';
  3846. module.exports = {
  3847. ArgumentsType: 'arguments',
  3848. AtkeywordType: 'atkeyword',
  3849. AtruleType: 'atrule',
  3850. AttributeSelectorType: 'attributeSelector',
  3851. AttributeNameType: 'attributeName',
  3852. AttributeFlagsType: 'attributeFlags',
  3853. AttributeMatchType: 'attributeMatch',
  3854. AttributeValueType: 'attributeValue',
  3855. BlockType: 'block',
  3856. BracketsType: 'brackets',
  3857. ClassType: 'class',
  3858. CombinatorType: 'combinator',
  3859. CommentMLType: 'multilineComment',
  3860. CommentSLType: 'singlelineComment',
  3861. ConditionType: 'condition',
  3862. ConditionalStatementType: 'conditionalStatement',
  3863. CustomPropertyType: 'customProperty',
  3864. DeclarationType: 'declaration',
  3865. DeclDelimType: 'declarationDelimiter',
  3866. DefaultType: 'default',
  3867. DelimType: 'delimiter',
  3868. DimensionType: 'dimension',
  3869. EscapedStringType: 'escapedString',
  3870. ExtendType: 'extend',
  3871. ExpressionType: 'expression',
  3872. FunctionType: 'function',
  3873. FunctionsListType: 'functionsList',
  3874. GlobalType: 'global',
  3875. IdentType: 'ident',
  3876. ImportantType: 'important',
  3877. IncludeType: 'include',
  3878. InterpolationType: 'interpolation',
  3879. InterpolatedVariableType: 'interpolatedVariable',
  3880. KeyframesSelectorType: 'keyframesSelector',
  3881. LoopType: 'loop',
  3882. MixinType: 'mixin',
  3883. NamePrefixType: 'namePrefix',
  3884. NamespacePrefixType: 'namespacePrefix',
  3885. NamespaceSeparatorType: 'namespaceSeparator',
  3886. NumberType: 'number',
  3887. OperatorType: 'operator',
  3888. OptionalType: 'optional',
  3889. ParenthesesType: 'parentheses',
  3890. ParentSelectorType: 'parentSelector',
  3891. ParentSelectorExtensionType: 'parentSelectorExtension',
  3892. PercentageType: 'percentage',
  3893. PlaceholderType: 'placeholder',
  3894. ProgidType: 'progid',
  3895. PropertyType: 'property',
  3896. PropertyDelimType: 'propertyDelimiter',
  3897. PseudocType: 'pseudoClass',
  3898. PseudoeType: 'pseudoElement',
  3899. RawType: 'raw',
  3900. RulesetType: 'ruleset',
  3901. SType: 'space',
  3902. SelectorType: 'selector',
  3903. ShashType: 'id',
  3904. StringType: 'string',
  3905. StylesheetType: 'stylesheet',
  3906. TypeSelectorType: 'typeSelector',
  3907. UnicodeRangeType: 'unicodeRange',
  3908. UniversalSelectorType: 'universalSelector',
  3909. UriType: 'uri',
  3910. UrangeType: 'urange',
  3911. ValueType: 'value',
  3912. VariableType: 'variable',
  3913. VariablesListType: 'variablesList',
  3914. VhashType: 'color'
  3915. };
  3916. /***/ }),
  3917. /* 16 */
  3918. /***/ (function(module, exports, __webpack_require__) {
  3919. 'use strict';
  3920. module.exports = function (css, tabSize) {
  3921. var TokenType = __webpack_require__(13);
  3922. var tokens = [];
  3923. var urlMode = false;
  3924. var blockMode = 0;
  3925. var pos = 0;
  3926. var tn = 0;
  3927. var ln = 1;
  3928. var col = 1;
  3929. var cssLength = 0;
  3930. var Punctuation = {
  3931. ' ': TokenType.Space,
  3932. '\n': TokenType.Newline,
  3933. '\r': TokenType.Newline,
  3934. '\t': TokenType.Tab,
  3935. '!': TokenType.ExclamationMark,
  3936. '"': TokenType.QuotationMark,
  3937. '#': TokenType.NumberSign,
  3938. '$': TokenType.DollarSign,
  3939. '%': TokenType.PercentSign,
  3940. '&': TokenType.Ampersand,
  3941. '\'': TokenType.Apostrophe,
  3942. '(': TokenType.LeftParenthesis,
  3943. ')': TokenType.RightParenthesis,
  3944. '*': TokenType.Asterisk,
  3945. '+': TokenType.PlusSign,
  3946. ',': TokenType.Comma,
  3947. '-': TokenType.HyphenMinus,
  3948. '.': TokenType.FullStop,
  3949. '/': TokenType.Solidus,
  3950. ':': TokenType.Colon,
  3951. ';': TokenType.Semicolon,
  3952. '<': TokenType.LessThanSign,
  3953. '=': TokenType.EqualsSign,
  3954. '>': TokenType.GreaterThanSign,
  3955. '?': TokenType.QuestionMark,
  3956. '@': TokenType.CommercialAt,
  3957. '[': TokenType.LeftSquareBracket,
  3958. ']': TokenType.RightSquareBracket,
  3959. '^': TokenType.CircumflexAccent,
  3960. '_': TokenType.LowLine,
  3961. '{': TokenType.LeftCurlyBracket,
  3962. '|': TokenType.VerticalLine,
  3963. '}': TokenType.RightCurlyBracket,
  3964. '~': TokenType.Tilde
  3965. };
  3966. /**
  3967. * Add a token to the token list
  3968. * @param {string} type
  3969. * @param {string} value
  3970. */
  3971. function pushToken(type, value, column) {
  3972. tokens.push({
  3973. tn: tn++,
  3974. ln: ln,
  3975. col: column,
  3976. type: type,
  3977. value: value
  3978. });
  3979. }
  3980. /**
  3981. * Check if a character is a decimal digit
  3982. * @param {string} c Character
  3983. * @returns {boolean}
  3984. */
  3985. function isDecimalDigit(c) {
  3986. return '0123456789'.indexOf(c) >= 0;
  3987. }
  3988. /**
  3989. * Parse spaces
  3990. * @param {string} css Unparsed part of CSS string
  3991. */
  3992. function parseSpaces(css) {
  3993. var start = pos;
  3994. // Read the string until we meet a non-space character:
  3995. for (; pos < cssLength; pos++) {
  3996. if (css.charAt(pos) !== ' ') break;
  3997. }
  3998. // Add a substring containing only spaces to tokens:
  3999. pushToken(TokenType.Space, css.substring(start, pos--), col);
  4000. col += pos - start;
  4001. }
  4002. /**
  4003. * Parse a string within quotes
  4004. * @param {string} css Unparsed part of CSS string
  4005. * @param {string} q Quote (either `'` or `"`)
  4006. */
  4007. function parseString(css, q) {
  4008. var start = pos;
  4009. // Read the string until we meet a matching quote:
  4010. for (pos++; pos < cssLength; pos++) {
  4011. // Skip escaped quotes:
  4012. if (css.charAt(pos) === '\\') pos++;else if (css.charAt(pos) === q) break;
  4013. }
  4014. // Add the string (including quotes) to tokens:
  4015. pushToken(q === '"' ? TokenType.StringDQ : TokenType.StringSQ, css.substring(start, pos + 1), col);
  4016. col += pos - start;
  4017. }
  4018. /**
  4019. * Parse numbers
  4020. * @param {string} css Unparsed part of CSS string
  4021. */
  4022. function parseDecimalNumber(css) {
  4023. var start = pos;
  4024. // Read the string until we meet a character that's not a digit:
  4025. for (; pos < cssLength; pos++) {
  4026. if (!isDecimalDigit(css.charAt(pos))) break;
  4027. }
  4028. // Add the number to tokens:
  4029. pushToken(TokenType.DecimalNumber, css.substring(start, pos--), col);
  4030. col += pos - start;
  4031. }
  4032. /**
  4033. * Parse identifier
  4034. * @param {string} css Unparsed part of CSS string
  4035. */
  4036. function parseIdentifier(css) {
  4037. var start = pos;
  4038. // Skip all opening slashes:
  4039. while (css.charAt(pos) === '/') {
  4040. pos++;
  4041. } // Read the string until we meet a punctuation mark:
  4042. for (; pos < cssLength; pos++) {
  4043. // Skip all '\':
  4044. if (css.charAt(pos) === '\\') pos++;else if (Punctuation[css.charAt(pos)]) break;
  4045. }
  4046. var ident = css.substring(start, pos--);
  4047. // Enter url mode if parsed substring is `url`:
  4048. urlMode = urlMode || ident === 'url';
  4049. // Add identifier to tokens:
  4050. pushToken(TokenType.Identifier, ident, col);
  4051. col += pos - start;
  4052. }
  4053. /**
  4054. * Parse a multiline comment
  4055. * @param {string} css Unparsed part of CSS string
  4056. */
  4057. function parseMLComment(css) {
  4058. var start = pos;
  4059. // Read the string until we meet `*/`.
  4060. // Since we already know first 2 characters (`/*`), start reading
  4061. // from `pos + 2`:
  4062. for (pos = pos + 2; pos < cssLength; pos++) {
  4063. if (css.charAt(pos) === '*' && css.charAt(pos + 1) === '/') {
  4064. pos++;
  4065. break;
  4066. }
  4067. }
  4068. // Add full comment (including `/*` and `*/`) to the list of tokens:
  4069. var comment = css.substring(start, pos + 1);
  4070. pushToken(TokenType.CommentML, comment, col);
  4071. var newlines = comment.split('\n');
  4072. if (newlines.length > 1) {
  4073. ln += newlines.length - 1;
  4074. col = newlines[newlines.length - 1].length;
  4075. } else {
  4076. col += pos - start;
  4077. }
  4078. }
  4079. function parseSLComment(css) {
  4080. var start = pos;
  4081. // Read the string until we meet line break.
  4082. // Since we already know first 2 characters (`//`), start reading
  4083. // from `pos + 2`:
  4084. for (pos += 2; pos < cssLength; pos++) {
  4085. if (css.charAt(pos) === '\n' || css.charAt(pos) === '\r') {
  4086. break;
  4087. }
  4088. }
  4089. // Add comment (including `//` and line break) to the list of tokens:
  4090. pushToken(TokenType.CommentSL, css.substring(start, pos--), col);
  4091. col += pos - start;
  4092. }
  4093. /**
  4094. * Convert a CSS string to a list of tokens
  4095. * @param {string} css CSS string
  4096. * @returns {Array} List of tokens
  4097. * @private
  4098. */
  4099. function getTokens(css) {
  4100. var c; // Current character
  4101. var cn; // Next character
  4102. cssLength = css.length;
  4103. // Parse string, character by character:
  4104. for (pos = 0; pos < cssLength; col++, pos++) {
  4105. c = css.charAt(pos);
  4106. cn = css.charAt(pos + 1);
  4107. // If we meet `/*`, it's a start of a multiline comment.
  4108. // Parse following characters as a multiline comment:
  4109. if (c === '/' && cn === '*') {
  4110. parseMLComment(css);
  4111. }
  4112. // If we meet `//` and it is not a part of url:
  4113. else if (!urlMode && c === '/' && cn === '/') {
  4114. // If we're currently inside a block, treat `//` as a start
  4115. // of identifier. Else treat `//` as a start of a single-line
  4116. // comment:
  4117. if (blockMode > 0) parseIdentifier(css);else parseSLComment(css);
  4118. }
  4119. // If current character is a double or single quote, it's a start
  4120. // of a string:
  4121. else if (c === '"' || c === "'") {
  4122. parseString(css, c);
  4123. }
  4124. // If current character is a space:
  4125. else if (c === ' ') {
  4126. parseSpaces(css);
  4127. }
  4128. // If current character is a punctuation mark:
  4129. else if (Punctuation[c]) {
  4130. // Add it to the list of tokens:
  4131. pushToken(Punctuation[c], c, col);
  4132. if (c === '\n' || c === '\r') {
  4133. ln++;
  4134. col = 0;
  4135. } // Go to next line
  4136. else if (c === ')') urlMode = false; // Exit url mode
  4137. else if (c === '{') blockMode++; // Enter a block
  4138. else if (c === '}') blockMode--; // Exit a block
  4139. else if (c === '\t' && tabSize > 1) col += tabSize - 1;
  4140. }
  4141. // If current character is a decimal digit:
  4142. else if (isDecimalDigit(c)) {
  4143. parseDecimalNumber(css);
  4144. }
  4145. // If current character is anything else:
  4146. else {
  4147. parseIdentifier(css);
  4148. }
  4149. }
  4150. return tokens;
  4151. }
  4152. return getTokens(css);
  4153. };
  4154. /***/ }),
  4155. /* 17 */
  4156. /***/ (function(module, exports, __webpack_require__) {
  4157. 'use strict';
  4158. exports.__esModule = true;
  4159. exports.default = {
  4160. mark: __webpack_require__(18),
  4161. parse: __webpack_require__(19),
  4162. stringify: __webpack_require__(4),
  4163. tokenizer: __webpack_require__(20)
  4164. };
  4165. module.exports = exports['default'];
  4166. /***/ }),
  4167. /* 18 */
  4168. /***/ (function(module, exports, __webpack_require__) {
  4169. 'use strict';
  4170. var TokenType = __webpack_require__(13);
  4171. module.exports = function () {
  4172. /**
  4173. * Mark whitespaces and comments
  4174. */
  4175. function markSC(tokens) {
  4176. var tokensLength = tokens.length;
  4177. var ws = -1; // Flag for whitespaces
  4178. var sc = -1; // Flag for whitespaces and comments
  4179. var t = void 0; // Current token
  4180. // For every token in the token list, mark spaces and line breaks
  4181. // as spaces (set both `ws` and `sc` flags). Mark multiline comments
  4182. // with `sc` flag.
  4183. // If there are several spaces or tabs or line breaks or multiline
  4184. // comments in a row, group them: take the last one's index number
  4185. // and save it to the first token in the group as a reference:
  4186. // e.g., `ws_last = 7` for a group of whitespaces or `sc_last = 9`
  4187. // for a group of whitespaces and comments.
  4188. for (var i = 0; i < tokensLength; i++) {
  4189. t = tokens[i];
  4190. switch (t.type) {
  4191. case TokenType.Space:
  4192. case TokenType.Tab:
  4193. case TokenType.Newline:
  4194. t.ws = true;
  4195. t.sc = true;
  4196. if (ws === -1) ws = i;
  4197. if (sc === -1) sc = i;
  4198. break;
  4199. case TokenType.CommentML:
  4200. case TokenType.CommentSL:
  4201. if (ws !== -1) {
  4202. tokens[ws].ws_last = i - 1;
  4203. ws = -1;
  4204. }
  4205. t.sc = true;
  4206. break;
  4207. default:
  4208. if (ws !== -1) {
  4209. tokens[ws].ws_last = i - 1;
  4210. ws = -1;
  4211. }
  4212. if (sc !== -1) {
  4213. tokens[sc].sc_last = i - 1;
  4214. sc = -1;
  4215. }
  4216. }
  4217. }
  4218. if (ws !== -1) tokens[ws].ws_last = i - 1;
  4219. if (sc !== -1) tokens[sc].sc_last = i - 1;
  4220. }
  4221. /**
  4222. * Pair brackets
  4223. */
  4224. function markBrackets(tokens) {
  4225. var tokensLength = tokens.length;
  4226. var ps = []; // Parentheses
  4227. var sbs = []; // Square brackets
  4228. var cbs = []; // Curly brackets
  4229. var t = void 0; // Current token
  4230. // For every token in the token list, if we meet an opening (left)
  4231. // bracket, push its index number to a corresponding array.
  4232. // If we then meet a closing (right) bracket, look at the corresponding
  4233. // array. If there are any elements (records about previously met
  4234. // left brackets), take a token of the last left bracket (take
  4235. // the last index number from the array and find a token with
  4236. // this index number) and save right bracket's index as a reference:
  4237. for (var i = 0; i < tokensLength; i++) {
  4238. t = tokens[i];
  4239. switch (t.type) {
  4240. case TokenType.LeftParenthesis:
  4241. ps.push(i);
  4242. break;
  4243. case TokenType.RightParenthesis:
  4244. if (ps.length) {
  4245. t.left = ps.pop();
  4246. tokens[t.left].right = i;
  4247. }
  4248. break;
  4249. case TokenType.LeftSquareBracket:
  4250. sbs.push(i);
  4251. break;
  4252. case TokenType.RightSquareBracket:
  4253. if (sbs.length) {
  4254. t.left = sbs.pop();
  4255. tokens[t.left].right = i;
  4256. }
  4257. break;
  4258. case TokenType.LeftCurlyBracket:
  4259. cbs.push(i);
  4260. break;
  4261. case TokenType.RightCurlyBracket:
  4262. if (cbs.length) {
  4263. t.left = cbs.pop();
  4264. tokens[t.left].right = i;
  4265. }
  4266. break;
  4267. }
  4268. }
  4269. }
  4270. return function (tokens) {
  4271. markBrackets(tokens);
  4272. markSC(tokens);
  4273. };
  4274. }();
  4275. /***/ }),
  4276. /* 19 */
  4277. /***/ (function(module, exports, __webpack_require__) {
  4278. 'use strict';
  4279. var Node = __webpack_require__(1);
  4280. var NodeType = __webpack_require__(15);
  4281. var TokenType = __webpack_require__(13);
  4282. var tokens = void 0;
  4283. var tokensLength = void 0;
  4284. var pos = void 0;
  4285. var contexts = {
  4286. 'arguments': function _arguments() {
  4287. return checkArguments(pos) && getArguments();
  4288. },
  4289. 'atkeyword': function atkeyword() {
  4290. return checkAtkeyword(pos) && getAtkeyword();
  4291. },
  4292. 'atrule': function atrule() {
  4293. return checkAtrule(pos) && getAtrule();
  4294. },
  4295. 'attributeSelector': function attributeSelector() {
  4296. return checkAttributeSelector(pos) && getAttributeSelector();
  4297. },
  4298. 'block': function block() {
  4299. return checkBlock(pos) && getBlock();
  4300. },
  4301. 'brackets': function brackets() {
  4302. return checkBrackets(pos) && getBrackets();
  4303. },
  4304. 'class': function _class() {
  4305. return checkClass(pos) && getClass();
  4306. },
  4307. 'combinator': function combinator() {
  4308. return checkCombinator(pos) && getCombinator();
  4309. },
  4310. 'commentML': function commentML() {
  4311. return checkCommentML(pos) && getCommentML();
  4312. },
  4313. 'commentSL': function commentSL() {
  4314. return checkCommentSL(pos) && getCommentSL();
  4315. },
  4316. 'condition': function condition() {
  4317. return checkCondition(pos) && getCondition();
  4318. },
  4319. 'declaration': function declaration() {
  4320. return checkDeclaration(pos) && getDeclaration();
  4321. },
  4322. 'declDelim': function declDelim() {
  4323. return checkDeclDelim(pos) && getDeclDelim();
  4324. },
  4325. 'delim': function delim() {
  4326. return checkDelim(pos) && getDelim();
  4327. },
  4328. 'dimension': function dimension() {
  4329. return checkDimension(pos) && getDimension();
  4330. },
  4331. 'escapedString': function escapedString() {
  4332. return checkEscapedString(pos) && getEscapedString();
  4333. },
  4334. 'expression': function expression() {
  4335. return checkExpression(pos) && getExpression();
  4336. },
  4337. 'extend': function extend() {
  4338. return checkExtend(pos) && getExtend();
  4339. },
  4340. 'function': function _function() {
  4341. return checkFunction(pos) && getFunction();
  4342. },
  4343. 'ident': function ident() {
  4344. return checkIdent(pos) && getIdent();
  4345. },
  4346. 'important': function important() {
  4347. return checkImportant(pos) && getImportant();
  4348. },
  4349. 'include': function include() {
  4350. return checkInclude(pos) && getInclude();
  4351. },
  4352. 'interpolatedVariable': function interpolatedVariable() {
  4353. return checkInterpolatedVariable(pos) && getInterpolatedVariable();
  4354. },
  4355. 'mixin': function mixin() {
  4356. return checkMixin(pos) && getMixin();
  4357. },
  4358. 'namespace': function namespace() {
  4359. return checkNamespace(pos) && getNamespace();
  4360. },
  4361. 'number': function number() {
  4362. return checkNumber(pos) && getNumber();
  4363. },
  4364. 'operator': function operator() {
  4365. return checkOperator(pos) && getOperator();
  4366. },
  4367. 'parentheses': function parentheses() {
  4368. return checkParentheses(pos) && getParentheses();
  4369. },
  4370. 'parentselector': function parentselector() {
  4371. return checkParentSelector(pos) && getParentSelector();
  4372. },
  4373. 'percentage': function percentage() {
  4374. return checkPercentage(pos) && getPercentage();
  4375. },
  4376. 'progid': function progid() {
  4377. return checkProgid(pos) && getProgid();
  4378. },
  4379. 'property': function property() {
  4380. return checkProperty(pos) && getProperty();
  4381. },
  4382. 'propertyDelim': function propertyDelim() {
  4383. return checkPropertyDelim(pos) && getPropertyDelim();
  4384. },
  4385. 'pseudoc': function pseudoc() {
  4386. return checkPseudoc(pos) && getPseudoc();
  4387. },
  4388. 'pseudoe': function pseudoe() {
  4389. return checkPseudoe(pos) && getPseudoe();
  4390. },
  4391. 'ruleset': function ruleset() {
  4392. return checkRuleset(pos) && getRuleset();
  4393. },
  4394. 's': function s() {
  4395. return checkS(pos) && getS();
  4396. },
  4397. 'selector': function selector() {
  4398. return checkSelector(pos) && getSelector();
  4399. },
  4400. 'shash': function shash() {
  4401. return checkShash(pos) && getShash();
  4402. },
  4403. 'string': function string() {
  4404. return checkString(pos) && getString();
  4405. },
  4406. 'stylesheet': function stylesheet() {
  4407. return checkStylesheet(pos) && getStylesheet();
  4408. },
  4409. 'unary': function unary() {
  4410. return checkUnary(pos) && getUnary();
  4411. },
  4412. 'unicodeRange': function unicodeRange() {
  4413. return checkUnicodeRange(pos) && getUnicodeRange();
  4414. },
  4415. 'universalSelector': function universalSelector() {
  4416. return checkUniversalSelector(pos) && getUniversalSelector();
  4417. },
  4418. 'urange': function urange() {
  4419. return checkUrange(pos) && getUrange();
  4420. },
  4421. 'uri': function uri() {
  4422. return checkUri(pos) && getUri();
  4423. },
  4424. 'value': function value() {
  4425. return checkValue(pos) && getValue();
  4426. },
  4427. 'variable': function variable() {
  4428. return checkVariable(pos) && getVariable();
  4429. },
  4430. 'variableslist': function variableslist() {
  4431. return checkVariablesList(pos) && getVariablesList();
  4432. },
  4433. 'vhash': function vhash() {
  4434. return checkVhash(pos) && getVhash();
  4435. }
  4436. };
  4437. /**
  4438. * Stop parsing and display error
  4439. * @param {Number=} i Token's index number
  4440. */
  4441. function throwError(i) {
  4442. var ln = tokens[i].ln;
  4443. throw { line: ln, syntax: 'less' };
  4444. }
  4445. /**
  4446. * @param {Object} exclude
  4447. * @param {Number} i Token's index number
  4448. * @returns {Number}
  4449. */
  4450. function checkExcluding(exclude, i) {
  4451. var start = i;
  4452. while (i < tokensLength) {
  4453. if (exclude[tokens[i++].type]) break;
  4454. }
  4455. return i - start - 2;
  4456. }
  4457. /**
  4458. * @param {Number} start
  4459. * @param {Number} finish
  4460. * @returns {String}
  4461. */
  4462. function joinValues(start, finish) {
  4463. var s = '';
  4464. for (var i = start; i < finish + 1; i++) {
  4465. s += tokens[i].value;
  4466. }
  4467. return s;
  4468. }
  4469. /**
  4470. * @param {Number} start
  4471. * @param {Number} num
  4472. * @returns {String}
  4473. */
  4474. function joinValues2(start, num) {
  4475. if (start + num - 1 >= tokensLength) return;
  4476. var s = '';
  4477. for (var i = 0; i < num; i++) {
  4478. s += tokens[start + i].value;
  4479. }
  4480. return s;
  4481. }
  4482. function getLastPosition(content, line, column, colOffset) {
  4483. return typeof content === 'string' ? getLastPositionForString(content, line, column, colOffset) : getLastPositionForArray(content, line, column, colOffset);
  4484. }
  4485. function getLastPositionForString(content, line, column, colOffset) {
  4486. var position = [];
  4487. if (!content) {
  4488. position = [line, column];
  4489. if (colOffset) position[1] += colOffset - 1;
  4490. return position;
  4491. }
  4492. var lastLinebreak = content.lastIndexOf('\n');
  4493. var endsWithLinebreak = lastLinebreak === content.length - 1;
  4494. var splitContent = content.split('\n');
  4495. var linebreaksCount = splitContent.length - 1;
  4496. var prevLinebreak = linebreaksCount === 0 || linebreaksCount === 1 ? -1 : content.length - splitContent[linebreaksCount - 1].length - 2;
  4497. // Line:
  4498. var offset = endsWithLinebreak ? linebreaksCount - 1 : linebreaksCount;
  4499. position[0] = line + offset;
  4500. // Column:
  4501. if (endsWithLinebreak) {
  4502. offset = prevLinebreak !== -1 ? content.length - prevLinebreak : content.length - 1;
  4503. } else {
  4504. offset = linebreaksCount !== 0 ? content.length - lastLinebreak - column - 1 : content.length - 1;
  4505. }
  4506. position[1] = column + offset;
  4507. if (!colOffset) return position;
  4508. if (endsWithLinebreak) {
  4509. position[0]++;
  4510. position[1] = colOffset;
  4511. } else {
  4512. position[1] += colOffset;
  4513. }
  4514. return position;
  4515. }
  4516. function getLastPositionForArray(content, line, column, colOffset) {
  4517. var position = void 0;
  4518. if (content.length === 0) {
  4519. position = [line, column];
  4520. } else {
  4521. var c = content[content.length - 1];
  4522. if (c.hasOwnProperty('end')) {
  4523. position = [c.end.line, c.end.column];
  4524. } else {
  4525. position = getLastPosition(c.content, line, column);
  4526. }
  4527. }
  4528. if (!colOffset) return position;
  4529. if (tokens[pos - 1] && tokens[pos - 1].type !== 'Newline') {
  4530. position[1] += colOffset;
  4531. } else {
  4532. position[0]++;
  4533. position[1] = 1;
  4534. }
  4535. return position;
  4536. }
  4537. function newNode(type, content, line, column, end) {
  4538. if (!end) end = getLastPosition(content, line, column);
  4539. return new Node({
  4540. type: type,
  4541. content: content,
  4542. start: {
  4543. line: line,
  4544. column: column
  4545. },
  4546. end: {
  4547. line: end[0],
  4548. column: end[1]
  4549. },
  4550. syntax: 'less'
  4551. });
  4552. }
  4553. /**
  4554. * @param {Number} i Token's index number
  4555. * @returns {Number}
  4556. */
  4557. function checkAny(i) {
  4558. var l = void 0;
  4559. if (l = checkBrackets(i)) tokens[i].any_child = 1;else if (l = checkParentheses(i)) tokens[i].any_child = 2;else if (l = checkString(i)) tokens[i].any_child = 3;else if (l = checkVariablesList(i)) tokens[i].any_child = 4;else if (l = checkVariable(i)) tokens[i].any_child = 5;else if (l = checkPercentage(i)) tokens[i].any_child = 6;else if (l = checkDimension(i)) tokens[i].any_child = 7;else if (l = checkUnicodeRange(i)) tokens[i].any_child = 15;else if (l = checkNumber(i)) tokens[i].any_child = 8;else if (l = checkUri(i)) tokens[i].any_child = 9;else if (l = checkExpression(i)) tokens[i].any_child = 10;else if (l = checkFunction(i)) tokens[i].any_child = 11;else if (l = checkIdent(i)) tokens[i].any_child = 12;else if (l = checkClass(i)) tokens[i].any_child = 13;else if (l = checkUnary(i)) tokens[i].any_child = 14;
  4560. return l;
  4561. }
  4562. /**
  4563. * @returns {Array}
  4564. */
  4565. function getAny() {
  4566. var childType = tokens[pos].any_child;
  4567. if (childType === 1) return getBrackets();
  4568. if (childType === 2) return getParentheses();
  4569. if (childType === 3) return getString();
  4570. if (childType === 4) return getVariablesList();
  4571. if (childType === 5) return getVariable();
  4572. if (childType === 6) return getPercentage();
  4573. if (childType === 7) return getDimension();
  4574. if (childType === 15) return getUnicodeRange();
  4575. if (childType === 8) return getNumber();
  4576. if (childType === 9) return getUri();
  4577. if (childType === 10) return getExpression();
  4578. if (childType === 11) return getFunction();
  4579. if (childType === 12) return getIdent();
  4580. if (childType === 13) return getClass();
  4581. if (childType === 14) return getUnary();
  4582. }
  4583. /**
  4584. * Check if token is part of mixin's arguments.
  4585. * @param {Number} i Token's index number
  4586. * @returns {Number}
  4587. */
  4588. function checkArguments(i) {
  4589. var start = i;
  4590. var l = void 0;
  4591. if (i >= tokensLength || tokens[i].type !== TokenType.LeftParenthesis) return 0;
  4592. // Skip `(`.
  4593. i++;
  4594. while (i < tokens[start].right) {
  4595. if (l = checkArgument(i)) i += l;else return 0;
  4596. }
  4597. return tokens[start].right - start + 1;
  4598. }
  4599. /**
  4600. * @returns {Array}
  4601. */
  4602. function getArguments() {
  4603. var type = NodeType.ArgumentsType;
  4604. var token = tokens[pos];
  4605. var line = token.ln;
  4606. var column = token.col;
  4607. var content = [];
  4608. var body = void 0;
  4609. // Skip `(`.
  4610. pos++;
  4611. while (pos < tokensLength && tokens[pos].type !== TokenType.RightParenthesis) {
  4612. if (checkDeclaration(pos)) content.push(getDeclaration());else if (checkArgument(pos)) {
  4613. body = getArgument();
  4614. if (typeof body.content === 'string') content.push(body);else content = content.concat(body);
  4615. } else if (checkClass(pos)) content.push(getClass());else throwError(pos);
  4616. }
  4617. var end = getLastPosition(content, line, column, 1);
  4618. // Skip `)`.
  4619. pos++;
  4620. return newNode(type, content, line, column, end);
  4621. }
  4622. /**
  4623. * Check if token is valid to be part of arguments list.
  4624. * @param {Number} i Token's index number
  4625. * @returns {Number}
  4626. */
  4627. function checkArgument(i) {
  4628. var l = void 0;
  4629. if (l = checkEscapedString(i)) tokens[i].argument_child = 1;else if (l = checkDeclaration(i)) tokens[i].argument_child = 2;else if (l = checkVariablesList(i)) tokens[i].argument_child = 3;else if (l = checkVariable(i)) tokens[i].argument_child = 4;else if (l = checkSC(i)) tokens[i].argument_child = 5;else if (l = checkUnary(i)) tokens[i].argument_child = 6;else if (l = checkOperator(i)) tokens[i].argument_child = 7;else if (l = checkDelim(i)) tokens[i].argument_child = 8;else if (l = checkDeclDelim(i)) tokens[i].argument_child = 9;else if (l = checkString(i)) tokens[i].argument_child = 10;else if (l = checkPercentage(i)) tokens[i].argument_child = 11;else if (l = checkDimension(i)) tokens[i].argument_child = 12;else if (l = checkNumber(i)) tokens[i].argument_child = 13;else if (l = checkUri(i)) tokens[i].argument_child = 14;else if (l = checkFunction(i)) tokens[i].argument_child = 15;else if (l = checkIdent(i)) tokens[i].argument_child = 16;else if (l = checkVhash(i)) tokens[i].argument_child = 17;else if (l = checkBlock(i)) tokens[i].argument_child = 18;else if (l = checkParentheses(i)) tokens[i].argument_child = 19;
  4630. return l;
  4631. }
  4632. /**
  4633. * @returns {Array} Node that is part of arguments list.
  4634. */
  4635. function getArgument() {
  4636. var childType = tokens[pos].argument_child;
  4637. if (childType === 1) return getEscapedString();
  4638. if (childType === 2) return getDeclaration();
  4639. if (childType === 3) return getVariablesList();
  4640. if (childType === 4) return getVariable();
  4641. if (childType === 5) return getSC();
  4642. if (childType === 6) return getUnary();
  4643. if (childType === 7) return getOperator();
  4644. if (childType === 8) return getDelim();
  4645. if (childType === 9) return getDeclDelim();
  4646. if (childType === 10) return getString();
  4647. if (childType === 11) return getPercentage();
  4648. if (childType === 12) return getDimension();
  4649. if (childType === 13) return getNumber();
  4650. if (childType === 14) return getUri();
  4651. if (childType === 15) return getFunction();
  4652. if (childType === 16) return getIdent();
  4653. if (childType === 17) return getVhash();
  4654. if (childType === 18) return getBlock();
  4655. if (childType === 19) return getParentheses();
  4656. }
  4657. /**
  4658. * Check if token is part of an @-word (e.g. `@import`, `@include`)
  4659. * @param {Number} i Token's index number
  4660. * @returns {Number}
  4661. */
  4662. function checkAtkeyword(i) {
  4663. var l = void 0;
  4664. // Check that token is `@`:
  4665. if (i >= tokensLength || tokens[i++].type !== TokenType.CommercialAt) return 0;
  4666. return (l = checkIdent(i)) ? l + 1 : 0;
  4667. }
  4668. /**
  4669. * Get node with @-word
  4670. * @returns {Array} `['atkeyword', ['ident', x]]` where `x` is
  4671. * an identifier without
  4672. * `@` (e.g. `import`, `include`)
  4673. */
  4674. function getAtkeyword() {
  4675. var type = NodeType.AtkeywordType;
  4676. var token = tokens[pos];
  4677. var line = token.ln;
  4678. var column = token.col;
  4679. // Skip `@`.
  4680. pos++;
  4681. var content = [getIdent()];
  4682. return newNode(type, content, line, column);
  4683. }
  4684. /**
  4685. * Check if token is a part of an @-rule
  4686. * @param {Number} i Token's index number
  4687. * @returns {Number} Length of @-rule
  4688. */
  4689. function checkAtrule(i) {
  4690. var l = void 0;
  4691. if (i >= tokensLength) return 0;
  4692. // If token already has a record of being part of an @-rule,
  4693. // return the @-rule's length:
  4694. if (tokens[i].atrule_l !== undefined) return tokens[i].atrule_l;
  4695. // If token is part of an @-rule, save the rule's type to token.
  4696. if (l = checkKeyframesRule(i)) tokens[i].atrule_type = 4;
  4697. // @-rule with ruleset:
  4698. else if (l = checkAtruler(i)) tokens[i].atrule_type = 1;
  4699. // Block @-rule:
  4700. else if (l = checkAtruleb(i)) tokens[i].atrule_type = 2;
  4701. // Single-line @-rule:
  4702. else if (l = checkAtrules(i)) tokens[i].atrule_type = 3;else return 0;
  4703. // If token is part of an @-rule, save the rule's length to token:
  4704. tokens[i].atrule_l = l;
  4705. return l;
  4706. }
  4707. /**
  4708. * Get node with @-rule
  4709. * @returns {Array}
  4710. */
  4711. function getAtrule() {
  4712. var childType = tokens[pos].atrule_type;
  4713. if (childType === 1) return getAtruler(); // @-rule with ruleset
  4714. if (childType === 2) return getAtruleb(); // Block @-rule
  4715. if (childType === 3) return getAtrules(); // Single-line @-rule
  4716. if (childType === 4) return getKeyframesRule();
  4717. }
  4718. /**
  4719. * Check if token is part of a block @-rule
  4720. * @param {Number} i Token's index number
  4721. * @returns {Number} Length of the @-rule
  4722. */
  4723. function checkAtruleb(i) {
  4724. var start = i;
  4725. var l = void 0;
  4726. if (i >= tokensLength) return 0;
  4727. if (l = checkAtkeyword(i)) i += l;else return 0;
  4728. if (l = checkTsets(i)) i += l;
  4729. if (l = checkBlock(i)) i += l;else return 0;
  4730. return i - start;
  4731. }
  4732. /**
  4733. * Get node with a block @-rule
  4734. * @returns {Array} `['atruleb', ['atkeyword', x], y, ['block', z]]`
  4735. */
  4736. function getAtruleb() {
  4737. var type = NodeType.AtruleType;
  4738. var token = tokens[pos];
  4739. var line = token.ln;
  4740. var column = token.col;
  4741. var content = [].concat(getAtkeyword(), getTsets(), getBlock());
  4742. return newNode(type, content, line, column);
  4743. }
  4744. /**
  4745. * Check if token is part of an @-rule with ruleset
  4746. * @param {Number} i Token's index number
  4747. * @returns {Number} Length of the @-rule
  4748. */
  4749. function checkAtruler(i) {
  4750. var start = i;
  4751. var l = void 0;
  4752. if (i >= tokensLength) return 0;
  4753. if (l = checkAtkeyword(i)) i += l;else return 0;
  4754. if (l = checkTsets(i)) i += l;
  4755. if (i < tokensLength && tokens[i].type === TokenType.LeftCurlyBracket) i++;else return 0;
  4756. if (l = checkAtrulers(i)) i += l;
  4757. if (i < tokensLength && tokens[i].type === TokenType.RightCurlyBracket) i++;else return 0;
  4758. return i - start;
  4759. }
  4760. /**
  4761. * Get node with an @-rule with ruleset
  4762. * @returns {Array} ['atruler', ['atkeyword', x], y, z]
  4763. */
  4764. function getAtruler() {
  4765. var type = NodeType.AtruleType;
  4766. var token = tokens[pos];
  4767. var line = token.ln;
  4768. var column = token.col;
  4769. var content = [].concat(getAtkeyword(), getTsets(), getAtrulers());
  4770. return newNode(type, content, line, column);
  4771. }
  4772. /**
  4773. * @param {Number} i Token's index number
  4774. * @returns {Number}
  4775. */
  4776. function checkAtrulers(i) {
  4777. var start = i;
  4778. var l = void 0;
  4779. if (i >= tokensLength) return 0;
  4780. if (l = checkSC(i)) i += l;
  4781. while (i < tokensLength) {
  4782. if (l = checkSC(i)) tokens[i].atrulers_child = 1;else if (l = checkAtrule(i)) tokens[i].atrulers_child = 2;else if (l = checkRuleset(i)) tokens[i].atrulers_child = 3;else break;
  4783. i += l;
  4784. }
  4785. if (i < tokensLength) tokens[i].atrulers_end = 1;
  4786. if (l = checkSC(i)) i += l;
  4787. return i - start;
  4788. }
  4789. /**
  4790. * @returns {Array} `['atrulers', x]`
  4791. */
  4792. function getAtrulers() {
  4793. var type = NodeType.BlockType;
  4794. var token = tokens[pos];
  4795. var line = token.ln;
  4796. var column = token.col;
  4797. var content = [];
  4798. // Skip `{`.
  4799. pos++;
  4800. content = content.concat(getSC());
  4801. while (pos < tokensLength && !tokens[pos].atrulers_end) {
  4802. var childType = tokens[pos].atrulers_child;
  4803. if (childType === 1) content = content.concat(getSC());else if (childType === 2) content.push(getAtrule());else if (childType === 3) content.push(getRuleset());else break;
  4804. }
  4805. content = content.concat(getSC());
  4806. var end = getLastPosition(content, line, column, 1);
  4807. // Skip `}`.
  4808. pos++;
  4809. return newNode(type, content, line, column, end);
  4810. }
  4811. /**
  4812. * @param {Number} i Token's index number
  4813. * @returns {Number}
  4814. */
  4815. function checkAtrules(i) {
  4816. var start = i;
  4817. var l = void 0;
  4818. if (i >= tokensLength) return 0;
  4819. if (l = checkAtkeyword(i)) i += l;else return 0;
  4820. if (l = checkTsets(i)) i += l;
  4821. return i - start;
  4822. }
  4823. /**
  4824. * @returns {Array} `['atrules', ['atkeyword', x], y]`
  4825. */
  4826. function getAtrules() {
  4827. var type = NodeType.AtruleType;
  4828. var token = tokens[pos];
  4829. var line = token.ln;
  4830. var column = token.col;
  4831. var content = [].concat(getAtkeyword(), getTsets());
  4832. return newNode(type, content, line, column);
  4833. }
  4834. /**
  4835. * Check if token is part of a block (e.g. `{...}`).
  4836. * @param {Number} i Token's index number
  4837. * @returns {Number} Length of the block
  4838. */
  4839. function checkBlock(i) {
  4840. return i < tokensLength && tokens[i].type === TokenType.LeftCurlyBracket ? tokens[i].right - i + 1 : 0;
  4841. }
  4842. /**
  4843. * Get node with a block
  4844. * @returns {Array} `['block', x]`
  4845. */
  4846. function getBlock() {
  4847. var type = NodeType.BlockType;
  4848. var token = tokens[pos];
  4849. var line = token.ln;
  4850. var column = token.col;
  4851. var end = tokens[pos].right;
  4852. var content = [];
  4853. // Skip `{`.
  4854. pos++;
  4855. while (pos < end) {
  4856. if (checkBlockdecl(pos)) content = content.concat(getBlockdecl());else throwError(pos);
  4857. }
  4858. var end_ = getLastPosition(content, line, column, 1);
  4859. pos = end + 1;
  4860. return newNode(type, content, line, column, end_);
  4861. }
  4862. /**
  4863. * Check if token is part of a declaration (property-value pair)
  4864. * @param {Number} i Token's index number
  4865. * @returns {Number} Length of the declaration
  4866. */
  4867. function checkBlockdecl(i) {
  4868. var l = void 0;
  4869. if (i >= tokensLength) return 0;
  4870. if (l = checkBlockdecl1(i)) tokens[i].bd_type = 1;else if (l = checkBlockdecl2(i)) tokens[i].bd_type = 2;else if (l = checkBlockdecl3(i)) tokens[i].bd_type = 3;else if (l = checkBlockdecl4(i)) tokens[i].bd_type = 4;else return 0;
  4871. return l;
  4872. }
  4873. /**
  4874. * @returns {Array}
  4875. */
  4876. function getBlockdecl() {
  4877. var childType = tokens[pos].bd_type;
  4878. if (childType === 1) return getBlockdecl1();
  4879. if (childType === 2) return getBlockdecl2();
  4880. if (childType === 3) return getBlockdecl3();
  4881. if (childType === 4) return getBlockdecl4();
  4882. }
  4883. /**
  4884. * @param {Number} i Token's index number
  4885. * @returns {Number}
  4886. */
  4887. function checkBlockdecl1(i) {
  4888. var start = i;
  4889. var l = void 0;
  4890. if (l = checkSC(i)) i += l;
  4891. if (l = checkCondition(i)) tokens[i].bd_kind = 1;else if (l = checkExtend(i)) tokens[i].bd_kind = 6;else if (l = checkRuleset(i)) tokens[i].bd_kind = 2;else if (l = checkDeclaration(i)) tokens[i].bd_kind = 3;else if (l = checkAtrule(i)) tokens[i].bd_kind = 4;else if (l = checkInclude(i)) tokens[i].bd_kind = 5;else return 0;
  4892. i += l;
  4893. if (i < tokensLength && (l = checkDeclDelim(i))) i += l;else return 0;
  4894. if (l = checkSC(i)) i += l;else return 0;
  4895. return i - start;
  4896. }
  4897. /**
  4898. * @returns {Array}
  4899. */
  4900. function getBlockdecl1() {
  4901. var sc = getSC();
  4902. var content = void 0;
  4903. switch (tokens[pos].bd_kind) {
  4904. case 1:
  4905. content = getCondition();
  4906. break;
  4907. case 2:
  4908. content = getRuleset();
  4909. break;
  4910. case 3:
  4911. content = getDeclaration();
  4912. break;
  4913. case 4:
  4914. content = getAtrule();
  4915. break;
  4916. case 5:
  4917. content = getInclude();
  4918. break;
  4919. case 6:
  4920. content = getExtend();
  4921. break;
  4922. }
  4923. return sc.concat(content, getDeclDelim(), getSC());
  4924. }
  4925. /**
  4926. * @param {Number} i Token's index number
  4927. * @returns {Number}
  4928. */
  4929. function checkBlockdecl2(i) {
  4930. var start = i;
  4931. var l = void 0;
  4932. if (l = checkSC(i)) i += l;
  4933. if (l = checkCondition(i)) tokens[i].bd_kind = 1;else if (l = checkExtend(i)) tokens[i].bd_kind = 3;else if (l = checkRuleset(i)) tokens[i].bd_kind = 6;else if (l = checkDeclaration(i)) tokens[i].bd_kind = 4;else if (l = checkAtrule(i)) tokens[i].bd_kind = 5;else if (l = checkInclude(i)) tokens[i].bd_kind = 2;else return 0;
  4934. i += l;
  4935. if (l = checkSC(i)) i += l;
  4936. return i - start;
  4937. }
  4938. /**
  4939. * @returns {Array}
  4940. */
  4941. function getBlockdecl2() {
  4942. var sc = getSC();
  4943. var content = void 0;
  4944. switch (tokens[pos].bd_kind) {
  4945. case 1:
  4946. content = getCondition();
  4947. break;
  4948. case 2:
  4949. content = getInclude();
  4950. break;
  4951. case 3:
  4952. content = getExtend();
  4953. break;
  4954. case 4:
  4955. content = getDeclaration();
  4956. break;
  4957. case 5:
  4958. content = getAtrule();
  4959. break;
  4960. case 6:
  4961. content = getRuleset();
  4962. break;
  4963. }
  4964. return sc.concat(content, getSC());
  4965. }
  4966. /**
  4967. * @param {Number} i Token's index number
  4968. * @returns {Number}
  4969. */
  4970. function checkBlockdecl3(i) {
  4971. var start = i;
  4972. var l = void 0;
  4973. if (l = checkSC(i)) i += l;
  4974. if (l = checkDeclDelim(i)) i += l;else return 0;
  4975. if (l = checkSC(i)) i += l;
  4976. return i - start;
  4977. }
  4978. /**
  4979. * @returns {Array} `[s0, ['declDelim'], s1]` where `s0` and `s1` are
  4980. * are optional whitespaces.
  4981. */
  4982. function getBlockdecl3() {
  4983. return [].concat(getSC(), getDeclDelim(), getSC());
  4984. }
  4985. /**
  4986. * @param {Number} i Token's index number
  4987. * @returns {Number}
  4988. */
  4989. function checkBlockdecl4(i) {
  4990. return checkSC(i);
  4991. }
  4992. /**
  4993. * @returns {Array}
  4994. */
  4995. function getBlockdecl4() {
  4996. return getSC();
  4997. }
  4998. /**
  4999. * Check if token is part of text inside square brackets, e.g. `[1]`
  5000. * @param {Number} i Token's index number
  5001. * @returns {Number}
  5002. */
  5003. function checkBrackets(i) {
  5004. if (i >= tokensLength) return 0;
  5005. var start = i;
  5006. // Skip `[`.
  5007. if (tokens[i].type === TokenType.LeftSquareBracket) i++;else return 0;
  5008. if (i < tokens[start].right) {
  5009. var l = checkTsets(i);
  5010. if (l) i += l;else return 0;
  5011. }
  5012. // Skip `]`.
  5013. i++;
  5014. return i - start;
  5015. }
  5016. /**
  5017. * Get node with text inside square brackets, e.g. `[1]`
  5018. * @returns {Node}
  5019. */
  5020. function getBrackets() {
  5021. var type = NodeType.BracketsType;
  5022. var token = tokens[pos];
  5023. var line = token.ln;
  5024. var column = token.col;
  5025. var right = token.right;
  5026. var content = [];
  5027. // Skip `[`.
  5028. pos++;
  5029. if (pos < right) {
  5030. content = getTsets();
  5031. }
  5032. var end = getLastPosition(content, line, column, 1);
  5033. // Skip `]`.
  5034. pos++;
  5035. return newNode(type, content, line, column, end);
  5036. }
  5037. /**
  5038. * Check if token is part of a class selector (e.g. `.abc`)
  5039. * @param {Number} i Token's index number
  5040. * @returns {Number} Length of the class selector
  5041. */
  5042. function checkClass(i) {
  5043. var l = void 0;
  5044. if (i >= tokensLength) return 0;
  5045. if (tokens[i].class_l) return tokens[i].class_l;
  5046. if (tokens[i++].type === TokenType.FullStop) {
  5047. if (l = checkInterpolatedVariable(i)) tokens[i].class_child = 1;else if (l = checkIdent(i)) tokens[i].class_child = 2;else return 0;
  5048. tokens[i].class_l = l + 1;
  5049. return l + 1;
  5050. }
  5051. return 0;
  5052. }
  5053. /**
  5054. * Get node with a class selector
  5055. * @returns {Array} `['class', ['ident', x]]` where x is a class's
  5056. * identifier (without `.`, e.g. `abc`).
  5057. */
  5058. function getClass() {
  5059. var type = NodeType.ClassType;
  5060. var token = tokens[pos];
  5061. var line = token.ln;
  5062. var column = token.col;
  5063. var content = [];
  5064. // Skip `.`
  5065. pos++;
  5066. var childType = tokens[pos].class_child;
  5067. if (childType === 1) content.push(getInterpolatedVariable());else content.push(getIdent());
  5068. return newNode(type, content, line, column);
  5069. }
  5070. function checkCombinator(i) {
  5071. if (i >= tokensLength) return 0;
  5072. var l = void 0;
  5073. if (l = checkCombinator1(i)) tokens[i].combinatorType = 1;else if (l = checkCombinator2(i)) tokens[i].combinatorType = 2;else if (l = checkCombinator3(i)) tokens[i].combinatorType = 3;else if (l = checkCombinator4(i)) tokens[i].combinatorType = 4;
  5074. return l;
  5075. }
  5076. function getCombinator() {
  5077. var type = tokens[pos].combinatorType;
  5078. if (type === 1) return getCombinator1();
  5079. if (type === 2) return getCombinator2();
  5080. if (type === 3) return getCombinator3();
  5081. if (type === 4) return getCombinator4();
  5082. }
  5083. /**
  5084. * (1) `>>>`
  5085. *
  5086. * @param {Number} i
  5087. * @return {Number}
  5088. */
  5089. function checkCombinator1(i) {
  5090. if (i < tokensLength && tokens[i++].type === TokenType.GreaterThanSign && i < tokensLength && tokens[i++].type === TokenType.GreaterThanSign && i < tokensLength && tokens[i++].type === TokenType.GreaterThanSign) return 3;
  5091. return 0;
  5092. }
  5093. /**
  5094. * @return {Node}
  5095. */
  5096. function getCombinator1() {
  5097. var type = NodeType.CombinatorType;
  5098. var token = tokens[pos];
  5099. var line = token.ln;
  5100. var column = token.col;
  5101. var content = '>>>';
  5102. // Skip combinator
  5103. pos += 3;
  5104. return newNode(type, content, line, column);
  5105. }
  5106. /**
  5107. * (1) `||`
  5108. * (2) `>>`
  5109. *
  5110. * @param {Number} i
  5111. * @return {Number}
  5112. */
  5113. function checkCombinator2(i) {
  5114. if (i + 1 >= tokensLength) return 0;
  5115. if (tokens[i].type === TokenType.VerticalLine && tokens[i + 1].type === TokenType.VerticalLine) return 2;
  5116. if (tokens[i].type === TokenType.GreaterThanSign && tokens[i + 1].type === TokenType.GreaterThanSign) return 2;
  5117. return 0;
  5118. }
  5119. /**
  5120. * @return {Node}
  5121. */
  5122. function getCombinator2() {
  5123. var type = NodeType.CombinatorType;
  5124. var token = tokens[pos];
  5125. var line = token.ln;
  5126. var column = token.col;
  5127. var content = '' + token.value + tokens[pos + 1].value;
  5128. // Skip combinator
  5129. pos += 2;
  5130. return newNode(type, content, line, column);
  5131. }
  5132. /**
  5133. * (1) `>`
  5134. * (2) `+`
  5135. * (3) `~`
  5136. *
  5137. * @param {Number} i
  5138. * @return {Number}
  5139. */
  5140. function checkCombinator3(i) {
  5141. var type = tokens[i].type;
  5142. if (type === TokenType.PlusSign || type === TokenType.GreaterThanSign || type === TokenType.Tilde) return 1;else return 0;
  5143. }
  5144. /**
  5145. * @return {Node}
  5146. */
  5147. function getCombinator3() {
  5148. var type = NodeType.CombinatorType;
  5149. var token = tokens[pos];
  5150. var line = token.ln;
  5151. var column = token.col;
  5152. var content = token.value;
  5153. // Skip combinator
  5154. pos++;
  5155. return newNode(type, content, line, column);
  5156. }
  5157. /**
  5158. * (1) `/panda/`
  5159. */
  5160. function checkCombinator4(i) {
  5161. var start = i;
  5162. if (tokens[i].type === TokenType.Solidus) i++;else return 0;
  5163. var l = void 0;
  5164. if (l = checkIdent(i)) i += l;else return 0;
  5165. if (tokens[i].type === TokenType.Solidus) i++;else return 0;
  5166. return i - start;
  5167. }
  5168. /**
  5169. * @return {Node}
  5170. */
  5171. function getCombinator4() {
  5172. var type = NodeType.CombinatorType;
  5173. var token = tokens[pos];
  5174. var line = token.ln;
  5175. var column = token.col;
  5176. // Skip `/`.
  5177. pos++;
  5178. var ident = getIdent();
  5179. // Skip `/`.
  5180. pos++;
  5181. var content = '/' + ident.content + '/';
  5182. return newNode(type, content, line, column);
  5183. }
  5184. /**
  5185. * Check if token is a multiline comment.
  5186. * @param {Number} i Token's index number
  5187. * @returns {Number} `1` if token is a multiline comment, otherwise `0`
  5188. */
  5189. function checkCommentML(i) {
  5190. return i < tokensLength && tokens[i].type === TokenType.CommentML ? 1 : 0;
  5191. }
  5192. /**
  5193. * Get node with a multiline comment
  5194. * @returns {Array} `['commentML', x]` where `x`
  5195. * is the comment's text (without `/*` and `* /`).
  5196. */
  5197. function getCommentML() {
  5198. var type = NodeType.CommentMLType;
  5199. var token = tokens[pos];
  5200. var line = token.ln;
  5201. var column = token.col;
  5202. var content = tokens[pos].value.substring(2);
  5203. var l = content.length;
  5204. if (content.charAt(l - 2) === '*' && content.charAt(l - 1) === '/') content = content.substring(0, l - 2);
  5205. var end = getLastPosition(content, line, column, 2);
  5206. if (end[0] === line) end[1] += 2;
  5207. pos++;
  5208. return newNode(type, content, line, column, end);
  5209. }
  5210. /**
  5211. * Check if token is part of a single-line comment.
  5212. * @param {Number} i Token's index number
  5213. * @returns {Number} `1` if token is a single-line comment, otherwise `0`
  5214. */
  5215. function checkCommentSL(i) {
  5216. return i < tokensLength && tokens[i].type === TokenType.CommentSL ? 1 : 0;
  5217. }
  5218. /**
  5219. * Get node with a single-line comment.
  5220. * @returns {Array}
  5221. */
  5222. function getCommentSL() {
  5223. var type = NodeType.CommentSLType;
  5224. var token = tokens[pos];
  5225. var line = token.ln;
  5226. var column = token.col;
  5227. var content = tokens[pos++].value.substring(2);
  5228. var end = getLastPosition(content, line, column + 2);
  5229. return newNode(type, content, line, column, end);
  5230. }
  5231. /**
  5232. * Check if token is part of a condition.
  5233. * @param {Number} i Token's index number
  5234. * @return {Number} Length of the condition
  5235. */
  5236. function checkCondition(i) {
  5237. var start = i;
  5238. var l = void 0;
  5239. if (i >= tokensLength) return 0;
  5240. if ((l = checkIdent(i)) && tokens[i].value === 'when') i += l;else return 0;
  5241. while (i < tokensLength) {
  5242. if (l = checkBlock(i)) {
  5243. tokens[i].condition_child = 0;
  5244. break;
  5245. } else if (l = checkFunction(i)) tokens[i].condition_child = 1;else if (l = checkBrackets(i)) tokens[i].condition_child = 2;else if (l = checkParentheses(i)) tokens[i].condition_child = 3;else if (l = checkVariable(i)) tokens[i].condition_child = 4;else if (l = checkIdent(i)) tokens[i].condition_child = 5;else if (l = checkNumber(i)) tokens[i].condition_child = 6;else if (l = checkDelim(i)) tokens[i].condition_child = 7;else if (l = checkOperator(i)) tokens[i].condition_child = 8;else if (l = checkCombinator(i)) tokens[i].condition_child = 9;else if (l = checkSC(i)) tokens[i].condition_child = 10;else if (l = checkString(i)) tokens[i].condition_child = 11;else return 0;
  5246. i += l;
  5247. }
  5248. return i - start;
  5249. }
  5250. /**
  5251. * Get node with a condition.
  5252. * @returns {Array} `['condition', x]`
  5253. */
  5254. function getCondition() {
  5255. var type = NodeType.ConditionType;
  5256. var token = tokens[pos];
  5257. var line = token.ln;
  5258. var column = token.col;
  5259. var content = [];
  5260. content.push(getIdent());
  5261. while (pos < tokensLength) {
  5262. var childType = tokens[pos].condition_child;
  5263. if (childType === 0) break;else if (childType === 1) content.push(getFunction());else if (childType === 2) content.push(getBrackets());else if (childType === 3) content.push(getParentheses());else if (childType === 4) content.push(getVariable());else if (childType === 5) content.push(getIdent());else if (childType === 6) content.push(getNumber());else if (childType === 7) content.push(getDelim());else if (childType === 8) content.push(getOperator());else if (childType === 9) content.push(getCombinator());else if (childType === 10) content = content.concat(getSC());else if (childType === 11) content.push(getString());
  5264. }
  5265. return newNode(type, content, line, column);
  5266. }
  5267. /**
  5268. * Check if token is part of a declaration (property-value pair)
  5269. * @param {Number} i Token's index number
  5270. * @returns {Number} Length of the declaration
  5271. */
  5272. function checkDeclaration(i) {
  5273. var start = i;
  5274. var l = void 0;
  5275. if (i >= tokensLength) return 0;
  5276. if (l = checkProperty(i)) i += l;else return 0;
  5277. if (l = checkSC(i)) i += l;
  5278. if (l = checkPropertyDelim(i)) i++;else return 0;
  5279. if (l = checkSC(i)) i += l;
  5280. if (l = checkValue(i)) i += l;else return 0;
  5281. return i - start;
  5282. }
  5283. /**
  5284. * Get node with a declaration
  5285. * @returns {Array} `['declaration', ['property', x], ['propertyDelim'],
  5286. * ['value', y]]`
  5287. */
  5288. function getDeclaration() {
  5289. var type = NodeType.DeclarationType;
  5290. var token = tokens[pos];
  5291. var line = token.ln;
  5292. var column = token.col;
  5293. var content = [].concat(getProperty(), getSC(), getPropertyDelim(), getSC(), getValue());
  5294. return newNode(type, content, line, column);
  5295. }
  5296. /**
  5297. * Check if token is a semicolon
  5298. * @param {Number} i Token's index number
  5299. * @returns {Number} `1` if token is a semicolon, otherwise `0`
  5300. */
  5301. function checkDeclDelim(i) {
  5302. return i < tokensLength && tokens[i].type === TokenType.Semicolon ? 1 : 0;
  5303. }
  5304. /**
  5305. * Get node with a semicolon
  5306. * @returns {Array} `['declDelim']`
  5307. */
  5308. function getDeclDelim() {
  5309. var type = NodeType.DeclDelimType;
  5310. var token = tokens[pos];
  5311. var line = token.ln;
  5312. var column = token.col;
  5313. var content = ';';
  5314. pos++;
  5315. return newNode(type, content, line, column);
  5316. }
  5317. /**
  5318. * Check if token is a comma
  5319. * @param {Number} i Token's index number
  5320. * @returns {Number} `1` if token is a comma, otherwise `0`
  5321. */
  5322. function checkDelim(i) {
  5323. return i < tokensLength && tokens[i].type === TokenType.Comma ? 1 : 0;
  5324. }
  5325. /**
  5326. * Get node with a comma
  5327. * @returns {Array} `['delim']`
  5328. */
  5329. function getDelim() {
  5330. var type = NodeType.DelimType;
  5331. var token = tokens[pos];
  5332. var line = token.ln;
  5333. var column = token.col;
  5334. var content = ',';
  5335. pos++;
  5336. return newNode(type, content, line, column);
  5337. }
  5338. /**
  5339. * Check if token is part of a number with dimension unit (e.g. `10px`)
  5340. * @param {Number} i Token's index number
  5341. * @returns {Number}
  5342. */
  5343. function checkDimension(i) {
  5344. var ln = checkNumber(i);
  5345. var li = void 0;
  5346. if (i >= tokensLength || !ln || i + ln >= tokensLength) return 0;
  5347. return (li = checkUnit(i + ln)) ? ln + li : 0;
  5348. }
  5349. /**
  5350. * Get node of a number with dimension unit
  5351. * @return {Node}
  5352. */
  5353. function getDimension() {
  5354. var type = NodeType.DimensionType;
  5355. var token = tokens[pos];
  5356. var line = token.ln;
  5357. var column = token.col;
  5358. var content = [getNumber(), getUnit()];
  5359. return newNode(type, content, line, column);
  5360. }
  5361. /**
  5362. * Check if token is part of an escaped string (e.g. `~"ms:something"`).
  5363. * @param {Number} i Token's index number
  5364. * @returns {Number} Length of the string (including `~` and quotes)
  5365. */
  5366. function checkEscapedString(i) {
  5367. var start = i;
  5368. var l = void 0;
  5369. if (i >= tokensLength) return 0;
  5370. if (tokens[i].type === TokenType.Tilde && (l = checkString(i + 1))) return i + l - start;else return 0;
  5371. }
  5372. /**
  5373. * Get node with an escaped string
  5374. * @returns {Array} `['escapedString', ['string', x]]` where `x` is a string
  5375. * without `~` but with quotes
  5376. */
  5377. function getEscapedString() {
  5378. var type = NodeType.EscapedStringType;
  5379. var token = tokens[pos];
  5380. var line = token.ln;
  5381. var column = token.col;
  5382. pos++;
  5383. var content = tokens[pos].value;
  5384. var end = getLastPosition(content, line, column + 1);
  5385. pos++;
  5386. return newNode(type, content, line, column, end);
  5387. }
  5388. /**
  5389. * @param {Number} i Token's index number
  5390. * @returns {Number}
  5391. */
  5392. function checkExpression(i) {
  5393. var start = i;
  5394. if (i >= tokensLength || tokens[i++].value !== 'expression' || i >= tokensLength || tokens[i].type !== TokenType.LeftParenthesis) {
  5395. return 0;
  5396. }
  5397. return tokens[i].right - start + 1;
  5398. }
  5399. /**
  5400. * @returns {Array}
  5401. */
  5402. function getExpression() {
  5403. var type = NodeType.ExpressionType;
  5404. var token = tokens[pos];
  5405. var line = token.ln;
  5406. var column = token.col;
  5407. pos++;
  5408. var content = joinValues(pos + 1, tokens[pos].right - 1);
  5409. var end = getLastPosition(content, line, column, 1);
  5410. if (end[0] === line) end[1] += 11;
  5411. pos = tokens[pos].right + 1;
  5412. return newNode(type, content, line, column, end);
  5413. }
  5414. function checkExtend(i) {
  5415. if (i >= tokensLength) return 0;
  5416. var l = void 0;
  5417. if (l = checkExtend1(i)) tokens[i].extendType = 1;else if (l = checkExtend2(i)) tokens[i].extendType = 2;else return 0;
  5418. return l;
  5419. }
  5420. function getExtend() {
  5421. var childType = tokens[pos].extendType;
  5422. if (childType === 1) return getExtend1();
  5423. if (childType === 2) return getExtend2();
  5424. }
  5425. /**
  5426. * (1) `selector:extend(selector) {...}`
  5427. */
  5428. function checkExtend1(i) {
  5429. var start = i;
  5430. var l = void 0;
  5431. if (i >= tokensLength) return 0;
  5432. if (l = checkExtendSelector(i)) i += l;else return 0;
  5433. if (tokens[i + 1] && tokens[i + 1].value === 'extend' && (l = checkPseudoc(i))) i += l;else return 0;
  5434. if (l = checkSC(i)) i += l;
  5435. if (l = checkBlock(i)) i += l;else return 0;
  5436. return i - start;
  5437. }
  5438. function getExtend1() {
  5439. var type = NodeType.ExtendType;
  5440. var token = tokens[pos];
  5441. var line = token.ln;
  5442. var column = token.col;
  5443. var content = [].concat(getExtendSelector(), getPseudoc(), getSC(), getBlock());
  5444. return newNode(type, content, line, column);
  5445. }
  5446. /**
  5447. * (1) `selector:extend(selector)`
  5448. */
  5449. function checkExtend2(i) {
  5450. var start = i;
  5451. var l = void 0;
  5452. if (i >= tokensLength) return 0;
  5453. if (l = checkExtendSelector(i)) i += l;else return 0;
  5454. if (tokens[i + 1] && tokens[i + 1].value === 'extend' && (l = checkPseudoc(i))) i += l;else return 0;
  5455. return i - start;
  5456. }
  5457. function getExtend2() {
  5458. var type = NodeType.ExtendType;
  5459. var token = tokens[pos];
  5460. var line = token.ln;
  5461. var column = token.col;
  5462. var content = [].concat(getExtendSelector(), getPseudoc());
  5463. return newNode(type, content, line, column);
  5464. }
  5465. function checkExtendSelector(i) {
  5466. var l = void 0;
  5467. if (l = checkParentSelectorWithExtension(i)) tokens[i].extend_type = 1;else if (l = checkIdent(i)) tokens[i].extend_type = 2;else if (l = checkClass(i)) tokens[i].extend_type = 3;else if (l = checkShash(i)) tokens[i].extend_type = 4;
  5468. return l;
  5469. }
  5470. function getExtendSelector() {
  5471. var childType = tokens[pos].extend_type;
  5472. if (childType === 1) return getParentSelectorWithExtension();
  5473. if (childType === 2) return [getIdent()];
  5474. if (childType === 3) return [getClass()];
  5475. if (childType === 4) return [getShash()];
  5476. }
  5477. /**
  5478. * @param {Number} i Token's index number
  5479. * @returns {Number}
  5480. */
  5481. function checkFunction(i) {
  5482. var start = i;
  5483. var l = void 0;
  5484. if (i >= tokensLength) return 0;
  5485. if (l = checkIdent(i)) i += l;else return 0;
  5486. return i < tokensLength && tokens[i].type === TokenType.LeftParenthesis ? tokens[i].right - start + 1 : 0;
  5487. }
  5488. /**
  5489. * @returns {Array}
  5490. */
  5491. function getFunction() {
  5492. var type = NodeType.FunctionType;
  5493. var token = tokens[pos];
  5494. var line = token.ln;
  5495. var column = token.col;
  5496. var content = [].concat(getIdent(), getArguments());
  5497. return newNode(type, content, line, column);
  5498. }
  5499. /**
  5500. * Check if token is part of an identifier
  5501. * @param {Number} i Token's index number
  5502. * @returns {Number} Length of the identifier
  5503. */
  5504. function checkIdent(i) {
  5505. var start = i;
  5506. if (i >= tokensLength) return 0;
  5507. if (tokens[i].type === TokenType.HyphenMinus) i++;
  5508. if (tokens[i].type === TokenType.LowLine || tokens[i].type === TokenType.Identifier) i++;else return 0;
  5509. for (; i < tokensLength; i++) {
  5510. if (tokens[i].type !== TokenType.HyphenMinus && tokens[i].type !== TokenType.LowLine && tokens[i].type !== TokenType.Identifier && tokens[i].type !== TokenType.DecimalNumber) break;
  5511. }
  5512. tokens[start].ident_last = i - 1;
  5513. return i - start;
  5514. }
  5515. /**
  5516. * Get node with an identifier
  5517. * @returns {Array} `['ident', x]` where `x` is identifier's name
  5518. */
  5519. function getIdent() {
  5520. var type = NodeType.IdentType;
  5521. var token = tokens[pos];
  5522. var line = token.ln;
  5523. var column = token.col;
  5524. var content = joinValues(pos, tokens[pos].ident_last);
  5525. pos = tokens[pos].ident_last + 1;
  5526. return newNode(type, content, line, column);
  5527. }
  5528. /**
  5529. * @param {number} i Token's index number
  5530. * @returns {number} Length of the identifier
  5531. */
  5532. function checkPartialIdent(i) {
  5533. var start = i;
  5534. if (i >= tokensLength) return 0;
  5535. for (; i < tokensLength; i++) {
  5536. if (tokens[i].type !== TokenType.HyphenMinus && tokens[i].type !== TokenType.LowLine && tokens[i].type !== TokenType.Identifier && tokens[i].type !== TokenType.DecimalNumber) break;
  5537. }
  5538. tokens[start].ident_last = i - 1;
  5539. return i - start;
  5540. }
  5541. /**
  5542. * Check if token is part of `!important` word
  5543. * @param {Number} i Token's index number
  5544. * @returns {Number}
  5545. */
  5546. function checkImportant(i) {
  5547. var start = i;
  5548. var l = void 0;
  5549. if (i >= tokensLength || tokens[i++].type !== TokenType.ExclamationMark) return 0;
  5550. if (l = checkSC(i)) i += l;
  5551. if (tokens[i].value === 'important') {
  5552. tokens[start].importantEnd = i;
  5553. return i - start + 1;
  5554. } else {
  5555. return 0;
  5556. }
  5557. }
  5558. /**
  5559. * Get node with `!important` word
  5560. * @returns {Array} `['important', sc]` where `sc` is optional whitespace
  5561. */
  5562. function getImportant() {
  5563. var token = tokens[pos];
  5564. var line = token.ln;
  5565. var column = token.col;
  5566. var content = joinValues(pos, token.importantEnd);
  5567. pos = token.importantEnd + 1;
  5568. return newNode(NodeType.ImportantType, content, line, column);
  5569. }
  5570. /**
  5571. * Check if token is part of an include (`@include` or `@extend` directive).
  5572. * @param {Number} i Token's index number
  5573. * @returns {Number}
  5574. */
  5575. function checkInclude(i) {
  5576. var l = void 0;
  5577. if (i >= tokensLength) return 0;
  5578. if (l = checkInclude1(i)) tokens[i].include_type = 1;else if (l = checkInclude2(i)) tokens[i].include_type = 2;
  5579. return l;
  5580. }
  5581. /**
  5582. * Get node with included mixin
  5583. * @returns {Array} `['include', x]`
  5584. */
  5585. function getInclude() {
  5586. var type = tokens[pos].include_type;
  5587. if (type === 1) return getInclude1();
  5588. if (type === 2) return getInclude2();
  5589. }
  5590. /**
  5591. * @param {Number} i Token's index number
  5592. * @returns {Number}
  5593. */
  5594. function checkInclude1(i) {
  5595. var start = i;
  5596. var l = void 0;
  5597. if (l = checkClass(i) || checkShash(i)) i += l;else return 0;
  5598. while (i < tokensLength) {
  5599. if (l = checkClass(i) || checkShash(i) || checkSC(i)) i += l;else if (tokens[i].type === TokenType.GreaterThanSign) i++;else break;
  5600. }
  5601. if (l = checkArguments(i)) i += l;else return 0;
  5602. if (i < tokensLength && (l = checkSC(i))) i += l;
  5603. if (i < tokensLength && (l = checkImportant(i))) i += l;
  5604. return i - start;
  5605. }
  5606. /**
  5607. * @returns {Array} `['include', x]`
  5608. */
  5609. function getInclude1() {
  5610. var type = NodeType.IncludeType;
  5611. var token = tokens[pos];
  5612. var line = token.ln;
  5613. var column = token.col;
  5614. var content = [];
  5615. content.push(checkClass(pos) ? getClass() : getShash());
  5616. while (pos < tokensLength) {
  5617. if (checkClass(pos)) content.push(getClass());else if (checkShash(pos)) content.push(getShash());else if (checkSC(pos)) content = content.concat(getSC());else if (checkOperator(pos)) content.push(getOperator());else break;
  5618. }
  5619. content.push(getArguments());
  5620. content = content.concat(getSC());
  5621. if (checkImportant(pos)) content.push(getImportant());
  5622. return newNode(type, content, line, column);
  5623. }
  5624. /**
  5625. * @param {Number} i Token's index number
  5626. * @returns {Number}
  5627. */
  5628. function checkInclude2(i) {
  5629. var start = i;
  5630. var l = void 0;
  5631. if (l = checkClass(i) || checkShash(i)) i += l;else return 0;
  5632. while (i < tokensLength) {
  5633. if (l = checkClass(i) || checkShash(i) || checkSC(i)) i += l;else if (tokens[i].type === TokenType.GreaterThanSign) i++;else break;
  5634. }
  5635. return i - start;
  5636. }
  5637. /**
  5638. * @returns {Array} `['include', x]`
  5639. */
  5640. function getInclude2() {
  5641. var type = NodeType.IncludeType;
  5642. var token = tokens[pos];
  5643. var line = token.ln;
  5644. var column = token.col;
  5645. var content = [];
  5646. content.push(checkClass(pos) ? getClass() : getShash());
  5647. while (pos < tokensLength) {
  5648. if (checkClass(pos)) content.push(getClass());else if (checkShash(pos)) content.push(getShash());else if (checkSC(pos)) content = content.concat(getSC());else if (checkOperator(pos)) content.push(getOperator());else break;
  5649. }
  5650. return newNode(type, content, line, column);
  5651. }
  5652. /**
  5653. * Check if token is part of LESS interpolated variable
  5654. * @param {Number} i Token's index number
  5655. * @returns {Number}
  5656. */
  5657. function checkInterpolatedVariable(i) {
  5658. var start = i;
  5659. var l = void 0;
  5660. if (i >= tokensLength) return 0;
  5661. if (tokens[i].type !== TokenType.CommercialAt || !tokens[i + 1] || tokens[i + 1].type !== TokenType.LeftCurlyBracket) {
  5662. return 0;
  5663. }
  5664. i += 2;
  5665. if (l = checkIdent(i)) i += l;else return 0;
  5666. return tokens[i].type === TokenType.RightCurlyBracket ? i - start + 1 : 0;
  5667. }
  5668. /**
  5669. * Get node with LESS interpolated variable
  5670. * @returns {Array} `['interpolatedVariable', x]`
  5671. */
  5672. function getInterpolatedVariable() {
  5673. var type = NodeType.InterpolatedVariableType;
  5674. var token = tokens[pos];
  5675. var line = token.ln;
  5676. var column = token.col;
  5677. var content = [];
  5678. // Skip `@{`:
  5679. pos += 2;
  5680. content.push(getIdent());
  5681. var end = getLastPosition(content, line, column, 1);
  5682. // Skip `}`:
  5683. pos++;
  5684. return newNode(type, content, line, column, end);
  5685. }
  5686. function checkKeyframesBlock(i) {
  5687. var start = i;
  5688. var l = void 0;
  5689. if (i >= tokensLength) return 0;
  5690. if (l = checkKeyframesSelector(i)) i += l;else return 0;
  5691. if (l = checkSC(i)) i += l;
  5692. if (l = checkBlock(i)) i += l;else return 0;
  5693. return i - start;
  5694. }
  5695. function getKeyframesBlock() {
  5696. var type = NodeType.RulesetType;
  5697. var token = tokens[pos];
  5698. var line = token.ln;
  5699. var column = token.col;
  5700. var content = [].concat(getKeyframesSelector(), getSC(), getBlock());
  5701. return newNode(type, content, line, column);
  5702. }
  5703. function checkKeyframesBlocks(i) {
  5704. var start = i;
  5705. var l = void 0;
  5706. if (i < tokensLength && tokens[i].type === TokenType.LeftCurlyBracket) i++;else return 0;
  5707. if (l = checkSC(i)) i += l;
  5708. if (l = checkKeyframesBlock(i)) i += l;else return 0;
  5709. while (tokens[i].type !== TokenType.RightCurlyBracket) {
  5710. if (l = checkSC(i)) i += l;else if (l = checkKeyframesBlock(i)) i += l;else break;
  5711. }
  5712. if (i < tokensLength && tokens[i].type === TokenType.RightCurlyBracket) i++;else return 0;
  5713. return i - start;
  5714. }
  5715. function getKeyframesBlocks() {
  5716. var type = NodeType.BlockType;
  5717. var token = tokens[pos];
  5718. var line = token.ln;
  5719. var column = token.col;
  5720. var keyframesBlocksEnd = token.right;
  5721. var content = [];
  5722. // Skip `{`.
  5723. pos++;
  5724. while (pos < keyframesBlocksEnd) {
  5725. if (checkSC(pos)) content = content.concat(getSC());else if (checkKeyframesBlock(pos)) content.push(getKeyframesBlock());
  5726. }
  5727. var end = getLastPosition(content, line, column, 1);
  5728. // Skip `}`.
  5729. pos++;
  5730. return newNode(type, content, line, column, end);
  5731. }
  5732. /**
  5733. * Check if token is part of a @keyframes rule.
  5734. * @param {Number} i Token's index number
  5735. * @return {Number} Length of the @keyframes rule
  5736. */
  5737. function checkKeyframesRule(i) {
  5738. var start = i;
  5739. var l = void 0;
  5740. if (i >= tokensLength) return 0;
  5741. if (l = checkAtkeyword(i)) i += l;else return 0;
  5742. var atruleName = joinValues2(i - l, l);
  5743. if (atruleName.toLowerCase().indexOf('keyframes') === -1) return 0;
  5744. if (l = checkSC(i)) i += l;else return 0;
  5745. if (l = checkIdent(i)) i += l;else return 0;
  5746. if (l = checkSC(i)) i += l;
  5747. if (l = checkKeyframesBlocks(i)) i += l;else return 0;
  5748. return i - start;
  5749. }
  5750. /**
  5751. * @return {Node}
  5752. */
  5753. function getKeyframesRule() {
  5754. var type = NodeType.AtruleType;
  5755. var token = tokens[pos];
  5756. var line = token.ln;
  5757. var column = token.col;
  5758. var content = [].concat(getAtkeyword(), getSC(), getIdent(), getSC(), getKeyframesBlocks());
  5759. return newNode(type, content, line, column);
  5760. }
  5761. function checkKeyframesSelector(i) {
  5762. var start = i;
  5763. var l = void 0;
  5764. if (i >= tokensLength) return 0;
  5765. if (l = checkIdent(i)) {
  5766. // Valid selectors are only `from` and `to`.
  5767. var selector = joinValues2(i, l);
  5768. if (selector !== 'from' && selector !== 'to') return 0;
  5769. i += l;
  5770. tokens[start].keyframesSelectorType = 1;
  5771. } else if (l = checkPercentage(i)) {
  5772. i += l;
  5773. tokens[start].keyframesSelectorType = 2;
  5774. } else {
  5775. return 0;
  5776. }
  5777. return i - start;
  5778. }
  5779. function getKeyframesSelector() {
  5780. var keyframesSelectorType = NodeType.KeyframesSelectorType;
  5781. var selectorType = NodeType.SelectorType;
  5782. var token = tokens[pos];
  5783. var line = token.ln;
  5784. var column = token.col;
  5785. var content = [];
  5786. if (token.keyframesSelectorType === 1) {
  5787. content.push(getIdent());
  5788. } else {
  5789. content.push(getPercentage());
  5790. }
  5791. var keyframesSelector = newNode(keyframesSelectorType, content, line, column);
  5792. return newNode(selectorType, [keyframesSelector], line, column);
  5793. }
  5794. /**
  5795. * Check if token is part of a LESS mixin
  5796. * @param {Number} i Token's index number
  5797. * @returns {Number} Length of the mixin
  5798. */
  5799. function checkMixin(i) {
  5800. var l = void 0;
  5801. if (i >= tokensLength) return 0;
  5802. if (l = checkMixin1(i)) tokens[i].mixin_type = 1;else if (l = checkMixin2(i)) tokens[i].mixin_type = 2;else return 0;
  5803. return l;
  5804. }
  5805. /**
  5806. * @returns {Array}
  5807. */
  5808. function getMixin() {
  5809. var type = tokens[pos].mixin_type;
  5810. if (type === 1) return getMixin1();
  5811. if (type === 2) return getMixin2();
  5812. }
  5813. function checkMixin1(i) {
  5814. var start = i;
  5815. var l = void 0;
  5816. if (i >= tokensLength) return 0;
  5817. if (l = checkClass(i) || checkShash(i)) i += l;else return 0;
  5818. if (l = checkSC(i)) i += l;
  5819. if (l = checkArguments(i)) i += l;
  5820. if (l = checkSC(i)) i += l;
  5821. if (l = checkBlock(i)) i += l;else return 0;
  5822. return i - start;
  5823. }
  5824. /**
  5825. * Get node with a mixin
  5826. * @returns {Array} `['mixin', x]`
  5827. */
  5828. function getMixin1() {
  5829. var type = NodeType.MixinType;
  5830. var token = tokens[pos];
  5831. var line = token.ln;
  5832. var column = token.col;
  5833. var content = [];
  5834. content.push(checkClass(pos) ? getClass() : getShash());
  5835. content = content.concat(getSC());
  5836. if (checkArguments(pos)) content.push(getArguments());
  5837. content = content.concat(getSC());
  5838. if (checkBlock(pos)) content.push(getBlock());
  5839. return newNode(type, content, line, column);
  5840. }
  5841. /**
  5842. * Check if token is part of a LESS mixin
  5843. * @param {Number} i Token's index number
  5844. * @returns {Number} Length of the mixin
  5845. */
  5846. function checkMixin2(i) {
  5847. var start = i;
  5848. var l = void 0;
  5849. if (i >= tokensLength) return 0;
  5850. if (l = checkClass(i) || checkShash(i)) i += l;else return 0;
  5851. if (l = checkSC(i)) i += l;
  5852. if (l = checkArguments(i)) i += l;
  5853. return i - start;
  5854. }
  5855. /**
  5856. * Get node with a mixin
  5857. * @returns {Array} `['mixin', x]`
  5858. */
  5859. function getMixin2() {
  5860. var type = NodeType.MixinType;
  5861. var token = tokens[pos];
  5862. var line = token.ln;
  5863. var column = token.col;
  5864. var content = [];
  5865. content.push(checkClass(pos) ? getClass() : getShash());
  5866. content = content.concat(getSC());
  5867. if (checkArguments(pos)) content.push(getArguments());
  5868. return newNode(type, content, line, column);
  5869. }
  5870. /**
  5871. * Check if token is a namespace sign (`|`)
  5872. * @param {Number} i Token's index number
  5873. * @returns {Number} `1` if token is `|`, `0` if not
  5874. */
  5875. function checkNamespace(i) {
  5876. return i < tokensLength && tokens[i].type === TokenType.VerticalLine ? 1 : 0;
  5877. }
  5878. /**
  5879. * Get node with a namespace sign
  5880. * @returns {Array} `['namespace']`
  5881. */
  5882. function getNamespace() {
  5883. var type = NodeType.NamespaceType;
  5884. var token = tokens[pos];
  5885. var line = token.ln;
  5886. var column = token.col;
  5887. var content = '|';
  5888. pos++;
  5889. return newNode(type, content, line, column);
  5890. }
  5891. /**
  5892. * @param {Number} i Token's index number
  5893. * @returns {Number}
  5894. */
  5895. function checkNmName2(i) {
  5896. if (tokens[i].type === TokenType.Identifier) return 1;else if (tokens[i].type !== TokenType.DecimalNumber) return 0;
  5897. i++;
  5898. return i < tokensLength && tokens[i].type === TokenType.Identifier ? 2 : 1;
  5899. }
  5900. /**
  5901. * @returns {String}
  5902. */
  5903. function getNmName2() {
  5904. var s = tokens[pos].value;
  5905. if (tokens[pos++].type === TokenType.DecimalNumber && pos < tokensLength && tokens[pos].type === TokenType.Identifier) s += tokens[pos++].value;
  5906. return s;
  5907. }
  5908. /**
  5909. * Check if token is part of a number
  5910. * @param {Number} i Token's index number
  5911. * @returns {Number} Length of number
  5912. */
  5913. function checkNumber(i) {
  5914. if (i >= tokensLength) return 0;
  5915. if (tokens[i].number_l) return tokens[i].number_l;
  5916. // `10`:
  5917. if (i < tokensLength && tokens[i].type === TokenType.DecimalNumber && (!tokens[i + 1] || tokens[i + 1] && tokens[i + 1].type !== TokenType.FullStop)) {
  5918. tokens[i].number_l = 1;
  5919. return 1;
  5920. }
  5921. // `10.`:
  5922. if (i < tokensLength && tokens[i].type === TokenType.DecimalNumber && tokens[i + 1] && tokens[i + 1].type === TokenType.FullStop && (!tokens[i + 2] || tokens[i + 2].type !== TokenType.DecimalNumber)) {
  5923. tokens[i].number_l = 2;
  5924. return 2;
  5925. }
  5926. // `.10`:
  5927. if (i < tokensLength && tokens[i].type === TokenType.FullStop && tokens[i + 1].type === TokenType.DecimalNumber) {
  5928. tokens[i].number_l = 2;
  5929. return 2;
  5930. }
  5931. // `10.10`:
  5932. if (i < tokensLength && tokens[i].type === TokenType.DecimalNumber && tokens[i + 1] && tokens[i + 1].type === TokenType.FullStop && tokens[i + 2] && tokens[i + 2].type === TokenType.DecimalNumber) {
  5933. tokens[i].number_l = 3;
  5934. return 3;
  5935. }
  5936. return 0;
  5937. }
  5938. /**
  5939. * Get node with number
  5940. * @returns {Array} `['number', x]` where `x` is a number converted
  5941. * to string.
  5942. */
  5943. function getNumber() {
  5944. var type = NodeType.NumberType;
  5945. var token = tokens[pos];
  5946. var line = token.ln;
  5947. var column = token.col;
  5948. var l = tokens[pos].number_l;
  5949. var content = '';
  5950. for (var j = 0; j < l; j++) {
  5951. content += tokens[pos + j].value;
  5952. }
  5953. pos += l;
  5954. return newNode(type, content, line, column);
  5955. }
  5956. /**
  5957. * Check if token is an operator (`/`, `,`, `:`, `=`, `>`, `<` or `*`)
  5958. * @param {Number} i Token's index number
  5959. * @returns {Number} `1` if token is an operator, otherwise `0`
  5960. */
  5961. function checkOperator(i) {
  5962. if (i >= tokensLength) return 0;
  5963. switch (tokens[i].type) {
  5964. case TokenType.Solidus:
  5965. case TokenType.Comma:
  5966. case TokenType.Colon:
  5967. case TokenType.EqualsSign:
  5968. case TokenType.LessThanSign:
  5969. case TokenType.GreaterThanSign:
  5970. case TokenType.Asterisk:
  5971. return 1;
  5972. }
  5973. return 0;
  5974. }
  5975. /**
  5976. * Get node with an operator
  5977. * @returns {Array} `['operator', x]` where `x` is an operator converted
  5978. * to string.
  5979. */
  5980. function getOperator() {
  5981. var type = NodeType.OperatorType;
  5982. var token = tokens[pos];
  5983. var line = token.ln;
  5984. var column = token.col;
  5985. var content = token.value;
  5986. pos++;
  5987. return newNode(type, content, line, column);
  5988. }
  5989. /**
  5990. * Check if token is part of text inside parentheses, e.g. `(1)`
  5991. * @param {Number} i Token's index number
  5992. * @return {Number}
  5993. */
  5994. function checkParentheses(i) {
  5995. if (i >= tokensLength) return 0;
  5996. var start = i;
  5997. var right = tokens[i].right;
  5998. // Skip `(`.
  5999. if (tokens[i].type === TokenType.LeftParenthesis) i++;else return 0;
  6000. if (i < right) {
  6001. var l = checkTsets(i);
  6002. if (l) i += l;else return 0;
  6003. }
  6004. // Skip `)`.
  6005. i++;
  6006. return i - start;
  6007. }
  6008. /**
  6009. * Get node with text inside parentheses, e.g. `(1)`
  6010. * @return {Node}
  6011. */
  6012. function getParentheses() {
  6013. var type = NodeType.ParenthesesType;
  6014. var token = tokens[pos];
  6015. var line = token.ln;
  6016. var column = token.col;
  6017. var right = token.right;
  6018. var content = [];
  6019. // Skip `(`.
  6020. pos++;
  6021. if (pos < right) {
  6022. content = getTsets();
  6023. }
  6024. var end = getLastPosition(content, line, column, 1);
  6025. // Skip `)`.
  6026. pos++;
  6027. return newNode(type, content, line, column, end);
  6028. }
  6029. /**
  6030. * Check if token is a parent selector (`&`).
  6031. * @param {Number} i Token's index number
  6032. * @returns {Number}
  6033. */
  6034. function checkParentSelector(i) {
  6035. return i < tokensLength && tokens[i].type === TokenType.Ampersand ? 1 : 0;
  6036. }
  6037. /**
  6038. * Get node with a parent selector
  6039. * @returns {Array} `['parentSelector']`
  6040. */
  6041. function getParentSelector() {
  6042. var type = NodeType.ParentSelectorType;
  6043. var token = tokens[pos];
  6044. var line = token.ln;
  6045. var column = token.col;
  6046. var content = '&';
  6047. pos++;
  6048. return newNode(type, content, line, column);
  6049. }
  6050. function checkParentSelectorExtension(i) {
  6051. var start = i;
  6052. var l = void 0;
  6053. if (i >= tokensLength) return 0;
  6054. while (i < tokensLength) {
  6055. if (l = checkNumber(i) || checkPartialIdent(i)) i += l;else break;
  6056. }
  6057. return i - start;
  6058. }
  6059. function getParentSelectorExtension() {
  6060. var type = NodeType.ParentSelectorExtensionType;
  6061. var token = tokens[pos];
  6062. var line = token.ln;
  6063. var column = token.col;
  6064. var content = [];
  6065. while (pos < tokensLength) {
  6066. if (checkNumber(pos)) {
  6067. content.push(getNumber());
  6068. } else if (checkPartialIdent(pos)) {
  6069. content.push(getIdent());
  6070. } else break;
  6071. }
  6072. return newNode(type, content, line, column);
  6073. }
  6074. function checkParentSelectorWithExtension(i) {
  6075. var start = i;
  6076. var l = void 0;
  6077. if (i >= tokensLength) return 0;
  6078. if (l = checkParentSelector(i)) i += l;else return 0;
  6079. if (l = checkParentSelectorExtension(i)) i += l;
  6080. return i - start;
  6081. }
  6082. function getParentSelectorWithExtension() {
  6083. var content = [getParentSelector()];
  6084. if (checkParentSelectorExtension(pos)) content.push(getParentSelectorExtension());
  6085. return content;
  6086. }
  6087. /**
  6088. * Check if token is part of a number with percent sign (e.g. `10%`)
  6089. * @param {Number} i Token's index number
  6090. * @returns {Number}
  6091. */
  6092. function checkPercentage(i) {
  6093. var start = i;
  6094. var l = void 0;
  6095. if (i >= tokensLength) return 0;
  6096. if (l = checkNumber(i)) i += l;else return 0;
  6097. if (i >= tokensLength) return 0;
  6098. // Skip `%`.
  6099. if (tokens[i].type === TokenType.PercentSign) i++;else return 0;
  6100. return i - start;
  6101. }
  6102. /**
  6103. * Get node of number with percent sign
  6104. * @returns {Array} `['percentage', ['number', x]]` where `x` is a number
  6105. * (without percent sign) converted to string.
  6106. */
  6107. function getPercentage() {
  6108. var type = NodeType.PercentageType;
  6109. var token = tokens[pos];
  6110. var line = token.ln;
  6111. var column = token.col;
  6112. var content = [getNumber()];
  6113. var end = getLastPosition(content, line, column, 1);
  6114. // Skip `%`.
  6115. pos++;
  6116. return newNode(type, content, line, column, end);
  6117. }
  6118. /**
  6119. * @param {Number} i Token's index number
  6120. * @returns {Number}
  6121. */
  6122. function checkProgid(i) {
  6123. var start = i;
  6124. var l = void 0;
  6125. if (i >= tokensLength) return 0;
  6126. if (joinValues2(i, 6) === 'progid:DXImageTransform.Microsoft.') i += 6;else return 0;
  6127. if (l = checkIdent(i)) i += l;else return 0;
  6128. if (l = checkSC(i)) i += l;
  6129. if (tokens[i].type === TokenType.LeftParenthesis) {
  6130. tokens[start].progid_end = tokens[i].right;
  6131. i = tokens[i].right + 1;
  6132. } else return 0;
  6133. return i - start;
  6134. }
  6135. /**
  6136. * @returns {Array}
  6137. */
  6138. function getProgid() {
  6139. var type = NodeType.ProgidType;
  6140. var token = tokens[pos];
  6141. var line = token.ln;
  6142. var column = token.col;
  6143. var progid_end = token.progid_end;
  6144. var content = joinValues(pos, progid_end);
  6145. pos = progid_end + 1;
  6146. return newNode(type, content, line, column);
  6147. }
  6148. /**
  6149. * Check if token is part of a property
  6150. * @param {Number} i Token's index number
  6151. * @returns {Number} Length of the property
  6152. */
  6153. function checkProperty(i) {
  6154. var start = i;
  6155. var l = void 0;
  6156. if (i >= tokensLength) return 0;
  6157. if (l = checkVariable(i) || checkIdent(i)) i += l;else return 0;
  6158. return i - start;
  6159. }
  6160. /**
  6161. * Get node with a property
  6162. * @returns {Array} `['property', x]`
  6163. */
  6164. function getProperty() {
  6165. var type = NodeType.PropertyType;
  6166. var token = tokens[pos];
  6167. var line = token.ln;
  6168. var column = token.col;
  6169. var content = [];
  6170. if (checkVariable(pos)) {
  6171. content.push(getVariable());
  6172. } else {
  6173. content.push(getIdent());
  6174. }
  6175. return newNode(type, content, line, column);
  6176. }
  6177. /**
  6178. * Check if token is a colon
  6179. * @param {Number} i Token's index number
  6180. * @returns {Number} `1` if token is a colon, otherwise `0`
  6181. */
  6182. function checkPropertyDelim(i) {
  6183. return i < tokensLength && tokens[i].type === TokenType.Colon ? 1 : 0;
  6184. }
  6185. /**
  6186. * Get node with a colon
  6187. * @returns {Array} `['propertyDelim']`
  6188. */
  6189. function getPropertyDelim() {
  6190. var type = NodeType.PropertyDelimType;
  6191. var token = tokens[pos];
  6192. var line = token.ln;
  6193. var column = token.col;
  6194. var content = ':';
  6195. // Skip `:`.
  6196. pos++;
  6197. return newNode(type, content, line, column);
  6198. }
  6199. /**
  6200. * @param {Number} i Token's index number
  6201. * @returns {Number}
  6202. */
  6203. function checkPseudo(i) {
  6204. return checkPseudoe(i) || checkPseudoc(i);
  6205. }
  6206. /**
  6207. * @returns {Array}
  6208. */
  6209. function getPseudo() {
  6210. if (checkPseudoe(pos)) return getPseudoe();
  6211. if (checkPseudoc(pos)) return getPseudoc();
  6212. }
  6213. /**
  6214. * @param {Number} i Token's index number
  6215. * @returns {Number}
  6216. */
  6217. function checkPseudoe(i) {
  6218. var l = void 0;
  6219. // Check `::`
  6220. if (i >= tokensLength || tokens[i].type !== TokenType.Colon || i + 1 >= tokensLength || tokens[i + 1].type !== TokenType.Colon) return 0;
  6221. if (l = checkPseudoElement1(i)) tokens[i].pseudoElementType = 1;else if (l = checkPseudoElement2(i)) tokens[i].pseudoElementType = 2;else return 0;
  6222. return l;
  6223. }
  6224. /**
  6225. * @returns {Node}
  6226. */
  6227. function getPseudoe() {
  6228. var childType = tokens[pos].pseudoElementType;
  6229. if (childType === 1) return getPseudoElement1();
  6230. if (childType === 2) return getPseudoElement2();
  6231. }
  6232. /**
  6233. * (1) `::slotted(selector)`
  6234. * (2) `::slotted(selector, selector)`
  6235. */
  6236. function checkPseudoElement1(i) {
  6237. var start = i;
  6238. var l = void 0;
  6239. // Skip `::`.
  6240. i += 2;
  6241. if (i >= tokensLength) return 0;
  6242. if (l = checkIdent(i)) i += l;else return 0;
  6243. if (i >= tokensLength || tokens[i].type !== TokenType.LeftParenthesis) return 0;
  6244. var right = tokens[i].right;
  6245. // Skip `(`.
  6246. i++;
  6247. if (l = checkSC(i)) i += l;
  6248. if (l = checkSelectorsGroup(i)) i += l;else return 0;
  6249. if (l = checkSC(i)) i += l;
  6250. if (i !== right) return 0;
  6251. // Skip `)`.
  6252. i++;
  6253. return i - start;
  6254. }
  6255. /**
  6256. * (1) `::slotted(selector)`
  6257. * (2) `::slotted(selector, selector)`
  6258. */
  6259. function getPseudoElement1() {
  6260. var type = NodeType.PseudoeType;
  6261. var token = tokens[pos];
  6262. var line = token.ln;
  6263. var column = token.col;
  6264. var content = [];
  6265. // Skip `::`.
  6266. pos += 2;
  6267. content.push(getIdent());
  6268. {
  6269. var _type = NodeType.ArgumentsType;
  6270. var _token = tokens[pos];
  6271. var _line = _token.ln;
  6272. var _column = _token.col;
  6273. // Skip `(`.
  6274. pos++;
  6275. var selectorContent = [].concat(getSC(), getSelectorsGroup(), getSC());
  6276. var end = getLastPosition(selectorContent, _line, _column, 1);
  6277. var args = newNode(_type, selectorContent, _line, _column, end);
  6278. content.push(args);
  6279. // Skip `)`.
  6280. pos++;
  6281. }
  6282. return newNode(type, content, line, column);
  6283. }
  6284. function checkPseudoElement2(i) {
  6285. var start = i;
  6286. var l = void 0;
  6287. // Skip `::`.
  6288. i += 2;
  6289. if (l = checkInterpolatedVariable(i) || checkIdent(i)) i += l;else return 0;
  6290. return i - start;
  6291. }
  6292. /**
  6293. * @returns {Array}
  6294. */
  6295. function getPseudoElement2() {
  6296. var type = NodeType.PseudoeType;
  6297. var token = tokens[pos];
  6298. var line = token.ln;
  6299. var column = token.col;
  6300. // Skip `::`.
  6301. pos += 2;
  6302. var content = [];
  6303. if (checkInterpolatedVariable(pos)) {
  6304. content.push(getInterpolatedVariable());
  6305. } else {
  6306. content.push(getIdent());
  6307. }
  6308. return newNode(type, content, line, column);
  6309. }
  6310. /**
  6311. * @param {Number} i Token's index number
  6312. * @returns {Number}
  6313. */
  6314. function checkPseudoc(i) {
  6315. var l = void 0;
  6316. if (i >= tokensLength || tokens[i].type !== TokenType.Colon) return 0;
  6317. if (l = checkPseudoClass3(i)) tokens[i].pseudoClassType = 3;else if (l = checkPseudoClass4(i)) tokens[i].pseudoClassType = 4;else if (l = checkPseudoClass5(i)) tokens[i].pseudoClassType = 5;else if (l = checkPseudoClass1(i)) tokens[i].pseudoClassType = 1;else if (l = checkPseudoClass2(i)) tokens[i].pseudoClassType = 2;else if (l = checkPseudoClass6(i)) tokens[i].pseudoClassType = 6;else return 0;
  6318. return l;
  6319. }
  6320. function getPseudoc() {
  6321. var childType = tokens[pos].pseudoClassType;
  6322. if (childType === 1) return getPseudoClass1();
  6323. if (childType === 2) return getPseudoClass2();
  6324. if (childType === 3) return getPseudoClass3();
  6325. if (childType === 4) return getPseudoClass4();
  6326. if (childType === 5) return getPseudoClass5();
  6327. if (childType === 6) return getPseudoClass6();
  6328. }
  6329. /**
  6330. * (1) `:not(selector)`
  6331. * (2) `:extend(selector, selector)`
  6332. */
  6333. function checkPseudoClass1(i) {
  6334. var start = i;
  6335. var l = void 0;
  6336. // Skip `:`.
  6337. i++;
  6338. if (i >= tokensLength) return 0;
  6339. if (l = checkIdent(i)) i += l;else return 0;
  6340. if (i >= tokensLength || tokens[i].type !== TokenType.LeftParenthesis) return 0;
  6341. var right = tokens[i].right;
  6342. // Skip `(`.
  6343. i++;
  6344. if (l = checkSC(i)) i += l;
  6345. if (l = checkSelectorsGroup(i)) i += l;else return 0;
  6346. if (l = checkSC(i)) i += l;
  6347. if (i !== right) return 0;
  6348. // Skip `)`.
  6349. i++;
  6350. return i - start;
  6351. }
  6352. /**
  6353. * (-) `:not(panda)`
  6354. */
  6355. function getPseudoClass1() {
  6356. var type = NodeType.PseudocType;
  6357. var token = tokens[pos];
  6358. var line = token.ln;
  6359. var column = token.col;
  6360. var content = [];
  6361. // Skip `:`.
  6362. pos++;
  6363. content.push(getIdent());
  6364. {
  6365. var _type2 = NodeType.ArgumentsType;
  6366. var _token2 = tokens[pos];
  6367. var _line2 = _token2.ln;
  6368. var _column2 = _token2.col;
  6369. // Skip `(`.
  6370. pos++;
  6371. var selectorContent = [].concat(getSC(), getSelectorsGroup(), getSC());
  6372. var end = getLastPosition(selectorContent, _line2, _column2, 1);
  6373. var args = newNode(_type2, selectorContent, _line2, _column2, end);
  6374. content.push(args);
  6375. // Skip `)`.
  6376. pos++;
  6377. }
  6378. return newNode(type, content, line, column);
  6379. }
  6380. /**
  6381. * (1) `:nth-child(odd)`
  6382. * (2) `:nth-child(even)`
  6383. * (3) `:lang(de-DE)`
  6384. */
  6385. function checkPseudoClass2(i) {
  6386. var start = i;
  6387. var l = 0;
  6388. // Skip `:`.
  6389. i++;
  6390. if (i >= tokensLength) return 0;
  6391. if (l = checkIdent(i)) i += l;else return 0;
  6392. if (i >= tokensLength || tokens[i].type !== TokenType.LeftParenthesis) return 0;
  6393. var right = tokens[i].right;
  6394. // Skip `(`.
  6395. i++;
  6396. if (l = checkSC(i)) i += l;
  6397. if (l = checkIdent(i)) i += l;else return 0;
  6398. if (l = checkSC(i)) i += l;
  6399. if (i !== right) return 0;
  6400. // Skip `)`.
  6401. i++;
  6402. return i - start;
  6403. }
  6404. function getPseudoClass2() {
  6405. var type = NodeType.PseudocType;
  6406. var token = tokens[pos];
  6407. var line = token.ln;
  6408. var column = token.col;
  6409. var content = [];
  6410. // Skip `:`.
  6411. pos++;
  6412. content.push(getIdent());
  6413. {
  6414. // Skip `(`.
  6415. pos++;
  6416. var l = tokens[pos].ln;
  6417. var c = tokens[pos].col;
  6418. var value = [].concat(getSC(), getIdent(), getSC());
  6419. var end = getLastPosition(value, l, c, 1);
  6420. var args = newNode(NodeType.ArgumentsType, value, l, c, end);
  6421. content.push(args);
  6422. // Skip `)`.
  6423. pos++;
  6424. }
  6425. return newNode(type, content, line, column);
  6426. }
  6427. /**
  6428. * (-) `:nth-child(-3n + 2)`
  6429. */
  6430. function checkPseudoClass3(i) {
  6431. var start = i;
  6432. var l = 0;
  6433. // Skip `:`.
  6434. i++;
  6435. if (i >= tokensLength) return 0;
  6436. if (l = checkIdent(i)) i += l;else return 0;
  6437. if (i >= tokensLength || tokens[i].type !== TokenType.LeftParenthesis) return 0;
  6438. var right = tokens[i].right;
  6439. // Skip `(`.
  6440. i++;
  6441. if (l = checkSC(i)) i += l;
  6442. if (l = checkUnary(i)) i += l;
  6443. if (i >= tokensLength) return 0;
  6444. if (tokens[i].type === TokenType.DecimalNumber) i++;
  6445. if (i >= tokensLength) return 0;
  6446. if (tokens[i].value === 'n') i++;else return 0;
  6447. if (l = checkSC(i)) i += l;
  6448. if (i >= tokensLength) return 0;
  6449. if (tokens[i].value === '+' || tokens[i].value === '-') i++;else return 0;
  6450. if (l = checkSC(i)) i += l;
  6451. if (tokens[i].type === TokenType.DecimalNumber) i++;else return 0;
  6452. if (l = checkSC(i)) i += l;
  6453. if (i !== right) return 0;
  6454. // Skip `)`.
  6455. i++;
  6456. return i - start;
  6457. }
  6458. function getPseudoClass3() {
  6459. var type = NodeType.PseudocType;
  6460. var token = tokens[pos];
  6461. var line = token.ln;
  6462. var column = token.col;
  6463. var content = [];
  6464. // Skip `:`.
  6465. pos++;
  6466. content.push(getIdent());
  6467. var l = tokens[pos].ln;
  6468. var c = tokens[pos].col;
  6469. var value = [];
  6470. // Skip `(`.
  6471. pos++;
  6472. value = value.concat(getSC());
  6473. if (checkUnary(pos)) value.push(getUnary());
  6474. if (checkNumber(pos)) value.push(getNumber());
  6475. {
  6476. var _l = tokens[pos].ln;
  6477. var _c = tokens[pos].col;
  6478. var _content = tokens[pos].value;
  6479. var ident = newNode(NodeType.IdentType, _content, _l, _c);
  6480. value.push(ident);
  6481. pos++;
  6482. }
  6483. value = value.concat(getSC());
  6484. if (checkUnary(pos)) value.push(getUnary());
  6485. value = value.concat(getSC());
  6486. if (checkNumber(pos)) value.push(getNumber());
  6487. value = value.concat(getSC());
  6488. var end = getLastPosition(value, l, c, 1);
  6489. var args = newNode(NodeType.ArgumentsType, value, l, c, end);
  6490. content.push(args);
  6491. // Skip `)`.
  6492. pos++;
  6493. return newNode(type, content, line, column);
  6494. }
  6495. /**
  6496. * (-) `:nth-child(-3n)`
  6497. */
  6498. function checkPseudoClass4(i) {
  6499. var start = i;
  6500. var l = 0;
  6501. // Skip `:`.
  6502. i++;
  6503. if (i >= tokensLength) return 0;
  6504. if (l = checkIdent(i)) i += l;else return 0;
  6505. if (i >= tokensLength) return 0;
  6506. if (tokens[i].type !== TokenType.LeftParenthesis) return 0;
  6507. var right = tokens[i].right;
  6508. // Skip `(`.
  6509. i++;
  6510. if (l = checkSC(i)) i += l;
  6511. if (l = checkUnary(i)) i += l;
  6512. if (tokens[i].type === TokenType.DecimalNumber) i++;
  6513. if (tokens[i].value === 'n') i++;else return 0;
  6514. if (l = checkSC(i)) i += l;
  6515. if (i !== right) return 0;
  6516. // Skip `)`.
  6517. i++;
  6518. return i - start;
  6519. }
  6520. function getPseudoClass4() {
  6521. var type = NodeType.PseudocType;
  6522. var token = tokens[pos];
  6523. var line = token.ln;
  6524. var column = token.col;
  6525. var content = [];
  6526. // Skip `:`.
  6527. pos++;
  6528. content.push(getIdent());
  6529. var l = tokens[pos].ln;
  6530. var c = tokens[pos].col;
  6531. var value = [];
  6532. // Skip `(`.
  6533. pos++;
  6534. value = value.concat(getSC());
  6535. if (checkUnary(pos)) value.push(getUnary());
  6536. if (checkNumber(pos)) value.push(getNumber());
  6537. if (checkIdent(pos)) value.push(getIdent());
  6538. value = value.concat(getSC());
  6539. var end = getLastPosition(value, l, c, 1);
  6540. var args = newNode(NodeType.ArgumentsType, value, l, c, end);
  6541. content.push(args);
  6542. // Skip `)`.
  6543. pos++;
  6544. return newNode(type, content, line, column);
  6545. }
  6546. /**
  6547. * (-) `:nth-child(+8)`
  6548. */
  6549. function checkPseudoClass5(i) {
  6550. var start = i;
  6551. var l = 0;
  6552. // Skip `:`.
  6553. i++;
  6554. if (i >= tokensLength) return 0;
  6555. if (l = checkIdent(i)) i += l;else return 0;
  6556. if (i >= tokensLength) return 0;
  6557. if (tokens[i].type !== TokenType.LeftParenthesis) return 0;
  6558. var right = tokens[i].right;
  6559. // Skip `(`.
  6560. i++;
  6561. if (l = checkSC(i)) i += l;
  6562. if (l = checkUnary(i)) i += l;
  6563. if (tokens[i].type === TokenType.DecimalNumber) i++;else return 0;
  6564. if (l = checkSC(i)) i += l;
  6565. if (i !== right) return 0;
  6566. // Skip `)`.
  6567. i++;
  6568. return i - start;
  6569. }
  6570. function getPseudoClass5() {
  6571. var type = NodeType.PseudocType;
  6572. var token = tokens[pos];
  6573. var line = token.ln;
  6574. var column = token.col;
  6575. var content = [];
  6576. // Skip `:`.
  6577. pos++;
  6578. content.push(getIdent());
  6579. var l = tokens[pos].ln;
  6580. var c = tokens[pos].col;
  6581. var value = [];
  6582. // Skip `(`.
  6583. pos++;
  6584. value = value.concat(getSC());
  6585. if (checkUnary(pos)) value.push(getUnary());
  6586. if (checkNumber(pos)) value.push(getNumber());
  6587. value = value.concat(getSC());
  6588. var end = getLastPosition(value, l, c, 1);
  6589. var args = newNode(NodeType.ArgumentsType, value, l, c, end);
  6590. content.push(args);
  6591. // Skip `)`.
  6592. pos++;
  6593. return newNode(type, content, line, column);
  6594. }
  6595. /**
  6596. * (-) `:checked`
  6597. */
  6598. function checkPseudoClass6(i) {
  6599. var start = i;
  6600. var l = 0;
  6601. // Skip `:`.
  6602. i++;
  6603. if (i >= tokensLength) return 0;
  6604. if (l = checkInterpolatedVariable(i)) i += l;else if (l = checkIdent(i)) i += l;else return 0;
  6605. return i - start;
  6606. }
  6607. function getPseudoClass6() {
  6608. var type = NodeType.PseudocType;
  6609. var token = tokens[pos];
  6610. var line = token.ln;
  6611. var column = token.col;
  6612. var content = [];
  6613. // Skip `:`.
  6614. pos++;
  6615. var ident = checkInterpolatedVariable(pos) ? getInterpolatedVariable() : getIdent();
  6616. content.push(ident);
  6617. return newNode(type, content, line, column);
  6618. }
  6619. /**
  6620. * @param {Number} i Token's index number
  6621. * @returns {Number}
  6622. */
  6623. function checkRuleset(i) {
  6624. var start = i;
  6625. var l = void 0;
  6626. if (i >= tokensLength) return 0;
  6627. if (l = checkSelectorsGroup(i)) i += l;else return 0;
  6628. if (l = checkSC(i)) i += l;
  6629. if (l = checkBlock(i)) i += l;else return 0;
  6630. return i - start;
  6631. }
  6632. function getRuleset() {
  6633. var type = NodeType.RulesetType;
  6634. var token = tokens[pos];
  6635. var line = token.ln;
  6636. var column = token.col;
  6637. var content = [].concat(getSelectorsGroup(), getSC(), getBlock());
  6638. return newNode(type, content, line, column);
  6639. }
  6640. /**
  6641. * Check if token is marked as a space (if it's a space or a tab
  6642. * or a line break).
  6643. * @param {Number} i
  6644. * @returns {Number} Number of spaces in a row starting with the given token.
  6645. */
  6646. function checkS(i) {
  6647. return i < tokensLength && tokens[i].ws ? tokens[i].ws_last - i + 1 : 0;
  6648. }
  6649. /**
  6650. * Get node with spaces
  6651. * @returns {Array} `['s', x]` where `x` is a string containing spaces
  6652. */
  6653. function getS() {
  6654. var type = NodeType.SType;
  6655. var token = tokens[pos];
  6656. var line = token.ln;
  6657. var column = token.col;
  6658. var content = joinValues(pos, tokens[pos].ws_last);
  6659. pos = tokens[pos].ws_last + 1;
  6660. return newNode(type, content, line, column);
  6661. }
  6662. /**
  6663. * Check if token is a space or a comment.
  6664. * @param {Number} i Token's index number
  6665. * @returns {Number} Number of similar (space or comment) tokens
  6666. * in a row starting with the given token.
  6667. */
  6668. function checkSC(i) {
  6669. if (i >= tokensLength) return 0;
  6670. var l = void 0;
  6671. var lsc = 0;
  6672. while (i < tokensLength) {
  6673. if (!(l = checkS(i)) && !(l = checkCommentML(i)) && !(l = checkCommentSL(i))) break;
  6674. i += l;
  6675. lsc += l;
  6676. }
  6677. return lsc || 0;
  6678. }
  6679. /**
  6680. * Get node with spaces and comments
  6681. * @returns {Array} Array containing nodes with spaces (if there are any)
  6682. * and nodes with comments (if there are any):
  6683. * `[['s', x]*, ['comment', y]*]` where `x` is a string of spaces
  6684. * and `y` is a comment's text (without `/*` and `* /`).
  6685. */
  6686. function getSC() {
  6687. var sc = [];
  6688. if (pos >= tokensLength) return sc;
  6689. while (pos < tokensLength) {
  6690. if (checkS(pos)) sc.push(getS());else if (checkCommentML(pos)) sc.push(getCommentML());else if (checkCommentSL(pos)) sc.push(getCommentSL());else break;
  6691. }
  6692. return sc;
  6693. }
  6694. /**
  6695. * Check if token is part of a hexadecimal number (e.g. `#fff`) inside
  6696. * a simple selector
  6697. * @param {Number} i Token's index number
  6698. * @returns {Number}
  6699. */
  6700. function checkShash(i) {
  6701. var l = void 0;
  6702. if (i >= tokensLength || tokens[i].type !== TokenType.NumberSign) return 0;
  6703. if (l = checkInterpolatedVariable(i + 1) || checkIdent(i + 1)) return l + 1;else return 0;
  6704. }
  6705. /**
  6706. * Get node with a hexadecimal number (e.g. `#fff`) inside a simple
  6707. * selector
  6708. * @returns {Array} `['shash', x]` where `x` is a hexadecimal number
  6709. * converted to string (without `#`, e.g. `fff`)
  6710. */
  6711. function getShash() {
  6712. var type = NodeType.ShashType;
  6713. var token = tokens[pos];
  6714. var line = token.ln;
  6715. var column = token.col;
  6716. var content = [];
  6717. // Skip `#`.
  6718. pos++;
  6719. if (checkInterpolatedVariable(pos)) content.push(getInterpolatedVariable());else content.push(getIdent());
  6720. return newNode(type, content, line, column);
  6721. }
  6722. /**
  6723. * Check if token is part of a string (text wrapped in quotes)
  6724. * @param {Number} i Token's index number
  6725. * @returns {Number} `1` if token is part of a string, `0` if not
  6726. */
  6727. function checkString(i) {
  6728. if (i >= tokensLength) {
  6729. return 0;
  6730. }
  6731. if (tokens[i].type === TokenType.StringSQ || tokens[i].type === TokenType.StringDQ) {
  6732. return 1;
  6733. }
  6734. return 0;
  6735. }
  6736. /**
  6737. * Get string's node
  6738. * @returns {Array} `['string', x]` where `x` is a string (including
  6739. * quotes).
  6740. */
  6741. function getString() {
  6742. var type = NodeType.StringType;
  6743. var token = tokens[pos];
  6744. var line = token.ln;
  6745. var column = token.col;
  6746. var content = token.value;
  6747. pos++;
  6748. return newNode(type, content, line, column);
  6749. }
  6750. /**
  6751. * Validate stylesheet: it should consist of any number (0 or more) of
  6752. * rulesets (sets of rules with selectors), @-rules, whitespaces or
  6753. * comments.
  6754. * @param {Number} i Token's index number
  6755. * @returns {Number}
  6756. */
  6757. function checkStylesheet(i) {
  6758. var start = i;
  6759. var l = void 0;
  6760. // Check every token:
  6761. while (i < tokensLength) {
  6762. if (l = checkSC(i) || checkRuleset(i) || checkDeclaration(i) || checkDeclDelim(i) || checkAtrule(i) || checkMixin(i)) i += l;else throwError(i);
  6763. }
  6764. return i - start;
  6765. }
  6766. /**
  6767. * @returns {Array} `['stylesheet', x]` where `x` is all stylesheet's
  6768. * nodes.
  6769. */
  6770. function getStylesheet() {
  6771. var type = NodeType.StylesheetType;
  6772. var token = tokens[pos];
  6773. var line = token.ln;
  6774. var column = token.col;
  6775. var content = [];
  6776. while (pos < tokensLength) {
  6777. if (checkSC(pos)) content = content.concat(getSC());else if (checkRuleset(pos)) content.push(getRuleset());else if (checkDeclaration(pos)) content.push(getDeclaration());else if (checkDeclDelim(pos)) content.push(getDeclDelim());else if (checkAtrule(pos)) content.push(getAtrule());else if (checkMixin(pos)) content.push(getMixin());else throwError(pos);
  6778. }
  6779. return newNode(type, content, line, column);
  6780. }
  6781. /**
  6782. * @param {Number} i Token's index number
  6783. * @returns {Number}
  6784. */
  6785. function checkTset(i) {
  6786. var l = void 0;
  6787. if (l = checkVhash(i)) tokens[i].tset_child = 1;else if (l = checkAny(i)) tokens[i].tset_child = 2;else if (l = checkSC(i)) tokens[i].tset_child = 3;else if (l = checkOperator(i)) tokens[i].tset_child = 4;
  6788. return l;
  6789. }
  6790. /**
  6791. * @returns {Array}
  6792. */
  6793. function getTset() {
  6794. var childType = tokens[pos].tset_child;
  6795. if (childType === 1) return getVhash();
  6796. if (childType === 2) return getAny();
  6797. if (childType === 3) return getSC();
  6798. if (childType === 4) return getOperator();
  6799. }
  6800. /**
  6801. * @param {Number} i Token's index number
  6802. * @returns {Number}
  6803. */
  6804. function checkTsets(i) {
  6805. var start = i;
  6806. var l = void 0;
  6807. if (i >= tokensLength) return 0;
  6808. while (l = checkTset(i)) {
  6809. i += l;
  6810. }
  6811. return i - start;
  6812. }
  6813. /**
  6814. * @returns {Array}
  6815. */
  6816. function getTsets() {
  6817. var content = [];
  6818. var t = void 0;
  6819. while (checkTset(pos)) {
  6820. t = getTset();
  6821. if (typeof t.content === 'string') content.push(t);else content = content.concat(t);
  6822. }
  6823. return content;
  6824. }
  6825. /**
  6826. * Check if token is an unary (arithmetical) sign (`+` or `-`)
  6827. * @param {Number} i Token's index number
  6828. * @returns {Number} `1` if token is an unary sign, `0` if not
  6829. */
  6830. function checkUnary(i) {
  6831. if (i >= tokensLength) return 0;
  6832. if (tokens[i].type === TokenType.HyphenMinus || tokens[i].type === TokenType.PlusSign) {
  6833. return 1;
  6834. }
  6835. return 0;
  6836. }
  6837. /**
  6838. * Get node with an unary (arithmetical) sign (`+` or `-`)
  6839. * @returns {Array} `['unary', x]` where `x` is an unary sign
  6840. * converted to string.
  6841. */
  6842. function getUnary() {
  6843. var type = NodeType.OperatorType;
  6844. var token = tokens[pos];
  6845. var line = token.ln;
  6846. var column = token.col;
  6847. var content = token.value;
  6848. pos++;
  6849. return newNode(type, content, line, column);
  6850. }
  6851. /**
  6852. * Check if token is a unicode range (single or multiple <urange> nodes)
  6853. * @param {number} i Token's index
  6854. * @return {number} Unicode range node's length
  6855. */
  6856. function checkUnicodeRange(i) {
  6857. var start = i;
  6858. var l = void 0;
  6859. if (i >= tokensLength) return 0;
  6860. if (l = checkUrange(i)) i += l;else return 0;
  6861. while (i < tokensLength) {
  6862. var spaceBefore = checkSC(i);
  6863. var comma = checkDelim(i + spaceBefore);
  6864. if (!comma) break;
  6865. var spaceAfter = checkSC(i + spaceBefore + comma);
  6866. if (l = checkUrange(i + spaceBefore + comma + spaceAfter)) {
  6867. i += spaceBefore + comma + spaceAfter + l;
  6868. } else break;
  6869. }
  6870. return i - start;
  6871. }
  6872. /**
  6873. * Get a unicode range node
  6874. * @return {Node}
  6875. */
  6876. function getUnicodeRange() {
  6877. var type = NodeType.UnicodeRangeType;
  6878. var token = tokens[pos];
  6879. var line = token.ln;
  6880. var column = token.col;
  6881. var content = [];
  6882. while (pos < tokensLength) {
  6883. if (checkSC(pos)) content = content.concat(getSC());else if (checkDelim(pos)) content.push(getDelim());else if (checkUrange(pos)) content.push(getUrange());else break;
  6884. }
  6885. return newNode(type, content, line, column);
  6886. }
  6887. /**
  6888. * Check if token is unit
  6889. * @param {Number} i Token's index number
  6890. * @return {Number}
  6891. */
  6892. function checkUnit(i) {
  6893. var units = ['em', 'ex', 'ch', 'rem', 'vh', 'vw', 'vmin', 'vmax', 'px', 'mm', 'q', 'cm', 'in', 'pt', 'pc', 'deg', 'grad', 'rad', 'turn', 's', 'ms', 'Hz', 'kHz', 'dpi', 'dpcm', 'dppx'];
  6894. return units.indexOf(tokens[i].value) !== -1 ? 1 : 0;
  6895. }
  6896. /**
  6897. * Get unit node of type ident
  6898. * @return {Node} An ident node containing the unit value
  6899. */
  6900. function getUnit() {
  6901. var type = NodeType.IdentType;
  6902. var token = tokens[pos];
  6903. var line = token.ln;
  6904. var column = token.col;
  6905. var content = token.value;
  6906. pos++;
  6907. return newNode(type, content, line, column);
  6908. }
  6909. /**
  6910. * Check if token is a u-range (part of a unicode-range)
  6911. * (1) `U+416`
  6912. * (2) `U+400-4ff`
  6913. * (3) `U+4??`
  6914. * @param {number} i Token's index
  6915. * @return {number} Urange node's length
  6916. */
  6917. function checkUrange(i) {
  6918. var start = i;
  6919. var l = void 0;
  6920. if (i >= tokensLength) return 0;
  6921. // Check for unicode prefix (u+ or U+)
  6922. if (tokens[i].value === 'U' || tokens[i].value === 'u') i += 1;else return 0;
  6923. if (i >= tokensLength) return 0;
  6924. if (tokens[i].value === '+') i += 1;else return 0;
  6925. while (i < tokensLength) {
  6926. if (l = checkIdent(i)) i += l;else if (l = checkNumber(i)) i += l;else if (l = checkUnary(i)) i += l;else if (l = _checkUnicodeWildcard(i)) i += l;else break;
  6927. }
  6928. tokens[start].urangeEnd = i - 1;
  6929. return i - start;
  6930. }
  6931. /**
  6932. * Get a u-range node (part of a unicode-range)
  6933. * @return {Node}
  6934. */
  6935. function getUrange() {
  6936. var startPos = pos;
  6937. var type = NodeType.UrangeType;
  6938. var token = tokens[pos];
  6939. var line = token.ln;
  6940. var column = token.col;
  6941. var content = [];
  6942. content = joinValues(startPos, tokens[startPos].urangeEnd);
  6943. pos = tokens[startPos].urangeEnd + 1;
  6944. return newNode(type, content, line, column);
  6945. }
  6946. /**
  6947. * Check for unicode wildcard characters `?`
  6948. * @param {number} i Token's index
  6949. * @return {number} Wildcard length
  6950. */
  6951. function _checkUnicodeWildcard(i) {
  6952. var start = i;
  6953. if (i >= tokensLength) return 0;
  6954. while (i < tokensLength) {
  6955. if (tokens[i].type === TokenType.QuestionMark) i += 1;else break;
  6956. }
  6957. return i - start;
  6958. }
  6959. /**
  6960. * Check if token is part of URI (e.g. `url('/css/styles.css')`)
  6961. * @param {Number} i Token's index number
  6962. * @returns {Number} Length of URI
  6963. */
  6964. function checkUri(i) {
  6965. var start = i;
  6966. if (i >= tokensLength || tokens[i++].value !== 'url' || i >= tokensLength || tokens[i].type !== TokenType.LeftParenthesis) return 0;
  6967. return tokens[i].right - start + 1;
  6968. }
  6969. /**
  6970. * Get node with URI
  6971. * @returns {Array} `['uri', x]` where `x` is URI's nodes (without `url`
  6972. * and braces, e.g. `['string', ''/css/styles.css'']`).
  6973. */
  6974. function getUri() {
  6975. var startPos = pos;
  6976. var uriExcluding = {};
  6977. var uri = void 0;
  6978. var token = void 0;
  6979. var l = void 0;
  6980. var raw = void 0;
  6981. pos += 2;
  6982. uriExcluding[TokenType.Space] = 1;
  6983. uriExcluding[TokenType.Tab] = 1;
  6984. uriExcluding[TokenType.Newline] = 1;
  6985. uriExcluding[TokenType.LeftParenthesis] = 1;
  6986. uriExcluding[TokenType.RightParenthesis] = 1;
  6987. if (checkUri1(pos)) {
  6988. uri = [].concat(getSC()).concat([getString()]).concat(getSC());
  6989. } else {
  6990. uri = getSC();
  6991. l = checkExcluding(uriExcluding, pos);
  6992. token = tokens[pos];
  6993. raw = newNode(NodeType.RawType, joinValues(pos, pos + l), token.ln, token.col);
  6994. uri.push(raw);
  6995. pos += l + 1;
  6996. uri = uri.concat(getSC());
  6997. }
  6998. token = tokens[startPos];
  6999. var line = token.ln;
  7000. var column = token.col;
  7001. var end = getLastPosition(uri, line, column, 1);
  7002. pos++;
  7003. return newNode(NodeType.UriType, uri, line, column, end);
  7004. }
  7005. /**
  7006. * @param {Number} i Token's index number
  7007. * @returns {Number}
  7008. */
  7009. function checkUri1(i) {
  7010. var start = i;
  7011. var l = void 0;
  7012. if (i >= tokensLength) return 0;
  7013. if (l = checkSC(i)) i += l;
  7014. if (tokens[i].type !== TokenType.StringDQ && tokens[i].type !== TokenType.StringSQ) {
  7015. return 0;
  7016. }
  7017. i++;
  7018. if (l = checkSC(i)) i += l;
  7019. return i - start;
  7020. }
  7021. /**
  7022. * Check if token is part of a value
  7023. * @param {Number} i Token's index number
  7024. * @returns {Number} Length of the value
  7025. */
  7026. function checkValue(i) {
  7027. var start = i;
  7028. var l = void 0;
  7029. var s = void 0;
  7030. var _i = void 0;
  7031. while (i < tokensLength) {
  7032. s = checkSC(i);
  7033. _i = i + s;
  7034. if (l = _checkValue(_i)) i += l + s;
  7035. if (!l || checkBlock(_i)) break;
  7036. }
  7037. tokens[start].value_end = i;
  7038. return i - start;
  7039. }
  7040. /**
  7041. * @returns {Array}
  7042. */
  7043. function getValue() {
  7044. var type = NodeType.ValueType;
  7045. var token = tokens[pos];
  7046. var line = token.ln;
  7047. var column = token.col;
  7048. var end = tokens[pos].value_end;
  7049. var content = [];
  7050. var _pos = void 0;
  7051. var s = void 0;
  7052. while (pos < end) {
  7053. s = checkSC(pos);
  7054. _pos = pos + s;
  7055. if (!_checkValue(_pos)) break;
  7056. if (s) content = content.concat(getSC());
  7057. content.push(_getValue());
  7058. }
  7059. return newNode(type, content, line, column);
  7060. }
  7061. /**
  7062. * @param {Number} i Token's index number
  7063. * @returns {Number}
  7064. */
  7065. function _checkValue(i) {
  7066. var l = void 0;
  7067. if (l = checkEscapedString(i)) tokens[i].value_child = 1;else if (l = checkInterpolatedVariable(i)) tokens[i].value_child = 2;else if (l = checkVariable(i)) tokens[i].value_child = 3;else if (l = checkVhash(i)) tokens[i].value_child = 4;else if (l = checkBlock(i)) tokens[i].value_child = 5;else if (l = checkProgid(i)) tokens[i].value_child = 6;else if (l = checkAny(i)) tokens[i].value_child = 7;else if (l = checkAtkeyword(i)) tokens[i].value_child = 8;else if (l = checkOperator(i)) tokens[i].value_child = 9;else if (l = checkImportant(i)) tokens[i].value_child = 10;
  7068. return l;
  7069. }
  7070. /**
  7071. * @returns {Array}
  7072. */
  7073. function _getValue() {
  7074. var childType = tokens[pos].value_child;
  7075. if (childType === 1) return getEscapedString();
  7076. if (childType === 2) return getInterpolatedVariable();
  7077. if (childType === 3) return getVariable();
  7078. if (childType === 4) return getVhash();
  7079. if (childType === 5) return getBlock();
  7080. if (childType === 6) return getProgid();
  7081. if (childType === 7) return getAny();
  7082. if (childType === 8) return getAtkeyword();
  7083. if (childType === 9) return getOperator();
  7084. if (childType === 10) return getImportant();
  7085. }
  7086. /**
  7087. * Check if token is part of LESS variable
  7088. * @param {Number} i Token's index number
  7089. * @returns {Number} Length of the variable
  7090. */
  7091. function checkVariable(i) {
  7092. var l = void 0;
  7093. if (i >= tokensLength || tokens[i].type !== TokenType.CommercialAt) return 0;
  7094. if (tokens[i - 1] && tokens[i - 1].type === TokenType.CommercialAt && tokens[i - 2] && tokens[i - 2].type === TokenType.CommercialAt) return 0;
  7095. return (l = checkVariable(i + 1) || checkIdent(i + 1)) ? l + 1 : 0;
  7096. }
  7097. /**
  7098. * Get node with a variable
  7099. * @returns {Array} `['variable', ['ident', x]]` where `x` is
  7100. * a variable name.
  7101. */
  7102. function getVariable() {
  7103. var type = NodeType.VariableType;
  7104. var token = tokens[pos];
  7105. var line = token.ln;
  7106. var column = token.col;
  7107. var content = [];
  7108. // Skip `$`.
  7109. pos++;
  7110. if (checkVariable(pos)) content.push(getVariable());else content.push(getIdent());
  7111. return newNode(type, content, line, column);
  7112. }
  7113. /**
  7114. * Check if token is part of a variables list (e.g. `@rest...`).
  7115. * @param {Number} i Token's index number
  7116. * @returns {Number}
  7117. */
  7118. function checkVariablesList(i) {
  7119. var d = 0; // Number of dots
  7120. var l = void 0;
  7121. if (i >= tokensLength) return 0;
  7122. if (l = checkVariable(i)) i += l;else return 0;
  7123. while (tokens[i] && tokens[i].type === TokenType.FullStop) {
  7124. d++;
  7125. i++;
  7126. }
  7127. return d === 3 ? l + d : 0;
  7128. }
  7129. /**
  7130. * Get node with a variables list
  7131. * @returns {Array} `['variableslist', ['variable', ['ident', x]]]` where
  7132. * `x` is a variable name.
  7133. */
  7134. function getVariablesList() {
  7135. var type = NodeType.VariablesListType;
  7136. var token = tokens[pos];
  7137. var line = token.ln;
  7138. var column = token.col;
  7139. var content = [getVariable()];
  7140. var end = getLastPosition(content, line, column, 3);
  7141. // Skip `...`.
  7142. pos += 3;
  7143. return newNode(type, content, line, column, end);
  7144. }
  7145. /**
  7146. * Check if token is part of a hexadecimal number (e.g. `#fff`) inside
  7147. * some value
  7148. * @param {Number} i Token's index number
  7149. * @returns {Number}
  7150. */
  7151. function checkVhash(i) {
  7152. var start = i;
  7153. var l = void 0;
  7154. if (i >= tokensLength) return 0;
  7155. // Skip `#`.
  7156. if (tokens[i].type === TokenType.NumberSign) i++;else return 0;
  7157. if (l = checkNmName2(i)) i += l;else return 0;
  7158. return i - start;
  7159. }
  7160. /**
  7161. * Get node with a hexadecimal number (e.g. `#fff`) inside some value
  7162. * @returns {Array} `['vhash', x]` where `x` is a hexadecimal number
  7163. * converted to string (without `#`, e.g. `'fff'`).
  7164. */
  7165. function getVhash() {
  7166. var type = NodeType.VhashType;
  7167. var token = tokens[pos];
  7168. var line = token.ln;
  7169. var column = token.col;
  7170. // Skip `#`.
  7171. pos++;
  7172. var content = getNmName2();
  7173. var end = getLastPosition(content, line, column + 1);
  7174. return newNode(type, content, line, column, end);
  7175. }
  7176. function checkSelectorsGroup(i) {
  7177. if (i >= tokensLength) return 0;
  7178. var start = i;
  7179. var l = void 0;
  7180. if (l = checkSelector(i)) i += l;else return 0;
  7181. while (i < tokensLength) {
  7182. var spaceBefore = checkSC(i);
  7183. var comma = checkDelim(i + spaceBefore);
  7184. if (!comma) break;
  7185. var spaceAfter = checkSC(i + spaceBefore + comma);
  7186. if (l = checkSelector(i + spaceBefore + comma + spaceAfter)) {
  7187. i += spaceBefore + comma + spaceAfter + l;
  7188. } else break;
  7189. }
  7190. tokens[start].selectorsGroupEnd = i;
  7191. return i - start;
  7192. }
  7193. function getSelectorsGroup() {
  7194. var selectorsGroup = [];
  7195. var selectorsGroupEnd = tokens[pos].selectorsGroupEnd;
  7196. selectorsGroup.push(getSelector());
  7197. while (pos < selectorsGroupEnd) {
  7198. selectorsGroup = selectorsGroup.concat(getSC(), getDelim(), getSC(), getSelector());
  7199. }
  7200. return selectorsGroup;
  7201. }
  7202. function checkSelector(i) {
  7203. var l = void 0;
  7204. if (l = checkSelector1(i)) tokens[i].selectorType = 1;else if (l = checkSelector2(i)) tokens[i].selectorType = 2;
  7205. return l;
  7206. }
  7207. function getSelector() {
  7208. var selectorType = tokens[pos].selectorType;
  7209. if (selectorType === 1) return getSelector1();else return getSelector2();
  7210. }
  7211. /**
  7212. * Checks for selector which starts with a compound selector.
  7213. */
  7214. function checkSelector1(i) {
  7215. if (i >= tokensLength) return 0;
  7216. var start = i;
  7217. var l = void 0;
  7218. if (l = checkCompoundSelector(i)) i += l;else return 0;
  7219. while (i < tokensLength) {
  7220. var space = checkSC(i);
  7221. var comma = checkCombinator(i + space);
  7222. if (!space && !comma) break;
  7223. if (comma) {
  7224. i += space + comma;
  7225. space = checkSC(i);
  7226. }
  7227. if (l = checkCompoundSelector(i + space)) i += space + l;else break;
  7228. }
  7229. tokens[start].selectorEnd = i;
  7230. return i - start;
  7231. }
  7232. function getSelector1() {
  7233. var type = NodeType.SelectorType;
  7234. var token = tokens[pos];
  7235. var line = token.ln;
  7236. var column = token.col;
  7237. var selectorEnd = token.selectorEnd;
  7238. var content = getCompoundSelector();
  7239. while (pos < selectorEnd) {
  7240. if (checkSC(pos)) content = content.concat(getSC());else if (checkCombinator(pos)) content.push(getCombinator());else if (checkCompoundSelector(pos)) content = content.concat(getCompoundSelector());
  7241. }
  7242. return newNode(type, content, line, column);
  7243. }
  7244. /**
  7245. * Checks for a selector that starts with a combinator.
  7246. */
  7247. function checkSelector2(i) {
  7248. if (i >= tokensLength) return 0;
  7249. var start = i;
  7250. var l = void 0;
  7251. if (l = checkCombinator(i)) i += l;else return 0;
  7252. while (i < tokensLength) {
  7253. var spaceBefore = checkSC(i);
  7254. if (l = checkCompoundSelector(i + spaceBefore)) i += spaceBefore + l;else break;
  7255. var spaceAfter = checkSC(i);
  7256. var comma = checkCombinator(i + spaceAfter);
  7257. if (!spaceAfter && !comma) break;
  7258. if (comma) {
  7259. i += spaceAfter + comma;
  7260. }
  7261. }
  7262. tokens[start].selectorEnd = i;
  7263. return i - start;
  7264. }
  7265. function getSelector2() {
  7266. var type = NodeType.SelectorType;
  7267. var token = tokens[pos];
  7268. var line = token.ln;
  7269. var column = token.col;
  7270. var selectorEnd = token.selectorEnd;
  7271. var content = [getCombinator()];
  7272. while (pos < selectorEnd) {
  7273. if (checkSC(pos)) content = content.concat(getSC());else if (checkCombinator(pos)) content.push(getCombinator());else if (checkCompoundSelector(pos)) content = content.concat(getCompoundSelector());
  7274. }
  7275. return newNode(type, content, line, column);
  7276. }
  7277. function checkCompoundSelector(i) {
  7278. var l = void 0;
  7279. if (l = checkCompoundSelector1(i)) {
  7280. tokens[i].compoundSelectorType = 1;
  7281. } else if (l = checkCompoundSelector2(i)) {
  7282. tokens[i].compoundSelectorType = 2;
  7283. }
  7284. return l;
  7285. }
  7286. function getCompoundSelector() {
  7287. var type = tokens[pos].compoundSelectorType;
  7288. if (type === 1) return getCompoundSelector1();
  7289. if (type === 2) return getCompoundSelector2();
  7290. }
  7291. function checkCompoundSelector1(i) {
  7292. if (i >= tokensLength) return 0;
  7293. var start = i;
  7294. var l = void 0;
  7295. if (l = checkUniversalSelector(i) || checkTypeSelector(i) || checkParentSelectorWithExtension(i)) i += l;else return 0;
  7296. while (i < tokensLength) {
  7297. var _l2 = checkShash(i) || checkClass(i) || checkAttributeSelector(i) || checkPseudo(i);
  7298. if (_l2) i += _l2;else break;
  7299. }
  7300. tokens[start].compoundSelectorEnd = i;
  7301. return i - start;
  7302. }
  7303. function getCompoundSelector1() {
  7304. var sequence = [];
  7305. var compoundSelectorEnd = tokens[pos].compoundSelectorEnd;
  7306. if (checkUniversalSelector(pos)) sequence.push(getUniversalSelector());else if (checkTypeSelector(pos)) sequence.push(getTypeSelector());else if (checkParentSelectorWithExtension(pos)) sequence = sequence.concat(getParentSelectorWithExtension());
  7307. while (pos < compoundSelectorEnd) {
  7308. if (checkShash(pos)) sequence.push(getShash());else if (checkClass(pos)) sequence.push(getClass());else if (checkAttributeSelector(pos)) sequence.push(getAttributeSelector());else if (checkPseudo(pos)) sequence.push(getPseudo());
  7309. }
  7310. return sequence;
  7311. }
  7312. function checkCompoundSelector2(i) {
  7313. if (i >= tokensLength) return 0;
  7314. var start = i;
  7315. while (i < tokensLength) {
  7316. var l = checkShash(i) || checkClass(i) || checkAttributeSelector(i) || checkPseudo(i);
  7317. if (l) i += l;else break;
  7318. }
  7319. tokens[start].compoundSelectorEnd = i;
  7320. return i - start;
  7321. }
  7322. function getCompoundSelector2() {
  7323. var sequence = [];
  7324. var compoundSelectorEnd = tokens[pos].compoundSelectorEnd;
  7325. while (pos < compoundSelectorEnd) {
  7326. if (checkShash(pos)) sequence.push(getShash());else if (checkClass(pos)) sequence.push(getClass());else if (checkAttributeSelector(pos)) sequence.push(getAttributeSelector());else if (checkPseudo(pos)) sequence.push(getPseudo());
  7327. }
  7328. return sequence;
  7329. }
  7330. function checkUniversalSelector(i) {
  7331. if (i >= tokensLength) return 0;
  7332. var start = i;
  7333. var l = void 0;
  7334. if (l = checkNamePrefix(i)) i += l;
  7335. if (tokens[i].type === TokenType.Asterisk) i++;else return 0;
  7336. return i - start;
  7337. }
  7338. function getUniversalSelector() {
  7339. var type = NodeType.UniversalSelectorType;
  7340. var token = tokens[pos];
  7341. var line = token.ln;
  7342. var column = token.col;
  7343. var content = [];
  7344. var end = void 0;
  7345. if (checkNamePrefix(pos)) {
  7346. content.push(getNamePrefix());
  7347. end = getLastPosition(content, line, column, 1);
  7348. }
  7349. pos++;
  7350. return newNode(type, content, line, column, end);
  7351. }
  7352. function checkTypeSelector(i) {
  7353. if (i >= tokensLength) return 0;
  7354. var start = i;
  7355. var l = void 0;
  7356. if (l = checkNamePrefix(i)) i += l;
  7357. if (l = checkIdent(i)) i += l;else return 0;
  7358. return i - start;
  7359. }
  7360. function getTypeSelector() {
  7361. var type = NodeType.TypeSelectorType;
  7362. var token = tokens[pos];
  7363. var line = token.ln;
  7364. var column = token.col;
  7365. var content = [];
  7366. if (checkNamePrefix(pos)) content.push(getNamePrefix());
  7367. content.push(getIdent());
  7368. return newNode(type, content, line, column);
  7369. }
  7370. function checkAttributeSelector(i) {
  7371. var l = void 0;
  7372. if (l = checkAttributeSelector1(i)) tokens[i].attributeSelectorType = 1;else if (l = checkAttributeSelector2(i)) tokens[i].attributeSelectorType = 2;
  7373. return l;
  7374. }
  7375. function getAttributeSelector() {
  7376. var type = tokens[pos].attributeSelectorType;
  7377. if (type === 1) return getAttributeSelector1();else return getAttributeSelector2();
  7378. }
  7379. /**
  7380. * (1) `[panda=nani]`
  7381. * (2) `[panda='nani']`
  7382. * (3) `[panda='nani' i]`
  7383. *
  7384. */
  7385. function checkAttributeSelector1(i) {
  7386. var start = i;
  7387. if (tokens[i].type === TokenType.LeftSquareBracket) i++;else return 0;
  7388. var l = void 0;
  7389. if (l = checkSC(i)) i += l;
  7390. if (l = checkAttributeName(i)) i += l;else return 0;
  7391. if (l = checkSC(i)) i += l;
  7392. if (l = checkAttributeMatch(i)) i += l;else return 0;
  7393. if (l = checkSC(i)) i += l;
  7394. if (l = checkAttributeValue(i)) i += l;else return 0;
  7395. if (l = checkSC(i)) i += l;
  7396. if (l = checkAttributeFlags(i)) {
  7397. i += l;
  7398. if (l = checkSC(i)) i += l;
  7399. }
  7400. if (tokens[i].type === TokenType.RightSquareBracket) i++;else return 0;
  7401. return i - start;
  7402. }
  7403. function getAttributeSelector1() {
  7404. var type = NodeType.AttributeSelectorType;
  7405. var token = tokens[pos];
  7406. var line = token.ln;
  7407. var column = token.col;
  7408. var content = [];
  7409. // Skip `[`.
  7410. pos++;
  7411. content = content.concat(getSC(), getAttributeName(), getSC(), getAttributeMatch(), getSC(), getAttributeValue(), getSC());
  7412. if (checkAttributeFlags(pos)) {
  7413. content.push(getAttributeFlags());
  7414. content = content.concat(getSC());
  7415. }
  7416. // Skip `]`.
  7417. pos++;
  7418. var end = getLastPosition(content, line, column, 1);
  7419. return newNode(type, content, line, column, end);
  7420. }
  7421. /**
  7422. * (1) `[panda]`
  7423. */
  7424. function checkAttributeSelector2(i) {
  7425. var start = i;
  7426. if (tokens[i].type === TokenType.LeftSquareBracket) i++;else return 0;
  7427. var l = void 0;
  7428. if (l = checkSC(i)) i += l;
  7429. if (l = checkAttributeName(i)) i += l;else return 0;
  7430. if (l = checkSC(i)) i += l;
  7431. if (tokens[i].type === TokenType.RightSquareBracket) i++;else return 0;
  7432. return i - start;
  7433. }
  7434. function getAttributeSelector2() {
  7435. var type = NodeType.AttributeSelectorType;
  7436. var token = tokens[pos];
  7437. var line = token.ln;
  7438. var column = token.col;
  7439. var content = [];
  7440. // Skip `[`.
  7441. pos++;
  7442. content = content.concat(getSC(), getAttributeName(), getSC());
  7443. // Skip `]`.
  7444. pos++;
  7445. var end = getLastPosition(content, line, column, 1);
  7446. return newNode(type, content, line, column, end);
  7447. }
  7448. function checkAttributeName(i) {
  7449. var start = i;
  7450. var l = void 0;
  7451. if (l = checkNamePrefix(i)) i += l;
  7452. if (l = checkIdent(i)) i += l;else return 0;
  7453. return i - start;
  7454. }
  7455. function getAttributeName() {
  7456. var type = NodeType.AttributeNameType;
  7457. var token = tokens[pos];
  7458. var line = token.ln;
  7459. var column = token.col;
  7460. var content = [];
  7461. if (checkNamePrefix(pos)) content.push(getNamePrefix());
  7462. content.push(getIdent());
  7463. return newNode(type, content, line, column);
  7464. }
  7465. function checkAttributeMatch(i) {
  7466. var l = void 0;
  7467. if (l = checkAttributeMatch1(i)) tokens[i].attributeMatchType = 1;else if (l = checkAttributeMatch2(i)) tokens[i].attributeMatchType = 2;
  7468. return l;
  7469. }
  7470. function getAttributeMatch() {
  7471. var type = tokens[pos].attributeMatchType;
  7472. if (type === 1) return getAttributeMatch1();else return getAttributeMatch2();
  7473. }
  7474. function checkAttributeMatch1(i) {
  7475. var start = i;
  7476. var type = tokens[i].type;
  7477. if (type === TokenType.Tilde || type === TokenType.VerticalLine || type === TokenType.CircumflexAccent || type === TokenType.DollarSign || type === TokenType.Asterisk) i++;else return 0;
  7478. if (tokens[i].type === TokenType.EqualsSign) i++;else return 0;
  7479. return i - start;
  7480. }
  7481. function getAttributeMatch1() {
  7482. var type = NodeType.AttributeMatchType;
  7483. var token = tokens[pos];
  7484. var line = token.ln;
  7485. var column = token.col;
  7486. var content = tokens[pos].value + tokens[pos + 1].value;
  7487. pos += 2;
  7488. return newNode(type, content, line, column);
  7489. }
  7490. function checkAttributeMatch2(i) {
  7491. if (tokens[i].type === TokenType.EqualsSign) return 1;else return 0;
  7492. }
  7493. function getAttributeMatch2() {
  7494. var type = NodeType.AttributeMatchType;
  7495. var token = tokens[pos];
  7496. var line = token.ln;
  7497. var column = token.col;
  7498. var content = '=';
  7499. pos++;
  7500. return newNode(type, content, line, column);
  7501. }
  7502. function checkAttributeValue(i) {
  7503. return checkString(i) || checkIdent(i);
  7504. }
  7505. function getAttributeValue() {
  7506. var type = NodeType.AttributeValueType;
  7507. var token = tokens[pos];
  7508. var line = token.ln;
  7509. var column = token.col;
  7510. var content = [];
  7511. if (checkString(pos)) content.push(getString());else content.push(getIdent());
  7512. return newNode(type, content, line, column);
  7513. }
  7514. function checkAttributeFlags(i) {
  7515. return checkIdent(i);
  7516. }
  7517. function getAttributeFlags() {
  7518. var type = NodeType.AttributeFlagsType;
  7519. var token = tokens[pos];
  7520. var line = token.ln;
  7521. var column = token.col;
  7522. var content = [getIdent()];
  7523. return newNode(type, content, line, column);
  7524. }
  7525. function checkNamePrefix(i) {
  7526. if (i >= tokensLength) return 0;
  7527. var l = void 0;
  7528. if (l = checkNamePrefix1(i)) tokens[i].namePrefixType = 1;else if (l = checkNamePrefix2(i)) tokens[i].namePrefixType = 2;
  7529. return l;
  7530. }
  7531. function getNamePrefix() {
  7532. var type = tokens[pos].namePrefixType;
  7533. if (type === 1) return getNamePrefix1();else return getNamePrefix2();
  7534. }
  7535. /**
  7536. * (1) `panda|`
  7537. * (2) `panda<comment>|`
  7538. */
  7539. function checkNamePrefix1(i) {
  7540. var start = i;
  7541. var l = void 0;
  7542. if (l = checkNamespacePrefix(i)) i += l;else return 0;
  7543. if (l = checkCommentML(i)) i += l;
  7544. if (l = checkNamespaceSeparator(i)) i += l;else return 0;
  7545. return i - start;
  7546. }
  7547. function getNamePrefix1() {
  7548. var type = NodeType.NamePrefixType;
  7549. var token = tokens[pos];
  7550. var line = token.ln;
  7551. var column = token.col;
  7552. var content = [];
  7553. content.push(getNamespacePrefix());
  7554. if (checkCommentML(pos)) content.push(getCommentML());
  7555. content.push(getNamespaceSeparator());
  7556. return newNode(type, content, line, column);
  7557. }
  7558. /**
  7559. * (1) `|`
  7560. */
  7561. function checkNamePrefix2(i) {
  7562. return checkNamespaceSeparator(i);
  7563. }
  7564. function getNamePrefix2() {
  7565. var type = NodeType.NamePrefixType;
  7566. var token = tokens[pos];
  7567. var line = token.ln;
  7568. var column = token.col;
  7569. var content = [getNamespaceSeparator()];
  7570. return newNode(type, content, line, column);
  7571. }
  7572. /**
  7573. * (1) `*`
  7574. * (2) `panda`
  7575. */
  7576. function checkNamespacePrefix(i) {
  7577. if (i >= tokensLength) return 0;
  7578. var l = void 0;
  7579. if (tokens[i].type === TokenType.Asterisk) return 1;else if (l = checkIdent(i)) return l;else return 0;
  7580. }
  7581. function getNamespacePrefix() {
  7582. var type = NodeType.NamespacePrefixType;
  7583. var token = tokens[pos];
  7584. var line = token.ln;
  7585. var column = token.col;
  7586. var content = [];
  7587. if (token.type === TokenType.Asterisk) {
  7588. var asteriskNode = newNode(NodeType.IdentType, '*', line, column);
  7589. content.push(asteriskNode);
  7590. pos++;
  7591. } else if (checkIdent(pos)) content.push(getIdent());
  7592. return newNode(type, content, line, column);
  7593. }
  7594. /**
  7595. * (1) `|`
  7596. */
  7597. function checkNamespaceSeparator(i) {
  7598. if (i >= tokensLength) return 0;
  7599. if (tokens[i].type !== TokenType.VerticalLine) return 0;
  7600. // Return false if `|=` - [attr|=value]
  7601. if (tokens[i + 1] && tokens[i + 1].type === TokenType.EqualsSign) return 0;
  7602. return 1;
  7603. }
  7604. function getNamespaceSeparator() {
  7605. var type = NodeType.NamespaceSeparatorType;
  7606. var token = tokens[pos];
  7607. var line = token.ln;
  7608. var column = token.col;
  7609. var content = '|';
  7610. pos++;
  7611. return newNode(type, content, line, column);
  7612. }
  7613. module.exports = function (_tokens, context) {
  7614. tokens = _tokens;
  7615. tokensLength = tokens.length;
  7616. pos = 0;
  7617. return contexts[context]();
  7618. };
  7619. /***/ }),
  7620. /* 20 */
  7621. /***/ (function(module, exports, __webpack_require__) {
  7622. 'use strict';
  7623. module.exports = function (css, tabSize) {
  7624. var TokenType = __webpack_require__(13);
  7625. var tokens = [];
  7626. var urlMode = false;
  7627. var c = void 0; // Current character
  7628. var cn = void 0; // Next character
  7629. var pos = 0;
  7630. var tn = 0;
  7631. var ln = 1;
  7632. var col = 1;
  7633. var Punctuation = {
  7634. ' ': TokenType.Space,
  7635. '\n': TokenType.Newline,
  7636. '\r': TokenType.Newline,
  7637. '\t': TokenType.Tab,
  7638. '!': TokenType.ExclamationMark,
  7639. '"': TokenType.QuotationMark,
  7640. '#': TokenType.NumberSign,
  7641. '$': TokenType.DollarSign,
  7642. '%': TokenType.PercentSign,
  7643. '&': TokenType.Ampersand,
  7644. '\'': TokenType.Apostrophe,
  7645. '(': TokenType.LeftParenthesis,
  7646. ')': TokenType.RightParenthesis,
  7647. '*': TokenType.Asterisk,
  7648. '+': TokenType.PlusSign,
  7649. ',': TokenType.Comma,
  7650. '-': TokenType.HyphenMinus,
  7651. '.': TokenType.FullStop,
  7652. '/': TokenType.Solidus,
  7653. ':': TokenType.Colon,
  7654. ';': TokenType.Semicolon,
  7655. '<': TokenType.LessThanSign,
  7656. '=': TokenType.EqualsSign,
  7657. '>': TokenType.GreaterThanSign,
  7658. '?': TokenType.QuestionMark,
  7659. '@': TokenType.CommercialAt,
  7660. '[': TokenType.LeftSquareBracket,
  7661. ']': TokenType.RightSquareBracket,
  7662. '^': TokenType.CircumflexAccent,
  7663. '_': TokenType.LowLine,
  7664. '{': TokenType.LeftCurlyBracket,
  7665. '|': TokenType.VerticalLine,
  7666. '}': TokenType.RightCurlyBracket,
  7667. '~': TokenType.Tilde
  7668. };
  7669. /**
  7670. * Add a token to the token list
  7671. * @param {string} type
  7672. * @param {string} value
  7673. */
  7674. function pushToken(type, value, column) {
  7675. tokens.push({
  7676. tn: tn++,
  7677. ln: ln,
  7678. col: column,
  7679. type: type,
  7680. value: value
  7681. });
  7682. }
  7683. /**
  7684. * Check if a character is a decimal digit
  7685. * @param {string} c Character
  7686. * @returns {boolean}
  7687. */
  7688. function isDecimalDigit(c) {
  7689. return '0123456789'.indexOf(c) >= 0;
  7690. }
  7691. /**
  7692. * Parse spaces
  7693. * @param {string} css Unparsed part of CSS string
  7694. */
  7695. function parseSpaces(css) {
  7696. var start = pos;
  7697. // Read the string until we meet a non-space character:
  7698. for (; pos < css.length; pos++) {
  7699. if (css.charAt(pos) !== ' ') break;
  7700. }
  7701. // Add a substring containing only spaces to tokens:
  7702. pushToken(TokenType.Space, css.substring(start, pos--), col);
  7703. col += pos - start;
  7704. }
  7705. /**
  7706. * Parse a string within quotes
  7707. * @param {string} css Unparsed part of CSS string
  7708. * @param {string} q Quote (either `'` or `"`)
  7709. */
  7710. function parseString(css, q) {
  7711. var start = pos;
  7712. // Read the string until we meet a matching quote:
  7713. for (pos++; pos < css.length; pos++) {
  7714. // Skip escaped quotes:
  7715. if (css.charAt(pos) === '\\') pos++;else if (css.charAt(pos) === q) break;
  7716. }
  7717. // Add the string (including quotes) to tokens:
  7718. var type = q === '"' ? TokenType.StringDQ : TokenType.StringSQ;
  7719. pushToken(type, css.substring(start, pos + 1), col);
  7720. col += pos - start;
  7721. }
  7722. /**
  7723. * Parse numbers
  7724. * @param {string} css Unparsed part of CSS string
  7725. */
  7726. function parseDecimalNumber(css) {
  7727. var start = pos;
  7728. // Read the string until we meet a character that's not a digit:
  7729. for (; pos < css.length; pos++) {
  7730. if (!isDecimalDigit(css.charAt(pos))) break;
  7731. }
  7732. // Add the number to tokens:
  7733. pushToken(TokenType.DecimalNumber, css.substring(start, pos--), col);
  7734. col += pos - start;
  7735. }
  7736. /**
  7737. * Parse identifier
  7738. * @param {string} css Unparsed part of CSS string
  7739. */
  7740. function parseIdentifier(css) {
  7741. var start = pos;
  7742. // Skip all opening slashes:
  7743. while (css.charAt(pos) === '/') {
  7744. pos++;
  7745. } // Read the string until we meet a punctuation mark:
  7746. for (; pos < css.length; pos++) {
  7747. // Skip all '\':
  7748. if (css.charAt(pos) === '\\') pos++;else if (css.charAt(pos) in Punctuation) break;
  7749. }
  7750. var ident = css.substring(start, pos--);
  7751. // Enter url mode if parsed substring is `url`:
  7752. if (!urlMode && ident === 'url' && css.charAt(pos + 1) === '(') {
  7753. urlMode = true;
  7754. }
  7755. // Add identifier to tokens:
  7756. pushToken(TokenType.Identifier, ident, col);
  7757. col += pos - start;
  7758. }
  7759. /**
  7760. * Parse a multiline comment
  7761. * @param {string} css Unparsed part of CSS string
  7762. */
  7763. function parseMLComment(css) {
  7764. var start = pos;
  7765. // Read the string until we meet `*/`.
  7766. // Since we already know first 2 characters (`/*`), start reading
  7767. // from `pos + 2`:
  7768. for (pos = pos + 2; pos < css.length; pos++) {
  7769. if (css.charAt(pos) === '*' && css.charAt(pos + 1) === '/') {
  7770. pos++;
  7771. break;
  7772. }
  7773. }
  7774. // Add full comment (including `/*` and `*/`) to the list of tokens:
  7775. var comment = css.substring(start, pos + 1);
  7776. pushToken(TokenType.CommentML, comment, col);
  7777. var newlines = comment.split('\n');
  7778. if (newlines.length > 1) {
  7779. ln += newlines.length - 1;
  7780. col = newlines[newlines.length - 1].length;
  7781. } else {
  7782. col += pos - start;
  7783. }
  7784. }
  7785. /**
  7786. * Parse a single line comment
  7787. * @param {string} css Unparsed part of CSS string
  7788. */
  7789. function parseSLComment(css) {
  7790. var start = pos;
  7791. // Read the string until we meet line break.
  7792. // Since we already know first 2 characters (`//`), start reading
  7793. // from `pos + 2`:
  7794. for (pos += 2; pos < css.length; pos++) {
  7795. if (css.charAt(pos) === '\n' || css.charAt(pos) === '\r') {
  7796. break;
  7797. }
  7798. }
  7799. // Add comment (including `//` and line break) to the list of tokens:
  7800. pushToken(TokenType.CommentSL, css.substring(start, pos--), col);
  7801. col += pos - start;
  7802. }
  7803. /**
  7804. * Convert a CSS string to a list of tokens
  7805. * @param {string} css CSS string
  7806. * @returns {Array} List of tokens
  7807. * @private
  7808. */
  7809. function getTokens(css) {
  7810. // Parse string, character by character:
  7811. for (pos = 0; pos < css.length; col++, pos++) {
  7812. c = css.charAt(pos);
  7813. cn = css.charAt(pos + 1);
  7814. // If we meet `/*`, it's a start of a multiline comment.
  7815. // Parse following characters as a multiline comment:
  7816. if (c === '/' && cn === '*') {
  7817. parseMLComment(css);
  7818. }
  7819. // If we meet `//` and it is not a part of url:
  7820. else if (!urlMode && c === '/' && cn === '/') {
  7821. // If we're currently inside a block, treat `//` as a start
  7822. // of identifier. Else treat `//` as a start of a single-line
  7823. // comment:
  7824. parseSLComment(css);
  7825. }
  7826. // If current character is a double or single quote, it's a start
  7827. // of a string:
  7828. else if (c === '"' || c === "'") {
  7829. parseString(css, c);
  7830. }
  7831. // If current character is a space:
  7832. else if (c === ' ') {
  7833. parseSpaces(css);
  7834. }
  7835. // If current character is a punctuation mark:
  7836. else if (c in Punctuation) {
  7837. // Add it to the list of tokens:
  7838. pushToken(Punctuation[c], c, col);
  7839. if (c === '\n' || c === '\r') {
  7840. ln++;
  7841. col = 0;
  7842. } // Go to next line
  7843. if (c === ')') urlMode = false; // Exit url mode
  7844. else if (c === '\t' && tabSize > 1) col += tabSize - 1;
  7845. }
  7846. // If current character is a decimal digit:
  7847. else if (isDecimalDigit(c)) {
  7848. parseDecimalNumber(css);
  7849. }
  7850. // If current character is anything else:
  7851. else {
  7852. parseIdentifier(css);
  7853. }
  7854. }
  7855. return tokens;
  7856. }
  7857. return getTokens(css);
  7858. };
  7859. /***/ }),
  7860. /* 21 */
  7861. /***/ (function(module, exports, __webpack_require__) {
  7862. 'use strict';
  7863. exports.__esModule = true;
  7864. exports.default = {
  7865. mark: __webpack_require__(22),
  7866. parse: __webpack_require__(23),
  7867. stringify: __webpack_require__(5),
  7868. tokenizer: __webpack_require__(24)
  7869. };
  7870. module.exports = exports['default'];
  7871. /***/ }),
  7872. /* 22 */
  7873. /***/ (function(module, exports, __webpack_require__) {
  7874. 'use strict';
  7875. var TokenType = __webpack_require__(13);
  7876. module.exports = function () {
  7877. /**
  7878. * Mark whitespaces and comments
  7879. */
  7880. function markSC(tokens) {
  7881. var tokensLength = tokens.length;
  7882. var ws = -1; // Flag for whitespaces
  7883. var sc = -1; // Flag for whitespaces and comments
  7884. var t = void 0; // Current token
  7885. // For every token in the token list, mark spaces and line breaks
  7886. // as spaces (set both `ws` and `sc` flags). Mark multiline comments
  7887. // with `sc` flag.
  7888. // If there are several spaces or tabs or line breaks or multiline
  7889. // comments in a row, group them: take the last one's index number
  7890. // and save it to the first token in the group as a reference:
  7891. // e.g., `ws_last = 7` for a group of whitespaces or `sc_last = 9`
  7892. // for a group of whitespaces and comments.
  7893. for (var i = 0; i < tokensLength; i++) {
  7894. t = tokens[i];
  7895. switch (t.type) {
  7896. case TokenType.Space:
  7897. case TokenType.Tab:
  7898. t.ws = true;
  7899. t.sc = true;
  7900. if (ws === -1) ws = i;
  7901. if (sc === -1) sc = i;
  7902. break;
  7903. case TokenType.Newline:
  7904. t.ws = true;
  7905. t.sc = true;
  7906. ws = ws === -1 ? i : ws;
  7907. sc = sc === -1 ? i : ws;
  7908. tokens[ws].ws_last = i - 1;
  7909. tokens[sc].sc_last = i - 1;
  7910. tokens[i].ws_last = i;
  7911. tokens[i].sc_last = i;
  7912. ws = -1;
  7913. sc = -1;
  7914. break;
  7915. case TokenType.CommentML:
  7916. case TokenType.CommentSL:
  7917. if (ws !== -1) {
  7918. tokens[ws].ws_last = i - 1;
  7919. ws = -1;
  7920. }
  7921. t.sc = true;
  7922. break;
  7923. default:
  7924. if (ws !== -1) {
  7925. tokens[ws].ws_last = i - 1;
  7926. ws = -1;
  7927. }
  7928. if (sc !== -1) {
  7929. tokens[sc].sc_last = i - 1;
  7930. sc = -1;
  7931. }
  7932. }
  7933. }
  7934. if (ws !== -1) tokens[ws].ws_last = i - 1;
  7935. if (sc !== -1) tokens[sc].sc_last = i - 1;
  7936. }
  7937. /**
  7938. * Pair brackets
  7939. */
  7940. function markBrackets(tokens) {
  7941. var tokensLength = tokens.length;
  7942. var ps = []; // Parentheses
  7943. var sbs = []; // Square brackets
  7944. var cbs = []; // Curly brackets
  7945. var t = void 0; // Current token
  7946. // For every token in the token list, if we meet an opening (left)
  7947. // bracket, push its index number to a corresponding array.
  7948. // If we then meet a closing (right) bracket, look at the corresponding
  7949. // array. If there are any elements (records about previously met
  7950. // left brackets), take a token of the last left bracket (take
  7951. // the last index number from the array and find a token with
  7952. // this index number) and save right bracket's index as a reference:
  7953. for (var i = 0; i < tokensLength; i++) {
  7954. t = tokens[i];
  7955. switch (t.type) {
  7956. case TokenType.LeftParenthesis:
  7957. ps.push(i);
  7958. break;
  7959. case TokenType.RightParenthesis:
  7960. if (ps.length) {
  7961. t.left = ps.pop();
  7962. tokens[t.left].right = i;
  7963. }
  7964. break;
  7965. case TokenType.LeftSquareBracket:
  7966. sbs.push(i);
  7967. break;
  7968. case TokenType.RightSquareBracket:
  7969. if (sbs.length) {
  7970. t.left = sbs.pop();
  7971. tokens[t.left].right = i;
  7972. }
  7973. break;
  7974. case TokenType.LeftCurlyBracket:
  7975. cbs.push(i);
  7976. break;
  7977. case TokenType.RightCurlyBracket:
  7978. if (cbs.length) {
  7979. t.left = cbs.pop();
  7980. tokens[t.left].right = i;
  7981. }
  7982. break;
  7983. }
  7984. }
  7985. }
  7986. function markBlocks(tokens) {
  7987. var i = 0;
  7988. var l = tokens.length;
  7989. var lines = [];
  7990. var whitespaceOnlyLines = [];
  7991. for (i = 0; i < l; i++) {
  7992. var lineStart = i;
  7993. var currentLineIndent = 0;
  7994. // Get all spaces.
  7995. while (i < l && (tokens[i].type === TokenType.Space || tokens[i].type === TokenType.Tab)) {
  7996. currentLineIndent += tokens[i].value.length;
  7997. i++;
  7998. }
  7999. lines.push([lineStart, currentLineIndent]);
  8000. var x = i;
  8001. while (i < l && tokens[i].type !== TokenType.Newline) {
  8002. i++;
  8003. }
  8004. if (x === i) {
  8005. whitespaceOnlyLines.push(lines.length - 1);
  8006. }
  8007. }
  8008. var levels = [0];
  8009. var blockStarts = [];
  8010. for (i = 0; i < lines.length; i++) {
  8011. var line = lines[i];
  8012. var token = line[0];
  8013. var indent = line[1];
  8014. var lastLevel = levels[levels.length - 1];
  8015. if (indent > lastLevel) {
  8016. blockStarts.push(token);
  8017. levels.push(indent);
  8018. } else {
  8019. // Check if line is whitespace-only.
  8020. var p = i;
  8021. while (true) {
  8022. if (whitespaceOnlyLines.indexOf(p) === -1) break;
  8023. p++;
  8024. }
  8025. if (i === p && indent === lastLevel) continue;
  8026. if (!lines[p]) {
  8027. continue;
  8028. }
  8029. indent = lines[p][1];
  8030. if (indent === lastLevel) {
  8031. i = p;
  8032. continue;
  8033. }
  8034. if (indent > lastLevel) {
  8035. blockStarts.push(token);
  8036. levels.push(lines[p][1]);
  8037. i = p;
  8038. continue;
  8039. }
  8040. while (true) {
  8041. var _lastLevel = levels.pop();
  8042. if (indent < _lastLevel) {
  8043. var start = blockStarts.pop();
  8044. tokens[start].block_end = token - 1;
  8045. } else {
  8046. levels.push(indent);
  8047. break;
  8048. }
  8049. }
  8050. }
  8051. }
  8052. blockStarts.forEach(function (start) {
  8053. tokens[start].block_end = tokens.length - 1;
  8054. });
  8055. }
  8056. return function (tokens) {
  8057. markBrackets(tokens);
  8058. markSC(tokens);
  8059. markBlocks(tokens);
  8060. };
  8061. }();
  8062. /***/ }),
  8063. /* 23 */
  8064. /***/ (function(module, exports, __webpack_require__) {
  8065. 'use strict';
  8066. var Node = __webpack_require__(1);
  8067. var NodeType = __webpack_require__(15);
  8068. var TokenType = __webpack_require__(13);
  8069. var tokens = void 0;
  8070. var tokensLength = void 0;
  8071. var pos = void 0;
  8072. var contexts = {
  8073. 'arguments': function _arguments() {
  8074. return checkArguments(pos) && getArguments();
  8075. },
  8076. 'atkeyword': function atkeyword() {
  8077. return checkAtkeyword(pos) && getAtkeyword();
  8078. },
  8079. 'atrule': function atrule() {
  8080. return checkAtrule(pos) && getAtrule();
  8081. },
  8082. 'attributeSelector': function attributeSelector() {
  8083. return checkAttributeSelector(pos) && getAttributeSelector();
  8084. },
  8085. 'block': function block() {
  8086. return checkBlock(pos) && getBlock();
  8087. },
  8088. 'brackets': function brackets() {
  8089. return checkBrackets(pos) && getBrackets();
  8090. },
  8091. 'class': function _class() {
  8092. return checkClass(pos) && getClass();
  8093. },
  8094. 'combinator': function combinator() {
  8095. return checkCombinator(pos) && getCombinator();
  8096. },
  8097. 'commentML': function commentML() {
  8098. return checkCommentML(pos) && getCommentML();
  8099. },
  8100. 'commentSL': function commentSL() {
  8101. return checkCommentSL(pos) && getCommentSL();
  8102. },
  8103. 'condition': function condition() {
  8104. return checkCondition(pos) && getCondition();
  8105. },
  8106. 'conditionalStatement': function conditionalStatement() {
  8107. return checkConditionalStatement(pos) && getConditionalStatement();
  8108. },
  8109. 'declaration': function declaration() {
  8110. return checkDeclaration(pos) && getDeclaration();
  8111. },
  8112. 'declDelim': function declDelim() {
  8113. return checkDeclDelim(pos) && getDeclDelim();
  8114. },
  8115. 'default': function _default() {
  8116. return checkDefault(pos) && getDefault();
  8117. },
  8118. 'delim': function delim() {
  8119. return checkDelim(pos) && getDelim();
  8120. },
  8121. 'dimension': function dimension() {
  8122. return checkDimension(pos) && getDimension();
  8123. },
  8124. 'expression': function expression() {
  8125. return checkExpression(pos) && getExpression();
  8126. },
  8127. 'extend': function extend() {
  8128. return checkExtend(pos) && getExtend();
  8129. },
  8130. 'function': function _function() {
  8131. return checkFunction(pos) && getFunction();
  8132. },
  8133. 'global': function global() {
  8134. return checkGlobal(pos) && getGlobal();
  8135. },
  8136. 'ident': function ident() {
  8137. return checkIdent(pos) && getIdent();
  8138. },
  8139. 'important': function important() {
  8140. return checkImportant(pos) && getImportant();
  8141. },
  8142. 'include': function include() {
  8143. return checkInclude(pos) && getInclude();
  8144. },
  8145. 'interpolation': function interpolation() {
  8146. return checkInterpolation(pos) && getInterpolation();
  8147. },
  8148. 'loop': function loop() {
  8149. return checkLoop(pos) && getLoop();
  8150. },
  8151. 'mixin': function mixin() {
  8152. return checkMixin(pos) && getMixin();
  8153. },
  8154. 'namespace': function namespace() {
  8155. return checkNamespace(pos) && getNamespace();
  8156. },
  8157. 'number': function number() {
  8158. return checkNumber(pos) && getNumber();
  8159. },
  8160. 'operator': function operator() {
  8161. return checkOperator(pos) && getOperator();
  8162. },
  8163. 'optional': function optional() {
  8164. return checkOptional(pos) && getOptional();
  8165. },
  8166. 'parentheses': function parentheses() {
  8167. return checkParentheses(pos) && getParentheses();
  8168. },
  8169. 'parentselector': function parentselector() {
  8170. return checkParentSelector(pos) && getParentSelector();
  8171. },
  8172. 'percentage': function percentage() {
  8173. return checkPercentage(pos) && getPercentage();
  8174. },
  8175. 'placeholder': function placeholder() {
  8176. return checkPlaceholder(pos) && getPlaceholder();
  8177. },
  8178. 'progid': function progid() {
  8179. return checkProgid(pos) && getProgid();
  8180. },
  8181. 'property': function property() {
  8182. return checkProperty(pos) && getProperty();
  8183. },
  8184. 'propertyDelim': function propertyDelim() {
  8185. return checkPropertyDelim(pos) && getPropertyDelim();
  8186. },
  8187. 'pseudoc': function pseudoc() {
  8188. return checkPseudoc(pos) && getPseudoc();
  8189. },
  8190. 'pseudoe': function pseudoe() {
  8191. return checkPseudoe(pos) && getPseudoe();
  8192. },
  8193. 'ruleset': function ruleset() {
  8194. return checkRuleset(pos) && getRuleset();
  8195. },
  8196. 's': function s() {
  8197. return checkS(pos) && getS();
  8198. },
  8199. 'selector': function selector() {
  8200. return checkSelector(pos) && getSelector();
  8201. },
  8202. 'shash': function shash() {
  8203. return checkShash(pos) && getShash();
  8204. },
  8205. 'string': function string() {
  8206. return checkString(pos) && getString();
  8207. },
  8208. 'stylesheet': function stylesheet() {
  8209. return checkStylesheet(pos) && getStylesheet();
  8210. },
  8211. 'typeSelector': function typeSelector() {
  8212. return checkTypeSelector(pos) && getTypeSelector();
  8213. },
  8214. 'unary': function unary() {
  8215. return checkUnary(pos) && getUnary();
  8216. },
  8217. 'unicodeRange': function unicodeRange() {
  8218. return checkUnicodeRange(pos) && getUnicodeRange();
  8219. },
  8220. 'universalSelector': function universalSelector() {
  8221. return checkUniversalSelector(pos) && getUniversalSelector();
  8222. },
  8223. 'urange': function urange() {
  8224. return checkUrange(pos) && getUrange();
  8225. },
  8226. 'uri': function uri() {
  8227. return checkUri(pos) && getUri();
  8228. },
  8229. 'value': function value() {
  8230. return checkValue(pos) && getValue();
  8231. },
  8232. 'variable': function variable() {
  8233. return checkVariable(pos) && getVariable();
  8234. },
  8235. 'variableslist': function variableslist() {
  8236. return checkVariablesList(pos) && getVariablesList();
  8237. },
  8238. 'vhash': function vhash() {
  8239. return checkVhash(pos) && getVhash();
  8240. }
  8241. };
  8242. /**
  8243. * Stops parsing and display error.
  8244. *
  8245. * @param {number=} i Token's index number
  8246. */
  8247. function throwError(i) {
  8248. var ln = tokens[i].ln;
  8249. throw { line: ln, syntax: 'sass' };
  8250. }
  8251. /**
  8252. * @param {number} start
  8253. * @param {number} finish
  8254. * @return {string}
  8255. */
  8256. function joinValues(start, finish) {
  8257. var s = '';
  8258. for (var i = start; i < finish + 1; i++) {
  8259. s += tokens[i].value;
  8260. }
  8261. return s;
  8262. }
  8263. /**
  8264. * @param {number} start
  8265. * @param {number} num
  8266. * @return {string}
  8267. */
  8268. function joinValues2(start, num) {
  8269. if (start + num - 1 >= tokensLength) return;
  8270. var s = '';
  8271. for (var i = 0; i < num; i++) {
  8272. s += tokens[start + i].value;
  8273. }
  8274. return s;
  8275. }
  8276. /**
  8277. * @param {string|!Array} content
  8278. * @param {number} line
  8279. * @param {number} column
  8280. * @param {number} colOffset
  8281. */
  8282. function getLastPosition(content, line, column, colOffset) {
  8283. return typeof content === 'string' ? getLastPositionForString(content, line, column, colOffset) : getLastPositionForArray(content, line, column, colOffset);
  8284. }
  8285. /**
  8286. * @param {string} content
  8287. * @param {number} line
  8288. * @param {number} column
  8289. * @param {number} colOffset
  8290. */
  8291. function getLastPositionForString(content, line, column, colOffset) {
  8292. var position = [];
  8293. if (!content) {
  8294. position = [line, column];
  8295. if (colOffset) position[1] += colOffset - 1;
  8296. return position;
  8297. }
  8298. var lastLinebreak = content.lastIndexOf('\n');
  8299. var endsWithLinebreak = lastLinebreak === content.length - 1;
  8300. var splitContent = content.split('\n');
  8301. var linebreaksCount = splitContent.length - 1;
  8302. var prevLinebreak = linebreaksCount === 0 || linebreaksCount === 1 ? -1 : content.length - splitContent[linebreaksCount - 1].length - 2;
  8303. // Line:
  8304. var offset = endsWithLinebreak ? linebreaksCount - 1 : linebreaksCount;
  8305. position[0] = line + offset;
  8306. // Column:
  8307. if (endsWithLinebreak) {
  8308. offset = prevLinebreak !== -1 ? content.length - prevLinebreak : content.length - 1;
  8309. } else {
  8310. offset = linebreaksCount !== 0 ? content.length - lastLinebreak - column - 1 : content.length - 1;
  8311. }
  8312. position[1] = column + offset;
  8313. if (!colOffset) return position;
  8314. if (endsWithLinebreak) {
  8315. position[0]++;
  8316. position[1] = colOffset;
  8317. } else {
  8318. position[1] += colOffset;
  8319. }
  8320. return position;
  8321. }
  8322. /**
  8323. * @param {!Array} content
  8324. * @param {number} line
  8325. * @param {number} column
  8326. * @param {number} colOffset
  8327. */
  8328. function getLastPositionForArray(content, line, column, colOffset) {
  8329. var position = void 0;
  8330. if (content.length === 0) {
  8331. position = [line, column];
  8332. } else {
  8333. var c = content[content.length - 1];
  8334. if (c.hasOwnProperty('end')) {
  8335. position = [c.end.line, c.end.column];
  8336. } else {
  8337. position = getLastPosition(c.content, line, column);
  8338. }
  8339. }
  8340. if (!colOffset) return position;
  8341. if (tokens[pos - 1] && tokens[pos - 1].type !== 'Newline') {
  8342. position[1] += colOffset;
  8343. } else {
  8344. position[0]++;
  8345. position[1] = 1;
  8346. }
  8347. return position;
  8348. }
  8349. /**
  8350. * @param {string} type
  8351. * @param {string|!Array} content
  8352. * @param {number} line
  8353. * @param {number} column
  8354. * @param {!Array} end
  8355. */
  8356. function newNode(type, content, line, column, end) {
  8357. if (!end) end = getLastPosition(content, line, column);
  8358. return new Node({
  8359. type: type,
  8360. content: content,
  8361. start: {
  8362. line: line,
  8363. column: column
  8364. },
  8365. end: {
  8366. line: end[0],
  8367. column: end[1]
  8368. },
  8369. syntax: 'sass'
  8370. });
  8371. }
  8372. /**
  8373. * @param {number} i Token's index number
  8374. * @return {number}
  8375. */
  8376. function checkAny(i) {
  8377. var l = void 0;
  8378. if (l = checkBrackets(i)) tokens[i].any_child = 1;else if (l = checkParentheses(i)) tokens[i].any_child = 2;else if (l = checkString(i)) tokens[i].any_child = 3;else if (l = checkVariablesList(i)) tokens[i].any_child = 4;else if (l = checkVariable(i)) tokens[i].any_child = 5;else if (l = checkPlaceholder(i)) tokens[i].any_child = 6;else if (l = checkPercentage(i)) tokens[i].any_child = 7;else if (l = checkDimension(i)) tokens[i].any_child = 8;else if (l = checkUnicodeRange(i)) tokens[i].any_child = 9;else if (l = checkNumber(i)) tokens[i].any_child = 10;else if (l = checkUri(i)) tokens[i].any_child = 11;else if (l = checkExpression(i)) tokens[i].any_child = 12;else if (l = checkFunctionsList(i)) tokens[i].any_child = 13;else if (l = checkFunction(i)) tokens[i].any_child = 14;else if (l = checkInterpolation(i)) tokens[i].any_child = 15;else if (l = checkIdent(i)) tokens[i].any_child = 16;else if (l = checkClass(i)) tokens[i].any_child = 17;else if (l = checkUnary(i)) tokens[i].any_child = 18;else if (l = checkParentSelector(i)) tokens[i].any_child = 19;else if (l = checkImportant(i)) tokens[i].any_child = 20;else if (l = checkGlobal(i)) tokens[i].any_child = 21;else if (l = checkDefault(i)) tokens[i].any_child = 22;else if (l = checkOptional(i)) tokens[i].any_child = 23;
  8379. return l;
  8380. }
  8381. /**
  8382. * @return {!Node}
  8383. */
  8384. function getAny() {
  8385. var childType = tokens[pos].any_child;
  8386. if (childType === 1) return getBrackets();
  8387. if (childType === 2) return getParentheses();
  8388. if (childType === 3) return getString();
  8389. if (childType === 4) return getVariablesList();
  8390. if (childType === 5) return getVariable();
  8391. if (childType === 6) return getPlaceholder();
  8392. if (childType === 7) return getPercentage();
  8393. if (childType === 8) return getDimension();
  8394. if (childType === 9) return getUnicodeRange();
  8395. if (childType === 10) return getNumber();
  8396. if (childType === 11) return getUri();
  8397. if (childType === 12) return getExpression();
  8398. if (childType === 13) return getFunctionsList();
  8399. if (childType === 14) return getFunction();
  8400. if (childType === 15) return getInterpolation();
  8401. if (childType === 16) return getIdent();
  8402. if (childType === 17) return getClass();
  8403. if (childType === 18) return getUnary();
  8404. if (childType === 19) return getParentSelector();
  8405. if (childType === 20) return getImportant();
  8406. if (childType === 21) return getGlobal();
  8407. if (childType === 22) return getDefault();
  8408. if (childType === 23) return getOptional();
  8409. }
  8410. /**
  8411. * Checks if token is part of mixin's arguments.
  8412. *
  8413. * @param {number} i Token's index number
  8414. * @return {number} Length of arguments
  8415. */
  8416. function checkArguments(i) {
  8417. var start = i;
  8418. var l = void 0;
  8419. if (i >= tokensLength || tokens[i].type !== TokenType.LeftParenthesis) return 0;
  8420. // Skip `(`.
  8421. i++;
  8422. while (i < tokens[start].right) {
  8423. if (l = checkArgument(i)) i += l;else return 0;
  8424. }
  8425. return tokens[start].right - start + 1;
  8426. }
  8427. /**
  8428. * @return {Array}
  8429. */
  8430. function getArguments() {
  8431. var type = NodeType.ArgumentsType;
  8432. var token = tokens[pos];
  8433. var line = token.ln;
  8434. var column = token.col;
  8435. var content = [];
  8436. var body = void 0;
  8437. // Skip `(`.
  8438. pos++;
  8439. while (pos < tokensLength && tokens[pos].type !== TokenType.RightParenthesis) {
  8440. if (checkSingleValueDeclaration(pos)) {
  8441. content.push(getSingleValueDeclaration());
  8442. } else if (checkArgument(pos)) {
  8443. body = getArgument();
  8444. if (typeof body.content === 'string') content.push(body);else content = content.concat(body);
  8445. } else if (checkClass(pos)) content.push(getClass());else throwError(pos);
  8446. }
  8447. var end = getLastPosition(content, line, column, 1);
  8448. // Skip `)`.
  8449. pos++;
  8450. return newNode(type, content, line, column, end);
  8451. }
  8452. /**
  8453. * Checks if token is valid to be part of arguments list
  8454. * @param {number} i Token's index number
  8455. * @return {number} Length of argument
  8456. */
  8457. function checkArgument(i) {
  8458. var l = void 0;
  8459. if (l = checkBrackets(i)) tokens[i].argument_child = 1;else if (l = checkParentheses(i)) tokens[i].argument_child = 2;else if (l = checkSingleValueDeclaration(i)) tokens[i].argument_child = 3;else if (l = checkFunctionsList(i)) tokens[i].argument_child = 4;else if (l = checkFunction(i)) tokens[i].argument_child = 5;else if (l = checkVariablesList(i)) tokens[i].argument_child = 6;else if (l = checkVariable(i)) tokens[i].argument_child = 7;else if (l = checkSC(i)) tokens[i].argument_child = 8;else if (l = checkDelim(i)) tokens[i].argument_child = 9;else if (l = checkDeclDelim(i)) tokens[i].argument_child = 10;else if (l = checkString(i)) tokens[i].argument_child = 11;else if (l = checkPercentage(i)) tokens[i].argument_child = 12;else if (l = checkDimension(i)) tokens[i].argument_child = 13;else if (l = checkNumber(i)) tokens[i].argument_child = 14;else if (l = checkUri(i)) tokens[i].argument_child = 15;else if (l = checkInterpolation(i)) tokens[i].argument_child = 16;else if (l = checkIdent(i)) tokens[i].argument_child = 17;else if (l = checkVhash(i)) tokens[i].argument_child = 18;else if (l = checkCustomProperty(i)) tokens[i].argument_child = 19;else if (l = checkOperator(i)) tokens[i].argument_child = 20;else if (l = checkUnary(i)) tokens[i].argument_child = 21;else if (l = checkParentSelector(i)) tokens[i].argument_child = 22;else if (l = checkImportant(i)) tokens[i].argument_child = 23;else if (l = checkGlobal(i)) tokens[i].argument_child = 24;else if (l = checkDefault(i)) tokens[i].argument_child = 25;else if (l = checkOptional(i)) tokens[i].argument_child = 26;
  8460. return l;
  8461. }
  8462. /**
  8463. * @return {!Node}
  8464. */
  8465. function getArgument() {
  8466. var childType = tokens[pos].argument_child;
  8467. if (childType === 1) return getBrackets();
  8468. if (childType === 2) return getParentheses();
  8469. if (childType === 3) return getSingleValueDeclaration();
  8470. if (childType === 4) return getFunctionsList();
  8471. if (childType === 5) return getFunction();
  8472. if (childType === 6) return getVariablesList();
  8473. if (childType === 7) return getVariable();
  8474. if (childType === 8) return getSC();
  8475. if (childType === 9) return getDelim();
  8476. if (childType === 10) return getDeclDelim();
  8477. if (childType === 11) return getString();
  8478. if (childType === 12) return getPercentage();
  8479. if (childType === 13) return getDimension();
  8480. if (childType === 14) return getNumber();
  8481. if (childType === 15) return getUri();
  8482. if (childType === 16) return getInterpolation();
  8483. if (childType === 17) return getIdent();
  8484. if (childType === 18) return getVhash();
  8485. if (childType === 19) return getCustomProperty();
  8486. if (childType === 20) return getOperator();
  8487. if (childType === 21) return getUnary();
  8488. if (childType === 22) return getParentSelector();
  8489. if (childType === 23) return getImportant();
  8490. if (childType === 24) return getGlobal();
  8491. if (childType === 25) return getDefault();
  8492. if (childType === 26) return getOptional();
  8493. }
  8494. /**
  8495. * Checks if token is part of an @-word (e.g. `@import`, `@include`).
  8496. *
  8497. * @param {number} i Token's index number
  8498. * @return {number}
  8499. */
  8500. function checkAtkeyword(i) {
  8501. var l = void 0;
  8502. // Check that token is `@`:
  8503. if (i >= tokensLength || tokens[i++].type !== TokenType.CommercialAt) return 0;
  8504. return (l = checkIdentOrInterpolation(i)) ? l + 1 : 0;
  8505. }
  8506. /**
  8507. * Gets node with @-word.
  8508. *
  8509. * @return {!Node}
  8510. */
  8511. function getAtkeyword() {
  8512. var type = NodeType.AtkeywordType;
  8513. var token = tokens[pos];
  8514. var line = token.ln;
  8515. var column = token.col;
  8516. // Skip `@`.
  8517. pos++;
  8518. var content = getIdentOrInterpolation();
  8519. return newNode(type, content, line, column);
  8520. }
  8521. /**
  8522. * Checks if token is a part of an @-rule.
  8523. *
  8524. * @param {number} i Token's index number
  8525. * @return {number} Length of @-rule
  8526. */
  8527. function checkAtrule(i) {
  8528. var l = void 0;
  8529. if (i >= tokensLength) return 0;
  8530. // If token already has a record of being part of an @-rule,
  8531. // return the @-rule's length:
  8532. if (tokens[i].atrule_l !== undefined) return tokens[i].atrule_l;
  8533. // If token is part of an @-rule, save the rule's type to token.
  8534. // @keyframes:
  8535. if (l = checkKeyframesRule(i)) tokens[i].atrule_type = 4;
  8536. // @-rule with ruleset:
  8537. else if (l = checkAtruler(i)) tokens[i].atrule_type = 1;
  8538. // Block @-rule:
  8539. else if (l = checkAtruleb(i)) tokens[i].atrule_type = 2;
  8540. // Single-line @-rule:
  8541. else if (l = checkAtrules(i)) tokens[i].atrule_type = 3;else return 0;
  8542. // If token is part of an @-rule, save the rule's length to token:
  8543. tokens[i].atrule_l = l;
  8544. return l;
  8545. }
  8546. /**
  8547. * Gets node with @-rule.
  8548. *
  8549. * @return {!Node}
  8550. */
  8551. function getAtrule() {
  8552. var childType = tokens[pos].atrule_type;
  8553. if (childType === 1) return getAtruler(); // @-rule with ruleset
  8554. if (childType === 2) return getAtruleb(); // Block @-rule
  8555. if (childType === 3) return getAtrules(); // Single-line @-rule
  8556. if (childType === 4) return getKeyframesRule();
  8557. }
  8558. /**
  8559. * Checks if token is part of a block @-rule.
  8560. *
  8561. * @param {number} i Token's index number
  8562. * @return {number} Length of the @-rule
  8563. */
  8564. function checkAtruleb(i) {
  8565. var start = i;
  8566. var l = void 0;
  8567. if (i >= tokensLength) return 0;
  8568. if (l = checkAtkeyword(i)) i += l;else return 0;
  8569. if (l = checkTsets(i)) i += l;
  8570. if (l = checkBlock(i)) i += l;else return 0;
  8571. return i - start;
  8572. }
  8573. /**
  8574. * Gets node with a block @-rule.
  8575. *
  8576. * @return {!Node}
  8577. */
  8578. function getAtruleb() {
  8579. var type = NodeType.AtruleType;
  8580. var token = tokens[pos];
  8581. var line = token.ln;
  8582. var column = token.col;
  8583. var content = [].concat(getAtkeyword(), getTsets(), getBlock());
  8584. return newNode(type, content, line, column);
  8585. }
  8586. /**
  8587. * Checks if token is part of an @-rule with ruleset.
  8588. *
  8589. * @param {number} i Token's index number
  8590. * @return {number} Length of the @-rule
  8591. */
  8592. function checkAtruler(i) {
  8593. var start = i;
  8594. var l = void 0;
  8595. if (i >= tokensLength) return 0;
  8596. if (l = checkAtkeyword(i)) i += l;else return 0;
  8597. if (l = checkTsets(i)) i += l;
  8598. if (l = checkAtrulers(i)) i += l;else return 0;
  8599. return i - start;
  8600. }
  8601. /**
  8602. * Gets node with an @-rule with ruleset.
  8603. *
  8604. * @return {!Node}
  8605. */
  8606. function getAtruler() {
  8607. var type = NodeType.AtruleType;
  8608. var token = tokens[pos];
  8609. var line = token.ln;
  8610. var column = token.col;
  8611. var content = [].concat(getAtkeyword(), getTsets(), getAtrulers());
  8612. return newNode(type, content, line, column);
  8613. }
  8614. /**
  8615. * @param {number} i Token's index number
  8616. * @return {number}
  8617. */
  8618. function checkAtrulers(i) {
  8619. var start = i;
  8620. var l = void 0;
  8621. if (i >= tokensLength) return 0;
  8622. var blockEnd = tokens[i].block_end;
  8623. if (!blockEnd) return 0;
  8624. while (i < blockEnd) {
  8625. if (l = checkSC(i)) tokens[i].atrulers_child = 1;else if (l = checkAtrule(i)) tokens[i].atrulers_child = 2;else if (l = checkRuleset(i)) tokens[i].atrulers_child = 3;else return 0;
  8626. i += l;
  8627. }
  8628. if (i < tokensLength) tokens[i].atrulers_end = 1;
  8629. return i - start;
  8630. }
  8631. /**
  8632. * @return {!Node}
  8633. */
  8634. function getAtrulers() {
  8635. var type = NodeType.BlockType;
  8636. var token = tokens[pos];
  8637. var line = token.ln;
  8638. var column = token.col;
  8639. var content = getSC();
  8640. while (pos < tokensLength && !tokens[pos].atrulers_end) {
  8641. var childType = tokens[pos].atrulers_child;
  8642. if (childType === 1) content = content.concat(getSC());else if (childType === 2) content.push(getAtrule());else if (childType === 3) content.push(getRuleset());else break;
  8643. }
  8644. var end = getLastPosition(content, line, column);
  8645. return newNode(type, content, line, column, end);
  8646. }
  8647. /**
  8648. * @param {number} i Token's index number
  8649. * @return {number}
  8650. */
  8651. function checkAtrules(i) {
  8652. var start = i;
  8653. var l = void 0;
  8654. if (i >= tokensLength) return 0;
  8655. if (l = checkAtkeyword(i)) i += l;else return 0;
  8656. if (l = checkTsets(i)) i += l;
  8657. return i - start;
  8658. }
  8659. /**
  8660. * @return {!Node}
  8661. */
  8662. function getAtrules() {
  8663. var type = NodeType.AtruleType;
  8664. var token = tokens[pos];
  8665. var line = token.ln;
  8666. var column = token.col;
  8667. var content = [].concat(getAtkeyword(), getTsets());
  8668. return newNode(type, content, line, column);
  8669. }
  8670. /**
  8671. * Checks if token is part of a block (e.g. `{...}`).
  8672. *
  8673. * @param {number} i Token's index number
  8674. * @return {number} Length of the block
  8675. */
  8676. function checkBlock(i) {
  8677. return i < tokensLength && tokens[i].block_end ? tokens[i].block_end - i + 1 : 0;
  8678. }
  8679. /**
  8680. * Gets node with a block.
  8681. *
  8682. * @return {!Node}
  8683. */
  8684. function getBlock() {
  8685. var type = NodeType.BlockType;
  8686. var token = tokens[pos];
  8687. var line = token.ln;
  8688. var column = token.col;
  8689. var end = tokens[pos].block_end;
  8690. var content = [];
  8691. while (pos < end) {
  8692. if (checkBlockdecl(pos)) content = content.concat(getBlockdecl());else throwError(pos);
  8693. }
  8694. return newNode(type, content, line, column);
  8695. }
  8696. /**
  8697. * Checks if token is part of a declaration (property-value pair).
  8698. *
  8699. * @param {number} i Token's index number
  8700. * @return {number} Length of the declaration
  8701. */
  8702. function checkBlockdecl(i) {
  8703. var l = void 0;
  8704. if (i >= tokensLength) return 0;
  8705. if (l = checkBlockdecl7(i)) tokens[i].bd_type = 7;else if (l = checkBlockdecl5(i)) tokens[i].bd_type = 5;else if (l = checkBlockdecl6(i)) tokens[i].bd_type = 6;else if (l = checkBlockdecl1(i)) tokens[i].bd_type = 1;else if (l = checkBlockdecl2(i)) tokens[i].bd_type = 2;else if (l = checkBlockdecl3(i)) tokens[i].bd_type = 3;else if (l = checkBlockdecl4(i)) tokens[i].bd_type = 4;else return 0;
  8706. return l;
  8707. }
  8708. /**
  8709. * @return {!Array}
  8710. */
  8711. function getBlockdecl() {
  8712. var childType = tokens[pos].bd_type;
  8713. if (childType === 1) return getBlockdecl1();
  8714. if (childType === 2) return getBlockdecl2();
  8715. if (childType === 3) return getBlockdecl3();
  8716. if (childType === 4) return getBlockdecl4();
  8717. if (childType === 5) return getBlockdecl5();
  8718. if (childType === 6) return getBlockdecl6();
  8719. if (childType === 7) return getBlockdecl7();
  8720. }
  8721. /**
  8722. * @param {number} i Token's index number
  8723. * @return {number}
  8724. */
  8725. function checkBlockdecl1(i) {
  8726. var start = i;
  8727. var l = void 0;
  8728. if (l = checkInclude(i)) tokens[i].bd_kind = 2;else if (l = checkDeclaration(i)) tokens[i].bd_kind = 5;else if (l = checkAtrule(i)) tokens[i].bd_kind = 6;else return 0;
  8729. i += l;
  8730. if (tokens[start].bd_kind === 2 && [2, 4, 6, 8].indexOf(tokens[start].include_type) === -1) return 0;
  8731. if (tokens[start].bd_kind === 6 && tokens[start].atrule_type === 3) return 0;
  8732. while (i < tokensLength) {
  8733. if (l = checkDeclDelim(i)) return i + l - start;
  8734. if (l = checkS(i)) i += l;else if (l = checkCommentSL(i)) i += l;else break;
  8735. }
  8736. return 0;
  8737. }
  8738. /**
  8739. * @return {!Array}
  8740. */
  8741. function getBlockdecl1() {
  8742. var content = [];
  8743. var _content = [];
  8744. switch (tokens[pos].bd_kind) {
  8745. case 2:
  8746. content.push(getInclude());
  8747. break;
  8748. case 5:
  8749. content.push(getDeclaration());
  8750. break;
  8751. case 6:
  8752. content.push(getAtrule());
  8753. break;
  8754. }
  8755. while (pos < tokensLength) {
  8756. var _pos = pos;
  8757. if (checkDeclDelim(pos)) {
  8758. _content.push(getDeclDelim());
  8759. content = content.concat(_content);
  8760. break;
  8761. }
  8762. if (checkS(pos)) _content.push(getS());else if (checkCommentSL(pos)) _content.push(getCommentSL());else {
  8763. pos = _pos;
  8764. break;
  8765. }
  8766. }
  8767. return content;
  8768. }
  8769. /**
  8770. * @param {number} i Token's index number
  8771. * @return {number}
  8772. */
  8773. function checkBlockdecl2(i) {
  8774. var start = i;
  8775. var l = void 0;
  8776. if (l = checkConditionalStatement(i)) tokens[i].bd_kind = 1;else if (l = checkInclude(i)) tokens[i].bd_kind = 2;else if (l = checkExtend(i)) tokens[i].bd_kind = 4;else if (l = checkMixin(i)) tokens[i].bd_kind = 8;else if (l = checkLoop(i)) tokens[i].bd_kind = 3;else if (l = checkRuleset(i)) tokens[i].bd_kind = 7;else if (l = checkDeclaration(i)) tokens[i].bd_kind = 5;else if (l = checkAtrule(i)) tokens[i].bd_kind = 6;else return 0;
  8777. i += l;
  8778. while (i < tokensLength) {
  8779. if (l = checkS(i)) i += l;else if (l = checkCommentSL(i)) i += l;else break;
  8780. }
  8781. return i - start;
  8782. }
  8783. /**
  8784. * @return {!Array}
  8785. */
  8786. function getBlockdecl2() {
  8787. var content = [];
  8788. switch (tokens[pos].bd_kind) {
  8789. case 1:
  8790. content.push(getConditionalStatement());
  8791. break;
  8792. case 2:
  8793. content.push(getInclude());
  8794. break;
  8795. case 3:
  8796. content.push(getLoop());
  8797. break;
  8798. case 4:
  8799. content.push(getExtend());
  8800. break;
  8801. case 5:
  8802. content.push(getDeclaration());
  8803. break;
  8804. case 6:
  8805. content.push(getAtrule());
  8806. break;
  8807. case 7:
  8808. content.push(getRuleset());
  8809. break;
  8810. case 8:
  8811. content.push(getMixin());
  8812. break;
  8813. }
  8814. while (pos < tokensLength) {
  8815. if (checkS(pos)) content.push(getS());else if (checkCommentSL(pos)) content.push(getCommentSL());else break;
  8816. }
  8817. return content;
  8818. }
  8819. /**
  8820. * @param {number} i Token's index number
  8821. * @return {number}
  8822. */
  8823. function checkBlockdecl3(i) {
  8824. var start = i;
  8825. var l = void 0;
  8826. if (l = checkConditionalStatement(i)) tokens[i].bd_kind = 1;else if (l = checkInclude(i)) tokens[i].bd_kind = 2;else if (l = checkExtend(i)) tokens[i].bd_kind = 4;else if (l = checkLoop(i)) tokens[i].bd_kind = 3;else if (l = checkRuleset(i)) tokens[i].bd_kind = 7;else if (l = checkDeclaration(i)) tokens[i].bd_kind = 5;else if (l = checkAtrule(i)) tokens[i].bd_kind = 6;else return 0;
  8827. i += l;
  8828. return i - start;
  8829. }
  8830. /**
  8831. * @return {!Array}
  8832. */
  8833. function getBlockdecl3() {
  8834. var content = void 0;
  8835. switch (tokens[pos].bd_kind) {
  8836. case 1:
  8837. content = getConditionalStatement();
  8838. break;
  8839. case 2:
  8840. content = getInclude();
  8841. break;
  8842. case 3:
  8843. content = getLoop();
  8844. break;
  8845. case 4:
  8846. content = getExtend();
  8847. break;
  8848. case 5:
  8849. content = getDeclaration();
  8850. break;
  8851. case 6:
  8852. content = getAtrule();
  8853. break;
  8854. case 7:
  8855. content = getRuleset();
  8856. break;
  8857. }
  8858. return [content];
  8859. }
  8860. /**
  8861. * @param {number} i Token's index number
  8862. * @return {number}
  8863. */
  8864. function checkBlockdecl4(i) {
  8865. return checkSC(i);
  8866. }
  8867. /**
  8868. * @return {!Array}
  8869. */
  8870. function getBlockdecl4() {
  8871. return getSC();
  8872. }
  8873. /**
  8874. * @param {number} i Token's index number
  8875. * @return {number}
  8876. */
  8877. function checkBlockdecl5(i) {
  8878. var start = i;
  8879. var l = void 0;
  8880. if (l = checkInclude(i)) i += l;else if (l = checkRuleset(i)) i += l;else return 0;
  8881. while (i < tokensLength) {
  8882. if (l = checkS(i)) i += l;else if (l = checkCommentSL(i)) i += l;else break;
  8883. }
  8884. return i - start;
  8885. }
  8886. /**
  8887. * @return {!Array}
  8888. */
  8889. function getBlockdecl5() {
  8890. var content = [];
  8891. if (checkInclude(pos)) content.push(getInclude());else content.push(getRuleset());
  8892. while (pos < tokensLength) {
  8893. if (checkS(pos)) content.push(getS());else if (checkCommentSL(pos)) content.push(getCommentSL());else break;
  8894. }
  8895. return content;
  8896. }
  8897. /**
  8898. * @param {number} i Token's index number
  8899. * @return {number}
  8900. */
  8901. function checkBlockdecl6(i) {
  8902. var start = i;
  8903. var l = void 0;
  8904. if (l = checkInclude(i)) i += l;else if (l = checkRuleset(i)) i += l;else return 0;
  8905. return i - start;
  8906. }
  8907. /**
  8908. * @return {!Array}
  8909. */
  8910. function getBlockdecl6() {
  8911. var content = void 0;
  8912. if (checkInclude(pos)) content = getInclude();else content = getRuleset();
  8913. return [content];
  8914. }
  8915. /**
  8916. * @param {number} i Token's index number
  8917. * @return {number}
  8918. */
  8919. function checkBlockdecl7(i) {
  8920. var start = i;
  8921. var l = void 0;
  8922. if (l = checkInclude(i)) i += l;else return 0;
  8923. if ([2, 4, 6, 8].indexOf(tokens[start].include_type) === -1) return 0;
  8924. while (i < tokensLength) {
  8925. if (l = checkDeclDelim(i)) return i + l - start;
  8926. if (l = checkS(i)) i += l;else if (l = checkCommentSL(i)) i += l;else break;
  8927. }
  8928. return 0;
  8929. }
  8930. /**
  8931. * @return {!Array}
  8932. */
  8933. function getBlockdecl7() {
  8934. var content = [];
  8935. var _content = [];
  8936. content.push(getInclude());
  8937. while (pos < tokensLength) {
  8938. var _pos = pos;
  8939. if (checkDeclDelim(pos)) {
  8940. _content.push(getDeclDelim());
  8941. content = content.concat(_content);
  8942. break;
  8943. }
  8944. if (checkS(pos)) _content.push(getS());else if (checkCommentSL(pos)) _content.push(getCommentSL());else {
  8945. pos = _pos;
  8946. break;
  8947. }
  8948. }
  8949. return content;
  8950. }
  8951. /**
  8952. * Checks if token is part of text inside square brackets, e.g. `[1]`.
  8953. *
  8954. * @param {number} i Token's index number
  8955. * @return {number}
  8956. */
  8957. function checkBrackets(i) {
  8958. if (i >= tokensLength) return 0;
  8959. var start = i;
  8960. // Skip `[`.
  8961. if (tokens[i].type === TokenType.LeftSquareBracket) i++;else return 0;
  8962. if (i < tokens[start].right) {
  8963. var l = checkTsets(i);
  8964. if (l) i += l;else return 0;
  8965. }
  8966. // Skip `]`.
  8967. i++;
  8968. return i - start;
  8969. }
  8970. /**
  8971. * Gets node with text inside square brackets, e.g. `[1]`.
  8972. *
  8973. * @return {!Node}
  8974. */
  8975. function getBrackets() {
  8976. var type = NodeType.BracketsType;
  8977. var token = tokens[pos];
  8978. var line = token.ln;
  8979. var column = token.col;
  8980. var right = token.right;
  8981. var content = [];
  8982. // Skip `[`.
  8983. pos++;
  8984. if (pos < right) {
  8985. content = getTsets();
  8986. }
  8987. var end = getLastPosition(content, line, column, 1);
  8988. // Skip `]`.
  8989. pos++;
  8990. return newNode(type, content, line, column, end);
  8991. }
  8992. /**
  8993. * Checks if token is part of a class selector (e.g. `.abc`).
  8994. *
  8995. * @param {number} i Token's index number
  8996. * @return {number} Length of the class selector
  8997. */
  8998. function checkClass(i) {
  8999. var start = i;
  9000. var l = void 0;
  9001. if (i >= tokensLength) return 0;
  9002. if (tokens[i].class_l) return tokens[i].class_l;
  9003. // Skip `.`.
  9004. if (tokens[i].type === TokenType.FullStop) i++;else return 0;
  9005. if (l = checkIdentOrInterpolation(i)) i += l;else return 0;
  9006. while (i < tokensLength) {
  9007. if (l = checkIdentOrInterpolation(i)) {
  9008. tokens[start].class_l = l + 1;
  9009. i += l;
  9010. } else break;
  9011. }
  9012. tokens[start].classEnd = i;
  9013. return i - start;
  9014. }
  9015. /**
  9016. * Gets node with a class selector.
  9017. *
  9018. * @return {!Node}
  9019. */
  9020. function getClass() {
  9021. var type = NodeType.ClassType;
  9022. var token = tokens[pos];
  9023. var line = token.ln;
  9024. var column = token.col;
  9025. var end = token.classEnd;
  9026. var content = [];
  9027. // Skip `.`
  9028. pos++;
  9029. while (pos < end) {
  9030. if (checkIdentOrInterpolation(pos)) {
  9031. content = content.concat(getIdentOrInterpolation());
  9032. } else break;
  9033. }
  9034. return newNode(type, content, line, column);
  9035. }
  9036. /**
  9037. * @param {number} i
  9038. * @return {number}
  9039. */
  9040. function checkCombinator(i) {
  9041. if (i >= tokensLength) return 0;
  9042. var l = void 0;
  9043. if (l = checkCombinator1(i)) tokens[i].combinatorType = 1;else if (l = checkCombinator2(i)) tokens[i].combinatorType = 2;else if (l = checkCombinator3(i)) tokens[i].combinatorType = 3;else if (l = checkCombinator4(i)) tokens[i].combinatorType = 4;
  9044. return l;
  9045. }
  9046. /**
  9047. * @return {!Node}
  9048. */
  9049. function getCombinator() {
  9050. var type = tokens[pos].combinatorType;
  9051. if (type === 1) return getCombinator1();
  9052. if (type === 2) return getCombinator2();
  9053. if (type === 3) return getCombinator3();
  9054. if (type === 4) return getCombinator4();
  9055. }
  9056. /**
  9057. * (1) `>>>`
  9058. *
  9059. * @param {Number} i
  9060. * @return {Number}
  9061. */
  9062. function checkCombinator1(i) {
  9063. if (i < tokensLength && tokens[i++].type === TokenType.GreaterThanSign && i < tokensLength && tokens[i++].type === TokenType.GreaterThanSign && i < tokensLength && tokens[i++].type === TokenType.GreaterThanSign) return 3;
  9064. return 0;
  9065. }
  9066. /**
  9067. * @return {Node}
  9068. */
  9069. function getCombinator1() {
  9070. var type = NodeType.CombinatorType;
  9071. var token = tokens[pos];
  9072. var line = token.ln;
  9073. var column = token.col;
  9074. var content = '>>>';
  9075. // Skip combinator
  9076. pos += 3;
  9077. return newNode(type, content, line, column);
  9078. }
  9079. /**
  9080. * (1) `||`
  9081. * (2) `>>`
  9082. *
  9083. * @param {number} i
  9084. * @return {number}
  9085. */
  9086. function checkCombinator2(i) {
  9087. if (i + 1 >= tokensLength) return 0;
  9088. if (tokens[i].type === TokenType.VerticalLine && tokens[i + 1].type === TokenType.VerticalLine) return 2;
  9089. if (tokens[i].type === TokenType.GreaterThanSign && tokens[i + 1].type === TokenType.GreaterThanSign) return 2;
  9090. return 0;
  9091. }
  9092. /**
  9093. * @return {!Node}
  9094. */
  9095. function getCombinator2() {
  9096. var type = NodeType.CombinatorType;
  9097. var token = tokens[pos];
  9098. var line = token.ln;
  9099. var column = token.col;
  9100. var content = '' + token.value + tokens[pos + 1].value;
  9101. // Skip combinator
  9102. pos += 2;
  9103. return newNode(type, content, line, column);
  9104. }
  9105. /**
  9106. * (1) `>`
  9107. * (2) `+`
  9108. * (3) `~`
  9109. *
  9110. * @param {number} i
  9111. * @return {number}
  9112. */
  9113. function checkCombinator3(i) {
  9114. var type = tokens[i].type;
  9115. if (type === TokenType.PlusSign || type === TokenType.GreaterThanSign || type === TokenType.Tilde) return 1;else return 0;
  9116. }
  9117. /**
  9118. * @return {Node}
  9119. */
  9120. function getCombinator3() {
  9121. var type = NodeType.CombinatorType;
  9122. var token = tokens[pos];
  9123. var line = token.ln;
  9124. var column = token.col;
  9125. var content = token.value;
  9126. // Skip combinator
  9127. pos++;
  9128. return newNode(type, content, line, column);
  9129. }
  9130. /**
  9131. * (1) `/panda/`
  9132. */
  9133. function checkCombinator4(i) {
  9134. var start = i;
  9135. if (tokens[i].type === TokenType.Solidus) i++;else return 0;
  9136. var l = void 0;
  9137. if (l = checkIdent(i)) i += l;else return 0;
  9138. if (tokens[i].type === TokenType.Solidus) i++;else return 0;
  9139. return i - start;
  9140. }
  9141. /**
  9142. * @return {Node}
  9143. */
  9144. function getCombinator4() {
  9145. var type = NodeType.CombinatorType;
  9146. var token = tokens[pos];
  9147. var line = token.ln;
  9148. var column = token.col;
  9149. // Skip `/`.
  9150. pos++;
  9151. var ident = getIdent();
  9152. // Skip `/`.
  9153. pos++;
  9154. var content = '/' + ident.content + '/';
  9155. return newNode(type, content, line, column);
  9156. }
  9157. /**
  9158. * Check if token is a multiline comment.
  9159. * @param {number} i Token's index number
  9160. * @return {number} `1` if token is a multiline comment, otherwise `0`
  9161. */
  9162. function checkCommentML(i) {
  9163. return i < tokensLength && tokens[i].type === TokenType.CommentML ? 1 : 0;
  9164. }
  9165. /**
  9166. * Get node with a multiline comment
  9167. * @return {Array} `['commentML', x]` where `x`
  9168. * is the comment's text (without `/*` and `* /`).
  9169. */
  9170. function getCommentML() {
  9171. var type = NodeType.CommentMLType;
  9172. var token = tokens[pos];
  9173. var line = token.ln;
  9174. var column = token.col;
  9175. var content = tokens[pos].value.substring(2);
  9176. var end = getLastPosition(content, line, column + 2);
  9177. if (content.endsWith('*/')) {
  9178. content = content.substring(0, content.length - 2);
  9179. }
  9180. pos++;
  9181. return newNode(type, content, line, column, end);
  9182. }
  9183. /**
  9184. * Check if token is part of a single-line comment.
  9185. * @param {number} i Token's index number
  9186. * @return {number} `1` if token is a single-line comment, otherwise `0`
  9187. */
  9188. function checkCommentSL(i) {
  9189. return i < tokensLength && tokens[i].type === TokenType.CommentSL ? 1 : 0;
  9190. }
  9191. /**
  9192. * Get node with a single-line comment.
  9193. * @return {Array} `['commentSL', x]` where `x` is comment's message
  9194. * (without `//`)
  9195. */
  9196. function getCommentSL() {
  9197. var type = NodeType.CommentSLType;
  9198. var token = tokens[pos];
  9199. var line = token.ln;
  9200. var column = token.col;
  9201. var content = tokens[pos++].value.substring(2);
  9202. var end = !content ? [line, column + 1] : getLastPosition(content, line, column + 2);
  9203. return newNode(type, content, line, column, end);
  9204. }
  9205. /**
  9206. * Check if token is part of a condition
  9207. * (e.g. `@if ...`, `@else if ...` or `@else ...`).
  9208. * @param {number} i Token's index number
  9209. * @return {number} Length of the condition
  9210. */
  9211. function checkCondition(i) {
  9212. var start = i;
  9213. var l = void 0;
  9214. var _i = void 0;
  9215. var s = void 0;
  9216. if (i >= tokensLength) return 0;
  9217. if (l = checkAtkeyword(i)) i += l;else return 0;
  9218. if (['if', 'else'].indexOf(tokens[start + 1].value) < 0) return 0;
  9219. while (i < tokensLength) {
  9220. if (l = checkBlock(i)) break;
  9221. s = checkSC(i);
  9222. _i = i + s;
  9223. if (l = _checkCondition(_i)) i += l + s;else break;
  9224. }
  9225. return i - start;
  9226. }
  9227. function _checkCondition(i) {
  9228. return checkVariable(i) || checkNumber(i) || checkInterpolation(i) || checkIdent(i) || checkOperator(i) || checkCombinator(i) || checkString(i);
  9229. }
  9230. /**
  9231. * Get node with a condition.
  9232. * @return {Array} `['condition', x]`
  9233. */
  9234. function getCondition() {
  9235. var type = NodeType.ConditionType;
  9236. var token = tokens[pos];
  9237. var line = token.ln;
  9238. var column = token.col;
  9239. var content = [];
  9240. var s = void 0;
  9241. var _pos = void 0;
  9242. content.push(getAtkeyword());
  9243. while (pos < tokensLength) {
  9244. if (checkBlock(pos)) break;
  9245. s = checkSC(pos);
  9246. _pos = pos + s;
  9247. if (!_checkCondition(_pos)) break;
  9248. if (s) content = content.concat(getSC());
  9249. content.push(_getCondition());
  9250. }
  9251. return newNode(type, content, line, column);
  9252. }
  9253. function _getCondition() {
  9254. if (checkVariable(pos)) return getVariable();
  9255. if (checkNumber(pos)) return getNumber();
  9256. if (checkInterpolation(pos)) return getInterpolation();
  9257. if (checkIdent(pos)) return getIdent();
  9258. if (checkOperator(pos)) return getOperator();
  9259. if (checkCombinator(pos)) return getCombinator();
  9260. if (checkString(pos)) return getString();
  9261. }
  9262. /**
  9263. * Check if token is part of a conditional statement
  9264. * (e.g. `@if ... {} @else if ... {} @else ... {}`).
  9265. * @param {number} i Token's index number
  9266. * @return {number} Length of the condition
  9267. */
  9268. function checkConditionalStatement(i) {
  9269. var start = i;
  9270. var l = void 0;
  9271. if (i >= tokensLength) return 0;
  9272. if (l = checkCondition(i)) i += l;else return 0;
  9273. if (l = checkSC(i)) i += l;
  9274. if (l = checkBlock(i)) i += l;else return 0;
  9275. return i - start;
  9276. }
  9277. /**
  9278. * Get node with a condition.
  9279. * @return {Array} `['condition', x]`
  9280. */
  9281. function getConditionalStatement() {
  9282. var type = NodeType.ConditionalStatementType;
  9283. var token = tokens[pos];
  9284. var line = token.ln;
  9285. var column = token.col;
  9286. var content = [].concat(getCondition(), getSC(), getBlock());
  9287. return newNode(type, content, line, column);
  9288. }
  9289. /**
  9290. * Check if token is part of a declaration (property-value pair)
  9291. * @param {number} i Token's index number
  9292. * @return {number} Length of the declaration
  9293. */
  9294. function checkDeclaration(i) {
  9295. return checkDeclaration1(i) || checkDeclaration2(i);
  9296. }
  9297. /**
  9298. * Get node with a declaration
  9299. * @return {Array} `['declaration', ['property', x], ['propertyDelim'],
  9300. * ['value', y]]`
  9301. */
  9302. function getDeclaration() {
  9303. return checkDeclaration1(pos) ? getDeclaration1() : getDeclaration2();
  9304. }
  9305. /**
  9306. * Check if token is part of a declaration (property-value pair)
  9307. * @param {number} i Token's index number
  9308. * @return {number} Length of the declaration
  9309. */
  9310. function checkDeclaration1(i) {
  9311. var start = i;
  9312. var l = void 0;
  9313. if (i >= tokensLength) return 0;
  9314. if (l = checkProperty(i)) i += l;else return 0;
  9315. if (l = checkSC(i)) i += l;
  9316. if (l = checkPropertyDelim(i)) i++;else return 0;
  9317. if (l = checkValue(i)) return i + l - start;
  9318. if (l = checkS(i)) i += l;
  9319. if (l = checkValue(i)) i += l;else return 0;
  9320. return i - start;
  9321. }
  9322. /**
  9323. * Get node with a declaration
  9324. * @return {Array} `['declaration', ['property', x], ['propertyDelim'],
  9325. * ['value', y]]`
  9326. */
  9327. function getDeclaration1() {
  9328. var type = NodeType.DeclarationType;
  9329. var token = tokens[pos];
  9330. var line = token.ln;
  9331. var column = token.col;
  9332. var content = [];
  9333. content.push(getProperty());
  9334. if (checkS(pos)) content.push(getS());
  9335. content.push(getPropertyDelim());
  9336. if (checkS(pos)) content.push(getS());
  9337. content.push(getValue());
  9338. return newNode(type, content, line, column);
  9339. }
  9340. /**
  9341. * Check if token is part of a declaration (property-value pair)
  9342. * @param {number} i Token's index number
  9343. * @return {number} Length of the declaration
  9344. */
  9345. function checkDeclaration2(i) {
  9346. var start = i;
  9347. var l = void 0;
  9348. if (i >= tokensLength) return 0;
  9349. if (l = checkPropertyDelim(i)) i++;else return 0;
  9350. if (l = checkProperty(i)) i += l;else return 0;
  9351. if (l = checkValue(i)) return i + l - start;
  9352. if (l = checkSC(i)) i += l;
  9353. if (l = checkValue(i)) i += l;else return 0;
  9354. return i - start;
  9355. }
  9356. /**
  9357. * Get node with a declaration
  9358. * @return {Array} `['declaration', ['propertyDelim'], ['property', x],
  9359. * ['value', y]]`
  9360. */
  9361. function getDeclaration2() {
  9362. var type = NodeType.DeclarationType;
  9363. var token = tokens[pos];
  9364. var line = token.ln;
  9365. var column = token.col;
  9366. var content = [].concat(getPropertyDelim(), getProperty(), getSC(), getValue());
  9367. return newNode(type, content, line, column);
  9368. }
  9369. /**
  9370. * @param {number} i Token's index number
  9371. * @returns {number} Length of the declaration
  9372. */
  9373. function checkSingleValueDeclaration(i) {
  9374. var start = i;
  9375. var l = void 0;
  9376. if (i >= tokensLength) return 0;
  9377. if (l = checkProperty(i)) i += l;else return 0;
  9378. if (l = checkSC(i)) i += l;
  9379. if (l = checkPropertyDelim(i)) i++;else return 0;
  9380. if (l = checkSC(i)) i += l;
  9381. if (l = checkSingleValue(i)) i += l;else return 0;
  9382. return i - start;
  9383. }
  9384. /**
  9385. * Get node with a declaration
  9386. * @returns {Array} `['declaration', ['property', x], ['propertyDelim'],
  9387. * ['value', y]]`
  9388. */
  9389. function getSingleValueDeclaration() {
  9390. var type = NodeType.DeclarationType;
  9391. var token = tokens[pos];
  9392. var line = token.ln;
  9393. var column = token.col;
  9394. var content = [].concat(getProperty(), getSC(), getPropertyDelim(), getSC(), getSingleValue());
  9395. return newNode(type, content, line, column);
  9396. }
  9397. /**
  9398. * Check if token is a semicolon
  9399. * @param {number} i Token's index number
  9400. * @return {number} `1` if token is a semicolon, otherwise `0`
  9401. */
  9402. function checkDeclDelim(i) {
  9403. if (i >= tokensLength) return 0;
  9404. return tokens[i].type === TokenType.Newline || tokens[i].type === TokenType.Semicolon ? 1 : 0;
  9405. }
  9406. /**
  9407. * Get node with a semicolon
  9408. * @return {Array} `['declDelim']`
  9409. */
  9410. function getDeclDelim() {
  9411. var type = NodeType.DeclDelimType;
  9412. var token = tokens[pos];
  9413. var line = token.ln;
  9414. var column = token.col;
  9415. var content = '\n';
  9416. pos++;
  9417. return newNode(type, content, line, column);
  9418. }
  9419. /**
  9420. * Check if token if part of `!default` word.
  9421. * @param {number} i Token's index number
  9422. * @return {number} Length of the `!default` word
  9423. */
  9424. function checkDefault(i) {
  9425. var start = i;
  9426. var l = void 0;
  9427. if (i >= tokensLength || tokens[i++].type !== TokenType.ExclamationMark) return 0;
  9428. if (l = checkSC(i)) i += l;
  9429. if (tokens[i].value === 'default') {
  9430. tokens[start].defaultEnd = i;
  9431. return i - start + 1;
  9432. } else {
  9433. return 0;
  9434. }
  9435. }
  9436. /**
  9437. * Get node with a `!default` word
  9438. * @return {Array} `['default', sc]` where `sc` is optional whitespace
  9439. */
  9440. function getDefault() {
  9441. var type = NodeType.DefaultType;
  9442. var token = tokens[pos];
  9443. var line = token.ln;
  9444. var column = token.col;
  9445. var content = joinValues(pos, token.defaultEnd);
  9446. pos = token.defaultEnd + 1;
  9447. return newNode(type, content, line, column);
  9448. }
  9449. /**
  9450. * Check if token is a comma
  9451. * @param {number} i Token's index number
  9452. * @return {number} `1` if token is a comma, otherwise `0`
  9453. */
  9454. function checkDelim(i) {
  9455. return i < tokensLength && tokens[i].type === TokenType.Comma ? 1 : 0;
  9456. }
  9457. /**
  9458. * Get node with a comma
  9459. * @return {Array} `['delim']`
  9460. */
  9461. function getDelim() {
  9462. var type = NodeType.DelimType;
  9463. var token = tokens[pos];
  9464. var line = token.ln;
  9465. var column = token.col;
  9466. var content = ',';
  9467. pos++;
  9468. return newNode(type, content, line, column);
  9469. }
  9470. /**
  9471. * Check if token is part of a number with dimension unit (e.g. `10px`)
  9472. * @param {Number} i Token's index number
  9473. * @return {Number}
  9474. */
  9475. function checkDimension(i) {
  9476. var ln = checkNumber(i);
  9477. var li = void 0;
  9478. if (i >= tokensLength || !ln || i + ln >= tokensLength) return 0;
  9479. return (li = checkUnit(i + ln)) ? ln + li : 0;
  9480. }
  9481. /**
  9482. * Get node of a number with dimension unit
  9483. * @return {Node}
  9484. */
  9485. function getDimension() {
  9486. var type = NodeType.DimensionType;
  9487. var token = tokens[pos];
  9488. var line = token.ln;
  9489. var column = token.col;
  9490. var content = [getNumber(), getUnit()];
  9491. return newNode(type, content, line, column);
  9492. }
  9493. /**
  9494. * @param {number} i Token's index number
  9495. * @return {number}
  9496. */
  9497. function checkExpression(i) {
  9498. var start = i;
  9499. if (i >= tokensLength || tokens[i++].value !== 'expression' || i >= tokensLength || tokens[i].type !== TokenType.LeftParenthesis) {
  9500. return 0;
  9501. }
  9502. return tokens[i].right - start + 1;
  9503. }
  9504. /**
  9505. * @return {Array}
  9506. */
  9507. function getExpression() {
  9508. var type = NodeType.ExpressionType;
  9509. var token = tokens[pos];
  9510. var line = token.ln;
  9511. var column = token.col;
  9512. pos++;
  9513. var content = joinValues(pos + 1, tokens[pos].right - 1);
  9514. var end = getLastPosition(content, line, column, 1);
  9515. if (end[0] === line) end[1] += 11;
  9516. pos = tokens[pos].right + 1;
  9517. return newNode(type, content, line, column, end);
  9518. }
  9519. function checkExtend(i) {
  9520. if (i >= tokensLength) return 0;
  9521. var l = void 0;
  9522. if (l = checkExtend1(i)) tokens[i].extend_child = 1;else if (l = checkExtend2(i)) tokens[i].extend_child = 2;
  9523. return l;
  9524. }
  9525. function getExtend() {
  9526. var childType = tokens[pos].extend_child;
  9527. if (childType === 1) return getExtend1();
  9528. if (childType === 2) return getExtend2();
  9529. }
  9530. /**
  9531. * Checks if token is part of an extend with `!optional` flag.
  9532. * @param {number} i
  9533. */
  9534. function checkExtend1(i) {
  9535. var start = i;
  9536. var l = void 0;
  9537. if (i >= tokensLength) return 0;
  9538. if (l = checkAtkeyword(i)) i += l;else return 0;
  9539. if (tokens[start + 1].value !== 'extend') return 0;
  9540. if (l = checkSC(i)) i += l;else return 0;
  9541. if (l = checkSelectorsGroup(i)) i += l;else return 0;
  9542. if (l = checkSC(i)) i += l;else return 0;
  9543. if (l = checkOptional(i)) i += l;else return 0;
  9544. return i - start;
  9545. }
  9546. function getExtend1() {
  9547. var type = NodeType.ExtendType;
  9548. var token = tokens[pos];
  9549. var line = token.ln;
  9550. var column = token.col;
  9551. var content = [].concat(getAtkeyword(), getSC(), getSelectorsGroup(), getSC(), getOptional());
  9552. return newNode(type, content, line, column);
  9553. }
  9554. /**
  9555. * Checks if token is part of an extend without `!optional` flag.
  9556. * @param {number} i
  9557. */
  9558. function checkExtend2(i) {
  9559. var start = i;
  9560. var l = void 0;
  9561. if (i >= tokensLength) return 0;
  9562. if (l = checkAtkeyword(i)) i += l;else return 0;
  9563. if (tokens[start + 1].value !== 'extend') return 0;
  9564. if (l = checkSC(i)) i += l;else return 0;
  9565. if (l = checkSelectorsGroup(i)) i += l;else return 0;
  9566. return i - start;
  9567. }
  9568. function getExtend2() {
  9569. var type = NodeType.ExtendType;
  9570. var token = tokens[pos];
  9571. var line = token.ln;
  9572. var column = token.col;
  9573. var content = [].concat(getAtkeyword(), getSC(), getSelectorsGroup());
  9574. return newNode(type, content, line, column);
  9575. }
  9576. /**
  9577. * @param {number} i Token's index number
  9578. * @return {number}
  9579. */
  9580. function checkFunction(i) {
  9581. var start = i;
  9582. var l = void 0;
  9583. if (i >= tokensLength) return 0;
  9584. if (l = checkIdentOrInterpolation(i)) i += l;else return 0;
  9585. return i < tokensLength && tokens[i].type === TokenType.LeftParenthesis ? tokens[i].right - start + 1 : 0;
  9586. }
  9587. /**
  9588. * @return {Array}
  9589. */
  9590. function getFunction() {
  9591. var type = NodeType.FunctionType;
  9592. var token = tokens[pos];
  9593. var line = token.ln;
  9594. var column = token.col;
  9595. var content = [].concat(getIdentOrInterpolation(), getArguments());
  9596. return newNode(type, content, line, column);
  9597. }
  9598. /**
  9599. * Check if token is part of a functions list (e.g. `function(value)...`).
  9600. * @param {Number} i Token's index number
  9601. * @returns {Number}
  9602. */
  9603. function checkFunctionsList(i) {
  9604. var d = 0; // Number of dots
  9605. var l = void 0;
  9606. if (i >= tokensLength) return 0;
  9607. if (l = checkFunction(i)) i += l;else return 0;
  9608. while (i < tokensLength && tokens[i].type === TokenType.FullStop) {
  9609. d++;
  9610. i++;
  9611. }
  9612. return d === 3 ? l + d : 0;
  9613. }
  9614. /**
  9615. * Get node with a functions list
  9616. * @returns {Array}
  9617. */
  9618. function getFunctionsList() {
  9619. var type = NodeType.FunctionsListType;
  9620. var token = tokens[pos];
  9621. var line = token.ln;
  9622. var column = token.col;
  9623. var content = [getFunction()];
  9624. var end = getLastPosition(content, line, column, 3);
  9625. // Skip `...`.
  9626. pos += 3;
  9627. return newNode(type, content, line, column, end);
  9628. }
  9629. /**
  9630. * Check if token is part of `!global` word
  9631. * @param {number} i Token's index number
  9632. * @return {number}
  9633. */
  9634. function checkGlobal(i) {
  9635. var start = i;
  9636. var l = void 0;
  9637. if (i >= tokensLength || tokens[i++].type !== TokenType.ExclamationMark) return 0;
  9638. if (l = checkSC(i)) i += l;
  9639. if (tokens[i].value === 'global') {
  9640. tokens[start].globalEnd = i;
  9641. return i - start + 1;
  9642. } else {
  9643. return 0;
  9644. }
  9645. }
  9646. /**
  9647. * Get node with `!global` word
  9648. */
  9649. function getGlobal() {
  9650. var type = NodeType.GlobalType;
  9651. var token = tokens[pos];
  9652. var line = token.ln;
  9653. var column = token.col;
  9654. var content = joinValues(pos, token.globalEnd);
  9655. pos = token.globalEnd + 1;
  9656. return newNode(type, content, line, column);
  9657. }
  9658. /**
  9659. * Check if token is part of an identifier
  9660. * @param {number} i Token's index number
  9661. * @return {number} Length of the identifier
  9662. */
  9663. function checkIdent(i) {
  9664. var start = i;
  9665. if (i >= tokensLength) return 0;
  9666. // Check if token is part of a negative number
  9667. if (tokens[i].type === TokenType.HyphenMinus && tokens[i + 1].type === TokenType.DecimalNumber) return 0;
  9668. if (tokens[i].type === TokenType.HyphenMinus) i++;
  9669. if (checkInterpolation(i)) {
  9670. tokens[start].ident_last = i - 1;
  9671. return i - start;
  9672. }
  9673. if (tokens[i].type === TokenType.LowLine || tokens[i].type === TokenType.Identifier) i++;else return 0;
  9674. for (; i < tokensLength; i++) {
  9675. if (tokens[i].type !== TokenType.HyphenMinus && tokens[i].type !== TokenType.LowLine && tokens[i].type !== TokenType.Identifier && tokens[i].type !== TokenType.DecimalNumber) break;
  9676. }
  9677. tokens[start].ident_last = i - 1;
  9678. return i - start;
  9679. }
  9680. /**
  9681. * Get node with an identifier
  9682. * @return {Array} `['ident', x]` where `x` is identifier's name
  9683. */
  9684. function getIdent() {
  9685. var type = NodeType.IdentType;
  9686. var token = tokens[pos];
  9687. var line = token.ln;
  9688. var column = token.col;
  9689. var content = joinValues(pos, tokens[pos].ident_last);
  9690. pos = tokens[pos].ident_last + 1;
  9691. return newNode(type, content, line, column);
  9692. }
  9693. /**
  9694. * @param {number} i Token's index number
  9695. * @returns {number} Length of the identifier
  9696. */
  9697. function checkPartialIdent(i) {
  9698. var start = i;
  9699. if (i >= tokensLength) return 0;
  9700. for (; i < tokensLength; i++) {
  9701. if (tokens[i].type !== TokenType.HyphenMinus && tokens[i].type !== TokenType.LowLine && tokens[i].type !== TokenType.Identifier && tokens[i].type !== TokenType.DecimalNumber) break;
  9702. }
  9703. tokens[start].ident_last = i - 1;
  9704. return i - start;
  9705. }
  9706. /**
  9707. * @param {number} i Token's index number
  9708. * @returns {number} Length of the identifier
  9709. */
  9710. function checkIdentOrInterpolation(i) {
  9711. var start = i;
  9712. var l = void 0;
  9713. var prevIsInterpolation = false;
  9714. while (i < tokensLength) {
  9715. if (l = checkInterpolation(i)) {
  9716. tokens[i].ii_type = 1;
  9717. i += l;
  9718. prevIsInterpolation = true;
  9719. } else if (l = checkIdent(i)) {
  9720. tokens[i].ii_type = 2;
  9721. i += l;
  9722. prevIsInterpolation = false;
  9723. } else if (prevIsInterpolation && (l = checkPartialIdent(i))) {
  9724. tokens[i].ii_type = 3;
  9725. i += l;
  9726. prevIsInterpolation = false;
  9727. } else break;
  9728. }
  9729. return i - start;
  9730. }
  9731. function getIdentOrInterpolation() {
  9732. var content = [];
  9733. while (pos < tokensLength) {
  9734. var tokenType = tokens[pos].ii_type;
  9735. if (tokenType === 1) {
  9736. content.push(getInterpolation());
  9737. } else if (tokenType === 2 || tokenType === 3) {
  9738. content.push(getIdent());
  9739. } else break;
  9740. }
  9741. return content;
  9742. }
  9743. /**
  9744. * Check if token is part of `!important` word
  9745. * @param {number} i Token's index number
  9746. * @return {number}
  9747. */
  9748. function checkImportant(i) {
  9749. var start = i;
  9750. var l = void 0;
  9751. if (i >= tokensLength || tokens[i++].type !== TokenType.ExclamationMark) return 0;
  9752. if (l = checkSC(i)) i += l;
  9753. if (tokens[i].value === 'important') {
  9754. tokens[start].importantEnd = i;
  9755. return i - start + 1;
  9756. } else {
  9757. return 0;
  9758. }
  9759. }
  9760. /**
  9761. * Get node with `!important` word
  9762. * @return {Array} `['important', sc]` where `sc` is optional whitespace
  9763. */
  9764. function getImportant() {
  9765. var type = NodeType.ImportantType;
  9766. var token = tokens[pos];
  9767. var line = token.ln;
  9768. var column = token.col;
  9769. var content = joinValues(pos, token.importantEnd);
  9770. pos = token.importantEnd + 1;
  9771. return newNode(type, content, line, column);
  9772. }
  9773. /**
  9774. * Check if token is part of an included mixin (`@include` or `@extend`
  9775. * directive).
  9776. * @param {number} i Token's index number
  9777. * @return {number} Length of the included mixin
  9778. */
  9779. function checkInclude(i) {
  9780. var l = void 0;
  9781. if (i >= tokensLength) return 0;
  9782. if (l = checkIncludeWithKeyframes1(i)) tokens[i].include_type = 9;else if (l = checkInclude1(i)) tokens[i].include_type = 1;else if (l = checkInclude2(i)) tokens[i].include_type = 2;else if (l = checkInclude3(i)) tokens[i].include_type = 3;else if (l = checkInclude4(i)) tokens[i].include_type = 4;else if (l = checkIncludeWithKeyframes2(i)) tokens[i].include_type = 10;else if (l = checkInclude5(i)) tokens[i].include_type = 5;else if (l = checkInclude6(i)) tokens[i].include_type = 6;else if (l = checkInclude7(i)) tokens[i].include_type = 7;else if (l = checkInclude8(i)) tokens[i].include_type = 8;
  9783. return l;
  9784. }
  9785. /**
  9786. * Get node with included mixin
  9787. * @return {Array} `['include', x]`
  9788. */
  9789. function getInclude() {
  9790. var type = tokens[pos].include_type;
  9791. if (type === 1) return getInclude1();
  9792. if (type === 2) return getInclude2();
  9793. if (type === 3) return getInclude3();
  9794. if (type === 4) return getInclude4();
  9795. if (type === 5) return getInclude5();
  9796. if (type === 6) return getInclude6();
  9797. if (type === 7) return getInclude7();
  9798. if (type === 8) return getInclude8();
  9799. if (type === 9) return getIncludeWithKeyframes1();
  9800. if (type === 10) return getIncludeWithKeyframes2();
  9801. }
  9802. /**
  9803. * Check if token is part of an included mixin like `@include nani(foo) {...}`
  9804. * @param {number} i Token's index number
  9805. * @return {number} Length of the include
  9806. */
  9807. function checkInclude1(i) {
  9808. var start = i;
  9809. var l = void 0;
  9810. if (l = checkAtkeyword(i)) i += l;else return 0;
  9811. if (tokens[start + 1].value !== 'include') return 0;
  9812. if (l = checkSC(i)) i += l;else return 0;
  9813. if (l = checkIdentOrInterpolation(i)) i += l;else return 0;
  9814. if (l = checkSC(i)) i += l;
  9815. if (l = checkArguments(i)) i += l;else return 0;
  9816. if (l = checkSC(i)) i += l;
  9817. if (l = checkBlock(i)) i += l;else return 0;
  9818. return i - start;
  9819. }
  9820. /**
  9821. * Get node with included mixin like `@include nani(foo) {...}`
  9822. * @return {Array} `['include', ['atkeyword', x], sc, ['selector', y], sc,
  9823. * ['arguments', z], sc, ['block', q], sc` where `x` is `include` or
  9824. * `extend`, `y` is mixin's identifier (selector), `z` are arguments
  9825. * passed to the mixin, `q` is block passed to the mixin and `sc`
  9826. * are optional whitespaces
  9827. */
  9828. function getInclude1() {
  9829. var type = NodeType.IncludeType;
  9830. var token = tokens[pos];
  9831. var line = token.ln;
  9832. var column = token.col;
  9833. var content = [].concat(getAtkeyword(), getSC(), getIdentOrInterpolation(), getSC(), getArguments(), getSC(), getBlock());
  9834. return newNode(type, content, line, column);
  9835. }
  9836. /**
  9837. * Check if token is part of an included mixin like `@include nani(foo)`
  9838. * @param {number} i Token's index number
  9839. * @return {number} Length of the include
  9840. */
  9841. function checkInclude2(i) {
  9842. var start = i;
  9843. var l = void 0;
  9844. if (l = checkAtkeyword(i)) i += l;else return 0;
  9845. if (tokens[start + 1].value !== 'include') return 0;
  9846. if (l = checkSC(i)) i += l;else return 0;
  9847. if (l = checkIdentOrInterpolation(i)) i += l;else return 0;
  9848. if (l = checkSC(i)) i += l;
  9849. if (l = checkArguments(i)) i += l;else return 0;
  9850. return i - start;
  9851. }
  9852. /**
  9853. * Get node with included mixin like `@include nani(foo)`
  9854. * @return {Array} `['include', ['atkeyword', x], sc, ['selector', y], sc,
  9855. * ['arguments', z], sc]` where `x` is `include` or `extend`, `y` is
  9856. * mixin's identifier (selector), `z` are arguments passed to the
  9857. * mixin and `sc` are optional whitespaces
  9858. */
  9859. function getInclude2() {
  9860. var type = NodeType.IncludeType;
  9861. var token = tokens[pos];
  9862. var line = token.ln;
  9863. var column = token.col;
  9864. var content = [].concat(getAtkeyword(), getSC(), getIdentOrInterpolation(), getSC(), getArguments());
  9865. return newNode(type, content, line, column);
  9866. }
  9867. /**
  9868. * Check if token is part of an included mixin with a content block passed
  9869. * as an argument (e.g. `@include nani {...}`)
  9870. * @param {number} i Token's index number
  9871. * @return {number} Length of the mixin
  9872. */
  9873. function checkInclude3(i) {
  9874. var start = i;
  9875. var l = void 0;
  9876. if (l = checkAtkeyword(i)) i += l;else return 0;
  9877. if (tokens[start + 1].value !== 'include') return 0;
  9878. if (l = checkSC(i)) i += l;else return 0;
  9879. if (l = checkIdentOrInterpolation(i)) i += l;else return 0;
  9880. if (l = checkSC(i)) i += l;
  9881. if (l = checkBlock(i)) i += l;else return 0;
  9882. return i - start;
  9883. }
  9884. /**
  9885. * Get node with an included mixin with a content block passed
  9886. * as an argument (e.g. `@include nani {...}`)
  9887. * @return {Array} `['include', x]`
  9888. */
  9889. function getInclude3() {
  9890. var type = NodeType.IncludeType;
  9891. var token = tokens[pos];
  9892. var line = token.ln;
  9893. var column = token.col;
  9894. var content = [].concat(getAtkeyword(), getSC(), getIdentOrInterpolation(), getSC(), getBlock());
  9895. return newNode(type, content, line, column);
  9896. }
  9897. /**
  9898. * @param {number} i Token's index number
  9899. * @return {number}
  9900. */
  9901. function checkInclude4(i) {
  9902. var start = i;
  9903. var l = void 0;
  9904. if (l = checkAtkeyword(i)) i += l;else return 0;
  9905. if (tokens[start + 1].value !== 'include') return 0;
  9906. if (l = checkSC(i)) i += l;else return 0;
  9907. if (l = checkIdentOrInterpolation(i)) i += l;else return 0;
  9908. return i - start;
  9909. }
  9910. /**
  9911. * @return {Array} `['include', x]`
  9912. */
  9913. function getInclude4() {
  9914. var type = NodeType.IncludeType;
  9915. var token = tokens[pos];
  9916. var line = token.ln;
  9917. var column = token.col;
  9918. var content = [].concat(getAtkeyword(), getSC(), getIdentOrInterpolation());
  9919. return newNode(type, content, line, column);
  9920. }
  9921. /**
  9922. * Check if token is part of an included mixin like `+nani(foo) {...}`
  9923. * @param {number} i Token's index number
  9924. * @return {number} Length of the include
  9925. */
  9926. function checkInclude5(i) {
  9927. var start = i;
  9928. var l = void 0;
  9929. if (tokens[i].type === TokenType.PlusSign) i++;else return 0;
  9930. if (l = checkIdentOrInterpolation(i)) i += l;else return 0;
  9931. if (l = checkSC(i)) i += l;
  9932. if (l = checkArguments(i)) i += l;else return 0;
  9933. if (l = checkSC(i)) i += l;
  9934. if (l = checkBlock(i)) i += l;else return 0;
  9935. return i - start;
  9936. }
  9937. /**
  9938. * Get node with included mixin like `+nani(foo) {...}`
  9939. * @return {Array} `['include', ['operator', '+'], ['selector', x], sc,
  9940. * ['arguments', y], sc, ['block', z], sc` where `x` is
  9941. * mixin's identifier (selector), `y` are arguments passed to the
  9942. * mixin, `z` is block passed to mixin and `sc` are optional whitespaces
  9943. */
  9944. function getInclude5() {
  9945. var type = NodeType.IncludeType;
  9946. var token = tokens[pos];
  9947. var line = token.ln;
  9948. var column = token.col;
  9949. var content = [].concat(getOperator(), getIdentOrInterpolation(), getSC(), getArguments(), getSC(), getBlock());
  9950. return newNode(type, content, line, column);
  9951. }
  9952. /**
  9953. * Check if token is part of an included mixin like `+nani(foo)`
  9954. * @param {number} i Token's index number
  9955. * @return {number} Length of the include
  9956. */
  9957. function checkInclude6(i) {
  9958. var start = i;
  9959. var l = void 0;
  9960. if (tokens[i].type === TokenType.PlusSign) i++;else return 0;
  9961. if (l = checkIdentOrInterpolation(i)) i += l;else return 0;
  9962. if (l = checkSC(i)) i += l;
  9963. if (l = checkArguments(i)) i += l;else return 0;
  9964. return i - start;
  9965. }
  9966. /**
  9967. * Get node with included mixin like `+nani(foo)`
  9968. * @return {Array} `['include', ['operator', '+'], ['selector', y], sc,
  9969. * ['arguments', z], sc]` where `y` is
  9970. * mixin's identifier (selector), `z` are arguments passed to the
  9971. * mixin and `sc` are optional whitespaces
  9972. */
  9973. function getInclude6() {
  9974. var type = NodeType.IncludeType;
  9975. var token = tokens[pos];
  9976. var line = token.ln;
  9977. var column = token.col;
  9978. var content = [].concat(getOperator(), getIdentOrInterpolation(), getSC(), getArguments());
  9979. return newNode(type, content, line, column);
  9980. }
  9981. /**
  9982. * Check if token is part of an included mixin with a content block passed
  9983. * as an argument (e.g. `+nani {...}`)
  9984. * @param {number} i Token's index number
  9985. * @return {number} Length of the mixin
  9986. */
  9987. function checkInclude7(i) {
  9988. var start = i;
  9989. var l = void 0;
  9990. if (tokens[i].type === TokenType.PlusSign) i++;else return 0;
  9991. if (l = checkIdentOrInterpolation(i)) i += l;else return 0;
  9992. if (l = checkSC(i)) i += l;
  9993. if (l = checkBlock(i)) i += l;else return 0;
  9994. return i - start;
  9995. }
  9996. /**
  9997. * Get node with an included mixin with a content block passed
  9998. * as an argument (e.g. `+nani {...}`)
  9999. * @return {Array} `['include', x]`
  10000. */
  10001. function getInclude7() {
  10002. var type = NodeType.IncludeType;
  10003. var token = tokens[pos];
  10004. var line = token.ln;
  10005. var column = token.col;
  10006. var content = [].concat(getOperator(), getIdentOrInterpolation(), getSC(), getBlock());
  10007. return newNode(type, content, line, column);
  10008. }
  10009. /**
  10010. * @param {number} i Token's index number
  10011. * @return {number}
  10012. */
  10013. function checkInclude8(i) {
  10014. var start = i;
  10015. var l = void 0;
  10016. if (tokens[i].type === TokenType.PlusSign) i++;else return 0;
  10017. if (l = checkIdentOrInterpolation(i)) i += l;else return 0;
  10018. return i - start;
  10019. }
  10020. /**
  10021. * @return {Array} `['include', x]`
  10022. */
  10023. function getInclude8() {
  10024. var type = NodeType.IncludeType;
  10025. var token = tokens[pos];
  10026. var line = token.ln;
  10027. var column = token.col;
  10028. var content = [].concat(getOperator(), getIdentOrInterpolation());
  10029. return newNode(type, content, line, column);
  10030. }
  10031. /**
  10032. * Get node with included mixin with keyfames selector like
  10033. * `@include nani(foo) { 0% {}}`
  10034. * @param {number} i Token's index number
  10035. * @returns {number} Length of the include
  10036. */
  10037. function checkIncludeWithKeyframes1(i) {
  10038. var start = i;
  10039. var l = void 0;
  10040. if (l = checkAtkeyword(i)) i += l;else return 0;
  10041. if (tokens[start + 1].value !== 'include') return 0;
  10042. if (l = checkSC(i)) i += l;else return 0;
  10043. if (l = checkIdentOrInterpolation(i)) i += l;else return 0;
  10044. if (l = checkSC(i)) i += l;
  10045. if (l = checkArguments(i)) i += l;else return 0;
  10046. if (l = checkSC(i)) i += l;
  10047. if (l = checkKeyframesBlocks(i)) i += l;else return 0;
  10048. return i - start;
  10049. }
  10050. /**
  10051. * Get node with included mixin with keyfames selector like
  10052. * `@include nani(foo) { 0% {}}`
  10053. * @return {!Node}
  10054. */
  10055. function getIncludeWithKeyframes1() {
  10056. var type = NodeType.IncludeType;
  10057. var token = tokens[pos];
  10058. var line = token.ln;
  10059. var column = token.col;
  10060. var content = [].concat(getAtkeyword(), getSC(), getIdentOrInterpolation(), getSC(), getArguments(), getSC(), getKeyframesBlocks());
  10061. return newNode(type, content, line, column);
  10062. }
  10063. /**
  10064. * Get node with included mixin with keyfames selector like
  10065. * `+nani(foo) { 0% {}}`
  10066. * @param {number} i Token's index number
  10067. * @returns {number} Length of the include
  10068. */
  10069. function checkIncludeWithKeyframes2(i) {
  10070. var start = i;
  10071. var l = void 0;
  10072. if (tokens[i].type === TokenType.PlusSign) i++;else return 0;
  10073. if (l = checkIdentOrInterpolation(i)) i += l;else return 0;
  10074. if (l = checkSC(i)) i += l;
  10075. if (l = checkArguments(i)) i += l;else return 0;
  10076. if (l = checkSC(i)) i += l;
  10077. if (l = checkKeyframesBlocks(i)) i += l;else return 0;
  10078. return i - start;
  10079. }
  10080. /**
  10081. * Get node with included mixin with keyfames selector like
  10082. * `+nani(foo) { 0% {}}`
  10083. * @return {!Node}
  10084. */
  10085. function getIncludeWithKeyframes2() {
  10086. var type = NodeType.IncludeType;
  10087. var token = tokens[pos];
  10088. var line = token.ln;
  10089. var column = token.col;
  10090. var content = [].concat(getOperator(), getIdentOrInterpolation(), getSC(), getArguments(), getSC(), getKeyframesBlocks());
  10091. return newNode(type, content, line, column);
  10092. }
  10093. /**
  10094. * Check if token is part of an interpolated variable (e.g. `#{$nani}`).
  10095. * @param {number} i Token's index number
  10096. * @return {number}
  10097. */
  10098. function checkInterpolation(i) {
  10099. var start = i;
  10100. var l = void 0;
  10101. if (i >= tokensLength) return 0;
  10102. if (tokens[i].type !== TokenType.NumberSign || !tokens[i + 1] || tokens[i + 1].type !== TokenType.LeftCurlyBracket) return 0;
  10103. i += 2;
  10104. while (tokens[i].type !== TokenType.RightCurlyBracket) {
  10105. if (l = checkArgument(i)) i += l;else return 0;
  10106. }
  10107. return tokens[i].type === TokenType.RightCurlyBracket ? i - start + 1 : 0;
  10108. }
  10109. /**
  10110. * Get node with an interpolated variable
  10111. * @return {Array} `['interpolation', x]`
  10112. */
  10113. function getInterpolation() {
  10114. var type = NodeType.InterpolationType;
  10115. var token = tokens[pos];
  10116. var line = token.ln;
  10117. var column = token.col;
  10118. var content = [];
  10119. // Skip `#{`:
  10120. pos += 2;
  10121. while (pos < tokensLength && tokens[pos].type !== TokenType.RightCurlyBracket) {
  10122. var body = getArgument();
  10123. if (typeof body.content === 'string') content.push(body);else content = content.concat(body);
  10124. }
  10125. var end = getLastPosition(content, line, column, 1);
  10126. // Skip `}`:
  10127. pos++;
  10128. return newNode(type, content, line, column, end);
  10129. }
  10130. /**
  10131. * Check a single keyframe block - `5% {}`
  10132. * @param {number} i
  10133. * @return {number}
  10134. */
  10135. function checkKeyframesBlock(i) {
  10136. var start = i;
  10137. var l = void 0;
  10138. if (i >= tokensLength) return 0;
  10139. if (l = checkKeyframesSelectorsGroup(i)) i += l;else return 0;
  10140. if (l = checkSC(i)) i += l;
  10141. if (l = checkBlock(i)) i += l;else return 0;
  10142. return i - start;
  10143. }
  10144. /**
  10145. * Get a single keyframe block - `5% {}`
  10146. * @return {Node}
  10147. */
  10148. function getKeyframesBlock() {
  10149. var type = NodeType.RulesetType;
  10150. var token = tokens[pos];
  10151. var line = token.ln;
  10152. var column = token.col;
  10153. var content = [].concat(getKeyframesSelectorsGroup(), getSC(), getBlock());
  10154. return newNode(type, content, line, column);
  10155. }
  10156. /**
  10157. * Check all keyframe blocks - `5% {} 100% {}`
  10158. * @param {number} i
  10159. * @return {number}
  10160. */
  10161. function checkKeyframesBlocks(i) {
  10162. if (i >= tokensLength) return 0;
  10163. var blockEnd = tokens[i].block_end;
  10164. var start = i;
  10165. var l = void 0;
  10166. if (!blockEnd) return 0;
  10167. if (l = checkSC(i)) i += l;
  10168. if (l = checkKeyframesBlock(i)) i += l;
  10169. while (i < blockEnd) {
  10170. if (l = checkSC(i)) i += l;else if (l = checkKeyframesBlock(i)) i += l;else if (l = checkAtrule(i)) i += l;else break;
  10171. }
  10172. if (i !== blockEnd + 1) return 0;
  10173. return blockEnd + 1 - start;
  10174. }
  10175. /**
  10176. * Get all keyframe blocks - `5% {} 100% {}`
  10177. * @return {Node}
  10178. */
  10179. function getKeyframesBlocks() {
  10180. var type = NodeType.BlockType;
  10181. var token = tokens[pos];
  10182. var line = token.ln;
  10183. var column = token.col;
  10184. var keyframesBlocksEnd = token.block_end;
  10185. var content = [];
  10186. while (pos < keyframesBlocksEnd) {
  10187. if (checkSC(pos)) content = content.concat(getSC());else if (checkKeyframesBlock(pos)) content.push(getKeyframesBlock());else if (checkAtrule(pos)) content.push(getAtrule()); // @content
  10188. else break;
  10189. }
  10190. return newNode(type, content, line, column);
  10191. }
  10192. /**
  10193. * Check if token is part of a @keyframes rule.
  10194. * @param {number} i Token's index number
  10195. * @return {number} Length of the @keyframes rule
  10196. */
  10197. function checkKeyframesRule(i) {
  10198. var start = i;
  10199. var l = void 0;
  10200. if (i >= tokensLength) return 0;
  10201. if (l = checkAtkeyword(i)) i += l;else return 0;
  10202. var atruleName = joinValues2(i - l, l);
  10203. if (atruleName.toLowerCase().indexOf('keyframes') === -1) return 0;
  10204. if (l = checkSC(i)) i += l;else return 0;
  10205. if (l = checkIdentOrInterpolation(i) || checkPseudoc(i)) i += l;else return 0;
  10206. if (l = checkSC(i)) i += l;
  10207. if (l = checkKeyframesBlocks(i)) i += l;else return 0;
  10208. return i - start;
  10209. }
  10210. /**
  10211. * @return {Node}
  10212. */
  10213. function getKeyframesRule() {
  10214. var type = NodeType.AtruleType;
  10215. var token = tokens[pos];
  10216. var line = token.ln;
  10217. var column = token.col;
  10218. var content = [].concat(getAtkeyword(), getSC());
  10219. if (checkIdentOrInterpolation(pos)) content = content.concat(getIdentOrInterpolation());else if (checkPseudoc(pos)) {
  10220. content = content.concat(getPseudoc());
  10221. }
  10222. content = content.concat(getSC(), getKeyframesBlocks());
  10223. return newNode(type, content, line, column);
  10224. }
  10225. /**
  10226. * Check a single keyframe selector - `5%`, `from` etc
  10227. * @param {Number} i
  10228. * @return {Number}
  10229. */
  10230. function checkKeyframesSelector(i) {
  10231. var start = i;
  10232. var l = void 0;
  10233. if (i >= tokensLength) return 0;
  10234. if (l = checkIdent(i)) {
  10235. // Valid selectors are only `from` and `to`.
  10236. var selector = joinValues2(i, l);
  10237. if (selector !== 'from' && selector !== 'to') return 0;
  10238. i += l;
  10239. tokens[start].keyframesSelectorType = 1;
  10240. } else if (l = checkPercentage(i)) {
  10241. i += l;
  10242. tokens[start].keyframesSelectorType = 2;
  10243. } else if (l = checkInterpolation(i)) {
  10244. i += l;
  10245. tokens[start].keyframesSelectorType = 3;
  10246. } else {
  10247. return 0;
  10248. }
  10249. return i - start;
  10250. }
  10251. /**
  10252. * Get a single keyframe selector
  10253. * @return {Node}
  10254. */
  10255. function getKeyframesSelector() {
  10256. var keyframesSelectorType = NodeType.KeyframesSelectorType;
  10257. var selectorType = NodeType.SelectorType;
  10258. var token = tokens[pos];
  10259. var line = token.ln;
  10260. var column = token.col;
  10261. var content = [];
  10262. if (token.keyframesSelectorType === 1) {
  10263. content.push(getIdent());
  10264. } else if (token.keyframesSelectorType === 2) {
  10265. content.push(getPercentage());
  10266. } else if (token.keyframesSelectorType === 3) {
  10267. content.push(getInterpolation());
  10268. }
  10269. var keyframesSelector = newNode(keyframesSelectorType, content, line, column);
  10270. return newNode(selectorType, [keyframesSelector], line, column);
  10271. }
  10272. /**
  10273. * Check the keyframe's selector groups
  10274. * @param {number} i
  10275. * @return {number}
  10276. */
  10277. function checkKeyframesSelectorsGroup(i) {
  10278. var start = i;
  10279. var l = void 0;
  10280. if (l = checkKeyframesSelector(i)) i += l;else return 0;
  10281. // Check for trailing space
  10282. if (l = checkSC(i) && tokens[i].type !== TokenType.Newline) i += l;
  10283. while (i < tokensLength) {
  10284. var tempStart = i;
  10285. var tempIndex = i;
  10286. var tempLength = void 0;
  10287. if (tempLength = checkDelim(tempIndex)) tempIndex += tempLength;else break;
  10288. // Check for maxmimum space usage - 'space', '\n', 'space'
  10289. if (tempLength = checkSC(tempIndex)) tempIndex += tempLength;
  10290. if (tempLength = checkSC(tempIndex)) tempIndex += tempLength;
  10291. if (tempLength = checkSC(tempIndex)) tempIndex += tempLength;
  10292. if (tempLength = checkKeyframesSelector(tempIndex)) tempIndex += tempLength;else break;
  10293. // Check for trailing space
  10294. if (tempLength = checkSC(tempIndex) && tokens[tempIndex].type !== TokenType.Newline) {
  10295. tempIndex += tempLength;
  10296. }
  10297. i += tempIndex - tempStart;
  10298. }
  10299. tokens[start].selectorsGroupEnd = i;
  10300. return i - start;
  10301. }
  10302. /**
  10303. * Get the keyframe's selector groups
  10304. * @return {Array} An array of keyframe selectors
  10305. */
  10306. function getKeyframesSelectorsGroup() {
  10307. var selectorsGroup = [];
  10308. var selectorsGroupEnd = tokens[pos].selectorsGroupEnd;
  10309. selectorsGroup.push(getKeyframesSelector());
  10310. if (checkSC(pos) && tokens[pos].type !== TokenType.Newline) {
  10311. selectorsGroup = selectorsGroup.concat(getSC());
  10312. }
  10313. while (pos < selectorsGroupEnd) {
  10314. selectorsGroup = selectorsGroup.concat(getDelim(), getSC(), getSC(), getSC(), getKeyframesSelector());
  10315. if (checkSC(pos) && tokens[pos].type !== TokenType.Newline) {
  10316. selectorsGroup = selectorsGroup.concat(getSC());
  10317. }
  10318. }
  10319. return selectorsGroup;
  10320. }
  10321. /**
  10322. * Check if token is part of a loop.
  10323. * @param {number} i Token's index number
  10324. * @return {number} Length of the loop
  10325. */
  10326. function checkLoop(i) {
  10327. var start = i;
  10328. var l = void 0;
  10329. if (i >= tokensLength) return 0;
  10330. if (l = checkAtkeyword(i)) i += l;else return 0;
  10331. if (['for', 'each', 'while'].indexOf(tokens[start + 1].value) < 0) return 0;
  10332. while (i < tokensLength) {
  10333. if (l = checkBlock(i)) {
  10334. i += l;
  10335. break;
  10336. } else if (l = checkVariable(i) || checkNumber(i) || checkInterpolation(i) || checkIdent(i) || checkSC(i) || checkOperator(i) || checkCombinator(i) || checkString(i)) i += l;else return 0;
  10337. }
  10338. return i - start;
  10339. }
  10340. /**
  10341. * Get node with a loop.
  10342. * @return {Array} `['loop', x]`
  10343. */
  10344. function getLoop() {
  10345. var type = NodeType.LoopType;
  10346. var token = tokens[pos];
  10347. var line = token.ln;
  10348. var column = token.col;
  10349. var content = [];
  10350. content.push(getAtkeyword());
  10351. while (pos < tokensLength) {
  10352. if (checkBlock(pos)) {
  10353. content.push(getBlock());
  10354. break;
  10355. } else if (checkVariable(pos)) content.push(getVariable());else if (checkNumber(pos)) content.push(getNumber());else if (checkInterpolation(pos)) content.push(getInterpolation());else if (checkIdent(pos)) content.push(getIdent());else if (checkOperator(pos)) content.push(getOperator());else if (checkCombinator(pos)) content.push(getCombinator());else if (checkSC(pos)) content = content.concat(getSC());else if (checkString(pos)) content.push(getString());
  10356. }
  10357. return newNode(type, content, line, column);
  10358. }
  10359. /**
  10360. * Check if token is part of a mixin
  10361. * @param {number} i Token's index number
  10362. * @return {number} Length of the mixin
  10363. */
  10364. function checkMixin(i) {
  10365. return checkMixin1(i) || checkMixin2(i);
  10366. }
  10367. /**
  10368. * Get node with a mixin
  10369. * @return {Array} `['mixin', x]`
  10370. */
  10371. function getMixin() {
  10372. return checkMixin1(pos) ? getMixin1() : getMixin2();
  10373. }
  10374. /**
  10375. * Check if token is part of a mixin
  10376. * @param {number} i Token's index number
  10377. * @return {number} Length of the mixin
  10378. */
  10379. function checkMixin1(i) {
  10380. var start = i;
  10381. var l = void 0;
  10382. if (i >= tokensLength) return 0;
  10383. if ((l = checkAtkeyword(i)) && tokens[i + 1].value === 'mixin') i += l;else return 0;
  10384. if (l = checkSC(i)) i += l;
  10385. if (l = checkIdentOrInterpolation(i)) i += l;else return 0;
  10386. if (l = checkSC(i)) i += l;
  10387. if (l = checkBlock(i)) i += l;else {
  10388. if (l = checkArguments(i)) i += l;
  10389. if (l = checkSC(i)) i += l;
  10390. if (l = checkBlock(i)) i += l;else return 0;
  10391. }
  10392. return i - start;
  10393. }
  10394. /**
  10395. * Get node with a mixin
  10396. * @return {Array} `['mixin', x]`
  10397. */
  10398. function getMixin1() {
  10399. var type = NodeType.MixinType;
  10400. var token = tokens[pos];
  10401. var line = token.ln;
  10402. var column = token.col;
  10403. var content = [].concat(getAtkeyword(), getSC());
  10404. if (checkIdentOrInterpolation(pos)) content = content.concat(getIdentOrInterpolation());
  10405. content = content.concat(getSC());
  10406. if (checkBlock(pos)) content.push(getBlock());else {
  10407. if (checkArguments(pos)) content.push(getArguments());
  10408. content = content.concat(getSC());
  10409. content.push(getBlock());
  10410. }
  10411. return newNode(type, content, line, column);
  10412. }
  10413. /**
  10414. * Check if token is part of a mixin
  10415. * @param {number} i Token's index number
  10416. * @return {number} Length of the mixin
  10417. */
  10418. function checkMixin2(i) {
  10419. var start = i;
  10420. var l = void 0;
  10421. if (i >= tokensLength) return 0;
  10422. if (tokens[i].type === TokenType.EqualsSign) i++;else return 0;
  10423. if (l = checkSC(i)) i += l;
  10424. if (l = checkIdentOrInterpolation(i)) i += l;else return 0;
  10425. if (l = checkSC(i)) i += l;
  10426. if (l = checkBlock(i)) i += l;else {
  10427. if (l = checkArguments(i)) i += l;
  10428. if (l = checkSC(i)) i += l;
  10429. if (l = checkBlock(i)) i += l;else return 0;
  10430. }
  10431. return i - start;
  10432. }
  10433. /**
  10434. * Get node with a mixin
  10435. * @return {Array} `['mixin', x]`
  10436. */
  10437. function getMixin2() {
  10438. var type = NodeType.MixinType;
  10439. var token = tokens[pos];
  10440. var line = token.ln;
  10441. var column = token.col;
  10442. var content = [].concat(getOperator(), getSC());
  10443. if (checkIdentOrInterpolation(pos)) content = content.concat(getIdentOrInterpolation());
  10444. content = content.concat(getSC());
  10445. if (checkBlock(pos)) content.push(getBlock());else {
  10446. if (checkArguments(pos)) content.push(getArguments());
  10447. content = content.concat(getSC());
  10448. content.push(getBlock());
  10449. }
  10450. return newNode(type, content, line, column);
  10451. }
  10452. /**
  10453. * Check if token is a namespace sign (`|`)
  10454. * @param {number} i Token's index number
  10455. * @return {number} `1` if token is `|`, `0` if not
  10456. */
  10457. function checkNamespace(i) {
  10458. return i < tokensLength && tokens[i].type === TokenType.VerticalLine ? 1 : 0;
  10459. }
  10460. /**
  10461. * Get node with a namespace sign
  10462. * @return {Array} `['namespace']`
  10463. */
  10464. function getNamespace() {
  10465. var type = NodeType.NamespaceType;
  10466. var token = tokens[pos];
  10467. var line = token.ln;
  10468. var column = token.col;
  10469. var content = '|';
  10470. pos++;
  10471. return newNode(type, content, line, column);
  10472. }
  10473. /**
  10474. * @param {number} i Token's index number
  10475. * @return {number}
  10476. */
  10477. function checkNmName2(i) {
  10478. if (tokens[i].type === TokenType.Identifier) return 1;else if (tokens[i].type !== TokenType.DecimalNumber) return 0;
  10479. i++;
  10480. return i < tokensLength && tokens[i].type === TokenType.Identifier ? 2 : 1;
  10481. }
  10482. /**
  10483. * @return {string}
  10484. */
  10485. function getNmName2() {
  10486. var s = tokens[pos].value;
  10487. if (tokens[pos++].type === TokenType.DecimalNumber && pos < tokensLength && tokens[pos].type === TokenType.Identifier) s += tokens[pos++].value;
  10488. return s;
  10489. }
  10490. /**
  10491. * Check if token is part of a number
  10492. * @param {number} i Token's index number
  10493. * @return {number} Length of number
  10494. */
  10495. function checkNumber(i) {
  10496. if (i >= tokensLength) return 0;
  10497. if (tokens[i].number_l) return tokens[i].number_l;
  10498. // `10`:
  10499. if (i < tokensLength && tokens[i].type === TokenType.DecimalNumber && (!tokens[i + 1] || tokens[i + 1] && tokens[i + 1].type !== TokenType.FullStop)) {
  10500. tokens[i].number_l = 1;
  10501. return 1;
  10502. }
  10503. // `10.`:
  10504. if (i < tokensLength && tokens[i].type === TokenType.DecimalNumber && tokens[i + 1] && tokens[i + 1].type === TokenType.FullStop && (!tokens[i + 2] || tokens[i + 2].type !== TokenType.DecimalNumber)) {
  10505. tokens[i].number_l = 2;
  10506. return 2;
  10507. }
  10508. // `.10`:
  10509. if (i < tokensLength && tokens[i].type === TokenType.FullStop && tokens[i + 1].type === TokenType.DecimalNumber) {
  10510. tokens[i].number_l = 2;
  10511. return 2;
  10512. }
  10513. // `10.10`:
  10514. if (i < tokensLength && tokens[i].type === TokenType.DecimalNumber && tokens[i + 1] && tokens[i + 1].type === TokenType.FullStop && tokens[i + 2] && tokens[i + 2].type === TokenType.DecimalNumber) {
  10515. tokens[i].number_l = 3;
  10516. return 3;
  10517. }
  10518. return 0;
  10519. }
  10520. /**
  10521. * Get node with number
  10522. * @return {Array} `['number', x]` where `x` is a number converted
  10523. * to string.
  10524. */
  10525. function getNumber() {
  10526. var type = NodeType.NumberType;
  10527. var token = tokens[pos];
  10528. var line = token.ln;
  10529. var column = token.col;
  10530. var l = tokens[pos].number_l;
  10531. var content = '';
  10532. for (var j = 0; j < l; j++) {
  10533. content += tokens[pos + j].value;
  10534. }
  10535. pos += l;
  10536. return newNode(type, content, line, column);
  10537. }
  10538. /**
  10539. * Check if token is an operator (`/`, `%`, `,`, `:` or `=`).
  10540. * @param {number} i Token's index number
  10541. * @return {number} `1` if token is an operator, otherwise `0`
  10542. */
  10543. function checkOperator(i) {
  10544. if (i >= tokensLength) return 0;
  10545. switch (tokens[i].type) {
  10546. case TokenType.Solidus:
  10547. case TokenType.PercentSign:
  10548. case TokenType.Comma:
  10549. case TokenType.Colon:
  10550. case TokenType.EqualsSign:
  10551. case TokenType.EqualitySign:
  10552. case TokenType.InequalitySign:
  10553. case TokenType.LessThanSign:
  10554. case TokenType.GreaterThanSign:
  10555. case TokenType.Asterisk:
  10556. return 1;
  10557. }
  10558. return 0;
  10559. }
  10560. /**
  10561. * Get node with an operator
  10562. * @return {Array} `['operator', x]` where `x` is an operator converted
  10563. * to string.
  10564. */
  10565. function getOperator() {
  10566. var type = NodeType.OperatorType;
  10567. var token = tokens[pos];
  10568. var line = token.ln;
  10569. var column = token.col;
  10570. var content = token.value;
  10571. pos++;
  10572. return newNode(type, content, line, column);
  10573. }
  10574. /**
  10575. * Check if token is part of `!optional` word
  10576. * @param {number} i Token's index number
  10577. * @return {number}
  10578. */
  10579. function checkOptional(i) {
  10580. var start = i;
  10581. var l = void 0;
  10582. if (i >= tokensLength || tokens[i++].type !== TokenType.ExclamationMark) return 0;
  10583. if (l = checkSC(i)) i += l;
  10584. if (tokens[i].value === 'optional') {
  10585. tokens[start].optionalEnd = i;
  10586. return i - start + 1;
  10587. } else {
  10588. return 0;
  10589. }
  10590. }
  10591. /**
  10592. * Get node with `!optional` word
  10593. */
  10594. function getOptional() {
  10595. var type = NodeType.OptionalType;
  10596. var token = tokens[pos];
  10597. var line = token.ln;
  10598. var column = token.col;
  10599. var content = joinValues(pos, token.optionalEnd);
  10600. pos = token.optionalEnd + 1;
  10601. return newNode(type, content, line, column);
  10602. }
  10603. /**
  10604. * Check if token is part of text inside parentheses, e.g. `(1)`
  10605. * @param {number} i Token's index number
  10606. * @return {number}
  10607. */
  10608. function checkParentheses(i) {
  10609. if (i >= tokensLength) return 0;
  10610. var start = i;
  10611. var right = tokens[i].right;
  10612. var l = void 0;
  10613. // Skip `(`.
  10614. if (tokens[i].type === TokenType.LeftParenthesis) i++;else return 0;
  10615. if (i < right) {
  10616. if (l = checkTsets(i)) i += l;else return 0;
  10617. }
  10618. // Skip `)`.
  10619. i++;
  10620. return i - start;
  10621. }
  10622. /**
  10623. * Get node with text inside parentheses, e.g. `(1)`
  10624. * @return {Node}
  10625. */
  10626. function getParentheses() {
  10627. var type = NodeType.ParenthesesType;
  10628. var token = tokens[pos];
  10629. var line = token.ln;
  10630. var column = token.col;
  10631. var right = token.right;
  10632. var content = [];
  10633. // Skip `(`.
  10634. pos++;
  10635. if (pos < right) {
  10636. content = getTsets();
  10637. }
  10638. var end = getLastPosition(content, line, column, 1);
  10639. // Skip `)`.
  10640. pos++;
  10641. return newNode(type, content, line, column, end);
  10642. }
  10643. /**
  10644. * Check if token is a parent selector, e.g. `&`
  10645. * @param {number} i Token's index number
  10646. * @return {number}
  10647. */
  10648. function checkParentSelector(i) {
  10649. return i < tokensLength && tokens[i].type === TokenType.Ampersand ? 1 : 0;
  10650. }
  10651. /**
  10652. * Get node with a parent selector
  10653. * @return {Node}
  10654. */
  10655. function getParentSelector() {
  10656. var type = NodeType.ParentSelectorType;
  10657. var token = tokens[pos];
  10658. var line = token.ln;
  10659. var column = token.col;
  10660. var content = '&';
  10661. pos++;
  10662. return newNode(type, content, line, column);
  10663. }
  10664. /**
  10665. * Check if token is a parent selector extension, e.g. `&--foo-bar`
  10666. * @param {number} i Token's index number
  10667. * @returns {number} Length of the parent selector extension
  10668. */
  10669. function checkParentSelectorExtension(i) {
  10670. var start = i;
  10671. var l = void 0;
  10672. if (i >= tokensLength) return 0;
  10673. while (i < tokensLength) {
  10674. if (l = checkIdentOrInterpolation(i) || checkPartialIdent(i)) i += l;else break;
  10675. }
  10676. return i - start;
  10677. }
  10678. /**
  10679. * Get parent selector extension node
  10680. * @return {Node}
  10681. */
  10682. function getParentSelectorExtension() {
  10683. var type = NodeType.ParentSelectorExtensionType;
  10684. var token = tokens[pos];
  10685. var line = token.ln;
  10686. var column = token.col;
  10687. var content = [];
  10688. while (pos < tokensLength) {
  10689. if (checkIdentOrInterpolation(pos)) {
  10690. content = content.concat(getIdentOrInterpolation());
  10691. } else if (checkPartialIdent(pos)) {
  10692. content.push(getIdent());
  10693. } else break;
  10694. }
  10695. return newNode(type, content, line, column);
  10696. }
  10697. /**
  10698. * Check if token is a parent selector with an extension or not
  10699. * @param {number} i Token's index number
  10700. * @return {number} Length of the parent selector and extension if applicable
  10701. */
  10702. function checkParentSelectorWithExtension(i) {
  10703. var start = i;
  10704. var l = void 0;
  10705. if (i >= tokensLength) return 0;
  10706. if (l = checkParentSelector(i)) i += l;else return 0;
  10707. if (l = checkParentSelectorExtension(i)) i += l;
  10708. return i - start;
  10709. }
  10710. /**
  10711. * Get parent selector node and extension node if applicable
  10712. * @return {Array}
  10713. */
  10714. function getParentSelectorWithExtension() {
  10715. var content = [getParentSelector()];
  10716. if (checkParentSelectorExtension(pos)) content.push(getParentSelectorExtension());
  10717. return content;
  10718. }
  10719. /**
  10720. * Check if token is part of a number or an interpolation with a percent sign
  10721. * (e.g. `10%`).
  10722. * @param {number} i Token's index number
  10723. * @return {number}
  10724. */
  10725. function checkPercentage(i) {
  10726. var start = i;
  10727. var l = void 0;
  10728. if (i >= tokensLength) return 0;
  10729. if (l = checkNumberOrInterpolation(i)) i += l;else return 0;
  10730. if (i >= tokensLength) return 0;
  10731. // Skip `%`.
  10732. if (tokens[i].type === TokenType.PercentSign) i++;else return 0;
  10733. return i - start;
  10734. }
  10735. /**
  10736. * Get a percentage node that contains either a number or an interpolation
  10737. * @return {Object} The percentage node
  10738. */
  10739. function getPercentage() {
  10740. var type = NodeType.PercentageType;
  10741. var token = tokens[pos];
  10742. var line = token.ln;
  10743. var column = token.col;
  10744. var content = getNumberOrInterpolation();
  10745. var end = getLastPosition(content, line, column, 1);
  10746. // Skip `%`.
  10747. pos++;
  10748. return newNode(type, content, line, column, end);
  10749. }
  10750. /**
  10751. * Check if token is a number or an interpolation
  10752. * @param {number} i Token's index number
  10753. * @return {number}
  10754. */
  10755. function checkNumberOrInterpolation(i) {
  10756. var start = i;
  10757. var l = void 0;
  10758. while (i < tokensLength) {
  10759. if (l = checkInterpolation(i) || checkNumber(i)) i += l;else break;
  10760. }
  10761. return i - start;
  10762. }
  10763. /**
  10764. * Get a number and/or interpolation node
  10765. * @return {Array} An array containing a single or multiple nodes
  10766. */
  10767. function getNumberOrInterpolation() {
  10768. var content = [];
  10769. while (pos < tokensLength) {
  10770. if (checkInterpolation(pos)) content.push(getInterpolation());else if (checkNumber(pos)) content.push(getNumber());else break;
  10771. }
  10772. return content;
  10773. }
  10774. /**
  10775. * Check if token is part of a placeholder selector (e.g. `%abc`).
  10776. * @param {number} i Token's index number
  10777. * @return {number} Length of the selector
  10778. */
  10779. function checkPlaceholder(i) {
  10780. var start = i;
  10781. var l = void 0;
  10782. if (i >= tokensLength) return 0;
  10783. if (tokens[start].placeholder_l) return tokens[start].placeholder_l;
  10784. // Skip `%`.
  10785. if (tokens[i].type === TokenType.PercentSign) i++;else return 0;
  10786. if (l = checkIdentOrInterpolation(i)) {
  10787. i += l;
  10788. tokens[start].placeholder_l = i - start;
  10789. } else return 0;
  10790. return i - start;
  10791. }
  10792. /**
  10793. * Get node with a placeholder selector
  10794. * @return {Array} `['placeholder', ['ident', x]]` where x is a placeholder's
  10795. * identifier (without `%`, e.g. `abc`).
  10796. */
  10797. function getPlaceholder() {
  10798. var type = NodeType.PlaceholderType;
  10799. var token = tokens[pos];
  10800. var line = token.ln;
  10801. var column = token.col;
  10802. var content = [];
  10803. // Skip `%`.
  10804. pos++;
  10805. content = content.concat(getIdentOrInterpolation());
  10806. return newNode(type, content, line, column);
  10807. }
  10808. /**
  10809. * @param {number} i Token's index number
  10810. * @return {number}
  10811. */
  10812. function checkProgid(i) {
  10813. var start = i;
  10814. var l = void 0;
  10815. if (i >= tokensLength) return 0;
  10816. if (joinValues2(i, 6) === 'progid:DXImageTransform.Microsoft.') i += 6;else return 0;
  10817. if (l = checkIdentOrInterpolation(i)) i += l;else return 0;
  10818. if (l = checkSC(i)) i += l;
  10819. if (tokens[i].type === TokenType.LeftParenthesis) {
  10820. tokens[start].progid_end = tokens[i].right;
  10821. i = tokens[i].right + 1;
  10822. } else return 0;
  10823. return i - start;
  10824. }
  10825. /**
  10826. * @return {Array}
  10827. */
  10828. function getProgid() {
  10829. var type = NodeType.ProgidType;
  10830. var token = tokens[pos];
  10831. var line = token.ln;
  10832. var column = token.col;
  10833. var progid_end = token.progid_end;
  10834. var content = joinValues(pos, progid_end);
  10835. pos = progid_end + 1;
  10836. return newNode(type, content, line, column);
  10837. }
  10838. /**
  10839. * Check if token is part of a property
  10840. * @param {Number} i Token's index number
  10841. * @return {Number} Length of the property
  10842. */
  10843. function checkProperty(i) {
  10844. var start = i;
  10845. var l = void 0;
  10846. if (l = checkProperty1(i)) tokens[start].propertyType = 1;else if (l = checkProperty2(i)) tokens[start].propertyType = 2;else if (l = checkProperty3(i)) tokens[start].propertyType = 3;
  10847. return l;
  10848. }
  10849. /**
  10850. * Get node with a property
  10851. * @return {!Node}
  10852. */
  10853. function getProperty() {
  10854. var type = tokens[pos].propertyType;
  10855. if (type === 1) return getProperty1();
  10856. if (type === 2) return getProperty2();
  10857. if (type === 3) return getProperty3();
  10858. }
  10859. /**
  10860. * Check if token is part of a property
  10861. * (1) `foo`
  10862. * (2) `#{$foo}`
  10863. * @param {Number} i Token's index number
  10864. * @returns {Number} Length of the property
  10865. */
  10866. function checkProperty1(i) {
  10867. var start = i;
  10868. var l = void 0;
  10869. if (i >= tokensLength) return 0;
  10870. if (l = checkIdentOrInterpolation(i)) i += l;else return 0;
  10871. return i - start;
  10872. }
  10873. /**
  10874. * Get node with a property
  10875. * @returns {Array}
  10876. */
  10877. function getProperty1() {
  10878. var type = NodeType.PropertyType;
  10879. var token = tokens[pos];
  10880. var line = token.ln;
  10881. var column = token.col;
  10882. var content = getIdentOrInterpolation();
  10883. return newNode(type, content, line, column);
  10884. }
  10885. /**
  10886. * Check if token is part of a custom property
  10887. * (1) `--foo-bar`
  10888. * @param {Number} i Token's index number
  10889. * @return {Number} Length of the property
  10890. */
  10891. function checkProperty2(i) {
  10892. return checkCustomProperty(i);
  10893. }
  10894. /**
  10895. * Get node with a custom property
  10896. * @return {Node}
  10897. */
  10898. function getProperty2() {
  10899. return getCustomProperty();
  10900. }
  10901. /**
  10902. * Check if token is part of a property
  10903. * (1) `$foo`
  10904. * @param {Number} i Token's index number
  10905. * @returns {Number} Length of the property
  10906. */
  10907. function checkProperty3(i) {
  10908. var start = i;
  10909. var l = void 0;
  10910. if (i >= tokensLength) return 0;
  10911. if (l = checkVariable(i)) i += l;else return 0;
  10912. return i - start;
  10913. }
  10914. /**
  10915. * Get node with a property
  10916. * @returns {Array} `['property', x]`
  10917. */
  10918. function getProperty3() {
  10919. var type = NodeType.PropertyType;
  10920. var token = tokens[pos];
  10921. var line = token.ln;
  10922. var column = token.col;
  10923. var content = [getVariable()];
  10924. return newNode(type, content, line, column);
  10925. }
  10926. /**
  10927. * Check if token is part of a custom property
  10928. * @param {Number} i Token's index number
  10929. * @return {Number} Length of the property
  10930. */
  10931. function checkCustomProperty(i) {
  10932. var start = i;
  10933. var l = void 0;
  10934. if (i >= tokensLength) return 0;
  10935. if (tokens[i].type !== TokenType.HyphenMinus || tokens[i + 1] && tokens[i + 1].type !== TokenType.HyphenMinus) return 0;
  10936. // Skip `--`
  10937. i += 2;
  10938. if (l = checkIdentOrInterpolation(i)) i += l;else return 0;
  10939. return i - start;
  10940. }
  10941. /**
  10942. * Get node with a custom property
  10943. * @return {Node}
  10944. */
  10945. function getCustomProperty() {
  10946. var type = NodeType.CustomPropertyType;
  10947. var token = tokens[pos];
  10948. var line = token.ln;
  10949. var column = token.col;
  10950. // Skip `--`
  10951. pos += 2;
  10952. var content = getIdentOrInterpolation();
  10953. return newNode(type, content, line, column);
  10954. }
  10955. /**
  10956. * Check if token is a colon
  10957. * @param {number} i Token's index number
  10958. * @return {number} `1` if token is a colon, otherwise `0`
  10959. */
  10960. function checkPropertyDelim(i) {
  10961. return i < tokensLength && tokens[i].type === TokenType.Colon ? 1 : 0;
  10962. }
  10963. /**
  10964. * Get node with a colon
  10965. * @return {Array} `['propertyDelim']`
  10966. */
  10967. function getPropertyDelim() {
  10968. var type = NodeType.PropertyDelimType;
  10969. var token = tokens[pos];
  10970. var line = token.ln;
  10971. var column = token.col;
  10972. var content = ':';
  10973. // Skip `:`.
  10974. pos++;
  10975. return newNode(type, content, line, column);
  10976. }
  10977. /**
  10978. * @param {number} i Token's index number
  10979. * @return {number}
  10980. */
  10981. function checkPseudo(i) {
  10982. return checkPseudoe(i) || checkPseudoc(i);
  10983. }
  10984. /**
  10985. * @return {Array}
  10986. */
  10987. function getPseudo() {
  10988. if (checkPseudoe(pos)) return getPseudoe();
  10989. if (checkPseudoc(pos)) return getPseudoc();
  10990. }
  10991. /**
  10992. * @param {Number} i Token's index number
  10993. * @return {Number}
  10994. */
  10995. function checkPseudoe(i) {
  10996. var l = void 0;
  10997. // Check `::`
  10998. if (i >= tokensLength || tokens[i].type !== TokenType.Colon || i + 1 >= tokensLength || tokens[i + 1].type !== TokenType.Colon) return 0;
  10999. if (l = checkPseudoElement1(i)) tokens[i].pseudoElementType = 1;else if (l = checkPseudoElement2(i)) tokens[i].pseudoElementType = 2;else return 0;
  11000. return l;
  11001. }
  11002. /**
  11003. * @return {Node}
  11004. */
  11005. function getPseudoe() {
  11006. var childType = tokens[pos].pseudoElementType;
  11007. if (childType === 1) return getPseudoElement1();
  11008. if (childType === 2) return getPseudoElement2();
  11009. }
  11010. /**
  11011. * (1) `::slotted(selector)`
  11012. * (2) `::slotted(selector, selector)`
  11013. */
  11014. function checkPseudoElement1(i) {
  11015. var start = i;
  11016. var l = void 0;
  11017. // Skip `::`.
  11018. i += 2;
  11019. if (i >= tokensLength) return 0;
  11020. if (l = checkIdent(i)) i += l;else return 0;
  11021. if (i >= tokensLength || tokens[i].type !== TokenType.LeftParenthesis) return 0;
  11022. var right = tokens[i].right;
  11023. // Skip `(`.
  11024. i++;
  11025. if (l = checkSC(i)) i += l;
  11026. if (l = checkSelectorsGroup(i)) i += l;else return 0;
  11027. if (l = checkSC(i)) i += l;
  11028. if (i !== right) return 0;
  11029. // Skip `)`.
  11030. i++;
  11031. return i - start;
  11032. }
  11033. /**
  11034. * (1) `::slotted(selector)`
  11035. * (2) `::slotted(selector, selector)`
  11036. */
  11037. function getPseudoElement1() {
  11038. var type = NodeType.PseudoeType;
  11039. var token = tokens[pos];
  11040. var line = token.ln;
  11041. var column = token.col;
  11042. var content = [];
  11043. // Skip `::`.
  11044. pos += 2;
  11045. content.push(getIdent());
  11046. {
  11047. var _type = NodeType.ArgumentsType;
  11048. var _token = tokens[pos];
  11049. var _line = _token.ln;
  11050. var _column = _token.col;
  11051. // Skip `(`.
  11052. pos++;
  11053. var selectorContent = [].concat(getSC(), getSelectorsGroup(), getSC());
  11054. var end = getLastPosition(selectorContent, _line, _column, 1);
  11055. var args = newNode(_type, selectorContent, _line, _column, end);
  11056. content.push(args);
  11057. // Skip `)`.
  11058. pos++;
  11059. }
  11060. return newNode(type, content, line, column);
  11061. }
  11062. function checkPseudoElement2(i) {
  11063. var start = i;
  11064. var l = void 0;
  11065. // Skip `::`.
  11066. i += 2;
  11067. if (l = checkIdentOrInterpolation(i)) i += l;else return 0;
  11068. return i - start;
  11069. }
  11070. /**
  11071. * @return {Node}
  11072. */
  11073. function getPseudoElement2() {
  11074. var type = NodeType.PseudoeType;
  11075. var token = tokens[pos];
  11076. var line = token.ln;
  11077. var column = token.col;
  11078. // Skip `::`.
  11079. pos += 2;
  11080. var content = getIdentOrInterpolation();
  11081. return newNode(type, content, line, column);
  11082. }
  11083. /**
  11084. * @param {number} i Token's index number
  11085. * @return {number}
  11086. */
  11087. function checkPseudoc(i) {
  11088. var l = void 0;
  11089. if (i >= tokensLength || tokens[i].type !== TokenType.Colon) return 0;
  11090. if (l = checkPseudoClass3(i)) tokens[i].pseudoClassType = 3;else if (l = checkPseudoClass4(i)) tokens[i].pseudoClassType = 4;else if (l = checkPseudoClass5(i)) tokens[i].pseudoClassType = 5;else if (l = checkPseudoClass1(i)) tokens[i].pseudoClassType = 1;else if (l = checkPseudoClass2(i)) tokens[i].pseudoClassType = 2;else if (l = checkPseudoClass6(i)) tokens[i].pseudoClassType = 6;else return 0;
  11091. return l;
  11092. }
  11093. /**
  11094. * @return {Array}
  11095. */
  11096. function getPseudoc() {
  11097. var childType = tokens[pos].pseudoClassType;
  11098. if (childType === 1) return getPseudoClass1();
  11099. if (childType === 2) return getPseudoClass2();
  11100. if (childType === 3) return getPseudoClass3();
  11101. if (childType === 4) return getPseudoClass4();
  11102. if (childType === 5) return getPseudoClass5();
  11103. if (childType === 6) return getPseudoClass6();
  11104. }
  11105. /**
  11106. * (-) `:not(panda)`
  11107. */
  11108. function checkPseudoClass1(i) {
  11109. var start = i;
  11110. var l = void 0;
  11111. // Skip `:`.
  11112. i++;
  11113. if (i >= tokensLength) return 0;
  11114. if (l = checkIdentOrInterpolation(i)) i += l;else return 0;
  11115. if (i >= tokensLength || tokens[i].type !== TokenType.LeftParenthesis) return 0;
  11116. var right = tokens[i].right;
  11117. // Skip `(`.
  11118. i++;
  11119. if (l = checkSC(i)) i += l;
  11120. if (l = checkSelectorsGroup(i)) i += l;else return 0;
  11121. if (l = checkSC(i)) i += l;
  11122. if (i !== right) return 0;
  11123. // Skip `)`.
  11124. i++;
  11125. return i - start;
  11126. }
  11127. /**
  11128. * (-) `:not(panda)`
  11129. */
  11130. function getPseudoClass1() {
  11131. var type = NodeType.PseudocType;
  11132. var token = tokens[pos];
  11133. var line = token.ln;
  11134. var column = token.col;
  11135. var content = [];
  11136. // Skip `:`.
  11137. pos++;
  11138. content = content.concat(getIdentOrInterpolation());
  11139. {
  11140. var _type2 = NodeType.ArgumentsType;
  11141. var _token2 = tokens[pos];
  11142. var _line2 = _token2.ln;
  11143. var _column2 = _token2.col;
  11144. // Skip `(`.
  11145. pos++;
  11146. var selectorContent = [].concat(getSC(), getSelectorsGroup(), getSC());
  11147. var end = getLastPosition(selectorContent, _line2, _column2, 1);
  11148. var args = newNode(_type2, selectorContent, _line2, _column2, end);
  11149. content.push(args);
  11150. // Skip `)`.
  11151. pos++;
  11152. }
  11153. return newNode(type, content, line, column);
  11154. }
  11155. /**
  11156. * (1) `:nth-child(odd)`
  11157. * (2) `:nth-child(even)`
  11158. * (3) `:lang(de-DE)`
  11159. */
  11160. function checkPseudoClass2(i) {
  11161. var start = i;
  11162. var l = void 0;
  11163. // Skip `:`.
  11164. i++;
  11165. if (i >= tokensLength) return 0;
  11166. if (l = checkIdentOrInterpolation(i)) i += l;else return 0;
  11167. if (i >= tokensLength || tokens[i].type !== TokenType.LeftParenthesis) return 0;
  11168. var right = tokens[i].right;
  11169. // Skip `(`.
  11170. i++;
  11171. if (l = checkSC(i)) i += l;
  11172. if (l = checkIdentOrInterpolation(i)) i += l;else return 0;
  11173. if (l = checkSC(i)) i += l;
  11174. if (i !== right) return 0;
  11175. // Skip `)`.
  11176. i++;
  11177. return i - start;
  11178. }
  11179. function getPseudoClass2() {
  11180. var type = NodeType.PseudocType;
  11181. var token = tokens[pos];
  11182. var line = token.ln;
  11183. var column = token.col;
  11184. var content = [];
  11185. // Skip `:`.
  11186. pos++;
  11187. content = content.concat(getIdentOrInterpolation());
  11188. var l = tokens[pos].ln;
  11189. var c = tokens[pos].col;
  11190. // Skip `(`.
  11191. pos++;
  11192. var value = [].concat(getSC(), getIdentOrInterpolation(), getSC());
  11193. var end = getLastPosition(value, l, c, 1);
  11194. var args = newNode(NodeType.ArgumentsType, value, l, c, end);
  11195. content.push(args);
  11196. // Skip `)`.
  11197. pos++;
  11198. return newNode(type, content, line, column);
  11199. }
  11200. /**
  11201. * (-) `:nth-child(-3n + 2)`
  11202. */
  11203. function checkPseudoClass3(i) {
  11204. var start = i;
  11205. var l = void 0;
  11206. // Skip `:`.
  11207. i++;
  11208. if (i >= tokensLength) return 0;
  11209. if (l = checkIdentOrInterpolation(i)) i += l;else return 0;
  11210. if (i >= tokensLength || tokens[i].type !== TokenType.LeftParenthesis) return 0;
  11211. var right = tokens[i].right;
  11212. // Skip `(`.
  11213. i++;
  11214. if (l = checkSC(i)) i += l;
  11215. if (l = checkUnary(i)) i += l;
  11216. if (l = checkNumberOrInterpolation(i)) i += l;
  11217. if (i >= tokensLength) return 0;
  11218. if (tokens[i].value === 'n') i++;
  11219. if (l = checkSC(i)) i += l;
  11220. if (i >= tokensLength) return 0;
  11221. if (tokens[i].type === TokenType.PlusSign || tokens[i].type === TokenType.HyphenMinus) i++;else return 0;
  11222. if (l = checkSC(i)) i += l;
  11223. if (l = checkNumberOrInterpolation(i)) i += l;else return 0;
  11224. if (l = checkSC(i)) i += l;
  11225. if (i !== right) return 0;
  11226. // Skip `)`.
  11227. i++;
  11228. return i - start;
  11229. }
  11230. function getPseudoClass3() {
  11231. var type = NodeType.PseudocType;
  11232. var token = tokens[pos];
  11233. var line = token.ln;
  11234. var column = token.col;
  11235. var content = [];
  11236. // Skip `:`.
  11237. pos++;
  11238. content = content.concat(getIdentOrInterpolation());
  11239. var l = tokens[pos].ln;
  11240. var c = tokens[pos].col;
  11241. var value = [];
  11242. // Skip `(`.
  11243. pos++;
  11244. value = value.concat(getSC());
  11245. if (checkUnary(pos)) value.push(getUnary());
  11246. if (checkNumberOrInterpolation(pos)) value = value.concat(getNumberOrInterpolation());
  11247. {
  11248. var _token3 = tokens[pos];
  11249. if (_token3.value === 'n') {
  11250. var _l = _token3.ln;
  11251. var _c = _token3.col;
  11252. var _content2 = _token3.value;
  11253. var ident = newNode(NodeType.IdentType, _content2, _l, _c);
  11254. value.push(ident);
  11255. pos++;
  11256. }
  11257. }
  11258. value = value.concat(getSC());
  11259. if (checkUnary(pos)) value.push(getUnary());
  11260. value = value.concat(getSC());
  11261. if (checkNumberOrInterpolation(pos)) value = value.concat(getNumberOrInterpolation());
  11262. value = value.concat(getSC());
  11263. var end = getLastPosition(value, l, c, 1);
  11264. var args = newNode(NodeType.ArgumentsType, value, l, c, end);
  11265. content.push(args);
  11266. // Skip `)`.
  11267. pos++;
  11268. return newNode(type, content, line, column);
  11269. }
  11270. /**
  11271. * (-) `:nth-child(-3n)`
  11272. */
  11273. function checkPseudoClass4(i) {
  11274. var start = i;
  11275. var l = void 0;
  11276. // Skip `:`.
  11277. i++;
  11278. if (i >= tokensLength) return 0;
  11279. if (l = checkIdentOrInterpolation(i)) i += l;else return 0;
  11280. if (i >= tokensLength) return 0;
  11281. if (tokens[i].type !== TokenType.LeftParenthesis) return 0;
  11282. var right = tokens[i].right;
  11283. // Skip `(`.
  11284. i++;
  11285. if (l = checkSC(i)) i += l;
  11286. if (l = checkUnary(i)) i += l;
  11287. if (l = checkInterpolation(i)) i += l;
  11288. if (tokens[i].type === TokenType.DecimalNumber) i++;
  11289. if (tokens[i].value === 'n') i++;else return 0;
  11290. if (l = checkSC(i)) i += l;
  11291. if (i !== right) return 0;
  11292. // Skip `)`.
  11293. i++;
  11294. return i - start;
  11295. }
  11296. function getPseudoClass4() {
  11297. var type = NodeType.PseudocType;
  11298. var token = tokens[pos];
  11299. var line = token.ln;
  11300. var column = token.col;
  11301. var content = [];
  11302. // Skip `:`.
  11303. pos++;
  11304. content = content.concat(getIdentOrInterpolation());
  11305. var l = tokens[pos].ln;
  11306. var c = tokens[pos].col;
  11307. var value = [];
  11308. // Skip `(`.
  11309. pos++;
  11310. value = value.concat(getSC());
  11311. if (checkUnary(pos)) value.push(getUnary());
  11312. if (checkInterpolation(pos)) value.push(getInterpolation());
  11313. if (checkNumber(pos)) value.push(getNumber());
  11314. if (checkIdent(pos)) value.push(getIdent());
  11315. value = value.concat(getSC());
  11316. var end = getLastPosition(value, l, c, 1);
  11317. var args = newNode(NodeType.ArgumentsType, value, l, c, end);
  11318. content.push(args);
  11319. // Skip `)`.
  11320. pos++;
  11321. return newNode(type, content, line, column);
  11322. }
  11323. /**
  11324. * (-) `:nth-child(+8)`
  11325. */
  11326. function checkPseudoClass5(i) {
  11327. var start = i;
  11328. var l = void 0;
  11329. // Skip `:`.
  11330. i++;
  11331. if (i >= tokensLength) return 0;
  11332. if (l = checkIdentOrInterpolation(i)) i += l;else return 0;
  11333. if (i >= tokensLength) return 0;
  11334. if (tokens[i].type !== TokenType.LeftParenthesis) return 0;
  11335. var right = tokens[i].right;
  11336. // Skip `(`.
  11337. i++;
  11338. if (l = checkSC(i)) i += l;
  11339. if (l = checkUnary(i)) i += l;
  11340. if (tokens[i].type === TokenType.DecimalNumber) i++;else return 0;
  11341. if (l = checkSC(i)) i += l;
  11342. if (i !== right) return 0;
  11343. // Skip `)`.
  11344. i++;
  11345. return i - start;
  11346. }
  11347. function getPseudoClass5() {
  11348. var type = NodeType.PseudocType;
  11349. var token = tokens[pos];
  11350. var line = token.ln;
  11351. var column = token.col;
  11352. var content = [];
  11353. // Skip `:`.
  11354. pos++;
  11355. content = content.concat(getIdentOrInterpolation());
  11356. var l = tokens[pos].ln;
  11357. var c = tokens[pos].col;
  11358. var value = [];
  11359. // Skip `(`.
  11360. pos++;
  11361. value = value.concat(getSC());
  11362. if (checkUnary(pos)) value.push(getUnary());
  11363. if (checkNumber(pos)) value.push(getNumber());
  11364. value = value.concat(getSC());
  11365. var end = getLastPosition(value, l, c, 1);
  11366. var args = newNode(NodeType.ArgumentsType, value, l, c, end);
  11367. content.push(args);
  11368. // Skip `)`.
  11369. pos++;
  11370. return newNode(type, content, line, column);
  11371. }
  11372. /**
  11373. * (-) `:checked`
  11374. */
  11375. function checkPseudoClass6(i) {
  11376. var start = i;
  11377. var l = void 0;
  11378. // Skip `:`.
  11379. i++;
  11380. if (i >= tokensLength) return 0;
  11381. if (l = checkIdentOrInterpolation(i)) i += l;else return 0;
  11382. return i - start;
  11383. }
  11384. function getPseudoClass6() {
  11385. var type = NodeType.PseudocType;
  11386. var token = tokens[pos];
  11387. var line = token.ln;
  11388. var column = token.col;
  11389. // Skip `:`.
  11390. pos++;
  11391. var content = getIdentOrInterpolation();
  11392. return newNode(type, content, line, column);
  11393. }
  11394. /**
  11395. * @param {number} i Token's index number
  11396. * @return {number}
  11397. */
  11398. function checkRuleset(i) {
  11399. var start = i;
  11400. var l = void 0;
  11401. if (i >= tokensLength) return 0;
  11402. if (l = checkSelectorsGroup(i)) i += l;else return 0;
  11403. if (l = checkSC(i)) i += l;
  11404. if (l = checkBlock(i)) {
  11405. i += l;
  11406. } else if (l = checkSC(i)) {
  11407. i += l;
  11408. if (l = checkBlock(i)) i += l;else return 0;
  11409. } else return 0;
  11410. return i - start;
  11411. }
  11412. function getRuleset() {
  11413. var type = NodeType.RulesetType;
  11414. var token = tokens[pos];
  11415. var line = token.ln;
  11416. var column = token.col;
  11417. var content = [].concat(getSelectorsGroup(), getSC());
  11418. if (checkBlock(pos)) {
  11419. content.push(getBlock());
  11420. } else {
  11421. content = content.concat(getSC(), getBlock());
  11422. }
  11423. return newNode(type, content, line, column);
  11424. }
  11425. /**
  11426. * Check if token is marked as a space (if it's a space or a tab
  11427. * or a line break).
  11428. * @param {number} i
  11429. * @return {number} Number of spaces in a row starting with the given token.
  11430. */
  11431. function checkS(i) {
  11432. return i < tokensLength && tokens[i].ws ? tokens[i].ws_last - i + 1 : 0;
  11433. }
  11434. /**
  11435. * Get node with spaces
  11436. * @return {Array} `['s', x]` where `x` is a string containing spaces
  11437. */
  11438. function getS() {
  11439. var type = NodeType.SType;
  11440. var token = tokens[pos];
  11441. var line = token.ln;
  11442. var column = token.col;
  11443. var content = joinValues(pos, tokens[pos].ws_last);
  11444. pos = tokens[pos].ws_last + 1;
  11445. return newNode(type, content, line, column);
  11446. }
  11447. /**
  11448. * Check if token is a space, newline, or a comment.
  11449. * @param {number} i Token's index number
  11450. * @return {number} Number of similar (space, newline, or comment) tokens
  11451. * in a row starting with the given token.
  11452. */
  11453. function checkMultilineSC(i) {
  11454. if (!tokens[i]) return 0;
  11455. var l = void 0;
  11456. var lsc = 0;
  11457. while (i < tokensLength) {
  11458. if (!(l = checkS(i)) && !(l = checkCommentML(i)) && !(l = checkCommentSL(i))) break;
  11459. i += l;
  11460. lsc += l;
  11461. }
  11462. return lsc || 0;
  11463. }
  11464. /**
  11465. * Get node with spaces newlines and comments
  11466. * @return {!Node}
  11467. */
  11468. function getMultilineSC() {
  11469. var sc = [];
  11470. if (pos >= tokensLength) return sc;
  11471. while (pos < tokensLength) {
  11472. if (checkS(pos)) sc.push(getS());else if (checkCommentML(pos)) sc.push(getCommentML());else if (checkCommentSL(pos)) sc.push(getCommentSL());else break;
  11473. }
  11474. return sc;
  11475. }
  11476. /**
  11477. * Check if token is a space or a comment.
  11478. * @param {number} i Token's index number
  11479. * @return {number} Number of similar (space or comment) tokens
  11480. * in a row starting with the given token.
  11481. */
  11482. function checkSC(i) {
  11483. if (i >= tokensLength) return 0;
  11484. var l = void 0;
  11485. var lsc = 0;
  11486. var ln = tokens[i].ln;
  11487. while (i < tokensLength) {
  11488. if (tokens[i].ln !== ln) break;
  11489. if (l = checkS(i)) tokens[i].sc_child = 1;else if (l = checkCommentML(i)) tokens[i].sc_child = 2;else if (l = checkCommentSL(i)) tokens[i].sc_child = 3;else break;
  11490. i += l;
  11491. lsc += l;
  11492. if (tokens[i] && tokens[i].type === TokenType.Newline) break;
  11493. }
  11494. return lsc || 0;
  11495. }
  11496. /**
  11497. * Get node with spaces and comments
  11498. * @return {Array} Array containing nodes with spaces (if there are any)
  11499. * and nodes with comments (if there are any):
  11500. * `[['s', x]*, ['comment', y]*]` where `x` is a string of spaces
  11501. * and `y` is a comment's text (without `/*` and `* /`).
  11502. */
  11503. function getSC() {
  11504. var sc = [];
  11505. if (pos >= tokensLength) return sc;
  11506. var ln = tokens[pos].ln;
  11507. while (pos < tokensLength) {
  11508. if (tokens[pos].ln !== ln) break;else if (checkS(pos)) sc.push(getS());else if (checkCommentML(pos)) sc.push(getCommentML());else if (checkCommentSL(pos)) sc.push(getCommentSL());else break;
  11509. if (tokens[pos] && tokens[pos].type === TokenType.Newline) break;
  11510. }
  11511. return sc;
  11512. }
  11513. /**
  11514. * Check if token is part of a hexadecimal number (e.g. `#fff`) inside a simple
  11515. * selector
  11516. * @param {number} i Token's index number
  11517. * @return {number}
  11518. */
  11519. function checkShash(i) {
  11520. var start = i;
  11521. var l = void 0;
  11522. if (i >= tokensLength) return 0;
  11523. if (tokens[i].type === TokenType.NumberSign) i++;else return 0;
  11524. if (l = checkIdentOrInterpolation(i) || checkPartialIdent(i)) i += l;else return 0;
  11525. while (i < tokensLength) {
  11526. if (l = checkIdentOrInterpolation(i) || checkPartialIdent(i)) i += l;else break;
  11527. }
  11528. tokens[start].shashEnd = i;
  11529. return i - start;
  11530. }
  11531. /**
  11532. * Get node with a hexadecimal number (e.g. `#fff`) inside a simple selector
  11533. * @return {Node}
  11534. */
  11535. function getShash() {
  11536. var type = NodeType.ShashType;
  11537. var token = tokens[pos];
  11538. var line = token.ln;
  11539. var column = token.col;
  11540. var end = token.shashEnd;
  11541. var content = [];
  11542. // Skip `#`.
  11543. pos++;
  11544. while (pos < end) {
  11545. if (checkIdentOrInterpolation(pos)) {
  11546. content = content.concat(getIdentOrInterpolation());
  11547. } else if (checkPartialIdent(pos)) {
  11548. content.push(getIdent());
  11549. } else break;
  11550. }
  11551. return newNode(type, content, line, column);
  11552. }
  11553. /**
  11554. * Check if token is part of a string (text wrapped in quotes)
  11555. * @param {number} i Token's index number
  11556. * @return {number} `1` if token is part of a string, `0` if not
  11557. */
  11558. function checkString(i) {
  11559. if (i >= tokensLength) return 0;
  11560. if (tokens[i].type === TokenType.StringSQ || tokens[i].type === TokenType.StringDQ) {
  11561. return 1;
  11562. }
  11563. return 0;
  11564. }
  11565. /**
  11566. * Get string's node
  11567. * @return {Array} `['string', x]` where `x` is a string (including
  11568. * quotes).
  11569. */
  11570. function getString() {
  11571. var type = NodeType.StringType;
  11572. var token = tokens[pos];
  11573. var line = token.ln;
  11574. var column = token.col;
  11575. var content = token.value;
  11576. pos++;
  11577. return newNode(type, content, line, column);
  11578. }
  11579. /**
  11580. * Validate stylesheet: it should consist of any number (0 or more) of
  11581. * rulesets (sets of rules with selectors), @-rules, whitespaces or
  11582. * comments.
  11583. * @param {number} i Token's index number
  11584. * @return {number}
  11585. */
  11586. function checkStylesheet(i) {
  11587. var start = i;
  11588. var l = void 0;
  11589. while (i < tokensLength) {
  11590. if (l = checkSC(i) || checkDeclaration(i) || checkDeclDelim(i) || checkInclude(i) || checkExtend(i) || checkMixin(i) || checkLoop(i) || checkConditionalStatement(i) || checkAtrule(i) || checkRuleset(i)) i += l;else throwError(i);
  11591. }
  11592. return i - start;
  11593. }
  11594. /**
  11595. * @return {Array} `['stylesheet', x]` where `x` is all stylesheet's
  11596. * nodes.
  11597. */
  11598. function getStylesheet() {
  11599. var type = NodeType.StylesheetType;
  11600. var token = tokens[pos];
  11601. var line = token.ln;
  11602. var column = token.col;
  11603. var content = [];
  11604. var node = void 0;
  11605. var wasDeclaration = false;
  11606. while (pos < tokensLength) {
  11607. if (wasDeclaration && checkDeclDelim(pos)) node = getDeclDelim();else if (checkSC(pos)) node = getSC();else if (checkRuleset(pos)) node = getRuleset();else if (checkInclude(pos)) node = getInclude();else if (checkExtend(pos)) node = getExtend();else if (checkMixin(pos)) node = getMixin();else if (checkLoop(pos)) node = getLoop();else if (checkConditionalStatement(pos)) node = getConditionalStatement();else if (checkAtrule(pos)) node = getAtrule();else if (checkDeclaration(pos)) node = getDeclaration();else throwError(pos);
  11608. wasDeclaration = node.type === NodeType.DeclarationType;
  11609. if (Array.isArray(node)) content = content.concat(node);else content.push(node);
  11610. }
  11611. return newNode(type, content, line, column);
  11612. }
  11613. /**
  11614. * @param {Number} i Token's index number
  11615. * @return {Number}
  11616. */
  11617. function checkTset(i) {
  11618. return checkVhash(i) || checkOperator(i) || checkAny(i) || checkSC(i);
  11619. }
  11620. /**
  11621. * @return {Array}
  11622. */
  11623. function getTset() {
  11624. if (checkVhash(pos)) return getVhash();else if (checkOperator(pos)) return getOperator();else if (checkAny(pos)) return getAny();else if (checkSC(pos)) return getSC();
  11625. }
  11626. /**
  11627. * @param {number} i Token's index number
  11628. * @return {number}
  11629. */
  11630. function checkTsets(i) {
  11631. var start = i;
  11632. var l = void 0;
  11633. if (i >= tokensLength) return 0;
  11634. while (tokens[i - 1].type !== TokenType.Newline && (l = checkTset(i))) {
  11635. i += l;
  11636. }
  11637. return i - start;
  11638. }
  11639. /**
  11640. * @return {Array}
  11641. */
  11642. function getTsets() {
  11643. var content = [];
  11644. var t = void 0;
  11645. while (tokens[pos - 1].type !== TokenType.Newline && (t = getTset())) {
  11646. if (typeof t.content === 'string') content.push(t);else content = content.concat(t);
  11647. }
  11648. return content;
  11649. }
  11650. /**
  11651. * Check if token is an unary (arithmetical) sign (`+` or `-`)
  11652. * @param {number} i Token's index number
  11653. * @return {number} `1` if token is an unary sign, `0` if not
  11654. */
  11655. function checkUnary(i) {
  11656. if (i >= tokensLength) return 0;
  11657. if (tokens[i].type === TokenType.HyphenMinus || tokens[i].type === TokenType.PlusSign) {
  11658. return 1;
  11659. }
  11660. return 0;
  11661. }
  11662. /**
  11663. * Get node with an unary (arithmetical) sign (`+` or `-`)
  11664. * @return {Array} `['unary', x]` where `x` is an unary sign
  11665. * converted to string.
  11666. */
  11667. function getUnary() {
  11668. var type = NodeType.OperatorType;
  11669. var token = tokens[pos];
  11670. var line = token.ln;
  11671. var column = token.col;
  11672. var content = token.value;
  11673. pos++;
  11674. return newNode(type, content, line, column);
  11675. }
  11676. /**
  11677. * Check if token is a unicode range (single or multiple <urange> nodes)
  11678. * @param {number} i Token's index
  11679. * @return {number} Unicode range node's length
  11680. */
  11681. function checkUnicodeRange(i) {
  11682. var start = i;
  11683. var l = void 0;
  11684. if (i >= tokensLength) return 0;
  11685. if (l = checkUrange(i)) i += l;else return 0;
  11686. while (i < tokensLength) {
  11687. var spaceBefore = checkSC(i);
  11688. var comma = checkDelim(i + spaceBefore);
  11689. if (!comma) break;
  11690. var spaceAfter = checkSC(i + spaceBefore + comma);
  11691. if (l = checkUrange(i + spaceBefore + comma + spaceAfter)) {
  11692. i += spaceBefore + comma + spaceAfter + l;
  11693. } else break;
  11694. }
  11695. return i - start;
  11696. }
  11697. /**
  11698. * Get a unicode range node
  11699. * @return {Node}
  11700. */
  11701. function getUnicodeRange() {
  11702. var type = NodeType.UnicodeRangeType;
  11703. var token = tokens[pos];
  11704. var line = token.ln;
  11705. var column = token.col;
  11706. var content = [];
  11707. while (pos < tokensLength) {
  11708. if (checkSC(pos)) content = content.concat(getSC());else if (checkDelim(pos)) content.push(getDelim());else if (checkUrange(pos)) content.push(getUrange());else break;
  11709. }
  11710. return newNode(type, content, line, column);
  11711. }
  11712. /**
  11713. * Check if token is unit
  11714. * @param {Number} i Token's index number
  11715. * @return {Number}
  11716. */
  11717. function checkUnit(i) {
  11718. var units = ['em', 'ex', 'ch', 'rem', 'vh', 'vw', 'vmin', 'vmax', 'px', 'mm', 'q', 'cm', 'in', 'pt', 'pc', 'deg', 'grad', 'rad', 'turn', 's', 'ms', 'Hz', 'kHz', 'dpi', 'dpcm', 'dppx'];
  11719. return units.indexOf(tokens[i].value) !== -1 ? 1 : 0;
  11720. }
  11721. /**
  11722. * Get unit node of type ident
  11723. * @return {Node} An ident node containing the unit value
  11724. */
  11725. function getUnit() {
  11726. var type = NodeType.IdentType;
  11727. var token = tokens[pos];
  11728. var line = token.ln;
  11729. var column = token.col;
  11730. var content = token.value;
  11731. pos++;
  11732. return newNode(type, content, line, column);
  11733. }
  11734. /**
  11735. * Check if token is a u-range (part of a unicode-range)
  11736. * (1) `U+416`
  11737. * (2) `U+400-4ff`
  11738. * (3) `U+4??`
  11739. * @param {number} i Token's index
  11740. * @return {number} Urange node's length
  11741. */
  11742. function checkUrange(i) {
  11743. var start = i;
  11744. var l = void 0;
  11745. if (i >= tokensLength) return 0;
  11746. // Check for unicode prefix (u+ or U+)
  11747. if (tokens[i].value === 'U' || tokens[i].value === 'u') i += 1;else return 0;
  11748. if (i >= tokensLength) return 0;
  11749. if (tokens[i].value === '+') i += 1;else return 0;
  11750. while (i < tokensLength) {
  11751. if (l = checkIdent(i)) i += l;else if (l = checkNumber(i)) i += l;else if (l = checkUnary(i)) i += l;else if (l = _checkUnicodeWildcard(i)) i += l;else break;
  11752. }
  11753. tokens[start].urangeEnd = i - 1;
  11754. return i - start;
  11755. }
  11756. /**
  11757. * Get a u-range node (part of a unicode-range)
  11758. * @return {Node}
  11759. */
  11760. function getUrange() {
  11761. var startPos = pos;
  11762. var type = NodeType.UrangeType;
  11763. var token = tokens[pos];
  11764. var line = token.ln;
  11765. var column = token.col;
  11766. var content = [];
  11767. content = joinValues(startPos, tokens[startPos].urangeEnd);
  11768. pos = tokens[startPos].urangeEnd + 1;
  11769. return newNode(type, content, line, column);
  11770. }
  11771. /**
  11772. * Check for unicode wildcard characters `?`
  11773. * @param {number} i Token's index
  11774. * @return {number} Wildcard length
  11775. */
  11776. function _checkUnicodeWildcard(i) {
  11777. var start = i;
  11778. if (i >= tokensLength) return 0;
  11779. while (i < tokensLength) {
  11780. if (tokens[i].type === TokenType.QuestionMark) i += 1;else break;
  11781. }
  11782. return i - start;
  11783. }
  11784. /**
  11785. * Check if token is part of URI, e.g. `url('/css/styles.css')`
  11786. * @param {number} i Token's index number
  11787. * @returns {number} Length of URI
  11788. */
  11789. function checkUri(i) {
  11790. var start = i;
  11791. var l = void 0;
  11792. if (i >= tokensLength || tokens[i].value !== 'url') return 0;
  11793. // Skip `url`.
  11794. i++;
  11795. if (i >= tokensLength || tokens[i].type !== TokenType.LeftParenthesis) return 0;
  11796. // Store the opening parenthesis token as we will reference it's `right`
  11797. // property to determine when the parentheses close
  11798. var leftParenthesis = tokens[i];
  11799. // Skip `(`.
  11800. i++;
  11801. // Determine the type of URI
  11802. while (i < leftParenthesis.right) {
  11803. if (l = checkUri1(i)) {
  11804. i += l;
  11805. tokens[start].uriType = 1; // Raw based URI (without quotes)
  11806. } else if (l = checkUri2(i)) {
  11807. i += l;
  11808. tokens[start].uriType = 2; // Non-raw based URI (with quotes)
  11809. } else return 0;
  11810. }
  11811. // Skip `)`.
  11812. i++;
  11813. return i - start;
  11814. }
  11815. /**
  11816. * Get specific type of URI node
  11817. * @return {Node} Specific type of URI node
  11818. */
  11819. function getUri() {
  11820. var startPos = pos;
  11821. var type = NodeType.UriType;
  11822. var token = tokens[startPos];
  11823. var line = token.ln;
  11824. var column = token.col;
  11825. var content = [];
  11826. var end = void 0;
  11827. var uriType = tokens[startPos].uriType;
  11828. // Skip `url` and `(`.
  11829. pos += 2;
  11830. if (uriType === 1) content = content.concat(getUri1());else if (uriType === 2) content = content.concat(getUri2());else end = getLastPosition(content, line, column, 4);
  11831. if (!end) end = getLastPosition(content, line, column, 1);
  11832. // Skip `)`.
  11833. pos++;
  11834. return newNode(type, content, line, column, end);
  11835. }
  11836. /**
  11837. * Check if token type is valid URI character
  11838. * @param {number} i Token's index number
  11839. * @return {number} Length of raw node
  11840. */
  11841. function checkUriRawCharacters(i) {
  11842. var start = i;
  11843. var l = void 0;
  11844. if (l = checkIdent(i)) i += l;else if (l = checkNumber(i)) i += l;else {
  11845. switch (tokens[i].type) {
  11846. case TokenType.ExclamationMark:
  11847. case TokenType.NumberSign:
  11848. case TokenType.DollarSign:
  11849. case TokenType.PercentSign:
  11850. case TokenType.Ampersand:
  11851. case TokenType.Asterisk:
  11852. case TokenType.PlusSign:
  11853. case TokenType.Comma:
  11854. case TokenType.HyphenMinus:
  11855. case TokenType.FullStop:
  11856. case TokenType.Solidus:
  11857. case TokenType.Colon:
  11858. case TokenType.Semicolon:
  11859. case TokenType.LessThanSign:
  11860. case TokenType.EqualsSign:
  11861. case TokenType.GreaterThanSign:
  11862. case TokenType.QuotationMark:
  11863. case TokenType.CommercialAt:
  11864. case TokenType.LeftSquareBracket:
  11865. case TokenType.RightSquareBracket:
  11866. case TokenType.CircumflexAccent:
  11867. case TokenType.LowLine:
  11868. case TokenType.LeftCurlyBracket:
  11869. case TokenType.VerticalLine:
  11870. case TokenType.RightCurlyBracket:
  11871. case TokenType.Tilde:
  11872. i += 1;
  11873. break;
  11874. default:
  11875. return 0;
  11876. }
  11877. }
  11878. return i - start;
  11879. }
  11880. /**
  11881. * Check if content of URI can be contained within a raw node
  11882. * @param {number} i Token's index number
  11883. * @return {number} Length of raw node
  11884. */
  11885. function checkUriRaw(i) {
  11886. var start = i;
  11887. var l = void 0;
  11888. while (i < tokensLength) {
  11889. if (checkInterpolation(i) || checkVariable(i)) break;else if (l = checkUriRawCharacters(i)) i += l;else break;
  11890. }
  11891. tokens[start].uri_raw_end = i;
  11892. return i - start;
  11893. }
  11894. /**
  11895. * Get a raw node
  11896. * @return {Node}
  11897. */
  11898. function getUriRaw() {
  11899. var startPos = pos;
  11900. var type = NodeType.RawType;
  11901. var token = tokens[startPos];
  11902. var line = token.ln;
  11903. var column = token.col;
  11904. var content = [];
  11905. var l = void 0;
  11906. while (pos < tokens[startPos].uri_raw_end) {
  11907. if (checkInterpolation(pos) || checkVariable(pos)) break;else if (l = checkUriRawCharacters(pos)) pos += l;else break;
  11908. }
  11909. content = joinValues(startPos, pos - 1);
  11910. return newNode(type, content, line, column);
  11911. }
  11912. /**
  11913. * Check for a raw (without quotes) URI
  11914. * (1) http://foo.com/bar.png
  11915. * (2) http://foo.com/#{$bar}.png
  11916. * (3) #{$foo}/bar.png
  11917. * (4) #{$foo}
  11918. * @param {number} i Token's index number
  11919. * @return {number} Length of URI node
  11920. */
  11921. function checkUri1(i) {
  11922. var start = i;
  11923. var l = void 0;
  11924. if (l = checkSC(i)) i += l;
  11925. while (i < tokensLength) {
  11926. if (l = checkInterpolation(i) || checkUriRaw(i)) i += l;else break;
  11927. }
  11928. if (l = checkSC(i)) i += l;
  11929. // Check that we are at the end of the uri
  11930. if (i < tokens[start - 1].right) return 0;
  11931. tokens[start].uri_end = i;
  11932. return i - start;
  11933. }
  11934. /**
  11935. * Get a raw (without quotes) URI
  11936. node
  11937. * @return {Array}
  11938. */
  11939. function getUri1() {
  11940. var startPos = pos;
  11941. var content = [];
  11942. if (checkSC(pos)) content = content.concat(getSC());
  11943. while (pos < tokens[startPos].uri_end) {
  11944. if (checkInterpolation(pos)) content.push(getInterpolation());else if (checkUriRaw(pos)) content.push(getUriRaw());else break;
  11945. }
  11946. if (checkSC(pos)) content = content.concat(getSC());
  11947. return content;
  11948. }
  11949. /**
  11950. * Check for a non-raw (with quotes) URI
  11951. * (1) 'http://foo.com/bar.png'
  11952. * (2) 'http://foo.com/'#{$bar}.png
  11953. * (3) #{$foo}'/bar.png'
  11954. * @param {number} i Token's index number
  11955. * @return {number} Length of URI node
  11956. */
  11957. function checkUri2(i) {
  11958. var start = i;
  11959. var l = void 0;
  11960. while (i < tokensLength) {
  11961. if (l = checkSC(i)) i += l;else if (l = checkString(i)) i += l;else if (l = checkFunction(i)) i += l;else if (l = checkUnary(i)) i += l;else if (l = checkIdentOrInterpolation(i)) i += l;else if (l = checkVariable(i)) i += l;else break;
  11962. }
  11963. // Check that we are at the end of the uri
  11964. if (i < tokens[start - 1].right) return 0;
  11965. tokens[start].uri_end = i;
  11966. return i - start;
  11967. }
  11968. /**
  11969. * Get a non-raw (with quotes) URI node
  11970. * @return {Array}
  11971. */
  11972. function getUri2() {
  11973. var startPos = pos;
  11974. var content = [];
  11975. while (pos < tokens[startPos].uri_end) {
  11976. if (checkSC(pos)) content = content.concat(getSC());else if (checkUnary(pos)) content.push(getUnary());else if (_checkValue(pos)) content.push(_getValue());else break;
  11977. }
  11978. return content;
  11979. }
  11980. /**
  11981. * Check if token is part of a value
  11982. * @param {number} i Token's index number
  11983. * @return {number} Length of the value
  11984. */
  11985. function checkValue(i) {
  11986. var start = i;
  11987. var l = void 0;
  11988. var s = void 0;
  11989. var _i = void 0;
  11990. while (i < tokensLength) {
  11991. if (checkDeclDelim(i)) break;
  11992. if (l = checkBlock(i)) {
  11993. i += l;
  11994. break;
  11995. }
  11996. s = checkS(i);
  11997. _i = i + s;
  11998. if (l = _checkValue(_i)) i += l + s;
  11999. if (!l || checkBlock(i - l)) break;
  12000. }
  12001. return i - start;
  12002. }
  12003. /**
  12004. * @return {Array}
  12005. */
  12006. function getValue() {
  12007. var type = NodeType.ValueType;
  12008. var token = tokens[pos];
  12009. var line = token.ln;
  12010. var column = token.col;
  12011. var content = [];
  12012. var _pos = void 0;
  12013. var s = void 0;
  12014. while (pos < tokensLength) {
  12015. if (checkDeclDelim(pos)) break;
  12016. s = checkS(pos);
  12017. _pos = pos + s;
  12018. if (checkDeclDelim(_pos)) break;
  12019. if (checkBlock(pos)) {
  12020. content.push(getBlock());
  12021. break;
  12022. }
  12023. if (!_checkValue(_pos)) break;
  12024. if (s) content.push(getS());
  12025. content.push(_getValue());
  12026. if (checkBlock(_pos)) break;
  12027. }
  12028. return newNode(type, content, line, column);
  12029. }
  12030. /**
  12031. * @param {number} i Token's index number
  12032. * @return {number}
  12033. */
  12034. function _checkValue(i) {
  12035. var l = void 0;
  12036. if (l = checkInterpolation(i)) tokens[i].value_child = 1;else if (l = checkVariable(i)) tokens[i].value_child = 2;else if (l = checkVhash(i)) tokens[i].value_child = 3;else if (l = checkBlock(i)) tokens[i].value_child = 4;else if (l = checkAtkeyword(i)) tokens[i].value_child = 5;else if (l = checkOperator(i)) tokens[i].value_child = 6;else if (l = checkImportant(i)) tokens[i].value_child = 7;else if (l = checkGlobal(i)) tokens[i].value_child = 8;else if (l = checkDefault(i)) tokens[i].value_child = 9;else if (l = checkProgid(i)) tokens[i].value_child = 10;else if (l = checkAny(i)) tokens[i].value_child = 11;else if (l = checkParentSelector(i)) tokens[i].value_child = 12;
  12037. return l;
  12038. }
  12039. /**
  12040. * @return {Array}
  12041. */
  12042. function _getValue() {
  12043. var childType = tokens[pos].value_child;
  12044. if (childType === 1) return getInterpolation();
  12045. if (childType === 2) return getVariable();
  12046. if (childType === 3) return getVhash();
  12047. if (childType === 4) return getBlock();
  12048. if (childType === 5) return getAtkeyword();
  12049. if (childType === 6) return getOperator();
  12050. if (childType === 7) return getImportant();
  12051. if (childType === 8) return getGlobal();
  12052. if (childType === 9) return getDefault();
  12053. if (childType === 10) return getProgid();
  12054. if (childType === 11) return getAny();
  12055. if (childType === 12) return getParentSelector();
  12056. }
  12057. /**
  12058. * @param {number} i Token's index number
  12059. * @returns {number} Length of the value
  12060. */
  12061. function checkSingleValue(i) {
  12062. var start = i;
  12063. var l = void 0;
  12064. var s = void 0;
  12065. var _i = void 0;
  12066. while (i < tokensLength) {
  12067. if (checkDeclDelim(i) || checkDelim(i)) break;
  12068. if (l = checkBlock(i)) {
  12069. i += l;
  12070. break;
  12071. }
  12072. s = checkSC(i);
  12073. _i = i + s;
  12074. if (l = _checkValue(_i)) i += l + s;
  12075. if (!l || checkBlock(i - l)) break;
  12076. }
  12077. return i - start;
  12078. }
  12079. /**
  12080. * @returns {Array}
  12081. */
  12082. function getSingleValue() {
  12083. var type = NodeType.ValueType;
  12084. var token = tokens[pos];
  12085. var line = token.ln;
  12086. var column = token.col;
  12087. var content = [];
  12088. var _pos = void 0;
  12089. var s = void 0;
  12090. while (pos < tokensLength) {
  12091. if (checkDeclDelim(pos) || checkDelim(pos)) break;
  12092. s = checkSC(pos);
  12093. _pos = pos + s;
  12094. if (checkDeclDelim(_pos) || checkDelim(_pos)) break;
  12095. if (checkBlock(pos)) {
  12096. content.push(getBlock());
  12097. break;
  12098. }
  12099. if (!_checkValue(_pos)) break;
  12100. if (s) content.push(getS());
  12101. content.push(_getValue());
  12102. if (checkBlock(_pos)) break;
  12103. }
  12104. return newNode(type, content, line, column);
  12105. }
  12106. /**
  12107. * Check if token is part of a variable
  12108. * @param {number} i Token's index number
  12109. * @return {number} Length of the variable
  12110. */
  12111. function checkVariable(i) {
  12112. var start = i;
  12113. var l = void 0;
  12114. if (i >= tokensLength) return 0;
  12115. // Skip `$`.
  12116. if (tokens[i].type === TokenType.DollarSign) i++;else return 0;
  12117. if (l = checkIdent(i)) i += l;else return 0;
  12118. return i - start;
  12119. }
  12120. /**
  12121. * Get node with a variable
  12122. * @return {Array} `['variable', ['ident', x]]` where `x` is
  12123. * a variable name.
  12124. */
  12125. function getVariable() {
  12126. var type = NodeType.VariableType;
  12127. var token = tokens[pos];
  12128. var line = token.ln;
  12129. var column = token.col;
  12130. // Skip `$`.
  12131. pos++;
  12132. var content = [getIdent()];
  12133. return newNode(type, content, line, column);
  12134. }
  12135. /**
  12136. * Check if token is part of a variables list (e.g. `$values...`).
  12137. * @param {number} i Token's index number
  12138. * @return {number}
  12139. */
  12140. function checkVariablesList(i) {
  12141. var d = 0; // Number of dots
  12142. var l = void 0;
  12143. if (i >= tokensLength) return 0;
  12144. if (l = checkVariable(i)) i += l;else return 0;
  12145. while (i < tokensLength && tokens[i].type === TokenType.FullStop) {
  12146. d++;
  12147. i++;
  12148. }
  12149. return d === 3 ? l + d : 0;
  12150. }
  12151. /**
  12152. * Get node with a variables list
  12153. * @return {Array} `['variableslist', ['variable', ['ident', x]]]` where
  12154. * `x` is a variable name.
  12155. */
  12156. function getVariablesList() {
  12157. var type = NodeType.VariablesListType;
  12158. var token = tokens[pos];
  12159. var line = token.ln;
  12160. var column = token.col;
  12161. var content = [getVariable()];
  12162. var end = getLastPosition(content, line, column, 3);
  12163. // Skip `...`.
  12164. pos += 3;
  12165. return newNode(type, content, line, column, end);
  12166. }
  12167. /**
  12168. * Check if token is part of a hexadecimal number (e.g. `#fff`) inside
  12169. * some value
  12170. * @param {number} i Token's index number
  12171. * @return {number}
  12172. */
  12173. function checkVhash(i) {
  12174. var start = i;
  12175. var l = void 0;
  12176. if (i >= tokensLength) return 0;
  12177. // Skip `#`.
  12178. if (tokens[i].type === TokenType.NumberSign) i++;else return 0;
  12179. if (l = checkNmName2(i)) i += l;else return 0;
  12180. return i - start;
  12181. }
  12182. /**
  12183. * Get node with a hexadecimal number (e.g. `#fff`) inside some value
  12184. * @return {Array} `['vhash', x]` where `x` is a hexadecimal number
  12185. * converted to string (without `#`, e.g. `'fff'`).
  12186. */
  12187. function getVhash() {
  12188. var type = NodeType.VhashType;
  12189. var token = tokens[pos];
  12190. var line = token.ln;
  12191. var column = token.col;
  12192. // Skip `#`.
  12193. pos++;
  12194. var content = getNmName2();
  12195. var end = getLastPosition(content, line, column + 1);
  12196. return newNode(type, content, line, column, end);
  12197. }
  12198. function checkSelectorsGroup(i) {
  12199. if (i >= tokensLength) return 0;
  12200. var start = i;
  12201. var l = void 0;
  12202. if (l = checkSelector(i)) i += l;else return 0;
  12203. while (i < tokensLength) {
  12204. var spaceBefore = checkSC(i);
  12205. var comma = checkDelim(i + spaceBefore);
  12206. if (!comma) break;
  12207. var spaceAfter = checkMultilineSC(i + spaceBefore + comma);
  12208. var spaceEnd = spaceAfter ? checkMultilineSC(i + spaceBefore + comma + spaceAfter) : 0;
  12209. if (l = checkSelector(i + spaceBefore + comma + spaceAfter + spaceEnd)) i += spaceBefore + comma + spaceAfter + spaceEnd + l;else break;
  12210. }
  12211. tokens[start].selectorsGroupEnd = i;
  12212. return i - start;
  12213. }
  12214. function getSelectorsGroup() {
  12215. var selectorsGroup = [];
  12216. var selectorsGroupEnd = tokens[pos].selectorsGroupEnd;
  12217. selectorsGroup.push(getSelector());
  12218. while (pos < selectorsGroupEnd) {
  12219. selectorsGroup = selectorsGroup.concat(getMultilineSC(), getDelim(), getMultilineSC(), getSelector());
  12220. }
  12221. return selectorsGroup;
  12222. }
  12223. function checkSelector(i) {
  12224. var l = void 0;
  12225. if (l = checkSelector1(i)) tokens[i].selectorType = 1;else if (l = checkSelector2(i)) tokens[i].selectorType = 2;
  12226. return l;
  12227. }
  12228. function getSelector() {
  12229. var selectorType = tokens[pos].selectorType;
  12230. if (selectorType === 1) return getSelector1();else return getSelector2();
  12231. }
  12232. /**
  12233. * Checks for selector which starts with a compound selector.
  12234. */
  12235. function checkSelector1(i) {
  12236. if (i >= tokensLength) return 0;
  12237. var start = i;
  12238. var l = void 0;
  12239. if (l = checkCompoundSelector(i)) i += l;else return 0;
  12240. while (i < tokensLength) {
  12241. var space = checkSC(i);
  12242. var comma = checkCombinator(i + space);
  12243. if (!space && !comma) break;
  12244. if (comma) {
  12245. i += space + comma;
  12246. space = checkSC(i);
  12247. }
  12248. if (l = checkCompoundSelector(i + space)) i += space + l;else break;
  12249. }
  12250. tokens[start].selectorEnd = i;
  12251. return i - start;
  12252. }
  12253. function getSelector1() {
  12254. var type = NodeType.SelectorType;
  12255. var token = tokens[pos];
  12256. var line = token.ln;
  12257. var column = token.col;
  12258. var selectorEnd = token.selectorEnd;
  12259. var content = getCompoundSelector();
  12260. while (pos < selectorEnd) {
  12261. if (checkSC(pos)) content = content.concat(getSC());else if (checkCombinator(pos)) content.push(getCombinator());else if (checkCompoundSelector(pos)) content = content.concat(getCompoundSelector());
  12262. }
  12263. return newNode(type, content, line, column);
  12264. }
  12265. /**
  12266. * Checks for a selector that starts with a combinator.
  12267. */
  12268. function checkSelector2(i) {
  12269. if (i >= tokensLength) return 0;
  12270. var start = i;
  12271. var l = void 0;
  12272. if (l = checkCombinator(i)) i += l;else return 0;
  12273. while (i < tokensLength) {
  12274. var spaceBefore = checkSC(i);
  12275. if (l = checkCompoundSelector(i + spaceBefore)) i += spaceBefore + l;else break;
  12276. var spaceAfter = checkSC(i);
  12277. var comma = checkCombinator(i + spaceAfter);
  12278. if (!spaceAfter && !comma) break;
  12279. if (comma) {
  12280. i += spaceAfter + comma;
  12281. }
  12282. }
  12283. tokens[start].selectorEnd = i;
  12284. return i - start;
  12285. }
  12286. function getSelector2() {
  12287. var type = NodeType.SelectorType;
  12288. var token = tokens[pos];
  12289. var line = token.ln;
  12290. var column = token.col;
  12291. var selectorEnd = token.selectorEnd;
  12292. var content = [getCombinator()];
  12293. while (pos < selectorEnd) {
  12294. if (checkSC(pos)) content = content.concat(getSC());else if (checkCombinator(pos)) content.push(getCombinator());else if (checkCompoundSelector(pos)) content = content.concat(getCompoundSelector());
  12295. }
  12296. return newNode(type, content, line, column);
  12297. }
  12298. function checkCompoundSelector(i) {
  12299. var l = void 0;
  12300. if (l = checkCompoundSelector1(i)) {
  12301. tokens[i].compoundSelectorType = 1;
  12302. } else if (l = checkCompoundSelector2(i)) {
  12303. tokens[i].compoundSelectorType = 2;
  12304. }
  12305. return l;
  12306. }
  12307. function getCompoundSelector() {
  12308. var type = tokens[pos].compoundSelectorType;
  12309. if (type === 1) return getCompoundSelector1();
  12310. if (type === 2) return getCompoundSelector2();
  12311. }
  12312. /**
  12313. * Check for compound selectors that start with either a type selector,
  12314. * placeholder or parent selector with extension
  12315. * (1) `foo.bar`
  12316. * (2) `foo[attr=val]`
  12317. * (3) `foo:first-of-type`
  12318. * (4) `foo%bar`
  12319. * @param {number} i Token's index
  12320. * @return {number} Compound selector's length
  12321. */
  12322. function checkCompoundSelector1(i) {
  12323. if (i >= tokensLength) return 0;
  12324. var start = i;
  12325. var l = void 0;
  12326. if (l = checkUniversalSelector(i) || checkTypeSelector(i) || checkPlaceholder(i) || checkParentSelectorWithExtension(i)) i += l;else return 0;
  12327. while (i < tokensLength) {
  12328. var _l2 = checkShash(i) || checkClass(i) || checkAttributeSelector(i) || checkPseudo(i) || checkPlaceholder(i) || checkInterpolation(i);
  12329. if (_l2) i += _l2;else break;
  12330. }
  12331. tokens[start].compoundSelectorEnd = i;
  12332. return i - start;
  12333. }
  12334. /**
  12335. * @return {Array} An array of nodes that make up the compound selector
  12336. */
  12337. function getCompoundSelector1() {
  12338. var sequence = [];
  12339. var compoundSelectorEnd = tokens[pos].compoundSelectorEnd;
  12340. if (checkUniversalSelector(pos)) sequence.push(getUniversalSelector());else if (checkTypeSelector(pos)) sequence.push(getTypeSelector());else if (checkPlaceholder(pos)) sequence.push(getPlaceholder());else if (checkParentSelectorWithExtension(pos)) sequence = sequence.concat(getParentSelectorWithExtension());
  12341. while (pos < compoundSelectorEnd) {
  12342. if (checkShash(pos)) sequence.push(getShash());else if (checkClass(pos)) sequence.push(getClass());else if (checkAttributeSelector(pos)) sequence.push(getAttributeSelector());else if (checkPseudo(pos)) sequence.push(getPseudo());else if (checkPlaceholder(pos)) sequence.push(getPlaceholder());else if (checkInterpolation(pos)) sequence.push(getInterpolation());else break;
  12343. }
  12344. return sequence;
  12345. }
  12346. /**
  12347. * Check for all other compound selectors
  12348. * (1) `.foo.bar`
  12349. * (2) `.foo[attr=val]`
  12350. * (3) `.foo:first-of-type`
  12351. * (4) `.foo%bar`
  12352. * (5) `.foo#{$bar}`
  12353. * @param {number} i Token's index
  12354. * @return {number} Compound selector's length
  12355. */
  12356. function checkCompoundSelector2(i) {
  12357. if (i >= tokensLength) return 0;
  12358. var start = i;
  12359. while (i < tokensLength) {
  12360. var l = checkShash(i) || checkClass(i) || checkAttributeSelector(i) || checkPseudo(i) || checkPlaceholder(i) || checkInterpolation(i);
  12361. if (l) i += l;else break;
  12362. }
  12363. tokens[start].compoundSelectorEnd = i;
  12364. return i - start;
  12365. }
  12366. /**
  12367. * @return {Array} An array of nodes that make up the compound selector
  12368. */
  12369. function getCompoundSelector2() {
  12370. var sequence = [];
  12371. var compoundSelectorEnd = tokens[pos].compoundSelectorEnd;
  12372. while (pos < compoundSelectorEnd) {
  12373. if (checkShash(pos)) sequence.push(getShash());else if (checkClass(pos)) sequence.push(getClass());else if (checkAttributeSelector(pos)) sequence.push(getAttributeSelector());else if (checkPseudo(pos)) sequence.push(getPseudo());else if (checkPlaceholder(pos)) sequence.push(getPlaceholder());else if (checkInterpolation(pos)) sequence.push(getInterpolation());else break;
  12374. }
  12375. return sequence;
  12376. }
  12377. function checkUniversalSelector(i) {
  12378. if (i >= tokensLength) return 0;
  12379. var start = i;
  12380. var l = void 0;
  12381. if (l = checkNamePrefix(i)) i += l;
  12382. if (tokens[i].type === TokenType.Asterisk) i++;else return 0;
  12383. return i - start;
  12384. }
  12385. function getUniversalSelector() {
  12386. var type = NodeType.UniversalSelectorType;
  12387. var token = tokens[pos];
  12388. var line = token.ln;
  12389. var column = token.col;
  12390. var content = [];
  12391. var end = void 0;
  12392. if (checkNamePrefix(pos)) {
  12393. content.push(getNamePrefix());
  12394. end = getLastPosition(content, line, column, 1);
  12395. }
  12396. pos++;
  12397. return newNode(type, content, line, column, end);
  12398. }
  12399. /**
  12400. * Check if token is part of a type selector
  12401. * @param {number} i Token's index
  12402. * @return {number} Type selector's length
  12403. */
  12404. function checkTypeSelector(i) {
  12405. if (i >= tokensLength) return 0;
  12406. var start = i;
  12407. var l = void 0;
  12408. if (l = checkNamePrefix(i)) i += l;
  12409. if (l = checkIdentOrInterpolation(i)) i += l;else return 0;
  12410. return i - start;
  12411. }
  12412. /**
  12413. * Get type selector node
  12414. * @return {Node}
  12415. */
  12416. function getTypeSelector() {
  12417. var type = NodeType.TypeSelectorType;
  12418. var token = tokens[pos];
  12419. var line = token.ln;
  12420. var column = token.col;
  12421. var content = [];
  12422. if (checkNamePrefix(pos)) content.push(getNamePrefix());
  12423. content = content.concat(getIdentOrInterpolation());
  12424. return newNode(type, content, line, column);
  12425. }
  12426. function checkAttributeSelector(i) {
  12427. var l = void 0;
  12428. if (l = checkAttributeSelector1(i)) tokens[i].attributeSelectorType = 1;else if (l = checkAttributeSelector2(i)) tokens[i].attributeSelectorType = 2;
  12429. return l;
  12430. }
  12431. function getAttributeSelector() {
  12432. var type = tokens[pos].attributeSelectorType;
  12433. if (type === 1) return getAttributeSelector1();else return getAttributeSelector2();
  12434. }
  12435. /**
  12436. * (1) `[panda=nani]`
  12437. * (2) `[panda='nani']`
  12438. * (3) `[panda='nani' i]`
  12439. *
  12440. */
  12441. function checkAttributeSelector1(i) {
  12442. var start = i;
  12443. if (tokens[i].type === TokenType.LeftSquareBracket) i++;else return 0;
  12444. var l = void 0;
  12445. if (l = checkSC(i)) i += l;
  12446. if (l = checkAttributeName(i)) i += l;else return 0;
  12447. if (l = checkSC(i)) i += l;
  12448. if (l = checkAttributeMatch(i)) i += l;else return 0;
  12449. if (l = checkSC(i)) i += l;
  12450. if (l = checkAttributeValue(i)) i += l;else return 0;
  12451. if (l = checkSC(i)) i += l;
  12452. if (l = checkAttributeFlags(i)) {
  12453. i += l;
  12454. if (l = checkSC(i)) i += l;
  12455. }
  12456. if (tokens[i].type === TokenType.RightSquareBracket) i++;else return 0;
  12457. return i - start;
  12458. }
  12459. function getAttributeSelector1() {
  12460. var type = NodeType.AttributeSelectorType;
  12461. var token = tokens[pos];
  12462. var line = token.ln;
  12463. var column = token.col;
  12464. var content = [];
  12465. // Skip `[`.
  12466. pos++;
  12467. content = content.concat(getSC(), getAttributeName(), getSC(), getAttributeMatch(), getSC(), getAttributeValue(), getSC());
  12468. if (checkAttributeFlags(pos)) {
  12469. content.push(getAttributeFlags());
  12470. content = content.concat(getSC());
  12471. }
  12472. // Skip `]`.
  12473. pos++;
  12474. var end = getLastPosition(content, line, column, 1);
  12475. return newNode(type, content, line, column, end);
  12476. }
  12477. /**
  12478. * (1) `[panda]`
  12479. */
  12480. function checkAttributeSelector2(i) {
  12481. var start = i;
  12482. if (tokens[i].type === TokenType.LeftSquareBracket) i++;else return 0;
  12483. var l = void 0;
  12484. if (l = checkSC(i)) i += l;
  12485. if (l = checkAttributeName(i)) i += l;else return 0;
  12486. if (l = checkSC(i)) i += l;
  12487. if (tokens[i].type === TokenType.RightSquareBracket) i++;else return 0;
  12488. return i - start;
  12489. }
  12490. function getAttributeSelector2() {
  12491. var type = NodeType.AttributeSelectorType;
  12492. var token = tokens[pos];
  12493. var line = token.ln;
  12494. var column = token.col;
  12495. var content = [];
  12496. // Skip `[`.
  12497. pos++;
  12498. content = content.concat(getSC(), getAttributeName(), getSC());
  12499. // Skip `]`.
  12500. pos++;
  12501. var end = getLastPosition(content, line, column, 1);
  12502. return newNode(type, content, line, column, end);
  12503. }
  12504. function checkAttributeName(i) {
  12505. var start = i;
  12506. var l = void 0;
  12507. if (l = checkNamePrefix(i)) i += l;
  12508. if (l = checkIdentOrInterpolation(i)) i += l;else return 0;
  12509. return i - start;
  12510. }
  12511. function getAttributeName() {
  12512. var type = NodeType.AttributeNameType;
  12513. var token = tokens[pos];
  12514. var line = token.ln;
  12515. var column = token.col;
  12516. var content = [];
  12517. if (checkNamePrefix(pos)) content.push(getNamePrefix());
  12518. content = content.concat(getIdentOrInterpolation());
  12519. return newNode(type, content, line, column);
  12520. }
  12521. function checkAttributeMatch(i) {
  12522. var l = void 0;
  12523. if (l = checkAttributeMatch1(i)) tokens[i].attributeMatchType = 1;else if (l = checkAttributeMatch2(i)) tokens[i].attributeMatchType = 2;
  12524. return l;
  12525. }
  12526. function getAttributeMatch() {
  12527. var type = tokens[pos].attributeMatchType;
  12528. if (type === 1) return getAttributeMatch1();else return getAttributeMatch2();
  12529. }
  12530. function checkAttributeMatch1(i) {
  12531. var start = i;
  12532. var type = tokens[i].type;
  12533. if (type === TokenType.Tilde || type === TokenType.VerticalLine || type === TokenType.CircumflexAccent || type === TokenType.DollarSign || type === TokenType.Asterisk) i++;else return 0;
  12534. if (tokens[i].type === TokenType.EqualsSign) i++;else return 0;
  12535. return i - start;
  12536. }
  12537. function getAttributeMatch1() {
  12538. var type = NodeType.AttributeMatchType;
  12539. var token = tokens[pos];
  12540. var line = token.ln;
  12541. var column = token.col;
  12542. var content = tokens[pos].value + tokens[pos + 1].value;
  12543. pos += 2;
  12544. return newNode(type, content, line, column);
  12545. }
  12546. function checkAttributeMatch2(i) {
  12547. if (tokens[i].type === TokenType.EqualsSign) return 1;else return 0;
  12548. }
  12549. function getAttributeMatch2() {
  12550. var type = NodeType.AttributeMatchType;
  12551. var token = tokens[pos];
  12552. var line = token.ln;
  12553. var column = token.col;
  12554. var content = '=';
  12555. pos++;
  12556. return newNode(type, content, line, column);
  12557. }
  12558. function checkAttributeValue(i) {
  12559. return checkString(i) || checkIdentOrInterpolation(i);
  12560. }
  12561. function getAttributeValue() {
  12562. var type = NodeType.AttributeValueType;
  12563. var token = tokens[pos];
  12564. var line = token.ln;
  12565. var column = token.col;
  12566. var content = [];
  12567. if (checkString(pos)) content.push(getString());else content = content.concat(getIdentOrInterpolation());
  12568. return newNode(type, content, line, column);
  12569. }
  12570. function checkAttributeFlags(i) {
  12571. return checkIdentOrInterpolation(i);
  12572. }
  12573. function getAttributeFlags() {
  12574. var type = NodeType.AttributeFlagsType;
  12575. var token = tokens[pos];
  12576. var line = token.ln;
  12577. var column = token.col;
  12578. var content = getIdentOrInterpolation();
  12579. return newNode(type, content, line, column);
  12580. }
  12581. function checkNamePrefix(i) {
  12582. if (i >= tokensLength) return 0;
  12583. var l = void 0;
  12584. if (l = checkNamePrefix1(i)) tokens[i].namePrefixType = 1;else if (l = checkNamePrefix2(i)) tokens[i].namePrefixType = 2;
  12585. return l;
  12586. }
  12587. function getNamePrefix() {
  12588. var type = tokens[pos].namePrefixType;
  12589. if (type === 1) return getNamePrefix1();else return getNamePrefix2();
  12590. }
  12591. /**
  12592. * (1) `panda|`
  12593. * (2) `panda<comment>|`
  12594. */
  12595. function checkNamePrefix1(i) {
  12596. var start = i;
  12597. var l = void 0;
  12598. if (l = checkNamespacePrefix(i)) i += l;else return 0;
  12599. if (l = checkCommentML(i)) i += l;
  12600. if (l = checkNamespaceSeparator(i)) i += l;else return 0;
  12601. return i - start;
  12602. }
  12603. function getNamePrefix1() {
  12604. var type = NodeType.NamePrefixType;
  12605. var token = tokens[pos];
  12606. var line = token.ln;
  12607. var column = token.col;
  12608. var content = [];
  12609. content.push(getNamespacePrefix());
  12610. if (checkCommentML(pos)) content.push(getCommentML());
  12611. content.push(getNamespaceSeparator());
  12612. return newNode(type, content, line, column);
  12613. }
  12614. /**
  12615. * (1) `|`
  12616. */
  12617. function checkNamePrefix2(i) {
  12618. return checkNamespaceSeparator(i);
  12619. }
  12620. function getNamePrefix2() {
  12621. var type = NodeType.NamePrefixType;
  12622. var token = tokens[pos];
  12623. var line = token.ln;
  12624. var column = token.col;
  12625. var content = [getNamespaceSeparator()];
  12626. return newNode(type, content, line, column);
  12627. }
  12628. /**
  12629. * (1) `*`
  12630. * (2) `panda`
  12631. */
  12632. function checkNamespacePrefix(i) {
  12633. if (i >= tokensLength) return 0;
  12634. var l = void 0;
  12635. if (tokens[i].type === TokenType.Asterisk) return 1;else if (l = checkIdentOrInterpolation(i)) return l;else return 0;
  12636. }
  12637. function getNamespacePrefix() {
  12638. var type = NodeType.NamespacePrefixType;
  12639. var token = tokens[pos];
  12640. var line = token.ln;
  12641. var column = token.col;
  12642. var content = [];
  12643. if (token.type === TokenType.Asterisk) {
  12644. var asteriskNode = newNode(NodeType.IdentType, '*', line, column);
  12645. content.push(asteriskNode);
  12646. pos++;
  12647. } else if (checkIdentOrInterpolation(pos)) content = content.concat(getIdentOrInterpolation());
  12648. return newNode(type, content, line, column);
  12649. }
  12650. /**
  12651. * (1) `|`
  12652. */
  12653. function checkNamespaceSeparator(i) {
  12654. if (i >= tokensLength) return 0;
  12655. if (tokens[i].type !== TokenType.VerticalLine) return 0;
  12656. // Return false if `|=` - [attr|=value]
  12657. if (tokens[i + 1] && tokens[i + 1].type === TokenType.EqualsSign) return 0;
  12658. return 1;
  12659. }
  12660. function getNamespaceSeparator() {
  12661. var type = NodeType.NamespaceSeparatorType;
  12662. var token = tokens[pos];
  12663. var line = token.ln;
  12664. var column = token.col;
  12665. var content = '|';
  12666. pos++;
  12667. return newNode(type, content, line, column);
  12668. }
  12669. module.exports = function (_tokens, context) {
  12670. tokens = _tokens;
  12671. tokensLength = tokens.length;
  12672. pos = 0;
  12673. return contexts[context]();
  12674. };
  12675. /***/ }),
  12676. /* 24 */
  12677. /***/ (function(module, exports, __webpack_require__) {
  12678. 'use strict';
  12679. module.exports = function (css, tabSize) {
  12680. var TokenType = __webpack_require__(13);
  12681. var tokens = [];
  12682. var urlMode = false;
  12683. var c = void 0; // Current character
  12684. var cn = void 0; // Next character
  12685. var pos = 0;
  12686. var tn = 0;
  12687. var ln = 1;
  12688. var col = 1;
  12689. var Punctuation = {
  12690. ' ': TokenType.Space,
  12691. '\n': TokenType.Newline,
  12692. '\r': TokenType.Newline,
  12693. '\t': TokenType.Tab,
  12694. '!': TokenType.ExclamationMark,
  12695. '"': TokenType.QuotationMark,
  12696. '#': TokenType.NumberSign,
  12697. '$': TokenType.DollarSign,
  12698. '%': TokenType.PercentSign,
  12699. '&': TokenType.Ampersand,
  12700. '\'': TokenType.Apostrophe,
  12701. '(': TokenType.LeftParenthesis,
  12702. ')': TokenType.RightParenthesis,
  12703. '*': TokenType.Asterisk,
  12704. '+': TokenType.PlusSign,
  12705. ',': TokenType.Comma,
  12706. '-': TokenType.HyphenMinus,
  12707. '.': TokenType.FullStop,
  12708. '/': TokenType.Solidus,
  12709. ':': TokenType.Colon,
  12710. ';': TokenType.Semicolon,
  12711. '<': TokenType.LessThanSign,
  12712. '=': TokenType.EqualsSign,
  12713. '==': TokenType.EqualitySign,
  12714. '!=': TokenType.InequalitySign,
  12715. '>': TokenType.GreaterThanSign,
  12716. '?': TokenType.QuestionMark,
  12717. '@': TokenType.CommercialAt,
  12718. '[': TokenType.LeftSquareBracket,
  12719. ']': TokenType.RightSquareBracket,
  12720. '^': TokenType.CircumflexAccent,
  12721. '_': TokenType.LowLine,
  12722. '{': TokenType.LeftCurlyBracket,
  12723. '|': TokenType.VerticalLine,
  12724. '}': TokenType.RightCurlyBracket,
  12725. '~': TokenType.Tilde,
  12726. '`': TokenType.Backtick
  12727. };
  12728. /**
  12729. * Add a token to the token list
  12730. * @param {string} type
  12731. * @param {string} value
  12732. */
  12733. function pushToken(type, value, column) {
  12734. tokens.push({
  12735. tn: tn++,
  12736. ln: ln,
  12737. col: column,
  12738. type: type,
  12739. value: value
  12740. });
  12741. }
  12742. /**
  12743. * Check if a character is a decimal digit
  12744. * @param {string} c Character
  12745. * @returns {boolean}
  12746. */
  12747. function isDecimalDigit(c) {
  12748. return '0123456789'.indexOf(c) >= 0;
  12749. }
  12750. /**
  12751. * Parse spaces
  12752. * @param {string} css Unparsed part of CSS string
  12753. */
  12754. function parseSpaces(css) {
  12755. var start = pos;
  12756. // Read the string until we meet a non-space character:
  12757. for (; pos < css.length; pos++) {
  12758. if (css.charAt(pos) !== ' ') break;
  12759. }
  12760. // Add a substring containing only spaces to tokens:
  12761. pushToken(TokenType.Space, css.substring(start, pos--), col);
  12762. col += pos - start;
  12763. }
  12764. /**
  12765. * Parse a string within quotes
  12766. * @param {string} css Unparsed part of CSS string
  12767. * @param {string} q Quote (either `'` or `"`)
  12768. */
  12769. function parseString(css, q) {
  12770. var start = pos;
  12771. // Read the string until we meet a matching quote:
  12772. for (pos++; pos < css.length; pos++) {
  12773. // Skip escaped quotes:
  12774. if (css.charAt(pos) === '\\') pos++;else if (css.charAt(pos) === q) break;
  12775. }
  12776. // Add the string (including quotes) to tokens:
  12777. var type = q === '"' ? TokenType.StringDQ : TokenType.StringSQ;
  12778. pushToken(type, css.substring(start, pos + 1), col);
  12779. col += pos - start;
  12780. }
  12781. /**
  12782. * Parse numbers
  12783. * @param {string} css Unparsed part of CSS string
  12784. */
  12785. function parseDecimalNumber(css) {
  12786. var start = pos;
  12787. // Read the string until we meet a character that's not a digit:
  12788. for (; pos < css.length; pos++) {
  12789. if (!isDecimalDigit(css.charAt(pos))) break;
  12790. }
  12791. // Add the number to tokens:
  12792. pushToken(TokenType.DecimalNumber, css.substring(start, pos--), col);
  12793. col += pos - start;
  12794. }
  12795. /**
  12796. * Parse identifier
  12797. * @param {string} css Unparsed part of CSS string
  12798. */
  12799. function parseIdentifier(css) {
  12800. var start = pos;
  12801. // Skip all opening slashes:
  12802. while (css.charAt(pos) === '/') {
  12803. pos++;
  12804. } // Read the string until we meet a punctuation mark:
  12805. for (; pos < css.length; pos++) {
  12806. // Skip all '\':
  12807. if (css.charAt(pos) === '\\') pos++;else if (css.charAt(pos) in Punctuation) break;
  12808. }
  12809. var ident = css.substring(start, pos--);
  12810. // Enter url mode if parsed substring is `url`:
  12811. if (!urlMode && ident === 'url' && css.charAt(pos + 1) === '(') {
  12812. urlMode = true;
  12813. }
  12814. // Add identifier to tokens:
  12815. pushToken(TokenType.Identifier, ident, col);
  12816. col += pos - start;
  12817. }
  12818. /**
  12819. * Parse equality sign
  12820. */
  12821. function parseEquality() {
  12822. pushToken(TokenType.EqualitySign, '==', col);
  12823. pos++;
  12824. col++;
  12825. }
  12826. /**
  12827. * Parse inequality sign
  12828. */
  12829. function parseInequality() {
  12830. pushToken(TokenType.InequalitySign, '!=', col);
  12831. pos++;
  12832. col++;
  12833. }
  12834. /**
  12835. * Parse a multiline comment
  12836. * @param {string} css Unparsed part of CSS string
  12837. */
  12838. function parseMLComment(css) {
  12839. var start = pos;
  12840. var col_ = col;
  12841. // Get current indent level:
  12842. var il = 0;
  12843. for (var _pos = pos - 1; _pos > -1; _pos--) {
  12844. // TODO: Can be tabs:
  12845. if (css.charAt(_pos) === ' ') il++;else break;
  12846. }
  12847. for (pos += 2; pos < css.length; pos++) {
  12848. var ch = css.charAt(pos);
  12849. if (ch === '\n') {
  12850. var _pos2 = void 0;
  12851. // Get new line's indent level:
  12852. var _il = 0;
  12853. for (_pos2 = pos + 1; _pos2 < css.length; _pos2++) {
  12854. if (css.charAt(_pos2) === ' ') _il++;else break;
  12855. }
  12856. if (_il > il) {
  12857. col = 0;
  12858. pos += _pos2 - pos;
  12859. } else {
  12860. pos--;
  12861. break;
  12862. }
  12863. } else if (ch === '*' && css.charAt(pos + 1) === '/') {
  12864. pos++;
  12865. break;
  12866. }
  12867. }
  12868. // If CRLF is used, we need to adjust pos
  12869. if (css.charAt(pos) === '\r') pos--;
  12870. // Add full comment (including `/*`) to the list of tokens:
  12871. var comment = css.substring(start, pos + 1);
  12872. pushToken(TokenType.CommentML, comment, col_);
  12873. var newlines = comment.split('\n');
  12874. if (newlines.length > 1) {
  12875. ln += newlines.length - 1;
  12876. col = newlines[newlines.length - 1].length;
  12877. } else {
  12878. col += pos - start;
  12879. }
  12880. }
  12881. /**
  12882. * Parse a single line comment
  12883. * @param {string} css Unparsed part of CSS string
  12884. */
  12885. function parseSLComment(css) {
  12886. var start = pos;
  12887. var col_ = col;
  12888. var _pos;
  12889. // Check if comment is the only token on the line, and if so,
  12890. // get current indent level:
  12891. var il = 0;
  12892. var onlyToken = false;
  12893. for (_pos = pos - 1; _pos > -1; _pos--) {
  12894. // TODO: Can be tabs:
  12895. if (css.charAt(_pos) === ' ') il++;else if (css.charAt(_pos) === '\n') {
  12896. onlyToken = true;
  12897. break;
  12898. } else break;
  12899. }
  12900. if (_pos === -1) onlyToken = true;
  12901. // Read the string until we meet comment end.
  12902. // Since we already know first 2 characters (`//`), start reading
  12903. // from `pos + 2`:
  12904. if (!onlyToken) {
  12905. for (pos += 2; pos < css.length; pos++) {
  12906. if (css.charAt(pos) === '\n' || css.charAt(pos) === '\r') {
  12907. break;
  12908. }
  12909. }
  12910. } else {
  12911. for (pos += 2; pos < css.length; pos++) {
  12912. var ch = css.charAt(pos);
  12913. if (ch === '\n') {
  12914. // Get new line's indent level:
  12915. var _il = 0;
  12916. for (_pos = pos + 1; _pos < css.length; _pos++) {
  12917. if (css.charAt(_pos) === ' ') _il++;else break;
  12918. }
  12919. if (_il > il) {
  12920. col = 0;
  12921. pos += _pos - pos;
  12922. } else {
  12923. break;
  12924. }
  12925. }
  12926. }
  12927. }
  12928. // If CRLF is used, we need to adjust pos
  12929. if (css.charAt(pos - 1) === '\r') pos--;
  12930. // Add comment (including `//` and line break) to the list of tokens:
  12931. var comment = css.substring(start, pos--);
  12932. pushToken(TokenType.CommentSL, comment, col_);
  12933. var newlines = comment.split('\n');
  12934. if (newlines.length > 1) {
  12935. ln += newlines.length - 1;
  12936. col = newlines[newlines.length - 1].length;
  12937. } else {
  12938. col += pos - start;
  12939. }
  12940. }
  12941. /**
  12942. * Convert a CSS string to a list of tokens
  12943. * @param {string} css CSS string
  12944. * @returns {Array} List of tokens
  12945. * @private
  12946. */
  12947. function getTokens(css) {
  12948. // Parse string, character by character:
  12949. for (pos = 0; pos < css.length; col++, pos++) {
  12950. c = css.charAt(pos);
  12951. cn = css.charAt(pos + 1);
  12952. // If we meet `/*`, it's a start of a multiline comment.
  12953. // Parse following characters as a multiline comment:
  12954. if (c === '/' && cn === '*') {
  12955. parseMLComment(css);
  12956. }
  12957. // If we meet `//` and it is not a part of url:
  12958. else if (!urlMode && c === '/' && cn === '/') {
  12959. // If we're currently inside a block, treat `//` as a start
  12960. // of identifier. Else treat `//` as a start of a single-line
  12961. // comment:
  12962. parseSLComment(css);
  12963. }
  12964. // If current character is a double or single quote, it's a start
  12965. // of a string:
  12966. else if (c === '"' || c === "'") {
  12967. parseString(css, c);
  12968. }
  12969. // If current character is a space:
  12970. else if (c === ' ') {
  12971. parseSpaces(css);
  12972. }
  12973. // If current character is `=`, it must be combined with next `=`
  12974. else if (c === '=' && cn === '=') {
  12975. parseEquality(css);
  12976. }
  12977. // If we meet `!=`, this must be inequality
  12978. else if (c === '!' && cn === '=') {
  12979. parseInequality(css);
  12980. }
  12981. // If current character is a punctuation mark:
  12982. else if (c in Punctuation) {
  12983. // Check for CRLF here or just LF
  12984. if (c === '\r' && cn === '\n' || c === '\n') {
  12985. // If \r we know the next character is \n due to statement above
  12986. // so we push a CRLF token type to the token list and importantly
  12987. // skip the next character so as not to double count newlines or
  12988. // columns etc
  12989. if (c === '\r') {
  12990. pushToken(TokenType.Newline, '\r\n', col);
  12991. pos++; // If CRLF skip the next character and push crlf token
  12992. } else if (c === '\n') {
  12993. // If just a LF newline and not part of CRLF newline we can just
  12994. // push punctuation as usual
  12995. pushToken(Punctuation[c], c, col);
  12996. }
  12997. ln++; // Go to next line
  12998. col = 0; // Reset the column count
  12999. } else if (c !== '\r' && c !== '\n') {
  13000. // Handle all other punctuation and add to list of tokens
  13001. pushToken(Punctuation[c], c, col);
  13002. } // Go to next line
  13003. if (c === ')') urlMode = false; // Exit url mode
  13004. else if (c === '\t' && tabSize > 1) col += tabSize - 1;
  13005. }
  13006. // If current character is a decimal digit:
  13007. else if (isDecimalDigit(c)) {
  13008. parseDecimalNumber(css);
  13009. }
  13010. // If current character is anything else:
  13011. else {
  13012. parseIdentifier(css);
  13013. }
  13014. }
  13015. return tokens;
  13016. }
  13017. return getTokens(css);
  13018. };
  13019. /***/ }),
  13020. /* 25 */
  13021. /***/ (function(module, exports, __webpack_require__) {
  13022. 'use strict';
  13023. exports.__esModule = true;
  13024. exports.default = {
  13025. mark: __webpack_require__(26),
  13026. parse: __webpack_require__(27),
  13027. stringify: __webpack_require__(6),
  13028. tokenizer: __webpack_require__(28)
  13029. };
  13030. module.exports = exports['default'];
  13031. /***/ }),
  13032. /* 26 */
  13033. /***/ (function(module, exports, __webpack_require__) {
  13034. 'use strict';
  13035. var TokenType = __webpack_require__(13);
  13036. module.exports = function () {
  13037. /**
  13038. * Mark whitespaces and comments
  13039. */
  13040. function markSC(tokens) {
  13041. var tokensLength = tokens.length;
  13042. var ws = -1; // Flag for whitespaces
  13043. var sc = -1; // Flag for whitespaces and comments
  13044. var t = void 0; // Current token
  13045. // For every token in the token list, mark spaces and line breaks
  13046. // as spaces (set both `ws` and `sc` flags). Mark multiline comments
  13047. // with `sc` flag.
  13048. // If there are several spaces or tabs or line breaks or multiline
  13049. // comments in a row, group them: take the last one's index number
  13050. // and save it to the first token in the group as a reference:
  13051. // e.g., `ws_last = 7` for a group of whitespaces or `sc_last = 9`
  13052. // for a group of whitespaces and comments.
  13053. for (var i = 0; i < tokensLength; i++) {
  13054. t = tokens[i];
  13055. switch (t.type) {
  13056. case TokenType.Space:
  13057. case TokenType.Tab:
  13058. case TokenType.Newline:
  13059. t.ws = true;
  13060. t.sc = true;
  13061. if (ws === -1) ws = i;
  13062. if (sc === -1) sc = i;
  13063. break;
  13064. case TokenType.CommentML:
  13065. case TokenType.CommentSL:
  13066. if (ws !== -1) {
  13067. tokens[ws].ws_last = i - 1;
  13068. ws = -1;
  13069. }
  13070. t.sc = true;
  13071. break;
  13072. default:
  13073. if (ws !== -1) {
  13074. tokens[ws].ws_last = i - 1;
  13075. ws = -1;
  13076. }
  13077. if (sc !== -1) {
  13078. tokens[sc].sc_last = i - 1;
  13079. sc = -1;
  13080. }
  13081. }
  13082. }
  13083. if (ws !== -1) tokens[ws].ws_last = i - 1;
  13084. if (sc !== -1) tokens[sc].sc_last = i - 1;
  13085. }
  13086. /**
  13087. * Pair brackets
  13088. */
  13089. function markBrackets(tokens) {
  13090. var tokensLength = tokens.length;
  13091. var ps = []; // Parentheses
  13092. var sbs = []; // Square brackets
  13093. var cbs = []; // Curly brackets
  13094. var t = void 0; // Current token
  13095. // For every token in the token list, if we meet an opening (left)
  13096. // bracket, push its index number to a corresponding array.
  13097. // If we then meet a closing (right) bracket, look at the corresponding
  13098. // array. If there are any elements (records about previously met
  13099. // left brackets), take a token of the last left bracket (take
  13100. // the last index number from the array and find a token with
  13101. // this index number) and save right bracket's index as a reference:
  13102. for (var i = 0; i < tokensLength; i++) {
  13103. t = tokens[i];
  13104. switch (t.type) {
  13105. case TokenType.LeftParenthesis:
  13106. ps.push(i);
  13107. break;
  13108. case TokenType.RightParenthesis:
  13109. if (ps.length) {
  13110. t.left = ps.pop();
  13111. tokens[t.left].right = i;
  13112. }
  13113. break;
  13114. case TokenType.LeftSquareBracket:
  13115. sbs.push(i);
  13116. break;
  13117. case TokenType.RightSquareBracket:
  13118. if (sbs.length) {
  13119. t.left = sbs.pop();
  13120. tokens[t.left].right = i;
  13121. }
  13122. break;
  13123. case TokenType.LeftCurlyBracket:
  13124. cbs.push(i);
  13125. break;
  13126. case TokenType.RightCurlyBracket:
  13127. if (cbs.length) {
  13128. t.left = cbs.pop();
  13129. tokens[t.left].right = i;
  13130. }
  13131. break;
  13132. }
  13133. }
  13134. }
  13135. return function (tokens) {
  13136. markBrackets(tokens);
  13137. markSC(tokens);
  13138. };
  13139. }();
  13140. /***/ }),
  13141. /* 27 */
  13142. /***/ (function(module, exports, __webpack_require__) {
  13143. 'use strict';
  13144. var Node = __webpack_require__(1);
  13145. var NodeType = __webpack_require__(15);
  13146. var TokenType = __webpack_require__(13);
  13147. var tokens = void 0;
  13148. var tokensLength = void 0;
  13149. var pos = void 0;
  13150. var contexts = {
  13151. 'arguments': function _arguments() {
  13152. return checkArguments(pos) && getArguments();
  13153. },
  13154. 'atkeyword': function atkeyword() {
  13155. return checkAtkeyword(pos) && getAtkeyword();
  13156. },
  13157. 'atrule': function atrule() {
  13158. return checkAtrule(pos) && getAtrule();
  13159. },
  13160. 'attributeSelector': function attributeSelector() {
  13161. return checkAttributeSelector(pos) && getAttributeSelector();
  13162. },
  13163. 'block': function block() {
  13164. return checkBlock(pos) && getBlock();
  13165. },
  13166. 'brackets': function brackets() {
  13167. return checkBrackets(pos) && getBrackets();
  13168. },
  13169. 'class': function _class() {
  13170. return checkClass(pos) && getClass();
  13171. },
  13172. 'combinator': function combinator() {
  13173. return checkCombinator(pos) && getCombinator();
  13174. },
  13175. 'commentML': function commentML() {
  13176. return checkCommentML(pos) && getCommentML();
  13177. },
  13178. 'commentSL': function commentSL() {
  13179. return checkCommentSL(pos) && getCommentSL();
  13180. },
  13181. 'condition': function condition() {
  13182. return checkCondition(pos) && getCondition();
  13183. },
  13184. 'conditionalStatement': function conditionalStatement() {
  13185. return checkConditionalStatement(pos) && getConditionalStatement();
  13186. },
  13187. 'declaration': function declaration() {
  13188. return checkDeclaration(pos) && getDeclaration();
  13189. },
  13190. 'declDelim': function declDelim() {
  13191. return checkDeclDelim(pos) && getDeclDelim();
  13192. },
  13193. 'default': function _default() {
  13194. return checkDefault(pos) && getDefault();
  13195. },
  13196. 'delim': function delim() {
  13197. return checkDelim(pos) && getDelim();
  13198. },
  13199. 'dimension': function dimension() {
  13200. return checkDimension(pos) && getDimension();
  13201. },
  13202. 'expression': function expression() {
  13203. return checkExpression(pos) && getExpression();
  13204. },
  13205. 'extend': function extend() {
  13206. return checkExtend(pos) && getExtend();
  13207. },
  13208. 'function': function _function() {
  13209. return checkFunction(pos) && getFunction();
  13210. },
  13211. 'global': function global() {
  13212. return checkGlobal(pos) && getGlobal();
  13213. },
  13214. 'ident': function ident() {
  13215. return checkIdent(pos) && getIdent();
  13216. },
  13217. 'important': function important() {
  13218. return checkImportant(pos) && getImportant();
  13219. },
  13220. 'include': function include() {
  13221. return checkInclude(pos) && getInclude();
  13222. },
  13223. 'interpolation': function interpolation() {
  13224. return checkInterpolation(pos) && getInterpolation();
  13225. },
  13226. 'loop': function loop() {
  13227. return checkLoop(pos) && getLoop();
  13228. },
  13229. 'mixin': function mixin() {
  13230. return checkMixin(pos) && getMixin();
  13231. },
  13232. 'namespace': function namespace() {
  13233. return checkNamespace(pos) && getNamespace();
  13234. },
  13235. 'number': function number() {
  13236. return checkNumber(pos) && getNumber();
  13237. },
  13238. 'operator': function operator() {
  13239. return checkOperator(pos) && getOperator();
  13240. },
  13241. 'optional': function optional() {
  13242. return checkOptional(pos) && getOptional();
  13243. },
  13244. 'parentheses': function parentheses() {
  13245. return checkParentheses(pos) && getParentheses();
  13246. },
  13247. 'parentselector': function parentselector() {
  13248. return checkParentSelector(pos) && getParentSelector();
  13249. },
  13250. 'percentage': function percentage() {
  13251. return checkPercentage(pos) && getPercentage();
  13252. },
  13253. 'placeholder': function placeholder() {
  13254. return checkPlaceholder(pos) && getPlaceholder();
  13255. },
  13256. 'progid': function progid() {
  13257. return checkProgid(pos) && getProgid();
  13258. },
  13259. 'property': function property() {
  13260. return checkProperty(pos) && getProperty();
  13261. },
  13262. 'propertyDelim': function propertyDelim() {
  13263. return checkPropertyDelim(pos) && getPropertyDelim();
  13264. },
  13265. 'pseudoc': function pseudoc() {
  13266. return checkPseudoc(pos) && getPseudoc();
  13267. },
  13268. 'pseudoe': function pseudoe() {
  13269. return checkPseudoe(pos) && getPseudoe();
  13270. },
  13271. 'ruleset': function ruleset() {
  13272. return checkRuleset(pos) && getRuleset();
  13273. },
  13274. 's': function s() {
  13275. return checkS(pos) && getS();
  13276. },
  13277. 'selector': function selector() {
  13278. return checkSelector(pos) && getSelector();
  13279. },
  13280. 'shash': function shash() {
  13281. return checkShash(pos) && getShash();
  13282. },
  13283. 'string': function string() {
  13284. return checkString(pos) && getString();
  13285. },
  13286. 'stylesheet': function stylesheet() {
  13287. return checkStylesheet(pos) && getStylesheet();
  13288. },
  13289. 'typeSelector': function typeSelector() {
  13290. return checkTypeSelector(pos) && getTypeSelector();
  13291. },
  13292. 'unary': function unary() {
  13293. return checkUnary(pos) && getUnary();
  13294. },
  13295. 'unicodeRange': function unicodeRange() {
  13296. return checkUnicodeRange(pos) && getUnicodeRange();
  13297. },
  13298. 'universalSelector': function universalSelector() {
  13299. return checkUniversalSelector(pos) && getUniversalSelector();
  13300. },
  13301. 'urange': function urange() {
  13302. return checkUrange(pos) && getUrange();
  13303. },
  13304. 'uri': function uri() {
  13305. return checkUri(pos) && getUri();
  13306. },
  13307. 'value': function value() {
  13308. return checkValue(pos) && getValue();
  13309. },
  13310. 'variable': function variable() {
  13311. return checkVariable(pos) && getVariable();
  13312. },
  13313. 'variableslist': function variableslist() {
  13314. return checkVariablesList(pos) && getVariablesList();
  13315. },
  13316. 'vhash': function vhash() {
  13317. return checkVhash(pos) && getVhash();
  13318. }
  13319. };
  13320. /**
  13321. * Stop parsing and display error
  13322. * @param {Number=} i Token's index number
  13323. */
  13324. function throwError(i) {
  13325. var ln = tokens[i].ln;
  13326. throw { line: ln, syntax: 'scss' };
  13327. }
  13328. /**
  13329. * @param {Number} start
  13330. * @param {Number} finish
  13331. * @returns {String}
  13332. */
  13333. function joinValues(start, finish) {
  13334. var s = '';
  13335. for (var i = start; i < finish + 1; i++) {
  13336. s += tokens[i].value;
  13337. }
  13338. return s;
  13339. }
  13340. /**
  13341. * @param {Number} start
  13342. * @param {Number} num
  13343. * @returns {String}
  13344. */
  13345. function joinValues2(start, num) {
  13346. if (start + num - 1 >= tokensLength) return;
  13347. var s = '';
  13348. for (var i = 0; i < num; i++) {
  13349. s += tokens[start + i].value;
  13350. }
  13351. return s;
  13352. }
  13353. function getLastPosition(content, line, column, colOffset) {
  13354. return typeof content === 'string' ? getLastPositionForString(content, line, column, colOffset) : getLastPositionForArray(content, line, column, colOffset);
  13355. }
  13356. function getLastPositionForString(content, line, column, colOffset) {
  13357. var position = [];
  13358. if (!content) {
  13359. position = [line, column];
  13360. if (colOffset) position[1] += colOffset - 1;
  13361. return position;
  13362. }
  13363. var lastLinebreak = content.lastIndexOf('\n');
  13364. var endsWithLinebreak = lastLinebreak === content.length - 1;
  13365. var splitContent = content.split('\n');
  13366. var linebreaksCount = splitContent.length - 1;
  13367. var prevLinebreak = linebreaksCount === 0 || linebreaksCount === 1 ? -1 : content.length - splitContent[linebreaksCount - 1].length - 2;
  13368. // Line:
  13369. var offset = endsWithLinebreak ? linebreaksCount - 1 : linebreaksCount;
  13370. position[0] = line + offset;
  13371. // Column:
  13372. if (endsWithLinebreak) {
  13373. offset = prevLinebreak !== -1 ? content.length - prevLinebreak : content.length - 1;
  13374. } else {
  13375. offset = linebreaksCount !== 0 ? content.length - lastLinebreak - column - 1 : content.length - 1;
  13376. }
  13377. position[1] = column + offset;
  13378. if (!colOffset) return position;
  13379. if (endsWithLinebreak) {
  13380. position[0]++;
  13381. position[1] = colOffset;
  13382. } else {
  13383. position[1] += colOffset;
  13384. }
  13385. return position;
  13386. }
  13387. function getLastPositionForArray(content, line, column, colOffset) {
  13388. var position = void 0;
  13389. if (content.length === 0) {
  13390. position = [line, column];
  13391. } else {
  13392. var c = content[content.length - 1];
  13393. if (c.hasOwnProperty('end')) {
  13394. position = [c.end.line, c.end.column];
  13395. } else {
  13396. position = getLastPosition(c.content, line, column);
  13397. }
  13398. }
  13399. if (!colOffset) return position;
  13400. if (tokens[pos - 1] && tokens[pos - 1].type !== 'Newline') {
  13401. position[1] += colOffset;
  13402. } else {
  13403. position[0]++;
  13404. position[1] = 1;
  13405. }
  13406. return position;
  13407. }
  13408. function newNode(type, content, line, column, end) {
  13409. if (!end) end = getLastPosition(content, line, column);
  13410. return new Node({
  13411. type: type,
  13412. content: content,
  13413. start: {
  13414. line: line,
  13415. column: column
  13416. },
  13417. end: {
  13418. line: end[0],
  13419. column: end[1]
  13420. },
  13421. syntax: 'scss'
  13422. });
  13423. }
  13424. /**
  13425. * @param {Number} i Token's index number
  13426. * @returns {Number}
  13427. */
  13428. function checkAny(i) {
  13429. var l = void 0;
  13430. if (l = checkBrackets(i)) tokens[i].any_child = 1;else if (l = checkParentheses(i)) tokens[i].any_child = 2;else if (l = checkString(i)) tokens[i].any_child = 3;else if (l = checkVariablesList(i)) tokens[i].any_child = 4;else if (l = checkVariable(i)) tokens[i].any_child = 5;else if (l = checkPlaceholder(i)) tokens[i].any_child = 6;else if (l = checkPercentage(i)) tokens[i].any_child = 7;else if (l = checkDimension(i)) tokens[i].any_child = 8;else if (l = checkUnicodeRange(i)) tokens[i].any_child = 9;else if (l = checkNumber(i)) tokens[i].any_child = 10;else if (l = checkUri(i)) tokens[i].any_child = 11;else if (l = checkExpression(i)) tokens[i].any_child = 12;else if (l = checkFunctionsList(i)) tokens[i].any_child = 13;else if (l = checkFunction(i)) tokens[i].any_child = 14;else if (l = checkInterpolation(i)) tokens[i].any_child = 15;else if (l = checkIdent(i)) tokens[i].any_child = 16;else if (l = checkClass(i)) tokens[i].any_child = 17;else if (l = checkUnary(i)) tokens[i].any_child = 18;else if (l = checkParentSelector(i)) tokens[i].any_child = 19;else if (l = checkImportant(i)) tokens[i].any_child = 20;else if (l = checkGlobal(i)) tokens[i].any_child = 21;else if (l = checkDefault(i)) tokens[i].any_child = 22;else if (l = checkOptional(i)) tokens[i].any_child = 23;
  13431. return l;
  13432. }
  13433. /**
  13434. * @returns {!Node}
  13435. */
  13436. function getAny() {
  13437. var childType = tokens[pos].any_child;
  13438. if (childType === 1) return getBrackets();
  13439. if (childType === 2) return getParentheses();
  13440. if (childType === 3) return getString();
  13441. if (childType === 4) return getVariablesList();
  13442. if (childType === 5) return getVariable();
  13443. if (childType === 6) return getPlaceholder();
  13444. if (childType === 7) return getPercentage();
  13445. if (childType === 8) return getDimension();
  13446. if (childType === 9) return getUnicodeRange();
  13447. if (childType === 10) return getNumber();
  13448. if (childType === 11) return getUri();
  13449. if (childType === 12) return getExpression();
  13450. if (childType === 13) return getFunctionsList();
  13451. if (childType === 14) return getFunction();
  13452. if (childType === 15) return getInterpolation();
  13453. if (childType === 16) return getIdent();
  13454. if (childType === 17) return getClass();
  13455. if (childType === 18) return getUnary();
  13456. if (childType === 19) return getParentSelector();
  13457. if (childType === 20) return getImportant();
  13458. if (childType === 21) return getGlobal();
  13459. if (childType === 22) return getDefault();
  13460. if (childType === 23) return getOptional();
  13461. }
  13462. /**
  13463. * Check if token is part of mixin's arguments.
  13464. * @param {Number} i Token's index number
  13465. * @returns {Number} Length of arguments
  13466. */
  13467. function checkArguments(i) {
  13468. var start = i;
  13469. var l = void 0;
  13470. if (i >= tokensLength || tokens[i].type !== TokenType.LeftParenthesis) return 0;
  13471. // Skip `(`.
  13472. i++;
  13473. while (i < tokens[start].right) {
  13474. if (l = checkArgument(i)) i += l;else return 0;
  13475. }
  13476. return tokens[start].right - start + 1;
  13477. }
  13478. /**
  13479. * @returns {Array}
  13480. */
  13481. function getArguments() {
  13482. var type = NodeType.ArgumentsType;
  13483. var token = tokens[pos];
  13484. var line = token.ln;
  13485. var column = token.col;
  13486. var content = [];
  13487. var body = void 0;
  13488. // Skip `(`.
  13489. pos++;
  13490. while (pos < tokensLength && tokens[pos].type !== TokenType.RightParenthesis) {
  13491. if (checkSingleValueDeclaration(pos)) {
  13492. content.push(getSingleValueDeclaration());
  13493. } else if (checkArgument(pos)) {
  13494. body = getArgument();
  13495. if (typeof body.content === 'string') content.push(body);else content = content.concat(body);
  13496. } else if (checkClass(pos)) content.push(getClass());else throwError(pos);
  13497. }
  13498. var end = getLastPosition(content, line, column, 1);
  13499. // Skip `)`.
  13500. pos++;
  13501. return newNode(type, content, line, column, end);
  13502. }
  13503. /**
  13504. * Check if token is valid to be part of arguments list
  13505. * @param {Number} i Token's index number
  13506. * @returns {Number} Length of argument
  13507. */
  13508. function checkArgument(i) {
  13509. var l = void 0;
  13510. if (l = checkBrackets(i)) tokens[i].argument_child = 1;else if (l = checkParentheses(i)) tokens[i].argument_child = 2;else if (l = checkSingleValueDeclaration(i)) tokens[i].argument_child = 3;else if (l = checkFunctionsList(i)) tokens[i].argument_child = 4;else if (l = checkFunction(i)) tokens[i].argument_child = 5;else if (l = checkVariablesList(i)) tokens[i].argument_child = 6;else if (l = checkVariable(i)) tokens[i].argument_child = 7;else if (l = checkSC(i)) tokens[i].argument_child = 8;else if (l = checkDelim(i)) tokens[i].argument_child = 9;else if (l = checkDeclDelim(i)) tokens[i].argument_child = 10;else if (l = checkString(i)) tokens[i].argument_child = 11;else if (l = checkPercentage(i)) tokens[i].argument_child = 12;else if (l = checkDimension(i)) tokens[i].argument_child = 13;else if (l = checkNumber(i)) tokens[i].argument_child = 14;else if (l = checkUri(i)) tokens[i].argument_child = 15;else if (l = checkInterpolation(i)) tokens[i].argument_child = 16;else if (l = checkIdent(i)) tokens[i].argument_child = 17;else if (l = checkVhash(i)) tokens[i].argument_child = 18;else if (l = checkCustomProperty(i)) tokens[i].argument_child = 19;else if (l = checkOperator(i)) tokens[i].argument_child = 20;else if (l = checkUnary(i)) tokens[i].argument_child = 21;else if (l = checkParentSelector(i)) tokens[i].argument_child = 22;else if (l = checkImportant(i)) tokens[i].argument_child = 23;else if (l = checkGlobal(i)) tokens[i].argument_child = 24;else if (l = checkDefault(i)) tokens[i].argument_child = 25;else if (l = checkOptional(i)) tokens[i].argument_child = 26;
  13511. return l;
  13512. }
  13513. /**
  13514. * @returns {Array} Node that is part of arguments list
  13515. */
  13516. function getArgument() {
  13517. var childType = tokens[pos].argument_child;
  13518. if (childType === 1) return getBrackets();
  13519. if (childType === 2) return getParentheses();
  13520. if (childType === 3) return getSingleValueDeclaration();
  13521. if (childType === 4) return getFunctionsList();
  13522. if (childType === 5) return getFunction();
  13523. if (childType === 6) return getVariablesList();
  13524. if (childType === 7) return getVariable();
  13525. if (childType === 8) return getSC();
  13526. if (childType === 9) return getDelim();
  13527. if (childType === 10) return getDeclDelim();
  13528. if (childType === 11) return getString();
  13529. if (childType === 12) return getPercentage();
  13530. if (childType === 13) return getDimension();
  13531. if (childType === 14) return getNumber();
  13532. if (childType === 15) return getUri();
  13533. if (childType === 16) return getInterpolation();
  13534. if (childType === 17) return getIdent();
  13535. if (childType === 18) return getVhash();
  13536. if (childType === 19) return getCustomProperty();
  13537. if (childType === 20) return getOperator();
  13538. if (childType === 21) return getUnary();
  13539. if (childType === 22) return getParentSelector();
  13540. if (childType === 23) return getImportant();
  13541. if (childType === 24) return getGlobal();
  13542. if (childType === 25) return getDefault();
  13543. if (childType === 26) return getOptional();
  13544. }
  13545. /**
  13546. * Check if token is part of an @-word (e.g. `@import`, `@include`)
  13547. * @param {Number} i Token's index number
  13548. * @returns {Number}
  13549. */
  13550. function checkAtkeyword(i) {
  13551. var l = void 0;
  13552. // Check that token is `@`:
  13553. if (i >= tokensLength || tokens[i++].type !== TokenType.CommercialAt) return 0;
  13554. return (l = checkIdentOrInterpolation(i)) ? l + 1 : 0;
  13555. }
  13556. /**
  13557. * Get node with @-word
  13558. * @return {Node}
  13559. */
  13560. function getAtkeyword() {
  13561. var type = NodeType.AtkeywordType;
  13562. var token = tokens[pos];
  13563. var line = token.ln;
  13564. var column = token.col;
  13565. // Skip `@`.
  13566. pos++;
  13567. var content = getIdentOrInterpolation();
  13568. return newNode(type, content, line, column);
  13569. }
  13570. /**
  13571. * Check if token is a part of an @-rule
  13572. * @param {Number} i Token's index number
  13573. * @returns {Number} Length of @-rule
  13574. */
  13575. function checkAtrule(i) {
  13576. var l = void 0;
  13577. if (i >= tokensLength) return 0;
  13578. // If token already has a record of being part of an @-rule,
  13579. // return the @-rule's length:
  13580. if (tokens[i].atrule_l !== undefined) return tokens[i].atrule_l;
  13581. // If token is part of an @-rule, save the rule's type to token.
  13582. // @keyframes:
  13583. if (l = checkKeyframesRule(i)) tokens[i].atrule_type = 4;
  13584. // @-rule with ruleset:
  13585. else if (l = checkAtruler(i)) tokens[i].atrule_type = 1;
  13586. // Block @-rule:
  13587. else if (l = checkAtruleb(i)) tokens[i].atrule_type = 2;
  13588. // Single-line @-rule:
  13589. else if (l = checkAtrules(i)) tokens[i].atrule_type = 3;else return 0;
  13590. // If token is part of an @-rule, save the rule's length to token:
  13591. tokens[i].atrule_l = l;
  13592. return l;
  13593. }
  13594. /**
  13595. * Get node with @-rule
  13596. * @returns {Array}
  13597. */
  13598. function getAtrule() {
  13599. var childType = tokens[pos].atrule_type;
  13600. if (childType === 1) return getAtruler(); // @-rule with ruleset
  13601. if (childType === 2) return getAtruleb(); // Block @-rule
  13602. if (childType === 3) return getAtrules(); // Single-line @-rule
  13603. if (childType === 4) return getKeyframesRule();
  13604. }
  13605. /**
  13606. * Check if token is part of a block @-rule
  13607. * @param {Number} i Token's index number
  13608. * @returns {Number} Length of the @-rule
  13609. */
  13610. function checkAtruleb(i) {
  13611. var start = i;
  13612. var l = void 0;
  13613. if (i >= tokensLength) return 0;
  13614. if (l = checkAtkeyword(i)) i += l;else return 0;
  13615. if (l = checkTsets(i)) i += l;
  13616. if (l = checkBlock(i)) i += l;else return 0;
  13617. return i - start;
  13618. }
  13619. /**
  13620. * Get node with a block @-rule
  13621. * @returns {Array} `['atruleb', ['atkeyword', x], y, ['block', z]]`
  13622. */
  13623. function getAtruleb() {
  13624. var type = NodeType.AtruleType;
  13625. var token = tokens[pos];
  13626. var line = token.ln;
  13627. var column = token.col;
  13628. var content = [].concat(getAtkeyword(), getTsets(), getBlock());
  13629. return newNode(type, content, line, column);
  13630. }
  13631. /**
  13632. * Check if token is part of an @-rule with ruleset
  13633. * @param {Number} i Token's index number
  13634. * @returns {Number} Length of the @-rule
  13635. */
  13636. function checkAtruler(i) {
  13637. var start = i;
  13638. var l = void 0;
  13639. if (i >= tokensLength) return 0;
  13640. if (l = checkAtkeyword(i)) i += l;else return 0;
  13641. if (l = checkTsets(i)) i += l;
  13642. if (i < tokensLength && tokens[i].type === TokenType.LeftCurlyBracket) i++;else return 0;
  13643. if (l = checkAtrulers(i)) i += l;
  13644. if (i < tokensLength && tokens[i].type === TokenType.RightCurlyBracket) i++;else return 0;
  13645. return i - start;
  13646. }
  13647. /**
  13648. * Get node with an @-rule with ruleset
  13649. * @returns {Array} ['atruler', ['atkeyword', x], y, z]
  13650. */
  13651. function getAtruler() {
  13652. var type = NodeType.AtruleType;
  13653. var token = tokens[pos];
  13654. var line = token.ln;
  13655. var column = token.col;
  13656. var content = [].concat(getAtkeyword(), getTsets(), getAtrulers());
  13657. return newNode(type, content, line, column);
  13658. }
  13659. /**
  13660. * @param {Number} i Token's index number
  13661. * @returns {Number}
  13662. */
  13663. function checkAtrulers(i) {
  13664. var start = i;
  13665. var l = void 0;
  13666. if (i >= tokensLength) return 0;
  13667. if (l = checkSC(i)) i += l;
  13668. while (i < tokensLength) {
  13669. if (l = checkSC(i)) tokens[i].atrulers_child = 1;else if (l = checkAtrule(i)) tokens[i].atrulers_child = 2;else if (l = checkRuleset(i)) tokens[i].atrulers_child = 3;else break;
  13670. i += l;
  13671. }
  13672. if (i < tokensLength) tokens[i].atrulers_end = 1;
  13673. if (l = checkSC(i)) i += l;
  13674. return i - start;
  13675. }
  13676. /**
  13677. * @returns {Array} `['atrulers', x]`
  13678. */
  13679. function getAtrulers() {
  13680. var type = NodeType.BlockType;
  13681. var token = tokens[pos];
  13682. var line = token.ln;
  13683. var column = token.col;
  13684. var content = [];
  13685. // Skip `{`.
  13686. pos++;
  13687. content = content.concat(getSC());
  13688. while (pos < tokensLength && !tokens[pos].atrulers_end) {
  13689. var childType = tokens[pos].atrulers_child;
  13690. if (childType === 1) content = content.concat(getSC());else if (childType === 2) content.push(getAtrule());else if (childType === 3) content.push(getRuleset());else break;
  13691. }
  13692. content = content.concat(getSC());
  13693. var end = getLastPosition(content, line, column, 1);
  13694. // Skip `}`.
  13695. pos++;
  13696. return newNode(type, content, line, column, end);
  13697. }
  13698. /**
  13699. * @param {Number} i Token's index number
  13700. * @returns {Number}
  13701. */
  13702. function checkAtrules(i) {
  13703. var start = i;
  13704. var l = void 0;
  13705. if (i >= tokensLength) return 0;
  13706. if (l = checkAtkeyword(i)) i += l;else return 0;
  13707. if (l = checkTsets(i)) i += l;
  13708. return i - start;
  13709. }
  13710. /**
  13711. * @returns {Array} `['atrules', ['atkeyword', x], y]`
  13712. */
  13713. function getAtrules() {
  13714. var type = NodeType.AtruleType;
  13715. var token = tokens[pos];
  13716. var line = token.ln;
  13717. var column = token.col;
  13718. var content = [].concat(getAtkeyword(), getTsets());
  13719. return newNode(type, content, line, column);
  13720. }
  13721. /**
  13722. * Check if token is part of a block (e.g. `{...}`).
  13723. * @param {Number} i Token's index number
  13724. * @returns {Number} Length of the block
  13725. */
  13726. function checkBlock(i) {
  13727. return i < tokensLength && tokens[i].type === TokenType.LeftCurlyBracket ? tokens[i].right - i + 1 : 0;
  13728. }
  13729. /**
  13730. * Get node with a block
  13731. * @returns {Array} `['block', x]`
  13732. */
  13733. function getBlock() {
  13734. var type = NodeType.BlockType;
  13735. var token = tokens[pos];
  13736. var line = token.ln;
  13737. var column = token.col;
  13738. var end = tokens[pos].right;
  13739. var content = [];
  13740. // Skip `{`.
  13741. pos++;
  13742. while (pos < end) {
  13743. if (checkBlockdecl(pos)) content = content.concat(getBlockdecl());else throwError(pos);
  13744. }
  13745. var end_ = getLastPosition(content, line, column, 1);
  13746. pos = end + 1;
  13747. return newNode(type, content, line, column, end_);
  13748. }
  13749. /**
  13750. * Check if token is part of a declaration (property-value pair)
  13751. * @param {Number} i Token's index number
  13752. * @returns {Number} Length of the declaration
  13753. */
  13754. function checkBlockdecl(i) {
  13755. var l = void 0;
  13756. if (i >= tokensLength) return 0;
  13757. if (l = checkBlockdecl1(i)) tokens[i].bd_type = 1;else if (l = checkBlockdecl2(i)) tokens[i].bd_type = 2;else if (l = checkBlockdecl3(i)) tokens[i].bd_type = 3;else if (l = checkBlockdecl4(i)) tokens[i].bd_type = 4;else return 0;
  13758. return l;
  13759. }
  13760. /**
  13761. * @returns {Array}
  13762. */
  13763. function getBlockdecl() {
  13764. var childType = tokens[pos].bd_type;
  13765. if (childType === 1) return getBlockdecl1();
  13766. if (childType === 2) return getBlockdecl2();
  13767. if (childType === 3) return getBlockdecl3();
  13768. if (childType === 4) return getBlockdecl4();
  13769. }
  13770. /**
  13771. * @param {Number} i Token's index number
  13772. * @returns {Number}
  13773. */
  13774. function checkBlockdecl1(i) {
  13775. var start = i;
  13776. var l = void 0;
  13777. if (l = checkSC(i)) i += l;
  13778. if (l = checkConditionalStatement(i)) tokens[i].bd_kind = 1;else if (l = checkInclude(i)) tokens[i].bd_kind = 2;else if (l = checkExtend(i)) tokens[i].bd_kind = 4;else if (l = checkLoop(i)) tokens[i].bd_kind = 3;else if (l = checkAtrule(i)) tokens[i].bd_kind = 6;else if (l = checkRuleset(i)) tokens[i].bd_kind = 7;else if (l = checkDeclaration(i)) tokens[i].bd_kind = 5;else return 0;
  13779. i += l;
  13780. if (i < tokensLength && (l = checkDeclDelim(i))) i += l;else return 0;
  13781. if (l = checkSC(i)) i += l;
  13782. return i - start;
  13783. }
  13784. /**
  13785. * @returns {Array}
  13786. */
  13787. function getBlockdecl1() {
  13788. var sc = getSC();
  13789. var content = void 0;
  13790. switch (tokens[pos].bd_kind) {
  13791. case 1:
  13792. content = getConditionalStatement();
  13793. break;
  13794. case 2:
  13795. content = getInclude();
  13796. break;
  13797. case 3:
  13798. content = getLoop();
  13799. break;
  13800. case 4:
  13801. content = getExtend();
  13802. break;
  13803. case 5:
  13804. content = getDeclaration();
  13805. break;
  13806. case 6:
  13807. content = getAtrule();
  13808. break;
  13809. case 7:
  13810. content = getRuleset();
  13811. break;
  13812. }
  13813. return sc.concat(content, getSC(), getDeclDelim(), getSC());
  13814. }
  13815. /**
  13816. * @param {Number} i Token's index number
  13817. * @returns {Number}
  13818. */
  13819. function checkBlockdecl2(i) {
  13820. var start = i;
  13821. var l = void 0;
  13822. if (l = checkSC(i)) i += l;
  13823. if (l = checkConditionalStatement(i)) tokens[i].bd_kind = 1;else if (l = checkInclude(i)) tokens[i].bd_kind = 2;else if (l = checkExtend(i)) tokens[i].bd_kind = 4;else if (l = checkMixin(i)) tokens[i].bd_kind = 8;else if (l = checkLoop(i)) tokens[i].bd_kind = 3;else if (l = checkAtrule(i)) tokens[i].bd_kind = 6;else if (l = checkRuleset(i)) tokens[i].bd_kind = 7;else if (l = checkDeclaration(i)) tokens[i].bd_kind = 5;else return 0;
  13824. i += l;
  13825. if (l = checkSC(i)) i += l;
  13826. return i - start;
  13827. }
  13828. /**
  13829. * @returns {Array}
  13830. */
  13831. function getBlockdecl2() {
  13832. var sc = getSC();
  13833. var content = void 0;
  13834. switch (tokens[pos].bd_kind) {
  13835. case 1:
  13836. content = getConditionalStatement();
  13837. break;
  13838. case 2:
  13839. content = getInclude();
  13840. break;
  13841. case 3:
  13842. content = getLoop();
  13843. break;
  13844. case 4:
  13845. content = getExtend();
  13846. break;
  13847. case 5:
  13848. content = getDeclaration();
  13849. break;
  13850. case 6:
  13851. content = getAtrule();
  13852. break;
  13853. case 7:
  13854. content = getRuleset();
  13855. break;
  13856. case 8:
  13857. content = getMixin();
  13858. break;
  13859. }
  13860. return sc.concat(content, getSC());
  13861. }
  13862. /**
  13863. * @param {Number} i Token's index number
  13864. * @returns {Number}
  13865. */
  13866. function checkBlockdecl3(i) {
  13867. var start = i;
  13868. var l = void 0;
  13869. if (l = checkSC(i)) i += l;
  13870. if (l = checkDeclDelim(i)) i += l;else return 0;
  13871. if (l = checkSC(i)) i += l;
  13872. return i - start;
  13873. }
  13874. /**
  13875. * @returns {Array} `[s0, ['declDelim'], s1]` where `s0` and `s1` are
  13876. * are optional whitespaces.
  13877. */
  13878. function getBlockdecl3() {
  13879. return [].concat(getSC(), getDeclDelim(), getSC());
  13880. }
  13881. /**
  13882. * @param {Number} i Token's index number
  13883. * @returns {Number}
  13884. */
  13885. function checkBlockdecl4(i) {
  13886. return checkSC(i);
  13887. }
  13888. /**
  13889. * @returns {Array}
  13890. */
  13891. function getBlockdecl4() {
  13892. return getSC();
  13893. }
  13894. /**
  13895. * Check if token is part of text inside square brackets, e.g. `[1]`
  13896. * @param {Number} i Token's index number
  13897. * @returns {Number}
  13898. */
  13899. function checkBrackets(i) {
  13900. if (i >= tokensLength) return 0;
  13901. var start = i;
  13902. // Skip `[`.
  13903. if (tokens[i].type === TokenType.LeftSquareBracket) i++;else return 0;
  13904. if (i < tokens[start].right) {
  13905. var l = checkTsets(i);
  13906. if (l) i += l;else return 0;
  13907. }
  13908. // Skip `]`.
  13909. i++;
  13910. return i - start;
  13911. }
  13912. /**
  13913. * Get node with text inside parentheses or square brackets (e.g. `(1)`)
  13914. * @return {Node}
  13915. */
  13916. function getBrackets() {
  13917. var type = NodeType.BracketsType;
  13918. var token = tokens[pos];
  13919. var line = token.ln;
  13920. var column = token.col;
  13921. var right = token.right;
  13922. var content = [];
  13923. // Skip `[`.
  13924. pos++;
  13925. if (pos < right) {
  13926. content = getTsets();
  13927. }
  13928. var end = getLastPosition(content, line, column, 1);
  13929. // Skip `]`.
  13930. pos++;
  13931. return newNode(type, content, line, column, end);
  13932. }
  13933. /**
  13934. * Check if token is part of a class selector (e.g. `.abc`)
  13935. * @param {Number} i Token's index number
  13936. * @returns {Number} Length of the class selector
  13937. */
  13938. function checkClass(i) {
  13939. var start = i;
  13940. var l = void 0;
  13941. if (i >= tokensLength) return 0;
  13942. if (tokens[i].class_l) return tokens[i].class_l;
  13943. // Skip `.`.
  13944. if (tokens[i].type === TokenType.FullStop) i++;else return 0;
  13945. if (l = checkIdentOrInterpolation(i)) i += l;else return 0;
  13946. while (i < tokensLength) {
  13947. if (l = checkIdentOrInterpolation(i)) {
  13948. tokens[start].class_l = l + 1;
  13949. i += l;
  13950. } else break;
  13951. }
  13952. tokens[start].classEnd = i;
  13953. return i - start;
  13954. }
  13955. /**
  13956. * Get node with a class selector
  13957. * @returns {Array} `['class', ['ident', x]]` where x is a class's
  13958. * identifier (without `.`, e.g. `abc`).
  13959. */
  13960. function getClass() {
  13961. var type = NodeType.ClassType;
  13962. var token = tokens[pos];
  13963. var line = token.ln;
  13964. var column = token.col;
  13965. var end = token.classEnd;
  13966. var content = [];
  13967. // Skip `.`
  13968. pos++;
  13969. while (pos < end) {
  13970. if (checkIdentOrInterpolation(pos)) {
  13971. content = content.concat(getIdentOrInterpolation());
  13972. } else break;
  13973. }
  13974. return newNode(type, content, line, column);
  13975. }
  13976. function checkCombinator(i) {
  13977. if (i >= tokensLength) return 0;
  13978. var l = void 0;
  13979. if (l = checkCombinator1(i)) tokens[i].combinatorType = 1;else if (l = checkCombinator2(i)) tokens[i].combinatorType = 2;else if (l = checkCombinator3(i)) tokens[i].combinatorType = 3;else if (l = checkCombinator4(i)) tokens[i].combinatorType = 4;
  13980. return l;
  13981. }
  13982. function getCombinator() {
  13983. var type = tokens[pos].combinatorType;
  13984. if (type === 1) return getCombinator1();
  13985. if (type === 2) return getCombinator2();
  13986. if (type === 3) return getCombinator3();
  13987. if (type === 4) return getCombinator4();
  13988. }
  13989. /**
  13990. * (1) `>>>`
  13991. *
  13992. * @param {Number} i
  13993. * @return {Number}
  13994. */
  13995. function checkCombinator1(i) {
  13996. if (i < tokensLength && tokens[i++].type === TokenType.GreaterThanSign && i < tokensLength && tokens[i++].type === TokenType.GreaterThanSign && i < tokensLength && tokens[i++].type === TokenType.GreaterThanSign) return 3;
  13997. return 0;
  13998. }
  13999. /**
  14000. * @return {Node}
  14001. */
  14002. function getCombinator1() {
  14003. var type = NodeType.CombinatorType;
  14004. var token = tokens[pos];
  14005. var line = token.ln;
  14006. var column = token.col;
  14007. var content = '>>>';
  14008. // Skip combinator
  14009. pos += 3;
  14010. return newNode(type, content, line, column);
  14011. }
  14012. /**
  14013. * (1) `||`
  14014. * (2) `>>`
  14015. *
  14016. * @param {Number} i
  14017. * @return {Number}
  14018. */
  14019. function checkCombinator2(i) {
  14020. if (i + 1 >= tokensLength) return 0;
  14021. if (tokens[i].type === TokenType.VerticalLine && tokens[i + 1].type === TokenType.VerticalLine) return 2;
  14022. if (tokens[i].type === TokenType.GreaterThanSign && tokens[i + 1].type === TokenType.GreaterThanSign) return 2;
  14023. return 0;
  14024. }
  14025. /**
  14026. * @return {Node}
  14027. */
  14028. function getCombinator2() {
  14029. var type = NodeType.CombinatorType;
  14030. var token = tokens[pos];
  14031. var line = token.ln;
  14032. var column = token.col;
  14033. var content = '' + token.value + tokens[pos + 1].value;
  14034. // Skip combinator
  14035. pos += 2;
  14036. return newNode(type, content, line, column);
  14037. }
  14038. /**
  14039. * (1) `>`
  14040. * (2) `+`
  14041. * (3) `~`
  14042. *
  14043. * @param {Number} i
  14044. * @return {Number}
  14045. */
  14046. function checkCombinator3(i) {
  14047. var type = tokens[i].type;
  14048. if (type === TokenType.PlusSign || type === TokenType.GreaterThanSign || type === TokenType.Tilde) return 1;else return 0;
  14049. }
  14050. /**
  14051. * @return {Node}
  14052. */
  14053. function getCombinator3() {
  14054. var type = NodeType.CombinatorType;
  14055. var token = tokens[pos];
  14056. var line = token.ln;
  14057. var column = token.col;
  14058. var content = token.value;
  14059. // Skip combinator
  14060. pos++;
  14061. return newNode(type, content, line, column);
  14062. }
  14063. /**
  14064. * (1) `/panda/`
  14065. */
  14066. function checkCombinator4(i) {
  14067. var start = i;
  14068. if (tokens[i].type === TokenType.Solidus) i++;else return 0;
  14069. var l = void 0;
  14070. if (l = checkIdent(i)) i += l;else return 0;
  14071. if (tokens[i].type === TokenType.Solidus) i++;else return 0;
  14072. return i - start;
  14073. }
  14074. /**
  14075. * @return {Node}
  14076. */
  14077. function getCombinator4() {
  14078. var type = NodeType.CombinatorType;
  14079. var token = tokens[pos];
  14080. var line = token.ln;
  14081. var column = token.col;
  14082. // Skip `/`.
  14083. pos++;
  14084. var ident = getIdent();
  14085. // Skip `/`.
  14086. pos++;
  14087. var content = '/' + ident.content + '/';
  14088. return newNode(type, content, line, column);
  14089. }
  14090. /**
  14091. * Check if token is a multiline comment.
  14092. * @param {Number} i Token's index number
  14093. * @returns {Number} `1` if token is a multiline comment, otherwise `0`
  14094. */
  14095. function checkCommentML(i) {
  14096. return i < tokensLength && tokens[i].type === TokenType.CommentML ? 1 : 0;
  14097. }
  14098. /**
  14099. * Get node with a multiline comment
  14100. * @returns {Array} `['commentML', x]` where `x`
  14101. * is the comment's text (without `/*` and `* /`).
  14102. */
  14103. function getCommentML() {
  14104. var type = NodeType.CommentMLType;
  14105. var token = tokens[pos];
  14106. var line = token.ln;
  14107. var column = token.col;
  14108. var content = tokens[pos].value.substring(2);
  14109. var l = content.length;
  14110. if (content.charAt(l - 2) === '*' && content.charAt(l - 1) === '/') content = content.substring(0, l - 2);
  14111. var end = getLastPosition(content, line, column, 2);
  14112. if (end[0] === line) end[1] += 2;
  14113. pos++;
  14114. return newNode(type, content, line, column, end);
  14115. }
  14116. /**
  14117. * Check if token is part of a single-line comment.
  14118. * @param {Number} i Token's index number
  14119. * @returns {Number} `1` if token is a single-line comment, otherwise `0`
  14120. */
  14121. function checkCommentSL(i) {
  14122. return i < tokensLength && tokens[i].type === TokenType.CommentSL ? 1 : 0;
  14123. }
  14124. /**
  14125. * Get node with a single-line comment.
  14126. * @returns {Array} `['commentSL', x]` where `x` is comment's message
  14127. * (without `//`)
  14128. */
  14129. function getCommentSL() {
  14130. var type = NodeType.CommentSLType;
  14131. var token = tokens[pos];
  14132. var line = token.ln;
  14133. var column = token.col;
  14134. var content = tokens[pos++].value.substring(2);
  14135. var end = getLastPosition(content, line, column + 2);
  14136. return newNode(type, content, line, column, end);
  14137. }
  14138. /**
  14139. * Check if token is part of a condition
  14140. * (e.g. `@if ...`, `@else if ...` or `@else ...`).
  14141. * @param {Number} i Token's index number
  14142. * @returns {Number} Length of the condition
  14143. */
  14144. function checkCondition(i) {
  14145. var start = i;
  14146. var l = void 0;
  14147. var _i = void 0;
  14148. var s = void 0;
  14149. if (i >= tokensLength) return 0;
  14150. if (l = checkAtkeyword(i)) i += l;else return 0;
  14151. if (['if', 'else'].indexOf(tokens[start + 1].value) < 0) return 0;
  14152. while (i < tokensLength) {
  14153. if (l = checkBlock(i)) break;
  14154. s = checkSC(i);
  14155. _i = i + s;
  14156. if (l = _checkCondition(_i)) i += l + s;else break;
  14157. }
  14158. return i - start;
  14159. }
  14160. function _checkCondition(i) {
  14161. return checkVariable(i) || checkNumber(i) || checkInterpolation(i) || checkIdent(i) || checkOperator(i) || checkCombinator(i) || checkString(i);
  14162. }
  14163. /**
  14164. * Get node with a condition.
  14165. * @returns {Array} `['condition', x]`
  14166. */
  14167. function getCondition() {
  14168. var type = NodeType.ConditionType;
  14169. var token = tokens[pos];
  14170. var line = token.ln;
  14171. var column = token.col;
  14172. var content = [];
  14173. var s = void 0;
  14174. var _pos = void 0;
  14175. content.push(getAtkeyword());
  14176. while (pos < tokensLength) {
  14177. if (checkBlock(pos)) break;
  14178. s = checkSC(pos);
  14179. _pos = pos + s;
  14180. if (!_checkCondition(_pos)) break;
  14181. if (s) content = content.concat(getSC());
  14182. content.push(_getCondition());
  14183. }
  14184. return newNode(type, content, line, column);
  14185. }
  14186. function _getCondition() {
  14187. if (checkVariable(pos)) return getVariable();
  14188. if (checkNumber(pos)) return getNumber();
  14189. if (checkInterpolation(pos)) return getInterpolation();
  14190. if (checkIdent(pos)) return getIdent();
  14191. if (checkOperator(pos)) return getOperator();
  14192. if (checkCombinator(pos)) return getCombinator();
  14193. if (checkString(pos)) return getString();
  14194. }
  14195. /**
  14196. * Check if token is part of a conditional statement
  14197. * (e.g. `@if ... {} @else if ... {} @else ... {}`).
  14198. * @param {Number} i Token's index number
  14199. * @returns {Number} Length of the condition
  14200. */
  14201. function checkConditionalStatement(i) {
  14202. var start = i;
  14203. var l = void 0;
  14204. if (i >= tokensLength) return 0;
  14205. if (l = checkCondition(i)) i += l;else return 0;
  14206. if (l = checkSC(i)) i += l;
  14207. if (l = checkBlock(i)) i += l;else return 0;
  14208. return i - start;
  14209. }
  14210. /**
  14211. * Get node with a condition.
  14212. * @returns {Array} `['condition', x]`
  14213. */
  14214. function getConditionalStatement() {
  14215. var type = NodeType.ConditionalStatementType;
  14216. var token = tokens[pos];
  14217. var line = token.ln;
  14218. var column = token.col;
  14219. var content = [].concat(getCondition(), getSC(), getBlock());
  14220. return newNode(type, content, line, column);
  14221. }
  14222. /**
  14223. * Check if token is part of a declaration (property-value pair)
  14224. * @param {Number} i Token's index number
  14225. * @returns {Number} Length of the declaration
  14226. */
  14227. function checkDeclaration(i) {
  14228. var start = i;
  14229. var l = void 0;
  14230. if (i >= tokensLength) return 0;
  14231. if (l = checkProperty(i)) i += l;else return 0;
  14232. if (l = checkSC(i)) i += l;
  14233. if (l = checkPropertyDelim(i)) i++;else return 0;
  14234. if (l = checkSC(i)) i += l;
  14235. if (l = checkValue(i)) i += l;else return 0;
  14236. return i - start;
  14237. }
  14238. /**
  14239. * Get node with a declaration
  14240. * @returns {Array} `['declaration', ['property', x], ['propertyDelim'],
  14241. * ['value', y]]`
  14242. */
  14243. function getDeclaration() {
  14244. var type = NodeType.DeclarationType;
  14245. var token = tokens[pos];
  14246. var line = token.ln;
  14247. var column = token.col;
  14248. var content = [].concat(getProperty(), getSC(), getPropertyDelim(), getSC(), getValue());
  14249. return newNode(type, content, line, column);
  14250. }
  14251. /**
  14252. * @param {number} i Token's index number
  14253. * @returns {number} Length of the declaration
  14254. */
  14255. function checkSingleValueDeclaration(i) {
  14256. var start = i;
  14257. var l = void 0;
  14258. if (i >= tokensLength) return 0;
  14259. if (l = checkProperty(i)) i += l;else return 0;
  14260. if (l = checkSC(i)) i += l;
  14261. if (l = checkPropertyDelim(i)) i++;else return 0;
  14262. if (l = checkSC(i)) i += l;
  14263. if (l = checkSingleValue(i)) i += l;else return 0;
  14264. return i - start;
  14265. }
  14266. /**
  14267. * Get node with a declaration
  14268. * @returns {Array} `['declaration', ['property', x], ['propertyDelim'],
  14269. * ['value', y]]`
  14270. */
  14271. function getSingleValueDeclaration() {
  14272. var type = NodeType.DeclarationType;
  14273. var token = tokens[pos];
  14274. var line = token.ln;
  14275. var column = token.col;
  14276. var content = [].concat(getProperty(), getSC(), getPropertyDelim(), getSC(), getSingleValue());
  14277. return newNode(type, content, line, column);
  14278. }
  14279. /**
  14280. * Check if token is a semicolon
  14281. * @param {Number} i Token's index number
  14282. * @returns {Number} `1` if token is a semicolon, otherwise `0`
  14283. */
  14284. function checkDeclDelim(i) {
  14285. return i < tokensLength && tokens[i].type === TokenType.Semicolon ? 1 : 0;
  14286. }
  14287. /**
  14288. * Get node with a semicolon
  14289. * @returns {Array} `['declDelim']`
  14290. */
  14291. function getDeclDelim() {
  14292. var type = NodeType.DeclDelimType;
  14293. var token = tokens[pos];
  14294. var line = token.ln;
  14295. var column = token.col;
  14296. var content = ';';
  14297. pos++;
  14298. return newNode(type, content, line, column);
  14299. }
  14300. /**
  14301. * Check if token if part of `!default` word.
  14302. * @param {Number} i Token's index number
  14303. * @returns {Number} Length of the `!default` word
  14304. */
  14305. function checkDefault(i) {
  14306. var start = i;
  14307. var l = void 0;
  14308. if (i >= tokensLength || tokens[i++].type !== TokenType.ExclamationMark) return 0;
  14309. if (l = checkSC(i)) i += l;
  14310. if (tokens[i].value === 'default') {
  14311. tokens[start].defaultEnd = i;
  14312. return i - start + 1;
  14313. } else {
  14314. return 0;
  14315. }
  14316. }
  14317. /**
  14318. * Get node with a `!default` word
  14319. * @returns {Array} `['default', sc]` where `sc` is optional whitespace
  14320. */
  14321. function getDefault() {
  14322. var type = NodeType.DefaultType;
  14323. var token = tokens[pos];
  14324. var line = token.ln;
  14325. var column = token.col;
  14326. var content = joinValues(pos, token.defaultEnd);
  14327. pos = token.defaultEnd + 1;
  14328. return newNode(type, content, line, column);
  14329. }
  14330. /**
  14331. * Check if token is a comma
  14332. * @param {Number} i Token's index number
  14333. * @returns {Number} `1` if token is a comma, otherwise `0`
  14334. */
  14335. function checkDelim(i) {
  14336. return i < tokensLength && tokens[i].type === TokenType.Comma ? 1 : 0;
  14337. }
  14338. /**
  14339. * Get node with a comma
  14340. * @returns {Array} `['delim']`
  14341. */
  14342. function getDelim() {
  14343. var type = NodeType.DelimType;
  14344. var token = tokens[pos];
  14345. var line = token.ln;
  14346. var column = token.col;
  14347. var content = ',';
  14348. pos++;
  14349. return newNode(type, content, line, column);
  14350. }
  14351. /**
  14352. * Check if token is part of a number with dimension unit (e.g. `10px`)
  14353. * @param {Number} i Token's index number
  14354. * @return {Number}
  14355. */
  14356. function checkDimension(i) {
  14357. var ln = checkNumber(i);
  14358. var li = void 0;
  14359. if (i >= tokensLength || !ln || i + ln >= tokensLength) return 0;
  14360. return (li = checkUnit(i + ln)) ? ln + li : 0;
  14361. }
  14362. /**
  14363. * Get node of a number with dimension unit
  14364. * @return {Node}
  14365. */
  14366. function getDimension() {
  14367. var type = NodeType.DimensionType;
  14368. var token = tokens[pos];
  14369. var line = token.ln;
  14370. var column = token.col;
  14371. var content = [getNumber(), getUnit()];
  14372. return newNode(type, content, line, column);
  14373. }
  14374. /**
  14375. * @param {Number} i Token's index number
  14376. * @returns {Number}
  14377. */
  14378. function checkExpression(i) {
  14379. var start = i;
  14380. if (i >= tokensLength || tokens[i++].value !== 'expression' || i >= tokensLength || tokens[i].type !== TokenType.LeftParenthesis) {
  14381. return 0;
  14382. }
  14383. return tokens[i].right - start + 1;
  14384. }
  14385. /**
  14386. * @returns {Array}
  14387. */
  14388. function getExpression() {
  14389. var type = NodeType.ExpressionType;
  14390. var token = tokens[pos];
  14391. var line = token.ln;
  14392. var column = token.col;
  14393. pos++;
  14394. var content = joinValues(pos + 1, tokens[pos].right - 1);
  14395. var end = getLastPosition(content, line, column, 1);
  14396. if (end[0] === line) end[1] += 11;
  14397. pos = tokens[pos].right + 1;
  14398. return newNode(type, content, line, column, end);
  14399. }
  14400. function checkExtend(i) {
  14401. if (i >= tokensLength) return 0;
  14402. var l = void 0;
  14403. if (l = checkExtend1(i)) tokens[i].extend_child = 1;else if (l = checkExtend2(i)) tokens[i].extend_child = 2;
  14404. return l;
  14405. }
  14406. function getExtend() {
  14407. var childType = tokens[pos].extend_child;
  14408. if (childType === 1) return getExtend1();
  14409. if (childType === 2) return getExtend2();
  14410. }
  14411. /**
  14412. * Checks if token is part of an extend with `!optional` flag.
  14413. * @param {Number} i
  14414. */
  14415. function checkExtend1(i) {
  14416. var start = i;
  14417. var l = void 0;
  14418. if (i >= tokensLength) return 0;
  14419. if (l = checkAtkeyword(i)) i += l;else return 0;
  14420. if (tokens[start + 1].value !== 'extend') return 0;
  14421. if (l = checkSC(i)) i += l;else return 0;
  14422. if (l = checkSelectorsGroup(i)) i += l;else return 0;
  14423. if (l = checkSC(i)) i += l;else return 0;
  14424. if (l = checkOptional(i)) i += l;else return 0;
  14425. return i - start;
  14426. }
  14427. function getExtend1() {
  14428. var type = NodeType.ExtendType;
  14429. var token = tokens[pos];
  14430. var line = token.ln;
  14431. var column = token.col;
  14432. var content = [].concat(getAtkeyword(), getSC(), getSelectorsGroup(), getSC(), getOptional());
  14433. return newNode(type, content, line, column);
  14434. }
  14435. /**
  14436. * Checks if token is part of an extend without `!optional` flag.
  14437. * @param {Number} i
  14438. */
  14439. function checkExtend2(i) {
  14440. var start = i;
  14441. var l = void 0;
  14442. if (i >= tokensLength) return 0;
  14443. if (l = checkAtkeyword(i)) i += l;else return 0;
  14444. if (tokens[start + 1].value !== 'extend') return 0;
  14445. if (l = checkSC(i)) i += l;else return 0;
  14446. if (l = checkSelectorsGroup(i)) i += l;else return 0;
  14447. return i - start;
  14448. }
  14449. function getExtend2() {
  14450. var type = NodeType.ExtendType;
  14451. var token = tokens[pos];
  14452. var line = token.ln;
  14453. var column = token.col;
  14454. var content = [].concat(getAtkeyword(), getSC(), getSelectorsGroup());
  14455. return newNode(type, content, line, column);
  14456. }
  14457. /**
  14458. * @param {Number} i Token's index number
  14459. * @returns {Number}
  14460. */
  14461. function checkFunction(i) {
  14462. var start = i;
  14463. var l = void 0;
  14464. if (i >= tokensLength) return 0;
  14465. if (l = checkIdentOrInterpolation(i)) i += l;else return 0;
  14466. return i < tokensLength && tokens[i].type === TokenType.LeftParenthesis ? tokens[i].right - start + 1 : 0;
  14467. }
  14468. /**
  14469. * @returns {Array}
  14470. */
  14471. function getFunction() {
  14472. var type = NodeType.FunctionType;
  14473. var token = tokens[pos];
  14474. var line = token.ln;
  14475. var column = token.col;
  14476. var content = [].concat(getIdentOrInterpolation(), getArguments());
  14477. return newNode(type, content, line, column);
  14478. }
  14479. /**
  14480. * Check if token is part of a functions list (e.g. `function(value)...`).
  14481. * @param {Number} i Token's index number
  14482. * @returns {Number}
  14483. */
  14484. function checkFunctionsList(i) {
  14485. var d = 0; // Number of dots
  14486. var l = void 0;
  14487. if (i >= tokensLength) return 0;
  14488. if (l = checkFunction(i)) i += l;else return 0;
  14489. while (i < tokensLength && tokens[i].type === TokenType.FullStop) {
  14490. d++;
  14491. i++;
  14492. }
  14493. return d === 3 ? l + d : 0;
  14494. }
  14495. /**
  14496. * Get node with a functions list
  14497. * @returns {Array}
  14498. */
  14499. function getFunctionsList() {
  14500. var type = NodeType.FunctionsListType;
  14501. var token = tokens[pos];
  14502. var line = token.ln;
  14503. var column = token.col;
  14504. var content = [getFunction()];
  14505. var end = getLastPosition(content, line, column, 3);
  14506. // Skip `...`.
  14507. pos += 3;
  14508. return newNode(type, content, line, column, end);
  14509. }
  14510. /**
  14511. * Check if token is part of `!global` word
  14512. * @param {Number} i Token's index number
  14513. * @returns {Number}
  14514. */
  14515. function checkGlobal(i) {
  14516. var start = i;
  14517. var l = void 0;
  14518. if (i >= tokensLength || tokens[i++].type !== TokenType.ExclamationMark) return 0;
  14519. if (l = checkSC(i)) i += l;
  14520. if (tokens[i].value === 'global') {
  14521. tokens[start].globalEnd = i;
  14522. return i - start + 1;
  14523. } else {
  14524. return 0;
  14525. }
  14526. }
  14527. /**
  14528. * Get node with `!global` word
  14529. */
  14530. function getGlobal() {
  14531. var type = NodeType.GlobalType;
  14532. var token = tokens[pos];
  14533. var line = token.ln;
  14534. var column = token.col;
  14535. var content = joinValues(pos, token.globalEnd);
  14536. pos = token.globalEnd + 1;
  14537. return newNode(type, content, line, column);
  14538. }
  14539. /**
  14540. * Check if token is part of an identifier
  14541. * @param {Number} i Token's index number
  14542. * @returns {Number} Length of the identifier
  14543. */
  14544. function checkIdent(i) {
  14545. var start = i;
  14546. if (i >= tokensLength) return 0;
  14547. // Check if token is part of a negative number
  14548. if (tokens[i].type === TokenType.HyphenMinus && tokens[i + 1].type === TokenType.DecimalNumber) return 0;
  14549. if (tokens[i].type === TokenType.HyphenMinus) i++;
  14550. if (checkInterpolation(i)) {
  14551. tokens[start].ident_last = i - 1;
  14552. return i - start;
  14553. }
  14554. if (tokens[i].type === TokenType.LowLine || tokens[i].type === TokenType.Identifier) i++;else return 0;
  14555. for (; i < tokensLength; i++) {
  14556. if (tokens[i].type !== TokenType.HyphenMinus && tokens[i].type !== TokenType.LowLine && tokens[i].type !== TokenType.Identifier && tokens[i].type !== TokenType.DecimalNumber) break;
  14557. }
  14558. tokens[start].ident_last = i - 1;
  14559. return i - start;
  14560. }
  14561. /**
  14562. * Get node with an identifier
  14563. * @returns {Array} `['ident', x]` where `x` is identifier's name
  14564. */
  14565. function getIdent() {
  14566. var type = NodeType.IdentType;
  14567. var token = tokens[pos];
  14568. var line = token.ln;
  14569. var column = token.col;
  14570. var content = joinValues(pos, tokens[pos].ident_last);
  14571. pos = tokens[pos].ident_last + 1;
  14572. return newNode(type, content, line, column);
  14573. }
  14574. /**
  14575. * @param {number} i Token's index number
  14576. * @returns {number} Length of the identifier
  14577. */
  14578. function checkPartialIdent(i) {
  14579. var start = i;
  14580. if (i >= tokensLength) return 0;
  14581. for (; i < tokensLength; i++) {
  14582. if (tokens[i].type !== TokenType.HyphenMinus && tokens[i].type !== TokenType.LowLine && tokens[i].type !== TokenType.Identifier && tokens[i].type !== TokenType.DecimalNumber) break;
  14583. }
  14584. tokens[start].ident_last = i - 1;
  14585. return i - start;
  14586. }
  14587. function checkIdentOrInterpolation(i) {
  14588. var start = i;
  14589. var l = void 0;
  14590. var prevIsInterpolation = false;
  14591. while (i < tokensLength) {
  14592. if (l = checkInterpolation(i)) {
  14593. tokens[i].ii_type = 1;
  14594. i += l;
  14595. prevIsInterpolation = true;
  14596. } else if (l = checkIdent(i)) {
  14597. tokens[i].ii_type = 2;
  14598. i += l;
  14599. prevIsInterpolation = false;
  14600. } else if (prevIsInterpolation && (l = checkPartialIdent(i))) {
  14601. tokens[i].ii_type = 3;
  14602. i += l;
  14603. prevIsInterpolation = false;
  14604. } else break;
  14605. }
  14606. return i - start;
  14607. }
  14608. function getIdentOrInterpolation() {
  14609. var content = [];
  14610. while (pos < tokensLength) {
  14611. var tokenType = tokens[pos].ii_type;
  14612. if (tokenType === 1) {
  14613. content.push(getInterpolation());
  14614. } else if (tokenType === 2 || tokenType === 3) {
  14615. content.push(getIdent());
  14616. } else break;
  14617. }
  14618. return content;
  14619. }
  14620. /**
  14621. * Check if token is part of `!important` word
  14622. * @param {Number} i Token's index number
  14623. * @returns {Number}
  14624. */
  14625. function checkImportant(i) {
  14626. var start = i;
  14627. var l = void 0;
  14628. if (i >= tokensLength || tokens[i++].type !== TokenType.ExclamationMark) return 0;
  14629. if (l = checkSC(i)) i += l;
  14630. if (tokens[i].value === 'important') {
  14631. tokens[start].importantEnd = i;
  14632. return i - start + 1;
  14633. } else {
  14634. return 0;
  14635. }
  14636. }
  14637. /**
  14638. * Get node with `!important` word
  14639. * @returns {Array} `['important', sc]` where `sc` is optional whitespace
  14640. */
  14641. function getImportant() {
  14642. var type = NodeType.ImportantType;
  14643. var token = tokens[pos];
  14644. var line = token.ln;
  14645. var column = token.col;
  14646. var content = joinValues(pos, token.importantEnd);
  14647. pos = token.importantEnd + 1;
  14648. return newNode(type, content, line, column);
  14649. }
  14650. /**
  14651. * Check if token is part of an included mixin (`@include` or `@extend`
  14652. * directive).
  14653. * @param {Number} i Token's index number
  14654. * @returns {Number} Length of the included mixin
  14655. */
  14656. function checkInclude(i) {
  14657. var l = void 0;
  14658. if (i >= tokensLength) return 0;
  14659. if (l = checkInclude1(i)) tokens[i].include_type = 1;else if (l = checkInclude2(i)) tokens[i].include_type = 2;else if (l = checkInclude3(i)) tokens[i].include_type = 3;else if (l = checkInclude4(i)) tokens[i].include_type = 4;else if (l = checkInclude5(i)) tokens[i].include_type = 5;
  14660. return l;
  14661. }
  14662. /**
  14663. * Get node with included mixin
  14664. * @returns {Array} `['include', x]`
  14665. */
  14666. function getInclude() {
  14667. var type = tokens[pos].include_type;
  14668. if (type === 1) return getInclude1();
  14669. if (type === 2) return getInclude2();
  14670. if (type === 3) return getInclude3();
  14671. if (type === 4) return getInclude4();
  14672. if (type === 5) return getInclude5();
  14673. }
  14674. /**
  14675. * Get node with included mixin with keyfames selector like
  14676. * `@include nani(foo) { 0% {}}`
  14677. * @param {Number} i Token's index number
  14678. * @returns {Number} Length of the include
  14679. */
  14680. function checkInclude1(i) {
  14681. var start = i;
  14682. var l = void 0;
  14683. if (l = checkAtkeyword(i)) i += l;else return 0;
  14684. if (tokens[start + 1].value !== 'include') return 0;
  14685. if (l = checkSC(i)) i += l;else return 0;
  14686. if (l = checkIdentOrInterpolation(i)) i += l;else return 0;
  14687. if (l = checkSC(i)) i += l;
  14688. if (l = checkArguments(i)) i += l;else return 0;
  14689. if (l = checkSC(i)) i += l;
  14690. if (l = checkKeyframesBlocks(i)) i += l;else return 0;
  14691. return i - start;
  14692. }
  14693. /**
  14694. * Get node with included mixin with keyfames selector like
  14695. * `@include nani(foo) { 0% {}}`
  14696. * @returns {Array} `['include', ['atkeyword', x], sc, ['selector', y], sc,
  14697. * ['arguments', z], sc, ['block', q], sc` where `x` is `include` or
  14698. * `extend`, `y` is mixin's identifier (selector), `z` are arguments
  14699. * passed to the mixin, `q` is block passed to the mixin containing a
  14700. * ruleset > selector > keyframesSelector, and `sc` are optional
  14701. * whitespaces
  14702. */
  14703. function getInclude1() {
  14704. var type = NodeType.IncludeType;
  14705. var token = tokens[pos];
  14706. var line = token.ln;
  14707. var column = token.col;
  14708. var content = [].concat(getAtkeyword(), getSC(), getIdentOrInterpolation(), getSC(), getArguments(), getSC(), getKeyframesBlocks());
  14709. return newNode(type, content, line, column);
  14710. }
  14711. /**
  14712. * Check if token is part of an included mixin like `@include nani(foo) {...}`
  14713. * @param {Number} i Token's index number
  14714. * @returns {Number} Length of the include
  14715. */
  14716. function checkInclude2(i) {
  14717. var start = i;
  14718. var l = void 0;
  14719. if (l = checkAtkeyword(i)) i += l;else return 0;
  14720. if (tokens[start + 1].value !== 'include') return 0;
  14721. if (l = checkSC(i)) i += l;else return 0;
  14722. if (l = checkIdentOrInterpolation(i)) i += l;else return 0;
  14723. if (l = checkSC(i)) i += l;
  14724. if (l = checkArguments(i)) i += l;else return 0;
  14725. if (l = checkSC(i)) i += l;
  14726. if (l = checkBlock(i)) i += l;else return 0;
  14727. return i - start;
  14728. }
  14729. /**
  14730. * Get node with included mixin like `@include nani(foo) {...}`
  14731. * @returns {Array} `['include', ['atkeyword', x], sc, ['selector', y], sc,
  14732. * ['arguments', z], sc, ['block', q], sc` where `x` is `include` or
  14733. * `extend`, `y` is mixin's identifier (selector), `z` are arguments
  14734. * passed to the mixin, `q` is block passed to the mixin and `sc`
  14735. * are optional whitespaces
  14736. */
  14737. function getInclude2() {
  14738. var type = NodeType.IncludeType;
  14739. var token = tokens[pos];
  14740. var line = token.ln;
  14741. var column = token.col;
  14742. var content = [].concat(getAtkeyword(), getSC(), getIdentOrInterpolation(), getSC(), getArguments(), getSC(), getBlock());
  14743. return newNode(type, content, line, column);
  14744. }
  14745. /**
  14746. * Check if token is part of an included mixin like `@include nani(foo)`
  14747. * @param {Number} i Token's index number
  14748. * @returns {Number} Length of the include
  14749. */
  14750. function checkInclude3(i) {
  14751. var start = i;
  14752. var l = void 0;
  14753. if (l = checkAtkeyword(i)) i += l;else return 0;
  14754. if (tokens[start + 1].value !== 'include') return 0;
  14755. if (l = checkSC(i)) i += l;else return 0;
  14756. if (l = checkIdentOrInterpolation(i)) i += l;else return 0;
  14757. if (l = checkSC(i)) i += l;
  14758. if (l = checkArguments(i)) i += l;else return 0;
  14759. return i - start;
  14760. }
  14761. /**
  14762. * Get node with included mixin like `@include nani(foo)`
  14763. * @returns {Array} `['include', ['atkeyword', x], sc, ['selector', y], sc,
  14764. * ['arguments', z], sc]` where `x` is `include` or `extend`, `y` is
  14765. * mixin's identifier (selector), `z` are arguments passed to the
  14766. * mixin and `sc` are optional whitespaces
  14767. */
  14768. function getInclude3() {
  14769. var type = NodeType.IncludeType;
  14770. var token = tokens[pos];
  14771. var line = token.ln;
  14772. var column = token.col;
  14773. var content = [].concat(getAtkeyword(), getSC(), getIdentOrInterpolation(), getSC(), getArguments());
  14774. return newNode(type, content, line, column);
  14775. }
  14776. /**
  14777. * Check if token is part of an included mixin with a content block passed
  14778. * as an argument (e.g. `@include nani {...}`)
  14779. * @param {Number} i Token's index number
  14780. * @returns {Number} Length of the mixin
  14781. */
  14782. function checkInclude4(i) {
  14783. var start = i;
  14784. var l = void 0;
  14785. if (l = checkAtkeyword(i)) i += l;else return 0;
  14786. if (tokens[start + 1].value !== 'include') return 0;
  14787. if (l = checkSC(i)) i += l;else return 0;
  14788. if (l = checkIdentOrInterpolation(i)) i += l;else return 0;
  14789. if (l = checkSC(i)) i += l;
  14790. if (l = checkBlock(i)) i += l;else return 0;
  14791. return i - start;
  14792. }
  14793. /**
  14794. * Get node with an included mixin with a content block passed
  14795. * as an argument (e.g. `@include nani {...}`)
  14796. * @returns {Array} `['include', x]`
  14797. */
  14798. function getInclude4() {
  14799. var type = NodeType.IncludeType;
  14800. var token = tokens[pos];
  14801. var line = token.ln;
  14802. var column = token.col;
  14803. var content = [].concat(getAtkeyword(), getSC(), getIdentOrInterpolation(), getSC(), getBlock());
  14804. return newNode(type, content, line, column);
  14805. }
  14806. /**
  14807. * @param {Number} i Token's index number
  14808. * @returns {Number}
  14809. */
  14810. function checkInclude5(i) {
  14811. var start = i;
  14812. var l = void 0;
  14813. if (l = checkAtkeyword(i)) i += l;else return 0;
  14814. if (tokens[start + 1].value !== 'include') return 0;
  14815. if (l = checkSC(i)) i += l;else return 0;
  14816. if (l = checkIdentOrInterpolation(i)) i += l;else return 0;
  14817. return i - start;
  14818. }
  14819. /**
  14820. * @returns {Array} `['include', x]`
  14821. */
  14822. function getInclude5() {
  14823. var type = NodeType.IncludeType;
  14824. var token = tokens[pos];
  14825. var line = token.ln;
  14826. var column = token.col;
  14827. var content = [].concat(getAtkeyword(), getSC(), getIdentOrInterpolation());
  14828. return newNode(type, content, line, column);
  14829. }
  14830. /**
  14831. * Check if token is part of an interpolated variable (e.g. `#{$nani}`).
  14832. * @param {Number} i Token's index number
  14833. * @returns {Number}
  14834. */
  14835. function checkInterpolation(i) {
  14836. var start = i;
  14837. var l = void 0;
  14838. if (i >= tokensLength) return 0;
  14839. if (tokens[i].type !== TokenType.NumberSign || !tokens[i + 1] || tokens[i + 1].type !== TokenType.LeftCurlyBracket) return 0;
  14840. i += 2;
  14841. while (tokens[i].type !== TokenType.RightCurlyBracket) {
  14842. if (l = checkArgument(i)) i += l;else return 0;
  14843. }
  14844. return tokens[i].type === TokenType.RightCurlyBracket ? i - start + 1 : 0;
  14845. }
  14846. /**
  14847. * Get node with an interpolated variable
  14848. * @returns {Array} `['interpolation', x]`
  14849. */
  14850. function getInterpolation() {
  14851. var type = NodeType.InterpolationType;
  14852. var token = tokens[pos];
  14853. var line = token.ln;
  14854. var column = token.col;
  14855. var content = [];
  14856. // Skip `#{`:
  14857. pos += 2;
  14858. while (pos < tokensLength && tokens[pos].type !== TokenType.RightCurlyBracket) {
  14859. var body = getArgument();
  14860. if (typeof body.content === 'string') content.push(body);else content = content.concat(body);
  14861. }
  14862. var end = getLastPosition(content, line, column, 1);
  14863. // Skip `}`:
  14864. pos++;
  14865. return newNode(type, content, line, column, end);
  14866. }
  14867. /**
  14868. * Check a single keyframe block - `5% {}`
  14869. * @param {Number} i
  14870. * @returns {Number}
  14871. */
  14872. function checkKeyframesBlock(i) {
  14873. var start = i;
  14874. var l = void 0;
  14875. if (i >= tokensLength) return 0;
  14876. if (l = checkKeyframesSelectorsGroup(i)) i += l;else return 0;
  14877. if (l = checkSC(i)) i += l;
  14878. if (l = checkBlock(i)) i += l;else return 0;
  14879. return i - start;
  14880. }
  14881. /**
  14882. * Get a single keyframe block - `5% {}`
  14883. * @returns {Node}
  14884. */
  14885. function getKeyframesBlock() {
  14886. var type = NodeType.RulesetType;
  14887. var token = tokens[pos];
  14888. var line = token.ln;
  14889. var column = token.col;
  14890. var content = [].concat(getKeyframesSelectorsGroup(), getSC(), getBlock());
  14891. return newNode(type, content, line, column);
  14892. }
  14893. /**
  14894. * Check all keyframe blocks - `5% {} 100% {}`
  14895. * @param {Number} i
  14896. * @returns {Number}
  14897. */
  14898. function checkKeyframesBlocks(i) {
  14899. var start = i;
  14900. var l = void 0;
  14901. if (i < tokensLength && tokens[i].type === TokenType.LeftCurlyBracket) i++;else return 0;
  14902. if (l = checkSC(i)) i += l;
  14903. if (l = checkKeyframesBlock(i)) i += l;
  14904. while (tokens[i].type !== TokenType.RightCurlyBracket) {
  14905. if (l = checkSC(i)) i += l;else if (l = checkKeyframesBlock(i)) i += l;else if (l = checkAtrule(i)) {
  14906. i += l;
  14907. if (l = checkSC(i)) i += l;
  14908. if (l = checkDeclDelim(i)) i += l;
  14909. } else break;
  14910. }
  14911. if (i < tokensLength && tokens[i].type === TokenType.RightCurlyBracket) i++;else return 0;
  14912. return i - start;
  14913. }
  14914. /**
  14915. * Get all keyframe blocks - `5% {} 100% {}`
  14916. * @returns {Node}
  14917. */
  14918. function getKeyframesBlocks() {
  14919. var type = NodeType.BlockType;
  14920. var token = tokens[pos];
  14921. var line = token.ln;
  14922. var column = token.col;
  14923. var keyframesBlocksEnd = token.right;
  14924. var content = [];
  14925. // Skip `{`.
  14926. pos++;
  14927. while (pos < keyframesBlocksEnd) {
  14928. if (checkSC(pos)) content = content.concat(getSC());else if (checkKeyframesBlock(pos)) content.push(getKeyframesBlock());else if (checkAtrule(pos)) {
  14929. content.push(getAtrule()); // @content
  14930. if (checkSC(pos)) content = content.concat(getSC());
  14931. if (checkDeclDelim(pos)) content.push(getDeclDelim());
  14932. } else break;
  14933. }
  14934. var end = getLastPosition(content, line, column, 1);
  14935. // Skip `}`.
  14936. pos++;
  14937. return newNode(type, content, line, column, end);
  14938. }
  14939. /**
  14940. * Check if token is part of a @keyframes rule.
  14941. * @param {Number} i Token's index number
  14942. * @return {Number} Length of the @keyframes rule
  14943. */
  14944. function checkKeyframesRule(i) {
  14945. var start = i;
  14946. var l = void 0;
  14947. if (i >= tokensLength) return 0;
  14948. if (l = checkAtkeyword(i)) i += l;else return 0;
  14949. var atruleName = joinValues2(i - l, l);
  14950. if (atruleName.toLowerCase().indexOf('keyframes') === -1) return 0;
  14951. if (l = checkSC(i)) i += l;else return 0;
  14952. if (l = checkIdentOrInterpolation(i) || checkPseudoc(i)) i += l;else return 0;
  14953. if (l = checkSC(i)) i += l;
  14954. if (l = checkKeyframesBlocks(i)) i += l;else return 0;
  14955. return i - start;
  14956. }
  14957. /**
  14958. * @return {Node}
  14959. */
  14960. function getKeyframesRule() {
  14961. var type = NodeType.AtruleType;
  14962. var token = tokens[pos];
  14963. var line = token.ln;
  14964. var column = token.col;
  14965. var content = [].concat(getAtkeyword(), getSC());
  14966. if (checkIdentOrInterpolation(pos)) content = content.concat(getIdentOrInterpolation());else if (checkPseudoc(pos)) {
  14967. content = content.concat(getPseudoc());
  14968. }
  14969. content = content.concat(getSC(), getKeyframesBlocks());
  14970. return newNode(type, content, line, column);
  14971. }
  14972. /**
  14973. * Check a single keyframe selector - `5%`, `from` etc
  14974. * @param {Number} i
  14975. * @returns {Number}
  14976. */
  14977. function checkKeyframesSelector(i) {
  14978. var start = i;
  14979. var l = void 0;
  14980. if (i >= tokensLength) return 0;
  14981. if (l = checkIdent(i)) {
  14982. // Valid selectors are only `from` and `to`.
  14983. var selector = joinValues2(i, l);
  14984. if (selector !== 'from' && selector !== 'to') return 0;
  14985. i += l;
  14986. tokens[start].keyframesSelectorType = 1;
  14987. } else if (l = checkPercentage(i)) {
  14988. i += l;
  14989. tokens[start].keyframesSelectorType = 2;
  14990. } else if (l = checkInterpolation(i)) {
  14991. i += l;
  14992. tokens[start].keyframesSelectorType = 3;
  14993. } else {
  14994. return 0;
  14995. }
  14996. return i - start;
  14997. }
  14998. /**
  14999. * Get a single keyframe selector
  15000. * @returns {Node}
  15001. */
  15002. function getKeyframesSelector() {
  15003. var keyframesSelectorType = NodeType.KeyframesSelectorType;
  15004. var selectorType = NodeType.SelectorType;
  15005. var token = tokens[pos];
  15006. var line = token.ln;
  15007. var column = token.col;
  15008. var content = [];
  15009. if (token.keyframesSelectorType === 1) {
  15010. content.push(getIdent());
  15011. } else if (token.keyframesSelectorType === 2) {
  15012. content.push(getPercentage());
  15013. } else if (token.keyframesSelectorType === 3) {
  15014. content.push(getInterpolation());
  15015. }
  15016. var keyframesSelector = newNode(keyframesSelectorType, content, line, column);
  15017. return newNode(selectorType, [keyframesSelector], line, column);
  15018. }
  15019. /**
  15020. * Check the keyframe's selector groups
  15021. * @param {Number} i
  15022. * @returns {Number}
  15023. */
  15024. function checkKeyframesSelectorsGroup(i) {
  15025. var start = i;
  15026. var l = void 0;
  15027. if (l = checkKeyframesSelector(i)) i += l;else return 0;
  15028. while (i < tokensLength) {
  15029. var spaceBefore = checkSC(i);
  15030. var comma = checkDelim(i + spaceBefore);
  15031. if (!comma) break;
  15032. var spaceAfter = checkSC(i + spaceBefore + comma);
  15033. if (l = checkKeyframesSelector(i + spaceBefore + comma + spaceAfter)) {
  15034. i += spaceBefore + comma + spaceAfter + l;
  15035. } else break;
  15036. }
  15037. tokens[start].selectorsGroupEnd = i;
  15038. return i - start;
  15039. }
  15040. /**
  15041. * Get the keyframe's selector groups
  15042. * @returns {Array} An array of keyframe selectors
  15043. */
  15044. function getKeyframesSelectorsGroup() {
  15045. var selectorsGroup = [];
  15046. var selectorsGroupEnd = tokens[pos].selectorsGroupEnd;
  15047. selectorsGroup.push(getKeyframesSelector());
  15048. while (pos < selectorsGroupEnd) {
  15049. selectorsGroup = selectorsGroup.concat(getSC(), getDelim(), getSC(), getKeyframesSelector());
  15050. }
  15051. return selectorsGroup;
  15052. }
  15053. /**
  15054. * Check if token is part of a loop.
  15055. * @param {Number} i Token's index number
  15056. * @returns {Number} Length of the loop
  15057. */
  15058. function checkLoop(i) {
  15059. var start = i;
  15060. var l = void 0;
  15061. if (i >= tokensLength) return 0;
  15062. if (l = checkAtkeyword(i)) i += l;else return 0;
  15063. if (['for', 'each', 'while'].indexOf(tokens[start + 1].value) < 0) return 0;
  15064. while (i < tokensLength) {
  15065. if (l = checkBlock(i)) {
  15066. i += l;
  15067. break;
  15068. } else if (l = checkVariable(i) || checkNumber(i) || checkInterpolation(i) || checkIdent(i) || checkSC(i) || checkOperator(i) || checkCombinator(i) || checkString(i)) i += l;else return 0;
  15069. }
  15070. return i - start;
  15071. }
  15072. /**
  15073. * Get node with a loop.
  15074. * @returns {Array} `['loop', x]`
  15075. */
  15076. function getLoop() {
  15077. var type = NodeType.LoopType;
  15078. var token = tokens[pos];
  15079. var line = token.ln;
  15080. var column = token.col;
  15081. var content = [];
  15082. content.push(getAtkeyword());
  15083. while (pos < tokensLength) {
  15084. if (checkBlock(pos)) {
  15085. content.push(getBlock());
  15086. break;
  15087. } else if (checkVariable(pos)) content.push(getVariable());else if (checkNumber(pos)) content.push(getNumber());else if (checkInterpolation(pos)) content.push(getInterpolation());else if (checkIdent(pos)) content.push(getIdent());else if (checkOperator(pos)) content.push(getOperator());else if (checkCombinator(pos)) content.push(getCombinator());else if (checkSC(pos)) content = content.concat(getSC());else if (checkString(pos)) content.push(getString());
  15088. }
  15089. return newNode(type, content, line, column);
  15090. }
  15091. /**
  15092. * Check if token is part of a mixin
  15093. * @param {Number} i Token's index number
  15094. * @returns {Number} Length of the mixin
  15095. */
  15096. function checkMixin(i) {
  15097. var start = i;
  15098. var l = void 0;
  15099. if (i >= tokensLength) return 0;
  15100. if ((l = checkAtkeyword(i)) && tokens[i + 1].value === 'mixin') i += l;else return 0;
  15101. if (l = checkSC(i)) i += l;
  15102. if (l = checkIdentOrInterpolation(i)) i += l;else return 0;
  15103. if (l = checkSC(i)) i += l;
  15104. if (l = checkArguments(i)) i += l;
  15105. if (l = checkSC(i)) i += l;
  15106. if (l = checkBlock(i)) i += l;else return 0;
  15107. return i - start;
  15108. }
  15109. /**
  15110. * Get node with a mixin
  15111. * @returns {Array} `['mixin', x]`
  15112. */
  15113. function getMixin() {
  15114. var type = NodeType.MixinType;
  15115. var token = tokens[pos];
  15116. var line = token.ln;
  15117. var column = token.col;
  15118. var content = [].concat(getAtkeyword(), getSC());
  15119. if (checkIdentOrInterpolation(pos)) content = content.concat(getIdentOrInterpolation());
  15120. content = content.concat(getSC());
  15121. if (checkArguments(pos)) content.push(getArguments());
  15122. content = content.concat(getSC());
  15123. if (checkBlock(pos)) content.push(getBlock());
  15124. return newNode(type, content, line, column);
  15125. }
  15126. /**
  15127. * Check if token is a namespace sign (`|`)
  15128. * @param {Number} i Token's index number
  15129. * @returns {Number} `1` if token is `|`, `0` if not
  15130. */
  15131. function checkNamespace(i) {
  15132. return i < tokensLength && tokens[i].type === TokenType.VerticalLine ? 1 : 0;
  15133. }
  15134. /**
  15135. * Get node with a namespace sign
  15136. * @returns {Array} `['namespace']`
  15137. */
  15138. function getNamespace() {
  15139. var type = NodeType.NamespaceType;
  15140. var token = tokens[pos];
  15141. var line = token.ln;
  15142. var column = token.col;
  15143. var content = '|';
  15144. pos++;
  15145. return newNode(type, content, line, column);
  15146. }
  15147. /**
  15148. * @param {Number} i Token's index number
  15149. * @returns {Number}
  15150. */
  15151. function checkNmName2(i) {
  15152. if (tokens[i].type === TokenType.Identifier) return 1;else if (tokens[i].type !== TokenType.DecimalNumber) return 0;
  15153. i++;
  15154. return i < tokensLength && tokens[i].type === TokenType.Identifier ? 2 : 1;
  15155. }
  15156. /**
  15157. * @returns {String}
  15158. */
  15159. function getNmName2() {
  15160. var s = tokens[pos].value;
  15161. if (tokens[pos++].type === TokenType.DecimalNumber && pos < tokensLength && tokens[pos].type === TokenType.Identifier) s += tokens[pos++].value;
  15162. return s;
  15163. }
  15164. /**
  15165. * Check if token is part of a number
  15166. * @param {Number} i Token's index number
  15167. * @returns {Number} Length of number
  15168. */
  15169. function checkNumber(i) {
  15170. if (i >= tokensLength) return 0;
  15171. if (tokens[i].number_l) return tokens[i].number_l;
  15172. // `10`:
  15173. if (i < tokensLength && tokens[i].type === TokenType.DecimalNumber && (!tokens[i + 1] || tokens[i + 1] && tokens[i + 1].type !== TokenType.FullStop)) {
  15174. tokens[i].number_l = 1;
  15175. return 1;
  15176. }
  15177. // `10.`:
  15178. if (i < tokensLength && tokens[i].type === TokenType.DecimalNumber && tokens[i + 1] && tokens[i + 1].type === TokenType.FullStop && (!tokens[i + 2] || tokens[i + 2].type !== TokenType.DecimalNumber)) {
  15179. tokens[i].number_l = 2;
  15180. return 2;
  15181. }
  15182. // `.10`:
  15183. if (i < tokensLength && tokens[i].type === TokenType.FullStop && tokens[i + 1].type === TokenType.DecimalNumber) {
  15184. tokens[i].number_l = 2;
  15185. return 2;
  15186. }
  15187. // `10.10`:
  15188. if (i < tokensLength && tokens[i].type === TokenType.DecimalNumber && tokens[i + 1] && tokens[i + 1].type === TokenType.FullStop && tokens[i + 2] && tokens[i + 2].type === TokenType.DecimalNumber) {
  15189. tokens[i].number_l = 3;
  15190. return 3;
  15191. }
  15192. return 0;
  15193. }
  15194. /**
  15195. * Get node with number
  15196. * @returns {Array} `['number', x]` where `x` is a number converted
  15197. * to string.
  15198. */
  15199. function getNumber() {
  15200. var type = NodeType.NumberType;
  15201. var token = tokens[pos];
  15202. var line = token.ln;
  15203. var column = token.col;
  15204. var l = tokens[pos].number_l;
  15205. var content = '';
  15206. for (var j = 0; j < l; j++) {
  15207. content += tokens[pos + j].value;
  15208. }
  15209. pos += l;
  15210. return newNode(type, content, line, column);
  15211. }
  15212. /**
  15213. * Check if token is an operator (`/`, `%`, `,`, `:` or `=`).
  15214. * @param {Number} i Token's index number
  15215. * @returns {Number} `1` if token is an operator, otherwise `0`
  15216. */
  15217. function checkOperator(i) {
  15218. if (i >= tokensLength) return 0;
  15219. switch (tokens[i].type) {
  15220. case TokenType.Solidus:
  15221. case TokenType.PercentSign:
  15222. case TokenType.Comma:
  15223. case TokenType.Colon:
  15224. case TokenType.EqualsSign:
  15225. case TokenType.EqualitySign:
  15226. case TokenType.InequalitySign:
  15227. case TokenType.LessThanSign:
  15228. case TokenType.GreaterThanSign:
  15229. case TokenType.Asterisk:
  15230. return 1;
  15231. }
  15232. return 0;
  15233. }
  15234. /**
  15235. * Get node with an operator
  15236. * @returns {Array} `['operator', x]` where `x` is an operator converted
  15237. * to string.
  15238. */
  15239. function getOperator() {
  15240. var type = NodeType.OperatorType;
  15241. var token = tokens[pos];
  15242. var line = token.ln;
  15243. var column = token.col;
  15244. var content = token.value;
  15245. pos++;
  15246. return newNode(type, content, line, column);
  15247. }
  15248. /**
  15249. * Check if token is part of `!optional` word
  15250. * @param {Number} i Token's index number
  15251. * @returns {Number}
  15252. */
  15253. function checkOptional(i) {
  15254. var start = i;
  15255. var l = void 0;
  15256. if (i >= tokensLength || tokens[i++].type !== TokenType.ExclamationMark) return 0;
  15257. if (l = checkSC(i)) i += l;
  15258. if (tokens[i].value === 'optional') {
  15259. tokens[start].optionalEnd = i;
  15260. return i - start + 1;
  15261. } else {
  15262. return 0;
  15263. }
  15264. }
  15265. /**
  15266. * Get node with `!optional` word
  15267. */
  15268. function getOptional() {
  15269. var type = NodeType.OptionalType;
  15270. var token = tokens[pos];
  15271. var line = token.ln;
  15272. var column = token.col;
  15273. var content = joinValues(pos, token.optionalEnd);
  15274. pos = token.optionalEnd + 1;
  15275. return newNode(type, content, line, column);
  15276. }
  15277. /**
  15278. * Check if token is part of text inside parentheses, e.g. `(1)`
  15279. * @param {Number} i Token's index number
  15280. * @return {Number}
  15281. */
  15282. function checkParentheses(i) {
  15283. if (i >= tokensLength) return 0;
  15284. var start = i;
  15285. var right = tokens[i].right;
  15286. var l = void 0;
  15287. // Skip `(`.
  15288. if (tokens[i].type === TokenType.LeftParenthesis) i++;else return 0;
  15289. if (i < right) {
  15290. if (l = checkTsets(i)) i += l;else return 0;
  15291. }
  15292. // Skip `)`.
  15293. i++;
  15294. return i - start;
  15295. }
  15296. /**
  15297. * Get node with text inside parentheses, e.g. `(1)`
  15298. * @return {Node}
  15299. */
  15300. function getParentheses() {
  15301. var type = NodeType.ParenthesesType;
  15302. var token = tokens[pos];
  15303. var line = token.ln;
  15304. var column = token.col;
  15305. var right = token.right;
  15306. var content = [];
  15307. // Skip `(`.
  15308. pos++;
  15309. if (pos < right) {
  15310. content = getTsets();
  15311. }
  15312. var end = getLastPosition(content, line, column, 1);
  15313. // Skip `)`.
  15314. pos++;
  15315. return newNode(type, content, line, column, end);
  15316. }
  15317. /**
  15318. * Check if token is a parent selector, e.g. `&`
  15319. * @param {number} i Token's index number
  15320. * @return {number}
  15321. */
  15322. function checkParentSelector(i) {
  15323. return i < tokensLength && tokens[i].type === TokenType.Ampersand ? 1 : 0;
  15324. }
  15325. /**
  15326. * Get node with a parent selector
  15327. * @return {Node}
  15328. */
  15329. function getParentSelector() {
  15330. var type = NodeType.ParentSelectorType;
  15331. var token = tokens[pos];
  15332. var line = token.ln;
  15333. var column = token.col;
  15334. var content = '&';
  15335. pos++;
  15336. return newNode(type, content, line, column);
  15337. }
  15338. /**
  15339. * Check if token is a parent selector extension, e.g. `&--foo-bar`
  15340. * @param {number} i Token's index number
  15341. * @returns {number} Length of the parent selector extension
  15342. */
  15343. function checkParentSelectorExtension(i) {
  15344. var start = i;
  15345. var l = void 0;
  15346. if (i >= tokensLength) return 0;
  15347. while (i < tokensLength) {
  15348. if (l = checkIdentOrInterpolation(i) || checkPartialIdent(i)) i += l;else break;
  15349. }
  15350. return i - start;
  15351. }
  15352. /**
  15353. * Get parent selector extension node
  15354. * @return {Node}
  15355. */
  15356. function getParentSelectorExtension() {
  15357. var type = NodeType.ParentSelectorExtensionType;
  15358. var token = tokens[pos];
  15359. var line = token.ln;
  15360. var column = token.col;
  15361. var content = [];
  15362. while (pos < tokensLength) {
  15363. if (checkIdentOrInterpolation(pos)) {
  15364. content = content.concat(getIdentOrInterpolation());
  15365. } else if (checkPartialIdent(pos)) {
  15366. content.push(getIdent());
  15367. } else break;
  15368. }
  15369. return newNode(type, content, line, column);
  15370. }
  15371. /**
  15372. * Check if token is a parent selector with an extension or not
  15373. * @param {number} i Token's index number
  15374. * @return {number} Length of the parent selector and extension if applicable
  15375. */
  15376. function checkParentSelectorWithExtension(i) {
  15377. var start = i;
  15378. var l = void 0;
  15379. if (i >= tokensLength) return 0;
  15380. if (l = checkParentSelector(i)) i += l;else return 0;
  15381. if (l = checkParentSelectorExtension(i)) i += l;
  15382. return i - start;
  15383. }
  15384. /**
  15385. * Get parent selector node and extension node if applicable
  15386. * @return {Array}
  15387. */
  15388. function getParentSelectorWithExtension() {
  15389. var content = [getParentSelector()];
  15390. if (checkParentSelectorExtension(pos)) content.push(getParentSelectorExtension());
  15391. return content;
  15392. }
  15393. /**
  15394. * Check if token is part of a number or an interpolation with a percent sign
  15395. * (e.g. `10%`).
  15396. * @param {Number} i Token's index number
  15397. * @returns {Number}
  15398. */
  15399. function checkPercentage(i) {
  15400. var start = i;
  15401. var l = void 0;
  15402. if (i >= tokensLength) return 0;
  15403. if (l = checkNumberOrInterpolation(i)) i += l;else return 0;
  15404. if (i >= tokensLength) return 0;
  15405. // Skip `%`.
  15406. if (tokens[i].type === TokenType.PercentSign) i++;else return 0;
  15407. return i - start;
  15408. }
  15409. /**
  15410. * Get a percentage node that contains either a number or an interpolation
  15411. * @returns {Object} The percentage node
  15412. */
  15413. function getPercentage() {
  15414. var type = NodeType.PercentageType;
  15415. var token = tokens[pos];
  15416. var line = token.ln;
  15417. var column = token.col;
  15418. var content = getNumberOrInterpolation();
  15419. var end = getLastPosition(content, line, column, 1);
  15420. // Skip `%`.
  15421. pos++;
  15422. return newNode(type, content, line, column, end);
  15423. }
  15424. /**
  15425. * Check if token is a number or an interpolation
  15426. * @param {Number} i Token's index number
  15427. * @returns {Number}
  15428. */
  15429. function checkNumberOrInterpolation(i) {
  15430. var start = i;
  15431. var l = void 0;
  15432. while (i < tokensLength) {
  15433. if (l = checkInterpolation(i) || checkNumber(i)) i += l;else break;
  15434. }
  15435. return i - start;
  15436. }
  15437. /**
  15438. * Get a number and/or interpolation node
  15439. * @returns {Array} An array containing a single or multiple nodes
  15440. */
  15441. function getNumberOrInterpolation() {
  15442. var content = [];
  15443. while (pos < tokensLength) {
  15444. if (checkInterpolation(pos)) content.push(getInterpolation());else if (checkNumber(pos)) content.push(getNumber());else break;
  15445. }
  15446. return content;
  15447. }
  15448. /**
  15449. * Check if token is part of a placeholder selector (e.g. `%abc`).
  15450. * @param {Number} i Token's index number
  15451. * @returns {Number} Length of the selector
  15452. */
  15453. function checkPlaceholder(i) {
  15454. var start = i;
  15455. var l = void 0;
  15456. if (i >= tokensLength) return 0;
  15457. if (tokens[start].placeholder_l) return tokens[start].placeholder_l;
  15458. // Skip `%`.
  15459. if (tokens[i].type === TokenType.PercentSign) i++;else return 0;
  15460. if (l = checkIdentOrInterpolation(i)) {
  15461. i += l;
  15462. tokens[start].placeholder_l = i - start;
  15463. } else return 0;
  15464. return i - start;
  15465. }
  15466. /**
  15467. * Get node with a placeholder selector
  15468. * @returns {Array} `['placeholder', ['ident', x]]` where x is a placeholder's
  15469. * identifier (without `%`, e.g. `abc`).
  15470. */
  15471. function getPlaceholder() {
  15472. var type = NodeType.PlaceholderType;
  15473. var token = tokens[pos];
  15474. var line = token.ln;
  15475. var column = token.col;
  15476. var content = [];
  15477. // Skip `%`.
  15478. pos++;
  15479. content = content.concat(getIdentOrInterpolation());
  15480. return newNode(type, content, line, column);
  15481. }
  15482. /**
  15483. * @param {Number} i Token's index number
  15484. * @returns {Number}
  15485. */
  15486. function checkProgid(i) {
  15487. var start = i;
  15488. var l = void 0;
  15489. if (i >= tokensLength) return 0;
  15490. if (joinValues2(i, 6) === 'progid:DXImageTransform.Microsoft.') i += 6;else return 0;
  15491. if (l = checkIdentOrInterpolation(i)) i += l;else return 0;
  15492. if (l = checkSC(i)) i += l;
  15493. if (tokens[i].type === TokenType.LeftParenthesis) {
  15494. tokens[start].progid_end = tokens[i].right;
  15495. i = tokens[i].right + 1;
  15496. } else return 0;
  15497. return i - start;
  15498. }
  15499. /**
  15500. * @returns {Array}
  15501. */
  15502. function getProgid() {
  15503. var type = NodeType.ProgidType;
  15504. var token = tokens[pos];
  15505. var line = token.ln;
  15506. var column = token.col;
  15507. var progid_end = token.progid_end;
  15508. var content = joinValues(pos, progid_end);
  15509. pos = progid_end + 1;
  15510. return newNode(type, content, line, column);
  15511. }
  15512. /**
  15513. * Check if token is part of a property
  15514. * @param {Number} i Token's index number
  15515. * @return {Number} Length of the property
  15516. */
  15517. function checkProperty(i) {
  15518. var start = i;
  15519. var l = void 0;
  15520. if (l = checkProperty1(i)) tokens[start].propertyType = 1;else if (l = checkProperty2(i)) tokens[start].propertyType = 2;else if (l = checkProperty3(i)) tokens[start].propertyType = 3;
  15521. return l;
  15522. }
  15523. /**
  15524. * Get node with a property
  15525. * @return {Node}
  15526. */
  15527. function getProperty() {
  15528. var type = tokens[pos].propertyType;
  15529. if (type === 1) return getProperty1();
  15530. if (type === 2) return getProperty2();
  15531. if (type === 3) return getProperty3();
  15532. }
  15533. /**
  15534. * Check if token is part of a property
  15535. * (1) `foo`
  15536. * (2) `#{$foo}`
  15537. * @param {Number} i Token's index number
  15538. * @returns {Number} Length of the property
  15539. */
  15540. function checkProperty1(i) {
  15541. var start = i;
  15542. var l = void 0;
  15543. if (i >= tokensLength) return 0;
  15544. if (l = checkIdentOrInterpolation(i)) i += l;else return 0;
  15545. return i - start;
  15546. }
  15547. /**
  15548. * Get node with a property
  15549. * @returns {Array}
  15550. */
  15551. function getProperty1() {
  15552. var type = NodeType.PropertyType;
  15553. var token = tokens[pos];
  15554. var line = token.ln;
  15555. var column = token.col;
  15556. var content = getIdentOrInterpolation();
  15557. return newNode(type, content, line, column);
  15558. }
  15559. /**
  15560. * Check if token is part of a custom property
  15561. * (1) `--foo-bar`
  15562. * @param {Number} i Token's index number
  15563. * @return {Number} Length of the property
  15564. */
  15565. function checkProperty2(i) {
  15566. return checkCustomProperty(i);
  15567. }
  15568. /**
  15569. * Get node with a custom property
  15570. * @return {Node}
  15571. */
  15572. function getProperty2() {
  15573. return getCustomProperty();
  15574. }
  15575. /**
  15576. * Check if token is part of a property
  15577. * (1) `$foo`
  15578. * @param {Number} i Token's index number
  15579. * @returns {Number} Length of the property
  15580. */
  15581. function checkProperty3(i) {
  15582. var start = i;
  15583. var l = void 0;
  15584. if (i >= tokensLength) return 0;
  15585. if (l = checkVariable(i)) i += l;else return 0;
  15586. return i - start;
  15587. }
  15588. /**
  15589. * Get node with a property
  15590. * @returns {Array} `['property', x]`
  15591. */
  15592. function getProperty3() {
  15593. var type = NodeType.PropertyType;
  15594. var token = tokens[pos];
  15595. var line = token.ln;
  15596. var column = token.col;
  15597. var content = [getVariable()];
  15598. return newNode(type, content, line, column);
  15599. }
  15600. /**
  15601. * Check if token is part of a custom property
  15602. * @param {Number} i Token's index number
  15603. * @return {Number} Length of the property
  15604. */
  15605. function checkCustomProperty(i) {
  15606. var start = i;
  15607. var l = void 0;
  15608. if (i >= tokensLength) return 0;
  15609. if (tokens[i].type !== TokenType.HyphenMinus || tokens[i + 1] && tokens[i + 1].type !== TokenType.HyphenMinus) return 0;
  15610. // Skip `--`
  15611. i += 2;
  15612. if (l = checkIdentOrInterpolation(i)) i += l;else return 0;
  15613. return i - start;
  15614. }
  15615. /**
  15616. * Get node with a custom property
  15617. * @return {Node}
  15618. */
  15619. function getCustomProperty() {
  15620. var type = NodeType.CustomPropertyType;
  15621. var token = tokens[pos];
  15622. var line = token.ln;
  15623. var column = token.col;
  15624. // Skip `--`
  15625. pos += 2;
  15626. var content = getIdentOrInterpolation();
  15627. return newNode(type, content, line, column);
  15628. }
  15629. /**
  15630. * Check if token is a colon
  15631. * @param {Number} i Token's index number
  15632. * @returns {Number} `1` if token is a colon, otherwise `0`
  15633. */
  15634. function checkPropertyDelim(i) {
  15635. return i < tokensLength && tokens[i].type === TokenType.Colon ? 1 : 0;
  15636. }
  15637. /**
  15638. * Get node with a colon
  15639. * @returns {Array} `['propertyDelim']`
  15640. */
  15641. function getPropertyDelim() {
  15642. var type = NodeType.PropertyDelimType;
  15643. var token = tokens[pos];
  15644. var line = token.ln;
  15645. var column = token.col;
  15646. var content = ':';
  15647. // Skip `:`.
  15648. pos++;
  15649. return newNode(type, content, line, column);
  15650. }
  15651. /**
  15652. * @param {Number} i Token's index number
  15653. * @returns {Number}
  15654. */
  15655. function checkPseudo(i) {
  15656. return checkPseudoe(i) || checkPseudoc(i);
  15657. }
  15658. /**
  15659. * @returns {Array}
  15660. */
  15661. function getPseudo() {
  15662. if (checkPseudoe(pos)) return getPseudoe();
  15663. if (checkPseudoc(pos)) return getPseudoc();
  15664. }
  15665. /**
  15666. * @param {Number} i Token's index number
  15667. * @returns {Number}
  15668. */
  15669. function checkPseudoe(i) {
  15670. var l = void 0;
  15671. // Check `::`
  15672. if (i >= tokensLength || tokens[i].type !== TokenType.Colon || i >= tokensLength || tokens[i + 1].type !== TokenType.Colon) return 0;
  15673. if (l = checkPseudoElement1(i)) tokens[i].pseudoElementType = 1;else if (l = checkPseudoElement2(i)) tokens[i].pseudoElementType = 2;else return 0;
  15674. return l;
  15675. }
  15676. /**
  15677. * @returns {Node}
  15678. */
  15679. function getPseudoe() {
  15680. var childType = tokens[pos].pseudoElementType;
  15681. if (childType === 1) return getPseudoElement1();
  15682. if (childType === 2) return getPseudoElement2();
  15683. }
  15684. /**
  15685. * (1) `::slotted(selector)`
  15686. * (2) `::slotted(selector, selector)`
  15687. */
  15688. function checkPseudoElement1(i) {
  15689. var start = i;
  15690. var l = void 0;
  15691. // Skip `::`.
  15692. i += 2;
  15693. if (i >= tokensLength) return 0;
  15694. if (l = checkIdent(i)) i += l;else return 0;
  15695. if (i >= tokensLength || tokens[i].type !== TokenType.LeftParenthesis) return 0;
  15696. var right = tokens[i].right;
  15697. // Skip `(`.
  15698. i++;
  15699. if (l = checkSC(i)) i += l;
  15700. if (l = checkSelectorsGroup(i)) i += l;else return 0;
  15701. if (l = checkSC(i)) i += l;
  15702. if (i !== right) return 0;
  15703. // Skip `)`.
  15704. i++;
  15705. return i - start;
  15706. }
  15707. /**
  15708. * (1) `::slotted(selector)`
  15709. * (2) `::slotted(selector, selector)`
  15710. */
  15711. function getPseudoElement1() {
  15712. var type = NodeType.PseudoeType;
  15713. var token = tokens[pos];
  15714. var line = token.ln;
  15715. var column = token.col;
  15716. var content = [];
  15717. // Skip `::`.
  15718. pos += 2;
  15719. content.push(getIdent());
  15720. {
  15721. var _type = NodeType.ArgumentsType;
  15722. var _token = tokens[pos];
  15723. var _line = _token.ln;
  15724. var _column = _token.col;
  15725. // Skip `(`.
  15726. pos++;
  15727. var selectorContent = [].concat(getSC(), getSelectorsGroup(), getSC());
  15728. var end = getLastPosition(selectorContent, _line, _column, 1);
  15729. var args = newNode(_type, selectorContent, _line, _column, end);
  15730. content.push(args);
  15731. // Skip `)`.
  15732. pos++;
  15733. }
  15734. return newNode(type, content, line, column);
  15735. }
  15736. function checkPseudoElement2(i) {
  15737. var start = i;
  15738. var l = void 0;
  15739. // Skip `::`.
  15740. i += 2;
  15741. if (l = checkIdentOrInterpolation(i)) i += l;else return 0;
  15742. return i - start;
  15743. }
  15744. /**
  15745. * @returns {Node}
  15746. */
  15747. function getPseudoElement2() {
  15748. var type = NodeType.PseudoeType;
  15749. var token = tokens[pos];
  15750. var line = token.ln;
  15751. var column = token.col;
  15752. // Skip `::`.
  15753. pos += 2;
  15754. var content = getIdentOrInterpolation();
  15755. return newNode(type, content, line, column);
  15756. }
  15757. /**
  15758. * @param {Number} i Token's index number
  15759. * @returns {Number}
  15760. */
  15761. function checkPseudoc(i) {
  15762. var l = void 0;
  15763. if (i >= tokensLength || tokens[i].type !== TokenType.Colon) return 0;
  15764. if (l = checkPseudoClass3(i)) tokens[i].pseudoClassType = 3;else if (l = checkPseudoClass4(i)) tokens[i].pseudoClassType = 4;else if (l = checkPseudoClass5(i)) tokens[i].pseudoClassType = 5;else if (l = checkPseudoClass1(i)) tokens[i].pseudoClassType = 1;else if (l = checkPseudoClass2(i)) tokens[i].pseudoClassType = 2;else if (l = checkPseudoClass6(i)) tokens[i].pseudoClassType = 6;else return 0;
  15765. return l;
  15766. }
  15767. /**
  15768. * @returns {Array}
  15769. */
  15770. function getPseudoc() {
  15771. var childType = tokens[pos].pseudoClassType;
  15772. if (childType === 1) return getPseudoClass1();
  15773. if (childType === 2) return getPseudoClass2();
  15774. if (childType === 3) return getPseudoClass3();
  15775. if (childType === 4) return getPseudoClass4();
  15776. if (childType === 5) return getPseudoClass5();
  15777. if (childType === 6) return getPseudoClass6();
  15778. }
  15779. /**
  15780. * (-) `:not(panda)`
  15781. */
  15782. function checkPseudoClass1(i) {
  15783. var start = i;
  15784. var l = void 0;
  15785. // Skip `:`.
  15786. i++;
  15787. if (i >= tokensLength) return 0;
  15788. if (l = checkIdentOrInterpolation(i)) i += l;else return 0;
  15789. if (i >= tokensLength || tokens[i].type !== TokenType.LeftParenthesis) return 0;
  15790. var right = tokens[i].right;
  15791. // Skip `(`.
  15792. i++;
  15793. if (l = checkSC(i)) i += l;
  15794. if (l = checkSelectorsGroup(i)) i += l;else return 0;
  15795. if (l = checkSC(i)) i += l;
  15796. if (i !== right) return 0;
  15797. // Skip `)`.
  15798. i++;
  15799. return i - start;
  15800. }
  15801. /**
  15802. * (-) `:not(panda)`
  15803. */
  15804. function getPseudoClass1() {
  15805. var type = NodeType.PseudocType;
  15806. var token = tokens[pos];
  15807. var line = token.ln;
  15808. var column = token.col;
  15809. var content = [];
  15810. // Skip `:`.
  15811. pos++;
  15812. content = content.concat(getIdentOrInterpolation());
  15813. {
  15814. var _type2 = NodeType.ArgumentsType;
  15815. var _token2 = tokens[pos];
  15816. var _line2 = _token2.ln;
  15817. var _column2 = _token2.col;
  15818. // Skip `(`.
  15819. pos++;
  15820. var selectorContent = [].concat(getSC(), getSelectorsGroup(), getSC());
  15821. var end = getLastPosition(selectorContent, _line2, _column2, 1);
  15822. var args = newNode(_type2, selectorContent, _line2, _column2, end);
  15823. content.push(args);
  15824. // Skip `)`.
  15825. pos++;
  15826. }
  15827. return newNode(type, content, line, column);
  15828. }
  15829. /**
  15830. * (1) `:nth-child(odd)`
  15831. * (2) `:nth-child(even)`
  15832. * (3) `:lang(de-DE)`
  15833. */
  15834. function checkPseudoClass2(i) {
  15835. var start = i;
  15836. var l = void 0;
  15837. // Skip `:`.
  15838. i++;
  15839. if (i >= tokensLength) return 0;
  15840. if (l = checkIdentOrInterpolation(i)) i += l;else return 0;
  15841. if (i >= tokensLength || tokens[i].type !== TokenType.LeftParenthesis) return 0;
  15842. var right = tokens[i].right;
  15843. // Skip `(`.
  15844. i++;
  15845. if (l = checkSC(i)) i += l;
  15846. if (l = checkIdentOrInterpolation(i)) i += l;else return 0;
  15847. if (l = checkSC(i)) i += l;
  15848. if (i !== right) return 0;
  15849. // Skip `)`.
  15850. i++;
  15851. return i - start;
  15852. }
  15853. function getPseudoClass2() {
  15854. var type = NodeType.PseudocType;
  15855. var token = tokens[pos];
  15856. var line = token.ln;
  15857. var column = token.col;
  15858. var content = [];
  15859. // Skip `:`.
  15860. pos++;
  15861. content = content.concat(getIdentOrInterpolation());
  15862. var l = tokens[pos].ln;
  15863. var c = tokens[pos].col;
  15864. // Skip `(`.
  15865. pos++;
  15866. var value = [].concat(getSC(), getIdentOrInterpolation(), getSC());
  15867. var end = getLastPosition(value, l, c, 1);
  15868. var args = newNode(NodeType.ArgumentsType, value, l, c, end);
  15869. content.push(args);
  15870. // Skip `)`.
  15871. pos++;
  15872. return newNode(type, content, line, column);
  15873. }
  15874. /**
  15875. * (-) `:nth-child(-3n + 2)`
  15876. */
  15877. function checkPseudoClass3(i) {
  15878. var start = i;
  15879. var l = void 0;
  15880. // Skip `:`.
  15881. i++;
  15882. if (i >= tokensLength) return 0;
  15883. if (l = checkIdentOrInterpolation(i)) i += l;else return 0;
  15884. if (i >= tokensLength || tokens[i].type !== TokenType.LeftParenthesis) return 0;
  15885. var right = tokens[i].right;
  15886. // Skip `(`.
  15887. i++;
  15888. if (l = checkSC(i)) i += l;
  15889. if (l = checkUnary(i)) i += l;
  15890. if (l = checkNumberOrInterpolation(i)) i += l;
  15891. if (i >= tokensLength) return 0;
  15892. if (tokens[i].value === 'n') i++;
  15893. if (l = checkSC(i)) i += l;
  15894. if (i >= tokensLength) return 0;
  15895. if (tokens[i].type === TokenType.PlusSign || tokens[i].type === TokenType.HyphenMinus) i++;else return 0;
  15896. if (l = checkSC(i)) i += l;
  15897. if (l = checkNumberOrInterpolation(i)) i += l;else return 0;
  15898. if (l = checkSC(i)) i += l;
  15899. if (i !== right) return 0;
  15900. // Skip `)`.
  15901. i++;
  15902. return i - start;
  15903. }
  15904. function getPseudoClass3() {
  15905. var type = NodeType.PseudocType;
  15906. var token = tokens[pos];
  15907. var line = token.ln;
  15908. var column = token.col;
  15909. var content = [];
  15910. // Skip `:`.
  15911. pos++;
  15912. content = content.concat(getIdentOrInterpolation());
  15913. var l = tokens[pos].ln;
  15914. var c = tokens[pos].col;
  15915. var value = [];
  15916. // Skip `(`.
  15917. pos++;
  15918. value = value.concat(getSC());
  15919. if (checkUnary(pos)) value.push(getUnary());
  15920. if (checkNumberOrInterpolation(pos)) value = value.concat(getNumberOrInterpolation());
  15921. {
  15922. var _token3 = tokens[pos];
  15923. if (_token3.value === 'n') {
  15924. var _l = _token3.ln;
  15925. var _c = _token3.col;
  15926. var _content = _token3.value;
  15927. var ident = newNode(NodeType.IdentType, _content, _l, _c);
  15928. value.push(ident);
  15929. pos++;
  15930. }
  15931. }
  15932. value = value.concat(getSC());
  15933. if (checkUnary(pos)) value.push(getUnary());
  15934. value = value.concat(getSC());
  15935. if (checkNumberOrInterpolation(pos)) value = value.concat(getNumberOrInterpolation());
  15936. value = value.concat(getSC());
  15937. var end = getLastPosition(value, l, c, 1);
  15938. var args = newNode(NodeType.ArgumentsType, value, l, c, end);
  15939. content.push(args);
  15940. // Skip `)`.
  15941. pos++;
  15942. return newNode(type, content, line, column);
  15943. }
  15944. /**
  15945. * (-) `:nth-child(-3n)`
  15946. */
  15947. function checkPseudoClass4(i) {
  15948. var start = i;
  15949. var l = void 0;
  15950. // Skip `:`.
  15951. i++;
  15952. if (i >= tokensLength) return 0;
  15953. if (l = checkIdentOrInterpolation(i)) i += l;else return 0;
  15954. if (i >= tokensLength) return 0;
  15955. if (tokens[i].type !== TokenType.LeftParenthesis) return 0;
  15956. var right = tokens[i].right;
  15957. // Skip `(`.
  15958. i++;
  15959. if (l = checkSC(i)) i += l;
  15960. if (l = checkUnary(i)) i += l;
  15961. if (l = checkInterpolation(i)) i += l;
  15962. if (tokens[i].type === TokenType.DecimalNumber) i++;
  15963. if (tokens[i].value === 'n') i++;else return 0;
  15964. if (l = checkSC(i)) i += l;
  15965. if (i !== right) return 0;
  15966. // Skip `)`.
  15967. i++;
  15968. return i - start;
  15969. }
  15970. function getPseudoClass4() {
  15971. var type = NodeType.PseudocType;
  15972. var token = tokens[pos];
  15973. var line = token.ln;
  15974. var column = token.col;
  15975. var content = [];
  15976. // Skip `:`.
  15977. pos++;
  15978. content = content.concat(getIdentOrInterpolation());
  15979. var l = tokens[pos].ln;
  15980. var c = tokens[pos].col;
  15981. var value = [];
  15982. // Skip `(`.
  15983. pos++;
  15984. value = value.concat(getSC());
  15985. if (checkUnary(pos)) value.push(getUnary());
  15986. if (checkInterpolation(pos)) value.push(getInterpolation());
  15987. if (checkNumber(pos)) value.push(getNumber());
  15988. if (checkIdent(pos)) value.push(getIdent());
  15989. value = value.concat(getSC());
  15990. var end = getLastPosition(value, l, c, 1);
  15991. var args = newNode(NodeType.ArgumentsType, value, l, c, end);
  15992. content.push(args);
  15993. // Skip `)`.
  15994. pos++;
  15995. return newNode(type, content, line, column);
  15996. }
  15997. /**
  15998. * (-) `:nth-child(+8)`
  15999. */
  16000. function checkPseudoClass5(i) {
  16001. var start = i;
  16002. var l = void 0;
  16003. // Skip `:`.
  16004. i++;
  16005. if (i >= tokensLength) return 0;
  16006. if (l = checkIdentOrInterpolation(i)) i += l;else return 0;
  16007. if (i >= tokensLength) return 0;
  16008. if (tokens[i].type !== TokenType.LeftParenthesis) return 0;
  16009. var right = tokens[i].right;
  16010. // Skip `(`.
  16011. i++;
  16012. if (l = checkSC(i)) i += l;
  16013. if (l = checkUnary(i)) i += l;
  16014. if (tokens[i].type === TokenType.DecimalNumber) i++;else return 0;
  16015. if (l = checkSC(i)) i += l;
  16016. if (i !== right) return 0;
  16017. // Skip `)`.
  16018. i++;
  16019. return i - start;
  16020. }
  16021. function getPseudoClass5() {
  16022. var type = NodeType.PseudocType;
  16023. var token = tokens[pos];
  16024. var line = token.ln;
  16025. var column = token.col;
  16026. var content = [];
  16027. // Skip `:`.
  16028. pos++;
  16029. content = content.concat(getIdentOrInterpolation());
  16030. var l = tokens[pos].ln;
  16031. var c = tokens[pos].col;
  16032. var value = [];
  16033. // Skip `(`.
  16034. pos++;
  16035. value = value.concat(getSC());
  16036. if (checkUnary(pos)) value.push(getUnary());
  16037. if (checkNumber(pos)) value.push(getNumber());
  16038. value = value.concat(getSC());
  16039. var end = getLastPosition(value, l, c, 1);
  16040. var args = newNode(NodeType.ArgumentsType, value, l, c, end);
  16041. content.push(args);
  16042. // Skip `)`.
  16043. pos++;
  16044. return newNode(type, content, line, column);
  16045. }
  16046. /**
  16047. * (-) `:checked`
  16048. */
  16049. function checkPseudoClass6(i) {
  16050. var start = i;
  16051. var l = void 0;
  16052. // Skip `:`.
  16053. i++;
  16054. if (i >= tokensLength) return 0;
  16055. if (l = checkIdentOrInterpolation(i)) i += l;else return 0;
  16056. return i - start;
  16057. }
  16058. function getPseudoClass6() {
  16059. var type = NodeType.PseudocType;
  16060. var token = tokens[pos];
  16061. var line = token.ln;
  16062. var column = token.col;
  16063. // Skip `:`.
  16064. pos++;
  16065. var content = getIdentOrInterpolation();
  16066. return newNode(type, content, line, column);
  16067. }
  16068. /**
  16069. * @param {Number} i Token's index number
  16070. * @returns {Number}
  16071. */
  16072. function checkRuleset(i) {
  16073. var start = i;
  16074. var l = void 0;
  16075. if (i >= tokensLength) return 0;
  16076. if (l = checkSelectorsGroup(i)) i += l;else return 0;
  16077. if (l = checkSC(i)) i += l;
  16078. if (l = checkBlock(i)) i += l;else return 0;
  16079. return i - start;
  16080. }
  16081. function getRuleset() {
  16082. var type = NodeType.RulesetType;
  16083. var token = tokens[pos];
  16084. var line = token.ln;
  16085. var column = token.col;
  16086. var content = [].concat(getSelectorsGroup(), getSC(), getBlock());
  16087. return newNode(type, content, line, column);
  16088. }
  16089. /**
  16090. * Check if token is marked as a space (if it's a space or a tab
  16091. * or a line break).
  16092. * @param {Number} i
  16093. * @returns {Number} Number of spaces in a row starting with the given token.
  16094. */
  16095. function checkS(i) {
  16096. return i < tokensLength && tokens[i].ws ? tokens[i].ws_last - i + 1 : 0;
  16097. }
  16098. /**
  16099. * Get node with spaces
  16100. * @returns {Array} `['s', x]` where `x` is a string containing spaces
  16101. */
  16102. function getS() {
  16103. var type = NodeType.SType;
  16104. var token = tokens[pos];
  16105. var line = token.ln;
  16106. var column = token.col;
  16107. var content = joinValues(pos, tokens[pos].ws_last);
  16108. pos = tokens[pos].ws_last + 1;
  16109. return newNode(type, content, line, column);
  16110. }
  16111. /**
  16112. * Check if token is a space or a comment.
  16113. * @param {Number} i Token's index number
  16114. * @returns {Number} Number of similar (space or comment) tokens
  16115. * in a row starting with the given token.
  16116. */
  16117. function checkSC(i) {
  16118. if (i >= tokensLength) return 0;
  16119. var l = void 0;
  16120. var lsc = 0;
  16121. while (i < tokensLength) {
  16122. if (l = checkS(i)) tokens[i].sc_child = 1;else if (l = checkCommentML(i)) tokens[i].sc_child = 2;else if (l = checkCommentSL(i)) tokens[i].sc_child = 3;else break;
  16123. i += l;
  16124. lsc += l;
  16125. }
  16126. return lsc || 0;
  16127. }
  16128. /**
  16129. * Get node with spaces and comments
  16130. * @returns {Array} Array containing nodes with spaces (if there are any)
  16131. * and nodes with comments (if there are any):
  16132. * `[['s', x]*, ['comment', y]*]` where `x` is a string of spaces
  16133. * and `y` is a comment's text (without `/*` and `* /`).
  16134. */
  16135. function getSC() {
  16136. var sc = [];
  16137. if (pos >= tokensLength) return sc;
  16138. while (pos < tokensLength) {
  16139. var childType = tokens[pos].sc_child;
  16140. if (childType === 1) sc.push(getS());else if (childType === 2) sc.push(getCommentML());else if (childType === 3) sc.push(getCommentSL());else break;
  16141. }
  16142. return sc;
  16143. }
  16144. /**
  16145. * Check if token is part of a hexadecimal number (e.g. `#fff`) inside a simple
  16146. * selector
  16147. * @param {number} i Token's index number
  16148. * @return {number}
  16149. */
  16150. function checkShash(i) {
  16151. var start = i;
  16152. var l = void 0;
  16153. if (i >= tokensLength) return 0;
  16154. if (tokens[i].type === TokenType.NumberSign) i++;else return 0;
  16155. if (l = checkIdentOrInterpolation(i) || checkPartialIdent(i)) i += l;else return 0;
  16156. while (i < tokensLength) {
  16157. if (l = checkIdentOrInterpolation(i) || checkPartialIdent(i)) i += l;else break;
  16158. }
  16159. tokens[start].shashEnd = i;
  16160. return i - start;
  16161. }
  16162. /**
  16163. * Get node with a hexadecimal number (e.g. `#fff`) inside a simple selector
  16164. * @returns {Node}
  16165. */
  16166. function getShash() {
  16167. var type = NodeType.ShashType;
  16168. var token = tokens[pos];
  16169. var line = token.ln;
  16170. var column = token.col;
  16171. var end = token.shashEnd;
  16172. var content = [];
  16173. // Skip `#`.
  16174. pos++;
  16175. while (pos < end) {
  16176. if (checkIdentOrInterpolation(pos)) {
  16177. content = content.concat(getIdentOrInterpolation());
  16178. } else if (checkPartialIdent(pos)) {
  16179. content.push(getIdent());
  16180. } else break;
  16181. }
  16182. return newNode(type, content, line, column);
  16183. }
  16184. /**
  16185. * Check if token is part of a string (text wrapped in quotes)
  16186. * @param {Number} i Token's index number
  16187. * @returns {Number} `1` if token is part of a string, `0` if not
  16188. */
  16189. function checkString(i) {
  16190. if (i >= tokensLength) return 0;
  16191. if (tokens[i].type === TokenType.StringSQ || tokens[i].type === TokenType.StringDQ) {
  16192. return 1;
  16193. }
  16194. return 0;
  16195. }
  16196. /**
  16197. * Get string's node
  16198. * @returns {Array} `['string', x]` where `x` is a string (including
  16199. * quotes).
  16200. */
  16201. function getString() {
  16202. var type = NodeType.StringType;
  16203. var token = tokens[pos];
  16204. var line = token.ln;
  16205. var column = token.col;
  16206. var content = token.value;
  16207. pos++;
  16208. return newNode(type, content, line, column);
  16209. }
  16210. /**
  16211. * Validate stylesheet: it should consist of any number (0 or more) of
  16212. * rulesets (sets of rules with selectors), @-rules, whitespaces or
  16213. * comments.
  16214. * @param {Number} i Token's index number
  16215. * @returns {Number}
  16216. */
  16217. function checkStylesheet(i) {
  16218. var start = i;
  16219. var l = void 0;
  16220. while (i < tokensLength) {
  16221. if (l = checkSC(i)) tokens[i].stylesheet_child = 1;else if (l = checkRuleset(i)) tokens[i].stylesheet_child = 2;else if (l = checkInclude(i)) tokens[i].stylesheet_child = 3;else if (l = checkExtend(i)) tokens[i].stylesheet_child = 4;else if (l = checkMixin(i)) tokens[i].stylesheet_child = 5;else if (l = checkLoop(i)) tokens[i].stylesheet_child = 6;else if (l = checkConditionalStatement(i)) tokens[i].stylesheet_child = 7;else if (l = checkAtrule(i)) tokens[i].stylesheet_child = 8;else if (l = checkDeclaration(i)) tokens[i].stylesheet_child = 9;else if (l = checkDeclDelim(i)) tokens[i].stylesheet_child = 10;else throwError(i);
  16222. i += l;
  16223. }
  16224. return i - start;
  16225. }
  16226. /**
  16227. * @returns {Array} `['stylesheet', x]` where `x` is all stylesheet's
  16228. * nodes.
  16229. */
  16230. function getStylesheet() {
  16231. var type = NodeType.StylesheetType;
  16232. var token = tokens[pos];
  16233. var line = token.ln;
  16234. var column = token.col;
  16235. var content = [];
  16236. while (pos < tokensLength) {
  16237. var childType = tokens[pos].stylesheet_child;
  16238. if (childType === 1) content = content.concat(getSC());
  16239. if (childType === 2) content.push(getRuleset());
  16240. if (childType === 3) content.push(getInclude());
  16241. if (childType === 4) content.push(getExtend());
  16242. if (childType === 5) content.push(getMixin());
  16243. if (childType === 6) content.push(getLoop());
  16244. if (childType === 7) content.push(getConditionalStatement());
  16245. if (childType === 8) content.push(getAtrule());
  16246. if (childType === 9) content.push(getDeclaration());
  16247. if (childType === 10) content.push(getDeclDelim());
  16248. }
  16249. return newNode(type, content, line, column);
  16250. }
  16251. /**
  16252. * @param {Number} i Token's index number
  16253. * @returns {Number}
  16254. */
  16255. function checkTset(i) {
  16256. var l = void 0;
  16257. if (l = checkVhash(i)) tokens[i].tset_child = 1;else if (l = checkOperator(i)) tokens[i].tset_child = 2;else if (l = checkAny(i)) tokens[i].tset_child = 3;else if (l = checkSC(i)) tokens[i].tset_child = 4;
  16258. return l;
  16259. }
  16260. /**
  16261. * @returns {Array}
  16262. */
  16263. function getTset() {
  16264. var childType = tokens[pos].tset_child;
  16265. if (childType === 1) return getVhash();
  16266. if (childType === 2) return getOperator();
  16267. if (childType === 3) return getAny();
  16268. if (childType === 4) return getSC();
  16269. }
  16270. /**
  16271. * @param {Number} i Token's index number
  16272. * @returns {Number}
  16273. */
  16274. function checkTsets(i) {
  16275. var start = i;
  16276. var l = void 0;
  16277. if (i >= tokensLength) return 0;
  16278. while (l = checkTset(i)) {
  16279. i += l;
  16280. }
  16281. tokens[start].tsets_end = i;
  16282. return i - start;
  16283. }
  16284. /**
  16285. * @returns {Array}
  16286. */
  16287. function getTsets() {
  16288. var content = [];
  16289. var t = void 0;
  16290. if (pos >= tokensLength) return content;
  16291. var end = tokens[pos].tsets_end;
  16292. while (pos < end) {
  16293. t = getTset();
  16294. if (typeof t.content === 'string') content.push(t);else content = content.concat(t);
  16295. }
  16296. return content;
  16297. }
  16298. /**
  16299. * Check if token is an unary (arithmetical) sign (`+` or `-`)
  16300. * @param {Number} i Token's index number
  16301. * @returns {Number} `1` if token is an unary sign, `0` if not
  16302. */
  16303. function checkUnary(i) {
  16304. if (i >= tokensLength) return 0;
  16305. if (tokens[i].type === TokenType.HyphenMinus || tokens[i].type === TokenType.PlusSign) {
  16306. return 1;
  16307. }
  16308. return 0;
  16309. }
  16310. /**
  16311. * Get node with an unary (arithmetical) sign (`+` or `-`)
  16312. * @returns {Array} `['unary', x]` where `x` is an unary sign
  16313. * converted to string.
  16314. */
  16315. function getUnary() {
  16316. var type = NodeType.OperatorType;
  16317. var token = tokens[pos];
  16318. var line = token.ln;
  16319. var column = token.col;
  16320. var content = token.value;
  16321. pos++;
  16322. return newNode(type, content, line, column);
  16323. }
  16324. /**
  16325. * Check if token is a unicode range (single or multiple <urange> nodes)
  16326. * @param {number} i Token's index
  16327. * @return {number} Unicode range node's length
  16328. */
  16329. function checkUnicodeRange(i) {
  16330. var start = i;
  16331. var l = void 0;
  16332. if (i >= tokensLength) return 0;
  16333. if (l = checkUrange(i)) i += l;else return 0;
  16334. while (i < tokensLength) {
  16335. var spaceBefore = checkSC(i);
  16336. var comma = checkDelim(i + spaceBefore);
  16337. if (!comma) break;
  16338. var spaceAfter = checkSC(i + spaceBefore + comma);
  16339. if (l = checkUrange(i + spaceBefore + comma + spaceAfter)) {
  16340. i += spaceBefore + comma + spaceAfter + l;
  16341. } else break;
  16342. }
  16343. return i - start;
  16344. }
  16345. /**
  16346. * Get a unicode range node
  16347. * @return {Node}
  16348. */
  16349. function getUnicodeRange() {
  16350. var type = NodeType.UnicodeRangeType;
  16351. var token = tokens[pos];
  16352. var line = token.ln;
  16353. var column = token.col;
  16354. var content = [];
  16355. while (pos < tokensLength) {
  16356. if (checkSC(pos)) content = content.concat(getSC());else if (checkDelim(pos)) content.push(getDelim());else if (checkUrange(pos)) content.push(getUrange());else break;
  16357. }
  16358. return newNode(type, content, line, column);
  16359. }
  16360. /**
  16361. * Check if token is unit
  16362. * @param {Number} i Token's index number
  16363. * @return {Number}
  16364. */
  16365. function checkUnit(i) {
  16366. var units = ['em', 'ex', 'ch', 'rem', 'vh', 'vw', 'vmin', 'vmax', 'px', 'mm', 'q', 'cm', 'in', 'pt', 'pc', 'deg', 'grad', 'rad', 'turn', 's', 'ms', 'Hz', 'kHz', 'dpi', 'dpcm', 'dppx'];
  16367. return units.indexOf(tokens[i].value) !== -1 ? 1 : 0;
  16368. }
  16369. /**
  16370. * Get unit node of type ident
  16371. * @return {Node} An ident node containing the unit value
  16372. */
  16373. function getUnit() {
  16374. var type = NodeType.IdentType;
  16375. var token = tokens[pos];
  16376. var line = token.ln;
  16377. var column = token.col;
  16378. var content = token.value;
  16379. pos++;
  16380. return newNode(type, content, line, column);
  16381. }
  16382. /**
  16383. * Check if token is a u-range (part of a unicode-range)
  16384. * (1) `U+416`
  16385. * (2) `U+400-4ff`
  16386. * (3) `U+4??`
  16387. * @param {number} i Token's index
  16388. * @return {number} Urange node's length
  16389. */
  16390. function checkUrange(i) {
  16391. var start = i;
  16392. var l = void 0;
  16393. if (i >= tokensLength) return 0;
  16394. // Check for unicode prefix (u+ or U+)
  16395. if (tokens[i].value === 'U' || tokens[i].value === 'u') i += 1;else return 0;
  16396. if (i >= tokensLength) return 0;
  16397. if (tokens[i].value === '+') i += 1;else return 0;
  16398. while (i < tokensLength) {
  16399. if (l = checkIdent(i)) i += l;else if (l = checkNumber(i)) i += l;else if (l = checkUnary(i)) i += l;else if (l = _checkUnicodeWildcard(i)) i += l;else break;
  16400. }
  16401. tokens[start].urangeEnd = i - 1;
  16402. return i - start;
  16403. }
  16404. /**
  16405. * Get a u-range node (part of a unicode-range)
  16406. * @return {Node}
  16407. */
  16408. function getUrange() {
  16409. var startPos = pos;
  16410. var type = NodeType.UrangeType;
  16411. var token = tokens[pos];
  16412. var line = token.ln;
  16413. var column = token.col;
  16414. var content = [];
  16415. content = joinValues(startPos, tokens[startPos].urangeEnd);
  16416. pos = tokens[startPos].urangeEnd + 1;
  16417. return newNode(type, content, line, column);
  16418. }
  16419. /**
  16420. * Check for unicode wildcard characters `?`
  16421. * @param {number} i Token's index
  16422. * @return {number} Wildcard length
  16423. */
  16424. function _checkUnicodeWildcard(i) {
  16425. var start = i;
  16426. if (i >= tokensLength) return 0;
  16427. while (i < tokensLength) {
  16428. if (tokens[i].type === TokenType.QuestionMark) i += 1;else break;
  16429. }
  16430. return i - start;
  16431. }
  16432. /**
  16433. * Check if token is part of URI, e.g. `url('/css/styles.css')`
  16434. * @param {number} i Token's index number
  16435. * @returns {number} Length of URI
  16436. */
  16437. function checkUri(i) {
  16438. var start = i;
  16439. var l = void 0;
  16440. if (i >= tokensLength || tokens[i].value !== 'url') return 0;
  16441. // Skip `url`.
  16442. i++;
  16443. if (i >= tokensLength || tokens[i].type !== TokenType.LeftParenthesis) return 0;
  16444. // Store the opening parenthesis token as we will reference it's `right`
  16445. // property to determine when the parentheses close
  16446. var leftParenthesis = tokens[i];
  16447. // Skip `(`.
  16448. i++;
  16449. // Determine the type of URI
  16450. while (i < leftParenthesis.right) {
  16451. if (l = checkUri1(i)) {
  16452. i += l;
  16453. tokens[start].uriType = 1; // Raw based URI (without quotes)
  16454. } else if (l = checkUri2(i)) {
  16455. i += l;
  16456. tokens[start].uriType = 2; // Non-raw based URI (with quotes)
  16457. } else return 0;
  16458. }
  16459. // Skip `)`.
  16460. i++;
  16461. return i - start;
  16462. }
  16463. /**
  16464. * Get specific type of URI node
  16465. * @return {Node} Specific type of URI node
  16466. */
  16467. function getUri() {
  16468. var startPos = pos;
  16469. var type = NodeType.UriType;
  16470. var token = tokens[startPos];
  16471. var line = token.ln;
  16472. var column = token.col;
  16473. var content = [];
  16474. var end = void 0;
  16475. var uriType = tokens[startPos].uriType;
  16476. // Skip `url` and `(`.
  16477. pos += 2;
  16478. if (uriType === 1) content = content.concat(getUri1());else if (uriType === 2) content = content.concat(getUri2());else end = getLastPosition(content, line, column, 4);
  16479. if (!end) end = getLastPosition(content, line, column, 1);
  16480. // Skip `)`.
  16481. pos++;
  16482. return newNode(type, content, line, column, end);
  16483. }
  16484. /**
  16485. * Check if token type is valid URI character
  16486. * @param {number} i Token's index number
  16487. * @return {number} Length of raw node
  16488. */
  16489. function checkUriRawCharacters(i) {
  16490. var start = i;
  16491. var l = void 0;
  16492. if (l = checkIdent(i)) i += l;else if (l = checkNumber(i)) i += l;else {
  16493. switch (tokens[i].type) {
  16494. case TokenType.ExclamationMark:
  16495. case TokenType.NumberSign:
  16496. case TokenType.DollarSign:
  16497. case TokenType.PercentSign:
  16498. case TokenType.Ampersand:
  16499. case TokenType.Asterisk:
  16500. case TokenType.PlusSign:
  16501. case TokenType.Comma:
  16502. case TokenType.HyphenMinus:
  16503. case TokenType.FullStop:
  16504. case TokenType.Solidus:
  16505. case TokenType.Colon:
  16506. case TokenType.Semicolon:
  16507. case TokenType.LessThanSign:
  16508. case TokenType.EqualsSign:
  16509. case TokenType.GreaterThanSign:
  16510. case TokenType.QuotationMark:
  16511. case TokenType.CommercialAt:
  16512. case TokenType.LeftSquareBracket:
  16513. case TokenType.RightSquareBracket:
  16514. case TokenType.CircumflexAccent:
  16515. case TokenType.LowLine:
  16516. case TokenType.LeftCurlyBracket:
  16517. case TokenType.VerticalLine:
  16518. case TokenType.RightCurlyBracket:
  16519. case TokenType.Tilde:
  16520. i += 1;
  16521. break;
  16522. default:
  16523. return 0;
  16524. }
  16525. }
  16526. return i - start;
  16527. }
  16528. /**
  16529. * Check if content of URI can be contained within a raw node
  16530. * @param {number} i Token's index number
  16531. * @return {number} Length of raw node
  16532. */
  16533. function checkUriRaw(i) {
  16534. var start = i;
  16535. var l = void 0;
  16536. while (i < tokensLength) {
  16537. if (checkInterpolation(i) || checkVariable(i)) break;else if (l = checkUriRawCharacters(i)) i += l;else break;
  16538. }
  16539. tokens[start].uri_raw_end = i;
  16540. return i - start;
  16541. }
  16542. /**
  16543. * Get a raw node
  16544. * @return {Node}
  16545. */
  16546. function getUriRaw() {
  16547. var startPos = pos;
  16548. var type = NodeType.RawType;
  16549. var token = tokens[startPos];
  16550. var line = token.ln;
  16551. var column = token.col;
  16552. var content = [];
  16553. var l = void 0;
  16554. while (pos < tokens[startPos].uri_raw_end) {
  16555. if (checkInterpolation(pos) || checkVariable(pos)) break;else if (l = checkUriRawCharacters(pos)) pos += l;else break;
  16556. }
  16557. content = joinValues(startPos, pos - 1);
  16558. return newNode(type, content, line, column);
  16559. }
  16560. /**
  16561. * Check for a raw (without quotes) URI
  16562. * (1) http://foo.com/bar.png
  16563. * (2) http://foo.com/#{$bar}.png
  16564. * (3) #{$foo}/bar.png
  16565. * (4) #{$foo}
  16566. * @param {number} i Token's index number
  16567. * @return {number} Length of URI node
  16568. */
  16569. function checkUri1(i) {
  16570. var start = i;
  16571. var l = void 0;
  16572. if (l = checkSC(i)) i += l;
  16573. while (i < tokensLength) {
  16574. if (l = checkInterpolation(i) || checkUriRaw(i)) i += l;else break;
  16575. }
  16576. if (l = checkSC(i)) i += l;
  16577. // Check that we are at the end of the uri
  16578. if (i < tokens[start - 1].right) return 0;
  16579. tokens[start].uri_end = i;
  16580. return i - start;
  16581. }
  16582. /**
  16583. * Get a raw (without quotes) URI
  16584. node
  16585. * @return {Array}
  16586. */
  16587. function getUri1() {
  16588. var startPos = pos;
  16589. var content = [];
  16590. if (checkSC(pos)) content = content.concat(getSC());
  16591. while (pos < tokens[startPos].uri_end) {
  16592. if (checkInterpolation(pos)) content.push(getInterpolation());else if (checkUriRaw(pos)) content.push(getUriRaw());else break;
  16593. }
  16594. if (checkSC(pos)) content = content.concat(getSC());
  16595. return content;
  16596. }
  16597. /**
  16598. * Check for a non-raw (with quotes) URI
  16599. * (1) 'http://foo.com/bar.png'
  16600. * (2) 'http://foo.com/'#{$bar}.png
  16601. * (3) #{$foo}'/bar.png'
  16602. * @param {number} i Token's index number
  16603. * @return {number} Length of URI node
  16604. */
  16605. function checkUri2(i) {
  16606. var start = i;
  16607. var l = void 0;
  16608. while (i < tokensLength) {
  16609. if (l = checkSC(i)) i += l;else if (l = checkString(i)) i += l;else if (l = checkFunction(i)) i += l;else if (l = checkUnary(i)) i += l;else if (l = checkIdentOrInterpolation(i)) i += l;else if (l = checkVariable(i)) i += l;else break;
  16610. }
  16611. // Check that we are at the end of the uri
  16612. if (i < tokens[start - 1].right) return 0;
  16613. tokens[start].uri_end = i;
  16614. return i - start;
  16615. }
  16616. /**
  16617. * Get a non-raw (with quotes) URI node
  16618. * @return {Array}
  16619. */
  16620. function getUri2() {
  16621. var startPos = pos;
  16622. var content = [];
  16623. while (pos < tokens[startPos].uri_end) {
  16624. if (checkSC(pos)) content = content.concat(getSC());else if (checkUnary(pos)) content.push(getUnary());else if (_checkValue(pos)) content.push(_getValue());else break;
  16625. }
  16626. return content;
  16627. }
  16628. /**
  16629. * Check if token is part of a value
  16630. * @param {Number} i Token's index number
  16631. * @returns {Number} Length of the value
  16632. */
  16633. function checkValue(i) {
  16634. var start = i;
  16635. var l = void 0;
  16636. var s = void 0;
  16637. var _i = void 0;
  16638. while (i < tokensLength) {
  16639. if (checkDeclDelim(i)) break;
  16640. s = checkSC(i);
  16641. _i = i + s;
  16642. if (l = _checkValue(_i)) i += l + s;
  16643. if (!l || checkBlock(i - l)) break;
  16644. }
  16645. tokens[start].value_end = i;
  16646. return i - start;
  16647. }
  16648. /**
  16649. * @returns {Array}
  16650. */
  16651. function getValue() {
  16652. var type = NodeType.ValueType;
  16653. var token = tokens[pos];
  16654. var line = token.ln;
  16655. var column = token.col;
  16656. var end = tokens[pos].value_end;
  16657. var content = [];
  16658. var _pos = void 0;
  16659. var s = void 0;
  16660. while (pos < end) {
  16661. s = checkSC(pos);
  16662. _pos = pos + s;
  16663. if (checkDeclDelim(_pos)) break;
  16664. if (!_checkValue(_pos)) break;
  16665. if (s) content = content.concat(getSC());
  16666. content.push(_getValue());
  16667. if (checkBlock(_pos)) break;
  16668. }
  16669. return newNode(type, content, line, column);
  16670. }
  16671. /**
  16672. * @param {Number} i Token's index number
  16673. * @returns {Number}
  16674. */
  16675. function _checkValue(i) {
  16676. var l = void 0;
  16677. if (l = checkInterpolation(i)) tokens[i].value_child = 1;else if (l = checkVariable(i)) tokens[i].value_child = 2;else if (l = checkVhash(i)) tokens[i].value_child = 3;else if (l = checkBlock(i)) tokens[i].value_child = 4;else if (l = checkAtkeyword(i)) tokens[i].value_child = 5;else if (l = checkOperator(i)) tokens[i].value_child = 6;else if (l = checkImportant(i)) tokens[i].value_child = 7;else if (l = checkGlobal(i)) tokens[i].value_child = 8;else if (l = checkDefault(i)) tokens[i].value_child = 9;else if (l = checkProgid(i)) tokens[i].value_child = 10;else if (l = checkAny(i)) tokens[i].value_child = 11;else if (l = checkParentSelector(i)) tokens[i].value_child = 12;
  16678. return l;
  16679. }
  16680. /**
  16681. * @returns {Array}
  16682. */
  16683. function _getValue() {
  16684. var childType = tokens[pos].value_child;
  16685. if (childType === 1) return getInterpolation();
  16686. if (childType === 2) return getVariable();
  16687. if (childType === 3) return getVhash();
  16688. if (childType === 4) return getBlock();
  16689. if (childType === 5) return getAtkeyword();
  16690. if (childType === 6) return getOperator();
  16691. if (childType === 7) return getImportant();
  16692. if (childType === 8) return getGlobal();
  16693. if (childType === 9) return getDefault();
  16694. if (childType === 10) return getProgid();
  16695. if (childType === 11) return getAny();
  16696. if (childType === 12) return getParentSelector();
  16697. }
  16698. /**
  16699. * @param {number} i Token's index number
  16700. * @returns {number} Length of the value
  16701. */
  16702. function checkSingleValue(i) {
  16703. var start = i;
  16704. var l = void 0;
  16705. var s = void 0;
  16706. var _i = void 0;
  16707. while (i < tokensLength) {
  16708. if (checkDeclDelim(i) || checkDelim(i)) break;
  16709. s = checkSC(i);
  16710. _i = i + s;
  16711. if (l = _checkValue(_i)) i += l + s;
  16712. if (!l || checkBlock(i - l)) break;
  16713. }
  16714. return i - start;
  16715. }
  16716. /**
  16717. * @returns {Array}
  16718. */
  16719. function getSingleValue() {
  16720. var type = NodeType.ValueType;
  16721. var token = tokens[pos];
  16722. var line = token.ln;
  16723. var column = token.col;
  16724. var content = [];
  16725. var _pos = void 0;
  16726. var s = void 0;
  16727. while (pos < tokensLength) {
  16728. s = checkSC(pos);
  16729. _pos = pos + s;
  16730. if (checkDeclDelim(_pos) || checkDelim(_pos)) break;
  16731. if (!_checkValue(_pos)) break;
  16732. if (s) content = content.concat(getSC());
  16733. content.push(_getValue());
  16734. if (checkBlock(_pos)) break;
  16735. }
  16736. return newNode(type, content, line, column);
  16737. }
  16738. /**
  16739. * Check if token is part of a variable
  16740. * @param {Number} i Token's index number
  16741. * @returns {Number} Length of the variable
  16742. */
  16743. function checkVariable(i) {
  16744. var start = i;
  16745. var l = void 0;
  16746. if (i >= tokensLength) return 0;
  16747. // Skip `$`.
  16748. if (tokens[i].type === TokenType.DollarSign) i++;else return 0;
  16749. if (l = checkIdent(i)) i += l;else return 0;
  16750. return i - start;
  16751. }
  16752. /**
  16753. * Get node with a variable
  16754. * @returns {Array} `['variable', ['ident', x]]` where `x` is
  16755. * a variable name.
  16756. */
  16757. function getVariable() {
  16758. var type = NodeType.VariableType;
  16759. var token = tokens[pos];
  16760. var line = token.ln;
  16761. var column = token.col;
  16762. // Skip `$`.
  16763. pos++;
  16764. var content = [getIdent()];
  16765. return newNode(type, content, line, column);
  16766. }
  16767. /**
  16768. * Check if token is part of a variables list (e.g. `$values...`).
  16769. * @param {Number} i Token's index number
  16770. * @returns {Number}
  16771. */
  16772. function checkVariablesList(i) {
  16773. var d = 0; // Number of dots
  16774. var l = void 0;
  16775. if (i >= tokensLength) return 0;
  16776. if (l = checkVariable(i)) i += l;else return 0;
  16777. while (i < tokensLength && tokens[i].type === TokenType.FullStop) {
  16778. d++;
  16779. i++;
  16780. }
  16781. return d === 3 ? l + d : 0;
  16782. }
  16783. /**
  16784. * Get node with a variables list
  16785. * @returns {Array} `['variableslist', ['variable', ['ident', x]]]` where
  16786. * `x` is a variable name.
  16787. */
  16788. function getVariablesList() {
  16789. var type = NodeType.VariablesListType;
  16790. var token = tokens[pos];
  16791. var line = token.ln;
  16792. var column = token.col;
  16793. var content = [getVariable()];
  16794. var end = getLastPosition(content, line, column, 3);
  16795. // Skip `...`.
  16796. pos += 3;
  16797. return newNode(type, content, line, column, end);
  16798. }
  16799. /**
  16800. * Check if token is part of a hexadecimal number (e.g. `#fff`) inside
  16801. * some value
  16802. * @param {Number} i Token's index number
  16803. * @returns {Number}
  16804. */
  16805. function checkVhash(i) {
  16806. var start = i;
  16807. var l = void 0;
  16808. if (i >= tokensLength) return 0;
  16809. // Skip `#`.
  16810. if (tokens[i].type === TokenType.NumberSign) i++;else return 0;
  16811. if (l = checkNmName2(i)) i += l;else return 0;
  16812. return i - start;
  16813. }
  16814. /**
  16815. * Get node with a hexadecimal number (e.g. `#fff`) inside some value
  16816. * @returns {Array} `['vhash', x]` where `x` is a hexadecimal number
  16817. * converted to string (without `#`, e.g. `'fff'`).
  16818. */
  16819. function getVhash() {
  16820. var type = NodeType.VhashType;
  16821. var token = tokens[pos];
  16822. var line = token.ln;
  16823. var column = token.col;
  16824. // Skip `#`.
  16825. pos++;
  16826. var content = getNmName2();
  16827. var end = getLastPosition(content, line, column + 1);
  16828. return newNode(type, content, line, column, end);
  16829. }
  16830. function checkSelectorsGroup(i) {
  16831. if (i >= tokensLength) return 0;
  16832. var start = i;
  16833. var l = void 0;
  16834. var selectorCounter = 0;
  16835. var delimCounter = 0;
  16836. if (l = checkSelector(i)) {
  16837. i += l;
  16838. selectorCounter++;
  16839. } else return 0;
  16840. while (i < tokensLength) {
  16841. var tempStart = i;
  16842. var tempIndex = i;
  16843. var tempLength = void 0;
  16844. var spaceBefore = checkSC(tempIndex);
  16845. if (tempLength = checkDelim(tempIndex + spaceBefore)) {
  16846. tempIndex += spaceBefore + tempLength;
  16847. delimCounter++;
  16848. if (tempLength = checkSC(tempIndex)) tempIndex += tempLength;
  16849. if (tempLength = checkSelector(tempIndex)) {
  16850. tempIndex += tempLength;
  16851. selectorCounter++;
  16852. }
  16853. } else break;
  16854. i += tempIndex - tempStart;
  16855. }
  16856. tokens[start].selectorsGroupEnd = i;
  16857. tokens[start].selectorsGroupSelectorCount = selectorCounter;
  16858. tokens[start].selectorsGroupDelimCount = delimCounter;
  16859. return i - start;
  16860. }
  16861. function getSelectorsGroup() {
  16862. var selectorsGroup = [];
  16863. var selectorCounter = 0;
  16864. var delimCounter = 0;
  16865. var selectorsGroupEnd = tokens[pos].selectorsGroupEnd;
  16866. var selectorCount = tokens[pos].selectorsGroupSelectorCount;
  16867. var delimCount = tokens[pos].selectorsGroupDelimCount;
  16868. selectorsGroup.push(getSelector());
  16869. selectorCounter++;
  16870. while (pos < selectorsGroupEnd) {
  16871. if (delimCounter < delimCount) {
  16872. selectorsGroup = selectorsGroup.concat(getSC());
  16873. selectorsGroup = selectorsGroup.concat(getDelim());
  16874. delimCounter++;
  16875. selectorsGroup = selectorsGroup.concat(getSC());
  16876. if (selectorCounter < selectorCount) {
  16877. selectorsGroup = selectorsGroup.concat(getSelector());
  16878. selectorCounter++;
  16879. }
  16880. }
  16881. }
  16882. return selectorsGroup;
  16883. }
  16884. function checkSelector(i) {
  16885. var l = void 0;
  16886. if (l = checkSelector1(i)) tokens[i].selectorType = 1;else if (l = checkSelector2(i)) tokens[i].selectorType = 2;
  16887. return l;
  16888. }
  16889. function getSelector() {
  16890. var selectorType = tokens[pos].selectorType;
  16891. if (selectorType === 1) return getSelector1();else return getSelector2();
  16892. }
  16893. /**
  16894. * Checks for selector which starts with a compound selector.
  16895. */
  16896. function checkSelector1(i) {
  16897. if (i >= tokensLength) return 0;
  16898. var start = i;
  16899. var l = void 0;
  16900. if (l = checkCompoundSelector(i)) i += l;else return 0;
  16901. while (i < tokensLength) {
  16902. var space = checkSC(i);
  16903. var comma = checkCombinator(i + space);
  16904. if (!space && !comma) break;
  16905. if (comma) {
  16906. i += space + comma;
  16907. space = checkSC(i);
  16908. }
  16909. if (l = checkCompoundSelector(i + space)) i += space + l;else break;
  16910. }
  16911. tokens[start].selectorEnd = i;
  16912. return i - start;
  16913. }
  16914. function getSelector1() {
  16915. var type = NodeType.SelectorType;
  16916. var token = tokens[pos];
  16917. var line = token.ln;
  16918. var column = token.col;
  16919. var selectorEnd = token.selectorEnd;
  16920. var content = getCompoundSelector();
  16921. while (pos < selectorEnd) {
  16922. if (checkSC(pos)) content = content.concat(getSC());else if (checkCombinator(pos)) content.push(getCombinator());else if (checkCompoundSelector(pos)) content = content.concat(getCompoundSelector());
  16923. }
  16924. return newNode(type, content, line, column);
  16925. }
  16926. /**
  16927. * Checks for a selector that starts with a combinator.
  16928. */
  16929. function checkSelector2(i) {
  16930. if (i >= tokensLength) return 0;
  16931. var start = i;
  16932. var l = void 0;
  16933. if (l = checkCombinator(i)) i += l;else return 0;
  16934. while (i < tokensLength) {
  16935. var spaceBefore = checkSC(i);
  16936. if (l = checkCompoundSelector(i + spaceBefore)) i += spaceBefore + l;else break;
  16937. var spaceAfter = checkSC(i);
  16938. var comma = checkCombinator(i + spaceAfter);
  16939. if (!spaceAfter && !comma) break;
  16940. if (comma) {
  16941. i += spaceAfter + comma;
  16942. }
  16943. }
  16944. tokens[start].selectorEnd = i;
  16945. return i - start;
  16946. }
  16947. function getSelector2() {
  16948. var type = NodeType.SelectorType;
  16949. var token = tokens[pos];
  16950. var line = token.ln;
  16951. var column = token.col;
  16952. var selectorEnd = token.selectorEnd;
  16953. var content = [getCombinator()];
  16954. while (pos < selectorEnd) {
  16955. if (checkSC(pos)) content = content.concat(getSC());else if (checkCombinator(pos)) content.push(getCombinator());else if (checkCompoundSelector(pos)) content = content.concat(getCompoundSelector());
  16956. }
  16957. return newNode(type, content, line, column);
  16958. }
  16959. function checkCompoundSelector(i) {
  16960. var l = void 0;
  16961. if (l = checkCompoundSelector1(i)) {
  16962. tokens[i].compoundSelectorType = 1;
  16963. } else if (l = checkCompoundSelector2(i)) {
  16964. tokens[i].compoundSelectorType = 2;
  16965. }
  16966. return l;
  16967. }
  16968. function getCompoundSelector() {
  16969. var type = tokens[pos].compoundSelectorType;
  16970. if (type === 1) return getCompoundSelector1();
  16971. if (type === 2) return getCompoundSelector2();
  16972. }
  16973. /**
  16974. * Check for compound selectors that start with either a type selector,
  16975. * placeholder or parent selector with extension
  16976. * (1) `foo.bar`
  16977. * (2) `foo[attr=val]`
  16978. * (3) `foo:first-of-type`
  16979. * (4) `foo%bar`
  16980. * @param {number} i Token's index
  16981. * @return {number} Compound selector's length
  16982. */
  16983. function checkCompoundSelector1(i) {
  16984. if (i >= tokensLength) return 0;
  16985. var start = i;
  16986. var l = void 0;
  16987. if (l = checkUniversalSelector(i) || checkTypeSelector(i) || checkPlaceholder(i) || checkParentSelectorWithExtension(i)) i += l;else return 0;
  16988. while (i < tokensLength) {
  16989. var _l2 = checkShash(i) || checkClass(i) || checkAttributeSelector(i) || checkPseudo(i) || checkPlaceholder(i) || checkInterpolation(i);
  16990. if (_l2) i += _l2;else break;
  16991. }
  16992. tokens[start].compoundSelectorEnd = i;
  16993. return i - start;
  16994. }
  16995. /**
  16996. * @return {Array} An array of nodes that make up the compound selector
  16997. */
  16998. function getCompoundSelector1() {
  16999. var sequence = [];
  17000. var compoundSelectorEnd = tokens[pos].compoundSelectorEnd;
  17001. if (checkUniversalSelector(pos)) sequence.push(getUniversalSelector());else if (checkTypeSelector(pos)) sequence.push(getTypeSelector());else if (checkPlaceholder(pos)) sequence.push(getPlaceholder());else if (checkParentSelectorWithExtension(pos)) sequence = sequence.concat(getParentSelectorWithExtension());
  17002. while (pos < compoundSelectorEnd) {
  17003. if (checkShash(pos)) sequence.push(getShash());else if (checkClass(pos)) sequence.push(getClass());else if (checkAttributeSelector(pos)) sequence.push(getAttributeSelector());else if (checkPseudo(pos)) sequence.push(getPseudo());else if (checkPlaceholder(pos)) sequence.push(getPlaceholder());else if (checkInterpolation(pos)) sequence.push(getInterpolation());else break;
  17004. }
  17005. return sequence;
  17006. }
  17007. /**
  17008. * Check for all other compound selectors
  17009. * (1) `.foo.bar`
  17010. * (2) `.foo[attr=val]`
  17011. * (3) `.foo:first-of-type`
  17012. * (4) `.foo%bar`
  17013. * (5) `.foo#{$bar}`
  17014. * @param {number} i Token's index
  17015. * @return {number} Compound selector's length
  17016. */
  17017. function checkCompoundSelector2(i) {
  17018. if (i >= tokensLength) return 0;
  17019. var start = i;
  17020. while (i < tokensLength) {
  17021. var l = checkShash(i) || checkClass(i) || checkAttributeSelector(i) || checkPseudo(i) || checkPlaceholder(i) || checkInterpolation(i);
  17022. if (l) i += l;else break;
  17023. }
  17024. tokens[start].compoundSelectorEnd = i;
  17025. return i - start;
  17026. }
  17027. /**
  17028. * @return {Array} An array of nodes that make up the compound selector
  17029. */
  17030. function getCompoundSelector2() {
  17031. var sequence = [];
  17032. var compoundSelectorEnd = tokens[pos].compoundSelectorEnd;
  17033. while (pos < compoundSelectorEnd) {
  17034. if (checkShash(pos)) sequence.push(getShash());else if (checkClass(pos)) sequence.push(getClass());else if (checkAttributeSelector(pos)) sequence.push(getAttributeSelector());else if (checkPseudo(pos)) sequence.push(getPseudo());else if (checkPlaceholder(pos)) sequence.push(getPlaceholder());else if (checkInterpolation(pos)) sequence.push(getInterpolation());else break;
  17035. }
  17036. return sequence;
  17037. }
  17038. function checkUniversalSelector(i) {
  17039. if (i >= tokensLength) return 0;
  17040. var start = i;
  17041. var l = void 0;
  17042. if (l = checkNamePrefix(i)) i += l;
  17043. if (tokens[i].type === TokenType.Asterisk) i++;else return 0;
  17044. return i - start;
  17045. }
  17046. function getUniversalSelector() {
  17047. var type = NodeType.UniversalSelectorType;
  17048. var token = tokens[pos];
  17049. var line = token.ln;
  17050. var column = token.col;
  17051. var content = [];
  17052. var end = void 0;
  17053. if (checkNamePrefix(pos)) {
  17054. content.push(getNamePrefix());
  17055. end = getLastPosition(content, line, column, 1);
  17056. }
  17057. pos++;
  17058. return newNode(type, content, line, column, end);
  17059. }
  17060. /**
  17061. * Check if token is part of a type selector
  17062. * @param {number} i Token's index
  17063. * @return {number} Type selector's length
  17064. */
  17065. function checkTypeSelector(i) {
  17066. if (i >= tokensLength) return 0;
  17067. var start = i;
  17068. var l = void 0;
  17069. if (l = checkNamePrefix(i)) i += l;
  17070. if (l = checkIdentOrInterpolation(i)) i += l;else return 0;
  17071. return i - start;
  17072. }
  17073. /**
  17074. * Get type selector node
  17075. * @return {Node}
  17076. */
  17077. function getTypeSelector() {
  17078. var type = NodeType.TypeSelectorType;
  17079. var token = tokens[pos];
  17080. var line = token.ln;
  17081. var column = token.col;
  17082. var content = [];
  17083. if (checkNamePrefix(pos)) content.push(getNamePrefix());
  17084. content = content.concat(getIdentOrInterpolation());
  17085. return newNode(type, content, line, column);
  17086. }
  17087. function checkAttributeSelector(i) {
  17088. var l = void 0;
  17089. if (l = checkAttributeSelector1(i)) tokens[i].attributeSelectorType = 1;else if (l = checkAttributeSelector2(i)) tokens[i].attributeSelectorType = 2;
  17090. return l;
  17091. }
  17092. function getAttributeSelector() {
  17093. var type = tokens[pos].attributeSelectorType;
  17094. if (type === 1) return getAttributeSelector1();else return getAttributeSelector2();
  17095. }
  17096. /**
  17097. * (1) `[panda=nani]`
  17098. * (2) `[panda='nani']`
  17099. * (3) `[panda='nani' i]`
  17100. *
  17101. */
  17102. function checkAttributeSelector1(i) {
  17103. var start = i;
  17104. if (tokens[i].type === TokenType.LeftSquareBracket) i++;else return 0;
  17105. var l = void 0;
  17106. if (l = checkSC(i)) i += l;
  17107. if (l = checkAttributeName(i)) i += l;else return 0;
  17108. if (l = checkSC(i)) i += l;
  17109. if (l = checkAttributeMatch(i)) i += l;else return 0;
  17110. if (l = checkSC(i)) i += l;
  17111. if (l = checkAttributeValue(i)) i += l;else return 0;
  17112. if (l = checkSC(i)) i += l;
  17113. if (l = checkAttributeFlags(i)) {
  17114. i += l;
  17115. if (l = checkSC(i)) i += l;
  17116. }
  17117. if (tokens[i].type === TokenType.RightSquareBracket) i++;else return 0;
  17118. return i - start;
  17119. }
  17120. function getAttributeSelector1() {
  17121. var type = NodeType.AttributeSelectorType;
  17122. var token = tokens[pos];
  17123. var line = token.ln;
  17124. var column = token.col;
  17125. var content = [];
  17126. // Skip `[`.
  17127. pos++;
  17128. content = content.concat(getSC(), getAttributeName(), getSC(), getAttributeMatch(), getSC(), getAttributeValue(), getSC());
  17129. if (checkAttributeFlags(pos)) {
  17130. content.push(getAttributeFlags());
  17131. content = content.concat(getSC());
  17132. }
  17133. // Skip `]`.
  17134. pos++;
  17135. var end = getLastPosition(content, line, column, 1);
  17136. return newNode(type, content, line, column, end);
  17137. }
  17138. /**
  17139. * (1) `[panda]`
  17140. */
  17141. function checkAttributeSelector2(i) {
  17142. var start = i;
  17143. if (tokens[i].type === TokenType.LeftSquareBracket) i++;else return 0;
  17144. var l = void 0;
  17145. if (l = checkSC(i)) i += l;
  17146. if (l = checkAttributeName(i)) i += l;else return 0;
  17147. if (l = checkSC(i)) i += l;
  17148. if (tokens[i].type === TokenType.RightSquareBracket) i++;else return 0;
  17149. return i - start;
  17150. }
  17151. function getAttributeSelector2() {
  17152. var type = NodeType.AttributeSelectorType;
  17153. var token = tokens[pos];
  17154. var line = token.ln;
  17155. var column = token.col;
  17156. var content = [];
  17157. // Skip `[`.
  17158. pos++;
  17159. content = content.concat(getSC(), getAttributeName(), getSC());
  17160. // Skip `]`.
  17161. pos++;
  17162. var end = getLastPosition(content, line, column, 1);
  17163. return newNode(type, content, line, column, end);
  17164. }
  17165. function checkAttributeName(i) {
  17166. var start = i;
  17167. var l = void 0;
  17168. if (l = checkNamePrefix(i)) i += l;
  17169. if (l = checkIdentOrInterpolation(i)) i += l;else return 0;
  17170. return i - start;
  17171. }
  17172. function getAttributeName() {
  17173. var type = NodeType.AttributeNameType;
  17174. var token = tokens[pos];
  17175. var line = token.ln;
  17176. var column = token.col;
  17177. var content = [];
  17178. if (checkNamePrefix(pos)) content.push(getNamePrefix());
  17179. content = content.concat(getIdentOrInterpolation());
  17180. return newNode(type, content, line, column);
  17181. }
  17182. function checkAttributeMatch(i) {
  17183. var l = void 0;
  17184. if (l = checkAttributeMatch1(i)) tokens[i].attributeMatchType = 1;else if (l = checkAttributeMatch2(i)) tokens[i].attributeMatchType = 2;
  17185. return l;
  17186. }
  17187. function getAttributeMatch() {
  17188. var type = tokens[pos].attributeMatchType;
  17189. if (type === 1) return getAttributeMatch1();else return getAttributeMatch2();
  17190. }
  17191. function checkAttributeMatch1(i) {
  17192. var start = i;
  17193. var type = tokens[i].type;
  17194. if (type === TokenType.Tilde || type === TokenType.VerticalLine || type === TokenType.CircumflexAccent || type === TokenType.DollarSign || type === TokenType.Asterisk) i++;else return 0;
  17195. if (tokens[i].type === TokenType.EqualsSign) i++;else return 0;
  17196. return i - start;
  17197. }
  17198. function getAttributeMatch1() {
  17199. var type = NodeType.AttributeMatchType;
  17200. var token = tokens[pos];
  17201. var line = token.ln;
  17202. var column = token.col;
  17203. var content = tokens[pos].value + tokens[pos + 1].value;
  17204. pos += 2;
  17205. return newNode(type, content, line, column);
  17206. }
  17207. function checkAttributeMatch2(i) {
  17208. if (tokens[i].type === TokenType.EqualsSign) return 1;else return 0;
  17209. }
  17210. function getAttributeMatch2() {
  17211. var type = NodeType.AttributeMatchType;
  17212. var token = tokens[pos];
  17213. var line = token.ln;
  17214. var column = token.col;
  17215. var content = '=';
  17216. pos++;
  17217. return newNode(type, content, line, column);
  17218. }
  17219. function checkAttributeValue(i) {
  17220. return checkString(i) || checkIdentOrInterpolation(i);
  17221. }
  17222. function getAttributeValue() {
  17223. var type = NodeType.AttributeValueType;
  17224. var token = tokens[pos];
  17225. var line = token.ln;
  17226. var column = token.col;
  17227. var content = [];
  17228. if (checkString(pos)) content.push(getString());else content = content.concat(getIdentOrInterpolation());
  17229. return newNode(type, content, line, column);
  17230. }
  17231. function checkAttributeFlags(i) {
  17232. return checkIdentOrInterpolation(i);
  17233. }
  17234. function getAttributeFlags() {
  17235. var type = NodeType.AttributeFlagsType;
  17236. var token = tokens[pos];
  17237. var line = token.ln;
  17238. var column = token.col;
  17239. var content = getIdentOrInterpolation();
  17240. return newNode(type, content, line, column);
  17241. }
  17242. function checkNamePrefix(i) {
  17243. if (i >= tokensLength) return 0;
  17244. var l = void 0;
  17245. if (l = checkNamePrefix1(i)) tokens[i].namePrefixType = 1;else if (l = checkNamePrefix2(i)) tokens[i].namePrefixType = 2;
  17246. return l;
  17247. }
  17248. function getNamePrefix() {
  17249. var type = tokens[pos].namePrefixType;
  17250. if (type === 1) return getNamePrefix1();else return getNamePrefix2();
  17251. }
  17252. /**
  17253. * (1) `panda|`
  17254. * (2) `panda<comment>|`
  17255. */
  17256. function checkNamePrefix1(i) {
  17257. var start = i;
  17258. var l = void 0;
  17259. if (l = checkNamespacePrefix(i)) i += l;else return 0;
  17260. if (l = checkCommentML(i)) i += l;
  17261. if (l = checkNamespaceSeparator(i)) i += l;else return 0;
  17262. return i - start;
  17263. }
  17264. function getNamePrefix1() {
  17265. var type = NodeType.NamePrefixType;
  17266. var token = tokens[pos];
  17267. var line = token.ln;
  17268. var column = token.col;
  17269. var content = [];
  17270. content.push(getNamespacePrefix());
  17271. if (checkCommentML(pos)) content.push(getCommentML());
  17272. content.push(getNamespaceSeparator());
  17273. return newNode(type, content, line, column);
  17274. }
  17275. /**
  17276. * (1) `|`
  17277. */
  17278. function checkNamePrefix2(i) {
  17279. return checkNamespaceSeparator(i);
  17280. }
  17281. function getNamePrefix2() {
  17282. var type = NodeType.NamePrefixType;
  17283. var token = tokens[pos];
  17284. var line = token.ln;
  17285. var column = token.col;
  17286. var content = [getNamespaceSeparator()];
  17287. return newNode(type, content, line, column);
  17288. }
  17289. /**
  17290. * (1) `*`
  17291. * (2) `panda`
  17292. */
  17293. function checkNamespacePrefix(i) {
  17294. if (i >= tokensLength) return 0;
  17295. var l = void 0;
  17296. if (tokens[i].type === TokenType.Asterisk) return 1;else if (l = checkIdentOrInterpolation(i)) return l;else return 0;
  17297. }
  17298. function getNamespacePrefix() {
  17299. var type = NodeType.NamespacePrefixType;
  17300. var token = tokens[pos];
  17301. var line = token.ln;
  17302. var column = token.col;
  17303. var content = [];
  17304. if (token.type === TokenType.Asterisk) {
  17305. var asteriskNode = newNode(NodeType.IdentType, '*', line, column);
  17306. content.push(asteriskNode);
  17307. pos++;
  17308. } else if (checkIdentOrInterpolation(pos)) content = content.concat(getIdentOrInterpolation());
  17309. return newNode(type, content, line, column);
  17310. }
  17311. /**
  17312. * (1) `|`
  17313. */
  17314. function checkNamespaceSeparator(i) {
  17315. if (i >= tokensLength) return 0;
  17316. if (tokens[i].type !== TokenType.VerticalLine) return 0;
  17317. // Return false if `|=` - [attr|=value]
  17318. if (tokens[i + 1] && tokens[i + 1].type === TokenType.EqualsSign) return 0;
  17319. return 1;
  17320. }
  17321. function getNamespaceSeparator() {
  17322. var type = NodeType.NamespaceSeparatorType;
  17323. var token = tokens[pos];
  17324. var line = token.ln;
  17325. var column = token.col;
  17326. var content = '|';
  17327. pos++;
  17328. return newNode(type, content, line, column);
  17329. }
  17330. module.exports = function (_tokens, context) {
  17331. tokens = _tokens;
  17332. tokensLength = tokens.length;
  17333. pos = 0;
  17334. return contexts[context]();
  17335. };
  17336. /***/ }),
  17337. /* 28 */
  17338. /***/ (function(module, exports, __webpack_require__) {
  17339. 'use strict';
  17340. module.exports = function (css, tabSize) {
  17341. var TokenType = __webpack_require__(13);
  17342. var tokens = [];
  17343. var urlMode = false;
  17344. var c = void 0; // Current character
  17345. var cn = void 0; // Next character
  17346. var pos = 0;
  17347. var tn = 0;
  17348. var ln = 1;
  17349. var col = 1;
  17350. var Punctuation = {
  17351. ' ': TokenType.Space,
  17352. '\n': TokenType.Newline,
  17353. '\r': TokenType.Newline,
  17354. '\t': TokenType.Tab,
  17355. '!': TokenType.ExclamationMark,
  17356. '"': TokenType.QuotationMark,
  17357. '#': TokenType.NumberSign,
  17358. '$': TokenType.DollarSign,
  17359. '%': TokenType.PercentSign,
  17360. '&': TokenType.Ampersand,
  17361. '\'': TokenType.Apostrophe,
  17362. '(': TokenType.LeftParenthesis,
  17363. ')': TokenType.RightParenthesis,
  17364. '*': TokenType.Asterisk,
  17365. '+': TokenType.PlusSign,
  17366. ',': TokenType.Comma,
  17367. '-': TokenType.HyphenMinus,
  17368. '.': TokenType.FullStop,
  17369. '/': TokenType.Solidus,
  17370. ':': TokenType.Colon,
  17371. ';': TokenType.Semicolon,
  17372. '<': TokenType.LessThanSign,
  17373. '=': TokenType.EqualsSign,
  17374. '==': TokenType.EqualitySign,
  17375. '!=': TokenType.InequalitySign,
  17376. '>': TokenType.GreaterThanSign,
  17377. '?': TokenType.QuestionMark,
  17378. '@': TokenType.CommercialAt,
  17379. '[': TokenType.LeftSquareBracket,
  17380. ']': TokenType.RightSquareBracket,
  17381. '^': TokenType.CircumflexAccent,
  17382. '_': TokenType.LowLine,
  17383. '{': TokenType.LeftCurlyBracket,
  17384. '|': TokenType.VerticalLine,
  17385. '}': TokenType.RightCurlyBracket,
  17386. '~': TokenType.Tilde,
  17387. '`': TokenType.Backtick
  17388. };
  17389. /**
  17390. * Add a token to the token list
  17391. * @param {string} type
  17392. * @param {string} value
  17393. */
  17394. function pushToken(type, value, column) {
  17395. tokens.push({
  17396. tn: tn++,
  17397. ln: ln,
  17398. col: column,
  17399. type: type,
  17400. value: value
  17401. });
  17402. }
  17403. /**
  17404. * Check if a character is a decimal digit
  17405. * @param {string} c Character
  17406. * @returns {boolean}
  17407. */
  17408. function isDecimalDigit(c) {
  17409. return '0123456789'.indexOf(c) >= 0;
  17410. }
  17411. /**
  17412. * Parse spaces
  17413. * @param {string} css Unparsed part of CSS string
  17414. */
  17415. function parseSpaces(css) {
  17416. var start = pos;
  17417. // Read the string until we meet a non-space character:
  17418. for (; pos < css.length; pos++) {
  17419. if (css.charAt(pos) !== ' ') break;
  17420. }
  17421. // Add a substring containing only spaces to tokens:
  17422. pushToken(TokenType.Space, css.substring(start, pos--), col);
  17423. col += pos - start;
  17424. }
  17425. /**
  17426. * Parse a string within quotes
  17427. * @param {string} css Unparsed part of CSS string
  17428. * @param {string} q Quote (either `'` or `"`)
  17429. */
  17430. function parseString(css, q) {
  17431. var start = pos;
  17432. // Read the string until we meet a matching quote:
  17433. for (pos++; pos < css.length; pos++) {
  17434. // Skip escaped quotes:
  17435. if (css.charAt(pos) === '\\') pos++;else if (css.charAt(pos) === q) break;
  17436. }
  17437. // Add the string (including quotes) to tokens:
  17438. var type = q === '"' ? TokenType.StringDQ : TokenType.StringSQ;
  17439. pushToken(type, css.substring(start, pos + 1), col);
  17440. col += pos - start;
  17441. }
  17442. /**
  17443. * Parse numbers
  17444. * @param {string} css Unparsed part of CSS string
  17445. */
  17446. function parseDecimalNumber(css) {
  17447. var start = pos;
  17448. // Read the string until we meet a character that's not a digit:
  17449. for (; pos < css.length; pos++) {
  17450. if (!isDecimalDigit(css.charAt(pos))) break;
  17451. }
  17452. // Add the number to tokens:
  17453. pushToken(TokenType.DecimalNumber, css.substring(start, pos--), col);
  17454. col += pos - start;
  17455. }
  17456. /**
  17457. * Parse identifier
  17458. * @param {string} css Unparsed part of CSS string
  17459. */
  17460. function parseIdentifier(css) {
  17461. var start = pos;
  17462. // Skip all opening slashes:
  17463. while (css.charAt(pos) === '/') {
  17464. pos++;
  17465. } // Read the string until we meet a punctuation mark:
  17466. for (; pos < css.length; pos++) {
  17467. // Skip all '\':
  17468. if (css.charAt(pos) === '\\') pos++;else if (css.charAt(pos) in Punctuation) break;
  17469. }
  17470. var ident = css.substring(start, pos--);
  17471. // Enter url mode if parsed substring is `url`:
  17472. if (!urlMode && ident === 'url' && css.charAt(pos + 1) === '(') {
  17473. urlMode = true;
  17474. }
  17475. // Add identifier to tokens:
  17476. pushToken(TokenType.Identifier, ident, col);
  17477. col += pos - start;
  17478. }
  17479. /**
  17480. * Parse equality sign
  17481. */
  17482. function parseEquality() {
  17483. pushToken(TokenType.EqualitySign, '==', col);
  17484. pos++;
  17485. col++;
  17486. }
  17487. /**
  17488. * Parse inequality sign
  17489. */
  17490. function parseInequality() {
  17491. pushToken(TokenType.InequalitySign, '!=', col);
  17492. pos++;
  17493. col++;
  17494. }
  17495. /**
  17496. * Parse a multiline comment
  17497. * @param {string} css Unparsed part of CSS string
  17498. */
  17499. function parseMLComment(css) {
  17500. var start = pos;
  17501. // Read the string until we meet `*/`.
  17502. // Since we already know first 2 characters (`/*`), start reading
  17503. // from `pos + 2`:
  17504. for (pos += 2; pos < css.length; pos++) {
  17505. if (css.charAt(pos) === '*' && css.charAt(pos + 1) === '/') {
  17506. pos++;
  17507. break;
  17508. }
  17509. }
  17510. // Add full comment (including `/*` and `*/`) to the list of tokens:
  17511. var comment = css.substring(start, pos + 1);
  17512. pushToken(TokenType.CommentML, comment, col);
  17513. var newlines = comment.split('\n');
  17514. if (newlines.length > 1) {
  17515. ln += newlines.length - 1;
  17516. col = newlines[newlines.length - 1].length;
  17517. } else {
  17518. col += pos - start;
  17519. }
  17520. }
  17521. /**
  17522. * Parse a single line comment
  17523. * @param {string} css Unparsed part of CSS string
  17524. */
  17525. function parseSLComment(css) {
  17526. var start = pos;
  17527. // Read the string until we meet line break.
  17528. // Since we already know first 2 characters (`//`), start reading
  17529. // from `pos + 2`:
  17530. for (pos += 2; pos < css.length; pos++) {
  17531. if (css.charAt(pos) === '\n' || css.charAt(pos) === '\r') {
  17532. break;
  17533. }
  17534. }
  17535. // Add comment (including `//` and line break) to the list of tokens:
  17536. pushToken(TokenType.CommentSL, css.substring(start, pos--), col);
  17537. col += pos - start;
  17538. }
  17539. /**
  17540. * Convert a CSS string to a list of tokens
  17541. * @param {string} css CSS string
  17542. * @returns {Array} List of tokens
  17543. * @private
  17544. */
  17545. function getTokens(css) {
  17546. // Parse string, character by character:
  17547. for (pos = 0; pos < css.length; col++, pos++) {
  17548. c = css.charAt(pos);
  17549. cn = css.charAt(pos + 1);
  17550. // If we meet `/*`, it's a start of a multiline comment.
  17551. // Parse following characters as a multiline comment:
  17552. if (c === '/' && cn === '*') {
  17553. parseMLComment(css);
  17554. }
  17555. // If we meet `//` and it is not a part of url:
  17556. else if (!urlMode && c === '/' && cn === '/') {
  17557. // If we're currently inside a block, treat `//` as a start
  17558. // of identifier. Else treat `//` as a start of a single-line
  17559. // comment:
  17560. parseSLComment(css);
  17561. }
  17562. // If current character is a double or single quote, it's a start
  17563. // of a string:
  17564. else if (c === '"' || c === "'") {
  17565. parseString(css, c);
  17566. }
  17567. // If current character is a space:
  17568. else if (c === ' ') {
  17569. parseSpaces(css);
  17570. }
  17571. // If current character is `=`, it must be combined with next `=`
  17572. else if (c === '=' && cn === '=') {
  17573. parseEquality(css);
  17574. }
  17575. // If we meet `!=`, this must be inequality
  17576. else if (c === '!' && cn === '=') {
  17577. parseInequality(css);
  17578. }
  17579. // If current character is a punctuation mark:
  17580. else if (c in Punctuation) {
  17581. // Check for CRLF here or just LF
  17582. if (c === '\r' && cn === '\n' || c === '\n') {
  17583. // If \r we know the next character is \n due to statement above
  17584. // so we push a CRLF token type to the token list and importantly
  17585. // skip the next character so as not to double count newlines or
  17586. // columns etc
  17587. if (c === '\r') {
  17588. pushToken(TokenType.Newline, '\r\n', col);
  17589. pos++; // If CRLF skip the next character and push crlf token
  17590. } else if (c === '\n') {
  17591. // If just a LF newline and not part of CRLF newline we can just
  17592. // push punctuation as usual
  17593. pushToken(Punctuation[c], c, col);
  17594. }
  17595. ln++; // Go to next line
  17596. col = 0; // Reset the column count
  17597. } else if (c !== '\r' && c !== '\n') {
  17598. // Handle all other punctuation and add to list of tokens
  17599. pushToken(Punctuation[c], c, col);
  17600. } // Go to next line
  17601. if (c === ')') urlMode = false; // Exit url mode
  17602. else if (c === '\t' && tabSize > 1) col += tabSize - 1;
  17603. }
  17604. // If current character is a decimal digit:
  17605. else if (isDecimalDigit(c)) {
  17606. parseDecimalNumber(css);
  17607. }
  17608. // If current character is anything else:
  17609. else {
  17610. parseIdentifier(css);
  17611. }
  17612. }
  17613. return tokens;
  17614. }
  17615. return getTokens(css);
  17616. };
  17617. /***/ }),
  17618. /* 29 */
  17619. /***/ (function(module, exports, __webpack_require__) {
  17620. 'use strict';
  17621. var Node = __webpack_require__(1);
  17622. var NodeTypes = __webpack_require__(15);
  17623. module.exports = function () {
  17624. return new Node({
  17625. type: NodeTypes.StylesheetType,
  17626. content: [],
  17627. start: [0, 0],
  17628. end: [0, 0]
  17629. });
  17630. };
  17631. /***/ })
  17632. /******/ ])
  17633. });
  17634. ;