worker-css.js 290 KB

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