worker-css.js 269 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087
  1. "no use strict";
  2. !(function(window) {
  3. if (typeof window.window != "undefined" && window.document)
  4. return;
  5. if (window.require && window.define)
  6. return;
  7. if (!window.console) {
  8. window.console = function() {
  9. var msgs = Array.prototype.slice.call(arguments, 0);
  10. postMessage({type: "log", data: msgs});
  11. };
  12. window.console.error =
  13. window.console.warn =
  14. window.console.log =
  15. window.console.trace = window.console;
  16. }
  17. window.window = window;
  18. window.ace = window;
  19. window.onerror = function(message, file, line, col, err) {
  20. postMessage({type: "error", data: {
  21. message: message,
  22. data: err.data,
  23. file: file,
  24. line: line,
  25. col: col,
  26. stack: err.stack
  27. }});
  28. };
  29. window.normalizeModule = function(parentId, moduleName) {
  30. // normalize plugin requires
  31. if (moduleName.indexOf("!") !== -1) {
  32. var chunks = moduleName.split("!");
  33. return window.normalizeModule(parentId, chunks[0]) + "!" + window.normalizeModule(parentId, chunks[1]);
  34. }
  35. // normalize relative requires
  36. if (moduleName.charAt(0) == ".") {
  37. var base = parentId.split("/").slice(0, -1).join("/");
  38. moduleName = (base ? base + "/" : "") + moduleName;
  39. while (moduleName.indexOf(".") !== -1 && previous != moduleName) {
  40. var previous = moduleName;
  41. moduleName = moduleName.replace(/^\.\//, "").replace(/\/\.\//, "/").replace(/[^\/]+\/\.\.\//, "");
  42. }
  43. }
  44. return moduleName;
  45. };
  46. window.require = function require(parentId, id) {
  47. if (!id) {
  48. id = parentId;
  49. parentId = null;
  50. }
  51. if (!id.charAt)
  52. throw new Error("worker.js require() accepts only (parentId, id) as arguments");
  53. id = window.normalizeModule(parentId, id);
  54. var module = window.require.modules[id];
  55. if (module) {
  56. if (!module.initialized) {
  57. module.initialized = true;
  58. module.exports = module.factory().exports;
  59. }
  60. return module.exports;
  61. }
  62. if (!window.require.tlns)
  63. return console.log("unable to load " + id);
  64. var path = resolveModuleId(id, window.require.tlns);
  65. if (path.slice(-3) != ".js") path += ".js";
  66. window.require.id = id;
  67. window.require.modules[id] = {}; // prevent infinite loop on broken modules
  68. importScripts(path);
  69. return window.require(parentId, id);
  70. };
  71. function resolveModuleId(id, paths) {
  72. var testPath = id, tail = "";
  73. while (testPath) {
  74. var alias = paths[testPath];
  75. if (typeof alias == "string") {
  76. return alias + tail;
  77. } else if (alias) {
  78. return alias.location.replace(/\/*$/, "/") + (tail || alias.main || alias.name);
  79. } else if (alias === false) {
  80. return "";
  81. }
  82. var i = testPath.lastIndexOf("/");
  83. if (i === -1) break;
  84. tail = testPath.substr(i) + tail;
  85. testPath = testPath.slice(0, i);
  86. }
  87. return id;
  88. }
  89. window.require.modules = {};
  90. window.require.tlns = {};
  91. window.define = function(id, deps, factory) {
  92. if (arguments.length == 2) {
  93. factory = deps;
  94. if (typeof id != "string") {
  95. deps = id;
  96. id = window.require.id;
  97. }
  98. } else if (arguments.length == 1) {
  99. factory = id;
  100. deps = [];
  101. id = window.require.id;
  102. }
  103. if (typeof factory != "function") {
  104. window.require.modules[id] = {
  105. exports: factory,
  106. initialized: true
  107. };
  108. return;
  109. }
  110. if (!deps.length)
  111. // If there is no dependencies, we inject "require", "exports" and
  112. // "module" as dependencies, to provide CommonJS compatibility.
  113. deps = ["require", "exports", "module"];
  114. var req = function(childId) {
  115. return window.require(id, childId);
  116. };
  117. window.require.modules[id] = {
  118. exports: {},
  119. factory: function() {
  120. var module = this;
  121. var returnExports = factory.apply(this, deps.slice(0, factory.length).map(function(dep) {
  122. switch (dep) {
  123. // Because "require", "exports" and "module" aren't actual
  124. // dependencies, we must handle them seperately.
  125. case "require": return req;
  126. case "exports": return module.exports;
  127. case "module": return module;
  128. // But for all other dependencies, we can just go ahead and
  129. // require them.
  130. default: return req(dep);
  131. }
  132. }));
  133. if (returnExports)
  134. module.exports = returnExports;
  135. return module;
  136. }
  137. };
  138. };
  139. window.define.amd = {};
  140. require.tlns = {};
  141. window.initBaseUrls = function initBaseUrls(topLevelNamespaces) {
  142. for (var i in topLevelNamespaces)
  143. require.tlns[i] = topLevelNamespaces[i];
  144. };
  145. window.initSender = function initSender() {
  146. var EventEmitter = window.require("ace/lib/event_emitter").EventEmitter;
  147. var oop = window.require("ace/lib/oop");
  148. var Sender = function() {};
  149. (function() {
  150. oop.implement(this, EventEmitter);
  151. this.callback = function(data, callbackId) {
  152. postMessage({
  153. type: "call",
  154. id: callbackId,
  155. data: data
  156. });
  157. };
  158. this.emit = function(name, data) {
  159. postMessage({
  160. type: "event",
  161. name: name,
  162. data: data
  163. });
  164. };
  165. }).call(Sender.prototype);
  166. return new Sender();
  167. };
  168. var main = window.main = null;
  169. var sender = window.sender = null;
  170. window.onmessage = function(e) {
  171. var msg = e.data;
  172. if (msg.event && sender) {
  173. sender._signal(msg.event, msg.data);
  174. }
  175. else if (msg.command) {
  176. if (main[msg.command])
  177. main[msg.command].apply(main, msg.args);
  178. else if (window[msg.command])
  179. window[msg.command].apply(window, msg.args);
  180. else
  181. throw new Error("Unknown command:" + msg.command);
  182. }
  183. else if (msg.init) {
  184. window.initBaseUrls(msg.tlns);
  185. sender = window.sender = window.initSender();
  186. var clazz = require(msg.module)[msg.classname];
  187. main = window.main = new clazz(sender);
  188. }
  189. };
  190. })(this);
  191. ace.define("ace/lib/oop",[], function(require, exports, module) {
  192. "use strict";
  193. exports.inherits = function(ctor, superCtor) {
  194. ctor.super_ = superCtor;
  195. ctor.prototype = Object.create(superCtor.prototype, {
  196. constructor: {
  197. value: ctor,
  198. enumerable: false,
  199. writable: true,
  200. configurable: true
  201. }
  202. });
  203. };
  204. exports.mixin = function(obj, mixin) {
  205. for (var key in mixin) {
  206. obj[key] = mixin[key];
  207. }
  208. return obj;
  209. };
  210. exports.implement = function(proto, mixin) {
  211. exports.mixin(proto, mixin);
  212. };
  213. });
  214. ace.define("ace/lib/lang",[], function(require, exports, module) {
  215. "use strict";
  216. exports.last = function(a) {
  217. return a[a.length - 1];
  218. };
  219. exports.stringReverse = function(string) {
  220. return string.split("").reverse().join("");
  221. };
  222. exports.stringRepeat = function (string, count) {
  223. var result = '';
  224. while (count > 0) {
  225. if (count & 1)
  226. result += string;
  227. if (count >>= 1)
  228. string += string;
  229. }
  230. return result;
  231. };
  232. var trimBeginRegexp = /^\s\s*/;
  233. var trimEndRegexp = /\s\s*$/;
  234. exports.stringTrimLeft = function (string) {
  235. return string.replace(trimBeginRegexp, '');
  236. };
  237. exports.stringTrimRight = function (string) {
  238. return string.replace(trimEndRegexp, '');
  239. };
  240. exports.copyObject = function(obj) {
  241. var copy = {};
  242. for (var key in obj) {
  243. copy[key] = obj[key];
  244. }
  245. return copy;
  246. };
  247. exports.copyArray = function(array){
  248. var copy = [];
  249. for (var i=0, l=array.length; i<l; i++) {
  250. if (array[i] && typeof array[i] == "object")
  251. copy[i] = this.copyObject(array[i]);
  252. else
  253. copy[i] = array[i];
  254. }
  255. return copy;
  256. };
  257. exports.deepCopy = function deepCopy(obj) {
  258. if (typeof obj !== "object" || !obj)
  259. return obj;
  260. var copy;
  261. if (Array.isArray(obj)) {
  262. copy = [];
  263. for (var key = 0; key < obj.length; key++) {
  264. copy[key] = deepCopy(obj[key]);
  265. }
  266. return copy;
  267. }
  268. if (Object.prototype.toString.call(obj) !== "[object Object]")
  269. return obj;
  270. copy = {};
  271. for (var key in obj)
  272. copy[key] = deepCopy(obj[key]);
  273. return copy;
  274. };
  275. exports.arrayToMap = function(arr) {
  276. var map = {};
  277. for (var i=0; i<arr.length; i++) {
  278. map[arr[i]] = 1;
  279. }
  280. return map;
  281. };
  282. exports.createMap = function(props) {
  283. var map = Object.create(null);
  284. for (var i in props) {
  285. map[i] = props[i];
  286. }
  287. return map;
  288. };
  289. exports.arrayRemove = function(array, value) {
  290. for (var i = 0; i <= array.length; i++) {
  291. if (value === array[i]) {
  292. array.splice(i, 1);
  293. }
  294. }
  295. };
  296. exports.escapeRegExp = function(str) {
  297. return str.replace(/([.*+?^${}()|[\]\/\\])/g, '\\$1');
  298. };
  299. exports.escapeHTML = function(str) {
  300. return ("" + str).replace(/&/g, "&#38;").replace(/"/g, "&#34;").replace(/'/g, "&#39;").replace(/</g, "&#60;");
  301. };
  302. exports.getMatchOffsets = function(string, regExp) {
  303. var matches = [];
  304. string.replace(regExp, function(str) {
  305. matches.push({
  306. offset: arguments[arguments.length-2],
  307. length: str.length
  308. });
  309. });
  310. return matches;
  311. };
  312. exports.deferredCall = function(fcn) {
  313. var timer = null;
  314. var callback = function() {
  315. timer = null;
  316. fcn();
  317. };
  318. var deferred = function(timeout) {
  319. deferred.cancel();
  320. timer = setTimeout(callback, timeout || 0);
  321. return deferred;
  322. };
  323. deferred.schedule = deferred;
  324. deferred.call = function() {
  325. this.cancel();
  326. fcn();
  327. return deferred;
  328. };
  329. deferred.cancel = function() {
  330. clearTimeout(timer);
  331. timer = null;
  332. return deferred;
  333. };
  334. deferred.isPending = function() {
  335. return timer;
  336. };
  337. return deferred;
  338. };
  339. exports.delayedCall = function(fcn, defaultTimeout) {
  340. var timer = null;
  341. var callback = function() {
  342. timer = null;
  343. fcn();
  344. };
  345. var _self = function(timeout) {
  346. if (timer == null)
  347. timer = setTimeout(callback, timeout || defaultTimeout);
  348. };
  349. _self.delay = function(timeout) {
  350. timer && clearTimeout(timer);
  351. timer = setTimeout(callback, timeout || defaultTimeout);
  352. };
  353. _self.schedule = _self;
  354. _self.call = function() {
  355. this.cancel();
  356. fcn();
  357. };
  358. _self.cancel = function() {
  359. timer && clearTimeout(timer);
  360. timer = null;
  361. };
  362. _self.isPending = function() {
  363. return timer;
  364. };
  365. return _self;
  366. };
  367. });
  368. ace.define("ace/range",[], function(require, exports, module) {
  369. "use strict";
  370. var comparePoints = function(p1, p2) {
  371. return p1.row - p2.row || p1.column - p2.column;
  372. };
  373. var Range = function(startRow, startColumn, endRow, endColumn) {
  374. this.start = {
  375. row: startRow,
  376. column: startColumn
  377. };
  378. this.end = {
  379. row: endRow,
  380. column: endColumn
  381. };
  382. };
  383. (function() {
  384. this.isEqual = function(range) {
  385. return this.start.row === range.start.row &&
  386. this.end.row === range.end.row &&
  387. this.start.column === range.start.column &&
  388. this.end.column === range.end.column;
  389. };
  390. this.toString = function() {
  391. return ("Range: [" + this.start.row + "/" + this.start.column +
  392. "] -> [" + this.end.row + "/" + this.end.column + "]");
  393. };
  394. this.contains = function(row, column) {
  395. return this.compare(row, column) == 0;
  396. };
  397. this.compareRange = function(range) {
  398. var cmp,
  399. end = range.end,
  400. start = range.start;
  401. cmp = this.compare(end.row, end.column);
  402. if (cmp == 1) {
  403. cmp = this.compare(start.row, start.column);
  404. if (cmp == 1) {
  405. return 2;
  406. } else if (cmp == 0) {
  407. return 1;
  408. } else {
  409. return 0;
  410. }
  411. } else if (cmp == -1) {
  412. return -2;
  413. } else {
  414. cmp = this.compare(start.row, start.column);
  415. if (cmp == -1) {
  416. return -1;
  417. } else if (cmp == 1) {
  418. return 42;
  419. } else {
  420. return 0;
  421. }
  422. }
  423. };
  424. this.comparePoint = function(p) {
  425. return this.compare(p.row, p.column);
  426. };
  427. this.containsRange = function(range) {
  428. return this.comparePoint(range.start) == 0 && this.comparePoint(range.end) == 0;
  429. };
  430. this.intersects = function(range) {
  431. var cmp = this.compareRange(range);
  432. return (cmp == -1 || cmp == 0 || cmp == 1);
  433. };
  434. this.isEnd = function(row, column) {
  435. return this.end.row == row && this.end.column == column;
  436. };
  437. this.isStart = function(row, column) {
  438. return this.start.row == row && this.start.column == column;
  439. };
  440. this.setStart = function(row, column) {
  441. if (typeof row == "object") {
  442. this.start.column = row.column;
  443. this.start.row = row.row;
  444. } else {
  445. this.start.row = row;
  446. this.start.column = column;
  447. }
  448. };
  449. this.setEnd = function(row, column) {
  450. if (typeof row == "object") {
  451. this.end.column = row.column;
  452. this.end.row = row.row;
  453. } else {
  454. this.end.row = row;
  455. this.end.column = column;
  456. }
  457. };
  458. this.inside = function(row, column) {
  459. if (this.compare(row, column) == 0) {
  460. if (this.isEnd(row, column) || this.isStart(row, column)) {
  461. return false;
  462. } else {
  463. return true;
  464. }
  465. }
  466. return false;
  467. };
  468. this.insideStart = function(row, column) {
  469. if (this.compare(row, column) == 0) {
  470. if (this.isEnd(row, column)) {
  471. return false;
  472. } else {
  473. return true;
  474. }
  475. }
  476. return false;
  477. };
  478. this.insideEnd = function(row, column) {
  479. if (this.compare(row, column) == 0) {
  480. if (this.isStart(row, column)) {
  481. return false;
  482. } else {
  483. return true;
  484. }
  485. }
  486. return false;
  487. };
  488. this.compare = function(row, column) {
  489. if (!this.isMultiLine()) {
  490. if (row === this.start.row) {
  491. return column < this.start.column ? -1 : (column > this.end.column ? 1 : 0);
  492. }
  493. }
  494. if (row < this.start.row)
  495. return -1;
  496. if (row > this.end.row)
  497. return 1;
  498. if (this.start.row === row)
  499. return column >= this.start.column ? 0 : -1;
  500. if (this.end.row === row)
  501. return column <= this.end.column ? 0 : 1;
  502. return 0;
  503. };
  504. this.compareStart = function(row, column) {
  505. if (this.start.row == row && this.start.column == column) {
  506. return -1;
  507. } else {
  508. return this.compare(row, column);
  509. }
  510. };
  511. this.compareEnd = function(row, column) {
  512. if (this.end.row == row && this.end.column == column) {
  513. return 1;
  514. } else {
  515. return this.compare(row, column);
  516. }
  517. };
  518. this.compareInside = function(row, column) {
  519. if (this.end.row == row && this.end.column == column) {
  520. return 1;
  521. } else if (this.start.row == row && this.start.column == column) {
  522. return -1;
  523. } else {
  524. return this.compare(row, column);
  525. }
  526. };
  527. this.clipRows = function(firstRow, lastRow) {
  528. if (this.end.row > lastRow)
  529. var end = {row: lastRow + 1, column: 0};
  530. else if (this.end.row < firstRow)
  531. var end = {row: firstRow, column: 0};
  532. if (this.start.row > lastRow)
  533. var start = {row: lastRow + 1, column: 0};
  534. else if (this.start.row < firstRow)
  535. var start = {row: firstRow, column: 0};
  536. return Range.fromPoints(start || this.start, end || this.end);
  537. };
  538. this.extend = function(row, column) {
  539. var cmp = this.compare(row, column);
  540. if (cmp == 0)
  541. return this;
  542. else if (cmp == -1)
  543. var start = {row: row, column: column};
  544. else
  545. var end = {row: row, column: column};
  546. return Range.fromPoints(start || this.start, end || this.end);
  547. };
  548. this.isEmpty = function() {
  549. return (this.start.row === this.end.row && this.start.column === this.end.column);
  550. };
  551. this.isMultiLine = function() {
  552. return (this.start.row !== this.end.row);
  553. };
  554. this.clone = function() {
  555. return Range.fromPoints(this.start, this.end);
  556. };
  557. this.collapseRows = function() {
  558. if (this.end.column == 0)
  559. return new Range(this.start.row, 0, Math.max(this.start.row, this.end.row-1), 0);
  560. else
  561. return new Range(this.start.row, 0, this.end.row, 0);
  562. };
  563. this.toScreenRange = function(session) {
  564. var screenPosStart = session.documentToScreenPosition(this.start);
  565. var screenPosEnd = session.documentToScreenPosition(this.end);
  566. return new Range(
  567. screenPosStart.row, screenPosStart.column,
  568. screenPosEnd.row, screenPosEnd.column
  569. );
  570. };
  571. this.moveBy = function(row, column) {
  572. this.start.row += row;
  573. this.start.column += column;
  574. this.end.row += row;
  575. this.end.column += column;
  576. };
  577. }).call(Range.prototype);
  578. Range.fromPoints = function(start, end) {
  579. return new Range(start.row, start.column, end.row, end.column);
  580. };
  581. Range.comparePoints = comparePoints;
  582. Range.comparePoints = function(p1, p2) {
  583. return p1.row - p2.row || p1.column - p2.column;
  584. };
  585. exports.Range = Range;
  586. });
  587. ace.define("ace/apply_delta",[], function(require, exports, module) {
  588. "use strict";
  589. function throwDeltaError(delta, errorText){
  590. console.log("Invalid Delta:", delta);
  591. throw "Invalid Delta: " + errorText;
  592. }
  593. function positionInDocument(docLines, position) {
  594. return position.row >= 0 && position.row < docLines.length &&
  595. position.column >= 0 && position.column <= docLines[position.row].length;
  596. }
  597. function validateDelta(docLines, delta) {
  598. if (delta.action != "insert" && delta.action != "remove")
  599. throwDeltaError(delta, "delta.action must be 'insert' or 'remove'");
  600. if (!(delta.lines instanceof Array))
  601. throwDeltaError(delta, "delta.lines must be an Array");
  602. if (!delta.start || !delta.end)
  603. throwDeltaError(delta, "delta.start/end must be an present");
  604. var start = delta.start;
  605. if (!positionInDocument(docLines, delta.start))
  606. throwDeltaError(delta, "delta.start must be contained in document");
  607. var end = delta.end;
  608. if (delta.action == "remove" && !positionInDocument(docLines, end))
  609. throwDeltaError(delta, "delta.end must contained in document for 'remove' actions");
  610. var numRangeRows = end.row - start.row;
  611. var numRangeLastLineChars = (end.column - (numRangeRows == 0 ? start.column : 0));
  612. if (numRangeRows != delta.lines.length - 1 || delta.lines[numRangeRows].length != numRangeLastLineChars)
  613. throwDeltaError(delta, "delta.range must match delta lines");
  614. }
  615. exports.applyDelta = function(docLines, delta, doNotValidate) {
  616. var row = delta.start.row;
  617. var startColumn = delta.start.column;
  618. var line = docLines[row] || "";
  619. switch (delta.action) {
  620. case "insert":
  621. var lines = delta.lines;
  622. if (lines.length === 1) {
  623. docLines[row] = line.substring(0, startColumn) + delta.lines[0] + line.substring(startColumn);
  624. } else {
  625. var args = [row, 1].concat(delta.lines);
  626. docLines.splice.apply(docLines, args);
  627. docLines[row] = line.substring(0, startColumn) + docLines[row];
  628. docLines[row + delta.lines.length - 1] += line.substring(startColumn);
  629. }
  630. break;
  631. case "remove":
  632. var endColumn = delta.end.column;
  633. var endRow = delta.end.row;
  634. if (row === endRow) {
  635. docLines[row] = line.substring(0, startColumn) + line.substring(endColumn);
  636. } else {
  637. docLines.splice(
  638. row, endRow - row + 1,
  639. line.substring(0, startColumn) + docLines[endRow].substring(endColumn)
  640. );
  641. }
  642. break;
  643. }
  644. };
  645. });
  646. ace.define("ace/lib/event_emitter",[], function(require, exports, module) {
  647. "use strict";
  648. var EventEmitter = {};
  649. var stopPropagation = function() { this.propagationStopped = true; };
  650. var preventDefault = function() { this.defaultPrevented = true; };
  651. EventEmitter._emit =
  652. EventEmitter._dispatchEvent = function(eventName, e) {
  653. this._eventRegistry || (this._eventRegistry = {});
  654. this._defaultHandlers || (this._defaultHandlers = {});
  655. var listeners = this._eventRegistry[eventName] || [];
  656. var defaultHandler = this._defaultHandlers[eventName];
  657. if (!listeners.length && !defaultHandler)
  658. return;
  659. if (typeof e != "object" || !e)
  660. e = {};
  661. if (!e.type)
  662. e.type = eventName;
  663. if (!e.stopPropagation)
  664. e.stopPropagation = stopPropagation;
  665. if (!e.preventDefault)
  666. e.preventDefault = preventDefault;
  667. listeners = listeners.slice();
  668. for (var i=0; i<listeners.length; i++) {
  669. listeners[i](e, this);
  670. if (e.propagationStopped)
  671. break;
  672. }
  673. if (defaultHandler && !e.defaultPrevented)
  674. return defaultHandler(e, this);
  675. };
  676. EventEmitter._signal = function(eventName, e) {
  677. var listeners = (this._eventRegistry || {})[eventName];
  678. if (!listeners)
  679. return;
  680. listeners = listeners.slice();
  681. for (var i=0; i<listeners.length; i++)
  682. listeners[i](e, this);
  683. };
  684. EventEmitter.once = function(eventName, callback) {
  685. var _self = this;
  686. this.on(eventName, function newCallback() {
  687. _self.off(eventName, newCallback);
  688. callback.apply(null, arguments);
  689. });
  690. if (!callback) {
  691. return new Promise(function(resolve) {
  692. callback = resolve;
  693. });
  694. }
  695. };
  696. EventEmitter.setDefaultHandler = function(eventName, callback) {
  697. var handlers = this._defaultHandlers;
  698. if (!handlers)
  699. handlers = this._defaultHandlers = {_disabled_: {}};
  700. if (handlers[eventName]) {
  701. var old = handlers[eventName];
  702. var disabled = handlers._disabled_[eventName];
  703. if (!disabled)
  704. handlers._disabled_[eventName] = disabled = [];
  705. disabled.push(old);
  706. var i = disabled.indexOf(callback);
  707. if (i != -1)
  708. disabled.splice(i, 1);
  709. }
  710. handlers[eventName] = callback;
  711. };
  712. EventEmitter.removeDefaultHandler = function(eventName, callback) {
  713. var handlers = this._defaultHandlers;
  714. if (!handlers)
  715. return;
  716. var disabled = handlers._disabled_[eventName];
  717. if (handlers[eventName] == callback) {
  718. if (disabled)
  719. this.setDefaultHandler(eventName, disabled.pop());
  720. } else if (disabled) {
  721. var i = disabled.indexOf(callback);
  722. if (i != -1)
  723. disabled.splice(i, 1);
  724. }
  725. };
  726. EventEmitter.on =
  727. EventEmitter.addEventListener = function(eventName, callback, capturing) {
  728. this._eventRegistry = this._eventRegistry || {};
  729. var listeners = this._eventRegistry[eventName];
  730. if (!listeners)
  731. listeners = this._eventRegistry[eventName] = [];
  732. if (listeners.indexOf(callback) == -1)
  733. listeners[capturing ? "unshift" : "push"](callback);
  734. return callback;
  735. };
  736. EventEmitter.off =
  737. EventEmitter.removeListener =
  738. EventEmitter.removeEventListener = function(eventName, callback) {
  739. this._eventRegistry = this._eventRegistry || {};
  740. var listeners = this._eventRegistry[eventName];
  741. if (!listeners)
  742. return;
  743. var index = listeners.indexOf(callback);
  744. if (index !== -1)
  745. listeners.splice(index, 1);
  746. };
  747. EventEmitter.removeAllListeners = function(eventName) {
  748. if (!eventName) this._eventRegistry = this._defaultHandlers = undefined;
  749. if (this._eventRegistry) this._eventRegistry[eventName] = undefined;
  750. if (this._defaultHandlers) this._defaultHandlers[eventName] = undefined;
  751. };
  752. exports.EventEmitter = EventEmitter;
  753. });
  754. ace.define("ace/anchor",[], function(require, exports, module) {
  755. "use strict";
  756. var oop = require("./lib/oop");
  757. var EventEmitter = require("./lib/event_emitter").EventEmitter;
  758. var Anchor = exports.Anchor = function(doc, row, column) {
  759. this.$onChange = this.onChange.bind(this);
  760. this.attach(doc);
  761. if (typeof column == "undefined")
  762. this.setPosition(row.row, row.column);
  763. else
  764. this.setPosition(row, column);
  765. };
  766. (function() {
  767. oop.implement(this, EventEmitter);
  768. this.getPosition = function() {
  769. return this.$clipPositionToDocument(this.row, this.column);
  770. };
  771. this.getDocument = function() {
  772. return this.document;
  773. };
  774. this.$insertRight = false;
  775. this.onChange = function(delta) {
  776. if (delta.start.row == delta.end.row && delta.start.row != this.row)
  777. return;
  778. if (delta.start.row > this.row)
  779. return;
  780. var point = $getTransformedPoint(delta, {row: this.row, column: this.column}, this.$insertRight);
  781. this.setPosition(point.row, point.column, true);
  782. };
  783. function $pointsInOrder(point1, point2, equalPointsInOrder) {
  784. var bColIsAfter = equalPointsInOrder ? point1.column <= point2.column : point1.column < point2.column;
  785. return (point1.row < point2.row) || (point1.row == point2.row && bColIsAfter);
  786. }
  787. function $getTransformedPoint(delta, point, moveIfEqual) {
  788. var deltaIsInsert = delta.action == "insert";
  789. var deltaRowShift = (deltaIsInsert ? 1 : -1) * (delta.end.row - delta.start.row);
  790. var deltaColShift = (deltaIsInsert ? 1 : -1) * (delta.end.column - delta.start.column);
  791. var deltaStart = delta.start;
  792. var deltaEnd = deltaIsInsert ? deltaStart : delta.end; // Collapse insert range.
  793. if ($pointsInOrder(point, deltaStart, moveIfEqual)) {
  794. return {
  795. row: point.row,
  796. column: point.column
  797. };
  798. }
  799. if ($pointsInOrder(deltaEnd, point, !moveIfEqual)) {
  800. return {
  801. row: point.row + deltaRowShift,
  802. column: point.column + (point.row == deltaEnd.row ? deltaColShift : 0)
  803. };
  804. }
  805. return {
  806. row: deltaStart.row,
  807. column: deltaStart.column
  808. };
  809. }
  810. this.setPosition = function(row, column, noClip) {
  811. var pos;
  812. if (noClip) {
  813. pos = {
  814. row: row,
  815. column: column
  816. };
  817. } else {
  818. pos = this.$clipPositionToDocument(row, column);
  819. }
  820. if (this.row == pos.row && this.column == pos.column)
  821. return;
  822. var old = {
  823. row: this.row,
  824. column: this.column
  825. };
  826. this.row = pos.row;
  827. this.column = pos.column;
  828. this._signal("change", {
  829. old: old,
  830. value: pos
  831. });
  832. };
  833. this.detach = function() {
  834. this.document.off("change", this.$onChange);
  835. };
  836. this.attach = function(doc) {
  837. this.document = doc || this.document;
  838. this.document.on("change", this.$onChange);
  839. };
  840. this.$clipPositionToDocument = function(row, column) {
  841. var pos = {};
  842. if (row >= this.document.getLength()) {
  843. pos.row = Math.max(0, this.document.getLength() - 1);
  844. pos.column = this.document.getLine(pos.row).length;
  845. }
  846. else if (row < 0) {
  847. pos.row = 0;
  848. pos.column = 0;
  849. }
  850. else {
  851. pos.row = row;
  852. pos.column = Math.min(this.document.getLine(pos.row).length, Math.max(0, column));
  853. }
  854. if (column < 0)
  855. pos.column = 0;
  856. return pos;
  857. };
  858. }).call(Anchor.prototype);
  859. });
  860. ace.define("ace/document",[], function(require, exports, module) {
  861. "use strict";
  862. var oop = require("./lib/oop");
  863. var applyDelta = require("./apply_delta").applyDelta;
  864. var EventEmitter = require("./lib/event_emitter").EventEmitter;
  865. var Range = require("./range").Range;
  866. var Anchor = require("./anchor").Anchor;
  867. var Document = function(textOrLines) {
  868. this.$lines = [""];
  869. if (textOrLines.length === 0) {
  870. this.$lines = [""];
  871. } else if (Array.isArray(textOrLines)) {
  872. this.insertMergedLines({row: 0, column: 0}, textOrLines);
  873. } else {
  874. this.insert({row: 0, column:0}, textOrLines);
  875. }
  876. };
  877. (function() {
  878. oop.implement(this, EventEmitter);
  879. this.setValue = function(text) {
  880. var len = this.getLength() - 1;
  881. this.remove(new Range(0, 0, len, this.getLine(len).length));
  882. this.insert({row: 0, column: 0}, text);
  883. };
  884. this.getValue = function() {
  885. return this.getAllLines().join(this.getNewLineCharacter());
  886. };
  887. this.createAnchor = function(row, column) {
  888. return new Anchor(this, row, column);
  889. };
  890. if ("aaa".split(/a/).length === 0) {
  891. this.$split = function(text) {
  892. return text.replace(/\r\n|\r/g, "\n").split("\n");
  893. };
  894. } else {
  895. this.$split = function(text) {
  896. return text.split(/\r\n|\r|\n/);
  897. };
  898. }
  899. this.$detectNewLine = function(text) {
  900. var match = text.match(/^.*?(\r\n|\r|\n)/m);
  901. this.$autoNewLine = match ? match[1] : "\n";
  902. this._signal("changeNewLineMode");
  903. };
  904. this.getNewLineCharacter = function() {
  905. switch (this.$newLineMode) {
  906. case "windows":
  907. return "\r\n";
  908. case "unix":
  909. return "\n";
  910. default:
  911. return this.$autoNewLine || "\n";
  912. }
  913. };
  914. this.$autoNewLine = "";
  915. this.$newLineMode = "auto";
  916. this.setNewLineMode = function(newLineMode) {
  917. if (this.$newLineMode === newLineMode)
  918. return;
  919. this.$newLineMode = newLineMode;
  920. this._signal("changeNewLineMode");
  921. };
  922. this.getNewLineMode = function() {
  923. return this.$newLineMode;
  924. };
  925. this.isNewLine = function(text) {
  926. return (text == "\r\n" || text == "\r" || text == "\n");
  927. };
  928. this.getLine = function(row) {
  929. return this.$lines[row] || "";
  930. };
  931. this.getLines = function(firstRow, lastRow) {
  932. return this.$lines.slice(firstRow, lastRow + 1);
  933. };
  934. this.getAllLines = function() {
  935. return this.getLines(0, this.getLength());
  936. };
  937. this.getLength = function() {
  938. return this.$lines.length;
  939. };
  940. this.getTextRange = function(range) {
  941. return this.getLinesForRange(range).join(this.getNewLineCharacter());
  942. };
  943. this.getLinesForRange = function(range) {
  944. var lines;
  945. if (range.start.row === range.end.row) {
  946. lines = [this.getLine(range.start.row).substring(range.start.column, range.end.column)];
  947. } else {
  948. lines = this.getLines(range.start.row, range.end.row);
  949. lines[0] = (lines[0] || "").substring(range.start.column);
  950. var l = lines.length - 1;
  951. if (range.end.row - range.start.row == l)
  952. lines[l] = lines[l].substring(0, range.end.column);
  953. }
  954. return lines;
  955. };
  956. this.insertLines = function(row, lines) {
  957. console.warn("Use of document.insertLines is deprecated. Use the insertFullLines method instead.");
  958. return this.insertFullLines(row, lines);
  959. };
  960. this.removeLines = function(firstRow, lastRow) {
  961. console.warn("Use of document.removeLines is deprecated. Use the removeFullLines method instead.");
  962. return this.removeFullLines(firstRow, lastRow);
  963. };
  964. this.insertNewLine = function(position) {
  965. console.warn("Use of document.insertNewLine is deprecated. Use insertMergedLines(position, ['', '']) instead.");
  966. return this.insertMergedLines(position, ["", ""]);
  967. };
  968. this.insert = function(position, text) {
  969. if (this.getLength() <= 1)
  970. this.$detectNewLine(text);
  971. return this.insertMergedLines(position, this.$split(text));
  972. };
  973. this.insertInLine = function(position, text) {
  974. var start = this.clippedPos(position.row, position.column);
  975. var end = this.pos(position.row, position.column + text.length);
  976. this.applyDelta({
  977. start: start,
  978. end: end,
  979. action: "insert",
  980. lines: [text]
  981. }, true);
  982. return this.clonePos(end);
  983. };
  984. this.clippedPos = function(row, column) {
  985. var length = this.getLength();
  986. if (row === undefined) {
  987. row = length;
  988. } else if (row < 0) {
  989. row = 0;
  990. } else if (row >= length) {
  991. row = length - 1;
  992. column = undefined;
  993. }
  994. var line = this.getLine(row);
  995. if (column == undefined)
  996. column = line.length;
  997. column = Math.min(Math.max(column, 0), line.length);
  998. return {row: row, column: column};
  999. };
  1000. this.clonePos = function(pos) {
  1001. return {row: pos.row, column: pos.column};
  1002. };
  1003. this.pos = function(row, column) {
  1004. return {row: row, column: column};
  1005. };
  1006. this.$clipPosition = function(position) {
  1007. var length = this.getLength();
  1008. if (position.row >= length) {
  1009. position.row = Math.max(0, length - 1);
  1010. position.column = this.getLine(length - 1).length;
  1011. } else {
  1012. position.row = Math.max(0, position.row);
  1013. position.column = Math.min(Math.max(position.column, 0), this.getLine(position.row).length);
  1014. }
  1015. return position;
  1016. };
  1017. this.insertFullLines = function(row, lines) {
  1018. row = Math.min(Math.max(row, 0), this.getLength());
  1019. var column = 0;
  1020. if (row < this.getLength()) {
  1021. lines = lines.concat([""]);
  1022. column = 0;
  1023. } else {
  1024. lines = [""].concat(lines);
  1025. row--;
  1026. column = this.$lines[row].length;
  1027. }
  1028. this.insertMergedLines({row: row, column: column}, lines);
  1029. };
  1030. this.insertMergedLines = function(position, lines) {
  1031. var start = this.clippedPos(position.row, position.column);
  1032. var end = {
  1033. row: start.row + lines.length - 1,
  1034. column: (lines.length == 1 ? start.column : 0) + lines[lines.length - 1].length
  1035. };
  1036. this.applyDelta({
  1037. start: start,
  1038. end: end,
  1039. action: "insert",
  1040. lines: lines
  1041. });
  1042. return this.clonePos(end);
  1043. };
  1044. this.remove = function(range) {
  1045. var start = this.clippedPos(range.start.row, range.start.column);
  1046. var end = this.clippedPos(range.end.row, range.end.column);
  1047. this.applyDelta({
  1048. start: start,
  1049. end: end,
  1050. action: "remove",
  1051. lines: this.getLinesForRange({start: start, end: end})
  1052. });
  1053. return this.clonePos(start);
  1054. };
  1055. this.removeInLine = function(row, startColumn, endColumn) {
  1056. var start = this.clippedPos(row, startColumn);
  1057. var end = this.clippedPos(row, endColumn);
  1058. this.applyDelta({
  1059. start: start,
  1060. end: end,
  1061. action: "remove",
  1062. lines: this.getLinesForRange({start: start, end: end})
  1063. }, true);
  1064. return this.clonePos(start);
  1065. };
  1066. this.removeFullLines = function(firstRow, lastRow) {
  1067. firstRow = Math.min(Math.max(0, firstRow), this.getLength() - 1);
  1068. lastRow = Math.min(Math.max(0, lastRow ), this.getLength() - 1);
  1069. var deleteFirstNewLine = lastRow == this.getLength() - 1 && firstRow > 0;
  1070. var deleteLastNewLine = lastRow < this.getLength() - 1;
  1071. var startRow = ( deleteFirstNewLine ? firstRow - 1 : firstRow );
  1072. var startCol = ( deleteFirstNewLine ? this.getLine(startRow).length : 0 );
  1073. var endRow = ( deleteLastNewLine ? lastRow + 1 : lastRow );
  1074. var endCol = ( deleteLastNewLine ? 0 : this.getLine(endRow).length );
  1075. var range = new Range(startRow, startCol, endRow, endCol);
  1076. var deletedLines = this.$lines.slice(firstRow, lastRow + 1);
  1077. this.applyDelta({
  1078. start: range.start,
  1079. end: range.end,
  1080. action: "remove",
  1081. lines: this.getLinesForRange(range)
  1082. });
  1083. return deletedLines;
  1084. };
  1085. this.removeNewLine = function(row) {
  1086. if (row < this.getLength() - 1 && row >= 0) {
  1087. this.applyDelta({
  1088. start: this.pos(row, this.getLine(row).length),
  1089. end: this.pos(row + 1, 0),
  1090. action: "remove",
  1091. lines: ["", ""]
  1092. });
  1093. }
  1094. };
  1095. this.replace = function(range, text) {
  1096. if (!(range instanceof Range))
  1097. range = Range.fromPoints(range.start, range.end);
  1098. if (text.length === 0 && range.isEmpty())
  1099. return range.start;
  1100. if (text == this.getTextRange(range))
  1101. return range.end;
  1102. this.remove(range);
  1103. var end;
  1104. if (text) {
  1105. end = this.insert(range.start, text);
  1106. }
  1107. else {
  1108. end = range.start;
  1109. }
  1110. return end;
  1111. };
  1112. this.applyDeltas = function(deltas) {
  1113. for (var i=0; i<deltas.length; i++) {
  1114. this.applyDelta(deltas[i]);
  1115. }
  1116. };
  1117. this.revertDeltas = function(deltas) {
  1118. for (var i=deltas.length-1; i>=0; i--) {
  1119. this.revertDelta(deltas[i]);
  1120. }
  1121. };
  1122. this.applyDelta = function(delta, doNotValidate) {
  1123. var isInsert = delta.action == "insert";
  1124. if (isInsert ? delta.lines.length <= 1 && !delta.lines[0]
  1125. : !Range.comparePoints(delta.start, delta.end)) {
  1126. return;
  1127. }
  1128. if (isInsert && delta.lines.length > 20000) {
  1129. this.$splitAndapplyLargeDelta(delta, 20000);
  1130. }
  1131. else {
  1132. applyDelta(this.$lines, delta, doNotValidate);
  1133. this._signal("change", delta);
  1134. }
  1135. };
  1136. this.$safeApplyDelta = function(delta) {
  1137. var docLength = this.$lines.length;
  1138. if (
  1139. delta.action == "remove" && delta.start.row < docLength && delta.end.row < docLength
  1140. || delta.action == "insert" && delta.start.row <= docLength
  1141. ) {
  1142. this.applyDelta(delta);
  1143. }
  1144. };
  1145. this.$splitAndapplyLargeDelta = function(delta, MAX) {
  1146. var lines = delta.lines;
  1147. var l = lines.length - MAX + 1;
  1148. var row = delta.start.row;
  1149. var column = delta.start.column;
  1150. for (var from = 0, to = 0; from < l; from = to) {
  1151. to += MAX - 1;
  1152. var chunk = lines.slice(from, to);
  1153. chunk.push("");
  1154. this.applyDelta({
  1155. start: this.pos(row + from, column),
  1156. end: this.pos(row + to, column = 0),
  1157. action: delta.action,
  1158. lines: chunk
  1159. }, true);
  1160. }
  1161. delta.lines = lines.slice(from);
  1162. delta.start.row = row + from;
  1163. delta.start.column = column;
  1164. this.applyDelta(delta, true);
  1165. };
  1166. this.revertDelta = function(delta) {
  1167. this.$safeApplyDelta({
  1168. start: this.clonePos(delta.start),
  1169. end: this.clonePos(delta.end),
  1170. action: (delta.action == "insert" ? "remove" : "insert"),
  1171. lines: delta.lines.slice()
  1172. });
  1173. };
  1174. this.indexToPosition = function(index, startRow) {
  1175. var lines = this.$lines || this.getAllLines();
  1176. var newlineLength = this.getNewLineCharacter().length;
  1177. for (var i = startRow || 0, l = lines.length; i < l; i++) {
  1178. index -= lines[i].length + newlineLength;
  1179. if (index < 0)
  1180. return {row: i, column: index + lines[i].length + newlineLength};
  1181. }
  1182. return {row: l-1, column: index + lines[l-1].length + newlineLength};
  1183. };
  1184. this.positionToIndex = function(pos, startRow) {
  1185. var lines = this.$lines || this.getAllLines();
  1186. var newlineLength = this.getNewLineCharacter().length;
  1187. var index = 0;
  1188. var row = Math.min(pos.row, lines.length);
  1189. for (var i = startRow || 0; i < row; ++i)
  1190. index += lines[i].length + newlineLength;
  1191. return index + pos.column;
  1192. };
  1193. }).call(Document.prototype);
  1194. exports.Document = Document;
  1195. });
  1196. ace.define("ace/worker/mirror",[], function(require, exports, module) {
  1197. "use strict";
  1198. var Range = require("../range").Range;
  1199. var Document = require("../document").Document;
  1200. var lang = require("../lib/lang");
  1201. var Mirror = exports.Mirror = function(sender) {
  1202. this.sender = sender;
  1203. var doc = this.doc = new Document("");
  1204. var deferredUpdate = this.deferredUpdate = lang.delayedCall(this.onUpdate.bind(this));
  1205. var _self = this;
  1206. sender.on("change", function(e) {
  1207. var data = e.data;
  1208. if (data[0].start) {
  1209. doc.applyDeltas(data);
  1210. } else {
  1211. for (var i = 0; i < data.length; i += 2) {
  1212. if (Array.isArray(data[i+1])) {
  1213. var d = {action: "insert", start: data[i], lines: data[i+1]};
  1214. } else {
  1215. var d = {action: "remove", start: data[i], end: data[i+1]};
  1216. }
  1217. doc.applyDelta(d, true);
  1218. }
  1219. }
  1220. if (_self.$timeout)
  1221. return deferredUpdate.schedule(_self.$timeout);
  1222. _self.onUpdate();
  1223. });
  1224. };
  1225. (function() {
  1226. this.$timeout = 500;
  1227. this.setTimeout = function(timeout) {
  1228. this.$timeout = timeout;
  1229. };
  1230. this.setValue = function(value) {
  1231. this.doc.setValue(value);
  1232. this.deferredUpdate.schedule(this.$timeout);
  1233. };
  1234. this.getValue = function(callbackId) {
  1235. this.sender.callback(this.doc.getValue(), callbackId);
  1236. };
  1237. this.onUpdate = function() {
  1238. };
  1239. this.isPending = function() {
  1240. return this.deferredUpdate.isPending();
  1241. };
  1242. }).call(Mirror.prototype);
  1243. });
  1244. ace.define("ace/mode/css/csslint",[], function(require, exports, module) {
  1245. var parserlib = {};
  1246. (function(){
  1247. function EventTarget(){
  1248. this._listeners = {};
  1249. }
  1250. EventTarget.prototype = {
  1251. constructor: EventTarget,
  1252. addListener: function(type, listener){
  1253. if (!this._listeners[type]){
  1254. this._listeners[type] = [];
  1255. }
  1256. this._listeners[type].push(listener);
  1257. },
  1258. fire: function(event){
  1259. if (typeof event == "string"){
  1260. event = { type: event };
  1261. }
  1262. if (typeof event.target != "undefined"){
  1263. event.target = this;
  1264. }
  1265. if (typeof event.type == "undefined"){
  1266. throw new Error("Event object missing 'type' property.");
  1267. }
  1268. if (this._listeners[event.type]){
  1269. var listeners = this._listeners[event.type].concat();
  1270. for (var i=0, len=listeners.length; i < len; i++){
  1271. listeners[i].call(this, event);
  1272. }
  1273. }
  1274. },
  1275. removeListener: function(type, listener){
  1276. if (this._listeners[type]){
  1277. var listeners = this._listeners[type];
  1278. for (var i=0, len=listeners.length; i < len; i++){
  1279. if (listeners[i] === listener){
  1280. listeners.splice(i, 1);
  1281. break;
  1282. }
  1283. }
  1284. }
  1285. }
  1286. };
  1287. function StringReader(text){
  1288. this._input = text.replace(/\n\r?/g, "\n");
  1289. this._line = 1;
  1290. this._col = 1;
  1291. this._cursor = 0;
  1292. }
  1293. StringReader.prototype = {
  1294. constructor: StringReader,
  1295. getCol: function(){
  1296. return this._col;
  1297. },
  1298. getLine: function(){
  1299. return this._line ;
  1300. },
  1301. eof: function(){
  1302. return (this._cursor == this._input.length);
  1303. },
  1304. peek: function(count){
  1305. var c = null;
  1306. count = (typeof count == "undefined" ? 1 : count);
  1307. if (this._cursor < this._input.length){
  1308. c = this._input.charAt(this._cursor + count - 1);
  1309. }
  1310. return c;
  1311. },
  1312. read: function(){
  1313. var c = null;
  1314. if (this._cursor < this._input.length){
  1315. if (this._input.charAt(this._cursor) == "\n"){
  1316. this._line++;
  1317. this._col=1;
  1318. } else {
  1319. this._col++;
  1320. }
  1321. c = this._input.charAt(this._cursor++);
  1322. }
  1323. return c;
  1324. },
  1325. mark: function(){
  1326. this._bookmark = {
  1327. cursor: this._cursor,
  1328. line: this._line,
  1329. col: this._col
  1330. };
  1331. },
  1332. reset: function(){
  1333. if (this._bookmark){
  1334. this._cursor = this._bookmark.cursor;
  1335. this._line = this._bookmark.line;
  1336. this._col = this._bookmark.col;
  1337. delete this._bookmark;
  1338. }
  1339. },
  1340. readTo: function(pattern){
  1341. var buffer = "",
  1342. c;
  1343. while (buffer.length < pattern.length || buffer.lastIndexOf(pattern) != buffer.length - pattern.length){
  1344. c = this.read();
  1345. if (c){
  1346. buffer += c;
  1347. } else {
  1348. throw new Error("Expected \"" + pattern + "\" at line " + this._line + ", col " + this._col + ".");
  1349. }
  1350. }
  1351. return buffer;
  1352. },
  1353. readWhile: function(filter){
  1354. var buffer = "",
  1355. c = this.read();
  1356. while(c !== null && filter(c)){
  1357. buffer += c;
  1358. c = this.read();
  1359. }
  1360. return buffer;
  1361. },
  1362. readMatch: function(matcher){
  1363. var source = this._input.substring(this._cursor),
  1364. value = null;
  1365. if (typeof matcher == "string"){
  1366. if (source.indexOf(matcher) === 0){
  1367. value = this.readCount(matcher.length);
  1368. }
  1369. } else if (matcher instanceof RegExp){
  1370. if (matcher.test(source)){
  1371. value = this.readCount(RegExp.lastMatch.length);
  1372. }
  1373. }
  1374. return value;
  1375. },
  1376. readCount: function(count){
  1377. var buffer = "";
  1378. while(count--){
  1379. buffer += this.read();
  1380. }
  1381. return buffer;
  1382. }
  1383. };
  1384. function SyntaxError(message, line, col){
  1385. this.col = col;
  1386. this.line = line;
  1387. this.message = message;
  1388. }
  1389. SyntaxError.prototype = new Error();
  1390. function SyntaxUnit(text, line, col, type){
  1391. this.col = col;
  1392. this.line = line;
  1393. this.text = text;
  1394. this.type = type;
  1395. }
  1396. SyntaxUnit.fromToken = function(token){
  1397. return new SyntaxUnit(token.value, token.startLine, token.startCol);
  1398. };
  1399. SyntaxUnit.prototype = {
  1400. constructor: SyntaxUnit,
  1401. valueOf: function(){
  1402. return this.text;
  1403. },
  1404. toString: function(){
  1405. return this.text;
  1406. }
  1407. };
  1408. function TokenStreamBase(input, tokenData){
  1409. this._reader = input ? new StringReader(input.toString()) : null;
  1410. this._token = null;
  1411. this._tokenData = tokenData;
  1412. this._lt = [];
  1413. this._ltIndex = 0;
  1414. this._ltIndexCache = [];
  1415. }
  1416. TokenStreamBase.createTokenData = function(tokens){
  1417. var nameMap = [],
  1418. typeMap = {},
  1419. tokenData = tokens.concat([]),
  1420. i = 0,
  1421. len = tokenData.length+1;
  1422. tokenData.UNKNOWN = -1;
  1423. tokenData.unshift({name:"EOF"});
  1424. for (; i < len; i++){
  1425. nameMap.push(tokenData[i].name);
  1426. tokenData[tokenData[i].name] = i;
  1427. if (tokenData[i].text){
  1428. typeMap[tokenData[i].text] = i;
  1429. }
  1430. }
  1431. tokenData.name = function(tt){
  1432. return nameMap[tt];
  1433. };
  1434. tokenData.type = function(c){
  1435. return typeMap[c];
  1436. };
  1437. return tokenData;
  1438. };
  1439. TokenStreamBase.prototype = {
  1440. constructor: TokenStreamBase,
  1441. match: function(tokenTypes, channel){
  1442. if (!(tokenTypes instanceof Array)){
  1443. tokenTypes = [tokenTypes];
  1444. }
  1445. var tt = this.get(channel),
  1446. i = 0,
  1447. len = tokenTypes.length;
  1448. while(i < len){
  1449. if (tt == tokenTypes[i++]){
  1450. return true;
  1451. }
  1452. }
  1453. this.unget();
  1454. return false;
  1455. },
  1456. mustMatch: function(tokenTypes, channel){
  1457. var token;
  1458. if (!(tokenTypes instanceof Array)){
  1459. tokenTypes = [tokenTypes];
  1460. }
  1461. if (!this.match.apply(this, arguments)){
  1462. token = this.LT(1);
  1463. throw new SyntaxError("Expected " + this._tokenData[tokenTypes[0]].name +
  1464. " at line " + token.startLine + ", col " + token.startCol + ".", token.startLine, token.startCol);
  1465. }
  1466. },
  1467. advance: function(tokenTypes, channel){
  1468. while(this.LA(0) !== 0 && !this.match(tokenTypes, channel)){
  1469. this.get();
  1470. }
  1471. return this.LA(0);
  1472. },
  1473. get: function(channel){
  1474. var tokenInfo = this._tokenData,
  1475. reader = this._reader,
  1476. value,
  1477. i =0,
  1478. len = tokenInfo.length,
  1479. found = false,
  1480. token,
  1481. info;
  1482. if (this._lt.length && this._ltIndex >= 0 && this._ltIndex < this._lt.length){
  1483. i++;
  1484. this._token = this._lt[this._ltIndex++];
  1485. info = tokenInfo[this._token.type];
  1486. while((info.channel !== undefined && channel !== info.channel) &&
  1487. this._ltIndex < this._lt.length){
  1488. this._token = this._lt[this._ltIndex++];
  1489. info = tokenInfo[this._token.type];
  1490. i++;
  1491. }
  1492. if ((info.channel === undefined || channel === info.channel) &&
  1493. this._ltIndex <= this._lt.length){
  1494. this._ltIndexCache.push(i);
  1495. return this._token.type;
  1496. }
  1497. }
  1498. token = this._getToken();
  1499. if (token.type > -1 && !tokenInfo[token.type].hide){
  1500. token.channel = tokenInfo[token.type].channel;
  1501. this._token = token;
  1502. this._lt.push(token);
  1503. this._ltIndexCache.push(this._lt.length - this._ltIndex + i);
  1504. if (this._lt.length > 5){
  1505. this._lt.shift();
  1506. }
  1507. if (this._ltIndexCache.length > 5){
  1508. this._ltIndexCache.shift();
  1509. }
  1510. this._ltIndex = this._lt.length;
  1511. }
  1512. info = tokenInfo[token.type];
  1513. if (info &&
  1514. (info.hide ||
  1515. (info.channel !== undefined && channel !== info.channel))){
  1516. return this.get(channel);
  1517. } else {
  1518. return token.type;
  1519. }
  1520. },
  1521. LA: function(index){
  1522. var total = index,
  1523. tt;
  1524. if (index > 0){
  1525. if (index > 5){
  1526. throw new Error("Too much lookahead.");
  1527. }
  1528. while(total){
  1529. tt = this.get();
  1530. total--;
  1531. }
  1532. while(total < index){
  1533. this.unget();
  1534. total++;
  1535. }
  1536. } else if (index < 0){
  1537. if(this._lt[this._ltIndex+index]){
  1538. tt = this._lt[this._ltIndex+index].type;
  1539. } else {
  1540. throw new Error("Too much lookbehind.");
  1541. }
  1542. } else {
  1543. tt = this._token.type;
  1544. }
  1545. return tt;
  1546. },
  1547. LT: function(index){
  1548. this.LA(index);
  1549. return this._lt[this._ltIndex+index-1];
  1550. },
  1551. peek: function(){
  1552. return this.LA(1);
  1553. },
  1554. token: function(){
  1555. return this._token;
  1556. },
  1557. tokenName: function(tokenType){
  1558. if (tokenType < 0 || tokenType > this._tokenData.length){
  1559. return "UNKNOWN_TOKEN";
  1560. } else {
  1561. return this._tokenData[tokenType].name;
  1562. }
  1563. },
  1564. tokenType: function(tokenName){
  1565. return this._tokenData[tokenName] || -1;
  1566. },
  1567. unget: function(){
  1568. if (this._ltIndexCache.length){
  1569. this._ltIndex -= this._ltIndexCache.pop();//--;
  1570. this._token = this._lt[this._ltIndex - 1];
  1571. } else {
  1572. throw new Error("Too much lookahead.");
  1573. }
  1574. }
  1575. };
  1576. parserlib.util = {
  1577. StringReader: StringReader,
  1578. SyntaxError : SyntaxError,
  1579. SyntaxUnit : SyntaxUnit,
  1580. EventTarget : EventTarget,
  1581. TokenStreamBase : TokenStreamBase
  1582. };
  1583. })();
  1584. (function(){
  1585. var EventTarget = parserlib.util.EventTarget,
  1586. TokenStreamBase = parserlib.util.TokenStreamBase,
  1587. StringReader = parserlib.util.StringReader,
  1588. SyntaxError = parserlib.util.SyntaxError,
  1589. SyntaxUnit = parserlib.util.SyntaxUnit;
  1590. var Colors = {
  1591. aliceblue :"#f0f8ff",
  1592. antiquewhite :"#faebd7",
  1593. aqua :"#00ffff",
  1594. aquamarine :"#7fffd4",
  1595. azure :"#f0ffff",
  1596. beige :"#f5f5dc",
  1597. bisque :"#ffe4c4",
  1598. black :"#000000",
  1599. blanchedalmond :"#ffebcd",
  1600. blue :"#0000ff",
  1601. blueviolet :"#8a2be2",
  1602. brown :"#a52a2a",
  1603. burlywood :"#deb887",
  1604. cadetblue :"#5f9ea0",
  1605. chartreuse :"#7fff00",
  1606. chocolate :"#d2691e",
  1607. coral :"#ff7f50",
  1608. cornflowerblue :"#6495ed",
  1609. cornsilk :"#fff8dc",
  1610. crimson :"#dc143c",
  1611. cyan :"#00ffff",
  1612. darkblue :"#00008b",
  1613. darkcyan :"#008b8b",
  1614. darkgoldenrod :"#b8860b",
  1615. darkgray :"#a9a9a9",
  1616. darkgrey :"#a9a9a9",
  1617. darkgreen :"#006400",
  1618. darkkhaki :"#bdb76b",
  1619. darkmagenta :"#8b008b",
  1620. darkolivegreen :"#556b2f",
  1621. darkorange :"#ff8c00",
  1622. darkorchid :"#9932cc",
  1623. darkred :"#8b0000",
  1624. darksalmon :"#e9967a",
  1625. darkseagreen :"#8fbc8f",
  1626. darkslateblue :"#483d8b",
  1627. darkslategray :"#2f4f4f",
  1628. darkslategrey :"#2f4f4f",
  1629. darkturquoise :"#00ced1",
  1630. darkviolet :"#9400d3",
  1631. deeppink :"#ff1493",
  1632. deepskyblue :"#00bfff",
  1633. dimgray :"#696969",
  1634. dimgrey :"#696969",
  1635. dodgerblue :"#1e90ff",
  1636. firebrick :"#b22222",
  1637. floralwhite :"#fffaf0",
  1638. forestgreen :"#228b22",
  1639. fuchsia :"#ff00ff",
  1640. gainsboro :"#dcdcdc",
  1641. ghostwhite :"#f8f8ff",
  1642. gold :"#ffd700",
  1643. goldenrod :"#daa520",
  1644. gray :"#808080",
  1645. grey :"#808080",
  1646. green :"#008000",
  1647. greenyellow :"#adff2f",
  1648. honeydew :"#f0fff0",
  1649. hotpink :"#ff69b4",
  1650. indianred :"#cd5c5c",
  1651. indigo :"#4b0082",
  1652. ivory :"#fffff0",
  1653. khaki :"#f0e68c",
  1654. lavender :"#e6e6fa",
  1655. lavenderblush :"#fff0f5",
  1656. lawngreen :"#7cfc00",
  1657. lemonchiffon :"#fffacd",
  1658. lightblue :"#add8e6",
  1659. lightcoral :"#f08080",
  1660. lightcyan :"#e0ffff",
  1661. lightgoldenrodyellow :"#fafad2",
  1662. lightgray :"#d3d3d3",
  1663. lightgrey :"#d3d3d3",
  1664. lightgreen :"#90ee90",
  1665. lightpink :"#ffb6c1",
  1666. lightsalmon :"#ffa07a",
  1667. lightseagreen :"#20b2aa",
  1668. lightskyblue :"#87cefa",
  1669. lightslategray :"#778899",
  1670. lightslategrey :"#778899",
  1671. lightsteelblue :"#b0c4de",
  1672. lightyellow :"#ffffe0",
  1673. lime :"#00ff00",
  1674. limegreen :"#32cd32",
  1675. linen :"#faf0e6",
  1676. magenta :"#ff00ff",
  1677. maroon :"#800000",
  1678. mediumaquamarine:"#66cdaa",
  1679. mediumblue :"#0000cd",
  1680. mediumorchid :"#ba55d3",
  1681. mediumpurple :"#9370d8",
  1682. mediumseagreen :"#3cb371",
  1683. mediumslateblue :"#7b68ee",
  1684. mediumspringgreen :"#00fa9a",
  1685. mediumturquoise :"#48d1cc",
  1686. mediumvioletred :"#c71585",
  1687. midnightblue :"#191970",
  1688. mintcream :"#f5fffa",
  1689. mistyrose :"#ffe4e1",
  1690. moccasin :"#ffe4b5",
  1691. navajowhite :"#ffdead",
  1692. navy :"#000080",
  1693. oldlace :"#fdf5e6",
  1694. olive :"#808000",
  1695. olivedrab :"#6b8e23",
  1696. orange :"#ffa500",
  1697. orangered :"#ff4500",
  1698. orchid :"#da70d6",
  1699. palegoldenrod :"#eee8aa",
  1700. palegreen :"#98fb98",
  1701. paleturquoise :"#afeeee",
  1702. palevioletred :"#d87093",
  1703. papayawhip :"#ffefd5",
  1704. peachpuff :"#ffdab9",
  1705. peru :"#cd853f",
  1706. pink :"#ffc0cb",
  1707. plum :"#dda0dd",
  1708. powderblue :"#b0e0e6",
  1709. purple :"#800080",
  1710. red :"#ff0000",
  1711. rosybrown :"#bc8f8f",
  1712. royalblue :"#4169e1",
  1713. saddlebrown :"#8b4513",
  1714. salmon :"#fa8072",
  1715. sandybrown :"#f4a460",
  1716. seagreen :"#2e8b57",
  1717. seashell :"#fff5ee",
  1718. sienna :"#a0522d",
  1719. silver :"#c0c0c0",
  1720. skyblue :"#87ceeb",
  1721. slateblue :"#6a5acd",
  1722. slategray :"#708090",
  1723. slategrey :"#708090",
  1724. snow :"#fffafa",
  1725. springgreen :"#00ff7f",
  1726. steelblue :"#4682b4",
  1727. tan :"#d2b48c",
  1728. teal :"#008080",
  1729. thistle :"#d8bfd8",
  1730. tomato :"#ff6347",
  1731. turquoise :"#40e0d0",
  1732. violet :"#ee82ee",
  1733. wheat :"#f5deb3",
  1734. white :"#ffffff",
  1735. whitesmoke :"#f5f5f5",
  1736. yellow :"#ffff00",
  1737. yellowgreen :"#9acd32",
  1738. activeBorder :"Active window border.",
  1739. activecaption :"Active window caption.",
  1740. appworkspace :"Background color of multiple document interface.",
  1741. background :"Desktop background.",
  1742. buttonface :"The face background color for 3-D elements that appear 3-D due to one layer of surrounding border.",
  1743. 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.",
  1744. 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.",
  1745. buttontext :"Text on push buttons.",
  1746. captiontext :"Text in caption, size box, and scrollbar arrow box.",
  1747. graytext :"Grayed (disabled) text. This color is set to #000 if the current display driver does not support a solid gray color.",
  1748. greytext :"Greyed (disabled) text. This color is set to #000 if the current display driver does not support a solid grey color.",
  1749. highlight :"Item(s) selected in a control.",
  1750. highlighttext :"Text of item(s) selected in a control.",
  1751. inactiveborder :"Inactive window border.",
  1752. inactivecaption :"Inactive window caption.",
  1753. inactivecaptiontext :"Color of text in an inactive caption.",
  1754. infobackground :"Background color for tooltip controls.",
  1755. infotext :"Text color for tooltip controls.",
  1756. menu :"Menu background.",
  1757. menutext :"Text in menus.",
  1758. scrollbar :"Scroll bar gray area.",
  1759. 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.",
  1760. threedface :"The face background color for 3-D elements that appear 3-D due to two concentric layers of surrounding border.",
  1761. 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.",
  1762. 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.",
  1763. 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.",
  1764. window :"Window background.",
  1765. windowframe :"Window frame.",
  1766. windowtext :"Text in windows."
  1767. };
  1768. function Combinator(text, line, col){
  1769. SyntaxUnit.call(this, text, line, col, Parser.COMBINATOR_TYPE);
  1770. this.type = "unknown";
  1771. if (/^\s+$/.test(text)){
  1772. this.type = "descendant";
  1773. } else if (text == ">"){
  1774. this.type = "child";
  1775. } else if (text == "+"){
  1776. this.type = "adjacent-sibling";
  1777. } else if (text == "~"){
  1778. this.type = "sibling";
  1779. }
  1780. }
  1781. Combinator.prototype = new SyntaxUnit();
  1782. Combinator.prototype.constructor = Combinator;
  1783. function MediaFeature(name, value){
  1784. SyntaxUnit.call(this, "(" + name + (value !== null ? ":" + value : "") + ")", name.startLine, name.startCol, Parser.MEDIA_FEATURE_TYPE);
  1785. this.name = name;
  1786. this.value = value;
  1787. }
  1788. MediaFeature.prototype = new SyntaxUnit();
  1789. MediaFeature.prototype.constructor = MediaFeature;
  1790. function MediaQuery(modifier, mediaType, features, line, col){
  1791. SyntaxUnit.call(this, (modifier ? modifier + " ": "") + (mediaType ? mediaType : "") + (mediaType && features.length > 0 ? " and " : "") + features.join(" and "), line, col, Parser.MEDIA_QUERY_TYPE);
  1792. this.modifier = modifier;
  1793. this.mediaType = mediaType;
  1794. this.features = features;
  1795. }
  1796. MediaQuery.prototype = new SyntaxUnit();
  1797. MediaQuery.prototype.constructor = MediaQuery;
  1798. function Parser(options){
  1799. EventTarget.call(this);
  1800. this.options = options || {};
  1801. this._tokenStream = null;
  1802. }
  1803. Parser.DEFAULT_TYPE = 0;
  1804. Parser.COMBINATOR_TYPE = 1;
  1805. Parser.MEDIA_FEATURE_TYPE = 2;
  1806. Parser.MEDIA_QUERY_TYPE = 3;
  1807. Parser.PROPERTY_NAME_TYPE = 4;
  1808. Parser.PROPERTY_VALUE_TYPE = 5;
  1809. Parser.PROPERTY_VALUE_PART_TYPE = 6;
  1810. Parser.SELECTOR_TYPE = 7;
  1811. Parser.SELECTOR_PART_TYPE = 8;
  1812. Parser.SELECTOR_SUB_PART_TYPE = 9;
  1813. Parser.prototype = function(){
  1814. var proto = new EventTarget(), //new prototype
  1815. prop,
  1816. additions = {
  1817. constructor: Parser,
  1818. DEFAULT_TYPE : 0,
  1819. COMBINATOR_TYPE : 1,
  1820. MEDIA_FEATURE_TYPE : 2,
  1821. MEDIA_QUERY_TYPE : 3,
  1822. PROPERTY_NAME_TYPE : 4,
  1823. PROPERTY_VALUE_TYPE : 5,
  1824. PROPERTY_VALUE_PART_TYPE : 6,
  1825. SELECTOR_TYPE : 7,
  1826. SELECTOR_PART_TYPE : 8,
  1827. SELECTOR_SUB_PART_TYPE : 9,
  1828. _stylesheet: function(){
  1829. var tokenStream = this._tokenStream,
  1830. charset = null,
  1831. count,
  1832. token,
  1833. tt;
  1834. this.fire("startstylesheet");
  1835. this._charset();
  1836. this._skipCruft();
  1837. while (tokenStream.peek() == Tokens.IMPORT_SYM){
  1838. this._import();
  1839. this._skipCruft();
  1840. }
  1841. while (tokenStream.peek() == Tokens.NAMESPACE_SYM){
  1842. this._namespace();
  1843. this._skipCruft();
  1844. }
  1845. tt = tokenStream.peek();
  1846. while(tt > Tokens.EOF){
  1847. try {
  1848. switch(tt){
  1849. case Tokens.MEDIA_SYM:
  1850. this._media();
  1851. this._skipCruft();
  1852. break;
  1853. case Tokens.PAGE_SYM:
  1854. this._page();
  1855. this._skipCruft();
  1856. break;
  1857. case Tokens.FONT_FACE_SYM:
  1858. this._font_face();
  1859. this._skipCruft();
  1860. break;
  1861. case Tokens.KEYFRAMES_SYM:
  1862. this._keyframes();
  1863. this._skipCruft();
  1864. break;
  1865. case Tokens.VIEWPORT_SYM:
  1866. this._viewport();
  1867. this._skipCruft();
  1868. break;
  1869. case Tokens.UNKNOWN_SYM: //unknown @ rule
  1870. tokenStream.get();
  1871. if (!this.options.strict){
  1872. this.fire({
  1873. type: "error",
  1874. error: null,
  1875. message: "Unknown @ rule: " + tokenStream.LT(0).value + ".",
  1876. line: tokenStream.LT(0).startLine,
  1877. col: tokenStream.LT(0).startCol
  1878. });
  1879. count=0;
  1880. while (tokenStream.advance([Tokens.LBRACE, Tokens.RBRACE]) == Tokens.LBRACE){
  1881. count++; //keep track of nesting depth
  1882. }
  1883. while(count){
  1884. tokenStream.advance([Tokens.RBRACE]);
  1885. count--;
  1886. }
  1887. } else {
  1888. throw new SyntaxError("Unknown @ rule.", tokenStream.LT(0).startLine, tokenStream.LT(0).startCol);
  1889. }
  1890. break;
  1891. case Tokens.S:
  1892. this._readWhitespace();
  1893. break;
  1894. default:
  1895. if(!this._ruleset()){
  1896. switch(tt){
  1897. case Tokens.CHARSET_SYM:
  1898. token = tokenStream.LT(1);
  1899. this._charset(false);
  1900. throw new SyntaxError("@charset not allowed here.", token.startLine, token.startCol);
  1901. case Tokens.IMPORT_SYM:
  1902. token = tokenStream.LT(1);
  1903. this._import(false);
  1904. throw new SyntaxError("@import not allowed here.", token.startLine, token.startCol);
  1905. case Tokens.NAMESPACE_SYM:
  1906. token = tokenStream.LT(1);
  1907. this._namespace(false);
  1908. throw new SyntaxError("@namespace not allowed here.", token.startLine, token.startCol);
  1909. default:
  1910. tokenStream.get(); //get the last token
  1911. this._unexpectedToken(tokenStream.token());
  1912. }
  1913. }
  1914. }
  1915. } catch(ex) {
  1916. if (ex instanceof SyntaxError && !this.options.strict){
  1917. this.fire({
  1918. type: "error",
  1919. error: ex,
  1920. message: ex.message,
  1921. line: ex.line,
  1922. col: ex.col
  1923. });
  1924. } else {
  1925. throw ex;
  1926. }
  1927. }
  1928. tt = tokenStream.peek();
  1929. }
  1930. if (tt != Tokens.EOF){
  1931. this._unexpectedToken(tokenStream.token());
  1932. }
  1933. this.fire("endstylesheet");
  1934. },
  1935. _charset: function(emit){
  1936. var tokenStream = this._tokenStream,
  1937. charset,
  1938. token,
  1939. line,
  1940. col;
  1941. if (tokenStream.match(Tokens.CHARSET_SYM)){
  1942. line = tokenStream.token().startLine;
  1943. col = tokenStream.token().startCol;
  1944. this._readWhitespace();
  1945. tokenStream.mustMatch(Tokens.STRING);
  1946. token = tokenStream.token();
  1947. charset = token.value;
  1948. this._readWhitespace();
  1949. tokenStream.mustMatch(Tokens.SEMICOLON);
  1950. if (emit !== false){
  1951. this.fire({
  1952. type: "charset",
  1953. charset:charset,
  1954. line: line,
  1955. col: col
  1956. });
  1957. }
  1958. }
  1959. },
  1960. _import: function(emit){
  1961. var tokenStream = this._tokenStream,
  1962. tt,
  1963. uri,
  1964. importToken,
  1965. mediaList = [];
  1966. tokenStream.mustMatch(Tokens.IMPORT_SYM);
  1967. importToken = tokenStream.token();
  1968. this._readWhitespace();
  1969. tokenStream.mustMatch([Tokens.STRING, Tokens.URI]);
  1970. uri = tokenStream.token().value.replace(/^(?:url\()?["']?([^"']+?)["']?\)?$/, "$1");
  1971. this._readWhitespace();
  1972. mediaList = this._media_query_list();
  1973. tokenStream.mustMatch(Tokens.SEMICOLON);
  1974. this._readWhitespace();
  1975. if (emit !== false){
  1976. this.fire({
  1977. type: "import",
  1978. uri: uri,
  1979. media: mediaList,
  1980. line: importToken.startLine,
  1981. col: importToken.startCol
  1982. });
  1983. }
  1984. },
  1985. _namespace: function(emit){
  1986. var tokenStream = this._tokenStream,
  1987. line,
  1988. col,
  1989. prefix,
  1990. uri;
  1991. tokenStream.mustMatch(Tokens.NAMESPACE_SYM);
  1992. line = tokenStream.token().startLine;
  1993. col = tokenStream.token().startCol;
  1994. this._readWhitespace();
  1995. if (tokenStream.match(Tokens.IDENT)){
  1996. prefix = tokenStream.token().value;
  1997. this._readWhitespace();
  1998. }
  1999. tokenStream.mustMatch([Tokens.STRING, Tokens.URI]);
  2000. uri = tokenStream.token().value.replace(/(?:url\()?["']([^"']+)["']\)?/, "$1");
  2001. this._readWhitespace();
  2002. tokenStream.mustMatch(Tokens.SEMICOLON);
  2003. this._readWhitespace();
  2004. if (emit !== false){
  2005. this.fire({
  2006. type: "namespace",
  2007. prefix: prefix,
  2008. uri: uri,
  2009. line: line,
  2010. col: col
  2011. });
  2012. }
  2013. },
  2014. _media: function(){
  2015. var tokenStream = this._tokenStream,
  2016. line,
  2017. col,
  2018. mediaList;// = [];
  2019. tokenStream.mustMatch(Tokens.MEDIA_SYM);
  2020. line = tokenStream.token().startLine;
  2021. col = tokenStream.token().startCol;
  2022. this._readWhitespace();
  2023. mediaList = this._media_query_list();
  2024. tokenStream.mustMatch(Tokens.LBRACE);
  2025. this._readWhitespace();
  2026. this.fire({
  2027. type: "startmedia",
  2028. media: mediaList,
  2029. line: line,
  2030. col: col
  2031. });
  2032. while(true) {
  2033. if (tokenStream.peek() == Tokens.PAGE_SYM){
  2034. this._page();
  2035. } else if (tokenStream.peek() == Tokens.FONT_FACE_SYM){
  2036. this._font_face();
  2037. } else if (tokenStream.peek() == Tokens.VIEWPORT_SYM){
  2038. this._viewport();
  2039. } else if (!this._ruleset()){
  2040. break;
  2041. }
  2042. }
  2043. tokenStream.mustMatch(Tokens.RBRACE);
  2044. this._readWhitespace();
  2045. this.fire({
  2046. type: "endmedia",
  2047. media: mediaList,
  2048. line: line,
  2049. col: col
  2050. });
  2051. },
  2052. _media_query_list: function(){
  2053. var tokenStream = this._tokenStream,
  2054. mediaList = [];
  2055. this._readWhitespace();
  2056. if (tokenStream.peek() == Tokens.IDENT || tokenStream.peek() == Tokens.LPAREN){
  2057. mediaList.push(this._media_query());
  2058. }
  2059. while(tokenStream.match(Tokens.COMMA)){
  2060. this._readWhitespace();
  2061. mediaList.push(this._media_query());
  2062. }
  2063. return mediaList;
  2064. },
  2065. _media_query: function(){
  2066. var tokenStream = this._tokenStream,
  2067. type = null,
  2068. ident = null,
  2069. token = null,
  2070. expressions = [];
  2071. if (tokenStream.match(Tokens.IDENT)){
  2072. ident = tokenStream.token().value.toLowerCase();
  2073. if (ident != "only" && ident != "not"){
  2074. tokenStream.unget();
  2075. ident = null;
  2076. } else {
  2077. token = tokenStream.token();
  2078. }
  2079. }
  2080. this._readWhitespace();
  2081. if (tokenStream.peek() == Tokens.IDENT){
  2082. type = this._media_type();
  2083. if (token === null){
  2084. token = tokenStream.token();
  2085. }
  2086. } else if (tokenStream.peek() == Tokens.LPAREN){
  2087. if (token === null){
  2088. token = tokenStream.LT(1);
  2089. }
  2090. expressions.push(this._media_expression());
  2091. }
  2092. if (type === null && expressions.length === 0){
  2093. return null;
  2094. } else {
  2095. this._readWhitespace();
  2096. while (tokenStream.match(Tokens.IDENT)){
  2097. if (tokenStream.token().value.toLowerCase() != "and"){
  2098. this._unexpectedToken(tokenStream.token());
  2099. }
  2100. this._readWhitespace();
  2101. expressions.push(this._media_expression());
  2102. }
  2103. }
  2104. return new MediaQuery(ident, type, expressions, token.startLine, token.startCol);
  2105. },
  2106. _media_type: function(){
  2107. return this._media_feature();
  2108. },
  2109. _media_expression: function(){
  2110. var tokenStream = this._tokenStream,
  2111. feature = null,
  2112. token,
  2113. expression = null;
  2114. tokenStream.mustMatch(Tokens.LPAREN);
  2115. this._readWhitespace();
  2116. feature = this._media_feature();
  2117. this._readWhitespace();
  2118. if (tokenStream.match(Tokens.COLON)){
  2119. this._readWhitespace();
  2120. token = tokenStream.LT(1);
  2121. expression = this._expression();
  2122. }
  2123. tokenStream.mustMatch(Tokens.RPAREN);
  2124. this._readWhitespace();
  2125. return new MediaFeature(feature, (expression ? new SyntaxUnit(expression, token.startLine, token.startCol) : null));
  2126. },
  2127. _media_feature: function(){
  2128. var tokenStream = this._tokenStream;
  2129. tokenStream.mustMatch(Tokens.IDENT);
  2130. return SyntaxUnit.fromToken(tokenStream.token());
  2131. },
  2132. _page: function(){
  2133. var tokenStream = this._tokenStream,
  2134. line,
  2135. col,
  2136. identifier = null,
  2137. pseudoPage = null;
  2138. tokenStream.mustMatch(Tokens.PAGE_SYM);
  2139. line = tokenStream.token().startLine;
  2140. col = tokenStream.token().startCol;
  2141. this._readWhitespace();
  2142. if (tokenStream.match(Tokens.IDENT)){
  2143. identifier = tokenStream.token().value;
  2144. if (identifier.toLowerCase() === "auto"){
  2145. this._unexpectedToken(tokenStream.token());
  2146. }
  2147. }
  2148. if (tokenStream.peek() == Tokens.COLON){
  2149. pseudoPage = this._pseudo_page();
  2150. }
  2151. this._readWhitespace();
  2152. this.fire({
  2153. type: "startpage",
  2154. id: identifier,
  2155. pseudo: pseudoPage,
  2156. line: line,
  2157. col: col
  2158. });
  2159. this._readDeclarations(true, true);
  2160. this.fire({
  2161. type: "endpage",
  2162. id: identifier,
  2163. pseudo: pseudoPage,
  2164. line: line,
  2165. col: col
  2166. });
  2167. },
  2168. _margin: function(){
  2169. var tokenStream = this._tokenStream,
  2170. line,
  2171. col,
  2172. marginSym = this._margin_sym();
  2173. if (marginSym){
  2174. line = tokenStream.token().startLine;
  2175. col = tokenStream.token().startCol;
  2176. this.fire({
  2177. type: "startpagemargin",
  2178. margin: marginSym,
  2179. line: line,
  2180. col: col
  2181. });
  2182. this._readDeclarations(true);
  2183. this.fire({
  2184. type: "endpagemargin",
  2185. margin: marginSym,
  2186. line: line,
  2187. col: col
  2188. });
  2189. return true;
  2190. } else {
  2191. return false;
  2192. }
  2193. },
  2194. _margin_sym: function(){
  2195. var tokenStream = this._tokenStream;
  2196. if(tokenStream.match([Tokens.TOPLEFTCORNER_SYM, Tokens.TOPLEFT_SYM,
  2197. Tokens.TOPCENTER_SYM, Tokens.TOPRIGHT_SYM, Tokens.TOPRIGHTCORNER_SYM,
  2198. Tokens.BOTTOMLEFTCORNER_SYM, Tokens.BOTTOMLEFT_SYM,
  2199. Tokens.BOTTOMCENTER_SYM, Tokens.BOTTOMRIGHT_SYM,
  2200. Tokens.BOTTOMRIGHTCORNER_SYM, Tokens.LEFTTOP_SYM,
  2201. Tokens.LEFTMIDDLE_SYM, Tokens.LEFTBOTTOM_SYM, Tokens.RIGHTTOP_SYM,
  2202. Tokens.RIGHTMIDDLE_SYM, Tokens.RIGHTBOTTOM_SYM]))
  2203. {
  2204. return SyntaxUnit.fromToken(tokenStream.token());
  2205. } else {
  2206. return null;
  2207. }
  2208. },
  2209. _pseudo_page: function(){
  2210. var tokenStream = this._tokenStream;
  2211. tokenStream.mustMatch(Tokens.COLON);
  2212. tokenStream.mustMatch(Tokens.IDENT);
  2213. return tokenStream.token().value;
  2214. },
  2215. _font_face: function(){
  2216. var tokenStream = this._tokenStream,
  2217. line,
  2218. col;
  2219. tokenStream.mustMatch(Tokens.FONT_FACE_SYM);
  2220. line = tokenStream.token().startLine;
  2221. col = tokenStream.token().startCol;
  2222. this._readWhitespace();
  2223. this.fire({
  2224. type: "startfontface",
  2225. line: line,
  2226. col: col
  2227. });
  2228. this._readDeclarations(true);
  2229. this.fire({
  2230. type: "endfontface",
  2231. line: line,
  2232. col: col
  2233. });
  2234. },
  2235. _viewport: function(){
  2236. var tokenStream = this._tokenStream,
  2237. line,
  2238. col;
  2239. tokenStream.mustMatch(Tokens.VIEWPORT_SYM);
  2240. line = tokenStream.token().startLine;
  2241. col = tokenStream.token().startCol;
  2242. this._readWhitespace();
  2243. this.fire({
  2244. type: "startviewport",
  2245. line: line,
  2246. col: col
  2247. });
  2248. this._readDeclarations(true);
  2249. this.fire({
  2250. type: "endviewport",
  2251. line: line,
  2252. col: col
  2253. });
  2254. },
  2255. _operator: function(inFunction){
  2256. var tokenStream = this._tokenStream,
  2257. token = null;
  2258. if (tokenStream.match([Tokens.SLASH, Tokens.COMMA]) ||
  2259. (inFunction && tokenStream.match([Tokens.PLUS, Tokens.STAR, Tokens.MINUS]))){
  2260. token = tokenStream.token();
  2261. this._readWhitespace();
  2262. }
  2263. return token ? PropertyValuePart.fromToken(token) : null;
  2264. },
  2265. _combinator: function(){
  2266. var tokenStream = this._tokenStream,
  2267. value = null,
  2268. token;
  2269. if(tokenStream.match([Tokens.PLUS, Tokens.GREATER, Tokens.TILDE])){
  2270. token = tokenStream.token();
  2271. value = new Combinator(token.value, token.startLine, token.startCol);
  2272. this._readWhitespace();
  2273. }
  2274. return value;
  2275. },
  2276. _unary_operator: function(){
  2277. var tokenStream = this._tokenStream;
  2278. if (tokenStream.match([Tokens.MINUS, Tokens.PLUS])){
  2279. return tokenStream.token().value;
  2280. } else {
  2281. return null;
  2282. }
  2283. },
  2284. _property: function(){
  2285. var tokenStream = this._tokenStream,
  2286. value = null,
  2287. hack = null,
  2288. tokenValue,
  2289. token,
  2290. line,
  2291. col;
  2292. if (tokenStream.peek() == Tokens.STAR && this.options.starHack){
  2293. tokenStream.get();
  2294. token = tokenStream.token();
  2295. hack = token.value;
  2296. line = token.startLine;
  2297. col = token.startCol;
  2298. }
  2299. if(tokenStream.match(Tokens.IDENT)){
  2300. token = tokenStream.token();
  2301. tokenValue = token.value;
  2302. if (tokenValue.charAt(0) == "_" && this.options.underscoreHack){
  2303. hack = "_";
  2304. tokenValue = tokenValue.substring(1);
  2305. }
  2306. value = new PropertyName(tokenValue, hack, (line||token.startLine), (col||token.startCol));
  2307. this._readWhitespace();
  2308. }
  2309. return value;
  2310. },
  2311. _ruleset: function(){
  2312. var tokenStream = this._tokenStream,
  2313. tt,
  2314. selectors;
  2315. try {
  2316. selectors = this._selectors_group();
  2317. } catch (ex){
  2318. if (ex instanceof SyntaxError && !this.options.strict){
  2319. this.fire({
  2320. type: "error",
  2321. error: ex,
  2322. message: ex.message,
  2323. line: ex.line,
  2324. col: ex.col
  2325. });
  2326. tt = tokenStream.advance([Tokens.RBRACE]);
  2327. if (tt == Tokens.RBRACE){
  2328. } else {
  2329. throw ex;
  2330. }
  2331. } else {
  2332. throw ex;
  2333. }
  2334. return true;
  2335. }
  2336. if (selectors){
  2337. this.fire({
  2338. type: "startrule",
  2339. selectors: selectors,
  2340. line: selectors[0].line,
  2341. col: selectors[0].col
  2342. });
  2343. this._readDeclarations(true);
  2344. this.fire({
  2345. type: "endrule",
  2346. selectors: selectors,
  2347. line: selectors[0].line,
  2348. col: selectors[0].col
  2349. });
  2350. }
  2351. return selectors;
  2352. },
  2353. _selectors_group: function(){
  2354. var tokenStream = this._tokenStream,
  2355. selectors = [],
  2356. selector;
  2357. selector = this._selector();
  2358. if (selector !== null){
  2359. selectors.push(selector);
  2360. while(tokenStream.match(Tokens.COMMA)){
  2361. this._readWhitespace();
  2362. selector = this._selector();
  2363. if (selector !== null){
  2364. selectors.push(selector);
  2365. } else {
  2366. this._unexpectedToken(tokenStream.LT(1));
  2367. }
  2368. }
  2369. }
  2370. return selectors.length ? selectors : null;
  2371. },
  2372. _selector: function(){
  2373. var tokenStream = this._tokenStream,
  2374. selector = [],
  2375. nextSelector = null,
  2376. combinator = null,
  2377. ws = null;
  2378. nextSelector = this._simple_selector_sequence();
  2379. if (nextSelector === null){
  2380. return null;
  2381. }
  2382. selector.push(nextSelector);
  2383. do {
  2384. combinator = this._combinator();
  2385. if (combinator !== null){
  2386. selector.push(combinator);
  2387. nextSelector = this._simple_selector_sequence();
  2388. if (nextSelector === null){
  2389. this._unexpectedToken(tokenStream.LT(1));
  2390. } else {
  2391. selector.push(nextSelector);
  2392. }
  2393. } else {
  2394. if (this._readWhitespace()){
  2395. ws = new Combinator(tokenStream.token().value, tokenStream.token().startLine, tokenStream.token().startCol);
  2396. combinator = this._combinator();
  2397. nextSelector = this._simple_selector_sequence();
  2398. if (nextSelector === null){
  2399. if (combinator !== null){
  2400. this._unexpectedToken(tokenStream.LT(1));
  2401. }
  2402. } else {
  2403. if (combinator !== null){
  2404. selector.push(combinator);
  2405. } else {
  2406. selector.push(ws);
  2407. }
  2408. selector.push(nextSelector);
  2409. }
  2410. } else {
  2411. break;
  2412. }
  2413. }
  2414. } while(true);
  2415. return new Selector(selector, selector[0].line, selector[0].col);
  2416. },
  2417. _simple_selector_sequence: function(){
  2418. var tokenStream = this._tokenStream,
  2419. elementName = null,
  2420. modifiers = [],
  2421. selectorText= "",
  2422. components = [
  2423. function(){
  2424. return tokenStream.match(Tokens.HASH) ?
  2425. new SelectorSubPart(tokenStream.token().value, "id", tokenStream.token().startLine, tokenStream.token().startCol) :
  2426. null;
  2427. },
  2428. this._class,
  2429. this._attrib,
  2430. this._pseudo,
  2431. this._negation
  2432. ],
  2433. i = 0,
  2434. len = components.length,
  2435. component = null,
  2436. found = false,
  2437. line,
  2438. col;
  2439. line = tokenStream.LT(1).startLine;
  2440. col = tokenStream.LT(1).startCol;
  2441. elementName = this._type_selector();
  2442. if (!elementName){
  2443. elementName = this._universal();
  2444. }
  2445. if (elementName !== null){
  2446. selectorText += elementName;
  2447. }
  2448. while(true){
  2449. if (tokenStream.peek() === Tokens.S){
  2450. break;
  2451. }
  2452. while(i < len && component === null){
  2453. component = components[i++].call(this);
  2454. }
  2455. if (component === null){
  2456. if (selectorText === ""){
  2457. return null;
  2458. } else {
  2459. break;
  2460. }
  2461. } else {
  2462. i = 0;
  2463. modifiers.push(component);
  2464. selectorText += component.toString();
  2465. component = null;
  2466. }
  2467. }
  2468. return selectorText !== "" ?
  2469. new SelectorPart(elementName, modifiers, selectorText, line, col) :
  2470. null;
  2471. },
  2472. _type_selector: function(){
  2473. var tokenStream = this._tokenStream,
  2474. ns = this._namespace_prefix(),
  2475. elementName = this._element_name();
  2476. if (!elementName){
  2477. if (ns){
  2478. tokenStream.unget();
  2479. if (ns.length > 1){
  2480. tokenStream.unget();
  2481. }
  2482. }
  2483. return null;
  2484. } else {
  2485. if (ns){
  2486. elementName.text = ns + elementName.text;
  2487. elementName.col -= ns.length;
  2488. }
  2489. return elementName;
  2490. }
  2491. },
  2492. _class: function(){
  2493. var tokenStream = this._tokenStream,
  2494. token;
  2495. if (tokenStream.match(Tokens.DOT)){
  2496. tokenStream.mustMatch(Tokens.IDENT);
  2497. token = tokenStream.token();
  2498. return new SelectorSubPart("." + token.value, "class", token.startLine, token.startCol - 1);
  2499. } else {
  2500. return null;
  2501. }
  2502. },
  2503. _element_name: function(){
  2504. var tokenStream = this._tokenStream,
  2505. token;
  2506. if (tokenStream.match(Tokens.IDENT)){
  2507. token = tokenStream.token();
  2508. return new SelectorSubPart(token.value, "elementName", token.startLine, token.startCol);
  2509. } else {
  2510. return null;
  2511. }
  2512. },
  2513. _namespace_prefix: function(){
  2514. var tokenStream = this._tokenStream,
  2515. value = "";
  2516. if (tokenStream.LA(1) === Tokens.PIPE || tokenStream.LA(2) === Tokens.PIPE){
  2517. if(tokenStream.match([Tokens.IDENT, Tokens.STAR])){
  2518. value += tokenStream.token().value;
  2519. }
  2520. tokenStream.mustMatch(Tokens.PIPE);
  2521. value += "|";
  2522. }
  2523. return value.length ? value : null;
  2524. },
  2525. _universal: function(){
  2526. var tokenStream = this._tokenStream,
  2527. value = "",
  2528. ns;
  2529. ns = this._namespace_prefix();
  2530. if(ns){
  2531. value += ns;
  2532. }
  2533. if(tokenStream.match(Tokens.STAR)){
  2534. value += "*";
  2535. }
  2536. return value.length ? value : null;
  2537. },
  2538. _attrib: function(){
  2539. var tokenStream = this._tokenStream,
  2540. value = null,
  2541. ns,
  2542. token;
  2543. if (tokenStream.match(Tokens.LBRACKET)){
  2544. token = tokenStream.token();
  2545. value = token.value;
  2546. value += this._readWhitespace();
  2547. ns = this._namespace_prefix();
  2548. if (ns){
  2549. value += ns;
  2550. }
  2551. tokenStream.mustMatch(Tokens.IDENT);
  2552. value += tokenStream.token().value;
  2553. value += this._readWhitespace();
  2554. if(tokenStream.match([Tokens.PREFIXMATCH, Tokens.SUFFIXMATCH, Tokens.SUBSTRINGMATCH,
  2555. Tokens.EQUALS, Tokens.INCLUDES, Tokens.DASHMATCH])){
  2556. value += tokenStream.token().value;
  2557. value += this._readWhitespace();
  2558. tokenStream.mustMatch([Tokens.IDENT, Tokens.STRING]);
  2559. value += tokenStream.token().value;
  2560. value += this._readWhitespace();
  2561. }
  2562. tokenStream.mustMatch(Tokens.RBRACKET);
  2563. return new SelectorSubPart(value + "]", "attribute", token.startLine, token.startCol);
  2564. } else {
  2565. return null;
  2566. }
  2567. },
  2568. _pseudo: function(){
  2569. var tokenStream = this._tokenStream,
  2570. pseudo = null,
  2571. colons = ":",
  2572. line,
  2573. col;
  2574. if (tokenStream.match(Tokens.COLON)){
  2575. if (tokenStream.match(Tokens.COLON)){
  2576. colons += ":";
  2577. }
  2578. if (tokenStream.match(Tokens.IDENT)){
  2579. pseudo = tokenStream.token().value;
  2580. line = tokenStream.token().startLine;
  2581. col = tokenStream.token().startCol - colons.length;
  2582. } else if (tokenStream.peek() == Tokens.FUNCTION){
  2583. line = tokenStream.LT(1).startLine;
  2584. col = tokenStream.LT(1).startCol - colons.length;
  2585. pseudo = this._functional_pseudo();
  2586. }
  2587. if (pseudo){
  2588. pseudo = new SelectorSubPart(colons + pseudo, "pseudo", line, col);
  2589. }
  2590. }
  2591. return pseudo;
  2592. },
  2593. _functional_pseudo: function(){
  2594. var tokenStream = this._tokenStream,
  2595. value = null;
  2596. if(tokenStream.match(Tokens.FUNCTION)){
  2597. value = tokenStream.token().value;
  2598. value += this._readWhitespace();
  2599. value += this._expression();
  2600. tokenStream.mustMatch(Tokens.RPAREN);
  2601. value += ")";
  2602. }
  2603. return value;
  2604. },
  2605. _expression: function(){
  2606. var tokenStream = this._tokenStream,
  2607. value = "";
  2608. while(tokenStream.match([Tokens.PLUS, Tokens.MINUS, Tokens.DIMENSION,
  2609. Tokens.NUMBER, Tokens.STRING, Tokens.IDENT, Tokens.LENGTH,
  2610. Tokens.FREQ, Tokens.ANGLE, Tokens.TIME,
  2611. Tokens.RESOLUTION, Tokens.SLASH])){
  2612. value += tokenStream.token().value;
  2613. value += this._readWhitespace();
  2614. }
  2615. return value.length ? value : null;
  2616. },
  2617. _negation: function(){
  2618. var tokenStream = this._tokenStream,
  2619. line,
  2620. col,
  2621. value = "",
  2622. arg,
  2623. subpart = null;
  2624. if (tokenStream.match(Tokens.NOT)){
  2625. value = tokenStream.token().value;
  2626. line = tokenStream.token().startLine;
  2627. col = tokenStream.token().startCol;
  2628. value += this._readWhitespace();
  2629. arg = this._negation_arg();
  2630. value += arg;
  2631. value += this._readWhitespace();
  2632. tokenStream.match(Tokens.RPAREN);
  2633. value += tokenStream.token().value;
  2634. subpart = new SelectorSubPart(value, "not", line, col);
  2635. subpart.args.push(arg);
  2636. }
  2637. return subpart;
  2638. },
  2639. _negation_arg: function(){
  2640. var tokenStream = this._tokenStream,
  2641. args = [
  2642. this._type_selector,
  2643. this._universal,
  2644. function(){
  2645. return tokenStream.match(Tokens.HASH) ?
  2646. new SelectorSubPart(tokenStream.token().value, "id", tokenStream.token().startLine, tokenStream.token().startCol) :
  2647. null;
  2648. },
  2649. this._class,
  2650. this._attrib,
  2651. this._pseudo
  2652. ],
  2653. arg = null,
  2654. i = 0,
  2655. len = args.length,
  2656. elementName,
  2657. line,
  2658. col,
  2659. part;
  2660. line = tokenStream.LT(1).startLine;
  2661. col = tokenStream.LT(1).startCol;
  2662. while(i < len && arg === null){
  2663. arg = args[i].call(this);
  2664. i++;
  2665. }
  2666. if (arg === null){
  2667. this._unexpectedToken(tokenStream.LT(1));
  2668. }
  2669. if (arg.type == "elementName"){
  2670. part = new SelectorPart(arg, [], arg.toString(), line, col);
  2671. } else {
  2672. part = new SelectorPart(null, [arg], arg.toString(), line, col);
  2673. }
  2674. return part;
  2675. },
  2676. _declaration: function(){
  2677. var tokenStream = this._tokenStream,
  2678. property = null,
  2679. expr = null,
  2680. prio = null,
  2681. error = null,
  2682. invalid = null,
  2683. propertyName= "";
  2684. property = this._property();
  2685. if (property !== null){
  2686. tokenStream.mustMatch(Tokens.COLON);
  2687. this._readWhitespace();
  2688. expr = this._expr();
  2689. if (!expr || expr.length === 0){
  2690. this._unexpectedToken(tokenStream.LT(1));
  2691. }
  2692. prio = this._prio();
  2693. propertyName = property.toString();
  2694. if (this.options.starHack && property.hack == "*" ||
  2695. this.options.underscoreHack && property.hack == "_") {
  2696. propertyName = property.text;
  2697. }
  2698. try {
  2699. this._validateProperty(propertyName, expr);
  2700. } catch (ex) {
  2701. invalid = ex;
  2702. }
  2703. this.fire({
  2704. type: "property",
  2705. property: property,
  2706. value: expr,
  2707. important: prio,
  2708. line: property.line,
  2709. col: property.col,
  2710. invalid: invalid
  2711. });
  2712. return true;
  2713. } else {
  2714. return false;
  2715. }
  2716. },
  2717. _prio: function(){
  2718. var tokenStream = this._tokenStream,
  2719. result = tokenStream.match(Tokens.IMPORTANT_SYM);
  2720. this._readWhitespace();
  2721. return result;
  2722. },
  2723. _expr: function(inFunction){
  2724. var tokenStream = this._tokenStream,
  2725. values = [],
  2726. value = null,
  2727. operator = null;
  2728. value = this._term(inFunction);
  2729. if (value !== null){
  2730. values.push(value);
  2731. do {
  2732. operator = this._operator(inFunction);
  2733. if (operator){
  2734. values.push(operator);
  2735. } /*else {
  2736. values.push(new PropertyValue(valueParts, valueParts[0].line, valueParts[0].col));
  2737. valueParts = [];
  2738. }*/
  2739. value = this._term(inFunction);
  2740. if (value === null){
  2741. break;
  2742. } else {
  2743. values.push(value);
  2744. }
  2745. } while(true);
  2746. }
  2747. return values.length > 0 ? new PropertyValue(values, values[0].line, values[0].col) : null;
  2748. },
  2749. _term: function(inFunction){
  2750. var tokenStream = this._tokenStream,
  2751. unary = null,
  2752. value = null,
  2753. endChar = null,
  2754. token,
  2755. line,
  2756. col;
  2757. unary = this._unary_operator();
  2758. if (unary !== null){
  2759. line = tokenStream.token().startLine;
  2760. col = tokenStream.token().startCol;
  2761. }
  2762. if (tokenStream.peek() == Tokens.IE_FUNCTION && this.options.ieFilters){
  2763. value = this._ie_function();
  2764. if (unary === null){
  2765. line = tokenStream.token().startLine;
  2766. col = tokenStream.token().startCol;
  2767. }
  2768. } else if (inFunction && tokenStream.match([Tokens.LPAREN, Tokens.LBRACE, Tokens.LBRACKET])){
  2769. token = tokenStream.token();
  2770. endChar = token.endChar;
  2771. value = token.value + this._expr(inFunction).text;
  2772. if (unary === null){
  2773. line = tokenStream.token().startLine;
  2774. col = tokenStream.token().startCol;
  2775. }
  2776. tokenStream.mustMatch(Tokens.type(endChar));
  2777. value += endChar;
  2778. this._readWhitespace();
  2779. } else if (tokenStream.match([Tokens.NUMBER, Tokens.PERCENTAGE, Tokens.LENGTH,
  2780. Tokens.ANGLE, Tokens.TIME,
  2781. Tokens.FREQ, Tokens.STRING, Tokens.IDENT, Tokens.URI, Tokens.UNICODE_RANGE])){
  2782. value = tokenStream.token().value;
  2783. if (unary === null){
  2784. line = tokenStream.token().startLine;
  2785. col = tokenStream.token().startCol;
  2786. }
  2787. this._readWhitespace();
  2788. } else {
  2789. token = this._hexcolor();
  2790. if (token === null){
  2791. if (unary === null){
  2792. line = tokenStream.LT(1).startLine;
  2793. col = tokenStream.LT(1).startCol;
  2794. }
  2795. if (value === null){
  2796. if (tokenStream.LA(3) == Tokens.EQUALS && this.options.ieFilters){
  2797. value = this._ie_function();
  2798. } else {
  2799. value = this._function();
  2800. }
  2801. }
  2802. } else {
  2803. value = token.value;
  2804. if (unary === null){
  2805. line = token.startLine;
  2806. col = token.startCol;
  2807. }
  2808. }
  2809. }
  2810. return value !== null ?
  2811. new PropertyValuePart(unary !== null ? unary + value : value, line, col) :
  2812. null;
  2813. },
  2814. _function: function(){
  2815. var tokenStream = this._tokenStream,
  2816. functionText = null,
  2817. expr = null,
  2818. lt;
  2819. if (tokenStream.match(Tokens.FUNCTION)){
  2820. functionText = tokenStream.token().value;
  2821. this._readWhitespace();
  2822. expr = this._expr(true);
  2823. functionText += expr;
  2824. if (this.options.ieFilters && tokenStream.peek() == Tokens.EQUALS){
  2825. do {
  2826. if (this._readWhitespace()){
  2827. functionText += tokenStream.token().value;
  2828. }
  2829. if (tokenStream.LA(0) == Tokens.COMMA){
  2830. functionText += tokenStream.token().value;
  2831. }
  2832. tokenStream.match(Tokens.IDENT);
  2833. functionText += tokenStream.token().value;
  2834. tokenStream.match(Tokens.EQUALS);
  2835. functionText += tokenStream.token().value;
  2836. lt = tokenStream.peek();
  2837. while(lt != Tokens.COMMA && lt != Tokens.S && lt != Tokens.RPAREN){
  2838. tokenStream.get();
  2839. functionText += tokenStream.token().value;
  2840. lt = tokenStream.peek();
  2841. }
  2842. } while(tokenStream.match([Tokens.COMMA, Tokens.S]));
  2843. }
  2844. tokenStream.match(Tokens.RPAREN);
  2845. functionText += ")";
  2846. this._readWhitespace();
  2847. }
  2848. return functionText;
  2849. },
  2850. _ie_function: function(){
  2851. var tokenStream = this._tokenStream,
  2852. functionText = null,
  2853. expr = null,
  2854. lt;
  2855. if (tokenStream.match([Tokens.IE_FUNCTION, Tokens.FUNCTION])){
  2856. functionText = tokenStream.token().value;
  2857. do {
  2858. if (this._readWhitespace()){
  2859. functionText += tokenStream.token().value;
  2860. }
  2861. if (tokenStream.LA(0) == Tokens.COMMA){
  2862. functionText += tokenStream.token().value;
  2863. }
  2864. tokenStream.match(Tokens.IDENT);
  2865. functionText += tokenStream.token().value;
  2866. tokenStream.match(Tokens.EQUALS);
  2867. functionText += tokenStream.token().value;
  2868. lt = tokenStream.peek();
  2869. while(lt != Tokens.COMMA && lt != Tokens.S && lt != Tokens.RPAREN){
  2870. tokenStream.get();
  2871. functionText += tokenStream.token().value;
  2872. lt = tokenStream.peek();
  2873. }
  2874. } while(tokenStream.match([Tokens.COMMA, Tokens.S]));
  2875. tokenStream.match(Tokens.RPAREN);
  2876. functionText += ")";
  2877. this._readWhitespace();
  2878. }
  2879. return functionText;
  2880. },
  2881. _hexcolor: function(){
  2882. var tokenStream = this._tokenStream,
  2883. token = null,
  2884. color;
  2885. if(tokenStream.match(Tokens.HASH)){
  2886. token = tokenStream.token();
  2887. color = token.value;
  2888. if (!/#[a-f0-9]{3,6}/i.test(color)){
  2889. throw new SyntaxError("Expected a hex color but found '" + color + "' at line " + token.startLine + ", col " + token.startCol + ".", token.startLine, token.startCol);
  2890. }
  2891. this._readWhitespace();
  2892. }
  2893. return token;
  2894. },
  2895. _keyframes: function(){
  2896. var tokenStream = this._tokenStream,
  2897. token,
  2898. tt,
  2899. name,
  2900. prefix = "";
  2901. tokenStream.mustMatch(Tokens.KEYFRAMES_SYM);
  2902. token = tokenStream.token();
  2903. if (/^@\-([^\-]+)\-/.test(token.value)) {
  2904. prefix = RegExp.$1;
  2905. }
  2906. this._readWhitespace();
  2907. name = this._keyframe_name();
  2908. this._readWhitespace();
  2909. tokenStream.mustMatch(Tokens.LBRACE);
  2910. this.fire({
  2911. type: "startkeyframes",
  2912. name: name,
  2913. prefix: prefix,
  2914. line: token.startLine,
  2915. col: token.startCol
  2916. });
  2917. this._readWhitespace();
  2918. tt = tokenStream.peek();
  2919. while(tt == Tokens.IDENT || tt == Tokens.PERCENTAGE) {
  2920. this._keyframe_rule();
  2921. this._readWhitespace();
  2922. tt = tokenStream.peek();
  2923. }
  2924. this.fire({
  2925. type: "endkeyframes",
  2926. name: name,
  2927. prefix: prefix,
  2928. line: token.startLine,
  2929. col: token.startCol
  2930. });
  2931. this._readWhitespace();
  2932. tokenStream.mustMatch(Tokens.RBRACE);
  2933. },
  2934. _keyframe_name: function(){
  2935. var tokenStream = this._tokenStream,
  2936. token;
  2937. tokenStream.mustMatch([Tokens.IDENT, Tokens.STRING]);
  2938. return SyntaxUnit.fromToken(tokenStream.token());
  2939. },
  2940. _keyframe_rule: function(){
  2941. var tokenStream = this._tokenStream,
  2942. token,
  2943. keyList = this._key_list();
  2944. this.fire({
  2945. type: "startkeyframerule",
  2946. keys: keyList,
  2947. line: keyList[0].line,
  2948. col: keyList[0].col
  2949. });
  2950. this._readDeclarations(true);
  2951. this.fire({
  2952. type: "endkeyframerule",
  2953. keys: keyList,
  2954. line: keyList[0].line,
  2955. col: keyList[0].col
  2956. });
  2957. },
  2958. _key_list: function(){
  2959. var tokenStream = this._tokenStream,
  2960. token,
  2961. key,
  2962. keyList = [];
  2963. keyList.push(this._key());
  2964. this._readWhitespace();
  2965. while(tokenStream.match(Tokens.COMMA)){
  2966. this._readWhitespace();
  2967. keyList.push(this._key());
  2968. this._readWhitespace();
  2969. }
  2970. return keyList;
  2971. },
  2972. _key: function(){
  2973. var tokenStream = this._tokenStream,
  2974. token;
  2975. if (tokenStream.match(Tokens.PERCENTAGE)){
  2976. return SyntaxUnit.fromToken(tokenStream.token());
  2977. } else if (tokenStream.match(Tokens.IDENT)){
  2978. token = tokenStream.token();
  2979. if (/from|to/i.test(token.value)){
  2980. return SyntaxUnit.fromToken(token);
  2981. }
  2982. tokenStream.unget();
  2983. }
  2984. this._unexpectedToken(tokenStream.LT(1));
  2985. },
  2986. _skipCruft: function(){
  2987. while(this._tokenStream.match([Tokens.S, Tokens.CDO, Tokens.CDC])){
  2988. }
  2989. },
  2990. _readDeclarations: function(checkStart, readMargins){
  2991. var tokenStream = this._tokenStream,
  2992. tt;
  2993. this._readWhitespace();
  2994. if (checkStart){
  2995. tokenStream.mustMatch(Tokens.LBRACE);
  2996. }
  2997. this._readWhitespace();
  2998. try {
  2999. while(true){
  3000. if (tokenStream.match(Tokens.SEMICOLON) || (readMargins && this._margin())){
  3001. } else if (this._declaration()){
  3002. if (!tokenStream.match(Tokens.SEMICOLON)){
  3003. break;
  3004. }
  3005. } else {
  3006. break;
  3007. }
  3008. this._readWhitespace();
  3009. }
  3010. tokenStream.mustMatch(Tokens.RBRACE);
  3011. this._readWhitespace();
  3012. } catch (ex) {
  3013. if (ex instanceof SyntaxError && !this.options.strict){
  3014. this.fire({
  3015. type: "error",
  3016. error: ex,
  3017. message: ex.message,
  3018. line: ex.line,
  3019. col: ex.col
  3020. });
  3021. tt = tokenStream.advance([Tokens.SEMICOLON, Tokens.RBRACE]);
  3022. if (tt == Tokens.SEMICOLON){
  3023. this._readDeclarations(false, readMargins);
  3024. } else if (tt != Tokens.RBRACE){
  3025. throw ex;
  3026. }
  3027. } else {
  3028. throw ex;
  3029. }
  3030. }
  3031. },
  3032. _readWhitespace: function(){
  3033. var tokenStream = this._tokenStream,
  3034. ws = "";
  3035. while(tokenStream.match(Tokens.S)){
  3036. ws += tokenStream.token().value;
  3037. }
  3038. return ws;
  3039. },
  3040. _unexpectedToken: function(token){
  3041. throw new SyntaxError("Unexpected token '" + token.value + "' at line " + token.startLine + ", col " + token.startCol + ".", token.startLine, token.startCol);
  3042. },
  3043. _verifyEnd: function(){
  3044. if (this._tokenStream.LA(1) != Tokens.EOF){
  3045. this._unexpectedToken(this._tokenStream.LT(1));
  3046. }
  3047. },
  3048. _validateProperty: function(property, value){
  3049. Validation.validate(property, value);
  3050. },
  3051. parse: function(input){
  3052. this._tokenStream = new TokenStream(input, Tokens);
  3053. this._stylesheet();
  3054. },
  3055. parseStyleSheet: function(input){
  3056. return this.parse(input);
  3057. },
  3058. parseMediaQuery: function(input){
  3059. this._tokenStream = new TokenStream(input, Tokens);
  3060. var result = this._media_query();
  3061. this._verifyEnd();
  3062. return result;
  3063. },
  3064. parsePropertyValue: function(input){
  3065. this._tokenStream = new TokenStream(input, Tokens);
  3066. this._readWhitespace();
  3067. var result = this._expr();
  3068. this._readWhitespace();
  3069. this._verifyEnd();
  3070. return result;
  3071. },
  3072. parseRule: function(input){
  3073. this._tokenStream = new TokenStream(input, Tokens);
  3074. this._readWhitespace();
  3075. var result = this._ruleset();
  3076. this._readWhitespace();
  3077. this._verifyEnd();
  3078. return result;
  3079. },
  3080. parseSelector: function(input){
  3081. this._tokenStream = new TokenStream(input, Tokens);
  3082. this._readWhitespace();
  3083. var result = this._selector();
  3084. this._readWhitespace();
  3085. this._verifyEnd();
  3086. return result;
  3087. },
  3088. parseStyleAttribute: function(input){
  3089. input += "}"; // for error recovery in _readDeclarations()
  3090. this._tokenStream = new TokenStream(input, Tokens);
  3091. this._readDeclarations();
  3092. }
  3093. };
  3094. for (prop in additions){
  3095. if (additions.hasOwnProperty(prop)){
  3096. proto[prop] = additions[prop];
  3097. }
  3098. }
  3099. return proto;
  3100. }();
  3101. var Properties = {
  3102. "align-items" : "flex-start | flex-end | center | baseline | stretch",
  3103. "align-content" : "flex-start | flex-end | center | space-between | space-around | stretch",
  3104. "align-self" : "auto | flex-start | flex-end | center | baseline | stretch",
  3105. "-webkit-align-items" : "flex-start | flex-end | center | baseline | stretch",
  3106. "-webkit-align-content" : "flex-start | flex-end | center | space-between | space-around | stretch",
  3107. "-webkit-align-self" : "auto | flex-start | flex-end | center | baseline | stretch",
  3108. "alignment-adjust" : "auto | baseline | before-edge | text-before-edge | middle | central | after-edge | text-after-edge | ideographic | alphabetic | hanging | mathematical | <percentage> | <length>",
  3109. "alignment-baseline" : "baseline | use-script | before-edge | text-before-edge | after-edge | text-after-edge | central | middle | ideographic | alphabetic | hanging | mathematical",
  3110. "animation" : 1,
  3111. "animation-delay" : { multi: "<time>", comma: true },
  3112. "animation-direction" : { multi: "normal | reverse | alternate | alternate-reverse", comma: true },
  3113. "animation-duration" : { multi: "<time>", comma: true },
  3114. "animation-fill-mode" : { multi: "none | forwards | backwards | both", comma: true },
  3115. "animation-iteration-count" : { multi: "<number> | infinite", comma: true },
  3116. "animation-name" : { multi: "none | <ident>", comma: true },
  3117. "animation-play-state" : { multi: "running | paused", comma: true },
  3118. "animation-timing-function" : 1,
  3119. "-moz-animation-delay" : { multi: "<time>", comma: true },
  3120. "-moz-animation-direction" : { multi: "normal | reverse | alternate | alternate-reverse", comma: true },
  3121. "-moz-animation-duration" : { multi: "<time>", comma: true },
  3122. "-moz-animation-iteration-count" : { multi: "<number> | infinite", comma: true },
  3123. "-moz-animation-name" : { multi: "none | <ident>", comma: true },
  3124. "-moz-animation-play-state" : { multi: "running | paused", comma: true },
  3125. "-ms-animation-delay" : { multi: "<time>", comma: true },
  3126. "-ms-animation-direction" : { multi: "normal | reverse | alternate | alternate-reverse", comma: true },
  3127. "-ms-animation-duration" : { multi: "<time>", comma: true },
  3128. "-ms-animation-iteration-count" : { multi: "<number> | infinite", comma: true },
  3129. "-ms-animation-name" : { multi: "none | <ident>", comma: true },
  3130. "-ms-animation-play-state" : { multi: "running | paused", comma: true },
  3131. "-webkit-animation-delay" : { multi: "<time>", comma: true },
  3132. "-webkit-animation-direction" : { multi: "normal | reverse | alternate | alternate-reverse", comma: true },
  3133. "-webkit-animation-duration" : { multi: "<time>", comma: true },
  3134. "-webkit-animation-fill-mode" : { multi: "none | forwards | backwards | both", comma: true },
  3135. "-webkit-animation-iteration-count" : { multi: "<number> | infinite", comma: true },
  3136. "-webkit-animation-name" : { multi: "none | <ident>", comma: true },
  3137. "-webkit-animation-play-state" : { multi: "running | paused", comma: true },
  3138. "-o-animation-delay" : { multi: "<time>", comma: true },
  3139. "-o-animation-direction" : { multi: "normal | reverse | alternate | alternate-reverse", comma: true },
  3140. "-o-animation-duration" : { multi: "<time>", comma: true },
  3141. "-o-animation-iteration-count" : { multi: "<number> | infinite", comma: true },
  3142. "-o-animation-name" : { multi: "none | <ident>", comma: true },
  3143. "-o-animation-play-state" : { multi: "running | paused", comma: true },
  3144. "appearance" : "icon | window | desktop | workspace | document | tooltip | dialog | button | push-button | hyperlink | 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 | none | inherit",
  3145. "azimuth" : function (expression) {
  3146. var simple = "<angle> | leftwards | rightwards | inherit",
  3147. direction = "left-side | far-left | left | center-left | center | center-right | right | far-right | right-side",
  3148. behind = false,
  3149. valid = false,
  3150. part;
  3151. if (!ValidationTypes.isAny(expression, simple)) {
  3152. if (ValidationTypes.isAny(expression, "behind")) {
  3153. behind = true;
  3154. valid = true;
  3155. }
  3156. if (ValidationTypes.isAny(expression, direction)) {
  3157. valid = true;
  3158. if (!behind) {
  3159. ValidationTypes.isAny(expression, "behind");
  3160. }
  3161. }
  3162. }
  3163. if (expression.hasNext()) {
  3164. part = expression.next();
  3165. if (valid) {
  3166. throw new ValidationError("Expected end of value but found '" + part + "'.", part.line, part.col);
  3167. } else {
  3168. throw new ValidationError("Expected (<'azimuth'>) but found '" + part + "'.", part.line, part.col);
  3169. }
  3170. }
  3171. },
  3172. "backface-visibility" : "visible | hidden",
  3173. "background" : 1,
  3174. "background-attachment" : { multi: "<attachment>", comma: true },
  3175. "background-clip" : { multi: "<box>", comma: true },
  3176. "background-color" : "<color> | inherit",
  3177. "background-image" : { multi: "<bg-image>", comma: true },
  3178. "background-origin" : { multi: "<box>", comma: true },
  3179. "background-position" : { multi: "<bg-position>", comma: true },
  3180. "background-repeat" : { multi: "<repeat-style>" },
  3181. "background-size" : { multi: "<bg-size>", comma: true },
  3182. "baseline-shift" : "baseline | sub | super | <percentage> | <length>",
  3183. "behavior" : 1,
  3184. "binding" : 1,
  3185. "bleed" : "<length>",
  3186. "bookmark-label" : "<content> | <attr> | <string>",
  3187. "bookmark-level" : "none | <integer>",
  3188. "bookmark-state" : "open | closed",
  3189. "bookmark-target" : "none | <uri> | <attr>",
  3190. "border" : "<border-width> || <border-style> || <color>",
  3191. "border-bottom" : "<border-width> || <border-style> || <color>",
  3192. "border-bottom-color" : "<color> | inherit",
  3193. "border-bottom-left-radius" : "<x-one-radius>",
  3194. "border-bottom-right-radius" : "<x-one-radius>",
  3195. "border-bottom-style" : "<border-style>",
  3196. "border-bottom-width" : "<border-width>",
  3197. "border-collapse" : "collapse | separate | inherit",
  3198. "border-color" : { multi: "<color> | inherit", max: 4 },
  3199. "border-image" : 1,
  3200. "border-image-outset" : { multi: "<length> | <number>", max: 4 },
  3201. "border-image-repeat" : { multi: "stretch | repeat | round", max: 2 },
  3202. "border-image-slice" : function(expression) {
  3203. var valid = false,
  3204. numeric = "<number> | <percentage>",
  3205. fill = false,
  3206. count = 0,
  3207. max = 4,
  3208. part;
  3209. if (ValidationTypes.isAny(expression, "fill")) {
  3210. fill = true;
  3211. valid = true;
  3212. }
  3213. while (expression.hasNext() && count < max) {
  3214. valid = ValidationTypes.isAny(expression, numeric);
  3215. if (!valid) {
  3216. break;
  3217. }
  3218. count++;
  3219. }
  3220. if (!fill) {
  3221. ValidationTypes.isAny(expression, "fill");
  3222. } else {
  3223. valid = true;
  3224. }
  3225. if (expression.hasNext()) {
  3226. part = expression.next();
  3227. if (valid) {
  3228. throw new ValidationError("Expected end of value but found '" + part + "'.", part.line, part.col);
  3229. } else {
  3230. throw new ValidationError("Expected ([<number> | <percentage>]{1,4} && fill?) but found '" + part + "'.", part.line, part.col);
  3231. }
  3232. }
  3233. },
  3234. "border-image-source" : "<image> | none",
  3235. "border-image-width" : { multi: "<length> | <percentage> | <number> | auto", max: 4 },
  3236. "border-left" : "<border-width> || <border-style> || <color>",
  3237. "border-left-color" : "<color> | inherit",
  3238. "border-left-style" : "<border-style>",
  3239. "border-left-width" : "<border-width>",
  3240. "border-radius" : function(expression) {
  3241. var valid = false,
  3242. simple = "<length> | <percentage> | inherit",
  3243. slash = false,
  3244. fill = false,
  3245. count = 0,
  3246. max = 8,
  3247. part;
  3248. while (expression.hasNext() && count < max) {
  3249. valid = ValidationTypes.isAny(expression, simple);
  3250. if (!valid) {
  3251. if (expression.peek() == "/" && count > 0 && !slash) {
  3252. slash = true;
  3253. max = count + 5;
  3254. expression.next();
  3255. } else {
  3256. break;
  3257. }
  3258. }
  3259. count++;
  3260. }
  3261. if (expression.hasNext()) {
  3262. part = expression.next();
  3263. if (valid) {
  3264. throw new ValidationError("Expected end of value but found '" + part + "'.", part.line, part.col);
  3265. } else {
  3266. throw new ValidationError("Expected (<'border-radius'>) but found '" + part + "'.", part.line, part.col);
  3267. }
  3268. }
  3269. },
  3270. "border-right" : "<border-width> || <border-style> || <color>",
  3271. "border-right-color" : "<color> | inherit",
  3272. "border-right-style" : "<border-style>",
  3273. "border-right-width" : "<border-width>",
  3274. "border-spacing" : { multi: "<length> | inherit", max: 2 },
  3275. "border-style" : { multi: "<border-style>", max: 4 },
  3276. "border-top" : "<border-width> || <border-style> || <color>",
  3277. "border-top-color" : "<color> | inherit",
  3278. "border-top-left-radius" : "<x-one-radius>",
  3279. "border-top-right-radius" : "<x-one-radius>",
  3280. "border-top-style" : "<border-style>",
  3281. "border-top-width" : "<border-width>",
  3282. "border-width" : { multi: "<border-width>", max: 4 },
  3283. "bottom" : "<margin-width> | inherit",
  3284. "-moz-box-align" : "start | end | center | baseline | stretch",
  3285. "-moz-box-decoration-break" : "slice |clone",
  3286. "-moz-box-direction" : "normal | reverse | inherit",
  3287. "-moz-box-flex" : "<number>",
  3288. "-moz-box-flex-group" : "<integer>",
  3289. "-moz-box-lines" : "single | multiple",
  3290. "-moz-box-ordinal-group" : "<integer>",
  3291. "-moz-box-orient" : "horizontal | vertical | inline-axis | block-axis | inherit",
  3292. "-moz-box-pack" : "start | end | center | justify",
  3293. "-webkit-box-align" : "start | end | center | baseline | stretch",
  3294. "-webkit-box-decoration-break" : "slice |clone",
  3295. "-webkit-box-direction" : "normal | reverse | inherit",
  3296. "-webkit-box-flex" : "<number>",
  3297. "-webkit-box-flex-group" : "<integer>",
  3298. "-webkit-box-lines" : "single | multiple",
  3299. "-webkit-box-ordinal-group" : "<integer>",
  3300. "-webkit-box-orient" : "horizontal | vertical | inline-axis | block-axis | inherit",
  3301. "-webkit-box-pack" : "start | end | center | justify",
  3302. "box-shadow" : function (expression) {
  3303. var result = false,
  3304. part;
  3305. if (!ValidationTypes.isAny(expression, "none")) {
  3306. Validation.multiProperty("<shadow>", expression, true, Infinity);
  3307. } else {
  3308. if (expression.hasNext()) {
  3309. part = expression.next();
  3310. throw new ValidationError("Expected end of value but found '" + part + "'.", part.line, part.col);
  3311. }
  3312. }
  3313. },
  3314. "box-sizing" : "content-box | border-box | inherit",
  3315. "break-after" : "auto | always | avoid | left | right | page | column | avoid-page | avoid-column",
  3316. "break-before" : "auto | always | avoid | left | right | page | column | avoid-page | avoid-column",
  3317. "break-inside" : "auto | avoid | avoid-page | avoid-column",
  3318. "caption-side" : "top | bottom | inherit",
  3319. "clear" : "none | right | left | both | inherit",
  3320. "clip" : 1,
  3321. "color" : "<color> | inherit",
  3322. "color-profile" : 1,
  3323. "column-count" : "<integer> | auto", //http://www.w3.org/TR/css3-multicol/
  3324. "column-fill" : "auto | balance",
  3325. "column-gap" : "<length> | normal",
  3326. "column-rule" : "<border-width> || <border-style> || <color>",
  3327. "column-rule-color" : "<color>",
  3328. "column-rule-style" : "<border-style>",
  3329. "column-rule-width" : "<border-width>",
  3330. "column-span" : "none | all",
  3331. "column-width" : "<length> | auto",
  3332. "columns" : 1,
  3333. "content" : 1,
  3334. "counter-increment" : 1,
  3335. "counter-reset" : 1,
  3336. "crop" : "<shape> | auto",
  3337. "cue" : "cue-after | cue-before | inherit",
  3338. "cue-after" : 1,
  3339. "cue-before" : 1,
  3340. "cursor" : 1,
  3341. "direction" : "ltr | rtl | inherit",
  3342. "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 | none | inherit | -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",
  3343. "dominant-baseline" : 1,
  3344. "drop-initial-after-adjust" : "central | middle | after-edge | text-after-edge | ideographic | alphabetic | mathematical | <percentage> | <length>",
  3345. "drop-initial-after-align" : "baseline | use-script | before-edge | text-before-edge | after-edge | text-after-edge | central | middle | ideographic | alphabetic | hanging | mathematical",
  3346. "drop-initial-before-adjust" : "before-edge | text-before-edge | central | middle | hanging | mathematical | <percentage> | <length>",
  3347. "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",
  3348. "drop-initial-size" : "auto | line | <length> | <percentage>",
  3349. "drop-initial-value" : "initial | <integer>",
  3350. "elevation" : "<angle> | below | level | above | higher | lower | inherit",
  3351. "empty-cells" : "show | hide | inherit",
  3352. "filter" : 1,
  3353. "fit" : "fill | hidden | meet | slice",
  3354. "fit-position" : 1,
  3355. "flex" : "<flex>",
  3356. "flex-basis" : "<width>",
  3357. "flex-direction" : "row | row-reverse | column | column-reverse",
  3358. "flex-flow" : "<flex-direction> || <flex-wrap>",
  3359. "flex-grow" : "<number>",
  3360. "flex-shrink" : "<number>",
  3361. "flex-wrap" : "nowrap | wrap | wrap-reverse",
  3362. "-webkit-flex" : "<flex>",
  3363. "-webkit-flex-basis" : "<width>",
  3364. "-webkit-flex-direction" : "row | row-reverse | column | column-reverse",
  3365. "-webkit-flex-flow" : "<flex-direction> || <flex-wrap>",
  3366. "-webkit-flex-grow" : "<number>",
  3367. "-webkit-flex-shrink" : "<number>",
  3368. "-webkit-flex-wrap" : "nowrap | wrap | wrap-reverse",
  3369. "-ms-flex" : "<flex>",
  3370. "-ms-flex-align" : "start | end | center | stretch | baseline",
  3371. "-ms-flex-direction" : "row | row-reverse | column | column-reverse | inherit",
  3372. "-ms-flex-order" : "<number>",
  3373. "-ms-flex-pack" : "start | end | center | justify",
  3374. "-ms-flex-wrap" : "nowrap | wrap | wrap-reverse",
  3375. "float" : "left | right | none | inherit",
  3376. "float-offset" : 1,
  3377. "font" : 1,
  3378. "font-family" : 1,
  3379. "font-size" : "<absolute-size> | <relative-size> | <length> | <percentage> | inherit",
  3380. "font-size-adjust" : "<number> | none | inherit",
  3381. "font-stretch" : "normal | ultra-condensed | extra-condensed | condensed | semi-condensed | semi-expanded | expanded | extra-expanded | ultra-expanded | inherit",
  3382. "font-style" : "normal | italic | oblique | inherit",
  3383. "font-variant" : "normal | small-caps | inherit",
  3384. "font-weight" : "normal | bold | bolder | lighter | 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900 | inherit",
  3385. "grid-cell-stacking" : "columns | rows | layer",
  3386. "grid-column" : 1,
  3387. "grid-columns" : 1,
  3388. "grid-column-align" : "start | end | center | stretch",
  3389. "grid-column-sizing" : 1,
  3390. "grid-column-span" : "<integer>",
  3391. "grid-flow" : "none | rows | columns",
  3392. "grid-layer" : "<integer>",
  3393. "grid-row" : 1,
  3394. "grid-rows" : 1,
  3395. "grid-row-align" : "start | end | center | stretch",
  3396. "grid-row-gap" : 1,
  3397. "grid-row-span" : "<integer>",
  3398. "grid-row-sizing" : 1,
  3399. "grid-template" : 1,
  3400. "grid-template-areas" : 1,
  3401. "grid-template-columns" : 1,
  3402. "grid-template-rows" : 1,
  3403. "hanging-punctuation" : 1,
  3404. "height" : "<margin-width> | <content-sizing> | inherit",
  3405. "hyphenate-after" : "<integer> | auto",
  3406. "hyphenate-before" : "<integer> | auto",
  3407. "hyphenate-character" : "<string> | auto",
  3408. "hyphenate-lines" : "no-limit | <integer>",
  3409. "hyphenate-resource" : 1,
  3410. "hyphens" : "none | manual | auto",
  3411. "icon" : 1,
  3412. "image-orientation" : "angle | auto",
  3413. "image-rendering" : 1,
  3414. "image-resolution" : 1,
  3415. "inline-box-align" : "initial | last | <integer>",
  3416. "justify-content" : "flex-start | flex-end | center | space-between | space-around",
  3417. "-webkit-justify-content" : "flex-start | flex-end | center | space-between | space-around",
  3418. "left" : "<margin-width> | inherit",
  3419. "letter-spacing" : "<length> | normal | inherit",
  3420. "line-height" : "<number> | <length> | <percentage> | normal | inherit",
  3421. "line-break" : "auto | loose | normal | strict",
  3422. "line-stacking" : 1,
  3423. "line-stacking-ruby" : "exclude-ruby | include-ruby",
  3424. "line-stacking-shift" : "consider-shifts | disregard-shifts",
  3425. "line-stacking-strategy" : "inline-line-height | block-line-height | max-height | grid-height",
  3426. "list-style" : 1,
  3427. "list-style-image" : "<uri> | none | inherit",
  3428. "list-style-position" : "inside | outside | inherit",
  3429. "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 | inherit",
  3430. "margin" : { multi: "<margin-width> | inherit", max: 4 },
  3431. "margin-bottom" : "<margin-width> | inherit",
  3432. "margin-left" : "<margin-width> | inherit",
  3433. "margin-right" : "<margin-width> | inherit",
  3434. "margin-top" : "<margin-width> | inherit",
  3435. "mark" : 1,
  3436. "mark-after" : 1,
  3437. "mark-before" : 1,
  3438. "marks" : 1,
  3439. "marquee-direction" : 1,
  3440. "marquee-play-count" : 1,
  3441. "marquee-speed" : 1,
  3442. "marquee-style" : 1,
  3443. "max-height" : "<length> | <percentage> | <content-sizing> | none | inherit",
  3444. "max-width" : "<length> | <percentage> | <content-sizing> | none | inherit",
  3445. "max-zoom" : "<number> | <percentage> | auto",
  3446. "min-height" : "<length> | <percentage> | <content-sizing> | contain-floats | -moz-contain-floats | -webkit-contain-floats | inherit",
  3447. "min-width" : "<length> | <percentage> | <content-sizing> | contain-floats | -moz-contain-floats | -webkit-contain-floats | inherit",
  3448. "min-zoom" : "<number> | <percentage> | auto",
  3449. "move-to" : 1,
  3450. "nav-down" : 1,
  3451. "nav-index" : 1,
  3452. "nav-left" : 1,
  3453. "nav-right" : 1,
  3454. "nav-up" : 1,
  3455. "opacity" : "<number> | inherit",
  3456. "order" : "<integer>",
  3457. "-webkit-order" : "<integer>",
  3458. "orphans" : "<integer> | inherit",
  3459. "outline" : 1,
  3460. "outline-color" : "<color> | invert | inherit",
  3461. "outline-offset" : 1,
  3462. "outline-style" : "<border-style> | inherit",
  3463. "outline-width" : "<border-width> | inherit",
  3464. "overflow" : "visible | hidden | scroll | auto | inherit",
  3465. "overflow-style" : 1,
  3466. "overflow-wrap" : "normal | break-word",
  3467. "overflow-x" : 1,
  3468. "overflow-y" : 1,
  3469. "padding" : { multi: "<padding-width> | inherit", max: 4 },
  3470. "padding-bottom" : "<padding-width> | inherit",
  3471. "padding-left" : "<padding-width> | inherit",
  3472. "padding-right" : "<padding-width> | inherit",
  3473. "padding-top" : "<padding-width> | inherit",
  3474. "page" : 1,
  3475. "page-break-after" : "auto | always | avoid | left | right | inherit",
  3476. "page-break-before" : "auto | always | avoid | left | right | inherit",
  3477. "page-break-inside" : "auto | avoid | inherit",
  3478. "page-policy" : 1,
  3479. "pause" : 1,
  3480. "pause-after" : 1,
  3481. "pause-before" : 1,
  3482. "perspective" : 1,
  3483. "perspective-origin" : 1,
  3484. "phonemes" : 1,
  3485. "pitch" : 1,
  3486. "pitch-range" : 1,
  3487. "play-during" : 1,
  3488. "pointer-events" : "auto | none | visiblePainted | visibleFill | visibleStroke | visible | painted | fill | stroke | all | inherit",
  3489. "position" : "static | relative | absolute | fixed | inherit",
  3490. "presentation-level" : 1,
  3491. "punctuation-trim" : 1,
  3492. "quotes" : 1,
  3493. "rendering-intent" : 1,
  3494. "resize" : 1,
  3495. "rest" : 1,
  3496. "rest-after" : 1,
  3497. "rest-before" : 1,
  3498. "richness" : 1,
  3499. "right" : "<margin-width> | inherit",
  3500. "rotation" : 1,
  3501. "rotation-point" : 1,
  3502. "ruby-align" : 1,
  3503. "ruby-overhang" : 1,
  3504. "ruby-position" : 1,
  3505. "ruby-span" : 1,
  3506. "size" : 1,
  3507. "speak" : "normal | none | spell-out | inherit",
  3508. "speak-header" : "once | always | inherit",
  3509. "speak-numeral" : "digits | continuous | inherit",
  3510. "speak-punctuation" : "code | none | inherit",
  3511. "speech-rate" : 1,
  3512. "src" : 1,
  3513. "stress" : 1,
  3514. "string-set" : 1,
  3515. "table-layout" : "auto | fixed | inherit",
  3516. "tab-size" : "<integer> | <length>",
  3517. "target" : 1,
  3518. "target-name" : 1,
  3519. "target-new" : 1,
  3520. "target-position" : 1,
  3521. "text-align" : "left | right | center | justify | inherit" ,
  3522. "text-align-last" : 1,
  3523. "text-decoration" : 1,
  3524. "text-emphasis" : 1,
  3525. "text-height" : 1,
  3526. "text-indent" : "<length> | <percentage> | inherit",
  3527. "text-justify" : "auto | none | inter-word | inter-ideograph | inter-cluster | distribute | kashida",
  3528. "text-outline" : 1,
  3529. "text-overflow" : 1,
  3530. "text-rendering" : "auto | optimizeSpeed | optimizeLegibility | geometricPrecision | inherit",
  3531. "text-shadow" : 1,
  3532. "text-transform" : "capitalize | uppercase | lowercase | none | inherit",
  3533. "text-wrap" : "normal | none | avoid",
  3534. "top" : "<margin-width> | inherit",
  3535. "-ms-touch-action" : "auto | none | pan-x | pan-y",
  3536. "touch-action" : "auto | none | pan-x | pan-y",
  3537. "transform" : 1,
  3538. "transform-origin" : 1,
  3539. "transform-style" : 1,
  3540. "transition" : 1,
  3541. "transition-delay" : 1,
  3542. "transition-duration" : 1,
  3543. "transition-property" : 1,
  3544. "transition-timing-function" : 1,
  3545. "unicode-bidi" : "normal | embed | isolate | bidi-override | isolate-override | plaintext | inherit",
  3546. "user-modify" : "read-only | read-write | write-only | inherit",
  3547. "user-select" : "none | text | toggle | element | elements | all | inherit",
  3548. "user-zoom" : "zoom | fixed",
  3549. "vertical-align" : "auto | use-script | baseline | sub | super | top | text-top | central | middle | bottom | text-bottom | <percentage> | <length>",
  3550. "visibility" : "visible | hidden | collapse | inherit",
  3551. "voice-balance" : 1,
  3552. "voice-duration" : 1,
  3553. "voice-family" : 1,
  3554. "voice-pitch" : 1,
  3555. "voice-pitch-range" : 1,
  3556. "voice-rate" : 1,
  3557. "voice-stress" : 1,
  3558. "voice-volume" : 1,
  3559. "volume" : 1,
  3560. "white-space" : "normal | pre | nowrap | pre-wrap | pre-line | inherit | -pre-wrap | -o-pre-wrap | -moz-pre-wrap | -hp-pre-wrap", //http://perishablepress.com/wrapping-content/
  3561. "white-space-collapse" : 1,
  3562. "widows" : "<integer> | inherit",
  3563. "width" : "<length> | <percentage> | <content-sizing> | auto | inherit",
  3564. "word-break" : "normal | keep-all | break-all",
  3565. "word-spacing" : "<length> | normal | inherit",
  3566. "word-wrap" : "normal | break-word",
  3567. "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 | inherit",
  3568. "z-index" : "<integer> | auto | inherit",
  3569. "zoom" : "<number> | <percentage> | normal"
  3570. };
  3571. function PropertyName(text, hack, line, col){
  3572. SyntaxUnit.call(this, text, line, col, Parser.PROPERTY_NAME_TYPE);
  3573. this.hack = hack;
  3574. }
  3575. PropertyName.prototype = new SyntaxUnit();
  3576. PropertyName.prototype.constructor = PropertyName;
  3577. PropertyName.prototype.toString = function(){
  3578. return (this.hack ? this.hack : "") + this.text;
  3579. };
  3580. function PropertyValue(parts, line, col){
  3581. SyntaxUnit.call(this, parts.join(" "), line, col, Parser.PROPERTY_VALUE_TYPE);
  3582. this.parts = parts;
  3583. }
  3584. PropertyValue.prototype = new SyntaxUnit();
  3585. PropertyValue.prototype.constructor = PropertyValue;
  3586. function PropertyValueIterator(value){
  3587. this._i = 0;
  3588. this._parts = value.parts;
  3589. this._marks = [];
  3590. this.value = value;
  3591. }
  3592. PropertyValueIterator.prototype.count = function(){
  3593. return this._parts.length;
  3594. };
  3595. PropertyValueIterator.prototype.isFirst = function(){
  3596. return this._i === 0;
  3597. };
  3598. PropertyValueIterator.prototype.hasNext = function(){
  3599. return (this._i < this._parts.length);
  3600. };
  3601. PropertyValueIterator.prototype.mark = function(){
  3602. this._marks.push(this._i);
  3603. };
  3604. PropertyValueIterator.prototype.peek = function(count){
  3605. return this.hasNext() ? this._parts[this._i + (count || 0)] : null;
  3606. };
  3607. PropertyValueIterator.prototype.next = function(){
  3608. return this.hasNext() ? this._parts[this._i++] : null;
  3609. };
  3610. PropertyValueIterator.prototype.previous = function(){
  3611. return this._i > 0 ? this._parts[--this._i] : null;
  3612. };
  3613. PropertyValueIterator.prototype.restore = function(){
  3614. if (this._marks.length){
  3615. this._i = this._marks.pop();
  3616. }
  3617. };
  3618. function PropertyValuePart(text, line, col){
  3619. SyntaxUnit.call(this, text, line, col, Parser.PROPERTY_VALUE_PART_TYPE);
  3620. this.type = "unknown";
  3621. var temp;
  3622. if (/^([+\-]?[\d\.]+)([a-z]+)$/i.test(text)){ //dimension
  3623. this.type = "dimension";
  3624. this.value = +RegExp.$1;
  3625. this.units = RegExp.$2;
  3626. switch(this.units.toLowerCase()){
  3627. case "em":
  3628. case "rem":
  3629. case "ex":
  3630. case "px":
  3631. case "cm":
  3632. case "mm":
  3633. case "in":
  3634. case "pt":
  3635. case "pc":
  3636. case "ch":
  3637. case "vh":
  3638. case "vw":
  3639. case "fr":
  3640. case "vmax":
  3641. case "vmin":
  3642. this.type = "length";
  3643. break;
  3644. case "deg":
  3645. case "rad":
  3646. case "grad":
  3647. this.type = "angle";
  3648. break;
  3649. case "ms":
  3650. case "s":
  3651. this.type = "time";
  3652. break;
  3653. case "hz":
  3654. case "khz":
  3655. this.type = "frequency";
  3656. break;
  3657. case "dpi":
  3658. case "dpcm":
  3659. this.type = "resolution";
  3660. break;
  3661. }
  3662. } else if (/^([+\-]?[\d\.]+)%$/i.test(text)){ //percentage
  3663. this.type = "percentage";
  3664. this.value = +RegExp.$1;
  3665. } else if (/^([+\-]?\d+)$/i.test(text)){ //integer
  3666. this.type = "integer";
  3667. this.value = +RegExp.$1;
  3668. } else if (/^([+\-]?[\d\.]+)$/i.test(text)){ //number
  3669. this.type = "number";
  3670. this.value = +RegExp.$1;
  3671. } else if (/^#([a-f0-9]{3,6})/i.test(text)){ //hexcolor
  3672. this.type = "color";
  3673. temp = RegExp.$1;
  3674. if (temp.length == 3){
  3675. this.red = parseInt(temp.charAt(0)+temp.charAt(0),16);
  3676. this.green = parseInt(temp.charAt(1)+temp.charAt(1),16);
  3677. this.blue = parseInt(temp.charAt(2)+temp.charAt(2),16);
  3678. } else {
  3679. this.red = parseInt(temp.substring(0,2),16);
  3680. this.green = parseInt(temp.substring(2,4),16);
  3681. this.blue = parseInt(temp.substring(4,6),16);
  3682. }
  3683. } else if (/^rgb\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)/i.test(text)){ //rgb() color with absolute numbers
  3684. this.type = "color";
  3685. this.red = +RegExp.$1;
  3686. this.green = +RegExp.$2;
  3687. this.blue = +RegExp.$3;
  3688. } else if (/^rgb\(\s*(\d+)%\s*,\s*(\d+)%\s*,\s*(\d+)%\s*\)/i.test(text)){ //rgb() color with percentages
  3689. this.type = "color";
  3690. this.red = +RegExp.$1 * 255 / 100;
  3691. this.green = +RegExp.$2 * 255 / 100;
  3692. this.blue = +RegExp.$3 * 255 / 100;
  3693. } else if (/^rgba\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*,\s*([\d\.]+)\s*\)/i.test(text)){ //rgba() color with absolute numbers
  3694. this.type = "color";
  3695. this.red = +RegExp.$1;
  3696. this.green = +RegExp.$2;
  3697. this.blue = +RegExp.$3;
  3698. this.alpha = +RegExp.$4;
  3699. } else if (/^rgba\(\s*(\d+)%\s*,\s*(\d+)%\s*,\s*(\d+)%\s*,\s*([\d\.]+)\s*\)/i.test(text)){ //rgba() color with percentages
  3700. this.type = "color";
  3701. this.red = +RegExp.$1 * 255 / 100;
  3702. this.green = +RegExp.$2 * 255 / 100;
  3703. this.blue = +RegExp.$3 * 255 / 100;
  3704. this.alpha = +RegExp.$4;
  3705. } else if (/^hsl\(\s*(\d+)\s*,\s*(\d+)%\s*,\s*(\d+)%\s*\)/i.test(text)){ //hsl()
  3706. this.type = "color";
  3707. this.hue = +RegExp.$1;
  3708. this.saturation = +RegExp.$2 / 100;
  3709. this.lightness = +RegExp.$3 / 100;
  3710. } else if (/^hsla\(\s*(\d+)\s*,\s*(\d+)%\s*,\s*(\d+)%\s*,\s*([\d\.]+)\s*\)/i.test(text)){ //hsla() color with percentages
  3711. this.type = "color";
  3712. this.hue = +RegExp.$1;
  3713. this.saturation = +RegExp.$2 / 100;
  3714. this.lightness = +RegExp.$3 / 100;
  3715. this.alpha = +RegExp.$4;
  3716. } else if (/^url\(["']?([^\)"']+)["']?\)/i.test(text)){ //URI
  3717. this.type = "uri";
  3718. this.uri = RegExp.$1;
  3719. } else if (/^([^\(]+)\(/i.test(text)){
  3720. this.type = "function";
  3721. this.name = RegExp.$1;
  3722. this.value = text;
  3723. } else if (/^["'][^"']*["']/.test(text)){ //string
  3724. this.type = "string";
  3725. this.value = eval(text);
  3726. } else if (Colors[text.toLowerCase()]){ //named color
  3727. this.type = "color";
  3728. temp = Colors[text.toLowerCase()].substring(1);
  3729. this.red = parseInt(temp.substring(0,2),16);
  3730. this.green = parseInt(temp.substring(2,4),16);
  3731. this.blue = parseInt(temp.substring(4,6),16);
  3732. } else if (/^[\,\/]$/.test(text)){
  3733. this.type = "operator";
  3734. this.value = text;
  3735. } else if (/^[a-z\-_\u0080-\uFFFF][a-z0-9\-_\u0080-\uFFFF]*$/i.test(text)){
  3736. this.type = "identifier";
  3737. this.value = text;
  3738. }
  3739. }
  3740. PropertyValuePart.prototype = new SyntaxUnit();
  3741. PropertyValuePart.prototype.constructor = PropertyValuePart;
  3742. PropertyValuePart.fromToken = function(token){
  3743. return new PropertyValuePart(token.value, token.startLine, token.startCol);
  3744. };
  3745. var Pseudos = {
  3746. ":first-letter": 1,
  3747. ":first-line": 1,
  3748. ":before": 1,
  3749. ":after": 1
  3750. };
  3751. Pseudos.ELEMENT = 1;
  3752. Pseudos.CLASS = 2;
  3753. Pseudos.isElement = function(pseudo){
  3754. return pseudo.indexOf("::") === 0 || Pseudos[pseudo.toLowerCase()] == Pseudos.ELEMENT;
  3755. };
  3756. function Selector(parts, line, col){
  3757. SyntaxUnit.call(this, parts.join(" "), line, col, Parser.SELECTOR_TYPE);
  3758. this.parts = parts;
  3759. this.specificity = Specificity.calculate(this);
  3760. }
  3761. Selector.prototype = new SyntaxUnit();
  3762. Selector.prototype.constructor = Selector;
  3763. function SelectorPart(elementName, modifiers, text, line, col){
  3764. SyntaxUnit.call(this, text, line, col, Parser.SELECTOR_PART_TYPE);
  3765. this.elementName = elementName;
  3766. this.modifiers = modifiers;
  3767. }
  3768. SelectorPart.prototype = new SyntaxUnit();
  3769. SelectorPart.prototype.constructor = SelectorPart;
  3770. function SelectorSubPart(text, type, line, col){
  3771. SyntaxUnit.call(this, text, line, col, Parser.SELECTOR_SUB_PART_TYPE);
  3772. this.type = type;
  3773. this.args = [];
  3774. }
  3775. SelectorSubPart.prototype = new SyntaxUnit();
  3776. SelectorSubPart.prototype.constructor = SelectorSubPart;
  3777. function Specificity(a, b, c, d){
  3778. this.a = a;
  3779. this.b = b;
  3780. this.c = c;
  3781. this.d = d;
  3782. }
  3783. Specificity.prototype = {
  3784. constructor: Specificity,
  3785. compare: function(other){
  3786. var comps = ["a", "b", "c", "d"],
  3787. i, len;
  3788. for (i=0, len=comps.length; i < len; i++){
  3789. if (this[comps[i]] < other[comps[i]]){
  3790. return -1;
  3791. } else if (this[comps[i]] > other[comps[i]]){
  3792. return 1;
  3793. }
  3794. }
  3795. return 0;
  3796. },
  3797. valueOf: function(){
  3798. return (this.a * 1000) + (this.b * 100) + (this.c * 10) + this.d;
  3799. },
  3800. toString: function(){
  3801. return this.a + "," + this.b + "," + this.c + "," + this.d;
  3802. }
  3803. };
  3804. Specificity.calculate = function(selector){
  3805. var i, len,
  3806. part,
  3807. b=0, c=0, d=0;
  3808. function updateValues(part){
  3809. var i, j, len, num,
  3810. elementName = part.elementName ? part.elementName.text : "",
  3811. modifier;
  3812. if (elementName && elementName.charAt(elementName.length-1) != "*") {
  3813. d++;
  3814. }
  3815. for (i=0, len=part.modifiers.length; i < len; i++){
  3816. modifier = part.modifiers[i];
  3817. switch(modifier.type){
  3818. case "class":
  3819. case "attribute":
  3820. c++;
  3821. break;
  3822. case "id":
  3823. b++;
  3824. break;
  3825. case "pseudo":
  3826. if (Pseudos.isElement(modifier.text)){
  3827. d++;
  3828. } else {
  3829. c++;
  3830. }
  3831. break;
  3832. case "not":
  3833. for (j=0, num=modifier.args.length; j < num; j++){
  3834. updateValues(modifier.args[j]);
  3835. }
  3836. }
  3837. }
  3838. }
  3839. for (i=0, len=selector.parts.length; i < len; i++){
  3840. part = selector.parts[i];
  3841. if (part instanceof SelectorPart){
  3842. updateValues(part);
  3843. }
  3844. }
  3845. return new Specificity(0, b, c, d);
  3846. };
  3847. var h = /^[0-9a-fA-F]$/,
  3848. nonascii = /^[\u0080-\uFFFF]$/,
  3849. nl = /\n|\r\n|\r|\f/;
  3850. function isHexDigit(c){
  3851. return c !== null && h.test(c);
  3852. }
  3853. function isDigit(c){
  3854. return c !== null && /\d/.test(c);
  3855. }
  3856. function isWhitespace(c){
  3857. return c !== null && /\s/.test(c);
  3858. }
  3859. function isNewLine(c){
  3860. return c !== null && nl.test(c);
  3861. }
  3862. function isNameStart(c){
  3863. return c !== null && (/[a-z_\u0080-\uFFFF\\]/i.test(c));
  3864. }
  3865. function isNameChar(c){
  3866. return c !== null && (isNameStart(c) || /[0-9\-\\]/.test(c));
  3867. }
  3868. function isIdentStart(c){
  3869. return c !== null && (isNameStart(c) || /\-\\/.test(c));
  3870. }
  3871. function mix(receiver, supplier){
  3872. for (var prop in supplier){
  3873. if (supplier.hasOwnProperty(prop)){
  3874. receiver[prop] = supplier[prop];
  3875. }
  3876. }
  3877. return receiver;
  3878. }
  3879. function TokenStream(input){
  3880. TokenStreamBase.call(this, input, Tokens);
  3881. }
  3882. TokenStream.prototype = mix(new TokenStreamBase(), {
  3883. _getToken: function(channel){
  3884. var c,
  3885. reader = this._reader,
  3886. token = null,
  3887. startLine = reader.getLine(),
  3888. startCol = reader.getCol();
  3889. c = reader.read();
  3890. while(c){
  3891. switch(c){
  3892. case "/":
  3893. if(reader.peek() == "*"){
  3894. token = this.commentToken(c, startLine, startCol);
  3895. } else {
  3896. token = this.charToken(c, startLine, startCol);
  3897. }
  3898. break;
  3899. case "|":
  3900. case "~":
  3901. case "^":
  3902. case "$":
  3903. case "*":
  3904. if(reader.peek() == "="){
  3905. token = this.comparisonToken(c, startLine, startCol);
  3906. } else {
  3907. token = this.charToken(c, startLine, startCol);
  3908. }
  3909. break;
  3910. case "\"":
  3911. case "'":
  3912. token = this.stringToken(c, startLine, startCol);
  3913. break;
  3914. case "#":
  3915. if (isNameChar(reader.peek())){
  3916. token = this.hashToken(c, startLine, startCol);
  3917. } else {
  3918. token = this.charToken(c, startLine, startCol);
  3919. }
  3920. break;
  3921. case ".":
  3922. if (isDigit(reader.peek())){
  3923. token = this.numberToken(c, startLine, startCol);
  3924. } else {
  3925. token = this.charToken(c, startLine, startCol);
  3926. }
  3927. break;
  3928. case "-":
  3929. if (reader.peek() == "-"){ //could be closing HTML-style comment
  3930. token = this.htmlCommentEndToken(c, startLine, startCol);
  3931. } else if (isNameStart(reader.peek())){
  3932. token = this.identOrFunctionToken(c, startLine, startCol);
  3933. } else {
  3934. token = this.charToken(c, startLine, startCol);
  3935. }
  3936. break;
  3937. case "!":
  3938. token = this.importantToken(c, startLine, startCol);
  3939. break;
  3940. case "@":
  3941. token = this.atRuleToken(c, startLine, startCol);
  3942. break;
  3943. case ":":
  3944. token = this.notToken(c, startLine, startCol);
  3945. break;
  3946. case "<":
  3947. token = this.htmlCommentStartToken(c, startLine, startCol);
  3948. break;
  3949. case "U":
  3950. case "u":
  3951. if (reader.peek() == "+"){
  3952. token = this.unicodeRangeToken(c, startLine, startCol);
  3953. break;
  3954. }
  3955. default:
  3956. if (isDigit(c)){
  3957. token = this.numberToken(c, startLine, startCol);
  3958. } else
  3959. if (isWhitespace(c)){
  3960. token = this.whitespaceToken(c, startLine, startCol);
  3961. } else
  3962. if (isIdentStart(c)){
  3963. token = this.identOrFunctionToken(c, startLine, startCol);
  3964. } else
  3965. {
  3966. token = this.charToken(c, startLine, startCol);
  3967. }
  3968. }
  3969. break;
  3970. }
  3971. if (!token && c === null){
  3972. token = this.createToken(Tokens.EOF,null,startLine,startCol);
  3973. }
  3974. return token;
  3975. },
  3976. createToken: function(tt, value, startLine, startCol, options){
  3977. var reader = this._reader;
  3978. options = options || {};
  3979. return {
  3980. value: value,
  3981. type: tt,
  3982. channel: options.channel,
  3983. endChar: options.endChar,
  3984. hide: options.hide || false,
  3985. startLine: startLine,
  3986. startCol: startCol,
  3987. endLine: reader.getLine(),
  3988. endCol: reader.getCol()
  3989. };
  3990. },
  3991. atRuleToken: function(first, startLine, startCol){
  3992. var rule = first,
  3993. reader = this._reader,
  3994. tt = Tokens.CHAR,
  3995. valid = false,
  3996. ident,
  3997. c;
  3998. reader.mark();
  3999. ident = this.readName();
  4000. rule = first + ident;
  4001. tt = Tokens.type(rule.toLowerCase());
  4002. if (tt == Tokens.CHAR || tt == Tokens.UNKNOWN){
  4003. if (rule.length > 1){
  4004. tt = Tokens.UNKNOWN_SYM;
  4005. } else {
  4006. tt = Tokens.CHAR;
  4007. rule = first;
  4008. reader.reset();
  4009. }
  4010. }
  4011. return this.createToken(tt, rule, startLine, startCol);
  4012. },
  4013. charToken: function(c, startLine, startCol){
  4014. var tt = Tokens.type(c);
  4015. var opts = {};
  4016. if (tt == -1){
  4017. tt = Tokens.CHAR;
  4018. } else {
  4019. opts.endChar = Tokens[tt].endChar;
  4020. }
  4021. return this.createToken(tt, c, startLine, startCol, opts);
  4022. },
  4023. commentToken: function(first, startLine, startCol){
  4024. var reader = this._reader,
  4025. comment = this.readComment(first);
  4026. return this.createToken(Tokens.COMMENT, comment, startLine, startCol);
  4027. },
  4028. comparisonToken: function(c, startLine, startCol){
  4029. var reader = this._reader,
  4030. comparison = c + reader.read(),
  4031. tt = Tokens.type(comparison) || Tokens.CHAR;
  4032. return this.createToken(tt, comparison, startLine, startCol);
  4033. },
  4034. hashToken: function(first, startLine, startCol){
  4035. var reader = this._reader,
  4036. name = this.readName(first);
  4037. return this.createToken(Tokens.HASH, name, startLine, startCol);
  4038. },
  4039. htmlCommentStartToken: function(first, startLine, startCol){
  4040. var reader = this._reader,
  4041. text = first;
  4042. reader.mark();
  4043. text += reader.readCount(3);
  4044. if (text == "<!--"){
  4045. return this.createToken(Tokens.CDO, text, startLine, startCol);
  4046. } else {
  4047. reader.reset();
  4048. return this.charToken(first, startLine, startCol);
  4049. }
  4050. },
  4051. htmlCommentEndToken: function(first, startLine, startCol){
  4052. var reader = this._reader,
  4053. text = first;
  4054. reader.mark();
  4055. text += reader.readCount(2);
  4056. if (text == "-->"){
  4057. return this.createToken(Tokens.CDC, text, startLine, startCol);
  4058. } else {
  4059. reader.reset();
  4060. return this.charToken(first, startLine, startCol);
  4061. }
  4062. },
  4063. identOrFunctionToken: function(first, startLine, startCol){
  4064. var reader = this._reader,
  4065. ident = this.readName(first),
  4066. tt = Tokens.IDENT;
  4067. if (reader.peek() == "("){
  4068. ident += reader.read();
  4069. if (ident.toLowerCase() == "url("){
  4070. tt = Tokens.URI;
  4071. ident = this.readURI(ident);
  4072. if (ident.toLowerCase() == "url("){
  4073. tt = Tokens.FUNCTION;
  4074. }
  4075. } else {
  4076. tt = Tokens.FUNCTION;
  4077. }
  4078. } else if (reader.peek() == ":"){ //might be an IE function
  4079. if (ident.toLowerCase() == "progid"){
  4080. ident += reader.readTo("(");
  4081. tt = Tokens.IE_FUNCTION;
  4082. }
  4083. }
  4084. return this.createToken(tt, ident, startLine, startCol);
  4085. },
  4086. importantToken: function(first, startLine, startCol){
  4087. var reader = this._reader,
  4088. important = first,
  4089. tt = Tokens.CHAR,
  4090. temp,
  4091. c;
  4092. reader.mark();
  4093. c = reader.read();
  4094. while(c){
  4095. if (c == "/"){
  4096. if (reader.peek() != "*"){
  4097. break;
  4098. } else {
  4099. temp = this.readComment(c);
  4100. if (temp === ""){ //broken!
  4101. break;
  4102. }
  4103. }
  4104. } else if (isWhitespace(c)){
  4105. important += c + this.readWhitespace();
  4106. } else if (/i/i.test(c)){
  4107. temp = reader.readCount(8);
  4108. if (/mportant/i.test(temp)){
  4109. important += c + temp;
  4110. tt = Tokens.IMPORTANT_SYM;
  4111. }
  4112. break; //we're done
  4113. } else {
  4114. break;
  4115. }
  4116. c = reader.read();
  4117. }
  4118. if (tt == Tokens.CHAR){
  4119. reader.reset();
  4120. return this.charToken(first, startLine, startCol);
  4121. } else {
  4122. return this.createToken(tt, important, startLine, startCol);
  4123. }
  4124. },
  4125. notToken: function(first, startLine, startCol){
  4126. var reader = this._reader,
  4127. text = first;
  4128. reader.mark();
  4129. text += reader.readCount(4);
  4130. if (text.toLowerCase() == ":not("){
  4131. return this.createToken(Tokens.NOT, text, startLine, startCol);
  4132. } else {
  4133. reader.reset();
  4134. return this.charToken(first, startLine, startCol);
  4135. }
  4136. },
  4137. numberToken: function(first, startLine, startCol){
  4138. var reader = this._reader,
  4139. value = this.readNumber(first),
  4140. ident,
  4141. tt = Tokens.NUMBER,
  4142. c = reader.peek();
  4143. if (isIdentStart(c)){
  4144. ident = this.readName(reader.read());
  4145. value += ident;
  4146. if (/^em$|^ex$|^px$|^gd$|^rem$|^vw$|^vh$|^fr$|^vmax$|^vmin$|^ch$|^cm$|^mm$|^in$|^pt$|^pc$/i.test(ident)){
  4147. tt = Tokens.LENGTH;
  4148. } else if (/^deg|^rad$|^grad$/i.test(ident)){
  4149. tt = Tokens.ANGLE;
  4150. } else if (/^ms$|^s$/i.test(ident)){
  4151. tt = Tokens.TIME;
  4152. } else if (/^hz$|^khz$/i.test(ident)){
  4153. tt = Tokens.FREQ;
  4154. } else if (/^dpi$|^dpcm$/i.test(ident)){
  4155. tt = Tokens.RESOLUTION;
  4156. } else {
  4157. tt = Tokens.DIMENSION;
  4158. }
  4159. } else if (c == "%"){
  4160. value += reader.read();
  4161. tt = Tokens.PERCENTAGE;
  4162. }
  4163. return this.createToken(tt, value, startLine, startCol);
  4164. },
  4165. stringToken: function(first, startLine, startCol){
  4166. var delim = first,
  4167. string = first,
  4168. reader = this._reader,
  4169. prev = first,
  4170. tt = Tokens.STRING,
  4171. c = reader.read();
  4172. while(c){
  4173. string += c;
  4174. if (c == delim && prev != "\\"){
  4175. break;
  4176. }
  4177. if (isNewLine(reader.peek()) && c != "\\"){
  4178. tt = Tokens.INVALID;
  4179. break;
  4180. }
  4181. prev = c;
  4182. c = reader.read();
  4183. }
  4184. if (c === null){
  4185. tt = Tokens.INVALID;
  4186. }
  4187. return this.createToken(tt, string, startLine, startCol);
  4188. },
  4189. unicodeRangeToken: function(first, startLine, startCol){
  4190. var reader = this._reader,
  4191. value = first,
  4192. temp,
  4193. tt = Tokens.CHAR;
  4194. if (reader.peek() == "+"){
  4195. reader.mark();
  4196. value += reader.read();
  4197. value += this.readUnicodeRangePart(true);
  4198. if (value.length == 2){
  4199. reader.reset();
  4200. } else {
  4201. tt = Tokens.UNICODE_RANGE;
  4202. if (value.indexOf("?") == -1){
  4203. if (reader.peek() == "-"){
  4204. reader.mark();
  4205. temp = reader.read();
  4206. temp += this.readUnicodeRangePart(false);
  4207. if (temp.length == 1){
  4208. reader.reset();
  4209. } else {
  4210. value += temp;
  4211. }
  4212. }
  4213. }
  4214. }
  4215. }
  4216. return this.createToken(tt, value, startLine, startCol);
  4217. },
  4218. whitespaceToken: function(first, startLine, startCol){
  4219. var reader = this._reader,
  4220. value = first + this.readWhitespace();
  4221. return this.createToken(Tokens.S, value, startLine, startCol);
  4222. },
  4223. readUnicodeRangePart: function(allowQuestionMark){
  4224. var reader = this._reader,
  4225. part = "",
  4226. c = reader.peek();
  4227. while(isHexDigit(c) && part.length < 6){
  4228. reader.read();
  4229. part += c;
  4230. c = reader.peek();
  4231. }
  4232. if (allowQuestionMark){
  4233. while(c == "?" && part.length < 6){
  4234. reader.read();
  4235. part += c;
  4236. c = reader.peek();
  4237. }
  4238. }
  4239. return part;
  4240. },
  4241. readWhitespace: function(){
  4242. var reader = this._reader,
  4243. whitespace = "",
  4244. c = reader.peek();
  4245. while(isWhitespace(c)){
  4246. reader.read();
  4247. whitespace += c;
  4248. c = reader.peek();
  4249. }
  4250. return whitespace;
  4251. },
  4252. readNumber: function(first){
  4253. var reader = this._reader,
  4254. number = first,
  4255. hasDot = (first == "."),
  4256. c = reader.peek();
  4257. while(c){
  4258. if (isDigit(c)){
  4259. number += reader.read();
  4260. } else if (c == "."){
  4261. if (hasDot){
  4262. break;
  4263. } else {
  4264. hasDot = true;
  4265. number += reader.read();
  4266. }
  4267. } else {
  4268. break;
  4269. }
  4270. c = reader.peek();
  4271. }
  4272. return number;
  4273. },
  4274. readString: function(){
  4275. var reader = this._reader,
  4276. delim = reader.read(),
  4277. string = delim,
  4278. prev = delim,
  4279. c = reader.peek();
  4280. while(c){
  4281. c = reader.read();
  4282. string += c;
  4283. if (c == delim && prev != "\\"){
  4284. break;
  4285. }
  4286. if (isNewLine(reader.peek()) && c != "\\"){
  4287. string = "";
  4288. break;
  4289. }
  4290. prev = c;
  4291. c = reader.peek();
  4292. }
  4293. if (c === null){
  4294. string = "";
  4295. }
  4296. return string;
  4297. },
  4298. readURI: function(first){
  4299. var reader = this._reader,
  4300. uri = first,
  4301. inner = "",
  4302. c = reader.peek();
  4303. reader.mark();
  4304. while(c && isWhitespace(c)){
  4305. reader.read();
  4306. c = reader.peek();
  4307. }
  4308. if (c == "'" || c == "\""){
  4309. inner = this.readString();
  4310. } else {
  4311. inner = this.readURL();
  4312. }
  4313. c = reader.peek();
  4314. while(c && isWhitespace(c)){
  4315. reader.read();
  4316. c = reader.peek();
  4317. }
  4318. if (inner === "" || c != ")"){
  4319. uri = first;
  4320. reader.reset();
  4321. } else {
  4322. uri += inner + reader.read();
  4323. }
  4324. return uri;
  4325. },
  4326. readURL: function(){
  4327. var reader = this._reader,
  4328. url = "",
  4329. c = reader.peek();
  4330. while (/^[!#$%&\\*-~]$/.test(c)){
  4331. url += reader.read();
  4332. c = reader.peek();
  4333. }
  4334. return url;
  4335. },
  4336. readName: function(first){
  4337. var reader = this._reader,
  4338. ident = first || "",
  4339. c = reader.peek();
  4340. while(true){
  4341. if (c == "\\"){
  4342. ident += this.readEscape(reader.read());
  4343. c = reader.peek();
  4344. } else if(c && isNameChar(c)){
  4345. ident += reader.read();
  4346. c = reader.peek();
  4347. } else {
  4348. break;
  4349. }
  4350. }
  4351. return ident;
  4352. },
  4353. readEscape: function(first){
  4354. var reader = this._reader,
  4355. cssEscape = first || "",
  4356. i = 0,
  4357. c = reader.peek();
  4358. if (isHexDigit(c)){
  4359. do {
  4360. cssEscape += reader.read();
  4361. c = reader.peek();
  4362. } while(c && isHexDigit(c) && ++i < 6);
  4363. }
  4364. if (cssEscape.length == 3 && /\s/.test(c) ||
  4365. cssEscape.length == 7 || cssEscape.length == 1){
  4366. reader.read();
  4367. } else {
  4368. c = "";
  4369. }
  4370. return cssEscape + c;
  4371. },
  4372. readComment: function(first){
  4373. var reader = this._reader,
  4374. comment = first || "",
  4375. c = reader.read();
  4376. if (c == "*"){
  4377. while(c){
  4378. comment += c;
  4379. if (comment.length > 2 && c == "*" && reader.peek() == "/"){
  4380. comment += reader.read();
  4381. break;
  4382. }
  4383. c = reader.read();
  4384. }
  4385. return comment;
  4386. } else {
  4387. return "";
  4388. }
  4389. }
  4390. });
  4391. var Tokens = [
  4392. { name: "CDO"},
  4393. { name: "CDC"},
  4394. { name: "S", whitespace: true/*, channel: "ws"*/},
  4395. { name: "COMMENT", comment: true, hide: true, channel: "comment" },
  4396. { name: "INCLUDES", text: "~="},
  4397. { name: "DASHMATCH", text: "|="},
  4398. { name: "PREFIXMATCH", text: "^="},
  4399. { name: "SUFFIXMATCH", text: "$="},
  4400. { name: "SUBSTRINGMATCH", text: "*="},
  4401. { name: "STRING"},
  4402. { name: "IDENT"},
  4403. { name: "HASH"},
  4404. { name: "IMPORT_SYM", text: "@import"},
  4405. { name: "PAGE_SYM", text: "@page"},
  4406. { name: "MEDIA_SYM", text: "@media"},
  4407. { name: "FONT_FACE_SYM", text: "@font-face"},
  4408. { name: "CHARSET_SYM", text: "@charset"},
  4409. { name: "NAMESPACE_SYM", text: "@namespace"},
  4410. { name: "VIEWPORT_SYM", text: ["@viewport", "@-ms-viewport"]},
  4411. { name: "UNKNOWN_SYM" },
  4412. { name: "KEYFRAMES_SYM", text: [ "@keyframes", "@-webkit-keyframes", "@-moz-keyframes", "@-o-keyframes" ] },
  4413. { name: "IMPORTANT_SYM"},
  4414. { name: "LENGTH"},
  4415. { name: "ANGLE"},
  4416. { name: "TIME"},
  4417. { name: "FREQ"},
  4418. { name: "DIMENSION"},
  4419. { name: "PERCENTAGE"},
  4420. { name: "NUMBER"},
  4421. { name: "URI"},
  4422. { name: "FUNCTION"},
  4423. { name: "UNICODE_RANGE"},
  4424. { name: "INVALID"},
  4425. { name: "PLUS", text: "+" },
  4426. { name: "GREATER", text: ">"},
  4427. { name: "COMMA", text: ","},
  4428. { name: "TILDE", text: "~"},
  4429. { name: "NOT"},
  4430. { name: "TOPLEFTCORNER_SYM", text: "@top-left-corner"},
  4431. { name: "TOPLEFT_SYM", text: "@top-left"},
  4432. { name: "TOPCENTER_SYM", text: "@top-center"},
  4433. { name: "TOPRIGHT_SYM", text: "@top-right"},
  4434. { name: "TOPRIGHTCORNER_SYM", text: "@top-right-corner"},
  4435. { name: "BOTTOMLEFTCORNER_SYM", text: "@bottom-left-corner"},
  4436. { name: "BOTTOMLEFT_SYM", text: "@bottom-left"},
  4437. { name: "BOTTOMCENTER_SYM", text: "@bottom-center"},
  4438. { name: "BOTTOMRIGHT_SYM", text: "@bottom-right"},
  4439. { name: "BOTTOMRIGHTCORNER_SYM", text: "@bottom-right-corner"},
  4440. { name: "LEFTTOP_SYM", text: "@left-top"},
  4441. { name: "LEFTMIDDLE_SYM", text: "@left-middle"},
  4442. { name: "LEFTBOTTOM_SYM", text: "@left-bottom"},
  4443. { name: "RIGHTTOP_SYM", text: "@right-top"},
  4444. { name: "RIGHTMIDDLE_SYM", text: "@right-middle"},
  4445. { name: "RIGHTBOTTOM_SYM", text: "@right-bottom"},
  4446. { name: "RESOLUTION", state: "media"},
  4447. { name: "IE_FUNCTION" },
  4448. { name: "CHAR" },
  4449. {
  4450. name: "PIPE",
  4451. text: "|"
  4452. },
  4453. {
  4454. name: "SLASH",
  4455. text: "/"
  4456. },
  4457. {
  4458. name: "MINUS",
  4459. text: "-"
  4460. },
  4461. {
  4462. name: "STAR",
  4463. text: "*"
  4464. },
  4465. {
  4466. name: "LBRACE",
  4467. endChar: "}",
  4468. text: "{"
  4469. },
  4470. {
  4471. name: "RBRACE",
  4472. text: "}"
  4473. },
  4474. {
  4475. name: "LBRACKET",
  4476. endChar: "]",
  4477. text: "["
  4478. },
  4479. {
  4480. name: "RBRACKET",
  4481. text: "]"
  4482. },
  4483. {
  4484. name: "EQUALS",
  4485. text: "="
  4486. },
  4487. {
  4488. name: "COLON",
  4489. text: ":"
  4490. },
  4491. {
  4492. name: "SEMICOLON",
  4493. text: ";"
  4494. },
  4495. {
  4496. name: "LPAREN",
  4497. endChar: ")",
  4498. text: "("
  4499. },
  4500. {
  4501. name: "RPAREN",
  4502. text: ")"
  4503. },
  4504. {
  4505. name: "DOT",
  4506. text: "."
  4507. }
  4508. ];
  4509. (function(){
  4510. var nameMap = [],
  4511. typeMap = {};
  4512. Tokens.UNKNOWN = -1;
  4513. Tokens.unshift({name:"EOF"});
  4514. for (var i=0, len = Tokens.length; i < len; i++){
  4515. nameMap.push(Tokens[i].name);
  4516. Tokens[Tokens[i].name] = i;
  4517. if (Tokens[i].text){
  4518. if (Tokens[i].text instanceof Array){
  4519. for (var j=0; j < Tokens[i].text.length; j++){
  4520. typeMap[Tokens[i].text[j]] = i;
  4521. }
  4522. } else {
  4523. typeMap[Tokens[i].text] = i;
  4524. }
  4525. }
  4526. }
  4527. Tokens.name = function(tt){
  4528. return nameMap[tt];
  4529. };
  4530. Tokens.type = function(c){
  4531. return typeMap[c] || -1;
  4532. };
  4533. })();
  4534. var Validation = {
  4535. validate: function(property, value){
  4536. var name = property.toString().toLowerCase(),
  4537. parts = value.parts,
  4538. expression = new PropertyValueIterator(value),
  4539. spec = Properties[name],
  4540. part,
  4541. valid,
  4542. j, count,
  4543. msg,
  4544. types,
  4545. last,
  4546. literals,
  4547. max, multi, group;
  4548. if (!spec) {
  4549. if (name.indexOf("-") !== 0){ //vendor prefixed are ok
  4550. throw new ValidationError("Unknown property '" + property + "'.", property.line, property.col);
  4551. }
  4552. } else if (typeof spec != "number"){
  4553. if (typeof spec == "string"){
  4554. if (spec.indexOf("||") > -1) {
  4555. this.groupProperty(spec, expression);
  4556. } else {
  4557. this.singleProperty(spec, expression, 1);
  4558. }
  4559. } else if (spec.multi) {
  4560. this.multiProperty(spec.multi, expression, spec.comma, spec.max || Infinity);
  4561. } else if (typeof spec == "function") {
  4562. spec(expression);
  4563. }
  4564. }
  4565. },
  4566. singleProperty: function(types, expression, max, partial) {
  4567. var result = false,
  4568. value = expression.value,
  4569. count = 0,
  4570. part;
  4571. while (expression.hasNext() && count < max) {
  4572. result = ValidationTypes.isAny(expression, types);
  4573. if (!result) {
  4574. break;
  4575. }
  4576. count++;
  4577. }
  4578. if (!result) {
  4579. if (expression.hasNext() && !expression.isFirst()) {
  4580. part = expression.peek();
  4581. throw new ValidationError("Expected end of value but found '" + part + "'.", part.line, part.col);
  4582. } else {
  4583. throw new ValidationError("Expected (" + types + ") but found '" + value + "'.", value.line, value.col);
  4584. }
  4585. } else if (expression.hasNext()) {
  4586. part = expression.next();
  4587. throw new ValidationError("Expected end of value but found '" + part + "'.", part.line, part.col);
  4588. }
  4589. },
  4590. multiProperty: function (types, expression, comma, max) {
  4591. var result = false,
  4592. value = expression.value,
  4593. count = 0,
  4594. sep = false,
  4595. part;
  4596. while(expression.hasNext() && !result && count < max) {
  4597. if (ValidationTypes.isAny(expression, types)) {
  4598. count++;
  4599. if (!expression.hasNext()) {
  4600. result = true;
  4601. } else if (comma) {
  4602. if (expression.peek() == ",") {
  4603. part = expression.next();
  4604. } else {
  4605. break;
  4606. }
  4607. }
  4608. } else {
  4609. break;
  4610. }
  4611. }
  4612. if (!result) {
  4613. if (expression.hasNext() && !expression.isFirst()) {
  4614. part = expression.peek();
  4615. throw new ValidationError("Expected end of value but found '" + part + "'.", part.line, part.col);
  4616. } else {
  4617. part = expression.previous();
  4618. if (comma && part == ",") {
  4619. throw new ValidationError("Expected end of value but found '" + part + "'.", part.line, part.col);
  4620. } else {
  4621. throw new ValidationError("Expected (" + types + ") but found '" + value + "'.", value.line, value.col);
  4622. }
  4623. }
  4624. } else if (expression.hasNext()) {
  4625. part = expression.next();
  4626. throw new ValidationError("Expected end of value but found '" + part + "'.", part.line, part.col);
  4627. }
  4628. },
  4629. groupProperty: function (types, expression, comma) {
  4630. var result = false,
  4631. value = expression.value,
  4632. typeCount = types.split("||").length,
  4633. groups = { count: 0 },
  4634. partial = false,
  4635. name,
  4636. part;
  4637. while(expression.hasNext() && !result) {
  4638. name = ValidationTypes.isAnyOfGroup(expression, types);
  4639. if (name) {
  4640. if (groups[name]) {
  4641. break;
  4642. } else {
  4643. groups[name] = 1;
  4644. groups.count++;
  4645. partial = true;
  4646. if (groups.count == typeCount || !expression.hasNext()) {
  4647. result = true;
  4648. }
  4649. }
  4650. } else {
  4651. break;
  4652. }
  4653. }
  4654. if (!result) {
  4655. if (partial && expression.hasNext()) {
  4656. part = expression.peek();
  4657. throw new ValidationError("Expected end of value but found '" + part + "'.", part.line, part.col);
  4658. } else {
  4659. throw new ValidationError("Expected (" + types + ") but found '" + value + "'.", value.line, value.col);
  4660. }
  4661. } else if (expression.hasNext()) {
  4662. part = expression.next();
  4663. throw new ValidationError("Expected end of value but found '" + part + "'.", part.line, part.col);
  4664. }
  4665. }
  4666. };
  4667. function ValidationError(message, line, col){
  4668. this.col = col;
  4669. this.line = line;
  4670. this.message = message;
  4671. }
  4672. ValidationError.prototype = new Error();
  4673. var ValidationTypes = {
  4674. isLiteral: function (part, literals) {
  4675. var text = part.text.toString().toLowerCase(),
  4676. args = literals.split(" | "),
  4677. i, len, found = false;
  4678. for (i=0,len=args.length; i < len && !found; i++){
  4679. if (text == args[i].toLowerCase()){
  4680. found = true;
  4681. }
  4682. }
  4683. return found;
  4684. },
  4685. isSimple: function(type) {
  4686. return !!this.simple[type];
  4687. },
  4688. isComplex: function(type) {
  4689. return !!this.complex[type];
  4690. },
  4691. isAny: function (expression, types) {
  4692. var args = types.split(" | "),
  4693. i, len, found = false;
  4694. for (i=0,len=args.length; i < len && !found && expression.hasNext(); i++){
  4695. found = this.isType(expression, args[i]);
  4696. }
  4697. return found;
  4698. },
  4699. isAnyOfGroup: function(expression, types) {
  4700. var args = types.split(" || "),
  4701. i, len, found = false;
  4702. for (i=0,len=args.length; i < len && !found; i++){
  4703. found = this.isType(expression, args[i]);
  4704. }
  4705. return found ? args[i-1] : false;
  4706. },
  4707. isType: function (expression, type) {
  4708. var part = expression.peek(),
  4709. result = false;
  4710. if (type.charAt(0) != "<") {
  4711. result = this.isLiteral(part, type);
  4712. if (result) {
  4713. expression.next();
  4714. }
  4715. } else if (this.simple[type]) {
  4716. result = this.simple[type](part);
  4717. if (result) {
  4718. expression.next();
  4719. }
  4720. } else {
  4721. result = this.complex[type](expression);
  4722. }
  4723. return result;
  4724. },
  4725. simple: {
  4726. "<absolute-size>": function(part){
  4727. return ValidationTypes.isLiteral(part, "xx-small | x-small | small | medium | large | x-large | xx-large");
  4728. },
  4729. "<attachment>": function(part){
  4730. return ValidationTypes.isLiteral(part, "scroll | fixed | local");
  4731. },
  4732. "<attr>": function(part){
  4733. return part.type == "function" && part.name == "attr";
  4734. },
  4735. "<bg-image>": function(part){
  4736. return this["<image>"](part) || this["<gradient>"](part) || part == "none";
  4737. },
  4738. "<gradient>": function(part) {
  4739. return part.type == "function" && /^(?:\-(?:ms|moz|o|webkit)\-)?(?:repeating\-)?(?:radial\-|linear\-)?gradient/i.test(part);
  4740. },
  4741. "<box>": function(part){
  4742. return ValidationTypes.isLiteral(part, "padding-box | border-box | content-box");
  4743. },
  4744. "<content>": function(part){
  4745. return part.type == "function" && part.name == "content";
  4746. },
  4747. "<relative-size>": function(part){
  4748. return ValidationTypes.isLiteral(part, "smaller | larger");
  4749. },
  4750. "<ident>": function(part){
  4751. return part.type == "identifier";
  4752. },
  4753. "<length>": function(part){
  4754. if (part.type == "function" && /^(?:\-(?:ms|moz|o|webkit)\-)?calc/i.test(part)){
  4755. return true;
  4756. }else{
  4757. return part.type == "length" || part.type == "number" || part.type == "integer" || part == "0";
  4758. }
  4759. },
  4760. "<color>": function(part){
  4761. return part.type == "color" || part == "transparent";
  4762. },
  4763. "<number>": function(part){
  4764. return part.type == "number" || this["<integer>"](part);
  4765. },
  4766. "<integer>": function(part){
  4767. return part.type == "integer";
  4768. },
  4769. "<line>": function(part){
  4770. return part.type == "integer";
  4771. },
  4772. "<angle>": function(part){
  4773. return part.type == "angle";
  4774. },
  4775. "<uri>": function(part){
  4776. return part.type == "uri";
  4777. },
  4778. "<image>": function(part){
  4779. return this["<uri>"](part);
  4780. },
  4781. "<percentage>": function(part){
  4782. return part.type == "percentage" || part == "0";
  4783. },
  4784. "<border-width>": function(part){
  4785. return this["<length>"](part) || ValidationTypes.isLiteral(part, "thin | medium | thick");
  4786. },
  4787. "<border-style>": function(part){
  4788. return ValidationTypes.isLiteral(part, "none | hidden | dotted | dashed | solid | double | groove | ridge | inset | outset");
  4789. },
  4790. "<content-sizing>": function(part){ // http://www.w3.org/TR/css3-sizing/#width-height-keywords
  4791. return ValidationTypes.isLiteral(part, "fill-available | -moz-available | -webkit-fill-available | max-content | -moz-max-content | -webkit-max-content | min-content | -moz-min-content | -webkit-min-content | fit-content | -moz-fit-content | -webkit-fit-content");
  4792. },
  4793. "<margin-width>": function(part){
  4794. return this["<length>"](part) || this["<percentage>"](part) || ValidationTypes.isLiteral(part, "auto");
  4795. },
  4796. "<padding-width>": function(part){
  4797. return this["<length>"](part) || this["<percentage>"](part);
  4798. },
  4799. "<shape>": function(part){
  4800. return part.type == "function" && (part.name == "rect" || part.name == "inset-rect");
  4801. },
  4802. "<time>": function(part) {
  4803. return part.type == "time";
  4804. },
  4805. "<flex-grow>": function(part){
  4806. return this["<number>"](part);
  4807. },
  4808. "<flex-shrink>": function(part){
  4809. return this["<number>"](part);
  4810. },
  4811. "<width>": function(part){
  4812. return this["<margin-width>"](part);
  4813. },
  4814. "<flex-basis>": function(part){
  4815. return this["<width>"](part);
  4816. },
  4817. "<flex-direction>": function(part){
  4818. return ValidationTypes.isLiteral(part, "row | row-reverse | column | column-reverse");
  4819. },
  4820. "<flex-wrap>": function(part){
  4821. return ValidationTypes.isLiteral(part, "nowrap | wrap | wrap-reverse");
  4822. }
  4823. },
  4824. complex: {
  4825. "<bg-position>": function(expression){
  4826. var types = this,
  4827. result = false,
  4828. numeric = "<percentage> | <length>",
  4829. xDir = "left | right",
  4830. yDir = "top | bottom",
  4831. count = 0,
  4832. hasNext = function() {
  4833. return expression.hasNext() && expression.peek() != ",";
  4834. };
  4835. while (expression.peek(count) && expression.peek(count) != ",") {
  4836. count++;
  4837. }
  4838. if (count < 3) {
  4839. if (ValidationTypes.isAny(expression, xDir + " | center | " + numeric)) {
  4840. result = true;
  4841. ValidationTypes.isAny(expression, yDir + " | center | " + numeric);
  4842. } else if (ValidationTypes.isAny(expression, yDir)) {
  4843. result = true;
  4844. ValidationTypes.isAny(expression, xDir + " | center");
  4845. }
  4846. } else {
  4847. if (ValidationTypes.isAny(expression, xDir)) {
  4848. if (ValidationTypes.isAny(expression, yDir)) {
  4849. result = true;
  4850. ValidationTypes.isAny(expression, numeric);
  4851. } else if (ValidationTypes.isAny(expression, numeric)) {
  4852. if (ValidationTypes.isAny(expression, yDir)) {
  4853. result = true;
  4854. ValidationTypes.isAny(expression, numeric);
  4855. } else if (ValidationTypes.isAny(expression, "center")) {
  4856. result = true;
  4857. }
  4858. }
  4859. } else if (ValidationTypes.isAny(expression, yDir)) {
  4860. if (ValidationTypes.isAny(expression, xDir)) {
  4861. result = true;
  4862. ValidationTypes.isAny(expression, numeric);
  4863. } else if (ValidationTypes.isAny(expression, numeric)) {
  4864. if (ValidationTypes.isAny(expression, xDir)) {
  4865. result = true;
  4866. ValidationTypes.isAny(expression, numeric);
  4867. } else if (ValidationTypes.isAny(expression, "center")) {
  4868. result = true;
  4869. }
  4870. }
  4871. } else if (ValidationTypes.isAny(expression, "center")) {
  4872. if (ValidationTypes.isAny(expression, xDir + " | " + yDir)) {
  4873. result = true;
  4874. ValidationTypes.isAny(expression, numeric);
  4875. }
  4876. }
  4877. }
  4878. return result;
  4879. },
  4880. "<bg-size>": function(expression){
  4881. var types = this,
  4882. result = false,
  4883. numeric = "<percentage> | <length> | auto",
  4884. part,
  4885. i, len;
  4886. if (ValidationTypes.isAny(expression, "cover | contain")) {
  4887. result = true;
  4888. } else if (ValidationTypes.isAny(expression, numeric)) {
  4889. result = true;
  4890. ValidationTypes.isAny(expression, numeric);
  4891. }
  4892. return result;
  4893. },
  4894. "<repeat-style>": function(expression){
  4895. var result = false,
  4896. values = "repeat | space | round | no-repeat",
  4897. part;
  4898. if (expression.hasNext()){
  4899. part = expression.next();
  4900. if (ValidationTypes.isLiteral(part, "repeat-x | repeat-y")) {
  4901. result = true;
  4902. } else if (ValidationTypes.isLiteral(part, values)) {
  4903. result = true;
  4904. if (expression.hasNext() && ValidationTypes.isLiteral(expression.peek(), values)) {
  4905. expression.next();
  4906. }
  4907. }
  4908. }
  4909. return result;
  4910. },
  4911. "<shadow>": function(expression) {
  4912. var result = false,
  4913. count = 0,
  4914. inset = false,
  4915. color = false,
  4916. part;
  4917. if (expression.hasNext()) {
  4918. if (ValidationTypes.isAny(expression, "inset")){
  4919. inset = true;
  4920. }
  4921. if (ValidationTypes.isAny(expression, "<color>")) {
  4922. color = true;
  4923. }
  4924. while (ValidationTypes.isAny(expression, "<length>") && count < 4) {
  4925. count++;
  4926. }
  4927. if (expression.hasNext()) {
  4928. if (!color) {
  4929. ValidationTypes.isAny(expression, "<color>");
  4930. }
  4931. if (!inset) {
  4932. ValidationTypes.isAny(expression, "inset");
  4933. }
  4934. }
  4935. result = (count >= 2 && count <= 4);
  4936. }
  4937. return result;
  4938. },
  4939. "<x-one-radius>": function(expression) {
  4940. var result = false,
  4941. simple = "<length> | <percentage> | inherit";
  4942. if (ValidationTypes.isAny(expression, simple)){
  4943. result = true;
  4944. ValidationTypes.isAny(expression, simple);
  4945. }
  4946. return result;
  4947. },
  4948. "<flex>": function(expression) {
  4949. var part,
  4950. result = false;
  4951. if (ValidationTypes.isAny(expression, "none | inherit")) {
  4952. result = true;
  4953. } else {
  4954. if (ValidationTypes.isType(expression, "<flex-grow>")) {
  4955. if (expression.peek()) {
  4956. if (ValidationTypes.isType(expression, "<flex-shrink>")) {
  4957. if (expression.peek()) {
  4958. result = ValidationTypes.isType(expression, "<flex-basis>");
  4959. } else {
  4960. result = true;
  4961. }
  4962. } else if (ValidationTypes.isType(expression, "<flex-basis>")) {
  4963. result = expression.peek() === null;
  4964. }
  4965. } else {
  4966. result = true;
  4967. }
  4968. } else if (ValidationTypes.isType(expression, "<flex-basis>")) {
  4969. result = true;
  4970. }
  4971. }
  4972. if (!result) {
  4973. part = expression.peek();
  4974. throw new ValidationError("Expected (none | [ <flex-grow> <flex-shrink>? || <flex-basis> ]) but found '" + expression.value.text + "'.", part.line, part.col);
  4975. }
  4976. return result;
  4977. }
  4978. }
  4979. };
  4980. parserlib.css = {
  4981. Colors :Colors,
  4982. Combinator :Combinator,
  4983. Parser :Parser,
  4984. PropertyName :PropertyName,
  4985. PropertyValue :PropertyValue,
  4986. PropertyValuePart :PropertyValuePart,
  4987. MediaFeature :MediaFeature,
  4988. MediaQuery :MediaQuery,
  4989. Selector :Selector,
  4990. SelectorPart :SelectorPart,
  4991. SelectorSubPart :SelectorSubPart,
  4992. Specificity :Specificity,
  4993. TokenStream :TokenStream,
  4994. Tokens :Tokens,
  4995. ValidationError :ValidationError
  4996. };
  4997. })();
  4998. (function(){
  4999. for(var prop in parserlib){
  5000. exports[prop] = parserlib[prop];
  5001. }
  5002. })();
  5003. function objectToString(o) {
  5004. return Object.prototype.toString.call(o);
  5005. }
  5006. var util = {
  5007. isArray: function (ar) {
  5008. return Array.isArray(ar) || (typeof ar === 'object' && objectToString(ar) === '[object Array]');
  5009. },
  5010. isDate: function (d) {
  5011. return typeof d === 'object' && objectToString(d) === '[object Date]';
  5012. },
  5013. isRegExp: function (re) {
  5014. return typeof re === 'object' && objectToString(re) === '[object RegExp]';
  5015. },
  5016. getRegExpFlags: function (re) {
  5017. var flags = '';
  5018. re.global && (flags += 'g');
  5019. re.ignoreCase && (flags += 'i');
  5020. re.multiline && (flags += 'm');
  5021. return flags;
  5022. }
  5023. };
  5024. if (typeof module === 'object')
  5025. module.exports = clone;
  5026. function clone(parent, circular, depth, prototype) {
  5027. var allParents = [];
  5028. var allChildren = [];
  5029. var useBuffer = typeof Buffer != 'undefined';
  5030. if (typeof circular == 'undefined')
  5031. circular = true;
  5032. if (typeof depth == 'undefined')
  5033. depth = Infinity;
  5034. function _clone(parent, depth) {
  5035. if (parent === null)
  5036. return null;
  5037. if (depth == 0)
  5038. return parent;
  5039. var child;
  5040. if (typeof parent != 'object') {
  5041. return parent;
  5042. }
  5043. if (util.isArray(parent)) {
  5044. child = [];
  5045. } else if (util.isRegExp(parent)) {
  5046. child = new RegExp(parent.source, util.getRegExpFlags(parent));
  5047. if (parent.lastIndex) child.lastIndex = parent.lastIndex;
  5048. } else if (util.isDate(parent)) {
  5049. child = new Date(parent.getTime());
  5050. } else if (useBuffer && Buffer.isBuffer(parent)) {
  5051. child = new Buffer(parent.length);
  5052. parent.copy(child);
  5053. return child;
  5054. } else {
  5055. if (typeof prototype == 'undefined') child = Object.create(Object.getPrototypeOf(parent));
  5056. else child = Object.create(prototype);
  5057. }
  5058. if (circular) {
  5059. var index = allParents.indexOf(parent);
  5060. if (index != -1) {
  5061. return allChildren[index];
  5062. }
  5063. allParents.push(parent);
  5064. allChildren.push(child);
  5065. }
  5066. for (var i in parent) {
  5067. child[i] = _clone(parent[i], depth - 1);
  5068. }
  5069. return child;
  5070. }
  5071. return _clone(parent, depth);
  5072. }
  5073. clone.clonePrototype = function(parent) {
  5074. if (parent === null)
  5075. return null;
  5076. var c = function () {};
  5077. c.prototype = parent;
  5078. return new c();
  5079. };
  5080. var CSSLint = (function(){
  5081. var rules = [],
  5082. formatters = [],
  5083. embeddedRuleset = /\/\*csslint([^\*]*)\*\//,
  5084. api = new parserlib.util.EventTarget();
  5085. api.version = "@VERSION@";
  5086. api.addRule = function(rule){
  5087. rules.push(rule);
  5088. rules[rule.id] = rule;
  5089. };
  5090. api.clearRules = function(){
  5091. rules = [];
  5092. };
  5093. api.getRules = function(){
  5094. return [].concat(rules).sort(function(a,b){
  5095. return a.id > b.id ? 1 : 0;
  5096. });
  5097. };
  5098. api.getRuleset = function() {
  5099. var ruleset = {},
  5100. i = 0,
  5101. len = rules.length;
  5102. while (i < len){
  5103. ruleset[rules[i++].id] = 1; //by default, everything is a warning
  5104. }
  5105. return ruleset;
  5106. };
  5107. function applyEmbeddedRuleset(text, ruleset){
  5108. var valueMap,
  5109. embedded = text && text.match(embeddedRuleset),
  5110. rules = embedded && embedded[1];
  5111. if (rules) {
  5112. valueMap = {
  5113. "true": 2, // true is error
  5114. "": 1, // blank is warning
  5115. "false": 0, // false is ignore
  5116. "2": 2, // explicit error
  5117. "1": 1, // explicit warning
  5118. "0": 0 // explicit ignore
  5119. };
  5120. rules.toLowerCase().split(",").forEach(function(rule){
  5121. var pair = rule.split(":"),
  5122. property = pair[0] || "",
  5123. value = pair[1] || "";
  5124. ruleset[property.trim()] = valueMap[value.trim()];
  5125. });
  5126. }
  5127. return ruleset;
  5128. }
  5129. api.addFormatter = function(formatter) {
  5130. formatters[formatter.id] = formatter;
  5131. };
  5132. api.getFormatter = function(formatId){
  5133. return formatters[formatId];
  5134. };
  5135. api.format = function(results, filename, formatId, options) {
  5136. var formatter = this.getFormatter(formatId),
  5137. result = null;
  5138. if (formatter){
  5139. result = formatter.startFormat();
  5140. result += formatter.formatResults(results, filename, options || {});
  5141. result += formatter.endFormat();
  5142. }
  5143. return result;
  5144. };
  5145. api.hasFormat = function(formatId){
  5146. return formatters.hasOwnProperty(formatId);
  5147. };
  5148. api.verify = function(text, ruleset){
  5149. var i = 0,
  5150. reporter,
  5151. lines,
  5152. report,
  5153. parser = new parserlib.css.Parser({ starHack: true, ieFilters: true,
  5154. underscoreHack: true, strict: false });
  5155. lines = text.replace(/\n\r?/g, "$split$").split("$split$");
  5156. if (!ruleset){
  5157. ruleset = this.getRuleset();
  5158. }
  5159. if (embeddedRuleset.test(text)){
  5160. ruleset = clone(ruleset);
  5161. ruleset = applyEmbeddedRuleset(text, ruleset);
  5162. }
  5163. reporter = new Reporter(lines, ruleset);
  5164. ruleset.errors = 2; //always report parsing errors as errors
  5165. for (i in ruleset){
  5166. if(ruleset.hasOwnProperty(i) && ruleset[i]){
  5167. if (rules[i]){
  5168. rules[i].init(parser, reporter);
  5169. }
  5170. }
  5171. }
  5172. try {
  5173. parser.parse(text);
  5174. } catch (ex) {
  5175. reporter.error("Fatal error, cannot continue: " + ex.message, ex.line, ex.col, {});
  5176. }
  5177. report = {
  5178. messages : reporter.messages,
  5179. stats : reporter.stats,
  5180. ruleset : reporter.ruleset
  5181. };
  5182. report.messages.sort(function (a, b){
  5183. if (a.rollup && !b.rollup){
  5184. return 1;
  5185. } else if (!a.rollup && b.rollup){
  5186. return -1;
  5187. } else {
  5188. return a.line - b.line;
  5189. }
  5190. });
  5191. return report;
  5192. };
  5193. return api;
  5194. })();
  5195. function Reporter(lines, ruleset){
  5196. this.messages = [];
  5197. this.stats = [];
  5198. this.lines = lines;
  5199. this.ruleset = ruleset;
  5200. }
  5201. Reporter.prototype = {
  5202. constructor: Reporter,
  5203. error: function(message, line, col, rule){
  5204. this.messages.push({
  5205. type : "error",
  5206. line : line,
  5207. col : col,
  5208. message : message,
  5209. evidence: this.lines[line-1],
  5210. rule : rule || {}
  5211. });
  5212. },
  5213. warn: function(message, line, col, rule){
  5214. this.report(message, line, col, rule);
  5215. },
  5216. report: function(message, line, col, rule){
  5217. this.messages.push({
  5218. type : this.ruleset[rule.id] === 2 ? "error" : "warning",
  5219. line : line,
  5220. col : col,
  5221. message : message,
  5222. evidence: this.lines[line-1],
  5223. rule : rule
  5224. });
  5225. },
  5226. info: function(message, line, col, rule){
  5227. this.messages.push({
  5228. type : "info",
  5229. line : line,
  5230. col : col,
  5231. message : message,
  5232. evidence: this.lines[line-1],
  5233. rule : rule
  5234. });
  5235. },
  5236. rollupError: function(message, rule){
  5237. this.messages.push({
  5238. type : "error",
  5239. rollup : true,
  5240. message : message,
  5241. rule : rule
  5242. });
  5243. },
  5244. rollupWarn: function(message, rule){
  5245. this.messages.push({
  5246. type : "warning",
  5247. rollup : true,
  5248. message : message,
  5249. rule : rule
  5250. });
  5251. },
  5252. stat: function(name, value){
  5253. this.stats[name] = value;
  5254. }
  5255. };
  5256. CSSLint._Reporter = Reporter;
  5257. CSSLint.Util = {
  5258. mix: function(receiver, supplier){
  5259. var prop;
  5260. for (prop in supplier){
  5261. if (supplier.hasOwnProperty(prop)){
  5262. receiver[prop] = supplier[prop];
  5263. }
  5264. }
  5265. return prop;
  5266. },
  5267. indexOf: function(values, value){
  5268. if (values.indexOf){
  5269. return values.indexOf(value);
  5270. } else {
  5271. for (var i=0, len=values.length; i < len; i++){
  5272. if (values[i] === value){
  5273. return i;
  5274. }
  5275. }
  5276. return -1;
  5277. }
  5278. },
  5279. forEach: function(values, func) {
  5280. if (values.forEach){
  5281. return values.forEach(func);
  5282. } else {
  5283. for (var i=0, len=values.length; i < len; i++){
  5284. func(values[i], i, values);
  5285. }
  5286. }
  5287. }
  5288. };
  5289. CSSLint.addRule({
  5290. id: "adjoining-classes",
  5291. name: "Disallow adjoining classes",
  5292. desc: "Don't use adjoining classes.",
  5293. browsers: "IE6",
  5294. init: function(parser, reporter){
  5295. var rule = this;
  5296. parser.addListener("startrule", function(event){
  5297. var selectors = event.selectors,
  5298. selector,
  5299. part,
  5300. modifier,
  5301. classCount,
  5302. i, j, k;
  5303. for (i=0; i < selectors.length; i++){
  5304. selector = selectors[i];
  5305. for (j=0; j < selector.parts.length; j++){
  5306. part = selector.parts[j];
  5307. if (part.type === parser.SELECTOR_PART_TYPE){
  5308. classCount = 0;
  5309. for (k=0; k < part.modifiers.length; k++){
  5310. modifier = part.modifiers[k];
  5311. if (modifier.type === "class"){
  5312. classCount++;
  5313. }
  5314. if (classCount > 1){
  5315. reporter.report("Don't use adjoining classes.", part.line, part.col, rule);
  5316. }
  5317. }
  5318. }
  5319. }
  5320. }
  5321. });
  5322. }
  5323. });
  5324. CSSLint.addRule({
  5325. id: "box-model",
  5326. name: "Beware of broken box size",
  5327. desc: "Don't use width or height when using padding or border.",
  5328. browsers: "All",
  5329. init: function(parser, reporter){
  5330. var rule = this,
  5331. widthProperties = {
  5332. border: 1,
  5333. "border-left": 1,
  5334. "border-right": 1,
  5335. padding: 1,
  5336. "padding-left": 1,
  5337. "padding-right": 1
  5338. },
  5339. heightProperties = {
  5340. border: 1,
  5341. "border-bottom": 1,
  5342. "border-top": 1,
  5343. padding: 1,
  5344. "padding-bottom": 1,
  5345. "padding-top": 1
  5346. },
  5347. properties,
  5348. boxSizing = false;
  5349. function startRule(){
  5350. properties = {};
  5351. boxSizing = false;
  5352. }
  5353. function endRule(){
  5354. var prop, value;
  5355. if (!boxSizing) {
  5356. if (properties.height){
  5357. for (prop in heightProperties){
  5358. if (heightProperties.hasOwnProperty(prop) && properties[prop]){
  5359. value = properties[prop].value;
  5360. if (!(prop === "padding" && value.parts.length === 2 && value.parts[0].value === 0)){
  5361. reporter.report("Using height with " + prop + " can sometimes make elements larger than you expect.", properties[prop].line, properties[prop].col, rule);
  5362. }
  5363. }
  5364. }
  5365. }
  5366. if (properties.width){
  5367. for (prop in widthProperties){
  5368. if (widthProperties.hasOwnProperty(prop) && properties[prop]){
  5369. value = properties[prop].value;
  5370. if (!(prop === "padding" && value.parts.length === 2 && value.parts[1].value === 0)){
  5371. reporter.report("Using width with " + prop + " can sometimes make elements larger than you expect.", properties[prop].line, properties[prop].col, rule);
  5372. }
  5373. }
  5374. }
  5375. }
  5376. }
  5377. }
  5378. parser.addListener("startrule", startRule);
  5379. parser.addListener("startfontface", startRule);
  5380. parser.addListener("startpage", startRule);
  5381. parser.addListener("startpagemargin", startRule);
  5382. parser.addListener("startkeyframerule", startRule);
  5383. parser.addListener("property", function(event){
  5384. var name = event.property.text.toLowerCase();
  5385. if (heightProperties[name] || widthProperties[name]){
  5386. if (!/^0\S*$/.test(event.value) && !(name === "border" && event.value.toString() === "none")){
  5387. properties[name] = { line: event.property.line, col: event.property.col, value: event.value };
  5388. }
  5389. } else {
  5390. if (/^(width|height)/i.test(name) && /^(length|percentage)/.test(event.value.parts[0].type)){
  5391. properties[name] = 1;
  5392. } else if (name === "box-sizing") {
  5393. boxSizing = true;
  5394. }
  5395. }
  5396. });
  5397. parser.addListener("endrule", endRule);
  5398. parser.addListener("endfontface", endRule);
  5399. parser.addListener("endpage", endRule);
  5400. parser.addListener("endpagemargin", endRule);
  5401. parser.addListener("endkeyframerule", endRule);
  5402. }
  5403. });
  5404. CSSLint.addRule({
  5405. id: "box-sizing",
  5406. name: "Disallow use of box-sizing",
  5407. desc: "The box-sizing properties isn't supported in IE6 and IE7.",
  5408. browsers: "IE6, IE7",
  5409. tags: ["Compatibility"],
  5410. init: function(parser, reporter){
  5411. var rule = this;
  5412. parser.addListener("property", function(event){
  5413. var name = event.property.text.toLowerCase();
  5414. if (name === "box-sizing"){
  5415. reporter.report("The box-sizing property isn't supported in IE6 and IE7.", event.line, event.col, rule);
  5416. }
  5417. });
  5418. }
  5419. });
  5420. CSSLint.addRule({
  5421. id: "bulletproof-font-face",
  5422. name: "Use the bulletproof @font-face syntax",
  5423. 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).",
  5424. browsers: "All",
  5425. init: function(parser, reporter){
  5426. var rule = this,
  5427. fontFaceRule = false,
  5428. firstSrc = true,
  5429. ruleFailed = false,
  5430. line, col;
  5431. parser.addListener("startfontface", function(){
  5432. fontFaceRule = true;
  5433. });
  5434. parser.addListener("property", function(event){
  5435. if (!fontFaceRule) {
  5436. return;
  5437. }
  5438. var propertyName = event.property.toString().toLowerCase(),
  5439. value = event.value.toString();
  5440. line = event.line;
  5441. col = event.col;
  5442. if (propertyName === "src") {
  5443. var regex = /^\s?url\(['"].+\.eot\?.*['"]\)\s*format\(['"]embedded-opentype['"]\).*$/i;
  5444. if (!value.match(regex) && firstSrc) {
  5445. ruleFailed = true;
  5446. firstSrc = false;
  5447. } else if (value.match(regex) && !firstSrc) {
  5448. ruleFailed = false;
  5449. }
  5450. }
  5451. });
  5452. parser.addListener("endfontface", function(){
  5453. fontFaceRule = false;
  5454. if (ruleFailed) {
  5455. reporter.report("@font-face declaration doesn't follow the fontspring bulletproof syntax.", line, col, rule);
  5456. }
  5457. });
  5458. }
  5459. });
  5460. CSSLint.addRule({
  5461. id: "compatible-vendor-prefixes",
  5462. name: "Require compatible vendor prefixes",
  5463. desc: "Include all compatible vendor prefixes to reach a wider range of users.",
  5464. browsers: "All",
  5465. init: function (parser, reporter) {
  5466. var rule = this,
  5467. compatiblePrefixes,
  5468. properties,
  5469. prop,
  5470. variations,
  5471. prefixed,
  5472. i,
  5473. len,
  5474. inKeyFrame = false,
  5475. arrayPush = Array.prototype.push,
  5476. applyTo = [];
  5477. compatiblePrefixes = {
  5478. "animation" : "webkit moz",
  5479. "animation-delay" : "webkit moz",
  5480. "animation-direction" : "webkit moz",
  5481. "animation-duration" : "webkit moz",
  5482. "animation-fill-mode" : "webkit moz",
  5483. "animation-iteration-count" : "webkit moz",
  5484. "animation-name" : "webkit moz",
  5485. "animation-play-state" : "webkit moz",
  5486. "animation-timing-function" : "webkit moz",
  5487. "appearance" : "webkit moz",
  5488. "border-end" : "webkit moz",
  5489. "border-end-color" : "webkit moz",
  5490. "border-end-style" : "webkit moz",
  5491. "border-end-width" : "webkit moz",
  5492. "border-image" : "webkit moz o",
  5493. "border-radius" : "webkit",
  5494. "border-start" : "webkit moz",
  5495. "border-start-color" : "webkit moz",
  5496. "border-start-style" : "webkit moz",
  5497. "border-start-width" : "webkit moz",
  5498. "box-align" : "webkit moz ms",
  5499. "box-direction" : "webkit moz ms",
  5500. "box-flex" : "webkit moz ms",
  5501. "box-lines" : "webkit ms",
  5502. "box-ordinal-group" : "webkit moz ms",
  5503. "box-orient" : "webkit moz ms",
  5504. "box-pack" : "webkit moz ms",
  5505. "box-sizing" : "webkit moz",
  5506. "box-shadow" : "webkit moz",
  5507. "column-count" : "webkit moz ms",
  5508. "column-gap" : "webkit moz ms",
  5509. "column-rule" : "webkit moz ms",
  5510. "column-rule-color" : "webkit moz ms",
  5511. "column-rule-style" : "webkit moz ms",
  5512. "column-rule-width" : "webkit moz ms",
  5513. "column-width" : "webkit moz ms",
  5514. "hyphens" : "epub moz",
  5515. "line-break" : "webkit ms",
  5516. "margin-end" : "webkit moz",
  5517. "margin-start" : "webkit moz",
  5518. "marquee-speed" : "webkit wap",
  5519. "marquee-style" : "webkit wap",
  5520. "padding-end" : "webkit moz",
  5521. "padding-start" : "webkit moz",
  5522. "tab-size" : "moz o",
  5523. "text-size-adjust" : "webkit ms",
  5524. "transform" : "webkit moz ms o",
  5525. "transform-origin" : "webkit moz ms o",
  5526. "transition" : "webkit moz o",
  5527. "transition-delay" : "webkit moz o",
  5528. "transition-duration" : "webkit moz o",
  5529. "transition-property" : "webkit moz o",
  5530. "transition-timing-function" : "webkit moz o",
  5531. "user-modify" : "webkit moz",
  5532. "user-select" : "webkit moz ms",
  5533. "word-break" : "epub ms",
  5534. "writing-mode" : "epub ms"
  5535. };
  5536. for (prop in compatiblePrefixes) {
  5537. if (compatiblePrefixes.hasOwnProperty(prop)) {
  5538. variations = [];
  5539. prefixed = compatiblePrefixes[prop].split(" ");
  5540. for (i = 0, len = prefixed.length; i < len; i++) {
  5541. variations.push("-" + prefixed[i] + "-" + prop);
  5542. }
  5543. compatiblePrefixes[prop] = variations;
  5544. arrayPush.apply(applyTo, variations);
  5545. }
  5546. }
  5547. parser.addListener("startrule", function () {
  5548. properties = [];
  5549. });
  5550. parser.addListener("startkeyframes", function (event) {
  5551. inKeyFrame = event.prefix || true;
  5552. });
  5553. parser.addListener("endkeyframes", function () {
  5554. inKeyFrame = false;
  5555. });
  5556. parser.addListener("property", function (event) {
  5557. var name = event.property;
  5558. if (CSSLint.Util.indexOf(applyTo, name.text) > -1) {
  5559. if (!inKeyFrame || typeof inKeyFrame !== "string" ||
  5560. name.text.indexOf("-" + inKeyFrame + "-") !== 0) {
  5561. properties.push(name);
  5562. }
  5563. }
  5564. });
  5565. parser.addListener("endrule", function () {
  5566. if (!properties.length) {
  5567. return;
  5568. }
  5569. var propertyGroups = {},
  5570. i,
  5571. len,
  5572. name,
  5573. prop,
  5574. variations,
  5575. value,
  5576. full,
  5577. actual,
  5578. item,
  5579. propertiesSpecified;
  5580. for (i = 0, len = properties.length; i < len; i++) {
  5581. name = properties[i];
  5582. for (prop in compatiblePrefixes) {
  5583. if (compatiblePrefixes.hasOwnProperty(prop)) {
  5584. variations = compatiblePrefixes[prop];
  5585. if (CSSLint.Util.indexOf(variations, name.text) > -1) {
  5586. if (!propertyGroups[prop]) {
  5587. propertyGroups[prop] = {
  5588. full : variations.slice(0),
  5589. actual : [],
  5590. actualNodes: []
  5591. };
  5592. }
  5593. if (CSSLint.Util.indexOf(propertyGroups[prop].actual, name.text) === -1) {
  5594. propertyGroups[prop].actual.push(name.text);
  5595. propertyGroups[prop].actualNodes.push(name);
  5596. }
  5597. }
  5598. }
  5599. }
  5600. }
  5601. for (prop in propertyGroups) {
  5602. if (propertyGroups.hasOwnProperty(prop)) {
  5603. value = propertyGroups[prop];
  5604. full = value.full;
  5605. actual = value.actual;
  5606. if (full.length > actual.length) {
  5607. for (i = 0, len = full.length; i < len; i++) {
  5608. item = full[i];
  5609. if (CSSLint.Util.indexOf(actual, item) === -1) {
  5610. propertiesSpecified = (actual.length === 1) ? actual[0] : (actual.length === 2) ? actual.join(" and ") : actual.join(", ");
  5611. reporter.report("The property " + item + " is compatible with " + propertiesSpecified + " and should be included as well.", value.actualNodes[0].line, value.actualNodes[0].col, rule);
  5612. }
  5613. }
  5614. }
  5615. }
  5616. }
  5617. });
  5618. }
  5619. });
  5620. CSSLint.addRule({
  5621. id: "display-property-grouping",
  5622. name: "Require properties appropriate for display",
  5623. desc: "Certain properties shouldn't be used with certain display property values.",
  5624. browsers: "All",
  5625. init: function(parser, reporter){
  5626. var rule = this;
  5627. var propertiesToCheck = {
  5628. display: 1,
  5629. "float": "none",
  5630. height: 1,
  5631. width: 1,
  5632. margin: 1,
  5633. "margin-left": 1,
  5634. "margin-right": 1,
  5635. "margin-bottom": 1,
  5636. "margin-top": 1,
  5637. padding: 1,
  5638. "padding-left": 1,
  5639. "padding-right": 1,
  5640. "padding-bottom": 1,
  5641. "padding-top": 1,
  5642. "vertical-align": 1
  5643. },
  5644. properties;
  5645. function reportProperty(name, display, msg){
  5646. if (properties[name]){
  5647. if (typeof propertiesToCheck[name] !== "string" || properties[name].value.toLowerCase() !== propertiesToCheck[name]){
  5648. reporter.report(msg || name + " can't be used with display: " + display + ".", properties[name].line, properties[name].col, rule);
  5649. }
  5650. }
  5651. }
  5652. function startRule(){
  5653. properties = {};
  5654. }
  5655. function endRule(){
  5656. var display = properties.display ? properties.display.value : null;
  5657. if (display){
  5658. switch(display){
  5659. case "inline":
  5660. reportProperty("height", display);
  5661. reportProperty("width", display);
  5662. reportProperty("margin", display);
  5663. reportProperty("margin-top", display);
  5664. reportProperty("margin-bottom", display);
  5665. reportProperty("float", display, "display:inline has no effect on floated elements (but may be used to fix the IE6 double-margin bug).");
  5666. break;
  5667. case "block":
  5668. reportProperty("vertical-align", display);
  5669. break;
  5670. case "inline-block":
  5671. reportProperty("float", display);
  5672. break;
  5673. default:
  5674. if (display.indexOf("table-") === 0){
  5675. reportProperty("margin", display);
  5676. reportProperty("margin-left", display);
  5677. reportProperty("margin-right", display);
  5678. reportProperty("margin-top", display);
  5679. reportProperty("margin-bottom", display);
  5680. reportProperty("float", display);
  5681. }
  5682. }
  5683. }
  5684. }
  5685. parser.addListener("startrule", startRule);
  5686. parser.addListener("startfontface", startRule);
  5687. parser.addListener("startkeyframerule", startRule);
  5688. parser.addListener("startpagemargin", startRule);
  5689. parser.addListener("startpage", startRule);
  5690. parser.addListener("property", function(event){
  5691. var name = event.property.text.toLowerCase();
  5692. if (propertiesToCheck[name]){
  5693. properties[name] = { value: event.value.text, line: event.property.line, col: event.property.col };
  5694. }
  5695. });
  5696. parser.addListener("endrule", endRule);
  5697. parser.addListener("endfontface", endRule);
  5698. parser.addListener("endkeyframerule", endRule);
  5699. parser.addListener("endpagemargin", endRule);
  5700. parser.addListener("endpage", endRule);
  5701. }
  5702. });
  5703. CSSLint.addRule({
  5704. id: "duplicate-background-images",
  5705. name: "Disallow duplicate background images",
  5706. desc: "Every background-image should be unique. Use a common class for e.g. sprites.",
  5707. browsers: "All",
  5708. init: function(parser, reporter){
  5709. var rule = this,
  5710. stack = {};
  5711. parser.addListener("property", function(event){
  5712. var name = event.property.text,
  5713. value = event.value,
  5714. i, len;
  5715. if (name.match(/background/i)) {
  5716. for (i=0, len=value.parts.length; i < len; i++) {
  5717. if (value.parts[i].type === "uri") {
  5718. if (typeof stack[value.parts[i].uri] === "undefined") {
  5719. stack[value.parts[i].uri] = event;
  5720. }
  5721. else {
  5722. 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);
  5723. }
  5724. }
  5725. }
  5726. }
  5727. });
  5728. }
  5729. });
  5730. CSSLint.addRule({
  5731. id: "duplicate-properties",
  5732. name: "Disallow duplicate properties",
  5733. desc: "Duplicate properties must appear one after the other.",
  5734. browsers: "All",
  5735. init: function(parser, reporter){
  5736. var rule = this,
  5737. properties,
  5738. lastProperty;
  5739. function startRule(){
  5740. properties = {};
  5741. }
  5742. parser.addListener("startrule", startRule);
  5743. parser.addListener("startfontface", startRule);
  5744. parser.addListener("startpage", startRule);
  5745. parser.addListener("startpagemargin", startRule);
  5746. parser.addListener("startkeyframerule", startRule);
  5747. parser.addListener("property", function(event){
  5748. var property = event.property,
  5749. name = property.text.toLowerCase();
  5750. if (properties[name] && (lastProperty !== name || properties[name] === event.value.text)){
  5751. reporter.report("Duplicate property '" + event.property + "' found.", event.line, event.col, rule);
  5752. }
  5753. properties[name] = event.value.text;
  5754. lastProperty = name;
  5755. });
  5756. }
  5757. });
  5758. CSSLint.addRule({
  5759. id: "empty-rules",
  5760. name: "Disallow empty rules",
  5761. desc: "Rules without any properties specified should be removed.",
  5762. browsers: "All",
  5763. init: function(parser, reporter){
  5764. var rule = this,
  5765. count = 0;
  5766. parser.addListener("startrule", function(){
  5767. count=0;
  5768. });
  5769. parser.addListener("property", function(){
  5770. count++;
  5771. });
  5772. parser.addListener("endrule", function(event){
  5773. var selectors = event.selectors;
  5774. if (count === 0){
  5775. reporter.report("Rule is empty.", selectors[0].line, selectors[0].col, rule);
  5776. }
  5777. });
  5778. }
  5779. });
  5780. CSSLint.addRule({
  5781. id: "errors",
  5782. name: "Parsing Errors",
  5783. desc: "This rule looks for recoverable syntax errors.",
  5784. browsers: "All",
  5785. init: function(parser, reporter){
  5786. var rule = this;
  5787. parser.addListener("error", function(event){
  5788. reporter.error(event.message, event.line, event.col, rule);
  5789. });
  5790. }
  5791. });
  5792. CSSLint.addRule({
  5793. id: "fallback-colors",
  5794. name: "Require fallback colors",
  5795. desc: "For older browsers that don't support RGBA, HSL, or HSLA, provide a fallback color.",
  5796. browsers: "IE6,IE7,IE8",
  5797. init: function(parser, reporter){
  5798. var rule = this,
  5799. lastProperty,
  5800. propertiesToCheck = {
  5801. color: 1,
  5802. background: 1,
  5803. "border-color": 1,
  5804. "border-top-color": 1,
  5805. "border-right-color": 1,
  5806. "border-bottom-color": 1,
  5807. "border-left-color": 1,
  5808. border: 1,
  5809. "border-top": 1,
  5810. "border-right": 1,
  5811. "border-bottom": 1,
  5812. "border-left": 1,
  5813. "background-color": 1
  5814. },
  5815. properties;
  5816. function startRule(){
  5817. properties = {};
  5818. lastProperty = null;
  5819. }
  5820. parser.addListener("startrule", startRule);
  5821. parser.addListener("startfontface", startRule);
  5822. parser.addListener("startpage", startRule);
  5823. parser.addListener("startpagemargin", startRule);
  5824. parser.addListener("startkeyframerule", startRule);
  5825. parser.addListener("property", function(event){
  5826. var property = event.property,
  5827. name = property.text.toLowerCase(),
  5828. parts = event.value.parts,
  5829. i = 0,
  5830. colorType = "",
  5831. len = parts.length;
  5832. if(propertiesToCheck[name]){
  5833. while(i < len){
  5834. if (parts[i].type === "color"){
  5835. if ("alpha" in parts[i] || "hue" in parts[i]){
  5836. if (/([^\)]+)\(/.test(parts[i])){
  5837. colorType = RegExp.$1.toUpperCase();
  5838. }
  5839. if (!lastProperty || (lastProperty.property.text.toLowerCase() !== name || lastProperty.colorType !== "compat")){
  5840. reporter.report("Fallback " + name + " (hex or RGB) should precede " + colorType + " " + name + ".", event.line, event.col, rule);
  5841. }
  5842. } else {
  5843. event.colorType = "compat";
  5844. }
  5845. }
  5846. i++;
  5847. }
  5848. }
  5849. lastProperty = event;
  5850. });
  5851. }
  5852. });
  5853. CSSLint.addRule({
  5854. id: "floats",
  5855. name: "Disallow too many floats",
  5856. desc: "This rule tests if the float property is used too many times",
  5857. browsers: "All",
  5858. init: function(parser, reporter){
  5859. var rule = this;
  5860. var count = 0;
  5861. parser.addListener("property", function(event){
  5862. if (event.property.text.toLowerCase() === "float" &&
  5863. event.value.text.toLowerCase() !== "none"){
  5864. count++;
  5865. }
  5866. });
  5867. parser.addListener("endstylesheet", function(){
  5868. reporter.stat("floats", count);
  5869. if (count >= 10){
  5870. reporter.rollupWarn("Too many floats (" + count + "), you're probably using them for layout. Consider using a grid system instead.", rule);
  5871. }
  5872. });
  5873. }
  5874. });
  5875. CSSLint.addRule({
  5876. id: "font-faces",
  5877. name: "Don't use too many web fonts",
  5878. desc: "Too many different web fonts in the same stylesheet.",
  5879. browsers: "All",
  5880. init: function(parser, reporter){
  5881. var rule = this,
  5882. count = 0;
  5883. parser.addListener("startfontface", function(){
  5884. count++;
  5885. });
  5886. parser.addListener("endstylesheet", function(){
  5887. if (count > 5){
  5888. reporter.rollupWarn("Too many @font-face declarations (" + count + ").", rule);
  5889. }
  5890. });
  5891. }
  5892. });
  5893. CSSLint.addRule({
  5894. id: "font-sizes",
  5895. name: "Disallow too many font sizes",
  5896. desc: "Checks the number of font-size declarations.",
  5897. browsers: "All",
  5898. init: function(parser, reporter){
  5899. var rule = this,
  5900. count = 0;
  5901. parser.addListener("property", function(event){
  5902. if (event.property.toString() === "font-size"){
  5903. count++;
  5904. }
  5905. });
  5906. parser.addListener("endstylesheet", function(){
  5907. reporter.stat("font-sizes", count);
  5908. if (count >= 10){
  5909. reporter.rollupWarn("Too many font-size declarations (" + count + "), abstraction needed.", rule);
  5910. }
  5911. });
  5912. }
  5913. });
  5914. CSSLint.addRule({
  5915. id: "gradients",
  5916. name: "Require all gradient definitions",
  5917. desc: "When using a vendor-prefixed gradient, make sure to use them all.",
  5918. browsers: "All",
  5919. init: function(parser, reporter){
  5920. var rule = this,
  5921. gradients;
  5922. parser.addListener("startrule", function(){
  5923. gradients = {
  5924. moz: 0,
  5925. webkit: 0,
  5926. oldWebkit: 0,
  5927. o: 0
  5928. };
  5929. });
  5930. parser.addListener("property", function(event){
  5931. if (/\-(moz|o|webkit)(?:\-(?:linear|radial))\-gradient/i.test(event.value)){
  5932. gradients[RegExp.$1] = 1;
  5933. } else if (/\-webkit\-gradient/i.test(event.value)){
  5934. gradients.oldWebkit = 1;
  5935. }
  5936. });
  5937. parser.addListener("endrule", function(event){
  5938. var missing = [];
  5939. if (!gradients.moz){
  5940. missing.push("Firefox 3.6+");
  5941. }
  5942. if (!gradients.webkit){
  5943. missing.push("Webkit (Safari 5+, Chrome)");
  5944. }
  5945. if (!gradients.oldWebkit){
  5946. missing.push("Old Webkit (Safari 4+, Chrome)");
  5947. }
  5948. if (!gradients.o){
  5949. missing.push("Opera 11.1+");
  5950. }
  5951. if (missing.length && missing.length < 4){
  5952. reporter.report("Missing vendor-prefixed CSS gradients for " + missing.join(", ") + ".", event.selectors[0].line, event.selectors[0].col, rule);
  5953. }
  5954. });
  5955. }
  5956. });
  5957. CSSLint.addRule({
  5958. id: "ids",
  5959. name: "Disallow IDs in selectors",
  5960. desc: "Selectors should not contain IDs.",
  5961. browsers: "All",
  5962. init: function(parser, reporter){
  5963. var rule = this;
  5964. parser.addListener("startrule", function(event){
  5965. var selectors = event.selectors,
  5966. selector,
  5967. part,
  5968. modifier,
  5969. idCount,
  5970. i, j, k;
  5971. for (i=0; i < selectors.length; i++){
  5972. selector = selectors[i];
  5973. idCount = 0;
  5974. for (j=0; j < selector.parts.length; j++){
  5975. part = selector.parts[j];
  5976. if (part.type === parser.SELECTOR_PART_TYPE){
  5977. for (k=0; k < part.modifiers.length; k++){
  5978. modifier = part.modifiers[k];
  5979. if (modifier.type === "id"){
  5980. idCount++;
  5981. }
  5982. }
  5983. }
  5984. }
  5985. if (idCount === 1){
  5986. reporter.report("Don't use IDs in selectors.", selector.line, selector.col, rule);
  5987. } else if (idCount > 1){
  5988. reporter.report(idCount + " IDs in the selector, really?", selector.line, selector.col, rule);
  5989. }
  5990. }
  5991. });
  5992. }
  5993. });
  5994. CSSLint.addRule({
  5995. id: "import",
  5996. name: "Disallow @import",
  5997. desc: "Don't use @import, use <link> instead.",
  5998. browsers: "All",
  5999. init: function(parser, reporter){
  6000. var rule = this;
  6001. parser.addListener("import", function(event){
  6002. reporter.report("@import prevents parallel downloads, use <link> instead.", event.line, event.col, rule);
  6003. });
  6004. }
  6005. });
  6006. CSSLint.addRule({
  6007. id: "important",
  6008. name: "Disallow !important",
  6009. desc: "Be careful when using !important declaration",
  6010. browsers: "All",
  6011. init: function(parser, reporter){
  6012. var rule = this,
  6013. count = 0;
  6014. parser.addListener("property", function(event){
  6015. if (event.important === true){
  6016. count++;
  6017. reporter.report("Use of !important", event.line, event.col, rule);
  6018. }
  6019. });
  6020. parser.addListener("endstylesheet", function(){
  6021. reporter.stat("important", count);
  6022. if (count >= 10){
  6023. reporter.rollupWarn("Too many !important declarations (" + count + "), try to use less than 10 to avoid specificity issues.", rule);
  6024. }
  6025. });
  6026. }
  6027. });
  6028. CSSLint.addRule({
  6029. id: "known-properties",
  6030. name: "Require use of known properties",
  6031. desc: "Properties should be known (listed in CSS3 specification) or be a vendor-prefixed property.",
  6032. browsers: "All",
  6033. init: function(parser, reporter){
  6034. var rule = this;
  6035. parser.addListener("property", function(event){
  6036. if (event.invalid) {
  6037. reporter.report(event.invalid.message, event.line, event.col, rule);
  6038. }
  6039. });
  6040. }
  6041. });
  6042. CSSLint.addRule({
  6043. id: "order-alphabetical",
  6044. name: "Alphabetical order",
  6045. desc: "Assure properties are in alphabetical order",
  6046. browsers: "All",
  6047. init: function(parser, reporter){
  6048. var rule = this,
  6049. properties;
  6050. var startRule = function () {
  6051. properties = [];
  6052. };
  6053. parser.addListener("startrule", startRule);
  6054. parser.addListener("startfontface", startRule);
  6055. parser.addListener("startpage", startRule);
  6056. parser.addListener("startpagemargin", startRule);
  6057. parser.addListener("startkeyframerule", startRule);
  6058. parser.addListener("property", function(event){
  6059. var name = event.property.text,
  6060. lowerCasePrefixLessName = name.toLowerCase().replace(/^-.*?-/, "");
  6061. properties.push(lowerCasePrefixLessName);
  6062. });
  6063. parser.addListener("endrule", function(event){
  6064. var currentProperties = properties.join(","),
  6065. expectedProperties = properties.sort().join(",");
  6066. if (currentProperties !== expectedProperties){
  6067. reporter.report("Rule doesn't have all its properties in alphabetical ordered.", event.line, event.col, rule);
  6068. }
  6069. });
  6070. }
  6071. });
  6072. CSSLint.addRule({
  6073. id: "outline-none",
  6074. name: "Disallow outline: none",
  6075. desc: "Use of outline: none or outline: 0 should be limited to :focus rules.",
  6076. browsers: "All",
  6077. tags: ["Accessibility"],
  6078. init: function(parser, reporter){
  6079. var rule = this,
  6080. lastRule;
  6081. function startRule(event){
  6082. if (event.selectors){
  6083. lastRule = {
  6084. line: event.line,
  6085. col: event.col,
  6086. selectors: event.selectors,
  6087. propCount: 0,
  6088. outline: false
  6089. };
  6090. } else {
  6091. lastRule = null;
  6092. }
  6093. }
  6094. function endRule(){
  6095. if (lastRule){
  6096. if (lastRule.outline){
  6097. if (lastRule.selectors.toString().toLowerCase().indexOf(":focus") === -1){
  6098. reporter.report("Outlines should only be modified using :focus.", lastRule.line, lastRule.col, rule);
  6099. } else if (lastRule.propCount === 1) {
  6100. reporter.report("Outlines shouldn't be hidden unless other visual changes are made.", lastRule.line, lastRule.col, rule);
  6101. }
  6102. }
  6103. }
  6104. }
  6105. parser.addListener("startrule", startRule);
  6106. parser.addListener("startfontface", startRule);
  6107. parser.addListener("startpage", startRule);
  6108. parser.addListener("startpagemargin", startRule);
  6109. parser.addListener("startkeyframerule", startRule);
  6110. parser.addListener("property", function(event){
  6111. var name = event.property.text.toLowerCase(),
  6112. value = event.value;
  6113. if (lastRule){
  6114. lastRule.propCount++;
  6115. if (name === "outline" && (value.toString() === "none" || value.toString() === "0")){
  6116. lastRule.outline = true;
  6117. }
  6118. }
  6119. });
  6120. parser.addListener("endrule", endRule);
  6121. parser.addListener("endfontface", endRule);
  6122. parser.addListener("endpage", endRule);
  6123. parser.addListener("endpagemargin", endRule);
  6124. parser.addListener("endkeyframerule", endRule);
  6125. }
  6126. });
  6127. CSSLint.addRule({
  6128. id: "overqualified-elements",
  6129. name: "Disallow overqualified elements",
  6130. desc: "Don't use classes or IDs with elements (a.foo or a#foo).",
  6131. browsers: "All",
  6132. init: function(parser, reporter){
  6133. var rule = this,
  6134. classes = {};
  6135. parser.addListener("startrule", function(event){
  6136. var selectors = event.selectors,
  6137. selector,
  6138. part,
  6139. modifier,
  6140. i, j, k;
  6141. for (i=0; i < selectors.length; i++){
  6142. selector = selectors[i];
  6143. for (j=0; j < selector.parts.length; j++){
  6144. part = selector.parts[j];
  6145. if (part.type === parser.SELECTOR_PART_TYPE){
  6146. for (k=0; k < part.modifiers.length; k++){
  6147. modifier = part.modifiers[k];
  6148. if (part.elementName && modifier.type === "id"){
  6149. reporter.report("Element (" + part + ") is overqualified, just use " + modifier + " without element name.", part.line, part.col, rule);
  6150. } else if (modifier.type === "class"){
  6151. if (!classes[modifier]){
  6152. classes[modifier] = [];
  6153. }
  6154. classes[modifier].push({ modifier: modifier, part: part });
  6155. }
  6156. }
  6157. }
  6158. }
  6159. }
  6160. });
  6161. parser.addListener("endstylesheet", function(){
  6162. var prop;
  6163. for (prop in classes){
  6164. if (classes.hasOwnProperty(prop)){
  6165. if (classes[prop].length === 1 && classes[prop][0].part.elementName){
  6166. 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);
  6167. }
  6168. }
  6169. }
  6170. });
  6171. }
  6172. });
  6173. CSSLint.addRule({
  6174. id: "qualified-headings",
  6175. name: "Disallow qualified headings",
  6176. desc: "Headings should not be qualified (namespaced).",
  6177. browsers: "All",
  6178. init: function(parser, reporter){
  6179. var rule = this;
  6180. parser.addListener("startrule", function(event){
  6181. var selectors = event.selectors,
  6182. selector,
  6183. part,
  6184. i, j;
  6185. for (i=0; i < selectors.length; i++){
  6186. selector = selectors[i];
  6187. for (j=0; j < selector.parts.length; j++){
  6188. part = selector.parts[j];
  6189. if (part.type === parser.SELECTOR_PART_TYPE){
  6190. if (part.elementName && /h[1-6]/.test(part.elementName.toString()) && j > 0){
  6191. reporter.report("Heading (" + part.elementName + ") should not be qualified.", part.line, part.col, rule);
  6192. }
  6193. }
  6194. }
  6195. }
  6196. });
  6197. }
  6198. });
  6199. CSSLint.addRule({
  6200. id: "regex-selectors",
  6201. name: "Disallow selectors that look like regexs",
  6202. desc: "Selectors that look like regular expressions are slow and should be avoided.",
  6203. browsers: "All",
  6204. init: function(parser, reporter){
  6205. var rule = this;
  6206. parser.addListener("startrule", function(event){
  6207. var selectors = event.selectors,
  6208. selector,
  6209. part,
  6210. modifier,
  6211. i, j, k;
  6212. for (i=0; i < selectors.length; i++){
  6213. selector = selectors[i];
  6214. for (j=0; j < selector.parts.length; j++){
  6215. part = selector.parts[j];
  6216. if (part.type === parser.SELECTOR_PART_TYPE){
  6217. for (k=0; k < part.modifiers.length; k++){
  6218. modifier = part.modifiers[k];
  6219. if (modifier.type === "attribute"){
  6220. if (/([\~\|\^\$\*]=)/.test(modifier)){
  6221. reporter.report("Attribute selectors with " + RegExp.$1 + " are slow!", modifier.line, modifier.col, rule);
  6222. }
  6223. }
  6224. }
  6225. }
  6226. }
  6227. }
  6228. });
  6229. }
  6230. });
  6231. CSSLint.addRule({
  6232. id: "rules-count",
  6233. name: "Rules Count",
  6234. desc: "Track how many rules there are.",
  6235. browsers: "All",
  6236. init: function(parser, reporter){
  6237. var count = 0;
  6238. parser.addListener("startrule", function(){
  6239. count++;
  6240. });
  6241. parser.addListener("endstylesheet", function(){
  6242. reporter.stat("rule-count", count);
  6243. });
  6244. }
  6245. });
  6246. CSSLint.addRule({
  6247. id: "selector-max-approaching",
  6248. name: "Warn when approaching the 4095 selector limit for IE",
  6249. desc: "Will warn when selector count is >= 3800 selectors.",
  6250. browsers: "IE",
  6251. init: function(parser, reporter) {
  6252. var rule = this, count = 0;
  6253. parser.addListener("startrule", function(event) {
  6254. count += event.selectors.length;
  6255. });
  6256. parser.addListener("endstylesheet", function() {
  6257. if (count >= 3800) {
  6258. reporter.report("You have " + count + " selectors. Internet Explorer supports a maximum of 4095 selectors per stylesheet. Consider refactoring.",0,0,rule);
  6259. }
  6260. });
  6261. }
  6262. });
  6263. CSSLint.addRule({
  6264. id: "selector-max",
  6265. name: "Error when past the 4095 selector limit for IE",
  6266. desc: "Will error when selector count is > 4095.",
  6267. browsers: "IE",
  6268. init: function(parser, reporter){
  6269. var rule = this, count = 0;
  6270. parser.addListener("startrule", function(event) {
  6271. count += event.selectors.length;
  6272. });
  6273. parser.addListener("endstylesheet", function() {
  6274. if (count > 4095) {
  6275. reporter.report("You have " + count + " selectors. Internet Explorer supports a maximum of 4095 selectors per stylesheet. Consider refactoring.",0,0,rule);
  6276. }
  6277. });
  6278. }
  6279. });
  6280. CSSLint.addRule({
  6281. id: "selector-newline",
  6282. name: "Disallow new-line characters in selectors",
  6283. desc: "New-line characters in selectors are usually a forgotten comma and not a descendant combinator.",
  6284. browsers: "All",
  6285. init: function(parser, reporter) {
  6286. var rule = this;
  6287. function startRule(event) {
  6288. var i, len, selector, p, n, pLen, part, part2, type, currentLine, nextLine,
  6289. selectors = event.selectors;
  6290. for (i = 0, len = selectors.length; i < len; i++) {
  6291. selector = selectors[i];
  6292. for (p = 0, pLen = selector.parts.length; p < pLen; p++) {
  6293. for (n = p + 1; n < pLen; n++) {
  6294. part = selector.parts[p];
  6295. part2 = selector.parts[n];
  6296. type = part.type;
  6297. currentLine = part.line;
  6298. nextLine = part2.line;
  6299. if (type === "descendant" && nextLine > currentLine) {
  6300. reporter.report("newline character found in selector (forgot a comma?)", currentLine, selectors[i].parts[0].col, rule);
  6301. }
  6302. }
  6303. }
  6304. }
  6305. }
  6306. parser.addListener("startrule", startRule);
  6307. }
  6308. });
  6309. CSSLint.addRule({
  6310. id: "shorthand",
  6311. name: "Require shorthand properties",
  6312. desc: "Use shorthand properties where possible.",
  6313. browsers: "All",
  6314. init: function(parser, reporter){
  6315. var rule = this,
  6316. prop, i, len,
  6317. propertiesToCheck = {},
  6318. properties,
  6319. mapping = {
  6320. "margin": [
  6321. "margin-top",
  6322. "margin-bottom",
  6323. "margin-left",
  6324. "margin-right"
  6325. ],
  6326. "padding": [
  6327. "padding-top",
  6328. "padding-bottom",
  6329. "padding-left",
  6330. "padding-right"
  6331. ]
  6332. };
  6333. for (prop in mapping){
  6334. if (mapping.hasOwnProperty(prop)){
  6335. for (i=0, len=mapping[prop].length; i < len; i++){
  6336. propertiesToCheck[mapping[prop][i]] = prop;
  6337. }
  6338. }
  6339. }
  6340. function startRule(){
  6341. properties = {};
  6342. }
  6343. function endRule(event){
  6344. var prop, i, len, total;
  6345. for (prop in mapping){
  6346. if (mapping.hasOwnProperty(prop)){
  6347. total=0;
  6348. for (i=0, len=mapping[prop].length; i < len; i++){
  6349. total += properties[mapping[prop][i]] ? 1 : 0;
  6350. }
  6351. if (total === mapping[prop].length){
  6352. reporter.report("The properties " + mapping[prop].join(", ") + " can be replaced by " + prop + ".", event.line, event.col, rule);
  6353. }
  6354. }
  6355. }
  6356. }
  6357. parser.addListener("startrule", startRule);
  6358. parser.addListener("startfontface", startRule);
  6359. parser.addListener("property", function(event){
  6360. var name = event.property.toString().toLowerCase();
  6361. if (propertiesToCheck[name]){
  6362. properties[name] = 1;
  6363. }
  6364. });
  6365. parser.addListener("endrule", endRule);
  6366. parser.addListener("endfontface", endRule);
  6367. }
  6368. });
  6369. CSSLint.addRule({
  6370. id: "star-property-hack",
  6371. name: "Disallow properties with a star prefix",
  6372. desc: "Checks for the star property hack (targets IE6/7)",
  6373. browsers: "All",
  6374. init: function(parser, reporter){
  6375. var rule = this;
  6376. parser.addListener("property", function(event){
  6377. var property = event.property;
  6378. if (property.hack === "*") {
  6379. reporter.report("Property with star prefix found.", event.property.line, event.property.col, rule);
  6380. }
  6381. });
  6382. }
  6383. });
  6384. CSSLint.addRule({
  6385. id: "text-indent",
  6386. name: "Disallow negative text-indent",
  6387. desc: "Checks for text indent less than -99px",
  6388. browsers: "All",
  6389. init: function(parser, reporter){
  6390. var rule = this,
  6391. textIndent,
  6392. direction;
  6393. function startRule(){
  6394. textIndent = false;
  6395. direction = "inherit";
  6396. }
  6397. function endRule(){
  6398. if (textIndent && direction !== "ltr"){
  6399. 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);
  6400. }
  6401. }
  6402. parser.addListener("startrule", startRule);
  6403. parser.addListener("startfontface", startRule);
  6404. parser.addListener("property", function(event){
  6405. var name = event.property.toString().toLowerCase(),
  6406. value = event.value;
  6407. if (name === "text-indent" && value.parts[0].value < -99){
  6408. textIndent = event.property;
  6409. } else if (name === "direction" && value.toString() === "ltr"){
  6410. direction = "ltr";
  6411. }
  6412. });
  6413. parser.addListener("endrule", endRule);
  6414. parser.addListener("endfontface", endRule);
  6415. }
  6416. });
  6417. CSSLint.addRule({
  6418. id: "underscore-property-hack",
  6419. name: "Disallow properties with an underscore prefix",
  6420. desc: "Checks for the underscore property hack (targets IE6)",
  6421. browsers: "All",
  6422. init: function(parser, reporter){
  6423. var rule = this;
  6424. parser.addListener("property", function(event){
  6425. var property = event.property;
  6426. if (property.hack === "_") {
  6427. reporter.report("Property with underscore prefix found.", event.property.line, event.property.col, rule);
  6428. }
  6429. });
  6430. }
  6431. });
  6432. CSSLint.addRule({
  6433. id: "unique-headings",
  6434. name: "Headings should only be defined once",
  6435. desc: "Headings should be defined only once.",
  6436. browsers: "All",
  6437. init: function(parser, reporter){
  6438. var rule = this;
  6439. var headings = {
  6440. h1: 0,
  6441. h2: 0,
  6442. h3: 0,
  6443. h4: 0,
  6444. h5: 0,
  6445. h6: 0
  6446. };
  6447. parser.addListener("startrule", function(event){
  6448. var selectors = event.selectors,
  6449. selector,
  6450. part,
  6451. pseudo,
  6452. i, j;
  6453. for (i=0; i < selectors.length; i++){
  6454. selector = selectors[i];
  6455. part = selector.parts[selector.parts.length-1];
  6456. if (part.elementName && /(h[1-6])/i.test(part.elementName.toString())){
  6457. for (j=0; j < part.modifiers.length; j++){
  6458. if (part.modifiers[j].type === "pseudo"){
  6459. pseudo = true;
  6460. break;
  6461. }
  6462. }
  6463. if (!pseudo){
  6464. headings[RegExp.$1]++;
  6465. if (headings[RegExp.$1] > 1) {
  6466. reporter.report("Heading (" + part.elementName + ") has already been defined.", part.line, part.col, rule);
  6467. }
  6468. }
  6469. }
  6470. }
  6471. });
  6472. parser.addListener("endstylesheet", function(){
  6473. var prop,
  6474. messages = [];
  6475. for (prop in headings){
  6476. if (headings.hasOwnProperty(prop)){
  6477. if (headings[prop] > 1){
  6478. messages.push(headings[prop] + " " + prop + "s");
  6479. }
  6480. }
  6481. }
  6482. if (messages.length){
  6483. reporter.rollupWarn("You have " + messages.join(", ") + " defined in this stylesheet.", rule);
  6484. }
  6485. });
  6486. }
  6487. });
  6488. CSSLint.addRule({
  6489. id: "universal-selector",
  6490. name: "Disallow universal selector",
  6491. desc: "The universal selector (*) is known to be slow.",
  6492. browsers: "All",
  6493. init: function(parser, reporter){
  6494. var rule = this;
  6495. parser.addListener("startrule", function(event){
  6496. var selectors = event.selectors,
  6497. selector,
  6498. part,
  6499. i;
  6500. for (i=0; i < selectors.length; i++){
  6501. selector = selectors[i];
  6502. part = selector.parts[selector.parts.length-1];
  6503. if (part.elementName === "*"){
  6504. reporter.report(rule.desc, part.line, part.col, rule);
  6505. }
  6506. }
  6507. });
  6508. }
  6509. });
  6510. CSSLint.addRule({
  6511. id: "unqualified-attributes",
  6512. name: "Disallow unqualified attribute selectors",
  6513. desc: "Unqualified attribute selectors are known to be slow.",
  6514. browsers: "All",
  6515. init: function(parser, reporter){
  6516. var rule = this;
  6517. parser.addListener("startrule", function(event){
  6518. var selectors = event.selectors,
  6519. selector,
  6520. part,
  6521. modifier,
  6522. i, k;
  6523. for (i=0; i < selectors.length; i++){
  6524. selector = selectors[i];
  6525. part = selector.parts[selector.parts.length-1];
  6526. if (part.type === parser.SELECTOR_PART_TYPE){
  6527. for (k=0; k < part.modifiers.length; k++){
  6528. modifier = part.modifiers[k];
  6529. if (modifier.type === "attribute" && (!part.elementName || part.elementName === "*")){
  6530. reporter.report(rule.desc, part.line, part.col, rule);
  6531. }
  6532. }
  6533. }
  6534. }
  6535. });
  6536. }
  6537. });
  6538. CSSLint.addRule({
  6539. id: "vendor-prefix",
  6540. name: "Require standard property with vendor prefix",
  6541. desc: "When using a vendor-prefixed property, make sure to include the standard one.",
  6542. browsers: "All",
  6543. init: function(parser, reporter){
  6544. var rule = this,
  6545. properties,
  6546. num,
  6547. propertiesToCheck = {
  6548. "-webkit-border-radius": "border-radius",
  6549. "-webkit-border-top-left-radius": "border-top-left-radius",
  6550. "-webkit-border-top-right-radius": "border-top-right-radius",
  6551. "-webkit-border-bottom-left-radius": "border-bottom-left-radius",
  6552. "-webkit-border-bottom-right-radius": "border-bottom-right-radius",
  6553. "-o-border-radius": "border-radius",
  6554. "-o-border-top-left-radius": "border-top-left-radius",
  6555. "-o-border-top-right-radius": "border-top-right-radius",
  6556. "-o-border-bottom-left-radius": "border-bottom-left-radius",
  6557. "-o-border-bottom-right-radius": "border-bottom-right-radius",
  6558. "-moz-border-radius": "border-radius",
  6559. "-moz-border-radius-topleft": "border-top-left-radius",
  6560. "-moz-border-radius-topright": "border-top-right-radius",
  6561. "-moz-border-radius-bottomleft": "border-bottom-left-radius",
  6562. "-moz-border-radius-bottomright": "border-bottom-right-radius",
  6563. "-moz-column-count": "column-count",
  6564. "-webkit-column-count": "column-count",
  6565. "-moz-column-gap": "column-gap",
  6566. "-webkit-column-gap": "column-gap",
  6567. "-moz-column-rule": "column-rule",
  6568. "-webkit-column-rule": "column-rule",
  6569. "-moz-column-rule-style": "column-rule-style",
  6570. "-webkit-column-rule-style": "column-rule-style",
  6571. "-moz-column-rule-color": "column-rule-color",
  6572. "-webkit-column-rule-color": "column-rule-color",
  6573. "-moz-column-rule-width": "column-rule-width",
  6574. "-webkit-column-rule-width": "column-rule-width",
  6575. "-moz-column-width": "column-width",
  6576. "-webkit-column-width": "column-width",
  6577. "-webkit-column-span": "column-span",
  6578. "-webkit-columns": "columns",
  6579. "-moz-box-shadow": "box-shadow",
  6580. "-webkit-box-shadow": "box-shadow",
  6581. "-moz-transform" : "transform",
  6582. "-webkit-transform" : "transform",
  6583. "-o-transform" : "transform",
  6584. "-ms-transform" : "transform",
  6585. "-moz-transform-origin" : "transform-origin",
  6586. "-webkit-transform-origin" : "transform-origin",
  6587. "-o-transform-origin" : "transform-origin",
  6588. "-ms-transform-origin" : "transform-origin",
  6589. "-moz-box-sizing" : "box-sizing",
  6590. "-webkit-box-sizing" : "box-sizing"
  6591. };
  6592. function startRule(){
  6593. properties = {};
  6594. num = 1;
  6595. }
  6596. function endRule(){
  6597. var prop,
  6598. i,
  6599. len,
  6600. needed,
  6601. actual,
  6602. needsStandard = [];
  6603. for (prop in properties){
  6604. if (propertiesToCheck[prop]){
  6605. needsStandard.push({ actual: prop, needed: propertiesToCheck[prop]});
  6606. }
  6607. }
  6608. for (i=0, len=needsStandard.length; i < len; i++){
  6609. needed = needsStandard[i].needed;
  6610. actual = needsStandard[i].actual;
  6611. if (!properties[needed]){
  6612. reporter.report("Missing standard property '" + needed + "' to go along with '" + actual + "'.", properties[actual][0].name.line, properties[actual][0].name.col, rule);
  6613. } else {
  6614. if (properties[needed][0].pos < properties[actual][0].pos){
  6615. reporter.report("Standard property '" + needed + "' should come after vendor-prefixed property '" + actual + "'.", properties[actual][0].name.line, properties[actual][0].name.col, rule);
  6616. }
  6617. }
  6618. }
  6619. }
  6620. parser.addListener("startrule", startRule);
  6621. parser.addListener("startfontface", startRule);
  6622. parser.addListener("startpage", startRule);
  6623. parser.addListener("startpagemargin", startRule);
  6624. parser.addListener("startkeyframerule", startRule);
  6625. parser.addListener("property", function(event){
  6626. var name = event.property.text.toLowerCase();
  6627. if (!properties[name]){
  6628. properties[name] = [];
  6629. }
  6630. properties[name].push({ name: event.property, value : event.value, pos:num++ });
  6631. });
  6632. parser.addListener("endrule", endRule);
  6633. parser.addListener("endfontface", endRule);
  6634. parser.addListener("endpage", endRule);
  6635. parser.addListener("endpagemargin", endRule);
  6636. parser.addListener("endkeyframerule", endRule);
  6637. }
  6638. });
  6639. CSSLint.addRule({
  6640. id: "zero-units",
  6641. name: "Disallow units for 0 values",
  6642. desc: "You don't need to specify units when a value is 0.",
  6643. browsers: "All",
  6644. init: function(parser, reporter){
  6645. var rule = this;
  6646. parser.addListener("property", function(event){
  6647. var parts = event.value.parts,
  6648. i = 0,
  6649. len = parts.length;
  6650. while(i < len){
  6651. if ((parts[i].units || parts[i].type === "percentage") && parts[i].value === 0 && parts[i].type !== "time"){
  6652. reporter.report("Values of 0 shouldn't have units specified.", parts[i].line, parts[i].col, rule);
  6653. }
  6654. i++;
  6655. }
  6656. });
  6657. }
  6658. });
  6659. (function() {
  6660. var xmlEscape = function(str) {
  6661. if (!str || str.constructor !== String) {
  6662. return "";
  6663. }
  6664. return str.replace(/[\"&><]/g, function(match) {
  6665. switch (match) {
  6666. case "\"":
  6667. return "&quot;";
  6668. case "&":
  6669. return "&amp;";
  6670. case "<":
  6671. return "&lt;";
  6672. case ">":
  6673. return "&gt;";
  6674. }
  6675. });
  6676. };
  6677. CSSLint.addFormatter({
  6678. id: "checkstyle-xml",
  6679. name: "Checkstyle XML format",
  6680. startFormat: function(){
  6681. return "<?xml version=\"1.0\" encoding=\"utf-8\"?><checkstyle>";
  6682. },
  6683. endFormat: function(){
  6684. return "</checkstyle>";
  6685. },
  6686. readError: function(filename, message) {
  6687. return "<file name=\"" + xmlEscape(filename) + "\"><error line=\"0\" column=\"0\" severty=\"error\" message=\"" + xmlEscape(message) + "\"></error></file>";
  6688. },
  6689. formatResults: function(results, filename/*, options*/) {
  6690. var messages = results.messages,
  6691. output = [];
  6692. var generateSource = function(rule) {
  6693. if (!rule || !("name" in rule)) {
  6694. return "";
  6695. }
  6696. return "net.csslint." + rule.name.replace(/\s/g,"");
  6697. };
  6698. if (messages.length > 0) {
  6699. output.push("<file name=\""+filename+"\">");
  6700. CSSLint.Util.forEach(messages, function (message) {
  6701. if (!message.rollup) {
  6702. output.push("<error line=\"" + message.line + "\" column=\"" + message.col + "\" severity=\"" + message.type + "\"" +
  6703. " message=\"" + xmlEscape(message.message) + "\" source=\"" + generateSource(message.rule) +"\"/>");
  6704. }
  6705. });
  6706. output.push("</file>");
  6707. }
  6708. return output.join("");
  6709. }
  6710. });
  6711. }());
  6712. CSSLint.addFormatter({
  6713. id: "compact",
  6714. name: "Compact, 'porcelain' format",
  6715. startFormat: function() {
  6716. return "";
  6717. },
  6718. endFormat: function() {
  6719. return "";
  6720. },
  6721. formatResults: function(results, filename, options) {
  6722. var messages = results.messages,
  6723. output = "";
  6724. options = options || {};
  6725. var capitalize = function(str) {
  6726. return str.charAt(0).toUpperCase() + str.slice(1);
  6727. };
  6728. if (messages.length === 0) {
  6729. return options.quiet ? "" : filename + ": Lint Free!";
  6730. }
  6731. CSSLint.Util.forEach(messages, function(message) {
  6732. if (message.rollup) {
  6733. output += filename + ": " + capitalize(message.type) + " - " + message.message + "\n";
  6734. } else {
  6735. output += filename + ": " + "line " + message.line +
  6736. ", col " + message.col + ", " + capitalize(message.type) + " - " + message.message + " (" + message.rule.id + ")\n";
  6737. }
  6738. });
  6739. return output;
  6740. }
  6741. });
  6742. CSSLint.addFormatter({
  6743. id: "csslint-xml",
  6744. name: "CSSLint XML format",
  6745. startFormat: function(){
  6746. return "<?xml version=\"1.0\" encoding=\"utf-8\"?><csslint>";
  6747. },
  6748. endFormat: function(){
  6749. return "</csslint>";
  6750. },
  6751. formatResults: function(results, filename/*, options*/) {
  6752. var messages = results.messages,
  6753. output = [];
  6754. var escapeSpecialCharacters = function(str) {
  6755. if (!str || str.constructor !== String) {
  6756. return "";
  6757. }
  6758. return str.replace(/\"/g, "'").replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
  6759. };
  6760. if (messages.length > 0) {
  6761. output.push("<file name=\""+filename+"\">");
  6762. CSSLint.Util.forEach(messages, function (message) {
  6763. if (message.rollup) {
  6764. output.push("<issue severity=\"" + message.type + "\" reason=\"" + escapeSpecialCharacters(message.message) + "\" evidence=\"" + escapeSpecialCharacters(message.evidence) + "\"/>");
  6765. } else {
  6766. output.push("<issue line=\"" + message.line + "\" char=\"" + message.col + "\" severity=\"" + message.type + "\"" +
  6767. " reason=\"" + escapeSpecialCharacters(message.message) + "\" evidence=\"" + escapeSpecialCharacters(message.evidence) + "\"/>");
  6768. }
  6769. });
  6770. output.push("</file>");
  6771. }
  6772. return output.join("");
  6773. }
  6774. });
  6775. CSSLint.addFormatter({
  6776. id: "junit-xml",
  6777. name: "JUNIT XML format",
  6778. startFormat: function(){
  6779. return "<?xml version=\"1.0\" encoding=\"utf-8\"?><testsuites>";
  6780. },
  6781. endFormat: function() {
  6782. return "</testsuites>";
  6783. },
  6784. formatResults: function(results, filename/*, options*/) {
  6785. var messages = results.messages,
  6786. output = [],
  6787. tests = {
  6788. "error": 0,
  6789. "failure": 0
  6790. };
  6791. var generateSource = function(rule) {
  6792. if (!rule || !("name" in rule)) {
  6793. return "";
  6794. }
  6795. return "net.csslint." + rule.name.replace(/\s/g,"");
  6796. };
  6797. var escapeSpecialCharacters = function(str) {
  6798. if (!str || str.constructor !== String) {
  6799. return "";
  6800. }
  6801. return str.replace(/\"/g, "'").replace(/</g, "&lt;").replace(/>/g, "&gt;");
  6802. };
  6803. if (messages.length > 0) {
  6804. messages.forEach(function (message) {
  6805. var type = message.type === "warning" ? "error" : message.type;
  6806. if (!message.rollup) {
  6807. output.push("<testcase time=\"0\" name=\"" + generateSource(message.rule) + "\">");
  6808. output.push("<" + type + " message=\"" + escapeSpecialCharacters(message.message) + "\"><![CDATA[" + message.line + ":" + message.col + ":" + escapeSpecialCharacters(message.evidence) + "]]></" + type + ">");
  6809. output.push("</testcase>");
  6810. tests[type] += 1;
  6811. }
  6812. });
  6813. output.unshift("<testsuite time=\"0\" tests=\"" + messages.length + "\" skipped=\"0\" errors=\"" + tests.error + "\" failures=\"" + tests.failure + "\" package=\"net.csslint\" name=\"" + filename + "\">");
  6814. output.push("</testsuite>");
  6815. }
  6816. return output.join("");
  6817. }
  6818. });
  6819. CSSLint.addFormatter({
  6820. id: "lint-xml",
  6821. name: "Lint XML format",
  6822. startFormat: function(){
  6823. return "<?xml version=\"1.0\" encoding=\"utf-8\"?><lint>";
  6824. },
  6825. endFormat: function(){
  6826. return "</lint>";
  6827. },
  6828. formatResults: function(results, filename/*, options*/) {
  6829. var messages = results.messages,
  6830. output = [];
  6831. var escapeSpecialCharacters = function(str) {
  6832. if (!str || str.constructor !== String) {
  6833. return "";
  6834. }
  6835. return str.replace(/\"/g, "'").replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
  6836. };
  6837. if (messages.length > 0) {
  6838. output.push("<file name=\""+filename+"\">");
  6839. CSSLint.Util.forEach(messages, function (message) {
  6840. if (message.rollup) {
  6841. output.push("<issue severity=\"" + message.type + "\" reason=\"" + escapeSpecialCharacters(message.message) + "\" evidence=\"" + escapeSpecialCharacters(message.evidence) + "\"/>");
  6842. } else {
  6843. output.push("<issue line=\"" + message.line + "\" char=\"" + message.col + "\" severity=\"" + message.type + "\"" +
  6844. " reason=\"" + escapeSpecialCharacters(message.message) + "\" evidence=\"" + escapeSpecialCharacters(message.evidence) + "\"/>");
  6845. }
  6846. });
  6847. output.push("</file>");
  6848. }
  6849. return output.join("");
  6850. }
  6851. });
  6852. CSSLint.addFormatter({
  6853. id: "text",
  6854. name: "Plain Text",
  6855. startFormat: function() {
  6856. return "";
  6857. },
  6858. endFormat: function() {
  6859. return "";
  6860. },
  6861. formatResults: function(results, filename, options) {
  6862. var messages = results.messages,
  6863. output = "";
  6864. options = options || {};
  6865. if (messages.length === 0) {
  6866. return options.quiet ? "" : "\n\ncsslint: No errors in " + filename + ".";
  6867. }
  6868. output = "\n\ncsslint: There ";
  6869. if (messages.length === 1) {
  6870. output += "is 1 problem";
  6871. } else {
  6872. output += "are " + messages.length + " problems";
  6873. }
  6874. output += " in " + filename + ".";
  6875. var pos = filename.lastIndexOf("/"),
  6876. shortFilename = filename;
  6877. if (pos === -1){
  6878. pos = filename.lastIndexOf("\\");
  6879. }
  6880. if (pos > -1){
  6881. shortFilename = filename.substring(pos+1);
  6882. }
  6883. CSSLint.Util.forEach(messages, function (message, i) {
  6884. output = output + "\n\n" + shortFilename;
  6885. if (message.rollup) {
  6886. output += "\n" + (i+1) + ": " + message.type;
  6887. output += "\n" + message.message;
  6888. } else {
  6889. output += "\n" + (i+1) + ": " + message.type + " at line " + message.line + ", col " + message.col;
  6890. output += "\n" + message.message;
  6891. output += "\n" + message.evidence;
  6892. }
  6893. });
  6894. return output;
  6895. }
  6896. });
  6897. module.exports.CSSLint = CSSLint;
  6898. });
  6899. ace.define("ace/mode/css_worker",[], function(require, exports, module) {
  6900. "use strict";
  6901. var oop = require("../lib/oop");
  6902. var lang = require("../lib/lang");
  6903. var Mirror = require("../worker/mirror").Mirror;
  6904. var CSSLint = require("./css/csslint").CSSLint;
  6905. var Worker = exports.Worker = function(sender) {
  6906. Mirror.call(this, sender);
  6907. this.setTimeout(400);
  6908. this.ruleset = null;
  6909. this.setDisabledRules("ids|order-alphabetical");
  6910. this.setInfoRules(
  6911. "adjoining-classes|qualified-headings|zero-units|gradients|" +
  6912. "import|outline-none|vendor-prefix"
  6913. );
  6914. };
  6915. oop.inherits(Worker, Mirror);
  6916. (function() {
  6917. this.setInfoRules = function(ruleNames) {
  6918. if (typeof ruleNames == "string")
  6919. ruleNames = ruleNames.split("|");
  6920. this.infoRules = lang.arrayToMap(ruleNames);
  6921. this.doc.getValue() && this.deferredUpdate.schedule(100);
  6922. };
  6923. this.setDisabledRules = function(ruleNames) {
  6924. if (!ruleNames) {
  6925. this.ruleset = null;
  6926. } else {
  6927. if (typeof ruleNames == "string")
  6928. ruleNames = ruleNames.split("|");
  6929. var all = {};
  6930. CSSLint.getRules().forEach(function(x){
  6931. all[x.id] = true;
  6932. });
  6933. ruleNames.forEach(function(x) {
  6934. delete all[x];
  6935. });
  6936. this.ruleset = all;
  6937. }
  6938. this.doc.getValue() && this.deferredUpdate.schedule(100);
  6939. };
  6940. this.onUpdate = function() {
  6941. var value = this.doc.getValue();
  6942. if (!value)
  6943. return this.sender.emit("annotate", []);
  6944. var infoRules = this.infoRules;
  6945. var result = CSSLint.verify(value, this.ruleset);
  6946. this.sender.emit("annotate", result.messages.map(function(msg) {
  6947. return {
  6948. row: msg.line - 1,
  6949. column: msg.col - 1,
  6950. text: msg.message,
  6951. type: infoRules[msg.rule.id] ? "info" : msg.type,
  6952. rule: msg.rule.name
  6953. };
  6954. }));
  6955. };
  6956. }).call(Worker.prototype);
  6957. });