worker-css.js 279 KB

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