worker-css.js 290 KB

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