worker-css.js 291 KB

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