worker-css.js 290 KB

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