worker-css.js 290 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765
  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",[], 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",[], 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",[], 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",[], 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",[], 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",[], 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",[], 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. }
  1126. else {
  1127. applyDelta(this.$lines, delta, doNotValidate);
  1128. this._signal("change", delta);
  1129. }
  1130. };
  1131. this.$splitAndapplyLargeDelta = function(delta, MAX) {
  1132. var lines = delta.lines;
  1133. var l = lines.length - MAX + 1;
  1134. var row = delta.start.row;
  1135. var column = delta.start.column;
  1136. for (var from = 0, to = 0; from < l; from = to) {
  1137. to += MAX - 1;
  1138. var chunk = lines.slice(from, to);
  1139. chunk.push("");
  1140. this.applyDelta({
  1141. start: this.pos(row + from, column),
  1142. end: this.pos(row + to, column = 0),
  1143. action: delta.action,
  1144. lines: chunk
  1145. }, true);
  1146. }
  1147. delta.lines = lines.slice(from);
  1148. delta.start.row = row + from;
  1149. delta.start.column = column;
  1150. this.applyDelta(delta, true);
  1151. };
  1152. this.revertDelta = function(delta) {
  1153. this.applyDelta({
  1154. start: this.clonePos(delta.start),
  1155. end: this.clonePos(delta.end),
  1156. action: (delta.action == "insert" ? "remove" : "insert"),
  1157. lines: delta.lines.slice()
  1158. });
  1159. };
  1160. this.indexToPosition = function(index, startRow) {
  1161. var lines = this.$lines || this.getAllLines();
  1162. var newlineLength = this.getNewLineCharacter().length;
  1163. for (var i = startRow || 0, l = lines.length; i < l; i++) {
  1164. index -= lines[i].length + newlineLength;
  1165. if (index < 0)
  1166. return {row: i, column: index + lines[i].length + newlineLength};
  1167. }
  1168. return {row: l-1, column: index + lines[l-1].length + newlineLength};
  1169. };
  1170. this.positionToIndex = function(pos, startRow) {
  1171. var lines = this.$lines || this.getAllLines();
  1172. var newlineLength = this.getNewLineCharacter().length;
  1173. var index = 0;
  1174. var row = Math.min(pos.row, lines.length);
  1175. for (var i = startRow || 0; i < row; ++i)
  1176. index += lines[i].length + newlineLength;
  1177. return index + pos.column;
  1178. };
  1179. }).call(Document.prototype);
  1180. exports.Document = Document;
  1181. });
  1182. ace.define("ace/worker/mirror",[], function(require, exports, module) {
  1183. "use strict";
  1184. var Range = require("../range").Range;
  1185. var Document = require("../document").Document;
  1186. var lang = require("../lib/lang");
  1187. var Mirror = exports.Mirror = function(sender) {
  1188. this.sender = sender;
  1189. var doc = this.doc = new Document("");
  1190. var deferredUpdate = this.deferredUpdate = lang.delayedCall(this.onUpdate.bind(this));
  1191. var _self = this;
  1192. sender.on("change", function(e) {
  1193. var data = e.data;
  1194. if (data[0].start) {
  1195. doc.applyDeltas(data);
  1196. } else {
  1197. for (var i = 0; i < data.length; i += 2) {
  1198. if (Array.isArray(data[i+1])) {
  1199. var d = {action: "insert", start: data[i], lines: data[i+1]};
  1200. } else {
  1201. var d = {action: "remove", start: data[i], end: data[i+1]};
  1202. }
  1203. doc.applyDelta(d, true);
  1204. }
  1205. }
  1206. if (_self.$timeout)
  1207. return deferredUpdate.schedule(_self.$timeout);
  1208. _self.onUpdate();
  1209. });
  1210. };
  1211. (function() {
  1212. this.$timeout = 500;
  1213. this.setTimeout = function(timeout) {
  1214. this.$timeout = timeout;
  1215. };
  1216. this.setValue = function(value) {
  1217. this.doc.setValue(value);
  1218. this.deferredUpdate.schedule(this.$timeout);
  1219. };
  1220. this.getValue = function(callbackId) {
  1221. this.sender.callback(this.doc.getValue(), callbackId);
  1222. };
  1223. this.onUpdate = function() {
  1224. };
  1225. this.isPending = function() {
  1226. return this.deferredUpdate.isPending();
  1227. };
  1228. }).call(Mirror.prototype);
  1229. });
  1230. ace.define("ace/mode/css/csslint",[], function(require, exports, module) {
  1231. var parserlib = {};
  1232. (function(){
  1233. function EventTarget(){
  1234. this._listeners = {};
  1235. }
  1236. EventTarget.prototype = {
  1237. constructor: EventTarget,
  1238. addListener: function(type, listener){
  1239. if (!this._listeners[type]){
  1240. this._listeners[type] = [];
  1241. }
  1242. this._listeners[type].push(listener);
  1243. },
  1244. fire: function(event){
  1245. if (typeof event == "string"){
  1246. event = { type: event };
  1247. }
  1248. if (typeof event.target != "undefined"){
  1249. event.target = this;
  1250. }
  1251. if (typeof event.type == "undefined"){
  1252. throw new Error("Event object missing 'type' property.");
  1253. }
  1254. if (this._listeners[event.type]){
  1255. var listeners = this._listeners[event.type].concat();
  1256. for (var i=0, len=listeners.length; i < len; i++){
  1257. listeners[i].call(this, event);
  1258. }
  1259. }
  1260. },
  1261. removeListener: function(type, listener){
  1262. if (this._listeners[type]){
  1263. var listeners = this._listeners[type];
  1264. for (var i=0, len=listeners.length; i < len; i++){
  1265. if (listeners[i] === listener){
  1266. listeners.splice(i, 1);
  1267. break;
  1268. }
  1269. }
  1270. }
  1271. }
  1272. };
  1273. function StringReader(text){
  1274. this._input = text.replace(/\n\r?/g, "\n");
  1275. this._line = 1;
  1276. this._col = 1;
  1277. this._cursor = 0;
  1278. }
  1279. StringReader.prototype = {
  1280. constructor: StringReader,
  1281. getCol: function(){
  1282. return this._col;
  1283. },
  1284. getLine: function(){
  1285. return this._line ;
  1286. },
  1287. eof: function(){
  1288. return (this._cursor == this._input.length);
  1289. },
  1290. peek: function(count){
  1291. var c = null;
  1292. count = (typeof count == "undefined" ? 1 : count);
  1293. if (this._cursor < this._input.length){
  1294. c = this._input.charAt(this._cursor + count - 1);
  1295. }
  1296. return c;
  1297. },
  1298. read: function(){
  1299. var c = null;
  1300. if (this._cursor < this._input.length){
  1301. if (this._input.charAt(this._cursor) == "\n"){
  1302. this._line++;
  1303. this._col=1;
  1304. } else {
  1305. this._col++;
  1306. }
  1307. c = this._input.charAt(this._cursor++);
  1308. }
  1309. return c;
  1310. },
  1311. mark: function(){
  1312. this._bookmark = {
  1313. cursor: this._cursor,
  1314. line: this._line,
  1315. col: this._col
  1316. };
  1317. },
  1318. reset: function(){
  1319. if (this._bookmark){
  1320. this._cursor = this._bookmark.cursor;
  1321. this._line = this._bookmark.line;
  1322. this._col = this._bookmark.col;
  1323. delete this._bookmark;
  1324. }
  1325. },
  1326. readTo: function(pattern){
  1327. var buffer = "",
  1328. c;
  1329. while (buffer.length < pattern.length || buffer.lastIndexOf(pattern) != buffer.length - pattern.length){
  1330. c = this.read();
  1331. if (c){
  1332. buffer += c;
  1333. } else {
  1334. throw new Error("Expected \"" + pattern + "\" at line " + this._line + ", col " + this._col + ".");
  1335. }
  1336. }
  1337. return buffer;
  1338. },
  1339. readWhile: function(filter){
  1340. var buffer = "",
  1341. c = this.read();
  1342. while(c !== null && filter(c)){
  1343. buffer += c;
  1344. c = this.read();
  1345. }
  1346. return buffer;
  1347. },
  1348. readMatch: function(matcher){
  1349. var source = this._input.substring(this._cursor),
  1350. value = null;
  1351. if (typeof matcher == "string"){
  1352. if (source.indexOf(matcher) === 0){
  1353. value = this.readCount(matcher.length);
  1354. }
  1355. } else if (matcher instanceof RegExp){
  1356. if (matcher.test(source)){
  1357. value = this.readCount(RegExp.lastMatch.length);
  1358. }
  1359. }
  1360. return value;
  1361. },
  1362. readCount: function(count){
  1363. var buffer = "";
  1364. while(count--){
  1365. buffer += this.read();
  1366. }
  1367. return buffer;
  1368. }
  1369. };
  1370. function SyntaxError(message, line, col){
  1371. this.col = col;
  1372. this.line = line;
  1373. this.message = message;
  1374. }
  1375. SyntaxError.prototype = new Error();
  1376. function SyntaxUnit(text, line, col, type){
  1377. this.col = col;
  1378. this.line = line;
  1379. this.text = text;
  1380. this.type = type;
  1381. }
  1382. SyntaxUnit.fromToken = function(token){
  1383. return new SyntaxUnit(token.value, token.startLine, token.startCol);
  1384. };
  1385. SyntaxUnit.prototype = {
  1386. constructor: SyntaxUnit,
  1387. valueOf: function(){
  1388. return this.text;
  1389. },
  1390. toString: function(){
  1391. return this.text;
  1392. }
  1393. };
  1394. function TokenStreamBase(input, tokenData){
  1395. this._reader = input ? new StringReader(input.toString()) : null;
  1396. this._token = null;
  1397. this._tokenData = tokenData;
  1398. this._lt = [];
  1399. this._ltIndex = 0;
  1400. this._ltIndexCache = [];
  1401. }
  1402. TokenStreamBase.createTokenData = function(tokens){
  1403. var nameMap = [],
  1404. typeMap = {},
  1405. tokenData = tokens.concat([]),
  1406. i = 0,
  1407. len = tokenData.length+1;
  1408. tokenData.UNKNOWN = -1;
  1409. tokenData.unshift({name:"EOF"});
  1410. for (; i < len; i++){
  1411. nameMap.push(tokenData[i].name);
  1412. tokenData[tokenData[i].name] = i;
  1413. if (tokenData[i].text){
  1414. typeMap[tokenData[i].text] = i;
  1415. }
  1416. }
  1417. tokenData.name = function(tt){
  1418. return nameMap[tt];
  1419. };
  1420. tokenData.type = function(c){
  1421. return typeMap[c];
  1422. };
  1423. return tokenData;
  1424. };
  1425. TokenStreamBase.prototype = {
  1426. constructor: TokenStreamBase,
  1427. match: function(tokenTypes, channel){
  1428. if (!(tokenTypes instanceof Array)){
  1429. tokenTypes = [tokenTypes];
  1430. }
  1431. var tt = this.get(channel),
  1432. i = 0,
  1433. len = tokenTypes.length;
  1434. while(i < len){
  1435. if (tt == tokenTypes[i++]){
  1436. return true;
  1437. }
  1438. }
  1439. this.unget();
  1440. return false;
  1441. },
  1442. mustMatch: function(tokenTypes, channel){
  1443. var token;
  1444. if (!(tokenTypes instanceof Array)){
  1445. tokenTypes = [tokenTypes];
  1446. }
  1447. if (!this.match.apply(this, arguments)){
  1448. token = this.LT(1);
  1449. throw new SyntaxError("Expected " + this._tokenData[tokenTypes[0]].name +
  1450. " at line " + token.startLine + ", col " + token.startCol + ".", token.startLine, token.startCol);
  1451. }
  1452. },
  1453. advance: function(tokenTypes, channel){
  1454. while(this.LA(0) !== 0 && !this.match(tokenTypes, channel)){
  1455. this.get();
  1456. }
  1457. return this.LA(0);
  1458. },
  1459. get: function(channel){
  1460. var tokenInfo = this._tokenData,
  1461. reader = this._reader,
  1462. value,
  1463. i =0,
  1464. len = tokenInfo.length,
  1465. found = false,
  1466. token,
  1467. info;
  1468. if (this._lt.length && this._ltIndex >= 0 && this._ltIndex < this._lt.length){
  1469. i++;
  1470. this._token = this._lt[this._ltIndex++];
  1471. info = tokenInfo[this._token.type];
  1472. while((info.channel !== undefined && channel !== info.channel) &&
  1473. this._ltIndex < this._lt.length){
  1474. this._token = this._lt[this._ltIndex++];
  1475. info = tokenInfo[this._token.type];
  1476. i++;
  1477. }
  1478. if ((info.channel === undefined || channel === info.channel) &&
  1479. this._ltIndex <= this._lt.length){
  1480. this._ltIndexCache.push(i);
  1481. return this._token.type;
  1482. }
  1483. }
  1484. token = this._getToken();
  1485. if (token.type > -1 && !tokenInfo[token.type].hide){
  1486. token.channel = tokenInfo[token.type].channel;
  1487. this._token = token;
  1488. this._lt.push(token);
  1489. this._ltIndexCache.push(this._lt.length - this._ltIndex + i);
  1490. if (this._lt.length > 5){
  1491. this._lt.shift();
  1492. }
  1493. if (this._ltIndexCache.length > 5){
  1494. this._ltIndexCache.shift();
  1495. }
  1496. this._ltIndex = this._lt.length;
  1497. }
  1498. info = tokenInfo[token.type];
  1499. if (info &&
  1500. (info.hide ||
  1501. (info.channel !== undefined && channel !== info.channel))){
  1502. return this.get(channel);
  1503. } else {
  1504. return token.type;
  1505. }
  1506. },
  1507. LA: function(index){
  1508. var total = index,
  1509. tt;
  1510. if (index > 0){
  1511. if (index > 5){
  1512. throw new Error("Too much lookahead.");
  1513. }
  1514. while(total){
  1515. tt = this.get();
  1516. total--;
  1517. }
  1518. while(total < index){
  1519. this.unget();
  1520. total++;
  1521. }
  1522. } else if (index < 0){
  1523. if(this._lt[this._ltIndex+index]){
  1524. tt = this._lt[this._ltIndex+index].type;
  1525. } else {
  1526. throw new Error("Too much lookbehind.");
  1527. }
  1528. } else {
  1529. tt = this._token.type;
  1530. }
  1531. return tt;
  1532. },
  1533. LT: function(index){
  1534. this.LA(index);
  1535. return this._lt[this._ltIndex+index-1];
  1536. },
  1537. peek: function(){
  1538. return this.LA(1);
  1539. },
  1540. token: function(){
  1541. return this._token;
  1542. },
  1543. tokenName: function(tokenType){
  1544. if (tokenType < 0 || tokenType > this._tokenData.length){
  1545. return "UNKNOWN_TOKEN";
  1546. } else {
  1547. return this._tokenData[tokenType].name;
  1548. }
  1549. },
  1550. tokenType: function(tokenName){
  1551. return this._tokenData[tokenName] || -1;
  1552. },
  1553. unget: function(){
  1554. if (this._ltIndexCache.length){
  1555. this._ltIndex -= this._ltIndexCache.pop();//--;
  1556. this._token = this._lt[this._ltIndex - 1];
  1557. } else {
  1558. throw new Error("Too much lookahead.");
  1559. }
  1560. }
  1561. };
  1562. parserlib.util = {
  1563. StringReader: StringReader,
  1564. SyntaxError : SyntaxError,
  1565. SyntaxUnit : SyntaxUnit,
  1566. EventTarget : EventTarget,
  1567. TokenStreamBase : TokenStreamBase
  1568. };
  1569. })();
  1570. (function(){
  1571. var EventTarget = parserlib.util.EventTarget,
  1572. TokenStreamBase = parserlib.util.TokenStreamBase,
  1573. StringReader = parserlib.util.StringReader,
  1574. SyntaxError = parserlib.util.SyntaxError,
  1575. SyntaxUnit = parserlib.util.SyntaxUnit;
  1576. var Colors = {
  1577. aliceblue :"#f0f8ff",
  1578. antiquewhite :"#faebd7",
  1579. aqua :"#00ffff",
  1580. aquamarine :"#7fffd4",
  1581. azure :"#f0ffff",
  1582. beige :"#f5f5dc",
  1583. bisque :"#ffe4c4",
  1584. black :"#000000",
  1585. blanchedalmond :"#ffebcd",
  1586. blue :"#0000ff",
  1587. blueviolet :"#8a2be2",
  1588. brown :"#a52a2a",
  1589. burlywood :"#deb887",
  1590. cadetblue :"#5f9ea0",
  1591. chartreuse :"#7fff00",
  1592. chocolate :"#d2691e",
  1593. coral :"#ff7f50",
  1594. cornflowerblue :"#6495ed",
  1595. cornsilk :"#fff8dc",
  1596. crimson :"#dc143c",
  1597. cyan :"#00ffff",
  1598. darkblue :"#00008b",
  1599. darkcyan :"#008b8b",
  1600. darkgoldenrod :"#b8860b",
  1601. darkgray :"#a9a9a9",
  1602. darkgrey :"#a9a9a9",
  1603. darkgreen :"#006400",
  1604. darkkhaki :"#bdb76b",
  1605. darkmagenta :"#8b008b",
  1606. darkolivegreen :"#556b2f",
  1607. darkorange :"#ff8c00",
  1608. darkorchid :"#9932cc",
  1609. darkred :"#8b0000",
  1610. darksalmon :"#e9967a",
  1611. darkseagreen :"#8fbc8f",
  1612. darkslateblue :"#483d8b",
  1613. darkslategray :"#2f4f4f",
  1614. darkslategrey :"#2f4f4f",
  1615. darkturquoise :"#00ced1",
  1616. darkviolet :"#9400d3",
  1617. deeppink :"#ff1493",
  1618. deepskyblue :"#00bfff",
  1619. dimgray :"#696969",
  1620. dimgrey :"#696969",
  1621. dodgerblue :"#1e90ff",
  1622. firebrick :"#b22222",
  1623. floralwhite :"#fffaf0",
  1624. forestgreen :"#228b22",
  1625. fuchsia :"#ff00ff",
  1626. gainsboro :"#dcdcdc",
  1627. ghostwhite :"#f8f8ff",
  1628. gold :"#ffd700",
  1629. goldenrod :"#daa520",
  1630. gray :"#808080",
  1631. grey :"#808080",
  1632. green :"#008000",
  1633. greenyellow :"#adff2f",
  1634. honeydew :"#f0fff0",
  1635. hotpink :"#ff69b4",
  1636. indianred :"#cd5c5c",
  1637. indigo :"#4b0082",
  1638. ivory :"#fffff0",
  1639. khaki :"#f0e68c",
  1640. lavender :"#e6e6fa",
  1641. lavenderblush :"#fff0f5",
  1642. lawngreen :"#7cfc00",
  1643. lemonchiffon :"#fffacd",
  1644. lightblue :"#add8e6",
  1645. lightcoral :"#f08080",
  1646. lightcyan :"#e0ffff",
  1647. lightgoldenrodyellow :"#fafad2",
  1648. lightgray :"#d3d3d3",
  1649. lightgrey :"#d3d3d3",
  1650. lightgreen :"#90ee90",
  1651. lightpink :"#ffb6c1",
  1652. lightsalmon :"#ffa07a",
  1653. lightseagreen :"#20b2aa",
  1654. lightskyblue :"#87cefa",
  1655. lightslategray :"#778899",
  1656. lightslategrey :"#778899",
  1657. lightsteelblue :"#b0c4de",
  1658. lightyellow :"#ffffe0",
  1659. lime :"#00ff00",
  1660. limegreen :"#32cd32",
  1661. linen :"#faf0e6",
  1662. magenta :"#ff00ff",
  1663. maroon :"#800000",
  1664. mediumaquamarine:"#66cdaa",
  1665. mediumblue :"#0000cd",
  1666. mediumorchid :"#ba55d3",
  1667. mediumpurple :"#9370d8",
  1668. mediumseagreen :"#3cb371",
  1669. mediumslateblue :"#7b68ee",
  1670. mediumspringgreen :"#00fa9a",
  1671. mediumturquoise :"#48d1cc",
  1672. mediumvioletred :"#c71585",
  1673. midnightblue :"#191970",
  1674. mintcream :"#f5fffa",
  1675. mistyrose :"#ffe4e1",
  1676. moccasin :"#ffe4b5",
  1677. navajowhite :"#ffdead",
  1678. navy :"#000080",
  1679. oldlace :"#fdf5e6",
  1680. olive :"#808000",
  1681. olivedrab :"#6b8e23",
  1682. orange :"#ffa500",
  1683. orangered :"#ff4500",
  1684. orchid :"#da70d6",
  1685. palegoldenrod :"#eee8aa",
  1686. palegreen :"#98fb98",
  1687. paleturquoise :"#afeeee",
  1688. palevioletred :"#d87093",
  1689. papayawhip :"#ffefd5",
  1690. peachpuff :"#ffdab9",
  1691. peru :"#cd853f",
  1692. pink :"#ffc0cb",
  1693. plum :"#dda0dd",
  1694. powderblue :"#b0e0e6",
  1695. purple :"#800080",
  1696. red :"#ff0000",
  1697. rosybrown :"#bc8f8f",
  1698. royalblue :"#4169e1",
  1699. saddlebrown :"#8b4513",
  1700. salmon :"#fa8072",
  1701. sandybrown :"#f4a460",
  1702. seagreen :"#2e8b57",
  1703. seashell :"#fff5ee",
  1704. sienna :"#a0522d",
  1705. silver :"#c0c0c0",
  1706. skyblue :"#87ceeb",
  1707. slateblue :"#6a5acd",
  1708. slategray :"#708090",
  1709. slategrey :"#708090",
  1710. snow :"#fffafa",
  1711. springgreen :"#00ff7f",
  1712. steelblue :"#4682b4",
  1713. tan :"#d2b48c",
  1714. teal :"#008080",
  1715. thistle :"#d8bfd8",
  1716. tomato :"#ff6347",
  1717. turquoise :"#40e0d0",
  1718. violet :"#ee82ee",
  1719. wheat :"#f5deb3",
  1720. white :"#ffffff",
  1721. whitesmoke :"#f5f5f5",
  1722. yellow :"#ffff00",
  1723. yellowgreen :"#9acd32",
  1724. activeBorder :"Active window border.",
  1725. activecaption :"Active window caption.",
  1726. appworkspace :"Background color of multiple document interface.",
  1727. background :"Desktop background.",
  1728. buttonface :"The face background color for 3-D elements that appear 3-D due to one layer of surrounding border.",
  1729. 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.",
  1730. 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.",
  1731. buttontext :"Text on push buttons.",
  1732. captiontext :"Text in caption, size box, and scrollbar arrow box.",
  1733. graytext :"Grayed (disabled) text. This color is set to #000 if the current display driver does not support a solid gray color.",
  1734. greytext :"Greyed (disabled) text. This color is set to #000 if the current display driver does not support a solid grey color.",
  1735. highlight :"Item(s) selected in a control.",
  1736. highlighttext :"Text of item(s) selected in a control.",
  1737. inactiveborder :"Inactive window border.",
  1738. inactivecaption :"Inactive window caption.",
  1739. inactivecaptiontext :"Color of text in an inactive caption.",
  1740. infobackground :"Background color for tooltip controls.",
  1741. infotext :"Text color for tooltip controls.",
  1742. menu :"Menu background.",
  1743. menutext :"Text in menus.",
  1744. scrollbar :"Scroll bar gray area.",
  1745. 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.",
  1746. threedface :"The face background color for 3-D elements that appear 3-D due to two concentric layers of surrounding border.",
  1747. 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.",
  1748. 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.",
  1749. 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.",
  1750. window :"Window background.",
  1751. windowframe :"Window frame.",
  1752. windowtext :"Text in windows."
  1753. };
  1754. function Combinator(text, line, col){
  1755. SyntaxUnit.call(this, text, line, col, Parser.COMBINATOR_TYPE);
  1756. this.type = "unknown";
  1757. if (/^\s+$/.test(text)){
  1758. this.type = "descendant";
  1759. } else if (text == ">"){
  1760. this.type = "child";
  1761. } else if (text == "+"){
  1762. this.type = "adjacent-sibling";
  1763. } else if (text == "~"){
  1764. this.type = "sibling";
  1765. }
  1766. }
  1767. Combinator.prototype = new SyntaxUnit();
  1768. Combinator.prototype.constructor = Combinator;
  1769. function MediaFeature(name, value){
  1770. SyntaxUnit.call(this, "(" + name + (value !== null ? ":" + value : "") + ")", name.startLine, name.startCol, Parser.MEDIA_FEATURE_TYPE);
  1771. this.name = name;
  1772. this.value = value;
  1773. }
  1774. MediaFeature.prototype = new SyntaxUnit();
  1775. MediaFeature.prototype.constructor = MediaFeature;
  1776. function MediaQuery(modifier, mediaType, features, line, col){
  1777. SyntaxUnit.call(this, (modifier ? modifier + " ": "") + (mediaType ? mediaType : "") + (mediaType && features.length > 0 ? " and " : "") + features.join(" and "), line, col, Parser.MEDIA_QUERY_TYPE);
  1778. this.modifier = modifier;
  1779. this.mediaType = mediaType;
  1780. this.features = features;
  1781. }
  1782. MediaQuery.prototype = new SyntaxUnit();
  1783. MediaQuery.prototype.constructor = MediaQuery;
  1784. function Parser(options){
  1785. EventTarget.call(this);
  1786. this.options = options || {};
  1787. this._tokenStream = null;
  1788. }
  1789. Parser.DEFAULT_TYPE = 0;
  1790. Parser.COMBINATOR_TYPE = 1;
  1791. Parser.MEDIA_FEATURE_TYPE = 2;
  1792. Parser.MEDIA_QUERY_TYPE = 3;
  1793. Parser.PROPERTY_NAME_TYPE = 4;
  1794. Parser.PROPERTY_VALUE_TYPE = 5;
  1795. Parser.PROPERTY_VALUE_PART_TYPE = 6;
  1796. Parser.SELECTOR_TYPE = 7;
  1797. Parser.SELECTOR_PART_TYPE = 8;
  1798. Parser.SELECTOR_SUB_PART_TYPE = 9;
  1799. Parser.prototype = function(){
  1800. var proto = new EventTarget(), //new prototype
  1801. prop,
  1802. additions = {
  1803. constructor: Parser,
  1804. DEFAULT_TYPE : 0,
  1805. COMBINATOR_TYPE : 1,
  1806. MEDIA_FEATURE_TYPE : 2,
  1807. MEDIA_QUERY_TYPE : 3,
  1808. PROPERTY_NAME_TYPE : 4,
  1809. PROPERTY_VALUE_TYPE : 5,
  1810. PROPERTY_VALUE_PART_TYPE : 6,
  1811. SELECTOR_TYPE : 7,
  1812. SELECTOR_PART_TYPE : 8,
  1813. SELECTOR_SUB_PART_TYPE : 9,
  1814. _stylesheet: function(){
  1815. var tokenStream = this._tokenStream,
  1816. charset = null,
  1817. count,
  1818. token,
  1819. tt;
  1820. this.fire("startstylesheet");
  1821. this._charset();
  1822. this._skipCruft();
  1823. while (tokenStream.peek() == Tokens.IMPORT_SYM){
  1824. this._import();
  1825. this._skipCruft();
  1826. }
  1827. while (tokenStream.peek() == Tokens.NAMESPACE_SYM){
  1828. this._namespace();
  1829. this._skipCruft();
  1830. }
  1831. tt = tokenStream.peek();
  1832. while(tt > Tokens.EOF){
  1833. try {
  1834. switch(tt){
  1835. case Tokens.MEDIA_SYM:
  1836. this._media();
  1837. this._skipCruft();
  1838. break;
  1839. case Tokens.PAGE_SYM:
  1840. this._page();
  1841. this._skipCruft();
  1842. break;
  1843. case Tokens.FONT_FACE_SYM:
  1844. this._font_face();
  1845. this._skipCruft();
  1846. break;
  1847. case Tokens.KEYFRAMES_SYM:
  1848. this._keyframes();
  1849. this._skipCruft();
  1850. break;
  1851. case Tokens.VIEWPORT_SYM:
  1852. this._viewport();
  1853. this._skipCruft();
  1854. break;
  1855. case Tokens.UNKNOWN_SYM: //unknown @ rule
  1856. tokenStream.get();
  1857. if (!this.options.strict){
  1858. this.fire({
  1859. type: "error",
  1860. error: null,
  1861. message: "Unknown @ rule: " + tokenStream.LT(0).value + ".",
  1862. line: tokenStream.LT(0).startLine,
  1863. col: tokenStream.LT(0).startCol
  1864. });
  1865. count=0;
  1866. while (tokenStream.advance([Tokens.LBRACE, Tokens.RBRACE]) == Tokens.LBRACE){
  1867. count++; //keep track of nesting depth
  1868. }
  1869. while(count){
  1870. tokenStream.advance([Tokens.RBRACE]);
  1871. count--;
  1872. }
  1873. } else {
  1874. throw new SyntaxError("Unknown @ rule.", tokenStream.LT(0).startLine, tokenStream.LT(0).startCol);
  1875. }
  1876. break;
  1877. case Tokens.S:
  1878. this._readWhitespace();
  1879. break;
  1880. default:
  1881. if(!this._ruleset()){
  1882. switch(tt){
  1883. case Tokens.CHARSET_SYM:
  1884. token = tokenStream.LT(1);
  1885. this._charset(false);
  1886. throw new SyntaxError("@charset not allowed here.", token.startLine, token.startCol);
  1887. case Tokens.IMPORT_SYM:
  1888. token = tokenStream.LT(1);
  1889. this._import(false);
  1890. throw new SyntaxError("@import not allowed here.", token.startLine, token.startCol);
  1891. case Tokens.NAMESPACE_SYM:
  1892. token = tokenStream.LT(1);
  1893. this._namespace(false);
  1894. throw new SyntaxError("@namespace not allowed here.", token.startLine, token.startCol);
  1895. default:
  1896. tokenStream.get(); //get the last token
  1897. this._unexpectedToken(tokenStream.token());
  1898. }
  1899. }
  1900. }
  1901. } catch(ex) {
  1902. if (ex instanceof SyntaxError && !this.options.strict){
  1903. this.fire({
  1904. type: "error",
  1905. error: ex,
  1906. message: ex.message,
  1907. line: ex.line,
  1908. col: ex.col
  1909. });
  1910. } else {
  1911. throw ex;
  1912. }
  1913. }
  1914. tt = tokenStream.peek();
  1915. }
  1916. if (tt != Tokens.EOF){
  1917. this._unexpectedToken(tokenStream.token());
  1918. }
  1919. this.fire("endstylesheet");
  1920. },
  1921. _charset: function(emit){
  1922. var tokenStream = this._tokenStream,
  1923. charset,
  1924. token,
  1925. line,
  1926. col;
  1927. if (tokenStream.match(Tokens.CHARSET_SYM)){
  1928. line = tokenStream.token().startLine;
  1929. col = tokenStream.token().startCol;
  1930. this._readWhitespace();
  1931. tokenStream.mustMatch(Tokens.STRING);
  1932. token = tokenStream.token();
  1933. charset = token.value;
  1934. this._readWhitespace();
  1935. tokenStream.mustMatch(Tokens.SEMICOLON);
  1936. if (emit !== false){
  1937. this.fire({
  1938. type: "charset",
  1939. charset:charset,
  1940. line: line,
  1941. col: col
  1942. });
  1943. }
  1944. }
  1945. },
  1946. _import: function(emit){
  1947. var tokenStream = this._tokenStream,
  1948. tt,
  1949. uri,
  1950. importToken,
  1951. mediaList = [];
  1952. tokenStream.mustMatch(Tokens.IMPORT_SYM);
  1953. importToken = tokenStream.token();
  1954. this._readWhitespace();
  1955. tokenStream.mustMatch([Tokens.STRING, Tokens.URI]);
  1956. uri = tokenStream.token().value.replace(/^(?:url\()?["']?([^"']+?)["']?\)?$/, "$1");
  1957. this._readWhitespace();
  1958. mediaList = this._media_query_list();
  1959. tokenStream.mustMatch(Tokens.SEMICOLON);
  1960. this._readWhitespace();
  1961. if (emit !== false){
  1962. this.fire({
  1963. type: "import",
  1964. uri: uri,
  1965. media: mediaList,
  1966. line: importToken.startLine,
  1967. col: importToken.startCol
  1968. });
  1969. }
  1970. },
  1971. _namespace: function(emit){
  1972. var tokenStream = this._tokenStream,
  1973. line,
  1974. col,
  1975. prefix,
  1976. uri;
  1977. tokenStream.mustMatch(Tokens.NAMESPACE_SYM);
  1978. line = tokenStream.token().startLine;
  1979. col = tokenStream.token().startCol;
  1980. this._readWhitespace();
  1981. if (tokenStream.match(Tokens.IDENT)){
  1982. prefix = tokenStream.token().value;
  1983. this._readWhitespace();
  1984. }
  1985. tokenStream.mustMatch([Tokens.STRING, Tokens.URI]);
  1986. uri = tokenStream.token().value.replace(/(?:url\()?["']([^"']+)["']\)?/, "$1");
  1987. this._readWhitespace();
  1988. tokenStream.mustMatch(Tokens.SEMICOLON);
  1989. this._readWhitespace();
  1990. if (emit !== false){
  1991. this.fire({
  1992. type: "namespace",
  1993. prefix: prefix,
  1994. uri: uri,
  1995. line: line,
  1996. col: col
  1997. });
  1998. }
  1999. },
  2000. _media: function(){
  2001. var tokenStream = this._tokenStream,
  2002. line,
  2003. col,
  2004. mediaList;// = [];
  2005. tokenStream.mustMatch(Tokens.MEDIA_SYM);
  2006. line = tokenStream.token().startLine;
  2007. col = tokenStream.token().startCol;
  2008. this._readWhitespace();
  2009. mediaList = this._media_query_list();
  2010. tokenStream.mustMatch(Tokens.LBRACE);
  2011. this._readWhitespace();
  2012. this.fire({
  2013. type: "startmedia",
  2014. media: mediaList,
  2015. line: line,
  2016. col: col
  2017. });
  2018. while(true) {
  2019. if (tokenStream.peek() == Tokens.PAGE_SYM){
  2020. this._page();
  2021. } else if (tokenStream.peek() == Tokens.FONT_FACE_SYM){
  2022. this._font_face();
  2023. } else if (tokenStream.peek() == Tokens.VIEWPORT_SYM){
  2024. this._viewport();
  2025. } else if (!this._ruleset()){
  2026. break;
  2027. }
  2028. }
  2029. tokenStream.mustMatch(Tokens.RBRACE);
  2030. this._readWhitespace();
  2031. this.fire({
  2032. type: "endmedia",
  2033. media: mediaList,
  2034. line: line,
  2035. col: col
  2036. });
  2037. },
  2038. _media_query_list: function(){
  2039. var tokenStream = this._tokenStream,
  2040. mediaList = [];
  2041. this._readWhitespace();
  2042. if (tokenStream.peek() == Tokens.IDENT || tokenStream.peek() == Tokens.LPAREN){
  2043. mediaList.push(this._media_query());
  2044. }
  2045. while(tokenStream.match(Tokens.COMMA)){
  2046. this._readWhitespace();
  2047. mediaList.push(this._media_query());
  2048. }
  2049. return mediaList;
  2050. },
  2051. _media_query: function(){
  2052. var tokenStream = this._tokenStream,
  2053. type = null,
  2054. ident = null,
  2055. token = null,
  2056. expressions = [];
  2057. if (tokenStream.match(Tokens.IDENT)){
  2058. ident = tokenStream.token().value.toLowerCase();
  2059. if (ident != "only" && ident != "not"){
  2060. tokenStream.unget();
  2061. ident = null;
  2062. } else {
  2063. token = tokenStream.token();
  2064. }
  2065. }
  2066. this._readWhitespace();
  2067. if (tokenStream.peek() == Tokens.IDENT){
  2068. type = this._media_type();
  2069. if (token === null){
  2070. token = tokenStream.token();
  2071. }
  2072. } else if (tokenStream.peek() == Tokens.LPAREN){
  2073. if (token === null){
  2074. token = tokenStream.LT(1);
  2075. }
  2076. expressions.push(this._media_expression());
  2077. }
  2078. if (type === null && expressions.length === 0){
  2079. return null;
  2080. } else {
  2081. this._readWhitespace();
  2082. while (tokenStream.match(Tokens.IDENT)){
  2083. if (tokenStream.token().value.toLowerCase() != "and"){
  2084. this._unexpectedToken(tokenStream.token());
  2085. }
  2086. this._readWhitespace();
  2087. expressions.push(this._media_expression());
  2088. }
  2089. }
  2090. return new MediaQuery(ident, type, expressions, token.startLine, token.startCol);
  2091. },
  2092. _media_type: function(){
  2093. return this._media_feature();
  2094. },
  2095. _media_expression: function(){
  2096. var tokenStream = this._tokenStream,
  2097. feature = null,
  2098. token,
  2099. expression = null;
  2100. tokenStream.mustMatch(Tokens.LPAREN);
  2101. this._readWhitespace();
  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. "max-zoom" : "<number> | <percentage> | auto",
  3427. "min-height" : "<length> | <percentage> | <content-sizing> | contain-floats | -moz-contain-floats | -webkit-contain-floats | inherit",
  3428. "min-width" : "<length> | <percentage> | <content-sizing> | contain-floats | -moz-contain-floats | -webkit-contain-floats | inherit",
  3429. "min-zoom" : "<number> | <percentage> | auto",
  3430. "move-to" : 1,
  3431. "nav-down" : 1,
  3432. "nav-index" : 1,
  3433. "nav-left" : 1,
  3434. "nav-right" : 1,
  3435. "nav-up" : 1,
  3436. "opacity" : "<number> | inherit",
  3437. "order" : "<integer>",
  3438. "-webkit-order" : "<integer>",
  3439. "orphans" : "<integer> | inherit",
  3440. "outline" : 1,
  3441. "outline-color" : "<color> | invert | inherit",
  3442. "outline-offset" : 1,
  3443. "outline-style" : "<border-style> | inherit",
  3444. "outline-width" : "<border-width> | inherit",
  3445. "overflow" : "visible | hidden | scroll | auto | inherit",
  3446. "overflow-style" : 1,
  3447. "overflow-wrap" : "normal | break-word",
  3448. "overflow-x" : 1,
  3449. "overflow-y" : 1,
  3450. "padding" : { multi: "<padding-width> | inherit", max: 4 },
  3451. "padding-bottom" : "<padding-width> | inherit",
  3452. "padding-left" : "<padding-width> | inherit",
  3453. "padding-right" : "<padding-width> | inherit",
  3454. "padding-top" : "<padding-width> | inherit",
  3455. "page" : 1,
  3456. "page-break-after" : "auto | always | avoid | left | right | inherit",
  3457. "page-break-before" : "auto | always | avoid | left | right | inherit",
  3458. "page-break-inside" : "auto | avoid | inherit",
  3459. "page-policy" : 1,
  3460. "pause" : 1,
  3461. "pause-after" : 1,
  3462. "pause-before" : 1,
  3463. "perspective" : 1,
  3464. "perspective-origin" : 1,
  3465. "phonemes" : 1,
  3466. "pitch" : 1,
  3467. "pitch-range" : 1,
  3468. "play-during" : 1,
  3469. "pointer-events" : "auto | none | visiblePainted | visibleFill | visibleStroke | visible | painted | fill | stroke | all | inherit",
  3470. "position" : "static | relative | absolute | fixed | inherit",
  3471. "presentation-level" : 1,
  3472. "punctuation-trim" : 1,
  3473. "quotes" : 1,
  3474. "rendering-intent" : 1,
  3475. "resize" : 1,
  3476. "rest" : 1,
  3477. "rest-after" : 1,
  3478. "rest-before" : 1,
  3479. "richness" : 1,
  3480. "right" : "<margin-width> | inherit",
  3481. "rotation" : 1,
  3482. "rotation-point" : 1,
  3483. "ruby-align" : 1,
  3484. "ruby-overhang" : 1,
  3485. "ruby-position" : 1,
  3486. "ruby-span" : 1,
  3487. "size" : 1,
  3488. "speak" : "normal | none | spell-out | inherit",
  3489. "speak-header" : "once | always | inherit",
  3490. "speak-numeral" : "digits | continuous | inherit",
  3491. "speak-punctuation" : "code | none | inherit",
  3492. "speech-rate" : 1,
  3493. "src" : 1,
  3494. "stress" : 1,
  3495. "string-set" : 1,
  3496. "table-layout" : "auto | fixed | inherit",
  3497. "tab-size" : "<integer> | <length>",
  3498. "target" : 1,
  3499. "target-name" : 1,
  3500. "target-new" : 1,
  3501. "target-position" : 1,
  3502. "text-align" : "left | right | center | justify | inherit" ,
  3503. "text-align-last" : 1,
  3504. "text-decoration" : 1,
  3505. "text-emphasis" : 1,
  3506. "text-height" : 1,
  3507. "text-indent" : "<length> | <percentage> | inherit",
  3508. "text-justify" : "auto | none | inter-word | inter-ideograph | inter-cluster | distribute | kashida",
  3509. "text-outline" : 1,
  3510. "text-overflow" : 1,
  3511. "text-rendering" : "auto | optimizeSpeed | optimizeLegibility | geometricPrecision | inherit",
  3512. "text-shadow" : 1,
  3513. "text-transform" : "capitalize | uppercase | lowercase | none | inherit",
  3514. "text-wrap" : "normal | none | avoid",
  3515. "top" : "<margin-width> | inherit",
  3516. "-ms-touch-action" : "auto | none | pan-x | pan-y",
  3517. "touch-action" : "auto | none | pan-x | pan-y",
  3518. "transform" : 1,
  3519. "transform-origin" : 1,
  3520. "transform-style" : 1,
  3521. "transition" : 1,
  3522. "transition-delay" : 1,
  3523. "transition-duration" : 1,
  3524. "transition-property" : 1,
  3525. "transition-timing-function" : 1,
  3526. "unicode-bidi" : "normal | embed | isolate | bidi-override | isolate-override | plaintext | inherit",
  3527. "user-modify" : "read-only | read-write | write-only | inherit",
  3528. "user-select" : "none | text | toggle | element | elements | all | inherit",
  3529. "user-zoom" : "zoom | fixed",
  3530. "vertical-align" : "auto | use-script | baseline | sub | super | top | text-top | central | middle | bottom | text-bottom | <percentage> | <length>",
  3531. "visibility" : "visible | hidden | collapse | inherit",
  3532. "voice-balance" : 1,
  3533. "voice-duration" : 1,
  3534. "voice-family" : 1,
  3535. "voice-pitch" : 1,
  3536. "voice-pitch-range" : 1,
  3537. "voice-rate" : 1,
  3538. "voice-stress" : 1,
  3539. "voice-volume" : 1,
  3540. "volume" : 1,
  3541. "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/
  3542. "white-space-collapse" : 1,
  3543. "widows" : "<integer> | inherit",
  3544. "width" : "<length> | <percentage> | <content-sizing> | auto | inherit",
  3545. "word-break" : "normal | keep-all | break-all",
  3546. "word-spacing" : "<length> | normal | inherit",
  3547. "word-wrap" : "normal | break-word",
  3548. "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",
  3549. "z-index" : "<integer> | auto | inherit",
  3550. "zoom" : "<number> | <percentage> | normal"
  3551. };
  3552. function PropertyName(text, hack, line, col){
  3553. SyntaxUnit.call(this, text, line, col, Parser.PROPERTY_NAME_TYPE);
  3554. this.hack = hack;
  3555. }
  3556. PropertyName.prototype = new SyntaxUnit();
  3557. PropertyName.prototype.constructor = PropertyName;
  3558. PropertyName.prototype.toString = function(){
  3559. return (this.hack ? this.hack : "") + this.text;
  3560. };
  3561. function PropertyValue(parts, line, col){
  3562. SyntaxUnit.call(this, parts.join(" "), line, col, Parser.PROPERTY_VALUE_TYPE);
  3563. this.parts = parts;
  3564. }
  3565. PropertyValue.prototype = new SyntaxUnit();
  3566. PropertyValue.prototype.constructor = PropertyValue;
  3567. function PropertyValueIterator(value){
  3568. this._i = 0;
  3569. this._parts = value.parts;
  3570. this._marks = [];
  3571. this.value = value;
  3572. }
  3573. PropertyValueIterator.prototype.count = function(){
  3574. return this._parts.length;
  3575. };
  3576. PropertyValueIterator.prototype.isFirst = function(){
  3577. return this._i === 0;
  3578. };
  3579. PropertyValueIterator.prototype.hasNext = function(){
  3580. return (this._i < this._parts.length);
  3581. };
  3582. PropertyValueIterator.prototype.mark = function(){
  3583. this._marks.push(this._i);
  3584. };
  3585. PropertyValueIterator.prototype.peek = function(count){
  3586. return this.hasNext() ? this._parts[this._i + (count || 0)] : null;
  3587. };
  3588. PropertyValueIterator.prototype.next = function(){
  3589. return this.hasNext() ? this._parts[this._i++] : null;
  3590. };
  3591. PropertyValueIterator.prototype.previous = function(){
  3592. return this._i > 0 ? this._parts[--this._i] : null;
  3593. };
  3594. PropertyValueIterator.prototype.restore = function(){
  3595. if (this._marks.length){
  3596. this._i = this._marks.pop();
  3597. }
  3598. };
  3599. function PropertyValuePart(text, line, col){
  3600. SyntaxUnit.call(this, text, line, col, Parser.PROPERTY_VALUE_PART_TYPE);
  3601. this.type = "unknown";
  3602. var temp;
  3603. if (/^([+\-]?[\d\.]+)([a-z]+)$/i.test(text)){ //dimension
  3604. this.type = "dimension";
  3605. this.value = +RegExp.$1;
  3606. this.units = RegExp.$2;
  3607. switch(this.units.toLowerCase()){
  3608. case "em":
  3609. case "rem":
  3610. case "ex":
  3611. case "px":
  3612. case "cm":
  3613. case "mm":
  3614. case "in":
  3615. case "pt":
  3616. case "pc":
  3617. case "ch":
  3618. case "vh":
  3619. case "vw":
  3620. case "vmax":
  3621. case "vmin":
  3622. this.type = "length";
  3623. break;
  3624. case "deg":
  3625. case "rad":
  3626. case "grad":
  3627. this.type = "angle";
  3628. break;
  3629. case "ms":
  3630. case "s":
  3631. this.type = "time";
  3632. break;
  3633. case "hz":
  3634. case "khz":
  3635. this.type = "frequency";
  3636. break;
  3637. case "dpi":
  3638. case "dpcm":
  3639. this.type = "resolution";
  3640. break;
  3641. }
  3642. } else if (/^([+\-]?[\d\.]+)%$/i.test(text)){ //percentage
  3643. this.type = "percentage";
  3644. this.value = +RegExp.$1;
  3645. } else if (/^([+\-]?\d+)$/i.test(text)){ //integer
  3646. this.type = "integer";
  3647. this.value = +RegExp.$1;
  3648. } else if (/^([+\-]?[\d\.]+)$/i.test(text)){ //number
  3649. this.type = "number";
  3650. this.value = +RegExp.$1;
  3651. } else if (/^#([a-f0-9]{3,6})/i.test(text)){ //hexcolor
  3652. this.type = "color";
  3653. temp = RegExp.$1;
  3654. if (temp.length == 3){
  3655. this.red = parseInt(temp.charAt(0)+temp.charAt(0),16);
  3656. this.green = parseInt(temp.charAt(1)+temp.charAt(1),16);
  3657. this.blue = parseInt(temp.charAt(2)+temp.charAt(2),16);
  3658. } else {
  3659. this.red = parseInt(temp.substring(0,2),16);
  3660. this.green = parseInt(temp.substring(2,4),16);
  3661. this.blue = parseInt(temp.substring(4,6),16);
  3662. }
  3663. } else if (/^rgb\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)/i.test(text)){ //rgb() color with absolute numbers
  3664. this.type = "color";
  3665. this.red = +RegExp.$1;
  3666. this.green = +RegExp.$2;
  3667. this.blue = +RegExp.$3;
  3668. } else if (/^rgb\(\s*(\d+)%\s*,\s*(\d+)%\s*,\s*(\d+)%\s*\)/i.test(text)){ //rgb() color with percentages
  3669. this.type = "color";
  3670. this.red = +RegExp.$1 * 255 / 100;
  3671. this.green = +RegExp.$2 * 255 / 100;
  3672. this.blue = +RegExp.$3 * 255 / 100;
  3673. } else if (/^rgba\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*,\s*([\d\.]+)\s*\)/i.test(text)){ //rgba() color with absolute numbers
  3674. this.type = "color";
  3675. this.red = +RegExp.$1;
  3676. this.green = +RegExp.$2;
  3677. this.blue = +RegExp.$3;
  3678. this.alpha = +RegExp.$4;
  3679. } else if (/^rgba\(\s*(\d+)%\s*,\s*(\d+)%\s*,\s*(\d+)%\s*,\s*([\d\.]+)\s*\)/i.test(text)){ //rgba() color with percentages
  3680. this.type = "color";
  3681. this.red = +RegExp.$1 * 255 / 100;
  3682. this.green = +RegExp.$2 * 255 / 100;
  3683. this.blue = +RegExp.$3 * 255 / 100;
  3684. this.alpha = +RegExp.$4;
  3685. } else if (/^hsl\(\s*(\d+)\s*,\s*(\d+)%\s*,\s*(\d+)%\s*\)/i.test(text)){ //hsl()
  3686. this.type = "color";
  3687. this.hue = +RegExp.$1;
  3688. this.saturation = +RegExp.$2 / 100;
  3689. this.lightness = +RegExp.$3 / 100;
  3690. } else if (/^hsla\(\s*(\d+)\s*,\s*(\d+)%\s*,\s*(\d+)%\s*,\s*([\d\.]+)\s*\)/i.test(text)){ //hsla() color with percentages
  3691. this.type = "color";
  3692. this.hue = +RegExp.$1;
  3693. this.saturation = +RegExp.$2 / 100;
  3694. this.lightness = +RegExp.$3 / 100;
  3695. this.alpha = +RegExp.$4;
  3696. } else if (/^url\(["']?([^\)"']+)["']?\)/i.test(text)){ //URI
  3697. this.type = "uri";
  3698. this.uri = RegExp.$1;
  3699. } else if (/^([^\(]+)\(/i.test(text)){
  3700. this.type = "function";
  3701. this.name = RegExp.$1;
  3702. this.value = text;
  3703. } else if (/^["'][^"']*["']/.test(text)){ //string
  3704. this.type = "string";
  3705. this.value = eval(text);
  3706. } else if (Colors[text.toLowerCase()]){ //named color
  3707. this.type = "color";
  3708. temp = Colors[text.toLowerCase()].substring(1);
  3709. this.red = parseInt(temp.substring(0,2),16);
  3710. this.green = parseInt(temp.substring(2,4),16);
  3711. this.blue = parseInt(temp.substring(4,6),16);
  3712. } else if (/^[\,\/]$/.test(text)){
  3713. this.type = "operator";
  3714. this.value = text;
  3715. } else if (/^[a-z\-_\u0080-\uFFFF][a-z0-9\-_\u0080-\uFFFF]*$/i.test(text)){
  3716. this.type = "identifier";
  3717. this.value = text;
  3718. }
  3719. }
  3720. PropertyValuePart.prototype = new SyntaxUnit();
  3721. PropertyValuePart.prototype.constructor = PropertyValuePart;
  3722. PropertyValuePart.fromToken = function(token){
  3723. return new PropertyValuePart(token.value, token.startLine, token.startCol);
  3724. };
  3725. var Pseudos = {
  3726. ":first-letter": 1,
  3727. ":first-line": 1,
  3728. ":before": 1,
  3729. ":after": 1
  3730. };
  3731. Pseudos.ELEMENT = 1;
  3732. Pseudos.CLASS = 2;
  3733. Pseudos.isElement = function(pseudo){
  3734. return pseudo.indexOf("::") === 0 || Pseudos[pseudo.toLowerCase()] == Pseudos.ELEMENT;
  3735. };
  3736. function Selector(parts, line, col){
  3737. SyntaxUnit.call(this, parts.join(" "), line, col, Parser.SELECTOR_TYPE);
  3738. this.parts = parts;
  3739. this.specificity = Specificity.calculate(this);
  3740. }
  3741. Selector.prototype = new SyntaxUnit();
  3742. Selector.prototype.constructor = Selector;
  3743. function SelectorPart(elementName, modifiers, text, line, col){
  3744. SyntaxUnit.call(this, text, line, col, Parser.SELECTOR_PART_TYPE);
  3745. this.elementName = elementName;
  3746. this.modifiers = modifiers;
  3747. }
  3748. SelectorPart.prototype = new SyntaxUnit();
  3749. SelectorPart.prototype.constructor = SelectorPart;
  3750. function SelectorSubPart(text, type, line, col){
  3751. SyntaxUnit.call(this, text, line, col, Parser.SELECTOR_SUB_PART_TYPE);
  3752. this.type = type;
  3753. this.args = [];
  3754. }
  3755. SelectorSubPart.prototype = new SyntaxUnit();
  3756. SelectorSubPart.prototype.constructor = SelectorSubPart;
  3757. function Specificity(a, b, c, d){
  3758. this.a = a;
  3759. this.b = b;
  3760. this.c = c;
  3761. this.d = d;
  3762. }
  3763. Specificity.prototype = {
  3764. constructor: Specificity,
  3765. compare: function(other){
  3766. var comps = ["a", "b", "c", "d"],
  3767. i, len;
  3768. for (i=0, len=comps.length; i < len; i++){
  3769. if (this[comps[i]] < other[comps[i]]){
  3770. return -1;
  3771. } else if (this[comps[i]] > other[comps[i]]){
  3772. return 1;
  3773. }
  3774. }
  3775. return 0;
  3776. },
  3777. valueOf: function(){
  3778. return (this.a * 1000) + (this.b * 100) + (this.c * 10) + this.d;
  3779. },
  3780. toString: function(){
  3781. return this.a + "," + this.b + "," + this.c + "," + this.d;
  3782. }
  3783. };
  3784. Specificity.calculate = function(selector){
  3785. var i, len,
  3786. part,
  3787. b=0, c=0, d=0;
  3788. function updateValues(part){
  3789. var i, j, len, num,
  3790. elementName = part.elementName ? part.elementName.text : "",
  3791. modifier;
  3792. if (elementName && elementName.charAt(elementName.length-1) != "*") {
  3793. d++;
  3794. }
  3795. for (i=0, len=part.modifiers.length; i < len; i++){
  3796. modifier = part.modifiers[i];
  3797. switch(modifier.type){
  3798. case "class":
  3799. case "attribute":
  3800. c++;
  3801. break;
  3802. case "id":
  3803. b++;
  3804. break;
  3805. case "pseudo":
  3806. if (Pseudos.isElement(modifier.text)){
  3807. d++;
  3808. } else {
  3809. c++;
  3810. }
  3811. break;
  3812. case "not":
  3813. for (j=0, num=modifier.args.length; j < num; j++){
  3814. updateValues(modifier.args[j]);
  3815. }
  3816. }
  3817. }
  3818. }
  3819. for (i=0, len=selector.parts.length; i < len; i++){
  3820. part = selector.parts[i];
  3821. if (part instanceof SelectorPart){
  3822. updateValues(part);
  3823. }
  3824. }
  3825. return new Specificity(0, b, c, d);
  3826. };
  3827. var h = /^[0-9a-fA-F]$/,
  3828. nonascii = /^[\u0080-\uFFFF]$/,
  3829. nl = /\n|\r\n|\r|\f/;
  3830. function isHexDigit(c){
  3831. return c !== null && h.test(c);
  3832. }
  3833. function isDigit(c){
  3834. return c !== null && /\d/.test(c);
  3835. }
  3836. function isWhitespace(c){
  3837. return c !== null && /\s/.test(c);
  3838. }
  3839. function isNewLine(c){
  3840. return c !== null && nl.test(c);
  3841. }
  3842. function isNameStart(c){
  3843. return c !== null && (/[a-z_\u0080-\uFFFF\\]/i.test(c));
  3844. }
  3845. function isNameChar(c){
  3846. return c !== null && (isNameStart(c) || /[0-9\-\\]/.test(c));
  3847. }
  3848. function isIdentStart(c){
  3849. return c !== null && (isNameStart(c) || /\-\\/.test(c));
  3850. }
  3851. function mix(receiver, supplier){
  3852. for (var prop in supplier){
  3853. if (supplier.hasOwnProperty(prop)){
  3854. receiver[prop] = supplier[prop];
  3855. }
  3856. }
  3857. return receiver;
  3858. }
  3859. function TokenStream(input){
  3860. TokenStreamBase.call(this, input, Tokens);
  3861. }
  3862. TokenStream.prototype = mix(new TokenStreamBase(), {
  3863. _getToken: function(channel){
  3864. var c,
  3865. reader = this._reader,
  3866. token = null,
  3867. startLine = reader.getLine(),
  3868. startCol = reader.getCol();
  3869. c = reader.read();
  3870. while(c){
  3871. switch(c){
  3872. case "/":
  3873. if(reader.peek() == "*"){
  3874. token = this.commentToken(c, startLine, startCol);
  3875. } else {
  3876. token = this.charToken(c, startLine, startCol);
  3877. }
  3878. break;
  3879. case "|":
  3880. case "~":
  3881. case "^":
  3882. case "$":
  3883. case "*":
  3884. if(reader.peek() == "="){
  3885. token = this.comparisonToken(c, startLine, startCol);
  3886. } else {
  3887. token = this.charToken(c, startLine, startCol);
  3888. }
  3889. break;
  3890. case "\"":
  3891. case "'":
  3892. token = this.stringToken(c, startLine, startCol);
  3893. break;
  3894. case "#":
  3895. if (isNameChar(reader.peek())){
  3896. token = this.hashToken(c, startLine, startCol);
  3897. } else {
  3898. token = this.charToken(c, startLine, startCol);
  3899. }
  3900. break;
  3901. case ".":
  3902. if (isDigit(reader.peek())){
  3903. token = this.numberToken(c, startLine, startCol);
  3904. } else {
  3905. token = this.charToken(c, startLine, startCol);
  3906. }
  3907. break;
  3908. case "-":
  3909. if (reader.peek() == "-"){ //could be closing HTML-style comment
  3910. token = this.htmlCommentEndToken(c, startLine, startCol);
  3911. } else if (isNameStart(reader.peek())){
  3912. token = this.identOrFunctionToken(c, startLine, startCol);
  3913. } else {
  3914. token = this.charToken(c, startLine, startCol);
  3915. }
  3916. break;
  3917. case "!":
  3918. token = this.importantToken(c, startLine, startCol);
  3919. break;
  3920. case "@":
  3921. token = this.atRuleToken(c, startLine, startCol);
  3922. break;
  3923. case ":":
  3924. token = this.notToken(c, startLine, startCol);
  3925. break;
  3926. case "<":
  3927. token = this.htmlCommentStartToken(c, startLine, startCol);
  3928. break;
  3929. case "U":
  3930. case "u":
  3931. if (reader.peek() == "+"){
  3932. token = this.unicodeRangeToken(c, startLine, startCol);
  3933. break;
  3934. }
  3935. default:
  3936. if (isDigit(c)){
  3937. token = this.numberToken(c, startLine, startCol);
  3938. } else
  3939. if (isWhitespace(c)){
  3940. token = this.whitespaceToken(c, startLine, startCol);
  3941. } else
  3942. if (isIdentStart(c)){
  3943. token = this.identOrFunctionToken(c, startLine, startCol);
  3944. } else
  3945. {
  3946. token = this.charToken(c, startLine, startCol);
  3947. }
  3948. }
  3949. break;
  3950. }
  3951. if (!token && c === null){
  3952. token = this.createToken(Tokens.EOF,null,startLine,startCol);
  3953. }
  3954. return token;
  3955. },
  3956. createToken: function(tt, value, startLine, startCol, options){
  3957. var reader = this._reader;
  3958. options = options || {};
  3959. return {
  3960. value: value,
  3961. type: tt,
  3962. channel: options.channel,
  3963. endChar: options.endChar,
  3964. hide: options.hide || false,
  3965. startLine: startLine,
  3966. startCol: startCol,
  3967. endLine: reader.getLine(),
  3968. endCol: reader.getCol()
  3969. };
  3970. },
  3971. atRuleToken: function(first, startLine, startCol){
  3972. var rule = first,
  3973. reader = this._reader,
  3974. tt = Tokens.CHAR,
  3975. valid = false,
  3976. ident,
  3977. c;
  3978. reader.mark();
  3979. ident = this.readName();
  3980. rule = first + ident;
  3981. tt = Tokens.type(rule.toLowerCase());
  3982. if (tt == Tokens.CHAR || tt == Tokens.UNKNOWN){
  3983. if (rule.length > 1){
  3984. tt = Tokens.UNKNOWN_SYM;
  3985. } else {
  3986. tt = Tokens.CHAR;
  3987. rule = first;
  3988. reader.reset();
  3989. }
  3990. }
  3991. return this.createToken(tt, rule, startLine, startCol);
  3992. },
  3993. charToken: function(c, startLine, startCol){
  3994. var tt = Tokens.type(c);
  3995. var opts = {};
  3996. if (tt == -1){
  3997. tt = Tokens.CHAR;
  3998. } else {
  3999. opts.endChar = Tokens[tt].endChar;
  4000. }
  4001. return this.createToken(tt, c, startLine, startCol, opts);
  4002. },
  4003. commentToken: function(first, startLine, startCol){
  4004. var reader = this._reader,
  4005. comment = this.readComment(first);
  4006. return this.createToken(Tokens.COMMENT, comment, startLine, startCol);
  4007. },
  4008. comparisonToken: function(c, startLine, startCol){
  4009. var reader = this._reader,
  4010. comparison = c + reader.read(),
  4011. tt = Tokens.type(comparison) || Tokens.CHAR;
  4012. return this.createToken(tt, comparison, startLine, startCol);
  4013. },
  4014. hashToken: function(first, startLine, startCol){
  4015. var reader = this._reader,
  4016. name = this.readName(first);
  4017. return this.createToken(Tokens.HASH, name, startLine, startCol);
  4018. },
  4019. htmlCommentStartToken: function(first, startLine, startCol){
  4020. var reader = this._reader,
  4021. text = first;
  4022. reader.mark();
  4023. text += reader.readCount(3);
  4024. if (text == "<!--"){
  4025. return this.createToken(Tokens.CDO, text, startLine, startCol);
  4026. } else {
  4027. reader.reset();
  4028. return this.charToken(first, startLine, startCol);
  4029. }
  4030. },
  4031. htmlCommentEndToken: function(first, startLine, startCol){
  4032. var reader = this._reader,
  4033. text = first;
  4034. reader.mark();
  4035. text += reader.readCount(2);
  4036. if (text == "-->"){
  4037. return this.createToken(Tokens.CDC, text, startLine, startCol);
  4038. } else {
  4039. reader.reset();
  4040. return this.charToken(first, startLine, startCol);
  4041. }
  4042. },
  4043. identOrFunctionToken: function(first, startLine, startCol){
  4044. var reader = this._reader,
  4045. ident = this.readName(first),
  4046. tt = Tokens.IDENT;
  4047. if (reader.peek() == "("){
  4048. ident += reader.read();
  4049. if (ident.toLowerCase() == "url("){
  4050. tt = Tokens.URI;
  4051. ident = this.readURI(ident);
  4052. if (ident.toLowerCase() == "url("){
  4053. tt = Tokens.FUNCTION;
  4054. }
  4055. } else {
  4056. tt = Tokens.FUNCTION;
  4057. }
  4058. } else if (reader.peek() == ":"){ //might be an IE function
  4059. if (ident.toLowerCase() == "progid"){
  4060. ident += reader.readTo("(");
  4061. tt = Tokens.IE_FUNCTION;
  4062. }
  4063. }
  4064. return this.createToken(tt, ident, startLine, startCol);
  4065. },
  4066. importantToken: function(first, startLine, startCol){
  4067. var reader = this._reader,
  4068. important = first,
  4069. tt = Tokens.CHAR,
  4070. temp,
  4071. c;
  4072. reader.mark();
  4073. c = reader.read();
  4074. while(c){
  4075. if (c == "/"){
  4076. if (reader.peek() != "*"){
  4077. break;
  4078. } else {
  4079. temp = this.readComment(c);
  4080. if (temp === ""){ //broken!
  4081. break;
  4082. }
  4083. }
  4084. } else if (isWhitespace(c)){
  4085. important += c + this.readWhitespace();
  4086. } else if (/i/i.test(c)){
  4087. temp = reader.readCount(8);
  4088. if (/mportant/i.test(temp)){
  4089. important += c + temp;
  4090. tt = Tokens.IMPORTANT_SYM;
  4091. }
  4092. break; //we're done
  4093. } else {
  4094. break;
  4095. }
  4096. c = reader.read();
  4097. }
  4098. if (tt == Tokens.CHAR){
  4099. reader.reset();
  4100. return this.charToken(first, startLine, startCol);
  4101. } else {
  4102. return this.createToken(tt, important, startLine, startCol);
  4103. }
  4104. },
  4105. notToken: function(first, startLine, startCol){
  4106. var reader = this._reader,
  4107. text = first;
  4108. reader.mark();
  4109. text += reader.readCount(4);
  4110. if (text.toLowerCase() == ":not("){
  4111. return this.createToken(Tokens.NOT, text, startLine, startCol);
  4112. } else {
  4113. reader.reset();
  4114. return this.charToken(first, startLine, startCol);
  4115. }
  4116. },
  4117. numberToken: function(first, startLine, startCol){
  4118. var reader = this._reader,
  4119. value = this.readNumber(first),
  4120. ident,
  4121. tt = Tokens.NUMBER,
  4122. c = reader.peek();
  4123. if (isIdentStart(c)){
  4124. ident = this.readName(reader.read());
  4125. value += ident;
  4126. if (/^em$|^ex$|^px$|^gd$|^rem$|^vw$|^vh$|^vmax$|^vmin$|^ch$|^cm$|^mm$|^in$|^pt$|^pc$/i.test(ident)){
  4127. tt = Tokens.LENGTH;
  4128. } else if (/^deg|^rad$|^grad$/i.test(ident)){
  4129. tt = Tokens.ANGLE;
  4130. } else if (/^ms$|^s$/i.test(ident)){
  4131. tt = Tokens.TIME;
  4132. } else if (/^hz$|^khz$/i.test(ident)){
  4133. tt = Tokens.FREQ;
  4134. } else if (/^dpi$|^dpcm$/i.test(ident)){
  4135. tt = Tokens.RESOLUTION;
  4136. } else {
  4137. tt = Tokens.DIMENSION;
  4138. }
  4139. } else if (c == "%"){
  4140. value += reader.read();
  4141. tt = Tokens.PERCENTAGE;
  4142. }
  4143. return this.createToken(tt, value, startLine, startCol);
  4144. },
  4145. stringToken: function(first, startLine, startCol){
  4146. var delim = first,
  4147. string = first,
  4148. reader = this._reader,
  4149. prev = first,
  4150. tt = Tokens.STRING,
  4151. c = reader.read();
  4152. while(c){
  4153. string += c;
  4154. if (c == delim && prev != "\\"){
  4155. break;
  4156. }
  4157. if (isNewLine(reader.peek()) && c != "\\"){
  4158. tt = Tokens.INVALID;
  4159. break;
  4160. }
  4161. prev = c;
  4162. c = reader.read();
  4163. }
  4164. if (c === null){
  4165. tt = Tokens.INVALID;
  4166. }
  4167. return this.createToken(tt, string, startLine, startCol);
  4168. },
  4169. unicodeRangeToken: function(first, startLine, startCol){
  4170. var reader = this._reader,
  4171. value = first,
  4172. temp,
  4173. tt = Tokens.CHAR;
  4174. if (reader.peek() == "+"){
  4175. reader.mark();
  4176. value += reader.read();
  4177. value += this.readUnicodeRangePart(true);
  4178. if (value.length == 2){
  4179. reader.reset();
  4180. } else {
  4181. tt = Tokens.UNICODE_RANGE;
  4182. if (value.indexOf("?") == -1){
  4183. if (reader.peek() == "-"){
  4184. reader.mark();
  4185. temp = reader.read();
  4186. temp += this.readUnicodeRangePart(false);
  4187. if (temp.length == 1){
  4188. reader.reset();
  4189. } else {
  4190. value += temp;
  4191. }
  4192. }
  4193. }
  4194. }
  4195. }
  4196. return this.createToken(tt, value, startLine, startCol);
  4197. },
  4198. whitespaceToken: function(first, startLine, startCol){
  4199. var reader = this._reader,
  4200. value = first + this.readWhitespace();
  4201. return this.createToken(Tokens.S, value, startLine, startCol);
  4202. },
  4203. readUnicodeRangePart: function(allowQuestionMark){
  4204. var reader = this._reader,
  4205. part = "",
  4206. c = reader.peek();
  4207. while(isHexDigit(c) && part.length < 6){
  4208. reader.read();
  4209. part += c;
  4210. c = reader.peek();
  4211. }
  4212. if (allowQuestionMark){
  4213. while(c == "?" && part.length < 6){
  4214. reader.read();
  4215. part += c;
  4216. c = reader.peek();
  4217. }
  4218. }
  4219. return part;
  4220. },
  4221. readWhitespace: function(){
  4222. var reader = this._reader,
  4223. whitespace = "",
  4224. c = reader.peek();
  4225. while(isWhitespace(c)){
  4226. reader.read();
  4227. whitespace += c;
  4228. c = reader.peek();
  4229. }
  4230. return whitespace;
  4231. },
  4232. readNumber: function(first){
  4233. var reader = this._reader,
  4234. number = first,
  4235. hasDot = (first == "."),
  4236. c = reader.peek();
  4237. while(c){
  4238. if (isDigit(c)){
  4239. number += reader.read();
  4240. } else if (c == "."){
  4241. if (hasDot){
  4242. break;
  4243. } else {
  4244. hasDot = true;
  4245. number += reader.read();
  4246. }
  4247. } else {
  4248. break;
  4249. }
  4250. c = reader.peek();
  4251. }
  4252. return number;
  4253. },
  4254. readString: function(){
  4255. var reader = this._reader,
  4256. delim = reader.read(),
  4257. string = delim,
  4258. prev = delim,
  4259. c = reader.peek();
  4260. while(c){
  4261. c = reader.read();
  4262. string += c;
  4263. if (c == delim && prev != "\\"){
  4264. break;
  4265. }
  4266. if (isNewLine(reader.peek()) && c != "\\"){
  4267. string = "";
  4268. break;
  4269. }
  4270. prev = c;
  4271. c = reader.peek();
  4272. }
  4273. if (c === null){
  4274. string = "";
  4275. }
  4276. return string;
  4277. },
  4278. readURI: function(first){
  4279. var reader = this._reader,
  4280. uri = first,
  4281. inner = "",
  4282. c = reader.peek();
  4283. reader.mark();
  4284. while(c && isWhitespace(c)){
  4285. reader.read();
  4286. c = reader.peek();
  4287. }
  4288. if (c == "'" || c == "\""){
  4289. inner = this.readString();
  4290. } else {
  4291. inner = this.readURL();
  4292. }
  4293. c = reader.peek();
  4294. while(c && isWhitespace(c)){
  4295. reader.read();
  4296. c = reader.peek();
  4297. }
  4298. if (inner === "" || c != ")"){
  4299. uri = first;
  4300. reader.reset();
  4301. } else {
  4302. uri += inner + reader.read();
  4303. }
  4304. return uri;
  4305. },
  4306. readURL: function(){
  4307. var reader = this._reader,
  4308. url = "",
  4309. c = reader.peek();
  4310. while (/^[!#$%&\\*-~]$/.test(c)){
  4311. url += reader.read();
  4312. c = reader.peek();
  4313. }
  4314. return url;
  4315. },
  4316. readName: function(first){
  4317. var reader = this._reader,
  4318. ident = first || "",
  4319. c = reader.peek();
  4320. while(true){
  4321. if (c == "\\"){
  4322. ident += this.readEscape(reader.read());
  4323. c = reader.peek();
  4324. } else if(c && isNameChar(c)){
  4325. ident += reader.read();
  4326. c = reader.peek();
  4327. } else {
  4328. break;
  4329. }
  4330. }
  4331. return ident;
  4332. },
  4333. readEscape: function(first){
  4334. var reader = this._reader,
  4335. cssEscape = first || "",
  4336. i = 0,
  4337. c = reader.peek();
  4338. if (isHexDigit(c)){
  4339. do {
  4340. cssEscape += reader.read();
  4341. c = reader.peek();
  4342. } while(c && isHexDigit(c) && ++i < 6);
  4343. }
  4344. if (cssEscape.length == 3 && /\s/.test(c) ||
  4345. cssEscape.length == 7 || cssEscape.length == 1){
  4346. reader.read();
  4347. } else {
  4348. c = "";
  4349. }
  4350. return cssEscape + c;
  4351. },
  4352. readComment: function(first){
  4353. var reader = this._reader,
  4354. comment = first || "",
  4355. c = reader.read();
  4356. if (c == "*"){
  4357. while(c){
  4358. comment += c;
  4359. if (comment.length > 2 && c == "*" && reader.peek() == "/"){
  4360. comment += reader.read();
  4361. break;
  4362. }
  4363. c = reader.read();
  4364. }
  4365. return comment;
  4366. } else {
  4367. return "";
  4368. }
  4369. }
  4370. });
  4371. var Tokens = [
  4372. { name: "CDO"},
  4373. { name: "CDC"},
  4374. { name: "S", whitespace: true/*, channel: "ws"*/},
  4375. { name: "COMMENT", comment: true, hide: true, channel: "comment" },
  4376. { name: "INCLUDES", text: "~="},
  4377. { name: "DASHMATCH", text: "|="},
  4378. { name: "PREFIXMATCH", text: "^="},
  4379. { name: "SUFFIXMATCH", text: "$="},
  4380. { name: "SUBSTRINGMATCH", text: "*="},
  4381. { name: "STRING"},
  4382. { name: "IDENT"},
  4383. { name: "HASH"},
  4384. { name: "IMPORT_SYM", text: "@import"},
  4385. { name: "PAGE_SYM", text: "@page"},
  4386. { name: "MEDIA_SYM", text: "@media"},
  4387. { name: "FONT_FACE_SYM", text: "@font-face"},
  4388. { name: "CHARSET_SYM", text: "@charset"},
  4389. { name: "NAMESPACE_SYM", text: "@namespace"},
  4390. { name: "VIEWPORT_SYM", text: ["@viewport", "@-ms-viewport"]},
  4391. { name: "UNKNOWN_SYM" },
  4392. { name: "KEYFRAMES_SYM", text: [ "@keyframes", "@-webkit-keyframes", "@-moz-keyframes", "@-o-keyframes" ] },
  4393. { name: "IMPORTANT_SYM"},
  4394. { name: "LENGTH"},
  4395. { name: "ANGLE"},
  4396. { name: "TIME"},
  4397. { name: "FREQ"},
  4398. { name: "DIMENSION"},
  4399. { name: "PERCENTAGE"},
  4400. { name: "NUMBER"},
  4401. { name: "URI"},
  4402. { name: "FUNCTION"},
  4403. { name: "UNICODE_RANGE"},
  4404. { name: "INVALID"},
  4405. { name: "PLUS", text: "+" },
  4406. { name: "GREATER", text: ">"},
  4407. { name: "COMMA", text: ","},
  4408. { name: "TILDE", text: "~"},
  4409. { name: "NOT"},
  4410. { name: "TOPLEFTCORNER_SYM", text: "@top-left-corner"},
  4411. { name: "TOPLEFT_SYM", text: "@top-left"},
  4412. { name: "TOPCENTER_SYM", text: "@top-center"},
  4413. { name: "TOPRIGHT_SYM", text: "@top-right"},
  4414. { name: "TOPRIGHTCORNER_SYM", text: "@top-right-corner"},
  4415. { name: "BOTTOMLEFTCORNER_SYM", text: "@bottom-left-corner"},
  4416. { name: "BOTTOMLEFT_SYM", text: "@bottom-left"},
  4417. { name: "BOTTOMCENTER_SYM", text: "@bottom-center"},
  4418. { name: "BOTTOMRIGHT_SYM", text: "@bottom-right"},
  4419. { name: "BOTTOMRIGHTCORNER_SYM", text: "@bottom-right-corner"},
  4420. { name: "LEFTTOP_SYM", text: "@left-top"},
  4421. { name: "LEFTMIDDLE_SYM", text: "@left-middle"},
  4422. { name: "LEFTBOTTOM_SYM", text: "@left-bottom"},
  4423. { name: "RIGHTTOP_SYM", text: "@right-top"},
  4424. { name: "RIGHTMIDDLE_SYM", text: "@right-middle"},
  4425. { name: "RIGHTBOTTOM_SYM", text: "@right-bottom"},
  4426. { name: "RESOLUTION", state: "media"},
  4427. { name: "IE_FUNCTION" },
  4428. { name: "CHAR" },
  4429. {
  4430. name: "PIPE",
  4431. text: "|"
  4432. },
  4433. {
  4434. name: "SLASH",
  4435. text: "/"
  4436. },
  4437. {
  4438. name: "MINUS",
  4439. text: "-"
  4440. },
  4441. {
  4442. name: "STAR",
  4443. text: "*"
  4444. },
  4445. {
  4446. name: "LBRACE",
  4447. endChar: "}",
  4448. text: "{"
  4449. },
  4450. {
  4451. name: "RBRACE",
  4452. text: "}"
  4453. },
  4454. {
  4455. name: "LBRACKET",
  4456. endChar: "]",
  4457. text: "["
  4458. },
  4459. {
  4460. name: "RBRACKET",
  4461. text: "]"
  4462. },
  4463. {
  4464. name: "EQUALS",
  4465. text: "="
  4466. },
  4467. {
  4468. name: "COLON",
  4469. text: ":"
  4470. },
  4471. {
  4472. name: "SEMICOLON",
  4473. text: ";"
  4474. },
  4475. {
  4476. name: "LPAREN",
  4477. endChar: ")",
  4478. text: "("
  4479. },
  4480. {
  4481. name: "RPAREN",
  4482. text: ")"
  4483. },
  4484. {
  4485. name: "DOT",
  4486. text: "."
  4487. }
  4488. ];
  4489. (function(){
  4490. var nameMap = [],
  4491. typeMap = {};
  4492. Tokens.UNKNOWN = -1;
  4493. Tokens.unshift({name:"EOF"});
  4494. for (var i=0, len = Tokens.length; i < len; i++){
  4495. nameMap.push(Tokens[i].name);
  4496. Tokens[Tokens[i].name] = i;
  4497. if (Tokens[i].text){
  4498. if (Tokens[i].text instanceof Array){
  4499. for (var j=0; j < Tokens[i].text.length; j++){
  4500. typeMap[Tokens[i].text[j]] = i;
  4501. }
  4502. } else {
  4503. typeMap[Tokens[i].text] = i;
  4504. }
  4505. }
  4506. }
  4507. Tokens.name = function(tt){
  4508. return nameMap[tt];
  4509. };
  4510. Tokens.type = function(c){
  4511. return typeMap[c] || -1;
  4512. };
  4513. })();
  4514. var Validation = {
  4515. validate: function(property, value){
  4516. var name = property.toString().toLowerCase(),
  4517. parts = value.parts,
  4518. expression = new PropertyValueIterator(value),
  4519. spec = Properties[name],
  4520. part,
  4521. valid,
  4522. j, count,
  4523. msg,
  4524. types,
  4525. last,
  4526. literals,
  4527. max, multi, group;
  4528. if (!spec) {
  4529. if (name.indexOf("-") !== 0){ //vendor prefixed are ok
  4530. throw new ValidationError("Unknown property '" + property + "'.", property.line, property.col);
  4531. }
  4532. } else if (typeof spec != "number"){
  4533. if (typeof spec == "string"){
  4534. if (spec.indexOf("||") > -1) {
  4535. this.groupProperty(spec, expression);
  4536. } else {
  4537. this.singleProperty(spec, expression, 1);
  4538. }
  4539. } else if (spec.multi) {
  4540. this.multiProperty(spec.multi, expression, spec.comma, spec.max || Infinity);
  4541. } else if (typeof spec == "function") {
  4542. spec(expression);
  4543. }
  4544. }
  4545. },
  4546. singleProperty: function(types, expression, max, partial) {
  4547. var result = false,
  4548. value = expression.value,
  4549. count = 0,
  4550. part;
  4551. while (expression.hasNext() && count < max) {
  4552. result = ValidationTypes.isAny(expression, types);
  4553. if (!result) {
  4554. break;
  4555. }
  4556. count++;
  4557. }
  4558. if (!result) {
  4559. if (expression.hasNext() && !expression.isFirst()) {
  4560. part = expression.peek();
  4561. throw new ValidationError("Expected end of value but found '" + part + "'.", part.line, part.col);
  4562. } else {
  4563. throw new ValidationError("Expected (" + types + ") but found '" + value + "'.", value.line, value.col);
  4564. }
  4565. } else if (expression.hasNext()) {
  4566. part = expression.next();
  4567. throw new ValidationError("Expected end of value but found '" + part + "'.", part.line, part.col);
  4568. }
  4569. },
  4570. multiProperty: function (types, expression, comma, max) {
  4571. var result = false,
  4572. value = expression.value,
  4573. count = 0,
  4574. sep = false,
  4575. part;
  4576. while(expression.hasNext() && !result && count < max) {
  4577. if (ValidationTypes.isAny(expression, types)) {
  4578. count++;
  4579. if (!expression.hasNext()) {
  4580. result = true;
  4581. } else if (comma) {
  4582. if (expression.peek() == ",") {
  4583. part = expression.next();
  4584. } else {
  4585. break;
  4586. }
  4587. }
  4588. } else {
  4589. break;
  4590. }
  4591. }
  4592. if (!result) {
  4593. if (expression.hasNext() && !expression.isFirst()) {
  4594. part = expression.peek();
  4595. throw new ValidationError("Expected end of value but found '" + part + "'.", part.line, part.col);
  4596. } else {
  4597. part = expression.previous();
  4598. if (comma && part == ",") {
  4599. throw new ValidationError("Expected end of value but found '" + part + "'.", part.line, part.col);
  4600. } else {
  4601. throw new ValidationError("Expected (" + types + ") but found '" + value + "'.", value.line, value.col);
  4602. }
  4603. }
  4604. } else if (expression.hasNext()) {
  4605. part = expression.next();
  4606. throw new ValidationError("Expected end of value but found '" + part + "'.", part.line, part.col);
  4607. }
  4608. },
  4609. groupProperty: function (types, expression, comma) {
  4610. var result = false,
  4611. value = expression.value,
  4612. typeCount = types.split("||").length,
  4613. groups = { count: 0 },
  4614. partial = false,
  4615. name,
  4616. part;
  4617. while(expression.hasNext() && !result) {
  4618. name = ValidationTypes.isAnyOfGroup(expression, types);
  4619. if (name) {
  4620. if (groups[name]) {
  4621. break;
  4622. } else {
  4623. groups[name] = 1;
  4624. groups.count++;
  4625. partial = true;
  4626. if (groups.count == typeCount || !expression.hasNext()) {
  4627. result = true;
  4628. }
  4629. }
  4630. } else {
  4631. break;
  4632. }
  4633. }
  4634. if (!result) {
  4635. if (partial && expression.hasNext()) {
  4636. part = expression.peek();
  4637. throw new ValidationError("Expected end of value but found '" + part + "'.", part.line, part.col);
  4638. } else {
  4639. throw new ValidationError("Expected (" + types + ") but found '" + value + "'.", value.line, value.col);
  4640. }
  4641. } else if (expression.hasNext()) {
  4642. part = expression.next();
  4643. throw new ValidationError("Expected end of value but found '" + part + "'.", part.line, part.col);
  4644. }
  4645. }
  4646. };
  4647. function ValidationError(message, line, col){
  4648. this.col = col;
  4649. this.line = line;
  4650. this.message = message;
  4651. }
  4652. ValidationError.prototype = new Error();
  4653. var ValidationTypes = {
  4654. isLiteral: function (part, literals) {
  4655. var text = part.text.toString().toLowerCase(),
  4656. args = literals.split(" | "),
  4657. i, len, found = false;
  4658. for (i=0,len=args.length; i < len && !found; i++){
  4659. if (text == args[i].toLowerCase()){
  4660. found = true;
  4661. }
  4662. }
  4663. return found;
  4664. },
  4665. isSimple: function(type) {
  4666. return !!this.simple[type];
  4667. },
  4668. isComplex: function(type) {
  4669. return !!this.complex[type];
  4670. },
  4671. isAny: function (expression, types) {
  4672. var args = types.split(" | "),
  4673. i, len, found = false;
  4674. for (i=0,len=args.length; i < len && !found && expression.hasNext(); i++){
  4675. found = this.isType(expression, args[i]);
  4676. }
  4677. return found;
  4678. },
  4679. isAnyOfGroup: function(expression, types) {
  4680. var args = types.split(" || "),
  4681. i, len, found = false;
  4682. for (i=0,len=args.length; i < len && !found; i++){
  4683. found = this.isType(expression, args[i]);
  4684. }
  4685. return found ? args[i-1] : false;
  4686. },
  4687. isType: function (expression, type) {
  4688. var part = expression.peek(),
  4689. result = false;
  4690. if (type.charAt(0) != "<") {
  4691. result = this.isLiteral(part, type);
  4692. if (result) {
  4693. expression.next();
  4694. }
  4695. } else if (this.simple[type]) {
  4696. result = this.simple[type](part);
  4697. if (result) {
  4698. expression.next();
  4699. }
  4700. } else {
  4701. result = this.complex[type](expression);
  4702. }
  4703. return result;
  4704. },
  4705. simple: {
  4706. "<absolute-size>": function(part){
  4707. return ValidationTypes.isLiteral(part, "xx-small | x-small | small | medium | large | x-large | xx-large");
  4708. },
  4709. "<attachment>": function(part){
  4710. return ValidationTypes.isLiteral(part, "scroll | fixed | local");
  4711. },
  4712. "<attr>": function(part){
  4713. return part.type == "function" && part.name == "attr";
  4714. },
  4715. "<bg-image>": function(part){
  4716. return this["<image>"](part) || this["<gradient>"](part) || part == "none";
  4717. },
  4718. "<gradient>": function(part) {
  4719. return part.type == "function" && /^(?:\-(?:ms|moz|o|webkit)\-)?(?:repeating\-)?(?:radial\-|linear\-)?gradient/i.test(part);
  4720. },
  4721. "<box>": function(part){
  4722. return ValidationTypes.isLiteral(part, "padding-box | border-box | content-box");
  4723. },
  4724. "<content>": function(part){
  4725. return part.type == "function" && part.name == "content";
  4726. },
  4727. "<relative-size>": function(part){
  4728. return ValidationTypes.isLiteral(part, "smaller | larger");
  4729. },
  4730. "<ident>": function(part){
  4731. return part.type == "identifier";
  4732. },
  4733. "<length>": function(part){
  4734. if (part.type == "function" && /^(?:\-(?:ms|moz|o|webkit)\-)?calc/i.test(part)){
  4735. return true;
  4736. }else{
  4737. return part.type == "length" || part.type == "number" || part.type == "integer" || part == "0";
  4738. }
  4739. },
  4740. "<color>": function(part){
  4741. return part.type == "color" || part == "transparent";
  4742. },
  4743. "<number>": function(part){
  4744. return part.type == "number" || this["<integer>"](part);
  4745. },
  4746. "<integer>": function(part){
  4747. return part.type == "integer";
  4748. },
  4749. "<line>": function(part){
  4750. return part.type == "integer";
  4751. },
  4752. "<angle>": function(part){
  4753. return part.type == "angle";
  4754. },
  4755. "<uri>": function(part){
  4756. return part.type == "uri";
  4757. },
  4758. "<image>": function(part){
  4759. return this["<uri>"](part);
  4760. },
  4761. "<percentage>": function(part){
  4762. return part.type == "percentage" || part == "0";
  4763. },
  4764. "<border-width>": function(part){
  4765. return this["<length>"](part) || ValidationTypes.isLiteral(part, "thin | medium | thick");
  4766. },
  4767. "<border-style>": function(part){
  4768. return ValidationTypes.isLiteral(part, "none | hidden | dotted | dashed | solid | double | groove | ridge | inset | outset");
  4769. },
  4770. "<content-sizing>": function(part){ // http://www.w3.org/TR/css3-sizing/#width-height-keywords
  4771. 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");
  4772. },
  4773. "<margin-width>": function(part){
  4774. return this["<length>"](part) || this["<percentage>"](part) || ValidationTypes.isLiteral(part, "auto");
  4775. },
  4776. "<padding-width>": function(part){
  4777. return this["<length>"](part) || this["<percentage>"](part);
  4778. },
  4779. "<shape>": function(part){
  4780. return part.type == "function" && (part.name == "rect" || part.name == "inset-rect");
  4781. },
  4782. "<time>": function(part) {
  4783. return part.type == "time";
  4784. },
  4785. "<flex-grow>": function(part){
  4786. return this["<number>"](part);
  4787. },
  4788. "<flex-shrink>": function(part){
  4789. return this["<number>"](part);
  4790. },
  4791. "<width>": function(part){
  4792. return this["<margin-width>"](part);
  4793. },
  4794. "<flex-basis>": function(part){
  4795. return this["<width>"](part);
  4796. },
  4797. "<flex-direction>": function(part){
  4798. return ValidationTypes.isLiteral(part, "row | row-reverse | column | column-reverse");
  4799. },
  4800. "<flex-wrap>": function(part){
  4801. return ValidationTypes.isLiteral(part, "nowrap | wrap | wrap-reverse");
  4802. }
  4803. },
  4804. complex: {
  4805. "<bg-position>": function(expression){
  4806. var types = this,
  4807. result = false,
  4808. numeric = "<percentage> | <length>",
  4809. xDir = "left | right",
  4810. yDir = "top | bottom",
  4811. count = 0,
  4812. hasNext = function() {
  4813. return expression.hasNext() && expression.peek() != ",";
  4814. };
  4815. while (expression.peek(count) && expression.peek(count) != ",") {
  4816. count++;
  4817. }
  4818. if (count < 3) {
  4819. if (ValidationTypes.isAny(expression, xDir + " | center | " + numeric)) {
  4820. result = true;
  4821. ValidationTypes.isAny(expression, yDir + " | center | " + numeric);
  4822. } else if (ValidationTypes.isAny(expression, yDir)) {
  4823. result = true;
  4824. ValidationTypes.isAny(expression, xDir + " | center");
  4825. }
  4826. } else {
  4827. if (ValidationTypes.isAny(expression, xDir)) {
  4828. if (ValidationTypes.isAny(expression, yDir)) {
  4829. result = true;
  4830. ValidationTypes.isAny(expression, numeric);
  4831. } else if (ValidationTypes.isAny(expression, numeric)) {
  4832. if (ValidationTypes.isAny(expression, yDir)) {
  4833. result = true;
  4834. ValidationTypes.isAny(expression, numeric);
  4835. } else if (ValidationTypes.isAny(expression, "center")) {
  4836. result = true;
  4837. }
  4838. }
  4839. } else if (ValidationTypes.isAny(expression, yDir)) {
  4840. if (ValidationTypes.isAny(expression, xDir)) {
  4841. result = true;
  4842. ValidationTypes.isAny(expression, numeric);
  4843. } else if (ValidationTypes.isAny(expression, numeric)) {
  4844. if (ValidationTypes.isAny(expression, xDir)) {
  4845. result = true;
  4846. ValidationTypes.isAny(expression, numeric);
  4847. } else if (ValidationTypes.isAny(expression, "center")) {
  4848. result = true;
  4849. }
  4850. }
  4851. } else if (ValidationTypes.isAny(expression, "center")) {
  4852. if (ValidationTypes.isAny(expression, xDir + " | " + yDir)) {
  4853. result = true;
  4854. ValidationTypes.isAny(expression, numeric);
  4855. }
  4856. }
  4857. }
  4858. return result;
  4859. },
  4860. "<bg-size>": function(expression){
  4861. var types = this,
  4862. result = false,
  4863. numeric = "<percentage> | <length> | auto",
  4864. part,
  4865. i, len;
  4866. if (ValidationTypes.isAny(expression, "cover | contain")) {
  4867. result = true;
  4868. } else if (ValidationTypes.isAny(expression, numeric)) {
  4869. result = true;
  4870. ValidationTypes.isAny(expression, numeric);
  4871. }
  4872. return result;
  4873. },
  4874. "<repeat-style>": function(expression){
  4875. var result = false,
  4876. values = "repeat | space | round | no-repeat",
  4877. part;
  4878. if (expression.hasNext()){
  4879. part = expression.next();
  4880. if (ValidationTypes.isLiteral(part, "repeat-x | repeat-y")) {
  4881. result = true;
  4882. } else if (ValidationTypes.isLiteral(part, values)) {
  4883. result = true;
  4884. if (expression.hasNext() && ValidationTypes.isLiteral(expression.peek(), values)) {
  4885. expression.next();
  4886. }
  4887. }
  4888. }
  4889. return result;
  4890. },
  4891. "<shadow>": function(expression) {
  4892. var result = false,
  4893. count = 0,
  4894. inset = false,
  4895. color = false,
  4896. part;
  4897. if (expression.hasNext()) {
  4898. if (ValidationTypes.isAny(expression, "inset")){
  4899. inset = true;
  4900. }
  4901. if (ValidationTypes.isAny(expression, "<color>")) {
  4902. color = true;
  4903. }
  4904. while (ValidationTypes.isAny(expression, "<length>") && count < 4) {
  4905. count++;
  4906. }
  4907. if (expression.hasNext()) {
  4908. if (!color) {
  4909. ValidationTypes.isAny(expression, "<color>");
  4910. }
  4911. if (!inset) {
  4912. ValidationTypes.isAny(expression, "inset");
  4913. }
  4914. }
  4915. result = (count >= 2 && count <= 4);
  4916. }
  4917. return result;
  4918. },
  4919. "<x-one-radius>": function(expression) {
  4920. var result = false,
  4921. simple = "<length> | <percentage> | inherit";
  4922. if (ValidationTypes.isAny(expression, simple)){
  4923. result = true;
  4924. ValidationTypes.isAny(expression, simple);
  4925. }
  4926. return result;
  4927. },
  4928. "<flex>": function(expression) {
  4929. var part,
  4930. result = false;
  4931. if (ValidationTypes.isAny(expression, "none | inherit")) {
  4932. result = true;
  4933. } else {
  4934. if (ValidationTypes.isType(expression, "<flex-grow>")) {
  4935. if (expression.peek()) {
  4936. if (ValidationTypes.isType(expression, "<flex-shrink>")) {
  4937. if (expression.peek()) {
  4938. result = ValidationTypes.isType(expression, "<flex-basis>");
  4939. } else {
  4940. result = true;
  4941. }
  4942. } else if (ValidationTypes.isType(expression, "<flex-basis>")) {
  4943. result = expression.peek() === null;
  4944. }
  4945. } else {
  4946. result = true;
  4947. }
  4948. } else if (ValidationTypes.isType(expression, "<flex-basis>")) {
  4949. result = true;
  4950. }
  4951. }
  4952. if (!result) {
  4953. part = expression.peek();
  4954. throw new ValidationError("Expected (none | [ <flex-grow> <flex-shrink>? || <flex-basis> ]) but found '" + expression.value.text + "'.", part.line, part.col);
  4955. }
  4956. return result;
  4957. }
  4958. }
  4959. };
  4960. parserlib.css = {
  4961. Colors :Colors,
  4962. Combinator :Combinator,
  4963. Parser :Parser,
  4964. PropertyName :PropertyName,
  4965. PropertyValue :PropertyValue,
  4966. PropertyValuePart :PropertyValuePart,
  4967. MediaFeature :MediaFeature,
  4968. MediaQuery :MediaQuery,
  4969. Selector :Selector,
  4970. SelectorPart :SelectorPart,
  4971. SelectorSubPart :SelectorSubPart,
  4972. Specificity :Specificity,
  4973. TokenStream :TokenStream,
  4974. Tokens :Tokens,
  4975. ValidationError :ValidationError
  4976. };
  4977. })();
  4978. (function(){
  4979. for(var prop in parserlib){
  4980. exports[prop] = parserlib[prop];
  4981. }
  4982. })();
  4983. function objectToString(o) {
  4984. return Object.prototype.toString.call(o);
  4985. }
  4986. var util = {
  4987. isArray: function (ar) {
  4988. return Array.isArray(ar) || (typeof ar === 'object' && objectToString(ar) === '[object Array]');
  4989. },
  4990. isDate: function (d) {
  4991. return typeof d === 'object' && objectToString(d) === '[object Date]';
  4992. },
  4993. isRegExp: function (re) {
  4994. return typeof re === 'object' && objectToString(re) === '[object RegExp]';
  4995. },
  4996. getRegExpFlags: function (re) {
  4997. var flags = '';
  4998. re.global && (flags += 'g');
  4999. re.ignoreCase && (flags += 'i');
  5000. re.multiline && (flags += 'm');
  5001. return flags;
  5002. }
  5003. };
  5004. if (typeof module === 'object')
  5005. module.exports = clone;
  5006. function clone(parent, circular, depth, prototype) {
  5007. var allParents = [];
  5008. var allChildren = [];
  5009. var useBuffer = typeof Buffer != 'undefined';
  5010. if (typeof circular == 'undefined')
  5011. circular = true;
  5012. if (typeof depth == 'undefined')
  5013. depth = Infinity;
  5014. function _clone(parent, depth) {
  5015. if (parent === null)
  5016. return null;
  5017. if (depth == 0)
  5018. return parent;
  5019. var child;
  5020. if (typeof parent != 'object') {
  5021. return parent;
  5022. }
  5023. if (util.isArray(parent)) {
  5024. child = [];
  5025. } else if (util.isRegExp(parent)) {
  5026. child = new RegExp(parent.source, util.getRegExpFlags(parent));
  5027. if (parent.lastIndex) child.lastIndex = parent.lastIndex;
  5028. } else if (util.isDate(parent)) {
  5029. child = new Date(parent.getTime());
  5030. } else if (useBuffer && Buffer.isBuffer(parent)) {
  5031. child = new Buffer(parent.length);
  5032. parent.copy(child);
  5033. return child;
  5034. } else {
  5035. if (typeof prototype == 'undefined') child = Object.create(Object.getPrototypeOf(parent));
  5036. else child = Object.create(prototype);
  5037. }
  5038. if (circular) {
  5039. var index = allParents.indexOf(parent);
  5040. if (index != -1) {
  5041. return allChildren[index];
  5042. }
  5043. allParents.push(parent);
  5044. allChildren.push(child);
  5045. }
  5046. for (var i in parent) {
  5047. child[i] = _clone(parent[i], depth - 1);
  5048. }
  5049. return child;
  5050. }
  5051. return _clone(parent, depth);
  5052. }
  5053. clone.clonePrototype = function(parent) {
  5054. if (parent === null)
  5055. return null;
  5056. var c = function () {};
  5057. c.prototype = parent;
  5058. return new c();
  5059. };
  5060. var CSSLint = (function(){
  5061. var rules = [],
  5062. formatters = [],
  5063. embeddedRuleset = /\/\*csslint([^\*]*)\*\//,
  5064. api = new parserlib.util.EventTarget();
  5065. api.version = "@VERSION@";
  5066. api.addRule = function(rule){
  5067. rules.push(rule);
  5068. rules[rule.id] = rule;
  5069. };
  5070. api.clearRules = function(){
  5071. rules = [];
  5072. };
  5073. api.getRules = function(){
  5074. return [].concat(rules).sort(function(a,b){
  5075. return a.id > b.id ? 1 : 0;
  5076. });
  5077. };
  5078. api.getRuleset = function() {
  5079. var ruleset = {},
  5080. i = 0,
  5081. len = rules.length;
  5082. while (i < len){
  5083. ruleset[rules[i++].id] = 1; //by default, everything is a warning
  5084. }
  5085. return ruleset;
  5086. };
  5087. function applyEmbeddedRuleset(text, ruleset){
  5088. var valueMap,
  5089. embedded = text && text.match(embeddedRuleset),
  5090. rules = embedded && embedded[1];
  5091. if (rules) {
  5092. valueMap = {
  5093. "true": 2, // true is error
  5094. "": 1, // blank is warning
  5095. "false": 0, // false is ignore
  5096. "2": 2, // explicit error
  5097. "1": 1, // explicit warning
  5098. "0": 0 // explicit ignore
  5099. };
  5100. rules.toLowerCase().split(",").forEach(function(rule){
  5101. var pair = rule.split(":"),
  5102. property = pair[0] || "",
  5103. value = pair[1] || "";
  5104. ruleset[property.trim()] = valueMap[value.trim()];
  5105. });
  5106. }
  5107. return ruleset;
  5108. }
  5109. api.addFormatter = function(formatter) {
  5110. formatters[formatter.id] = formatter;
  5111. };
  5112. api.getFormatter = function(formatId){
  5113. return formatters[formatId];
  5114. };
  5115. api.format = function(results, filename, formatId, options) {
  5116. var formatter = this.getFormatter(formatId),
  5117. result = null;
  5118. if (formatter){
  5119. result = formatter.startFormat();
  5120. result += formatter.formatResults(results, filename, options || {});
  5121. result += formatter.endFormat();
  5122. }
  5123. return result;
  5124. };
  5125. api.hasFormat = function(formatId){
  5126. return formatters.hasOwnProperty(formatId);
  5127. };
  5128. api.verify = function(text, ruleset){
  5129. var i = 0,
  5130. reporter,
  5131. lines,
  5132. report,
  5133. parser = new parserlib.css.Parser({ starHack: true, ieFilters: true,
  5134. underscoreHack: true, strict: false });
  5135. lines = text.replace(/\n\r?/g, "$split$").split("$split$");
  5136. if (!ruleset){
  5137. ruleset = this.getRuleset();
  5138. }
  5139. if (embeddedRuleset.test(text)){
  5140. ruleset = clone(ruleset);
  5141. ruleset = applyEmbeddedRuleset(text, ruleset);
  5142. }
  5143. reporter = new Reporter(lines, ruleset);
  5144. ruleset.errors = 2; //always report parsing errors as errors
  5145. for (i in ruleset){
  5146. if(ruleset.hasOwnProperty(i) && ruleset[i]){
  5147. if (rules[i]){
  5148. rules[i].init(parser, reporter);
  5149. }
  5150. }
  5151. }
  5152. try {
  5153. parser.parse(text);
  5154. } catch (ex) {
  5155. reporter.error("Fatal error, cannot continue: " + ex.message, ex.line, ex.col, {});
  5156. }
  5157. report = {
  5158. messages : reporter.messages,
  5159. stats : reporter.stats,
  5160. ruleset : reporter.ruleset
  5161. };
  5162. report.messages.sort(function (a, b){
  5163. if (a.rollup && !b.rollup){
  5164. return 1;
  5165. } else if (!a.rollup && b.rollup){
  5166. return -1;
  5167. } else {
  5168. return a.line - b.line;
  5169. }
  5170. });
  5171. return report;
  5172. };
  5173. return api;
  5174. })();
  5175. function Reporter(lines, ruleset){
  5176. this.messages = [];
  5177. this.stats = [];
  5178. this.lines = lines;
  5179. this.ruleset = ruleset;
  5180. }
  5181. Reporter.prototype = {
  5182. constructor: Reporter,
  5183. error: function(message, line, col, rule){
  5184. this.messages.push({
  5185. type : "error",
  5186. line : line,
  5187. col : col,
  5188. message : message,
  5189. evidence: this.lines[line-1],
  5190. rule : rule || {}
  5191. });
  5192. },
  5193. warn: function(message, line, col, rule){
  5194. this.report(message, line, col, rule);
  5195. },
  5196. report: function(message, line, col, rule){
  5197. this.messages.push({
  5198. type : this.ruleset[rule.id] === 2 ? "error" : "warning",
  5199. line : line,
  5200. col : col,
  5201. message : message,
  5202. evidence: this.lines[line-1],
  5203. rule : rule
  5204. });
  5205. },
  5206. info: function(message, line, col, rule){
  5207. this.messages.push({
  5208. type : "info",
  5209. line : line,
  5210. col : col,
  5211. message : message,
  5212. evidence: this.lines[line-1],
  5213. rule : rule
  5214. });
  5215. },
  5216. rollupError: function(message, rule){
  5217. this.messages.push({
  5218. type : "error",
  5219. rollup : true,
  5220. message : message,
  5221. rule : rule
  5222. });
  5223. },
  5224. rollupWarn: function(message, rule){
  5225. this.messages.push({
  5226. type : "warning",
  5227. rollup : true,
  5228. message : message,
  5229. rule : rule
  5230. });
  5231. },
  5232. stat: function(name, value){
  5233. this.stats[name] = value;
  5234. }
  5235. };
  5236. CSSLint._Reporter = Reporter;
  5237. CSSLint.Util = {
  5238. mix: function(receiver, supplier){
  5239. var prop;
  5240. for (prop in supplier){
  5241. if (supplier.hasOwnProperty(prop)){
  5242. receiver[prop] = supplier[prop];
  5243. }
  5244. }
  5245. return prop;
  5246. },
  5247. indexOf: function(values, value){
  5248. if (values.indexOf){
  5249. return values.indexOf(value);
  5250. } else {
  5251. for (var i=0, len=values.length; i < len; i++){
  5252. if (values[i] === value){
  5253. return i;
  5254. }
  5255. }
  5256. return -1;
  5257. }
  5258. },
  5259. forEach: function(values, func) {
  5260. if (values.forEach){
  5261. return values.forEach(func);
  5262. } else {
  5263. for (var i=0, len=values.length; i < len; i++){
  5264. func(values[i], i, values);
  5265. }
  5266. }
  5267. }
  5268. };
  5269. CSSLint.addRule({
  5270. id: "adjoining-classes",
  5271. name: "Disallow adjoining classes",
  5272. desc: "Don't use adjoining classes.",
  5273. browsers: "IE6",
  5274. init: function(parser, reporter){
  5275. var rule = this;
  5276. parser.addListener("startrule", function(event){
  5277. var selectors = event.selectors,
  5278. selector,
  5279. part,
  5280. modifier,
  5281. classCount,
  5282. i, j, k;
  5283. for (i=0; i < selectors.length; i++){
  5284. selector = selectors[i];
  5285. for (j=0; j < selector.parts.length; j++){
  5286. part = selector.parts[j];
  5287. if (part.type === parser.SELECTOR_PART_TYPE){
  5288. classCount = 0;
  5289. for (k=0; k < part.modifiers.length; k++){
  5290. modifier = part.modifiers[k];
  5291. if (modifier.type === "class"){
  5292. classCount++;
  5293. }
  5294. if (classCount > 1){
  5295. reporter.report("Don't use adjoining classes.", part.line, part.col, rule);
  5296. }
  5297. }
  5298. }
  5299. }
  5300. }
  5301. });
  5302. }
  5303. });
  5304. CSSLint.addRule({
  5305. id: "box-model",
  5306. name: "Beware of broken box size",
  5307. desc: "Don't use width or height when using padding or border.",
  5308. browsers: "All",
  5309. init: function(parser, reporter){
  5310. var rule = this,
  5311. widthProperties = {
  5312. border: 1,
  5313. "border-left": 1,
  5314. "border-right": 1,
  5315. padding: 1,
  5316. "padding-left": 1,
  5317. "padding-right": 1
  5318. },
  5319. heightProperties = {
  5320. border: 1,
  5321. "border-bottom": 1,
  5322. "border-top": 1,
  5323. padding: 1,
  5324. "padding-bottom": 1,
  5325. "padding-top": 1
  5326. },
  5327. properties,
  5328. boxSizing = false;
  5329. function startRule(){
  5330. properties = {};
  5331. boxSizing = false;
  5332. }
  5333. function endRule(){
  5334. var prop, value;
  5335. if (!boxSizing) {
  5336. if (properties.height){
  5337. for (prop in heightProperties){
  5338. if (heightProperties.hasOwnProperty(prop) && properties[prop]){
  5339. value = properties[prop].value;
  5340. if (!(prop === "padding" && value.parts.length === 2 && value.parts[0].value === 0)){
  5341. reporter.report("Using height with " + prop + " can sometimes make elements larger than you expect.", properties[prop].line, properties[prop].col, rule);
  5342. }
  5343. }
  5344. }
  5345. }
  5346. if (properties.width){
  5347. for (prop in widthProperties){
  5348. if (widthProperties.hasOwnProperty(prop) && properties[prop]){
  5349. value = properties[prop].value;
  5350. if (!(prop === "padding" && value.parts.length === 2 && value.parts[1].value === 0)){
  5351. reporter.report("Using width with " + prop + " can sometimes make elements larger than you expect.", properties[prop].line, properties[prop].col, rule);
  5352. }
  5353. }
  5354. }
  5355. }
  5356. }
  5357. }
  5358. parser.addListener("startrule", startRule);
  5359. parser.addListener("startfontface", startRule);
  5360. parser.addListener("startpage", startRule);
  5361. parser.addListener("startpagemargin", startRule);
  5362. parser.addListener("startkeyframerule", startRule);
  5363. parser.addListener("property", function(event){
  5364. var name = event.property.text.toLowerCase();
  5365. if (heightProperties[name] || widthProperties[name]){
  5366. if (!/^0\S*$/.test(event.value) && !(name === "border" && event.value.toString() === "none")){
  5367. properties[name] = { line: event.property.line, col: event.property.col, value: event.value };
  5368. }
  5369. } else {
  5370. if (/^(width|height)/i.test(name) && /^(length|percentage)/.test(event.value.parts[0].type)){
  5371. properties[name] = 1;
  5372. } else if (name === "box-sizing") {
  5373. boxSizing = true;
  5374. }
  5375. }
  5376. });
  5377. parser.addListener("endrule", endRule);
  5378. parser.addListener("endfontface", endRule);
  5379. parser.addListener("endpage", endRule);
  5380. parser.addListener("endpagemargin", endRule);
  5381. parser.addListener("endkeyframerule", endRule);
  5382. }
  5383. });
  5384. CSSLint.addRule({
  5385. id: "box-sizing",
  5386. name: "Disallow use of box-sizing",
  5387. desc: "The box-sizing properties isn't supported in IE6 and IE7.",
  5388. browsers: "IE6, IE7",
  5389. tags: ["Compatibility"],
  5390. init: function(parser, reporter){
  5391. var rule = this;
  5392. parser.addListener("property", function(event){
  5393. var name = event.property.text.toLowerCase();
  5394. if (name === "box-sizing"){
  5395. reporter.report("The box-sizing property isn't supported in IE6 and IE7.", event.line, event.col, rule);
  5396. }
  5397. });
  5398. }
  5399. });
  5400. CSSLint.addRule({
  5401. id: "bulletproof-font-face",
  5402. name: "Use the bulletproof @font-face syntax",
  5403. 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).",
  5404. browsers: "All",
  5405. init: function(parser, reporter){
  5406. var rule = this,
  5407. fontFaceRule = false,
  5408. firstSrc = true,
  5409. ruleFailed = false,
  5410. line, col;
  5411. parser.addListener("startfontface", function(){
  5412. fontFaceRule = true;
  5413. });
  5414. parser.addListener("property", function(event){
  5415. if (!fontFaceRule) {
  5416. return;
  5417. }
  5418. var propertyName = event.property.toString().toLowerCase(),
  5419. value = event.value.toString();
  5420. line = event.line;
  5421. col = event.col;
  5422. if (propertyName === "src") {
  5423. var regex = /^\s?url\(['"].+\.eot\?.*['"]\)\s*format\(['"]embedded-opentype['"]\).*$/i;
  5424. if (!value.match(regex) && firstSrc) {
  5425. ruleFailed = true;
  5426. firstSrc = false;
  5427. } else if (value.match(regex) && !firstSrc) {
  5428. ruleFailed = false;
  5429. }
  5430. }
  5431. });
  5432. parser.addListener("endfontface", function(){
  5433. fontFaceRule = false;
  5434. if (ruleFailed) {
  5435. reporter.report("@font-face declaration doesn't follow the fontspring bulletproof syntax.", line, col, rule);
  5436. }
  5437. });
  5438. }
  5439. });
  5440. CSSLint.addRule({
  5441. id: "compatible-vendor-prefixes",
  5442. name: "Require compatible vendor prefixes",
  5443. desc: "Include all compatible vendor prefixes to reach a wider range of users.",
  5444. browsers: "All",
  5445. init: function (parser, reporter) {
  5446. var rule = this,
  5447. compatiblePrefixes,
  5448. properties,
  5449. prop,
  5450. variations,
  5451. prefixed,
  5452. i,
  5453. len,
  5454. inKeyFrame = false,
  5455. arrayPush = Array.prototype.push,
  5456. applyTo = [];
  5457. compatiblePrefixes = {
  5458. "animation" : "webkit moz",
  5459. "animation-delay" : "webkit moz",
  5460. "animation-direction" : "webkit moz",
  5461. "animation-duration" : "webkit moz",
  5462. "animation-fill-mode" : "webkit moz",
  5463. "animation-iteration-count" : "webkit moz",
  5464. "animation-name" : "webkit moz",
  5465. "animation-play-state" : "webkit moz",
  5466. "animation-timing-function" : "webkit moz",
  5467. "appearance" : "webkit moz",
  5468. "border-end" : "webkit moz",
  5469. "border-end-color" : "webkit moz",
  5470. "border-end-style" : "webkit moz",
  5471. "border-end-width" : "webkit moz",
  5472. "border-image" : "webkit moz o",
  5473. "border-radius" : "webkit",
  5474. "border-start" : "webkit moz",
  5475. "border-start-color" : "webkit moz",
  5476. "border-start-style" : "webkit moz",
  5477. "border-start-width" : "webkit moz",
  5478. "box-align" : "webkit moz ms",
  5479. "box-direction" : "webkit moz ms",
  5480. "box-flex" : "webkit moz ms",
  5481. "box-lines" : "webkit ms",
  5482. "box-ordinal-group" : "webkit moz ms",
  5483. "box-orient" : "webkit moz ms",
  5484. "box-pack" : "webkit moz ms",
  5485. "box-sizing" : "webkit moz",
  5486. "box-shadow" : "webkit moz",
  5487. "column-count" : "webkit moz ms",
  5488. "column-gap" : "webkit moz ms",
  5489. "column-rule" : "webkit moz ms",
  5490. "column-rule-color" : "webkit moz ms",
  5491. "column-rule-style" : "webkit moz ms",
  5492. "column-rule-width" : "webkit moz ms",
  5493. "column-width" : "webkit moz ms",
  5494. "hyphens" : "epub moz",
  5495. "line-break" : "webkit ms",
  5496. "margin-end" : "webkit moz",
  5497. "margin-start" : "webkit moz",
  5498. "marquee-speed" : "webkit wap",
  5499. "marquee-style" : "webkit wap",
  5500. "padding-end" : "webkit moz",
  5501. "padding-start" : "webkit moz",
  5502. "tab-size" : "moz o",
  5503. "text-size-adjust" : "webkit ms",
  5504. "transform" : "webkit moz ms o",
  5505. "transform-origin" : "webkit moz ms o",
  5506. "transition" : "webkit moz o",
  5507. "transition-delay" : "webkit moz o",
  5508. "transition-duration" : "webkit moz o",
  5509. "transition-property" : "webkit moz o",
  5510. "transition-timing-function" : "webkit moz o",
  5511. "user-modify" : "webkit moz",
  5512. "user-select" : "webkit moz ms",
  5513. "word-break" : "epub ms",
  5514. "writing-mode" : "epub ms"
  5515. };
  5516. for (prop in compatiblePrefixes) {
  5517. if (compatiblePrefixes.hasOwnProperty(prop)) {
  5518. variations = [];
  5519. prefixed = compatiblePrefixes[prop].split(" ");
  5520. for (i = 0, len = prefixed.length; i < len; i++) {
  5521. variations.push("-" + prefixed[i] + "-" + prop);
  5522. }
  5523. compatiblePrefixes[prop] = variations;
  5524. arrayPush.apply(applyTo, variations);
  5525. }
  5526. }
  5527. parser.addListener("startrule", function () {
  5528. properties = [];
  5529. });
  5530. parser.addListener("startkeyframes", function (event) {
  5531. inKeyFrame = event.prefix || true;
  5532. });
  5533. parser.addListener("endkeyframes", function () {
  5534. inKeyFrame = false;
  5535. });
  5536. parser.addListener("property", function (event) {
  5537. var name = event.property;
  5538. if (CSSLint.Util.indexOf(applyTo, name.text) > -1) {
  5539. if (!inKeyFrame || typeof inKeyFrame !== "string" ||
  5540. name.text.indexOf("-" + inKeyFrame + "-") !== 0) {
  5541. properties.push(name);
  5542. }
  5543. }
  5544. });
  5545. parser.addListener("endrule", function () {
  5546. if (!properties.length) {
  5547. return;
  5548. }
  5549. var propertyGroups = {},
  5550. i,
  5551. len,
  5552. name,
  5553. prop,
  5554. variations,
  5555. value,
  5556. full,
  5557. actual,
  5558. item,
  5559. propertiesSpecified;
  5560. for (i = 0, len = properties.length; i < len; i++) {
  5561. name = properties[i];
  5562. for (prop in compatiblePrefixes) {
  5563. if (compatiblePrefixes.hasOwnProperty(prop)) {
  5564. variations = compatiblePrefixes[prop];
  5565. if (CSSLint.Util.indexOf(variations, name.text) > -1) {
  5566. if (!propertyGroups[prop]) {
  5567. propertyGroups[prop] = {
  5568. full : variations.slice(0),
  5569. actual : [],
  5570. actualNodes: []
  5571. };
  5572. }
  5573. if (CSSLint.Util.indexOf(propertyGroups[prop].actual, name.text) === -1) {
  5574. propertyGroups[prop].actual.push(name.text);
  5575. propertyGroups[prop].actualNodes.push(name);
  5576. }
  5577. }
  5578. }
  5579. }
  5580. }
  5581. for (prop in propertyGroups) {
  5582. if (propertyGroups.hasOwnProperty(prop)) {
  5583. value = propertyGroups[prop];
  5584. full = value.full;
  5585. actual = value.actual;
  5586. if (full.length > actual.length) {
  5587. for (i = 0, len = full.length; i < len; i++) {
  5588. item = full[i];
  5589. if (CSSLint.Util.indexOf(actual, item) === -1) {
  5590. propertiesSpecified = (actual.length === 1) ? actual[0] : (actual.length === 2) ? actual.join(" and ") : actual.join(", ");
  5591. reporter.report("The property " + item + " is compatible with " + propertiesSpecified + " and should be included as well.", value.actualNodes[0].line, value.actualNodes[0].col, rule);
  5592. }
  5593. }
  5594. }
  5595. }
  5596. }
  5597. });
  5598. }
  5599. });
  5600. CSSLint.addRule({
  5601. id: "display-property-grouping",
  5602. name: "Require properties appropriate for display",
  5603. desc: "Certain properties shouldn't be used with certain display property values.",
  5604. browsers: "All",
  5605. init: function(parser, reporter){
  5606. var rule = this;
  5607. var propertiesToCheck = {
  5608. display: 1,
  5609. "float": "none",
  5610. height: 1,
  5611. width: 1,
  5612. margin: 1,
  5613. "margin-left": 1,
  5614. "margin-right": 1,
  5615. "margin-bottom": 1,
  5616. "margin-top": 1,
  5617. padding: 1,
  5618. "padding-left": 1,
  5619. "padding-right": 1,
  5620. "padding-bottom": 1,
  5621. "padding-top": 1,
  5622. "vertical-align": 1
  5623. },
  5624. properties;
  5625. function reportProperty(name, display, msg){
  5626. if (properties[name]){
  5627. if (typeof propertiesToCheck[name] !== "string" || properties[name].value.toLowerCase() !== propertiesToCheck[name]){
  5628. reporter.report(msg || name + " can't be used with display: " + display + ".", properties[name].line, properties[name].col, rule);
  5629. }
  5630. }
  5631. }
  5632. function startRule(){
  5633. properties = {};
  5634. }
  5635. function endRule(){
  5636. var display = properties.display ? properties.display.value : null;
  5637. if (display){
  5638. switch(display){
  5639. case "inline":
  5640. reportProperty("height", display);
  5641. reportProperty("width", display);
  5642. reportProperty("margin", display);
  5643. reportProperty("margin-top", display);
  5644. reportProperty("margin-bottom", display);
  5645. reportProperty("float", display, "display:inline has no effect on floated elements (but may be used to fix the IE6 double-margin bug).");
  5646. break;
  5647. case "block":
  5648. reportProperty("vertical-align", display);
  5649. break;
  5650. case "inline-block":
  5651. reportProperty("float", display);
  5652. break;
  5653. default:
  5654. if (display.indexOf("table-") === 0){
  5655. reportProperty("margin", display);
  5656. reportProperty("margin-left", display);
  5657. reportProperty("margin-right", display);
  5658. reportProperty("margin-top", display);
  5659. reportProperty("margin-bottom", display);
  5660. reportProperty("float", display);
  5661. }
  5662. }
  5663. }
  5664. }
  5665. parser.addListener("startrule", startRule);
  5666. parser.addListener("startfontface", startRule);
  5667. parser.addListener("startkeyframerule", startRule);
  5668. parser.addListener("startpagemargin", startRule);
  5669. parser.addListener("startpage", startRule);
  5670. parser.addListener("property", function(event){
  5671. var name = event.property.text.toLowerCase();
  5672. if (propertiesToCheck[name]){
  5673. properties[name] = { value: event.value.text, line: event.property.line, col: event.property.col };
  5674. }
  5675. });
  5676. parser.addListener("endrule", endRule);
  5677. parser.addListener("endfontface", endRule);
  5678. parser.addListener("endkeyframerule", endRule);
  5679. parser.addListener("endpagemargin", endRule);
  5680. parser.addListener("endpage", endRule);
  5681. }
  5682. });
  5683. CSSLint.addRule({
  5684. id: "duplicate-background-images",
  5685. name: "Disallow duplicate background images",
  5686. desc: "Every background-image should be unique. Use a common class for e.g. sprites.",
  5687. browsers: "All",
  5688. init: function(parser, reporter){
  5689. var rule = this,
  5690. stack = {};
  5691. parser.addListener("property", function(event){
  5692. var name = event.property.text,
  5693. value = event.value,
  5694. i, len;
  5695. if (name.match(/background/i)) {
  5696. for (i=0, len=value.parts.length; i < len; i++) {
  5697. if (value.parts[i].type === "uri") {
  5698. if (typeof stack[value.parts[i].uri] === "undefined") {
  5699. stack[value.parts[i].uri] = event;
  5700. }
  5701. else {
  5702. 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);
  5703. }
  5704. }
  5705. }
  5706. }
  5707. });
  5708. }
  5709. });
  5710. CSSLint.addRule({
  5711. id: "duplicate-properties",
  5712. name: "Disallow duplicate properties",
  5713. desc: "Duplicate properties must appear one after the other.",
  5714. browsers: "All",
  5715. init: function(parser, reporter){
  5716. var rule = this,
  5717. properties,
  5718. lastProperty;
  5719. function startRule(){
  5720. properties = {};
  5721. }
  5722. parser.addListener("startrule", startRule);
  5723. parser.addListener("startfontface", startRule);
  5724. parser.addListener("startpage", startRule);
  5725. parser.addListener("startpagemargin", startRule);
  5726. parser.addListener("startkeyframerule", startRule);
  5727. parser.addListener("property", function(event){
  5728. var property = event.property,
  5729. name = property.text.toLowerCase();
  5730. if (properties[name] && (lastProperty !== name || properties[name] === event.value.text)){
  5731. reporter.report("Duplicate property '" + event.property + "' found.", event.line, event.col, rule);
  5732. }
  5733. properties[name] = event.value.text;
  5734. lastProperty = name;
  5735. });
  5736. }
  5737. });
  5738. CSSLint.addRule({
  5739. id: "empty-rules",
  5740. name: "Disallow empty rules",
  5741. desc: "Rules without any properties specified should be removed.",
  5742. browsers: "All",
  5743. init: function(parser, reporter){
  5744. var rule = this,
  5745. count = 0;
  5746. parser.addListener("startrule", function(){
  5747. count=0;
  5748. });
  5749. parser.addListener("property", function(){
  5750. count++;
  5751. });
  5752. parser.addListener("endrule", function(event){
  5753. var selectors = event.selectors;
  5754. if (count === 0){
  5755. reporter.report("Rule is empty.", selectors[0].line, selectors[0].col, rule);
  5756. }
  5757. });
  5758. }
  5759. });
  5760. CSSLint.addRule({
  5761. id: "errors",
  5762. name: "Parsing Errors",
  5763. desc: "This rule looks for recoverable syntax errors.",
  5764. browsers: "All",
  5765. init: function(parser, reporter){
  5766. var rule = this;
  5767. parser.addListener("error", function(event){
  5768. reporter.error(event.message, event.line, event.col, rule);
  5769. });
  5770. }
  5771. });
  5772. CSSLint.addRule({
  5773. id: "fallback-colors",
  5774. name: "Require fallback colors",
  5775. desc: "For older browsers that don't support RGBA, HSL, or HSLA, provide a fallback color.",
  5776. browsers: "IE6,IE7,IE8",
  5777. init: function(parser, reporter){
  5778. var rule = this,
  5779. lastProperty,
  5780. propertiesToCheck = {
  5781. color: 1,
  5782. background: 1,
  5783. "border-color": 1,
  5784. "border-top-color": 1,
  5785. "border-right-color": 1,
  5786. "border-bottom-color": 1,
  5787. "border-left-color": 1,
  5788. border: 1,
  5789. "border-top": 1,
  5790. "border-right": 1,
  5791. "border-bottom": 1,
  5792. "border-left": 1,
  5793. "background-color": 1
  5794. },
  5795. properties;
  5796. function startRule(){
  5797. properties = {};
  5798. lastProperty = null;
  5799. }
  5800. parser.addListener("startrule", startRule);
  5801. parser.addListener("startfontface", startRule);
  5802. parser.addListener("startpage", startRule);
  5803. parser.addListener("startpagemargin", startRule);
  5804. parser.addListener("startkeyframerule", startRule);
  5805. parser.addListener("property", function(event){
  5806. var property = event.property,
  5807. name = property.text.toLowerCase(),
  5808. parts = event.value.parts,
  5809. i = 0,
  5810. colorType = "",
  5811. len = parts.length;
  5812. if(propertiesToCheck[name]){
  5813. while(i < len){
  5814. if (parts[i].type === "color"){
  5815. if ("alpha" in parts[i] || "hue" in parts[i]){
  5816. if (/([^\)]+)\(/.test(parts[i])){
  5817. colorType = RegExp.$1.toUpperCase();
  5818. }
  5819. if (!lastProperty || (lastProperty.property.text.toLowerCase() !== name || lastProperty.colorType !== "compat")){
  5820. reporter.report("Fallback " + name + " (hex or RGB) should precede " + colorType + " " + name + ".", event.line, event.col, rule);
  5821. }
  5822. } else {
  5823. event.colorType = "compat";
  5824. }
  5825. }
  5826. i++;
  5827. }
  5828. }
  5829. lastProperty = event;
  5830. });
  5831. }
  5832. });
  5833. CSSLint.addRule({
  5834. id: "floats",
  5835. name: "Disallow too many floats",
  5836. desc: "This rule tests if the float property is used too many times",
  5837. browsers: "All",
  5838. init: function(parser, reporter){
  5839. var rule = this;
  5840. var count = 0;
  5841. parser.addListener("property", function(event){
  5842. if (event.property.text.toLowerCase() === "float" &&
  5843. event.value.text.toLowerCase() !== "none"){
  5844. count++;
  5845. }
  5846. });
  5847. parser.addListener("endstylesheet", function(){
  5848. reporter.stat("floats", count);
  5849. if (count >= 10){
  5850. reporter.rollupWarn("Too many floats (" + count + "), you're probably using them for layout. Consider using a grid system instead.", rule);
  5851. }
  5852. });
  5853. }
  5854. });
  5855. CSSLint.addRule({
  5856. id: "font-faces",
  5857. name: "Don't use too many web fonts",
  5858. desc: "Too many different web fonts in the same stylesheet.",
  5859. browsers: "All",
  5860. init: function(parser, reporter){
  5861. var rule = this,
  5862. count = 0;
  5863. parser.addListener("startfontface", function(){
  5864. count++;
  5865. });
  5866. parser.addListener("endstylesheet", function(){
  5867. if (count > 5){
  5868. reporter.rollupWarn("Too many @font-face declarations (" + count + ").", rule);
  5869. }
  5870. });
  5871. }
  5872. });
  5873. CSSLint.addRule({
  5874. id: "font-sizes",
  5875. name: "Disallow too many font sizes",
  5876. desc: "Checks the number of font-size declarations.",
  5877. browsers: "All",
  5878. init: function(parser, reporter){
  5879. var rule = this,
  5880. count = 0;
  5881. parser.addListener("property", function(event){
  5882. if (event.property.toString() === "font-size"){
  5883. count++;
  5884. }
  5885. });
  5886. parser.addListener("endstylesheet", function(){
  5887. reporter.stat("font-sizes", count);
  5888. if (count >= 10){
  5889. reporter.rollupWarn("Too many font-size declarations (" + count + "), abstraction needed.", rule);
  5890. }
  5891. });
  5892. }
  5893. });
  5894. CSSLint.addRule({
  5895. id: "gradients",
  5896. name: "Require all gradient definitions",
  5897. desc: "When using a vendor-prefixed gradient, make sure to use them all.",
  5898. browsers: "All",
  5899. init: function(parser, reporter){
  5900. var rule = this,
  5901. gradients;
  5902. parser.addListener("startrule", function(){
  5903. gradients = {
  5904. moz: 0,
  5905. webkit: 0,
  5906. oldWebkit: 0,
  5907. o: 0
  5908. };
  5909. });
  5910. parser.addListener("property", function(event){
  5911. if (/\-(moz|o|webkit)(?:\-(?:linear|radial))\-gradient/i.test(event.value)){
  5912. gradients[RegExp.$1] = 1;
  5913. } else if (/\-webkit\-gradient/i.test(event.value)){
  5914. gradients.oldWebkit = 1;
  5915. }
  5916. });
  5917. parser.addListener("endrule", function(event){
  5918. var missing = [];
  5919. if (!gradients.moz){
  5920. missing.push("Firefox 3.6+");
  5921. }
  5922. if (!gradients.webkit){
  5923. missing.push("Webkit (Safari 5+, Chrome)");
  5924. }
  5925. if (!gradients.oldWebkit){
  5926. missing.push("Old Webkit (Safari 4+, Chrome)");
  5927. }
  5928. if (!gradients.o){
  5929. missing.push("Opera 11.1+");
  5930. }
  5931. if (missing.length && missing.length < 4){
  5932. reporter.report("Missing vendor-prefixed CSS gradients for " + missing.join(", ") + ".", event.selectors[0].line, event.selectors[0].col, rule);
  5933. }
  5934. });
  5935. }
  5936. });
  5937. CSSLint.addRule({
  5938. id: "ids",
  5939. name: "Disallow IDs in selectors",
  5940. desc: "Selectors should not contain IDs.",
  5941. browsers: "All",
  5942. init: function(parser, reporter){
  5943. var rule = this;
  5944. parser.addListener("startrule", function(event){
  5945. var selectors = event.selectors,
  5946. selector,
  5947. part,
  5948. modifier,
  5949. idCount,
  5950. i, j, k;
  5951. for (i=0; i < selectors.length; i++){
  5952. selector = selectors[i];
  5953. idCount = 0;
  5954. for (j=0; j < selector.parts.length; j++){
  5955. part = selector.parts[j];
  5956. if (part.type === parser.SELECTOR_PART_TYPE){
  5957. for (k=0; k < part.modifiers.length; k++){
  5958. modifier = part.modifiers[k];
  5959. if (modifier.type === "id"){
  5960. idCount++;
  5961. }
  5962. }
  5963. }
  5964. }
  5965. if (idCount === 1){
  5966. reporter.report("Don't use IDs in selectors.", selector.line, selector.col, rule);
  5967. } else if (idCount > 1){
  5968. reporter.report(idCount + " IDs in the selector, really?", selector.line, selector.col, rule);
  5969. }
  5970. }
  5971. });
  5972. }
  5973. });
  5974. CSSLint.addRule({
  5975. id: "import",
  5976. name: "Disallow @import",
  5977. desc: "Don't use @import, use <link> instead.",
  5978. browsers: "All",
  5979. init: function(parser, reporter){
  5980. var rule = this;
  5981. parser.addListener("import", function(event){
  5982. reporter.report("@import prevents parallel downloads, use <link> instead.", event.line, event.col, rule);
  5983. });
  5984. }
  5985. });
  5986. CSSLint.addRule({
  5987. id: "important",
  5988. name: "Disallow !important",
  5989. desc: "Be careful when using !important declaration",
  5990. browsers: "All",
  5991. init: function(parser, reporter){
  5992. var rule = this,
  5993. count = 0;
  5994. parser.addListener("property", function(event){
  5995. if (event.important === true){
  5996. count++;
  5997. reporter.report("Use of !important", event.line, event.col, rule);
  5998. }
  5999. });
  6000. parser.addListener("endstylesheet", function(){
  6001. reporter.stat("important", count);
  6002. if (count >= 10){
  6003. reporter.rollupWarn("Too many !important declarations (" + count + "), try to use less than 10 to avoid specificity issues.", rule);
  6004. }
  6005. });
  6006. }
  6007. });
  6008. CSSLint.addRule({
  6009. id: "known-properties",
  6010. name: "Require use of known properties",
  6011. desc: "Properties should be known (listed in CSS3 specification) or be a vendor-prefixed property.",
  6012. browsers: "All",
  6013. init: function(parser, reporter){
  6014. var rule = this;
  6015. parser.addListener("property", function(event){
  6016. if (event.invalid) {
  6017. reporter.report(event.invalid.message, event.line, event.col, rule);
  6018. }
  6019. });
  6020. }
  6021. });
  6022. CSSLint.addRule({
  6023. id: "order-alphabetical",
  6024. name: "Alphabetical order",
  6025. desc: "Assure properties are in alphabetical order",
  6026. browsers: "All",
  6027. init: function(parser, reporter){
  6028. var rule = this,
  6029. properties;
  6030. var startRule = function () {
  6031. properties = [];
  6032. };
  6033. parser.addListener("startrule", startRule);
  6034. parser.addListener("startfontface", startRule);
  6035. parser.addListener("startpage", startRule);
  6036. parser.addListener("startpagemargin", startRule);
  6037. parser.addListener("startkeyframerule", startRule);
  6038. parser.addListener("property", function(event){
  6039. var name = event.property.text,
  6040. lowerCasePrefixLessName = name.toLowerCase().replace(/^-.*?-/, "");
  6041. properties.push(lowerCasePrefixLessName);
  6042. });
  6043. parser.addListener("endrule", function(event){
  6044. var currentProperties = properties.join(","),
  6045. expectedProperties = properties.sort().join(",");
  6046. if (currentProperties !== expectedProperties){
  6047. reporter.report("Rule doesn't have all its properties in alphabetical ordered.", event.line, event.col, rule);
  6048. }
  6049. });
  6050. }
  6051. });
  6052. CSSLint.addRule({
  6053. id: "outline-none",
  6054. name: "Disallow outline: none",
  6055. desc: "Use of outline: none or outline: 0 should be limited to :focus rules.",
  6056. browsers: "All",
  6057. tags: ["Accessibility"],
  6058. init: function(parser, reporter){
  6059. var rule = this,
  6060. lastRule;
  6061. function startRule(event){
  6062. if (event.selectors){
  6063. lastRule = {
  6064. line: event.line,
  6065. col: event.col,
  6066. selectors: event.selectors,
  6067. propCount: 0,
  6068. outline: false
  6069. };
  6070. } else {
  6071. lastRule = null;
  6072. }
  6073. }
  6074. function endRule(){
  6075. if (lastRule){
  6076. if (lastRule.outline){
  6077. if (lastRule.selectors.toString().toLowerCase().indexOf(":focus") === -1){
  6078. reporter.report("Outlines should only be modified using :focus.", lastRule.line, lastRule.col, rule);
  6079. } else if (lastRule.propCount === 1) {
  6080. reporter.report("Outlines shouldn't be hidden unless other visual changes are made.", lastRule.line, lastRule.col, rule);
  6081. }
  6082. }
  6083. }
  6084. }
  6085. parser.addListener("startrule", startRule);
  6086. parser.addListener("startfontface", startRule);
  6087. parser.addListener("startpage", startRule);
  6088. parser.addListener("startpagemargin", startRule);
  6089. parser.addListener("startkeyframerule", startRule);
  6090. parser.addListener("property", function(event){
  6091. var name = event.property.text.toLowerCase(),
  6092. value = event.value;
  6093. if (lastRule){
  6094. lastRule.propCount++;
  6095. if (name === "outline" && (value.toString() === "none" || value.toString() === "0")){
  6096. lastRule.outline = true;
  6097. }
  6098. }
  6099. });
  6100. parser.addListener("endrule", endRule);
  6101. parser.addListener("endfontface", endRule);
  6102. parser.addListener("endpage", endRule);
  6103. parser.addListener("endpagemargin", endRule);
  6104. parser.addListener("endkeyframerule", endRule);
  6105. }
  6106. });
  6107. CSSLint.addRule({
  6108. id: "overqualified-elements",
  6109. name: "Disallow overqualified elements",
  6110. desc: "Don't use classes or IDs with elements (a.foo or a#foo).",
  6111. browsers: "All",
  6112. init: function(parser, reporter){
  6113. var rule = this,
  6114. classes = {};
  6115. parser.addListener("startrule", function(event){
  6116. var selectors = event.selectors,
  6117. selector,
  6118. part,
  6119. modifier,
  6120. i, j, k;
  6121. for (i=0; i < selectors.length; i++){
  6122. selector = selectors[i];
  6123. for (j=0; j < selector.parts.length; j++){
  6124. part = selector.parts[j];
  6125. if (part.type === parser.SELECTOR_PART_TYPE){
  6126. for (k=0; k < part.modifiers.length; k++){
  6127. modifier = part.modifiers[k];
  6128. if (part.elementName && modifier.type === "id"){
  6129. reporter.report("Element (" + part + ") is overqualified, just use " + modifier + " without element name.", part.line, part.col, rule);
  6130. } else if (modifier.type === "class"){
  6131. if (!classes[modifier]){
  6132. classes[modifier] = [];
  6133. }
  6134. classes[modifier].push({ modifier: modifier, part: part });
  6135. }
  6136. }
  6137. }
  6138. }
  6139. }
  6140. });
  6141. parser.addListener("endstylesheet", function(){
  6142. var prop;
  6143. for (prop in classes){
  6144. if (classes.hasOwnProperty(prop)){
  6145. if (classes[prop].length === 1 && classes[prop][0].part.elementName){
  6146. 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);
  6147. }
  6148. }
  6149. }
  6150. });
  6151. }
  6152. });
  6153. CSSLint.addRule({
  6154. id: "qualified-headings",
  6155. name: "Disallow qualified headings",
  6156. desc: "Headings should not be qualified (namespaced).",
  6157. browsers: "All",
  6158. init: function(parser, reporter){
  6159. var rule = this;
  6160. parser.addListener("startrule", function(event){
  6161. var selectors = event.selectors,
  6162. selector,
  6163. part,
  6164. i, j;
  6165. for (i=0; i < selectors.length; i++){
  6166. selector = selectors[i];
  6167. for (j=0; j < selector.parts.length; j++){
  6168. part = selector.parts[j];
  6169. if (part.type === parser.SELECTOR_PART_TYPE){
  6170. if (part.elementName && /h[1-6]/.test(part.elementName.toString()) && j > 0){
  6171. reporter.report("Heading (" + part.elementName + ") should not be qualified.", part.line, part.col, rule);
  6172. }
  6173. }
  6174. }
  6175. }
  6176. });
  6177. }
  6178. });
  6179. CSSLint.addRule({
  6180. id: "regex-selectors",
  6181. name: "Disallow selectors that look like regexs",
  6182. desc: "Selectors that look like regular expressions are slow and should be avoided.",
  6183. browsers: "All",
  6184. init: function(parser, reporter){
  6185. var rule = this;
  6186. parser.addListener("startrule", function(event){
  6187. var selectors = event.selectors,
  6188. selector,
  6189. part,
  6190. modifier,
  6191. i, j, k;
  6192. for (i=0; i < selectors.length; i++){
  6193. selector = selectors[i];
  6194. for (j=0; j < selector.parts.length; j++){
  6195. part = selector.parts[j];
  6196. if (part.type === parser.SELECTOR_PART_TYPE){
  6197. for (k=0; k < part.modifiers.length; k++){
  6198. modifier = part.modifiers[k];
  6199. if (modifier.type === "attribute"){
  6200. if (/([\~\|\^\$\*]=)/.test(modifier)){
  6201. reporter.report("Attribute selectors with " + RegExp.$1 + " are slow!", modifier.line, modifier.col, rule);
  6202. }
  6203. }
  6204. }
  6205. }
  6206. }
  6207. }
  6208. });
  6209. }
  6210. });
  6211. CSSLint.addRule({
  6212. id: "rules-count",
  6213. name: "Rules Count",
  6214. desc: "Track how many rules there are.",
  6215. browsers: "All",
  6216. init: function(parser, reporter){
  6217. var count = 0;
  6218. parser.addListener("startrule", function(){
  6219. count++;
  6220. });
  6221. parser.addListener("endstylesheet", function(){
  6222. reporter.stat("rule-count", count);
  6223. });
  6224. }
  6225. });
  6226. CSSLint.addRule({
  6227. id: "selector-max-approaching",
  6228. name: "Warn when approaching the 4095 selector limit for IE",
  6229. desc: "Will warn when selector count is >= 3800 selectors.",
  6230. browsers: "IE",
  6231. init: function(parser, reporter) {
  6232. var rule = this, count = 0;
  6233. parser.addListener("startrule", function(event) {
  6234. count += event.selectors.length;
  6235. });
  6236. parser.addListener("endstylesheet", function() {
  6237. if (count >= 3800) {
  6238. reporter.report("You have " + count + " selectors. Internet Explorer supports a maximum of 4095 selectors per stylesheet. Consider refactoring.",0,0,rule);
  6239. }
  6240. });
  6241. }
  6242. });
  6243. CSSLint.addRule({
  6244. id: "selector-max",
  6245. name: "Error when past the 4095 selector limit for IE",
  6246. desc: "Will error when selector count is > 4095.",
  6247. browsers: "IE",
  6248. init: function(parser, reporter){
  6249. var rule = this, count = 0;
  6250. parser.addListener("startrule", function(event) {
  6251. count += event.selectors.length;
  6252. });
  6253. parser.addListener("endstylesheet", function() {
  6254. if (count > 4095) {
  6255. reporter.report("You have " + count + " selectors. Internet Explorer supports a maximum of 4095 selectors per stylesheet. Consider refactoring.",0,0,rule);
  6256. }
  6257. });
  6258. }
  6259. });
  6260. CSSLint.addRule({
  6261. id: "selector-newline",
  6262. name: "Disallow new-line characters in selectors",
  6263. desc: "New-line characters in selectors are usually a forgotten comma and not a descendant combinator.",
  6264. browsers: "All",
  6265. init: function(parser, reporter) {
  6266. var rule = this;
  6267. function startRule(event) {
  6268. var i, len, selector, p, n, pLen, part, part2, type, currentLine, nextLine,
  6269. selectors = event.selectors;
  6270. for (i = 0, len = selectors.length; i < len; i++) {
  6271. selector = selectors[i];
  6272. for (p = 0, pLen = selector.parts.length; p < pLen; p++) {
  6273. for (n = p + 1; n < pLen; n++) {
  6274. part = selector.parts[p];
  6275. part2 = selector.parts[n];
  6276. type = part.type;
  6277. currentLine = part.line;
  6278. nextLine = part2.line;
  6279. if (type === "descendant" && nextLine > currentLine) {
  6280. reporter.report("newline character found in selector (forgot a comma?)", currentLine, selectors[i].parts[0].col, rule);
  6281. }
  6282. }
  6283. }
  6284. }
  6285. }
  6286. parser.addListener("startrule", startRule);
  6287. }
  6288. });
  6289. CSSLint.addRule({
  6290. id: "shorthand",
  6291. name: "Require shorthand properties",
  6292. desc: "Use shorthand properties where possible.",
  6293. browsers: "All",
  6294. init: function(parser, reporter){
  6295. var rule = this,
  6296. prop, i, len,
  6297. propertiesToCheck = {},
  6298. properties,
  6299. mapping = {
  6300. "margin": [
  6301. "margin-top",
  6302. "margin-bottom",
  6303. "margin-left",
  6304. "margin-right"
  6305. ],
  6306. "padding": [
  6307. "padding-top",
  6308. "padding-bottom",
  6309. "padding-left",
  6310. "padding-right"
  6311. ]
  6312. };
  6313. for (prop in mapping){
  6314. if (mapping.hasOwnProperty(prop)){
  6315. for (i=0, len=mapping[prop].length; i < len; i++){
  6316. propertiesToCheck[mapping[prop][i]] = prop;
  6317. }
  6318. }
  6319. }
  6320. function startRule(){
  6321. properties = {};
  6322. }
  6323. function endRule(event){
  6324. var prop, i, len, total;
  6325. for (prop in mapping){
  6326. if (mapping.hasOwnProperty(prop)){
  6327. total=0;
  6328. for (i=0, len=mapping[prop].length; i < len; i++){
  6329. total += properties[mapping[prop][i]] ? 1 : 0;
  6330. }
  6331. if (total === mapping[prop].length){
  6332. reporter.report("The properties " + mapping[prop].join(", ") + " can be replaced by " + prop + ".", event.line, event.col, rule);
  6333. }
  6334. }
  6335. }
  6336. }
  6337. parser.addListener("startrule", startRule);
  6338. parser.addListener("startfontface", startRule);
  6339. parser.addListener("property", function(event){
  6340. var name = event.property.toString().toLowerCase();
  6341. if (propertiesToCheck[name]){
  6342. properties[name] = 1;
  6343. }
  6344. });
  6345. parser.addListener("endrule", endRule);
  6346. parser.addListener("endfontface", endRule);
  6347. }
  6348. });
  6349. CSSLint.addRule({
  6350. id: "star-property-hack",
  6351. name: "Disallow properties with a star prefix",
  6352. desc: "Checks for the star property hack (targets IE6/7)",
  6353. browsers: "All",
  6354. init: function(parser, reporter){
  6355. var rule = this;
  6356. parser.addListener("property", function(event){
  6357. var property = event.property;
  6358. if (property.hack === "*") {
  6359. reporter.report("Property with star prefix found.", event.property.line, event.property.col, rule);
  6360. }
  6361. });
  6362. }
  6363. });
  6364. CSSLint.addRule({
  6365. id: "text-indent",
  6366. name: "Disallow negative text-indent",
  6367. desc: "Checks for text indent less than -99px",
  6368. browsers: "All",
  6369. init: function(parser, reporter){
  6370. var rule = this,
  6371. textIndent,
  6372. direction;
  6373. function startRule(){
  6374. textIndent = false;
  6375. direction = "inherit";
  6376. }
  6377. function endRule(){
  6378. if (textIndent && direction !== "ltr"){
  6379. 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);
  6380. }
  6381. }
  6382. parser.addListener("startrule", startRule);
  6383. parser.addListener("startfontface", startRule);
  6384. parser.addListener("property", function(event){
  6385. var name = event.property.toString().toLowerCase(),
  6386. value = event.value;
  6387. if (name === "text-indent" && value.parts[0].value < -99){
  6388. textIndent = event.property;
  6389. } else if (name === "direction" && value.toString() === "ltr"){
  6390. direction = "ltr";
  6391. }
  6392. });
  6393. parser.addListener("endrule", endRule);
  6394. parser.addListener("endfontface", endRule);
  6395. }
  6396. });
  6397. CSSLint.addRule({
  6398. id: "underscore-property-hack",
  6399. name: "Disallow properties with an underscore prefix",
  6400. desc: "Checks for the underscore property hack (targets IE6)",
  6401. browsers: "All",
  6402. init: function(parser, reporter){
  6403. var rule = this;
  6404. parser.addListener("property", function(event){
  6405. var property = event.property;
  6406. if (property.hack === "_") {
  6407. reporter.report("Property with underscore prefix found.", event.property.line, event.property.col, rule);
  6408. }
  6409. });
  6410. }
  6411. });
  6412. CSSLint.addRule({
  6413. id: "unique-headings",
  6414. name: "Headings should only be defined once",
  6415. desc: "Headings should be defined only once.",
  6416. browsers: "All",
  6417. init: function(parser, reporter){
  6418. var rule = this;
  6419. var headings = {
  6420. h1: 0,
  6421. h2: 0,
  6422. h3: 0,
  6423. h4: 0,
  6424. h5: 0,
  6425. h6: 0
  6426. };
  6427. parser.addListener("startrule", function(event){
  6428. var selectors = event.selectors,
  6429. selector,
  6430. part,
  6431. pseudo,
  6432. i, j;
  6433. for (i=0; i < selectors.length; i++){
  6434. selector = selectors[i];
  6435. part = selector.parts[selector.parts.length-1];
  6436. if (part.elementName && /(h[1-6])/i.test(part.elementName.toString())){
  6437. for (j=0; j < part.modifiers.length; j++){
  6438. if (part.modifiers[j].type === "pseudo"){
  6439. pseudo = true;
  6440. break;
  6441. }
  6442. }
  6443. if (!pseudo){
  6444. headings[RegExp.$1]++;
  6445. if (headings[RegExp.$1] > 1) {
  6446. reporter.report("Heading (" + part.elementName + ") has already been defined.", part.line, part.col, rule);
  6447. }
  6448. }
  6449. }
  6450. }
  6451. });
  6452. parser.addListener("endstylesheet", function(){
  6453. var prop,
  6454. messages = [];
  6455. for (prop in headings){
  6456. if (headings.hasOwnProperty(prop)){
  6457. if (headings[prop] > 1){
  6458. messages.push(headings[prop] + " " + prop + "s");
  6459. }
  6460. }
  6461. }
  6462. if (messages.length){
  6463. reporter.rollupWarn("You have " + messages.join(", ") + " defined in this stylesheet.", rule);
  6464. }
  6465. });
  6466. }
  6467. });
  6468. CSSLint.addRule({
  6469. id: "universal-selector",
  6470. name: "Disallow universal selector",
  6471. desc: "The universal selector (*) is known to be slow.",
  6472. browsers: "All",
  6473. init: function(parser, reporter){
  6474. var rule = this;
  6475. parser.addListener("startrule", function(event){
  6476. var selectors = event.selectors,
  6477. selector,
  6478. part,
  6479. i;
  6480. for (i=0; i < selectors.length; i++){
  6481. selector = selectors[i];
  6482. part = selector.parts[selector.parts.length-1];
  6483. if (part.elementName === "*"){
  6484. reporter.report(rule.desc, part.line, part.col, rule);
  6485. }
  6486. }
  6487. });
  6488. }
  6489. });
  6490. CSSLint.addRule({
  6491. id: "unqualified-attributes",
  6492. name: "Disallow unqualified attribute selectors",
  6493. desc: "Unqualified attribute selectors are known to be slow.",
  6494. browsers: "All",
  6495. init: function(parser, reporter){
  6496. var rule = this;
  6497. parser.addListener("startrule", function(event){
  6498. var selectors = event.selectors,
  6499. selector,
  6500. part,
  6501. modifier,
  6502. i, k;
  6503. for (i=0; i < selectors.length; i++){
  6504. selector = selectors[i];
  6505. part = selector.parts[selector.parts.length-1];
  6506. if (part.type === parser.SELECTOR_PART_TYPE){
  6507. for (k=0; k < part.modifiers.length; k++){
  6508. modifier = part.modifiers[k];
  6509. if (modifier.type === "attribute" && (!part.elementName || part.elementName === "*")){
  6510. reporter.report(rule.desc, part.line, part.col, rule);
  6511. }
  6512. }
  6513. }
  6514. }
  6515. });
  6516. }
  6517. });
  6518. CSSLint.addRule({
  6519. id: "vendor-prefix",
  6520. name: "Require standard property with vendor prefix",
  6521. desc: "When using a vendor-prefixed property, make sure to include the standard one.",
  6522. browsers: "All",
  6523. init: function(parser, reporter){
  6524. var rule = this,
  6525. properties,
  6526. num,
  6527. propertiesToCheck = {
  6528. "-webkit-border-radius": "border-radius",
  6529. "-webkit-border-top-left-radius": "border-top-left-radius",
  6530. "-webkit-border-top-right-radius": "border-top-right-radius",
  6531. "-webkit-border-bottom-left-radius": "border-bottom-left-radius",
  6532. "-webkit-border-bottom-right-radius": "border-bottom-right-radius",
  6533. "-o-border-radius": "border-radius",
  6534. "-o-border-top-left-radius": "border-top-left-radius",
  6535. "-o-border-top-right-radius": "border-top-right-radius",
  6536. "-o-border-bottom-left-radius": "border-bottom-left-radius",
  6537. "-o-border-bottom-right-radius": "border-bottom-right-radius",
  6538. "-moz-border-radius": "border-radius",
  6539. "-moz-border-radius-topleft": "border-top-left-radius",
  6540. "-moz-border-radius-topright": "border-top-right-radius",
  6541. "-moz-border-radius-bottomleft": "border-bottom-left-radius",
  6542. "-moz-border-radius-bottomright": "border-bottom-right-radius",
  6543. "-moz-column-count": "column-count",
  6544. "-webkit-column-count": "column-count",
  6545. "-moz-column-gap": "column-gap",
  6546. "-webkit-column-gap": "column-gap",
  6547. "-moz-column-rule": "column-rule",
  6548. "-webkit-column-rule": "column-rule",
  6549. "-moz-column-rule-style": "column-rule-style",
  6550. "-webkit-column-rule-style": "column-rule-style",
  6551. "-moz-column-rule-color": "column-rule-color",
  6552. "-webkit-column-rule-color": "column-rule-color",
  6553. "-moz-column-rule-width": "column-rule-width",
  6554. "-webkit-column-rule-width": "column-rule-width",
  6555. "-moz-column-width": "column-width",
  6556. "-webkit-column-width": "column-width",
  6557. "-webkit-column-span": "column-span",
  6558. "-webkit-columns": "columns",
  6559. "-moz-box-shadow": "box-shadow",
  6560. "-webkit-box-shadow": "box-shadow",
  6561. "-moz-transform" : "transform",
  6562. "-webkit-transform" : "transform",
  6563. "-o-transform" : "transform",
  6564. "-ms-transform" : "transform",
  6565. "-moz-transform-origin" : "transform-origin",
  6566. "-webkit-transform-origin" : "transform-origin",
  6567. "-o-transform-origin" : "transform-origin",
  6568. "-ms-transform-origin" : "transform-origin",
  6569. "-moz-box-sizing" : "box-sizing",
  6570. "-webkit-box-sizing" : "box-sizing"
  6571. };
  6572. function startRule(){
  6573. properties = {};
  6574. num = 1;
  6575. }
  6576. function endRule(){
  6577. var prop,
  6578. i,
  6579. len,
  6580. needed,
  6581. actual,
  6582. needsStandard = [];
  6583. for (prop in properties){
  6584. if (propertiesToCheck[prop]){
  6585. needsStandard.push({ actual: prop, needed: propertiesToCheck[prop]});
  6586. }
  6587. }
  6588. for (i=0, len=needsStandard.length; i < len; i++){
  6589. needed = needsStandard[i].needed;
  6590. actual = needsStandard[i].actual;
  6591. if (!properties[needed]){
  6592. reporter.report("Missing standard property '" + needed + "' to go along with '" + actual + "'.", properties[actual][0].name.line, properties[actual][0].name.col, rule);
  6593. } else {
  6594. if (properties[needed][0].pos < properties[actual][0].pos){
  6595. reporter.report("Standard property '" + needed + "' should come after vendor-prefixed property '" + actual + "'.", properties[actual][0].name.line, properties[actual][0].name.col, rule);
  6596. }
  6597. }
  6598. }
  6599. }
  6600. parser.addListener("startrule", startRule);
  6601. parser.addListener("startfontface", startRule);
  6602. parser.addListener("startpage", startRule);
  6603. parser.addListener("startpagemargin", startRule);
  6604. parser.addListener("startkeyframerule", startRule);
  6605. parser.addListener("property", function(event){
  6606. var name = event.property.text.toLowerCase();
  6607. if (!properties[name]){
  6608. properties[name] = [];
  6609. }
  6610. properties[name].push({ name: event.property, value : event.value, pos:num++ });
  6611. });
  6612. parser.addListener("endrule", endRule);
  6613. parser.addListener("endfontface", endRule);
  6614. parser.addListener("endpage", endRule);
  6615. parser.addListener("endpagemargin", endRule);
  6616. parser.addListener("endkeyframerule", endRule);
  6617. }
  6618. });
  6619. CSSLint.addRule({
  6620. id: "zero-units",
  6621. name: "Disallow units for 0 values",
  6622. desc: "You don't need to specify units when a value is 0.",
  6623. browsers: "All",
  6624. init: function(parser, reporter){
  6625. var rule = this;
  6626. parser.addListener("property", function(event){
  6627. var parts = event.value.parts,
  6628. i = 0,
  6629. len = parts.length;
  6630. while(i < len){
  6631. if ((parts[i].units || parts[i].type === "percentage") && parts[i].value === 0 && parts[i].type !== "time"){
  6632. reporter.report("Values of 0 shouldn't have units specified.", parts[i].line, parts[i].col, rule);
  6633. }
  6634. i++;
  6635. }
  6636. });
  6637. }
  6638. });
  6639. (function() {
  6640. var xmlEscape = function(str) {
  6641. if (!str || str.constructor !== String) {
  6642. return "";
  6643. }
  6644. return str.replace(/[\"&><]/g, function(match) {
  6645. switch (match) {
  6646. case "\"":
  6647. return "&quot;";
  6648. case "&":
  6649. return "&amp;";
  6650. case "<":
  6651. return "&lt;";
  6652. case ">":
  6653. return "&gt;";
  6654. }
  6655. });
  6656. };
  6657. CSSLint.addFormatter({
  6658. id: "checkstyle-xml",
  6659. name: "Checkstyle XML format",
  6660. startFormat: function(){
  6661. return "<?xml version=\"1.0\" encoding=\"utf-8\"?><checkstyle>";
  6662. },
  6663. endFormat: function(){
  6664. return "</checkstyle>";
  6665. },
  6666. readError: function(filename, message) {
  6667. return "<file name=\"" + xmlEscape(filename) + "\"><error line=\"0\" column=\"0\" severty=\"error\" message=\"" + xmlEscape(message) + "\"></error></file>";
  6668. },
  6669. formatResults: function(results, filename/*, options*/) {
  6670. var messages = results.messages,
  6671. output = [];
  6672. var generateSource = function(rule) {
  6673. if (!rule || !("name" in rule)) {
  6674. return "";
  6675. }
  6676. return "net.csslint." + rule.name.replace(/\s/g,"");
  6677. };
  6678. if (messages.length > 0) {
  6679. output.push("<file name=\""+filename+"\">");
  6680. CSSLint.Util.forEach(messages, function (message) {
  6681. if (!message.rollup) {
  6682. output.push("<error line=\"" + message.line + "\" column=\"" + message.col + "\" severity=\"" + message.type + "\"" +
  6683. " message=\"" + xmlEscape(message.message) + "\" source=\"" + generateSource(message.rule) +"\"/>");
  6684. }
  6685. });
  6686. output.push("</file>");
  6687. }
  6688. return output.join("");
  6689. }
  6690. });
  6691. }());
  6692. CSSLint.addFormatter({
  6693. id: "compact",
  6694. name: "Compact, 'porcelain' format",
  6695. startFormat: function() {
  6696. return "";
  6697. },
  6698. endFormat: function() {
  6699. return "";
  6700. },
  6701. formatResults: function(results, filename, options) {
  6702. var messages = results.messages,
  6703. output = "";
  6704. options = options || {};
  6705. var capitalize = function(str) {
  6706. return str.charAt(0).toUpperCase() + str.slice(1);
  6707. };
  6708. if (messages.length === 0) {
  6709. return options.quiet ? "" : filename + ": Lint Free!";
  6710. }
  6711. CSSLint.Util.forEach(messages, function(message) {
  6712. if (message.rollup) {
  6713. output += filename + ": " + capitalize(message.type) + " - " + message.message + "\n";
  6714. } else {
  6715. output += filename + ": " + "line " + message.line +
  6716. ", col " + message.col + ", " + capitalize(message.type) + " - " + message.message + " (" + message.rule.id + ")\n";
  6717. }
  6718. });
  6719. return output;
  6720. }
  6721. });
  6722. CSSLint.addFormatter({
  6723. id: "csslint-xml",
  6724. name: "CSSLint XML format",
  6725. startFormat: function(){
  6726. return "<?xml version=\"1.0\" encoding=\"utf-8\"?><csslint>";
  6727. },
  6728. endFormat: function(){
  6729. return "</csslint>";
  6730. },
  6731. formatResults: function(results, filename/*, options*/) {
  6732. var messages = results.messages,
  6733. output = [];
  6734. var escapeSpecialCharacters = function(str) {
  6735. if (!str || str.constructor !== String) {
  6736. return "";
  6737. }
  6738. return str.replace(/\"/g, "'").replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
  6739. };
  6740. if (messages.length > 0) {
  6741. output.push("<file name=\""+filename+"\">");
  6742. CSSLint.Util.forEach(messages, function (message) {
  6743. if (message.rollup) {
  6744. output.push("<issue severity=\"" + message.type + "\" reason=\"" + escapeSpecialCharacters(message.message) + "\" evidence=\"" + escapeSpecialCharacters(message.evidence) + "\"/>");
  6745. } else {
  6746. output.push("<issue line=\"" + message.line + "\" char=\"" + message.col + "\" severity=\"" + message.type + "\"" +
  6747. " reason=\"" + escapeSpecialCharacters(message.message) + "\" evidence=\"" + escapeSpecialCharacters(message.evidence) + "\"/>");
  6748. }
  6749. });
  6750. output.push("</file>");
  6751. }
  6752. return output.join("");
  6753. }
  6754. });
  6755. CSSLint.addFormatter({
  6756. id: "junit-xml",
  6757. name: "JUNIT XML format",
  6758. startFormat: function(){
  6759. return "<?xml version=\"1.0\" encoding=\"utf-8\"?><testsuites>";
  6760. },
  6761. endFormat: function() {
  6762. return "</testsuites>";
  6763. },
  6764. formatResults: function(results, filename/*, options*/) {
  6765. var messages = results.messages,
  6766. output = [],
  6767. tests = {
  6768. "error": 0,
  6769. "failure": 0
  6770. };
  6771. var generateSource = function(rule) {
  6772. if (!rule || !("name" in rule)) {
  6773. return "";
  6774. }
  6775. return "net.csslint." + rule.name.replace(/\s/g,"");
  6776. };
  6777. var escapeSpecialCharacters = function(str) {
  6778. if (!str || str.constructor !== String) {
  6779. return "";
  6780. }
  6781. return str.replace(/\"/g, "'").replace(/</g, "&lt;").replace(/>/g, "&gt;");
  6782. };
  6783. if (messages.length > 0) {
  6784. messages.forEach(function (message) {
  6785. var type = message.type === "warning" ? "error" : message.type;
  6786. if (!message.rollup) {
  6787. output.push("<testcase time=\"0\" name=\"" + generateSource(message.rule) + "\">");
  6788. output.push("<" + type + " message=\"" + escapeSpecialCharacters(message.message) + "\"><![CDATA[" + message.line + ":" + message.col + ":" + escapeSpecialCharacters(message.evidence) + "]]></" + type + ">");
  6789. output.push("</testcase>");
  6790. tests[type] += 1;
  6791. }
  6792. });
  6793. output.unshift("<testsuite time=\"0\" tests=\"" + messages.length + "\" skipped=\"0\" errors=\"" + tests.error + "\" failures=\"" + tests.failure + "\" package=\"net.csslint\" name=\"" + filename + "\">");
  6794. output.push("</testsuite>");
  6795. }
  6796. return output.join("");
  6797. }
  6798. });
  6799. CSSLint.addFormatter({
  6800. id: "lint-xml",
  6801. name: "Lint XML format",
  6802. startFormat: function(){
  6803. return "<?xml version=\"1.0\" encoding=\"utf-8\"?><lint>";
  6804. },
  6805. endFormat: function(){
  6806. return "</lint>";
  6807. },
  6808. formatResults: function(results, filename/*, options*/) {
  6809. var messages = results.messages,
  6810. output = [];
  6811. var escapeSpecialCharacters = function(str) {
  6812. if (!str || str.constructor !== String) {
  6813. return "";
  6814. }
  6815. return str.replace(/\"/g, "'").replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
  6816. };
  6817. if (messages.length > 0) {
  6818. output.push("<file name=\""+filename+"\">");
  6819. CSSLint.Util.forEach(messages, function (message) {
  6820. if (message.rollup) {
  6821. output.push("<issue severity=\"" + message.type + "\" reason=\"" + escapeSpecialCharacters(message.message) + "\" evidence=\"" + escapeSpecialCharacters(message.evidence) + "\"/>");
  6822. } else {
  6823. output.push("<issue line=\"" + message.line + "\" char=\"" + message.col + "\" severity=\"" + message.type + "\"" +
  6824. " reason=\"" + escapeSpecialCharacters(message.message) + "\" evidence=\"" + escapeSpecialCharacters(message.evidence) + "\"/>");
  6825. }
  6826. });
  6827. output.push("</file>");
  6828. }
  6829. return output.join("");
  6830. }
  6831. });
  6832. CSSLint.addFormatter({
  6833. id: "text",
  6834. name: "Plain Text",
  6835. startFormat: function() {
  6836. return "";
  6837. },
  6838. endFormat: function() {
  6839. return "";
  6840. },
  6841. formatResults: function(results, filename, options) {
  6842. var messages = results.messages,
  6843. output = "";
  6844. options = options || {};
  6845. if (messages.length === 0) {
  6846. return options.quiet ? "" : "\n\ncsslint: No errors in " + filename + ".";
  6847. }
  6848. output = "\n\ncsslint: There ";
  6849. if (messages.length === 1) {
  6850. output += "is 1 problem";
  6851. } else {
  6852. output += "are " + messages.length + " problems";
  6853. }
  6854. output += " in " + filename + ".";
  6855. var pos = filename.lastIndexOf("/"),
  6856. shortFilename = filename;
  6857. if (pos === -1){
  6858. pos = filename.lastIndexOf("\\");
  6859. }
  6860. if (pos > -1){
  6861. shortFilename = filename.substring(pos+1);
  6862. }
  6863. CSSLint.Util.forEach(messages, function (message, i) {
  6864. output = output + "\n\n" + shortFilename;
  6865. if (message.rollup) {
  6866. output += "\n" + (i+1) + ": " + message.type;
  6867. output += "\n" + message.message;
  6868. } else {
  6869. output += "\n" + (i+1) + ": " + message.type + " at line " + message.line + ", col " + message.col;
  6870. output += "\n" + message.message;
  6871. output += "\n" + message.evidence;
  6872. }
  6873. });
  6874. return output;
  6875. }
  6876. });
  6877. module.exports.CSSLint = CSSLint;
  6878. });
  6879. ace.define("ace/mode/css_worker",[], function(require, exports, module) {
  6880. "use strict";
  6881. var oop = require("../lib/oop");
  6882. var lang = require("../lib/lang");
  6883. var Mirror = require("../worker/mirror").Mirror;
  6884. var CSSLint = require("./css/csslint").CSSLint;
  6885. var Worker = exports.Worker = function(sender) {
  6886. Mirror.call(this, sender);
  6887. this.setTimeout(400);
  6888. this.ruleset = null;
  6889. this.setDisabledRules("ids|order-alphabetical");
  6890. this.setInfoRules(
  6891. "adjoining-classes|qualified-headings|zero-units|gradients|" +
  6892. "import|outline-none|vendor-prefix"
  6893. );
  6894. };
  6895. oop.inherits(Worker, Mirror);
  6896. (function() {
  6897. this.setInfoRules = function(ruleNames) {
  6898. if (typeof ruleNames == "string")
  6899. ruleNames = ruleNames.split("|");
  6900. this.infoRules = lang.arrayToMap(ruleNames);
  6901. this.doc.getValue() && this.deferredUpdate.schedule(100);
  6902. };
  6903. this.setDisabledRules = function(ruleNames) {
  6904. if (!ruleNames) {
  6905. this.ruleset = null;
  6906. } else {
  6907. if (typeof ruleNames == "string")
  6908. ruleNames = ruleNames.split("|");
  6909. var all = {};
  6910. CSSLint.getRules().forEach(function(x){
  6911. all[x.id] = true;
  6912. });
  6913. ruleNames.forEach(function(x) {
  6914. delete all[x];
  6915. });
  6916. this.ruleset = all;
  6917. }
  6918. this.doc.getValue() && this.deferredUpdate.schedule(100);
  6919. };
  6920. this.onUpdate = function() {
  6921. var value = this.doc.getValue();
  6922. if (!value)
  6923. return this.sender.emit("annotate", []);
  6924. var infoRules = this.infoRules;
  6925. var result = CSSLint.verify(value, this.ruleset);
  6926. this.sender.emit("annotate", result.messages.map(function(msg) {
  6927. return {
  6928. row: msg.line - 1,
  6929. column: msg.col - 1,
  6930. text: msg.message,
  6931. type: infoRules[msg.rule.id] ? "info" : msg.type,
  6932. rule: msg.rule.name
  6933. };
  6934. }));
  6935. };
  6936. }).call(Worker.prototype);
  6937. });
  6938. ace.define("ace/lib/es5-shim",[], function(require, exports, module) {
  6939. //
  6940. //
  6941. function Empty() {}
  6942. if (!Function.prototype.bind) {
  6943. Function.prototype.bind = function bind(that) { // .length is 1
  6944. var target = this;
  6945. if (typeof target != "function") {
  6946. throw new TypeError("Function.prototype.bind called on incompatible " + target);
  6947. }
  6948. var args = slice.call(arguments, 1); // for normal call
  6949. var bound = function () {
  6950. if (this instanceof bound) {
  6951. var result = target.apply(
  6952. this,
  6953. args.concat(slice.call(arguments))
  6954. );
  6955. if (Object(result) === result) {
  6956. return result;
  6957. }
  6958. return this;
  6959. } else {
  6960. return target.apply(
  6961. that,
  6962. args.concat(slice.call(arguments))
  6963. );
  6964. }
  6965. };
  6966. if(target.prototype) {
  6967. Empty.prototype = target.prototype;
  6968. bound.prototype = new Empty();
  6969. Empty.prototype = null;
  6970. }
  6971. //
  6972. return bound;
  6973. };
  6974. }
  6975. var call = Function.prototype.call;
  6976. var prototypeOfArray = Array.prototype;
  6977. var prototypeOfObject = Object.prototype;
  6978. var slice = prototypeOfArray.slice;
  6979. var _toString = call.bind(prototypeOfObject.toString);
  6980. var owns = call.bind(prototypeOfObject.hasOwnProperty);
  6981. var defineGetter;
  6982. var defineSetter;
  6983. var lookupGetter;
  6984. var lookupSetter;
  6985. var supportsAccessors;
  6986. if ((supportsAccessors = owns(prototypeOfObject, "__defineGetter__"))) {
  6987. defineGetter = call.bind(prototypeOfObject.__defineGetter__);
  6988. defineSetter = call.bind(prototypeOfObject.__defineSetter__);
  6989. lookupGetter = call.bind(prototypeOfObject.__lookupGetter__);
  6990. lookupSetter = call.bind(prototypeOfObject.__lookupSetter__);
  6991. }
  6992. //
  6993. //
  6994. if ([1,2].splice(0).length != 2) {
  6995. if(function() { // test IE < 9 to splice bug - see issue #138
  6996. function makeArray(l) {
  6997. var a = new Array(l+2);
  6998. a[0] = a[1] = 0;
  6999. return a;
  7000. }
  7001. var array = [], lengthBefore;
  7002. array.splice.apply(array, makeArray(20));
  7003. array.splice.apply(array, makeArray(26));
  7004. lengthBefore = array.length; //46
  7005. array.splice(5, 0, "XXX"); // add one element
  7006. lengthBefore + 1 == array.length
  7007. if (lengthBefore + 1 == array.length) {
  7008. return true;// has right splice implementation without bugs
  7009. }
  7010. }()) {//IE 6/7
  7011. var array_splice = Array.prototype.splice;
  7012. Array.prototype.splice = function(start, deleteCount) {
  7013. if (!arguments.length) {
  7014. return [];
  7015. } else {
  7016. return array_splice.apply(this, [
  7017. start === void 0 ? 0 : start,
  7018. deleteCount === void 0 ? (this.length - start) : deleteCount
  7019. ].concat(slice.call(arguments, 2)))
  7020. }
  7021. };
  7022. } else {//IE8
  7023. Array.prototype.splice = function(pos, removeCount){
  7024. var length = this.length;
  7025. if (pos > 0) {
  7026. if (pos > length)
  7027. pos = length;
  7028. } else if (pos == void 0) {
  7029. pos = 0;
  7030. } else if (pos < 0) {
  7031. pos = Math.max(length + pos, 0);
  7032. }
  7033. if (!(pos+removeCount < length))
  7034. removeCount = length - pos;
  7035. var removed = this.slice(pos, pos+removeCount);
  7036. var insert = slice.call(arguments, 2);
  7037. var add = insert.length;
  7038. if (pos === length) {
  7039. if (add) {
  7040. this.push.apply(this, insert);
  7041. }
  7042. } else {
  7043. var remove = Math.min(removeCount, length - pos);
  7044. var tailOldPos = pos + remove;
  7045. var tailNewPos = tailOldPos + add - remove;
  7046. var tailCount = length - tailOldPos;
  7047. var lengthAfterRemove = length - remove;
  7048. if (tailNewPos < tailOldPos) { // case A
  7049. for (var i = 0; i < tailCount; ++i) {
  7050. this[tailNewPos+i] = this[tailOldPos+i];
  7051. }
  7052. } else if (tailNewPos > tailOldPos) { // case B
  7053. for (i = tailCount; i--; ) {
  7054. this[tailNewPos+i] = this[tailOldPos+i];
  7055. }
  7056. } // else, add == remove (nothing to do)
  7057. if (add && pos === lengthAfterRemove) {
  7058. this.length = lengthAfterRemove; // truncate array
  7059. this.push.apply(this, insert);
  7060. } else {
  7061. this.length = lengthAfterRemove + add; // reserves space
  7062. for (i = 0; i < add; ++i) {
  7063. this[pos+i] = insert[i];
  7064. }
  7065. }
  7066. }
  7067. return removed;
  7068. };
  7069. }
  7070. }
  7071. if (!Array.isArray) {
  7072. Array.isArray = function isArray(obj) {
  7073. return _toString(obj) == "[object Array]";
  7074. };
  7075. }
  7076. var boxedString = Object("a"),
  7077. splitString = boxedString[0] != "a" || !(0 in boxedString);
  7078. if (!Array.prototype.forEach) {
  7079. Array.prototype.forEach = function forEach(fun /*, thisp*/) {
  7080. var object = toObject(this),
  7081. self = splitString && _toString(this) == "[object String]" ?
  7082. this.split("") :
  7083. object,
  7084. thisp = arguments[1],
  7085. i = -1,
  7086. length = self.length >>> 0;
  7087. if (_toString(fun) != "[object Function]") {
  7088. throw new TypeError(); // TODO message
  7089. }
  7090. while (++i < length) {
  7091. if (i in self) {
  7092. fun.call(thisp, self[i], i, object);
  7093. }
  7094. }
  7095. };
  7096. }
  7097. if (!Array.prototype.map) {
  7098. Array.prototype.map = function map(fun /*, thisp*/) {
  7099. var object = toObject(this),
  7100. self = splitString && _toString(this) == "[object String]" ?
  7101. this.split("") :
  7102. object,
  7103. length = self.length >>> 0,
  7104. result = Array(length),
  7105. thisp = arguments[1];
  7106. if (_toString(fun) != "[object Function]") {
  7107. throw new TypeError(fun + " is not a function");
  7108. }
  7109. for (var i = 0; i < length; i++) {
  7110. if (i in self)
  7111. result[i] = fun.call(thisp, self[i], i, object);
  7112. }
  7113. return result;
  7114. };
  7115. }
  7116. if (!Array.prototype.filter) {
  7117. Array.prototype.filter = function filter(fun /*, thisp */) {
  7118. var object = toObject(this),
  7119. self = splitString && _toString(this) == "[object String]" ?
  7120. this.split("") :
  7121. object,
  7122. length = self.length >>> 0,
  7123. result = [],
  7124. value,
  7125. thisp = arguments[1];
  7126. if (_toString(fun) != "[object Function]") {
  7127. throw new TypeError(fun + " is not a function");
  7128. }
  7129. for (var i = 0; i < length; i++) {
  7130. if (i in self) {
  7131. value = self[i];
  7132. if (fun.call(thisp, value, i, object)) {
  7133. result.push(value);
  7134. }
  7135. }
  7136. }
  7137. return result;
  7138. };
  7139. }
  7140. if (!Array.prototype.every) {
  7141. Array.prototype.every = function every(fun /*, thisp */) {
  7142. var object = toObject(this),
  7143. self = splitString && _toString(this) == "[object String]" ?
  7144. this.split("") :
  7145. object,
  7146. length = self.length >>> 0,
  7147. thisp = arguments[1];
  7148. if (_toString(fun) != "[object Function]") {
  7149. throw new TypeError(fun + " is not a function");
  7150. }
  7151. for (var i = 0; i < length; i++) {
  7152. if (i in self && !fun.call(thisp, self[i], i, object)) {
  7153. return false;
  7154. }
  7155. }
  7156. return true;
  7157. };
  7158. }
  7159. if (!Array.prototype.some) {
  7160. Array.prototype.some = function some(fun /*, thisp */) {
  7161. var object = toObject(this),
  7162. self = splitString && _toString(this) == "[object String]" ?
  7163. this.split("") :
  7164. object,
  7165. length = self.length >>> 0,
  7166. thisp = arguments[1];
  7167. if (_toString(fun) != "[object Function]") {
  7168. throw new TypeError(fun + " is not a function");
  7169. }
  7170. for (var i = 0; i < length; i++) {
  7171. if (i in self && fun.call(thisp, self[i], i, object)) {
  7172. return true;
  7173. }
  7174. }
  7175. return false;
  7176. };
  7177. }
  7178. if (!Array.prototype.reduce) {
  7179. Array.prototype.reduce = function reduce(fun /*, initial*/) {
  7180. var object = toObject(this),
  7181. self = splitString && _toString(this) == "[object String]" ?
  7182. this.split("") :
  7183. object,
  7184. length = self.length >>> 0;
  7185. if (_toString(fun) != "[object Function]") {
  7186. throw new TypeError(fun + " is not a function");
  7187. }
  7188. if (!length && arguments.length == 1) {
  7189. throw new TypeError("reduce of empty array with no initial value");
  7190. }
  7191. var i = 0;
  7192. var result;
  7193. if (arguments.length >= 2) {
  7194. result = arguments[1];
  7195. } else {
  7196. do {
  7197. if (i in self) {
  7198. result = self[i++];
  7199. break;
  7200. }
  7201. if (++i >= length) {
  7202. throw new TypeError("reduce of empty array with no initial value");
  7203. }
  7204. } while (true);
  7205. }
  7206. for (; i < length; i++) {
  7207. if (i in self) {
  7208. result = fun.call(void 0, result, self[i], i, object);
  7209. }
  7210. }
  7211. return result;
  7212. };
  7213. }
  7214. if (!Array.prototype.reduceRight) {
  7215. Array.prototype.reduceRight = function reduceRight(fun /*, initial*/) {
  7216. var object = toObject(this),
  7217. self = splitString && _toString(this) == "[object String]" ?
  7218. this.split("") :
  7219. object,
  7220. length = self.length >>> 0;
  7221. if (_toString(fun) != "[object Function]") {
  7222. throw new TypeError(fun + " is not a function");
  7223. }
  7224. if (!length && arguments.length == 1) {
  7225. throw new TypeError("reduceRight of empty array with no initial value");
  7226. }
  7227. var result, i = length - 1;
  7228. if (arguments.length >= 2) {
  7229. result = arguments[1];
  7230. } else {
  7231. do {
  7232. if (i in self) {
  7233. result = self[i--];
  7234. break;
  7235. }
  7236. if (--i < 0) {
  7237. throw new TypeError("reduceRight of empty array with no initial value");
  7238. }
  7239. } while (true);
  7240. }
  7241. do {
  7242. if (i in this) {
  7243. result = fun.call(void 0, result, self[i], i, object);
  7244. }
  7245. } while (i--);
  7246. return result;
  7247. };
  7248. }
  7249. if (!Array.prototype.indexOf || ([0, 1].indexOf(1, 2) != -1)) {
  7250. Array.prototype.indexOf = function indexOf(sought /*, fromIndex */ ) {
  7251. var self = splitString && _toString(this) == "[object String]" ?
  7252. this.split("") :
  7253. toObject(this),
  7254. length = self.length >>> 0;
  7255. if (!length) {
  7256. return -1;
  7257. }
  7258. var i = 0;
  7259. if (arguments.length > 1) {
  7260. i = toInteger(arguments[1]);
  7261. }
  7262. i = i >= 0 ? i : Math.max(0, length + i);
  7263. for (; i < length; i++) {
  7264. if (i in self && self[i] === sought) {
  7265. return i;
  7266. }
  7267. }
  7268. return -1;
  7269. };
  7270. }
  7271. if (!Array.prototype.lastIndexOf || ([0, 1].lastIndexOf(0, -3) != -1)) {
  7272. Array.prototype.lastIndexOf = function lastIndexOf(sought /*, fromIndex */) {
  7273. var self = splitString && _toString(this) == "[object String]" ?
  7274. this.split("") :
  7275. toObject(this),
  7276. length = self.length >>> 0;
  7277. if (!length) {
  7278. return -1;
  7279. }
  7280. var i = length - 1;
  7281. if (arguments.length > 1) {
  7282. i = Math.min(i, toInteger(arguments[1]));
  7283. }
  7284. i = i >= 0 ? i : length - Math.abs(i);
  7285. for (; i >= 0; i--) {
  7286. if (i in self && sought === self[i]) {
  7287. return i;
  7288. }
  7289. }
  7290. return -1;
  7291. };
  7292. }
  7293. //
  7294. //
  7295. if (!Object.getPrototypeOf) {
  7296. Object.getPrototypeOf = function getPrototypeOf(object) {
  7297. return object.__proto__ || (
  7298. object.constructor ?
  7299. object.constructor.prototype :
  7300. prototypeOfObject
  7301. );
  7302. };
  7303. }
  7304. if (!Object.getOwnPropertyDescriptor) {
  7305. var ERR_NON_OBJECT = "Object.getOwnPropertyDescriptor called on a " +
  7306. "non-object: ";
  7307. Object.getOwnPropertyDescriptor = function getOwnPropertyDescriptor(object, property) {
  7308. if ((typeof object != "object" && typeof object != "function") || object === null)
  7309. throw new TypeError(ERR_NON_OBJECT + object);
  7310. if (!owns(object, property))
  7311. return;
  7312. var descriptor, getter, setter;
  7313. descriptor = { enumerable: true, configurable: true };
  7314. if (supportsAccessors) {
  7315. var prototype = object.__proto__;
  7316. object.__proto__ = prototypeOfObject;
  7317. var getter = lookupGetter(object, property);
  7318. var setter = lookupSetter(object, property);
  7319. object.__proto__ = prototype;
  7320. if (getter || setter) {
  7321. if (getter) descriptor.get = getter;
  7322. if (setter) descriptor.set = setter;
  7323. return descriptor;
  7324. }
  7325. }
  7326. descriptor.value = object[property];
  7327. return descriptor;
  7328. };
  7329. }
  7330. if (!Object.getOwnPropertyNames) {
  7331. Object.getOwnPropertyNames = function getOwnPropertyNames(object) {
  7332. return Object.keys(object);
  7333. };
  7334. }
  7335. if (!Object.create) {
  7336. var createEmpty;
  7337. if (Object.prototype.__proto__ === null) {
  7338. createEmpty = function () {
  7339. return { "__proto__": null };
  7340. };
  7341. } else {
  7342. createEmpty = function () {
  7343. var empty = {};
  7344. for (var i in empty)
  7345. empty[i] = null;
  7346. empty.constructor =
  7347. empty.hasOwnProperty =
  7348. empty.propertyIsEnumerable =
  7349. empty.isPrototypeOf =
  7350. empty.toLocaleString =
  7351. empty.toString =
  7352. empty.valueOf =
  7353. empty.__proto__ = null;
  7354. return empty;
  7355. }
  7356. }
  7357. Object.create = function create(prototype, properties) {
  7358. var object;
  7359. if (prototype === null) {
  7360. object = createEmpty();
  7361. } else {
  7362. if (typeof prototype != "object")
  7363. throw new TypeError("typeof prototype["+(typeof prototype)+"] != 'object'");
  7364. var Type = function () {};
  7365. Type.prototype = prototype;
  7366. object = new Type();
  7367. object.__proto__ = prototype;
  7368. }
  7369. if (properties !== void 0)
  7370. Object.defineProperties(object, properties);
  7371. return object;
  7372. };
  7373. }
  7374. function doesDefinePropertyWork(object) {
  7375. try {
  7376. Object.defineProperty(object, "sentinel", {});
  7377. return "sentinel" in object;
  7378. } catch (exception) {
  7379. }
  7380. }
  7381. if (Object.defineProperty) {
  7382. var definePropertyWorksOnObject = doesDefinePropertyWork({});
  7383. var definePropertyWorksOnDom = typeof document == "undefined" ||
  7384. doesDefinePropertyWork(document.createElement("div"));
  7385. if (!definePropertyWorksOnObject || !definePropertyWorksOnDom) {
  7386. var definePropertyFallback = Object.defineProperty;
  7387. }
  7388. }
  7389. if (!Object.defineProperty || definePropertyFallback) {
  7390. var ERR_NON_OBJECT_DESCRIPTOR = "Property description must be an object: ";
  7391. var ERR_NON_OBJECT_TARGET = "Object.defineProperty called on non-object: "
  7392. var ERR_ACCESSORS_NOT_SUPPORTED = "getters & setters can not be defined " +
  7393. "on this javascript engine";
  7394. Object.defineProperty = function defineProperty(object, property, descriptor) {
  7395. if ((typeof object != "object" && typeof object != "function") || object === null)
  7396. throw new TypeError(ERR_NON_OBJECT_TARGET + object);
  7397. if ((typeof descriptor != "object" && typeof descriptor != "function") || descriptor === null)
  7398. throw new TypeError(ERR_NON_OBJECT_DESCRIPTOR + descriptor);
  7399. if (definePropertyFallback) {
  7400. try {
  7401. return definePropertyFallback.call(Object, object, property, descriptor);
  7402. } catch (exception) {
  7403. }
  7404. }
  7405. if (owns(descriptor, "value")) {
  7406. if (supportsAccessors && (lookupGetter(object, property) ||
  7407. lookupSetter(object, property)))
  7408. {
  7409. var prototype = object.__proto__;
  7410. object.__proto__ = prototypeOfObject;
  7411. delete object[property];
  7412. object[property] = descriptor.value;
  7413. object.__proto__ = prototype;
  7414. } else {
  7415. object[property] = descriptor.value;
  7416. }
  7417. } else {
  7418. if (!supportsAccessors)
  7419. throw new TypeError(ERR_ACCESSORS_NOT_SUPPORTED);
  7420. if (owns(descriptor, "get"))
  7421. defineGetter(object, property, descriptor.get);
  7422. if (owns(descriptor, "set"))
  7423. defineSetter(object, property, descriptor.set);
  7424. }
  7425. return object;
  7426. };
  7427. }
  7428. if (!Object.defineProperties) {
  7429. Object.defineProperties = function defineProperties(object, properties) {
  7430. for (var property in properties) {
  7431. if (owns(properties, property))
  7432. Object.defineProperty(object, property, properties[property]);
  7433. }
  7434. return object;
  7435. };
  7436. }
  7437. if (!Object.seal) {
  7438. Object.seal = function seal(object) {
  7439. return object;
  7440. };
  7441. }
  7442. if (!Object.freeze) {
  7443. Object.freeze = function freeze(object) {
  7444. return object;
  7445. };
  7446. }
  7447. try {
  7448. Object.freeze(function () {});
  7449. } catch (exception) {
  7450. Object.freeze = (function freeze(freezeObject) {
  7451. return function freeze(object) {
  7452. if (typeof object == "function") {
  7453. return object;
  7454. } else {
  7455. return freezeObject(object);
  7456. }
  7457. };
  7458. })(Object.freeze);
  7459. }
  7460. if (!Object.preventExtensions) {
  7461. Object.preventExtensions = function preventExtensions(object) {
  7462. return object;
  7463. };
  7464. }
  7465. if (!Object.isSealed) {
  7466. Object.isSealed = function isSealed(object) {
  7467. return false;
  7468. };
  7469. }
  7470. if (!Object.isFrozen) {
  7471. Object.isFrozen = function isFrozen(object) {
  7472. return false;
  7473. };
  7474. }
  7475. if (!Object.isExtensible) {
  7476. Object.isExtensible = function isExtensible(object) {
  7477. if (Object(object) === object) {
  7478. throw new TypeError(); // TODO message
  7479. }
  7480. var name = '';
  7481. while (owns(object, name)) {
  7482. name += '?';
  7483. }
  7484. object[name] = true;
  7485. var returnValue = owns(object, name);
  7486. delete object[name];
  7487. return returnValue;
  7488. };
  7489. }
  7490. if (!Object.keys) {
  7491. var hasDontEnumBug = true,
  7492. dontEnums = [
  7493. "toString",
  7494. "toLocaleString",
  7495. "valueOf",
  7496. "hasOwnProperty",
  7497. "isPrototypeOf",
  7498. "propertyIsEnumerable",
  7499. "constructor"
  7500. ],
  7501. dontEnumsLength = dontEnums.length;
  7502. for (var key in {"toString": null}) {
  7503. hasDontEnumBug = false;
  7504. }
  7505. Object.keys = function keys(object) {
  7506. if (
  7507. (typeof object != "object" && typeof object != "function") ||
  7508. object === null
  7509. ) {
  7510. throw new TypeError("Object.keys called on a non-object");
  7511. }
  7512. var keys = [];
  7513. for (var name in object) {
  7514. if (owns(object, name)) {
  7515. keys.push(name);
  7516. }
  7517. }
  7518. if (hasDontEnumBug) {
  7519. for (var i = 0, ii = dontEnumsLength; i < ii; i++) {
  7520. var dontEnum = dontEnums[i];
  7521. if (owns(object, dontEnum)) {
  7522. keys.push(dontEnum);
  7523. }
  7524. }
  7525. }
  7526. return keys;
  7527. };
  7528. }
  7529. //
  7530. //
  7531. if (!Date.now) {
  7532. Date.now = function now() {
  7533. return new Date().getTime();
  7534. };
  7535. }
  7536. //
  7537. //
  7538. var ws = "\x09\x0A\x0B\x0C\x0D\x20\xA0\u1680\u180E\u2000\u2001\u2002\u2003" +
  7539. "\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000\u2028" +
  7540. "\u2029\uFEFF";
  7541. if (!String.prototype.trim || ws.trim()) {
  7542. ws = "[" + ws + "]";
  7543. var trimBeginRegexp = new RegExp("^" + ws + ws + "*"),
  7544. trimEndRegexp = new RegExp(ws + ws + "*$");
  7545. String.prototype.trim = function trim() {
  7546. return String(this).replace(trimBeginRegexp, "").replace(trimEndRegexp, "");
  7547. };
  7548. }
  7549. //
  7550. //
  7551. function toInteger(n) {
  7552. n = +n;
  7553. if (n !== n) { // isNaN
  7554. n = 0;
  7555. } else if (n !== 0 && n !== (1/0) && n !== -(1/0)) {
  7556. n = (n > 0 || -1) * Math.floor(Math.abs(n));
  7557. }
  7558. return n;
  7559. }
  7560. function isPrimitive(input) {
  7561. var type = typeof input;
  7562. return (
  7563. input === null ||
  7564. type === "undefined" ||
  7565. type === "boolean" ||
  7566. type === "number" ||
  7567. type === "string"
  7568. );
  7569. }
  7570. function toPrimitive(input) {
  7571. var val, valueOf, toString;
  7572. if (isPrimitive(input)) {
  7573. return input;
  7574. }
  7575. valueOf = input.valueOf;
  7576. if (typeof valueOf === "function") {
  7577. val = valueOf.call(input);
  7578. if (isPrimitive(val)) {
  7579. return val;
  7580. }
  7581. }
  7582. toString = input.toString;
  7583. if (typeof toString === "function") {
  7584. val = toString.call(input);
  7585. if (isPrimitive(val)) {
  7586. return val;
  7587. }
  7588. }
  7589. throw new TypeError();
  7590. }
  7591. var toObject = function (o) {
  7592. if (o == null) { // this matches both null and undefined
  7593. throw new TypeError("can't convert "+o+" to object");
  7594. }
  7595. return Object(o);
  7596. };
  7597. });