csslint-worker.js 360 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930
  1. /*!
  2. CSSLint v1.0.4
  3. Copyright (c) 2016 Nicole Sullivan and Nicholas C. Zakas. All rights reserved.
  4. Permission is hereby granted, free of charge, to any person obtaining a copy
  5. of this software and associated documentation files (the 'Software'), to deal
  6. in the Software without restriction, including without limitation the rights
  7. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. copies of the Software, and to permit persons to whom the Software is
  9. furnished to do so, subject to the following conditions:
  10. The above copyright notice and this permission notice shall be included in
  11. all copies or substantial portions of the Software.
  12. THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  13. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  14. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  15. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  16. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  17. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  18. THE SOFTWARE.
  19. */
  20. var exports = exports || {};
  21. /*!
  22. Parser-Lib
  23. Copyright (c) 2009-2016 Nicholas C. Zakas. All rights reserved.
  24. Permission is hereby granted, free of charge, to any person obtaining a copy
  25. of this software and associated documentation files (the "Software"), to deal
  26. in the Software without restriction, including without limitation the rights
  27. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  28. copies of the Software, and to permit persons to whom the Software is
  29. furnished to do so, subject to the following conditions:
  30. The above copyright notice and this permission notice shall be included in
  31. all copies or substantial portions of the Software.
  32. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  33. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  34. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  35. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  36. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  37. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  38. THE SOFTWARE.
  39. */
  40. /* Version v1.1.0, Build time: 6-December-2016 10:31:29 */
  41. var parserlib = (function () {
  42. var require;
  43. require=(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
  44. "use strict";
  45. /* exported Colors */
  46. var Colors = module.exports = {
  47. __proto__ :null,
  48. aliceblue :"#f0f8ff",
  49. antiquewhite :"#faebd7",
  50. aqua :"#00ffff",
  51. aquamarine :"#7fffd4",
  52. azure :"#f0ffff",
  53. beige :"#f5f5dc",
  54. bisque :"#ffe4c4",
  55. black :"#000000",
  56. blanchedalmond :"#ffebcd",
  57. blue :"#0000ff",
  58. blueviolet :"#8a2be2",
  59. brown :"#a52a2a",
  60. burlywood :"#deb887",
  61. cadetblue :"#5f9ea0",
  62. chartreuse :"#7fff00",
  63. chocolate :"#d2691e",
  64. coral :"#ff7f50",
  65. cornflowerblue :"#6495ed",
  66. cornsilk :"#fff8dc",
  67. crimson :"#dc143c",
  68. cyan :"#00ffff",
  69. darkblue :"#00008b",
  70. darkcyan :"#008b8b",
  71. darkgoldenrod :"#b8860b",
  72. darkgray :"#a9a9a9",
  73. darkgrey :"#a9a9a9",
  74. darkgreen :"#006400",
  75. darkkhaki :"#bdb76b",
  76. darkmagenta :"#8b008b",
  77. darkolivegreen :"#556b2f",
  78. darkorange :"#ff8c00",
  79. darkorchid :"#9932cc",
  80. darkred :"#8b0000",
  81. darksalmon :"#e9967a",
  82. darkseagreen :"#8fbc8f",
  83. darkslateblue :"#483d8b",
  84. darkslategray :"#2f4f4f",
  85. darkslategrey :"#2f4f4f",
  86. darkturquoise :"#00ced1",
  87. darkviolet :"#9400d3",
  88. deeppink :"#ff1493",
  89. deepskyblue :"#00bfff",
  90. dimgray :"#696969",
  91. dimgrey :"#696969",
  92. dodgerblue :"#1e90ff",
  93. firebrick :"#b22222",
  94. floralwhite :"#fffaf0",
  95. forestgreen :"#228b22",
  96. fuchsia :"#ff00ff",
  97. gainsboro :"#dcdcdc",
  98. ghostwhite :"#f8f8ff",
  99. gold :"#ffd700",
  100. goldenrod :"#daa520",
  101. gray :"#808080",
  102. grey :"#808080",
  103. green :"#008000",
  104. greenyellow :"#adff2f",
  105. honeydew :"#f0fff0",
  106. hotpink :"#ff69b4",
  107. indianred :"#cd5c5c",
  108. indigo :"#4b0082",
  109. ivory :"#fffff0",
  110. khaki :"#f0e68c",
  111. lavender :"#e6e6fa",
  112. lavenderblush :"#fff0f5",
  113. lawngreen :"#7cfc00",
  114. lemonchiffon :"#fffacd",
  115. lightblue :"#add8e6",
  116. lightcoral :"#f08080",
  117. lightcyan :"#e0ffff",
  118. lightgoldenrodyellow :"#fafad2",
  119. lightgray :"#d3d3d3",
  120. lightgrey :"#d3d3d3",
  121. lightgreen :"#90ee90",
  122. lightpink :"#ffb6c1",
  123. lightsalmon :"#ffa07a",
  124. lightseagreen :"#20b2aa",
  125. lightskyblue :"#87cefa",
  126. lightslategray :"#778899",
  127. lightslategrey :"#778899",
  128. lightsteelblue :"#b0c4de",
  129. lightyellow :"#ffffe0",
  130. lime :"#00ff00",
  131. limegreen :"#32cd32",
  132. linen :"#faf0e6",
  133. magenta :"#ff00ff",
  134. maroon :"#800000",
  135. mediumaquamarine:"#66cdaa",
  136. mediumblue :"#0000cd",
  137. mediumorchid :"#ba55d3",
  138. mediumpurple :"#9370d8",
  139. mediumseagreen :"#3cb371",
  140. mediumslateblue :"#7b68ee",
  141. mediumspringgreen :"#00fa9a",
  142. mediumturquoise :"#48d1cc",
  143. mediumvioletred :"#c71585",
  144. midnightblue :"#191970",
  145. mintcream :"#f5fffa",
  146. mistyrose :"#ffe4e1",
  147. moccasin :"#ffe4b5",
  148. navajowhite :"#ffdead",
  149. navy :"#000080",
  150. oldlace :"#fdf5e6",
  151. olive :"#808000",
  152. olivedrab :"#6b8e23",
  153. orange :"#ffa500",
  154. orangered :"#ff4500",
  155. orchid :"#da70d6",
  156. palegoldenrod :"#eee8aa",
  157. palegreen :"#98fb98",
  158. paleturquoise :"#afeeee",
  159. palevioletred :"#d87093",
  160. papayawhip :"#ffefd5",
  161. peachpuff :"#ffdab9",
  162. peru :"#cd853f",
  163. pink :"#ffc0cb",
  164. plum :"#dda0dd",
  165. powderblue :"#b0e0e6",
  166. purple :"#800080",
  167. red :"#ff0000",
  168. rosybrown :"#bc8f8f",
  169. royalblue :"#4169e1",
  170. saddlebrown :"#8b4513",
  171. salmon :"#fa8072",
  172. sandybrown :"#f4a460",
  173. seagreen :"#2e8b57",
  174. seashell :"#fff5ee",
  175. sienna :"#a0522d",
  176. silver :"#c0c0c0",
  177. skyblue :"#87ceeb",
  178. slateblue :"#6a5acd",
  179. slategray :"#708090",
  180. slategrey :"#708090",
  181. snow :"#fffafa",
  182. springgreen :"#00ff7f",
  183. steelblue :"#4682b4",
  184. tan :"#d2b48c",
  185. teal :"#008080",
  186. thistle :"#d8bfd8",
  187. tomato :"#ff6347",
  188. turquoise :"#40e0d0",
  189. violet :"#ee82ee",
  190. wheat :"#f5deb3",
  191. white :"#ffffff",
  192. whitesmoke :"#f5f5f5",
  193. yellow :"#ffff00",
  194. yellowgreen :"#9acd32",
  195. //'currentColor' color keyword https://www.w3.org/TR/css3-color/#currentcolor
  196. currentColor :"The value of the 'color' property.",
  197. //CSS2 system colors https://www.w3.org/TR/css3-color/#css2-system
  198. activeBorder :"Active window border.",
  199. activecaption :"Active window caption.",
  200. appworkspace :"Background color of multiple document interface.",
  201. background :"Desktop background.",
  202. buttonface :"The face background color for 3-D elements that appear 3-D due to one layer of surrounding border.",
  203. buttonhighlight :"The color of the border facing the light source for 3-D elements that appear 3-D due to one layer of surrounding border.",
  204. buttonshadow :"The color of the border away from the light source for 3-D elements that appear 3-D due to one layer of surrounding border.",
  205. buttontext :"Text on push buttons.",
  206. captiontext :"Text in caption, size box, and scrollbar arrow box.",
  207. graytext :"Grayed (disabled) text. This color is set to #000 if the current display driver does not support a solid gray color.",
  208. greytext :"Greyed (disabled) text. This color is set to #000 if the current display driver does not support a solid grey color.",
  209. highlight :"Item(s) selected in a control.",
  210. highlighttext :"Text of item(s) selected in a control.",
  211. inactiveborder :"Inactive window border.",
  212. inactivecaption :"Inactive window caption.",
  213. inactivecaptiontext :"Color of text in an inactive caption.",
  214. infobackground :"Background color for tooltip controls.",
  215. infotext :"Text color for tooltip controls.",
  216. menu :"Menu background.",
  217. menutext :"Text in menus.",
  218. scrollbar :"Scroll bar gray area.",
  219. threeddarkshadow :"The color of the darker (generally outer) of the two borders away from the light source for 3-D elements that appear 3-D due to two concentric layers of surrounding border.",
  220. threedface :"The face background color for 3-D elements that appear 3-D due to two concentric layers of surrounding border.",
  221. threedhighlight :"The color of the lighter (generally outer) of the two borders facing the light source for 3-D elements that appear 3-D due to two concentric layers of surrounding border.",
  222. threedlightshadow :"The color of the darker (generally inner) of the two borders facing the light source for 3-D elements that appear 3-D due to two concentric layers of surrounding border.",
  223. threedshadow :"The color of the lighter (generally inner) of the two borders away from the light source for 3-D elements that appear 3-D due to two concentric layers of surrounding border.",
  224. window :"Window background.",
  225. windowframe :"Window frame.",
  226. windowtext :"Text in windows."
  227. };
  228. },{}],2:[function(require,module,exports){
  229. "use strict";
  230. module.exports = Combinator;
  231. var SyntaxUnit = require("../util/SyntaxUnit");
  232. var Parser = require("./Parser");
  233. /**
  234. * Represents a selector combinator (whitespace, +, >).
  235. * @namespace parserlib.css
  236. * @class Combinator
  237. * @extends parserlib.util.SyntaxUnit
  238. * @constructor
  239. * @param {String} text The text representation of the unit.
  240. * @param {int} line The line of text on which the unit resides.
  241. * @param {int} col The column of text on which the unit resides.
  242. */
  243. function Combinator(text, line, col) {
  244. SyntaxUnit.call(this, text, line, col, Parser.COMBINATOR_TYPE);
  245. /**
  246. * The type of modifier.
  247. * @type String
  248. * @property type
  249. */
  250. this.type = "unknown";
  251. //pretty simple
  252. if (/^\s+$/.test(text)) {
  253. this.type = "descendant";
  254. } else if (text === ">") {
  255. this.type = "child";
  256. } else if (text === "+") {
  257. this.type = "adjacent-sibling";
  258. } else if (text === "~") {
  259. this.type = "sibling";
  260. }
  261. }
  262. Combinator.prototype = new SyntaxUnit();
  263. Combinator.prototype.constructor = Combinator;
  264. },{"../util/SyntaxUnit":26,"./Parser":6}],3:[function(require,module,exports){
  265. "use strict";
  266. module.exports = Matcher;
  267. var StringReader = require("../util/StringReader");
  268. var SyntaxError = require("../util/SyntaxError");
  269. /**
  270. * This class implements a combinator library for matcher functions.
  271. * The combinators are described at:
  272. * https://developer.mozilla.org/en-US/docs/Web/CSS/Value_definition_syntax#Component_value_combinators
  273. */
  274. function Matcher(matchFunc, toString) {
  275. this.match = function(expression) {
  276. // Save/restore marks to ensure that failed matches always restore
  277. // the original location in the expression.
  278. var result;
  279. expression.mark();
  280. result = matchFunc(expression);
  281. if (result) {
  282. expression.drop();
  283. } else {
  284. expression.restore();
  285. }
  286. return result;
  287. };
  288. this.toString = typeof toString === "function" ? toString : function() {
  289. return toString;
  290. };
  291. }
  292. /** Precedence table of combinators. */
  293. Matcher.prec = {
  294. MOD: 5,
  295. SEQ: 4,
  296. ANDAND: 3,
  297. OROR: 2,
  298. ALT: 1
  299. };
  300. /** Simple recursive-descent grammar to build matchers from strings. */
  301. Matcher.parse = function(str) {
  302. var reader, eat, expr, oror, andand, seq, mod, term, result;
  303. reader = new StringReader(str);
  304. eat = function(matcher) {
  305. var result = reader.readMatch(matcher);
  306. if (result === null) {
  307. throw new SyntaxError(
  308. "Expected "+matcher, reader.getLine(), reader.getCol());
  309. }
  310. return result;
  311. };
  312. expr = function() {
  313. // expr = oror (" | " oror)*
  314. var m = [ oror() ];
  315. while (reader.readMatch(" | ") !== null) {
  316. m.push(oror());
  317. }
  318. return m.length === 1 ? m[0] : Matcher.alt.apply(Matcher, m);
  319. };
  320. oror = function() {
  321. // oror = andand ( " || " andand)*
  322. var m = [ andand() ];
  323. while (reader.readMatch(" || ") !== null) {
  324. m.push(andand());
  325. }
  326. return m.length === 1 ? m[0] : Matcher.oror.apply(Matcher, m);
  327. };
  328. andand = function() {
  329. // andand = seq ( " && " seq)*
  330. var m = [ seq() ];
  331. while (reader.readMatch(" && ") !== null) {
  332. m.push(seq());
  333. }
  334. return m.length === 1 ? m[0] : Matcher.andand.apply(Matcher, m);
  335. };
  336. seq = function() {
  337. // seq = mod ( " " mod)*
  338. var m = [ mod() ];
  339. while (reader.readMatch(/^ (?![&|\]])/) !== null) {
  340. m.push(mod());
  341. }
  342. return m.length === 1 ? m[0] : Matcher.seq.apply(Matcher, m);
  343. };
  344. mod = function() {
  345. // mod = term ( "?" | "*" | "+" | "#" | "{<num>,<num>}" )?
  346. var m = term();
  347. if (reader.readMatch("?") !== null) {
  348. return m.question();
  349. } else if (reader.readMatch("*") !== null) {
  350. return m.star();
  351. } else if (reader.readMatch("+") !== null) {
  352. return m.plus();
  353. } else if (reader.readMatch("#") !== null) {
  354. return m.hash();
  355. } else if (reader.readMatch(/^\{\s*/) !== null) {
  356. var min = eat(/^\d+/);
  357. eat(/^\s*,\s*/);
  358. var max = eat(/^\d+/);
  359. eat(/^\s*\}/);
  360. return m.braces(+min, +max);
  361. }
  362. return m;
  363. };
  364. term = function() {
  365. // term = <nt> | literal | "[ " expression " ]"
  366. if (reader.readMatch("[ ") !== null) {
  367. var m = expr();
  368. eat(" ]");
  369. return m;
  370. }
  371. return Matcher.fromType(eat(/^[^ ?*+#{]+/));
  372. };
  373. result = expr();
  374. if (!reader.eof()) {
  375. throw new SyntaxError(
  376. "Expected end of string", reader.getLine(), reader.getCol());
  377. }
  378. return result;
  379. };
  380. /**
  381. * Convert a string to a matcher (parsing simple alternations),
  382. * or do nothing if the argument is already a matcher.
  383. */
  384. Matcher.cast = function(m) {
  385. if (m instanceof Matcher) {
  386. return m;
  387. }
  388. return Matcher.parse(m);
  389. };
  390. /**
  391. * Create a matcher for a single type.
  392. */
  393. Matcher.fromType = function(type) {
  394. // Late require of ValidationTypes to break a dependency cycle.
  395. var ValidationTypes = require("./ValidationTypes");
  396. return new Matcher(function(expression) {
  397. return expression.hasNext() && ValidationTypes.isType(expression, type);
  398. }, type);
  399. };
  400. /**
  401. * Create a matcher for one or more juxtaposed words, which all must
  402. * occur, in the given order.
  403. */
  404. Matcher.seq = function() {
  405. var ms = Array.prototype.slice.call(arguments).map(Matcher.cast);
  406. if (ms.length === 1) {
  407. return ms[0];
  408. }
  409. return new Matcher(function(expression) {
  410. var i, result = true;
  411. for (i = 0; result && i < ms.length; i++) {
  412. result = ms[i].match(expression);
  413. }
  414. return result;
  415. }, function(prec) {
  416. var p = Matcher.prec.SEQ;
  417. var s = ms.map(function(m) {
  418. return m.toString(p);
  419. }).join(" ");
  420. if (prec > p) {
  421. s = "[ " + s + " ]";
  422. }
  423. return s;
  424. });
  425. };
  426. /**
  427. * Create a matcher for one or more alternatives, where exactly one
  428. * must occur.
  429. */
  430. Matcher.alt = function() {
  431. var ms = Array.prototype.slice.call(arguments).map(Matcher.cast);
  432. if (ms.length === 1) {
  433. return ms[0];
  434. }
  435. return new Matcher(function(expression) {
  436. var i, result = false;
  437. for (i = 0; !result && i < ms.length; i++) {
  438. result = ms[i].match(expression);
  439. }
  440. return result;
  441. }, function(prec) {
  442. var p = Matcher.prec.ALT;
  443. var s = ms.map(function(m) {
  444. return m.toString(p);
  445. }).join(" | ");
  446. if (prec > p) {
  447. s = "[ " + s + " ]";
  448. }
  449. return s;
  450. });
  451. };
  452. /**
  453. * Create a matcher for two or more options. This implements the
  454. * double bar (||) and double ampersand (&&) operators, as well as
  455. * variants of && where some of the alternatives are optional.
  456. * This will backtrack through even successful matches to try to
  457. * maximize the number of items matched.
  458. */
  459. Matcher.many = function(required) {
  460. var ms = Array.prototype.slice.call(arguments, 1).reduce(function(acc, v) {
  461. if (v.expand) {
  462. // Insert all of the options for the given complex rule as
  463. // individual options.
  464. var ValidationTypes = require("./ValidationTypes");
  465. acc.push.apply(acc, ValidationTypes.complex[v.expand].options);
  466. } else {
  467. acc.push(Matcher.cast(v));
  468. }
  469. return acc;
  470. }, []);
  471. if (required === true) {
  472. required = ms.map(function() {
  473. return true;
  474. });
  475. }
  476. var result = new Matcher(function(expression) {
  477. var seen = [], max = 0, pass = 0;
  478. var success = function(matchCount) {
  479. if (pass === 0) {
  480. max = Math.max(matchCount, max);
  481. return matchCount === ms.length;
  482. } else {
  483. return matchCount === max;
  484. }
  485. };
  486. var tryMatch = function(matchCount) {
  487. for (var i = 0; i < ms.length; i++) {
  488. if (seen[i]) {
  489. continue;
  490. }
  491. expression.mark();
  492. if (ms[i].match(expression)) {
  493. seen[i] = true;
  494. // Increase matchCount iff this was a required element
  495. // (or if all the elements are optional)
  496. if (tryMatch(matchCount + ((required === false || required[i]) ? 1 : 0))) {
  497. expression.drop();
  498. return true;
  499. }
  500. // Backtrack: try *not* matching using this rule, and
  501. // let's see if it leads to a better overall match.
  502. expression.restore();
  503. seen[i] = false;
  504. } else {
  505. expression.drop();
  506. }
  507. }
  508. return success(matchCount);
  509. };
  510. if (!tryMatch(0)) {
  511. // Couldn't get a complete match, retrace our steps to make the
  512. // match with the maximum # of required elements.
  513. pass++;
  514. tryMatch(0);
  515. }
  516. if (required === false) {
  517. return max > 0;
  518. }
  519. // Use finer-grained specification of which matchers are required.
  520. for (var i = 0; i < ms.length; i++) {
  521. if (required[i] && !seen[i]) {
  522. return false;
  523. }
  524. }
  525. return true;
  526. }, function(prec) {
  527. var p = required === false ? Matcher.prec.OROR : Matcher.prec.ANDAND;
  528. var s = ms.map(function(m, i) {
  529. if (required !== false && !required[i]) {
  530. return m.toString(Matcher.prec.MOD) + "?";
  531. }
  532. return m.toString(p);
  533. }).join(required === false ? " || " : " && ");
  534. if (prec > p) {
  535. s = "[ " + s + " ]";
  536. }
  537. return s;
  538. });
  539. result.options = ms;
  540. return result;
  541. };
  542. /**
  543. * Create a matcher for two or more options, where all options are
  544. * mandatory but they may appear in any order.
  545. */
  546. Matcher.andand = function() {
  547. var args = Array.prototype.slice.call(arguments);
  548. args.unshift(true);
  549. return Matcher.many.apply(Matcher, args);
  550. };
  551. /**
  552. * Create a matcher for two or more options, where options are
  553. * optional and may appear in any order, but at least one must be
  554. * present.
  555. */
  556. Matcher.oror = function() {
  557. var args = Array.prototype.slice.call(arguments);
  558. args.unshift(false);
  559. return Matcher.many.apply(Matcher, args);
  560. };
  561. /** Instance methods on Matchers. */
  562. Matcher.prototype = {
  563. constructor: Matcher,
  564. // These are expected to be overridden in every instance.
  565. match: function() { throw new Error("unimplemented"); },
  566. toString: function() { throw new Error("unimplemented"); },
  567. // This returns a standalone function to do the matching.
  568. func: function() { return this.match.bind(this); },
  569. // Basic combinators
  570. then: function(m) { return Matcher.seq(this, m); },
  571. or: function(m) { return Matcher.alt(this, m); },
  572. andand: function(m) { return Matcher.many(true, this, m); },
  573. oror: function(m) { return Matcher.many(false, this, m); },
  574. // Component value multipliers
  575. star: function() { return this.braces(0, Infinity, "*"); },
  576. plus: function() { return this.braces(1, Infinity, "+"); },
  577. question: function() { return this.braces(0, 1, "?"); },
  578. hash: function() {
  579. return this.braces(1, Infinity, "#", Matcher.cast(","));
  580. },
  581. braces: function(min, max, marker, optSep) {
  582. var m1 = this, m2 = optSep ? optSep.then(this) : this;
  583. if (!marker) {
  584. marker = "{" + min + "," + max + "}";
  585. }
  586. return new Matcher(function(expression) {
  587. var result = true, i;
  588. for (i = 0; i < max; i++) {
  589. if (i > 0 && optSep) {
  590. result = m2.match(expression);
  591. } else {
  592. result = m1.match(expression);
  593. }
  594. if (!result) {
  595. break;
  596. }
  597. }
  598. return i >= min;
  599. }, function() {
  600. return m1.toString(Matcher.prec.MOD) + marker;
  601. });
  602. }
  603. };
  604. },{"../util/StringReader":24,"../util/SyntaxError":25,"./ValidationTypes":21}],4:[function(require,module,exports){
  605. "use strict";
  606. module.exports = MediaFeature;
  607. var SyntaxUnit = require("../util/SyntaxUnit");
  608. var Parser = require("./Parser");
  609. /**
  610. * Represents a media feature, such as max-width:500.
  611. * @namespace parserlib.css
  612. * @class MediaFeature
  613. * @extends parserlib.util.SyntaxUnit
  614. * @constructor
  615. * @param {SyntaxUnit} name The name of the feature.
  616. * @param {SyntaxUnit} value The value of the feature or null if none.
  617. */
  618. function MediaFeature(name, value) {
  619. SyntaxUnit.call(this, "(" + name + (value !== null ? ":" + value : "") + ")", name.startLine, name.startCol, Parser.MEDIA_FEATURE_TYPE);
  620. /**
  621. * The name of the media feature
  622. * @type String
  623. * @property name
  624. */
  625. this.name = name;
  626. /**
  627. * The value for the feature or null if there is none.
  628. * @type SyntaxUnit
  629. * @property value
  630. */
  631. this.value = value;
  632. }
  633. MediaFeature.prototype = new SyntaxUnit();
  634. MediaFeature.prototype.constructor = MediaFeature;
  635. },{"../util/SyntaxUnit":26,"./Parser":6}],5:[function(require,module,exports){
  636. "use strict";
  637. module.exports = MediaQuery;
  638. var SyntaxUnit = require("../util/SyntaxUnit");
  639. var Parser = require("./Parser");
  640. /**
  641. * Represents an individual media query.
  642. * @namespace parserlib.css
  643. * @class MediaQuery
  644. * @extends parserlib.util.SyntaxUnit
  645. * @constructor
  646. * @param {String} modifier The modifier "not" or "only" (or null).
  647. * @param {String} mediaType The type of media (i.e., "print").
  648. * @param {Array} parts Array of selectors parts making up this selector.
  649. * @param {int} line The line of text on which the unit resides.
  650. * @param {int} col The column of text on which the unit resides.
  651. */
  652. function MediaQuery(modifier, mediaType, features, line, col) {
  653. SyntaxUnit.call(this, (modifier ? modifier + " ": "") + (mediaType ? mediaType : "") + (mediaType && features.length > 0 ? " and " : "") + features.join(" and "), line, col, Parser.MEDIA_QUERY_TYPE);
  654. /**
  655. * The media modifier ("not" or "only")
  656. * @type String
  657. * @property modifier
  658. */
  659. this.modifier = modifier;
  660. /**
  661. * The mediaType (i.e., "print")
  662. * @type String
  663. * @property mediaType
  664. */
  665. this.mediaType = mediaType;
  666. /**
  667. * The parts that make up the selector.
  668. * @type Array
  669. * @property features
  670. */
  671. this.features = features;
  672. }
  673. MediaQuery.prototype = new SyntaxUnit();
  674. MediaQuery.prototype.constructor = MediaQuery;
  675. },{"../util/SyntaxUnit":26,"./Parser":6}],6:[function(require,module,exports){
  676. "use strict";
  677. module.exports = Parser;
  678. var EventTarget = require("../util/EventTarget");
  679. var SyntaxError = require("../util/SyntaxError");
  680. var SyntaxUnit = require("../util/SyntaxUnit");
  681. var Combinator = require("./Combinator");
  682. var MediaFeature = require("./MediaFeature");
  683. var MediaQuery = require("./MediaQuery");
  684. var PropertyName = require("./PropertyName");
  685. var PropertyValue = require("./PropertyValue");
  686. var PropertyValuePart = require("./PropertyValuePart");
  687. var Selector = require("./Selector");
  688. var SelectorPart = require("./SelectorPart");
  689. var SelectorSubPart = require("./SelectorSubPart");
  690. var TokenStream = require("./TokenStream");
  691. var Tokens = require("./Tokens");
  692. var Validation = require("./Validation");
  693. /**
  694. * A CSS3 parser.
  695. * @namespace parserlib.css
  696. * @class Parser
  697. * @constructor
  698. * @param {Object} options (Optional) Various options for the parser:
  699. * starHack (true|false) to allow IE6 star hack as valid,
  700. * underscoreHack (true|false) to interpret leading underscores
  701. * as IE6-7 targeting for known properties, ieFilters (true|false)
  702. * to indicate that IE < 8 filters should be accepted and not throw
  703. * syntax errors.
  704. */
  705. function Parser(options) {
  706. //inherit event functionality
  707. EventTarget.call(this);
  708. this.options = options || {};
  709. this._tokenStream = null;
  710. }
  711. //Static constants
  712. Parser.DEFAULT_TYPE = 0;
  713. Parser.COMBINATOR_TYPE = 1;
  714. Parser.MEDIA_FEATURE_TYPE = 2;
  715. Parser.MEDIA_QUERY_TYPE = 3;
  716. Parser.PROPERTY_NAME_TYPE = 4;
  717. Parser.PROPERTY_VALUE_TYPE = 5;
  718. Parser.PROPERTY_VALUE_PART_TYPE = 6;
  719. Parser.SELECTOR_TYPE = 7;
  720. Parser.SELECTOR_PART_TYPE = 8;
  721. Parser.SELECTOR_SUB_PART_TYPE = 9;
  722. Parser.prototype = function() {
  723. var proto = new EventTarget(), //new prototype
  724. prop,
  725. additions = {
  726. __proto__: null,
  727. //restore constructor
  728. constructor: Parser,
  729. //instance constants - yuck
  730. DEFAULT_TYPE : 0,
  731. COMBINATOR_TYPE : 1,
  732. MEDIA_FEATURE_TYPE : 2,
  733. MEDIA_QUERY_TYPE : 3,
  734. PROPERTY_NAME_TYPE : 4,
  735. PROPERTY_VALUE_TYPE : 5,
  736. PROPERTY_VALUE_PART_TYPE : 6,
  737. SELECTOR_TYPE : 7,
  738. SELECTOR_PART_TYPE : 8,
  739. SELECTOR_SUB_PART_TYPE : 9,
  740. //-----------------------------------------------------------------
  741. // Grammar
  742. //-----------------------------------------------------------------
  743. _stylesheet: function() {
  744. /*
  745. * stylesheet
  746. * : [ CHARSET_SYM S* STRING S* ';' ]?
  747. * [S|CDO|CDC]* [ import [S|CDO|CDC]* ]*
  748. * [ namespace [S|CDO|CDC]* ]*
  749. * [ [ ruleset | media | page | font_face | keyframes_rule | supports_rule ] [S|CDO|CDC]* ]*
  750. * ;
  751. */
  752. var tokenStream = this._tokenStream,
  753. count,
  754. token,
  755. tt;
  756. this.fire("startstylesheet");
  757. //try to read character set
  758. this._charset();
  759. this._skipCruft();
  760. //try to read imports - may be more than one
  761. while (tokenStream.peek() === Tokens.IMPORT_SYM) {
  762. this._import();
  763. this._skipCruft();
  764. }
  765. //try to read namespaces - may be more than one
  766. while (tokenStream.peek() === Tokens.NAMESPACE_SYM) {
  767. this._namespace();
  768. this._skipCruft();
  769. }
  770. //get the next token
  771. tt = tokenStream.peek();
  772. //try to read the rest
  773. while (tt > Tokens.EOF) {
  774. try {
  775. switch (tt) {
  776. case Tokens.MEDIA_SYM:
  777. this._media();
  778. this._skipCruft();
  779. break;
  780. case Tokens.PAGE_SYM:
  781. this._page();
  782. this._skipCruft();
  783. break;
  784. case Tokens.FONT_FACE_SYM:
  785. this._font_face();
  786. this._skipCruft();
  787. break;
  788. case Tokens.KEYFRAMES_SYM:
  789. this._keyframes();
  790. this._skipCruft();
  791. break;
  792. case Tokens.VIEWPORT_SYM:
  793. this._viewport();
  794. this._skipCruft();
  795. break;
  796. case Tokens.DOCUMENT_SYM:
  797. this._document();
  798. this._skipCruft();
  799. break;
  800. case Tokens.SUPPORTS_SYM:
  801. this._supports();
  802. this._skipCruft();
  803. break;
  804. case Tokens.UNKNOWN_SYM: //unknown @ rule
  805. tokenStream.get();
  806. if (!this.options.strict) {
  807. //fire error event
  808. this.fire({
  809. type: "error",
  810. error: null,
  811. message: "Unknown @ rule: " + tokenStream.LT(0).value + ".",
  812. line: tokenStream.LT(0).startLine,
  813. col: tokenStream.LT(0).startCol
  814. });
  815. //skip braces
  816. count=0;
  817. while (tokenStream.advance([Tokens.LBRACE, Tokens.RBRACE]) === Tokens.LBRACE) {
  818. count++; //keep track of nesting depth
  819. }
  820. while (count) {
  821. tokenStream.advance([Tokens.RBRACE]);
  822. count--;
  823. }
  824. } else {
  825. //not a syntax error, rethrow it
  826. throw new SyntaxError("Unknown @ rule.", tokenStream.LT(0).startLine, tokenStream.LT(0).startCol);
  827. }
  828. break;
  829. case Tokens.S:
  830. this._readWhitespace();
  831. break;
  832. default:
  833. if (!this._ruleset()) {
  834. //error handling for known issues
  835. switch (tt) {
  836. case Tokens.CHARSET_SYM:
  837. token = tokenStream.LT(1);
  838. this._charset(false);
  839. throw new SyntaxError("@charset not allowed here.", token.startLine, token.startCol);
  840. case Tokens.IMPORT_SYM:
  841. token = tokenStream.LT(1);
  842. this._import(false);
  843. throw new SyntaxError("@import not allowed here.", token.startLine, token.startCol);
  844. case Tokens.NAMESPACE_SYM:
  845. token = tokenStream.LT(1);
  846. this._namespace(false);
  847. throw new SyntaxError("@namespace not allowed here.", token.startLine, token.startCol);
  848. default:
  849. tokenStream.get(); //get the last token
  850. this._unexpectedToken(tokenStream.token());
  851. }
  852. }
  853. }
  854. } catch (ex) {
  855. if (ex instanceof SyntaxError && !this.options.strict) {
  856. this.fire({
  857. type: "error",
  858. error: ex,
  859. message: ex.message,
  860. line: ex.line,
  861. col: ex.col
  862. });
  863. } else {
  864. throw ex;
  865. }
  866. }
  867. tt = tokenStream.peek();
  868. }
  869. if (tt !== Tokens.EOF) {
  870. this._unexpectedToken(tokenStream.token());
  871. }
  872. this.fire("endstylesheet");
  873. },
  874. _charset: function(emit) {
  875. var tokenStream = this._tokenStream,
  876. charset,
  877. token,
  878. line,
  879. col;
  880. if (tokenStream.match(Tokens.CHARSET_SYM)) {
  881. line = tokenStream.token().startLine;
  882. col = tokenStream.token().startCol;
  883. this._readWhitespace();
  884. tokenStream.mustMatch(Tokens.STRING);
  885. token = tokenStream.token();
  886. charset = token.value;
  887. this._readWhitespace();
  888. tokenStream.mustMatch(Tokens.SEMICOLON);
  889. if (emit !== false) {
  890. this.fire({
  891. type: "charset",
  892. charset:charset,
  893. line: line,
  894. col: col
  895. });
  896. }
  897. }
  898. },
  899. _import: function(emit) {
  900. /*
  901. * import
  902. * : IMPORT_SYM S*
  903. * [STRING|URI] S* media_query_list? ';' S*
  904. */
  905. var tokenStream = this._tokenStream,
  906. uri,
  907. importToken,
  908. mediaList = [];
  909. //read import symbol
  910. tokenStream.mustMatch(Tokens.IMPORT_SYM);
  911. importToken = tokenStream.token();
  912. this._readWhitespace();
  913. tokenStream.mustMatch([Tokens.STRING, Tokens.URI]);
  914. //grab the URI value
  915. uri = tokenStream.token().value.replace(/^(?:url\()?["']?([^"']+?)["']?\)?$/, "$1");
  916. this._readWhitespace();
  917. mediaList = this._media_query_list();
  918. //must end with a semicolon
  919. tokenStream.mustMatch(Tokens.SEMICOLON);
  920. this._readWhitespace();
  921. if (emit !== false) {
  922. this.fire({
  923. type: "import",
  924. uri: uri,
  925. media: mediaList,
  926. line: importToken.startLine,
  927. col: importToken.startCol
  928. });
  929. }
  930. },
  931. _namespace: function(emit) {
  932. /*
  933. * namespace
  934. * : NAMESPACE_SYM S* [namespace_prefix S*]? [STRING|URI] S* ';' S*
  935. */
  936. var tokenStream = this._tokenStream,
  937. line,
  938. col,
  939. prefix,
  940. uri;
  941. //read import symbol
  942. tokenStream.mustMatch(Tokens.NAMESPACE_SYM);
  943. line = tokenStream.token().startLine;
  944. col = tokenStream.token().startCol;
  945. this._readWhitespace();
  946. //it's a namespace prefix - no _namespace_prefix() method because it's just an IDENT
  947. if (tokenStream.match(Tokens.IDENT)) {
  948. prefix = tokenStream.token().value;
  949. this._readWhitespace();
  950. }
  951. tokenStream.mustMatch([Tokens.STRING, Tokens.URI]);
  952. /*if (!tokenStream.match(Tokens.STRING)){
  953. tokenStream.mustMatch(Tokens.URI);
  954. }*/
  955. //grab the URI value
  956. uri = tokenStream.token().value.replace(/(?:url\()?["']([^"']+)["']\)?/, "$1");
  957. this._readWhitespace();
  958. //must end with a semicolon
  959. tokenStream.mustMatch(Tokens.SEMICOLON);
  960. this._readWhitespace();
  961. if (emit !== false) {
  962. this.fire({
  963. type: "namespace",
  964. prefix: prefix,
  965. uri: uri,
  966. line: line,
  967. col: col
  968. });
  969. }
  970. },
  971. _supports: function(emit) {
  972. /*
  973. * supports_rule
  974. * : SUPPORTS_SYM S* supports_condition S* group_rule_body
  975. * ;
  976. */
  977. var tokenStream = this._tokenStream,
  978. line,
  979. col;
  980. if (tokenStream.match(Tokens.SUPPORTS_SYM)) {
  981. line = tokenStream.token().startLine;
  982. col = tokenStream.token().startCol;
  983. this._readWhitespace();
  984. this._supports_condition();
  985. this._readWhitespace();
  986. tokenStream.mustMatch(Tokens.LBRACE);
  987. this._readWhitespace();
  988. if (emit !== false) {
  989. this.fire({
  990. type: "startsupports",
  991. line: line,
  992. col: col
  993. });
  994. }
  995. while (true) {
  996. if (!this._ruleset()) {
  997. break;
  998. }
  999. }
  1000. tokenStream.mustMatch(Tokens.RBRACE);
  1001. this._readWhitespace();
  1002. this.fire({
  1003. type: "endsupports",
  1004. line: line,
  1005. col: col
  1006. });
  1007. }
  1008. },
  1009. _supports_condition: function() {
  1010. /*
  1011. * supports_condition
  1012. * : supports_negation | supports_conjunction | supports_disjunction |
  1013. * supports_condition_in_parens
  1014. * ;
  1015. */
  1016. var tokenStream = this._tokenStream,
  1017. ident;
  1018. if (tokenStream.match(Tokens.IDENT)) {
  1019. ident = tokenStream.token().value.toLowerCase();
  1020. if (ident === "not") {
  1021. tokenStream.mustMatch(Tokens.S);
  1022. this._supports_condition_in_parens();
  1023. } else {
  1024. tokenStream.unget();
  1025. }
  1026. } else {
  1027. this._supports_condition_in_parens();
  1028. this._readWhitespace();
  1029. while (tokenStream.peek() === Tokens.IDENT) {
  1030. ident = tokenStream.LT(1).value.toLowerCase();
  1031. if (ident === "and" || ident === "or") {
  1032. tokenStream.mustMatch(Tokens.IDENT);
  1033. this._readWhitespace();
  1034. this._supports_condition_in_parens();
  1035. this._readWhitespace();
  1036. }
  1037. }
  1038. }
  1039. },
  1040. _supports_condition_in_parens: function() {
  1041. /*
  1042. * supports_condition_in_parens
  1043. * : ( '(' S* supports_condition S* ')' ) | supports_declaration_condition |
  1044. * general_enclosed
  1045. * ;
  1046. */
  1047. var tokenStream = this._tokenStream,
  1048. ident;
  1049. if (tokenStream.match(Tokens.LPAREN)) {
  1050. this._readWhitespace();
  1051. if (tokenStream.match(Tokens.IDENT)) {
  1052. // look ahead for not keyword, if not given, continue with declaration condition.
  1053. ident = tokenStream.token().value.toLowerCase();
  1054. if (ident === "not") {
  1055. this._readWhitespace();
  1056. this._supports_condition();
  1057. this._readWhitespace();
  1058. tokenStream.mustMatch(Tokens.RPAREN);
  1059. } else {
  1060. tokenStream.unget();
  1061. this._supports_declaration_condition(false);
  1062. }
  1063. } else {
  1064. this._supports_condition();
  1065. this._readWhitespace();
  1066. tokenStream.mustMatch(Tokens.RPAREN);
  1067. }
  1068. } else {
  1069. this._supports_declaration_condition();
  1070. }
  1071. },
  1072. _supports_declaration_condition: function(requireStartParen) {
  1073. /*
  1074. * supports_declaration_condition
  1075. * : '(' S* declaration ')'
  1076. * ;
  1077. */
  1078. var tokenStream = this._tokenStream;
  1079. if (requireStartParen !== false) {
  1080. tokenStream.mustMatch(Tokens.LPAREN);
  1081. }
  1082. this._readWhitespace();
  1083. this._declaration();
  1084. tokenStream.mustMatch(Tokens.RPAREN);
  1085. },
  1086. _media: function() {
  1087. /*
  1088. * media
  1089. * : MEDIA_SYM S* media_query_list S* '{' S* ruleset* '}' S*
  1090. * ;
  1091. */
  1092. var tokenStream = this._tokenStream,
  1093. line,
  1094. col,
  1095. mediaList;// = [];
  1096. //look for @media
  1097. tokenStream.mustMatch(Tokens.MEDIA_SYM);
  1098. line = tokenStream.token().startLine;
  1099. col = tokenStream.token().startCol;
  1100. this._readWhitespace();
  1101. mediaList = this._media_query_list();
  1102. tokenStream.mustMatch(Tokens.LBRACE);
  1103. this._readWhitespace();
  1104. this.fire({
  1105. type: "startmedia",
  1106. media: mediaList,
  1107. line: line,
  1108. col: col
  1109. });
  1110. while (true) {
  1111. if (tokenStream.peek() === Tokens.PAGE_SYM) {
  1112. this._page();
  1113. } else if (tokenStream.peek() === Tokens.FONT_FACE_SYM) {
  1114. this._font_face();
  1115. } else if (tokenStream.peek() === Tokens.VIEWPORT_SYM) {
  1116. this._viewport();
  1117. } else if (tokenStream.peek() === Tokens.DOCUMENT_SYM) {
  1118. this._document();
  1119. } else if (tokenStream.peek() === Tokens.SUPPORTS_SYM) {
  1120. this._supports();
  1121. } else if (tokenStream.peek() === Tokens.MEDIA_SYM) {
  1122. this._media();
  1123. } else if (!this._ruleset()) {
  1124. break;
  1125. }
  1126. }
  1127. tokenStream.mustMatch(Tokens.RBRACE);
  1128. this._readWhitespace();
  1129. this.fire({
  1130. type: "endmedia",
  1131. media: mediaList,
  1132. line: line,
  1133. col: col
  1134. });
  1135. },
  1136. //CSS3 Media Queries
  1137. _media_query_list: function() {
  1138. /*
  1139. * media_query_list
  1140. * : S* [media_query [ ',' S* media_query ]* ]?
  1141. * ;
  1142. */
  1143. var tokenStream = this._tokenStream,
  1144. mediaList = [];
  1145. this._readWhitespace();
  1146. if (tokenStream.peek() === Tokens.IDENT || tokenStream.peek() === Tokens.LPAREN) {
  1147. mediaList.push(this._media_query());
  1148. }
  1149. while (tokenStream.match(Tokens.COMMA)) {
  1150. this._readWhitespace();
  1151. mediaList.push(this._media_query());
  1152. }
  1153. return mediaList;
  1154. },
  1155. /*
  1156. * Note: "expression" in the grammar maps to the _media_expression
  1157. * method.
  1158. */
  1159. _media_query: function() {
  1160. /*
  1161. * media_query
  1162. * : [ONLY | NOT]? S* media_type S* [ AND S* expression ]*
  1163. * | expression [ AND S* expression ]*
  1164. * ;
  1165. */
  1166. var tokenStream = this._tokenStream,
  1167. type = null,
  1168. ident = null,
  1169. token = null,
  1170. expressions = [];
  1171. if (tokenStream.match(Tokens.IDENT)) {
  1172. ident = tokenStream.token().value.toLowerCase();
  1173. //since there's no custom tokens for these, need to manually check
  1174. if (ident !== "only" && ident !== "not") {
  1175. tokenStream.unget();
  1176. ident = null;
  1177. } else {
  1178. token = tokenStream.token();
  1179. }
  1180. }
  1181. this._readWhitespace();
  1182. if (tokenStream.peek() === Tokens.IDENT) {
  1183. type = this._media_type();
  1184. if (token === null) {
  1185. token = tokenStream.token();
  1186. }
  1187. } else if (tokenStream.peek() === Tokens.LPAREN) {
  1188. if (token === null) {
  1189. token = tokenStream.LT(1);
  1190. }
  1191. expressions.push(this._media_expression());
  1192. }
  1193. if (type === null && expressions.length === 0) {
  1194. return null;
  1195. } else {
  1196. this._readWhitespace();
  1197. while (tokenStream.match(Tokens.IDENT)) {
  1198. if (tokenStream.token().value.toLowerCase() !== "and") {
  1199. this._unexpectedToken(tokenStream.token());
  1200. }
  1201. this._readWhitespace();
  1202. expressions.push(this._media_expression());
  1203. }
  1204. }
  1205. return new MediaQuery(ident, type, expressions, token.startLine, token.startCol);
  1206. },
  1207. //CSS3 Media Queries
  1208. _media_type: function() {
  1209. /*
  1210. * media_type
  1211. * : IDENT
  1212. * ;
  1213. */
  1214. return this._media_feature();
  1215. },
  1216. /**
  1217. * Note: in CSS3 Media Queries, this is called "expression".
  1218. * Renamed here to avoid conflict with CSS3 Selectors
  1219. * definition of "expression". Also note that "expr" in the
  1220. * grammar now maps to "expression" from CSS3 selectors.
  1221. * @method _media_expression
  1222. * @private
  1223. */
  1224. _media_expression: function() {
  1225. /*
  1226. * expression
  1227. * : '(' S* media_feature S* [ ':' S* expr ]? ')' S*
  1228. * ;
  1229. */
  1230. var tokenStream = this._tokenStream,
  1231. feature = null,
  1232. token,
  1233. expression = null;
  1234. tokenStream.mustMatch(Tokens.LPAREN);
  1235. feature = this._media_feature();
  1236. this._readWhitespace();
  1237. if (tokenStream.match(Tokens.COLON)) {
  1238. this._readWhitespace();
  1239. token = tokenStream.LT(1);
  1240. expression = this._expression();
  1241. }
  1242. tokenStream.mustMatch(Tokens.RPAREN);
  1243. this._readWhitespace();
  1244. return new MediaFeature(feature, expression ? new SyntaxUnit(expression, token.startLine, token.startCol) : null);
  1245. },
  1246. //CSS3 Media Queries
  1247. _media_feature: function() {
  1248. /*
  1249. * media_feature
  1250. * : IDENT
  1251. * ;
  1252. */
  1253. var tokenStream = this._tokenStream;
  1254. this._readWhitespace();
  1255. tokenStream.mustMatch(Tokens.IDENT);
  1256. return SyntaxUnit.fromToken(tokenStream.token());
  1257. },
  1258. //CSS3 Paged Media
  1259. _page: function() {
  1260. /*
  1261. * page:
  1262. * PAGE_SYM S* IDENT? pseudo_page? S*
  1263. * '{' S* [ declaration | margin ]? [ ';' S* [ declaration | margin ]? ]* '}' S*
  1264. * ;
  1265. */
  1266. var tokenStream = this._tokenStream,
  1267. line,
  1268. col,
  1269. identifier = null,
  1270. pseudoPage = null;
  1271. //look for @page
  1272. tokenStream.mustMatch(Tokens.PAGE_SYM);
  1273. line = tokenStream.token().startLine;
  1274. col = tokenStream.token().startCol;
  1275. this._readWhitespace();
  1276. if (tokenStream.match(Tokens.IDENT)) {
  1277. identifier = tokenStream.token().value;
  1278. //The value 'auto' may not be used as a page name and MUST be treated as a syntax error.
  1279. if (identifier.toLowerCase() === "auto") {
  1280. this._unexpectedToken(tokenStream.token());
  1281. }
  1282. }
  1283. //see if there's a colon upcoming
  1284. if (tokenStream.peek() === Tokens.COLON) {
  1285. pseudoPage = this._pseudo_page();
  1286. }
  1287. this._readWhitespace();
  1288. this.fire({
  1289. type: "startpage",
  1290. id: identifier,
  1291. pseudo: pseudoPage,
  1292. line: line,
  1293. col: col
  1294. });
  1295. this._readDeclarations(true, true);
  1296. this.fire({
  1297. type: "endpage",
  1298. id: identifier,
  1299. pseudo: pseudoPage,
  1300. line: line,
  1301. col: col
  1302. });
  1303. },
  1304. //CSS3 Paged Media
  1305. _margin: function() {
  1306. /*
  1307. * margin :
  1308. * margin_sym S* '{' declaration [ ';' S* declaration? ]* '}' S*
  1309. * ;
  1310. */
  1311. var tokenStream = this._tokenStream,
  1312. line,
  1313. col,
  1314. marginSym = this._margin_sym();
  1315. if (marginSym) {
  1316. line = tokenStream.token().startLine;
  1317. col = tokenStream.token().startCol;
  1318. this.fire({
  1319. type: "startpagemargin",
  1320. margin: marginSym,
  1321. line: line,
  1322. col: col
  1323. });
  1324. this._readDeclarations(true);
  1325. this.fire({
  1326. type: "endpagemargin",
  1327. margin: marginSym,
  1328. line: line,
  1329. col: col
  1330. });
  1331. return true;
  1332. } else {
  1333. return false;
  1334. }
  1335. },
  1336. //CSS3 Paged Media
  1337. _margin_sym: function() {
  1338. /*
  1339. * margin_sym :
  1340. * TOPLEFTCORNER_SYM |
  1341. * TOPLEFT_SYM |
  1342. * TOPCENTER_SYM |
  1343. * TOPRIGHT_SYM |
  1344. * TOPRIGHTCORNER_SYM |
  1345. * BOTTOMLEFTCORNER_SYM |
  1346. * BOTTOMLEFT_SYM |
  1347. * BOTTOMCENTER_SYM |
  1348. * BOTTOMRIGHT_SYM |
  1349. * BOTTOMRIGHTCORNER_SYM |
  1350. * LEFTTOP_SYM |
  1351. * LEFTMIDDLE_SYM |
  1352. * LEFTBOTTOM_SYM |
  1353. * RIGHTTOP_SYM |
  1354. * RIGHTMIDDLE_SYM |
  1355. * RIGHTBOTTOM_SYM
  1356. * ;
  1357. */
  1358. var tokenStream = this._tokenStream;
  1359. if (tokenStream.match([Tokens.TOPLEFTCORNER_SYM, Tokens.TOPLEFT_SYM,
  1360. Tokens.TOPCENTER_SYM, Tokens.TOPRIGHT_SYM, Tokens.TOPRIGHTCORNER_SYM,
  1361. Tokens.BOTTOMLEFTCORNER_SYM, Tokens.BOTTOMLEFT_SYM,
  1362. Tokens.BOTTOMCENTER_SYM, Tokens.BOTTOMRIGHT_SYM,
  1363. Tokens.BOTTOMRIGHTCORNER_SYM, Tokens.LEFTTOP_SYM,
  1364. Tokens.LEFTMIDDLE_SYM, Tokens.LEFTBOTTOM_SYM, Tokens.RIGHTTOP_SYM,
  1365. Tokens.RIGHTMIDDLE_SYM, Tokens.RIGHTBOTTOM_SYM])) {
  1366. return SyntaxUnit.fromToken(tokenStream.token());
  1367. } else {
  1368. return null;
  1369. }
  1370. },
  1371. _pseudo_page: function() {
  1372. /*
  1373. * pseudo_page
  1374. * : ':' IDENT
  1375. * ;
  1376. */
  1377. var tokenStream = this._tokenStream;
  1378. tokenStream.mustMatch(Tokens.COLON);
  1379. tokenStream.mustMatch(Tokens.IDENT);
  1380. //TODO: CSS3 Paged Media says only "left", "center", and "right" are allowed
  1381. return tokenStream.token().value;
  1382. },
  1383. _font_face: function() {
  1384. /*
  1385. * font_face
  1386. * : FONT_FACE_SYM S*
  1387. * '{' S* declaration [ ';' S* declaration ]* '}' S*
  1388. * ;
  1389. */
  1390. var tokenStream = this._tokenStream,
  1391. line,
  1392. col;
  1393. //look for @page
  1394. tokenStream.mustMatch(Tokens.FONT_FACE_SYM);
  1395. line = tokenStream.token().startLine;
  1396. col = tokenStream.token().startCol;
  1397. this._readWhitespace();
  1398. this.fire({
  1399. type: "startfontface",
  1400. line: line,
  1401. col: col
  1402. });
  1403. this._readDeclarations(true);
  1404. this.fire({
  1405. type: "endfontface",
  1406. line: line,
  1407. col: col
  1408. });
  1409. },
  1410. _viewport: function() {
  1411. /*
  1412. * viewport
  1413. * : VIEWPORT_SYM S*
  1414. * '{' S* declaration? [ ';' S* declaration? ]* '}' S*
  1415. * ;
  1416. */
  1417. var tokenStream = this._tokenStream,
  1418. line,
  1419. col;
  1420. tokenStream.mustMatch(Tokens.VIEWPORT_SYM);
  1421. line = tokenStream.token().startLine;
  1422. col = tokenStream.token().startCol;
  1423. this._readWhitespace();
  1424. this.fire({
  1425. type: "startviewport",
  1426. line: line,
  1427. col: col
  1428. });
  1429. this._readDeclarations(true);
  1430. this.fire({
  1431. type: "endviewport",
  1432. line: line,
  1433. col: col
  1434. });
  1435. },
  1436. _document: function() {
  1437. /*
  1438. * document
  1439. * : DOCUMENT_SYM S*
  1440. * _document_function [ ',' S* _document_function ]* S*
  1441. * '{' S* ruleset* '}'
  1442. * ;
  1443. */
  1444. var tokenStream = this._tokenStream,
  1445. token,
  1446. functions = [],
  1447. prefix = "";
  1448. tokenStream.mustMatch(Tokens.DOCUMENT_SYM);
  1449. token = tokenStream.token();
  1450. if (/^@\-([^\-]+)\-/.test(token.value)) {
  1451. prefix = RegExp.$1;
  1452. }
  1453. this._readWhitespace();
  1454. functions.push(this._document_function());
  1455. while (tokenStream.match(Tokens.COMMA)) {
  1456. this._readWhitespace();
  1457. functions.push(this._document_function());
  1458. }
  1459. tokenStream.mustMatch(Tokens.LBRACE);
  1460. this._readWhitespace();
  1461. this.fire({
  1462. type: "startdocument",
  1463. functions: functions,
  1464. prefix: prefix,
  1465. line: token.startLine,
  1466. col: token.startCol
  1467. });
  1468. var ok = true;
  1469. while (ok) {
  1470. switch (tokenStream.peek()) {
  1471. case Tokens.PAGE_SYM:
  1472. this._page();
  1473. break;
  1474. case Tokens.FONT_FACE_SYM:
  1475. this._font_face();
  1476. break;
  1477. case Tokens.VIEWPORT_SYM:
  1478. this._viewport();
  1479. break;
  1480. case Tokens.MEDIA_SYM:
  1481. this._media();
  1482. break;
  1483. case Tokens.KEYFRAMES_SYM:
  1484. this._keyframes();
  1485. break;
  1486. case Tokens.DOCUMENT_SYM:
  1487. this._document();
  1488. break;
  1489. case Tokens.SUPPORTS_SYM:
  1490. this._supports();
  1491. break;
  1492. default:
  1493. ok = Boolean(this._ruleset());
  1494. }
  1495. }
  1496. tokenStream.mustMatch(Tokens.RBRACE);
  1497. token = tokenStream.token();
  1498. this._readWhitespace();
  1499. this.fire({
  1500. type: "enddocument",
  1501. functions: functions,
  1502. prefix: prefix,
  1503. line: token.startLine,
  1504. col: token.startCol
  1505. });
  1506. },
  1507. _document_function: function() {
  1508. /*
  1509. * document_function
  1510. * : function | URI S*
  1511. * ;
  1512. */
  1513. var tokenStream = this._tokenStream,
  1514. value;
  1515. if (tokenStream.match(Tokens.URI)) {
  1516. value = tokenStream.token().value;
  1517. this._readWhitespace();
  1518. } else {
  1519. value = this._function();
  1520. }
  1521. return value;
  1522. },
  1523. _operator: function(inFunction) {
  1524. /*
  1525. * operator (outside function)
  1526. * : '/' S* | ',' S* | /( empty )/
  1527. * operator (inside function)
  1528. * : '/' S* | '+' S* | '*' S* | '-' S* /( empty )/
  1529. * ;
  1530. */
  1531. var tokenStream = this._tokenStream,
  1532. token = null;
  1533. if (tokenStream.match([Tokens.SLASH, Tokens.COMMA]) ||
  1534. (inFunction && tokenStream.match([Tokens.PLUS, Tokens.STAR, Tokens.MINUS]))) {
  1535. token = tokenStream.token();
  1536. this._readWhitespace();
  1537. }
  1538. return token ? PropertyValuePart.fromToken(token) : null;
  1539. },
  1540. _combinator: function() {
  1541. /*
  1542. * combinator
  1543. * : PLUS S* | GREATER S* | TILDE S* | S+
  1544. * ;
  1545. */
  1546. var tokenStream = this._tokenStream,
  1547. value = null,
  1548. token;
  1549. if (tokenStream.match([Tokens.PLUS, Tokens.GREATER, Tokens.TILDE])) {
  1550. token = tokenStream.token();
  1551. value = new Combinator(token.value, token.startLine, token.startCol);
  1552. this._readWhitespace();
  1553. }
  1554. return value;
  1555. },
  1556. _unary_operator: function() {
  1557. /*
  1558. * unary_operator
  1559. * : '-' | '+'
  1560. * ;
  1561. */
  1562. var tokenStream = this._tokenStream;
  1563. if (tokenStream.match([Tokens.MINUS, Tokens.PLUS])) {
  1564. return tokenStream.token().value;
  1565. } else {
  1566. return null;
  1567. }
  1568. },
  1569. _property: function() {
  1570. /*
  1571. * property
  1572. * : IDENT S*
  1573. * ;
  1574. */
  1575. var tokenStream = this._tokenStream,
  1576. value = null,
  1577. hack = null,
  1578. tokenValue,
  1579. token,
  1580. line,
  1581. col;
  1582. //check for star hack - throws error if not allowed
  1583. if (tokenStream.peek() === Tokens.STAR && this.options.starHack) {
  1584. tokenStream.get();
  1585. token = tokenStream.token();
  1586. hack = token.value;
  1587. line = token.startLine;
  1588. col = token.startCol;
  1589. }
  1590. if (tokenStream.match(Tokens.IDENT)) {
  1591. token = tokenStream.token();
  1592. tokenValue = token.value;
  1593. //check for underscore hack - no error if not allowed because it's valid CSS syntax
  1594. if (tokenValue.charAt(0) === "_" && this.options.underscoreHack) {
  1595. hack = "_";
  1596. tokenValue = tokenValue.substring(1);
  1597. }
  1598. value = new PropertyName(tokenValue, hack, (line||token.startLine), (col||token.startCol));
  1599. this._readWhitespace();
  1600. }
  1601. return value;
  1602. },
  1603. //Augmented with CSS3 Selectors
  1604. _ruleset: function() {
  1605. /*
  1606. * ruleset
  1607. * : selectors_group
  1608. * '{' S* declaration? [ ';' S* declaration? ]* '}' S*
  1609. * ;
  1610. */
  1611. var tokenStream = this._tokenStream,
  1612. tt,
  1613. selectors;
  1614. /*
  1615. * Error Recovery: If even a single selector fails to parse,
  1616. * then the entire ruleset should be thrown away.
  1617. */
  1618. try {
  1619. selectors = this._selectors_group();
  1620. } catch (ex) {
  1621. if (ex instanceof SyntaxError && !this.options.strict) {
  1622. //fire error event
  1623. this.fire({
  1624. type: "error",
  1625. error: ex,
  1626. message: ex.message,
  1627. line: ex.line,
  1628. col: ex.col
  1629. });
  1630. //skip over everything until closing brace
  1631. tt = tokenStream.advance([Tokens.RBRACE]);
  1632. if (tt === Tokens.RBRACE) {
  1633. //if there's a right brace, the rule is finished so don't do anything
  1634. } else {
  1635. //otherwise, rethrow the error because it wasn't handled properly
  1636. throw ex;
  1637. }
  1638. } else {
  1639. //not a syntax error, rethrow it
  1640. throw ex;
  1641. }
  1642. //trigger parser to continue
  1643. return true;
  1644. }
  1645. //if it got here, all selectors parsed
  1646. if (selectors) {
  1647. this.fire({
  1648. type: "startrule",
  1649. selectors: selectors,
  1650. line: selectors[0].line,
  1651. col: selectors[0].col
  1652. });
  1653. this._readDeclarations(true);
  1654. this.fire({
  1655. type: "endrule",
  1656. selectors: selectors,
  1657. line: selectors[0].line,
  1658. col: selectors[0].col
  1659. });
  1660. }
  1661. return selectors;
  1662. },
  1663. //CSS3 Selectors
  1664. _selectors_group: function() {
  1665. /*
  1666. * selectors_group
  1667. * : selector [ COMMA S* selector ]*
  1668. * ;
  1669. */
  1670. var tokenStream = this._tokenStream,
  1671. selectors = [],
  1672. selector;
  1673. selector = this._selector();
  1674. if (selector !== null) {
  1675. selectors.push(selector);
  1676. while (tokenStream.match(Tokens.COMMA)) {
  1677. this._readWhitespace();
  1678. selector = this._selector();
  1679. if (selector !== null) {
  1680. selectors.push(selector);
  1681. } else {
  1682. this._unexpectedToken(tokenStream.LT(1));
  1683. }
  1684. }
  1685. }
  1686. return selectors.length ? selectors : null;
  1687. },
  1688. //CSS3 Selectors
  1689. _selector: function() {
  1690. /*
  1691. * selector
  1692. * : simple_selector_sequence [ combinator simple_selector_sequence ]*
  1693. * ;
  1694. */
  1695. var tokenStream = this._tokenStream,
  1696. selector = [],
  1697. nextSelector = null,
  1698. combinator = null,
  1699. ws = null;
  1700. //if there's no simple selector, then there's no selector
  1701. nextSelector = this._simple_selector_sequence();
  1702. if (nextSelector === null) {
  1703. return null;
  1704. }
  1705. selector.push(nextSelector);
  1706. do {
  1707. //look for a combinator
  1708. combinator = this._combinator();
  1709. if (combinator !== null) {
  1710. selector.push(combinator);
  1711. nextSelector = this._simple_selector_sequence();
  1712. //there must be a next selector
  1713. if (nextSelector === null) {
  1714. this._unexpectedToken(tokenStream.LT(1));
  1715. } else {
  1716. //nextSelector is an instance of SelectorPart
  1717. selector.push(nextSelector);
  1718. }
  1719. } else {
  1720. //if there's not whitespace, we're done
  1721. if (this._readWhitespace()) {
  1722. //add whitespace separator
  1723. ws = new Combinator(tokenStream.token().value, tokenStream.token().startLine, tokenStream.token().startCol);
  1724. //combinator is not required
  1725. combinator = this._combinator();
  1726. //selector is required if there's a combinator
  1727. nextSelector = this._simple_selector_sequence();
  1728. if (nextSelector === null) {
  1729. if (combinator !== null) {
  1730. this._unexpectedToken(tokenStream.LT(1));
  1731. }
  1732. } else {
  1733. if (combinator !== null) {
  1734. selector.push(combinator);
  1735. } else {
  1736. selector.push(ws);
  1737. }
  1738. selector.push(nextSelector);
  1739. }
  1740. } else {
  1741. break;
  1742. }
  1743. }
  1744. } while (true);
  1745. return new Selector(selector, selector[0].line, selector[0].col);
  1746. },
  1747. //CSS3 Selectors
  1748. _simple_selector_sequence: function() {
  1749. /*
  1750. * simple_selector_sequence
  1751. * : [ type_selector | universal ]
  1752. * [ HASH | class | attrib | pseudo | any | negation ]*
  1753. * | [ HASH | class | attrib | pseudo | any | negation ]+
  1754. * ;
  1755. */
  1756. var tokenStream = this._tokenStream,
  1757. //parts of a simple selector
  1758. elementName = null,
  1759. modifiers = [],
  1760. //complete selector text
  1761. selectorText= "",
  1762. //the different parts after the element name to search for
  1763. components = [
  1764. //HASH
  1765. function() {
  1766. return tokenStream.match(Tokens.HASH) ?
  1767. new SelectorSubPart(tokenStream.token().value, "id", tokenStream.token().startLine, tokenStream.token().startCol) :
  1768. null;
  1769. },
  1770. this._class,
  1771. this._attrib,
  1772. this._pseudo,
  1773. this._any,
  1774. this._negation
  1775. ],
  1776. i = 0,
  1777. len = components.length,
  1778. component = null,
  1779. line,
  1780. col;
  1781. //get starting line and column for the selector
  1782. line = tokenStream.LT(1).startLine;
  1783. col = tokenStream.LT(1).startCol;
  1784. elementName = this._type_selector();
  1785. if (!elementName) {
  1786. elementName = this._universal();
  1787. }
  1788. if (elementName !== null) {
  1789. selectorText += elementName;
  1790. }
  1791. while (true) {
  1792. //whitespace means we're done
  1793. if (tokenStream.peek() === Tokens.S) {
  1794. break;
  1795. }
  1796. //check for each component
  1797. while (i < len && component === null) {
  1798. component = components[i++].call(this);
  1799. }
  1800. if (component === null) {
  1801. //we don't have a selector
  1802. if (selectorText === "") {
  1803. return null;
  1804. } else {
  1805. break;
  1806. }
  1807. } else {
  1808. i = 0;
  1809. modifiers.push(component);
  1810. selectorText += component.toString();
  1811. component = null;
  1812. }
  1813. }
  1814. return selectorText !== "" ?
  1815. new SelectorPart(elementName, modifiers, selectorText, line, col) :
  1816. null;
  1817. },
  1818. //CSS3 Selectors
  1819. _type_selector: function() {
  1820. /*
  1821. * type_selector
  1822. * : [ namespace_prefix ]? element_name
  1823. * ;
  1824. */
  1825. var tokenStream = this._tokenStream,
  1826. ns = this._namespace_prefix(),
  1827. elementName = this._element_name();
  1828. if (!elementName) {
  1829. /*
  1830. * Need to back out the namespace that was read due to both
  1831. * type_selector and universal reading namespace_prefix
  1832. * first. Kind of hacky, but only way I can figure out
  1833. * right now how to not change the grammar.
  1834. */
  1835. if (ns) {
  1836. tokenStream.unget();
  1837. if (ns.length > 1) {
  1838. tokenStream.unget();
  1839. }
  1840. }
  1841. return null;
  1842. } else {
  1843. if (ns) {
  1844. elementName.text = ns + elementName.text;
  1845. elementName.col -= ns.length;
  1846. }
  1847. return elementName;
  1848. }
  1849. },
  1850. //CSS3 Selectors
  1851. _class: function() {
  1852. /*
  1853. * class
  1854. * : '.' IDENT
  1855. * ;
  1856. */
  1857. var tokenStream = this._tokenStream,
  1858. token;
  1859. if (tokenStream.match(Tokens.DOT)) {
  1860. tokenStream.mustMatch(Tokens.IDENT);
  1861. token = tokenStream.token();
  1862. return new SelectorSubPart("." + token.value, "class", token.startLine, token.startCol - 1);
  1863. } else {
  1864. return null;
  1865. }
  1866. },
  1867. //CSS3 Selectors
  1868. _element_name: function() {
  1869. /*
  1870. * element_name
  1871. * : IDENT
  1872. * ;
  1873. */
  1874. var tokenStream = this._tokenStream,
  1875. token;
  1876. if (tokenStream.match(Tokens.IDENT)) {
  1877. token = tokenStream.token();
  1878. return new SelectorSubPart(token.value, "elementName", token.startLine, token.startCol);
  1879. } else {
  1880. return null;
  1881. }
  1882. },
  1883. //CSS3 Selectors
  1884. _namespace_prefix: function() {
  1885. /*
  1886. * namespace_prefix
  1887. * : [ IDENT | '*' ]? '|'
  1888. * ;
  1889. */
  1890. var tokenStream = this._tokenStream,
  1891. value = "";
  1892. //verify that this is a namespace prefix
  1893. if (tokenStream.LA(1) === Tokens.PIPE || tokenStream.LA(2) === Tokens.PIPE) {
  1894. if (tokenStream.match([Tokens.IDENT, Tokens.STAR])) {
  1895. value += tokenStream.token().value;
  1896. }
  1897. tokenStream.mustMatch(Tokens.PIPE);
  1898. value += "|";
  1899. }
  1900. return value.length ? value : null;
  1901. },
  1902. //CSS3 Selectors
  1903. _universal: function() {
  1904. /*
  1905. * universal
  1906. * : [ namespace_prefix ]? '*'
  1907. * ;
  1908. */
  1909. var tokenStream = this._tokenStream,
  1910. value = "",
  1911. ns;
  1912. ns = this._namespace_prefix();
  1913. if (ns) {
  1914. value += ns;
  1915. }
  1916. if (tokenStream.match(Tokens.STAR)) {
  1917. value += "*";
  1918. }
  1919. return value.length ? value : null;
  1920. },
  1921. //CSS3 Selectors
  1922. _attrib: function() {
  1923. /*
  1924. * attrib
  1925. * : '[' S* [ namespace_prefix ]? IDENT S*
  1926. * [ [ PREFIXMATCH |
  1927. * SUFFIXMATCH |
  1928. * SUBSTRINGMATCH |
  1929. * '=' |
  1930. * INCLUDES |
  1931. * DASHMATCH ] S* [ IDENT | STRING ] S*
  1932. * ]? ']'
  1933. * ;
  1934. */
  1935. var tokenStream = this._tokenStream,
  1936. value = null,
  1937. ns,
  1938. token;
  1939. if (tokenStream.match(Tokens.LBRACKET)) {
  1940. token = tokenStream.token();
  1941. value = token.value;
  1942. value += this._readWhitespace();
  1943. ns = this._namespace_prefix();
  1944. if (ns) {
  1945. value += ns;
  1946. }
  1947. tokenStream.mustMatch(Tokens.IDENT);
  1948. value += tokenStream.token().value;
  1949. value += this._readWhitespace();
  1950. if (tokenStream.match([Tokens.PREFIXMATCH, Tokens.SUFFIXMATCH, Tokens.SUBSTRINGMATCH,
  1951. Tokens.EQUALS, Tokens.INCLUDES, Tokens.DASHMATCH])) {
  1952. value += tokenStream.token().value;
  1953. value += this._readWhitespace();
  1954. tokenStream.mustMatch([Tokens.IDENT, Tokens.STRING]);
  1955. value += tokenStream.token().value;
  1956. value += this._readWhitespace();
  1957. }
  1958. tokenStream.mustMatch(Tokens.RBRACKET);
  1959. return new SelectorSubPart(value + "]", "attribute", token.startLine, token.startCol);
  1960. } else {
  1961. return null;
  1962. }
  1963. },
  1964. //CSS3 Selectors
  1965. _pseudo: function() {
  1966. /*
  1967. * pseudo
  1968. * : ':' ':'? [ IDENT | functional_pseudo ]
  1969. * ;
  1970. */
  1971. var tokenStream = this._tokenStream,
  1972. pseudo = null,
  1973. colons = ":",
  1974. line,
  1975. col;
  1976. if (tokenStream.match(Tokens.COLON)) {
  1977. if (tokenStream.match(Tokens.COLON)) {
  1978. colons += ":";
  1979. }
  1980. if (tokenStream.match(Tokens.IDENT)) {
  1981. pseudo = tokenStream.token().value;
  1982. line = tokenStream.token().startLine;
  1983. col = tokenStream.token().startCol - colons.length;
  1984. } else if (tokenStream.peek() === Tokens.FUNCTION) {
  1985. line = tokenStream.LT(1).startLine;
  1986. col = tokenStream.LT(1).startCol - colons.length;
  1987. pseudo = this._functional_pseudo();
  1988. }
  1989. if (pseudo) {
  1990. pseudo = new SelectorSubPart(colons + pseudo, "pseudo", line, col);
  1991. } else {
  1992. var startLine = tokenStream.LT(1).startLine,
  1993. startCol = tokenStream.LT(0).startCol;
  1994. throw new SyntaxError("Expected a `FUNCTION` or `IDENT` after colon at line " + startLine + ", col " + startCol + ".", startLine, startCol);
  1995. }
  1996. }
  1997. return pseudo;
  1998. },
  1999. //CSS3 Selectors
  2000. _functional_pseudo: function() {
  2001. /*
  2002. * functional_pseudo
  2003. * : FUNCTION S* expression ')'
  2004. * ;
  2005. */
  2006. var tokenStream = this._tokenStream,
  2007. value = null;
  2008. if (tokenStream.match(Tokens.FUNCTION)) {
  2009. value = tokenStream.token().value;
  2010. value += this._readWhitespace();
  2011. value += this._expression();
  2012. tokenStream.mustMatch(Tokens.RPAREN);
  2013. value += ")";
  2014. }
  2015. return value;
  2016. },
  2017. //CSS3 Selectors
  2018. _expression: function() {
  2019. /*
  2020. * expression
  2021. * : [ [ PLUS | '-' | DIMENSION | NUMBER | STRING | IDENT ] S* ]+
  2022. * ;
  2023. */
  2024. var tokenStream = this._tokenStream,
  2025. value = "";
  2026. while (tokenStream.match([Tokens.PLUS, Tokens.MINUS, Tokens.DIMENSION,
  2027. Tokens.NUMBER, Tokens.STRING, Tokens.IDENT, Tokens.LENGTH,
  2028. Tokens.FREQ, Tokens.ANGLE, Tokens.TIME,
  2029. Tokens.RESOLUTION, Tokens.SLASH])) {
  2030. value += tokenStream.token().value;
  2031. value += this._readWhitespace();
  2032. }
  2033. return value.length ? value : null;
  2034. },
  2035. //CSS3 Selectors
  2036. _any: function() {
  2037. /*
  2038. * any
  2039. * : ANY S* any_arg S* ')'
  2040. * ;
  2041. */
  2042. var tokenStream = this._tokenStream,
  2043. line,
  2044. col,
  2045. value = "",
  2046. arg,
  2047. subpart = null;
  2048. if (tokenStream.match(Tokens.ANY)) {
  2049. value = tokenStream.token().value;
  2050. line = tokenStream.token().startLine;
  2051. col = tokenStream.token().startCol;
  2052. value += this._readWhitespace();
  2053. arg = this._selectors_group();
  2054. value += arg;
  2055. value += this._readWhitespace();
  2056. tokenStream.match(Tokens.RPAREN);
  2057. value += tokenStream.token().value;
  2058. subpart = new SelectorSubPart(value, "any", line, col);
  2059. subpart.args.push(arg);
  2060. }
  2061. return subpart;
  2062. },
  2063. //CSS3 Selectors
  2064. _negation: function() {
  2065. /*
  2066. * negation
  2067. * : NOT S* negation_arg S* ')'
  2068. * ;
  2069. */
  2070. var tokenStream = this._tokenStream,
  2071. line,
  2072. col,
  2073. value = "",
  2074. arg,
  2075. subpart = null;
  2076. if (tokenStream.match(Tokens.NOT)) {
  2077. value = tokenStream.token().value;
  2078. line = tokenStream.token().startLine;
  2079. col = tokenStream.token().startCol;
  2080. value += this._readWhitespace();
  2081. arg = this._negation_arg();
  2082. value += arg;
  2083. value += this._readWhitespace();
  2084. tokenStream.match(Tokens.RPAREN);
  2085. value += tokenStream.token().value;
  2086. subpart = new SelectorSubPart(value, "not", line, col);
  2087. subpart.args.push(arg);
  2088. }
  2089. return subpart;
  2090. },
  2091. //CSS3 Selectors
  2092. _negation_arg: function() {
  2093. /*
  2094. * negation_arg
  2095. * : type_selector | universal | HASH | class | attrib | pseudo
  2096. * ;
  2097. */
  2098. var tokenStream = this._tokenStream,
  2099. args = [
  2100. this._type_selector,
  2101. this._universal,
  2102. function() {
  2103. return tokenStream.match(Tokens.HASH) ?
  2104. new SelectorSubPart(tokenStream.token().value, "id", tokenStream.token().startLine, tokenStream.token().startCol) :
  2105. null;
  2106. },
  2107. this._class,
  2108. this._attrib,
  2109. this._pseudo
  2110. ],
  2111. arg = null,
  2112. i = 0,
  2113. len = args.length,
  2114. line,
  2115. col,
  2116. part;
  2117. line = tokenStream.LT(1).startLine;
  2118. col = tokenStream.LT(1).startCol;
  2119. while (i < len && arg === null) {
  2120. arg = args[i].call(this);
  2121. i++;
  2122. }
  2123. //must be a negation arg
  2124. if (arg === null) {
  2125. this._unexpectedToken(tokenStream.LT(1));
  2126. }
  2127. //it's an element name
  2128. if (arg.type === "elementName") {
  2129. part = new SelectorPart(arg, [], arg.toString(), line, col);
  2130. } else {
  2131. part = new SelectorPart(null, [arg], arg.toString(), line, col);
  2132. }
  2133. return part;
  2134. },
  2135. _declaration: function() {
  2136. /*
  2137. * declaration
  2138. * : property ':' S* expr prio?
  2139. * | /( empty )/
  2140. * ;
  2141. */
  2142. var tokenStream = this._tokenStream,
  2143. property = null,
  2144. expr = null,
  2145. prio = null,
  2146. invalid = null,
  2147. propertyName= "";
  2148. property = this._property();
  2149. if (property !== null) {
  2150. tokenStream.mustMatch(Tokens.COLON);
  2151. this._readWhitespace();
  2152. expr = this._expr();
  2153. //if there's no parts for the value, it's an error
  2154. if (!expr || expr.length === 0) {
  2155. this._unexpectedToken(tokenStream.LT(1));
  2156. }
  2157. prio = this._prio();
  2158. /*
  2159. * If hacks should be allowed, then only check the root
  2160. * property. If hacks should not be allowed, treat
  2161. * _property or *property as invalid properties.
  2162. */
  2163. propertyName = property.toString();
  2164. if (this.options.starHack && property.hack === "*" ||
  2165. this.options.underscoreHack && property.hack === "_") {
  2166. propertyName = property.text;
  2167. }
  2168. try {
  2169. this._validateProperty(propertyName, expr);
  2170. } catch (ex) {
  2171. invalid = ex;
  2172. }
  2173. this.fire({
  2174. type: "property",
  2175. property: property,
  2176. value: expr,
  2177. important: prio,
  2178. line: property.line,
  2179. col: property.col,
  2180. invalid: invalid
  2181. });
  2182. return true;
  2183. } else {
  2184. return false;
  2185. }
  2186. },
  2187. _prio: function() {
  2188. /*
  2189. * prio
  2190. * : IMPORTANT_SYM S*
  2191. * ;
  2192. */
  2193. var tokenStream = this._tokenStream,
  2194. result = tokenStream.match(Tokens.IMPORTANT_SYM);
  2195. this._readWhitespace();
  2196. return result;
  2197. },
  2198. _expr: function(inFunction) {
  2199. /*
  2200. * expr
  2201. * : term [ operator term ]*
  2202. * ;
  2203. */
  2204. var values = [],
  2205. //valueParts = [],
  2206. value = null,
  2207. operator = null;
  2208. value = this._term(inFunction);
  2209. if (value !== null) {
  2210. values.push(value);
  2211. do {
  2212. operator = this._operator(inFunction);
  2213. //if there's an operator, keep building up the value parts
  2214. if (operator) {
  2215. values.push(operator);
  2216. } /*else {
  2217. //if there's not an operator, you have a full value
  2218. values.push(new PropertyValue(valueParts, valueParts[0].line, valueParts[0].col));
  2219. valueParts = [];
  2220. }*/
  2221. value = this._term(inFunction);
  2222. if (value === null) {
  2223. break;
  2224. } else {
  2225. values.push(value);
  2226. }
  2227. } while (true);
  2228. }
  2229. //cleanup
  2230. /*if (valueParts.length) {
  2231. values.push(new PropertyValue(valueParts, valueParts[0].line, valueParts[0].col));
  2232. }*/
  2233. return values.length > 0 ? new PropertyValue(values, values[0].line, values[0].col) : null;
  2234. },
  2235. _term: function(inFunction) {
  2236. /*
  2237. * term
  2238. * : unary_operator?
  2239. * [ NUMBER S* | PERCENTAGE S* | LENGTH S* | ANGLE S* |
  2240. * TIME S* | FREQ S* | function | ie_function ]
  2241. * | STRING S* | IDENT S* | URI S* | UNICODERANGE S* | hexcolor
  2242. * ;
  2243. */
  2244. var tokenStream = this._tokenStream,
  2245. unary = null,
  2246. value = null,
  2247. endChar = null,
  2248. part = null,
  2249. token,
  2250. line,
  2251. col;
  2252. //returns the operator or null
  2253. unary = this._unary_operator();
  2254. if (unary !== null) {
  2255. line = tokenStream.token().startLine;
  2256. col = tokenStream.token().startCol;
  2257. }
  2258. //exception for IE filters
  2259. if (tokenStream.peek() === Tokens.IE_FUNCTION && this.options.ieFilters) {
  2260. value = this._ie_function();
  2261. if (unary === null) {
  2262. line = tokenStream.token().startLine;
  2263. col = tokenStream.token().startCol;
  2264. }
  2265. //see if it's a simple block
  2266. } else if (inFunction && tokenStream.match([Tokens.LPAREN, Tokens.LBRACE, Tokens.LBRACKET])) {
  2267. token = tokenStream.token();
  2268. endChar = token.endChar;
  2269. value = token.value + this._expr(inFunction).text;
  2270. if (unary === null) {
  2271. line = tokenStream.token().startLine;
  2272. col = tokenStream.token().startCol;
  2273. }
  2274. tokenStream.mustMatch(Tokens.type(endChar));
  2275. value += endChar;
  2276. this._readWhitespace();
  2277. //see if there's a simple match
  2278. } else if (tokenStream.match([Tokens.NUMBER, Tokens.PERCENTAGE, Tokens.LENGTH,
  2279. Tokens.ANGLE, Tokens.TIME,
  2280. Tokens.FREQ, Tokens.STRING, Tokens.IDENT, Tokens.URI, Tokens.UNICODE_RANGE])) {
  2281. value = tokenStream.token().value;
  2282. if (unary === null) {
  2283. line = tokenStream.token().startLine;
  2284. col = tokenStream.token().startCol;
  2285. // Correct potentially-inaccurate IDENT parsing in
  2286. // PropertyValuePart constructor.
  2287. part = PropertyValuePart.fromToken(tokenStream.token());
  2288. }
  2289. this._readWhitespace();
  2290. } else {
  2291. //see if it's a color
  2292. token = this._hexcolor();
  2293. if (token === null) {
  2294. //if there's no unary, get the start of the next token for line/col info
  2295. if (unary === null) {
  2296. line = tokenStream.LT(1).startLine;
  2297. col = tokenStream.LT(1).startCol;
  2298. }
  2299. //has to be a function
  2300. if (value === null) {
  2301. /*
  2302. * This checks for alpha(opacity=0) style of IE
  2303. * functions. IE_FUNCTION only presents progid: style.
  2304. */
  2305. if (tokenStream.LA(3) === Tokens.EQUALS && this.options.ieFilters) {
  2306. value = this._ie_function();
  2307. } else {
  2308. value = this._function();
  2309. }
  2310. }
  2311. /*if (value === null) {
  2312. return null;
  2313. //throw new Error("Expected identifier at line " + tokenStream.token().startLine + ", character " + tokenStream.token().startCol + ".");
  2314. }*/
  2315. } else {
  2316. value = token.value;
  2317. if (unary === null) {
  2318. line = token.startLine;
  2319. col = token.startCol;
  2320. }
  2321. }
  2322. }
  2323. return part !== null ? part : value !== null ?
  2324. new PropertyValuePart(unary !== null ? unary + value : value, line, col) :
  2325. null;
  2326. },
  2327. _function: function() {
  2328. /*
  2329. * function
  2330. * : FUNCTION S* expr ')' S*
  2331. * ;
  2332. */
  2333. var tokenStream = this._tokenStream,
  2334. functionText = null,
  2335. expr = null,
  2336. lt;
  2337. if (tokenStream.match(Tokens.FUNCTION)) {
  2338. functionText = tokenStream.token().value;
  2339. this._readWhitespace();
  2340. expr = this._expr(true);
  2341. functionText += expr;
  2342. //START: Horrible hack in case it's an IE filter
  2343. if (this.options.ieFilters && tokenStream.peek() === Tokens.EQUALS) {
  2344. do {
  2345. if (this._readWhitespace()) {
  2346. functionText += tokenStream.token().value;
  2347. }
  2348. //might be second time in the loop
  2349. if (tokenStream.LA(0) === Tokens.COMMA) {
  2350. functionText += tokenStream.token().value;
  2351. }
  2352. tokenStream.match(Tokens.IDENT);
  2353. functionText += tokenStream.token().value;
  2354. tokenStream.match(Tokens.EQUALS);
  2355. functionText += tokenStream.token().value;
  2356. //functionText += this._term();
  2357. lt = tokenStream.peek();
  2358. while (lt !== Tokens.COMMA && lt !== Tokens.S && lt !== Tokens.RPAREN && lt !== Tokens.EOF) {
  2359. tokenStream.get();
  2360. functionText += tokenStream.token().value;
  2361. lt = tokenStream.peek();
  2362. }
  2363. } while (tokenStream.match([Tokens.COMMA, Tokens.S]));
  2364. }
  2365. //END: Horrible Hack
  2366. tokenStream.match(Tokens.RPAREN);
  2367. functionText += ")";
  2368. this._readWhitespace();
  2369. }
  2370. return functionText;
  2371. },
  2372. _ie_function: function() {
  2373. /* (My own extension)
  2374. * ie_function
  2375. * : IE_FUNCTION S* IDENT '=' term [S* ','? IDENT '=' term]+ ')' S*
  2376. * ;
  2377. */
  2378. var tokenStream = this._tokenStream,
  2379. functionText = null,
  2380. lt;
  2381. //IE function can begin like a regular function, too
  2382. if (tokenStream.match([Tokens.IE_FUNCTION, Tokens.FUNCTION])) {
  2383. functionText = tokenStream.token().value;
  2384. do {
  2385. if (this._readWhitespace()) {
  2386. functionText += tokenStream.token().value;
  2387. }
  2388. //might be second time in the loop
  2389. if (tokenStream.LA(0) === Tokens.COMMA) {
  2390. functionText += tokenStream.token().value;
  2391. }
  2392. tokenStream.match(Tokens.IDENT);
  2393. functionText += tokenStream.token().value;
  2394. tokenStream.match(Tokens.EQUALS);
  2395. functionText += tokenStream.token().value;
  2396. //functionText += this._term();
  2397. lt = tokenStream.peek();
  2398. while (lt !== Tokens.COMMA && lt !== Tokens.S && lt !== Tokens.RPAREN) {
  2399. tokenStream.get();
  2400. functionText += tokenStream.token().value;
  2401. lt = tokenStream.peek();
  2402. }
  2403. } while (tokenStream.match([Tokens.COMMA, Tokens.S]));
  2404. tokenStream.match(Tokens.RPAREN);
  2405. functionText += ")";
  2406. this._readWhitespace();
  2407. }
  2408. return functionText;
  2409. },
  2410. _hexcolor: function() {
  2411. /*
  2412. * There is a constraint on the color that it must
  2413. * have either 3 or 6 hex-digits (i.e., [0-9a-fA-F])
  2414. * after the "#"; e.g., "#000" is OK, but "#abcd" is not.
  2415. *
  2416. * hexcolor
  2417. * : HASH S*
  2418. * ;
  2419. */
  2420. var tokenStream = this._tokenStream,
  2421. token = null,
  2422. color;
  2423. if (tokenStream.match(Tokens.HASH)) {
  2424. //need to do some validation here
  2425. token = tokenStream.token();
  2426. color = token.value;
  2427. if (!/#[a-f0-9]{3,6}/i.test(color)) {
  2428. throw new SyntaxError("Expected a hex color but found '" + color + "' at line " + token.startLine + ", col " + token.startCol + ".", token.startLine, token.startCol);
  2429. }
  2430. this._readWhitespace();
  2431. }
  2432. return token;
  2433. },
  2434. //-----------------------------------------------------------------
  2435. // Animations methods
  2436. //-----------------------------------------------------------------
  2437. _keyframes: function() {
  2438. /*
  2439. * keyframes:
  2440. * : KEYFRAMES_SYM S* keyframe_name S* '{' S* keyframe_rule* '}' {
  2441. * ;
  2442. */
  2443. var tokenStream = this._tokenStream,
  2444. token,
  2445. tt,
  2446. name,
  2447. prefix = "";
  2448. tokenStream.mustMatch(Tokens.KEYFRAMES_SYM);
  2449. token = tokenStream.token();
  2450. if (/^@\-([^\-]+)\-/.test(token.value)) {
  2451. prefix = RegExp.$1;
  2452. }
  2453. this._readWhitespace();
  2454. name = this._keyframe_name();
  2455. this._readWhitespace();
  2456. tokenStream.mustMatch(Tokens.LBRACE);
  2457. this.fire({
  2458. type: "startkeyframes",
  2459. name: name,
  2460. prefix: prefix,
  2461. line: token.startLine,
  2462. col: token.startCol
  2463. });
  2464. this._readWhitespace();
  2465. tt = tokenStream.peek();
  2466. //check for key
  2467. while (tt === Tokens.IDENT || tt === Tokens.PERCENTAGE) {
  2468. this._keyframe_rule();
  2469. this._readWhitespace();
  2470. tt = tokenStream.peek();
  2471. }
  2472. this.fire({
  2473. type: "endkeyframes",
  2474. name: name,
  2475. prefix: prefix,
  2476. line: token.startLine,
  2477. col: token.startCol
  2478. });
  2479. this._readWhitespace();
  2480. tokenStream.mustMatch(Tokens.RBRACE);
  2481. this._readWhitespace();
  2482. },
  2483. _keyframe_name: function() {
  2484. /*
  2485. * keyframe_name:
  2486. * : IDENT
  2487. * | STRING
  2488. * ;
  2489. */
  2490. var tokenStream = this._tokenStream;
  2491. tokenStream.mustMatch([Tokens.IDENT, Tokens.STRING]);
  2492. return SyntaxUnit.fromToken(tokenStream.token());
  2493. },
  2494. _keyframe_rule: function() {
  2495. /*
  2496. * keyframe_rule:
  2497. * : key_list S*
  2498. * '{' S* declaration [ ';' S* declaration ]* '}' S*
  2499. * ;
  2500. */
  2501. var keyList = this._key_list();
  2502. this.fire({
  2503. type: "startkeyframerule",
  2504. keys: keyList,
  2505. line: keyList[0].line,
  2506. col: keyList[0].col
  2507. });
  2508. this._readDeclarations(true);
  2509. this.fire({
  2510. type: "endkeyframerule",
  2511. keys: keyList,
  2512. line: keyList[0].line,
  2513. col: keyList[0].col
  2514. });
  2515. },
  2516. _key_list: function() {
  2517. /*
  2518. * key_list:
  2519. * : key [ S* ',' S* key]*
  2520. * ;
  2521. */
  2522. var tokenStream = this._tokenStream,
  2523. keyList = [];
  2524. //must be least one key
  2525. keyList.push(this._key());
  2526. this._readWhitespace();
  2527. while (tokenStream.match(Tokens.COMMA)) {
  2528. this._readWhitespace();
  2529. keyList.push(this._key());
  2530. this._readWhitespace();
  2531. }
  2532. return keyList;
  2533. },
  2534. _key: function() {
  2535. /*
  2536. * There is a restriction that IDENT can be only "from" or "to".
  2537. *
  2538. * key
  2539. * : PERCENTAGE
  2540. * | IDENT
  2541. * ;
  2542. */
  2543. var tokenStream = this._tokenStream,
  2544. token;
  2545. if (tokenStream.match(Tokens.PERCENTAGE)) {
  2546. return SyntaxUnit.fromToken(tokenStream.token());
  2547. } else if (tokenStream.match(Tokens.IDENT)) {
  2548. token = tokenStream.token();
  2549. if (/from|to/i.test(token.value)) {
  2550. return SyntaxUnit.fromToken(token);
  2551. }
  2552. tokenStream.unget();
  2553. }
  2554. //if it gets here, there wasn't a valid token, so time to explode
  2555. this._unexpectedToken(tokenStream.LT(1));
  2556. },
  2557. //-----------------------------------------------------------------
  2558. // Helper methods
  2559. //-----------------------------------------------------------------
  2560. /**
  2561. * Not part of CSS grammar, but useful for skipping over
  2562. * combination of white space and HTML-style comments.
  2563. * @return {void}
  2564. * @method _skipCruft
  2565. * @private
  2566. */
  2567. _skipCruft: function() {
  2568. while (this._tokenStream.match([Tokens.S, Tokens.CDO, Tokens.CDC])) {
  2569. //noop
  2570. }
  2571. },
  2572. /**
  2573. * Not part of CSS grammar, but this pattern occurs frequently
  2574. * in the official CSS grammar. Split out here to eliminate
  2575. * duplicate code.
  2576. * @param {Boolean} checkStart Indicates if the rule should check
  2577. * for the left brace at the beginning.
  2578. * @param {Boolean} readMargins Indicates if the rule should check
  2579. * for margin patterns.
  2580. * @return {void}
  2581. * @method _readDeclarations
  2582. * @private
  2583. */
  2584. _readDeclarations: function(checkStart, readMargins) {
  2585. /*
  2586. * Reads the pattern
  2587. * S* '{' S* declaration [ ';' S* declaration ]* '}' S*
  2588. * or
  2589. * S* '{' S* [ declaration | margin ]? [ ';' S* [ declaration | margin ]? ]* '}' S*
  2590. * Note that this is how it is described in CSS3 Paged Media, but is actually incorrect.
  2591. * A semicolon is only necessary following a declaration if there's another declaration
  2592. * or margin afterwards.
  2593. */
  2594. var tokenStream = this._tokenStream,
  2595. tt;
  2596. this._readWhitespace();
  2597. if (checkStart) {
  2598. tokenStream.mustMatch(Tokens.LBRACE);
  2599. }
  2600. this._readWhitespace();
  2601. try {
  2602. while (true) {
  2603. if (tokenStream.match(Tokens.SEMICOLON) || (readMargins && this._margin())) {
  2604. //noop
  2605. } else if (this._declaration()) {
  2606. if (!tokenStream.match(Tokens.SEMICOLON)) {
  2607. break;
  2608. }
  2609. } else {
  2610. break;
  2611. }
  2612. //if ((!this._margin() && !this._declaration()) || !tokenStream.match(Tokens.SEMICOLON)){
  2613. // break;
  2614. //}
  2615. this._readWhitespace();
  2616. }
  2617. tokenStream.mustMatch(Tokens.RBRACE);
  2618. this._readWhitespace();
  2619. } catch (ex) {
  2620. if (ex instanceof SyntaxError && !this.options.strict) {
  2621. //fire error event
  2622. this.fire({
  2623. type: "error",
  2624. error: ex,
  2625. message: ex.message,
  2626. line: ex.line,
  2627. col: ex.col
  2628. });
  2629. //see if there's another declaration
  2630. tt = tokenStream.advance([Tokens.SEMICOLON, Tokens.RBRACE]);
  2631. if (tt === Tokens.SEMICOLON) {
  2632. //if there's a semicolon, then there might be another declaration
  2633. this._readDeclarations(false, readMargins);
  2634. } else if (tt !== Tokens.RBRACE) {
  2635. //if there's a right brace, the rule is finished so don't do anything
  2636. //otherwise, rethrow the error because it wasn't handled properly
  2637. throw ex;
  2638. }
  2639. } else {
  2640. //not a syntax error, rethrow it
  2641. throw ex;
  2642. }
  2643. }
  2644. },
  2645. /**
  2646. * In some cases, you can end up with two white space tokens in a
  2647. * row. Instead of making a change in every function that looks for
  2648. * white space, this function is used to match as much white space
  2649. * as necessary.
  2650. * @method _readWhitespace
  2651. * @return {String} The white space if found, empty string if not.
  2652. * @private
  2653. */
  2654. _readWhitespace: function() {
  2655. var tokenStream = this._tokenStream,
  2656. ws = "";
  2657. while (tokenStream.match(Tokens.S)) {
  2658. ws += tokenStream.token().value;
  2659. }
  2660. return ws;
  2661. },
  2662. /**
  2663. * Throws an error when an unexpected token is found.
  2664. * @param {Object} token The token that was found.
  2665. * @method _unexpectedToken
  2666. * @return {void}
  2667. * @private
  2668. */
  2669. _unexpectedToken: function(token) {
  2670. throw new SyntaxError("Unexpected token '" + token.value + "' at line " + token.startLine + ", col " + token.startCol + ".", token.startLine, token.startCol);
  2671. },
  2672. /**
  2673. * Helper method used for parsing subparts of a style sheet.
  2674. * @return {void}
  2675. * @method _verifyEnd
  2676. * @private
  2677. */
  2678. _verifyEnd: function() {
  2679. if (this._tokenStream.LA(1) !== Tokens.EOF) {
  2680. this._unexpectedToken(this._tokenStream.LT(1));
  2681. }
  2682. },
  2683. //-----------------------------------------------------------------
  2684. // Validation methods
  2685. //-----------------------------------------------------------------
  2686. _validateProperty: function(property, value) {
  2687. Validation.validate(property, value);
  2688. },
  2689. //-----------------------------------------------------------------
  2690. // Parsing methods
  2691. //-----------------------------------------------------------------
  2692. parse: function(input) {
  2693. this._tokenStream = new TokenStream(input, Tokens);
  2694. this._stylesheet();
  2695. },
  2696. parseStyleSheet: function(input) {
  2697. //just passthrough
  2698. return this.parse(input);
  2699. },
  2700. parseMediaQuery: function(input) {
  2701. this._tokenStream = new TokenStream(input, Tokens);
  2702. var result = this._media_query();
  2703. //if there's anything more, then it's an invalid selector
  2704. this._verifyEnd();
  2705. //otherwise return result
  2706. return result;
  2707. },
  2708. /**
  2709. * Parses a property value (everything after the semicolon).
  2710. * @return {parserlib.css.PropertyValue} The property value.
  2711. * @throws parserlib.util.SyntaxError If an unexpected token is found.
  2712. * @method parserPropertyValue
  2713. */
  2714. parsePropertyValue: function(input) {
  2715. this._tokenStream = new TokenStream(input, Tokens);
  2716. this._readWhitespace();
  2717. var result = this._expr();
  2718. //okay to have a trailing white space
  2719. this._readWhitespace();
  2720. //if there's anything more, then it's an invalid selector
  2721. this._verifyEnd();
  2722. //otherwise return result
  2723. return result;
  2724. },
  2725. /**
  2726. * Parses a complete CSS rule, including selectors and
  2727. * properties.
  2728. * @param {String} input The text to parser.
  2729. * @return {Boolean} True if the parse completed successfully, false if not.
  2730. * @method parseRule
  2731. */
  2732. parseRule: function(input) {
  2733. this._tokenStream = new TokenStream(input, Tokens);
  2734. //skip any leading white space
  2735. this._readWhitespace();
  2736. var result = this._ruleset();
  2737. //skip any trailing white space
  2738. this._readWhitespace();
  2739. //if there's anything more, then it's an invalid selector
  2740. this._verifyEnd();
  2741. //otherwise return result
  2742. return result;
  2743. },
  2744. /**
  2745. * Parses a single CSS selector (no comma)
  2746. * @param {String} input The text to parse as a CSS selector.
  2747. * @return {Selector} An object representing the selector.
  2748. * @throws parserlib.util.SyntaxError If an unexpected token is found.
  2749. * @method parseSelector
  2750. */
  2751. parseSelector: function(input) {
  2752. this._tokenStream = new TokenStream(input, Tokens);
  2753. //skip any leading white space
  2754. this._readWhitespace();
  2755. var result = this._selector();
  2756. //skip any trailing white space
  2757. this._readWhitespace();
  2758. //if there's anything more, then it's an invalid selector
  2759. this._verifyEnd();
  2760. //otherwise return result
  2761. return result;
  2762. },
  2763. /**
  2764. * Parses an HTML style attribute: a set of CSS declarations
  2765. * separated by semicolons.
  2766. * @param {String} input The text to parse as a style attribute
  2767. * @return {void}
  2768. * @method parseStyleAttribute
  2769. */
  2770. parseStyleAttribute: function(input) {
  2771. input += "}"; // for error recovery in _readDeclarations()
  2772. this._tokenStream = new TokenStream(input, Tokens);
  2773. this._readDeclarations();
  2774. }
  2775. };
  2776. //copy over onto prototype
  2777. for (prop in additions) {
  2778. if (Object.prototype.hasOwnProperty.call(additions, prop)) {
  2779. proto[prop] = additions[prop];
  2780. }
  2781. }
  2782. return proto;
  2783. }();
  2784. /*
  2785. nth
  2786. : S* [ ['-'|'+']? INTEGER? {N} [ S* ['-'|'+'] S* INTEGER ]? |
  2787. ['-'|'+']? INTEGER | {O}{D}{D} | {E}{V}{E}{N} ] S*
  2788. ;
  2789. */
  2790. },{"../util/EventTarget":23,"../util/SyntaxError":25,"../util/SyntaxUnit":26,"./Combinator":2,"./MediaFeature":4,"./MediaQuery":5,"./PropertyName":8,"./PropertyValue":9,"./PropertyValuePart":11,"./Selector":13,"./SelectorPart":14,"./SelectorSubPart":15,"./TokenStream":17,"./Tokens":18,"./Validation":19}],7:[function(require,module,exports){
  2791. "use strict";
  2792. /* exported Properties */
  2793. var Properties = module.exports = {
  2794. __proto__: null,
  2795. //A
  2796. "align-items" : "flex-start | flex-end | center | baseline | stretch",
  2797. "align-content" : "flex-start | flex-end | center | space-between | space-around | stretch",
  2798. "align-self" : "auto | flex-start | flex-end | center | baseline | stretch",
  2799. "all" : "initial | inherit | unset",
  2800. "-webkit-align-items" : "flex-start | flex-end | center | baseline | stretch",
  2801. "-webkit-align-content" : "flex-start | flex-end | center | space-between | space-around | stretch",
  2802. "-webkit-align-self" : "auto | flex-start | flex-end | center | baseline | stretch",
  2803. "alignment-adjust" : "auto | baseline | before-edge | text-before-edge | middle | central | after-edge | text-after-edge | ideographic | alphabetic | hanging | mathematical | <percentage> | <length>",
  2804. "alignment-baseline" : "auto | baseline | use-script | before-edge | text-before-edge | after-edge | text-after-edge | central | middle | ideographic | alphabetic | hanging | mathematical",
  2805. "animation" : 1,
  2806. "animation-delay" : "<time>#",
  2807. "animation-direction" : "<single-animation-direction>#",
  2808. "animation-duration" : "<time>#",
  2809. "animation-fill-mode" : "[ none | forwards | backwards | both ]#",
  2810. "animation-iteration-count" : "[ <number> | infinite ]#",
  2811. "animation-name" : "[ none | <single-animation-name> ]#",
  2812. "animation-play-state" : "[ running | paused ]#",
  2813. "animation-timing-function" : 1,
  2814. //vendor prefixed
  2815. "-moz-animation-delay" : "<time>#",
  2816. "-moz-animation-direction" : "[ normal | alternate ]#",
  2817. "-moz-animation-duration" : "<time>#",
  2818. "-moz-animation-iteration-count" : "[ <number> | infinite ]#",
  2819. "-moz-animation-name" : "[ none | <single-animation-name> ]#",
  2820. "-moz-animation-play-state" : "[ running | paused ]#",
  2821. "-ms-animation-delay" : "<time>#",
  2822. "-ms-animation-direction" : "[ normal | alternate ]#",
  2823. "-ms-animation-duration" : "<time>#",
  2824. "-ms-animation-iteration-count" : "[ <number> | infinite ]#",
  2825. "-ms-animation-name" : "[ none | <single-animation-name> ]#",
  2826. "-ms-animation-play-state" : "[ running | paused ]#",
  2827. "-webkit-animation-delay" : "<time>#",
  2828. "-webkit-animation-direction" : "[ normal | alternate ]#",
  2829. "-webkit-animation-duration" : "<time>#",
  2830. "-webkit-animation-fill-mode" : "[ none | forwards | backwards | both ]#",
  2831. "-webkit-animation-iteration-count" : "[ <number> | infinite ]#",
  2832. "-webkit-animation-name" : "[ none | <single-animation-name> ]#",
  2833. "-webkit-animation-play-state" : "[ running | paused ]#",
  2834. "-o-animation-delay" : "<time>#",
  2835. "-o-animation-direction" : "[ normal | alternate ]#",
  2836. "-o-animation-duration" : "<time>#",
  2837. "-o-animation-iteration-count" : "[ <number> | infinite ]#",
  2838. "-o-animation-name" : "[ none | <single-animation-name> ]#",
  2839. "-o-animation-play-state" : "[ running | paused ]#",
  2840. "appearance" : "none | auto",
  2841. "-moz-appearance" : "none | button | button-arrow-down | button-arrow-next | button-arrow-previous | button-arrow-up | button-bevel | button-focus | caret | checkbox | checkbox-container | checkbox-label | checkmenuitem | dualbutton | groupbox | listbox | listitem | menuarrow | menubar | menucheckbox | menuimage | menuitem | menuitemtext | menulist | menulist-button | menulist-text | menulist-textfield | menupopup | menuradio | menuseparator | meterbar | meterchunk | progressbar | progressbar-vertical | progresschunk | progresschunk-vertical | radio | radio-container | radio-label | radiomenuitem | range | range-thumb | resizer | resizerpanel | scale-horizontal | scalethumbend | scalethumb-horizontal | scalethumbstart | scalethumbtick | scalethumb-vertical | scale-vertical | scrollbarbutton-down | scrollbarbutton-left | scrollbarbutton-right | scrollbarbutton-up | scrollbarthumb-horizontal | scrollbarthumb-vertical | scrollbartrack-horizontal | scrollbartrack-vertical | searchfield | separator | sheet | spinner | spinner-downbutton | spinner-textfield | spinner-upbutton | splitter | statusbar | statusbarpanel | tab | tabpanel | tabpanels | tab-scroll-arrow-back | tab-scroll-arrow-forward | textfield | textfield-multiline | toolbar | toolbarbutton | toolbarbutton-dropdown | toolbargripper | toolbox | tooltip | treeheader | treeheadercell | treeheadersortarrow | treeitem | treeline | treetwisty | treetwistyopen | treeview | -moz-mac-unified-toolbar | -moz-win-borderless-glass | -moz-win-browsertabbar-toolbox | -moz-win-communicationstext | -moz-win-communications-toolbox | -moz-win-exclude-glass | -moz-win-glass | -moz-win-mediatext | -moz-win-media-toolbox | -moz-window-button-box | -moz-window-button-box-maximized | -moz-window-button-close | -moz-window-button-maximize | -moz-window-button-minimize | -moz-window-button-restore | -moz-window-frame-bottom | -moz-window-frame-left | -moz-window-frame-right | -moz-window-titlebar | -moz-window-titlebar-maximized",
  2842. "-ms-appearance" : "none | icon | window | desktop | workspace | document | tooltip | dialog | button | push-button | hyperlink | radio | radio-button | checkbox | menu-item | tab | menu | menubar | pull-down-menu | pop-up-menu | list-menu | radio-group | checkbox-group | outline-tree | range | field | combo-box | signature | password | normal",
  2843. "-webkit-appearance" : "none | button | button-bevel | caps-lock-indicator | caret | checkbox | default-button | listbox | listitem | media-fullscreen-button | media-mute-button | media-play-button | media-seek-back-button | media-seek-forward-button | media-slider | media-sliderthumb | menulist | menulist-button | menulist-text | menulist-textfield | push-button | radio | searchfield | searchfield-cancel-button | searchfield-decoration | searchfield-results-button | searchfield-results-decoration | slider-horizontal | slider-vertical | sliderthumb-horizontal | sliderthumb-vertical | square-button | textarea | textfield | scrollbarbutton-down | scrollbarbutton-left | scrollbarbutton-right | scrollbarbutton-up | scrollbargripper-horizontal | scrollbargripper-vertical | scrollbarthumb-horizontal | scrollbarthumb-vertical | scrollbartrack-horizontal | scrollbartrack-vertical",
  2844. "-o-appearance" : "none | window | desktop | workspace | document | tooltip | dialog | button | push-button | hyperlink | radio | radio-button | checkbox | menu-item | tab | menu | menubar | pull-down-menu | pop-up-menu | list-menu | radio-group | checkbox-group | outline-tree | range | field | combo-box | signature | password | normal",
  2845. "azimuth" : "<azimuth>",
  2846. //B
  2847. "backface-visibility" : "visible | hidden",
  2848. "background" : 1,
  2849. "background-attachment" : "<attachment>#",
  2850. "background-clip" : "<box>#",
  2851. "background-color" : "<color>",
  2852. "background-image" : "<bg-image>#",
  2853. "background-origin" : "<box>#",
  2854. "background-position" : "<bg-position>",
  2855. "background-repeat" : "<repeat-style>#",
  2856. "background-size" : "<bg-size>#",
  2857. "baseline-shift" : "baseline | sub | super | <percentage> | <length>",
  2858. "behavior" : 1,
  2859. "binding" : 1,
  2860. "bleed" : "<length>",
  2861. "bookmark-label" : "<content> | <attr> | <string>",
  2862. "bookmark-level" : "none | <integer>",
  2863. "bookmark-state" : "open | closed",
  2864. "bookmark-target" : "none | <uri> | <attr>",
  2865. "border" : "<border-width> || <border-style> || <color>",
  2866. "border-bottom" : "<border-width> || <border-style> || <color>",
  2867. "border-bottom-color" : "<color>",
  2868. "border-bottom-left-radius" : "<x-one-radius>",
  2869. "border-bottom-right-radius" : "<x-one-radius>",
  2870. "border-bottom-style" : "<border-style>",
  2871. "border-bottom-width" : "<border-width>",
  2872. "border-collapse" : "collapse | separate",
  2873. "border-color" : "<color>{1,4}",
  2874. "border-image" : 1,
  2875. "border-image-outset" : "[ <length> | <number> ]{1,4}",
  2876. "border-image-repeat" : "[ stretch | repeat | round ]{1,2}",
  2877. "border-image-slice" : "<border-image-slice>",
  2878. "border-image-source" : "<image> | none",
  2879. "border-image-width" : "[ <length> | <percentage> | <number> | auto ]{1,4}",
  2880. "border-left" : "<border-width> || <border-style> || <color>",
  2881. "border-left-color" : "<color>",
  2882. "border-left-style" : "<border-style>",
  2883. "border-left-width" : "<border-width>",
  2884. "border-radius" : "<border-radius>",
  2885. "border-right" : "<border-width> || <border-style> || <color>",
  2886. "border-right-color" : "<color>",
  2887. "border-right-style" : "<border-style>",
  2888. "border-right-width" : "<border-width>",
  2889. "border-spacing" : "<length>{1,2}",
  2890. "border-style" : "<border-style>{1,4}",
  2891. "border-top" : "<border-width> || <border-style> || <color>",
  2892. "border-top-color" : "<color>",
  2893. "border-top-left-radius" : "<x-one-radius>",
  2894. "border-top-right-radius" : "<x-one-radius>",
  2895. "border-top-style" : "<border-style>",
  2896. "border-top-width" : "<border-width>",
  2897. "border-width" : "<border-width>{1,4}",
  2898. "bottom" : "<margin-width>",
  2899. "-moz-box-align" : "start | end | center | baseline | stretch",
  2900. "-moz-box-decoration-break" : "slice | clone",
  2901. "-moz-box-direction" : "normal | reverse",
  2902. "-moz-box-flex" : "<number>",
  2903. "-moz-box-flex-group" : "<integer>",
  2904. "-moz-box-lines" : "single | multiple",
  2905. "-moz-box-ordinal-group" : "<integer>",
  2906. "-moz-box-orient" : "horizontal | vertical | inline-axis | block-axis",
  2907. "-moz-box-pack" : "start | end | center | justify",
  2908. "-o-box-decoration-break" : "slice | clone",
  2909. "-webkit-box-align" : "start | end | center | baseline | stretch",
  2910. "-webkit-box-decoration-break" : "slice | clone",
  2911. "-webkit-box-direction" : "normal | reverse",
  2912. "-webkit-box-flex" : "<number>",
  2913. "-webkit-box-flex-group" : "<integer>",
  2914. "-webkit-box-lines" : "single | multiple",
  2915. "-webkit-box-ordinal-group" : "<integer>",
  2916. "-webkit-box-orient" : "horizontal | vertical | inline-axis | block-axis",
  2917. "-webkit-box-pack" : "start | end | center | justify",
  2918. "box-decoration-break" : "slice | clone",
  2919. "box-shadow" : "<box-shadow>",
  2920. "box-sizing" : "content-box | border-box",
  2921. "break-after" : "auto | always | avoid | left | right | page | column | avoid-page | avoid-column",
  2922. "break-before" : "auto | always | avoid | left | right | page | column | avoid-page | avoid-column",
  2923. "break-inside" : "auto | avoid | avoid-page | avoid-column",
  2924. //C
  2925. "caption-side" : "top | bottom",
  2926. "clear" : "none | right | left | both",
  2927. "clip" : "<shape> | auto",
  2928. "-webkit-clip-path" : "<clip-source> | <clip-path> | none",
  2929. "clip-path" : "<clip-source> | <clip-path> | none",
  2930. "clip-rule" : "nonzero | evenodd",
  2931. "color" : "<color>",
  2932. "color-interpolation" : "auto | sRGB | linearRGB",
  2933. "color-interpolation-filters" : "auto | sRGB | linearRGB",
  2934. "color-profile" : 1,
  2935. "color-rendering" : "auto | optimizeSpeed | optimizeQuality",
  2936. "column-count" : "<integer> | auto", //https://www.w3.org/TR/css3-multicol/
  2937. "column-fill" : "auto | balance",
  2938. "column-gap" : "<length> | normal",
  2939. "column-rule" : "<border-width> || <border-style> || <color>",
  2940. "column-rule-color" : "<color>",
  2941. "column-rule-style" : "<border-style>",
  2942. "column-rule-width" : "<border-width>",
  2943. "column-span" : "none | all",
  2944. "column-width" : "<length> | auto",
  2945. "columns" : 1,
  2946. "content" : 1,
  2947. "counter-increment" : 1,
  2948. "counter-reset" : 1,
  2949. "crop" : "<shape> | auto",
  2950. "cue" : "cue-after | cue-before",
  2951. "cue-after" : 1,
  2952. "cue-before" : 1,
  2953. "cursor" : 1,
  2954. //D
  2955. "direction" : "ltr | rtl",
  2956. "display" : "inline | block | list-item | inline-block | table | inline-table | table-row-group | table-header-group | table-footer-group | table-row | table-column-group | table-column | table-cell | table-caption | grid | inline-grid | run-in | ruby | ruby-base | ruby-text | ruby-base-container | ruby-text-container | contents | none | -moz-box | -moz-inline-block | -moz-inline-box | -moz-inline-grid | -moz-inline-stack | -moz-inline-table | -moz-grid | -moz-grid-group | -moz-grid-line | -moz-groupbox | -moz-deck | -moz-popup | -moz-stack | -moz-marker | -webkit-box | -webkit-inline-box | -ms-flexbox | -ms-inline-flexbox | flex | -webkit-flex | inline-flex | -webkit-inline-flex",
  2957. "dominant-baseline" : "auto | use-script | no-change | reset-size | ideographic | alphabetic | hanging | mathematical | central | middle | text-after-edge | text-before-edge",
  2958. "drop-initial-after-adjust" : "central | middle | after-edge | text-after-edge | ideographic | alphabetic | mathematical | <percentage> | <length>",
  2959. "drop-initial-after-align" : "baseline | use-script | before-edge | text-before-edge | after-edge | text-after-edge | central | middle | ideographic | alphabetic | hanging | mathematical",
  2960. "drop-initial-before-adjust" : "before-edge | text-before-edge | central | middle | hanging | mathematical | <percentage> | <length>",
  2961. "drop-initial-before-align" : "caps-height | baseline | use-script | before-edge | text-before-edge | after-edge | text-after-edge | central | middle | ideographic | alphabetic | hanging | mathematical",
  2962. "drop-initial-size" : "auto | line | <length> | <percentage>",
  2963. "drop-initial-value" : "<integer>",
  2964. //E
  2965. "elevation" : "<angle> | below | level | above | higher | lower",
  2966. "empty-cells" : "show | hide",
  2967. "enable-background" : 1,
  2968. //F
  2969. "fill" : "<paint>",
  2970. "fill-opacity" : "<opacity-value>",
  2971. "fill-rule" : "nonzero | evenodd",
  2972. "filter" : "<filter-function-list> | none",
  2973. "fit" : "fill | hidden | meet | slice",
  2974. "fit-position" : 1,
  2975. "flex" : "<flex>",
  2976. "flex-basis" : "<width>",
  2977. "flex-direction" : "row | row-reverse | column | column-reverse",
  2978. "flex-flow" : "<flex-direction> || <flex-wrap>",
  2979. "flex-grow" : "<number>",
  2980. "flex-shrink" : "<number>",
  2981. "flex-wrap" : "nowrap | wrap | wrap-reverse",
  2982. "-webkit-flex" : "<flex>",
  2983. "-webkit-flex-basis" : "<width>",
  2984. "-webkit-flex-direction" : "row | row-reverse | column | column-reverse",
  2985. "-webkit-flex-flow" : "<flex-direction> || <flex-wrap>",
  2986. "-webkit-flex-grow" : "<number>",
  2987. "-webkit-flex-shrink" : "<number>",
  2988. "-webkit-flex-wrap" : "nowrap | wrap | wrap-reverse",
  2989. "-ms-flex" : "<flex>",
  2990. "-ms-flex-align" : "start | end | center | stretch | baseline",
  2991. "-ms-flex-direction" : "row | row-reverse | column | column-reverse",
  2992. "-ms-flex-order" : "<number>",
  2993. "-ms-flex-pack" : "start | end | center | justify",
  2994. "-ms-flex-wrap" : "nowrap | wrap | wrap-reverse",
  2995. "float" : "left | right | none",
  2996. "float-offset" : 1,
  2997. "flood-color" : 1,
  2998. "flood-opacity" : "<opacity-value>",
  2999. "font" : "<font-shorthand> | caption | icon | menu | message-box | small-caption | status-bar",
  3000. "font-family" : "<font-family>",
  3001. "font-feature-settings" : "<feature-tag-value> | normal",
  3002. "font-kerning" : "auto | normal | none",
  3003. "font-size" : "<font-size>",
  3004. "font-size-adjust" : "<number> | none",
  3005. "font-stretch" : "<font-stretch>",
  3006. "font-style" : "<font-style>",
  3007. "font-variant" : "<font-variant> | normal | none",
  3008. "font-variant-alternates" : "<font-variant-alternates> | normal",
  3009. "font-variant-caps" : "<font-variant-caps> | normal",
  3010. "font-variant-east-asian" : "<font-variant-east-asian> | normal",
  3011. "font-variant-ligatures" : "<font-variant-ligatures> | normal | none",
  3012. "font-variant-numeric" : "<font-variant-numeric> | normal",
  3013. "font-variant-position" : "normal | sub | super",
  3014. "font-weight" : "<font-weight>",
  3015. //G
  3016. "glyph-orientation-horizontal" : "<glyph-angle>",
  3017. "glyph-orientation-vertical" : "auto | <glyph-angle>",
  3018. "grid" : 1,
  3019. "grid-area" : 1,
  3020. "grid-auto-columns" : 1,
  3021. "grid-auto-flow" : 1,
  3022. "grid-auto-position" : 1,
  3023. "grid-auto-rows" : 1,
  3024. "grid-cell-stacking" : "columns | rows | layer",
  3025. "grid-column" : 1,
  3026. "grid-columns" : 1,
  3027. "grid-column-align" : "start | end | center | stretch",
  3028. "grid-column-sizing" : 1,
  3029. "grid-column-start" : 1,
  3030. "grid-column-end" : 1,
  3031. "grid-column-span" : "<integer>",
  3032. "grid-flow" : "none | rows | columns",
  3033. "grid-layer" : "<integer>",
  3034. "grid-row" : 1,
  3035. "grid-rows" : 1,
  3036. "grid-row-align" : "start | end | center | stretch",
  3037. "grid-row-start" : 1,
  3038. "grid-row-end" : 1,
  3039. "grid-row-span" : "<integer>",
  3040. "grid-row-sizing" : 1,
  3041. "grid-template" : 1,
  3042. "grid-template-areas" : 1,
  3043. "grid-template-columns" : 1,
  3044. "grid-template-rows" : 1,
  3045. //H
  3046. "hanging-punctuation" : 1,
  3047. "height" : "<margin-width> | <content-sizing>",
  3048. "hyphenate-after" : "<integer> | auto",
  3049. "hyphenate-before" : "<integer> | auto",
  3050. "hyphenate-character" : "<string> | auto",
  3051. "hyphenate-lines" : "no-limit | <integer>",
  3052. "hyphenate-resource" : 1,
  3053. "hyphens" : "none | manual | auto",
  3054. //I
  3055. "icon" : 1,
  3056. "image-orientation" : "angle | auto",
  3057. "image-rendering" : "auto | optimizeSpeed | optimizeQuality",
  3058. "image-resolution" : 1,
  3059. "ime-mode" : "auto | normal | active | inactive | disabled",
  3060. "inline-box-align" : "last | <integer>",
  3061. //J
  3062. "justify-content" : "flex-start | flex-end | center | space-between | space-around",
  3063. "-webkit-justify-content" : "flex-start | flex-end | center | space-between | space-around",
  3064. //K
  3065. "kerning" : "auto | <length>",
  3066. //L
  3067. "left" : "<margin-width>",
  3068. "letter-spacing" : "<length> | normal",
  3069. "line-height" : "<line-height>",
  3070. "line-break" : "auto | loose | normal | strict",
  3071. "line-stacking" : 1,
  3072. "line-stacking-ruby" : "exclude-ruby | include-ruby",
  3073. "line-stacking-shift" : "consider-shifts | disregard-shifts",
  3074. "line-stacking-strategy" : "inline-line-height | block-line-height | max-height | grid-height",
  3075. "list-style" : 1,
  3076. "list-style-image" : "<uri> | none",
  3077. "list-style-position" : "inside | outside",
  3078. "list-style-type" : "disc | circle | square | decimal | decimal-leading-zero | lower-roman | upper-roman | lower-greek | lower-latin | upper-latin | armenian | georgian | lower-alpha | upper-alpha | none",
  3079. //M
  3080. "margin" : "<margin-width>{1,4}",
  3081. "margin-bottom" : "<margin-width>",
  3082. "margin-left" : "<margin-width>",
  3083. "margin-right" : "<margin-width>",
  3084. "margin-top" : "<margin-width>",
  3085. "mark" : 1,
  3086. "mark-after" : 1,
  3087. "mark-before" : 1,
  3088. "marker" : 1,
  3089. "marker-end" : 1,
  3090. "marker-mid" : 1,
  3091. "marker-start" : 1,
  3092. "marks" : 1,
  3093. "marquee-direction" : 1,
  3094. "marquee-play-count" : 1,
  3095. "marquee-speed" : 1,
  3096. "marquee-style" : 1,
  3097. "mask" : 1,
  3098. "max-height" : "<length> | <percentage> | <content-sizing> | none",
  3099. "max-width" : "<length> | <percentage> | <content-sizing> | none",
  3100. "min-height" : "<length> | <percentage> | <content-sizing> | contain-floats | -moz-contain-floats | -webkit-contain-floats",
  3101. "min-width" : "<length> | <percentage> | <content-sizing> | contain-floats | -moz-contain-floats | -webkit-contain-floats",
  3102. "move-to" : 1,
  3103. //N
  3104. "nav-down" : 1,
  3105. "nav-index" : 1,
  3106. "nav-left" : 1,
  3107. "nav-right" : 1,
  3108. "nav-up" : 1,
  3109. //O
  3110. "object-fit" : "fill | contain | cover | none | scale-down",
  3111. "object-position" : "<position>",
  3112. "opacity" : "<opacity-value>",
  3113. "order" : "<integer>",
  3114. "-webkit-order" : "<integer>",
  3115. "orphans" : "<integer>",
  3116. "outline" : 1,
  3117. "outline-color" : "<color> | invert",
  3118. "outline-offset" : 1,
  3119. "outline-style" : "<border-style>",
  3120. "outline-width" : "<border-width>",
  3121. "overflow" : "visible | hidden | scroll | auto",
  3122. "overflow-style" : 1,
  3123. "overflow-wrap" : "normal | break-word",
  3124. "overflow-x" : 1,
  3125. "overflow-y" : 1,
  3126. //P
  3127. "padding" : "<padding-width>{1,4}",
  3128. "padding-bottom" : "<padding-width>",
  3129. "padding-left" : "<padding-width>",
  3130. "padding-right" : "<padding-width>",
  3131. "padding-top" : "<padding-width>",
  3132. "page" : 1,
  3133. "page-break-after" : "auto | always | avoid | left | right",
  3134. "page-break-before" : "auto | always | avoid | left | right",
  3135. "page-break-inside" : "auto | avoid",
  3136. "page-policy" : 1,
  3137. "pause" : 1,
  3138. "pause-after" : 1,
  3139. "pause-before" : 1,
  3140. "perspective" : 1,
  3141. "perspective-origin" : 1,
  3142. "phonemes" : 1,
  3143. "pitch" : 1,
  3144. "pitch-range" : 1,
  3145. "play-during" : 1,
  3146. "pointer-events" : "auto | none | visiblePainted | visibleFill | visibleStroke | visible | painted | fill | stroke | all",
  3147. "position" : "static | relative | absolute | fixed",
  3148. "presentation-level" : 1,
  3149. "punctuation-trim" : 1,
  3150. //Q
  3151. "quotes" : 1,
  3152. //R
  3153. "rendering-intent" : 1,
  3154. "resize" : 1,
  3155. "rest" : 1,
  3156. "rest-after" : 1,
  3157. "rest-before" : 1,
  3158. "richness" : 1,
  3159. "right" : "<margin-width>",
  3160. "rotation" : 1,
  3161. "rotation-point" : 1,
  3162. "ruby-align" : 1,
  3163. "ruby-overhang" : 1,
  3164. "ruby-position" : 1,
  3165. "ruby-span" : 1,
  3166. //S
  3167. "shape-rendering" : "auto | optimizeSpeed | crispEdges | geometricPrecision",
  3168. "size" : 1,
  3169. "speak" : "normal | none | spell-out",
  3170. "speak-header" : "once | always",
  3171. "speak-numeral" : "digits | continuous",
  3172. "speak-punctuation" : "code | none",
  3173. "speech-rate" : 1,
  3174. "src" : 1,
  3175. "stop-color" : 1,
  3176. "stop-opacity" : "<opacity-value>",
  3177. "stress" : 1,
  3178. "string-set" : 1,
  3179. "stroke" : "<paint>",
  3180. "stroke-dasharray" : "none | <dasharray>",
  3181. "stroke-dashoffset" : "<percentage> | <length>",
  3182. "stroke-linecap" : "butt | round | square",
  3183. "stroke-linejoin" : "miter | round | bevel",
  3184. "stroke-miterlimit" : "<miterlimit>",
  3185. "stroke-opacity" : "<opacity-value>",
  3186. "stroke-width" : "<percentage> | <length>",
  3187. "table-layout" : "auto | fixed",
  3188. "tab-size" : "<integer> | <length>",
  3189. "target" : 1,
  3190. "target-name" : 1,
  3191. "target-new" : 1,
  3192. "target-position" : 1,
  3193. "text-align" : "left | right | center | justify | match-parent | start | end",
  3194. "text-align-last" : 1,
  3195. "text-anchor" : "start | middle | end",
  3196. "text-decoration" : "<text-decoration-line> || <text-decoration-style> || <text-decoration-color>",
  3197. "text-decoration-color" : "<text-decoration-color>",
  3198. "text-decoration-line" : "<text-decoration-line>",
  3199. "text-decoration-style" : "<text-decoration-style>",
  3200. "text-emphasis" : 1,
  3201. "text-height" : 1,
  3202. "text-indent" : "<length> | <percentage>",
  3203. "text-justify" : "auto | none | inter-word | inter-ideograph | inter-cluster | distribute | kashida",
  3204. "text-outline" : 1,
  3205. "text-overflow" : 1,
  3206. "text-rendering" : "auto | optimizeSpeed | optimizeLegibility | geometricPrecision",
  3207. "text-shadow" : 1,
  3208. "text-transform" : "capitalize | uppercase | lowercase | none",
  3209. "text-wrap" : "normal | none | avoid",
  3210. "top" : "<margin-width>",
  3211. "-ms-touch-action" : "auto | none | pan-x | pan-y | pan-left | pan-right | pan-up | pan-down | manipulation",
  3212. "touch-action" : "auto | none | pan-x | pan-y | pan-left | pan-right | pan-up | pan-down | manipulation",
  3213. "transform" : 1,
  3214. "transform-origin" : 1,
  3215. "transform-style" : 1,
  3216. "transition" : 1,
  3217. "transition-delay" : 1,
  3218. "transition-duration" : 1,
  3219. "transition-property" : 1,
  3220. "transition-timing-function" : 1,
  3221. //U
  3222. "unicode-bidi" : "normal | embed | isolate | bidi-override | isolate-override | plaintext",
  3223. "user-modify" : "read-only | read-write | write-only",
  3224. "user-select" : "none | text | toggle | element | elements | all",
  3225. //V
  3226. "vertical-align" : "auto | use-script | baseline | sub | super | top | text-top | central | middle | bottom | text-bottom | <percentage> | <length>",
  3227. "visibility" : "visible | hidden | collapse",
  3228. "voice-balance" : 1,
  3229. "voice-duration" : 1,
  3230. "voice-family" : 1,
  3231. "voice-pitch" : 1,
  3232. "voice-pitch-range" : 1,
  3233. "voice-rate" : 1,
  3234. "voice-stress" : 1,
  3235. "voice-volume" : 1,
  3236. "volume" : 1,
  3237. //W
  3238. "white-space" : "normal | pre | nowrap | pre-wrap | pre-line | -pre-wrap | -o-pre-wrap | -moz-pre-wrap | -hp-pre-wrap", // https://perishablepress.com/wrapping-content/
  3239. "white-space-collapse" : 1,
  3240. "widows" : "<integer>",
  3241. "width" : "<length> | <percentage> | <content-sizing> | auto",
  3242. "will-change" : "<will-change>",
  3243. "word-break" : "normal | keep-all | break-all",
  3244. "word-spacing" : "<length> | normal",
  3245. "word-wrap" : "normal | break-word",
  3246. "writing-mode" : "horizontal-tb | vertical-rl | vertical-lr | lr-tb | rl-tb | tb-rl | bt-rl | tb-lr | bt-lr | lr-bt | rl-bt | lr | rl | tb",
  3247. //Z
  3248. "z-index" : "<integer> | auto",
  3249. "zoom" : "<number> | <percentage> | normal"
  3250. };
  3251. },{}],8:[function(require,module,exports){
  3252. "use strict";
  3253. module.exports = PropertyName;
  3254. var SyntaxUnit = require("../util/SyntaxUnit");
  3255. var Parser = require("./Parser");
  3256. /**
  3257. * Represents a selector combinator (whitespace, +, >).
  3258. * @namespace parserlib.css
  3259. * @class PropertyName
  3260. * @extends parserlib.util.SyntaxUnit
  3261. * @constructor
  3262. * @param {String} text The text representation of the unit.
  3263. * @param {String} hack The type of IE hack applied ("*", "_", or null).
  3264. * @param {int} line The line of text on which the unit resides.
  3265. * @param {int} col The column of text on which the unit resides.
  3266. */
  3267. function PropertyName(text, hack, line, col) {
  3268. SyntaxUnit.call(this, text, line, col, Parser.PROPERTY_NAME_TYPE);
  3269. /**
  3270. * The type of IE hack applied ("*", "_", or null).
  3271. * @type String
  3272. * @property hack
  3273. */
  3274. this.hack = hack;
  3275. }
  3276. PropertyName.prototype = new SyntaxUnit();
  3277. PropertyName.prototype.constructor = PropertyName;
  3278. PropertyName.prototype.toString = function() {
  3279. return (this.hack ? this.hack : "") + this.text;
  3280. };
  3281. },{"../util/SyntaxUnit":26,"./Parser":6}],9:[function(require,module,exports){
  3282. "use strict";
  3283. module.exports = PropertyValue;
  3284. var SyntaxUnit = require("../util/SyntaxUnit");
  3285. var Parser = require("./Parser");
  3286. /**
  3287. * Represents a single part of a CSS property value, meaning that it represents
  3288. * just everything single part between ":" and ";". If there are multiple values
  3289. * separated by commas, this type represents just one of the values.
  3290. * @param {String[]} parts An array of value parts making up this value.
  3291. * @param {int} line The line of text on which the unit resides.
  3292. * @param {int} col The column of text on which the unit resides.
  3293. * @namespace parserlib.css
  3294. * @class PropertyValue
  3295. * @extends parserlib.util.SyntaxUnit
  3296. * @constructor
  3297. */
  3298. function PropertyValue(parts, line, col) {
  3299. SyntaxUnit.call(this, parts.join(" "), line, col, Parser.PROPERTY_VALUE_TYPE);
  3300. /**
  3301. * The parts that make up the selector.
  3302. * @type Array
  3303. * @property parts
  3304. */
  3305. this.parts = parts;
  3306. }
  3307. PropertyValue.prototype = new SyntaxUnit();
  3308. PropertyValue.prototype.constructor = PropertyValue;
  3309. },{"../util/SyntaxUnit":26,"./Parser":6}],10:[function(require,module,exports){
  3310. "use strict";
  3311. module.exports = PropertyValueIterator;
  3312. /**
  3313. * A utility class that allows for easy iteration over the various parts of a
  3314. * property value.
  3315. * @param {parserlib.css.PropertyValue} value The property value to iterate over.
  3316. * @namespace parserlib.css
  3317. * @class PropertyValueIterator
  3318. * @constructor
  3319. */
  3320. function PropertyValueIterator(value) {
  3321. /**
  3322. * Iterator value
  3323. * @type int
  3324. * @property _i
  3325. * @private
  3326. */
  3327. this._i = 0;
  3328. /**
  3329. * The parts that make up the value.
  3330. * @type Array
  3331. * @property _parts
  3332. * @private
  3333. */
  3334. this._parts = value.parts;
  3335. /**
  3336. * Keeps track of bookmarks along the way.
  3337. * @type Array
  3338. * @property _marks
  3339. * @private
  3340. */
  3341. this._marks = [];
  3342. /**
  3343. * Holds the original property value.
  3344. * @type parserlib.css.PropertyValue
  3345. * @property value
  3346. */
  3347. this.value = value;
  3348. }
  3349. /**
  3350. * Returns the total number of parts in the value.
  3351. * @return {int} The total number of parts in the value.
  3352. * @method count
  3353. */
  3354. PropertyValueIterator.prototype.count = function() {
  3355. return this._parts.length;
  3356. };
  3357. /**
  3358. * Indicates if the iterator is positioned at the first item.
  3359. * @return {Boolean} True if positioned at first item, false if not.
  3360. * @method isFirst
  3361. */
  3362. PropertyValueIterator.prototype.isFirst = function() {
  3363. return this._i === 0;
  3364. };
  3365. /**
  3366. * Indicates if there are more parts of the property value.
  3367. * @return {Boolean} True if there are more parts, false if not.
  3368. * @method hasNext
  3369. */
  3370. PropertyValueIterator.prototype.hasNext = function() {
  3371. return this._i < this._parts.length;
  3372. };
  3373. /**
  3374. * Marks the current spot in the iteration so it can be restored to
  3375. * later on.
  3376. * @return {void}
  3377. * @method mark
  3378. */
  3379. PropertyValueIterator.prototype.mark = function() {
  3380. this._marks.push(this._i);
  3381. };
  3382. /**
  3383. * Returns the next part of the property value or null if there is no next
  3384. * part. Does not move the internal counter forward.
  3385. * @return {parserlib.css.PropertyValuePart} The next part of the property value or null if there is no next
  3386. * part.
  3387. * @method peek
  3388. */
  3389. PropertyValueIterator.prototype.peek = function(count) {
  3390. return this.hasNext() ? this._parts[this._i + (count || 0)] : null;
  3391. };
  3392. /**
  3393. * Returns the next part of the property value or null if there is no next
  3394. * part.
  3395. * @return {parserlib.css.PropertyValuePart} The next part of the property value or null if there is no next
  3396. * part.
  3397. * @method next
  3398. */
  3399. PropertyValueIterator.prototype.next = function() {
  3400. return this.hasNext() ? this._parts[this._i++] : null;
  3401. };
  3402. /**
  3403. * Returns the previous part of the property value or null if there is no
  3404. * previous part.
  3405. * @return {parserlib.css.PropertyValuePart} The previous part of the
  3406. * property value or null if there is no previous part.
  3407. * @method previous
  3408. */
  3409. PropertyValueIterator.prototype.previous = function() {
  3410. return this._i > 0 ? this._parts[--this._i] : null;
  3411. };
  3412. /**
  3413. * Restores the last saved bookmark.
  3414. * @return {void}
  3415. * @method restore
  3416. */
  3417. PropertyValueIterator.prototype.restore = function() {
  3418. if (this._marks.length) {
  3419. this._i = this._marks.pop();
  3420. }
  3421. };
  3422. /**
  3423. * Drops the last saved bookmark.
  3424. * @return {void}
  3425. * @method drop
  3426. */
  3427. PropertyValueIterator.prototype.drop = function() {
  3428. this._marks.pop();
  3429. };
  3430. },{}],11:[function(require,module,exports){
  3431. "use strict";
  3432. module.exports = PropertyValuePart;
  3433. var SyntaxUnit = require("../util/SyntaxUnit");
  3434. var Colors = require("./Colors");
  3435. var Parser = require("./Parser");
  3436. var Tokens = require("./Tokens");
  3437. /**
  3438. * Represents a single part of a CSS property value, meaning that it represents
  3439. * just one part of the data between ":" and ";".
  3440. * @param {String} text The text representation of the unit.
  3441. * @param {int} line The line of text on which the unit resides.
  3442. * @param {int} col The column of text on which the unit resides.
  3443. * @namespace parserlib.css
  3444. * @class PropertyValuePart
  3445. * @extends parserlib.util.SyntaxUnit
  3446. * @constructor
  3447. */
  3448. function PropertyValuePart(text, line, col, optionalHint) {
  3449. var hint = optionalHint || {};
  3450. SyntaxUnit.call(this, text, line, col, Parser.PROPERTY_VALUE_PART_TYPE);
  3451. /**
  3452. * Indicates the type of value unit.
  3453. * @type String
  3454. * @property type
  3455. */
  3456. this.type = "unknown";
  3457. //figure out what type of data it is
  3458. var temp;
  3459. //it is a measurement?
  3460. if (/^([+\-]?[\d\.]+)([a-z]+)$/i.test(text)) { //dimension
  3461. this.type = "dimension";
  3462. this.value = +RegExp.$1;
  3463. this.units = RegExp.$2;
  3464. //try to narrow down
  3465. switch (this.units.toLowerCase()) {
  3466. case "em":
  3467. case "rem":
  3468. case "ex":
  3469. case "px":
  3470. case "cm":
  3471. case "mm":
  3472. case "in":
  3473. case "pt":
  3474. case "pc":
  3475. case "ch":
  3476. case "vh":
  3477. case "vw":
  3478. case "vmax":
  3479. case "vmin":
  3480. this.type = "length";
  3481. break;
  3482. case "fr":
  3483. this.type = "grid";
  3484. break;
  3485. case "deg":
  3486. case "rad":
  3487. case "grad":
  3488. case "turn":
  3489. this.type = "angle";
  3490. break;
  3491. case "ms":
  3492. case "s":
  3493. this.type = "time";
  3494. break;
  3495. case "hz":
  3496. case "khz":
  3497. this.type = "frequency";
  3498. break;
  3499. case "dpi":
  3500. case "dpcm":
  3501. this.type = "resolution";
  3502. break;
  3503. //default
  3504. }
  3505. } else if (/^([+\-]?[\d\.]+)%$/i.test(text)) { //percentage
  3506. this.type = "percentage";
  3507. this.value = +RegExp.$1;
  3508. } else if (/^([+\-]?\d+)$/i.test(text)) { //integer
  3509. this.type = "integer";
  3510. this.value = +RegExp.$1;
  3511. } else if (/^([+\-]?[\d\.]+)$/i.test(text)) { //number
  3512. this.type = "number";
  3513. this.value = +RegExp.$1;
  3514. } else if (/^#([a-f0-9]{3,6})/i.test(text)) { //hexcolor
  3515. this.type = "color";
  3516. temp = RegExp.$1;
  3517. if (temp.length === 3) {
  3518. this.red = parseInt(temp.charAt(0)+temp.charAt(0), 16);
  3519. this.green = parseInt(temp.charAt(1)+temp.charAt(1), 16);
  3520. this.blue = parseInt(temp.charAt(2)+temp.charAt(2), 16);
  3521. } else {
  3522. this.red = parseInt(temp.substring(0, 2), 16);
  3523. this.green = parseInt(temp.substring(2, 4), 16);
  3524. this.blue = parseInt(temp.substring(4, 6), 16);
  3525. }
  3526. } else if (/^rgb\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)/i.test(text)) { //rgb() color with absolute numbers
  3527. this.type = "color";
  3528. this.red = +RegExp.$1;
  3529. this.green = +RegExp.$2;
  3530. this.blue = +RegExp.$3;
  3531. } else if (/^rgb\(\s*(\d+)%\s*,\s*(\d+)%\s*,\s*(\d+)%\s*\)/i.test(text)) { //rgb() color with percentages
  3532. this.type = "color";
  3533. this.red = +RegExp.$1 * 255 / 100;
  3534. this.green = +RegExp.$2 * 255 / 100;
  3535. this.blue = +RegExp.$3 * 255 / 100;
  3536. } else if (/^rgba\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*,\s*([\d\.]+)\s*\)/i.test(text)) { //rgba() color with absolute numbers
  3537. this.type = "color";
  3538. this.red = +RegExp.$1;
  3539. this.green = +RegExp.$2;
  3540. this.blue = +RegExp.$3;
  3541. this.alpha = +RegExp.$4;
  3542. } else if (/^rgba\(\s*(\d+)%\s*,\s*(\d+)%\s*,\s*(\d+)%\s*,\s*([\d\.]+)\s*\)/i.test(text)) { //rgba() color with percentages
  3543. this.type = "color";
  3544. this.red = +RegExp.$1 * 255 / 100;
  3545. this.green = +RegExp.$2 * 255 / 100;
  3546. this.blue = +RegExp.$3 * 255 / 100;
  3547. this.alpha = +RegExp.$4;
  3548. } else if (/^hsl\(\s*(\d+)\s*,\s*(\d+)%\s*,\s*(\d+)%\s*\)/i.test(text)) { //hsl()
  3549. this.type = "color";
  3550. this.hue = +RegExp.$1;
  3551. this.saturation = +RegExp.$2 / 100;
  3552. this.lightness = +RegExp.$3 / 100;
  3553. } else if (/^hsla\(\s*(\d+)\s*,\s*(\d+)%\s*,\s*(\d+)%\s*,\s*([\d\.]+)\s*\)/i.test(text)) { //hsla() color with percentages
  3554. this.type = "color";
  3555. this.hue = +RegExp.$1;
  3556. this.saturation = +RegExp.$2 / 100;
  3557. this.lightness = +RegExp.$3 / 100;
  3558. this.alpha = +RegExp.$4;
  3559. } else if (/^url\(("([^\\"]|\\.)*")\)/i.test(text)) { //URI
  3560. // generated by TokenStream.readURI, so always double-quoted.
  3561. this.type = "uri";
  3562. this.uri = PropertyValuePart.parseString(RegExp.$1);
  3563. } else if (/^([^\(]+)\(/i.test(text)) {
  3564. this.type = "function";
  3565. this.name = RegExp.$1;
  3566. this.value = text;
  3567. } else if (/^"([^\n\r\f\\"]|\\\r\n|\\[^\r0-9a-f]|\\[0-9a-f]{1,6}(\r\n|[ \n\r\t\f])?)*"/i.test(text)) { //double-quoted string
  3568. this.type = "string";
  3569. this.value = PropertyValuePart.parseString(text);
  3570. } else if (/^'([^\n\r\f\\']|\\\r\n|\\[^\r0-9a-f]|\\[0-9a-f]{1,6}(\r\n|[ \n\r\t\f])?)*'/i.test(text)) { //single-quoted string
  3571. this.type = "string";
  3572. this.value = PropertyValuePart.parseString(text);
  3573. } else if (Colors[text.toLowerCase()]) { //named color
  3574. this.type = "color";
  3575. temp = Colors[text.toLowerCase()].substring(1);
  3576. this.red = parseInt(temp.substring(0, 2), 16);
  3577. this.green = parseInt(temp.substring(2, 4), 16);
  3578. this.blue = parseInt(temp.substring(4, 6), 16);
  3579. } else if (/^[,\/]$/.test(text)) {
  3580. this.type = "operator";
  3581. this.value = text;
  3582. } else if (/^-?[a-z_\u00A0-\uFFFF][a-z0-9\-_\u00A0-\uFFFF]*$/i.test(text)) {
  3583. this.type = "identifier";
  3584. this.value = text;
  3585. }
  3586. // There can be ambiguity with escape sequences in identifiers, as
  3587. // well as with "color" parts which are also "identifiers", so record
  3588. // an explicit hint when the token generating this PropertyValuePart
  3589. // was an identifier.
  3590. this.wasIdent = Boolean(hint.ident);
  3591. }
  3592. PropertyValuePart.prototype = new SyntaxUnit();
  3593. PropertyValuePart.prototype.constructor = PropertyValuePart;
  3594. /**
  3595. * Helper method to parse a CSS string.
  3596. */
  3597. PropertyValuePart.parseString = function(str) {
  3598. str = str.slice(1, -1); // Strip surrounding single/double quotes
  3599. var replacer = function(match, esc) {
  3600. if (/^(\n|\r\n|\r|\f)$/.test(esc)) {
  3601. return "";
  3602. }
  3603. var m = /^[0-9a-f]{1,6}/i.exec(esc);
  3604. if (m) {
  3605. var codePoint = parseInt(m[0], 16);
  3606. if (String.fromCodePoint) {
  3607. return String.fromCodePoint(codePoint);
  3608. } else {
  3609. // XXX No support for surrogates on old JavaScript engines.
  3610. return String.fromCharCode(codePoint);
  3611. }
  3612. }
  3613. return esc;
  3614. };
  3615. return str.replace(/\\(\r\n|[^\r0-9a-f]|[0-9a-f]{1,6}(\r\n|[ \n\r\t\f])?)/ig,
  3616. replacer);
  3617. };
  3618. /**
  3619. * Helper method to serialize a CSS string.
  3620. */
  3621. PropertyValuePart.serializeString = function(value) {
  3622. var replacer = function(match, c) {
  3623. if (c === "\"") {
  3624. return "\\" + c;
  3625. }
  3626. var cp = String.codePointAt ? String.codePointAt(0) :
  3627. // We only escape non-surrogate chars, so using charCodeAt
  3628. // is harmless here.
  3629. String.charCodeAt(0);
  3630. return "\\" + cp.toString(16) + " ";
  3631. };
  3632. return "\"" + value.replace(/["\r\n\f]/g, replacer) + "\"";
  3633. };
  3634. /**
  3635. * Create a new syntax unit based solely on the given token.
  3636. * Convenience method for creating a new syntax unit when
  3637. * it represents a single token instead of multiple.
  3638. * @param {Object} token The token object to represent.
  3639. * @return {parserlib.css.PropertyValuePart} The object representing the token.
  3640. * @static
  3641. * @method fromToken
  3642. */
  3643. PropertyValuePart.fromToken = function(token) {
  3644. var part = new PropertyValuePart(token.value, token.startLine, token.startCol, {
  3645. // Tokens can have escaped characters that would fool the type
  3646. // identification in the PropertyValuePart constructor, so pass
  3647. // in a hint if this was an identifier.
  3648. ident: token.type === Tokens.IDENT
  3649. });
  3650. return part;
  3651. };
  3652. },{"../util/SyntaxUnit":26,"./Colors":1,"./Parser":6,"./Tokens":18}],12:[function(require,module,exports){
  3653. "use strict";
  3654. var Pseudos = module.exports = {
  3655. __proto__: null,
  3656. ":first-letter": 1,
  3657. ":first-line": 1,
  3658. ":before": 1,
  3659. ":after": 1
  3660. };
  3661. Pseudos.ELEMENT = 1;
  3662. Pseudos.CLASS = 2;
  3663. Pseudos.isElement = function(pseudo) {
  3664. return pseudo.indexOf("::") === 0 || Pseudos[pseudo.toLowerCase()] === Pseudos.ELEMENT;
  3665. };
  3666. },{}],13:[function(require,module,exports){
  3667. "use strict";
  3668. module.exports = Selector;
  3669. var SyntaxUnit = require("../util/SyntaxUnit");
  3670. var Parser = require("./Parser");
  3671. var Specificity = require("./Specificity");
  3672. /**
  3673. * Represents an entire single selector, including all parts but not
  3674. * including multiple selectors (those separated by commas).
  3675. * @namespace parserlib.css
  3676. * @class Selector
  3677. * @extends parserlib.util.SyntaxUnit
  3678. * @constructor
  3679. * @param {Array} parts Array of selectors parts making up this selector.
  3680. * @param {int} line The line of text on which the unit resides.
  3681. * @param {int} col The column of text on which the unit resides.
  3682. */
  3683. function Selector(parts, line, col) {
  3684. SyntaxUnit.call(this, parts.join(" "), line, col, Parser.SELECTOR_TYPE);
  3685. /**
  3686. * The parts that make up the selector.
  3687. * @type Array
  3688. * @property parts
  3689. */
  3690. this.parts = parts;
  3691. /**
  3692. * The specificity of the selector.
  3693. * @type parserlib.css.Specificity
  3694. * @property specificity
  3695. */
  3696. this.specificity = Specificity.calculate(this);
  3697. }
  3698. Selector.prototype = new SyntaxUnit();
  3699. Selector.prototype.constructor = Selector;
  3700. },{"../util/SyntaxUnit":26,"./Parser":6,"./Specificity":16}],14:[function(require,module,exports){
  3701. "use strict";
  3702. module.exports = SelectorPart;
  3703. var SyntaxUnit = require("../util/SyntaxUnit");
  3704. var Parser = require("./Parser");
  3705. /**
  3706. * Represents a single part of a selector string, meaning a single set of
  3707. * element name and modifiers. This does not include combinators such as
  3708. * spaces, +, >, etc.
  3709. * @namespace parserlib.css
  3710. * @class SelectorPart
  3711. * @extends parserlib.util.SyntaxUnit
  3712. * @constructor
  3713. * @param {String} elementName The element name in the selector or null
  3714. * if there is no element name.
  3715. * @param {Array} modifiers Array of individual modifiers for the element.
  3716. * May be empty if there are none.
  3717. * @param {String} text The text representation of the unit.
  3718. * @param {int} line The line of text on which the unit resides.
  3719. * @param {int} col The column of text on which the unit resides.
  3720. */
  3721. function SelectorPart(elementName, modifiers, text, line, col) {
  3722. SyntaxUnit.call(this, text, line, col, Parser.SELECTOR_PART_TYPE);
  3723. /**
  3724. * The tag name of the element to which this part
  3725. * of the selector affects.
  3726. * @type String
  3727. * @property elementName
  3728. */
  3729. this.elementName = elementName;
  3730. /**
  3731. * The parts that come after the element name, such as class names, IDs,
  3732. * pseudo classes/elements, etc.
  3733. * @type Array
  3734. * @property modifiers
  3735. */
  3736. this.modifiers = modifiers;
  3737. }
  3738. SelectorPart.prototype = new SyntaxUnit();
  3739. SelectorPart.prototype.constructor = SelectorPart;
  3740. },{"../util/SyntaxUnit":26,"./Parser":6}],15:[function(require,module,exports){
  3741. "use strict";
  3742. module.exports = SelectorSubPart;
  3743. var SyntaxUnit = require("../util/SyntaxUnit");
  3744. var Parser = require("./Parser");
  3745. /**
  3746. * Represents a selector modifier string, meaning a class name, element name,
  3747. * element ID, pseudo rule, etc.
  3748. * @namespace parserlib.css
  3749. * @class SelectorSubPart
  3750. * @extends parserlib.util.SyntaxUnit
  3751. * @constructor
  3752. * @param {String} text The text representation of the unit.
  3753. * @param {String} type The type of selector modifier.
  3754. * @param {int} line The line of text on which the unit resides.
  3755. * @param {int} col The column of text on which the unit resides.
  3756. */
  3757. function SelectorSubPart(text, type, line, col) {
  3758. SyntaxUnit.call(this, text, line, col, Parser.SELECTOR_SUB_PART_TYPE);
  3759. /**
  3760. * The type of modifier.
  3761. * @type String
  3762. * @property type
  3763. */
  3764. this.type = type;
  3765. /**
  3766. * Some subparts have arguments, this represents them.
  3767. * @type Array
  3768. * @property args
  3769. */
  3770. this.args = [];
  3771. }
  3772. SelectorSubPart.prototype = new SyntaxUnit();
  3773. SelectorSubPart.prototype.constructor = SelectorSubPart;
  3774. },{"../util/SyntaxUnit":26,"./Parser":6}],16:[function(require,module,exports){
  3775. "use strict";
  3776. module.exports = Specificity;
  3777. var Pseudos = require("./Pseudos");
  3778. var SelectorPart = require("./SelectorPart");
  3779. /**
  3780. * Represents a selector's specificity.
  3781. * @namespace parserlib.css
  3782. * @class Specificity
  3783. * @constructor
  3784. * @param {int} a Should be 1 for inline styles, zero for stylesheet styles
  3785. * @param {int} b Number of ID selectors
  3786. * @param {int} c Number of classes and pseudo classes
  3787. * @param {int} d Number of element names and pseudo elements
  3788. */
  3789. function Specificity(a, b, c, d) {
  3790. this.a = a;
  3791. this.b = b;
  3792. this.c = c;
  3793. this.d = d;
  3794. }
  3795. Specificity.prototype = {
  3796. constructor: Specificity,
  3797. /**
  3798. * Compare this specificity to another.
  3799. * @param {Specificity} other The other specificity to compare to.
  3800. * @return {int} -1 if the other specificity is larger, 1 if smaller, 0 if equal.
  3801. * @method compare
  3802. */
  3803. compare: function(other) {
  3804. var comps = ["a", "b", "c", "d"],
  3805. i, len;
  3806. for (i=0, len=comps.length; i < len; i++) {
  3807. if (this[comps[i]] < other[comps[i]]) {
  3808. return -1;
  3809. } else if (this[comps[i]] > other[comps[i]]) {
  3810. return 1;
  3811. }
  3812. }
  3813. return 0;
  3814. },
  3815. /**
  3816. * Creates a numeric value for the specificity.
  3817. * @return {int} The numeric value for the specificity.
  3818. * @method valueOf
  3819. */
  3820. valueOf: function() {
  3821. return (this.a * 1000) + (this.b * 100) + (this.c * 10) + this.d;
  3822. },
  3823. /**
  3824. * Returns a string representation for specificity.
  3825. * @return {String} The string representation of specificity.
  3826. * @method toString
  3827. */
  3828. toString: function() {
  3829. return this.a + "," + this.b + "," + this.c + "," + this.d;
  3830. }
  3831. };
  3832. /**
  3833. * Calculates the specificity of the given selector.
  3834. * @param {parserlib.css.Selector} The selector to calculate specificity for.
  3835. * @return {parserlib.css.Specificity} The specificity of the selector.
  3836. * @static
  3837. * @method calculate
  3838. */
  3839. Specificity.calculate = function(selector) {
  3840. var i, len,
  3841. part,
  3842. b=0, c=0, d=0;
  3843. function updateValues(part) {
  3844. var i, j, len, num,
  3845. elementName = part.elementName ? part.elementName.text : "",
  3846. modifier;
  3847. if (elementName && elementName.charAt(elementName.length-1) !== "*") {
  3848. d++;
  3849. }
  3850. for (i=0, len=part.modifiers.length; i < len; i++) {
  3851. modifier = part.modifiers[i];
  3852. switch (modifier.type) {
  3853. case "class":
  3854. case "attribute":
  3855. c++;
  3856. break;
  3857. case "id":
  3858. b++;
  3859. break;
  3860. case "pseudo":
  3861. if (Pseudos.isElement(modifier.text)) {
  3862. d++;
  3863. } else {
  3864. c++;
  3865. }
  3866. break;
  3867. case "not":
  3868. for (j=0, num=modifier.args.length; j < num; j++) {
  3869. updateValues(modifier.args[j]);
  3870. }
  3871. }
  3872. }
  3873. }
  3874. for (i=0, len=selector.parts.length; i < len; i++) {
  3875. part = selector.parts[i];
  3876. if (part instanceof SelectorPart) {
  3877. updateValues(part);
  3878. }
  3879. }
  3880. return new Specificity(0, b, c, d);
  3881. };
  3882. },{"./Pseudos":12,"./SelectorPart":14}],17:[function(require,module,exports){
  3883. "use strict";
  3884. module.exports = TokenStream;
  3885. var TokenStreamBase = require("../util/TokenStreamBase");
  3886. var PropertyValuePart = require("./PropertyValuePart");
  3887. var Tokens = require("./Tokens");
  3888. var h = /^[0-9a-fA-F]$/,
  3889. nonascii = /^[\u00A0-\uFFFF]$/,
  3890. nl = /\n|\r\n|\r|\f/,
  3891. whitespace = /\u0009|\u000a|\u000c|\u000d|\u0020/;
  3892. //-----------------------------------------------------------------------------
  3893. // Helper functions
  3894. //-----------------------------------------------------------------------------
  3895. function isHexDigit(c) {
  3896. return c !== null && h.test(c);
  3897. }
  3898. function isDigit(c) {
  3899. return c !== null && /\d/.test(c);
  3900. }
  3901. function isWhitespace(c) {
  3902. return c !== null && whitespace.test(c);
  3903. }
  3904. function isNewLine(c) {
  3905. return c !== null && nl.test(c);
  3906. }
  3907. function isNameStart(c) {
  3908. return c !== null && /[a-z_\u00A0-\uFFFF\\]/i.test(c);
  3909. }
  3910. function isNameChar(c) {
  3911. return c !== null && (isNameStart(c) || /[0-9\-\\]/.test(c));
  3912. }
  3913. function isIdentStart(c) {
  3914. return c !== null && (isNameStart(c) || /\-\\/.test(c));
  3915. }
  3916. function mix(receiver, supplier) {
  3917. for (var prop in supplier) {
  3918. if (Object.prototype.hasOwnProperty.call(supplier, prop)) {
  3919. receiver[prop] = supplier[prop];
  3920. }
  3921. }
  3922. return receiver;
  3923. }
  3924. //-----------------------------------------------------------------------------
  3925. // CSS Token Stream
  3926. //-----------------------------------------------------------------------------
  3927. /**
  3928. * A token stream that produces CSS tokens.
  3929. * @param {String|Reader} input The source of text to tokenize.
  3930. * @constructor
  3931. * @class TokenStream
  3932. * @namespace parserlib.css
  3933. */
  3934. function TokenStream(input) {
  3935. TokenStreamBase.call(this, input, Tokens);
  3936. }
  3937. TokenStream.prototype = mix(new TokenStreamBase(), {
  3938. /**
  3939. * Overrides the TokenStreamBase method of the same name
  3940. * to produce CSS tokens.
  3941. * @return {Object} A token object representing the next token.
  3942. * @method _getToken
  3943. * @private
  3944. */
  3945. _getToken: function() {
  3946. var c,
  3947. reader = this._reader,
  3948. token = null,
  3949. startLine = reader.getLine(),
  3950. startCol = reader.getCol();
  3951. c = reader.read();
  3952. while (c) {
  3953. switch (c) {
  3954. /*
  3955. * Potential tokens:
  3956. * - COMMENT
  3957. * - SLASH
  3958. * - CHAR
  3959. */
  3960. case "/":
  3961. if (reader.peek() === "*") {
  3962. token = this.commentToken(c, startLine, startCol);
  3963. } else {
  3964. token = this.charToken(c, startLine, startCol);
  3965. }
  3966. break;
  3967. /*
  3968. * Potential tokens:
  3969. * - DASHMATCH
  3970. * - INCLUDES
  3971. * - PREFIXMATCH
  3972. * - SUFFIXMATCH
  3973. * - SUBSTRINGMATCH
  3974. * - CHAR
  3975. */
  3976. case "|":
  3977. case "~":
  3978. case "^":
  3979. case "$":
  3980. case "*":
  3981. if (reader.peek() === "=") {
  3982. token = this.comparisonToken(c, startLine, startCol);
  3983. } else {
  3984. token = this.charToken(c, startLine, startCol);
  3985. }
  3986. break;
  3987. /*
  3988. * Potential tokens:
  3989. * - STRING
  3990. * - INVALID
  3991. */
  3992. case "\"":
  3993. case "'":
  3994. token = this.stringToken(c, startLine, startCol);
  3995. break;
  3996. /*
  3997. * Potential tokens:
  3998. * - HASH
  3999. * - CHAR
  4000. */
  4001. case "#":
  4002. if (isNameChar(reader.peek())) {
  4003. token = this.hashToken(c, startLine, startCol);
  4004. } else {
  4005. token = this.charToken(c, startLine, startCol);
  4006. }
  4007. break;
  4008. /*
  4009. * Potential tokens:
  4010. * - DOT
  4011. * - NUMBER
  4012. * - DIMENSION
  4013. * - PERCENTAGE
  4014. */
  4015. case ".":
  4016. if (isDigit(reader.peek())) {
  4017. token = this.numberToken(c, startLine, startCol);
  4018. } else {
  4019. token = this.charToken(c, startLine, startCol);
  4020. }
  4021. break;
  4022. /*
  4023. * Potential tokens:
  4024. * - CDC
  4025. * - MINUS
  4026. * - NUMBER
  4027. * - DIMENSION
  4028. * - PERCENTAGE
  4029. */
  4030. case "-":
  4031. if (reader.peek() === "-") { //could be closing HTML-style comment
  4032. token = this.htmlCommentEndToken(c, startLine, startCol);
  4033. } else if (isNameStart(reader.peek())) {
  4034. token = this.identOrFunctionToken(c, startLine, startCol);
  4035. } else {
  4036. token = this.charToken(c, startLine, startCol);
  4037. }
  4038. break;
  4039. /*
  4040. * Potential tokens:
  4041. * - IMPORTANT_SYM
  4042. * - CHAR
  4043. */
  4044. case "!":
  4045. token = this.importantToken(c, startLine, startCol);
  4046. break;
  4047. /*
  4048. * Any at-keyword or CHAR
  4049. */
  4050. case "@":
  4051. token = this.atRuleToken(c, startLine, startCol);
  4052. break;
  4053. /*
  4054. * Potential tokens:
  4055. * - ANY
  4056. * - NOT
  4057. * - CHAR
  4058. */
  4059. case ":":
  4060. token = this.notOrAnyToken(c, startLine, startCol);
  4061. break;
  4062. /*
  4063. * Potential tokens:
  4064. * - CDO
  4065. * - CHAR
  4066. */
  4067. case "<":
  4068. token = this.htmlCommentStartToken(c, startLine, startCol);
  4069. break;
  4070. /*
  4071. * Potential tokens:
  4072. * - IDENT
  4073. * - CHAR
  4074. */
  4075. case "\\":
  4076. if (/[^\r\n\f]/.test(reader.peek())) {
  4077. token = this.identOrFunctionToken(this.readEscape(c, true), startLine, startCol);
  4078. } else {
  4079. token = this.charToken(c, startLine, startCol);
  4080. }
  4081. break;
  4082. /*
  4083. * Potential tokens:
  4084. * - UNICODE_RANGE
  4085. * - URL
  4086. * - CHAR
  4087. */
  4088. case "U":
  4089. case "u":
  4090. if (reader.peek() === "+") {
  4091. token = this.unicodeRangeToken(c, startLine, startCol);
  4092. break;
  4093. }
  4094. /* falls through */
  4095. default:
  4096. /*
  4097. * Potential tokens:
  4098. * - NUMBER
  4099. * - DIMENSION
  4100. * - LENGTH
  4101. * - FREQ
  4102. * - TIME
  4103. * - EMS
  4104. * - EXS
  4105. * - ANGLE
  4106. */
  4107. if (isDigit(c)) {
  4108. token = this.numberToken(c, startLine, startCol);
  4109. } else
  4110. /*
  4111. * Potential tokens:
  4112. * - S
  4113. */
  4114. if (isWhitespace(c)) {
  4115. token = this.whitespaceToken(c, startLine, startCol);
  4116. } else
  4117. /*
  4118. * Potential tokens:
  4119. * - IDENT
  4120. */
  4121. if (isIdentStart(c)) {
  4122. token = this.identOrFunctionToken(c, startLine, startCol);
  4123. } else {
  4124. /*
  4125. * Potential tokens:
  4126. * - CHAR
  4127. * - PLUS
  4128. */
  4129. token = this.charToken(c, startLine, startCol);
  4130. }
  4131. }
  4132. //make sure this token is wanted
  4133. //TODO: check channel
  4134. break;
  4135. }
  4136. if (!token && c === null) {
  4137. token = this.createToken(Tokens.EOF, null, startLine, startCol);
  4138. }
  4139. return token;
  4140. },
  4141. //-------------------------------------------------------------------------
  4142. // Methods to create tokens
  4143. //-------------------------------------------------------------------------
  4144. /**
  4145. * Produces a token based on available data and the current
  4146. * reader position information. This method is called by other
  4147. * private methods to create tokens and is never called directly.
  4148. * @param {int} tt The token type.
  4149. * @param {String} value The text value of the token.
  4150. * @param {int} startLine The beginning line for the character.
  4151. * @param {int} startCol The beginning column for the character.
  4152. * @param {Object} options (Optional) Specifies a channel property
  4153. * to indicate that a different channel should be scanned
  4154. * and/or a hide property indicating that the token should
  4155. * be hidden.
  4156. * @return {Object} A token object.
  4157. * @method createToken
  4158. */
  4159. createToken: function(tt, value, startLine, startCol, options) {
  4160. var reader = this._reader;
  4161. options = options || {};
  4162. return {
  4163. value: value,
  4164. type: tt,
  4165. channel: options.channel,
  4166. endChar: options.endChar,
  4167. hide: options.hide || false,
  4168. startLine: startLine,
  4169. startCol: startCol,
  4170. endLine: reader.getLine(),
  4171. endCol: reader.getCol()
  4172. };
  4173. },
  4174. //-------------------------------------------------------------------------
  4175. // Methods to create specific tokens
  4176. //-------------------------------------------------------------------------
  4177. /**
  4178. * Produces a token for any at-rule. If the at-rule is unknown, then
  4179. * the token is for a single "@" character.
  4180. * @param {String} first The first character for the token.
  4181. * @param {int} startLine The beginning line for the character.
  4182. * @param {int} startCol The beginning column for the character.
  4183. * @return {Object} A token object.
  4184. * @method atRuleToken
  4185. */
  4186. atRuleToken: function(first, startLine, startCol) {
  4187. var rule = first,
  4188. reader = this._reader,
  4189. tt = Tokens.CHAR,
  4190. ident;
  4191. /*
  4192. * First, mark where we are. There are only four @ rules,
  4193. * so anything else is really just an invalid token.
  4194. * Basically, if this doesn't match one of the known @
  4195. * rules, just return '@' as an unknown token and allow
  4196. * parsing to continue after that point.
  4197. */
  4198. reader.mark();
  4199. //try to find the at-keyword
  4200. ident = this.readName();
  4201. rule = first + ident;
  4202. tt = Tokens.type(rule.toLowerCase());
  4203. //if it's not valid, use the first character only and reset the reader
  4204. if (tt === Tokens.CHAR || tt === Tokens.UNKNOWN) {
  4205. if (rule.length > 1) {
  4206. tt = Tokens.UNKNOWN_SYM;
  4207. } else {
  4208. tt = Tokens.CHAR;
  4209. rule = first;
  4210. reader.reset();
  4211. }
  4212. }
  4213. return this.createToken(tt, rule, startLine, startCol);
  4214. },
  4215. /**
  4216. * Produces a character token based on the given character
  4217. * and location in the stream. If there's a special (non-standard)
  4218. * token name, this is used; otherwise CHAR is used.
  4219. * @param {String} c The character for the token.
  4220. * @param {int} startLine The beginning line for the character.
  4221. * @param {int} startCol The beginning column for the character.
  4222. * @return {Object} A token object.
  4223. * @method charToken
  4224. */
  4225. charToken: function(c, startLine, startCol) {
  4226. var tt = Tokens.type(c);
  4227. var opts = {};
  4228. if (tt === -1) {
  4229. tt = Tokens.CHAR;
  4230. } else {
  4231. opts.endChar = Tokens[tt].endChar;
  4232. }
  4233. return this.createToken(tt, c, startLine, startCol, opts);
  4234. },
  4235. /**
  4236. * Produces a character token based on the given character
  4237. * and location in the stream. If there's a special (non-standard)
  4238. * token name, this is used; otherwise CHAR is used.
  4239. * @param {String} first The first character for the token.
  4240. * @param {int} startLine The beginning line for the character.
  4241. * @param {int} startCol The beginning column for the character.
  4242. * @return {Object} A token object.
  4243. * @method commentToken
  4244. */
  4245. commentToken: function(first, startLine, startCol) {
  4246. var comment = this.readComment(first);
  4247. return this.createToken(Tokens.COMMENT, comment, startLine, startCol);
  4248. },
  4249. /**
  4250. * Produces a comparison token based on the given character
  4251. * and location in the stream. The next character must be
  4252. * read and is already known to be an equals sign.
  4253. * @param {String} c The character for the token.
  4254. * @param {int} startLine The beginning line for the character.
  4255. * @param {int} startCol The beginning column for the character.
  4256. * @return {Object} A token object.
  4257. * @method comparisonToken
  4258. */
  4259. comparisonToken: function(c, startLine, startCol) {
  4260. var reader = this._reader,
  4261. comparison = c + reader.read(),
  4262. tt = Tokens.type(comparison) || Tokens.CHAR;
  4263. return this.createToken(tt, comparison, startLine, startCol);
  4264. },
  4265. /**
  4266. * Produces a hash token based on the specified information. The
  4267. * first character provided is the pound sign (#) and then this
  4268. * method reads a name afterward.
  4269. * @param {String} first The first character (#) in the hash name.
  4270. * @param {int} startLine The beginning line for the character.
  4271. * @param {int} startCol The beginning column for the character.
  4272. * @return {Object} A token object.
  4273. * @method hashToken
  4274. */
  4275. hashToken: function(first, startLine, startCol) {
  4276. var name = this.readName(first);
  4277. return this.createToken(Tokens.HASH, name, startLine, startCol);
  4278. },
  4279. /**
  4280. * Produces a CDO or CHAR token based on the specified information. The
  4281. * first character is provided and the rest is read by the function to determine
  4282. * the correct token to create.
  4283. * @param {String} first The first character in the token.
  4284. * @param {int} startLine The beginning line for the character.
  4285. * @param {int} startCol The beginning column for the character.
  4286. * @return {Object} A token object.
  4287. * @method htmlCommentStartToken
  4288. */
  4289. htmlCommentStartToken: function(first, startLine, startCol) {
  4290. var reader = this._reader,
  4291. text = first;
  4292. reader.mark();
  4293. text += reader.readCount(3);
  4294. if (text === "<!--") {
  4295. return this.createToken(Tokens.CDO, text, startLine, startCol);
  4296. } else {
  4297. reader.reset();
  4298. return this.charToken(first, startLine, startCol);
  4299. }
  4300. },
  4301. /**
  4302. * Produces a CDC or CHAR token based on the specified information. The
  4303. * first character is provided and the rest is read by the function to determine
  4304. * the correct token to create.
  4305. * @param {String} first The first character in the token.
  4306. * @param {int} startLine The beginning line for the character.
  4307. * @param {int} startCol The beginning column for the character.
  4308. * @return {Object} A token object.
  4309. * @method htmlCommentEndToken
  4310. */
  4311. htmlCommentEndToken: function(first, startLine, startCol) {
  4312. var reader = this._reader,
  4313. text = first;
  4314. reader.mark();
  4315. text += reader.readCount(2);
  4316. if (text === "-->") {
  4317. return this.createToken(Tokens.CDC, text, startLine, startCol);
  4318. } else {
  4319. reader.reset();
  4320. return this.charToken(first, startLine, startCol);
  4321. }
  4322. },
  4323. /**
  4324. * Produces an IDENT or FUNCTION token based on the specified information. The
  4325. * first character is provided and the rest is read by the function to determine
  4326. * the correct token to create.
  4327. * @param {String} first The first character in the identifier.
  4328. * @param {int} startLine The beginning line for the character.
  4329. * @param {int} startCol The beginning column for the character.
  4330. * @return {Object} A token object.
  4331. * @method identOrFunctionToken
  4332. */
  4333. identOrFunctionToken: function(first, startLine, startCol) {
  4334. var reader = this._reader,
  4335. ident = this.readName(first),
  4336. tt = Tokens.IDENT,
  4337. uriFns = ["url(", "url-prefix(", "domain("],
  4338. uri;
  4339. //if there's a left paren immediately after, it's a URI or function
  4340. if (reader.peek() === "(") {
  4341. ident += reader.read();
  4342. if (uriFns.indexOf(ident.toLowerCase()) > -1) {
  4343. reader.mark();
  4344. uri = this.readURI(ident);
  4345. if (uri === null) {
  4346. //didn't find a valid URL or there's no closing paren
  4347. reader.reset();
  4348. tt = Tokens.FUNCTION;
  4349. } else {
  4350. tt = Tokens.URI;
  4351. ident = uri;
  4352. }
  4353. } else {
  4354. tt = Tokens.FUNCTION;
  4355. }
  4356. } else if (reader.peek() === ":") { //might be an IE function
  4357. //IE-specific functions always being with progid:
  4358. if (ident.toLowerCase() === "progid") {
  4359. ident += reader.readTo("(");
  4360. tt = Tokens.IE_FUNCTION;
  4361. }
  4362. }
  4363. return this.createToken(tt, ident, startLine, startCol);
  4364. },
  4365. /**
  4366. * Produces an IMPORTANT_SYM or CHAR token based on the specified information. The
  4367. * first character is provided and the rest is read by the function to determine
  4368. * the correct token to create.
  4369. * @param {String} first The first character in the token.
  4370. * @param {int} startLine The beginning line for the character.
  4371. * @param {int} startCol The beginning column for the character.
  4372. * @return {Object} A token object.
  4373. * @method importantToken
  4374. */
  4375. importantToken: function(first, startLine, startCol) {
  4376. var reader = this._reader,
  4377. important = first,
  4378. tt = Tokens.CHAR,
  4379. temp,
  4380. c;
  4381. reader.mark();
  4382. c = reader.read();
  4383. while (c) {
  4384. //there can be a comment in here
  4385. if (c === "/") {
  4386. //if the next character isn't a star, then this isn't a valid !important token
  4387. if (reader.peek() !== "*") {
  4388. break;
  4389. } else {
  4390. temp = this.readComment(c);
  4391. if (temp === "") { //broken!
  4392. break;
  4393. }
  4394. }
  4395. } else if (isWhitespace(c)) {
  4396. important += c + this.readWhitespace();
  4397. } else if (/i/i.test(c)) {
  4398. temp = reader.readCount(8);
  4399. if (/mportant/i.test(temp)) {
  4400. important += c + temp;
  4401. tt = Tokens.IMPORTANT_SYM;
  4402. }
  4403. break; //we're done
  4404. } else {
  4405. break;
  4406. }
  4407. c = reader.read();
  4408. }
  4409. if (tt === Tokens.CHAR) {
  4410. reader.reset();
  4411. return this.charToken(first, startLine, startCol);
  4412. } else {
  4413. return this.createToken(tt, important, startLine, startCol);
  4414. }
  4415. },
  4416. /**
  4417. * Produces a NOT or ANY or CHAR token based on the specified information. The
  4418. * first character is provided and the rest is read by the function to determine
  4419. * the correct token to create.
  4420. * @param {String} first The first character in the token.
  4421. * @param {int} startLine The beginning line for the character.
  4422. * @param {int} startCol The beginning column for the character.
  4423. * @return {Object} A token object.
  4424. * @method notToken
  4425. */
  4426. notOrAnyToken: function(first, startLine, startCol) {
  4427. var reader = this._reader,
  4428. text = first;
  4429. reader.mark();
  4430. text += reader.readCount(4);
  4431. if (text.toLowerCase() === ":not(") {
  4432. return this.createToken(Tokens.NOT, text, startLine, startCol);
  4433. }
  4434. if (text.toLowerCase() === ":any(") {
  4435. return this.createToken(Tokens.ANY, text, startLine, startCol);
  4436. }
  4437. text += reader.readCount(5);
  4438. if (text.toLowerCase() === ":-moz-any(") {
  4439. return this.createToken(Tokens.ANY, text, startLine, startCol);
  4440. }
  4441. text += reader.readCount(3);
  4442. if (text.toLowerCase() === ":-webkit-any(") {
  4443. return this.createToken(Tokens.ANY, text, startLine, startCol);
  4444. }
  4445. reader.reset();
  4446. return this.charToken(first, startLine, startCol);
  4447. },
  4448. /**
  4449. * Produces a number token based on the given character
  4450. * and location in the stream. This may return a token of
  4451. * NUMBER, EMS, EXS, LENGTH, ANGLE, TIME, FREQ, DIMENSION,
  4452. * or PERCENTAGE.
  4453. * @param {String} first The first character for the token.
  4454. * @param {int} startLine The beginning line for the character.
  4455. * @param {int} startCol The beginning column for the character.
  4456. * @return {Object} A token object.
  4457. * @method numberToken
  4458. */
  4459. numberToken: function(first, startLine, startCol) {
  4460. var reader = this._reader,
  4461. value = this.readNumber(first),
  4462. ident,
  4463. tt = Tokens.NUMBER,
  4464. c = reader.peek();
  4465. if (isIdentStart(c)) {
  4466. ident = this.readName(reader.read());
  4467. value += ident;
  4468. if (/^em$|^ex$|^px$|^gd$|^rem$|^vw$|^vh$|^vmax$|^vmin$|^ch$|^cm$|^mm$|^in$|^pt$|^pc$/i.test(ident)) {
  4469. tt = Tokens.LENGTH;
  4470. } else if (/^deg|^rad$|^grad$|^turn$/i.test(ident)) {
  4471. tt = Tokens.ANGLE;
  4472. } else if (/^ms$|^s$/i.test(ident)) {
  4473. tt = Tokens.TIME;
  4474. } else if (/^hz$|^khz$/i.test(ident)) {
  4475. tt = Tokens.FREQ;
  4476. } else if (/^dpi$|^dpcm$/i.test(ident)) {
  4477. tt = Tokens.RESOLUTION;
  4478. } else {
  4479. tt = Tokens.DIMENSION;
  4480. }
  4481. } else if (c === "%") {
  4482. value += reader.read();
  4483. tt = Tokens.PERCENTAGE;
  4484. }
  4485. return this.createToken(tt, value, startLine, startCol);
  4486. },
  4487. /**
  4488. * Produces a string token based on the given character
  4489. * and location in the stream. Since strings may be indicated
  4490. * by single or double quotes, a failure to match starting
  4491. * and ending quotes results in an INVALID token being generated.
  4492. * The first character in the string is passed in and then
  4493. * the rest are read up to and including the final quotation mark.
  4494. * @param {String} first The first character in the string.
  4495. * @param {int} startLine The beginning line for the character.
  4496. * @param {int} startCol The beginning column for the character.
  4497. * @return {Object} A token object.
  4498. * @method stringToken
  4499. */
  4500. stringToken: function(first, startLine, startCol) {
  4501. var delim = first,
  4502. string = first,
  4503. reader = this._reader,
  4504. tt = Tokens.STRING,
  4505. c = reader.read(),
  4506. i;
  4507. while (c) {
  4508. string += c;
  4509. if (c === "\\") {
  4510. c = reader.read();
  4511. if (c === null) {
  4512. break; // premature EOF after backslash
  4513. } else if (/[^\r\n\f0-9a-f]/i.test(c)) {
  4514. // single-character escape
  4515. string += c;
  4516. } else {
  4517. // read up to six hex digits
  4518. for (i=0; isHexDigit(c) && i<6; i++) {
  4519. string += c;
  4520. c = reader.read();
  4521. }
  4522. // swallow trailing newline or space
  4523. if (c === "\r" && reader.peek() === "\n") {
  4524. string += c;
  4525. c = reader.read();
  4526. }
  4527. if (isWhitespace(c)) {
  4528. string += c;
  4529. } else {
  4530. // This character is null or not part of the escape;
  4531. // jump back to the top to process it.
  4532. continue;
  4533. }
  4534. }
  4535. } else if (c === delim) {
  4536. break; // delimiter found.
  4537. } else if (isNewLine(reader.peek())) {
  4538. // newline without an escapement: it's an invalid string
  4539. tt = Tokens.INVALID;
  4540. break;
  4541. }
  4542. c = reader.read();
  4543. }
  4544. //if c is null, that means we're out of input and the string was never closed
  4545. if (c === null) {
  4546. tt = Tokens.INVALID;
  4547. }
  4548. return this.createToken(tt, string, startLine, startCol);
  4549. },
  4550. unicodeRangeToken: function(first, startLine, startCol) {
  4551. var reader = this._reader,
  4552. value = first,
  4553. temp,
  4554. tt = Tokens.CHAR;
  4555. //then it should be a unicode range
  4556. if (reader.peek() === "+") {
  4557. reader.mark();
  4558. value += reader.read();
  4559. value += this.readUnicodeRangePart(true);
  4560. //ensure there's an actual unicode range here
  4561. if (value.length === 2) {
  4562. reader.reset();
  4563. } else {
  4564. tt = Tokens.UNICODE_RANGE;
  4565. //if there's a ? in the first part, there can't be a second part
  4566. if (value.indexOf("?") === -1) {
  4567. if (reader.peek() === "-") {
  4568. reader.mark();
  4569. temp = reader.read();
  4570. temp += this.readUnicodeRangePart(false);
  4571. //if there's not another value, back up and just take the first
  4572. if (temp.length === 1) {
  4573. reader.reset();
  4574. } else {
  4575. value += temp;
  4576. }
  4577. }
  4578. }
  4579. }
  4580. }
  4581. return this.createToken(tt, value, startLine, startCol);
  4582. },
  4583. /**
  4584. * Produces a S token based on the specified information. Since whitespace
  4585. * may have multiple characters, this consumes all whitespace characters
  4586. * into a single token.
  4587. * @param {String} first The first character in the token.
  4588. * @param {int} startLine The beginning line for the character.
  4589. * @param {int} startCol The beginning column for the character.
  4590. * @return {Object} A token object.
  4591. * @method whitespaceToken
  4592. */
  4593. whitespaceToken: function(first, startLine, startCol) {
  4594. var value = first + this.readWhitespace();
  4595. return this.createToken(Tokens.S, value, startLine, startCol);
  4596. },
  4597. //-------------------------------------------------------------------------
  4598. // Methods to read values from the string stream
  4599. //-------------------------------------------------------------------------
  4600. readUnicodeRangePart: function(allowQuestionMark) {
  4601. var reader = this._reader,
  4602. part = "",
  4603. c = reader.peek();
  4604. //first read hex digits
  4605. while (isHexDigit(c) && part.length < 6) {
  4606. reader.read();
  4607. part += c;
  4608. c = reader.peek();
  4609. }
  4610. //then read question marks if allowed
  4611. if (allowQuestionMark) {
  4612. while (c === "?" && part.length < 6) {
  4613. reader.read();
  4614. part += c;
  4615. c = reader.peek();
  4616. }
  4617. }
  4618. //there can't be any other characters after this point
  4619. return part;
  4620. },
  4621. readWhitespace: function() {
  4622. var reader = this._reader,
  4623. whitespace = "",
  4624. c = reader.peek();
  4625. while (isWhitespace(c)) {
  4626. reader.read();
  4627. whitespace += c;
  4628. c = reader.peek();
  4629. }
  4630. return whitespace;
  4631. },
  4632. readNumber: function(first) {
  4633. var reader = this._reader,
  4634. number = first,
  4635. hasDot = (first === "."),
  4636. c = reader.peek();
  4637. while (c) {
  4638. if (isDigit(c)) {
  4639. number += reader.read();
  4640. } else if (c === ".") {
  4641. if (hasDot) {
  4642. break;
  4643. } else {
  4644. hasDot = true;
  4645. number += reader.read();
  4646. }
  4647. } else {
  4648. break;
  4649. }
  4650. c = reader.peek();
  4651. }
  4652. return number;
  4653. },
  4654. // returns null w/o resetting reader if string is invalid.
  4655. readString: function() {
  4656. var token = this.stringToken(this._reader.read(), 0, 0);
  4657. return token.type === Tokens.INVALID ? null : token.value;
  4658. },
  4659. // returns null w/o resetting reader if URI is invalid.
  4660. readURI: function(first) {
  4661. var reader = this._reader,
  4662. uri = first,
  4663. inner = "",
  4664. c = reader.peek();
  4665. //skip whitespace before
  4666. while (c && isWhitespace(c)) {
  4667. reader.read();
  4668. c = reader.peek();
  4669. }
  4670. //it's a string
  4671. if (c === "'" || c === "\"") {
  4672. inner = this.readString();
  4673. if (inner !== null) {
  4674. inner = PropertyValuePart.parseString(inner);
  4675. }
  4676. } else {
  4677. inner = this.readUnquotedURL();
  4678. }
  4679. c = reader.peek();
  4680. //skip whitespace after
  4681. while (c && isWhitespace(c)) {
  4682. reader.read();
  4683. c = reader.peek();
  4684. }
  4685. //if there was no inner value or the next character isn't closing paren, it's not a URI
  4686. if (inner === null || c !== ")") {
  4687. uri = null;
  4688. } else {
  4689. // Ensure argument to URL is always double-quoted
  4690. // (This simplifies later processing in PropertyValuePart.)
  4691. uri += PropertyValuePart.serializeString(inner) + reader.read();
  4692. }
  4693. return uri;
  4694. },
  4695. // This method never fails, although it may return an empty string.
  4696. readUnquotedURL: function(first) {
  4697. var reader = this._reader,
  4698. url = first || "",
  4699. c;
  4700. for (c = reader.peek(); c; c = reader.peek()) {
  4701. // Note that the grammar at
  4702. // https://www.w3.org/TR/CSS2/grammar.html#scanner
  4703. // incorrectly includes the backslash character in the
  4704. // `url` production, although it is correctly omitted in
  4705. // the `baduri1` production.
  4706. if (nonascii.test(c) || /^[\-!#$%&*-\[\]-~]$/.test(c)) {
  4707. url += c;
  4708. reader.read();
  4709. } else if (c === "\\") {
  4710. if (/^[^\r\n\f]$/.test(reader.peek(2))) {
  4711. url += this.readEscape(reader.read(), true);
  4712. } else {
  4713. break; // bad escape sequence.
  4714. }
  4715. } else {
  4716. break; // bad character
  4717. }
  4718. }
  4719. return url;
  4720. },
  4721. readName: function(first) {
  4722. var reader = this._reader,
  4723. ident = first || "",
  4724. c;
  4725. for (c = reader.peek(); c; c = reader.peek()) {
  4726. if (c === "\\") {
  4727. if (/^[^\r\n\f]$/.test(reader.peek(2))) {
  4728. ident += this.readEscape(reader.read(), true);
  4729. } else {
  4730. // Bad escape sequence.
  4731. break;
  4732. }
  4733. } else if (isNameChar(c)) {
  4734. ident += reader.read();
  4735. } else {
  4736. break;
  4737. }
  4738. }
  4739. return ident;
  4740. },
  4741. readEscape: function(first, unescape) {
  4742. var reader = this._reader,
  4743. cssEscape = first || "",
  4744. i = 0,
  4745. c = reader.peek();
  4746. if (isHexDigit(c)) {
  4747. do {
  4748. cssEscape += reader.read();
  4749. c = reader.peek();
  4750. } while (c && isHexDigit(c) && ++i < 6);
  4751. }
  4752. if (cssEscape.length === 1) {
  4753. if (/^[^\r\n\f0-9a-f]$/.test(c)) {
  4754. reader.read();
  4755. if (unescape) {
  4756. return c;
  4757. }
  4758. } else {
  4759. // We should never get here (readName won't call readEscape
  4760. // if the escape sequence is bad).
  4761. throw new Error("Bad escape sequence.");
  4762. }
  4763. } else if (c === "\r") {
  4764. reader.read();
  4765. if (reader.peek() === "\n") {
  4766. c += reader.read();
  4767. }
  4768. } else if (/^[ \t\n\f]$/.test(c)) {
  4769. reader.read();
  4770. } else {
  4771. c = "";
  4772. }
  4773. if (unescape) {
  4774. var cp = parseInt(cssEscape.slice(first.length), 16);
  4775. return String.fromCodePoint ? String.fromCodePoint(cp) :
  4776. String.fromCharCode(cp);
  4777. }
  4778. return cssEscape + c;
  4779. },
  4780. readComment: function(first) {
  4781. var reader = this._reader,
  4782. comment = first || "",
  4783. c = reader.read();
  4784. if (c === "*") {
  4785. while (c) {
  4786. comment += c;
  4787. //look for end of comment
  4788. if (comment.length > 2 && c === "*" && reader.peek() === "/") {
  4789. comment += reader.read();
  4790. break;
  4791. }
  4792. c = reader.read();
  4793. }
  4794. return comment;
  4795. } else {
  4796. return "";
  4797. }
  4798. }
  4799. });
  4800. },{"../util/TokenStreamBase":27,"./PropertyValuePart":11,"./Tokens":18}],18:[function(require,module,exports){
  4801. "use strict";
  4802. var Tokens = module.exports = [
  4803. /*
  4804. * The following token names are defined in CSS3 Grammar: https://www.w3.org/TR/css3-syntax/#lexical
  4805. */
  4806. // HTML-style comments
  4807. { name: "CDO" },
  4808. { name: "CDC" },
  4809. // ignorables
  4810. { name: "S", whitespace: true/*, channel: "ws"*/ },
  4811. { name: "COMMENT", comment: true, hide: true, channel: "comment" },
  4812. // attribute equality
  4813. { name: "INCLUDES", text: "~=" },
  4814. { name: "DASHMATCH", text: "|=" },
  4815. { name: "PREFIXMATCH", text: "^=" },
  4816. { name: "SUFFIXMATCH", text: "$=" },
  4817. { name: "SUBSTRINGMATCH", text: "*=" },
  4818. // identifier types
  4819. { name: "STRING" },
  4820. { name: "IDENT" },
  4821. { name: "HASH" },
  4822. // at-keywords
  4823. { name: "IMPORT_SYM", text: "@import" },
  4824. { name: "PAGE_SYM", text: "@page" },
  4825. { name: "MEDIA_SYM", text: "@media" },
  4826. { name: "FONT_FACE_SYM", text: "@font-face" },
  4827. { name: "CHARSET_SYM", text: "@charset" },
  4828. { name: "NAMESPACE_SYM", text: "@namespace" },
  4829. { name: "SUPPORTS_SYM", text: "@supports" },
  4830. { name: "VIEWPORT_SYM", text: ["@viewport", "@-ms-viewport", "@-o-viewport"] },
  4831. { name: "DOCUMENT_SYM", text: ["@document", "@-moz-document"] },
  4832. { name: "UNKNOWN_SYM" },
  4833. //{ name: "ATKEYWORD"},
  4834. // CSS3 animations
  4835. { name: "KEYFRAMES_SYM", text: [ "@keyframes", "@-webkit-keyframes", "@-moz-keyframes", "@-o-keyframes" ] },
  4836. // important symbol
  4837. { name: "IMPORTANT_SYM" },
  4838. // measurements
  4839. { name: "LENGTH" },
  4840. { name: "ANGLE" },
  4841. { name: "TIME" },
  4842. { name: "FREQ" },
  4843. { name: "DIMENSION" },
  4844. { name: "PERCENTAGE" },
  4845. { name: "NUMBER" },
  4846. // functions
  4847. { name: "URI" },
  4848. { name: "FUNCTION" },
  4849. // Unicode ranges
  4850. { name: "UNICODE_RANGE" },
  4851. /*
  4852. * The following token names are defined in CSS3 Selectors: https://www.w3.org/TR/css3-selectors/#selector-syntax
  4853. */
  4854. // invalid string
  4855. { name: "INVALID" },
  4856. // combinators
  4857. { name: "PLUS", text: "+" },
  4858. { name: "GREATER", text: ">" },
  4859. { name: "COMMA", text: "," },
  4860. { name: "TILDE", text: "~" },
  4861. // modifier
  4862. { name: "NOT" },
  4863. { name: "ANY", text: ["any", "-webkit-any", "-moz-any"] },
  4864. /*
  4865. * Defined in CSS3 Paged Media
  4866. */
  4867. { name: "TOPLEFTCORNER_SYM", text: "@top-left-corner" },
  4868. { name: "TOPLEFT_SYM", text: "@top-left" },
  4869. { name: "TOPCENTER_SYM", text: "@top-center" },
  4870. { name: "TOPRIGHT_SYM", text: "@top-right" },
  4871. { name: "TOPRIGHTCORNER_SYM", text: "@top-right-corner" },
  4872. { name: "BOTTOMLEFTCORNER_SYM", text: "@bottom-left-corner" },
  4873. { name: "BOTTOMLEFT_SYM", text: "@bottom-left" },
  4874. { name: "BOTTOMCENTER_SYM", text: "@bottom-center" },
  4875. { name: "BOTTOMRIGHT_SYM", text: "@bottom-right" },
  4876. { name: "BOTTOMRIGHTCORNER_SYM", text: "@bottom-right-corner" },
  4877. { name: "LEFTTOP_SYM", text: "@left-top" },
  4878. { name: "LEFTMIDDLE_SYM", text: "@left-middle" },
  4879. { name: "LEFTBOTTOM_SYM", text: "@left-bottom" },
  4880. { name: "RIGHTTOP_SYM", text: "@right-top" },
  4881. { name: "RIGHTMIDDLE_SYM", text: "@right-middle" },
  4882. { name: "RIGHTBOTTOM_SYM", text: "@right-bottom" },
  4883. /*
  4884. * The following token names are defined in CSS3 Media Queries: https://www.w3.org/TR/css3-mediaqueries/#syntax
  4885. */
  4886. /*{ name: "MEDIA_ONLY", state: "media"},
  4887. { name: "MEDIA_NOT", state: "media"},
  4888. { name: "MEDIA_AND", state: "media"},*/
  4889. { name: "RESOLUTION", state: "media" },
  4890. /*
  4891. * The following token names are not defined in any CSS specification but are used by the lexer.
  4892. */
  4893. // not a real token, but useful for stupid IE filters
  4894. { name: "IE_FUNCTION" },
  4895. // part of CSS3 grammar but not the Flex code
  4896. { name: "CHAR" },
  4897. // TODO: Needed?
  4898. // Not defined as tokens, but might as well be
  4899. {
  4900. name: "PIPE",
  4901. text: "|"
  4902. },
  4903. {
  4904. name: "SLASH",
  4905. text: "/"
  4906. },
  4907. {
  4908. name: "MINUS",
  4909. text: "-"
  4910. },
  4911. {
  4912. name: "STAR",
  4913. text: "*"
  4914. },
  4915. {
  4916. name: "LBRACE",
  4917. endChar: "}",
  4918. text: "{"
  4919. },
  4920. {
  4921. name: "RBRACE",
  4922. text: "}"
  4923. },
  4924. {
  4925. name: "LBRACKET",
  4926. endChar: "]",
  4927. text: "["
  4928. },
  4929. {
  4930. name: "RBRACKET",
  4931. text: "]"
  4932. },
  4933. {
  4934. name: "EQUALS",
  4935. text: "="
  4936. },
  4937. {
  4938. name: "COLON",
  4939. text: ":"
  4940. },
  4941. {
  4942. name: "SEMICOLON",
  4943. text: ";"
  4944. },
  4945. {
  4946. name: "LPAREN",
  4947. endChar: ")",
  4948. text: "("
  4949. },
  4950. {
  4951. name: "RPAREN",
  4952. text: ")"
  4953. },
  4954. {
  4955. name: "DOT",
  4956. text: "."
  4957. }
  4958. ];
  4959. (function() {
  4960. var nameMap = [],
  4961. typeMap = Object.create(null);
  4962. Tokens.UNKNOWN = -1;
  4963. Tokens.unshift({ name:"EOF" });
  4964. for (var i=0, len = Tokens.length; i < len; i++) {
  4965. nameMap.push(Tokens[i].name);
  4966. Tokens[Tokens[i].name] = i;
  4967. if (Tokens[i].text) {
  4968. if (Tokens[i].text instanceof Array) {
  4969. for (var j=0; j < Tokens[i].text.length; j++) {
  4970. typeMap[Tokens[i].text[j]] = i;
  4971. }
  4972. } else {
  4973. typeMap[Tokens[i].text] = i;
  4974. }
  4975. }
  4976. }
  4977. Tokens.name = function(tt) {
  4978. return nameMap[tt];
  4979. };
  4980. Tokens.type = function(c) {
  4981. return typeMap[c] || -1;
  4982. };
  4983. })();
  4984. },{}],19:[function(require,module,exports){
  4985. "use strict";
  4986. /* exported Validation */
  4987. var Matcher = require("./Matcher");
  4988. var Properties = require("./Properties");
  4989. var ValidationTypes = require("./ValidationTypes");
  4990. var ValidationError = require("./ValidationError");
  4991. var PropertyValueIterator = require("./PropertyValueIterator");
  4992. var Validation = module.exports = {
  4993. validate: function(property, value) {
  4994. //normalize name
  4995. var name = property.toString().toLowerCase(),
  4996. expression = new PropertyValueIterator(value),
  4997. spec = Properties[name],
  4998. part;
  4999. if (!spec) {
  5000. if (name.indexOf("-") !== 0) { //vendor prefixed are ok
  5001. throw new ValidationError("Unknown property '" + property + "'.", property.line, property.col);
  5002. }
  5003. } else if (typeof spec !== "number") {
  5004. // All properties accept some CSS-wide values.
  5005. // https://drafts.csswg.org/css-values-3/#common-keywords
  5006. if (ValidationTypes.isAny(expression, "inherit | initial | unset")) {
  5007. if (expression.hasNext()) {
  5008. part = expression.next();
  5009. throw new ValidationError("Expected end of value but found '" + part + "'.", part.line, part.col);
  5010. }
  5011. return;
  5012. }
  5013. // Property-specific validation.
  5014. this.singleProperty(spec, expression);
  5015. }
  5016. },
  5017. singleProperty: function(types, expression) {
  5018. var result = false,
  5019. value = expression.value,
  5020. part;
  5021. result = Matcher.parse(types).match(expression);
  5022. if (!result) {
  5023. if (expression.hasNext() && !expression.isFirst()) {
  5024. part = expression.peek();
  5025. throw new ValidationError("Expected end of value but found '" + part + "'.", part.line, part.col);
  5026. } else {
  5027. throw new ValidationError("Expected (" + ValidationTypes.describe(types) + ") but found '" + value + "'.", value.line, value.col);
  5028. }
  5029. } else if (expression.hasNext()) {
  5030. part = expression.next();
  5031. throw new ValidationError("Expected end of value but found '" + part + "'.", part.line, part.col);
  5032. }
  5033. }
  5034. };
  5035. },{"./Matcher":3,"./Properties":7,"./PropertyValueIterator":10,"./ValidationError":20,"./ValidationTypes":21}],20:[function(require,module,exports){
  5036. "use strict";
  5037. module.exports = ValidationError;
  5038. /**
  5039. * Type to use when a validation error occurs.
  5040. * @class ValidationError
  5041. * @namespace parserlib.util
  5042. * @constructor
  5043. * @param {String} message The error message.
  5044. * @param {int} line The line at which the error occurred.
  5045. * @param {int} col The column at which the error occurred.
  5046. */
  5047. function ValidationError(message, line, col) {
  5048. /**
  5049. * The column at which the error occurred.
  5050. * @type int
  5051. * @property col
  5052. */
  5053. this.col = col;
  5054. /**
  5055. * The line at which the error occurred.
  5056. * @type int
  5057. * @property line
  5058. */
  5059. this.line = line;
  5060. /**
  5061. * The text representation of the unit.
  5062. * @type String
  5063. * @property text
  5064. */
  5065. this.message = message;
  5066. }
  5067. //inherit from Error
  5068. ValidationError.prototype = new Error();
  5069. },{}],21:[function(require,module,exports){
  5070. "use strict";
  5071. var ValidationTypes = module.exports;
  5072. var Matcher = require("./Matcher");
  5073. function copy(to, from) {
  5074. Object.keys(from).forEach(function(prop) {
  5075. to[prop] = from[prop];
  5076. });
  5077. }
  5078. copy(ValidationTypes, {
  5079. isLiteral: function (part, literals) {
  5080. var text = part.text.toString().toLowerCase(),
  5081. args = literals.split(" | "),
  5082. i, len, found = false;
  5083. for (i=0, len=args.length; i < len && !found; i++) {
  5084. if (args[i].charAt(0) === "<") {
  5085. found = this.simple[args[i]](part);
  5086. } else if (args[i].slice(-2) === "()") {
  5087. found = (part.type === "function" &&
  5088. part.name === args[i].slice(0, -2));
  5089. } else if (text === args[i].toLowerCase()) {
  5090. found = true;
  5091. }
  5092. }
  5093. return found;
  5094. },
  5095. isSimple: function(type) {
  5096. return Boolean(this.simple[type]);
  5097. },
  5098. isComplex: function(type) {
  5099. return Boolean(this.complex[type]);
  5100. },
  5101. describe: function(type) {
  5102. if (this.complex[type] instanceof Matcher) {
  5103. return this.complex[type].toString(0);
  5104. }
  5105. return type;
  5106. },
  5107. /**
  5108. * Determines if the next part(s) of the given expression
  5109. * are any of the given types.
  5110. */
  5111. isAny: function (expression, types) {
  5112. var args = types.split(" | "),
  5113. i, len, found = false;
  5114. for (i=0, len=args.length; i < len && !found && expression.hasNext(); i++) {
  5115. found = this.isType(expression, args[i]);
  5116. }
  5117. return found;
  5118. },
  5119. /**
  5120. * Determines if the next part(s) of the given expression
  5121. * are one of a group.
  5122. */
  5123. isAnyOfGroup: function(expression, types) {
  5124. var args = types.split(" || "),
  5125. i, len, found = false;
  5126. for (i=0, len=args.length; i < len && !found; i++) {
  5127. found = this.isType(expression, args[i]);
  5128. }
  5129. return found ? args[i-1] : false;
  5130. },
  5131. /**
  5132. * Determines if the next part(s) of the given expression
  5133. * are of a given type.
  5134. */
  5135. isType: function (expression, type) {
  5136. var part = expression.peek(),
  5137. result = false;
  5138. if (type.charAt(0) !== "<") {
  5139. result = this.isLiteral(part, type);
  5140. if (result) {
  5141. expression.next();
  5142. }
  5143. } else if (this.simple[type]) {
  5144. result = this.simple[type](part);
  5145. if (result) {
  5146. expression.next();
  5147. }
  5148. } else if (this.complex[type] instanceof Matcher) {
  5149. result = this.complex[type].match(expression);
  5150. } else {
  5151. result = this.complex[type](expression);
  5152. }
  5153. return result;
  5154. },
  5155. simple: {
  5156. __proto__: null,
  5157. "<absolute-size>":
  5158. "xx-small | x-small | small | medium | large | x-large | xx-large",
  5159. "<animateable-feature>":
  5160. "scroll-position | contents | <animateable-feature-name>",
  5161. "<animateable-feature-name>": function(part) {
  5162. return this["<ident>"](part) &&
  5163. !/^(unset|initial|inherit|will-change|auto|scroll-position|contents)$/i.test(part);
  5164. },
  5165. "<angle>": function(part) {
  5166. return part.type === "angle";
  5167. },
  5168. "<attachment>": "scroll | fixed | local",
  5169. "<attr>": "attr()",
  5170. // inset() = inset( <shape-arg>{1,4} [round <border-radius>]? )
  5171. // circle() = circle( [<shape-radius>]? [at <position>]? )
  5172. // ellipse() = ellipse( [<shape-radius>{2}]? [at <position>]? )
  5173. // polygon() = polygon( [<fill-rule>,]? [<shape-arg> <shape-arg>]# )
  5174. "<basic-shape>": "inset() | circle() | ellipse() | polygon()",
  5175. "<bg-image>": "<image> | <gradient> | none",
  5176. "<border-style>":
  5177. "none | hidden | dotted | dashed | solid | double | groove | " +
  5178. "ridge | inset | outset",
  5179. "<border-width>": "<length> | thin | medium | thick",
  5180. "<box>": "padding-box | border-box | content-box",
  5181. "<clip-source>": "<uri>",
  5182. "<color>": function(part) {
  5183. return part.type === "color" || String(part) === "transparent" || String(part) === "currentColor";
  5184. },
  5185. // The SVG <color> spec doesn't include "currentColor" or "transparent" as a color.
  5186. "<color-svg>": function(part) {
  5187. return part.type === "color";
  5188. },
  5189. "<content>": "content()",
  5190. // https://www.w3.org/TR/css3-sizing/#width-height-keywords
  5191. "<content-sizing>":
  5192. "fill-available | -moz-available | -webkit-fill-available | " +
  5193. "max-content | -moz-max-content | -webkit-max-content | " +
  5194. "min-content | -moz-min-content | -webkit-min-content | " +
  5195. "fit-content | -moz-fit-content | -webkit-fit-content",
  5196. "<feature-tag-value>": function(part) {
  5197. return part.type === "function" && /^[A-Z0-9]{4}$/i.test(part);
  5198. },
  5199. // custom() isn't actually in the spec
  5200. "<filter-function>":
  5201. "blur() | brightness() | contrast() | custom() | " +
  5202. "drop-shadow() | grayscale() | hue-rotate() | invert() | " +
  5203. "opacity() | saturate() | sepia()",
  5204. "<flex-basis>": "<width>",
  5205. "<flex-direction>": "row | row-reverse | column | column-reverse",
  5206. "<flex-grow>": "<number>",
  5207. "<flex-shrink>": "<number>",
  5208. "<flex-wrap>": "nowrap | wrap | wrap-reverse",
  5209. "<font-size>":
  5210. "<absolute-size> | <relative-size> | <length> | <percentage>",
  5211. "<font-stretch>":
  5212. "normal | ultra-condensed | extra-condensed | condensed | " +
  5213. "semi-condensed | semi-expanded | expanded | extra-expanded | " +
  5214. "ultra-expanded",
  5215. "<font-style>": "normal | italic | oblique",
  5216. "<font-variant-caps>":
  5217. "small-caps | all-small-caps | petite-caps | all-petite-caps | " +
  5218. "unicase | titling-caps",
  5219. "<font-variant-css21>": "normal | small-caps",
  5220. "<font-weight>":
  5221. "normal | bold | bolder | lighter | " +
  5222. "100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900",
  5223. "<generic-family>":
  5224. "serif | sans-serif | cursive | fantasy | monospace",
  5225. "<geometry-box>": "<shape-box> | fill-box | stroke-box | view-box",
  5226. "<glyph-angle>": function(part) {
  5227. return part.type === "angle" && part.units === "deg";
  5228. },
  5229. "<gradient>": function(part) {
  5230. return part.type === "function" && /^(?:\-(?:ms|moz|o|webkit)\-)?(?:repeating\-)?(?:radial\-|linear\-)?gradient/i.test(part);
  5231. },
  5232. "<icccolor>":
  5233. "cielab() | cielch() | cielchab() | " +
  5234. "icc-color() | icc-named-color()",
  5235. //any identifier
  5236. "<ident>": function(part) {
  5237. return part.type === "identifier" || part.wasIdent;
  5238. },
  5239. "<ident-not-generic-family>": function(part) {
  5240. return this["<ident>"](part) && !this["<generic-family>"](part);
  5241. },
  5242. "<image>": "<uri>",
  5243. "<integer>": function(part) {
  5244. return part.type === "integer";
  5245. },
  5246. "<length>": function(part) {
  5247. if (part.type === "function" && /^(?:\-(?:ms|moz|o|webkit)\-)?calc/i.test(part)) {
  5248. return true;
  5249. } else {
  5250. return part.type === "length" || part.type === "number" || part.type === "integer" || String(part) === "0";
  5251. }
  5252. },
  5253. "<line>": function(part) {
  5254. return part.type === "integer";
  5255. },
  5256. "<line-height>": "<number> | <length> | <percentage> | normal",
  5257. "<margin-width>": "<length> | <percentage> | auto",
  5258. "<miterlimit>": function(part) {
  5259. return this["<number>"](part) && part.value >= 1;
  5260. },
  5261. "<nonnegative-length-or-percentage>": function(part) {
  5262. return (this["<length>"](part) || this["<percentage>"](part)) &&
  5263. (String(part) === "0" || part.type === "function" || (part.value) >= 0);
  5264. },
  5265. "<nonnegative-number-or-percentage>": function(part) {
  5266. return (this["<number>"](part) || this["<percentage>"](part)) &&
  5267. (String(part) === "0" || part.type === "function" || (part.value) >= 0);
  5268. },
  5269. "<number>": function(part) {
  5270. return part.type === "number" || this["<integer>"](part);
  5271. },
  5272. "<opacity-value>": function(part) {
  5273. return this["<number>"](part) && part.value >= 0 && part.value <= 1;
  5274. },
  5275. "<padding-width>": "<nonnegative-length-or-percentage>",
  5276. "<percentage>": function(part) {
  5277. return part.type === "percentage" || String(part) === "0";
  5278. },
  5279. "<relative-size>": "smaller | larger",
  5280. "<shape>": "rect() | inset-rect()",
  5281. "<shape-box>": "<box> | margin-box",
  5282. "<single-animation-direction>":
  5283. "normal | reverse | alternate | alternate-reverse",
  5284. "<single-animation-name>": function(part) {
  5285. return this["<ident>"](part) &&
  5286. /^-?[a-z_][-a-z0-9_]+$/i.test(part) &&
  5287. !/^(none|unset|initial|inherit)$/i.test(part);
  5288. },
  5289. "<string>": function(part) {
  5290. return part.type === "string";
  5291. },
  5292. "<time>": function(part) {
  5293. return part.type === "time";
  5294. },
  5295. "<uri>": function(part) {
  5296. return part.type === "uri";
  5297. },
  5298. "<width>": "<margin-width>"
  5299. },
  5300. complex: {
  5301. __proto__: null,
  5302. "<azimuth>":
  5303. "<angle>" +
  5304. " | " +
  5305. "[ [ left-side | far-left | left | center-left | center | " +
  5306. "center-right | right | far-right | right-side ] || behind ]" +
  5307. " | "+
  5308. "leftwards | rightwards",
  5309. "<bg-position>": "<position>#",
  5310. "<bg-size>":
  5311. "[ <length> | <percentage> | auto ]{1,2} | cover | contain",
  5312. "<border-image-slice>":
  5313. // [<number> | <percentage>]{1,4} && fill?
  5314. // *but* fill can appear between any of the numbers
  5315. Matcher.many([true /* first element is required */],
  5316. Matcher.cast("<nonnegative-number-or-percentage>"),
  5317. Matcher.cast("<nonnegative-number-or-percentage>"),
  5318. Matcher.cast("<nonnegative-number-or-percentage>"),
  5319. Matcher.cast("<nonnegative-number-or-percentage>"),
  5320. "fill"),
  5321. "<border-radius>":
  5322. "<nonnegative-length-or-percentage>{1,4} " +
  5323. "[ / <nonnegative-length-or-percentage>{1,4} ]?",
  5324. "<box-shadow>": "none | <shadow>#",
  5325. "<clip-path>": "<basic-shape> || <geometry-box>",
  5326. "<dasharray>":
  5327. // "list of comma and/or white space separated <length>s and
  5328. // <percentage>s". There is a non-negative constraint.
  5329. Matcher.cast("<nonnegative-length-or-percentage>")
  5330. .braces(1, Infinity, "#", Matcher.cast(",").question()),
  5331. "<family-name>":
  5332. // <string> | <IDENT>+
  5333. "<string> | <ident-not-generic-family> <ident>*",
  5334. "<filter-function-list>": "[ <filter-function> | <uri> ]+",
  5335. // https://www.w3.org/TR/2014/WD-css-flexbox-1-20140325/#flex-property
  5336. "<flex>":
  5337. "none | [ <flex-grow> <flex-shrink>? || <flex-basis> ]",
  5338. "<font-family>": "[ <generic-family> | <family-name> ]#",
  5339. "<font-shorthand>":
  5340. "[ <font-style> || <font-variant-css21> || " +
  5341. "<font-weight> || <font-stretch> ]? <font-size> " +
  5342. "[ / <line-height> ]? <font-family>",
  5343. "<font-variant-alternates>":
  5344. // stylistic(<feature-value-name>)
  5345. "stylistic() || " +
  5346. "historical-forms || " +
  5347. // styleset(<feature-value-name> #)
  5348. "styleset() || " +
  5349. // character-variant(<feature-value-name> #)
  5350. "character-variant() || " +
  5351. // swash(<feature-value-name>)
  5352. "swash() || " +
  5353. // ornaments(<feature-value-name>)
  5354. "ornaments() || " +
  5355. // annotation(<feature-value-name>)
  5356. "annotation()",
  5357. "<font-variant-ligatures>":
  5358. // <common-lig-values>
  5359. "[ common-ligatures | no-common-ligatures ] || " +
  5360. // <discretionary-lig-values>
  5361. "[ discretionary-ligatures | no-discretionary-ligatures ] || " +
  5362. // <historical-lig-values>
  5363. "[ historical-ligatures | no-historical-ligatures ] || " +
  5364. // <contextual-alt-values>
  5365. "[ contextual | no-contextual ]",
  5366. "<font-variant-numeric>":
  5367. // <numeric-figure-values>
  5368. "[ lining-nums | oldstyle-nums ] || " +
  5369. // <numeric-spacing-values>
  5370. "[ proportional-nums | tabular-nums ] || " +
  5371. // <numeric-fraction-values>
  5372. "[ diagonal-fractions | stacked-fractions ] || " +
  5373. "ordinal || slashed-zero",
  5374. "<font-variant-east-asian>":
  5375. // <east-asian-variant-values>
  5376. "[ jis78 | jis83 | jis90 | jis04 | simplified | traditional ] || " +
  5377. // <east-asian-width-values>
  5378. "[ full-width | proportional-width ] || " +
  5379. "ruby",
  5380. // Note that <color> here is "as defined in the SVG spec", which
  5381. // is more restrictive that the <color> defined in the CSS spec.
  5382. // none | currentColor | <color> [<icccolor>]? |
  5383. // <funciri> [ none | currentColor | <color> [<icccolor>]? ]?
  5384. "<paint>": "<paint-basic> | <uri> <paint-basic>?",
  5385. // Helper definition for <paint> above.
  5386. "<paint-basic>": "none | currentColor | <color-svg> <icccolor>?",
  5387. "<position>":
  5388. // Because our `alt` combinator is ordered, we need to test these
  5389. // in order from longest possible match to shortest.
  5390. "[ center | [ left | right ] [ <percentage> | <length> ]? ] && " +
  5391. "[ center | [ top | bottom ] [ <percentage> | <length> ]? ]" +
  5392. " | " +
  5393. "[ left | center | right | <percentage> | <length> ] " +
  5394. "[ top | center | bottom | <percentage> | <length> ]" +
  5395. " | " +
  5396. "[ left | center | right | top | bottom | <percentage> | <length> ]",
  5397. "<repeat-style>":
  5398. "repeat-x | repeat-y | [ repeat | space | round | no-repeat ]{1,2}",
  5399. "<shadow>":
  5400. //inset? && [ <length>{2,4} && <color>? ]
  5401. Matcher.many([true /* length is required */],
  5402. Matcher.cast("<length>").braces(2, 4), "inset", "<color>"),
  5403. "<text-decoration-color>":
  5404. "<color>",
  5405. "<text-decoration-line>":
  5406. "none | [ underline || overline || line-through || blink ]",
  5407. "<text-decoration-style>":
  5408. "solid | double | dotted | dashed | wavy",
  5409. "<will-change>":
  5410. "auto | <animateable-feature>#",
  5411. "<x-one-radius>":
  5412. //[ <length> | <percentage> ] [ <length> | <percentage> ]?
  5413. "[ <length> | <percentage> ]{1,2}"
  5414. }
  5415. });
  5416. Object.keys(ValidationTypes.simple).forEach(function(nt) {
  5417. var rule = ValidationTypes.simple[nt];
  5418. if (typeof rule === "string") {
  5419. ValidationTypes.simple[nt] = function(part) {
  5420. return ValidationTypes.isLiteral(part, rule);
  5421. };
  5422. }
  5423. });
  5424. Object.keys(ValidationTypes.complex).forEach(function(nt) {
  5425. var rule = ValidationTypes.complex[nt];
  5426. if (typeof rule === "string") {
  5427. ValidationTypes.complex[nt] = Matcher.parse(rule);
  5428. }
  5429. });
  5430. // Because this is defined relative to other complex validation types,
  5431. // we need to define it *after* the rest of the types are initialized.
  5432. ValidationTypes.complex["<font-variant>"] =
  5433. Matcher.oror({ expand: "<font-variant-ligatures>" },
  5434. { expand: "<font-variant-alternates>" },
  5435. "<font-variant-caps>",
  5436. { expand: "<font-variant-numeric>" },
  5437. { expand: "<font-variant-east-asian>" });
  5438. },{"./Matcher":3}],22:[function(require,module,exports){
  5439. "use strict";
  5440. module.exports = {
  5441. Colors : require("./Colors"),
  5442. Combinator : require("./Combinator"),
  5443. Parser : require("./Parser"),
  5444. PropertyName : require("./PropertyName"),
  5445. PropertyValue : require("./PropertyValue"),
  5446. PropertyValuePart : require("./PropertyValuePart"),
  5447. Matcher : require("./Matcher"),
  5448. MediaFeature : require("./MediaFeature"),
  5449. MediaQuery : require("./MediaQuery"),
  5450. Selector : require("./Selector"),
  5451. SelectorPart : require("./SelectorPart"),
  5452. SelectorSubPart : require("./SelectorSubPart"),
  5453. Specificity : require("./Specificity"),
  5454. TokenStream : require("./TokenStream"),
  5455. Tokens : require("./Tokens"),
  5456. ValidationError : require("./ValidationError")
  5457. };
  5458. },{"./Colors":1,"./Combinator":2,"./Matcher":3,"./MediaFeature":4,"./MediaQuery":5,"./Parser":6,"./PropertyName":8,"./PropertyValue":9,"./PropertyValuePart":11,"./Selector":13,"./SelectorPart":14,"./SelectorSubPart":15,"./Specificity":16,"./TokenStream":17,"./Tokens":18,"./ValidationError":20}],23:[function(require,module,exports){
  5459. "use strict";
  5460. module.exports = EventTarget;
  5461. /**
  5462. * A generic base to inherit from for any object
  5463. * that needs event handling.
  5464. * @class EventTarget
  5465. * @constructor
  5466. */
  5467. function EventTarget() {
  5468. /**
  5469. * The array of listeners for various events.
  5470. * @type Object
  5471. * @property _listeners
  5472. * @private
  5473. */
  5474. this._listeners = Object.create(null);
  5475. }
  5476. EventTarget.prototype = {
  5477. //restore constructor
  5478. constructor: EventTarget,
  5479. /**
  5480. * Adds a listener for a given event type.
  5481. * @param {String} type The type of event to add a listener for.
  5482. * @param {Function} listener The function to call when the event occurs.
  5483. * @return {void}
  5484. * @method addListener
  5485. */
  5486. addListener: function(type, listener) {
  5487. if (!this._listeners[type]) {
  5488. this._listeners[type] = [];
  5489. }
  5490. this._listeners[type].push(listener);
  5491. },
  5492. /**
  5493. * Fires an event based on the passed-in object.
  5494. * @param {Object|String} event An object with at least a 'type' attribute
  5495. * or a string indicating the event name.
  5496. * @return {void}
  5497. * @method fire
  5498. */
  5499. fire: function(event) {
  5500. if (typeof event === "string") {
  5501. event = { type: event };
  5502. }
  5503. if (typeof event.target !== "undefined") {
  5504. event.target = this;
  5505. }
  5506. if (typeof event.type === "undefined") {
  5507. throw new Error("Event object missing 'type' property.");
  5508. }
  5509. if (this._listeners[event.type]) {
  5510. //create a copy of the array and use that so listeners can't chane
  5511. var listeners = this._listeners[event.type].concat();
  5512. for (var i=0, len=listeners.length; i < len; i++) {
  5513. listeners[i].call(this, event);
  5514. }
  5515. }
  5516. },
  5517. /**
  5518. * Removes a listener for a given event type.
  5519. * @param {String} type The type of event to remove a listener from.
  5520. * @param {Function} listener The function to remove from the event.
  5521. * @return {void}
  5522. * @method removeListener
  5523. */
  5524. removeListener: function(type, listener) {
  5525. if (this._listeners[type]) {
  5526. var listeners = this._listeners[type];
  5527. for (var i=0, len=listeners.length; i < len; i++) {
  5528. if (listeners[i] === listener) {
  5529. listeners.splice(i, 1);
  5530. break;
  5531. }
  5532. }
  5533. }
  5534. }
  5535. };
  5536. },{}],24:[function(require,module,exports){
  5537. "use strict";
  5538. module.exports = StringReader;
  5539. /**
  5540. * Convenient way to read through strings.
  5541. * @namespace parserlib.util
  5542. * @class StringReader
  5543. * @constructor
  5544. * @param {String} text The text to read.
  5545. */
  5546. function StringReader(text) {
  5547. /**
  5548. * The input text with line endings normalized.
  5549. * @property _input
  5550. * @type String
  5551. * @private
  5552. */
  5553. this._input = text.replace(/(\r\n?|\n)/g, "\n");
  5554. /**
  5555. * The row for the character to be read next.
  5556. * @property _line
  5557. * @type int
  5558. * @private
  5559. */
  5560. this._line = 1;
  5561. /**
  5562. * The column for the character to be read next.
  5563. * @property _col
  5564. * @type int
  5565. * @private
  5566. */
  5567. this._col = 1;
  5568. /**
  5569. * The index of the character in the input to be read next.
  5570. * @property _cursor
  5571. * @type int
  5572. * @private
  5573. */
  5574. this._cursor = 0;
  5575. }
  5576. StringReader.prototype = {
  5577. // restore constructor
  5578. constructor: StringReader,
  5579. //-------------------------------------------------------------------------
  5580. // Position info
  5581. //-------------------------------------------------------------------------
  5582. /**
  5583. * Returns the column of the character to be read next.
  5584. * @return {int} The column of the character to be read next.
  5585. * @method getCol
  5586. */
  5587. getCol: function() {
  5588. return this._col;
  5589. },
  5590. /**
  5591. * Returns the row of the character to be read next.
  5592. * @return {int} The row of the character to be read next.
  5593. * @method getLine
  5594. */
  5595. getLine: function() {
  5596. return this._line;
  5597. },
  5598. /**
  5599. * Determines if you're at the end of the input.
  5600. * @return {Boolean} True if there's no more input, false otherwise.
  5601. * @method eof
  5602. */
  5603. eof: function() {
  5604. return this._cursor === this._input.length;
  5605. },
  5606. //-------------------------------------------------------------------------
  5607. // Basic reading
  5608. //-------------------------------------------------------------------------
  5609. /**
  5610. * Reads the next character without advancing the cursor.
  5611. * @param {int} count How many characters to look ahead (default is 1).
  5612. * @return {String} The next character or null if there is no next character.
  5613. * @method peek
  5614. */
  5615. peek: function(count) {
  5616. var c = null;
  5617. count = typeof count === "undefined" ? 1 : count;
  5618. // if we're not at the end of the input...
  5619. if (this._cursor < this._input.length) {
  5620. // get character and increment cursor and column
  5621. c = this._input.charAt(this._cursor + count - 1);
  5622. }
  5623. return c;
  5624. },
  5625. /**
  5626. * Reads the next character from the input and adjusts the row and column
  5627. * accordingly.
  5628. * @return {String} The next character or null if there is no next character.
  5629. * @method read
  5630. */
  5631. read: function() {
  5632. var c = null;
  5633. // if we're not at the end of the input...
  5634. if (this._cursor < this._input.length) {
  5635. // if the last character was a newline, increment row count
  5636. // and reset column count
  5637. if (this._input.charAt(this._cursor) === "\n") {
  5638. this._line++;
  5639. this._col=1;
  5640. } else {
  5641. this._col++;
  5642. }
  5643. // get character and increment cursor and column
  5644. c = this._input.charAt(this._cursor++);
  5645. }
  5646. return c;
  5647. },
  5648. //-------------------------------------------------------------------------
  5649. // Misc
  5650. //-------------------------------------------------------------------------
  5651. /**
  5652. * Saves the current location so it can be returned to later.
  5653. * @method mark
  5654. * @return {void}
  5655. */
  5656. mark: function() {
  5657. this._bookmark = {
  5658. cursor: this._cursor,
  5659. line: this._line,
  5660. col: this._col
  5661. };
  5662. },
  5663. reset: function() {
  5664. if (this._bookmark) {
  5665. this._cursor = this._bookmark.cursor;
  5666. this._line = this._bookmark.line;
  5667. this._col = this._bookmark.col;
  5668. delete this._bookmark;
  5669. }
  5670. },
  5671. //-------------------------------------------------------------------------
  5672. // Advanced reading
  5673. //-------------------------------------------------------------------------
  5674. /**
  5675. * Reads up to and including the given string. Throws an error if that
  5676. * string is not found.
  5677. * @param {String} pattern The string to read.
  5678. * @return {String} The string when it is found.
  5679. * @throws Error when the string pattern is not found.
  5680. * @method readTo
  5681. */
  5682. readTo: function(pattern) {
  5683. var buffer = "",
  5684. c;
  5685. /*
  5686. * First, buffer must be the same length as the pattern.
  5687. * Then, buffer must end with the pattern or else reach the
  5688. * end of the input.
  5689. */
  5690. while (buffer.length < pattern.length || buffer.lastIndexOf(pattern) !== buffer.length - pattern.length) {
  5691. c = this.read();
  5692. if (c) {
  5693. buffer += c;
  5694. } else {
  5695. throw new Error("Expected \"" + pattern + "\" at line " + this._line + ", col " + this._col + ".");
  5696. }
  5697. }
  5698. return buffer;
  5699. },
  5700. /**
  5701. * Reads characters while each character causes the given
  5702. * filter function to return true. The function is passed
  5703. * in each character and either returns true to continue
  5704. * reading or false to stop.
  5705. * @param {Function} filter The function to read on each character.
  5706. * @return {String} The string made up of all characters that passed the
  5707. * filter check.
  5708. * @method readWhile
  5709. */
  5710. readWhile: function(filter) {
  5711. var buffer = "",
  5712. c = this.peek();
  5713. while (c !== null && filter(c)) {
  5714. buffer += this.read();
  5715. c = this.peek();
  5716. }
  5717. return buffer;
  5718. },
  5719. /**
  5720. * Reads characters that match either text or a regular expression and
  5721. * returns those characters. If a match is found, the row and column
  5722. * are adjusted; if no match is found, the reader's state is unchanged.
  5723. * reading or false to stop.
  5724. * @param {String|RegExp} matcher If a string, then the literal string
  5725. * value is searched for. If a regular expression, then any string
  5726. * matching the pattern is search for.
  5727. * @return {String} The string made up of all characters that matched or
  5728. * null if there was no match.
  5729. * @method readMatch
  5730. */
  5731. readMatch: function(matcher) {
  5732. var source = this._input.substring(this._cursor),
  5733. value = null;
  5734. // if it's a string, just do a straight match
  5735. if (typeof matcher === "string") {
  5736. if (source.slice(0, matcher.length) === matcher) {
  5737. value = this.readCount(matcher.length);
  5738. }
  5739. } else if (matcher instanceof RegExp) {
  5740. if (matcher.test(source)) {
  5741. value = this.readCount(RegExp.lastMatch.length);
  5742. }
  5743. }
  5744. return value;
  5745. },
  5746. /**
  5747. * Reads a given number of characters. If the end of the input is reached,
  5748. * it reads only the remaining characters and does not throw an error.
  5749. * @param {int} count The number of characters to read.
  5750. * @return {String} The string made up the read characters.
  5751. * @method readCount
  5752. */
  5753. readCount: function(count) {
  5754. var buffer = "";
  5755. while (count--) {
  5756. buffer += this.read();
  5757. }
  5758. return buffer;
  5759. }
  5760. };
  5761. },{}],25:[function(require,module,exports){
  5762. "use strict";
  5763. module.exports = SyntaxError;
  5764. /**
  5765. * Type to use when a syntax error occurs.
  5766. * @class SyntaxError
  5767. * @namespace parserlib.util
  5768. * @constructor
  5769. * @param {String} message The error message.
  5770. * @param {int} line The line at which the error occurred.
  5771. * @param {int} col The column at which the error occurred.
  5772. */
  5773. function SyntaxError(message, line, col) {
  5774. Error.call(this);
  5775. this.name = this.constructor.name;
  5776. /**
  5777. * The column at which the error occurred.
  5778. * @type int
  5779. * @property col
  5780. */
  5781. this.col = col;
  5782. /**
  5783. * The line at which the error occurred.
  5784. * @type int
  5785. * @property line
  5786. */
  5787. this.line = line;
  5788. /**
  5789. * The text representation of the unit.
  5790. * @type String
  5791. * @property text
  5792. */
  5793. this.message = message;
  5794. }
  5795. //inherit from Error
  5796. SyntaxError.prototype = Object.create(Error.prototype); // jshint ignore:line
  5797. SyntaxError.prototype.constructor = SyntaxError; // jshint ignore:line
  5798. },{}],26:[function(require,module,exports){
  5799. "use strict";
  5800. module.exports = SyntaxUnit;
  5801. /**
  5802. * Base type to represent a single syntactic unit.
  5803. * @class SyntaxUnit
  5804. * @namespace parserlib.util
  5805. * @constructor
  5806. * @param {String} text The text of the unit.
  5807. * @param {int} line The line of text on which the unit resides.
  5808. * @param {int} col The column of text on which the unit resides.
  5809. */
  5810. function SyntaxUnit(text, line, col, type) {
  5811. /**
  5812. * The column of text on which the unit resides.
  5813. * @type int
  5814. * @property col
  5815. */
  5816. this.col = col;
  5817. /**
  5818. * The line of text on which the unit resides.
  5819. * @type int
  5820. * @property line
  5821. */
  5822. this.line = line;
  5823. /**
  5824. * The text representation of the unit.
  5825. * @type String
  5826. * @property text
  5827. */
  5828. this.text = text;
  5829. /**
  5830. * The type of syntax unit.
  5831. * @type int
  5832. * @property type
  5833. */
  5834. this.type = type;
  5835. }
  5836. /**
  5837. * Create a new syntax unit based solely on the given token.
  5838. * Convenience method for creating a new syntax unit when
  5839. * it represents a single token instead of multiple.
  5840. * @param {Object} token The token object to represent.
  5841. * @return {parserlib.util.SyntaxUnit} The object representing the token.
  5842. * @static
  5843. * @method fromToken
  5844. */
  5845. SyntaxUnit.fromToken = function(token) {
  5846. return new SyntaxUnit(token.value, token.startLine, token.startCol);
  5847. };
  5848. SyntaxUnit.prototype = {
  5849. //restore constructor
  5850. constructor: SyntaxUnit,
  5851. /**
  5852. * Returns the text representation of the unit.
  5853. * @return {String} The text representation of the unit.
  5854. * @method valueOf
  5855. */
  5856. valueOf: function() {
  5857. return this.toString();
  5858. },
  5859. /**
  5860. * Returns the text representation of the unit.
  5861. * @return {String} The text representation of the unit.
  5862. * @method toString
  5863. */
  5864. toString: function() {
  5865. return this.text;
  5866. }
  5867. };
  5868. },{}],27:[function(require,module,exports){
  5869. "use strict";
  5870. module.exports = TokenStreamBase;
  5871. var StringReader = require("./StringReader");
  5872. var SyntaxError = require("./SyntaxError");
  5873. /**
  5874. * Generic TokenStream providing base functionality.
  5875. * @class TokenStreamBase
  5876. * @namespace parserlib.util
  5877. * @constructor
  5878. * @param {String|StringReader} input The text to tokenize or a reader from
  5879. * which to read the input.
  5880. */
  5881. function TokenStreamBase(input, tokenData) {
  5882. /**
  5883. * The string reader for easy access to the text.
  5884. * @type StringReader
  5885. * @property _reader
  5886. * @private
  5887. */
  5888. this._reader = new StringReader(input ? input.toString() : "");
  5889. /**
  5890. * Token object for the last consumed token.
  5891. * @type Token
  5892. * @property _token
  5893. * @private
  5894. */
  5895. this._token = null;
  5896. /**
  5897. * The array of token information.
  5898. * @type Array
  5899. * @property _tokenData
  5900. * @private
  5901. */
  5902. this._tokenData = tokenData;
  5903. /**
  5904. * Lookahead token buffer.
  5905. * @type Array
  5906. * @property _lt
  5907. * @private
  5908. */
  5909. this._lt = [];
  5910. /**
  5911. * Lookahead token buffer index.
  5912. * @type int
  5913. * @property _ltIndex
  5914. * @private
  5915. */
  5916. this._ltIndex = 0;
  5917. this._ltIndexCache = [];
  5918. }
  5919. /**
  5920. * Accepts an array of token information and outputs
  5921. * an array of token data containing key-value mappings
  5922. * and matching functions that the TokenStream needs.
  5923. * @param {Array} tokens An array of token descriptors.
  5924. * @return {Array} An array of processed token data.
  5925. * @method createTokenData
  5926. * @static
  5927. */
  5928. TokenStreamBase.createTokenData = function(tokens) {
  5929. var nameMap = [],
  5930. typeMap = Object.create(null),
  5931. tokenData = tokens.concat([]),
  5932. i = 0,
  5933. len = tokenData.length+1;
  5934. tokenData.UNKNOWN = -1;
  5935. tokenData.unshift({ name:"EOF" });
  5936. for (; i < len; i++) {
  5937. nameMap.push(tokenData[i].name);
  5938. tokenData[tokenData[i].name] = i;
  5939. if (tokenData[i].text) {
  5940. typeMap[tokenData[i].text] = i;
  5941. }
  5942. }
  5943. tokenData.name = function(tt) {
  5944. return nameMap[tt];
  5945. };
  5946. tokenData.type = function(c) {
  5947. return typeMap[c];
  5948. };
  5949. return tokenData;
  5950. };
  5951. TokenStreamBase.prototype = {
  5952. //restore constructor
  5953. constructor: TokenStreamBase,
  5954. //-------------------------------------------------------------------------
  5955. // Matching methods
  5956. //-------------------------------------------------------------------------
  5957. /**
  5958. * Determines if the next token matches the given token type.
  5959. * If so, that token is consumed; if not, the token is placed
  5960. * back onto the token stream. You can pass in any number of
  5961. * token types and this will return true if any of the token
  5962. * types is found.
  5963. * @param {int|int[]} tokenTypes Either a single token type or an array of
  5964. * token types that the next token might be. If an array is passed,
  5965. * it's assumed that the token can be any of these.
  5966. * @param {variant} channel (Optional) The channel to read from. If not
  5967. * provided, reads from the default (unnamed) channel.
  5968. * @return {Boolean} True if the token type matches, false if not.
  5969. * @method match
  5970. */
  5971. match: function(tokenTypes, channel) {
  5972. //always convert to an array, makes things easier
  5973. if (!(tokenTypes instanceof Array)) {
  5974. tokenTypes = [tokenTypes];
  5975. }
  5976. var tt = this.get(channel),
  5977. i = 0,
  5978. len = tokenTypes.length;
  5979. while (i < len) {
  5980. if (tt === tokenTypes[i++]) {
  5981. return true;
  5982. }
  5983. }
  5984. //no match found, put the token back
  5985. this.unget();
  5986. return false;
  5987. },
  5988. /**
  5989. * Determines if the next token matches the given token type.
  5990. * If so, that token is consumed; if not, an error is thrown.
  5991. * @param {int|int[]} tokenTypes Either a single token type or an array of
  5992. * token types that the next token should be. If an array is passed,
  5993. * it's assumed that the token must be one of these.
  5994. * @return {void}
  5995. * @method mustMatch
  5996. */
  5997. mustMatch: function(tokenTypes) {
  5998. var token;
  5999. //always convert to an array, makes things easier
  6000. if (!(tokenTypes instanceof Array)) {
  6001. tokenTypes = [tokenTypes];
  6002. }
  6003. if (!this.match.apply(this, arguments)) {
  6004. token = this.LT(1);
  6005. throw new SyntaxError("Expected " + this._tokenData[tokenTypes[0]].name +
  6006. " at line " + token.startLine + ", col " + token.startCol + ".", token.startLine, token.startCol);
  6007. }
  6008. },
  6009. //-------------------------------------------------------------------------
  6010. // Consuming methods
  6011. //-------------------------------------------------------------------------
  6012. /**
  6013. * Keeps reading from the token stream until either one of the specified
  6014. * token types is found or until the end of the input is reached.
  6015. * @param {int|int[]} tokenTypes Either a single token type or an array of
  6016. * token types that the next token should be. If an array is passed,
  6017. * it's assumed that the token must be one of these.
  6018. * @param {variant} channel (Optional) The channel to read from. If not
  6019. * provided, reads from the default (unnamed) channel.
  6020. * @return {void}
  6021. * @method advance
  6022. */
  6023. advance: function(tokenTypes, channel) {
  6024. while (this.LA(0) !== 0 && !this.match(tokenTypes, channel)) {
  6025. this.get();
  6026. }
  6027. return this.LA(0);
  6028. },
  6029. /**
  6030. * Consumes the next token from the token stream.
  6031. * @return {int} The token type of the token that was just consumed.
  6032. * @method get
  6033. */
  6034. get: function(channel) {
  6035. var tokenInfo = this._tokenData,
  6036. i =0,
  6037. token,
  6038. info;
  6039. //check the lookahead buffer first
  6040. if (this._lt.length && this._ltIndex >= 0 && this._ltIndex < this._lt.length) {
  6041. i++;
  6042. this._token = this._lt[this._ltIndex++];
  6043. info = tokenInfo[this._token.type];
  6044. //obey channels logic
  6045. while ((info.channel !== undefined && channel !== info.channel) &&
  6046. this._ltIndex < this._lt.length) {
  6047. this._token = this._lt[this._ltIndex++];
  6048. info = tokenInfo[this._token.type];
  6049. i++;
  6050. }
  6051. //here be dragons
  6052. if ((info.channel === undefined || channel === info.channel) &&
  6053. this._ltIndex <= this._lt.length) {
  6054. this._ltIndexCache.push(i);
  6055. return this._token.type;
  6056. }
  6057. }
  6058. //call token retriever method
  6059. token = this._getToken();
  6060. //if it should be hidden, don't save a token
  6061. if (token.type > -1 && !tokenInfo[token.type].hide) {
  6062. //apply token channel
  6063. token.channel = tokenInfo[token.type].channel;
  6064. //save for later
  6065. this._token = token;
  6066. this._lt.push(token);
  6067. //save space that will be moved (must be done before array is truncated)
  6068. this._ltIndexCache.push(this._lt.length - this._ltIndex + i);
  6069. //keep the buffer under 5 items
  6070. if (this._lt.length > 5) {
  6071. this._lt.shift();
  6072. }
  6073. //also keep the shift buffer under 5 items
  6074. if (this._ltIndexCache.length > 5) {
  6075. this._ltIndexCache.shift();
  6076. }
  6077. //update lookahead index
  6078. this._ltIndex = this._lt.length;
  6079. }
  6080. /*
  6081. * Skip to the next token if:
  6082. * 1. The token type is marked as hidden.
  6083. * 2. The token type has a channel specified and it isn't the current channel.
  6084. */
  6085. info = tokenInfo[token.type];
  6086. if (info &&
  6087. (info.hide ||
  6088. (info.channel !== undefined && channel !== info.channel))) {
  6089. return this.get(channel);
  6090. } else {
  6091. //return just the type
  6092. return token.type;
  6093. }
  6094. },
  6095. /**
  6096. * Looks ahead a certain number of tokens and returns the token type at
  6097. * that position. This will throw an error if you lookahead past the
  6098. * end of input, past the size of the lookahead buffer, or back past
  6099. * the first token in the lookahead buffer.
  6100. * @param {int} The index of the token type to retrieve. 0 for the
  6101. * current token, 1 for the next, -1 for the previous, etc.
  6102. * @return {int} The token type of the token in the given position.
  6103. * @method LA
  6104. */
  6105. LA: function(index) {
  6106. var total = index,
  6107. tt;
  6108. if (index > 0) {
  6109. //TODO: Store 5 somewhere
  6110. if (index > 5) {
  6111. throw new Error("Too much lookahead.");
  6112. }
  6113. //get all those tokens
  6114. while (total) {
  6115. tt = this.get();
  6116. total--;
  6117. }
  6118. //unget all those tokens
  6119. while (total < index) {
  6120. this.unget();
  6121. total++;
  6122. }
  6123. } else if (index < 0) {
  6124. if (this._lt[this._ltIndex+index]) {
  6125. tt = this._lt[this._ltIndex+index].type;
  6126. } else {
  6127. throw new Error("Too much lookbehind.");
  6128. }
  6129. } else {
  6130. tt = this._token.type;
  6131. }
  6132. return tt;
  6133. },
  6134. /**
  6135. * Looks ahead a certain number of tokens and returns the token at
  6136. * that position. This will throw an error if you lookahead past the
  6137. * end of input, past the size of the lookahead buffer, or back past
  6138. * the first token in the lookahead buffer.
  6139. * @param {int} The index of the token type to retrieve. 0 for the
  6140. * current token, 1 for the next, -1 for the previous, etc.
  6141. * @return {Object} The token of the token in the given position.
  6142. * @method LA
  6143. */
  6144. LT: function(index) {
  6145. //lookahead first to prime the token buffer
  6146. this.LA(index);
  6147. //now find the token, subtract one because _ltIndex is already at the next index
  6148. return this._lt[this._ltIndex+index-1];
  6149. },
  6150. /**
  6151. * Returns the token type for the next token in the stream without
  6152. * consuming it.
  6153. * @return {int} The token type of the next token in the stream.
  6154. * @method peek
  6155. */
  6156. peek: function() {
  6157. return this.LA(1);
  6158. },
  6159. /**
  6160. * Returns the actual token object for the last consumed token.
  6161. * @return {Token} The token object for the last consumed token.
  6162. * @method token
  6163. */
  6164. token: function() {
  6165. return this._token;
  6166. },
  6167. /**
  6168. * Returns the name of the token for the given token type.
  6169. * @param {int} tokenType The type of token to get the name of.
  6170. * @return {String} The name of the token or "UNKNOWN_TOKEN" for any
  6171. * invalid token type.
  6172. * @method tokenName
  6173. */
  6174. tokenName: function(tokenType) {
  6175. if (tokenType < 0 || tokenType > this._tokenData.length) {
  6176. return "UNKNOWN_TOKEN";
  6177. } else {
  6178. return this._tokenData[tokenType].name;
  6179. }
  6180. },
  6181. /**
  6182. * Returns the token type value for the given token name.
  6183. * @param {String} tokenName The name of the token whose value should be returned.
  6184. * @return {int} The token type value for the given token name or -1
  6185. * for an unknown token.
  6186. * @method tokenName
  6187. */
  6188. tokenType: function(tokenName) {
  6189. return this._tokenData[tokenName] || -1;
  6190. },
  6191. /**
  6192. * Returns the last consumed token to the token stream.
  6193. * @method unget
  6194. */
  6195. unget: function() {
  6196. //if (this._ltIndex > -1) {
  6197. if (this._ltIndexCache.length) {
  6198. this._ltIndex -= this._ltIndexCache.pop();//--;
  6199. this._token = this._lt[this._ltIndex - 1];
  6200. } else {
  6201. throw new Error("Too much lookahead.");
  6202. }
  6203. }
  6204. };
  6205. },{"./StringReader":24,"./SyntaxError":25}],28:[function(require,module,exports){
  6206. "use strict";
  6207. module.exports = {
  6208. StringReader : require("./StringReader"),
  6209. SyntaxError : require("./SyntaxError"),
  6210. SyntaxUnit : require("./SyntaxUnit"),
  6211. EventTarget : require("./EventTarget"),
  6212. TokenStreamBase : require("./TokenStreamBase")
  6213. };
  6214. },{"./EventTarget":23,"./StringReader":24,"./SyntaxError":25,"./SyntaxUnit":26,"./TokenStreamBase":27}],"parserlib":[function(require,module,exports){
  6215. "use strict";
  6216. module.exports = {
  6217. css : require("./css"),
  6218. util : require("./util")
  6219. };
  6220. },{"./css":22,"./util":28}]},{},[]);
  6221. return require('parserlib');
  6222. })();
  6223. var clone = (function() {
  6224. 'use strict';
  6225. var nativeMap;
  6226. try {
  6227. nativeMap = Map;
  6228. } catch(_) {
  6229. // maybe a reference error because no `Map`. Give it a dummy value that no
  6230. // value will ever be an instanceof.
  6231. nativeMap = function() {};
  6232. }
  6233. var nativeSet;
  6234. try {
  6235. nativeSet = Set;
  6236. } catch(_) {
  6237. nativeSet = function() {};
  6238. }
  6239. var nativePromise;
  6240. try {
  6241. nativePromise = Promise;
  6242. } catch(_) {
  6243. nativePromise = function() {};
  6244. }
  6245. /**
  6246. * Clones (copies) an Object using deep copying.
  6247. *
  6248. * This function supports circular references by default, but if you are certain
  6249. * there are no circular references in your object, you can save some CPU time
  6250. * by calling clone(obj, false).
  6251. *
  6252. * Caution: if `circular` is false and `parent` contains circular references,
  6253. * your program may enter an infinite loop and crash.
  6254. *
  6255. * @param `parent` - the object to be cloned
  6256. * @param `circular` - set to true if the object to be cloned may contain
  6257. * circular references. (optional - true by default)
  6258. * @param `depth` - set to a number if the object is only to be cloned to
  6259. * a particular depth. (optional - defaults to Infinity)
  6260. * @param `prototype` - sets the prototype to be used when cloning an object.
  6261. * (optional - defaults to parent prototype).
  6262. * @param `includeNonEnumerable` - set to true if the non-enumerable properties
  6263. * should be cloned as well. Non-enumerable properties on the prototype
  6264. * chain will be ignored. (optional - false by default)
  6265. */
  6266. function clone(parent, circular, depth, prototype, includeNonEnumerable) {
  6267. if (typeof circular === 'object') {
  6268. depth = circular.depth;
  6269. prototype = circular.prototype;
  6270. includeNonEnumerable = circular.includeNonEnumerable;
  6271. circular = circular.circular;
  6272. }
  6273. // maintain two arrays for circular references, where corresponding parents
  6274. // and children have the same index
  6275. var allParents = [];
  6276. var allChildren = [];
  6277. var useBuffer = typeof Buffer != 'undefined';
  6278. if (typeof circular == 'undefined')
  6279. circular = true;
  6280. if (typeof depth == 'undefined')
  6281. depth = Infinity;
  6282. // recurse this function so we don't reset allParents and allChildren
  6283. function _clone(parent, depth) {
  6284. // cloning null always returns null
  6285. if (parent === null)
  6286. return null;
  6287. if (depth === 0)
  6288. return parent;
  6289. var child;
  6290. var proto;
  6291. if (typeof parent != 'object') {
  6292. return parent;
  6293. }
  6294. if (parent instanceof nativeMap) {
  6295. child = new nativeMap();
  6296. } else if (parent instanceof nativeSet) {
  6297. child = new nativeSet();
  6298. } else if (parent instanceof nativePromise) {
  6299. child = new nativePromise(function (resolve, reject) {
  6300. parent.then(function(value) {
  6301. resolve(_clone(value, depth - 1));
  6302. }, function(err) {
  6303. reject(_clone(err, depth - 1));
  6304. });
  6305. });
  6306. } else if (clone.__isArray(parent)) {
  6307. child = [];
  6308. } else if (clone.__isRegExp(parent)) {
  6309. child = new RegExp(parent.source, __getRegExpFlags(parent));
  6310. if (parent.lastIndex) child.lastIndex = parent.lastIndex;
  6311. } else if (clone.__isDate(parent)) {
  6312. child = new Date(parent.getTime());
  6313. } else if (useBuffer && Buffer.isBuffer(parent)) {
  6314. child = new Buffer(parent.length);
  6315. parent.copy(child);
  6316. return child;
  6317. } else if (parent instanceof Error) {
  6318. child = Object.create(parent);
  6319. } else {
  6320. if (typeof prototype == 'undefined') {
  6321. proto = Object.getPrototypeOf(parent);
  6322. child = Object.create(proto);
  6323. }
  6324. else {
  6325. child = Object.create(prototype);
  6326. proto = prototype;
  6327. }
  6328. }
  6329. if (circular) {
  6330. var index = allParents.indexOf(parent);
  6331. if (index != -1) {
  6332. return allChildren[index];
  6333. }
  6334. allParents.push(parent);
  6335. allChildren.push(child);
  6336. }
  6337. if (parent instanceof nativeMap) {
  6338. var keyIterator = parent.keys();
  6339. while(true) {
  6340. var next = keyIterator.next();
  6341. if (next.done) {
  6342. break;
  6343. }
  6344. var keyChild = _clone(next.value, depth - 1);
  6345. var valueChild = _clone(parent.get(next.value), depth - 1);
  6346. child.set(keyChild, valueChild);
  6347. }
  6348. }
  6349. if (parent instanceof nativeSet) {
  6350. var iterator = parent.keys();
  6351. while(true) {
  6352. var next = iterator.next();
  6353. if (next.done) {
  6354. break;
  6355. }
  6356. var entryChild = _clone(next.value, depth - 1);
  6357. child.add(entryChild);
  6358. }
  6359. }
  6360. for (var i in parent) {
  6361. var attrs;
  6362. if (proto) {
  6363. attrs = Object.getOwnPropertyDescriptor(proto, i);
  6364. }
  6365. if (attrs && attrs.set == null) {
  6366. continue;
  6367. }
  6368. child[i] = _clone(parent[i], depth - 1);
  6369. }
  6370. if (Object.getOwnPropertySymbols) {
  6371. var symbols = Object.getOwnPropertySymbols(parent);
  6372. for (var i = 0; i < symbols.length; i++) {
  6373. // Don't need to worry about cloning a symbol because it is a primitive,
  6374. // like a number or string.
  6375. var symbol = symbols[i];
  6376. var descriptor = Object.getOwnPropertyDescriptor(parent, symbol);
  6377. if (descriptor && !descriptor.enumerable && !includeNonEnumerable) {
  6378. continue;
  6379. }
  6380. child[symbol] = _clone(parent[symbol], depth - 1);
  6381. if (!descriptor.enumerable) {
  6382. Object.defineProperty(child, symbol, {
  6383. enumerable: false
  6384. });
  6385. }
  6386. }
  6387. }
  6388. if (includeNonEnumerable) {
  6389. var allPropertyNames = Object.getOwnPropertyNames(parent);
  6390. for (var i = 0; i < allPropertyNames.length; i++) {
  6391. var propertyName = allPropertyNames[i];
  6392. var descriptor = Object.getOwnPropertyDescriptor(parent, propertyName);
  6393. if (descriptor && descriptor.enumerable) {
  6394. continue;
  6395. }
  6396. child[propertyName] = _clone(parent[propertyName], depth - 1);
  6397. Object.defineProperty(child, propertyName, {
  6398. enumerable: false
  6399. });
  6400. }
  6401. }
  6402. return child;
  6403. }
  6404. return _clone(parent, depth);
  6405. }
  6406. /**
  6407. * Simple flat clone using prototype, accepts only objects, usefull for property
  6408. * override on FLAT configuration object (no nested props).
  6409. *
  6410. * USE WITH CAUTION! This may not behave as you wish if you do not know how this
  6411. * works.
  6412. */
  6413. clone.clonePrototype = function clonePrototype(parent) {
  6414. if (parent === null)
  6415. return null;
  6416. var c = function () {};
  6417. c.prototype = parent;
  6418. return new c();
  6419. };
  6420. // private utility functions
  6421. function __objToStr(o) {
  6422. return Object.prototype.toString.call(o);
  6423. }
  6424. clone.__objToStr = __objToStr;
  6425. function __isDate(o) {
  6426. return typeof o === 'object' && __objToStr(o) === '[object Date]';
  6427. }
  6428. clone.__isDate = __isDate;
  6429. function __isArray(o) {
  6430. return typeof o === 'object' && __objToStr(o) === '[object Array]';
  6431. }
  6432. clone.__isArray = __isArray;
  6433. function __isRegExp(o) {
  6434. return typeof o === 'object' && __objToStr(o) === '[object RegExp]';
  6435. }
  6436. clone.__isRegExp = __isRegExp;
  6437. function __getRegExpFlags(re) {
  6438. var flags = '';
  6439. if (re.global) flags += 'g';
  6440. if (re.ignoreCase) flags += 'i';
  6441. if (re.multiline) flags += 'm';
  6442. return flags;
  6443. }
  6444. clone.__getRegExpFlags = __getRegExpFlags;
  6445. return clone;
  6446. })();
  6447. if (typeof module === 'object' && module.exports) {
  6448. module.exports = clone;
  6449. }
  6450. /**
  6451. * Main CSSLint object.
  6452. * @class CSSLint
  6453. * @static
  6454. * @extends parserlib.util.EventTarget
  6455. */
  6456. /* global parserlib, clone, Reporter */
  6457. /* exported CSSLint */
  6458. var CSSLint = (function() {
  6459. "use strict";
  6460. var rules = [],
  6461. formatters = [],
  6462. embeddedRuleset = /\/\*\s*csslint([^\*]*)\*\//,
  6463. api = new parserlib.util.EventTarget();
  6464. api.version = "1.0.4";
  6465. //-------------------------------------------------------------------------
  6466. // Rule Management
  6467. //-------------------------------------------------------------------------
  6468. /**
  6469. * Adds a new rule to the engine.
  6470. * @param {Object} rule The rule to add.
  6471. * @method addRule
  6472. */
  6473. api.addRule = function(rule) {
  6474. rules.push(rule);
  6475. rules[rule.id] = rule;
  6476. };
  6477. /**
  6478. * Clears all rule from the engine.
  6479. * @method clearRules
  6480. */
  6481. api.clearRules = function() {
  6482. rules = [];
  6483. };
  6484. /**
  6485. * Returns the rule objects.
  6486. * @return An array of rule objects.
  6487. * @method getRules
  6488. */
  6489. api.getRules = function() {
  6490. return [].concat(rules).sort(function(a, b) {
  6491. return a.id > b.id ? 1 : 0;
  6492. });
  6493. };
  6494. /**
  6495. * Returns a ruleset configuration object with all current rules.
  6496. * @return A ruleset object.
  6497. * @method getRuleset
  6498. */
  6499. api.getRuleset = function() {
  6500. var ruleset = {},
  6501. i = 0,
  6502. len = rules.length;
  6503. while (i < len) {
  6504. ruleset[rules[i++].id] = 1; // by default, everything is a warning
  6505. }
  6506. return ruleset;
  6507. };
  6508. /**
  6509. * Returns a ruleset object based on embedded rules.
  6510. * @param {String} text A string of css containing embedded rules.
  6511. * @param {Object} ruleset A ruleset object to modify.
  6512. * @return {Object} A ruleset object.
  6513. * @method getEmbeddedRuleset
  6514. */
  6515. function applyEmbeddedRuleset(text, ruleset) {
  6516. var valueMap,
  6517. embedded = text && text.match(embeddedRuleset),
  6518. rules = embedded && embedded[1];
  6519. if (rules) {
  6520. valueMap = {
  6521. "true": 2, // true is error
  6522. "": 1, // blank is warning
  6523. "false": 0, // false is ignore
  6524. "2": 2, // explicit error
  6525. "1": 1, // explicit warning
  6526. "0": 0 // explicit ignore
  6527. };
  6528. rules.toLowerCase().split(",").forEach(function(rule) {
  6529. var pair = rule.split(":"),
  6530. property = pair[0] || "",
  6531. value = pair[1] || "";
  6532. ruleset[property.trim()] = valueMap[value.trim()];
  6533. });
  6534. }
  6535. return ruleset;
  6536. }
  6537. //-------------------------------------------------------------------------
  6538. // Formatters
  6539. //-------------------------------------------------------------------------
  6540. /**
  6541. * Adds a new formatter to the engine.
  6542. * @param {Object} formatter The formatter to add.
  6543. * @method addFormatter
  6544. */
  6545. api.addFormatter = function(formatter) {
  6546. // formatters.push(formatter);
  6547. formatters[formatter.id] = formatter;
  6548. };
  6549. /**
  6550. * Retrieves a formatter for use.
  6551. * @param {String} formatId The name of the format to retrieve.
  6552. * @return {Object} The formatter or undefined.
  6553. * @method getFormatter
  6554. */
  6555. api.getFormatter = function(formatId) {
  6556. return formatters[formatId];
  6557. };
  6558. /**
  6559. * Formats the results in a particular format for a single file.
  6560. * @param {Object} result The results returned from CSSLint.verify().
  6561. * @param {String} filename The filename for which the results apply.
  6562. * @param {String} formatId The name of the formatter to use.
  6563. * @param {Object} options (Optional) for special output handling.
  6564. * @return {String} A formatted string for the results.
  6565. * @method format
  6566. */
  6567. api.format = function(results, filename, formatId, options) {
  6568. var formatter = this.getFormatter(formatId),
  6569. result = null;
  6570. if (formatter) {
  6571. result = formatter.startFormat();
  6572. result += formatter.formatResults(results, filename, options || {});
  6573. result += formatter.endFormat();
  6574. }
  6575. return result;
  6576. };
  6577. /**
  6578. * Indicates if the given format is supported.
  6579. * @param {String} formatId The ID of the format to check.
  6580. * @return {Boolean} True if the format exists, false if not.
  6581. * @method hasFormat
  6582. */
  6583. api.hasFormat = function(formatId) {
  6584. return formatters.hasOwnProperty(formatId);
  6585. };
  6586. //-------------------------------------------------------------------------
  6587. // Verification
  6588. //-------------------------------------------------------------------------
  6589. /**
  6590. * Starts the verification process for the given CSS text.
  6591. * @param {String} text The CSS text to verify.
  6592. * @param {Object} ruleset (Optional) List of rules to apply. If null, then
  6593. * all rules are used. If a rule has a value of 1 then it's a warning,
  6594. * a value of 2 means it's an error.
  6595. * @return {Object} Results of the verification.
  6596. * @method verify
  6597. */
  6598. api.verify = function(text, ruleset) {
  6599. var i = 0,
  6600. reporter,
  6601. lines,
  6602. allow = {},
  6603. ignore = [],
  6604. report,
  6605. parser = new parserlib.css.Parser({
  6606. starHack: true,
  6607. ieFilters: true,
  6608. underscoreHack: true,
  6609. strict: false
  6610. });
  6611. // normalize line endings
  6612. lines = text.replace(/\n\r?/g, "$split$").split("$split$");
  6613. // find 'allow' comments
  6614. CSSLint.Util.forEach(lines, function (line, lineno) {
  6615. var allowLine = line && line.match(/\/\*[ \t]*csslint[ \t]+allow:[ \t]*([^\*]*)\*\//i),
  6616. allowRules = allowLine && allowLine[1],
  6617. allowRuleset = {};
  6618. if (allowRules) {
  6619. allowRules.toLowerCase().split(",").forEach(function(allowRule) {
  6620. allowRuleset[allowRule.trim()] = true;
  6621. });
  6622. if (Object.keys(allowRuleset).length > 0) {
  6623. allow[lineno + 1] = allowRuleset;
  6624. }
  6625. }
  6626. });
  6627. var ignoreStart = null,
  6628. ignoreEnd = null;
  6629. CSSLint.Util.forEach(lines, function (line, lineno) {
  6630. // Keep oldest, "unclosest" ignore:start
  6631. if (ignoreStart === null && line.match(/\/\*[ \t]*csslint[ \t]+ignore:start[ \t]*\*\//i)) {
  6632. ignoreStart = lineno;
  6633. }
  6634. if (line.match(/\/\*[ \t]*csslint[ \t]+ignore:end[ \t]*\*\//i)) {
  6635. ignoreEnd = lineno;
  6636. }
  6637. if (ignoreStart !== null && ignoreEnd !== null) {
  6638. ignore.push([ignoreStart, ignoreEnd]);
  6639. ignoreStart = ignoreEnd = null;
  6640. }
  6641. });
  6642. // Close remaining ignore block, if any
  6643. if (ignoreStart !== null) {
  6644. ignore.push([ignoreStart, lines.length]);
  6645. }
  6646. if (!ruleset) {
  6647. ruleset = this.getRuleset();
  6648. }
  6649. if (embeddedRuleset.test(text)) {
  6650. // defensively copy so that caller's version does not get modified
  6651. ruleset = clone(ruleset);
  6652. ruleset = applyEmbeddedRuleset(text, ruleset);
  6653. }
  6654. reporter = new Reporter(lines, ruleset, allow, ignore);
  6655. ruleset.errors = 2; // always report parsing errors as errors
  6656. for (i in ruleset) {
  6657. if (ruleset.hasOwnProperty(i) && ruleset[i]) {
  6658. if (rules[i]) {
  6659. rules[i].init(parser, reporter);
  6660. }
  6661. }
  6662. }
  6663. // capture most horrible error type
  6664. try {
  6665. parser.parse(text);
  6666. } catch (ex) {
  6667. reporter.error("Fatal error, cannot continue: " + ex.message, ex.line, ex.col, {});
  6668. }
  6669. report = {
  6670. messages : reporter.messages,
  6671. stats : reporter.stats,
  6672. ruleset : reporter.ruleset,
  6673. allow : reporter.allow,
  6674. ignore : reporter.ignore
  6675. };
  6676. // sort by line numbers, rollups at the bottom
  6677. report.messages.sort(function (a, b) {
  6678. if (a.rollup && !b.rollup) {
  6679. return 1;
  6680. } else if (!a.rollup && b.rollup) {
  6681. return -1;
  6682. } else {
  6683. return a.line - b.line;
  6684. }
  6685. });
  6686. return report;
  6687. };
  6688. //-------------------------------------------------------------------------
  6689. // Publish the API
  6690. //-------------------------------------------------------------------------
  6691. return api;
  6692. })();
  6693. /**
  6694. * An instance of Report is used to report results of the
  6695. * verification back to the main API.
  6696. * @class Reporter
  6697. * @constructor
  6698. * @param {String[]} lines The text lines of the source.
  6699. * @param {Object} ruleset The set of rules to work with, including if
  6700. * they are errors or warnings.
  6701. * @param {Object} explicitly allowed lines
  6702. * @param {[][]} ingore list of line ranges to be ignored
  6703. */
  6704. function Reporter(lines, ruleset, allow, ignore) {
  6705. "use strict";
  6706. /**
  6707. * List of messages being reported.
  6708. * @property messages
  6709. * @type String[]
  6710. */
  6711. this.messages = [];
  6712. /**
  6713. * List of statistics being reported.
  6714. * @property stats
  6715. * @type String[]
  6716. */
  6717. this.stats = [];
  6718. /**
  6719. * Lines of code being reported on. Used to provide contextual information
  6720. * for messages.
  6721. * @property lines
  6722. * @type String[]
  6723. */
  6724. this.lines = lines;
  6725. /**
  6726. * Information about the rules. Used to determine whether an issue is an
  6727. * error or warning.
  6728. * @property ruleset
  6729. * @type Object
  6730. */
  6731. this.ruleset = ruleset;
  6732. /**
  6733. * Lines with specific rule messages to leave out of the report.
  6734. * @property allow
  6735. * @type Object
  6736. */
  6737. this.allow = allow;
  6738. if (!this.allow) {
  6739. this.allow = {};
  6740. }
  6741. /**
  6742. * Linesets not to include in the report.
  6743. * @property ignore
  6744. * @type [][]
  6745. */
  6746. this.ignore = ignore;
  6747. if (!this.ignore) {
  6748. this.ignore = [];
  6749. }
  6750. }
  6751. Reporter.prototype = {
  6752. // restore constructor
  6753. constructor: Reporter,
  6754. /**
  6755. * Report an error.
  6756. * @param {String} message The message to store.
  6757. * @param {int} line The line number.
  6758. * @param {int} col The column number.
  6759. * @param {Object} rule The rule this message relates to.
  6760. * @method error
  6761. */
  6762. error: function(message, line, col, rule) {
  6763. "use strict";
  6764. this.messages.push({
  6765. type : "error",
  6766. line : line,
  6767. col : col,
  6768. message : message,
  6769. evidence: this.lines[line-1],
  6770. rule : rule || {}
  6771. });
  6772. },
  6773. /**
  6774. * Report an warning.
  6775. * @param {String} message The message to store.
  6776. * @param {int} line The line number.
  6777. * @param {int} col The column number.
  6778. * @param {Object} rule The rule this message relates to.
  6779. * @method warn
  6780. * @deprecated Use report instead.
  6781. */
  6782. warn: function(message, line, col, rule) {
  6783. "use strict";
  6784. this.report(message, line, col, rule);
  6785. },
  6786. /**
  6787. * Report an issue.
  6788. * @param {String} message The message to store.
  6789. * @param {int} line The line number.
  6790. * @param {int} col The column number.
  6791. * @param {Object} rule The rule this message relates to.
  6792. * @method report
  6793. */
  6794. report: function(message, line, col, rule) {
  6795. "use strict";
  6796. // Check if rule violation should be allowed
  6797. if (this.allow.hasOwnProperty(line) && this.allow[line].hasOwnProperty(rule.id)) {
  6798. return;
  6799. }
  6800. var ignore = false;
  6801. CSSLint.Util.forEach(this.ignore, function (range) {
  6802. if (range[0] <= line && line <= range[1]) {
  6803. ignore = true;
  6804. }
  6805. });
  6806. if (ignore) {
  6807. return;
  6808. }
  6809. this.messages.push({
  6810. type : this.ruleset[rule.id] === 2 ? "error" : "warning",
  6811. line : line,
  6812. col : col,
  6813. message : message,
  6814. evidence: this.lines[line-1],
  6815. rule : rule
  6816. });
  6817. },
  6818. /**
  6819. * Report some informational text.
  6820. * @param {String} message The message to store.
  6821. * @param {int} line The line number.
  6822. * @param {int} col The column number.
  6823. * @param {Object} rule The rule this message relates to.
  6824. * @method info
  6825. */
  6826. info: function(message, line, col, rule) {
  6827. "use strict";
  6828. this.messages.push({
  6829. type : "info",
  6830. line : line,
  6831. col : col,
  6832. message : message,
  6833. evidence: this.lines[line-1],
  6834. rule : rule
  6835. });
  6836. },
  6837. /**
  6838. * Report some rollup error information.
  6839. * @param {String} message The message to store.
  6840. * @param {Object} rule The rule this message relates to.
  6841. * @method rollupError
  6842. */
  6843. rollupError: function(message, rule) {
  6844. "use strict";
  6845. this.messages.push({
  6846. type : "error",
  6847. rollup : true,
  6848. message : message,
  6849. rule : rule
  6850. });
  6851. },
  6852. /**
  6853. * Report some rollup warning information.
  6854. * @param {String} message The message to store.
  6855. * @param {Object} rule The rule this message relates to.
  6856. * @method rollupWarn
  6857. */
  6858. rollupWarn: function(message, rule) {
  6859. "use strict";
  6860. this.messages.push({
  6861. type : "warning",
  6862. rollup : true,
  6863. message : message,
  6864. rule : rule
  6865. });
  6866. },
  6867. /**
  6868. * Report a statistic.
  6869. * @param {String} name The name of the stat to store.
  6870. * @param {Variant} value The value of the stat.
  6871. * @method stat
  6872. */
  6873. stat: function(name, value) {
  6874. "use strict";
  6875. this.stats[name] = value;
  6876. }
  6877. };
  6878. // expose for testing purposes
  6879. CSSLint._Reporter = Reporter;
  6880. /*
  6881. * Utility functions that make life easier.
  6882. */
  6883. CSSLint.Util = {
  6884. /*
  6885. * Adds all properties from supplier onto receiver,
  6886. * overwriting if the same name already exists on
  6887. * receiver.
  6888. * @param {Object} The object to receive the properties.
  6889. * @param {Object} The object to provide the properties.
  6890. * @return {Object} The receiver
  6891. */
  6892. mix: function(receiver, supplier) {
  6893. "use strict";
  6894. var prop;
  6895. for (prop in supplier) {
  6896. if (supplier.hasOwnProperty(prop)) {
  6897. receiver[prop] = supplier[prop];
  6898. }
  6899. }
  6900. return prop;
  6901. },
  6902. /*
  6903. * Polyfill for array indexOf() method.
  6904. * @param {Array} values The array to search.
  6905. * @param {Variant} value The value to search for.
  6906. * @return {int} The index of the value if found, -1 if not.
  6907. */
  6908. indexOf: function(values, value) {
  6909. "use strict";
  6910. if (values.indexOf) {
  6911. return values.indexOf(value);
  6912. } else {
  6913. for (var i=0, len=values.length; i < len; i++) {
  6914. if (values[i] === value) {
  6915. return i;
  6916. }
  6917. }
  6918. return -1;
  6919. }
  6920. },
  6921. /*
  6922. * Polyfill for array forEach() method.
  6923. * @param {Array} values The array to operate on.
  6924. * @param {Function} func The function to call on each item.
  6925. * @return {void}
  6926. */
  6927. forEach: function(values, func) {
  6928. "use strict";
  6929. if (values.forEach) {
  6930. return values.forEach(func);
  6931. } else {
  6932. for (var i=0, len=values.length; i < len; i++) {
  6933. func(values[i], i, values);
  6934. }
  6935. }
  6936. }
  6937. };
  6938. /*
  6939. * Rule: Don't use adjoining classes (.foo.bar).
  6940. */
  6941. CSSLint.addRule({
  6942. // rule information
  6943. id: "adjoining-classes",
  6944. name: "Disallow adjoining classes",
  6945. desc: "Don't use adjoining classes.",
  6946. url: "https://github.com/CSSLint/csslint/wiki/Disallow-adjoining-classes",
  6947. browsers: "IE6",
  6948. // initialization
  6949. init: function(parser, reporter) {
  6950. "use strict";
  6951. var rule = this;
  6952. parser.addListener("startrule", function(event) {
  6953. var selectors = event.selectors,
  6954. selector,
  6955. part,
  6956. modifier,
  6957. classCount,
  6958. i, j, k;
  6959. for (i=0; i < selectors.length; i++) {
  6960. selector = selectors[i];
  6961. for (j=0; j < selector.parts.length; j++) {
  6962. part = selector.parts[j];
  6963. if (part.type === parser.SELECTOR_PART_TYPE) {
  6964. classCount = 0;
  6965. for (k=0; k < part.modifiers.length; k++) {
  6966. modifier = part.modifiers[k];
  6967. if (modifier.type === "class") {
  6968. classCount++;
  6969. }
  6970. if (classCount > 1){
  6971. reporter.report("Adjoining classes: "+selectors[i].text, part.line, part.col, rule);
  6972. }
  6973. }
  6974. }
  6975. }
  6976. }
  6977. });
  6978. }
  6979. });
  6980. /*
  6981. * Rule: Don't use width or height when using padding or border.
  6982. */
  6983. CSSLint.addRule({
  6984. // rule information
  6985. id: "box-model",
  6986. name: "Beware of broken box size",
  6987. desc: "Don't use width or height when using padding or border.",
  6988. url: "https://github.com/CSSLint/csslint/wiki/Beware-of-box-model-size",
  6989. browsers: "All",
  6990. // initialization
  6991. init: function(parser, reporter) {
  6992. "use strict";
  6993. var rule = this,
  6994. widthProperties = {
  6995. border: 1,
  6996. "border-left": 1,
  6997. "border-right": 1,
  6998. padding: 1,
  6999. "padding-left": 1,
  7000. "padding-right": 1
  7001. },
  7002. heightProperties = {
  7003. border: 1,
  7004. "border-bottom": 1,
  7005. "border-top": 1,
  7006. padding: 1,
  7007. "padding-bottom": 1,
  7008. "padding-top": 1
  7009. },
  7010. properties,
  7011. boxSizing = false;
  7012. function startRule() {
  7013. properties = {};
  7014. boxSizing = false;
  7015. }
  7016. function endRule() {
  7017. var prop, value;
  7018. if (!boxSizing) {
  7019. if (properties.height) {
  7020. for (prop in heightProperties) {
  7021. if (heightProperties.hasOwnProperty(prop) && properties[prop]) {
  7022. value = properties[prop].value;
  7023. // special case for padding
  7024. if (!(prop === "padding" && value.parts.length === 2 && value.parts[0].value === 0)) {
  7025. reporter.report("Using height with " + prop + " can sometimes make elements larger than you expect.", properties[prop].line, properties[prop].col, rule);
  7026. }
  7027. }
  7028. }
  7029. }
  7030. if (properties.width) {
  7031. for (prop in widthProperties) {
  7032. if (widthProperties.hasOwnProperty(prop) && properties[prop]) {
  7033. value = properties[prop].value;
  7034. if (!(prop === "padding" && value.parts.length === 2 && value.parts[1].value === 0)) {
  7035. reporter.report("Using width with " + prop + " can sometimes make elements larger than you expect.", properties[prop].line, properties[prop].col, rule);
  7036. }
  7037. }
  7038. }
  7039. }
  7040. }
  7041. }
  7042. parser.addListener("startrule", startRule);
  7043. parser.addListener("startfontface", startRule);
  7044. parser.addListener("startpage", startRule);
  7045. parser.addListener("startpagemargin", startRule);
  7046. parser.addListener("startkeyframerule", startRule);
  7047. parser.addListener("startviewport", startRule);
  7048. parser.addListener("property", function(event) {
  7049. var name = event.property.text.toLowerCase();
  7050. if (heightProperties[name] || widthProperties[name]) {
  7051. if (!/^0\S*$/.test(event.value) && !(name === "border" && event.value.toString() === "none")) {
  7052. properties[name] = {
  7053. line: event.property.line,
  7054. col: event.property.col,
  7055. value: event.value
  7056. };
  7057. }
  7058. } else {
  7059. if (/^(width|height)/i.test(name) && /^(length|percentage)/.test(event.value.parts[0].type)) {
  7060. properties[name] = 1;
  7061. } else if (name === "box-sizing") {
  7062. boxSizing = true;
  7063. }
  7064. }
  7065. });
  7066. parser.addListener("endrule", endRule);
  7067. parser.addListener("endfontface", endRule);
  7068. parser.addListener("endpage", endRule);
  7069. parser.addListener("endpagemargin", endRule);
  7070. parser.addListener("endkeyframerule", endRule);
  7071. parser.addListener("endviewport", endRule);
  7072. }
  7073. });
  7074. /*
  7075. * Rule: box-sizing doesn't work in IE6 and IE7.
  7076. */
  7077. CSSLint.addRule({
  7078. // rule information
  7079. id: "box-sizing",
  7080. name: "Disallow use of box-sizing",
  7081. desc: "The box-sizing properties isn't supported in IE6 and IE7.",
  7082. url: "https://github.com/CSSLint/csslint/wiki/Disallow-box-sizing",
  7083. browsers: "IE6, IE7",
  7084. tags: ["Compatibility"],
  7085. // initialization
  7086. init: function(parser, reporter) {
  7087. "use strict";
  7088. var rule = this;
  7089. parser.addListener("property", function(event) {
  7090. var name = event.property.text.toLowerCase();
  7091. if (name === "box-sizing") {
  7092. reporter.report("The box-sizing property isn't supported in IE6 and IE7.", event.line, event.col, rule);
  7093. }
  7094. });
  7095. }
  7096. });
  7097. /*
  7098. * Rule: Use the bulletproof @font-face syntax to avoid 404's in old IE
  7099. * (http://www.fontspring.com/blog/the-new-bulletproof-font-face-syntax)
  7100. */
  7101. CSSLint.addRule({
  7102. // rule information
  7103. id: "bulletproof-font-face",
  7104. name: "Use the bulletproof @font-face syntax",
  7105. desc: "Use the bulletproof @font-face syntax to avoid 404's in old IE (http://www.fontspring.com/blog/the-new-bulletproof-font-face-syntax).",
  7106. url: "https://github.com/CSSLint/csslint/wiki/Bulletproof-font-face",
  7107. browsers: "All",
  7108. // initialization
  7109. init: function(parser, reporter) {
  7110. "use strict";
  7111. var rule = this,
  7112. fontFaceRule = false,
  7113. firstSrc = true,
  7114. ruleFailed = false,
  7115. line, col;
  7116. // Mark the start of a @font-face declaration so we only test properties inside it
  7117. parser.addListener("startfontface", function() {
  7118. fontFaceRule = true;
  7119. });
  7120. parser.addListener("property", function(event) {
  7121. // If we aren't inside an @font-face declaration then just return
  7122. if (!fontFaceRule) {
  7123. return;
  7124. }
  7125. var propertyName = event.property.toString().toLowerCase(),
  7126. value = event.value.toString();
  7127. // Set the line and col numbers for use in the endfontface listener
  7128. line = event.line;
  7129. col = event.col;
  7130. // This is the property that we care about, we can ignore the rest
  7131. if (propertyName === "src") {
  7132. var regex = /^\s?url\(['"].+\.eot\?.*['"]\)\s*format\(['"]embedded-opentype['"]\).*$/i;
  7133. // We need to handle the advanced syntax with two src properties
  7134. if (!value.match(regex) && firstSrc) {
  7135. ruleFailed = true;
  7136. firstSrc = false;
  7137. } else if (value.match(regex) && !firstSrc) {
  7138. ruleFailed = false;
  7139. }
  7140. }
  7141. });
  7142. // Back to normal rules that we don't need to test
  7143. parser.addListener("endfontface", function() {
  7144. fontFaceRule = false;
  7145. if (ruleFailed) {
  7146. reporter.report("@font-face declaration doesn't follow the fontspring bulletproof syntax.", line, col, rule);
  7147. }
  7148. });
  7149. }
  7150. });
  7151. /*
  7152. * Rule: Include all compatible vendor prefixes to reach a wider
  7153. * range of users.
  7154. */
  7155. CSSLint.addRule({
  7156. // rule information
  7157. id: "compatible-vendor-prefixes",
  7158. name: "Require compatible vendor prefixes",
  7159. desc: "Include all compatible vendor prefixes to reach a wider range of users.",
  7160. url: "https://github.com/CSSLint/csslint/wiki/Require-compatible-vendor-prefixes",
  7161. browsers: "All",
  7162. // initialization
  7163. init: function (parser, reporter) {
  7164. "use strict";
  7165. var rule = this,
  7166. compatiblePrefixes,
  7167. properties,
  7168. prop,
  7169. variations,
  7170. prefixed,
  7171. i,
  7172. len,
  7173. inKeyFrame = false,
  7174. arrayPush = Array.prototype.push,
  7175. applyTo = [];
  7176. // See http://peter.sh/experiments/vendor-prefixed-css-property-overview/ for details
  7177. compatiblePrefixes = {
  7178. "animation" : "webkit",
  7179. "animation-delay" : "webkit",
  7180. "animation-direction" : "webkit",
  7181. "animation-duration" : "webkit",
  7182. "animation-fill-mode" : "webkit",
  7183. "animation-iteration-count" : "webkit",
  7184. "animation-name" : "webkit",
  7185. "animation-play-state" : "webkit",
  7186. "animation-timing-function" : "webkit",
  7187. "appearance" : "webkit moz",
  7188. "border-end" : "webkit moz",
  7189. "border-end-color" : "webkit moz",
  7190. "border-end-style" : "webkit moz",
  7191. "border-end-width" : "webkit moz",
  7192. "border-image" : "webkit moz o",
  7193. "border-radius" : "webkit",
  7194. "border-start" : "webkit moz",
  7195. "border-start-color" : "webkit moz",
  7196. "border-start-style" : "webkit moz",
  7197. "border-start-width" : "webkit moz",
  7198. "box-align" : "webkit moz ms",
  7199. "box-direction" : "webkit moz ms",
  7200. "box-flex" : "webkit moz ms",
  7201. "box-lines" : "webkit ms",
  7202. "box-ordinal-group" : "webkit moz ms",
  7203. "box-orient" : "webkit moz ms",
  7204. "box-pack" : "webkit moz ms",
  7205. "box-sizing" : "",
  7206. "box-shadow" : "",
  7207. "column-count" : "webkit moz ms",
  7208. "column-gap" : "webkit moz ms",
  7209. "column-rule" : "webkit moz ms",
  7210. "column-rule-color" : "webkit moz ms",
  7211. "column-rule-style" : "webkit moz ms",
  7212. "column-rule-width" : "webkit moz ms",
  7213. "column-width" : "webkit moz ms",
  7214. "hyphens" : "epub moz",
  7215. "line-break" : "webkit ms",
  7216. "margin-end" : "webkit moz",
  7217. "margin-start" : "webkit moz",
  7218. "marquee-speed" : "webkit wap",
  7219. "marquee-style" : "webkit wap",
  7220. "padding-end" : "webkit moz",
  7221. "padding-start" : "webkit moz",
  7222. "tab-size" : "moz o",
  7223. "text-size-adjust" : "webkit ms",
  7224. "transform" : "webkit ms",
  7225. "transform-origin" : "webkit ms",
  7226. "transition" : "",
  7227. "transition-delay" : "",
  7228. "transition-duration" : "",
  7229. "transition-property" : "",
  7230. "transition-timing-function" : "",
  7231. "user-modify" : "webkit moz",
  7232. "user-select" : "webkit moz ms",
  7233. "word-break" : "epub ms",
  7234. "writing-mode" : "epub ms"
  7235. };
  7236. for (prop in compatiblePrefixes) {
  7237. if (compatiblePrefixes.hasOwnProperty(prop)) {
  7238. variations = [];
  7239. prefixed = compatiblePrefixes[prop].split(" ");
  7240. for (i = 0, len = prefixed.length; i < len; i++) {
  7241. variations.push("-" + prefixed[i] + "-" + prop);
  7242. }
  7243. compatiblePrefixes[prop] = variations;
  7244. arrayPush.apply(applyTo, variations);
  7245. }
  7246. }
  7247. parser.addListener("startrule", function () {
  7248. properties = [];
  7249. });
  7250. parser.addListener("startkeyframes", function (event) {
  7251. inKeyFrame = event.prefix || true;
  7252. });
  7253. parser.addListener("endkeyframes", function () {
  7254. inKeyFrame = false;
  7255. });
  7256. parser.addListener("property", function (event) {
  7257. var name = event.property;
  7258. if (CSSLint.Util.indexOf(applyTo, name.text) > -1) {
  7259. // e.g., -moz-transform is okay to be alone in @-moz-keyframes
  7260. if (!inKeyFrame || typeof inKeyFrame !== "string" ||
  7261. name.text.indexOf("-" + inKeyFrame + "-") !== 0) {
  7262. properties.push(name);
  7263. }
  7264. }
  7265. });
  7266. parser.addListener("endrule", function () {
  7267. if (!properties.length) {
  7268. return;
  7269. }
  7270. var propertyGroups = {},
  7271. i,
  7272. len,
  7273. name,
  7274. prop,
  7275. variations,
  7276. value,
  7277. full,
  7278. actual,
  7279. item,
  7280. propertiesSpecified;
  7281. for (i = 0, len = properties.length; i < len; i++) {
  7282. name = properties[i];
  7283. for (prop in compatiblePrefixes) {
  7284. if (compatiblePrefixes.hasOwnProperty(prop)) {
  7285. variations = compatiblePrefixes[prop];
  7286. if (CSSLint.Util.indexOf(variations, name.text) > -1) {
  7287. if (!propertyGroups[prop]) {
  7288. propertyGroups[prop] = {
  7289. full: variations.slice(0),
  7290. actual: [],
  7291. actualNodes: []
  7292. };
  7293. }
  7294. if (CSSLint.Util.indexOf(propertyGroups[prop].actual, name.text) === -1) {
  7295. propertyGroups[prop].actual.push(name.text);
  7296. propertyGroups[prop].actualNodes.push(name);
  7297. }
  7298. }
  7299. }
  7300. }
  7301. }
  7302. for (prop in propertyGroups) {
  7303. if (propertyGroups.hasOwnProperty(prop)) {
  7304. value = propertyGroups[prop];
  7305. full = value.full;
  7306. actual = value.actual;
  7307. if (full.length > actual.length) {
  7308. for (i = 0, len = full.length; i < len; i++) {
  7309. item = full[i];
  7310. if (CSSLint.Util.indexOf(actual, item) === -1) {
  7311. propertiesSpecified = (actual.length === 1) ? actual[0] : (actual.length === 2) ? actual.join(" and ") : actual.join(", ");
  7312. reporter.report("The property " + item + " is compatible with " + propertiesSpecified + " and should be included as well.", value.actualNodes[0].line, value.actualNodes[0].col, rule);
  7313. }
  7314. }
  7315. }
  7316. }
  7317. }
  7318. });
  7319. }
  7320. });
  7321. /*
  7322. * Rule: Certain properties don't play well with certain display values.
  7323. * - float should not be used with inline-block
  7324. * - height, width, margin-top, margin-bottom, float should not be used with inline
  7325. * - vertical-align should not be used with block
  7326. * - margin, float should not be used with table-*
  7327. */
  7328. CSSLint.addRule({
  7329. // rule information
  7330. id: "display-property-grouping",
  7331. name: "Require properties appropriate for display",
  7332. desc: "Certain properties shouldn't be used with certain display property values.",
  7333. url: "https://github.com/CSSLint/csslint/wiki/Require-properties-appropriate-for-display",
  7334. browsers: "All",
  7335. // initialization
  7336. init: function(parser, reporter) {
  7337. "use strict";
  7338. var rule = this;
  7339. var propertiesToCheck = {
  7340. display: 1,
  7341. "float": "none",
  7342. height: 1,
  7343. width: 1,
  7344. margin: 1,
  7345. "margin-left": 1,
  7346. "margin-right": 1,
  7347. "margin-bottom": 1,
  7348. "margin-top": 1,
  7349. padding: 1,
  7350. "padding-left": 1,
  7351. "padding-right": 1,
  7352. "padding-bottom": 1,
  7353. "padding-top": 1,
  7354. "vertical-align": 1
  7355. },
  7356. properties;
  7357. function reportProperty(name, display, msg) {
  7358. if (properties[name]) {
  7359. if (typeof propertiesToCheck[name] !== "string" || properties[name].value.toLowerCase() !== propertiesToCheck[name]) {
  7360. reporter.report(msg || name + " can't be used with display: " + display + ".", properties[name].line, properties[name].col, rule);
  7361. }
  7362. }
  7363. }
  7364. function startRule() {
  7365. properties = {};
  7366. }
  7367. function endRule() {
  7368. var display = properties.display ? properties.display.value : null;
  7369. if (display) {
  7370. switch (display) {
  7371. case "inline":
  7372. // height, width, margin-top, margin-bottom, float should not be used with inline
  7373. reportProperty("height", display);
  7374. reportProperty("width", display);
  7375. reportProperty("margin", display);
  7376. reportProperty("margin-top", display);
  7377. reportProperty("margin-bottom", display);
  7378. reportProperty("float", display, "display:inline has no effect on floated elements (but may be used to fix the IE6 double-margin bug).");
  7379. break;
  7380. case "block":
  7381. // vertical-align should not be used with block
  7382. reportProperty("vertical-align", display);
  7383. break;
  7384. case "inline-block":
  7385. // float should not be used with inline-block
  7386. reportProperty("float", display);
  7387. break;
  7388. default:
  7389. // margin, float should not be used with table
  7390. if (display.indexOf("table-") === 0) {
  7391. reportProperty("margin", display);
  7392. reportProperty("margin-left", display);
  7393. reportProperty("margin-right", display);
  7394. reportProperty("margin-top", display);
  7395. reportProperty("margin-bottom", display);
  7396. reportProperty("float", display);
  7397. }
  7398. // otherwise do nothing
  7399. }
  7400. }
  7401. }
  7402. parser.addListener("startrule", startRule);
  7403. parser.addListener("startfontface", startRule);
  7404. parser.addListener("startkeyframerule", startRule);
  7405. parser.addListener("startpagemargin", startRule);
  7406. parser.addListener("startpage", startRule);
  7407. parser.addListener("startviewport", startRule);
  7408. parser.addListener("property", function(event) {
  7409. var name = event.property.text.toLowerCase();
  7410. if (propertiesToCheck[name]) {
  7411. properties[name] = {
  7412. value: event.value.text,
  7413. line: event.property.line,
  7414. col: event.property.col
  7415. };
  7416. }
  7417. });
  7418. parser.addListener("endrule", endRule);
  7419. parser.addListener("endfontface", endRule);
  7420. parser.addListener("endkeyframerule", endRule);
  7421. parser.addListener("endpagemargin", endRule);
  7422. parser.addListener("endpage", endRule);
  7423. parser.addListener("endviewport", endRule);
  7424. }
  7425. });
  7426. /*
  7427. * Rule: Disallow duplicate background-images (using url).
  7428. */
  7429. CSSLint.addRule({
  7430. // rule information
  7431. id: "duplicate-background-images",
  7432. name: "Disallow duplicate background images",
  7433. desc: "Every background-image should be unique. Use a common class for e.g. sprites.",
  7434. url: "https://github.com/CSSLint/csslint/wiki/Disallow-duplicate-background-images",
  7435. browsers: "All",
  7436. // initialization
  7437. init: function(parser, reporter) {
  7438. "use strict";
  7439. var rule = this,
  7440. stack = {};
  7441. parser.addListener("property", function(event) {
  7442. var name = event.property.text,
  7443. value = event.value,
  7444. i, len;
  7445. if (name.match(/background/i)) {
  7446. for (i=0, len=value.parts.length; i < len; i++) {
  7447. if (value.parts[i].type === "uri") {
  7448. if (typeof stack[value.parts[i].uri] === "undefined") {
  7449. stack[value.parts[i].uri] = event;
  7450. } else {
  7451. reporter.report("Background image '" + value.parts[i].uri + "' was used multiple times, first declared at line " + stack[value.parts[i].uri].line + ", col " + stack[value.parts[i].uri].col + ".", event.line, event.col, rule);
  7452. }
  7453. }
  7454. }
  7455. }
  7456. });
  7457. }
  7458. });
  7459. /*
  7460. * Rule: Duplicate properties must appear one after the other. If an already-defined
  7461. * property appears somewhere else in the rule, then it's likely an error.
  7462. */
  7463. CSSLint.addRule({
  7464. // rule information
  7465. id: "duplicate-properties",
  7466. name: "Disallow duplicate properties",
  7467. desc: "Duplicate properties must appear one after the other.",
  7468. url: "https://github.com/CSSLint/csslint/wiki/Disallow-duplicate-properties",
  7469. browsers: "All",
  7470. // initialization
  7471. init: function(parser, reporter) {
  7472. "use strict";
  7473. var rule = this,
  7474. properties,
  7475. lastProperty;
  7476. function startRule() {
  7477. properties = {};
  7478. }
  7479. parser.addListener("startrule", startRule);
  7480. parser.addListener("startfontface", startRule);
  7481. parser.addListener("startpage", startRule);
  7482. parser.addListener("startpagemargin", startRule);
  7483. parser.addListener("startkeyframerule", startRule);
  7484. parser.addListener("startviewport", startRule);
  7485. parser.addListener("property", function(event) {
  7486. var property = event.property,
  7487. name = property.text.toLowerCase();
  7488. if (properties[name] && (lastProperty !== name || properties[name] === event.value.text)) {
  7489. reporter.report("Duplicate property '" + event.property + "' found.", event.line, event.col, rule);
  7490. }
  7491. properties[name] = event.value.text;
  7492. lastProperty = name;
  7493. });
  7494. }
  7495. });
  7496. /*
  7497. * Rule: Style rules without any properties defined should be removed.
  7498. */
  7499. CSSLint.addRule({
  7500. // rule information
  7501. id: "empty-rules",
  7502. name: "Disallow empty rules",
  7503. desc: "Rules without any properties specified should be removed.",
  7504. url: "https://github.com/CSSLint/csslint/wiki/Disallow-empty-rules",
  7505. browsers: "All",
  7506. // initialization
  7507. init: function(parser, reporter) {
  7508. "use strict";
  7509. var rule = this,
  7510. count = 0;
  7511. parser.addListener("startrule", function() {
  7512. count=0;
  7513. });
  7514. parser.addListener("property", function() {
  7515. count++;
  7516. });
  7517. parser.addListener("endrule", function(event) {
  7518. var selectors = event.selectors;
  7519. if (count === 0) {
  7520. reporter.report("Rule is empty.", selectors[0].line, selectors[0].col, rule);
  7521. }
  7522. });
  7523. }
  7524. });
  7525. /*
  7526. * Rule: There should be no syntax errors. (Duh.)
  7527. */
  7528. CSSLint.addRule({
  7529. // rule information
  7530. id: "errors",
  7531. name: "Parsing Errors",
  7532. desc: "This rule looks for recoverable syntax errors.",
  7533. browsers: "All",
  7534. // initialization
  7535. init: function(parser, reporter) {
  7536. "use strict";
  7537. var rule = this;
  7538. parser.addListener("error", function(event) {
  7539. reporter.error(event.message, event.line, event.col, rule);
  7540. });
  7541. }
  7542. });
  7543. CSSLint.addRule({
  7544. // rule information
  7545. id: "fallback-colors",
  7546. name: "Require fallback colors",
  7547. desc: "For older browsers that don't support RGBA, HSL, or HSLA, provide a fallback color.",
  7548. url: "https://github.com/CSSLint/csslint/wiki/Require-fallback-colors",
  7549. browsers: "IE6,IE7,IE8",
  7550. // initialization
  7551. init: function(parser, reporter) {
  7552. "use strict";
  7553. var rule = this,
  7554. lastProperty,
  7555. propertiesToCheck = {
  7556. color: 1,
  7557. background: 1,
  7558. "border-color": 1,
  7559. "border-top-color": 1,
  7560. "border-right-color": 1,
  7561. "border-bottom-color": 1,
  7562. "border-left-color": 1,
  7563. border: 1,
  7564. "border-top": 1,
  7565. "border-right": 1,
  7566. "border-bottom": 1,
  7567. "border-left": 1,
  7568. "background-color": 1
  7569. };
  7570. function startRule() {
  7571. lastProperty = null;
  7572. }
  7573. parser.addListener("startrule", startRule);
  7574. parser.addListener("startfontface", startRule);
  7575. parser.addListener("startpage", startRule);
  7576. parser.addListener("startpagemargin", startRule);
  7577. parser.addListener("startkeyframerule", startRule);
  7578. parser.addListener("startviewport", startRule);
  7579. parser.addListener("property", function(event) {
  7580. var property = event.property,
  7581. name = property.text.toLowerCase(),
  7582. parts = event.value.parts,
  7583. i = 0,
  7584. colorType = "",
  7585. len = parts.length;
  7586. if (propertiesToCheck[name]) {
  7587. while (i < len) {
  7588. if (parts[i].type === "color") {
  7589. if ("alpha" in parts[i] || "hue" in parts[i]) {
  7590. if (/([^\)]+)\(/.test(parts[i])) {
  7591. colorType = RegExp.$1.toUpperCase();
  7592. }
  7593. if (!lastProperty || (lastProperty.property.text.toLowerCase() !== name || lastProperty.colorType !== "compat")) {
  7594. reporter.report("Fallback " + name + " (hex or RGB) should precede " + colorType + " " + name + ".", event.line, event.col, rule);
  7595. }
  7596. } else {
  7597. event.colorType = "compat";
  7598. }
  7599. }
  7600. i++;
  7601. }
  7602. }
  7603. lastProperty = event;
  7604. });
  7605. }
  7606. });
  7607. /*
  7608. * Rule: You shouldn't use more than 10 floats. If you do, there's probably
  7609. * room for some abstraction.
  7610. */
  7611. CSSLint.addRule({
  7612. // rule information
  7613. id: "floats",
  7614. name: "Disallow too many floats",
  7615. desc: "This rule tests if the float property is used too many times",
  7616. url: "https://github.com/CSSLint/csslint/wiki/Disallow-too-many-floats",
  7617. browsers: "All",
  7618. // initialization
  7619. init: function(parser, reporter) {
  7620. "use strict";
  7621. var rule = this;
  7622. var count = 0;
  7623. // count how many times "float" is used
  7624. parser.addListener("property", function(event) {
  7625. if (event.property.text.toLowerCase() === "float" &&
  7626. event.value.text.toLowerCase() !== "none") {
  7627. count++;
  7628. }
  7629. });
  7630. // report the results
  7631. parser.addListener("endstylesheet", function() {
  7632. reporter.stat("floats", count);
  7633. if (count >= 10) {
  7634. reporter.rollupWarn("Too many floats (" + count + "), you're probably using them for layout. Consider using a grid system instead.", rule);
  7635. }
  7636. });
  7637. }
  7638. });
  7639. /*
  7640. * Rule: Avoid too many @font-face declarations in the same stylesheet.
  7641. */
  7642. CSSLint.addRule({
  7643. // rule information
  7644. id: "font-faces",
  7645. name: "Don't use too many web fonts",
  7646. desc: "Too many different web fonts in the same stylesheet.",
  7647. url: "https://github.com/CSSLint/csslint/wiki/Don%27t-use-too-many-web-fonts",
  7648. browsers: "All",
  7649. // initialization
  7650. init: function(parser, reporter) {
  7651. "use strict";
  7652. var rule = this,
  7653. count = 0;
  7654. parser.addListener("startfontface", function() {
  7655. count++;
  7656. });
  7657. parser.addListener("endstylesheet", function() {
  7658. if (count > 5) {
  7659. reporter.rollupWarn("Too many @font-face declarations (" + count + ").", rule);
  7660. }
  7661. });
  7662. }
  7663. });
  7664. /*
  7665. * Rule: You shouldn't need more than 9 font-size declarations.
  7666. */
  7667. CSSLint.addRule({
  7668. // rule information
  7669. id: "font-sizes",
  7670. name: "Disallow too many font sizes",
  7671. desc: "Checks the number of font-size declarations.",
  7672. url: "https://github.com/CSSLint/csslint/wiki/Don%27t-use-too-many-font-size-declarations",
  7673. browsers: "All",
  7674. // initialization
  7675. init: function(parser, reporter) {
  7676. "use strict";
  7677. var rule = this,
  7678. count = 0;
  7679. // check for use of "font-size"
  7680. parser.addListener("property", function(event) {
  7681. if (event.property.toString() === "font-size") {
  7682. count++;
  7683. }
  7684. });
  7685. // report the results
  7686. parser.addListener("endstylesheet", function() {
  7687. reporter.stat("font-sizes", count);
  7688. if (count >= 10) {
  7689. reporter.rollupWarn("Too many font-size declarations (" + count + "), abstraction needed.", rule);
  7690. }
  7691. });
  7692. }
  7693. });
  7694. /*
  7695. * Rule: When using a vendor-prefixed gradient, make sure to use them all.
  7696. */
  7697. CSSLint.addRule({
  7698. // rule information
  7699. id: "gradients",
  7700. name: "Require all gradient definitions",
  7701. desc: "When using a vendor-prefixed gradient, make sure to use them all.",
  7702. url: "https://github.com/CSSLint/csslint/wiki/Require-all-gradient-definitions",
  7703. browsers: "All",
  7704. // initialization
  7705. init: function(parser, reporter) {
  7706. "use strict";
  7707. var rule = this,
  7708. gradients;
  7709. parser.addListener("startrule", function() {
  7710. gradients = {
  7711. moz: 0,
  7712. webkit: 0,
  7713. oldWebkit: 0,
  7714. o: 0
  7715. };
  7716. });
  7717. parser.addListener("property", function(event) {
  7718. if (/\-(moz|o|webkit)(?:\-(?:linear|radial))\-gradient/i.test(event.value)) {
  7719. gradients[RegExp.$1] = 1;
  7720. } else if (/\-webkit\-gradient/i.test(event.value)) {
  7721. gradients.oldWebkit = 1;
  7722. }
  7723. });
  7724. parser.addListener("endrule", function(event) {
  7725. var missing = [];
  7726. if (!gradients.moz) {
  7727. missing.push("Firefox 3.6+");
  7728. }
  7729. if (!gradients.webkit) {
  7730. missing.push("Webkit (Safari 5+, Chrome)");
  7731. }
  7732. if (!gradients.oldWebkit) {
  7733. missing.push("Old Webkit (Safari 4+, Chrome)");
  7734. }
  7735. if (!gradients.o) {
  7736. missing.push("Opera 11.1+");
  7737. }
  7738. if (missing.length && missing.length < 4) {
  7739. reporter.report("Missing vendor-prefixed CSS gradients for " + missing.join(", ") + ".", event.selectors[0].line, event.selectors[0].col, rule);
  7740. }
  7741. });
  7742. }
  7743. });
  7744. /*
  7745. * Rule: Don't use IDs for selectors.
  7746. */
  7747. CSSLint.addRule({
  7748. // rule information
  7749. id: "ids",
  7750. name: "Disallow IDs in selectors",
  7751. desc: "Selectors should not contain IDs.",
  7752. url: "https://github.com/CSSLint/csslint/wiki/Disallow-IDs-in-selectors",
  7753. browsers: "All",
  7754. // initialization
  7755. init: function(parser, reporter) {
  7756. "use strict";
  7757. var rule = this;
  7758. parser.addListener("startrule", function(event) {
  7759. var selectors = event.selectors,
  7760. selector,
  7761. part,
  7762. modifier,
  7763. idCount,
  7764. i, j, k;
  7765. for (i=0; i < selectors.length; i++) {
  7766. selector = selectors[i];
  7767. idCount = 0;
  7768. for (j=0; j < selector.parts.length; j++) {
  7769. part = selector.parts[j];
  7770. if (part.type === parser.SELECTOR_PART_TYPE) {
  7771. for (k=0; k < part.modifiers.length; k++) {
  7772. modifier = part.modifiers[k];
  7773. if (modifier.type === "id") {
  7774. idCount++;
  7775. }
  7776. }
  7777. }
  7778. }
  7779. if (idCount === 1) {
  7780. reporter.report("Don't use IDs in selectors.", selector.line, selector.col, rule);
  7781. } else if (idCount > 1) {
  7782. reporter.report(idCount + " IDs in the selector, really?", selector.line, selector.col, rule);
  7783. }
  7784. }
  7785. });
  7786. }
  7787. });
  7788. /*
  7789. * Rule: IE6-9 supports up to 31 stylesheet import.
  7790. * Reference:
  7791. * http://blogs.msdn.com/b/ieinternals/archive/2011/05/14/internet-explorer-stylesheet-rule-selector-import-sheet-limit-maximum.aspx
  7792. */
  7793. CSSLint.addRule({
  7794. // rule information
  7795. id: "import-ie-limit",
  7796. name: "@import limit on IE6-IE9",
  7797. desc: "IE6-9 supports up to 31 @import per stylesheet",
  7798. browsers: "IE6, IE7, IE8, IE9",
  7799. // initialization
  7800. init: function(parser, reporter) {
  7801. "use strict";
  7802. var rule = this,
  7803. MAX_IMPORT_COUNT = 31,
  7804. count = 0;
  7805. function startPage() {
  7806. count = 0;
  7807. }
  7808. parser.addListener("startpage", startPage);
  7809. parser.addListener("import", function() {
  7810. count++;
  7811. });
  7812. parser.addListener("endstylesheet", function() {
  7813. if (count > MAX_IMPORT_COUNT) {
  7814. reporter.rollupError(
  7815. "Too many @import rules (" + count + "). IE6-9 supports up to 31 import per stylesheet.",
  7816. rule
  7817. );
  7818. }
  7819. });
  7820. }
  7821. });
  7822. /*
  7823. * Rule: Don't use @import, use <link> instead.
  7824. */
  7825. CSSLint.addRule({
  7826. // rule information
  7827. id: "import",
  7828. name: "Disallow @import",
  7829. desc: "Don't use @import, use <link> instead.",
  7830. url: "https://github.com/CSSLint/csslint/wiki/Disallow-%40import",
  7831. browsers: "All",
  7832. // initialization
  7833. init: function(parser, reporter) {
  7834. "use strict";
  7835. var rule = this;
  7836. parser.addListener("import", function(event) {
  7837. reporter.report("@import prevents parallel downloads, use <link> instead.", event.line, event.col, rule);
  7838. });
  7839. }
  7840. });
  7841. /*
  7842. * Rule: Make sure !important is not overused, this could lead to specificity
  7843. * war. Display a warning on !important declarations, an error if it's
  7844. * used more at least 10 times.
  7845. */
  7846. CSSLint.addRule({
  7847. // rule information
  7848. id: "important",
  7849. name: "Disallow !important",
  7850. desc: "Be careful when using !important declaration",
  7851. url: "https://github.com/CSSLint/csslint/wiki/Disallow-%21important",
  7852. browsers: "All",
  7853. // initialization
  7854. init: function(parser, reporter) {
  7855. "use strict";
  7856. var rule = this,
  7857. count = 0;
  7858. // warn that important is used and increment the declaration counter
  7859. parser.addListener("property", function(event) {
  7860. if (event.important === true) {
  7861. count++;
  7862. reporter.report("Use of !important", event.line, event.col, rule);
  7863. }
  7864. });
  7865. // if there are more than 10, show an error
  7866. parser.addListener("endstylesheet", function() {
  7867. reporter.stat("important", count);
  7868. if (count >= 10) {
  7869. reporter.rollupWarn("Too many !important declarations (" + count + "), try to use less than 10 to avoid specificity issues.", rule);
  7870. }
  7871. });
  7872. }
  7873. });
  7874. /*
  7875. * Rule: Properties should be known (listed in CSS3 specification) or
  7876. * be a vendor-prefixed property.
  7877. */
  7878. CSSLint.addRule({
  7879. // rule information
  7880. id: "known-properties",
  7881. name: "Require use of known properties",
  7882. desc: "Properties should be known (listed in CSS3 specification) or be a vendor-prefixed property.",
  7883. url: "https://github.com/CSSLint/csslint/wiki/Require-use-of-known-properties",
  7884. browsers: "All",
  7885. // initialization
  7886. init: function(parser, reporter) {
  7887. "use strict";
  7888. var rule = this;
  7889. parser.addListener("property", function(event) {
  7890. // the check is handled entirely by the parser-lib (https://github.com/nzakas/parser-lib)
  7891. if (event.invalid) {
  7892. reporter.report(event.invalid.message, event.line, event.col, rule);
  7893. }
  7894. });
  7895. }
  7896. });
  7897. /*
  7898. * Rule: All properties should be in alphabetical order.
  7899. */
  7900. CSSLint.addRule({
  7901. // rule information
  7902. id: "order-alphabetical",
  7903. name: "Alphabetical order",
  7904. desc: "Assure properties are in alphabetical order",
  7905. browsers: "All",
  7906. // initialization
  7907. init: function(parser, reporter) {
  7908. "use strict";
  7909. var rule = this,
  7910. properties;
  7911. var startRule = function () {
  7912. properties = [];
  7913. };
  7914. var endRule = function(event) {
  7915. var currentProperties = properties.join(","),
  7916. expectedProperties = properties.sort().join(",");
  7917. if (currentProperties !== expectedProperties) {
  7918. reporter.report("Rule doesn't have all its properties in alphabetical order.", event.line, event.col, rule);
  7919. }
  7920. };
  7921. parser.addListener("startrule", startRule);
  7922. parser.addListener("startfontface", startRule);
  7923. parser.addListener("startpage", startRule);
  7924. parser.addListener("startpagemargin", startRule);
  7925. parser.addListener("startkeyframerule", startRule);
  7926. parser.addListener("startviewport", startRule);
  7927. parser.addListener("property", function(event) {
  7928. var name = event.property.text,
  7929. lowerCasePrefixLessName = name.toLowerCase().replace(/^-.*?-/, "");
  7930. properties.push(lowerCasePrefixLessName);
  7931. });
  7932. parser.addListener("endrule", endRule);
  7933. parser.addListener("endfontface", endRule);
  7934. parser.addListener("endpage", endRule);
  7935. parser.addListener("endpagemargin", endRule);
  7936. parser.addListener("endkeyframerule", endRule);
  7937. parser.addListener("endviewport", endRule);
  7938. }
  7939. });
  7940. /*
  7941. * Rule: outline: none or outline: 0 should only be used in a :focus rule
  7942. * and only if there are other properties in the same rule.
  7943. */
  7944. CSSLint.addRule({
  7945. // rule information
  7946. id: "outline-none",
  7947. name: "Disallow outline: none",
  7948. desc: "Use of outline: none or outline: 0 should be limited to :focus rules.",
  7949. url: "https://github.com/CSSLint/csslint/wiki/Disallow-outline%3Anone",
  7950. browsers: "All",
  7951. tags: ["Accessibility"],
  7952. // initialization
  7953. init: function(parser, reporter) {
  7954. "use strict";
  7955. var rule = this,
  7956. lastRule;
  7957. function startRule(event) {
  7958. if (event.selectors) {
  7959. lastRule = {
  7960. line: event.line,
  7961. col: event.col,
  7962. selectors: event.selectors,
  7963. propCount: 0,
  7964. outline: false
  7965. };
  7966. } else {
  7967. lastRule = null;
  7968. }
  7969. }
  7970. function endRule() {
  7971. if (lastRule) {
  7972. if (lastRule.outline) {
  7973. if (lastRule.selectors.toString().toLowerCase().indexOf(":focus") === -1) {
  7974. reporter.report("Outlines should only be modified using :focus.", lastRule.line, lastRule.col, rule);
  7975. } else if (lastRule.propCount === 1) {
  7976. reporter.report("Outlines shouldn't be hidden unless other visual changes are made.", lastRule.line, lastRule.col, rule);
  7977. }
  7978. }
  7979. }
  7980. }
  7981. parser.addListener("startrule", startRule);
  7982. parser.addListener("startfontface", startRule);
  7983. parser.addListener("startpage", startRule);
  7984. parser.addListener("startpagemargin", startRule);
  7985. parser.addListener("startkeyframerule", startRule);
  7986. parser.addListener("startviewport", startRule);
  7987. parser.addListener("property", function(event) {
  7988. var name = event.property.text.toLowerCase(),
  7989. value = event.value;
  7990. if (lastRule) {
  7991. lastRule.propCount++;
  7992. if (name === "outline" && (value.toString() === "none" || value.toString() === "0")) {
  7993. lastRule.outline = true;
  7994. }
  7995. }
  7996. });
  7997. parser.addListener("endrule", endRule);
  7998. parser.addListener("endfontface", endRule);
  7999. parser.addListener("endpage", endRule);
  8000. parser.addListener("endpagemargin", endRule);
  8001. parser.addListener("endkeyframerule", endRule);
  8002. parser.addListener("endviewport", endRule);
  8003. }
  8004. });
  8005. /*
  8006. * Rule: Don't use classes or IDs with elements (a.foo or a#foo).
  8007. */
  8008. CSSLint.addRule({
  8009. // rule information
  8010. id: "overqualified-elements",
  8011. name: "Disallow overqualified elements",
  8012. desc: "Don't use classes or IDs with elements (a.foo or a#foo).",
  8013. url: "https://github.com/CSSLint/csslint/wiki/Disallow-overqualified-elements",
  8014. browsers: "All",
  8015. // initialization
  8016. init: function(parser, reporter) {
  8017. "use strict";
  8018. var rule = this,
  8019. classes = {};
  8020. parser.addListener("startrule", function(event) {
  8021. var selectors = event.selectors,
  8022. selector,
  8023. part,
  8024. modifier,
  8025. i, j, k;
  8026. for (i=0; i < selectors.length; i++) {
  8027. selector = selectors[i];
  8028. for (j=0; j < selector.parts.length; j++) {
  8029. part = selector.parts[j];
  8030. if (part.type === parser.SELECTOR_PART_TYPE) {
  8031. for (k=0; k < part.modifiers.length; k++) {
  8032. modifier = part.modifiers[k];
  8033. if (part.elementName && modifier.type === "id") {
  8034. reporter.report("Element (" + part + ") is overqualified, just use " + modifier + " without element name.", part.line, part.col, rule);
  8035. } else if (modifier.type === "class") {
  8036. if (!classes[modifier]) {
  8037. classes[modifier] = [];
  8038. }
  8039. classes[modifier].push({
  8040. modifier: modifier,
  8041. part: part
  8042. });
  8043. }
  8044. }
  8045. }
  8046. }
  8047. }
  8048. });
  8049. parser.addListener("endstylesheet", function() {
  8050. var prop;
  8051. for (prop in classes) {
  8052. if (classes.hasOwnProperty(prop)) {
  8053. // one use means that this is overqualified
  8054. if (classes[prop].length === 1 && classes[prop][0].part.elementName) {
  8055. reporter.report("Element (" + classes[prop][0].part + ") is overqualified, just use " + classes[prop][0].modifier + " without element name.", classes[prop][0].part.line, classes[prop][0].part.col, rule);
  8056. }
  8057. }
  8058. }
  8059. });
  8060. }
  8061. });
  8062. /*
  8063. * Rule: Headings (h1-h6) should not be qualified (namespaced).
  8064. */
  8065. CSSLint.addRule({
  8066. // rule information
  8067. id: "qualified-headings",
  8068. name: "Disallow qualified headings",
  8069. desc: "Headings should not be qualified (namespaced).",
  8070. url: "https://github.com/CSSLint/csslint/wiki/Disallow-qualified-headings",
  8071. browsers: "All",
  8072. // initialization
  8073. init: function(parser, reporter) {
  8074. "use strict";
  8075. var rule = this;
  8076. parser.addListener("startrule", function(event) {
  8077. var selectors = event.selectors,
  8078. selector,
  8079. part,
  8080. i, j;
  8081. for (i=0; i < selectors.length; i++) {
  8082. selector = selectors[i];
  8083. for (j=0; j < selector.parts.length; j++) {
  8084. part = selector.parts[j];
  8085. if (part.type === parser.SELECTOR_PART_TYPE) {
  8086. if (part.elementName && /h[1-6]/.test(part.elementName.toString()) && j > 0) {
  8087. reporter.report("Heading (" + part.elementName + ") should not be qualified.", part.line, part.col, rule);
  8088. }
  8089. }
  8090. }
  8091. }
  8092. });
  8093. }
  8094. });
  8095. /*
  8096. * Rule: Selectors that look like regular expressions are slow and should be avoided.
  8097. */
  8098. CSSLint.addRule({
  8099. // rule information
  8100. id: "regex-selectors",
  8101. name: "Disallow selectors that look like regexs",
  8102. desc: "Selectors that look like regular expressions are slow and should be avoided.",
  8103. url: "https://github.com/CSSLint/csslint/wiki/Disallow-selectors-that-look-like-regular-expressions",
  8104. browsers: "All",
  8105. // initialization
  8106. init: function(parser, reporter) {
  8107. "use strict";
  8108. var rule = this;
  8109. parser.addListener("startrule", function(event) {
  8110. var selectors = event.selectors,
  8111. selector,
  8112. part,
  8113. modifier,
  8114. i, j, k;
  8115. for (i=0; i < selectors.length; i++) {
  8116. selector = selectors[i];
  8117. for (j=0; j < selector.parts.length; j++) {
  8118. part = selector.parts[j];
  8119. if (part.type === parser.SELECTOR_PART_TYPE) {
  8120. for (k=0; k < part.modifiers.length; k++) {
  8121. modifier = part.modifiers[k];
  8122. if (modifier.type === "attribute") {
  8123. if (/([~\|\^\$\*]=)/.test(modifier)) {
  8124. reporter.report("Attribute selectors with " + RegExp.$1 + " are slow!", modifier.line, modifier.col, rule);
  8125. }
  8126. }
  8127. }
  8128. }
  8129. }
  8130. }
  8131. });
  8132. }
  8133. });
  8134. /*
  8135. * Rule: Total number of rules should not exceed x.
  8136. */
  8137. CSSLint.addRule({
  8138. // rule information
  8139. id: "rules-count",
  8140. name: "Rules Count",
  8141. desc: "Track how many rules there are.",
  8142. browsers: "All",
  8143. // initialization
  8144. init: function(parser, reporter) {
  8145. "use strict";
  8146. var count = 0;
  8147. // count each rule
  8148. parser.addListener("startrule", function() {
  8149. count++;
  8150. });
  8151. parser.addListener("endstylesheet", function() {
  8152. reporter.stat("rule-count", count);
  8153. });
  8154. }
  8155. });
  8156. /*
  8157. * Rule: Warn people with approaching the IE 4095 limit
  8158. */
  8159. CSSLint.addRule({
  8160. // rule information
  8161. id: "selector-max-approaching",
  8162. name: "Warn when approaching the 4095 selector limit for IE",
  8163. desc: "Will warn when selector count is >= 3800 selectors.",
  8164. browsers: "IE",
  8165. // initialization
  8166. init: function(parser, reporter) {
  8167. "use strict";
  8168. var rule = this, count = 0;
  8169. parser.addListener("startrule", function(event) {
  8170. count += event.selectors.length;
  8171. });
  8172. parser.addListener("endstylesheet", function() {
  8173. if (count >= 3800) {
  8174. reporter.report("You have " + count + " selectors. Internet Explorer supports a maximum of 4095 selectors per stylesheet. Consider refactoring.", 0, 0, rule);
  8175. }
  8176. });
  8177. }
  8178. });
  8179. /*
  8180. * Rule: Warn people past the IE 4095 limit
  8181. */
  8182. CSSLint.addRule({
  8183. // rule information
  8184. id: "selector-max",
  8185. name: "Error when past the 4095 selector limit for IE",
  8186. desc: "Will error when selector count is > 4095.",
  8187. browsers: "IE",
  8188. // initialization
  8189. init: function(parser, reporter) {
  8190. "use strict";
  8191. var rule = this, count = 0;
  8192. parser.addListener("startrule", function(event) {
  8193. count += event.selectors.length;
  8194. });
  8195. parser.addListener("endstylesheet", function() {
  8196. if (count > 4095) {
  8197. reporter.report("You have " + count + " selectors. Internet Explorer supports a maximum of 4095 selectors per stylesheet. Consider refactoring.", 0, 0, rule);
  8198. }
  8199. });
  8200. }
  8201. });
  8202. /*
  8203. * Rule: Avoid new-line characters in selectors.
  8204. */
  8205. CSSLint.addRule({
  8206. // rule information
  8207. id: "selector-newline",
  8208. name: "Disallow new-line characters in selectors",
  8209. desc: "New-line characters in selectors are usually a forgotten comma and not a descendant combinator.",
  8210. browsers: "All",
  8211. // initialization
  8212. init: function(parser, reporter) {
  8213. "use strict";
  8214. var rule = this;
  8215. function startRule(event) {
  8216. var i, len, selector, p, n, pLen, part, part2, type, currentLine, nextLine,
  8217. selectors = event.selectors;
  8218. for (i = 0, len = selectors.length; i < len; i++) {
  8219. selector = selectors[i];
  8220. for (p = 0, pLen = selector.parts.length; p < pLen; p++) {
  8221. for (n = p + 1; n < pLen; n++) {
  8222. part = selector.parts[p];
  8223. part2 = selector.parts[n];
  8224. type = part.type;
  8225. currentLine = part.line;
  8226. nextLine = part2.line;
  8227. if (type === "descendant" && nextLine > currentLine) {
  8228. reporter.report("newline character found in selector (forgot a comma?)", currentLine, selectors[i].parts[0].col, rule);
  8229. }
  8230. }
  8231. }
  8232. }
  8233. }
  8234. parser.addListener("startrule", startRule);
  8235. }
  8236. });
  8237. /*
  8238. * Rule: Use shorthand properties where possible.
  8239. *
  8240. */
  8241. CSSLint.addRule({
  8242. // rule information
  8243. id: "shorthand",
  8244. name: "Require shorthand properties",
  8245. desc: "Use shorthand properties where possible.",
  8246. url: "https://github.com/CSSLint/csslint/wiki/Require-shorthand-properties",
  8247. browsers: "All",
  8248. // initialization
  8249. init: function(parser, reporter) {
  8250. "use strict";
  8251. var rule = this,
  8252. prop, i, len,
  8253. propertiesToCheck = {},
  8254. properties,
  8255. mapping = {
  8256. "margin": [
  8257. "margin-top",
  8258. "margin-bottom",
  8259. "margin-left",
  8260. "margin-right"
  8261. ],
  8262. "padding": [
  8263. "padding-top",
  8264. "padding-bottom",
  8265. "padding-left",
  8266. "padding-right"
  8267. ]
  8268. };
  8269. // initialize propertiesToCheck
  8270. for (prop in mapping) {
  8271. if (mapping.hasOwnProperty(prop)) {
  8272. for (i=0, len=mapping[prop].length; i < len; i++) {
  8273. propertiesToCheck[mapping[prop][i]] = prop;
  8274. }
  8275. }
  8276. }
  8277. function startRule() {
  8278. properties = {};
  8279. }
  8280. // event handler for end of rules
  8281. function endRule(event) {
  8282. var prop, i, len, total;
  8283. // check which properties this rule has
  8284. for (prop in mapping) {
  8285. if (mapping.hasOwnProperty(prop)) {
  8286. total=0;
  8287. for (i=0, len=mapping[prop].length; i < len; i++) {
  8288. total += properties[mapping[prop][i]] ? 1 : 0;
  8289. }
  8290. if (total === mapping[prop].length) {
  8291. reporter.report("The properties " + mapping[prop].join(", ") + " can be replaced by " + prop + ".", event.line, event.col, rule);
  8292. }
  8293. }
  8294. }
  8295. }
  8296. parser.addListener("startrule", startRule);
  8297. parser.addListener("startfontface", startRule);
  8298. // check for use of "font-size"
  8299. parser.addListener("property", function(event) {
  8300. var name = event.property.toString().toLowerCase();
  8301. if (propertiesToCheck[name]) {
  8302. properties[name] = 1;
  8303. }
  8304. });
  8305. parser.addListener("endrule", endRule);
  8306. parser.addListener("endfontface", endRule);
  8307. }
  8308. });
  8309. /*
  8310. * Rule: Don't use properties with a star prefix.
  8311. *
  8312. */
  8313. CSSLint.addRule({
  8314. // rule information
  8315. id: "star-property-hack",
  8316. name: "Disallow properties with a star prefix",
  8317. desc: "Checks for the star property hack (targets IE6/7)",
  8318. url: "https://github.com/CSSLint/csslint/wiki/Disallow-star-hack",
  8319. browsers: "All",
  8320. // initialization
  8321. init: function(parser, reporter) {
  8322. "use strict";
  8323. var rule = this;
  8324. // check if property name starts with "*"
  8325. parser.addListener("property", function(event) {
  8326. var property = event.property;
  8327. if (property.hack === "*") {
  8328. reporter.report("Property with star prefix found.", event.property.line, event.property.col, rule);
  8329. }
  8330. });
  8331. }
  8332. });
  8333. /*
  8334. * Rule: Don't use text-indent for image replacement if you need to support rtl.
  8335. *
  8336. */
  8337. CSSLint.addRule({
  8338. // rule information
  8339. id: "text-indent",
  8340. name: "Disallow negative text-indent",
  8341. desc: "Checks for text indent less than -99px",
  8342. url: "https://github.com/CSSLint/csslint/wiki/Disallow-negative-text-indent",
  8343. browsers: "All",
  8344. // initialization
  8345. init: function(parser, reporter) {
  8346. "use strict";
  8347. var rule = this,
  8348. textIndent,
  8349. direction;
  8350. function startRule() {
  8351. textIndent = false;
  8352. direction = "inherit";
  8353. }
  8354. // event handler for end of rules
  8355. function endRule() {
  8356. if (textIndent && direction !== "ltr") {
  8357. reporter.report("Negative text-indent doesn't work well with RTL. If you use text-indent for image replacement explicitly set direction for that item to ltr.", textIndent.line, textIndent.col, rule);
  8358. }
  8359. }
  8360. parser.addListener("startrule", startRule);
  8361. parser.addListener("startfontface", startRule);
  8362. // check for use of "font-size"
  8363. parser.addListener("property", function(event) {
  8364. var name = event.property.toString().toLowerCase(),
  8365. value = event.value;
  8366. if (name === "text-indent" && value.parts[0].value < -99) {
  8367. textIndent = event.property;
  8368. } else if (name === "direction" && value.toString() === "ltr") {
  8369. direction = "ltr";
  8370. }
  8371. });
  8372. parser.addListener("endrule", endRule);
  8373. parser.addListener("endfontface", endRule);
  8374. }
  8375. });
  8376. /*
  8377. * Rule: Don't use properties with a underscore prefix.
  8378. *
  8379. */
  8380. CSSLint.addRule({
  8381. // rule information
  8382. id: "underscore-property-hack",
  8383. name: "Disallow properties with an underscore prefix",
  8384. desc: "Checks for the underscore property hack (targets IE6)",
  8385. url: "https://github.com/CSSLint/csslint/wiki/Disallow-underscore-hack",
  8386. browsers: "All",
  8387. // initialization
  8388. init: function(parser, reporter) {
  8389. "use strict";
  8390. var rule = this;
  8391. // check if property name starts with "_"
  8392. parser.addListener("property", function(event) {
  8393. var property = event.property;
  8394. if (property.hack === "_") {
  8395. reporter.report("Property with underscore prefix found.", event.property.line, event.property.col, rule);
  8396. }
  8397. });
  8398. }
  8399. });
  8400. /*
  8401. * Rule: Headings (h1-h6) should be defined only once.
  8402. */
  8403. CSSLint.addRule({
  8404. // rule information
  8405. id: "unique-headings",
  8406. name: "Headings should only be defined once",
  8407. desc: "Headings should be defined only once.",
  8408. url: "https://github.com/CSSLint/csslint/wiki/Headings-should-only-be-defined-once",
  8409. browsers: "All",
  8410. // initialization
  8411. init: function(parser, reporter) {
  8412. "use strict";
  8413. var rule = this;
  8414. var headings = {
  8415. h1: 0,
  8416. h2: 0,
  8417. h3: 0,
  8418. h4: 0,
  8419. h5: 0,
  8420. h6: 0
  8421. };
  8422. parser.addListener("startrule", function(event) {
  8423. var selectors = event.selectors,
  8424. selector,
  8425. part,
  8426. pseudo,
  8427. i, j;
  8428. for (i=0; i < selectors.length; i++) {
  8429. selector = selectors[i];
  8430. part = selector.parts[selector.parts.length-1];
  8431. if (part.elementName && /(h[1-6])/i.test(part.elementName.toString())) {
  8432. for (j=0; j < part.modifiers.length; j++) {
  8433. if (part.modifiers[j].type === "pseudo") {
  8434. pseudo = true;
  8435. break;
  8436. }
  8437. }
  8438. if (!pseudo) {
  8439. headings[RegExp.$1]++;
  8440. if (headings[RegExp.$1] > 1) {
  8441. reporter.report("Heading (" + part.elementName + ") has already been defined.", part.line, part.col, rule);
  8442. }
  8443. }
  8444. }
  8445. }
  8446. });
  8447. parser.addListener("endstylesheet", function() {
  8448. var prop,
  8449. messages = [];
  8450. for (prop in headings) {
  8451. if (headings.hasOwnProperty(prop)) {
  8452. if (headings[prop] > 1) {
  8453. messages.push(headings[prop] + " " + prop + "s");
  8454. }
  8455. }
  8456. }
  8457. if (messages.length) {
  8458. reporter.rollupWarn("You have " + messages.join(", ") + " defined in this stylesheet.", rule);
  8459. }
  8460. });
  8461. }
  8462. });
  8463. /*
  8464. * Rule: Don't use universal selector because it's slow.
  8465. */
  8466. CSSLint.addRule({
  8467. // rule information
  8468. id: "universal-selector",
  8469. name: "Disallow universal selector",
  8470. desc: "The universal selector (*) is known to be slow.",
  8471. url: "https://github.com/CSSLint/csslint/wiki/Disallow-universal-selector",
  8472. browsers: "All",
  8473. // initialization
  8474. init: function(parser, reporter) {
  8475. "use strict";
  8476. var rule = this;
  8477. parser.addListener("startrule", function(event) {
  8478. var selectors = event.selectors,
  8479. selector,
  8480. part,
  8481. i;
  8482. for (i=0; i < selectors.length; i++) {
  8483. selector = selectors[i];
  8484. part = selector.parts[selector.parts.length-1];
  8485. if (part.elementName === "*") {
  8486. reporter.report(rule.desc, part.line, part.col, rule);
  8487. }
  8488. }
  8489. });
  8490. }
  8491. });
  8492. /*
  8493. * Rule: Don't use unqualified attribute selectors because they're just like universal selectors.
  8494. */
  8495. CSSLint.addRule({
  8496. // rule information
  8497. id: "unqualified-attributes",
  8498. name: "Disallow unqualified attribute selectors",
  8499. desc: "Unqualified attribute selectors are known to be slow.",
  8500. url: "https://github.com/CSSLint/csslint/wiki/Disallow-unqualified-attribute-selectors",
  8501. browsers: "All",
  8502. // initialization
  8503. init: function(parser, reporter) {
  8504. "use strict";
  8505. var rule = this;
  8506. parser.addListener("startrule", function(event) {
  8507. var selectors = event.selectors,
  8508. selectorContainsClassOrId = false,
  8509. selector,
  8510. part,
  8511. modifier,
  8512. i, k;
  8513. for (i=0; i < selectors.length; i++) {
  8514. selector = selectors[i];
  8515. part = selector.parts[selector.parts.length-1];
  8516. if (part.type === parser.SELECTOR_PART_TYPE) {
  8517. for (k=0; k < part.modifiers.length; k++) {
  8518. modifier = part.modifiers[k];
  8519. if (modifier.type === "class" || modifier.type === "id") {
  8520. selectorContainsClassOrId = true;
  8521. break;
  8522. }
  8523. }
  8524. if (!selectorContainsClassOrId) {
  8525. for (k=0; k < part.modifiers.length; k++) {
  8526. modifier = part.modifiers[k];
  8527. if (modifier.type === "attribute" && (!part.elementName || part.elementName === "*")) {
  8528. reporter.report(rule.desc, part.line, part.col, rule);
  8529. }
  8530. }
  8531. }
  8532. }
  8533. }
  8534. });
  8535. }
  8536. });
  8537. /*
  8538. * Rule: When using a vendor-prefixed property, make sure to
  8539. * include the standard one.
  8540. */
  8541. CSSLint.addRule({
  8542. // rule information
  8543. id: "vendor-prefix",
  8544. name: "Require standard property with vendor prefix",
  8545. desc: "When using a vendor-prefixed property, make sure to include the standard one.",
  8546. url: "https://github.com/CSSLint/csslint/wiki/Require-standard-property-with-vendor-prefix",
  8547. browsers: "All",
  8548. // initialization
  8549. init: function(parser, reporter) {
  8550. "use strict";
  8551. var rule = this,
  8552. properties,
  8553. num,
  8554. propertiesToCheck = {
  8555. "-webkit-border-radius": "border-radius",
  8556. "-webkit-border-top-left-radius": "border-top-left-radius",
  8557. "-webkit-border-top-right-radius": "border-top-right-radius",
  8558. "-webkit-border-bottom-left-radius": "border-bottom-left-radius",
  8559. "-webkit-border-bottom-right-radius": "border-bottom-right-radius",
  8560. "-o-border-radius": "border-radius",
  8561. "-o-border-top-left-radius": "border-top-left-radius",
  8562. "-o-border-top-right-radius": "border-top-right-radius",
  8563. "-o-border-bottom-left-radius": "border-bottom-left-radius",
  8564. "-o-border-bottom-right-radius": "border-bottom-right-radius",
  8565. "-moz-border-radius": "border-radius",
  8566. "-moz-border-radius-topleft": "border-top-left-radius",
  8567. "-moz-border-radius-topright": "border-top-right-radius",
  8568. "-moz-border-radius-bottomleft": "border-bottom-left-radius",
  8569. "-moz-border-radius-bottomright": "border-bottom-right-radius",
  8570. "-moz-column-count": "column-count",
  8571. "-webkit-column-count": "column-count",
  8572. "-moz-column-gap": "column-gap",
  8573. "-webkit-column-gap": "column-gap",
  8574. "-moz-column-rule": "column-rule",
  8575. "-webkit-column-rule": "column-rule",
  8576. "-moz-column-rule-style": "column-rule-style",
  8577. "-webkit-column-rule-style": "column-rule-style",
  8578. "-moz-column-rule-color": "column-rule-color",
  8579. "-webkit-column-rule-color": "column-rule-color",
  8580. "-moz-column-rule-width": "column-rule-width",
  8581. "-webkit-column-rule-width": "column-rule-width",
  8582. "-moz-column-width": "column-width",
  8583. "-webkit-column-width": "column-width",
  8584. "-webkit-column-span": "column-span",
  8585. "-webkit-columns": "columns",
  8586. "-moz-box-shadow": "box-shadow",
  8587. "-webkit-box-shadow": "box-shadow",
  8588. "-moz-transform": "transform",
  8589. "-webkit-transform": "transform",
  8590. "-o-transform": "transform",
  8591. "-ms-transform": "transform",
  8592. "-moz-transform-origin": "transform-origin",
  8593. "-webkit-transform-origin": "transform-origin",
  8594. "-o-transform-origin": "transform-origin",
  8595. "-ms-transform-origin": "transform-origin",
  8596. "-moz-box-sizing": "box-sizing",
  8597. "-webkit-box-sizing": "box-sizing"
  8598. };
  8599. // event handler for beginning of rules
  8600. function startRule() {
  8601. properties = {};
  8602. num = 1;
  8603. }
  8604. // event handler for end of rules
  8605. function endRule() {
  8606. var prop,
  8607. i,
  8608. len,
  8609. needed,
  8610. actual,
  8611. needsStandard = [];
  8612. for (prop in properties) {
  8613. if (propertiesToCheck[prop]) {
  8614. needsStandard.push({
  8615. actual: prop,
  8616. needed: propertiesToCheck[prop]
  8617. });
  8618. }
  8619. }
  8620. for (i=0, len=needsStandard.length; i < len; i++) {
  8621. needed = needsStandard[i].needed;
  8622. actual = needsStandard[i].actual;
  8623. if (!properties[needed]) {
  8624. reporter.report("Missing standard property '" + needed + "' to go along with '" + actual + "'.", properties[actual][0].name.line, properties[actual][0].name.col, rule);
  8625. } else {
  8626. // make sure standard property is last
  8627. if (properties[needed][0].pos < properties[actual][0].pos) {
  8628. reporter.report("Standard property '" + needed + "' should come after vendor-prefixed property '" + actual + "'.", properties[actual][0].name.line, properties[actual][0].name.col, rule);
  8629. }
  8630. }
  8631. }
  8632. }
  8633. parser.addListener("startrule", startRule);
  8634. parser.addListener("startfontface", startRule);
  8635. parser.addListener("startpage", startRule);
  8636. parser.addListener("startpagemargin", startRule);
  8637. parser.addListener("startkeyframerule", startRule);
  8638. parser.addListener("startviewport", startRule);
  8639. parser.addListener("property", function(event) {
  8640. var name = event.property.text.toLowerCase();
  8641. if (!properties[name]) {
  8642. properties[name] = [];
  8643. }
  8644. properties[name].push({
  8645. name: event.property,
  8646. value: event.value,
  8647. pos: num++
  8648. });
  8649. });
  8650. parser.addListener("endrule", endRule);
  8651. parser.addListener("endfontface", endRule);
  8652. parser.addListener("endpage", endRule);
  8653. parser.addListener("endpagemargin", endRule);
  8654. parser.addListener("endkeyframerule", endRule);
  8655. parser.addListener("endviewport", endRule);
  8656. }
  8657. });
  8658. /*
  8659. * Rule: You don't need to specify units when a value is 0.
  8660. */
  8661. CSSLint.addRule({
  8662. // rule information
  8663. id: "zero-units",
  8664. name: "Disallow units for 0 values",
  8665. desc: "You don't need to specify units when a value is 0.",
  8666. url: "https://github.com/CSSLint/csslint/wiki/Disallow-units-for-zero-values",
  8667. browsers: "All",
  8668. // initialization
  8669. init: function(parser, reporter) {
  8670. "use strict";
  8671. var rule = this;
  8672. // count how many times "float" is used
  8673. parser.addListener("property", function(event) {
  8674. var parts = event.value.parts,
  8675. i = 0,
  8676. len = parts.length;
  8677. while (i < len) {
  8678. if ((parts[i].units || parts[i].type === "percentage") && parts[i].value === 0 && parts[i].type !== "time") {
  8679. reporter.report("Values of 0 shouldn't have units specified.", parts[i].line, parts[i].col, rule);
  8680. }
  8681. i++;
  8682. }
  8683. });
  8684. }
  8685. });
  8686. (function() {
  8687. "use strict";
  8688. /**
  8689. * Replace special characters before write to output.
  8690. *
  8691. * Rules:
  8692. * - single quotes is the escape sequence for double-quotes
  8693. * - &amp; is the escape sequence for &
  8694. * - &lt; is the escape sequence for <
  8695. * - &gt; is the escape sequence for >
  8696. *
  8697. * @param {String} message to escape
  8698. * @return escaped message as {String}
  8699. */
  8700. var xmlEscape = function(str) {
  8701. if (!str || str.constructor !== String) {
  8702. return "";
  8703. }
  8704. return str.replace(/["&><]/g, function(match) {
  8705. switch (match) {
  8706. case "\"":
  8707. return "&quot;";
  8708. case "&":
  8709. return "&amp;";
  8710. case "<":
  8711. return "&lt;";
  8712. case ">":
  8713. return "&gt;";
  8714. }
  8715. });
  8716. };
  8717. CSSLint.addFormatter({
  8718. // format information
  8719. id: "checkstyle-xml",
  8720. name: "Checkstyle XML format",
  8721. /**
  8722. * Return opening root XML tag.
  8723. * @return {String} to prepend before all results
  8724. */
  8725. startFormat: function() {
  8726. return "<?xml version=\"1.0\" encoding=\"utf-8\"?><checkstyle>";
  8727. },
  8728. /**
  8729. * Return closing root XML tag.
  8730. * @return {String} to append after all results
  8731. */
  8732. endFormat: function() {
  8733. return "</checkstyle>";
  8734. },
  8735. /**
  8736. * Returns message when there is a file read error.
  8737. * @param {String} filename The name of the file that caused the error.
  8738. * @param {String} message The error message
  8739. * @return {String} The error message.
  8740. */
  8741. readError: function(filename, message) {
  8742. return "<file name=\"" + xmlEscape(filename) + "\"><error line=\"0\" column=\"0\" severty=\"error\" message=\"" + xmlEscape(message) + "\"></error></file>";
  8743. },
  8744. /**
  8745. * Given CSS Lint results for a file, return output for this format.
  8746. * @param results {Object} with error and warning messages
  8747. * @param filename {String} relative file path
  8748. * @param options {Object} (UNUSED for now) specifies special handling of output
  8749. * @return {String} output for results
  8750. */
  8751. formatResults: function(results, filename/*, options*/) {
  8752. var messages = results.messages,
  8753. output = [];
  8754. /**
  8755. * Generate a source string for a rule.
  8756. * Checkstyle source strings usually resemble Java class names e.g
  8757. * net.csslint.SomeRuleName
  8758. * @param {Object} rule
  8759. * @return rule source as {String}
  8760. */
  8761. var generateSource = function(rule) {
  8762. if (!rule || !("name" in rule)) {
  8763. return "";
  8764. }
  8765. return "net.csslint." + rule.name.replace(/\s/g, "");
  8766. };
  8767. if (messages.length > 0) {
  8768. output.push("<file name=\""+filename+"\">");
  8769. CSSLint.Util.forEach(messages, function (message) {
  8770. // ignore rollups for now
  8771. if (!message.rollup) {
  8772. output.push("<error line=\"" + message.line + "\" column=\"" + message.col + "\" severity=\"" + message.type + "\"" +
  8773. " message=\"" + xmlEscape(message.message) + "\" source=\"" + generateSource(message.rule) +"\"/>");
  8774. }
  8775. });
  8776. output.push("</file>");
  8777. }
  8778. return output.join("");
  8779. }
  8780. });
  8781. }());
  8782. CSSLint.addFormatter({
  8783. // format information
  8784. id: "compact",
  8785. name: "Compact, 'porcelain' format",
  8786. /**
  8787. * Return content to be printed before all file results.
  8788. * @return {String} to prepend before all results
  8789. */
  8790. startFormat: function() {
  8791. "use strict";
  8792. return "";
  8793. },
  8794. /**
  8795. * Return content to be printed after all file results.
  8796. * @return {String} to append after all results
  8797. */
  8798. endFormat: function() {
  8799. "use strict";
  8800. return "";
  8801. },
  8802. /**
  8803. * Given CSS Lint results for a file, return output for this format.
  8804. * @param results {Object} with error and warning messages
  8805. * @param filename {String} relative file path
  8806. * @param options {Object} (Optional) specifies special handling of output
  8807. * @return {String} output for results
  8808. */
  8809. formatResults: function(results, filename, options) {
  8810. "use strict";
  8811. var messages = results.messages,
  8812. output = "";
  8813. options = options || {};
  8814. /**
  8815. * Capitalize and return given string.
  8816. * @param str {String} to capitalize
  8817. * @return {String} capitalized
  8818. */
  8819. var capitalize = function(str) {
  8820. return str.charAt(0).toUpperCase() + str.slice(1);
  8821. };
  8822. if (messages.length === 0) {
  8823. return options.quiet ? "" : filename + ": Lint Free!";
  8824. }
  8825. CSSLint.Util.forEach(messages, function(message) {
  8826. if (message.rollup) {
  8827. output += filename + ": " + capitalize(message.type) + " - " + message.message + " (" + message.rule.id + ")\n";
  8828. } else {
  8829. output += filename + ": line " + message.line +
  8830. ", col " + message.col + ", " + capitalize(message.type) + " - " + message.message + " (" + message.rule.id + ")\n";
  8831. }
  8832. });
  8833. return output;
  8834. }
  8835. });
  8836. CSSLint.addFormatter({
  8837. // format information
  8838. id: "csslint-xml",
  8839. name: "CSSLint XML format",
  8840. /**
  8841. * Return opening root XML tag.
  8842. * @return {String} to prepend before all results
  8843. */
  8844. startFormat: function() {
  8845. "use strict";
  8846. return "<?xml version=\"1.0\" encoding=\"utf-8\"?><csslint>";
  8847. },
  8848. /**
  8849. * Return closing root XML tag.
  8850. * @return {String} to append after all results
  8851. */
  8852. endFormat: function() {
  8853. "use strict";
  8854. return "</csslint>";
  8855. },
  8856. /**
  8857. * Given CSS Lint results for a file, return output for this format.
  8858. * @param results {Object} with error and warning messages
  8859. * @param filename {String} relative file path
  8860. * @param options {Object} (UNUSED for now) specifies special handling of output
  8861. * @return {String} output for results
  8862. */
  8863. formatResults: function(results, filename/*, options*/) {
  8864. "use strict";
  8865. var messages = results.messages,
  8866. output = [];
  8867. /**
  8868. * Replace special characters before write to output.
  8869. *
  8870. * Rules:
  8871. * - single quotes is the escape sequence for double-quotes
  8872. * - &amp; is the escape sequence for &
  8873. * - &lt; is the escape sequence for <
  8874. * - &gt; is the escape sequence for >
  8875. *
  8876. * @param {String} message to escape
  8877. * @return escaped message as {String}
  8878. */
  8879. var escapeSpecialCharacters = function(str) {
  8880. if (!str || str.constructor !== String) {
  8881. return "";
  8882. }
  8883. return str.replace(/"/g, "'").replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
  8884. };
  8885. if (messages.length > 0) {
  8886. output.push("<file name=\""+filename+"\">");
  8887. CSSLint.Util.forEach(messages, function (message) {
  8888. if (message.rollup) {
  8889. output.push("<issue severity=\"" + message.type + "\" reason=\"" + escapeSpecialCharacters(message.message) + "\" evidence=\"" + escapeSpecialCharacters(message.evidence) + "\"/>");
  8890. } else {
  8891. output.push("<issue line=\"" + message.line + "\" char=\"" + message.col + "\" severity=\"" + message.type + "\"" +
  8892. " reason=\"" + escapeSpecialCharacters(message.message) + "\" evidence=\"" + escapeSpecialCharacters(message.evidence) + "\"/>");
  8893. }
  8894. });
  8895. output.push("</file>");
  8896. }
  8897. return output.join("");
  8898. }
  8899. });
  8900. /* globals JSON: true */
  8901. CSSLint.addFormatter({
  8902. // format information
  8903. id: "json",
  8904. name: "JSON",
  8905. /**
  8906. * Return content to be printed before all file results.
  8907. * @return {String} to prepend before all results
  8908. */
  8909. startFormat: function() {
  8910. "use strict";
  8911. this.json = [];
  8912. return "";
  8913. },
  8914. /**
  8915. * Return content to be printed after all file results.
  8916. * @return {String} to append after all results
  8917. */
  8918. endFormat: function() {
  8919. "use strict";
  8920. var ret = "";
  8921. if (this.json.length > 0) {
  8922. if (this.json.length === 1) {
  8923. ret = JSON.stringify(this.json[0]);
  8924. } else {
  8925. ret = JSON.stringify(this.json);
  8926. }
  8927. }
  8928. return ret;
  8929. },
  8930. /**
  8931. * Given CSS Lint results for a file, return output for this format.
  8932. * @param results {Object} with error and warning messages
  8933. * @param filename {String} relative file path (Unused)
  8934. * @return {String} output for results
  8935. */
  8936. formatResults: function(results, filename, options) {
  8937. "use strict";
  8938. if (results.messages.length > 0 || !options.quiet) {
  8939. this.json.push({
  8940. filename: filename,
  8941. messages: results.messages,
  8942. stats: results.stats
  8943. });
  8944. }
  8945. return "";
  8946. }
  8947. });
  8948. CSSLint.addFormatter({
  8949. // format information
  8950. id: "junit-xml",
  8951. name: "JUNIT XML format",
  8952. /**
  8953. * Return opening root XML tag.
  8954. * @return {String} to prepend before all results
  8955. */
  8956. startFormat: function() {
  8957. "use strict";
  8958. return "<?xml version=\"1.0\" encoding=\"utf-8\"?><testsuites>";
  8959. },
  8960. /**
  8961. * Return closing root XML tag.
  8962. * @return {String} to append after all results
  8963. */
  8964. endFormat: function() {
  8965. "use strict";
  8966. return "</testsuites>";
  8967. },
  8968. /**
  8969. * Given CSS Lint results for a file, return output for this format.
  8970. * @param results {Object} with error and warning messages
  8971. * @param filename {String} relative file path
  8972. * @param options {Object} (UNUSED for now) specifies special handling of output
  8973. * @return {String} output for results
  8974. */
  8975. formatResults: function(results, filename/*, options*/) {
  8976. "use strict";
  8977. var messages = results.messages,
  8978. output = [],
  8979. tests = {
  8980. "error": 0,
  8981. "failure": 0
  8982. };
  8983. /**
  8984. * Generate a source string for a rule.
  8985. * JUNIT source strings usually resemble Java class names e.g
  8986. * net.csslint.SomeRuleName
  8987. * @param {Object} rule
  8988. * @return rule source as {String}
  8989. */
  8990. var generateSource = function(rule) {
  8991. if (!rule || !("name" in rule)) {
  8992. return "";
  8993. }
  8994. return "net.csslint." + rule.name.replace(/\s/g, "");
  8995. };
  8996. /**
  8997. * Replace special characters before write to output.
  8998. *
  8999. * Rules:
  9000. * - single quotes is the escape sequence for double-quotes
  9001. * - &lt; is the escape sequence for <
  9002. * - &gt; is the escape sequence for >
  9003. *
  9004. * @param {String} message to escape
  9005. * @return escaped message as {String}
  9006. */
  9007. var escapeSpecialCharacters = function(str) {
  9008. if (!str || str.constructor !== String) {
  9009. return "";
  9010. }
  9011. return str.replace(/"/g, "'").replace(/</g, "&lt;").replace(/>/g, "&gt;");
  9012. };
  9013. if (messages.length > 0) {
  9014. messages.forEach(function (message) {
  9015. // since junit has no warning class
  9016. // all issues as errors
  9017. var type = message.type === "warning" ? "error" : message.type;
  9018. // ignore rollups for now
  9019. if (!message.rollup) {
  9020. // build the test case separately, once joined
  9021. // we'll add it to a custom array filtered by type
  9022. output.push("<testcase time=\"0\" name=\"" + generateSource(message.rule) + "\">");
  9023. output.push("<" + type + " message=\"" + escapeSpecialCharacters(message.message) + "\"><![CDATA[" + message.line + ":" + message.col + ":" + escapeSpecialCharacters(message.evidence) + "]]></" + type + ">");
  9024. output.push("</testcase>");
  9025. tests[type] += 1;
  9026. }
  9027. });
  9028. output.unshift("<testsuite time=\"0\" tests=\"" + messages.length + "\" skipped=\"0\" errors=\"" + tests.error + "\" failures=\"" + tests.failure + "\" package=\"net.csslint\" name=\"" + filename + "\">");
  9029. output.push("</testsuite>");
  9030. }
  9031. return output.join("");
  9032. }
  9033. });
  9034. CSSLint.addFormatter({
  9035. // format information
  9036. id: "lint-xml",
  9037. name: "Lint XML format",
  9038. /**
  9039. * Return opening root XML tag.
  9040. * @return {String} to prepend before all results
  9041. */
  9042. startFormat: function() {
  9043. "use strict";
  9044. return "<?xml version=\"1.0\" encoding=\"utf-8\"?><lint>";
  9045. },
  9046. /**
  9047. * Return closing root XML tag.
  9048. * @return {String} to append after all results
  9049. */
  9050. endFormat: function() {
  9051. "use strict";
  9052. return "</lint>";
  9053. },
  9054. /**
  9055. * Given CSS Lint results for a file, return output for this format.
  9056. * @param results {Object} with error and warning messages
  9057. * @param filename {String} relative file path
  9058. * @param options {Object} (UNUSED for now) specifies special handling of output
  9059. * @return {String} output for results
  9060. */
  9061. formatResults: function(results, filename/*, options*/) {
  9062. "use strict";
  9063. var messages = results.messages,
  9064. output = [];
  9065. /**
  9066. * Replace special characters before write to output.
  9067. *
  9068. * Rules:
  9069. * - single quotes is the escape sequence for double-quotes
  9070. * - &amp; is the escape sequence for &
  9071. * - &lt; is the escape sequence for <
  9072. * - &gt; is the escape sequence for >
  9073. *
  9074. * @param {String} message to escape
  9075. * @return escaped message as {String}
  9076. */
  9077. var escapeSpecialCharacters = function(str) {
  9078. if (!str || str.constructor !== String) {
  9079. return "";
  9080. }
  9081. return str.replace(/"/g, "'").replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
  9082. };
  9083. if (messages.length > 0) {
  9084. output.push("<file name=\""+filename+"\">");
  9085. CSSLint.Util.forEach(messages, function (message) {
  9086. if (message.rollup) {
  9087. output.push("<issue severity=\"" + message.type + "\" reason=\"" + escapeSpecialCharacters(message.message) + "\" evidence=\"" + escapeSpecialCharacters(message.evidence) + "\"/>");
  9088. } else {
  9089. var rule = "";
  9090. if (message.rule && message.rule.id) {
  9091. rule = "rule=\"" + escapeSpecialCharacters(message.rule.id) + "\" ";
  9092. }
  9093. output.push("<issue " + rule + "line=\"" + message.line + "\" char=\"" + message.col + "\" severity=\"" + message.type + "\"" +
  9094. " reason=\"" + escapeSpecialCharacters(message.message) + "\" evidence=\"" + escapeSpecialCharacters(message.evidence) + "\"/>");
  9095. }
  9096. });
  9097. output.push("</file>");
  9098. }
  9099. return output.join("");
  9100. }
  9101. });
  9102. CSSLint.addFormatter({
  9103. // format information
  9104. id: "text",
  9105. name: "Plain Text",
  9106. /**
  9107. * Return content to be printed before all file results.
  9108. * @return {String} to prepend before all results
  9109. */
  9110. startFormat: function() {
  9111. "use strict";
  9112. return "";
  9113. },
  9114. /**
  9115. * Return content to be printed after all file results.
  9116. * @return {String} to append after all results
  9117. */
  9118. endFormat: function() {
  9119. "use strict";
  9120. return "";
  9121. },
  9122. /**
  9123. * Given CSS Lint results for a file, return output for this format.
  9124. * @param results {Object} with error and warning messages
  9125. * @param filename {String} relative file path
  9126. * @param options {Object} (Optional) specifies special handling of output
  9127. * @return {String} output for results
  9128. */
  9129. formatResults: function(results, filename, options) {
  9130. "use strict";
  9131. var messages = results.messages,
  9132. output = "";
  9133. options = options || {};
  9134. if (messages.length === 0) {
  9135. return options.quiet ? "" : "\n\ncsslint: No errors in " + filename + ".";
  9136. }
  9137. output = "\n\ncsslint: There ";
  9138. if (messages.length === 1) {
  9139. output += "is 1 problem";
  9140. } else {
  9141. output += "are " + messages.length + " problems";
  9142. }
  9143. output += " in " + filename + ".";
  9144. var pos = filename.lastIndexOf("/"),
  9145. shortFilename = filename;
  9146. if (pos === -1) {
  9147. pos = filename.lastIndexOf("\\");
  9148. }
  9149. if (pos > -1) {
  9150. shortFilename = filename.substring(pos+1);
  9151. }
  9152. CSSLint.Util.forEach(messages, function (message, i) {
  9153. output = output + "\n\n" + shortFilename;
  9154. if (message.rollup) {
  9155. output += "\n" + (i+1) + ": " + message.type;
  9156. output += "\n" + message.message;
  9157. } else {
  9158. output += "\n" + (i+1) + ": " + message.type + " at line " + message.line + ", col " + message.col;
  9159. output += "\n" + message.message;
  9160. output += "\n" + message.evidence;
  9161. }
  9162. });
  9163. return output;
  9164. }
  9165. });
  9166. /*
  9167. * Web worker for CSSLint
  9168. */
  9169. /* global self, JSON */
  9170. // message indicates to start linting
  9171. self.onmessage = function(event) {
  9172. "use strict";
  9173. var data = event.data,
  9174. message,
  9175. text,
  9176. ruleset,
  9177. results;
  9178. try {
  9179. message = JSON.parse(data);
  9180. text = message.text;
  9181. ruleset = message.ruleset;
  9182. } catch (ex) {
  9183. text = data;
  9184. }
  9185. results = CSSLint.verify(text, ruleset);
  9186. // Not all browsers support structured clone, so JSON stringify results
  9187. self.postMessage(JSON.stringify(results));
  9188. };