worker-css.js 290 KB

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