less.js 434 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584
  1. /*!
  2. * Less - Leaner CSS v3.8.0
  3. * http://lesscss.org
  4. *
  5. * Copyright (c) 2009-2018, Alexis Sellier <self@cloudhead.net>
  6. * Licensed under the Apache-2.0 License.
  7. *
  8. */
  9. /** * @license Apache-2.0
  10. */
  11. (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.less = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
  12. var addDataAttr = require('./utils').addDataAttr,
  13. browser = require('./browser');
  14. module.exports = function(window, options) {
  15. // use options from the current script tag data attribues
  16. addDataAttr(options, browser.currentScript(window));
  17. if (options.isFileProtocol === undefined) {
  18. options.isFileProtocol = /^(file|(chrome|safari)(-extension)?|resource|qrc|app):/.test(window.location.protocol);
  19. }
  20. // Load styles asynchronously (default: false)
  21. //
  22. // This is set to `false` by default, so that the body
  23. // doesn't start loading before the stylesheets are parsed.
  24. // Setting this to `true` can result in flickering.
  25. //
  26. options.async = options.async || false;
  27. options.fileAsync = options.fileAsync || false;
  28. // Interval between watch polls
  29. options.poll = options.poll || (options.isFileProtocol ? 1000 : 1500);
  30. options.env = options.env || (window.location.hostname == '127.0.0.1' ||
  31. window.location.hostname == '0.0.0.0' ||
  32. window.location.hostname == 'localhost' ||
  33. (window.location.port &&
  34. window.location.port.length > 0) ||
  35. options.isFileProtocol ? 'development'
  36. : 'production');
  37. var dumpLineNumbers = /!dumpLineNumbers:(comments|mediaquery|all)/.exec(window.location.hash);
  38. if (dumpLineNumbers) {
  39. options.dumpLineNumbers = dumpLineNumbers[1];
  40. }
  41. if (options.useFileCache === undefined) {
  42. options.useFileCache = true;
  43. }
  44. if (options.onReady === undefined) {
  45. options.onReady = true;
  46. }
  47. if (options.relativeUrls) {
  48. options.rewriteUrls = 'all';
  49. }
  50. };
  51. },{"./browser":3,"./utils":11}],2:[function(require,module,exports){
  52. /**
  53. * Kicks off less and compiles any stylesheets
  54. * used in the browser distributed version of less
  55. * to kick-start less using the browser api
  56. */
  57. /* global window, document */
  58. // TODO - consider switching this out for a recommendation for this polyfill?
  59. // <script src="https://cdn.polyfill.io/v2/polyfill.min.js"></script>
  60. // Browsers have good Promise support
  61. require('promise/polyfill');
  62. var options = require('../less/default-options')();
  63. if (window.less) {
  64. for (key in window.less) {
  65. if (window.less.hasOwnProperty(key)) {
  66. options[key] = window.less[key];
  67. }
  68. }
  69. }
  70. require('./add-default-options')(window, options);
  71. options.plugins = options.plugins || [];
  72. if (window.LESS_PLUGINS) {
  73. options.plugins = options.plugins.concat(window.LESS_PLUGINS);
  74. }
  75. var less = module.exports = require('./index')(window, options);
  76. window.less = less;
  77. var css, head, style;
  78. // Always restore page visibility
  79. function resolveOrReject(data) {
  80. if (data.filename) {
  81. console.warn(data);
  82. }
  83. if (!options.async) {
  84. head.removeChild(style);
  85. }
  86. }
  87. if (options.onReady) {
  88. if (/!watch/.test(window.location.hash)) {
  89. less.watch();
  90. }
  91. // Simulate synchronous stylesheet loading by hiding page rendering
  92. if (!options.async) {
  93. css = 'body { display: none !important }';
  94. head = document.head || document.getElementsByTagName('head')[0];
  95. style = document.createElement('style');
  96. style.type = 'text/css';
  97. if (style.styleSheet) {
  98. style.styleSheet.cssText = css;
  99. } else {
  100. style.appendChild(document.createTextNode(css));
  101. }
  102. head.appendChild(style);
  103. }
  104. less.registerStylesheetsImmediately();
  105. less.pageLoadFinished = less.refresh(less.env === 'development').then(resolveOrReject, resolveOrReject);
  106. }
  107. },{"../less/default-options":17,"./add-default-options":1,"./index":8,"promise/polyfill":103}],3:[function(require,module,exports){
  108. var utils = require('./utils');
  109. module.exports = {
  110. createCSS: function (document, styles, sheet) {
  111. // Strip the query-string
  112. var href = sheet.href || '';
  113. // If there is no title set, use the filename, minus the extension
  114. var id = 'less:' + (sheet.title || utils.extractId(href));
  115. // If this has already been inserted into the DOM, we may need to replace it
  116. var oldStyleNode = document.getElementById(id);
  117. var keepOldStyleNode = false;
  118. // Create a new stylesheet node for insertion or (if necessary) replacement
  119. var styleNode = document.createElement('style');
  120. styleNode.setAttribute('type', 'text/css');
  121. if (sheet.media) {
  122. styleNode.setAttribute('media', sheet.media);
  123. }
  124. styleNode.id = id;
  125. if (!styleNode.styleSheet) {
  126. styleNode.appendChild(document.createTextNode(styles));
  127. // If new contents match contents of oldStyleNode, don't replace oldStyleNode
  128. keepOldStyleNode = (oldStyleNode !== null && oldStyleNode.childNodes.length > 0 && styleNode.childNodes.length > 0 &&
  129. oldStyleNode.firstChild.nodeValue === styleNode.firstChild.nodeValue);
  130. }
  131. var head = document.getElementsByTagName('head')[0];
  132. // If there is no oldStyleNode, just append; otherwise, only append if we need
  133. // to replace oldStyleNode with an updated stylesheet
  134. if (oldStyleNode === null || keepOldStyleNode === false) {
  135. var nextEl = sheet && sheet.nextSibling || null;
  136. if (nextEl) {
  137. nextEl.parentNode.insertBefore(styleNode, nextEl);
  138. } else {
  139. head.appendChild(styleNode);
  140. }
  141. }
  142. if (oldStyleNode && keepOldStyleNode === false) {
  143. oldStyleNode.parentNode.removeChild(oldStyleNode);
  144. }
  145. // For IE.
  146. // This needs to happen *after* the style element is added to the DOM, otherwise IE 7 and 8 may crash.
  147. // See http://social.msdn.microsoft.com/Forums/en-US/7e081b65-878a-4c22-8e68-c10d39c2ed32/internet-explorer-crashes-appending-style-element-to-head
  148. if (styleNode.styleSheet) {
  149. try {
  150. styleNode.styleSheet.cssText = styles;
  151. } catch (e) {
  152. throw new Error('Couldn\'t reassign styleSheet.cssText.');
  153. }
  154. }
  155. },
  156. currentScript: function(window) {
  157. var document = window.document;
  158. return document.currentScript || (function() {
  159. var scripts = document.getElementsByTagName('script');
  160. return scripts[scripts.length - 1];
  161. })();
  162. }
  163. };
  164. },{"./utils":11}],4:[function(require,module,exports){
  165. // Cache system is a bit outdated and could do with work
  166. module.exports = function(window, options, logger) {
  167. var cache = null;
  168. if (options.env !== 'development') {
  169. try {
  170. cache = (typeof window.localStorage === 'undefined') ? null : window.localStorage;
  171. } catch (_) {}
  172. }
  173. return {
  174. setCSS: function(path, lastModified, modifyVars, styles) {
  175. if (cache) {
  176. logger.info('saving ' + path + ' to cache.');
  177. try {
  178. cache.setItem(path, styles);
  179. cache.setItem(path + ':timestamp', lastModified);
  180. if (modifyVars) {
  181. cache.setItem(path + ':vars', JSON.stringify(modifyVars));
  182. }
  183. } catch (e) {
  184. // TODO - could do with adding more robust error handling
  185. logger.error('failed to save "' + path + '" to local storage for caching.');
  186. }
  187. }
  188. },
  189. getCSS: function(path, webInfo, modifyVars) {
  190. var css = cache && cache.getItem(path),
  191. timestamp = cache && cache.getItem(path + ':timestamp'),
  192. vars = cache && cache.getItem(path + ':vars');
  193. modifyVars = modifyVars || {};
  194. vars = vars || "{}"; // if not set, treat as the JSON representation of an empty object
  195. if (timestamp && webInfo.lastModified &&
  196. (new Date(webInfo.lastModified).valueOf() ===
  197. new Date(timestamp).valueOf()) &&
  198. JSON.stringify(modifyVars) === vars) {
  199. // Use local copy
  200. return css;
  201. }
  202. }
  203. };
  204. };
  205. },{}],5:[function(require,module,exports){
  206. var utils = require('./utils'),
  207. browser = require('./browser');
  208. module.exports = function(window, less, options) {
  209. function errorHTML(e, rootHref) {
  210. var id = 'less-error-message:' + utils.extractId(rootHref || '');
  211. var template = '<li><label>{line}</label><pre class="{class}">{content}</pre></li>';
  212. var elem = window.document.createElement('div'), timer, content, errors = [];
  213. var filename = e.filename || rootHref;
  214. var filenameNoPath = filename.match(/([^\/]+(\?.*)?)$/)[1];
  215. elem.id = id;
  216. elem.className = 'less-error-message';
  217. content = '<h3>' + (e.type || 'Syntax') + 'Error: ' + (e.message || 'There is an error in your .less file') +
  218. '</h3>' + '<p>in <a href="' + filename + '">' + filenameNoPath + '</a> ';
  219. var errorline = function (e, i, classname) {
  220. if (e.extract[i] !== undefined) {
  221. errors.push(template.replace(/\{line\}/, (parseInt(e.line, 10) || 0) + (i - 1))
  222. .replace(/\{class\}/, classname)
  223. .replace(/\{content\}/, e.extract[i]));
  224. }
  225. };
  226. if (e.line) {
  227. errorline(e, 0, '');
  228. errorline(e, 1, 'line');
  229. errorline(e, 2, '');
  230. content += 'on line ' + e.line + ', column ' + (e.column + 1) + ':</p>' +
  231. '<ul>' + errors.join('') + '</ul>';
  232. }
  233. if (e.stack && (e.extract || options.logLevel >= 4)) {
  234. content += '<br/>Stack Trace</br />' + e.stack.split('\n').slice(1).join('<br/>');
  235. }
  236. elem.innerHTML = content;
  237. // CSS for error messages
  238. browser.createCSS(window.document, [
  239. '.less-error-message ul, .less-error-message li {',
  240. 'list-style-type: none;',
  241. 'margin-right: 15px;',
  242. 'padding: 4px 0;',
  243. 'margin: 0;',
  244. '}',
  245. '.less-error-message label {',
  246. 'font-size: 12px;',
  247. 'margin-right: 15px;',
  248. 'padding: 4px 0;',
  249. 'color: #cc7777;',
  250. '}',
  251. '.less-error-message pre {',
  252. 'color: #dd6666;',
  253. 'padding: 4px 0;',
  254. 'margin: 0;',
  255. 'display: inline-block;',
  256. '}',
  257. '.less-error-message pre.line {',
  258. 'color: #ff0000;',
  259. '}',
  260. '.less-error-message h3 {',
  261. 'font-size: 20px;',
  262. 'font-weight: bold;',
  263. 'padding: 15px 0 5px 0;',
  264. 'margin: 0;',
  265. '}',
  266. '.less-error-message a {',
  267. 'color: #10a',
  268. '}',
  269. '.less-error-message .error {',
  270. 'color: red;',
  271. 'font-weight: bold;',
  272. 'padding-bottom: 2px;',
  273. 'border-bottom: 1px dashed red;',
  274. '}'
  275. ].join('\n'), { title: 'error-message' });
  276. elem.style.cssText = [
  277. 'font-family: Arial, sans-serif',
  278. 'border: 1px solid #e00',
  279. 'background-color: #eee',
  280. 'border-radius: 5px',
  281. '-webkit-border-radius: 5px',
  282. '-moz-border-radius: 5px',
  283. 'color: #e00',
  284. 'padding: 15px',
  285. 'margin-bottom: 15px'
  286. ].join(';');
  287. if (options.env === 'development') {
  288. timer = setInterval(function () {
  289. var document = window.document,
  290. body = document.body;
  291. if (body) {
  292. if (document.getElementById(id)) {
  293. body.replaceChild(elem, document.getElementById(id));
  294. } else {
  295. body.insertBefore(elem, body.firstChild);
  296. }
  297. clearInterval(timer);
  298. }
  299. }, 10);
  300. }
  301. }
  302. function removeErrorHTML(path) {
  303. var node = window.document.getElementById('less-error-message:' + utils.extractId(path));
  304. if (node) {
  305. node.parentNode.removeChild(node);
  306. }
  307. }
  308. function removeErrorConsole(path) {
  309. // no action
  310. }
  311. function removeError(path) {
  312. if (!options.errorReporting || options.errorReporting === 'html') {
  313. removeErrorHTML(path);
  314. } else if (options.errorReporting === 'console') {
  315. removeErrorConsole(path);
  316. } else if (typeof options.errorReporting === 'function') {
  317. options.errorReporting('remove', path);
  318. }
  319. }
  320. function errorConsole(e, rootHref) {
  321. var template = '{line} {content}';
  322. var filename = e.filename || rootHref;
  323. var errors = [];
  324. var content = (e.type || 'Syntax') + 'Error: ' + (e.message || 'There is an error in your .less file') +
  325. ' in ' + filename;
  326. var errorline = function (e, i, classname) {
  327. if (e.extract[i] !== undefined) {
  328. errors.push(template.replace(/\{line\}/, (parseInt(e.line, 10) || 0) + (i - 1))
  329. .replace(/\{class\}/, classname)
  330. .replace(/\{content\}/, e.extract[i]));
  331. }
  332. };
  333. if (e.line) {
  334. errorline(e, 0, '');
  335. errorline(e, 1, 'line');
  336. errorline(e, 2, '');
  337. content += ' on line ' + e.line + ', column ' + (e.column + 1) + ':\n' +
  338. errors.join('\n');
  339. }
  340. if (e.stack && (e.extract || options.logLevel >= 4)) {
  341. content += '\nStack Trace\n' + e.stack;
  342. }
  343. less.logger.error(content);
  344. }
  345. function error(e, rootHref) {
  346. if (!options.errorReporting || options.errorReporting === 'html') {
  347. errorHTML(e, rootHref);
  348. } else if (options.errorReporting === 'console') {
  349. errorConsole(e, rootHref);
  350. } else if (typeof options.errorReporting === 'function') {
  351. options.errorReporting('add', e, rootHref);
  352. }
  353. }
  354. return {
  355. add: error,
  356. remove: removeError
  357. };
  358. };
  359. },{"./browser":3,"./utils":11}],6:[function(require,module,exports){
  360. /* global window, XMLHttpRequest */
  361. module.exports = function(options, logger) {
  362. var AbstractFileManager = require('../less/environment/abstract-file-manager.js');
  363. var fileCache = {};
  364. // TODOS - move log somewhere. pathDiff and doing something similar in node. use pathDiff in the other browser file for the initial load
  365. var FileManager = function() {
  366. };
  367. FileManager.prototype = new AbstractFileManager();
  368. FileManager.prototype.alwaysMakePathsAbsolute = function alwaysMakePathsAbsolute() {
  369. return true;
  370. };
  371. FileManager.prototype.join = function join(basePath, laterPath) {
  372. if (!basePath) {
  373. return laterPath;
  374. }
  375. return this.extractUrlParts(laterPath, basePath).path;
  376. };
  377. FileManager.prototype.doXHR = function doXHR(url, type, callback, errback) {
  378. var xhr = new XMLHttpRequest();
  379. var async = options.isFileProtocol ? options.fileAsync : true;
  380. if (typeof xhr.overrideMimeType === 'function') {
  381. xhr.overrideMimeType('text/css');
  382. }
  383. logger.debug('XHR: Getting \'' + url + '\'');
  384. xhr.open('GET', url, async);
  385. xhr.setRequestHeader('Accept', type || 'text/x-less, text/css; q=0.9, */*; q=0.5');
  386. xhr.send(null);
  387. function handleResponse(xhr, callback, errback) {
  388. if (xhr.status >= 200 && xhr.status < 300) {
  389. callback(xhr.responseText,
  390. xhr.getResponseHeader('Last-Modified'));
  391. } else if (typeof errback === 'function') {
  392. errback(xhr.status, url);
  393. }
  394. }
  395. if (options.isFileProtocol && !options.fileAsync) {
  396. if (xhr.status === 0 || (xhr.status >= 200 && xhr.status < 300)) {
  397. callback(xhr.responseText);
  398. } else {
  399. errback(xhr.status, url);
  400. }
  401. } else if (async) {
  402. xhr.onreadystatechange = function () {
  403. if (xhr.readyState == 4) {
  404. handleResponse(xhr, callback, errback);
  405. }
  406. };
  407. } else {
  408. handleResponse(xhr, callback, errback);
  409. }
  410. };
  411. FileManager.prototype.supports = function(filename, currentDirectory, options, environment) {
  412. return true;
  413. };
  414. FileManager.prototype.clearFileCache = function() {
  415. fileCache = {};
  416. };
  417. FileManager.prototype.loadFile = function loadFile(filename, currentDirectory, options, environment) {
  418. // TODO: Add prefix support like less-node?
  419. // What about multiple paths?
  420. if (currentDirectory && !this.isPathAbsolute(filename)) {
  421. filename = currentDirectory + filename;
  422. }
  423. filename = options.ext ? this.tryAppendExtension(filename, options.ext) : filename;
  424. options = options || {};
  425. // sheet may be set to the stylesheet for the initial load or a collection of properties including
  426. // some context variables for imports
  427. var hrefParts = this.extractUrlParts(filename, window.location.href);
  428. var href = hrefParts.url;
  429. var self = this;
  430. return new Promise(function(resolve, reject) {
  431. if (options.useFileCache && fileCache[href]) {
  432. try {
  433. var lessText = fileCache[href];
  434. return resolve({ contents: lessText, filename: href, webInfo: { lastModified: new Date() }});
  435. } catch (e) {
  436. return reject({ filename: href, message: 'Error loading file ' + href + ' error was ' + e.message });
  437. }
  438. }
  439. self.doXHR(href, options.mime, function doXHRCallback(data, lastModified) {
  440. // per file cache
  441. fileCache[href] = data;
  442. // Use remote copy (re-parse)
  443. resolve({ contents: data, filename: href, webInfo: { lastModified: lastModified }});
  444. }, function doXHRError(status, url) {
  445. reject({ type: 'File', message: '\'' + url + '\' wasn\'t found (' + status + ')', href: href });
  446. });
  447. });
  448. };
  449. return FileManager;
  450. };
  451. },{"../less/environment/abstract-file-manager.js":18}],7:[function(require,module,exports){
  452. module.exports = function() {
  453. var functionRegistry = require('./../less/functions/function-registry');
  454. function imageSize() {
  455. throw {
  456. type: 'Runtime',
  457. message: 'Image size functions are not supported in browser version of less'
  458. };
  459. }
  460. var imageFunctions = {
  461. 'image-size': function(filePathNode) {
  462. imageSize(this, filePathNode);
  463. return -1;
  464. },
  465. 'image-width': function(filePathNode) {
  466. imageSize(this, filePathNode);
  467. return -1;
  468. },
  469. 'image-height': function(filePathNode) {
  470. imageSize(this, filePathNode);
  471. return -1;
  472. }
  473. };
  474. functionRegistry.addMultiple(imageFunctions);
  475. };
  476. },{"./../less/functions/function-registry":27}],8:[function(require,module,exports){
  477. //
  478. // index.js
  479. // Should expose the additional browser functions on to the less object
  480. //
  481. var addDataAttr = require('./utils').addDataAttr,
  482. browser = require('./browser');
  483. module.exports = function(window, options) {
  484. var document = window.document;
  485. var less = require('../less')();
  486. less.options = options;
  487. var environment = less.environment,
  488. FileManager = require('./file-manager')(options, less.logger),
  489. fileManager = new FileManager();
  490. environment.addFileManager(fileManager);
  491. less.FileManager = FileManager;
  492. less.PluginLoader = require('./plugin-loader');
  493. require('./log-listener')(less, options);
  494. var errors = require('./error-reporting')(window, less, options);
  495. var cache = less.cache = options.cache || require('./cache')(window, options, less.logger);
  496. require('./image-size')(less.environment);
  497. // Setup user functions - Deprecate?
  498. if (options.functions) {
  499. less.functions.functionRegistry.addMultiple(options.functions);
  500. }
  501. var typePattern = /^text\/(x-)?less$/;
  502. function clone(obj) {
  503. return JSON.parse(JSON.stringify(obj || {}));
  504. }
  505. // only really needed for phantom
  506. function bind(func, thisArg) {
  507. var curryArgs = Array.prototype.slice.call(arguments, 2);
  508. return function() {
  509. var args = curryArgs.concat(Array.prototype.slice.call(arguments, 0));
  510. return func.apply(thisArg, args);
  511. };
  512. }
  513. function loadStyles(modifyVars) {
  514. var styles = document.getElementsByTagName('style'),
  515. style;
  516. for (var i = 0; i < styles.length; i++) {
  517. style = styles[i];
  518. if (style.type.match(typePattern)) {
  519. var instanceOptions = clone(options);
  520. instanceOptions.modifyVars = modifyVars;
  521. var lessText = style.innerHTML || '';
  522. instanceOptions.filename = document.location.href.replace(/#.*$/, '');
  523. /* jshint loopfunc:true */
  524. // use closure to store current style
  525. less.render(lessText, instanceOptions,
  526. bind(function(style, e, result) {
  527. if (e) {
  528. errors.add(e, 'inline');
  529. } else {
  530. style.type = 'text/css';
  531. if (style.styleSheet) {
  532. style.styleSheet.cssText = result.css;
  533. } else {
  534. style.innerHTML = result.css;
  535. }
  536. }
  537. }, null, style));
  538. }
  539. }
  540. }
  541. function loadStyleSheet(sheet, callback, reload, remaining, modifyVars) {
  542. var instanceOptions = clone(options);
  543. addDataAttr(instanceOptions, sheet);
  544. instanceOptions.mime = sheet.type;
  545. if (modifyVars) {
  546. instanceOptions.modifyVars = modifyVars;
  547. }
  548. function loadInitialFileCallback(loadedFile) {
  549. var data = loadedFile.contents,
  550. path = loadedFile.filename,
  551. webInfo = loadedFile.webInfo;
  552. var newFileInfo = {
  553. currentDirectory: fileManager.getPath(path),
  554. filename: path,
  555. rootFilename: path,
  556. rewriteUrls: instanceOptions.rewriteUrls
  557. };
  558. newFileInfo.entryPath = newFileInfo.currentDirectory;
  559. newFileInfo.rootpath = instanceOptions.rootpath || newFileInfo.currentDirectory;
  560. if (webInfo) {
  561. webInfo.remaining = remaining;
  562. var css = cache.getCSS(path, webInfo, instanceOptions.modifyVars);
  563. if (!reload && css) {
  564. webInfo.local = true;
  565. callback(null, css, data, sheet, webInfo, path);
  566. return;
  567. }
  568. }
  569. // TODO add tests around how this behaves when reloading
  570. errors.remove(path);
  571. instanceOptions.rootFileInfo = newFileInfo;
  572. less.render(data, instanceOptions, function(e, result) {
  573. if (e) {
  574. e.href = path;
  575. callback(e);
  576. } else {
  577. cache.setCSS(sheet.href, webInfo.lastModified, instanceOptions.modifyVars, result.css);
  578. callback(null, result.css, data, sheet, webInfo, path);
  579. }
  580. });
  581. }
  582. fileManager.loadFile(sheet.href, null, instanceOptions, environment)
  583. .then(function(loadedFile) {
  584. loadInitialFileCallback(loadedFile);
  585. }).catch(function(err) {
  586. console.log(err);
  587. callback(err);
  588. });
  589. }
  590. function loadStyleSheets(callback, reload, modifyVars) {
  591. for (var i = 0; i < less.sheets.length; i++) {
  592. loadStyleSheet(less.sheets[i], callback, reload, less.sheets.length - (i + 1), modifyVars);
  593. }
  594. }
  595. function initRunningMode() {
  596. if (less.env === 'development') {
  597. less.watchTimer = setInterval(function () {
  598. if (less.watchMode) {
  599. fileManager.clearFileCache();
  600. loadStyleSheets(function (e, css, _, sheet, webInfo) {
  601. if (e) {
  602. errors.add(e, e.href || sheet.href);
  603. } else if (css) {
  604. browser.createCSS(window.document, css, sheet);
  605. }
  606. });
  607. }
  608. }, options.poll);
  609. }
  610. }
  611. //
  612. // Watch mode
  613. //
  614. less.watch = function () {
  615. if (!less.watchMode ) {
  616. less.env = 'development';
  617. initRunningMode();
  618. }
  619. this.watchMode = true;
  620. return true;
  621. };
  622. less.unwatch = function () {clearInterval(less.watchTimer); this.watchMode = false; return false; };
  623. //
  624. // Synchronously get all <link> tags with the 'rel' attribute set to
  625. // "stylesheet/less".
  626. //
  627. less.registerStylesheetsImmediately = function() {
  628. var links = document.getElementsByTagName('link');
  629. less.sheets = [];
  630. for (var i = 0; i < links.length; i++) {
  631. if (links[i].rel === 'stylesheet/less' || (links[i].rel.match(/stylesheet/) &&
  632. (links[i].type.match(typePattern)))) {
  633. less.sheets.push(links[i]);
  634. }
  635. }
  636. };
  637. //
  638. // Asynchronously get all <link> tags with the 'rel' attribute set to
  639. // "stylesheet/less", returning a Promise.
  640. //
  641. less.registerStylesheets = function() {
  642. return new Promise(function(resolve, reject) {
  643. less.registerStylesheetsImmediately();
  644. resolve();
  645. });
  646. };
  647. //
  648. // With this function, it's possible to alter variables and re-render
  649. // CSS without reloading less-files
  650. //
  651. less.modifyVars = function(record) {
  652. return less.refresh(true, record, false);
  653. };
  654. less.refresh = function (reload, modifyVars, clearFileCache) {
  655. if ((reload || clearFileCache) && clearFileCache !== false) {
  656. fileManager.clearFileCache();
  657. }
  658. return new Promise(function (resolve, reject) {
  659. var startTime, endTime, totalMilliseconds, remainingSheets;
  660. startTime = endTime = new Date();
  661. // Set counter for remaining unprocessed sheets
  662. remainingSheets = less.sheets.length;
  663. if (remainingSheets === 0) {
  664. endTime = new Date();
  665. totalMilliseconds = endTime - startTime;
  666. less.logger.info('Less has finished and no sheets were loaded.');
  667. resolve({
  668. startTime: startTime,
  669. endTime: endTime,
  670. totalMilliseconds: totalMilliseconds,
  671. sheets: less.sheets.length
  672. });
  673. } else {
  674. // Relies on less.sheets array, callback seems to be guaranteed to be called for every element of the array
  675. loadStyleSheets(function (e, css, _, sheet, webInfo) {
  676. if (e) {
  677. errors.add(e, e.href || sheet.href);
  678. reject(e);
  679. return;
  680. }
  681. if (webInfo.local) {
  682. less.logger.info('Loading ' + sheet.href + ' from cache.');
  683. } else {
  684. less.logger.info('Rendered ' + sheet.href + ' successfully.');
  685. }
  686. browser.createCSS(window.document, css, sheet);
  687. less.logger.info('CSS for ' + sheet.href + ' generated in ' + (new Date() - endTime) + 'ms');
  688. // Count completed sheet
  689. remainingSheets--;
  690. // Check if the last remaining sheet was processed and then call the promise
  691. if (remainingSheets === 0) {
  692. totalMilliseconds = new Date() - startTime;
  693. less.logger.info('Less has finished. CSS generated in ' + totalMilliseconds + 'ms');
  694. resolve({
  695. startTime: startTime,
  696. endTime: endTime,
  697. totalMilliseconds: totalMilliseconds,
  698. sheets: less.sheets.length
  699. });
  700. }
  701. endTime = new Date();
  702. }, reload, modifyVars);
  703. }
  704. loadStyles(modifyVars);
  705. });
  706. };
  707. less.refreshStyles = loadStyles;
  708. return less;
  709. };
  710. },{"../less":37,"./browser":3,"./cache":4,"./error-reporting":5,"./file-manager":6,"./image-size":7,"./log-listener":9,"./plugin-loader":10,"./utils":11}],9:[function(require,module,exports){
  711. module.exports = function(less, options) {
  712. var logLevel_debug = 4,
  713. logLevel_info = 3,
  714. logLevel_warn = 2,
  715. logLevel_error = 1;
  716. // The amount of logging in the javascript console.
  717. // 3 - Debug, information and errors
  718. // 2 - Information and errors
  719. // 1 - Errors
  720. // 0 - None
  721. // Defaults to 2
  722. options.logLevel = typeof options.logLevel !== 'undefined' ? options.logLevel : (options.env === 'development' ? logLevel_info : logLevel_error);
  723. if (!options.loggers) {
  724. options.loggers = [{
  725. debug: function(msg) {
  726. if (options.logLevel >= logLevel_debug) {
  727. console.log(msg);
  728. }
  729. },
  730. info: function(msg) {
  731. if (options.logLevel >= logLevel_info) {
  732. console.log(msg);
  733. }
  734. },
  735. warn: function(msg) {
  736. if (options.logLevel >= logLevel_warn) {
  737. console.warn(msg);
  738. }
  739. },
  740. error: function(msg) {
  741. if (options.logLevel >= logLevel_error) {
  742. console.error(msg);
  743. }
  744. }
  745. }];
  746. }
  747. for (var i = 0; i < options.loggers.length; i++) {
  748. less.logger.addListener(options.loggers[i]);
  749. }
  750. };
  751. },{}],10:[function(require,module,exports){
  752. // TODO: Add tests for browser @plugin
  753. /* global window */
  754. var AbstractPluginLoader = require('../less/environment/abstract-plugin-loader.js');
  755. /**
  756. * Browser Plugin Loader
  757. */
  758. var PluginLoader = function(less) {
  759. this.less = less;
  760. // Should we shim this.require for browser? Probably not?
  761. };
  762. PluginLoader.prototype = new AbstractPluginLoader();
  763. PluginLoader.prototype.loadPlugin = function(filename, basePath, context, environment, fileManager) {
  764. return new Promise(function(fulfill, reject) {
  765. fileManager.loadFile(filename, basePath, context, environment)
  766. .then(fulfill).catch(reject);
  767. });
  768. };
  769. module.exports = PluginLoader;
  770. },{"../less/environment/abstract-plugin-loader.js":19}],11:[function(require,module,exports){
  771. module.exports = {
  772. extractId: function(href) {
  773. return href.replace(/^[a-z-]+:\/+?[^\/]+/, '') // Remove protocol & domain
  774. .replace(/[\?\&]livereload=\w+/, '') // Remove LiveReload cachebuster
  775. .replace(/^\//, '') // Remove root /
  776. .replace(/\.[a-zA-Z]+$/, '') // Remove simple extension
  777. .replace(/[^\.\w-]+/g, '-') // Replace illegal characters
  778. .replace(/\./g, ':'); // Replace dots with colons(for valid id)
  779. },
  780. addDataAttr: function(options, tag) {
  781. for (var opt in tag.dataset) {
  782. if (tag.dataset.hasOwnProperty(opt)) {
  783. if (opt === 'env' || opt === 'dumpLineNumbers' || opt === 'rootpath' || opt === 'errorReporting') {
  784. options[opt] = tag.dataset[opt];
  785. } else {
  786. try {
  787. options[opt] = JSON.parse(tag.dataset[opt]);
  788. }
  789. catch (_) {}
  790. }
  791. }
  792. }
  793. }
  794. };
  795. },{}],12:[function(require,module,exports){
  796. module.exports = {
  797. Math: {
  798. ALWAYS: 0,
  799. PARENS_DIVISION: 1,
  800. PARENS: 2,
  801. STRICT_LEGACY: 3
  802. },
  803. RewriteUrls: {
  804. OFF: 0,
  805. LOCAL: 1,
  806. ALL: 2
  807. }
  808. };
  809. },{}],13:[function(require,module,exports){
  810. var contexts = {};
  811. module.exports = contexts;
  812. var Constants = require('./constants');
  813. var copyFromOriginal = function copyFromOriginal(original, destination, propertiesToCopy) {
  814. if (!original) { return; }
  815. for (var i = 0; i < propertiesToCopy.length; i++) {
  816. if (original.hasOwnProperty(propertiesToCopy[i])) {
  817. destination[propertiesToCopy[i]] = original[propertiesToCopy[i]];
  818. }
  819. }
  820. };
  821. /*
  822. parse is used whilst parsing
  823. */
  824. var parseCopyProperties = [
  825. // options
  826. 'paths', // option - unmodified - paths to search for imports on
  827. 'rewriteUrls', // option - whether to adjust URL's to be relative
  828. 'rootpath', // option - rootpath to append to URL's
  829. 'strictImports', // option -
  830. 'insecure', // option - whether to allow imports from insecure ssl hosts
  831. 'dumpLineNumbers', // option - whether to dump line numbers
  832. 'compress', // option - whether to compress
  833. 'syncImport', // option - whether to import synchronously
  834. 'chunkInput', // option - whether to chunk input. more performant but causes parse issues.
  835. 'mime', // browser only - mime type for sheet import
  836. 'useFileCache', // browser only - whether to use the per file session cache
  837. // context
  838. 'processImports', // option & context - whether to process imports. if false then imports will not be imported.
  839. // Used by the import manager to stop multiple import visitors being created.
  840. 'pluginManager' // Used as the plugin manager for the session
  841. ];
  842. contexts.Parse = function(options) {
  843. copyFromOriginal(options, this, parseCopyProperties);
  844. if (typeof this.paths === 'string') { this.paths = [this.paths]; }
  845. };
  846. var evalCopyProperties = [
  847. 'paths', // additional include paths
  848. 'compress', // whether to compress
  849. 'ieCompat', // whether to enforce IE compatibility (IE8 data-uri)
  850. 'math', // whether math has to be within parenthesis
  851. 'strictUnits', // whether units need to evaluate correctly
  852. 'sourceMap', // whether to output a source map
  853. 'importMultiple', // whether we are currently importing multiple copies
  854. 'urlArgs', // whether to add args into url tokens
  855. 'javascriptEnabled', // option - whether Inline JavaScript is enabled. if undefined, defaults to false
  856. 'pluginManager', // Used as the plugin manager for the session
  857. 'importantScope', // used to bubble up !important statements
  858. 'rewriteUrls' // option - whether to adjust URL's to be relative
  859. ];
  860. contexts.Eval = function(options, frames) {
  861. copyFromOriginal(options, this, evalCopyProperties);
  862. if (typeof this.paths === 'string') { this.paths = [this.paths]; }
  863. this.frames = frames || [];
  864. this.importantScope = this.importantScope || [];
  865. };
  866. contexts.Eval.prototype.enterCalc = function () {
  867. if (!this.calcStack) {
  868. this.calcStack = [];
  869. }
  870. this.calcStack.push(true);
  871. this.inCalc = true;
  872. };
  873. contexts.Eval.prototype.exitCalc = function () {
  874. this.calcStack.pop();
  875. if (!this.calcStack) {
  876. this.inCalc = false;
  877. }
  878. };
  879. contexts.Eval.prototype.inParenthesis = function () {
  880. if (!this.parensStack) {
  881. this.parensStack = [];
  882. }
  883. this.parensStack.push(true);
  884. };
  885. contexts.Eval.prototype.outOfParenthesis = function () {
  886. this.parensStack.pop();
  887. };
  888. contexts.Eval.prototype.inCalc = false;
  889. contexts.Eval.prototype.mathOn = true;
  890. contexts.Eval.prototype.isMathOn = function (op) {
  891. if (!this.mathOn) {
  892. return false;
  893. }
  894. if (op === '/' && this.math !== Constants.Math.ALWAYS && (!this.parensStack || !this.parensStack.length)) {
  895. return false;
  896. }
  897. if (this.math > Constants.Math.PARENS_DIVISION) {
  898. return this.parensStack && this.parensStack.length;
  899. }
  900. return true;
  901. };
  902. contexts.Eval.prototype.pathRequiresRewrite = function (path) {
  903. var isRelative = this.rewriteUrls === Constants.RewriteUrls.LOCAL ? isPathLocalRelative : isPathRelative;
  904. return isRelative(path);
  905. };
  906. contexts.Eval.prototype.rewritePath = function (path, rootpath) {
  907. var newPath;
  908. rootpath = rootpath || '';
  909. newPath = this.normalizePath(rootpath + path);
  910. // If a path was explicit relative and the rootpath was not an absolute path
  911. // we must ensure that the new path is also explicit relative.
  912. if (isPathLocalRelative(path) &&
  913. isPathRelative(rootpath) &&
  914. isPathLocalRelative(newPath) === false) {
  915. newPath = './' + newPath;
  916. }
  917. return newPath;
  918. };
  919. contexts.Eval.prototype.normalizePath = function (path) {
  920. var
  921. segments = path.split('/').reverse(),
  922. segment;
  923. path = [];
  924. while (segments.length !== 0) {
  925. segment = segments.pop();
  926. switch ( segment ) {
  927. case '.':
  928. break;
  929. case '..':
  930. if ((path.length === 0) || (path[path.length - 1] === '..')) {
  931. path.push( segment );
  932. } else {
  933. path.pop();
  934. }
  935. break;
  936. default:
  937. path.push(segment);
  938. break;
  939. }
  940. }
  941. return path.join('/');
  942. };
  943. function isPathRelative(path) {
  944. return !/^(?:[a-z-]+:|\/|#)/i.test(path);
  945. }
  946. function isPathLocalRelative(path) {
  947. return path.charAt(0) === '.';
  948. }
  949. // todo - do the same for the toCSS ?
  950. },{"./constants":12}],14:[function(require,module,exports){
  951. module.exports = {
  952. 'aliceblue':'#f0f8ff',
  953. 'antiquewhite':'#faebd7',
  954. 'aqua':'#00ffff',
  955. 'aquamarine':'#7fffd4',
  956. 'azure':'#f0ffff',
  957. 'beige':'#f5f5dc',
  958. 'bisque':'#ffe4c4',
  959. 'black':'#000000',
  960. 'blanchedalmond':'#ffebcd',
  961. 'blue':'#0000ff',
  962. 'blueviolet':'#8a2be2',
  963. 'brown':'#a52a2a',
  964. 'burlywood':'#deb887',
  965. 'cadetblue':'#5f9ea0',
  966. 'chartreuse':'#7fff00',
  967. 'chocolate':'#d2691e',
  968. 'coral':'#ff7f50',
  969. 'cornflowerblue':'#6495ed',
  970. 'cornsilk':'#fff8dc',
  971. 'crimson':'#dc143c',
  972. 'cyan':'#00ffff',
  973. 'darkblue':'#00008b',
  974. 'darkcyan':'#008b8b',
  975. 'darkgoldenrod':'#b8860b',
  976. 'darkgray':'#a9a9a9',
  977. 'darkgrey':'#a9a9a9',
  978. 'darkgreen':'#006400',
  979. 'darkkhaki':'#bdb76b',
  980. 'darkmagenta':'#8b008b',
  981. 'darkolivegreen':'#556b2f',
  982. 'darkorange':'#ff8c00',
  983. 'darkorchid':'#9932cc',
  984. 'darkred':'#8b0000',
  985. 'darksalmon':'#e9967a',
  986. 'darkseagreen':'#8fbc8f',
  987. 'darkslateblue':'#483d8b',
  988. 'darkslategray':'#2f4f4f',
  989. 'darkslategrey':'#2f4f4f',
  990. 'darkturquoise':'#00ced1',
  991. 'darkviolet':'#9400d3',
  992. 'deeppink':'#ff1493',
  993. 'deepskyblue':'#00bfff',
  994. 'dimgray':'#696969',
  995. 'dimgrey':'#696969',
  996. 'dodgerblue':'#1e90ff',
  997. 'firebrick':'#b22222',
  998. 'floralwhite':'#fffaf0',
  999. 'forestgreen':'#228b22',
  1000. 'fuchsia':'#ff00ff',
  1001. 'gainsboro':'#dcdcdc',
  1002. 'ghostwhite':'#f8f8ff',
  1003. 'gold':'#ffd700',
  1004. 'goldenrod':'#daa520',
  1005. 'gray':'#808080',
  1006. 'grey':'#808080',
  1007. 'green':'#008000',
  1008. 'greenyellow':'#adff2f',
  1009. 'honeydew':'#f0fff0',
  1010. 'hotpink':'#ff69b4',
  1011. 'indianred':'#cd5c5c',
  1012. 'indigo':'#4b0082',
  1013. 'ivory':'#fffff0',
  1014. 'khaki':'#f0e68c',
  1015. 'lavender':'#e6e6fa',
  1016. 'lavenderblush':'#fff0f5',
  1017. 'lawngreen':'#7cfc00',
  1018. 'lemonchiffon':'#fffacd',
  1019. 'lightblue':'#add8e6',
  1020. 'lightcoral':'#f08080',
  1021. 'lightcyan':'#e0ffff',
  1022. 'lightgoldenrodyellow':'#fafad2',
  1023. 'lightgray':'#d3d3d3',
  1024. 'lightgrey':'#d3d3d3',
  1025. 'lightgreen':'#90ee90',
  1026. 'lightpink':'#ffb6c1',
  1027. 'lightsalmon':'#ffa07a',
  1028. 'lightseagreen':'#20b2aa',
  1029. 'lightskyblue':'#87cefa',
  1030. 'lightslategray':'#778899',
  1031. 'lightslategrey':'#778899',
  1032. 'lightsteelblue':'#b0c4de',
  1033. 'lightyellow':'#ffffe0',
  1034. 'lime':'#00ff00',
  1035. 'limegreen':'#32cd32',
  1036. 'linen':'#faf0e6',
  1037. 'magenta':'#ff00ff',
  1038. 'maroon':'#800000',
  1039. 'mediumaquamarine':'#66cdaa',
  1040. 'mediumblue':'#0000cd',
  1041. 'mediumorchid':'#ba55d3',
  1042. 'mediumpurple':'#9370d8',
  1043. 'mediumseagreen':'#3cb371',
  1044. 'mediumslateblue':'#7b68ee',
  1045. 'mediumspringgreen':'#00fa9a',
  1046. 'mediumturquoise':'#48d1cc',
  1047. 'mediumvioletred':'#c71585',
  1048. 'midnightblue':'#191970',
  1049. 'mintcream':'#f5fffa',
  1050. 'mistyrose':'#ffe4e1',
  1051. 'moccasin':'#ffe4b5',
  1052. 'navajowhite':'#ffdead',
  1053. 'navy':'#000080',
  1054. 'oldlace':'#fdf5e6',
  1055. 'olive':'#808000',
  1056. 'olivedrab':'#6b8e23',
  1057. 'orange':'#ffa500',
  1058. 'orangered':'#ff4500',
  1059. 'orchid':'#da70d6',
  1060. 'palegoldenrod':'#eee8aa',
  1061. 'palegreen':'#98fb98',
  1062. 'paleturquoise':'#afeeee',
  1063. 'palevioletred':'#d87093',
  1064. 'papayawhip':'#ffefd5',
  1065. 'peachpuff':'#ffdab9',
  1066. 'peru':'#cd853f',
  1067. 'pink':'#ffc0cb',
  1068. 'plum':'#dda0dd',
  1069. 'powderblue':'#b0e0e6',
  1070. 'purple':'#800080',
  1071. 'rebeccapurple':'#663399',
  1072. 'red':'#ff0000',
  1073. 'rosybrown':'#bc8f8f',
  1074. 'royalblue':'#4169e1',
  1075. 'saddlebrown':'#8b4513',
  1076. 'salmon':'#fa8072',
  1077. 'sandybrown':'#f4a460',
  1078. 'seagreen':'#2e8b57',
  1079. 'seashell':'#fff5ee',
  1080. 'sienna':'#a0522d',
  1081. 'silver':'#c0c0c0',
  1082. 'skyblue':'#87ceeb',
  1083. 'slateblue':'#6a5acd',
  1084. 'slategray':'#708090',
  1085. 'slategrey':'#708090',
  1086. 'snow':'#fffafa',
  1087. 'springgreen':'#00ff7f',
  1088. 'steelblue':'#4682b4',
  1089. 'tan':'#d2b48c',
  1090. 'teal':'#008080',
  1091. 'thistle':'#d8bfd8',
  1092. 'tomato':'#ff6347',
  1093. 'turquoise':'#40e0d0',
  1094. 'violet':'#ee82ee',
  1095. 'wheat':'#f5deb3',
  1096. 'white':'#ffffff',
  1097. 'whitesmoke':'#f5f5f5',
  1098. 'yellow':'#ffff00',
  1099. 'yellowgreen':'#9acd32'
  1100. };
  1101. },{}],15:[function(require,module,exports){
  1102. module.exports = {
  1103. colors: require('./colors'),
  1104. unitConversions: require('./unit-conversions')
  1105. };
  1106. },{"./colors":14,"./unit-conversions":16}],16:[function(require,module,exports){
  1107. module.exports = {
  1108. length: {
  1109. 'm': 1,
  1110. 'cm': 0.01,
  1111. 'mm': 0.001,
  1112. 'in': 0.0254,
  1113. 'px': 0.0254 / 96,
  1114. 'pt': 0.0254 / 72,
  1115. 'pc': 0.0254 / 72 * 12
  1116. },
  1117. duration: {
  1118. 's': 1,
  1119. 'ms': 0.001
  1120. },
  1121. angle: {
  1122. 'rad': 1 / (2 * Math.PI),
  1123. 'deg': 1 / 360,
  1124. 'grad': 1 / 400,
  1125. 'turn': 1
  1126. }
  1127. };
  1128. },{}],17:[function(require,module,exports){
  1129. // Export a new default each time
  1130. module.exports = function() {
  1131. return {
  1132. /* Inline Javascript - @plugin still allowed */
  1133. javascriptEnabled: false,
  1134. /* Outputs a makefile import dependency list to stdout. */
  1135. depends: false,
  1136. /* (DEPRECATED) Compress using less built-in compression.
  1137. * This does an okay job but does not utilise all the tricks of
  1138. * dedicated css compression. */
  1139. compress: false,
  1140. /* Runs the less parser and just reports errors without any output. */
  1141. lint: false,
  1142. /* Sets available include paths.
  1143. * If the file in an @import rule does not exist at that exact location,
  1144. * less will look for it at the location(s) passed to this option.
  1145. * You might use this for instance to specify a path to a library which
  1146. * you want to be referenced simply and relatively in the less files. */
  1147. paths: [],
  1148. /* color output in the terminal */
  1149. color: true,
  1150. /* The strictImports controls whether the compiler will allow an @import inside of either
  1151. * @media blocks or (a later addition) other selector blocks.
  1152. * See: https://github.com/less/less.js/issues/656 */
  1153. strictImports: false,
  1154. /* Allow Imports from Insecure HTTPS Hosts */
  1155. insecure: false,
  1156. /* Allows you to add a path to every generated import and url in your css.
  1157. * This does not affect less import statements that are processed, just ones
  1158. * that are left in the output css. */
  1159. rootpath: '',
  1160. /* By default URLs are kept as-is, so if you import a file in a sub-directory
  1161. * that references an image, exactly the same URL will be output in the css.
  1162. * This option allows you to re-write URL's in imported files so that the
  1163. * URL is always relative to the base imported file */
  1164. rewriteUrls: false,
  1165. /* Compatibility with IE8. Used for limiting data-uri length */
  1166. ieCompat: false, // true until 3.0
  1167. /* How to process math
  1168. * 0 always - eagerly try to solve all operations
  1169. * 1 parens-division - require parens for division "/"
  1170. * 2 parens | strict - require parens for all operations
  1171. * 3 strict-legacy - legacy strict behavior (super-strict)
  1172. */
  1173. math: 0,
  1174. /* Without this option, less attempts to guess at the output unit when it does maths. */
  1175. strictUnits: false,
  1176. /* Effectively the declaration is put at the top of your base Less file,
  1177. * meaning it can be used but it also can be overridden if this variable
  1178. * is defined in the file. */
  1179. globalVars: null,
  1180. /* As opposed to the global variable option, this puts the declaration at the
  1181. * end of your base file, meaning it will override anything defined in your Less file. */
  1182. modifyVars: null,
  1183. /* This option allows you to specify a argument to go on to every URL. */
  1184. urlArgs: ''
  1185. }
  1186. }
  1187. },{}],18:[function(require,module,exports){
  1188. var abstractFileManager = function() {
  1189. };
  1190. abstractFileManager.prototype.getPath = function (filename) {
  1191. var j = filename.lastIndexOf('?');
  1192. if (j > 0) {
  1193. filename = filename.slice(0, j);
  1194. }
  1195. j = filename.lastIndexOf('/');
  1196. if (j < 0) {
  1197. j = filename.lastIndexOf('\\');
  1198. }
  1199. if (j < 0) {
  1200. return '';
  1201. }
  1202. return filename.slice(0, j + 1);
  1203. };
  1204. abstractFileManager.prototype.tryAppendExtension = function(path, ext) {
  1205. return /(\.[a-z]*$)|([\?;].*)$/.test(path) ? path : path + ext;
  1206. };
  1207. abstractFileManager.prototype.tryAppendLessExtension = function(path) {
  1208. return this.tryAppendExtension(path, '.less');
  1209. };
  1210. abstractFileManager.prototype.supportsSync = function() {
  1211. return false;
  1212. };
  1213. abstractFileManager.prototype.alwaysMakePathsAbsolute = function() {
  1214. return false;
  1215. };
  1216. abstractFileManager.prototype.isPathAbsolute = function(filename) {
  1217. return (/^(?:[a-z-]+:|\/|\\|#)/i).test(filename);
  1218. };
  1219. // TODO: pull out / replace?
  1220. abstractFileManager.prototype.join = function(basePath, laterPath) {
  1221. if (!basePath) {
  1222. return laterPath;
  1223. }
  1224. return basePath + laterPath;
  1225. };
  1226. abstractFileManager.prototype.pathDiff = function pathDiff(url, baseUrl) {
  1227. // diff between two paths to create a relative path
  1228. var urlParts = this.extractUrlParts(url),
  1229. baseUrlParts = this.extractUrlParts(baseUrl),
  1230. i, max, urlDirectories, baseUrlDirectories, diff = '';
  1231. if (urlParts.hostPart !== baseUrlParts.hostPart) {
  1232. return '';
  1233. }
  1234. max = Math.max(baseUrlParts.directories.length, urlParts.directories.length);
  1235. for (i = 0; i < max; i++) {
  1236. if (baseUrlParts.directories[i] !== urlParts.directories[i]) { break; }
  1237. }
  1238. baseUrlDirectories = baseUrlParts.directories.slice(i);
  1239. urlDirectories = urlParts.directories.slice(i);
  1240. for (i = 0; i < baseUrlDirectories.length - 1; i++) {
  1241. diff += '../';
  1242. }
  1243. for (i = 0; i < urlDirectories.length - 1; i++) {
  1244. diff += urlDirectories[i] + '/';
  1245. }
  1246. return diff;
  1247. };
  1248. // helper function, not part of API
  1249. abstractFileManager.prototype.extractUrlParts = function extractUrlParts(url, baseUrl) {
  1250. // urlParts[1] = protocol://hostname/ OR /
  1251. // urlParts[2] = / if path relative to host base
  1252. // urlParts[3] = directories
  1253. // urlParts[4] = filename
  1254. // urlParts[5] = parameters
  1255. var urlPartsRegex = /^((?:[a-z-]+:)?\/{2}(?:[^\/\?#]*\/)|([\/\\]))?((?:[^\/\\\?#]*[\/\\])*)([^\/\\\?#]*)([#\?].*)?$/i,
  1256. urlParts = url.match(urlPartsRegex),
  1257. returner = {}, rawDirectories = [], directories = [], i, baseUrlParts;
  1258. if (!urlParts) {
  1259. throw new Error('Could not parse sheet href - \'' + url + '\'');
  1260. }
  1261. // Stylesheets in IE don't always return the full path
  1262. if (baseUrl && (!urlParts[1] || urlParts[2])) {
  1263. baseUrlParts = baseUrl.match(urlPartsRegex);
  1264. if (!baseUrlParts) {
  1265. throw new Error('Could not parse page url - \'' + baseUrl + '\'');
  1266. }
  1267. urlParts[1] = urlParts[1] || baseUrlParts[1] || '';
  1268. if (!urlParts[2]) {
  1269. urlParts[3] = baseUrlParts[3] + urlParts[3];
  1270. }
  1271. }
  1272. if (urlParts[3]) {
  1273. rawDirectories = urlParts[3].replace(/\\/g, '/').split('/');
  1274. // collapse '..' and skip '.'
  1275. for (i = 0; i < rawDirectories.length; i++) {
  1276. if (rawDirectories[i] === '..') {
  1277. directories.pop();
  1278. }
  1279. else if (rawDirectories[i] !== '.') {
  1280. directories.push(rawDirectories[i]);
  1281. }
  1282. }
  1283. }
  1284. returner.hostPart = urlParts[1];
  1285. returner.directories = directories;
  1286. returner.rawPath = (urlParts[1] || '') + rawDirectories.join('/');
  1287. returner.path = (urlParts[1] || '') + directories.join('/');
  1288. returner.filename = urlParts[4];
  1289. returner.fileUrl = returner.path + (urlParts[4] || '');
  1290. returner.url = returner.fileUrl + (urlParts[5] || '');
  1291. return returner;
  1292. };
  1293. module.exports = abstractFileManager;
  1294. },{}],19:[function(require,module,exports){
  1295. var functionRegistry = require('../functions/function-registry'),
  1296. LessError = require('../less-error');
  1297. var AbstractPluginLoader = function() {
  1298. // Implemented by Node.js plugin loader
  1299. this.require = function() {
  1300. return null;
  1301. }
  1302. };
  1303. AbstractPluginLoader.prototype.evalPlugin = function(contents, context, imports, pluginOptions, fileInfo) {
  1304. var loader,
  1305. registry,
  1306. pluginObj,
  1307. localModule,
  1308. pluginManager,
  1309. filename,
  1310. result;
  1311. pluginManager = context.pluginManager;
  1312. if (fileInfo) {
  1313. if (typeof fileInfo === 'string') {
  1314. filename = fileInfo;
  1315. }
  1316. else {
  1317. filename = fileInfo.filename;
  1318. }
  1319. }
  1320. var shortname = (new this.less.FileManager()).extractUrlParts(filename).filename;
  1321. if (filename) {
  1322. pluginObj = pluginManager.get(filename);
  1323. if (pluginObj) {
  1324. result = this.trySetOptions(pluginObj, filename, shortname, pluginOptions);
  1325. if (result) {
  1326. return result;
  1327. }
  1328. try {
  1329. if (pluginObj.use) {
  1330. pluginObj.use.call(this.context, pluginObj);
  1331. }
  1332. }
  1333. catch (e) {
  1334. e.message = e.message || 'Error during @plugin call';
  1335. return new LessError(e, imports, filename);
  1336. }
  1337. return pluginObj;
  1338. }
  1339. }
  1340. localModule = {
  1341. exports: {},
  1342. pluginManager: pluginManager,
  1343. fileInfo: fileInfo
  1344. };
  1345. registry = functionRegistry.create();
  1346. var registerPlugin = function(obj) {
  1347. pluginObj = obj;
  1348. };
  1349. try {
  1350. loader = new Function('module', 'require', 'registerPlugin', 'functions', 'tree', 'less', 'fileInfo', contents);
  1351. loader(localModule, this.require(filename), registerPlugin, registry, this.less.tree, this.less, fileInfo);
  1352. }
  1353. catch (e) {
  1354. return new LessError(e, imports, filename);
  1355. }
  1356. if (!pluginObj) {
  1357. pluginObj = localModule.exports;
  1358. }
  1359. pluginObj = this.validatePlugin(pluginObj, filename, shortname);
  1360. if (pluginObj instanceof LessError) {
  1361. return pluginObj;
  1362. }
  1363. if (pluginObj) {
  1364. pluginObj.imports = imports;
  1365. pluginObj.filename = filename;
  1366. // For < 3.x (or unspecified minVersion) - setOptions() before install()
  1367. if (!pluginObj.minVersion || this.compareVersion('3.0.0', pluginObj.minVersion) < 0) {
  1368. result = this.trySetOptions(pluginObj, filename, shortname, pluginOptions);
  1369. if (result) {
  1370. return result;
  1371. }
  1372. }
  1373. // Run on first load
  1374. pluginManager.addPlugin(pluginObj, fileInfo.filename, registry);
  1375. pluginObj.functions = registry.getLocalFunctions();
  1376. // Need to call setOptions again because the pluginObj might have functions
  1377. result = this.trySetOptions(pluginObj, filename, shortname, pluginOptions);
  1378. if (result) {
  1379. return result;
  1380. }
  1381. // Run every @plugin call
  1382. try {
  1383. if (pluginObj.use) {
  1384. pluginObj.use.call(this.context, pluginObj);
  1385. }
  1386. }
  1387. catch (e) {
  1388. e.message = e.message || 'Error during @plugin call';
  1389. return new LessError(e, imports, filename);
  1390. }
  1391. }
  1392. else {
  1393. return new LessError({ message: 'Not a valid plugin' }, imports, filename);
  1394. }
  1395. return pluginObj;
  1396. };
  1397. AbstractPluginLoader.prototype.trySetOptions = function(plugin, filename, name, options) {
  1398. if (options && !plugin.setOptions) {
  1399. return new LessError({
  1400. message: 'Options have been provided but the plugin ' +
  1401. name + ' does not support any options.'
  1402. });
  1403. }
  1404. try {
  1405. plugin.setOptions && plugin.setOptions(options);
  1406. }
  1407. catch (e) {
  1408. return new LessError(e);
  1409. }
  1410. };
  1411. AbstractPluginLoader.prototype.validatePlugin = function(plugin, filename, name) {
  1412. if (plugin) {
  1413. // support plugins being a function
  1414. // so that the plugin can be more usable programmatically
  1415. if (typeof plugin === 'function') {
  1416. plugin = new plugin();
  1417. }
  1418. if (plugin.minVersion) {
  1419. if (this.compareVersion(plugin.minVersion, this.less.version) < 0) {
  1420. return new LessError({
  1421. message: 'Plugin ' + name + ' requires version ' +
  1422. this.versionToString(plugin.minVersion)
  1423. });
  1424. }
  1425. }
  1426. return plugin;
  1427. }
  1428. return null;
  1429. };
  1430. AbstractPluginLoader.prototype.compareVersion = function(aVersion, bVersion) {
  1431. if (typeof aVersion === 'string') {
  1432. aVersion = aVersion.match(/^(\d+)\.?(\d+)?\.?(\d+)?/);
  1433. aVersion.shift();
  1434. }
  1435. for (var i = 0; i < aVersion.length; i++) {
  1436. if (aVersion[i] !== bVersion[i]) {
  1437. return parseInt(aVersion[i]) > parseInt(bVersion[i]) ? -1 : 1;
  1438. }
  1439. }
  1440. return 0;
  1441. };
  1442. AbstractPluginLoader.prototype.versionToString = function(version) {
  1443. var versionString = '';
  1444. for (var i = 0; i < version.length; i++) {
  1445. versionString += (versionString ? '.' : '') + version[i];
  1446. }
  1447. return versionString;
  1448. };
  1449. AbstractPluginLoader.prototype.printUsage = function(plugins) {
  1450. for (var i = 0; i < plugins.length; i++) {
  1451. var plugin = plugins[i];
  1452. if (plugin.printUsage) {
  1453. plugin.printUsage();
  1454. }
  1455. }
  1456. };
  1457. module.exports = AbstractPluginLoader;
  1458. },{"../functions/function-registry":27,"../less-error":38}],20:[function(require,module,exports){
  1459. /**
  1460. * @todo Document why this abstraction exists, and the relationship between
  1461. * environment, file managers, and plugin manager
  1462. */
  1463. var logger = require('../logger');
  1464. var environment = function(externalEnvironment, fileManagers) {
  1465. this.fileManagers = fileManagers || [];
  1466. externalEnvironment = externalEnvironment || {};
  1467. var optionalFunctions = ['encodeBase64', 'mimeLookup', 'charsetLookup', 'getSourceMapGenerator'],
  1468. requiredFunctions = [],
  1469. functions = requiredFunctions.concat(optionalFunctions);
  1470. for (var i = 0; i < functions.length; i++) {
  1471. var propName = functions[i],
  1472. environmentFunc = externalEnvironment[propName];
  1473. if (environmentFunc) {
  1474. this[propName] = environmentFunc.bind(externalEnvironment);
  1475. } else if (i < requiredFunctions.length) {
  1476. this.warn('missing required function in environment - ' + propName);
  1477. }
  1478. }
  1479. };
  1480. environment.prototype.getFileManager = function (filename, currentDirectory, options, environment, isSync) {
  1481. if (!filename) {
  1482. logger.warn('getFileManager called with no filename.. Please report this issue. continuing.');
  1483. }
  1484. if (currentDirectory == null) {
  1485. logger.warn('getFileManager called with null directory.. Please report this issue. continuing.');
  1486. }
  1487. var fileManagers = this.fileManagers;
  1488. if (options.pluginManager) {
  1489. fileManagers = [].concat(fileManagers).concat(options.pluginManager.getFileManagers());
  1490. }
  1491. for (var i = fileManagers.length - 1; i >= 0 ; i--) {
  1492. var fileManager = fileManagers[i];
  1493. if (fileManager[isSync ? 'supportsSync' : 'supports'](filename, currentDirectory, options, environment)) {
  1494. return fileManager;
  1495. }
  1496. }
  1497. return null;
  1498. };
  1499. environment.prototype.addFileManager = function (fileManager) {
  1500. this.fileManagers.push(fileManager);
  1501. };
  1502. environment.prototype.clearFileManagers = function () {
  1503. this.fileManagers = [];
  1504. };
  1505. module.exports = environment;
  1506. },{"../logger":39}],21:[function(require,module,exports){
  1507. var functionRegistry = require('./function-registry'),
  1508. Anonymous = require('../tree/anonymous'),
  1509. Keyword = require('../tree/keyword');
  1510. functionRegistry.addMultiple({
  1511. boolean: function(condition) {
  1512. return condition ? Keyword.True : Keyword.False;
  1513. },
  1514. 'if': function(condition, trueValue, falseValue) {
  1515. return condition ? trueValue
  1516. : (falseValue || new Anonymous);
  1517. }
  1518. });
  1519. },{"../tree/anonymous":50,"../tree/keyword":70,"./function-registry":27}],22:[function(require,module,exports){
  1520. var Color = require('../tree/color'),
  1521. functionRegistry = require('./function-registry');
  1522. // Color Blending
  1523. // ref: http://www.w3.org/TR/compositing-1
  1524. function colorBlend(mode, color1, color2) {
  1525. var ab = color1.alpha, cb, // backdrop
  1526. as = color2.alpha, cs, // source
  1527. ar, cr, r = []; // result
  1528. ar = as + ab * (1 - as);
  1529. for (var i = 0; i < 3; i++) {
  1530. cb = color1.rgb[i] / 255;
  1531. cs = color2.rgb[i] / 255;
  1532. cr = mode(cb, cs);
  1533. if (ar) {
  1534. cr = (as * cs + ab * (cb -
  1535. as * (cb + cs - cr))) / ar;
  1536. }
  1537. r[i] = cr * 255;
  1538. }
  1539. return new Color(r, ar);
  1540. }
  1541. var colorBlendModeFunctions = {
  1542. multiply: function(cb, cs) {
  1543. return cb * cs;
  1544. },
  1545. screen: function(cb, cs) {
  1546. return cb + cs - cb * cs;
  1547. },
  1548. overlay: function(cb, cs) {
  1549. cb *= 2;
  1550. return (cb <= 1) ?
  1551. colorBlendModeFunctions.multiply(cb, cs) :
  1552. colorBlendModeFunctions.screen(cb - 1, cs);
  1553. },
  1554. softlight: function(cb, cs) {
  1555. var d = 1, e = cb;
  1556. if (cs > 0.5) {
  1557. e = 1;
  1558. d = (cb > 0.25) ? Math.sqrt(cb)
  1559. : ((16 * cb - 12) * cb + 4) * cb;
  1560. }
  1561. return cb - (1 - 2 * cs) * e * (d - cb);
  1562. },
  1563. hardlight: function(cb, cs) {
  1564. return colorBlendModeFunctions.overlay(cs, cb);
  1565. },
  1566. difference: function(cb, cs) {
  1567. return Math.abs(cb - cs);
  1568. },
  1569. exclusion: function(cb, cs) {
  1570. return cb + cs - 2 * cb * cs;
  1571. },
  1572. // non-w3c functions:
  1573. average: function(cb, cs) {
  1574. return (cb + cs) / 2;
  1575. },
  1576. negation: function(cb, cs) {
  1577. return 1 - Math.abs(cb + cs - 1);
  1578. }
  1579. };
  1580. for (var f in colorBlendModeFunctions) {
  1581. if (colorBlendModeFunctions.hasOwnProperty(f)) {
  1582. colorBlend[f] = colorBlend.bind(null, colorBlendModeFunctions[f]);
  1583. }
  1584. }
  1585. functionRegistry.addMultiple(colorBlend);
  1586. },{"../tree/color":55,"./function-registry":27}],23:[function(require,module,exports){
  1587. var Dimension = require('../tree/dimension'),
  1588. Color = require('../tree/color'),
  1589. Quoted = require('../tree/quoted'),
  1590. Anonymous = require('../tree/anonymous'),
  1591. functionRegistry = require('./function-registry'),
  1592. colorFunctions;
  1593. function clamp(val) {
  1594. return Math.min(1, Math.max(0, val));
  1595. }
  1596. function hsla(color) {
  1597. return colorFunctions.hsla(color.h, color.s, color.l, color.a);
  1598. }
  1599. function number(n) {
  1600. if (n instanceof Dimension) {
  1601. return parseFloat(n.unit.is('%') ? n.value / 100 : n.value);
  1602. } else if (typeof n === 'number') {
  1603. return n;
  1604. } else {
  1605. throw {
  1606. type: 'Argument',
  1607. message: 'color functions take numbers as parameters'
  1608. };
  1609. }
  1610. }
  1611. function scaled(n, size) {
  1612. if (n instanceof Dimension && n.unit.is('%')) {
  1613. return parseFloat(n.value * size / 100);
  1614. } else {
  1615. return number(n);
  1616. }
  1617. }
  1618. colorFunctions = {
  1619. rgb: function (r, g, b) {
  1620. return colorFunctions.rgba(r, g, b, 1.0);
  1621. },
  1622. rgba: function (r, g, b, a) {
  1623. var rgb = [r, g, b].map(function (c) { return scaled(c, 255); });
  1624. a = number(a);
  1625. return new Color(rgb, a);
  1626. },
  1627. hsl: function (h, s, l) {
  1628. return colorFunctions.hsla(h, s, l, 1.0);
  1629. },
  1630. hsla: function (h, s, l, a) {
  1631. var m1, m2;
  1632. function hue(h) {
  1633. h = h < 0 ? h + 1 : (h > 1 ? h - 1 : h);
  1634. if (h * 6 < 1) {
  1635. return m1 + (m2 - m1) * h * 6;
  1636. }
  1637. else if (h * 2 < 1) {
  1638. return m2;
  1639. }
  1640. else if (h * 3 < 2) {
  1641. return m1 + (m2 - m1) * (2 / 3 - h) * 6;
  1642. }
  1643. else {
  1644. return m1;
  1645. }
  1646. }
  1647. h = (number(h) % 360) / 360;
  1648. s = clamp(number(s)); l = clamp(number(l)); a = clamp(number(a));
  1649. m2 = l <= 0.5 ? l * (s + 1) : l + s - l * s;
  1650. m1 = l * 2 - m2;
  1651. return colorFunctions.rgba(hue(h + 1 / 3) * 255,
  1652. hue(h) * 255,
  1653. hue(h - 1 / 3) * 255,
  1654. a);
  1655. },
  1656. hsv: function(h, s, v) {
  1657. return colorFunctions.hsva(h, s, v, 1.0);
  1658. },
  1659. hsva: function(h, s, v, a) {
  1660. h = ((number(h) % 360) / 360) * 360;
  1661. s = number(s); v = number(v); a = number(a);
  1662. var i, f;
  1663. i = Math.floor((h / 60) % 6);
  1664. f = (h / 60) - i;
  1665. var vs = [v,
  1666. v * (1 - s),
  1667. v * (1 - f * s),
  1668. v * (1 - (1 - f) * s)];
  1669. var perm = [[0, 3, 1],
  1670. [2, 0, 1],
  1671. [1, 0, 3],
  1672. [1, 2, 0],
  1673. [3, 1, 0],
  1674. [0, 1, 2]];
  1675. return colorFunctions.rgba(vs[perm[i][0]] * 255,
  1676. vs[perm[i][1]] * 255,
  1677. vs[perm[i][2]] * 255,
  1678. a);
  1679. },
  1680. hue: function (color) {
  1681. return new Dimension(color.toHSL().h);
  1682. },
  1683. saturation: function (color) {
  1684. return new Dimension(color.toHSL().s * 100, '%');
  1685. },
  1686. lightness: function (color) {
  1687. return new Dimension(color.toHSL().l * 100, '%');
  1688. },
  1689. hsvhue: function(color) {
  1690. return new Dimension(color.toHSV().h);
  1691. },
  1692. hsvsaturation: function (color) {
  1693. return new Dimension(color.toHSV().s * 100, '%');
  1694. },
  1695. hsvvalue: function (color) {
  1696. return new Dimension(color.toHSV().v * 100, '%');
  1697. },
  1698. red: function (color) {
  1699. return new Dimension(color.rgb[0]);
  1700. },
  1701. green: function (color) {
  1702. return new Dimension(color.rgb[1]);
  1703. },
  1704. blue: function (color) {
  1705. return new Dimension(color.rgb[2]);
  1706. },
  1707. alpha: function (color) {
  1708. return new Dimension(color.toHSL().a);
  1709. },
  1710. luma: function (color) {
  1711. return new Dimension(color.luma() * color.alpha * 100, '%');
  1712. },
  1713. luminance: function (color) {
  1714. var luminance =
  1715. (0.2126 * color.rgb[0] / 255) +
  1716. (0.7152 * color.rgb[1] / 255) +
  1717. (0.0722 * color.rgb[2] / 255);
  1718. return new Dimension(luminance * color.alpha * 100, '%');
  1719. },
  1720. saturate: function (color, amount, method) {
  1721. // filter: saturate(3.2);
  1722. // should be kept as is, so check for color
  1723. if (!color.rgb) {
  1724. return null;
  1725. }
  1726. var hsl = color.toHSL();
  1727. if (typeof method !== 'undefined' && method.value === 'relative') {
  1728. hsl.s += hsl.s * amount.value / 100;
  1729. }
  1730. else {
  1731. hsl.s += amount.value / 100;
  1732. }
  1733. hsl.s = clamp(hsl.s);
  1734. return hsla(hsl);
  1735. },
  1736. desaturate: function (color, amount, method) {
  1737. var hsl = color.toHSL();
  1738. if (typeof method !== 'undefined' && method.value === 'relative') {
  1739. hsl.s -= hsl.s * amount.value / 100;
  1740. }
  1741. else {
  1742. hsl.s -= amount.value / 100;
  1743. }
  1744. hsl.s = clamp(hsl.s);
  1745. return hsla(hsl);
  1746. },
  1747. lighten: function (color, amount, method) {
  1748. var hsl = color.toHSL();
  1749. if (typeof method !== 'undefined' && method.value === 'relative') {
  1750. hsl.l += hsl.l * amount.value / 100;
  1751. }
  1752. else {
  1753. hsl.l += amount.value / 100;
  1754. }
  1755. hsl.l = clamp(hsl.l);
  1756. return hsla(hsl);
  1757. },
  1758. darken: function (color, amount, method) {
  1759. var hsl = color.toHSL();
  1760. if (typeof method !== 'undefined' && method.value === 'relative') {
  1761. hsl.l -= hsl.l * amount.value / 100;
  1762. }
  1763. else {
  1764. hsl.l -= amount.value / 100;
  1765. }
  1766. hsl.l = clamp(hsl.l);
  1767. return hsla(hsl);
  1768. },
  1769. fadein: function (color, amount, method) {
  1770. var hsl = color.toHSL();
  1771. if (typeof method !== 'undefined' && method.value === 'relative') {
  1772. hsl.a += hsl.a * amount.value / 100;
  1773. }
  1774. else {
  1775. hsl.a += amount.value / 100;
  1776. }
  1777. hsl.a = clamp(hsl.a);
  1778. return hsla(hsl);
  1779. },
  1780. fadeout: function (color, amount, method) {
  1781. var hsl = color.toHSL();
  1782. if (typeof method !== 'undefined' && method.value === 'relative') {
  1783. hsl.a -= hsl.a * amount.value / 100;
  1784. }
  1785. else {
  1786. hsl.a -= amount.value / 100;
  1787. }
  1788. hsl.a = clamp(hsl.a);
  1789. return hsla(hsl);
  1790. },
  1791. fade: function (color, amount) {
  1792. var hsl = color.toHSL();
  1793. hsl.a = amount.value / 100;
  1794. hsl.a = clamp(hsl.a);
  1795. return hsla(hsl);
  1796. },
  1797. spin: function (color, amount) {
  1798. var hsl = color.toHSL();
  1799. var hue = (hsl.h + amount.value) % 360;
  1800. hsl.h = hue < 0 ? 360 + hue : hue;
  1801. return hsla(hsl);
  1802. },
  1803. //
  1804. // Copyright (c) 2006-2009 Hampton Catlin, Natalie Weizenbaum, and Chris Eppstein
  1805. // http://sass-lang.com
  1806. //
  1807. mix: function (color1, color2, weight) {
  1808. if (!color1.toHSL || !color2.toHSL) {
  1809. console.log(color2.type);
  1810. console.dir(color2);
  1811. }
  1812. if (!weight) {
  1813. weight = new Dimension(50);
  1814. }
  1815. var p = weight.value / 100.0;
  1816. var w = p * 2 - 1;
  1817. var a = color1.toHSL().a - color2.toHSL().a;
  1818. var w1 = (((w * a == -1) ? w : (w + a) / (1 + w * a)) + 1) / 2.0;
  1819. var w2 = 1 - w1;
  1820. var rgb = [color1.rgb[0] * w1 + color2.rgb[0] * w2,
  1821. color1.rgb[1] * w1 + color2.rgb[1] * w2,
  1822. color1.rgb[2] * w1 + color2.rgb[2] * w2];
  1823. var alpha = color1.alpha * p + color2.alpha * (1 - p);
  1824. return new Color(rgb, alpha);
  1825. },
  1826. greyscale: function (color) {
  1827. return colorFunctions.desaturate(color, new Dimension(100));
  1828. },
  1829. contrast: function (color, dark, light, threshold) {
  1830. // filter: contrast(3.2);
  1831. // should be kept as is, so check for color
  1832. if (!color.rgb) {
  1833. return null;
  1834. }
  1835. if (typeof light === 'undefined') {
  1836. light = colorFunctions.rgba(255, 255, 255, 1.0);
  1837. }
  1838. if (typeof dark === 'undefined') {
  1839. dark = colorFunctions.rgba(0, 0, 0, 1.0);
  1840. }
  1841. // Figure out which is actually light and dark:
  1842. if (dark.luma() > light.luma()) {
  1843. var t = light;
  1844. light = dark;
  1845. dark = t;
  1846. }
  1847. if (typeof threshold === 'undefined') {
  1848. threshold = 0.43;
  1849. } else {
  1850. threshold = number(threshold);
  1851. }
  1852. if (color.luma() < threshold) {
  1853. return light;
  1854. } else {
  1855. return dark;
  1856. }
  1857. },
  1858. // Changes made in 2.7.0 - Reverted in 3.0.0
  1859. // contrast: function (color, color1, color2, threshold) {
  1860. // // Return which of `color1` and `color2` has the greatest contrast with `color`
  1861. // // according to the standard WCAG contrast ratio calculation.
  1862. // // http://www.w3.org/TR/WCAG20/#contrast-ratiodef
  1863. // // The threshold param is no longer used, in line with SASS.
  1864. // // filter: contrast(3.2);
  1865. // // should be kept as is, so check for color
  1866. // if (!color.rgb) {
  1867. // return null;
  1868. // }
  1869. // if (typeof color1 === 'undefined') {
  1870. // color1 = colorFunctions.rgba(0, 0, 0, 1.0);
  1871. // }
  1872. // if (typeof color2 === 'undefined') {
  1873. // color2 = colorFunctions.rgba(255, 255, 255, 1.0);
  1874. // }
  1875. // var contrast1, contrast2;
  1876. // var luma = color.luma();
  1877. // var luma1 = color1.luma();
  1878. // var luma2 = color2.luma();
  1879. // // Calculate contrast ratios for each color
  1880. // if (luma > luma1) {
  1881. // contrast1 = (luma + 0.05) / (luma1 + 0.05);
  1882. // } else {
  1883. // contrast1 = (luma1 + 0.05) / (luma + 0.05);
  1884. // }
  1885. // if (luma > luma2) {
  1886. // contrast2 = (luma + 0.05) / (luma2 + 0.05);
  1887. // } else {
  1888. // contrast2 = (luma2 + 0.05) / (luma + 0.05);
  1889. // }
  1890. // if (contrast1 > contrast2) {
  1891. // return color1;
  1892. // } else {
  1893. // return color2;
  1894. // }
  1895. // },
  1896. argb: function (color) {
  1897. return new Anonymous(color.toARGB());
  1898. },
  1899. color: function(c) {
  1900. if ((c instanceof Quoted) &&
  1901. (/^#([a-f0-9]{6}|[a-f0-9]{3})$/i.test(c.value))) {
  1902. return new Color(c.value.slice(1));
  1903. }
  1904. if ((c instanceof Color) || (c = Color.fromKeyword(c.value))) {
  1905. c.value = undefined;
  1906. return c;
  1907. }
  1908. throw {
  1909. type: 'Argument',
  1910. message: 'argument must be a color keyword or 3/6 digit hex e.g. #FFF'
  1911. };
  1912. },
  1913. tint: function(color, amount) {
  1914. return colorFunctions.mix(colorFunctions.rgb(255, 255, 255), color, amount);
  1915. },
  1916. shade: function(color, amount) {
  1917. return colorFunctions.mix(colorFunctions.rgb(0, 0, 0), color, amount);
  1918. }
  1919. };
  1920. functionRegistry.addMultiple(colorFunctions);
  1921. },{"../tree/anonymous":50,"../tree/color":55,"../tree/dimension":62,"../tree/quoted":80,"./function-registry":27}],24:[function(require,module,exports){
  1922. module.exports = function(environment) {
  1923. var Quoted = require('../tree/quoted'),
  1924. URL = require('../tree/url'),
  1925. utils = require('../utils'),
  1926. functionRegistry = require('./function-registry'),
  1927. fallback = function(functionThis, node) {
  1928. return new URL(node, functionThis.index, functionThis.currentFileInfo).eval(functionThis.context);
  1929. },
  1930. logger = require('../logger');
  1931. functionRegistry.add('data-uri', function(mimetypeNode, filePathNode) {
  1932. if (!filePathNode) {
  1933. filePathNode = mimetypeNode;
  1934. mimetypeNode = null;
  1935. }
  1936. var mimetype = mimetypeNode && mimetypeNode.value;
  1937. var filePath = filePathNode.value;
  1938. var currentFileInfo = this.currentFileInfo;
  1939. var currentDirectory = currentFileInfo.rewriteUrls ?
  1940. currentFileInfo.currentDirectory : currentFileInfo.entryPath;
  1941. var fragmentStart = filePath.indexOf('#');
  1942. var fragment = '';
  1943. if (fragmentStart !== -1) {
  1944. fragment = filePath.slice(fragmentStart);
  1945. filePath = filePath.slice(0, fragmentStart);
  1946. }
  1947. var context = utils.clone(this.context);
  1948. context.rawBuffer = true;
  1949. var fileManager = environment.getFileManager(filePath, currentDirectory, context, environment, true);
  1950. if (!fileManager) {
  1951. return fallback(this, filePathNode);
  1952. }
  1953. var useBase64 = false;
  1954. // detect the mimetype if not given
  1955. if (!mimetypeNode) {
  1956. mimetype = environment.mimeLookup(filePath);
  1957. if (mimetype === 'image/svg+xml') {
  1958. useBase64 = false;
  1959. } else {
  1960. // use base 64 unless it's an ASCII or UTF-8 format
  1961. var charset = environment.charsetLookup(mimetype);
  1962. useBase64 = ['US-ASCII', 'UTF-8'].indexOf(charset) < 0;
  1963. }
  1964. if (useBase64) { mimetype += ';base64'; }
  1965. }
  1966. else {
  1967. useBase64 = /;base64$/.test(mimetype);
  1968. }
  1969. var fileSync = fileManager.loadFileSync(filePath, currentDirectory, context, environment);
  1970. if (!fileSync.contents) {
  1971. logger.warn('Skipped data-uri embedding of ' + filePath + ' because file not found');
  1972. return fallback(this, filePathNode || mimetypeNode);
  1973. }
  1974. var buf = fileSync.contents;
  1975. if (useBase64 && !environment.encodeBase64) {
  1976. return fallback(this, filePathNode);
  1977. }
  1978. buf = useBase64 ? environment.encodeBase64(buf) : encodeURIComponent(buf);
  1979. var uri = 'data:' + mimetype + ',' + buf + fragment;
  1980. // IE8 cannot handle a data-uri larger than 32,768 characters. If this is exceeded
  1981. // and the --ieCompat flag is enabled, return a normal url() instead.
  1982. var DATA_URI_MAX = 32768;
  1983. if (uri.length >= DATA_URI_MAX) {
  1984. if (this.context.ieCompat !== false) {
  1985. logger.warn('Skipped data-uri embedding of ' + filePath + ' because its size (' + uri.length +
  1986. ' characters) exceeds IE8-safe ' + DATA_URI_MAX + ' characters!');
  1987. return fallback(this, filePathNode || mimetypeNode);
  1988. }
  1989. }
  1990. return new URL(new Quoted('"' + uri + '"', uri, false, this.index, this.currentFileInfo), this.index, this.currentFileInfo);
  1991. });
  1992. };
  1993. },{"../logger":39,"../tree/quoted":80,"../tree/url":85,"../utils":89,"./function-registry":27}],25:[function(require,module,exports){
  1994. var Keyword = require('../tree/keyword'),
  1995. functionRegistry = require('./function-registry');
  1996. var defaultFunc = {
  1997. eval: function () {
  1998. var v = this.value_, e = this.error_;
  1999. if (e) {
  2000. throw e;
  2001. }
  2002. if (v != null) {
  2003. return v ? Keyword.True : Keyword.False;
  2004. }
  2005. },
  2006. value: function (v) {
  2007. this.value_ = v;
  2008. },
  2009. error: function (e) {
  2010. this.error_ = e;
  2011. },
  2012. reset: function () {
  2013. this.value_ = this.error_ = null;
  2014. }
  2015. };
  2016. functionRegistry.add('default', defaultFunc.eval.bind(defaultFunc));
  2017. module.exports = defaultFunc;
  2018. },{"../tree/keyword":70,"./function-registry":27}],26:[function(require,module,exports){
  2019. var Expression = require('../tree/expression');
  2020. var functionCaller = function(name, context, index, currentFileInfo) {
  2021. this.name = name.toLowerCase();
  2022. this.index = index;
  2023. this.context = context;
  2024. this.currentFileInfo = currentFileInfo;
  2025. this.func = context.frames[0].functionRegistry.get(this.name);
  2026. };
  2027. functionCaller.prototype.isValid = function() {
  2028. return Boolean(this.func);
  2029. };
  2030. functionCaller.prototype.call = function(args) {
  2031. // This code is terrible and should be replaced as per this issue...
  2032. // https://github.com/less/less.js/issues/2477
  2033. if (Array.isArray(args)) {
  2034. args = args.filter(function (item) {
  2035. if (item.type === 'Comment') {
  2036. return false;
  2037. }
  2038. return true;
  2039. })
  2040. .map(function(item) {
  2041. if (item.type === 'Expression') {
  2042. var subNodes = item.value.filter(function (item) {
  2043. if (item.type === 'Comment') {
  2044. return false;
  2045. }
  2046. return true;
  2047. });
  2048. if (subNodes.length === 1) {
  2049. return subNodes[0];
  2050. } else {
  2051. return new Expression(subNodes);
  2052. }
  2053. }
  2054. return item;
  2055. });
  2056. }
  2057. return this.func.apply(this, args);
  2058. };
  2059. module.exports = functionCaller;
  2060. },{"../tree/expression":64}],27:[function(require,module,exports){
  2061. function makeRegistry( base ) {
  2062. return {
  2063. _data: {},
  2064. add: function(name, func) {
  2065. // precautionary case conversion, as later querying of
  2066. // the registry by function-caller uses lower case as well.
  2067. name = name.toLowerCase();
  2068. if (this._data.hasOwnProperty(name)) {
  2069. // TODO warn
  2070. }
  2071. this._data[name] = func;
  2072. },
  2073. addMultiple: function(functions) {
  2074. Object.keys(functions).forEach(
  2075. function(name) {
  2076. this.add(name, functions[name]);
  2077. }.bind(this));
  2078. },
  2079. get: function(name) {
  2080. return this._data[name] || ( base && base.get( name ));
  2081. },
  2082. getLocalFunctions: function() {
  2083. return this._data;
  2084. },
  2085. inherit: function() {
  2086. return makeRegistry( this );
  2087. },
  2088. create: function(base) {
  2089. return makeRegistry(base);
  2090. }
  2091. };
  2092. }
  2093. module.exports = makeRegistry( null );
  2094. },{}],28:[function(require,module,exports){
  2095. module.exports = function(environment) {
  2096. var functions = {
  2097. functionRegistry: require('./function-registry'),
  2098. functionCaller: require('./function-caller')
  2099. };
  2100. // register functions
  2101. require('./boolean');
  2102. require('./default');
  2103. require('./color');
  2104. require('./color-blending');
  2105. require('./data-uri')(environment);
  2106. require('./list');
  2107. require('./math');
  2108. require('./number');
  2109. require('./string');
  2110. require('./svg')(environment);
  2111. require('./types');
  2112. return functions;
  2113. };
  2114. },{"./boolean":21,"./color":23,"./color-blending":22,"./data-uri":24,"./default":25,"./function-caller":26,"./function-registry":27,"./list":29,"./math":31,"./number":32,"./string":33,"./svg":34,"./types":35}],29:[function(require,module,exports){
  2115. var Dimension = require('../tree/dimension'),
  2116. Declaration = require('../tree/declaration'),
  2117. Ruleset = require('../tree/ruleset'),
  2118. Selector = require('../tree/selector'),
  2119. Element = require('../tree/element'),
  2120. functionRegistry = require('./function-registry');
  2121. var getItemsFromNode = function(node) {
  2122. // handle non-array values as an array of length 1
  2123. // return 'undefined' if index is invalid
  2124. var items = Array.isArray(node.value) ?
  2125. node.value : Array(node);
  2126. return items;
  2127. };
  2128. functionRegistry.addMultiple({
  2129. _SELF: function(n) {
  2130. return n;
  2131. },
  2132. extract: function(values, index) {
  2133. index = index.value - 1; // (1-based index)
  2134. return getItemsFromNode(values)[index];
  2135. },
  2136. length: function(values) {
  2137. return new Dimension(getItemsFromNode(values).length);
  2138. },
  2139. each: function(list, rs) {
  2140. var i = 0, rules = [], newRules, iterator;
  2141. if (list.value) {
  2142. if (Array.isArray(list.value)) {
  2143. iterator = list.value;
  2144. } else {
  2145. iterator = [list.value];
  2146. }
  2147. } else if (list.ruleset) {
  2148. iterator = list.ruleset.rules;
  2149. } else if (Array.isArray(list)) {
  2150. iterator = list;
  2151. } else {
  2152. iterator = [list];
  2153. }
  2154. var valueName = '@value',
  2155. keyName = '@key',
  2156. indexName = '@index';
  2157. if (rs.params) {
  2158. valueName = rs.params[0] && rs.params[0].name;
  2159. keyName = rs.params[1] && rs.params[1].name;
  2160. indexName = rs.params[2] && rs.params[2].name;
  2161. rs = rs.rules;
  2162. } else {
  2163. rs = rs.ruleset;
  2164. }
  2165. iterator.forEach(function(item) {
  2166. i = i + 1;
  2167. var key, value;
  2168. if (item instanceof Declaration) {
  2169. key = typeof item.name === 'string' ? item.name : item.name[0].value;
  2170. value = item.value;
  2171. } else {
  2172. key = new Dimension(i);
  2173. value = item;
  2174. }
  2175. newRules = rs.rules.slice(0);
  2176. if (valueName) {
  2177. newRules.push(new Declaration(valueName,
  2178. value,
  2179. false, false, this.index, this.currentFileInfo));
  2180. }
  2181. if (indexName) {
  2182. newRules.push(new Declaration(indexName,
  2183. new Dimension(i),
  2184. false, false, this.index, this.currentFileInfo));
  2185. }
  2186. if (keyName) {
  2187. newRules.push(new Declaration(keyName,
  2188. key,
  2189. false, false, this.index, this.currentFileInfo));
  2190. }
  2191. rules.push(new Ruleset([ new(Selector)([ new Element("", '&') ]) ],
  2192. newRules,
  2193. rs.strictImports,
  2194. rs.visibilityInfo()
  2195. ));
  2196. });
  2197. return new Ruleset([ new(Selector)([ new Element("", '&') ]) ],
  2198. rules,
  2199. rs.strictImports,
  2200. rs.visibilityInfo()
  2201. ).eval(this.context);
  2202. }
  2203. });
  2204. },{"../tree/declaration":60,"../tree/dimension":62,"../tree/element":63,"../tree/ruleset":81,"../tree/selector":82,"./function-registry":27}],30:[function(require,module,exports){
  2205. var Dimension = require('../tree/dimension');
  2206. var MathHelper = function() {
  2207. };
  2208. MathHelper._math = function (fn, unit, n) {
  2209. if (!(n instanceof Dimension)) {
  2210. throw { type: 'Argument', message: 'argument must be a number' };
  2211. }
  2212. if (unit == null) {
  2213. unit = n.unit;
  2214. } else {
  2215. n = n.unify();
  2216. }
  2217. return new Dimension(fn(parseFloat(n.value)), unit);
  2218. };
  2219. module.exports = MathHelper;
  2220. },{"../tree/dimension":62}],31:[function(require,module,exports){
  2221. var functionRegistry = require('./function-registry'),
  2222. mathHelper = require('./math-helper.js');
  2223. var mathFunctions = {
  2224. // name, unit
  2225. ceil: null,
  2226. floor: null,
  2227. sqrt: null,
  2228. abs: null,
  2229. tan: '',
  2230. sin: '',
  2231. cos: '',
  2232. atan: 'rad',
  2233. asin: 'rad',
  2234. acos: 'rad'
  2235. };
  2236. for (var f in mathFunctions) {
  2237. if (mathFunctions.hasOwnProperty(f)) {
  2238. mathFunctions[f] = mathHelper._math.bind(null, Math[f], mathFunctions[f]);
  2239. }
  2240. }
  2241. mathFunctions.round = function (n, f) {
  2242. var fraction = typeof f === 'undefined' ? 0 : f.value;
  2243. return mathHelper._math(function(num) { return num.toFixed(fraction); }, null, n);
  2244. };
  2245. functionRegistry.addMultiple(mathFunctions);
  2246. },{"./function-registry":27,"./math-helper.js":30}],32:[function(require,module,exports){
  2247. var Dimension = require('../tree/dimension'),
  2248. Anonymous = require('../tree/anonymous'),
  2249. functionRegistry = require('./function-registry'),
  2250. mathHelper = require('./math-helper.js');
  2251. var minMax = function (isMin, args) {
  2252. args = Array.prototype.slice.call(args);
  2253. switch (args.length) {
  2254. case 0: throw { type: 'Argument', message: 'one or more arguments required' };
  2255. }
  2256. var i, j, current, currentUnified, referenceUnified, unit, unitStatic, unitClone,
  2257. order = [], // elems only contains original argument values.
  2258. values = {}; // key is the unit.toString() for unified Dimension values,
  2259. // value is the index into the order array.
  2260. for (i = 0; i < args.length; i++) {
  2261. current = args[i];
  2262. if (!(current instanceof Dimension)) {
  2263. if (Array.isArray(args[i].value)) {
  2264. Array.prototype.push.apply(args, Array.prototype.slice.call(args[i].value));
  2265. }
  2266. continue;
  2267. }
  2268. currentUnified = current.unit.toString() === '' && unitClone !== undefined ? new Dimension(current.value, unitClone).unify() : current.unify();
  2269. unit = currentUnified.unit.toString() === '' && unitStatic !== undefined ? unitStatic : currentUnified.unit.toString();
  2270. unitStatic = unit !== '' && unitStatic === undefined || unit !== '' && order[0].unify().unit.toString() === '' ? unit : unitStatic;
  2271. unitClone = unit !== '' && unitClone === undefined ? current.unit.toString() : unitClone;
  2272. j = values[''] !== undefined && unit !== '' && unit === unitStatic ? values[''] : values[unit];
  2273. if (j === undefined) {
  2274. if (unitStatic !== undefined && unit !== unitStatic) {
  2275. throw { type: 'Argument', message: 'incompatible types' };
  2276. }
  2277. values[unit] = order.length;
  2278. order.push(current);
  2279. continue;
  2280. }
  2281. referenceUnified = order[j].unit.toString() === '' && unitClone !== undefined ? new Dimension(order[j].value, unitClone).unify() : order[j].unify();
  2282. if ( isMin && currentUnified.value < referenceUnified.value ||
  2283. !isMin && currentUnified.value > referenceUnified.value) {
  2284. order[j] = current;
  2285. }
  2286. }
  2287. if (order.length == 1) {
  2288. return order[0];
  2289. }
  2290. args = order.map(function (a) { return a.toCSS(this.context); }).join(this.context.compress ? ',' : ', ');
  2291. return new Anonymous((isMin ? 'min' : 'max') + '(' + args + ')');
  2292. };
  2293. functionRegistry.addMultiple({
  2294. min: function () {
  2295. return minMax(true, arguments);
  2296. },
  2297. max: function () {
  2298. return minMax(false, arguments);
  2299. },
  2300. convert: function (val, unit) {
  2301. return val.convertTo(unit.value);
  2302. },
  2303. pi: function () {
  2304. return new Dimension(Math.PI);
  2305. },
  2306. mod: function(a, b) {
  2307. return new Dimension(a.value % b.value, a.unit);
  2308. },
  2309. pow: function(x, y) {
  2310. if (typeof x === 'number' && typeof y === 'number') {
  2311. x = new Dimension(x);
  2312. y = new Dimension(y);
  2313. } else if (!(x instanceof Dimension) || !(y instanceof Dimension)) {
  2314. throw { type: 'Argument', message: 'arguments must be numbers' };
  2315. }
  2316. return new Dimension(Math.pow(x.value, y.value), x.unit);
  2317. },
  2318. percentage: function (n) {
  2319. var result = mathHelper._math(function(num) {
  2320. return num * 100;
  2321. }, '%', n);
  2322. return result;
  2323. }
  2324. });
  2325. },{"../tree/anonymous":50,"../tree/dimension":62,"./function-registry":27,"./math-helper.js":30}],33:[function(require,module,exports){
  2326. var Quoted = require('../tree/quoted'),
  2327. Anonymous = require('../tree/anonymous'),
  2328. JavaScript = require('../tree/javascript'),
  2329. functionRegistry = require('./function-registry');
  2330. functionRegistry.addMultiple({
  2331. e: function (str) {
  2332. return new Anonymous(str instanceof JavaScript ? str.evaluated : str.value);
  2333. },
  2334. escape: function (str) {
  2335. return new Anonymous(
  2336. encodeURI(str.value).replace(/=/g, '%3D').replace(/:/g, '%3A').replace(/#/g, '%23').replace(/;/g, '%3B')
  2337. .replace(/\(/g, '%28').replace(/\)/g, '%29'));
  2338. },
  2339. replace: function (string, pattern, replacement, flags) {
  2340. var result = string.value;
  2341. replacement = (replacement.type === 'Quoted') ?
  2342. replacement.value : replacement.toCSS();
  2343. result = result.replace(new RegExp(pattern.value, flags ? flags.value : ''), replacement);
  2344. return new Quoted(string.quote || '', result, string.escaped);
  2345. },
  2346. '%': function (string /* arg, arg, ... */) {
  2347. var args = Array.prototype.slice.call(arguments, 1),
  2348. result = string.value;
  2349. for (var i = 0; i < args.length; i++) {
  2350. /* jshint loopfunc:true */
  2351. result = result.replace(/%[sda]/i, function(token) {
  2352. var value = ((args[i].type === 'Quoted') &&
  2353. token.match(/s/i)) ? args[i].value : args[i].toCSS();
  2354. return token.match(/[A-Z]$/) ? encodeURIComponent(value) : value;
  2355. });
  2356. }
  2357. result = result.replace(/%%/g, '%');
  2358. return new Quoted(string.quote || '', result, string.escaped);
  2359. }
  2360. });
  2361. },{"../tree/anonymous":50,"../tree/javascript":68,"../tree/quoted":80,"./function-registry":27}],34:[function(require,module,exports){
  2362. module.exports = function(environment) {
  2363. var Dimension = require('../tree/dimension'),
  2364. Color = require('../tree/color'),
  2365. Expression = require('../tree/expression'),
  2366. Quoted = require('../tree/quoted'),
  2367. URL = require('../tree/url'),
  2368. functionRegistry = require('./function-registry');
  2369. functionRegistry.add('svg-gradient', function(direction) {
  2370. var stops,
  2371. gradientDirectionSvg,
  2372. gradientType = 'linear',
  2373. rectangleDimension = 'x="0" y="0" width="1" height="1"',
  2374. renderEnv = {compress: false},
  2375. returner,
  2376. directionValue = direction.toCSS(renderEnv),
  2377. i, color, position, positionValue, alpha;
  2378. function throwArgumentDescriptor() {
  2379. throw { type: 'Argument',
  2380. message: 'svg-gradient expects direction, start_color [start_position], [color position,]...,' +
  2381. ' end_color [end_position] or direction, color list' };
  2382. }
  2383. if (arguments.length == 2) {
  2384. if (arguments[1].value.length < 2) {
  2385. throwArgumentDescriptor();
  2386. }
  2387. stops = arguments[1].value;
  2388. } else if (arguments.length < 3) {
  2389. throwArgumentDescriptor();
  2390. } else {
  2391. stops = Array.prototype.slice.call(arguments, 1);
  2392. }
  2393. switch (directionValue) {
  2394. case 'to bottom':
  2395. gradientDirectionSvg = 'x1="0%" y1="0%" x2="0%" y2="100%"';
  2396. break;
  2397. case 'to right':
  2398. gradientDirectionSvg = 'x1="0%" y1="0%" x2="100%" y2="0%"';
  2399. break;
  2400. case 'to bottom right':
  2401. gradientDirectionSvg = 'x1="0%" y1="0%" x2="100%" y2="100%"';
  2402. break;
  2403. case 'to top right':
  2404. gradientDirectionSvg = 'x1="0%" y1="100%" x2="100%" y2="0%"';
  2405. break;
  2406. case 'ellipse':
  2407. case 'ellipse at center':
  2408. gradientType = 'radial';
  2409. gradientDirectionSvg = 'cx="50%" cy="50%" r="75%"';
  2410. rectangleDimension = 'x="-50" y="-50" width="101" height="101"';
  2411. break;
  2412. default:
  2413. throw { type: 'Argument', message: 'svg-gradient direction must be \'to bottom\', \'to right\',' +
  2414. ' \'to bottom right\', \'to top right\' or \'ellipse at center\'' };
  2415. }
  2416. returner = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1 1">' +
  2417. '<' + gradientType + 'Gradient id="g" ' + gradientDirectionSvg + '>';
  2418. for (i = 0; i < stops.length; i += 1) {
  2419. if (stops[i] instanceof Expression) {
  2420. color = stops[i].value[0];
  2421. position = stops[i].value[1];
  2422. } else {
  2423. color = stops[i];
  2424. position = undefined;
  2425. }
  2426. if (!(color instanceof Color) || (!((i === 0 || i + 1 === stops.length) && position === undefined) && !(position instanceof Dimension))) {
  2427. throwArgumentDescriptor();
  2428. }
  2429. positionValue = position ? position.toCSS(renderEnv) : i === 0 ? '0%' : '100%';
  2430. alpha = color.alpha;
  2431. returner += '<stop offset="' + positionValue + '" stop-color="' + color.toRGB() + '"' + (alpha < 1 ? ' stop-opacity="' + alpha + '"' : '') + '/>';
  2432. }
  2433. returner += '</' + gradientType + 'Gradient>' +
  2434. '<rect ' + rectangleDimension + ' fill="url(#g)" /></svg>';
  2435. returner = encodeURIComponent(returner);
  2436. returner = 'data:image/svg+xml,' + returner;
  2437. return new URL(new Quoted('\'' + returner + '\'', returner, false, this.index, this.currentFileInfo), this.index, this.currentFileInfo);
  2438. });
  2439. };
  2440. },{"../tree/color":55,"../tree/dimension":62,"../tree/expression":64,"../tree/quoted":80,"../tree/url":85,"./function-registry":27}],35:[function(require,module,exports){
  2441. var Keyword = require('../tree/keyword'),
  2442. DetachedRuleset = require('../tree/detached-ruleset'),
  2443. Dimension = require('../tree/dimension'),
  2444. Color = require('../tree/color'),
  2445. Quoted = require('../tree/quoted'),
  2446. Anonymous = require('../tree/anonymous'),
  2447. URL = require('../tree/url'),
  2448. Operation = require('../tree/operation'),
  2449. functionRegistry = require('./function-registry');
  2450. var isa = function (n, Type) {
  2451. return (n instanceof Type) ? Keyword.True : Keyword.False;
  2452. },
  2453. isunit = function (n, unit) {
  2454. if (unit === undefined) {
  2455. throw { type: 'Argument', message: 'missing the required second argument to isunit.' };
  2456. }
  2457. unit = typeof unit.value === 'string' ? unit.value : unit;
  2458. if (typeof unit !== 'string') {
  2459. throw { type: 'Argument', message: 'Second argument to isunit should be a unit or a string.' };
  2460. }
  2461. return (n instanceof Dimension) && n.unit.is(unit) ? Keyword.True : Keyword.False;
  2462. };
  2463. functionRegistry.addMultiple({
  2464. isruleset: function (n) {
  2465. return isa(n, DetachedRuleset);
  2466. },
  2467. iscolor: function (n) {
  2468. return isa(n, Color);
  2469. },
  2470. isnumber: function (n) {
  2471. return isa(n, Dimension);
  2472. },
  2473. isstring: function (n) {
  2474. return isa(n, Quoted);
  2475. },
  2476. iskeyword: function (n) {
  2477. return isa(n, Keyword);
  2478. },
  2479. isurl: function (n) {
  2480. return isa(n, URL);
  2481. },
  2482. ispixel: function (n) {
  2483. return isunit(n, 'px');
  2484. },
  2485. ispercentage: function (n) {
  2486. return isunit(n, '%');
  2487. },
  2488. isem: function (n) {
  2489. return isunit(n, 'em');
  2490. },
  2491. isunit: isunit,
  2492. unit: function (val, unit) {
  2493. if (!(val instanceof Dimension)) {
  2494. throw { type: 'Argument',
  2495. message: 'the first argument to unit must be a number' +
  2496. (val instanceof Operation ? '. Have you forgotten parenthesis?' : '') };
  2497. }
  2498. if (unit) {
  2499. if (unit instanceof Keyword) {
  2500. unit = unit.value;
  2501. } else {
  2502. unit = unit.toCSS();
  2503. }
  2504. } else {
  2505. unit = '';
  2506. }
  2507. return new Dimension(val.value, unit);
  2508. },
  2509. 'get-unit': function (n) {
  2510. return new Anonymous(n.unit);
  2511. }
  2512. });
  2513. },{"../tree/anonymous":50,"../tree/color":55,"../tree/detached-ruleset":61,"../tree/dimension":62,"../tree/keyword":70,"../tree/operation":77,"../tree/quoted":80,"../tree/url":85,"./function-registry":27}],36:[function(require,module,exports){
  2514. var contexts = require('./contexts'),
  2515. Parser = require('./parser/parser'),
  2516. LessError = require('./less-error'),
  2517. utils = require('./utils'),
  2518. PromiseConstructor = typeof Promise === 'undefined' ? require('promise') : Promise,
  2519. logger = require('./logger');
  2520. module.exports = function(environment) {
  2521. // FileInfo = {
  2522. // 'rewriteUrls' - option - whether to adjust URL's to be relative
  2523. // 'filename' - full resolved filename of current file
  2524. // 'rootpath' - path to append to normal URLs for this node
  2525. // 'currentDirectory' - path to the current file, absolute
  2526. // 'rootFilename' - filename of the base file
  2527. // 'entryPath' - absolute path to the entry file
  2528. // 'reference' - whether the file should not be output and only output parts that are referenced
  2529. var ImportManager = function(less, context, rootFileInfo) {
  2530. this.less = less;
  2531. this.rootFilename = rootFileInfo.filename;
  2532. this.paths = context.paths || []; // Search paths, when importing
  2533. this.contents = {}; // map - filename to contents of all the files
  2534. this.contentsIgnoredChars = {}; // map - filename to lines at the beginning of each file to ignore
  2535. this.mime = context.mime;
  2536. this.error = null;
  2537. this.context = context;
  2538. // Deprecated? Unused outside of here, could be useful.
  2539. this.queue = []; // Files which haven't been imported yet
  2540. this.files = {}; // Holds the imported parse trees.
  2541. };
  2542. /**
  2543. * Add an import to be imported
  2544. * @param path - the raw path
  2545. * @param tryAppendExtension - whether to try appending a file extension (.less or .js if the path has no extension)
  2546. * @param currentFileInfo - the current file info (used for instance to work out relative paths)
  2547. * @param importOptions - import options
  2548. * @param callback - callback for when it is imported
  2549. */
  2550. ImportManager.prototype.push = function (path, tryAppendExtension, currentFileInfo, importOptions, callback) {
  2551. var importManager = this,
  2552. pluginLoader = this.context.pluginManager.Loader;
  2553. this.queue.push(path);
  2554. var fileParsedFunc = function (e, root, fullPath) {
  2555. importManager.queue.splice(importManager.queue.indexOf(path), 1); // Remove the path from the queue
  2556. var importedEqualsRoot = fullPath === importManager.rootFilename;
  2557. if (importOptions.optional && e) {
  2558. callback(null, {rules:[]}, false, null);
  2559. logger.info('The file ' + fullPath + ' was skipped because it was not found and the import was marked optional.');
  2560. }
  2561. else {
  2562. // Inline imports aren't cached here.
  2563. // If we start to cache them, please make sure they won't conflict with non-inline imports of the
  2564. // same name as they used to do before this comment and the condition below have been added.
  2565. if (!importManager.files[fullPath] && !importOptions.inline) {
  2566. importManager.files[fullPath] = { root: root, options: importOptions };
  2567. }
  2568. if (e && !importManager.error) { importManager.error = e; }
  2569. callback(e, root, importedEqualsRoot, fullPath);
  2570. }
  2571. };
  2572. var newFileInfo = {
  2573. rewriteUrls: this.context.rewriteUrls,
  2574. entryPath: currentFileInfo.entryPath,
  2575. rootpath: currentFileInfo.rootpath,
  2576. rootFilename: currentFileInfo.rootFilename
  2577. };
  2578. var fileManager = environment.getFileManager(path, currentFileInfo.currentDirectory, this.context, environment);
  2579. if (!fileManager) {
  2580. fileParsedFunc({ message: 'Could not find a file-manager for ' + path });
  2581. return;
  2582. }
  2583. var loadFileCallback = function(loadedFile) {
  2584. var plugin,
  2585. resolvedFilename = loadedFile.filename,
  2586. contents = loadedFile.contents.replace(/^\uFEFF/, '');
  2587. // Pass on an updated rootpath if path of imported file is relative and file
  2588. // is in a (sub|sup) directory
  2589. //
  2590. // Examples:
  2591. // - If path of imported file is 'module/nav/nav.less' and rootpath is 'less/',
  2592. // then rootpath should become 'less/module/nav/'
  2593. // - If path of imported file is '../mixins.less' and rootpath is 'less/',
  2594. // then rootpath should become 'less/../'
  2595. newFileInfo.currentDirectory = fileManager.getPath(resolvedFilename);
  2596. if (newFileInfo.rewriteUrls) {
  2597. newFileInfo.rootpath = fileManager.join(
  2598. (importManager.context.rootpath || ''),
  2599. fileManager.pathDiff(newFileInfo.currentDirectory, newFileInfo.entryPath));
  2600. if (!fileManager.isPathAbsolute(newFileInfo.rootpath) && fileManager.alwaysMakePathsAbsolute()) {
  2601. newFileInfo.rootpath = fileManager.join(newFileInfo.entryPath, newFileInfo.rootpath);
  2602. }
  2603. }
  2604. newFileInfo.filename = resolvedFilename;
  2605. var newEnv = new contexts.Parse(importManager.context);
  2606. newEnv.processImports = false;
  2607. importManager.contents[resolvedFilename] = contents;
  2608. if (currentFileInfo.reference || importOptions.reference) {
  2609. newFileInfo.reference = true;
  2610. }
  2611. if (importOptions.isPlugin) {
  2612. plugin = pluginLoader.evalPlugin(contents, newEnv, importManager, importOptions.pluginArgs, newFileInfo);
  2613. if (plugin instanceof LessError) {
  2614. fileParsedFunc(plugin, null, resolvedFilename);
  2615. }
  2616. else {
  2617. fileParsedFunc(null, plugin, resolvedFilename);
  2618. }
  2619. } else if (importOptions.inline) {
  2620. fileParsedFunc(null, contents, resolvedFilename);
  2621. } else {
  2622. // import (multiple) parse trees apparently get altered and can't be cached.
  2623. // TODO: investigate why this is
  2624. if (importManager.files[resolvedFilename]
  2625. && !importManager.files[resolvedFilename].options.multiple
  2626. && !importOptions.multiple) {
  2627. fileParsedFunc(null, importManager.files[resolvedFilename].root, resolvedFilename);
  2628. }
  2629. else {
  2630. new Parser(newEnv, importManager, newFileInfo).parse(contents, function (e, root) {
  2631. fileParsedFunc(e, root, resolvedFilename);
  2632. });
  2633. }
  2634. }
  2635. };
  2636. var promise, context = utils.clone(this.context);
  2637. if (tryAppendExtension) {
  2638. context.ext = importOptions.isPlugin ? '.js' : '.less';
  2639. }
  2640. if (importOptions.isPlugin) {
  2641. promise = pluginLoader.loadPlugin(path, currentFileInfo.currentDirectory, context, environment, fileManager);
  2642. }
  2643. else {
  2644. promise = fileManager.loadFile(path, currentFileInfo.currentDirectory, context, environment,
  2645. function(err, loadedFile) {
  2646. if (err) {
  2647. fileParsedFunc(err);
  2648. } else {
  2649. loadFileCallback(loadedFile);
  2650. }
  2651. });
  2652. }
  2653. if (promise) {
  2654. promise.then(loadFileCallback, fileParsedFunc);
  2655. }
  2656. };
  2657. return ImportManager;
  2658. };
  2659. },{"./contexts":13,"./less-error":38,"./logger":39,"./parser/parser":44,"./utils":89,"promise":undefined}],37:[function(require,module,exports){
  2660. module.exports = function(environment, fileManagers) {
  2661. var SourceMapOutput, SourceMapBuilder, ParseTree, ImportManager, Environment;
  2662. var initial = {
  2663. version: [3, 8, 0],
  2664. data: require('./data'),
  2665. tree: require('./tree'),
  2666. Environment: (Environment = require('./environment/environment')),
  2667. AbstractFileManager: require('./environment/abstract-file-manager'),
  2668. AbstractPluginLoader: require('./environment/abstract-plugin-loader'),
  2669. environment: (environment = new Environment(environment, fileManagers)),
  2670. visitors: require('./visitors'),
  2671. Parser: require('./parser/parser'),
  2672. functions: require('./functions')(environment),
  2673. contexts: require('./contexts'),
  2674. SourceMapOutput: (SourceMapOutput = require('./source-map-output')(environment)),
  2675. SourceMapBuilder: (SourceMapBuilder = require('./source-map-builder')(SourceMapOutput, environment)),
  2676. ParseTree: (ParseTree = require('./parse-tree')(SourceMapBuilder)),
  2677. ImportManager: (ImportManager = require('./import-manager')(environment)),
  2678. render: require('./render')(environment, ParseTree, ImportManager),
  2679. parse: require('./parse')(environment, ParseTree, ImportManager),
  2680. LessError: require('./less-error'),
  2681. transformTree: require('./transform-tree'),
  2682. utils: require('./utils'),
  2683. PluginManager: require('./plugin-manager'),
  2684. logger: require('./logger')
  2685. };
  2686. // Create a public API
  2687. var ctor = function(t) {
  2688. return function() {
  2689. var obj = Object.create(t.prototype);
  2690. t.apply(obj, Array.prototype.slice.call(arguments, 0));
  2691. return obj;
  2692. };
  2693. };
  2694. var t, api = Object.create(initial);
  2695. for (var n in initial.tree) {
  2696. /* eslint guard-for-in: 0 */
  2697. t = initial.tree[n];
  2698. if (typeof t === 'function') {
  2699. api[n.toLowerCase()] = ctor(t);
  2700. }
  2701. else {
  2702. api[n] = Object.create(null);
  2703. for (var o in t) {
  2704. /* eslint guard-for-in: 0 */
  2705. api[n][o.toLowerCase()] = ctor(t[o]);
  2706. }
  2707. }
  2708. }
  2709. return api;
  2710. };
  2711. },{"./contexts":13,"./data":15,"./environment/abstract-file-manager":18,"./environment/abstract-plugin-loader":19,"./environment/environment":20,"./functions":28,"./import-manager":36,"./less-error":38,"./logger":39,"./parse":41,"./parse-tree":40,"./parser/parser":44,"./plugin-manager":45,"./render":46,"./source-map-builder":47,"./source-map-output":48,"./transform-tree":49,"./tree":67,"./utils":89,"./visitors":93}],38:[function(require,module,exports){
  2712. var utils = require('./utils');
  2713. /**
  2714. * This is a centralized class of any error that could be thrown internally (mostly by the parser).
  2715. * Besides standard .message it keeps some additional data like a path to the file where the error
  2716. * occurred along with line and column numbers.
  2717. *
  2718. * @class
  2719. * @extends Error
  2720. * @type {module.LessError}
  2721. *
  2722. * @prop {string} type
  2723. * @prop {string} filename
  2724. * @prop {number} index
  2725. * @prop {number} line
  2726. * @prop {number} column
  2727. * @prop {number} callLine
  2728. * @prop {number} callExtract
  2729. * @prop {string[]} extract
  2730. *
  2731. * @param {Object} e - An error object to wrap around or just a descriptive object
  2732. * @param {Object} fileContentMap - An object with file contents in 'contents' property (like importManager) @todo - move to fileManager?
  2733. * @param {string} [currentFilename]
  2734. */
  2735. var LessError = module.exports = function LessError(e, fileContentMap, currentFilename) {
  2736. Error.call(this);
  2737. var filename = e.filename || currentFilename;
  2738. this.message = e.message;
  2739. this.stack = e.stack;
  2740. if (fileContentMap && filename) {
  2741. var input = fileContentMap.contents[filename],
  2742. loc = utils.getLocation(e.index, input),
  2743. line = loc.line,
  2744. col = loc.column,
  2745. callLine = e.call && utils.getLocation(e.call, input).line,
  2746. lines = input ? input.split('\n') : '';
  2747. this.type = e.type || 'Syntax';
  2748. this.filename = filename;
  2749. this.index = e.index;
  2750. this.line = typeof line === 'number' ? line + 1 : null;
  2751. this.column = col;
  2752. if (!this.line && this.stack) {
  2753. var found = this.stack.match(/(<anonymous>|Function):(\d+):(\d+)/);
  2754. if (found) {
  2755. if (found[2]) {
  2756. this.line = parseInt(found[2]) - 2;
  2757. }
  2758. if (found[3]) {
  2759. this.column = parseInt(found[3]);
  2760. }
  2761. }
  2762. }
  2763. this.callLine = callLine + 1;
  2764. this.callExtract = lines[callLine];
  2765. this.extract = [
  2766. lines[this.line - 2],
  2767. lines[this.line - 1],
  2768. lines[this.line]
  2769. ];
  2770. }
  2771. };
  2772. if (typeof Object.create === 'undefined') {
  2773. var F = function () {};
  2774. F.prototype = Error.prototype;
  2775. LessError.prototype = new F();
  2776. } else {
  2777. LessError.prototype = Object.create(Error.prototype);
  2778. }
  2779. LessError.prototype.constructor = LessError;
  2780. /**
  2781. * An overridden version of the default Object.prototype.toString
  2782. * which uses additional information to create a helpful message.
  2783. *
  2784. * @param {Object} options
  2785. * @returns {string}
  2786. */
  2787. LessError.prototype.toString = function(options) {
  2788. options = options || {};
  2789. var message = '';
  2790. var extract = this.extract || [];
  2791. var error = [];
  2792. var stylize = function (str) { return str; };
  2793. if (options.stylize) {
  2794. var type = typeof options.stylize;
  2795. if (type !== 'function') {
  2796. throw Error('options.stylize should be a function, got a ' + type + '!');
  2797. }
  2798. stylize = options.stylize;
  2799. }
  2800. if (this.line !== null) {
  2801. if (typeof extract[0] === 'string') {
  2802. error.push(stylize((this.line - 1) + ' ' + extract[0], 'grey'));
  2803. }
  2804. if (typeof extract[1] === 'string') {
  2805. var errorTxt = this.line + ' ';
  2806. if (extract[1]) {
  2807. errorTxt += extract[1].slice(0, this.column) +
  2808. stylize(stylize(stylize(extract[1].substr(this.column, 1), 'bold') +
  2809. extract[1].slice(this.column + 1), 'red'), 'inverse');
  2810. }
  2811. error.push(errorTxt);
  2812. }
  2813. if (typeof extract[2] === 'string') {
  2814. error.push(stylize((this.line + 1) + ' ' + extract[2], 'grey'));
  2815. }
  2816. error = error.join('\n') + stylize('', 'reset') + '\n';
  2817. }
  2818. message += stylize(this.type + 'Error: ' + this.message, 'red');
  2819. if (this.filename) {
  2820. message += stylize(' in ', 'red') + this.filename;
  2821. }
  2822. if (this.line) {
  2823. message += stylize(' on line ' + this.line + ', column ' + (this.column + 1) + ':', 'grey');
  2824. }
  2825. message += '\n' + error;
  2826. if (this.callLine) {
  2827. message += stylize('from ', 'red') + (this.filename || '') + '/n';
  2828. message += stylize(this.callLine, 'grey') + ' ' + this.callExtract + '/n';
  2829. }
  2830. return message;
  2831. };
  2832. },{"./utils":89}],39:[function(require,module,exports){
  2833. module.exports = {
  2834. error: function(msg) {
  2835. this._fireEvent('error', msg);
  2836. },
  2837. warn: function(msg) {
  2838. this._fireEvent('warn', msg);
  2839. },
  2840. info: function(msg) {
  2841. this._fireEvent('info', msg);
  2842. },
  2843. debug: function(msg) {
  2844. this._fireEvent('debug', msg);
  2845. },
  2846. addListener: function(listener) {
  2847. this._listeners.push(listener);
  2848. },
  2849. removeListener: function(listener) {
  2850. for (var i = 0; i < this._listeners.length; i++) {
  2851. if (this._listeners[i] === listener) {
  2852. this._listeners.splice(i, 1);
  2853. return;
  2854. }
  2855. }
  2856. },
  2857. _fireEvent: function(type, msg) {
  2858. for (var i = 0; i < this._listeners.length; i++) {
  2859. var logFunction = this._listeners[i][type];
  2860. if (logFunction) {
  2861. logFunction(msg);
  2862. }
  2863. }
  2864. },
  2865. _listeners: []
  2866. };
  2867. },{}],40:[function(require,module,exports){
  2868. var LessError = require('./less-error'),
  2869. transformTree = require('./transform-tree'),
  2870. logger = require('./logger');
  2871. module.exports = function(SourceMapBuilder) {
  2872. var ParseTree = function(root, imports) {
  2873. this.root = root;
  2874. this.imports = imports;
  2875. };
  2876. ParseTree.prototype.toCSS = function(options) {
  2877. var evaldRoot, result = {}, sourceMapBuilder;
  2878. try {
  2879. evaldRoot = transformTree(this.root, options);
  2880. } catch (e) {
  2881. throw new LessError(e, this.imports);
  2882. }
  2883. try {
  2884. var compress = Boolean(options.compress);
  2885. if (compress) {
  2886. logger.warn('The compress option has been deprecated. We recommend you use a dedicated css minifier, for instance see less-plugin-clean-css.');
  2887. }
  2888. var toCSSOptions = {
  2889. compress: compress,
  2890. dumpLineNumbers: options.dumpLineNumbers,
  2891. strictUnits: Boolean(options.strictUnits),
  2892. numPrecision: 8};
  2893. if (options.sourceMap) {
  2894. sourceMapBuilder = new SourceMapBuilder(options.sourceMap);
  2895. result.css = sourceMapBuilder.toCSS(evaldRoot, toCSSOptions, this.imports);
  2896. } else {
  2897. result.css = evaldRoot.toCSS(toCSSOptions);
  2898. }
  2899. } catch (e) {
  2900. throw new LessError(e, this.imports);
  2901. }
  2902. if (options.pluginManager) {
  2903. var postProcessors = options.pluginManager.getPostProcessors();
  2904. for (var i = 0; i < postProcessors.length; i++) {
  2905. result.css = postProcessors[i].process(result.css, { sourceMap: sourceMapBuilder, options: options, imports: this.imports });
  2906. }
  2907. }
  2908. if (options.sourceMap) {
  2909. result.map = sourceMapBuilder.getExternalSourceMap();
  2910. }
  2911. result.imports = [];
  2912. for (var file in this.imports.files) {
  2913. if (this.imports.files.hasOwnProperty(file) && file !== this.imports.rootFilename) {
  2914. result.imports.push(file);
  2915. }
  2916. }
  2917. return result;
  2918. };
  2919. return ParseTree;
  2920. };
  2921. },{"./less-error":38,"./logger":39,"./transform-tree":49}],41:[function(require,module,exports){
  2922. var PromiseConstructor,
  2923. contexts = require('./contexts'),
  2924. Parser = require('./parser/parser'),
  2925. PluginManager = require('./plugin-manager'),
  2926. LessError = require('./less-error'),
  2927. utils = require('./utils');
  2928. module.exports = function(environment, ParseTree, ImportManager) {
  2929. var parse = function (input, options, callback) {
  2930. if (typeof options === 'function') {
  2931. callback = options;
  2932. options = utils.copyOptions(this.options, {});
  2933. }
  2934. else {
  2935. options = utils.copyOptions(this.options, options || {});
  2936. }
  2937. if (!callback) {
  2938. if (!PromiseConstructor) {
  2939. PromiseConstructor = typeof Promise === 'undefined' ? require('promise') : Promise;
  2940. }
  2941. var self = this;
  2942. return new PromiseConstructor(function (resolve, reject) {
  2943. parse.call(self, input, options, function(err, output) {
  2944. if (err) {
  2945. reject(err);
  2946. } else {
  2947. resolve(output);
  2948. }
  2949. });
  2950. });
  2951. } else {
  2952. var context,
  2953. rootFileInfo,
  2954. pluginManager = new PluginManager(this, !options.reUsePluginManager);
  2955. options.pluginManager = pluginManager;
  2956. context = new contexts.Parse(options);
  2957. if (options.rootFileInfo) {
  2958. rootFileInfo = options.rootFileInfo;
  2959. } else {
  2960. var filename = options.filename || 'input';
  2961. var entryPath = filename.replace(/[^\/\\]*$/, '');
  2962. rootFileInfo = {
  2963. filename: filename,
  2964. rewriteUrls: context.rewriteUrls,
  2965. rootpath: context.rootpath || '',
  2966. currentDirectory: entryPath,
  2967. entryPath: entryPath,
  2968. rootFilename: filename
  2969. };
  2970. // add in a missing trailing slash
  2971. if (rootFileInfo.rootpath && rootFileInfo.rootpath.slice(-1) !== '/') {
  2972. rootFileInfo.rootpath += '/';
  2973. }
  2974. }
  2975. var imports = new ImportManager(this, context, rootFileInfo);
  2976. this.importManager = imports;
  2977. // TODO: allow the plugins to be just a list of paths or names
  2978. // Do an async plugin queue like lessc
  2979. if (options.plugins) {
  2980. options.plugins.forEach(function(plugin) {
  2981. var evalResult, contents;
  2982. if (plugin.fileContent) {
  2983. contents = plugin.fileContent.replace(/^\uFEFF/, '');
  2984. evalResult = pluginManager.Loader.evalPlugin(contents, context, imports, plugin.options, plugin.filename);
  2985. if (evalResult instanceof LessError) {
  2986. return callback(evalResult);
  2987. }
  2988. }
  2989. else {
  2990. pluginManager.addPlugin(plugin);
  2991. }
  2992. });
  2993. }
  2994. new Parser(context, imports, rootFileInfo)
  2995. .parse(input, function (e, root) {
  2996. if (e) { return callback(e); }
  2997. callback(null, root, imports, options);
  2998. }, options);
  2999. }
  3000. };
  3001. return parse;
  3002. };
  3003. },{"./contexts":13,"./less-error":38,"./parser/parser":44,"./plugin-manager":45,"./utils":89,"promise":undefined}],42:[function(require,module,exports){
  3004. // Split the input into chunks.
  3005. module.exports = function (input, fail) {
  3006. var len = input.length, level = 0, parenLevel = 0,
  3007. lastOpening, lastOpeningParen, lastMultiComment, lastMultiCommentEndBrace,
  3008. chunks = [], emitFrom = 0,
  3009. chunkerCurrentIndex, currentChunkStartIndex, cc, cc2, matched;
  3010. function emitChunk(force) {
  3011. var len = chunkerCurrentIndex - emitFrom;
  3012. if (((len < 512) && !force) || !len) {
  3013. return;
  3014. }
  3015. chunks.push(input.slice(emitFrom, chunkerCurrentIndex + 1));
  3016. emitFrom = chunkerCurrentIndex + 1;
  3017. }
  3018. for (chunkerCurrentIndex = 0; chunkerCurrentIndex < len; chunkerCurrentIndex++) {
  3019. cc = input.charCodeAt(chunkerCurrentIndex);
  3020. if (((cc >= 97) && (cc <= 122)) || (cc < 34)) {
  3021. // a-z or whitespace
  3022. continue;
  3023. }
  3024. switch (cc) {
  3025. case 40: // (
  3026. parenLevel++;
  3027. lastOpeningParen = chunkerCurrentIndex;
  3028. continue;
  3029. case 41: // )
  3030. if (--parenLevel < 0) {
  3031. return fail('missing opening `(`', chunkerCurrentIndex);
  3032. }
  3033. continue;
  3034. case 59: // ;
  3035. if (!parenLevel) { emitChunk(); }
  3036. continue;
  3037. case 123: // {
  3038. level++;
  3039. lastOpening = chunkerCurrentIndex;
  3040. continue;
  3041. case 125: // }
  3042. if (--level < 0) {
  3043. return fail('missing opening `{`', chunkerCurrentIndex);
  3044. }
  3045. if (!level && !parenLevel) { emitChunk(); }
  3046. continue;
  3047. case 92: // \
  3048. if (chunkerCurrentIndex < len - 1) { chunkerCurrentIndex++; continue; }
  3049. return fail('unescaped `\\`', chunkerCurrentIndex);
  3050. case 34:
  3051. case 39:
  3052. case 96: // ", ' and `
  3053. matched = 0;
  3054. currentChunkStartIndex = chunkerCurrentIndex;
  3055. for (chunkerCurrentIndex = chunkerCurrentIndex + 1; chunkerCurrentIndex < len; chunkerCurrentIndex++) {
  3056. cc2 = input.charCodeAt(chunkerCurrentIndex);
  3057. if (cc2 > 96) { continue; }
  3058. if (cc2 == cc) { matched = 1; break; }
  3059. if (cc2 == 92) { // \
  3060. if (chunkerCurrentIndex == len - 1) {
  3061. return fail('unescaped `\\`', chunkerCurrentIndex);
  3062. }
  3063. chunkerCurrentIndex++;
  3064. }
  3065. }
  3066. if (matched) { continue; }
  3067. return fail('unmatched `' + String.fromCharCode(cc) + '`', currentChunkStartIndex);
  3068. case 47: // /, check for comment
  3069. if (parenLevel || (chunkerCurrentIndex == len - 1)) { continue; }
  3070. cc2 = input.charCodeAt(chunkerCurrentIndex + 1);
  3071. if (cc2 == 47) {
  3072. // //, find lnfeed
  3073. for (chunkerCurrentIndex = chunkerCurrentIndex + 2; chunkerCurrentIndex < len; chunkerCurrentIndex++) {
  3074. cc2 = input.charCodeAt(chunkerCurrentIndex);
  3075. if ((cc2 <= 13) && ((cc2 == 10) || (cc2 == 13))) { break; }
  3076. }
  3077. } else if (cc2 == 42) {
  3078. // /*, find */
  3079. lastMultiComment = currentChunkStartIndex = chunkerCurrentIndex;
  3080. for (chunkerCurrentIndex = chunkerCurrentIndex + 2; chunkerCurrentIndex < len - 1; chunkerCurrentIndex++) {
  3081. cc2 = input.charCodeAt(chunkerCurrentIndex);
  3082. if (cc2 == 125) { lastMultiCommentEndBrace = chunkerCurrentIndex; }
  3083. if (cc2 != 42) { continue; }
  3084. if (input.charCodeAt(chunkerCurrentIndex + 1) == 47) { break; }
  3085. }
  3086. if (chunkerCurrentIndex == len - 1) {
  3087. return fail('missing closing `*/`', currentChunkStartIndex);
  3088. }
  3089. chunkerCurrentIndex++;
  3090. }
  3091. continue;
  3092. case 42: // *, check for unmatched */
  3093. if ((chunkerCurrentIndex < len - 1) && (input.charCodeAt(chunkerCurrentIndex + 1) == 47)) {
  3094. return fail('unmatched `/*`', chunkerCurrentIndex);
  3095. }
  3096. continue;
  3097. }
  3098. }
  3099. if (level !== 0) {
  3100. if ((lastMultiComment > lastOpening) && (lastMultiCommentEndBrace > lastMultiComment)) {
  3101. return fail('missing closing `}` or `*/`', lastOpening);
  3102. } else {
  3103. return fail('missing closing `}`', lastOpening);
  3104. }
  3105. } else if (parenLevel !== 0) {
  3106. return fail('missing closing `)`', lastOpeningParen);
  3107. }
  3108. emitChunk(true);
  3109. return chunks;
  3110. };
  3111. },{}],43:[function(require,module,exports){
  3112. var chunker = require('./chunker');
  3113. module.exports = function() {
  3114. var input, // Less input string
  3115. j, // current chunk
  3116. saveStack = [], // holds state for backtracking
  3117. furthest, // furthest index the parser has gone to
  3118. furthestPossibleErrorMessage, // if this is furthest we got to, this is the probably cause
  3119. chunks, // chunkified input
  3120. current, // current chunk
  3121. currentPos, // index of current chunk, in `input`
  3122. parserInput = {};
  3123. var CHARCODE_SPACE = 32,
  3124. CHARCODE_TAB = 9,
  3125. CHARCODE_LF = 10,
  3126. CHARCODE_CR = 13,
  3127. CHARCODE_PLUS = 43,
  3128. CHARCODE_COMMA = 44,
  3129. CHARCODE_FORWARD_SLASH = 47,
  3130. CHARCODE_9 = 57;
  3131. function skipWhitespace(length) {
  3132. var oldi = parserInput.i, oldj = j,
  3133. curr = parserInput.i - currentPos,
  3134. endIndex = parserInput.i + current.length - curr,
  3135. mem = (parserInput.i += length),
  3136. inp = input,
  3137. c, nextChar, comment;
  3138. for (; parserInput.i < endIndex; parserInput.i++) {
  3139. c = inp.charCodeAt(parserInput.i);
  3140. if (parserInput.autoCommentAbsorb && c === CHARCODE_FORWARD_SLASH) {
  3141. nextChar = inp.charAt(parserInput.i + 1);
  3142. if (nextChar === '/') {
  3143. comment = {index: parserInput.i, isLineComment: true};
  3144. var nextNewLine = inp.indexOf('\n', parserInput.i + 2);
  3145. if (nextNewLine < 0) {
  3146. nextNewLine = endIndex;
  3147. }
  3148. parserInput.i = nextNewLine;
  3149. comment.text = inp.substr(comment.index, parserInput.i - comment.index);
  3150. parserInput.commentStore.push(comment);
  3151. continue;
  3152. } else if (nextChar === '*') {
  3153. var nextStarSlash = inp.indexOf('*/', parserInput.i + 2);
  3154. if (nextStarSlash >= 0) {
  3155. comment = {
  3156. index: parserInput.i,
  3157. text: inp.substr(parserInput.i, nextStarSlash + 2 - parserInput.i),
  3158. isLineComment: false
  3159. };
  3160. parserInput.i += comment.text.length - 1;
  3161. parserInput.commentStore.push(comment);
  3162. continue;
  3163. }
  3164. }
  3165. break;
  3166. }
  3167. if ((c !== CHARCODE_SPACE) && (c !== CHARCODE_LF) && (c !== CHARCODE_TAB) && (c !== CHARCODE_CR)) {
  3168. break;
  3169. }
  3170. }
  3171. current = current.slice(length + parserInput.i - mem + curr);
  3172. currentPos = parserInput.i;
  3173. if (!current.length) {
  3174. if (j < chunks.length - 1) {
  3175. current = chunks[++j];
  3176. skipWhitespace(0); // skip space at the beginning of a chunk
  3177. return true; // things changed
  3178. }
  3179. parserInput.finished = true;
  3180. }
  3181. return oldi !== parserInput.i || oldj !== j;
  3182. }
  3183. parserInput.save = function() {
  3184. currentPos = parserInput.i;
  3185. saveStack.push( { current: current, i: parserInput.i, j: j });
  3186. };
  3187. parserInput.restore = function(possibleErrorMessage) {
  3188. if (parserInput.i > furthest || (parserInput.i === furthest && possibleErrorMessage && !furthestPossibleErrorMessage)) {
  3189. furthest = parserInput.i;
  3190. furthestPossibleErrorMessage = possibleErrorMessage;
  3191. }
  3192. var state = saveStack.pop();
  3193. current = state.current;
  3194. currentPos = parserInput.i = state.i;
  3195. j = state.j;
  3196. };
  3197. parserInput.forget = function() {
  3198. saveStack.pop();
  3199. };
  3200. parserInput.isWhitespace = function (offset) {
  3201. var pos = parserInput.i + (offset || 0),
  3202. code = input.charCodeAt(pos);
  3203. return (code === CHARCODE_SPACE || code === CHARCODE_CR || code === CHARCODE_TAB || code === CHARCODE_LF);
  3204. };
  3205. // Specialization of $(tok)
  3206. parserInput.$re = function(tok) {
  3207. if (parserInput.i > currentPos) {
  3208. current = current.slice(parserInput.i - currentPos);
  3209. currentPos = parserInput.i;
  3210. }
  3211. var m = tok.exec(current);
  3212. if (!m) {
  3213. return null;
  3214. }
  3215. skipWhitespace(m[0].length);
  3216. if (typeof m === 'string') {
  3217. return m;
  3218. }
  3219. return m.length === 1 ? m[0] : m;
  3220. };
  3221. parserInput.$char = function(tok) {
  3222. if (input.charAt(parserInput.i) !== tok) {
  3223. return null;
  3224. }
  3225. skipWhitespace(1);
  3226. return tok;
  3227. };
  3228. parserInput.$str = function(tok) {
  3229. var tokLength = tok.length;
  3230. // https://jsperf.com/string-startswith/21
  3231. for (var i = 0; i < tokLength; i++) {
  3232. if (input.charAt(parserInput.i + i) !== tok.charAt(i)) {
  3233. return null;
  3234. }
  3235. }
  3236. skipWhitespace(tokLength);
  3237. return tok;
  3238. };
  3239. parserInput.$quoted = function(loc) {
  3240. var pos = loc || parserInput.i,
  3241. startChar = input.charAt(pos);
  3242. if (startChar !== '\'' && startChar !== '"') {
  3243. return;
  3244. }
  3245. var length = input.length,
  3246. currentPosition = pos;
  3247. for (var i = 1; i + currentPosition < length; i++) {
  3248. var nextChar = input.charAt(i + currentPosition);
  3249. switch (nextChar) {
  3250. case '\\':
  3251. i++;
  3252. continue;
  3253. case '\r':
  3254. case '\n':
  3255. break;
  3256. case startChar:
  3257. var str = input.substr(currentPosition, i + 1);
  3258. if (!loc && loc !== 0) {
  3259. skipWhitespace(i + 1);
  3260. return str
  3261. }
  3262. return [startChar, str];
  3263. default:
  3264. }
  3265. }
  3266. return null;
  3267. };
  3268. /**
  3269. * Permissive parsing. Ignores everything except matching {} [] () and quotes
  3270. * until matching token (outside of blocks)
  3271. */
  3272. parserInput.$parseUntil = function(tok) {
  3273. var quote = '',
  3274. returnVal = null,
  3275. inComment = false,
  3276. blockDepth = 0,
  3277. blockStack = [],
  3278. parseGroups = [],
  3279. length = input.length,
  3280. startPos = parserInput.i,
  3281. lastPos = parserInput.i,
  3282. i = parserInput.i,
  3283. loop = true,
  3284. testChar;
  3285. if (typeof tok === 'string') {
  3286. testChar = function(char) {
  3287. return char === tok;
  3288. }
  3289. } else {
  3290. testChar = function(char) {
  3291. return tok.test(char);
  3292. }
  3293. }
  3294. do {
  3295. var prevChar, nextChar = input.charAt(i);
  3296. if (blockDepth === 0 && testChar(nextChar)) {
  3297. returnVal = input.substr(lastPos, i - lastPos);
  3298. if (returnVal) {
  3299. parseGroups.push(returnVal);
  3300. }
  3301. else {
  3302. parseGroups.push(' ');
  3303. }
  3304. returnVal = parseGroups;
  3305. skipWhitespace(i - startPos);
  3306. loop = false
  3307. } else {
  3308. if (inComment) {
  3309. if (nextChar === '*' &&
  3310. input.charAt(i + 1) === '/') {
  3311. i++;
  3312. blockDepth--;
  3313. inComment = false;
  3314. }
  3315. i++;
  3316. continue;
  3317. }
  3318. switch (nextChar) {
  3319. case '\\':
  3320. i++;
  3321. nextChar = input.charAt(i);
  3322. parseGroups.push(input.substr(lastPos, i - lastPos + 1));
  3323. lastPos = i + 1;
  3324. break;
  3325. case '/':
  3326. if (input.charAt(i + 1) === '*') {
  3327. i++;
  3328. inComment = true;
  3329. blockDepth++;
  3330. }
  3331. break;
  3332. case '\'':
  3333. case '"':
  3334. quote = parserInput.$quoted(i);
  3335. if (quote) {
  3336. parseGroups.push(input.substr(lastPos, i - lastPos), quote);
  3337. i += quote[1].length - 1;
  3338. lastPos = i + 1;
  3339. }
  3340. else {
  3341. skipWhitespace(i - startPos);
  3342. returnVal = nextChar;
  3343. loop = false;
  3344. }
  3345. break;
  3346. case '{':
  3347. blockStack.push('}');
  3348. blockDepth++;
  3349. break;
  3350. case '(':
  3351. blockStack.push(')');
  3352. blockDepth++;
  3353. break;
  3354. case '[':
  3355. blockStack.push(']');
  3356. blockDepth++;
  3357. break;
  3358. case '}':
  3359. case ')':
  3360. case ']':
  3361. var expected = blockStack.pop();
  3362. if (nextChar === expected) {
  3363. blockDepth--;
  3364. } else {
  3365. // move the parser to the error and return expected
  3366. skipWhitespace(i - startPos);
  3367. returnVal = expected;
  3368. loop = false;
  3369. }
  3370. }
  3371. i++;
  3372. if (i > length) {
  3373. loop = false;
  3374. }
  3375. }
  3376. prevChar = nextChar;
  3377. } while (loop);
  3378. return returnVal ? returnVal : null;
  3379. }
  3380. parserInput.autoCommentAbsorb = true;
  3381. parserInput.commentStore = [];
  3382. parserInput.finished = false;
  3383. // Same as $(), but don't change the state of the parser,
  3384. // just return the match.
  3385. parserInput.peek = function(tok) {
  3386. if (typeof tok === 'string') {
  3387. // https://jsperf.com/string-startswith/21
  3388. for (var i = 0; i < tok.length; i++) {
  3389. if (input.charAt(parserInput.i + i) !== tok.charAt(i)) {
  3390. return false;
  3391. }
  3392. }
  3393. return true;
  3394. } else {
  3395. return tok.test(current);
  3396. }
  3397. };
  3398. // Specialization of peek()
  3399. // TODO remove or change some currentChar calls to peekChar
  3400. parserInput.peekChar = function(tok) {
  3401. return input.charAt(parserInput.i) === tok;
  3402. };
  3403. parserInput.currentChar = function() {
  3404. return input.charAt(parserInput.i);
  3405. };
  3406. parserInput.prevChar = function() {
  3407. return input.charAt(parserInput.i - 1);
  3408. };
  3409. parserInput.getInput = function() {
  3410. return input;
  3411. };
  3412. parserInput.peekNotNumeric = function() {
  3413. var c = input.charCodeAt(parserInput.i);
  3414. // Is the first char of the dimension 0-9, '.', '+' or '-'
  3415. return (c > CHARCODE_9 || c < CHARCODE_PLUS) || c === CHARCODE_FORWARD_SLASH || c === CHARCODE_COMMA;
  3416. };
  3417. parserInput.start = function(str, chunkInput, failFunction) {
  3418. input = str;
  3419. parserInput.i = j = currentPos = furthest = 0;
  3420. // chunking apparently makes things quicker (but my tests indicate
  3421. // it might actually make things slower in node at least)
  3422. // and it is a non-perfect parse - it can't recognise
  3423. // unquoted urls, meaning it can't distinguish comments
  3424. // meaning comments with quotes or {}() in them get 'counted'
  3425. // and then lead to parse errors.
  3426. // In addition if the chunking chunks in the wrong place we might
  3427. // not be able to parse a parser statement in one go
  3428. // this is officially deprecated but can be switched on via an option
  3429. // in the case it causes too much performance issues.
  3430. if (chunkInput) {
  3431. chunks = chunker(str, failFunction);
  3432. } else {
  3433. chunks = [str];
  3434. }
  3435. current = chunks[0];
  3436. skipWhitespace(0);
  3437. };
  3438. parserInput.end = function() {
  3439. var message,
  3440. isFinished = parserInput.i >= input.length;
  3441. if (parserInput.i < furthest) {
  3442. message = furthestPossibleErrorMessage;
  3443. parserInput.i = furthest;
  3444. }
  3445. return {
  3446. isFinished: isFinished,
  3447. furthest: parserInput.i,
  3448. furthestPossibleErrorMessage: message,
  3449. furthestReachedEnd: parserInput.i >= input.length - 1,
  3450. furthestChar: input[parserInput.i]
  3451. };
  3452. };
  3453. return parserInput;
  3454. };
  3455. },{"./chunker":42}],44:[function(require,module,exports){
  3456. var LessError = require('../less-error'),
  3457. tree = require('../tree'),
  3458. visitors = require('../visitors'),
  3459. getParserInput = require('./parser-input'),
  3460. utils = require('../utils'),
  3461. functionRegistry = require('../functions/function-registry');
  3462. //
  3463. // less.js - parser
  3464. //
  3465. // A relatively straight-forward predictive parser.
  3466. // There is no tokenization/lexing stage, the input is parsed
  3467. // in one sweep.
  3468. //
  3469. // To make the parser fast enough to run in the browser, several
  3470. // optimization had to be made:
  3471. //
  3472. // - Matching and slicing on a huge input is often cause of slowdowns.
  3473. // The solution is to chunkify the input into smaller strings.
  3474. // The chunks are stored in the `chunks` var,
  3475. // `j` holds the current chunk index, and `currentPos` holds
  3476. // the index of the current chunk in relation to `input`.
  3477. // This gives us an almost 4x speed-up.
  3478. //
  3479. // - In many cases, we don't need to match individual tokens;
  3480. // for example, if a value doesn't hold any variables, operations
  3481. // or dynamic references, the parser can effectively 'skip' it,
  3482. // treating it as a literal.
  3483. // An example would be '1px solid #000' - which evaluates to itself,
  3484. // we don't need to know what the individual components are.
  3485. // The drawback, of course is that you don't get the benefits of
  3486. // syntax-checking on the CSS. This gives us a 50% speed-up in the parser,
  3487. // and a smaller speed-up in the code-gen.
  3488. //
  3489. //
  3490. // Token matching is done with the `$` function, which either takes
  3491. // a terminal string or regexp, or a non-terminal function to call.
  3492. // It also takes care of moving all the indices forwards.
  3493. //
  3494. var Parser = function Parser(context, imports, fileInfo) {
  3495. var parsers,
  3496. parserInput = getParserInput();
  3497. function error(msg, type) {
  3498. throw new LessError(
  3499. {
  3500. index: parserInput.i,
  3501. filename: fileInfo.filename,
  3502. type: type || 'Syntax',
  3503. message: msg
  3504. },
  3505. imports
  3506. );
  3507. }
  3508. function expect(arg, msg) {
  3509. // some older browsers return typeof 'function' for RegExp
  3510. var result = (arg instanceof Function) ? arg.call(parsers) : parserInput.$re(arg);
  3511. if (result) {
  3512. return result;
  3513. }
  3514. error(msg || (typeof arg === 'string'
  3515. ? 'expected \'' + arg + '\' got \'' + parserInput.currentChar() + '\''
  3516. : 'unexpected token'));
  3517. }
  3518. // Specialization of expect()
  3519. function expectChar(arg, msg) {
  3520. if (parserInput.$char(arg)) {
  3521. return arg;
  3522. }
  3523. error(msg || 'expected \'' + arg + '\' got \'' + parserInput.currentChar() + '\'');
  3524. }
  3525. function getDebugInfo(index) {
  3526. var filename = fileInfo.filename;
  3527. return {
  3528. lineNumber: utils.getLocation(index, parserInput.getInput()).line + 1,
  3529. fileName: filename
  3530. };
  3531. }
  3532. /**
  3533. * Used after initial parsing to create nodes on the fly
  3534. *
  3535. * @param {String} str - string to parse
  3536. * @param {Array} parseList - array of parsers to run input through e.g. ["value", "important"]
  3537. * @param {Number} currentIndex - start number to begin indexing
  3538. * @param {Object} fileInfo - fileInfo to attach to created nodes
  3539. */
  3540. function parseNode(str, parseList, currentIndex, fileInfo, callback) {
  3541. var result, returnNodes = [];
  3542. var parser = parserInput;
  3543. try {
  3544. parser.start(str, false, function fail(msg, index) {
  3545. callback({
  3546. message: msg,
  3547. index: index + currentIndex
  3548. });
  3549. });
  3550. for (var x = 0, p, i; (p = parseList[x]); x++) {
  3551. i = parser.i;
  3552. result = parsers[p]();
  3553. if (result) {
  3554. result._index = i + currentIndex;
  3555. result._fileInfo = fileInfo;
  3556. returnNodes.push(result);
  3557. }
  3558. else {
  3559. returnNodes.push(null);
  3560. }
  3561. }
  3562. var endInfo = parser.end();
  3563. if (endInfo.isFinished) {
  3564. callback(null, returnNodes);
  3565. }
  3566. else {
  3567. callback(true, null);
  3568. }
  3569. } catch (e) {
  3570. throw new LessError({
  3571. index: e.index + currentIndex,
  3572. message: e.message
  3573. }, imports, fileInfo.filename);
  3574. }
  3575. }
  3576. //
  3577. // The Parser
  3578. //
  3579. return {
  3580. parserInput: parserInput,
  3581. imports: imports,
  3582. fileInfo: fileInfo,
  3583. parseNode: parseNode,
  3584. //
  3585. // Parse an input string into an abstract syntax tree,
  3586. // @param str A string containing 'less' markup
  3587. // @param callback call `callback` when done.
  3588. // @param [additionalData] An optional map which can contains vars - a map (key, value) of variables to apply
  3589. //
  3590. parse: function (str, callback, additionalData) {
  3591. var root, error = null, globalVars, modifyVars, ignored, preText = '';
  3592. globalVars = (additionalData && additionalData.globalVars) ? Parser.serializeVars(additionalData.globalVars) + '\n' : '';
  3593. modifyVars = (additionalData && additionalData.modifyVars) ? '\n' + Parser.serializeVars(additionalData.modifyVars) : '';
  3594. if (context.pluginManager) {
  3595. var preProcessors = context.pluginManager.getPreProcessors();
  3596. for (var i = 0; i < preProcessors.length; i++) {
  3597. str = preProcessors[i].process(str, { context: context, imports: imports, fileInfo: fileInfo });
  3598. }
  3599. }
  3600. if (globalVars || (additionalData && additionalData.banner)) {
  3601. preText = ((additionalData && additionalData.banner) ? additionalData.banner : '') + globalVars;
  3602. ignored = imports.contentsIgnoredChars;
  3603. ignored[fileInfo.filename] = ignored[fileInfo.filename] || 0;
  3604. ignored[fileInfo.filename] += preText.length;
  3605. }
  3606. str = str.replace(/\r\n?/g, '\n');
  3607. // Remove potential UTF Byte Order Mark
  3608. str = preText + str.replace(/^\uFEFF/, '') + modifyVars;
  3609. imports.contents[fileInfo.filename] = str;
  3610. // Start with the primary rule.
  3611. // The whole syntax tree is held under a Ruleset node,
  3612. // with the `root` property set to true, so no `{}` are
  3613. // output. The callback is called when the input is parsed.
  3614. try {
  3615. parserInput.start(str, context.chunkInput, function fail(msg, index) {
  3616. throw new LessError({
  3617. index: index,
  3618. type: 'Parse',
  3619. message: msg,
  3620. filename: fileInfo.filename
  3621. }, imports);
  3622. });
  3623. tree.Node.prototype.parse = this;
  3624. root = new tree.Ruleset(null, this.parsers.primary());
  3625. tree.Node.prototype.rootNode = root;
  3626. root.root = true;
  3627. root.firstRoot = true;
  3628. root.functionRegistry = functionRegistry.inherit();
  3629. } catch (e) {
  3630. return callback(new LessError(e, imports, fileInfo.filename));
  3631. }
  3632. // If `i` is smaller than the `input.length - 1`,
  3633. // it means the parser wasn't able to parse the whole
  3634. // string, so we've got a parsing error.
  3635. //
  3636. // We try to extract a \n delimited string,
  3637. // showing the line where the parse error occurred.
  3638. // We split it up into two parts (the part which parsed,
  3639. // and the part which didn't), so we can color them differently.
  3640. var endInfo = parserInput.end();
  3641. if (!endInfo.isFinished) {
  3642. var message = endInfo.furthestPossibleErrorMessage;
  3643. if (!message) {
  3644. message = 'Unrecognised input';
  3645. if (endInfo.furthestChar === '}') {
  3646. message += '. Possibly missing opening \'{\'';
  3647. } else if (endInfo.furthestChar === ')') {
  3648. message += '. Possibly missing opening \'(\'';
  3649. } else if (endInfo.furthestReachedEnd) {
  3650. message += '. Possibly missing something';
  3651. }
  3652. }
  3653. error = new LessError({
  3654. type: 'Parse',
  3655. message: message,
  3656. index: endInfo.furthest,
  3657. filename: fileInfo.filename
  3658. }, imports);
  3659. }
  3660. var finish = function (e) {
  3661. e = error || e || imports.error;
  3662. if (e) {
  3663. if (!(e instanceof LessError)) {
  3664. e = new LessError(e, imports, fileInfo.filename);
  3665. }
  3666. return callback(e);
  3667. }
  3668. else {
  3669. return callback(null, root);
  3670. }
  3671. };
  3672. if (context.processImports !== false) {
  3673. new visitors.ImportVisitor(imports, finish)
  3674. .run(root);
  3675. } else {
  3676. return finish();
  3677. }
  3678. },
  3679. //
  3680. // Here in, the parsing rules/functions
  3681. //
  3682. // The basic structure of the syntax tree generated is as follows:
  3683. //
  3684. // Ruleset -> Declaration -> Value -> Expression -> Entity
  3685. //
  3686. // Here's some Less code:
  3687. //
  3688. // .class {
  3689. // color: #fff;
  3690. // border: 1px solid #000;
  3691. // width: @w + 4px;
  3692. // > .child {...}
  3693. // }
  3694. //
  3695. // And here's what the parse tree might look like:
  3696. //
  3697. // Ruleset (Selector '.class', [
  3698. // Declaration ("color", Value ([Expression [Color #fff]]))
  3699. // Declaration ("border", Value ([Expression [Dimension 1px][Keyword "solid"][Color #000]]))
  3700. // Declaration ("width", Value ([Expression [Operation " + " [Variable "@w"][Dimension 4px]]]))
  3701. // Ruleset (Selector [Element '>', '.child'], [...])
  3702. // ])
  3703. //
  3704. // In general, most rules will try to parse a token with the `$re()` function, and if the return
  3705. // value is truly, will return a new node, of the relevant type. Sometimes, we need to check
  3706. // first, before parsing, that's when we use `peek()`.
  3707. //
  3708. parsers: parsers = {
  3709. //
  3710. // The `primary` rule is the *entry* and *exit* point of the parser.
  3711. // The rules here can appear at any level of the parse tree.
  3712. //
  3713. // The recursive nature of the grammar is an interplay between the `block`
  3714. // rule, which represents `{ ... }`, the `ruleset` rule, and this `primary` rule,
  3715. // as represented by this simplified grammar:
  3716. //
  3717. // primary → (ruleset | declaration)+
  3718. // ruleset → selector+ block
  3719. // block → '{' primary '}'
  3720. //
  3721. // Only at one point is the primary rule not called from the
  3722. // block rule: at the root level.
  3723. //
  3724. primary: function () {
  3725. var mixin = this.mixin, root = [], node;
  3726. while (true) {
  3727. while (true) {
  3728. node = this.comment();
  3729. if (!node) { break; }
  3730. root.push(node);
  3731. }
  3732. // always process comments before deciding if finished
  3733. if (parserInput.finished) {
  3734. break;
  3735. }
  3736. if (parserInput.peek('}')) {
  3737. break;
  3738. }
  3739. node = this.extendRule();
  3740. if (node) {
  3741. root = root.concat(node);
  3742. continue;
  3743. }
  3744. node = mixin.definition() || this.declaration() || this.ruleset() ||
  3745. mixin.call(false, false) || this.variableCall() || this.entities.call() || this.atrule();
  3746. if (node) {
  3747. root.push(node);
  3748. } else {
  3749. var foundSemiColon = false;
  3750. while (parserInput.$char(';')) {
  3751. foundSemiColon = true;
  3752. }
  3753. if (!foundSemiColon) {
  3754. break;
  3755. }
  3756. }
  3757. }
  3758. return root;
  3759. },
  3760. // comments are collected by the main parsing mechanism and then assigned to nodes
  3761. // where the current structure allows it
  3762. comment: function () {
  3763. if (parserInput.commentStore.length) {
  3764. var comment = parserInput.commentStore.shift();
  3765. return new(tree.Comment)(comment.text, comment.isLineComment, comment.index, fileInfo);
  3766. }
  3767. },
  3768. //
  3769. // Entities are tokens which can be found inside an Expression
  3770. //
  3771. entities: {
  3772. mixinLookup: function() {
  3773. return parsers.mixin.call(true, true);
  3774. },
  3775. //
  3776. // A string, which supports escaping " and '
  3777. //
  3778. // "milky way" 'he\'s the one!'
  3779. //
  3780. quoted: function (forceEscaped) {
  3781. var str, index = parserInput.i, isEscaped = false;
  3782. parserInput.save();
  3783. if (parserInput.$char('~')) {
  3784. isEscaped = true;
  3785. } else if (forceEscaped) {
  3786. parserInput.restore();
  3787. return;
  3788. }
  3789. str = parserInput.$quoted();
  3790. if (!str) {
  3791. parserInput.restore();
  3792. return;
  3793. }
  3794. parserInput.forget();
  3795. return new(tree.Quoted)(str.charAt(0), str.substr(1, str.length - 2), isEscaped, index, fileInfo);
  3796. },
  3797. //
  3798. // A catch-all word, such as:
  3799. //
  3800. // black border-collapse
  3801. //
  3802. keyword: function () {
  3803. var k = parserInput.$char('%') || parserInput.$re(/^\[?(?:[\w-]|\\(?:[A-Fa-f0-9]{1,6} ?|[^A-Fa-f0-9]))+\]?/);
  3804. if (k) {
  3805. return tree.Color.fromKeyword(k) || new(tree.Keyword)(k);
  3806. }
  3807. },
  3808. //
  3809. // A function call
  3810. //
  3811. // rgb(255, 0, 255)
  3812. //
  3813. // The arguments are parsed with the `entities.arguments` parser.
  3814. //
  3815. call: function () {
  3816. var name, args, func, index = parserInput.i;
  3817. // http://jsperf.com/case-insensitive-regex-vs-strtolower-then-regex/18
  3818. if (parserInput.peek(/^url\(/i)) {
  3819. return;
  3820. }
  3821. parserInput.save();
  3822. name = parserInput.$re(/^([\w-]+|%|progid:[\w\.]+)\(/);
  3823. if (!name) {
  3824. parserInput.forget();
  3825. return;
  3826. }
  3827. name = name[1];
  3828. func = this.customFuncCall(name);
  3829. if (func) {
  3830. args = func.parse();
  3831. if (args && func.stop) {
  3832. parserInput.forget();
  3833. return args;
  3834. }
  3835. }
  3836. args = this.arguments(args);
  3837. if (!parserInput.$char(')')) {
  3838. parserInput.restore('Could not parse call arguments or missing \')\'');
  3839. return;
  3840. }
  3841. parserInput.forget();
  3842. return new(tree.Call)(name, args, index, fileInfo);
  3843. },
  3844. //
  3845. // Parsing rules for functions with non-standard args, e.g.:
  3846. //
  3847. // boolean(not(2 > 1))
  3848. //
  3849. // This is a quick prototype, to be modified/improved when
  3850. // more custom-parsed funcs come (e.g. `selector(...)`)
  3851. //
  3852. customFuncCall: function (name) {
  3853. /* Ideally the table is to be moved out of here for faster perf.,
  3854. but it's quite tricky since it relies on all these `parsers`
  3855. and `expect` available only here */
  3856. return {
  3857. alpha: f(parsers.ieAlpha, true),
  3858. boolean: f(condition),
  3859. 'if': f(condition)
  3860. }[name.toLowerCase()];
  3861. function f(parse, stop) {
  3862. return {
  3863. parse: parse, // parsing function
  3864. stop: stop // when true - stop after parse() and return its result,
  3865. // otherwise continue for plain args
  3866. };
  3867. }
  3868. function condition() {
  3869. return [expect(parsers.condition, 'expected condition')];
  3870. }
  3871. },
  3872. arguments: function (prevArgs) {
  3873. var argsComma = prevArgs || [],
  3874. argsSemiColon = [],
  3875. isSemiColonSeparated, value;
  3876. parserInput.save();
  3877. while (true) {
  3878. if (prevArgs) {
  3879. prevArgs = false;
  3880. } else {
  3881. value = parsers.detachedRuleset() || this.assignment() || parsers.expression();
  3882. if (!value) {
  3883. break;
  3884. }
  3885. if (value.value && value.value.length == 1) {
  3886. value = value.value[0];
  3887. }
  3888. argsComma.push(value);
  3889. }
  3890. if (parserInput.$char(',')) {
  3891. continue;
  3892. }
  3893. if (parserInput.$char(';') || isSemiColonSeparated) {
  3894. isSemiColonSeparated = true;
  3895. value = (argsComma.length < 1) ? argsComma[0]
  3896. : new tree.Value(argsComma);
  3897. argsSemiColon.push(value);
  3898. argsComma = [];
  3899. }
  3900. }
  3901. parserInput.forget();
  3902. return isSemiColonSeparated ? argsSemiColon : argsComma;
  3903. },
  3904. literal: function () {
  3905. return this.dimension() ||
  3906. this.color() ||
  3907. this.quoted() ||
  3908. this.unicodeDescriptor();
  3909. },
  3910. // Assignments are argument entities for calls.
  3911. // They are present in ie filter properties as shown below.
  3912. //
  3913. // filter: progid:DXImageTransform.Microsoft.Alpha( *opacity=50* )
  3914. //
  3915. assignment: function () {
  3916. var key, value;
  3917. parserInput.save();
  3918. key = parserInput.$re(/^\w+(?=\s?=)/i);
  3919. if (!key) {
  3920. parserInput.restore();
  3921. return;
  3922. }
  3923. if (!parserInput.$char('=')) {
  3924. parserInput.restore();
  3925. return;
  3926. }
  3927. value = parsers.entity();
  3928. if (value) {
  3929. parserInput.forget();
  3930. return new(tree.Assignment)(key, value);
  3931. } else {
  3932. parserInput.restore();
  3933. }
  3934. },
  3935. //
  3936. // Parse url() tokens
  3937. //
  3938. // We use a specific rule for urls, because they don't really behave like
  3939. // standard function calls. The difference is that the argument doesn't have
  3940. // to be enclosed within a string, so it can't be parsed as an Expression.
  3941. //
  3942. url: function () {
  3943. var value, index = parserInput.i;
  3944. parserInput.autoCommentAbsorb = false;
  3945. if (!parserInput.$str('url(')) {
  3946. parserInput.autoCommentAbsorb = true;
  3947. return;
  3948. }
  3949. value = this.quoted() || this.variable() || this.property() ||
  3950. parserInput.$re(/^(?:(?:\\[\(\)'"])|[^\(\)'"])+/) || '';
  3951. parserInput.autoCommentAbsorb = true;
  3952. expectChar(')');
  3953. return new(tree.URL)((value.value != null ||
  3954. value instanceof tree.Variable ||
  3955. value instanceof tree.Property) ?
  3956. value : new(tree.Anonymous)(value, index), index, fileInfo);
  3957. },
  3958. //
  3959. // A Variable entity, such as `@fink`, in
  3960. //
  3961. // width: @fink + 2px
  3962. //
  3963. // We use a different parser for variable definitions,
  3964. // see `parsers.variable`.
  3965. //
  3966. variable: function () {
  3967. var ch, name, index = parserInput.i;
  3968. parserInput.save();
  3969. if (parserInput.currentChar() === '@' && (name = parserInput.$re(/^@@?[\w-]+/))) {
  3970. ch = parserInput.currentChar();
  3971. if (ch === '(' || ch === '[' && !parserInput.prevChar().match(/^\s/)) {
  3972. // this may be a VariableCall lookup
  3973. var result = parsers.variableCall(name);
  3974. if (result) {
  3975. parserInput.forget();
  3976. return result;
  3977. }
  3978. }
  3979. parserInput.forget();
  3980. return new(tree.Variable)(name, index, fileInfo);
  3981. }
  3982. parserInput.restore();
  3983. },
  3984. // A variable entity using the protective {} e.g. @{var}
  3985. variableCurly: function () {
  3986. var curly, index = parserInput.i;
  3987. if (parserInput.currentChar() === '@' && (curly = parserInput.$re(/^@\{([\w-]+)\}/))) {
  3988. return new(tree.Variable)('@' + curly[1], index, fileInfo);
  3989. }
  3990. },
  3991. //
  3992. // A Property accessor, such as `$color`, in
  3993. //
  3994. // background-color: $color
  3995. //
  3996. property: function () {
  3997. var name, index = parserInput.i;
  3998. if (parserInput.currentChar() === '$' && (name = parserInput.$re(/^\$[\w-]+/))) {
  3999. return new(tree.Property)(name, index, fileInfo);
  4000. }
  4001. },
  4002. // A property entity useing the protective {} e.g. ${prop}
  4003. propertyCurly: function () {
  4004. var curly, index = parserInput.i;
  4005. if (parserInput.currentChar() === '$' && (curly = parserInput.$re(/^\$\{([\w-]+)\}/))) {
  4006. return new(tree.Property)('$' + curly[1], index, fileInfo);
  4007. }
  4008. },
  4009. //
  4010. // A Hexadecimal color
  4011. //
  4012. // #4F3C2F
  4013. //
  4014. // `rgb` and `hsl` colors are parsed through the `entities.call` parser.
  4015. //
  4016. color: function () {
  4017. var rgb;
  4018. if (parserInput.currentChar() === '#' && (rgb = parserInput.$re(/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})/))) {
  4019. // strip colons, brackets, whitespaces and other characters that should not
  4020. // definitely be part of color string
  4021. var colorCandidateString = rgb.input.match(/^#([\w]+).*/);
  4022. colorCandidateString = colorCandidateString[1];
  4023. if (!colorCandidateString.match(/^[A-Fa-f0-9]+$/)) { // verify if candidate consists only of allowed HEX characters
  4024. error('Invalid HEX color code');
  4025. }
  4026. return new(tree.Color)(rgb[1], undefined, '#' + colorCandidateString);
  4027. }
  4028. },
  4029. colorKeyword: function () {
  4030. parserInput.save();
  4031. var autoCommentAbsorb = parserInput.autoCommentAbsorb;
  4032. parserInput.autoCommentAbsorb = false;
  4033. var k = parserInput.$re(/^[_A-Za-z-][_A-Za-z0-9-]+/);
  4034. parserInput.autoCommentAbsorb = autoCommentAbsorb;
  4035. if (!k) {
  4036. parserInput.forget();
  4037. return;
  4038. }
  4039. parserInput.restore();
  4040. var color = tree.Color.fromKeyword(k);
  4041. if (color) {
  4042. parserInput.$str(k);
  4043. return color;
  4044. }
  4045. },
  4046. //
  4047. // A Dimension, that is, a number and a unit
  4048. //
  4049. // 0.5em 95%
  4050. //
  4051. dimension: function () {
  4052. if (parserInput.peekNotNumeric()) {
  4053. return;
  4054. }
  4055. var value = parserInput.$re(/^([+-]?\d*\.?\d+)(%|[a-z_]+)?/i);
  4056. if (value) {
  4057. return new(tree.Dimension)(value[1], value[2]);
  4058. }
  4059. },
  4060. //
  4061. // A unicode descriptor, as is used in unicode-range
  4062. //
  4063. // U+0?? or U+00A1-00A9
  4064. //
  4065. unicodeDescriptor: function () {
  4066. var ud;
  4067. ud = parserInput.$re(/^U\+[0-9a-fA-F?]+(\-[0-9a-fA-F?]+)?/);
  4068. if (ud) {
  4069. return new(tree.UnicodeDescriptor)(ud[0]);
  4070. }
  4071. },
  4072. //
  4073. // JavaScript code to be evaluated
  4074. //
  4075. // `window.location.href`
  4076. //
  4077. javascript: function () {
  4078. var js, index = parserInput.i;
  4079. parserInput.save();
  4080. var escape = parserInput.$char('~');
  4081. var jsQuote = parserInput.$char('`');
  4082. if (!jsQuote) {
  4083. parserInput.restore();
  4084. return;
  4085. }
  4086. js = parserInput.$re(/^[^`]*`/);
  4087. if (js) {
  4088. parserInput.forget();
  4089. return new(tree.JavaScript)(js.substr(0, js.length - 1), Boolean(escape), index, fileInfo);
  4090. }
  4091. parserInput.restore('invalid javascript definition');
  4092. }
  4093. },
  4094. //
  4095. // The variable part of a variable definition. Used in the `rule` parser
  4096. //
  4097. // @fink:
  4098. //
  4099. variable: function () {
  4100. var name;
  4101. if (parserInput.currentChar() === '@' && (name = parserInput.$re(/^(@[\w-]+)\s*:/))) { return name[1]; }
  4102. },
  4103. //
  4104. // Call a variable value to retrieve a detached ruleset
  4105. // or a value from a detached ruleset's rules.
  4106. //
  4107. // @fink();
  4108. // @fink;
  4109. // color: @fink[@color];
  4110. //
  4111. variableCall: function (parsedName) {
  4112. var lookups, important, i = parserInput.i,
  4113. inValue = !!parsedName, name = parsedName;
  4114. parserInput.save();
  4115. if (name || (parserInput.currentChar() === '@'
  4116. && (name = parserInput.$re(/^(@[\w-]+)(\(\s*\))?/)))) {
  4117. lookups = this.mixin.ruleLookups();
  4118. if (!lookups && ((inValue && parserInput.$str('()') !== '()') || (name[2] !== '()'))) {
  4119. parserInput.restore('Missing \'[...]\' lookup in variable call');
  4120. return;
  4121. }
  4122. if (!inValue) {
  4123. name = name[1];
  4124. }
  4125. if (lookups && parsers.important()) {
  4126. important = true;
  4127. }
  4128. var call = new tree.VariableCall(name, i, fileInfo);
  4129. if (!inValue && parsers.end()) {
  4130. parserInput.forget();
  4131. return call;
  4132. }
  4133. else {
  4134. parserInput.forget();
  4135. return new tree.NamespaceValue(call, lookups, important, i, fileInfo);
  4136. }
  4137. }
  4138. parserInput.restore();
  4139. },
  4140. //
  4141. // extend syntax - used to extend selectors
  4142. //
  4143. extend: function(isRule) {
  4144. var elements, e, index = parserInput.i, option, extendList, extend;
  4145. if (!parserInput.$str(isRule ? '&:extend(' : ':extend(')) {
  4146. return;
  4147. }
  4148. do {
  4149. option = null;
  4150. elements = null;
  4151. while (!(option = parserInput.$re(/^(all)(?=\s*(\)|,))/))) {
  4152. e = this.element();
  4153. if (!e) {
  4154. break;
  4155. }
  4156. if (elements) {
  4157. elements.push(e);
  4158. } else {
  4159. elements = [ e ];
  4160. }
  4161. }
  4162. option = option && option[1];
  4163. if (!elements) {
  4164. error('Missing target selector for :extend().');
  4165. }
  4166. extend = new(tree.Extend)(new(tree.Selector)(elements), option, index, fileInfo);
  4167. if (extendList) {
  4168. extendList.push(extend);
  4169. } else {
  4170. extendList = [ extend ];
  4171. }
  4172. } while (parserInput.$char(','));
  4173. expect(/^\)/);
  4174. if (isRule) {
  4175. expect(/^;/);
  4176. }
  4177. return extendList;
  4178. },
  4179. //
  4180. // extendRule - used in a rule to extend all the parent selectors
  4181. //
  4182. extendRule: function() {
  4183. return this.extend(true);
  4184. },
  4185. //
  4186. // Mixins
  4187. //
  4188. mixin: {
  4189. //
  4190. // A Mixin call, with an optional argument list
  4191. //
  4192. // #mixins > .square(#fff);
  4193. // #mixins.square(#fff);
  4194. // .rounded(4px, black);
  4195. // .button;
  4196. //
  4197. // We can lookup / return a value using the lookup syntax:
  4198. //
  4199. // color: #mixin.square(#fff)[@color];
  4200. //
  4201. // The `while` loop is there because mixins can be
  4202. // namespaced, but we only support the child and descendant
  4203. // selector for now.
  4204. //
  4205. call: function (inValue, getLookup) {
  4206. var s = parserInput.currentChar(), important = false, lookups,
  4207. index = parserInput.i, elements, args, hasParens;
  4208. if (s !== '.' && s !== '#') { return; }
  4209. parserInput.save(); // stop us absorbing part of an invalid selector
  4210. elements = this.elements();
  4211. if (elements) {
  4212. if (parserInput.$char('(')) {
  4213. args = this.args(true).args;
  4214. expectChar(')');
  4215. hasParens = true;
  4216. }
  4217. if (getLookup !== false) {
  4218. lookups = this.ruleLookups();
  4219. }
  4220. if (getLookup === true && !lookups) {
  4221. parserInput.restore();
  4222. return;
  4223. }
  4224. if (inValue && !lookups && !hasParens) {
  4225. // This isn't a valid in-value mixin call
  4226. parserInput.restore();
  4227. return;
  4228. }
  4229. if (!inValue && parsers.important()) {
  4230. important = true;
  4231. }
  4232. if (inValue || parsers.end()) {
  4233. parserInput.forget();
  4234. var mixin = new(tree.mixin.Call)(elements, args, index, fileInfo, !lookups && important);
  4235. if (lookups) {
  4236. return new tree.NamespaceValue(mixin, lookups, important);
  4237. }
  4238. else {
  4239. return mixin;
  4240. }
  4241. }
  4242. }
  4243. parserInput.restore();
  4244. },
  4245. /**
  4246. * Matching elements for mixins
  4247. * (Start with . or # and can have > )
  4248. */
  4249. elements: function() {
  4250. var elements, e, c, elem, elemIndex,
  4251. re = /^[#.](?:[\w-]|\\(?:[A-Fa-f0-9]{1,6} ?|[^A-Fa-f0-9]))+/;
  4252. while (true) {
  4253. elemIndex = parserInput.i;
  4254. e = parserInput.$re(re);
  4255. if (!e) {
  4256. break;
  4257. }
  4258. elem = new(tree.Element)(c, e, false, elemIndex, fileInfo);
  4259. if (elements) {
  4260. elements.push(elem);
  4261. } else {
  4262. elements = [ elem ];
  4263. }
  4264. c = parserInput.$char('>');
  4265. }
  4266. return elements;
  4267. },
  4268. args: function (isCall) {
  4269. var entities = parsers.entities,
  4270. returner = { args:null, variadic: false },
  4271. expressions = [], argsSemiColon = [], argsComma = [],
  4272. isSemiColonSeparated, expressionContainsNamed, name, nameLoop,
  4273. value, arg, expand, hasSep = true;
  4274. parserInput.save();
  4275. while (true) {
  4276. if (isCall) {
  4277. arg = parsers.detachedRuleset() || parsers.expression();
  4278. } else {
  4279. parserInput.commentStore.length = 0;
  4280. if (parserInput.$str('...')) {
  4281. returner.variadic = true;
  4282. if (parserInput.$char(';') && !isSemiColonSeparated) {
  4283. isSemiColonSeparated = true;
  4284. }
  4285. (isSemiColonSeparated ? argsSemiColon : argsComma)
  4286. .push({ variadic: true });
  4287. break;
  4288. }
  4289. arg = entities.variable() || entities.property() || entities.literal() || entities.keyword() || this.call(true);
  4290. }
  4291. if (!arg || !hasSep) {
  4292. break;
  4293. }
  4294. nameLoop = null;
  4295. if (arg.throwAwayComments) {
  4296. arg.throwAwayComments();
  4297. }
  4298. value = arg;
  4299. var val = null;
  4300. if (isCall) {
  4301. // Variable
  4302. if (arg.value && arg.value.length == 1) {
  4303. val = arg.value[0];
  4304. }
  4305. } else {
  4306. val = arg;
  4307. }
  4308. if (val && (val instanceof tree.Variable || val instanceof tree.Property)) {
  4309. if (parserInput.$char(':')) {
  4310. if (expressions.length > 0) {
  4311. if (isSemiColonSeparated) {
  4312. error('Cannot mix ; and , as delimiter types');
  4313. }
  4314. expressionContainsNamed = true;
  4315. }
  4316. value = parsers.detachedRuleset() || parsers.expression();
  4317. if (!value) {
  4318. if (isCall) {
  4319. error('could not understand value for named argument');
  4320. } else {
  4321. parserInput.restore();
  4322. returner.args = [];
  4323. return returner;
  4324. }
  4325. }
  4326. nameLoop = (name = val.name);
  4327. } else if (parserInput.$str('...')) {
  4328. if (!isCall) {
  4329. returner.variadic = true;
  4330. if (parserInput.$char(';') && !isSemiColonSeparated) {
  4331. isSemiColonSeparated = true;
  4332. }
  4333. (isSemiColonSeparated ? argsSemiColon : argsComma)
  4334. .push({ name: arg.name, variadic: true });
  4335. break;
  4336. } else {
  4337. expand = true;
  4338. }
  4339. } else if (!isCall) {
  4340. name = nameLoop = val.name;
  4341. value = null;
  4342. }
  4343. }
  4344. if (value) {
  4345. expressions.push(value);
  4346. }
  4347. argsComma.push({ name:nameLoop, value:value, expand:expand });
  4348. if (parserInput.$char(',')) {
  4349. hasSep = true;
  4350. continue;
  4351. }
  4352. hasSep = parserInput.$char(';') === ';';
  4353. if (hasSep || isSemiColonSeparated) {
  4354. if (expressionContainsNamed) {
  4355. error('Cannot mix ; and , as delimiter types');
  4356. }
  4357. isSemiColonSeparated = true;
  4358. if (expressions.length > 1) {
  4359. value = new(tree.Value)(expressions);
  4360. }
  4361. argsSemiColon.push({ name:name, value:value, expand:expand });
  4362. name = null;
  4363. expressions = [];
  4364. expressionContainsNamed = false;
  4365. }
  4366. }
  4367. parserInput.forget();
  4368. returner.args = isSemiColonSeparated ? argsSemiColon : argsComma;
  4369. return returner;
  4370. },
  4371. //
  4372. // A Mixin definition, with a list of parameters
  4373. //
  4374. // .rounded (@radius: 2px, @color) {
  4375. // ...
  4376. // }
  4377. //
  4378. // Until we have a finer grained state-machine, we have to
  4379. // do a look-ahead, to make sure we don't have a mixin call.
  4380. // See the `rule` function for more information.
  4381. //
  4382. // We start by matching `.rounded (`, and then proceed on to
  4383. // the argument list, which has optional default values.
  4384. // We store the parameters in `params`, with a `value` key,
  4385. // if there is a value, such as in the case of `@radius`.
  4386. //
  4387. // Once we've got our params list, and a closing `)`, we parse
  4388. // the `{...}` block.
  4389. //
  4390. definition: function () {
  4391. var name, params = [], match, ruleset, cond, variadic = false;
  4392. if ((parserInput.currentChar() !== '.' && parserInput.currentChar() !== '#') ||
  4393. parserInput.peek(/^[^{]*\}/)) {
  4394. return;
  4395. }
  4396. parserInput.save();
  4397. match = parserInput.$re(/^([#.](?:[\w-]|\\(?:[A-Fa-f0-9]{1,6} ?|[^A-Fa-f0-9]))+)\s*\(/);
  4398. if (match) {
  4399. name = match[1];
  4400. var argInfo = this.args(false);
  4401. params = argInfo.args;
  4402. variadic = argInfo.variadic;
  4403. // .mixincall("@{a}");
  4404. // looks a bit like a mixin definition..
  4405. // also
  4406. // .mixincall(@a: {rule: set;});
  4407. // so we have to be nice and restore
  4408. if (!parserInput.$char(')')) {
  4409. parserInput.restore('Missing closing \')\'');
  4410. return;
  4411. }
  4412. parserInput.commentStore.length = 0;
  4413. if (parserInput.$str('when')) { // Guard
  4414. cond = expect(parsers.conditions, 'expected condition');
  4415. }
  4416. ruleset = parsers.block();
  4417. if (ruleset) {
  4418. parserInput.forget();
  4419. return new(tree.mixin.Definition)(name, params, ruleset, cond, variadic);
  4420. } else {
  4421. parserInput.restore();
  4422. }
  4423. } else {
  4424. parserInput.forget();
  4425. }
  4426. },
  4427. ruleLookups: function() {
  4428. var rule, args, lookups = [];
  4429. if (parserInput.currentChar() !== '[') {
  4430. return;
  4431. }
  4432. while (true) {
  4433. parserInput.save();
  4434. args = null;
  4435. rule = this.lookupValue();
  4436. if (!rule && rule !== '') {
  4437. parserInput.restore();
  4438. break;
  4439. }
  4440. lookups.push(rule);
  4441. parserInput.forget();
  4442. }
  4443. if (lookups.length > 0) {
  4444. return lookups;
  4445. }
  4446. },
  4447. lookupValue: function() {
  4448. parserInput.save();
  4449. if (!parserInput.$char('[')) {
  4450. parserInput.restore();
  4451. return;
  4452. }
  4453. var name = parserInput.$re(/^(?:[@$]{0,2})[_a-zA-Z0-9-]*/);
  4454. if (!parserInput.$char(']')) {
  4455. parserInput.restore();
  4456. return;
  4457. }
  4458. if (name || name === '') {
  4459. parserInput.forget();
  4460. return name;
  4461. }
  4462. parserInput.restore();
  4463. }
  4464. },
  4465. //
  4466. // Entities are the smallest recognized token,
  4467. // and can be found inside a rule's value.
  4468. //
  4469. entity: function () {
  4470. var entities = this.entities;
  4471. return this.comment() || entities.literal() || entities.variable() || entities.url() ||
  4472. entities.property() || entities.call() || entities.keyword() || this.mixin.call(true) ||
  4473. entities.javascript();
  4474. },
  4475. //
  4476. // A Declaration terminator. Note that we use `peek()` to check for '}',
  4477. // because the `block` rule will be expecting it, but we still need to make sure
  4478. // it's there, if ';' was omitted.
  4479. //
  4480. end: function () {
  4481. return parserInput.$char(';') || parserInput.peek('}');
  4482. },
  4483. //
  4484. // IE's alpha function
  4485. //
  4486. // alpha(opacity=88)
  4487. //
  4488. ieAlpha: function () {
  4489. var value;
  4490. // http://jsperf.com/case-insensitive-regex-vs-strtolower-then-regex/18
  4491. if (!parserInput.$re(/^opacity=/i)) { return; }
  4492. value = parserInput.$re(/^\d+/);
  4493. if (!value) {
  4494. value = expect(parsers.entities.variable, 'Could not parse alpha');
  4495. value = '@{' + value.name.slice(1) + '}';
  4496. }
  4497. expectChar(')');
  4498. return new tree.Quoted('', 'alpha(opacity=' + value + ')');
  4499. },
  4500. //
  4501. // A Selector Element
  4502. //
  4503. // div
  4504. // + h1
  4505. // #socks
  4506. // input[type="text"]
  4507. //
  4508. // Elements are the building blocks for Selectors,
  4509. // they are made out of a `Combinator` (see combinator rule),
  4510. // and an element name, such as a tag a class, or `*`.
  4511. //
  4512. element: function () {
  4513. var e, c, v, index = parserInput.i;
  4514. c = this.combinator();
  4515. e = parserInput.$re(/^(?:\d+\.\d+|\d+)%/) ||
  4516. parserInput.$re(/^(?:[.#]?|:*)(?:[\w-]|[^\x00-\x9f]|\\(?:[A-Fa-f0-9]{1,6} ?|[^A-Fa-f0-9]))+/) ||
  4517. parserInput.$char('*') || parserInput.$char('&') || this.attribute() ||
  4518. parserInput.$re(/^\([^&()@]+\)/) || parserInput.$re(/^[\.#:](?=@)/) ||
  4519. this.entities.variableCurly();
  4520. if (!e) {
  4521. parserInput.save();
  4522. if (parserInput.$char('(')) {
  4523. if ((v = this.selector(false)) && parserInput.$char(')')) {
  4524. e = new(tree.Paren)(v);
  4525. parserInput.forget();
  4526. } else {
  4527. parserInput.restore('Missing closing \')\'');
  4528. }
  4529. } else {
  4530. parserInput.forget();
  4531. }
  4532. }
  4533. if (e) { return new(tree.Element)(c, e, e instanceof tree.Variable, index, fileInfo); }
  4534. },
  4535. //
  4536. // Combinators combine elements together, in a Selector.
  4537. //
  4538. // Because our parser isn't white-space sensitive, special care
  4539. // has to be taken, when parsing the descendant combinator, ` `,
  4540. // as it's an empty space. We have to check the previous character
  4541. // in the input, to see if it's a ` ` character. More info on how
  4542. // we deal with this in *combinator.js*.
  4543. //
  4544. combinator: function () {
  4545. var c = parserInput.currentChar();
  4546. if (c === '/') {
  4547. parserInput.save();
  4548. var slashedCombinator = parserInput.$re(/^\/[a-z]+\//i);
  4549. if (slashedCombinator) {
  4550. parserInput.forget();
  4551. return new(tree.Combinator)(slashedCombinator);
  4552. }
  4553. parserInput.restore();
  4554. }
  4555. if (c === '>' || c === '+' || c === '~' || c === '|' || c === '^') {
  4556. parserInput.i++;
  4557. if (c === '^' && parserInput.currentChar() === '^') {
  4558. c = '^^';
  4559. parserInput.i++;
  4560. }
  4561. while (parserInput.isWhitespace()) { parserInput.i++; }
  4562. return new(tree.Combinator)(c);
  4563. } else if (parserInput.isWhitespace(-1)) {
  4564. return new(tree.Combinator)(' ');
  4565. } else {
  4566. return new(tree.Combinator)(null);
  4567. }
  4568. },
  4569. //
  4570. // A CSS Selector
  4571. // with less extensions e.g. the ability to extend and guard
  4572. //
  4573. // .class > div + h1
  4574. // li a:hover
  4575. //
  4576. // Selectors are made out of one or more Elements, see above.
  4577. //
  4578. selector: function (isLess) {
  4579. var index = parserInput.i, elements, extendList, c, e, allExtends, when, condition;
  4580. isLess = isLess !== false;
  4581. while ((isLess && (extendList = this.extend())) || (isLess && (when = parserInput.$str('when'))) || (e = this.element())) {
  4582. if (when) {
  4583. condition = expect(this.conditions, 'expected condition');
  4584. } else if (condition) {
  4585. error('CSS guard can only be used at the end of selector');
  4586. } else if (extendList) {
  4587. if (allExtends) {
  4588. allExtends = allExtends.concat(extendList);
  4589. } else {
  4590. allExtends = extendList;
  4591. }
  4592. } else {
  4593. if (allExtends) { error('Extend can only be used at the end of selector'); }
  4594. c = parserInput.currentChar();
  4595. if (elements) {
  4596. elements.push(e);
  4597. } else {
  4598. elements = [ e ];
  4599. }
  4600. e = null;
  4601. }
  4602. if (c === '{' || c === '}' || c === ';' || c === ',' || c === ')') {
  4603. break;
  4604. }
  4605. }
  4606. if (elements) { return new(tree.Selector)(elements, allExtends, condition, index, fileInfo); }
  4607. if (allExtends) { error('Extend must be used to extend a selector, it cannot be used on its own'); }
  4608. },
  4609. selectors: function () {
  4610. var s, selectors;
  4611. while (true) {
  4612. s = this.selector();
  4613. if (!s) {
  4614. break;
  4615. }
  4616. if (selectors) {
  4617. selectors.push(s);
  4618. } else {
  4619. selectors = [ s ];
  4620. }
  4621. parserInput.commentStore.length = 0;
  4622. if (s.condition && selectors.length > 1) {
  4623. error("Guards are only currently allowed on a single selector.");
  4624. }
  4625. if (!parserInput.$char(',')) { break; }
  4626. if (s.condition) {
  4627. error("Guards are only currently allowed on a single selector.");
  4628. }
  4629. parserInput.commentStore.length = 0;
  4630. }
  4631. return selectors;
  4632. },
  4633. attribute: function () {
  4634. if (!parserInput.$char('[')) { return; }
  4635. var entities = this.entities,
  4636. key, val, op;
  4637. if (!(key = entities.variableCurly())) {
  4638. key = expect(/^(?:[_A-Za-z0-9-\*]*\|)?(?:[_A-Za-z0-9-]|\\.)+/);
  4639. }
  4640. op = parserInput.$re(/^[|~*$^]?=/);
  4641. if (op) {
  4642. val = entities.quoted() || parserInput.$re(/^[0-9]+%/) || parserInput.$re(/^[\w-]+/) || entities.variableCurly();
  4643. }
  4644. expectChar(']');
  4645. return new(tree.Attribute)(key, op, val);
  4646. },
  4647. //
  4648. // The `block` rule is used by `ruleset` and `mixin.definition`.
  4649. // It's a wrapper around the `primary` rule, with added `{}`.
  4650. //
  4651. block: function () {
  4652. var content;
  4653. if (parserInput.$char('{') && (content = this.primary()) && parserInput.$char('}')) {
  4654. return content;
  4655. }
  4656. },
  4657. blockRuleset: function() {
  4658. var block = this.block();
  4659. if (block) {
  4660. block = new tree.Ruleset(null, block);
  4661. }
  4662. return block;
  4663. },
  4664. detachedRuleset: function() {
  4665. var argInfo, params, variadic;
  4666. parserInput.save();
  4667. if (parserInput.$re(/^[.#]\(/)) {
  4668. /**
  4669. * DR args currently only implemented for each() function, and not
  4670. * yet settable as `@dr: #(@arg) {}`
  4671. * This should be done when DRs are merged with mixins.
  4672. * See: https://github.com/less/less-meta/issues/16
  4673. */
  4674. argInfo = this.mixin.args(false);
  4675. params = argInfo.args;
  4676. variadic = argInfo.variadic;
  4677. if (!parserInput.$char(')')) {
  4678. parserInput.restore();
  4679. return;
  4680. }
  4681. }
  4682. var blockRuleset = this.blockRuleset();
  4683. if (blockRuleset) {
  4684. parserInput.forget();
  4685. if (params) {
  4686. return new tree.mixin.Definition(null, params, blockRuleset, null, variadic);
  4687. }
  4688. return new tree.DetachedRuleset(blockRuleset);
  4689. }
  4690. parserInput.restore();
  4691. },
  4692. //
  4693. // div, .class, body > p {...}
  4694. //
  4695. ruleset: function () {
  4696. var selectors, rules, debugInfo;
  4697. parserInput.save();
  4698. if (context.dumpLineNumbers) {
  4699. debugInfo = getDebugInfo(parserInput.i);
  4700. }
  4701. selectors = this.selectors();
  4702. if (selectors && (rules = this.block())) {
  4703. parserInput.forget();
  4704. var ruleset = new(tree.Ruleset)(selectors, rules, context.strictImports);
  4705. if (context.dumpLineNumbers) {
  4706. ruleset.debugInfo = debugInfo;
  4707. }
  4708. return ruleset;
  4709. } else {
  4710. parserInput.restore();
  4711. }
  4712. },
  4713. declaration: function () {
  4714. var name, value, index = parserInput.i, hasDR,
  4715. c = parserInput.currentChar(), important, merge, isVariable;
  4716. if (c === '.' || c === '#' || c === '&' || c === ':') { return; }
  4717. parserInput.save();
  4718. name = this.variable() || this.ruleProperty();
  4719. if (name) {
  4720. isVariable = typeof name === 'string';
  4721. if (isVariable) {
  4722. value = this.detachedRuleset();
  4723. if (value) {
  4724. hasDR = true;
  4725. }
  4726. }
  4727. parserInput.commentStore.length = 0;
  4728. if (!value) {
  4729. // a name returned by this.ruleProperty() is always an array of the form:
  4730. // [string-1, ..., string-n, ""] or [string-1, ..., string-n, "+"]
  4731. // where each item is a tree.Keyword or tree.Variable
  4732. merge = !isVariable && name.length > 1 && name.pop().value;
  4733. // Custom property values get permissive parsing
  4734. if (name[0].value && name[0].value.slice(0, 2) === '--') {
  4735. value = this.permissiveValue();
  4736. }
  4737. // Try to store values as anonymous
  4738. // If we need the value later we'll re-parse it in ruleset.parseValue
  4739. else {
  4740. value = this.anonymousValue();
  4741. }
  4742. if (value) {
  4743. parserInput.forget();
  4744. // anonymous values absorb the end ';' which is required for them to work
  4745. return new (tree.Declaration)(name, value, false, merge, index, fileInfo);
  4746. }
  4747. if (!value) {
  4748. value = this.value();
  4749. }
  4750. if (value) {
  4751. important = this.important();
  4752. } else if (isVariable) {
  4753. // As a last resort, try permissiveValue
  4754. value = this.permissiveValue();
  4755. }
  4756. }
  4757. if (value && (this.end() || hasDR)) {
  4758. parserInput.forget();
  4759. return new (tree.Declaration)(name, value, important, merge, index, fileInfo);
  4760. }
  4761. else {
  4762. parserInput.restore();
  4763. }
  4764. } else {
  4765. parserInput.restore();
  4766. }
  4767. },
  4768. anonymousValue: function () {
  4769. var index = parserInput.i;
  4770. var match = parserInput.$re(/^([^.#@\$+\/'"*`(;{}-]*);/);
  4771. if (match) {
  4772. return new(tree.Anonymous)(match[1], index);
  4773. }
  4774. },
  4775. /**
  4776. * Used for custom properties, at-rules, and variables (as fallback)
  4777. * Parses almost anything inside of {} [] () "" blocks
  4778. * until it reaches outer-most tokens.
  4779. *
  4780. * First, it will try to parse comments and entities to reach
  4781. * the end. This is mostly like the Expression parser except no
  4782. * math is allowed.
  4783. */
  4784. permissiveValue: function (untilTokens) {
  4785. var i, e, done, value,
  4786. tok = untilTokens || ';',
  4787. index = parserInput.i, result = [];
  4788. function testCurrentChar() {
  4789. var char = parserInput.currentChar();
  4790. if (typeof tok === 'string') {
  4791. return char === tok;
  4792. } else {
  4793. return tok.test(char);
  4794. }
  4795. }
  4796. if (testCurrentChar()) {
  4797. return;
  4798. }
  4799. value = [];
  4800. do {
  4801. e = this.comment();
  4802. if (e) {
  4803. value.push(e);
  4804. continue;
  4805. }
  4806. e = this.entity();
  4807. if (e) {
  4808. value.push(e);
  4809. }
  4810. } while (e);
  4811. done = testCurrentChar();
  4812. if (value.length > 0) {
  4813. value = new(tree.Expression)(value);
  4814. if (done) {
  4815. return value;
  4816. }
  4817. else {
  4818. result.push(value);
  4819. }
  4820. // Preserve space before $parseUntil as it will not
  4821. if (parserInput.prevChar() === ' ') {
  4822. result.push(new tree.Anonymous(' ', index));
  4823. }
  4824. }
  4825. parserInput.save();
  4826. value = parserInput.$parseUntil(tok);
  4827. if (value) {
  4828. if (typeof value === 'string') {
  4829. error('Expected \'' + value + '\'', 'Parse');
  4830. }
  4831. if (value.length === 1 && value[0] === ' ') {
  4832. parserInput.forget();
  4833. return new tree.Anonymous('', index);
  4834. }
  4835. var item;
  4836. for (i = 0; i < value.length; i++) {
  4837. item = value[i];
  4838. if (Array.isArray(item)) {
  4839. // Treat actual quotes as normal quoted values
  4840. result.push(new tree.Quoted(item[0], item[1], true, index, fileInfo));
  4841. }
  4842. else {
  4843. if (i === value.length - 1) {
  4844. item = item.trim();
  4845. }
  4846. // Treat like quoted values, but replace vars like unquoted expressions
  4847. var quote = new tree.Quoted('\'', item, true, index, fileInfo);
  4848. quote.variableRegex = /@([\w-]+)/g;
  4849. quote.propRegex = /\$([\w-]+)/g;
  4850. result.push(quote);
  4851. }
  4852. }
  4853. parserInput.forget();
  4854. return new tree.Expression(result, true);
  4855. }
  4856. parserInput.restore();
  4857. },
  4858. //
  4859. // An @import atrule
  4860. //
  4861. // @import "lib";
  4862. //
  4863. // Depending on our environment, importing is done differently:
  4864. // In the browser, it's an XHR request, in Node, it would be a
  4865. // file-system operation. The function used for importing is
  4866. // stored in `import`, which we pass to the Import constructor.
  4867. //
  4868. 'import': function () {
  4869. var path, features, index = parserInput.i;
  4870. var dir = parserInput.$re(/^@import?\s+/);
  4871. if (dir) {
  4872. var options = (dir ? this.importOptions() : null) || {};
  4873. if ((path = this.entities.quoted() || this.entities.url())) {
  4874. features = this.mediaFeatures();
  4875. if (!parserInput.$char(';')) {
  4876. parserInput.i = index;
  4877. error('missing semi-colon or unrecognised media features on import');
  4878. }
  4879. features = features && new(tree.Value)(features);
  4880. return new(tree.Import)(path, features, options, index, fileInfo);
  4881. }
  4882. else {
  4883. parserInput.i = index;
  4884. error('malformed import statement');
  4885. }
  4886. }
  4887. },
  4888. importOptions: function() {
  4889. var o, options = {}, optionName, value;
  4890. // list of options, surrounded by parens
  4891. if (!parserInput.$char('(')) { return null; }
  4892. do {
  4893. o = this.importOption();
  4894. if (o) {
  4895. optionName = o;
  4896. value = true;
  4897. switch (optionName) {
  4898. case 'css':
  4899. optionName = 'less';
  4900. value = false;
  4901. break;
  4902. case 'once':
  4903. optionName = 'multiple';
  4904. value = false;
  4905. break;
  4906. }
  4907. options[optionName] = value;
  4908. if (!parserInput.$char(',')) { break; }
  4909. }
  4910. } while (o);
  4911. expectChar(')');
  4912. return options;
  4913. },
  4914. importOption: function() {
  4915. var opt = parserInput.$re(/^(less|css|multiple|once|inline|reference|optional)/);
  4916. if (opt) {
  4917. return opt[1];
  4918. }
  4919. },
  4920. mediaFeature: function () {
  4921. var entities = this.entities, nodes = [], e, p;
  4922. parserInput.save();
  4923. do {
  4924. e = entities.keyword() || entities.variable() || entities.mixinLookup();
  4925. if (e) {
  4926. nodes.push(e);
  4927. } else if (parserInput.$char('(')) {
  4928. p = this.property();
  4929. e = this.value();
  4930. if (parserInput.$char(')')) {
  4931. if (p && e) {
  4932. nodes.push(new(tree.Paren)(new(tree.Declaration)(p, e, null, null, parserInput.i, fileInfo, true)));
  4933. } else if (e) {
  4934. nodes.push(new(tree.Paren)(e));
  4935. } else {
  4936. error('badly formed media feature definition');
  4937. }
  4938. } else {
  4939. error('Missing closing \')\'', 'Parse');
  4940. }
  4941. }
  4942. } while (e);
  4943. parserInput.forget();
  4944. if (nodes.length > 0) {
  4945. return new(tree.Expression)(nodes);
  4946. }
  4947. },
  4948. mediaFeatures: function () {
  4949. var entities = this.entities, features = [], e;
  4950. do {
  4951. e = this.mediaFeature();
  4952. if (e) {
  4953. features.push(e);
  4954. if (!parserInput.$char(',')) { break; }
  4955. } else {
  4956. e = entities.variable() || entities.mixinLookup();
  4957. if (e) {
  4958. features.push(e);
  4959. if (!parserInput.$char(',')) { break; }
  4960. }
  4961. }
  4962. } while (e);
  4963. return features.length > 0 ? features : null;
  4964. },
  4965. media: function () {
  4966. var features, rules, media, debugInfo, index = parserInput.i;
  4967. if (context.dumpLineNumbers) {
  4968. debugInfo = getDebugInfo(index);
  4969. }
  4970. parserInput.save();
  4971. if (parserInput.$str('@media')) {
  4972. features = this.mediaFeatures();
  4973. rules = this.block();
  4974. if (!rules) {
  4975. error('media definitions require block statements after any features');
  4976. }
  4977. parserInput.forget();
  4978. media = new(tree.Media)(rules, features, index, fileInfo);
  4979. if (context.dumpLineNumbers) {
  4980. media.debugInfo = debugInfo;
  4981. }
  4982. return media;
  4983. }
  4984. parserInput.restore();
  4985. },
  4986. //
  4987. // A @plugin directive, used to import plugins dynamically.
  4988. //
  4989. // @plugin (args) "lib";
  4990. //
  4991. plugin: function () {
  4992. var path, args, options,
  4993. index = parserInput.i,
  4994. dir = parserInput.$re(/^@plugin?\s+/);
  4995. if (dir) {
  4996. args = this.pluginArgs();
  4997. if (args) {
  4998. options = {
  4999. pluginArgs: args,
  5000. isPlugin: true
  5001. };
  5002. }
  5003. else {
  5004. options = { isPlugin: true };
  5005. }
  5006. if ((path = this.entities.quoted() || this.entities.url())) {
  5007. if (!parserInput.$char(';')) {
  5008. parserInput.i = index;
  5009. error('missing semi-colon on @plugin');
  5010. }
  5011. return new(tree.Import)(path, null, options, index, fileInfo);
  5012. }
  5013. else {
  5014. parserInput.i = index;
  5015. error('malformed @plugin statement');
  5016. }
  5017. }
  5018. },
  5019. pluginArgs: function() {
  5020. // list of options, surrounded by parens
  5021. parserInput.save();
  5022. if (!parserInput.$char('(')) {
  5023. parserInput.restore();
  5024. return null;
  5025. }
  5026. var args = parserInput.$re(/^\s*([^\);]+)\)\s*/);
  5027. if (args[1]) {
  5028. parserInput.forget();
  5029. return args[1].trim();
  5030. }
  5031. else {
  5032. parserInput.restore();
  5033. return null;
  5034. }
  5035. },
  5036. //
  5037. // A CSS AtRule
  5038. //
  5039. // @charset "utf-8";
  5040. //
  5041. atrule: function () {
  5042. var index = parserInput.i, name, value, rules, nonVendorSpecificName,
  5043. hasIdentifier, hasExpression, hasUnknown, hasBlock = true, isRooted = true;
  5044. if (parserInput.currentChar() !== '@') { return; }
  5045. value = this['import']() || this.plugin() || this.media();
  5046. if (value) {
  5047. return value;
  5048. }
  5049. parserInput.save();
  5050. name = parserInput.$re(/^@[a-z-]+/);
  5051. if (!name) { return; }
  5052. nonVendorSpecificName = name;
  5053. if (name.charAt(1) == '-' && name.indexOf('-', 2) > 0) {
  5054. nonVendorSpecificName = '@' + name.slice(name.indexOf('-', 2) + 1);
  5055. }
  5056. switch (nonVendorSpecificName) {
  5057. case '@charset':
  5058. hasIdentifier = true;
  5059. hasBlock = false;
  5060. break;
  5061. case '@namespace':
  5062. hasExpression = true;
  5063. hasBlock = false;
  5064. break;
  5065. case '@keyframes':
  5066. case '@counter-style':
  5067. hasIdentifier = true;
  5068. break;
  5069. case '@document':
  5070. case '@supports':
  5071. hasUnknown = true;
  5072. isRooted = false;
  5073. break;
  5074. default:
  5075. hasUnknown = true;
  5076. break;
  5077. }
  5078. parserInput.commentStore.length = 0;
  5079. if (hasIdentifier) {
  5080. value = this.entity();
  5081. if (!value) {
  5082. error('expected ' + name + ' identifier');
  5083. }
  5084. } else if (hasExpression) {
  5085. value = this.expression();
  5086. if (!value) {
  5087. error('expected ' + name + ' expression');
  5088. }
  5089. } else if (hasUnknown) {
  5090. value = this.permissiveValue(/^[{;]/);
  5091. hasBlock = (parserInput.currentChar() === '{');
  5092. if (!value) {
  5093. if (!hasBlock && parserInput.currentChar() !== ';') {
  5094. error(name + ' rule is missing block or ending semi-colon');
  5095. }
  5096. }
  5097. else if (!value.value) {
  5098. value = null;
  5099. }
  5100. }
  5101. if (hasBlock) {
  5102. rules = this.blockRuleset();
  5103. }
  5104. if (rules || (!hasBlock && value && parserInput.$char(';'))) {
  5105. parserInput.forget();
  5106. return new (tree.AtRule)(name, value, rules, index, fileInfo,
  5107. context.dumpLineNumbers ? getDebugInfo(index) : null,
  5108. isRooted
  5109. );
  5110. }
  5111. parserInput.restore('at-rule options not recognised');
  5112. },
  5113. //
  5114. // A Value is a comma-delimited list of Expressions
  5115. //
  5116. // font-family: Baskerville, Georgia, serif;
  5117. //
  5118. // In a Rule, a Value represents everything after the `:`,
  5119. // and before the `;`.
  5120. //
  5121. value: function () {
  5122. var e, expressions = [], index = parserInput.i;
  5123. do {
  5124. e = this.expression();
  5125. if (e) {
  5126. expressions.push(e);
  5127. if (!parserInput.$char(',')) { break; }
  5128. }
  5129. } while (e);
  5130. if (expressions.length > 0) {
  5131. return new(tree.Value)(expressions, index);
  5132. }
  5133. },
  5134. important: function () {
  5135. if (parserInput.currentChar() === '!') {
  5136. return parserInput.$re(/^! *important/);
  5137. }
  5138. },
  5139. sub: function () {
  5140. var a, e;
  5141. parserInput.save();
  5142. if (parserInput.$char('(')) {
  5143. a = this.addition();
  5144. if (a && parserInput.$char(')')) {
  5145. parserInput.forget();
  5146. e = new(tree.Expression)([a]);
  5147. e.parens = true;
  5148. return e;
  5149. }
  5150. parserInput.restore('Expected \')\'');
  5151. return;
  5152. }
  5153. parserInput.restore();
  5154. },
  5155. multiplication: function () {
  5156. var m, a, op, operation, isSpaced;
  5157. m = this.operand();
  5158. if (m) {
  5159. isSpaced = parserInput.isWhitespace(-1);
  5160. while (true) {
  5161. if (parserInput.peek(/^\/[*\/]/)) {
  5162. break;
  5163. }
  5164. parserInput.save();
  5165. op = parserInput.$char('/') || parserInput.$char('*') || parserInput.$str('./');
  5166. if (!op) { parserInput.forget(); break; }
  5167. a = this.operand();
  5168. if (!a) { parserInput.restore(); break; }
  5169. parserInput.forget();
  5170. m.parensInOp = true;
  5171. a.parensInOp = true;
  5172. operation = new(tree.Operation)(op, [operation || m, a], isSpaced);
  5173. isSpaced = parserInput.isWhitespace(-1);
  5174. }
  5175. return operation || m;
  5176. }
  5177. },
  5178. addition: function () {
  5179. var m, a, op, operation, isSpaced;
  5180. m = this.multiplication();
  5181. if (m) {
  5182. isSpaced = parserInput.isWhitespace(-1);
  5183. while (true) {
  5184. op = parserInput.$re(/^[-+]\s+/) || (!isSpaced && (parserInput.$char('+') || parserInput.$char('-')));
  5185. if (!op) {
  5186. break;
  5187. }
  5188. a = this.multiplication();
  5189. if (!a) {
  5190. break;
  5191. }
  5192. m.parensInOp = true;
  5193. a.parensInOp = true;
  5194. operation = new(tree.Operation)(op, [operation || m, a], isSpaced);
  5195. isSpaced = parserInput.isWhitespace(-1);
  5196. }
  5197. return operation || m;
  5198. }
  5199. },
  5200. conditions: function () {
  5201. var a, b, index = parserInput.i, condition;
  5202. a = this.condition(true);
  5203. if (a) {
  5204. while (true) {
  5205. if (!parserInput.peek(/^,\s*(not\s*)?\(/) || !parserInput.$char(',')) {
  5206. break;
  5207. }
  5208. b = this.condition(true);
  5209. if (!b) {
  5210. break;
  5211. }
  5212. condition = new(tree.Condition)('or', condition || a, b, index);
  5213. }
  5214. return condition || a;
  5215. }
  5216. },
  5217. condition: function (needsParens) {
  5218. var result, logical, next;
  5219. function or() {
  5220. return parserInput.$str('or');
  5221. }
  5222. result = this.conditionAnd(needsParens);
  5223. if (!result) {
  5224. return ;
  5225. }
  5226. logical = or();
  5227. if (logical) {
  5228. next = this.condition(needsParens);
  5229. if (next) {
  5230. result = new(tree.Condition)(logical, result, next);
  5231. } else {
  5232. return ;
  5233. }
  5234. }
  5235. return result;
  5236. },
  5237. conditionAnd: function (needsParens) {
  5238. var result, logical, next, self = this;
  5239. function insideCondition() {
  5240. var cond = self.negatedCondition(needsParens) || self.parenthesisCondition(needsParens);
  5241. if (!cond && !needsParens) {
  5242. return self.atomicCondition(needsParens);
  5243. }
  5244. return cond;
  5245. }
  5246. function and() {
  5247. return parserInput.$str('and');
  5248. }
  5249. result = insideCondition();
  5250. if (!result) {
  5251. return ;
  5252. }
  5253. logical = and();
  5254. if (logical) {
  5255. next = this.conditionAnd(needsParens);
  5256. if (next) {
  5257. result = new(tree.Condition)(logical, result, next);
  5258. } else {
  5259. return ;
  5260. }
  5261. }
  5262. return result;
  5263. },
  5264. negatedCondition: function (needsParens) {
  5265. if (parserInput.$str('not')) {
  5266. var result = this.parenthesisCondition(needsParens);
  5267. if (result) {
  5268. result.negate = !result.negate;
  5269. }
  5270. return result;
  5271. }
  5272. },
  5273. parenthesisCondition: function (needsParens) {
  5274. function tryConditionFollowedByParenthesis(me) {
  5275. var body;
  5276. parserInput.save();
  5277. body = me.condition(needsParens);
  5278. if (!body) {
  5279. parserInput.restore();
  5280. return ;
  5281. }
  5282. if (!parserInput.$char(')')) {
  5283. parserInput.restore();
  5284. return ;
  5285. }
  5286. parserInput.forget();
  5287. return body;
  5288. }
  5289. var body;
  5290. parserInput.save();
  5291. if (!parserInput.$str('(')) {
  5292. parserInput.restore();
  5293. return ;
  5294. }
  5295. body = tryConditionFollowedByParenthesis(this);
  5296. if (body) {
  5297. parserInput.forget();
  5298. return body;
  5299. }
  5300. body = this.atomicCondition(needsParens);
  5301. if (!body) {
  5302. parserInput.restore();
  5303. return ;
  5304. }
  5305. if (!parserInput.$char(')')) {
  5306. parserInput.restore('expected \')\' got \'' + parserInput.currentChar() + '\'');
  5307. return ;
  5308. }
  5309. parserInput.forget();
  5310. return body;
  5311. },
  5312. atomicCondition: function (needsParens) {
  5313. var entities = this.entities, index = parserInput.i, a, b, c, op;
  5314. function cond() {
  5315. return this.addition() || entities.keyword() || entities.quoted() || entities.mixinLookup();
  5316. }
  5317. cond = cond.bind(this);
  5318. a = cond();
  5319. if (a) {
  5320. if (parserInput.$char('>')) {
  5321. if (parserInput.$char('=')) {
  5322. op = '>=';
  5323. } else {
  5324. op = '>';
  5325. }
  5326. } else
  5327. if (parserInput.$char('<')) {
  5328. if (parserInput.$char('=')) {
  5329. op = '<=';
  5330. } else {
  5331. op = '<';
  5332. }
  5333. } else
  5334. if (parserInput.$char('=')) {
  5335. if (parserInput.$char('>')) {
  5336. op = '=>';
  5337. } else if (parserInput.$char('<')) {
  5338. op = '=<';
  5339. } else {
  5340. op = '=';
  5341. }
  5342. }
  5343. if (op) {
  5344. b = cond();
  5345. if (b) {
  5346. c = new(tree.Condition)(op, a, b, index, false);
  5347. } else {
  5348. error('expected expression');
  5349. }
  5350. } else {
  5351. c = new(tree.Condition)('=', a, new(tree.Keyword)('true'), index, false);
  5352. }
  5353. return c;
  5354. }
  5355. },
  5356. //
  5357. // An operand is anything that can be part of an operation,
  5358. // such as a Color, or a Variable
  5359. //
  5360. operand: function () {
  5361. var entities = this.entities, negate;
  5362. if (parserInput.peek(/^-[@\$\(]/)) {
  5363. negate = parserInput.$char('-');
  5364. }
  5365. var o = this.sub() || entities.dimension() ||
  5366. entities.color() || entities.variable() ||
  5367. entities.property() || entities.call() ||
  5368. entities.quoted(true) || entities.colorKeyword() ||
  5369. entities.mixinLookup();
  5370. if (negate) {
  5371. o.parensInOp = true;
  5372. o = new(tree.Negative)(o);
  5373. }
  5374. return o;
  5375. },
  5376. //
  5377. // Expressions either represent mathematical operations,
  5378. // or white-space delimited Entities.
  5379. //
  5380. // 1px solid black
  5381. // @var * 2
  5382. //
  5383. expression: function () {
  5384. var entities = [], e, delim, index = parserInput.i;
  5385. do {
  5386. e = this.comment();
  5387. if (e) {
  5388. entities.push(e);
  5389. continue;
  5390. }
  5391. e = this.addition() || this.entity();
  5392. if (e) {
  5393. entities.push(e);
  5394. // operations do not allow keyword "/" dimension (e.g. small/20px) so we support that here
  5395. if (!parserInput.peek(/^\/[\/*]/)) {
  5396. delim = parserInput.$char('/');
  5397. if (delim) {
  5398. entities.push(new(tree.Anonymous)(delim, index));
  5399. }
  5400. }
  5401. }
  5402. } while (e);
  5403. if (entities.length > 0) {
  5404. return new(tree.Expression)(entities);
  5405. }
  5406. },
  5407. property: function () {
  5408. var name = parserInput.$re(/^(\*?-?[_a-zA-Z0-9-]+)\s*:/);
  5409. if (name) {
  5410. return name[1];
  5411. }
  5412. },
  5413. ruleProperty: function () {
  5414. var name = [], index = [], s, k;
  5415. parserInput.save();
  5416. var simpleProperty = parserInput.$re(/^([_a-zA-Z0-9-]+)\s*:/);
  5417. if (simpleProperty) {
  5418. name = [new(tree.Keyword)(simpleProperty[1])];
  5419. parserInput.forget();
  5420. return name;
  5421. }
  5422. function match(re) {
  5423. var i = parserInput.i,
  5424. chunk = parserInput.$re(re);
  5425. if (chunk) {
  5426. index.push(i);
  5427. return name.push(chunk[1]);
  5428. }
  5429. }
  5430. match(/^(\*?)/);
  5431. while (true) {
  5432. if (!match(/^((?:[\w-]+)|(?:[@\$]\{[\w-]+\}))/)) {
  5433. break;
  5434. }
  5435. }
  5436. if ((name.length > 1) && match(/^((?:\+_|\+)?)\s*:/)) {
  5437. parserInput.forget();
  5438. // at last, we have the complete match now. move forward,
  5439. // convert name particles to tree objects and return:
  5440. if (name[0] === '') {
  5441. name.shift();
  5442. index.shift();
  5443. }
  5444. for (k = 0; k < name.length; k++) {
  5445. s = name[k];
  5446. name[k] = (s.charAt(0) !== '@' && s.charAt(0) !== '$') ?
  5447. new(tree.Keyword)(s) :
  5448. (s.charAt(0) === '@' ?
  5449. new(tree.Variable)('@' + s.slice(2, -1), index[k], fileInfo) :
  5450. new(tree.Property)('$' + s.slice(2, -1), index[k], fileInfo));
  5451. }
  5452. return name;
  5453. }
  5454. parserInput.restore();
  5455. }
  5456. }
  5457. };
  5458. };
  5459. Parser.serializeVars = function(vars) {
  5460. var s = '';
  5461. for (var name in vars) {
  5462. if (Object.hasOwnProperty.call(vars, name)) {
  5463. var value = vars[name];
  5464. s += ((name[0] === '@') ? '' : '@') + name + ': ' + value +
  5465. ((String(value).slice(-1) === ';') ? '' : ';');
  5466. }
  5467. }
  5468. return s;
  5469. };
  5470. module.exports = Parser;
  5471. },{"../functions/function-registry":27,"../less-error":38,"../tree":67,"../utils":89,"../visitors":93,"./parser-input":43}],45:[function(require,module,exports){
  5472. /**
  5473. * Plugin Manager
  5474. */
  5475. var PluginManager = function(less) {
  5476. this.less = less;
  5477. this.visitors = [];
  5478. this.preProcessors = [];
  5479. this.postProcessors = [];
  5480. this.installedPlugins = [];
  5481. this.fileManagers = [];
  5482. this.iterator = -1;
  5483. this.pluginCache = {};
  5484. this.Loader = new less.PluginLoader(less);
  5485. };
  5486. var pm, PluginManagerFactory = function(less, newFactory) {
  5487. if (newFactory || !pm) {
  5488. pm = new PluginManager(less);
  5489. }
  5490. return pm;
  5491. };
  5492. /**
  5493. * Adds all the plugins in the array
  5494. * @param {Array} plugins
  5495. */
  5496. PluginManager.prototype.addPlugins = function(plugins) {
  5497. if (plugins) {
  5498. for (var i = 0; i < plugins.length; i++) {
  5499. this.addPlugin(plugins[i]);
  5500. }
  5501. }
  5502. };
  5503. /**
  5504. *
  5505. * @param plugin
  5506. * @param {String} filename
  5507. */
  5508. PluginManager.prototype.addPlugin = function(plugin, filename, functionRegistry) {
  5509. this.installedPlugins.push(plugin);
  5510. if (filename) {
  5511. this.pluginCache[filename] = plugin;
  5512. }
  5513. if (plugin.install) {
  5514. plugin.install(this.less, this, functionRegistry || this.less.functions.functionRegistry);
  5515. }
  5516. };
  5517. /**
  5518. *
  5519. * @param filename
  5520. */
  5521. PluginManager.prototype.get = function(filename) {
  5522. return this.pluginCache[filename];
  5523. };
  5524. /**
  5525. * Adds a visitor. The visitor object has options on itself to determine
  5526. * when it should run.
  5527. * @param visitor
  5528. */
  5529. PluginManager.prototype.addVisitor = function(visitor) {
  5530. this.visitors.push(visitor);
  5531. };
  5532. /**
  5533. * Adds a pre processor object
  5534. * @param {object} preProcessor
  5535. * @param {number} priority - guidelines 1 = before import, 1000 = import, 2000 = after import
  5536. */
  5537. PluginManager.prototype.addPreProcessor = function(preProcessor, priority) {
  5538. var indexToInsertAt;
  5539. for (indexToInsertAt = 0; indexToInsertAt < this.preProcessors.length; indexToInsertAt++) {
  5540. if (this.preProcessors[indexToInsertAt].priority >= priority) {
  5541. break;
  5542. }
  5543. }
  5544. this.preProcessors.splice(indexToInsertAt, 0, {preProcessor: preProcessor, priority: priority});
  5545. };
  5546. /**
  5547. * Adds a post processor object
  5548. * @param {object} postProcessor
  5549. * @param {number} priority - guidelines 1 = before compression, 1000 = compression, 2000 = after compression
  5550. */
  5551. PluginManager.prototype.addPostProcessor = function(postProcessor, priority) {
  5552. var indexToInsertAt;
  5553. for (indexToInsertAt = 0; indexToInsertAt < this.postProcessors.length; indexToInsertAt++) {
  5554. if (this.postProcessors[indexToInsertAt].priority >= priority) {
  5555. break;
  5556. }
  5557. }
  5558. this.postProcessors.splice(indexToInsertAt, 0, {postProcessor: postProcessor, priority: priority});
  5559. };
  5560. /**
  5561. *
  5562. * @param manager
  5563. */
  5564. PluginManager.prototype.addFileManager = function(manager) {
  5565. this.fileManagers.push(manager);
  5566. };
  5567. /**
  5568. *
  5569. * @returns {Array}
  5570. * @private
  5571. */
  5572. PluginManager.prototype.getPreProcessors = function() {
  5573. var preProcessors = [];
  5574. for (var i = 0; i < this.preProcessors.length; i++) {
  5575. preProcessors.push(this.preProcessors[i].preProcessor);
  5576. }
  5577. return preProcessors;
  5578. };
  5579. /**
  5580. *
  5581. * @returns {Array}
  5582. * @private
  5583. */
  5584. PluginManager.prototype.getPostProcessors = function() {
  5585. var postProcessors = [];
  5586. for (var i = 0; i < this.postProcessors.length; i++) {
  5587. postProcessors.push(this.postProcessors[i].postProcessor);
  5588. }
  5589. return postProcessors;
  5590. };
  5591. /**
  5592. *
  5593. * @returns {Array}
  5594. * @private
  5595. */
  5596. PluginManager.prototype.getVisitors = function() {
  5597. return this.visitors;
  5598. };
  5599. PluginManager.prototype.visitor = function() {
  5600. var self = this;
  5601. return {
  5602. first: function() {
  5603. self.iterator = -1;
  5604. return self.visitors[self.iterator];
  5605. },
  5606. get: function() {
  5607. self.iterator += 1;
  5608. return self.visitors[self.iterator];
  5609. }
  5610. };
  5611. };
  5612. /**
  5613. *
  5614. * @returns {Array}
  5615. * @private
  5616. */
  5617. PluginManager.prototype.getFileManagers = function() {
  5618. return this.fileManagers;
  5619. };
  5620. //
  5621. module.exports = PluginManagerFactory;
  5622. },{}],46:[function(require,module,exports){
  5623. var PromiseConstructor,
  5624. utils = require('./utils');
  5625. module.exports = function(environment, ParseTree, ImportManager) {
  5626. var render = function (input, options, callback) {
  5627. if (typeof options === 'function') {
  5628. callback = options;
  5629. options = utils.copyOptions(this.options, {});
  5630. }
  5631. else {
  5632. options = utils.copyOptions(this.options, options || {});
  5633. }
  5634. if (!callback) {
  5635. if (!PromiseConstructor) {
  5636. PromiseConstructor = typeof Promise === 'undefined' ? require('promise') : Promise;
  5637. }
  5638. var self = this;
  5639. return new PromiseConstructor(function (resolve, reject) {
  5640. render.call(self, input, options, function(err, output) {
  5641. if (err) {
  5642. reject(err);
  5643. } else {
  5644. resolve(output);
  5645. }
  5646. });
  5647. });
  5648. } else {
  5649. this.parse(input, options, function(err, root, imports, options) {
  5650. if (err) { return callback(err); }
  5651. var result;
  5652. try {
  5653. var parseTree = new ParseTree(root, imports);
  5654. result = parseTree.toCSS(options);
  5655. }
  5656. catch (err) { return callback(err); }
  5657. callback(null, result);
  5658. });
  5659. }
  5660. };
  5661. return render;
  5662. };
  5663. },{"./utils":89,"promise":undefined}],47:[function(require,module,exports){
  5664. module.exports = function (SourceMapOutput, environment) {
  5665. var SourceMapBuilder = function (options) {
  5666. this.options = options;
  5667. };
  5668. SourceMapBuilder.prototype.toCSS = function(rootNode, options, imports) {
  5669. var sourceMapOutput = new SourceMapOutput(
  5670. {
  5671. contentsIgnoredCharsMap: imports.contentsIgnoredChars,
  5672. rootNode: rootNode,
  5673. contentsMap: imports.contents,
  5674. sourceMapFilename: this.options.sourceMapFilename,
  5675. sourceMapURL: this.options.sourceMapURL,
  5676. outputFilename: this.options.sourceMapOutputFilename,
  5677. sourceMapBasepath: this.options.sourceMapBasepath,
  5678. sourceMapRootpath: this.options.sourceMapRootpath,
  5679. outputSourceFiles: this.options.outputSourceFiles,
  5680. sourceMapGenerator: this.options.sourceMapGenerator,
  5681. sourceMapFileInline: this.options.sourceMapFileInline
  5682. });
  5683. var css = sourceMapOutput.toCSS(options);
  5684. this.sourceMap = sourceMapOutput.sourceMap;
  5685. this.sourceMapURL = sourceMapOutput.sourceMapURL;
  5686. if (this.options.sourceMapInputFilename) {
  5687. this.sourceMapInputFilename = sourceMapOutput.normalizeFilename(this.options.sourceMapInputFilename);
  5688. }
  5689. if (this.options.sourceMapBasepath !== undefined && this.sourceMapURL !== undefined) {
  5690. this.sourceMapURL = sourceMapOutput.removeBasepath(this.sourceMapURL);
  5691. }
  5692. return css + this.getCSSAppendage();
  5693. };
  5694. SourceMapBuilder.prototype.getCSSAppendage = function() {
  5695. var sourceMapURL = this.sourceMapURL;
  5696. if (this.options.sourceMapFileInline) {
  5697. if (this.sourceMap === undefined) {
  5698. return '';
  5699. }
  5700. sourceMapURL = 'data:application/json;base64,' + environment.encodeBase64(this.sourceMap);
  5701. }
  5702. if (sourceMapURL) {
  5703. return '/*# sourceMappingURL=' + sourceMapURL + ' */';
  5704. }
  5705. return '';
  5706. };
  5707. SourceMapBuilder.prototype.getExternalSourceMap = function() {
  5708. return this.sourceMap;
  5709. };
  5710. SourceMapBuilder.prototype.setExternalSourceMap = function(sourceMap) {
  5711. this.sourceMap = sourceMap;
  5712. };
  5713. SourceMapBuilder.prototype.isInline = function() {
  5714. return this.options.sourceMapFileInline;
  5715. };
  5716. SourceMapBuilder.prototype.getSourceMapURL = function() {
  5717. return this.sourceMapURL;
  5718. };
  5719. SourceMapBuilder.prototype.getOutputFilename = function() {
  5720. return this.options.sourceMapOutputFilename;
  5721. };
  5722. SourceMapBuilder.prototype.getInputFilename = function() {
  5723. return this.sourceMapInputFilename;
  5724. };
  5725. return SourceMapBuilder;
  5726. };
  5727. },{}],48:[function(require,module,exports){
  5728. module.exports = function (environment) {
  5729. var SourceMapOutput = function (options) {
  5730. this._css = [];
  5731. this._rootNode = options.rootNode;
  5732. this._contentsMap = options.contentsMap;
  5733. this._contentsIgnoredCharsMap = options.contentsIgnoredCharsMap;
  5734. if (options.sourceMapFilename) {
  5735. this._sourceMapFilename = options.sourceMapFilename.replace(/\\/g, '/');
  5736. }
  5737. this._outputFilename = options.outputFilename;
  5738. this.sourceMapURL = options.sourceMapURL;
  5739. if (options.sourceMapBasepath) {
  5740. this._sourceMapBasepath = options.sourceMapBasepath.replace(/\\/g, '/');
  5741. }
  5742. if (options.sourceMapRootpath) {
  5743. this._sourceMapRootpath = options.sourceMapRootpath.replace(/\\/g, '/');
  5744. if (this._sourceMapRootpath.charAt(this._sourceMapRootpath.length - 1) !== '/') {
  5745. this._sourceMapRootpath += '/';
  5746. }
  5747. } else {
  5748. this._sourceMapRootpath = '';
  5749. }
  5750. this._outputSourceFiles = options.outputSourceFiles;
  5751. this._sourceMapGeneratorConstructor = environment.getSourceMapGenerator();
  5752. this._lineNumber = 0;
  5753. this._column = 0;
  5754. };
  5755. SourceMapOutput.prototype.removeBasepath = function(path) {
  5756. if (this._sourceMapBasepath && path.indexOf(this._sourceMapBasepath) === 0) {
  5757. path = path.substring(this._sourceMapBasepath.length);
  5758. if (path.charAt(0) === '\\' || path.charAt(0) === '/') {
  5759. path = path.substring(1);
  5760. }
  5761. }
  5762. return path;
  5763. };
  5764. SourceMapOutput.prototype.normalizeFilename = function(filename) {
  5765. filename = filename.replace(/\\/g, '/');
  5766. filename = this.removeBasepath(filename);
  5767. return (this._sourceMapRootpath || '') + filename;
  5768. };
  5769. SourceMapOutput.prototype.add = function(chunk, fileInfo, index, mapLines) {
  5770. // ignore adding empty strings
  5771. if (!chunk) {
  5772. return;
  5773. }
  5774. var lines,
  5775. sourceLines,
  5776. columns,
  5777. sourceColumns,
  5778. i;
  5779. if (fileInfo) {
  5780. var inputSource = this._contentsMap[fileInfo.filename];
  5781. // remove vars/banner added to the top of the file
  5782. if (this._contentsIgnoredCharsMap[fileInfo.filename]) {
  5783. // adjust the index
  5784. index -= this._contentsIgnoredCharsMap[fileInfo.filename];
  5785. if (index < 0) { index = 0; }
  5786. // adjust the source
  5787. inputSource = inputSource.slice(this._contentsIgnoredCharsMap[fileInfo.filename]);
  5788. }
  5789. inputSource = inputSource.substring(0, index);
  5790. sourceLines = inputSource.split('\n');
  5791. sourceColumns = sourceLines[sourceLines.length - 1];
  5792. }
  5793. lines = chunk.split('\n');
  5794. columns = lines[lines.length - 1];
  5795. if (fileInfo) {
  5796. if (!mapLines) {
  5797. this._sourceMapGenerator.addMapping({ generated: { line: this._lineNumber + 1, column: this._column},
  5798. original: { line: sourceLines.length, column: sourceColumns.length},
  5799. source: this.normalizeFilename(fileInfo.filename)});
  5800. } else {
  5801. for (i = 0; i < lines.length; i++) {
  5802. this._sourceMapGenerator.addMapping({ generated: { line: this._lineNumber + i + 1, column: i === 0 ? this._column : 0},
  5803. original: { line: sourceLines.length + i, column: i === 0 ? sourceColumns.length : 0},
  5804. source: this.normalizeFilename(fileInfo.filename)});
  5805. }
  5806. }
  5807. }
  5808. if (lines.length === 1) {
  5809. this._column += columns.length;
  5810. } else {
  5811. this._lineNumber += lines.length - 1;
  5812. this._column = columns.length;
  5813. }
  5814. this._css.push(chunk);
  5815. };
  5816. SourceMapOutput.prototype.isEmpty = function() {
  5817. return this._css.length === 0;
  5818. };
  5819. SourceMapOutput.prototype.toCSS = function(context) {
  5820. this._sourceMapGenerator = new this._sourceMapGeneratorConstructor({ file: this._outputFilename, sourceRoot: null });
  5821. if (this._outputSourceFiles) {
  5822. for (var filename in this._contentsMap) {
  5823. if (this._contentsMap.hasOwnProperty(filename)) {
  5824. var source = this._contentsMap[filename];
  5825. if (this._contentsIgnoredCharsMap[filename]) {
  5826. source = source.slice(this._contentsIgnoredCharsMap[filename]);
  5827. }
  5828. this._sourceMapGenerator.setSourceContent(this.normalizeFilename(filename), source);
  5829. }
  5830. }
  5831. }
  5832. this._rootNode.genCSS(context, this);
  5833. if (this._css.length > 0) {
  5834. var sourceMapURL,
  5835. sourceMapContent = JSON.stringify(this._sourceMapGenerator.toJSON());
  5836. if (this.sourceMapURL) {
  5837. sourceMapURL = this.sourceMapURL;
  5838. } else if (this._sourceMapFilename) {
  5839. sourceMapURL = this._sourceMapFilename;
  5840. }
  5841. this.sourceMapURL = sourceMapURL;
  5842. this.sourceMap = sourceMapContent;
  5843. }
  5844. return this._css.join('');
  5845. };
  5846. return SourceMapOutput;
  5847. };
  5848. },{}],49:[function(require,module,exports){
  5849. var contexts = require('./contexts'),
  5850. visitor = require('./visitors'),
  5851. tree = require('./tree');
  5852. module.exports = function(root, options) {
  5853. options = options || {};
  5854. var evaldRoot,
  5855. variables = options.variables,
  5856. evalEnv = new contexts.Eval(options);
  5857. //
  5858. // Allows setting variables with a hash, so:
  5859. //
  5860. // `{ color: new tree.Color('#f01') }` will become:
  5861. //
  5862. // new tree.Declaration('@color',
  5863. // new tree.Value([
  5864. // new tree.Expression([
  5865. // new tree.Color('#f01')
  5866. // ])
  5867. // ])
  5868. // )
  5869. //
  5870. if (typeof variables === 'object' && !Array.isArray(variables)) {
  5871. variables = Object.keys(variables).map(function (k) {
  5872. var value = variables[k];
  5873. if (!(value instanceof tree.Value)) {
  5874. if (!(value instanceof tree.Expression)) {
  5875. value = new tree.Expression([value]);
  5876. }
  5877. value = new tree.Value([value]);
  5878. }
  5879. return new tree.Declaration('@' + k, value, false, null, 0);
  5880. });
  5881. evalEnv.frames = [new tree.Ruleset(null, variables)];
  5882. }
  5883. var visitors = [
  5884. new visitor.JoinSelectorVisitor(),
  5885. new visitor.MarkVisibleSelectorsVisitor(true),
  5886. new visitor.ExtendVisitor(),
  5887. new visitor.ToCSSVisitor({compress: Boolean(options.compress)})
  5888. ], preEvalVisitors = [], v, visitorIterator;
  5889. /**
  5890. * first() / get() allows visitors to be added while visiting
  5891. *
  5892. * @todo Add scoping for visitors just like functions for @plugin; right now they're global
  5893. */
  5894. if (options.pluginManager) {
  5895. visitorIterator = options.pluginManager.visitor();
  5896. for (var i = 0; i < 2; i++) {
  5897. visitorIterator.first();
  5898. while ((v = visitorIterator.get())) {
  5899. if (v.isPreEvalVisitor) {
  5900. if (i === 0 || preEvalVisitors.indexOf(v) === -1) {
  5901. preEvalVisitors.push(v);
  5902. v.run(root);
  5903. }
  5904. }
  5905. else {
  5906. if (i === 0 || visitors.indexOf(v) === -1) {
  5907. if (v.isPreVisitor) {
  5908. visitors.unshift(v);
  5909. }
  5910. else {
  5911. visitors.push(v);
  5912. }
  5913. }
  5914. }
  5915. }
  5916. }
  5917. }
  5918. evaldRoot = root.eval(evalEnv);
  5919. for (var i = 0; i < visitors.length; i++) {
  5920. visitors[i].run(evaldRoot);
  5921. }
  5922. // Run any remaining visitors added after eval pass
  5923. if (options.pluginManager) {
  5924. visitorIterator.first();
  5925. while ((v = visitorIterator.get())) {
  5926. if (visitors.indexOf(v) === -1 && preEvalVisitors.indexOf(v) === -1) {
  5927. v.run(evaldRoot);
  5928. }
  5929. }
  5930. }
  5931. return evaldRoot;
  5932. };
  5933. },{"./contexts":13,"./tree":67,"./visitors":93}],50:[function(require,module,exports){
  5934. var Node = require('./node');
  5935. var Anonymous = function (value, index, currentFileInfo, mapLines, rulesetLike, visibilityInfo) {
  5936. this.value = value;
  5937. this._index = index;
  5938. this._fileInfo = currentFileInfo;
  5939. this.mapLines = mapLines;
  5940. this.rulesetLike = (typeof rulesetLike === 'undefined') ? false : rulesetLike;
  5941. this.allowRoot = true;
  5942. this.copyVisibilityInfo(visibilityInfo);
  5943. };
  5944. Anonymous.prototype = new Node();
  5945. Anonymous.prototype.type = 'Anonymous';
  5946. Anonymous.prototype.eval = function () {
  5947. return new Anonymous(this.value, this._index, this._fileInfo, this.mapLines, this.rulesetLike, this.visibilityInfo());
  5948. };
  5949. Anonymous.prototype.compare = function (other) {
  5950. return other.toCSS && this.toCSS() === other.toCSS() ? 0 : undefined;
  5951. };
  5952. Anonymous.prototype.isRulesetLike = function() {
  5953. return this.rulesetLike;
  5954. };
  5955. Anonymous.prototype.genCSS = function (context, output) {
  5956. this.nodeVisible = Boolean(this.value);
  5957. if (this.nodeVisible) {
  5958. output.add(this.value, this._fileInfo, this._index, this.mapLines);
  5959. }
  5960. };
  5961. module.exports = Anonymous;
  5962. },{"./node":76}],51:[function(require,module,exports){
  5963. var Node = require('./node');
  5964. var Assignment = function (key, val) {
  5965. this.key = key;
  5966. this.value = val;
  5967. };
  5968. Assignment.prototype = new Node();
  5969. Assignment.prototype.type = 'Assignment';
  5970. Assignment.prototype.accept = function (visitor) {
  5971. this.value = visitor.visit(this.value);
  5972. };
  5973. Assignment.prototype.eval = function (context) {
  5974. if (this.value.eval) {
  5975. return new Assignment(this.key, this.value.eval(context));
  5976. }
  5977. return this;
  5978. };
  5979. Assignment.prototype.genCSS = function (context, output) {
  5980. output.add(this.key + '=');
  5981. if (this.value.genCSS) {
  5982. this.value.genCSS(context, output);
  5983. } else {
  5984. output.add(this.value);
  5985. }
  5986. };
  5987. module.exports = Assignment;
  5988. },{"./node":76}],52:[function(require,module,exports){
  5989. var Node = require('./node'),
  5990. Selector = require('./selector'),
  5991. Ruleset = require('./ruleset'),
  5992. Anonymous = require('./anonymous');
  5993. var AtRule = function (name, value, rules, index, currentFileInfo, debugInfo, isRooted, visibilityInfo) {
  5994. var i;
  5995. this.name = name;
  5996. this.value = (value instanceof Node) ? value : (value ? new Anonymous(value) : value);
  5997. if (rules) {
  5998. if (Array.isArray(rules)) {
  5999. this.rules = rules;
  6000. } else {
  6001. this.rules = [rules];
  6002. this.rules[0].selectors = (new Selector([], null, null, index, currentFileInfo)).createEmptySelectors();
  6003. }
  6004. for (i = 0; i < this.rules.length; i++) {
  6005. this.rules[i].allowImports = true;
  6006. }
  6007. this.setParent(this.rules, this);
  6008. }
  6009. this._index = index;
  6010. this._fileInfo = currentFileInfo;
  6011. this.debugInfo = debugInfo;
  6012. this.isRooted = isRooted || false;
  6013. this.copyVisibilityInfo(visibilityInfo);
  6014. this.allowRoot = true;
  6015. };
  6016. AtRule.prototype = new Node();
  6017. AtRule.prototype.type = 'AtRule';
  6018. AtRule.prototype.accept = function (visitor) {
  6019. var value = this.value, rules = this.rules;
  6020. if (rules) {
  6021. this.rules = visitor.visitArray(rules);
  6022. }
  6023. if (value) {
  6024. this.value = visitor.visit(value);
  6025. }
  6026. };
  6027. AtRule.prototype.isRulesetLike = function() {
  6028. return this.rules || !this.isCharset();
  6029. };
  6030. AtRule.prototype.isCharset = function() {
  6031. return '@charset' === this.name;
  6032. };
  6033. AtRule.prototype.genCSS = function (context, output) {
  6034. var value = this.value, rules = this.rules;
  6035. output.add(this.name, this.fileInfo(), this.getIndex());
  6036. if (value) {
  6037. output.add(' ');
  6038. value.genCSS(context, output);
  6039. }
  6040. if (rules) {
  6041. this.outputRuleset(context, output, rules);
  6042. } else {
  6043. output.add(';');
  6044. }
  6045. };
  6046. AtRule.prototype.eval = function (context) {
  6047. var mediaPathBackup, mediaBlocksBackup, value = this.value, rules = this.rules;
  6048. // media stored inside other atrule should not bubble over it
  6049. // backpup media bubbling information
  6050. mediaPathBackup = context.mediaPath;
  6051. mediaBlocksBackup = context.mediaBlocks;
  6052. // deleted media bubbling information
  6053. context.mediaPath = [];
  6054. context.mediaBlocks = [];
  6055. if (value) {
  6056. value = value.eval(context);
  6057. }
  6058. if (rules) {
  6059. // assuming that there is only one rule at this point - that is how parser constructs the rule
  6060. rules = [rules[0].eval(context)];
  6061. rules[0].root = true;
  6062. }
  6063. // restore media bubbling information
  6064. context.mediaPath = mediaPathBackup;
  6065. context.mediaBlocks = mediaBlocksBackup;
  6066. return new AtRule(this.name, value, rules,
  6067. this.getIndex(), this.fileInfo(), this.debugInfo, this.isRooted, this.visibilityInfo());
  6068. };
  6069. AtRule.prototype.variable = function (name) {
  6070. if (this.rules) {
  6071. // assuming that there is only one rule at this point - that is how parser constructs the rule
  6072. return Ruleset.prototype.variable.call(this.rules[0], name);
  6073. }
  6074. };
  6075. AtRule.prototype.find = function () {
  6076. if (this.rules) {
  6077. // assuming that there is only one rule at this point - that is how parser constructs the rule
  6078. return Ruleset.prototype.find.apply(this.rules[0], arguments);
  6079. }
  6080. };
  6081. AtRule.prototype.rulesets = function () {
  6082. if (this.rules) {
  6083. // assuming that there is only one rule at this point - that is how parser constructs the rule
  6084. return Ruleset.prototype.rulesets.apply(this.rules[0]);
  6085. }
  6086. };
  6087. AtRule.prototype.outputRuleset = function (context, output, rules) {
  6088. var ruleCnt = rules.length, i;
  6089. context.tabLevel = (context.tabLevel | 0) + 1;
  6090. // Compressed
  6091. if (context.compress) {
  6092. output.add('{');
  6093. for (i = 0; i < ruleCnt; i++) {
  6094. rules[i].genCSS(context, output);
  6095. }
  6096. output.add('}');
  6097. context.tabLevel--;
  6098. return;
  6099. }
  6100. // Non-compressed
  6101. var tabSetStr = '\n' + Array(context.tabLevel).join(' '), tabRuleStr = tabSetStr + ' ';
  6102. if (!ruleCnt) {
  6103. output.add(' {' + tabSetStr + '}');
  6104. } else {
  6105. output.add(' {' + tabRuleStr);
  6106. rules[0].genCSS(context, output);
  6107. for (i = 1; i < ruleCnt; i++) {
  6108. output.add(tabRuleStr);
  6109. rules[i].genCSS(context, output);
  6110. }
  6111. output.add(tabSetStr + '}');
  6112. }
  6113. context.tabLevel--;
  6114. };
  6115. module.exports = AtRule;
  6116. },{"./anonymous":50,"./node":76,"./ruleset":81,"./selector":82}],53:[function(require,module,exports){
  6117. var Node = require('./node');
  6118. var Attribute = function (key, op, value) {
  6119. this.key = key;
  6120. this.op = op;
  6121. this.value = value;
  6122. };
  6123. Attribute.prototype = new Node();
  6124. Attribute.prototype.type = 'Attribute';
  6125. Attribute.prototype.eval = function (context) {
  6126. return new Attribute(this.key.eval ? this.key.eval(context) : this.key,
  6127. this.op, (this.value && this.value.eval) ? this.value.eval(context) : this.value);
  6128. };
  6129. Attribute.prototype.genCSS = function (context, output) {
  6130. output.add(this.toCSS(context));
  6131. };
  6132. Attribute.prototype.toCSS = function (context) {
  6133. var value = this.key.toCSS ? this.key.toCSS(context) : this.key;
  6134. if (this.op) {
  6135. value += this.op;
  6136. value += (this.value.toCSS ? this.value.toCSS(context) : this.value);
  6137. }
  6138. return '[' + value + ']';
  6139. };
  6140. module.exports = Attribute;
  6141. },{"./node":76}],54:[function(require,module,exports){
  6142. var Node = require('./node'),
  6143. Anonymous = require('./anonymous'),
  6144. FunctionCaller = require('../functions/function-caller');
  6145. //
  6146. // A function call node.
  6147. //
  6148. var Call = function (name, args, index, currentFileInfo) {
  6149. this.name = name;
  6150. this.args = args;
  6151. this.calc = name === 'calc';
  6152. this._index = index;
  6153. this._fileInfo = currentFileInfo;
  6154. };
  6155. Call.prototype = new Node();
  6156. Call.prototype.type = 'Call';
  6157. Call.prototype.accept = function (visitor) {
  6158. if (this.args) {
  6159. this.args = visitor.visitArray(this.args);
  6160. }
  6161. };
  6162. //
  6163. // When evaluating a function call,
  6164. // we either find the function in the functionRegistry,
  6165. // in which case we call it, passing the evaluated arguments,
  6166. // if this returns null or we cannot find the function, we
  6167. // simply print it out as it appeared originally [2].
  6168. //
  6169. // The reason why we evaluate the arguments, is in the case where
  6170. // we try to pass a variable to a function, like: `saturate(@color)`.
  6171. // The function should receive the value, not the variable.
  6172. //
  6173. Call.prototype.eval = function (context) {
  6174. /**
  6175. * Turn off math for calc(), and switch back on for evaluating nested functions
  6176. */
  6177. var currentMathContext = context.mathOn;
  6178. context.mathOn = !this.calc;
  6179. if (this.calc || context.inCalc) {
  6180. context.enterCalc();
  6181. }
  6182. var args = this.args.map(function (a) { return a.eval(context); });
  6183. if (this.calc || context.inCalc) {
  6184. context.exitCalc();
  6185. }
  6186. context.mathOn = currentMathContext;
  6187. var result, funcCaller = new FunctionCaller(this.name, context, this.getIndex(), this.fileInfo());
  6188. if (funcCaller.isValid()) {
  6189. try {
  6190. result = funcCaller.call(args);
  6191. } catch (e) {
  6192. throw {
  6193. type: e.type || 'Runtime',
  6194. message: 'error evaluating function `' + this.name + '`' +
  6195. (e.message ? ': ' + e.message : ''),
  6196. index: this.getIndex(),
  6197. filename: this.fileInfo().filename,
  6198. line: e.lineNumber,
  6199. column: e.columnNumber
  6200. };
  6201. }
  6202. if (result !== null && result !== undefined) {
  6203. // Results that that are not nodes are cast as Anonymous nodes
  6204. // Falsy values or booleans are returned as empty nodes
  6205. if (!(result instanceof Node)) {
  6206. if (!result || result === true) {
  6207. result = new Anonymous(null);
  6208. }
  6209. else {
  6210. result = new Anonymous(result.toString());
  6211. }
  6212. }
  6213. result._index = this._index;
  6214. result._fileInfo = this._fileInfo;
  6215. return result;
  6216. }
  6217. }
  6218. return new Call(this.name, args, this.getIndex(), this.fileInfo());
  6219. };
  6220. Call.prototype.genCSS = function (context, output) {
  6221. output.add(this.name + '(', this.fileInfo(), this.getIndex());
  6222. for (var i = 0; i < this.args.length; i++) {
  6223. this.args[i].genCSS(context, output);
  6224. if (i + 1 < this.args.length) {
  6225. output.add(', ');
  6226. }
  6227. }
  6228. output.add(')');
  6229. };
  6230. module.exports = Call;
  6231. },{"../functions/function-caller":26,"./anonymous":50,"./node":76}],55:[function(require,module,exports){
  6232. var Node = require('./node'),
  6233. colors = require('../data/colors');
  6234. //
  6235. // RGB Colors - #ff0014, #eee
  6236. //
  6237. var Color = function (rgb, a, originalForm) {
  6238. //
  6239. // The end goal here, is to parse the arguments
  6240. // into an integer triplet, such as `128, 255, 0`
  6241. //
  6242. // This facilitates operations and conversions.
  6243. //
  6244. if (Array.isArray(rgb)) {
  6245. this.rgb = rgb;
  6246. } else if (rgb.length == 6) {
  6247. this.rgb = rgb.match(/.{2}/g).map(function (c) {
  6248. return parseInt(c, 16);
  6249. });
  6250. } else {
  6251. this.rgb = rgb.split('').map(function (c) {
  6252. return parseInt(c + c, 16);
  6253. });
  6254. }
  6255. this.alpha = typeof a === 'number' ? a : 1;
  6256. if (typeof originalForm !== 'undefined') {
  6257. this.value = originalForm;
  6258. }
  6259. };
  6260. Color.prototype = new Node();
  6261. Color.prototype.type = 'Color';
  6262. function clamp(v, max) {
  6263. return Math.min(Math.max(v, 0), max);
  6264. }
  6265. function toHex(v) {
  6266. return '#' + v.map(function (c) {
  6267. c = clamp(Math.round(c), 255);
  6268. return (c < 16 ? '0' : '') + c.toString(16);
  6269. }).join('');
  6270. }
  6271. Color.prototype.luma = function () {
  6272. var r = this.rgb[0] / 255,
  6273. g = this.rgb[1] / 255,
  6274. b = this.rgb[2] / 255;
  6275. r = (r <= 0.03928) ? r / 12.92 : Math.pow(((r + 0.055) / 1.055), 2.4);
  6276. g = (g <= 0.03928) ? g / 12.92 : Math.pow(((g + 0.055) / 1.055), 2.4);
  6277. b = (b <= 0.03928) ? b / 12.92 : Math.pow(((b + 0.055) / 1.055), 2.4);
  6278. return 0.2126 * r + 0.7152 * g + 0.0722 * b;
  6279. };
  6280. Color.prototype.genCSS = function (context, output) {
  6281. output.add(this.toCSS(context));
  6282. };
  6283. Color.prototype.toCSS = function (context, doNotCompress) {
  6284. var compress = context && context.compress && !doNotCompress, color, alpha;
  6285. // `value` is set if this color was originally
  6286. // converted from a named color string so we need
  6287. // to respect this and try to output named color too.
  6288. if (this.value) {
  6289. return this.value;
  6290. }
  6291. // If we have some transparency, the only way to represent it
  6292. // is via `rgba`. Otherwise, we use the hex representation,
  6293. // which has better compatibility with older browsers.
  6294. // Values are capped between `0` and `255`, rounded and zero-padded.
  6295. alpha = this.fround(context, this.alpha);
  6296. if (alpha < 1) {
  6297. return 'rgba(' + this.rgb.map(function (c) {
  6298. return clamp(Math.round(c), 255);
  6299. }).concat(clamp(alpha, 1))
  6300. .join(',' + (compress ? '' : ' ')) + ')';
  6301. }
  6302. color = this.toRGB();
  6303. if (compress) {
  6304. var splitcolor = color.split('');
  6305. // Convert color to short format
  6306. if (splitcolor[1] === splitcolor[2] && splitcolor[3] === splitcolor[4] && splitcolor[5] === splitcolor[6]) {
  6307. color = '#' + splitcolor[1] + splitcolor[3] + splitcolor[5];
  6308. }
  6309. }
  6310. return color;
  6311. };
  6312. //
  6313. // Operations have to be done per-channel, if not,
  6314. // channels will spill onto each other. Once we have
  6315. // our result, in the form of an integer triplet,
  6316. // we create a new Color node to hold the result.
  6317. //
  6318. Color.prototype.operate = function (context, op, other) {
  6319. var rgb = new Array(3);
  6320. var alpha = this.alpha * (1 - other.alpha) + other.alpha;
  6321. for (var c = 0; c < 3; c++) {
  6322. rgb[c] = this._operate(context, op, this.rgb[c], other.rgb[c]);
  6323. }
  6324. return new Color(rgb, alpha);
  6325. };
  6326. Color.prototype.toRGB = function () {
  6327. return toHex(this.rgb);
  6328. };
  6329. Color.prototype.toHSL = function () {
  6330. var r = this.rgb[0] / 255,
  6331. g = this.rgb[1] / 255,
  6332. b = this.rgb[2] / 255,
  6333. a = this.alpha;
  6334. var max = Math.max(r, g, b), min = Math.min(r, g, b);
  6335. var h, s, l = (max + min) / 2, d = max - min;
  6336. if (max === min) {
  6337. h = s = 0;
  6338. } else {
  6339. s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
  6340. switch (max) {
  6341. case r: h = (g - b) / d + (g < b ? 6 : 0); break;
  6342. case g: h = (b - r) / d + 2; break;
  6343. case b: h = (r - g) / d + 4; break;
  6344. }
  6345. h /= 6;
  6346. }
  6347. return { h: h * 360, s: s, l: l, a: a };
  6348. };
  6349. // Adapted from http://mjijackson.com/2008/02/rgb-to-hsl-and-rgb-to-hsv-color-model-conversion-algorithms-in-javascript
  6350. Color.prototype.toHSV = function () {
  6351. var r = this.rgb[0] / 255,
  6352. g = this.rgb[1] / 255,
  6353. b = this.rgb[2] / 255,
  6354. a = this.alpha;
  6355. var max = Math.max(r, g, b), min = Math.min(r, g, b);
  6356. var h, s, v = max;
  6357. var d = max - min;
  6358. if (max === 0) {
  6359. s = 0;
  6360. } else {
  6361. s = d / max;
  6362. }
  6363. if (max === min) {
  6364. h = 0;
  6365. } else {
  6366. switch (max) {
  6367. case r: h = (g - b) / d + (g < b ? 6 : 0); break;
  6368. case g: h = (b - r) / d + 2; break;
  6369. case b: h = (r - g) / d + 4; break;
  6370. }
  6371. h /= 6;
  6372. }
  6373. return { h: h * 360, s: s, v: v, a: a };
  6374. };
  6375. Color.prototype.toARGB = function () {
  6376. return toHex([this.alpha * 255].concat(this.rgb));
  6377. };
  6378. Color.prototype.compare = function (x) {
  6379. return (x.rgb &&
  6380. x.rgb[0] === this.rgb[0] &&
  6381. x.rgb[1] === this.rgb[1] &&
  6382. x.rgb[2] === this.rgb[2] &&
  6383. x.alpha === this.alpha) ? 0 : undefined;
  6384. };
  6385. Color.fromKeyword = function(keyword) {
  6386. var c, key = keyword.toLowerCase();
  6387. if (colors.hasOwnProperty(key)) {
  6388. c = new Color(colors[key].slice(1));
  6389. }
  6390. else if (key === 'transparent') {
  6391. c = new Color([0, 0, 0], 0);
  6392. }
  6393. if (c) {
  6394. c.value = keyword;
  6395. return c;
  6396. }
  6397. };
  6398. module.exports = Color;
  6399. },{"../data/colors":14,"./node":76}],56:[function(require,module,exports){
  6400. var Node = require('./node');
  6401. var Combinator = function (value) {
  6402. if (value === ' ') {
  6403. this.value = ' ';
  6404. this.emptyOrWhitespace = true;
  6405. } else {
  6406. this.value = value ? value.trim() : '';
  6407. this.emptyOrWhitespace = this.value === '';
  6408. }
  6409. };
  6410. Combinator.prototype = new Node();
  6411. Combinator.prototype.type = 'Combinator';
  6412. var _noSpaceCombinators = {
  6413. '': true,
  6414. ' ': true,
  6415. '|': true
  6416. };
  6417. Combinator.prototype.genCSS = function (context, output) {
  6418. var spaceOrEmpty = (context.compress || _noSpaceCombinators[this.value]) ? '' : ' ';
  6419. output.add(spaceOrEmpty + this.value + spaceOrEmpty);
  6420. };
  6421. module.exports = Combinator;
  6422. },{"./node":76}],57:[function(require,module,exports){
  6423. var Node = require('./node'),
  6424. getDebugInfo = require('./debug-info');
  6425. var Comment = function (value, isLineComment, index, currentFileInfo) {
  6426. this.value = value;
  6427. this.isLineComment = isLineComment;
  6428. this._index = index;
  6429. this._fileInfo = currentFileInfo;
  6430. this.allowRoot = true;
  6431. };
  6432. Comment.prototype = new Node();
  6433. Comment.prototype.type = 'Comment';
  6434. Comment.prototype.genCSS = function (context, output) {
  6435. if (this.debugInfo) {
  6436. output.add(getDebugInfo(context, this), this.fileInfo(), this.getIndex());
  6437. }
  6438. output.add(this.value);
  6439. };
  6440. Comment.prototype.isSilent = function(context) {
  6441. var isCompressed = context.compress && this.value[2] !== '!';
  6442. return this.isLineComment || isCompressed;
  6443. };
  6444. module.exports = Comment;
  6445. },{"./debug-info":59,"./node":76}],58:[function(require,module,exports){
  6446. var Node = require('./node');
  6447. var Condition = function (op, l, r, i, negate) {
  6448. this.op = op.trim();
  6449. this.lvalue = l;
  6450. this.rvalue = r;
  6451. this._index = i;
  6452. this.negate = negate;
  6453. };
  6454. Condition.prototype = new Node();
  6455. Condition.prototype.type = 'Condition';
  6456. Condition.prototype.accept = function (visitor) {
  6457. this.lvalue = visitor.visit(this.lvalue);
  6458. this.rvalue = visitor.visit(this.rvalue);
  6459. };
  6460. Condition.prototype.eval = function (context) {
  6461. var result = (function (op, a, b) {
  6462. switch (op) {
  6463. case 'and': return a && b;
  6464. case 'or': return a || b;
  6465. default:
  6466. switch (Node.compare(a, b)) {
  6467. case -1:
  6468. return op === '<' || op === '=<' || op === '<=';
  6469. case 0:
  6470. return op === '=' || op === '>=' || op === '=<' || op === '<=';
  6471. case 1:
  6472. return op === '>' || op === '>=';
  6473. default:
  6474. return false;
  6475. }
  6476. }
  6477. })(this.op, this.lvalue.eval(context), this.rvalue.eval(context));
  6478. return this.negate ? !result : result;
  6479. };
  6480. module.exports = Condition;
  6481. },{"./node":76}],59:[function(require,module,exports){
  6482. var debugInfo = function(context, ctx, lineSeparator) {
  6483. var result = '';
  6484. if (context.dumpLineNumbers && !context.compress) {
  6485. switch (context.dumpLineNumbers) {
  6486. case 'comments':
  6487. result = debugInfo.asComment(ctx);
  6488. break;
  6489. case 'mediaquery':
  6490. result = debugInfo.asMediaQuery(ctx);
  6491. break;
  6492. case 'all':
  6493. result = debugInfo.asComment(ctx) + (lineSeparator || '') + debugInfo.asMediaQuery(ctx);
  6494. break;
  6495. }
  6496. }
  6497. return result;
  6498. };
  6499. debugInfo.asComment = function(ctx) {
  6500. return '/* line ' + ctx.debugInfo.lineNumber + ', ' + ctx.debugInfo.fileName + ' */\n';
  6501. };
  6502. debugInfo.asMediaQuery = function(ctx) {
  6503. var filenameWithProtocol = ctx.debugInfo.fileName;
  6504. if (!/^[a-z]+:\/\//i.test(filenameWithProtocol)) {
  6505. filenameWithProtocol = 'file://' + filenameWithProtocol;
  6506. }
  6507. return '@media -sass-debug-info{filename{font-family:' +
  6508. filenameWithProtocol.replace(/([.:\/\\])/g, function (a) {
  6509. if (a == '\\') {
  6510. a = '\/';
  6511. }
  6512. return '\\' + a;
  6513. }) +
  6514. '}line{font-family:\\00003' + ctx.debugInfo.lineNumber + '}}\n';
  6515. };
  6516. module.exports = debugInfo;
  6517. },{}],60:[function(require,module,exports){
  6518. var Node = require('./node'),
  6519. Value = require('./value'),
  6520. Keyword = require('./keyword'),
  6521. Anonymous = require('./anonymous'),
  6522. MATH = require('../constants').Math;
  6523. var Declaration = function (name, value, important, merge, index, currentFileInfo, inline, variable) {
  6524. this.name = name;
  6525. this.value = (value instanceof Node) ? value : new Value([value ? new Anonymous(value) : null]);
  6526. this.important = important ? ' ' + important.trim() : '';
  6527. this.merge = merge;
  6528. this._index = index;
  6529. this._fileInfo = currentFileInfo;
  6530. this.inline = inline || false;
  6531. this.variable = (variable !== undefined) ? variable
  6532. : (name.charAt && (name.charAt(0) === '@'));
  6533. this.allowRoot = true;
  6534. this.setParent(this.value, this);
  6535. };
  6536. function evalName(context, name) {
  6537. var value = '', i, n = name.length,
  6538. output = {add: function (s) {value += s;}};
  6539. for (i = 0; i < n; i++) {
  6540. name[i].eval(context).genCSS(context, output);
  6541. }
  6542. return value;
  6543. }
  6544. Declaration.prototype = new Node();
  6545. Declaration.prototype.type = 'Declaration';
  6546. Declaration.prototype.genCSS = function (context, output) {
  6547. output.add(this.name + (context.compress ? ':' : ': '), this.fileInfo(), this.getIndex());
  6548. try {
  6549. this.value.genCSS(context, output);
  6550. }
  6551. catch (e) {
  6552. e.index = this._index;
  6553. e.filename = this._fileInfo.filename;
  6554. throw e;
  6555. }
  6556. output.add(this.important + ((this.inline || (context.lastRule && context.compress)) ? '' : ';'), this._fileInfo, this._index);
  6557. };
  6558. Declaration.prototype.eval = function (context) {
  6559. var mathBypass = false, prevMath, name = this.name, evaldValue, variable = this.variable;
  6560. if (typeof name !== 'string') {
  6561. // expand 'primitive' name directly to get
  6562. // things faster (~10% for benchmark.less):
  6563. name = (name.length === 1) && (name[0] instanceof Keyword) ?
  6564. name[0].value : evalName(context, name);
  6565. variable = false; // never treat expanded interpolation as new variable name
  6566. }
  6567. // @todo remove when parens-division is default
  6568. if (name === 'font' && context.math === MATH.ALWAYS) {
  6569. mathBypass = true;
  6570. prevMath = context.math;
  6571. context.math = MATH.PARENS_DIVISION;
  6572. }
  6573. try {
  6574. context.importantScope.push({});
  6575. evaldValue = this.value.eval(context);
  6576. if (!this.variable && evaldValue.type === 'DetachedRuleset') {
  6577. throw { message: 'Rulesets cannot be evaluated on a property.',
  6578. index: this.getIndex(), filename: this.fileInfo().filename };
  6579. }
  6580. var important = this.important,
  6581. importantResult = context.importantScope.pop();
  6582. if (!important && importantResult.important) {
  6583. important = importantResult.important;
  6584. }
  6585. return new Declaration(name,
  6586. evaldValue,
  6587. important,
  6588. this.merge,
  6589. this.getIndex(), this.fileInfo(), this.inline,
  6590. variable);
  6591. }
  6592. catch (e) {
  6593. if (typeof e.index !== 'number') {
  6594. e.index = this.getIndex();
  6595. e.filename = this.fileInfo().filename;
  6596. }
  6597. throw e;
  6598. }
  6599. finally {
  6600. if (mathBypass) {
  6601. context.math = prevMath;
  6602. }
  6603. }
  6604. };
  6605. Declaration.prototype.makeImportant = function () {
  6606. return new Declaration(this.name,
  6607. this.value,
  6608. '!important',
  6609. this.merge,
  6610. this.getIndex(), this.fileInfo(), this.inline);
  6611. };
  6612. module.exports = Declaration;
  6613. },{"../constants":12,"./anonymous":50,"./keyword":70,"./node":76,"./value":86}],61:[function(require,module,exports){
  6614. var Node = require('./node'),
  6615. contexts = require('../contexts'),
  6616. utils = require('../utils');
  6617. var DetachedRuleset = function (ruleset, frames) {
  6618. this.ruleset = ruleset;
  6619. this.frames = frames;
  6620. this.setParent(this.ruleset, this);
  6621. };
  6622. DetachedRuleset.prototype = new Node();
  6623. DetachedRuleset.prototype.type = 'DetachedRuleset';
  6624. DetachedRuleset.prototype.evalFirst = true;
  6625. DetachedRuleset.prototype.accept = function (visitor) {
  6626. this.ruleset = visitor.visit(this.ruleset);
  6627. };
  6628. DetachedRuleset.prototype.eval = function (context) {
  6629. var frames = this.frames || utils.copyArray(context.frames);
  6630. return new DetachedRuleset(this.ruleset, frames);
  6631. };
  6632. DetachedRuleset.prototype.callEval = function (context) {
  6633. return this.ruleset.eval(this.frames ? new contexts.Eval(context, this.frames.concat(context.frames)) : context);
  6634. };
  6635. module.exports = DetachedRuleset;
  6636. },{"../contexts":13,"../utils":89,"./node":76}],62:[function(require,module,exports){
  6637. var Node = require('./node'),
  6638. unitConversions = require('../data/unit-conversions'),
  6639. Unit = require('./unit'),
  6640. Color = require('./color');
  6641. //
  6642. // A number with a unit
  6643. //
  6644. var Dimension = function (value, unit) {
  6645. this.value = parseFloat(value);
  6646. if (isNaN(this.value)) {
  6647. throw new Error('Dimension is not a number.');
  6648. }
  6649. this.unit = (unit && unit instanceof Unit) ? unit :
  6650. new Unit(unit ? [unit] : undefined);
  6651. this.setParent(this.unit, this);
  6652. };
  6653. Dimension.prototype = new Node();
  6654. Dimension.prototype.type = 'Dimension';
  6655. Dimension.prototype.accept = function (visitor) {
  6656. this.unit = visitor.visit(this.unit);
  6657. };
  6658. Dimension.prototype.eval = function (context) {
  6659. return this;
  6660. };
  6661. Dimension.prototype.toColor = function () {
  6662. return new Color([this.value, this.value, this.value]);
  6663. };
  6664. Dimension.prototype.genCSS = function (context, output) {
  6665. if ((context && context.strictUnits) && !this.unit.isSingular()) {
  6666. throw new Error('Multiple units in dimension. Correct the units or use the unit function. Bad unit: ' + this.unit.toString());
  6667. }
  6668. var value = this.fround(context, this.value),
  6669. strValue = String(value);
  6670. if (value !== 0 && value < 0.000001 && value > -0.000001) {
  6671. // would be output 1e-6 etc.
  6672. strValue = value.toFixed(20).replace(/0+$/, '');
  6673. }
  6674. if (context && context.compress) {
  6675. // Zero values doesn't need a unit
  6676. if (value === 0 && this.unit.isLength()) {
  6677. output.add(strValue);
  6678. return;
  6679. }
  6680. // Float values doesn't need a leading zero
  6681. if (value > 0 && value < 1) {
  6682. strValue = (strValue).substr(1);
  6683. }
  6684. }
  6685. output.add(strValue);
  6686. this.unit.genCSS(context, output);
  6687. };
  6688. // In an operation between two Dimensions,
  6689. // we default to the first Dimension's unit,
  6690. // so `1px + 2` will yield `3px`.
  6691. Dimension.prototype.operate = function (context, op, other) {
  6692. /* jshint noempty:false */
  6693. var value = this._operate(context, op, this.value, other.value),
  6694. unit = this.unit.clone();
  6695. if (op === '+' || op === '-') {
  6696. if (unit.numerator.length === 0 && unit.denominator.length === 0) {
  6697. unit = other.unit.clone();
  6698. if (this.unit.backupUnit) {
  6699. unit.backupUnit = this.unit.backupUnit;
  6700. }
  6701. } else if (other.unit.numerator.length === 0 && unit.denominator.length === 0) {
  6702. // do nothing
  6703. } else {
  6704. other = other.convertTo(this.unit.usedUnits());
  6705. if (context.strictUnits && other.unit.toString() !== unit.toString()) {
  6706. throw new Error('Incompatible units. Change the units or use the unit function. Bad units: \'' + unit.toString() +
  6707. '\' and \'' + other.unit.toString() + '\'.');
  6708. }
  6709. value = this._operate(context, op, this.value, other.value);
  6710. }
  6711. } else if (op === '*') {
  6712. unit.numerator = unit.numerator.concat(other.unit.numerator).sort();
  6713. unit.denominator = unit.denominator.concat(other.unit.denominator).sort();
  6714. unit.cancel();
  6715. } else if (op === '/') {
  6716. unit.numerator = unit.numerator.concat(other.unit.denominator).sort();
  6717. unit.denominator = unit.denominator.concat(other.unit.numerator).sort();
  6718. unit.cancel();
  6719. }
  6720. return new Dimension(value, unit);
  6721. };
  6722. Dimension.prototype.compare = function (other) {
  6723. var a, b;
  6724. if (!(other instanceof Dimension)) {
  6725. return undefined;
  6726. }
  6727. if (this.unit.isEmpty() || other.unit.isEmpty()) {
  6728. a = this;
  6729. b = other;
  6730. } else {
  6731. a = this.unify();
  6732. b = other.unify();
  6733. if (a.unit.compare(b.unit) !== 0) {
  6734. return undefined;
  6735. }
  6736. }
  6737. return Node.numericCompare(a.value, b.value);
  6738. };
  6739. Dimension.prototype.unify = function () {
  6740. return this.convertTo({ length: 'px', duration: 's', angle: 'rad' });
  6741. };
  6742. Dimension.prototype.convertTo = function (conversions) {
  6743. var value = this.value, unit = this.unit.clone(),
  6744. i, groupName, group, targetUnit, derivedConversions = {}, applyUnit;
  6745. if (typeof conversions === 'string') {
  6746. for (i in unitConversions) {
  6747. if (unitConversions[i].hasOwnProperty(conversions)) {
  6748. derivedConversions = {};
  6749. derivedConversions[i] = conversions;
  6750. }
  6751. }
  6752. conversions = derivedConversions;
  6753. }
  6754. applyUnit = function (atomicUnit, denominator) {
  6755. /* jshint loopfunc:true */
  6756. if (group.hasOwnProperty(atomicUnit)) {
  6757. if (denominator) {
  6758. value = value / (group[atomicUnit] / group[targetUnit]);
  6759. } else {
  6760. value = value * (group[atomicUnit] / group[targetUnit]);
  6761. }
  6762. return targetUnit;
  6763. }
  6764. return atomicUnit;
  6765. };
  6766. for (groupName in conversions) {
  6767. if (conversions.hasOwnProperty(groupName)) {
  6768. targetUnit = conversions[groupName];
  6769. group = unitConversions[groupName];
  6770. unit.map(applyUnit);
  6771. }
  6772. }
  6773. unit.cancel();
  6774. return new Dimension(value, unit);
  6775. };
  6776. module.exports = Dimension;
  6777. },{"../data/unit-conversions":16,"./color":55,"./node":76,"./unit":84}],63:[function(require,module,exports){
  6778. var Node = require('./node'),
  6779. Paren = require('./paren'),
  6780. Combinator = require('./combinator');
  6781. var Element = function (combinator, value, isVariable, index, currentFileInfo, visibilityInfo) {
  6782. this.combinator = combinator instanceof Combinator ?
  6783. combinator : new Combinator(combinator);
  6784. if (typeof value === 'string') {
  6785. this.value = value.trim();
  6786. } else if (value) {
  6787. this.value = value;
  6788. } else {
  6789. this.value = '';
  6790. }
  6791. this.isVariable = isVariable;
  6792. this._index = index;
  6793. this._fileInfo = currentFileInfo;
  6794. this.copyVisibilityInfo(visibilityInfo);
  6795. this.setParent(this.combinator, this);
  6796. };
  6797. Element.prototype = new Node();
  6798. Element.prototype.type = 'Element';
  6799. Element.prototype.accept = function (visitor) {
  6800. var value = this.value;
  6801. this.combinator = visitor.visit(this.combinator);
  6802. if (typeof value === 'object') {
  6803. this.value = visitor.visit(value);
  6804. }
  6805. };
  6806. Element.prototype.eval = function (context) {
  6807. return new Element(this.combinator,
  6808. this.value.eval ? this.value.eval(context) : this.value,
  6809. this.isVariable,
  6810. this.getIndex(),
  6811. this.fileInfo(), this.visibilityInfo());
  6812. };
  6813. Element.prototype.clone = function () {
  6814. return new Element(this.combinator,
  6815. this.value,
  6816. this.isVariable,
  6817. this.getIndex(),
  6818. this.fileInfo(), this.visibilityInfo());
  6819. };
  6820. Element.prototype.genCSS = function (context, output) {
  6821. output.add(this.toCSS(context), this.fileInfo(), this.getIndex());
  6822. };
  6823. Element.prototype.toCSS = function (context) {
  6824. context = context || {};
  6825. var value = this.value, firstSelector = context.firstSelector;
  6826. if (value instanceof Paren) {
  6827. // selector in parens should not be affected by outer selector
  6828. // flags (breaks only interpolated selectors - see #1973)
  6829. context.firstSelector = true;
  6830. }
  6831. value = value.toCSS ? value.toCSS(context) : value;
  6832. context.firstSelector = firstSelector;
  6833. if (value === '' && this.combinator.value.charAt(0) === '&') {
  6834. return '';
  6835. } else {
  6836. return this.combinator.toCSS(context) + value;
  6837. }
  6838. };
  6839. module.exports = Element;
  6840. },{"./combinator":56,"./node":76,"./paren":78}],64:[function(require,module,exports){
  6841. var Node = require('./node'),
  6842. Paren = require('./paren'),
  6843. Comment = require('./comment'),
  6844. Dimension = require('./dimension'),
  6845. MATH = require('../constants').Math;
  6846. var Expression = function (value, noSpacing) {
  6847. this.value = value;
  6848. this.noSpacing = noSpacing;
  6849. if (!value) {
  6850. throw new Error('Expression requires an array parameter');
  6851. }
  6852. };
  6853. Expression.prototype = new Node();
  6854. Expression.prototype.type = 'Expression';
  6855. Expression.prototype.accept = function (visitor) {
  6856. this.value = visitor.visitArray(this.value);
  6857. };
  6858. Expression.prototype.eval = function (context) {
  6859. var returnValue,
  6860. mathOn = context.isMathOn(),
  6861. inParenthesis = this.parens &&
  6862. (context.math !== MATH.STRICT_LEGACY || !this.parensInOp),
  6863. doubleParen = false;
  6864. if (inParenthesis) {
  6865. context.inParenthesis();
  6866. }
  6867. if (this.value.length > 1) {
  6868. returnValue = new Expression(this.value.map(function (e) {
  6869. if (!e.eval) {
  6870. return e;
  6871. }
  6872. return e.eval(context);
  6873. }), this.noSpacing);
  6874. } else if (this.value.length === 1) {
  6875. if (this.value[0].parens && !this.value[0].parensInOp && !context.inCalc) {
  6876. doubleParen = true;
  6877. }
  6878. returnValue = this.value[0].eval(context);
  6879. } else {
  6880. returnValue = this;
  6881. }
  6882. if (inParenthesis) {
  6883. context.outOfParenthesis();
  6884. }
  6885. if (this.parens && this.parensInOp && !mathOn && !doubleParen
  6886. && (!(returnValue instanceof Dimension))) {
  6887. returnValue = new Paren(returnValue);
  6888. }
  6889. return returnValue;
  6890. };
  6891. Expression.prototype.genCSS = function (context, output) {
  6892. for (var i = 0; i < this.value.length; i++) {
  6893. this.value[i].genCSS(context, output);
  6894. if (!this.noSpacing && i + 1 < this.value.length) {
  6895. output.add(' ');
  6896. }
  6897. }
  6898. };
  6899. Expression.prototype.throwAwayComments = function () {
  6900. this.value = this.value.filter(function(v) {
  6901. return !(v instanceof Comment);
  6902. });
  6903. };
  6904. module.exports = Expression;
  6905. },{"../constants":12,"./comment":57,"./dimension":62,"./node":76,"./paren":78}],65:[function(require,module,exports){
  6906. var Node = require('./node'),
  6907. Selector = require('./selector');
  6908. var Extend = function Extend(selector, option, index, currentFileInfo, visibilityInfo) {
  6909. this.selector = selector;
  6910. this.option = option;
  6911. this.object_id = Extend.next_id++;
  6912. this.parent_ids = [this.object_id];
  6913. this._index = index;
  6914. this._fileInfo = currentFileInfo;
  6915. this.copyVisibilityInfo(visibilityInfo);
  6916. this.allowRoot = true;
  6917. switch (option) {
  6918. case 'all':
  6919. this.allowBefore = true;
  6920. this.allowAfter = true;
  6921. break;
  6922. default:
  6923. this.allowBefore = false;
  6924. this.allowAfter = false;
  6925. break;
  6926. }
  6927. this.setParent(this.selector, this);
  6928. };
  6929. Extend.next_id = 0;
  6930. Extend.prototype = new Node();
  6931. Extend.prototype.type = 'Extend';
  6932. Extend.prototype.accept = function (visitor) {
  6933. this.selector = visitor.visit(this.selector);
  6934. };
  6935. Extend.prototype.eval = function (context) {
  6936. return new Extend(this.selector.eval(context), this.option, this.getIndex(), this.fileInfo(), this.visibilityInfo());
  6937. };
  6938. Extend.prototype.clone = function (context) {
  6939. return new Extend(this.selector, this.option, this.getIndex(), this.fileInfo(), this.visibilityInfo());
  6940. };
  6941. // it concatenates (joins) all selectors in selector array
  6942. Extend.prototype.findSelfSelectors = function (selectors) {
  6943. var selfElements = [],
  6944. i,
  6945. selectorElements;
  6946. for (i = 0; i < selectors.length; i++) {
  6947. selectorElements = selectors[i].elements;
  6948. // duplicate the logic in genCSS function inside the selector node.
  6949. // future TODO - move both logics into the selector joiner visitor
  6950. if (i > 0 && selectorElements.length && selectorElements[0].combinator.value === '') {
  6951. selectorElements[0].combinator.value = ' ';
  6952. }
  6953. selfElements = selfElements.concat(selectors[i].elements);
  6954. }
  6955. this.selfSelectors = [new Selector(selfElements)];
  6956. this.selfSelectors[0].copyVisibilityInfo(this.visibilityInfo());
  6957. };
  6958. module.exports = Extend;
  6959. },{"./node":76,"./selector":82}],66:[function(require,module,exports){
  6960. var Node = require('./node'),
  6961. Media = require('./media'),
  6962. URL = require('./url'),
  6963. Quoted = require('./quoted'),
  6964. Ruleset = require('./ruleset'),
  6965. Anonymous = require('./anonymous'),
  6966. utils = require('../utils'),
  6967. LessError = require('../less-error');
  6968. //
  6969. // CSS @import node
  6970. //
  6971. // The general strategy here is that we don't want to wait
  6972. // for the parsing to be completed, before we start importing
  6973. // the file. That's because in the context of a browser,
  6974. // most of the time will be spent waiting for the server to respond.
  6975. //
  6976. // On creation, we push the import path to our import queue, though
  6977. // `import,push`, we also pass it a callback, which it'll call once
  6978. // the file has been fetched, and parsed.
  6979. //
  6980. var Import = function (path, features, options, index, currentFileInfo, visibilityInfo) {
  6981. this.options = options;
  6982. this._index = index;
  6983. this._fileInfo = currentFileInfo;
  6984. this.path = path;
  6985. this.features = features;
  6986. this.allowRoot = true;
  6987. if (this.options.less !== undefined || this.options.inline) {
  6988. this.css = !this.options.less || this.options.inline;
  6989. } else {
  6990. var pathValue = this.getPath();
  6991. if (pathValue && /[#\.\&\?]css([\?;].*)?$/.test(pathValue)) {
  6992. this.css = true;
  6993. }
  6994. }
  6995. this.copyVisibilityInfo(visibilityInfo);
  6996. this.setParent(this.features, this);
  6997. this.setParent(this.path, this);
  6998. };
  6999. //
  7000. // The actual import node doesn't return anything, when converted to CSS.
  7001. // The reason is that it's used at the evaluation stage, so that the rules
  7002. // it imports can be treated like any other rules.
  7003. //
  7004. // In `eval`, we make sure all Import nodes get evaluated, recursively, so
  7005. // we end up with a flat structure, which can easily be imported in the parent
  7006. // ruleset.
  7007. //
  7008. Import.prototype = new Node();
  7009. Import.prototype.type = 'Import';
  7010. Import.prototype.accept = function (visitor) {
  7011. if (this.features) {
  7012. this.features = visitor.visit(this.features);
  7013. }
  7014. this.path = visitor.visit(this.path);
  7015. if (!this.options.isPlugin && !this.options.inline && this.root) {
  7016. this.root = visitor.visit(this.root);
  7017. }
  7018. };
  7019. Import.prototype.genCSS = function (context, output) {
  7020. if (this.css && this.path._fileInfo.reference === undefined) {
  7021. output.add('@import ', this._fileInfo, this._index);
  7022. this.path.genCSS(context, output);
  7023. if (this.features) {
  7024. output.add(' ');
  7025. this.features.genCSS(context, output);
  7026. }
  7027. output.add(';');
  7028. }
  7029. };
  7030. Import.prototype.getPath = function () {
  7031. return (this.path instanceof URL) ?
  7032. this.path.value.value : this.path.value;
  7033. };
  7034. Import.prototype.isVariableImport = function () {
  7035. var path = this.path;
  7036. if (path instanceof URL) {
  7037. path = path.value;
  7038. }
  7039. if (path instanceof Quoted) {
  7040. return path.containsVariables();
  7041. }
  7042. return true;
  7043. };
  7044. Import.prototype.evalForImport = function (context) {
  7045. var path = this.path;
  7046. if (path instanceof URL) {
  7047. path = path.value;
  7048. }
  7049. return new Import(path.eval(context), this.features, this.options, this._index, this._fileInfo, this.visibilityInfo());
  7050. };
  7051. Import.prototype.evalPath = function (context) {
  7052. var path = this.path.eval(context);
  7053. var fileInfo = this._fileInfo;
  7054. if (!(path instanceof URL)) {
  7055. // Add the rootpath if the URL requires a rewrite
  7056. var pathValue = path.value;
  7057. if (fileInfo &&
  7058. pathValue &&
  7059. context.pathRequiresRewrite(pathValue)) {
  7060. path.value = context.rewritePath(pathValue, fileInfo.rootpath);
  7061. } else {
  7062. path.value = context.normalizePath(path.value);
  7063. }
  7064. }
  7065. return path;
  7066. };
  7067. Import.prototype.eval = function (context) {
  7068. var result = this.doEval(context);
  7069. if (this.options.reference || this.blocksVisibility()) {
  7070. if (result.length || result.length === 0) {
  7071. result.forEach(function (node) {
  7072. node.addVisibilityBlock();
  7073. }
  7074. );
  7075. } else {
  7076. result.addVisibilityBlock();
  7077. }
  7078. }
  7079. return result;
  7080. };
  7081. Import.prototype.doEval = function (context) {
  7082. var ruleset, registry,
  7083. features = this.features && this.features.eval(context);
  7084. if (this.options.isPlugin) {
  7085. if (this.root && this.root.eval) {
  7086. try {
  7087. this.root.eval(context);
  7088. }
  7089. catch (e) {
  7090. e.message = 'Plugin error during evaluation';
  7091. throw new LessError(e, this.root.imports, this.root.filename);
  7092. }
  7093. }
  7094. registry = context.frames[0] && context.frames[0].functionRegistry;
  7095. if ( registry && this.root && this.root.functions ) {
  7096. registry.addMultiple( this.root.functions );
  7097. }
  7098. return [];
  7099. }
  7100. if (this.skip) {
  7101. if (typeof this.skip === 'function') {
  7102. this.skip = this.skip();
  7103. }
  7104. if (this.skip) {
  7105. return [];
  7106. }
  7107. }
  7108. if (this.options.inline) {
  7109. var contents = new Anonymous(this.root, 0,
  7110. {
  7111. filename: this.importedFilename,
  7112. reference: this.path._fileInfo && this.path._fileInfo.reference
  7113. }, true, true);
  7114. return this.features ? new Media([contents], this.features.value) : [contents];
  7115. } else if (this.css) {
  7116. var newImport = new Import(this.evalPath(context), features, this.options, this._index);
  7117. if (!newImport.css && this.error) {
  7118. throw this.error;
  7119. }
  7120. return newImport;
  7121. } else {
  7122. ruleset = new Ruleset(null, utils.copyArray(this.root.rules));
  7123. ruleset.evalImports(context);
  7124. return this.features ? new Media(ruleset.rules, this.features.value) : ruleset.rules;
  7125. }
  7126. };
  7127. module.exports = Import;
  7128. },{"../less-error":38,"../utils":89,"./anonymous":50,"./media":71,"./node":76,"./quoted":80,"./ruleset":81,"./url":85}],67:[function(require,module,exports){
  7129. var tree = Object.create(null);
  7130. tree.Node = require('./node');
  7131. tree.Color = require('./color');
  7132. tree.AtRule = require('./atrule');
  7133. tree.DetachedRuleset = require('./detached-ruleset');
  7134. tree.Operation = require('./operation');
  7135. tree.Dimension = require('./dimension');
  7136. tree.Unit = require('./unit');
  7137. tree.Keyword = require('./keyword');
  7138. tree.Variable = require('./variable');
  7139. tree.Property = require('./property');
  7140. tree.Ruleset = require('./ruleset');
  7141. tree.Element = require('./element');
  7142. tree.Attribute = require('./attribute');
  7143. tree.Combinator = require('./combinator');
  7144. tree.Selector = require('./selector');
  7145. tree.Quoted = require('./quoted');
  7146. tree.Expression = require('./expression');
  7147. tree.Declaration = require('./declaration');
  7148. tree.Call = require('./call');
  7149. tree.URL = require('./url');
  7150. tree.Import = require('./import');
  7151. tree.mixin = {
  7152. Call: require('./mixin-call'),
  7153. Definition: require('./mixin-definition')
  7154. };
  7155. tree.Comment = require('./comment');
  7156. tree.Anonymous = require('./anonymous');
  7157. tree.Value = require('./value');
  7158. tree.JavaScript = require('./javascript');
  7159. tree.Assignment = require('./assignment');
  7160. tree.Condition = require('./condition');
  7161. tree.Paren = require('./paren');
  7162. tree.Media = require('./media');
  7163. tree.UnicodeDescriptor = require('./unicode-descriptor');
  7164. tree.Negative = require('./negative');
  7165. tree.Extend = require('./extend');
  7166. tree.VariableCall = require('./variable-call');
  7167. tree.NamespaceValue = require('./namespace-value');
  7168. module.exports = tree;
  7169. },{"./anonymous":50,"./assignment":51,"./atrule":52,"./attribute":53,"./call":54,"./color":55,"./combinator":56,"./comment":57,"./condition":58,"./declaration":60,"./detached-ruleset":61,"./dimension":62,"./element":63,"./expression":64,"./extend":65,"./import":66,"./javascript":68,"./keyword":70,"./media":71,"./mixin-call":72,"./mixin-definition":73,"./namespace-value":74,"./negative":75,"./node":76,"./operation":77,"./paren":78,"./property":79,"./quoted":80,"./ruleset":81,"./selector":82,"./unicode-descriptor":83,"./unit":84,"./url":85,"./value":86,"./variable":88,"./variable-call":87}],68:[function(require,module,exports){
  7170. var JsEvalNode = require('./js-eval-node'),
  7171. Dimension = require('./dimension'),
  7172. Quoted = require('./quoted'),
  7173. Anonymous = require('./anonymous');
  7174. var JavaScript = function (string, escaped, index, currentFileInfo) {
  7175. this.escaped = escaped;
  7176. this.expression = string;
  7177. this._index = index;
  7178. this._fileInfo = currentFileInfo;
  7179. };
  7180. JavaScript.prototype = new JsEvalNode();
  7181. JavaScript.prototype.type = 'JavaScript';
  7182. JavaScript.prototype.eval = function(context) {
  7183. var result = this.evaluateJavaScript(this.expression, context);
  7184. var type = typeof result;
  7185. if (type === 'number' && !isNaN(result)) {
  7186. return new Dimension(result);
  7187. } else if (type === 'string') {
  7188. return new Quoted('"' + result + '"', result, this.escaped, this._index);
  7189. } else if (Array.isArray(result)) {
  7190. return new Anonymous(result.join(', '));
  7191. } else {
  7192. return new Anonymous(result);
  7193. }
  7194. };
  7195. module.exports = JavaScript;
  7196. },{"./anonymous":50,"./dimension":62,"./js-eval-node":69,"./quoted":80}],69:[function(require,module,exports){
  7197. var Node = require('./node'),
  7198. Variable = require('./variable');
  7199. var JsEvalNode = function() {
  7200. };
  7201. JsEvalNode.prototype = new Node();
  7202. JsEvalNode.prototype.evaluateJavaScript = function (expression, context) {
  7203. var result,
  7204. that = this,
  7205. evalContext = {};
  7206. if (!context.javascriptEnabled) {
  7207. throw { message: 'Inline JavaScript is not enabled. Is it set in your options?',
  7208. filename: this.fileInfo().filename,
  7209. index: this.getIndex() };
  7210. }
  7211. expression = expression.replace(/@\{([\w-]+)\}/g, function (_, name) {
  7212. return that.jsify(new Variable('@' + name, that.getIndex(), that.fileInfo()).eval(context));
  7213. });
  7214. try {
  7215. expression = new Function('return (' + expression + ')');
  7216. } catch (e) {
  7217. throw { message: 'JavaScript evaluation error: ' + e.message + ' from `' + expression + '`' ,
  7218. filename: this.fileInfo().filename,
  7219. index: this.getIndex() };
  7220. }
  7221. var variables = context.frames[0].variables();
  7222. for (var k in variables) {
  7223. if (variables.hasOwnProperty(k)) {
  7224. /* jshint loopfunc:true */
  7225. evalContext[k.slice(1)] = {
  7226. value: variables[k].value,
  7227. toJS: function () {
  7228. return this.value.eval(context).toCSS();
  7229. }
  7230. };
  7231. }
  7232. }
  7233. try {
  7234. result = expression.call(evalContext);
  7235. } catch (e) {
  7236. throw { message: 'JavaScript evaluation error: \'' + e.name + ': ' + e.message.replace(/["]/g, '\'') + '\'' ,
  7237. filename: this.fileInfo().filename,
  7238. index: this.getIndex() };
  7239. }
  7240. return result;
  7241. };
  7242. JsEvalNode.prototype.jsify = function (obj) {
  7243. if (Array.isArray(obj.value) && (obj.value.length > 1)) {
  7244. return '[' + obj.value.map(function (v) { return v.toCSS(); }).join(', ') + ']';
  7245. } else {
  7246. return obj.toCSS();
  7247. }
  7248. };
  7249. module.exports = JsEvalNode;
  7250. },{"./node":76,"./variable":88}],70:[function(require,module,exports){
  7251. var Node = require('./node');
  7252. var Keyword = function (value) { this.value = value; };
  7253. Keyword.prototype = new Node();
  7254. Keyword.prototype.type = 'Keyword';
  7255. Keyword.prototype.genCSS = function (context, output) {
  7256. if (this.value === '%') { throw { type: 'Syntax', message: 'Invalid % without number' }; }
  7257. output.add(this.value);
  7258. };
  7259. Keyword.True = new Keyword('true');
  7260. Keyword.False = new Keyword('false');
  7261. module.exports = Keyword;
  7262. },{"./node":76}],71:[function(require,module,exports){
  7263. var Ruleset = require('./ruleset'),
  7264. Value = require('./value'),
  7265. Selector = require('./selector'),
  7266. Anonymous = require('./anonymous'),
  7267. Expression = require('./expression'),
  7268. AtRule = require('./atrule'),
  7269. utils = require('../utils');
  7270. var Media = function (value, features, index, currentFileInfo, visibilityInfo) {
  7271. this._index = index;
  7272. this._fileInfo = currentFileInfo;
  7273. var selectors = (new Selector([], null, null, this._index, this._fileInfo)).createEmptySelectors();
  7274. this.features = new Value(features);
  7275. this.rules = [new Ruleset(selectors, value)];
  7276. this.rules[0].allowImports = true;
  7277. this.copyVisibilityInfo(visibilityInfo);
  7278. this.allowRoot = true;
  7279. this.setParent(selectors, this);
  7280. this.setParent(this.features, this);
  7281. this.setParent(this.rules, this);
  7282. };
  7283. Media.prototype = new AtRule();
  7284. Media.prototype.type = 'Media';
  7285. Media.prototype.isRulesetLike = function() { return true; };
  7286. Media.prototype.accept = function (visitor) {
  7287. if (this.features) {
  7288. this.features = visitor.visit(this.features);
  7289. }
  7290. if (this.rules) {
  7291. this.rules = visitor.visitArray(this.rules);
  7292. }
  7293. };
  7294. Media.prototype.genCSS = function (context, output) {
  7295. output.add('@media ', this._fileInfo, this._index);
  7296. this.features.genCSS(context, output);
  7297. this.outputRuleset(context, output, this.rules);
  7298. };
  7299. Media.prototype.eval = function (context) {
  7300. if (!context.mediaBlocks) {
  7301. context.mediaBlocks = [];
  7302. context.mediaPath = [];
  7303. }
  7304. var media = new Media(null, [], this._index, this._fileInfo, this.visibilityInfo());
  7305. if (this.debugInfo) {
  7306. this.rules[0].debugInfo = this.debugInfo;
  7307. media.debugInfo = this.debugInfo;
  7308. }
  7309. media.features = this.features.eval(context);
  7310. context.mediaPath.push(media);
  7311. context.mediaBlocks.push(media);
  7312. this.rules[0].functionRegistry = context.frames[0].functionRegistry.inherit();
  7313. context.frames.unshift(this.rules[0]);
  7314. media.rules = [this.rules[0].eval(context)];
  7315. context.frames.shift();
  7316. context.mediaPath.pop();
  7317. return context.mediaPath.length === 0 ? media.evalTop(context) :
  7318. media.evalNested(context);
  7319. };
  7320. Media.prototype.evalTop = function (context) {
  7321. var result = this;
  7322. // Render all dependent Media blocks.
  7323. if (context.mediaBlocks.length > 1) {
  7324. var selectors = (new Selector([], null, null, this.getIndex(), this.fileInfo())).createEmptySelectors();
  7325. result = new Ruleset(selectors, context.mediaBlocks);
  7326. result.multiMedia = true;
  7327. result.copyVisibilityInfo(this.visibilityInfo());
  7328. this.setParent(result, this);
  7329. }
  7330. delete context.mediaBlocks;
  7331. delete context.mediaPath;
  7332. return result;
  7333. };
  7334. Media.prototype.evalNested = function (context) {
  7335. var i, value,
  7336. path = context.mediaPath.concat([this]);
  7337. // Extract the media-query conditions separated with `,` (OR).
  7338. for (i = 0; i < path.length; i++) {
  7339. value = path[i].features instanceof Value ?
  7340. path[i].features.value : path[i].features;
  7341. path[i] = Array.isArray(value) ? value : [value];
  7342. }
  7343. // Trace all permutations to generate the resulting media-query.
  7344. //
  7345. // (a, b and c) with nested (d, e) ->
  7346. // a and d
  7347. // a and e
  7348. // b and c and d
  7349. // b and c and e
  7350. this.features = new Value(this.permute(path).map(function (path) {
  7351. path = path.map(function (fragment) {
  7352. return fragment.toCSS ? fragment : new Anonymous(fragment);
  7353. });
  7354. for (i = path.length - 1; i > 0; i--) {
  7355. path.splice(i, 0, new Anonymous('and'));
  7356. }
  7357. return new Expression(path);
  7358. }));
  7359. this.setParent(this.features, this);
  7360. // Fake a tree-node that doesn't output anything.
  7361. return new Ruleset([], []);
  7362. };
  7363. Media.prototype.permute = function (arr) {
  7364. if (arr.length === 0) {
  7365. return [];
  7366. } else if (arr.length === 1) {
  7367. return arr[0];
  7368. } else {
  7369. var result = [];
  7370. var rest = this.permute(arr.slice(1));
  7371. for (var i = 0; i < rest.length; i++) {
  7372. for (var j = 0; j < arr[0].length; j++) {
  7373. result.push([arr[0][j]].concat(rest[i]));
  7374. }
  7375. }
  7376. return result;
  7377. }
  7378. };
  7379. Media.prototype.bubbleSelectors = function (selectors) {
  7380. if (!selectors) {
  7381. return;
  7382. }
  7383. this.rules = [new Ruleset(utils.copyArray(selectors), [this.rules[0]])];
  7384. this.setParent(this.rules, this);
  7385. };
  7386. module.exports = Media;
  7387. },{"../utils":89,"./anonymous":50,"./atrule":52,"./expression":64,"./ruleset":81,"./selector":82,"./value":86}],72:[function(require,module,exports){
  7388. var Node = require('./node'),
  7389. Selector = require('./selector'),
  7390. MixinDefinition = require('./mixin-definition'),
  7391. defaultFunc = require('../functions/default');
  7392. var MixinCall = function (elements, args, index, currentFileInfo, important) {
  7393. this.selector = new Selector(elements);
  7394. this.arguments = args || [];
  7395. this._index = index;
  7396. this._fileInfo = currentFileInfo;
  7397. this.important = important;
  7398. this.allowRoot = true;
  7399. this.setParent(this.selector, this);
  7400. };
  7401. MixinCall.prototype = new Node();
  7402. MixinCall.prototype.type = 'MixinCall';
  7403. MixinCall.prototype.accept = function (visitor) {
  7404. if (this.selector) {
  7405. this.selector = visitor.visit(this.selector);
  7406. }
  7407. if (this.arguments.length) {
  7408. this.arguments = visitor.visitArray(this.arguments);
  7409. }
  7410. };
  7411. MixinCall.prototype.eval = function (context) {
  7412. var mixins, mixin, mixinPath, args = [], arg, argValue,
  7413. rules = [], match = false, i, m, f, isRecursive, isOneFound,
  7414. candidates = [], candidate, conditionResult = [], defaultResult, defFalseEitherCase = -1,
  7415. defNone = 0, defTrue = 1, defFalse = 2, count, originalRuleset, noArgumentsFilter;
  7416. this.selector = this.selector.eval(context);
  7417. function calcDefGroup(mixin, mixinPath) {
  7418. var f, p, namespace;
  7419. for (f = 0; f < 2; f++) {
  7420. conditionResult[f] = true;
  7421. defaultFunc.value(f);
  7422. for (p = 0; p < mixinPath.length && conditionResult[f]; p++) {
  7423. namespace = mixinPath[p];
  7424. if (namespace.matchCondition) {
  7425. conditionResult[f] = conditionResult[f] && namespace.matchCondition(null, context);
  7426. }
  7427. }
  7428. if (mixin.matchCondition) {
  7429. conditionResult[f] = conditionResult[f] && mixin.matchCondition(args, context);
  7430. }
  7431. }
  7432. if (conditionResult[0] || conditionResult[1]) {
  7433. if (conditionResult[0] != conditionResult[1]) {
  7434. return conditionResult[1] ?
  7435. defTrue : defFalse;
  7436. }
  7437. return defNone;
  7438. }
  7439. return defFalseEitherCase;
  7440. }
  7441. for (i = 0; i < this.arguments.length; i++) {
  7442. arg = this.arguments[i];
  7443. argValue = arg.value.eval(context);
  7444. if (arg.expand && Array.isArray(argValue.value)) {
  7445. argValue = argValue.value;
  7446. for (m = 0; m < argValue.length; m++) {
  7447. args.push({value: argValue[m]});
  7448. }
  7449. } else {
  7450. args.push({name: arg.name, value: argValue});
  7451. }
  7452. }
  7453. noArgumentsFilter = function(rule) {return rule.matchArgs(null, context);};
  7454. for (i = 0; i < context.frames.length; i++) {
  7455. if ((mixins = context.frames[i].find(this.selector, null, noArgumentsFilter)).length > 0) {
  7456. isOneFound = true;
  7457. // To make `default()` function independent of definition order we have two "subpasses" here.
  7458. // At first we evaluate each guard *twice* (with `default() == true` and `default() == false`),
  7459. // and build candidate list with corresponding flags. Then, when we know all possible matches,
  7460. // we make a final decision.
  7461. for (m = 0; m < mixins.length; m++) {
  7462. mixin = mixins[m].rule;
  7463. mixinPath = mixins[m].path;
  7464. isRecursive = false;
  7465. for (f = 0; f < context.frames.length; f++) {
  7466. if ((!(mixin instanceof MixinDefinition)) && mixin === (context.frames[f].originalRuleset || context.frames[f])) {
  7467. isRecursive = true;
  7468. break;
  7469. }
  7470. }
  7471. if (isRecursive) {
  7472. continue;
  7473. }
  7474. if (mixin.matchArgs(args, context)) {
  7475. candidate = {mixin: mixin, group: calcDefGroup(mixin, mixinPath)};
  7476. if (candidate.group !== defFalseEitherCase) {
  7477. candidates.push(candidate);
  7478. }
  7479. match = true;
  7480. }
  7481. }
  7482. defaultFunc.reset();
  7483. count = [0, 0, 0];
  7484. for (m = 0; m < candidates.length; m++) {
  7485. count[candidates[m].group]++;
  7486. }
  7487. if (count[defNone] > 0) {
  7488. defaultResult = defFalse;
  7489. } else {
  7490. defaultResult = defTrue;
  7491. if ((count[defTrue] + count[defFalse]) > 1) {
  7492. throw { type: 'Runtime',
  7493. message: 'Ambiguous use of `default()` found when matching for `' + this.format(args) + '`',
  7494. index: this.getIndex(), filename: this.fileInfo().filename };
  7495. }
  7496. }
  7497. for (m = 0; m < candidates.length; m++) {
  7498. candidate = candidates[m].group;
  7499. if ((candidate === defNone) || (candidate === defaultResult)) {
  7500. try {
  7501. mixin = candidates[m].mixin;
  7502. if (!(mixin instanceof MixinDefinition)) {
  7503. originalRuleset = mixin.originalRuleset || mixin;
  7504. mixin = new MixinDefinition('', [], mixin.rules, null, false, null, originalRuleset.visibilityInfo());
  7505. mixin.originalRuleset = originalRuleset;
  7506. }
  7507. var newRules = mixin.evalCall(context, args, this.important).rules;
  7508. this._setVisibilityToReplacement(newRules);
  7509. Array.prototype.push.apply(rules, newRules);
  7510. } catch (e) {
  7511. throw { message: e.message, index: this.getIndex(), filename: this.fileInfo().filename, stack: e.stack };
  7512. }
  7513. }
  7514. }
  7515. if (match) {
  7516. return rules;
  7517. }
  7518. }
  7519. }
  7520. if (isOneFound) {
  7521. throw { type: 'Runtime',
  7522. message: 'No matching definition was found for `' + this.format(args) + '`',
  7523. index: this.getIndex(), filename: this.fileInfo().filename };
  7524. } else {
  7525. throw { type: 'Name',
  7526. message: this.selector.toCSS().trim() + ' is undefined',
  7527. index: this.getIndex(), filename: this.fileInfo().filename };
  7528. }
  7529. };
  7530. MixinCall.prototype._setVisibilityToReplacement = function (replacement) {
  7531. var i, rule;
  7532. if (this.blocksVisibility()) {
  7533. for (i = 0; i < replacement.length; i++) {
  7534. rule = replacement[i];
  7535. rule.addVisibilityBlock();
  7536. }
  7537. }
  7538. };
  7539. MixinCall.prototype.format = function (args) {
  7540. return this.selector.toCSS().trim() + '(' +
  7541. (args ? args.map(function (a) {
  7542. var argValue = '';
  7543. if (a.name) {
  7544. argValue += a.name + ':';
  7545. }
  7546. if (a.value.toCSS) {
  7547. argValue += a.value.toCSS();
  7548. } else {
  7549. argValue += '???';
  7550. }
  7551. return argValue;
  7552. }).join(', ') : '') + ')';
  7553. };
  7554. module.exports = MixinCall;
  7555. },{"../functions/default":25,"./mixin-definition":73,"./node":76,"./selector":82}],73:[function(require,module,exports){
  7556. var Selector = require('./selector'),
  7557. Element = require('./element'),
  7558. Ruleset = require('./ruleset'),
  7559. Declaration = require('./declaration'),
  7560. DetachedRuleset = require('./detached-ruleset'),
  7561. Expression = require('./expression'),
  7562. contexts = require('../contexts'),
  7563. utils = require('../utils');
  7564. var Definition = function (name, params, rules, condition, variadic, frames, visibilityInfo) {
  7565. this.name = name || 'anonymous mixin';
  7566. this.selectors = [new Selector([new Element(null, name, false, this._index, this._fileInfo)])];
  7567. this.params = params;
  7568. this.condition = condition;
  7569. this.variadic = variadic;
  7570. this.arity = params.length;
  7571. this.rules = rules;
  7572. this._lookups = {};
  7573. var optionalParameters = [];
  7574. this.required = params.reduce(function (count, p) {
  7575. if (!p.name || (p.name && !p.value)) {
  7576. return count + 1;
  7577. }
  7578. else {
  7579. optionalParameters.push(p.name);
  7580. return count;
  7581. }
  7582. }, 0);
  7583. this.optionalParameters = optionalParameters;
  7584. this.frames = frames;
  7585. this.copyVisibilityInfo(visibilityInfo);
  7586. this.allowRoot = true;
  7587. };
  7588. Definition.prototype = new Ruleset();
  7589. Definition.prototype.type = 'MixinDefinition';
  7590. Definition.prototype.evalFirst = true;
  7591. Definition.prototype.accept = function (visitor) {
  7592. if (this.params && this.params.length) {
  7593. this.params = visitor.visitArray(this.params);
  7594. }
  7595. this.rules = visitor.visitArray(this.rules);
  7596. if (this.condition) {
  7597. this.condition = visitor.visit(this.condition);
  7598. }
  7599. };
  7600. Definition.prototype.evalParams = function (context, mixinEnv, args, evaldArguments) {
  7601. /* jshint boss:true */
  7602. var frame = new Ruleset(null, null),
  7603. varargs, arg,
  7604. params = utils.copyArray(this.params),
  7605. i, j, val, name, isNamedFound, argIndex, argsLength = 0;
  7606. if (mixinEnv.frames && mixinEnv.frames[0] && mixinEnv.frames[0].functionRegistry) {
  7607. frame.functionRegistry = mixinEnv.frames[0].functionRegistry.inherit();
  7608. }
  7609. mixinEnv = new contexts.Eval(mixinEnv, [frame].concat(mixinEnv.frames));
  7610. if (args) {
  7611. args = utils.copyArray(args);
  7612. argsLength = args.length;
  7613. for (i = 0; i < argsLength; i++) {
  7614. arg = args[i];
  7615. if (name = (arg && arg.name)) {
  7616. isNamedFound = false;
  7617. for (j = 0; j < params.length; j++) {
  7618. if (!evaldArguments[j] && name === params[j].name) {
  7619. evaldArguments[j] = arg.value.eval(context);
  7620. frame.prependRule(new Declaration(name, arg.value.eval(context)));
  7621. isNamedFound = true;
  7622. break;
  7623. }
  7624. }
  7625. if (isNamedFound) {
  7626. args.splice(i, 1);
  7627. i--;
  7628. continue;
  7629. } else {
  7630. throw { type: 'Runtime', message: 'Named argument for ' + this.name +
  7631. ' ' + args[i].name + ' not found' };
  7632. }
  7633. }
  7634. }
  7635. }
  7636. argIndex = 0;
  7637. for (i = 0; i < params.length; i++) {
  7638. if (evaldArguments[i]) { continue; }
  7639. arg = args && args[argIndex];
  7640. if (name = params[i].name) {
  7641. if (params[i].variadic) {
  7642. varargs = [];
  7643. for (j = argIndex; j < argsLength; j++) {
  7644. varargs.push(args[j].value.eval(context));
  7645. }
  7646. frame.prependRule(new Declaration(name, new Expression(varargs).eval(context)));
  7647. } else {
  7648. val = arg && arg.value;
  7649. if (val) {
  7650. // This was a mixin call, pass in a detached ruleset of it's eval'd rules
  7651. if (Array.isArray(val)) {
  7652. val = new DetachedRuleset(new Ruleset('', val));
  7653. }
  7654. else {
  7655. val = val.eval(context);
  7656. }
  7657. } else if (params[i].value) {
  7658. val = params[i].value.eval(mixinEnv);
  7659. frame.resetCache();
  7660. } else {
  7661. throw { type: 'Runtime', message: 'wrong number of arguments for ' + this.name +
  7662. ' (' + argsLength + ' for ' + this.arity + ')' };
  7663. }
  7664. frame.prependRule(new Declaration(name, val));
  7665. evaldArguments[i] = val;
  7666. }
  7667. }
  7668. if (params[i].variadic && args) {
  7669. for (j = argIndex; j < argsLength; j++) {
  7670. evaldArguments[j] = args[j].value.eval(context);
  7671. }
  7672. }
  7673. argIndex++;
  7674. }
  7675. return frame;
  7676. };
  7677. Definition.prototype.makeImportant = function() {
  7678. var rules = !this.rules ? this.rules : this.rules.map(function (r) {
  7679. if (r.makeImportant) {
  7680. return r.makeImportant(true);
  7681. } else {
  7682. return r;
  7683. }
  7684. });
  7685. var result = new Definition(this.name, this.params, rules, this.condition, this.variadic, this.frames);
  7686. return result;
  7687. };
  7688. Definition.prototype.eval = function (context) {
  7689. return new Definition(this.name, this.params, this.rules, this.condition, this.variadic, this.frames || utils.copyArray(context.frames));
  7690. };
  7691. Definition.prototype.evalCall = function (context, args, important) {
  7692. var _arguments = [],
  7693. mixinFrames = this.frames ? this.frames.concat(context.frames) : context.frames,
  7694. frame = this.evalParams(context, new contexts.Eval(context, mixinFrames), args, _arguments),
  7695. rules, ruleset;
  7696. frame.prependRule(new Declaration('@arguments', new Expression(_arguments).eval(context)));
  7697. rules = utils.copyArray(this.rules);
  7698. ruleset = new Ruleset(null, rules);
  7699. ruleset.originalRuleset = this;
  7700. ruleset = ruleset.eval(new contexts.Eval(context, [this, frame].concat(mixinFrames)));
  7701. if (important) {
  7702. ruleset = ruleset.makeImportant();
  7703. }
  7704. return ruleset;
  7705. };
  7706. Definition.prototype.matchCondition = function (args, context) {
  7707. if (this.condition && !this.condition.eval(
  7708. new contexts.Eval(context,
  7709. [this.evalParams(context, /* the parameter variables */
  7710. new contexts.Eval(context, this.frames ? this.frames.concat(context.frames) : context.frames), args, [])]
  7711. .concat(this.frames || []) // the parent namespace/mixin frames
  7712. .concat(context.frames)))) { // the current environment frames
  7713. return false;
  7714. }
  7715. return true;
  7716. };
  7717. Definition.prototype.matchArgs = function (args, context) {
  7718. var allArgsCnt = (args && args.length) || 0, len, optionalParameters = this.optionalParameters;
  7719. var requiredArgsCnt = !args ? 0 : args.reduce(function (count, p) {
  7720. if (optionalParameters.indexOf(p.name) < 0) {
  7721. return count + 1;
  7722. } else {
  7723. return count;
  7724. }
  7725. }, 0);
  7726. if (!this.variadic) {
  7727. if (requiredArgsCnt < this.required) {
  7728. return false;
  7729. }
  7730. if (allArgsCnt > this.params.length) {
  7731. return false;
  7732. }
  7733. } else {
  7734. if (requiredArgsCnt < (this.required - 1)) {
  7735. return false;
  7736. }
  7737. }
  7738. // check patterns
  7739. len = Math.min(requiredArgsCnt, this.arity);
  7740. for (var i = 0; i < len; i++) {
  7741. if (!this.params[i].name && !this.params[i].variadic) {
  7742. if (args[i].value.eval(context).toCSS() != this.params[i].value.eval(context).toCSS()) {
  7743. return false;
  7744. }
  7745. }
  7746. }
  7747. return true;
  7748. };
  7749. module.exports = Definition;
  7750. },{"../contexts":13,"../utils":89,"./declaration":60,"./detached-ruleset":61,"./element":63,"./expression":64,"./ruleset":81,"./selector":82}],74:[function(require,module,exports){
  7751. var Node = require('./node'),
  7752. Variable = require('./variable'),
  7753. Ruleset = require('./ruleset'),
  7754. Selector = require('./selector');
  7755. var NamespaceValue = function (ruleCall, lookups, important, index, fileInfo) {
  7756. this.value = ruleCall;
  7757. this.lookups = lookups;
  7758. this.important = important;
  7759. this._index = index;
  7760. this._fileInfo = fileInfo;
  7761. };
  7762. NamespaceValue.prototype = new Node();
  7763. NamespaceValue.prototype.type = 'NamespaceValue';
  7764. NamespaceValue.prototype.eval = function (context) {
  7765. var i, j, name, rules = this.value.eval(context);
  7766. for (i = 0; i < this.lookups.length; i++) {
  7767. name = this.lookups[i];
  7768. /**
  7769. * Eval'd DRs return rulesets.
  7770. * Eval'd mixins return rules, so let's make a ruleset if we need it.
  7771. * We need to do this because of late parsing of values
  7772. */
  7773. if (Array.isArray(rules)) {
  7774. rules = new Ruleset([new Selector()], rules);
  7775. }
  7776. if (name === '') {
  7777. rules = rules.lastDeclaration();
  7778. }
  7779. else if (name.charAt(0) === '@') {
  7780. if (name.charAt(1) === '@') {
  7781. name = '@' + new Variable(name.substr(1)).eval(context).value;
  7782. }
  7783. if (rules.variables) {
  7784. rules = rules.variable(name);
  7785. }
  7786. if (!rules) {
  7787. throw { type: 'Name',
  7788. message: 'variable ' + name + ' not found',
  7789. filename: this.fileInfo().filename,
  7790. index: this.getIndex() };
  7791. }
  7792. }
  7793. else {
  7794. if (name.substring(0, 2) === '$@') {
  7795. name = '$' + new Variable(name.substr(1)).eval(context).value;
  7796. }
  7797. else {
  7798. name = name.charAt(0) === '$' ? name : '$' + name;
  7799. }
  7800. if (rules.properties) {
  7801. rules = rules.property(name);
  7802. }
  7803. if (!rules) {
  7804. throw { type: 'Name',
  7805. message: 'property "' + name.substr(1) + '" not found',
  7806. filename: this.fileInfo().filename,
  7807. index: this.getIndex() };
  7808. }
  7809. // Properties are an array of values, since a ruleset can have multiple props.
  7810. // We pick the last one (the "cascaded" value)
  7811. rules = rules[rules.length - 1];
  7812. }
  7813. if (rules.value) {
  7814. rules = rules.eval(context).value;
  7815. }
  7816. if (rules.ruleset) {
  7817. rules = rules.ruleset.eval(context);
  7818. }
  7819. }
  7820. return rules;
  7821. };
  7822. module.exports = NamespaceValue;
  7823. },{"./node":76,"./ruleset":81,"./selector":82,"./variable":88}],75:[function(require,module,exports){
  7824. var Node = require('./node'),
  7825. Operation = require('./operation'),
  7826. Dimension = require('./dimension');
  7827. var Negative = function (node) {
  7828. this.value = node;
  7829. };
  7830. Negative.prototype = new Node();
  7831. Negative.prototype.type = 'Negative';
  7832. Negative.prototype.genCSS = function (context, output) {
  7833. output.add('-');
  7834. this.value.genCSS(context, output);
  7835. };
  7836. Negative.prototype.eval = function (context) {
  7837. if (context.isMathOn()) {
  7838. return (new Operation('*', [new Dimension(-1), this.value])).eval(context);
  7839. }
  7840. return new Negative(this.value.eval(context));
  7841. };
  7842. module.exports = Negative;
  7843. },{"./dimension":62,"./node":76,"./operation":77}],76:[function(require,module,exports){
  7844. var Node = function() {
  7845. this.parent = null;
  7846. this.visibilityBlocks = undefined;
  7847. this.nodeVisible = undefined;
  7848. this.rootNode = null;
  7849. this.parsed = null;
  7850. var self = this;
  7851. Object.defineProperty(this, 'currentFileInfo', {
  7852. get: function() { return self.fileInfo(); }
  7853. });
  7854. Object.defineProperty(this, 'index', {
  7855. get: function() { return self.getIndex(); }
  7856. });
  7857. };
  7858. Node.prototype.setParent = function(nodes, parent) {
  7859. function set(node) {
  7860. if (node && node instanceof Node) {
  7861. node.parent = parent;
  7862. }
  7863. }
  7864. if (Array.isArray(nodes)) {
  7865. nodes.forEach(set);
  7866. }
  7867. else {
  7868. set(nodes);
  7869. }
  7870. };
  7871. Node.prototype.getIndex = function() {
  7872. return this._index || (this.parent && this.parent.getIndex()) || 0;
  7873. };
  7874. Node.prototype.fileInfo = function() {
  7875. return this._fileInfo || (this.parent && this.parent.fileInfo()) || {};
  7876. };
  7877. Node.prototype.isRulesetLike = function() { return false; };
  7878. Node.prototype.toCSS = function (context) {
  7879. var strs = [];
  7880. this.genCSS(context, {
  7881. add: function(chunk, fileInfo, index) {
  7882. strs.push(chunk);
  7883. },
  7884. isEmpty: function () {
  7885. return strs.length === 0;
  7886. }
  7887. });
  7888. return strs.join('');
  7889. };
  7890. Node.prototype.genCSS = function (context, output) {
  7891. output.add(this.value);
  7892. };
  7893. Node.prototype.accept = function (visitor) {
  7894. this.value = visitor.visit(this.value);
  7895. };
  7896. Node.prototype.eval = function () { return this; };
  7897. Node.prototype._operate = function (context, op, a, b) {
  7898. switch (op) {
  7899. case '+': return a + b;
  7900. case '-': return a - b;
  7901. case '*': return a * b;
  7902. case '/': return a / b;
  7903. }
  7904. };
  7905. Node.prototype.fround = function(context, value) {
  7906. var precision = context && context.numPrecision;
  7907. // add "epsilon" to ensure numbers like 1.000000005 (represented as 1.000000004999...) are properly rounded:
  7908. return (precision) ? Number((value + 2e-16).toFixed(precision)) : value;
  7909. };
  7910. Node.compare = function (a, b) {
  7911. /* returns:
  7912. -1: a < b
  7913. 0: a = b
  7914. 1: a > b
  7915. and *any* other value for a != b (e.g. undefined, NaN, -2 etc.) */
  7916. if ((a.compare) &&
  7917. // for "symmetric results" force toCSS-based comparison
  7918. // of Quoted or Anonymous if either value is one of those
  7919. !(b.type === 'Quoted' || b.type === 'Anonymous')) {
  7920. return a.compare(b);
  7921. } else if (b.compare) {
  7922. return -b.compare(a);
  7923. } else if (a.type !== b.type) {
  7924. return undefined;
  7925. }
  7926. a = a.value;
  7927. b = b.value;
  7928. if (!Array.isArray(a)) {
  7929. return a === b ? 0 : undefined;
  7930. }
  7931. if (a.length !== b.length) {
  7932. return undefined;
  7933. }
  7934. for (var i = 0; i < a.length; i++) {
  7935. if (Node.compare(a[i], b[i]) !== 0) {
  7936. return undefined;
  7937. }
  7938. }
  7939. return 0;
  7940. };
  7941. Node.numericCompare = function (a, b) {
  7942. return a < b ? -1
  7943. : a === b ? 0
  7944. : a > b ? 1 : undefined;
  7945. };
  7946. // Returns true if this node represents root of ast imported by reference
  7947. Node.prototype.blocksVisibility = function () {
  7948. if (this.visibilityBlocks == null) {
  7949. this.visibilityBlocks = 0;
  7950. }
  7951. return this.visibilityBlocks !== 0;
  7952. };
  7953. Node.prototype.addVisibilityBlock = function () {
  7954. if (this.visibilityBlocks == null) {
  7955. this.visibilityBlocks = 0;
  7956. }
  7957. this.visibilityBlocks = this.visibilityBlocks + 1;
  7958. };
  7959. Node.prototype.removeVisibilityBlock = function () {
  7960. if (this.visibilityBlocks == null) {
  7961. this.visibilityBlocks = 0;
  7962. }
  7963. this.visibilityBlocks = this.visibilityBlocks - 1;
  7964. };
  7965. // Turns on node visibility - if called node will be shown in output regardless
  7966. // of whether it comes from import by reference or not
  7967. Node.prototype.ensureVisibility = function () {
  7968. this.nodeVisible = true;
  7969. };
  7970. // Turns off node visibility - if called node will NOT be shown in output regardless
  7971. // of whether it comes from import by reference or not
  7972. Node.prototype.ensureInvisibility = function () {
  7973. this.nodeVisible = false;
  7974. };
  7975. // return values:
  7976. // false - the node must not be visible
  7977. // true - the node must be visible
  7978. // undefined or null - the node has the same visibility as its parent
  7979. Node.prototype.isVisible = function () {
  7980. return this.nodeVisible;
  7981. };
  7982. Node.prototype.visibilityInfo = function() {
  7983. return {
  7984. visibilityBlocks: this.visibilityBlocks,
  7985. nodeVisible: this.nodeVisible
  7986. };
  7987. };
  7988. Node.prototype.copyVisibilityInfo = function(info) {
  7989. if (!info) {
  7990. return;
  7991. }
  7992. this.visibilityBlocks = info.visibilityBlocks;
  7993. this.nodeVisible = info.nodeVisible;
  7994. };
  7995. module.exports = Node;
  7996. },{}],77:[function(require,module,exports){
  7997. var Node = require('./node'),
  7998. Color = require('./color'),
  7999. Dimension = require('./dimension'),
  8000. MATH = require('../constants').Math;
  8001. var Operation = function (op, operands, isSpaced) {
  8002. this.op = op.trim();
  8003. this.operands = operands;
  8004. this.isSpaced = isSpaced;
  8005. };
  8006. Operation.prototype = new Node();
  8007. Operation.prototype.type = 'Operation';
  8008. Operation.prototype.accept = function (visitor) {
  8009. this.operands = visitor.visit(this.operands);
  8010. };
  8011. Operation.prototype.eval = function (context) {
  8012. var a = this.operands[0].eval(context),
  8013. b = this.operands[1].eval(context),
  8014. op;
  8015. if (context.isMathOn(this.op)) {
  8016. op = this.op === './' ? '/' : this.op;
  8017. if (a instanceof Dimension && b instanceof Color) {
  8018. a = a.toColor();
  8019. }
  8020. if (b instanceof Dimension && a instanceof Color) {
  8021. b = b.toColor();
  8022. }
  8023. if (!a.operate) {
  8024. if (a instanceof Operation && a.op === '/' && context.math === MATH.PARENS_DIVISION) {
  8025. return new Operation(this.op, [a, b], this.isSpaced);
  8026. }
  8027. throw { type: 'Operation',
  8028. message: 'Operation on an invalid type' };
  8029. }
  8030. return a.operate(context, op, b);
  8031. } else {
  8032. return new Operation(this.op, [a, b], this.isSpaced);
  8033. }
  8034. };
  8035. Operation.prototype.genCSS = function (context, output) {
  8036. this.operands[0].genCSS(context, output);
  8037. if (this.isSpaced) {
  8038. output.add(' ');
  8039. }
  8040. output.add(this.op);
  8041. if (this.isSpaced) {
  8042. output.add(' ');
  8043. }
  8044. this.operands[1].genCSS(context, output);
  8045. };
  8046. module.exports = Operation;
  8047. },{"../constants":12,"./color":55,"./dimension":62,"./node":76}],78:[function(require,module,exports){
  8048. var Node = require('./node');
  8049. var Paren = function (node) {
  8050. this.value = node;
  8051. };
  8052. Paren.prototype = new Node();
  8053. Paren.prototype.type = 'Paren';
  8054. Paren.prototype.genCSS = function (context, output) {
  8055. output.add('(');
  8056. this.value.genCSS(context, output);
  8057. output.add(')');
  8058. };
  8059. Paren.prototype.eval = function (context) {
  8060. return new Paren(this.value.eval(context));
  8061. };
  8062. module.exports = Paren;
  8063. },{"./node":76}],79:[function(require,module,exports){
  8064. var Node = require('./node'),
  8065. Declaration = require('./declaration');
  8066. var Property = function (name, index, currentFileInfo) {
  8067. this.name = name;
  8068. this._index = index;
  8069. this._fileInfo = currentFileInfo;
  8070. };
  8071. Property.prototype = new Node();
  8072. Property.prototype.type = 'Property';
  8073. Property.prototype.eval = function (context) {
  8074. var property, name = this.name;
  8075. // TODO: shorten this reference
  8076. var mergeRules = context.pluginManager.less.visitors.ToCSSVisitor.prototype._mergeRules;
  8077. if (this.evaluating) {
  8078. throw { type: 'Name',
  8079. message: 'Recursive property reference for ' + name,
  8080. filename: this.fileInfo().filename,
  8081. index: this.getIndex() };
  8082. }
  8083. this.evaluating = true;
  8084. property = this.find(context.frames, function (frame) {
  8085. var v, vArr = frame.property(name);
  8086. if (vArr) {
  8087. for (var i = 0; i < vArr.length; i++) {
  8088. v = vArr[i];
  8089. vArr[i] = new Declaration(v.name,
  8090. v.value,
  8091. v.important,
  8092. v.merge,
  8093. v.index,
  8094. v.currentFileInfo,
  8095. v.inline,
  8096. v.variable
  8097. );
  8098. }
  8099. mergeRules(vArr);
  8100. v = vArr[vArr.length - 1];
  8101. if (v.important) {
  8102. var importantScope = context.importantScope[context.importantScope.length - 1];
  8103. importantScope.important = v.important;
  8104. }
  8105. v = v.value.eval(context);
  8106. return v;
  8107. }
  8108. });
  8109. if (property) {
  8110. this.evaluating = false;
  8111. return property;
  8112. } else {
  8113. throw { type: 'Name',
  8114. message: 'Property \'' + name + '\' is undefined',
  8115. filename: this.currentFileInfo.filename,
  8116. index: this.index };
  8117. }
  8118. };
  8119. Property.prototype.find = function (obj, fun) {
  8120. for (var i = 0, r; i < obj.length; i++) {
  8121. r = fun.call(obj, obj[i]);
  8122. if (r) { return r; }
  8123. }
  8124. return null;
  8125. };
  8126. module.exports = Property;
  8127. },{"./declaration":60,"./node":76}],80:[function(require,module,exports){
  8128. var Node = require('./node'),
  8129. Variable = require('./variable'),
  8130. Property = require('./property');
  8131. var Quoted = function (str, content, escaped, index, currentFileInfo) {
  8132. this.escaped = (escaped == null) ? true : escaped;
  8133. this.value = content || '';
  8134. this.quote = str.charAt(0);
  8135. this._index = index;
  8136. this._fileInfo = currentFileInfo;
  8137. this.variableRegex = /@\{([\w-]+)\}/g;
  8138. this.propRegex = /\$\{([\w-]+)\}/g;
  8139. };
  8140. Quoted.prototype = new Node();
  8141. Quoted.prototype.type = 'Quoted';
  8142. Quoted.prototype.genCSS = function (context, output) {
  8143. if (!this.escaped) {
  8144. output.add(this.quote, this.fileInfo(), this.getIndex());
  8145. }
  8146. output.add(this.value);
  8147. if (!this.escaped) {
  8148. output.add(this.quote);
  8149. }
  8150. };
  8151. Quoted.prototype.containsVariables = function() {
  8152. return this.value.match(this.variableRegex);
  8153. };
  8154. Quoted.prototype.eval = function (context) {
  8155. var that = this, value = this.value;
  8156. var variableReplacement = function (_, name) {
  8157. var v = new Variable('@' + name, that.getIndex(), that.fileInfo()).eval(context, true);
  8158. return (v instanceof Quoted) ? v.value : v.toCSS();
  8159. };
  8160. var propertyReplacement = function (_, name) {
  8161. var v = new Property('$' + name, that.getIndex(), that.fileInfo()).eval(context, true);
  8162. return (v instanceof Quoted) ? v.value : v.toCSS();
  8163. };
  8164. function iterativeReplace(value, regexp, replacementFnc) {
  8165. var evaluatedValue = value;
  8166. do {
  8167. value = evaluatedValue;
  8168. evaluatedValue = value.replace(regexp, replacementFnc);
  8169. } while (value !== evaluatedValue);
  8170. return evaluatedValue;
  8171. }
  8172. value = iterativeReplace(value, this.variableRegex, variableReplacement);
  8173. value = iterativeReplace(value, this.propRegex, propertyReplacement);
  8174. return new Quoted(this.quote + value + this.quote, value, this.escaped, this.getIndex(), this.fileInfo());
  8175. };
  8176. Quoted.prototype.compare = function (other) {
  8177. // when comparing quoted strings allow the quote to differ
  8178. if (other.type === 'Quoted' && !this.escaped && !other.escaped) {
  8179. return Node.numericCompare(this.value, other.value);
  8180. } else {
  8181. return other.toCSS && this.toCSS() === other.toCSS() ? 0 : undefined;
  8182. }
  8183. };
  8184. module.exports = Quoted;
  8185. },{"./node":76,"./property":79,"./variable":88}],81:[function(require,module,exports){
  8186. var Node = require('./node'),
  8187. Declaration = require('./declaration'),
  8188. Keyword = require('./keyword'),
  8189. Comment = require('./comment'),
  8190. Paren = require('./paren'),
  8191. Selector = require('./selector'),
  8192. Element = require('./element'),
  8193. Anonymous = require('./anonymous'),
  8194. contexts = require('../contexts'),
  8195. globalFunctionRegistry = require('../functions/function-registry'),
  8196. defaultFunc = require('../functions/default'),
  8197. getDebugInfo = require('./debug-info'),
  8198. utils = require('../utils');
  8199. var Ruleset = function (selectors, rules, strictImports, visibilityInfo) {
  8200. this.selectors = selectors;
  8201. this.rules = rules;
  8202. this._lookups = {};
  8203. this._variables = null;
  8204. this._properties = null;
  8205. this.strictImports = strictImports;
  8206. this.copyVisibilityInfo(visibilityInfo);
  8207. this.allowRoot = true;
  8208. this.setParent(this.selectors, this);
  8209. this.setParent(this.rules, this);
  8210. };
  8211. Ruleset.prototype = new Node();
  8212. Ruleset.prototype.type = 'Ruleset';
  8213. Ruleset.prototype.isRuleset = true;
  8214. Ruleset.prototype.isRulesetLike = function() { return true; };
  8215. Ruleset.prototype.accept = function (visitor) {
  8216. if (this.paths) {
  8217. this.paths = visitor.visitArray(this.paths, true);
  8218. } else if (this.selectors) {
  8219. this.selectors = visitor.visitArray(this.selectors);
  8220. }
  8221. if (this.rules && this.rules.length) {
  8222. this.rules = visitor.visitArray(this.rules);
  8223. }
  8224. };
  8225. Ruleset.prototype.eval = function (context) {
  8226. var that = this, selectors, selCnt, selector, i, hasVariable, hasOnePassingSelector = false;
  8227. if (this.selectors && (selCnt = this.selectors.length)) {
  8228. selectors = new Array(selCnt);
  8229. defaultFunc.error({
  8230. type: 'Syntax',
  8231. message: 'it is currently only allowed in parametric mixin guards,'
  8232. });
  8233. for (i = 0; i < selCnt; i++) {
  8234. selector = this.selectors[i].eval(context);
  8235. for (var j = 0; j < selector.elements.length; j++) {
  8236. if (selector.elements[j].isVariable) {
  8237. hasVariable = true;
  8238. break;
  8239. }
  8240. }
  8241. selectors[i] = selector;
  8242. if (selector.evaldCondition) {
  8243. hasOnePassingSelector = true;
  8244. }
  8245. }
  8246. if (hasVariable) {
  8247. var toParseSelectors = new Array(selCnt);
  8248. for (i = 0; i < selCnt; i++) {
  8249. selector = selectors[i];
  8250. toParseSelectors[i] = selector.toCSS(context);
  8251. }
  8252. this.parse.parseNode(
  8253. toParseSelectors.join(','),
  8254. ["selectors"],
  8255. selectors[0].getIndex(),
  8256. selectors[0].fileInfo(),
  8257. function(err, result) {
  8258. if (result) {
  8259. selectors = utils.flattenArray(result);
  8260. }
  8261. });
  8262. }
  8263. defaultFunc.reset();
  8264. } else {
  8265. hasOnePassingSelector = true;
  8266. }
  8267. var rules = this.rules ? utils.copyArray(this.rules) : null,
  8268. ruleset = new Ruleset(selectors, rules, this.strictImports, this.visibilityInfo()),
  8269. rule, subRule;
  8270. ruleset.originalRuleset = this;
  8271. ruleset.root = this.root;
  8272. ruleset.firstRoot = this.firstRoot;
  8273. ruleset.allowImports = this.allowImports;
  8274. if (this.debugInfo) {
  8275. ruleset.debugInfo = this.debugInfo;
  8276. }
  8277. if (!hasOnePassingSelector) {
  8278. rules.length = 0;
  8279. }
  8280. // inherit a function registry from the frames stack when possible;
  8281. // otherwise from the global registry
  8282. ruleset.functionRegistry = (function (frames) {
  8283. var i = 0,
  8284. n = frames.length,
  8285. found;
  8286. for ( ; i !== n ; ++i ) {
  8287. found = frames[ i ].functionRegistry;
  8288. if ( found ) { return found; }
  8289. }
  8290. return globalFunctionRegistry;
  8291. }(context.frames)).inherit();
  8292. // push the current ruleset to the frames stack
  8293. var ctxFrames = context.frames;
  8294. ctxFrames.unshift(ruleset);
  8295. // currrent selectors
  8296. var ctxSelectors = context.selectors;
  8297. if (!ctxSelectors) {
  8298. context.selectors = ctxSelectors = [];
  8299. }
  8300. ctxSelectors.unshift(this.selectors);
  8301. // Evaluate imports
  8302. if (ruleset.root || ruleset.allowImports || !ruleset.strictImports) {
  8303. ruleset.evalImports(context);
  8304. }
  8305. // Store the frames around mixin definitions,
  8306. // so they can be evaluated like closures when the time comes.
  8307. var rsRules = ruleset.rules;
  8308. for (i = 0; (rule = rsRules[i]); i++) {
  8309. if (rule.evalFirst) {
  8310. rsRules[i] = rule.eval(context);
  8311. }
  8312. }
  8313. var mediaBlockCount = (context.mediaBlocks && context.mediaBlocks.length) || 0;
  8314. // Evaluate mixin calls.
  8315. for (i = 0; (rule = rsRules[i]); i++) {
  8316. if (rule.type === 'MixinCall') {
  8317. /* jshint loopfunc:true */
  8318. rules = rule.eval(context).filter(function(r) {
  8319. if ((r instanceof Declaration) && r.variable) {
  8320. // do not pollute the scope if the variable is
  8321. // already there. consider returning false here
  8322. // but we need a way to "return" variable from mixins
  8323. return !(ruleset.variable(r.name));
  8324. }
  8325. return true;
  8326. });
  8327. rsRules.splice.apply(rsRules, [i, 1].concat(rules));
  8328. i += rules.length - 1;
  8329. ruleset.resetCache();
  8330. } else if (rule.type === 'VariableCall') {
  8331. /* jshint loopfunc:true */
  8332. rules = rule.eval(context).rules.filter(function(r) {
  8333. if ((r instanceof Declaration) && r.variable) {
  8334. // do not pollute the scope at all
  8335. return false;
  8336. }
  8337. return true;
  8338. });
  8339. rsRules.splice.apply(rsRules, [i, 1].concat(rules));
  8340. i += rules.length - 1;
  8341. ruleset.resetCache();
  8342. }
  8343. }
  8344. // Evaluate everything else
  8345. for (i = 0; (rule = rsRules[i]); i++) {
  8346. if (!rule.evalFirst) {
  8347. rsRules[i] = rule = rule.eval ? rule.eval(context) : rule;
  8348. }
  8349. }
  8350. // Evaluate everything else
  8351. for (i = 0; (rule = rsRules[i]); i++) {
  8352. // for rulesets, check if it is a css guard and can be removed
  8353. if (rule instanceof Ruleset && rule.selectors && rule.selectors.length === 1) {
  8354. // check if it can be folded in (e.g. & where)
  8355. if (rule.selectors[0] && rule.selectors[0].isJustParentSelector()) {
  8356. rsRules.splice(i--, 1);
  8357. for (var j = 0; (subRule = rule.rules[j]); j++) {
  8358. if (subRule instanceof Node) {
  8359. subRule.copyVisibilityInfo(rule.visibilityInfo());
  8360. if (!(subRule instanceof Declaration) || !subRule.variable) {
  8361. rsRules.splice(++i, 0, subRule);
  8362. }
  8363. }
  8364. }
  8365. }
  8366. }
  8367. }
  8368. // Pop the stack
  8369. ctxFrames.shift();
  8370. ctxSelectors.shift();
  8371. if (context.mediaBlocks) {
  8372. for (i = mediaBlockCount; i < context.mediaBlocks.length; i++) {
  8373. context.mediaBlocks[i].bubbleSelectors(selectors);
  8374. }
  8375. }
  8376. return ruleset;
  8377. };
  8378. Ruleset.prototype.evalImports = function(context) {
  8379. var rules = this.rules, i, importRules;
  8380. if (!rules) { return; }
  8381. for (i = 0; i < rules.length; i++) {
  8382. if (rules[i].type === 'Import') {
  8383. importRules = rules[i].eval(context);
  8384. if (importRules && (importRules.length || importRules.length === 0)) {
  8385. rules.splice.apply(rules, [i, 1].concat(importRules));
  8386. i += importRules.length - 1;
  8387. } else {
  8388. rules.splice(i, 1, importRules);
  8389. }
  8390. this.resetCache();
  8391. }
  8392. }
  8393. };
  8394. Ruleset.prototype.makeImportant = function() {
  8395. var result = new Ruleset(this.selectors, this.rules.map(function (r) {
  8396. if (r.makeImportant) {
  8397. return r.makeImportant();
  8398. } else {
  8399. return r;
  8400. }
  8401. }), this.strictImports, this.visibilityInfo());
  8402. return result;
  8403. };
  8404. Ruleset.prototype.matchArgs = function (args) {
  8405. return !args || args.length === 0;
  8406. };
  8407. // lets you call a css selector with a guard
  8408. Ruleset.prototype.matchCondition = function (args, context) {
  8409. var lastSelector = this.selectors[this.selectors.length - 1];
  8410. if (!lastSelector.evaldCondition) {
  8411. return false;
  8412. }
  8413. if (lastSelector.condition &&
  8414. !lastSelector.condition.eval(
  8415. new contexts.Eval(context,
  8416. context.frames))) {
  8417. return false;
  8418. }
  8419. return true;
  8420. };
  8421. Ruleset.prototype.resetCache = function () {
  8422. this._rulesets = null;
  8423. this._variables = null;
  8424. this._properties = null;
  8425. this._lookups = {};
  8426. };
  8427. Ruleset.prototype.variables = function () {
  8428. if (!this._variables) {
  8429. this._variables = !this.rules ? {} : this.rules.reduce(function (hash, r) {
  8430. if (r instanceof Declaration && r.variable === true) {
  8431. hash[r.name] = r;
  8432. }
  8433. // when evaluating variables in an import statement, imports have not been eval'd
  8434. // so we need to go inside import statements.
  8435. // guard against root being a string (in the case of inlined less)
  8436. if (r.type === 'Import' && r.root && r.root.variables) {
  8437. var vars = r.root.variables();
  8438. for (var name in vars) {
  8439. if (vars.hasOwnProperty(name)) {
  8440. hash[name] = r.root.variable(name);
  8441. }
  8442. }
  8443. }
  8444. return hash;
  8445. }, {});
  8446. }
  8447. return this._variables;
  8448. };
  8449. Ruleset.prototype.properties = function () {
  8450. if (!this._properties) {
  8451. this._properties = !this.rules ? {} : this.rules.reduce(function (hash, r) {
  8452. if (r instanceof Declaration && r.variable !== true) {
  8453. var name = (r.name.length === 1) && (r.name[0] instanceof Keyword) ?
  8454. r.name[0].value : r.name;
  8455. // Properties don't overwrite as they can merge
  8456. if (!hash['$' + name]) {
  8457. hash['$' + name] = [ r ];
  8458. }
  8459. else {
  8460. hash['$' + name].push(r);
  8461. }
  8462. }
  8463. return hash;
  8464. }, {});
  8465. }
  8466. return this._properties;
  8467. };
  8468. Ruleset.prototype.variable = function (name) {
  8469. var decl = this.variables()[name];
  8470. if (decl) {
  8471. return this.parseValue(decl);
  8472. }
  8473. };
  8474. Ruleset.prototype.property = function (name) {
  8475. var decl = this.properties()[name];
  8476. if (decl) {
  8477. return this.parseValue(decl);
  8478. }
  8479. };
  8480. Ruleset.prototype.lastDeclaration = function () {
  8481. for (var i = this.rules.length; i > 0; i--) {
  8482. var decl = this.rules[i - 1];
  8483. if (decl instanceof Declaration) {
  8484. return this.parseValue(decl);
  8485. }
  8486. }
  8487. };
  8488. Ruleset.prototype.parseValue = function(toParse) {
  8489. var self = this;
  8490. function transformDeclaration(decl) {
  8491. if (decl.value instanceof Anonymous && !decl.parsed) {
  8492. if (typeof decl.value.value === 'string') {
  8493. this.parse.parseNode(
  8494. decl.value.value,
  8495. ['value', 'important'],
  8496. decl.value.getIndex(),
  8497. decl.fileInfo(),
  8498. function(err, result) {
  8499. if (err) {
  8500. decl.parsed = true;
  8501. }
  8502. if (result) {
  8503. decl.value = result[0];
  8504. decl.important = result[1] || '';
  8505. decl.parsed = true;
  8506. }
  8507. });
  8508. } else {
  8509. decl.parsed = true;
  8510. }
  8511. return decl;
  8512. }
  8513. else {
  8514. return decl;
  8515. }
  8516. }
  8517. if (!Array.isArray(toParse)) {
  8518. return transformDeclaration.call(self, toParse);
  8519. }
  8520. else {
  8521. var nodes = [];
  8522. toParse.forEach(function(n) {
  8523. nodes.push(transformDeclaration.call(self, n));
  8524. });
  8525. return nodes;
  8526. }
  8527. };
  8528. Ruleset.prototype.rulesets = function () {
  8529. if (!this.rules) { return []; }
  8530. var filtRules = [], rules = this.rules,
  8531. i, rule;
  8532. for (i = 0; (rule = rules[i]); i++) {
  8533. if (rule.isRuleset) {
  8534. filtRules.push(rule);
  8535. }
  8536. }
  8537. return filtRules;
  8538. };
  8539. Ruleset.prototype.prependRule = function (rule) {
  8540. var rules = this.rules;
  8541. if (rules) {
  8542. rules.unshift(rule);
  8543. } else {
  8544. this.rules = [ rule ];
  8545. }
  8546. this.setParent(rule, this);
  8547. };
  8548. Ruleset.prototype.find = function (selector, self, filter) {
  8549. self = self || this;
  8550. var rules = [], match, foundMixins,
  8551. key = selector.toCSS();
  8552. if (key in this._lookups) { return this._lookups[key]; }
  8553. this.rulesets().forEach(function (rule) {
  8554. if (rule !== self) {
  8555. for (var j = 0; j < rule.selectors.length; j++) {
  8556. match = selector.match(rule.selectors[j]);
  8557. if (match) {
  8558. if (selector.elements.length > match) {
  8559. if (!filter || filter(rule)) {
  8560. foundMixins = rule.find(new Selector(selector.elements.slice(match)), self, filter);
  8561. for (var i = 0; i < foundMixins.length; ++i) {
  8562. foundMixins[i].path.push(rule);
  8563. }
  8564. Array.prototype.push.apply(rules, foundMixins);
  8565. }
  8566. } else {
  8567. rules.push({ rule: rule, path: []});
  8568. }
  8569. break;
  8570. }
  8571. }
  8572. }
  8573. });
  8574. this._lookups[key] = rules;
  8575. return rules;
  8576. };
  8577. Ruleset.prototype.genCSS = function (context, output) {
  8578. var i, j,
  8579. charsetRuleNodes = [],
  8580. ruleNodes = [],
  8581. debugInfo, // Line number debugging
  8582. rule,
  8583. path;
  8584. context.tabLevel = (context.tabLevel || 0);
  8585. if (!this.root) {
  8586. context.tabLevel++;
  8587. }
  8588. var tabRuleStr = context.compress ? '' : Array(context.tabLevel + 1).join(' '),
  8589. tabSetStr = context.compress ? '' : Array(context.tabLevel).join(' '),
  8590. sep;
  8591. var charsetNodeIndex = 0;
  8592. var importNodeIndex = 0;
  8593. for (i = 0; (rule = this.rules[i]); i++) {
  8594. if (rule instanceof Comment) {
  8595. if (importNodeIndex === i) {
  8596. importNodeIndex++;
  8597. }
  8598. ruleNodes.push(rule);
  8599. } else if (rule.isCharset && rule.isCharset()) {
  8600. ruleNodes.splice(charsetNodeIndex, 0, rule);
  8601. charsetNodeIndex++;
  8602. importNodeIndex++;
  8603. } else if (rule.type === 'Import') {
  8604. ruleNodes.splice(importNodeIndex, 0, rule);
  8605. importNodeIndex++;
  8606. } else {
  8607. ruleNodes.push(rule);
  8608. }
  8609. }
  8610. ruleNodes = charsetRuleNodes.concat(ruleNodes);
  8611. // If this is the root node, we don't render
  8612. // a selector, or {}.
  8613. if (!this.root) {
  8614. debugInfo = getDebugInfo(context, this, tabSetStr);
  8615. if (debugInfo) {
  8616. output.add(debugInfo);
  8617. output.add(tabSetStr);
  8618. }
  8619. var paths = this.paths, pathCnt = paths.length,
  8620. pathSubCnt;
  8621. sep = context.compress ? ',' : (',\n' + tabSetStr);
  8622. for (i = 0; i < pathCnt; i++) {
  8623. path = paths[i];
  8624. if (!(pathSubCnt = path.length)) { continue; }
  8625. if (i > 0) { output.add(sep); }
  8626. context.firstSelector = true;
  8627. path[0].genCSS(context, output);
  8628. context.firstSelector = false;
  8629. for (j = 1; j < pathSubCnt; j++) {
  8630. path[j].genCSS(context, output);
  8631. }
  8632. }
  8633. output.add((context.compress ? '{' : ' {\n') + tabRuleStr);
  8634. }
  8635. // Compile rules and rulesets
  8636. for (i = 0; (rule = ruleNodes[i]); i++) {
  8637. if (i + 1 === ruleNodes.length) {
  8638. context.lastRule = true;
  8639. }
  8640. var currentLastRule = context.lastRule;
  8641. if (rule.isRulesetLike(rule)) {
  8642. context.lastRule = false;
  8643. }
  8644. if (rule.genCSS) {
  8645. rule.genCSS(context, output);
  8646. } else if (rule.value) {
  8647. output.add(rule.value.toString());
  8648. }
  8649. context.lastRule = currentLastRule;
  8650. if (!context.lastRule && rule.isVisible()) {
  8651. output.add(context.compress ? '' : ('\n' + tabRuleStr));
  8652. } else {
  8653. context.lastRule = false;
  8654. }
  8655. }
  8656. if (!this.root) {
  8657. output.add((context.compress ? '}' : '\n' + tabSetStr + '}'));
  8658. context.tabLevel--;
  8659. }
  8660. if (!output.isEmpty() && !context.compress && this.firstRoot) {
  8661. output.add('\n');
  8662. }
  8663. };
  8664. Ruleset.prototype.joinSelectors = function (paths, context, selectors) {
  8665. for (var s = 0; s < selectors.length; s++) {
  8666. this.joinSelector(paths, context, selectors[s]);
  8667. }
  8668. };
  8669. Ruleset.prototype.joinSelector = function (paths, context, selector) {
  8670. function createParenthesis(elementsToPak, originalElement) {
  8671. var replacementParen, j;
  8672. if (elementsToPak.length === 0) {
  8673. replacementParen = new Paren(elementsToPak[0]);
  8674. } else {
  8675. var insideParent = new Array(elementsToPak.length);
  8676. for (j = 0; j < elementsToPak.length; j++) {
  8677. insideParent[j] = new Element(
  8678. null,
  8679. elementsToPak[j],
  8680. originalElement.isVariable,
  8681. originalElement._index,
  8682. originalElement._fileInfo
  8683. );
  8684. }
  8685. replacementParen = new Paren(new Selector(insideParent));
  8686. }
  8687. return replacementParen;
  8688. }
  8689. function createSelector(containedElement, originalElement) {
  8690. var element, selector;
  8691. element = new Element(null, containedElement, originalElement.isVariable, originalElement._index, originalElement._fileInfo);
  8692. selector = new Selector([element]);
  8693. return selector;
  8694. }
  8695. // joins selector path from `beginningPath` with selector path in `addPath`
  8696. // `replacedElement` contains element that is being replaced by `addPath`
  8697. // returns concatenated path
  8698. function addReplacementIntoPath(beginningPath, addPath, replacedElement, originalSelector) {
  8699. var newSelectorPath, lastSelector, newJoinedSelector;
  8700. // our new selector path
  8701. newSelectorPath = [];
  8702. // construct the joined selector - if & is the first thing this will be empty,
  8703. // if not newJoinedSelector will be the last set of elements in the selector
  8704. if (beginningPath.length > 0) {
  8705. newSelectorPath = utils.copyArray(beginningPath);
  8706. lastSelector = newSelectorPath.pop();
  8707. newJoinedSelector = originalSelector.createDerived(utils.copyArray(lastSelector.elements));
  8708. }
  8709. else {
  8710. newJoinedSelector = originalSelector.createDerived([]);
  8711. }
  8712. if (addPath.length > 0) {
  8713. // /deep/ is a CSS4 selector - (removed, so should deprecate)
  8714. // that is valid without anything in front of it
  8715. // so if the & does not have a combinator that is "" or " " then
  8716. // and there is a combinator on the parent, then grab that.
  8717. // this also allows + a { & .b { .a & { ... though not sure why you would want to do that
  8718. var combinator = replacedElement.combinator, parentEl = addPath[0].elements[0];
  8719. if (combinator.emptyOrWhitespace && !parentEl.combinator.emptyOrWhitespace) {
  8720. combinator = parentEl.combinator;
  8721. }
  8722. // join the elements so far with the first part of the parent
  8723. newJoinedSelector.elements.push(new Element(
  8724. combinator,
  8725. parentEl.value,
  8726. replacedElement.isVariable,
  8727. replacedElement._index,
  8728. replacedElement._fileInfo
  8729. ));
  8730. newJoinedSelector.elements = newJoinedSelector.elements.concat(addPath[0].elements.slice(1));
  8731. }
  8732. // now add the joined selector - but only if it is not empty
  8733. if (newJoinedSelector.elements.length !== 0) {
  8734. newSelectorPath.push(newJoinedSelector);
  8735. }
  8736. // put together the parent selectors after the join (e.g. the rest of the parent)
  8737. if (addPath.length > 1) {
  8738. var restOfPath = addPath.slice(1);
  8739. restOfPath = restOfPath.map(function (selector) {
  8740. return selector.createDerived(selector.elements, []);
  8741. });
  8742. newSelectorPath = newSelectorPath.concat(restOfPath);
  8743. }
  8744. return newSelectorPath;
  8745. }
  8746. // joins selector path from `beginningPath` with every selector path in `addPaths` array
  8747. // `replacedElement` contains element that is being replaced by `addPath`
  8748. // returns array with all concatenated paths
  8749. function addAllReplacementsIntoPath( beginningPath, addPaths, replacedElement, originalSelector, result) {
  8750. var j;
  8751. for (j = 0; j < beginningPath.length; j++) {
  8752. var newSelectorPath = addReplacementIntoPath(beginningPath[j], addPaths, replacedElement, originalSelector);
  8753. result.push(newSelectorPath);
  8754. }
  8755. return result;
  8756. }
  8757. function mergeElementsOnToSelectors(elements, selectors) {
  8758. var i, sel;
  8759. if (elements.length === 0) {
  8760. return ;
  8761. }
  8762. if (selectors.length === 0) {
  8763. selectors.push([ new Selector(elements) ]);
  8764. return;
  8765. }
  8766. for (i = 0; (sel = selectors[i]); i++) {
  8767. // if the previous thing in sel is a parent this needs to join on to it
  8768. if (sel.length > 0) {
  8769. sel[sel.length - 1] = sel[sel.length - 1].createDerived(sel[sel.length - 1].elements.concat(elements));
  8770. }
  8771. else {
  8772. sel.push(new Selector(elements));
  8773. }
  8774. }
  8775. }
  8776. // replace all parent selectors inside `inSelector` by content of `context` array
  8777. // resulting selectors are returned inside `paths` array
  8778. // returns true if `inSelector` contained at least one parent selector
  8779. function replaceParentSelector(paths, context, inSelector) {
  8780. // The paths are [[Selector]]
  8781. // The first list is a list of comma separated selectors
  8782. // The inner list is a list of inheritance separated selectors
  8783. // e.g.
  8784. // .a, .b {
  8785. // .c {
  8786. // }
  8787. // }
  8788. // == [[.a] [.c]] [[.b] [.c]]
  8789. //
  8790. var i, j, k, currentElements, newSelectors, selectorsMultiplied, sel, el, hadParentSelector = false, length, lastSelector;
  8791. function findNestedSelector(element) {
  8792. var maybeSelector;
  8793. if (!(element.value instanceof Paren)) {
  8794. return null;
  8795. }
  8796. maybeSelector = element.value.value;
  8797. if (!(maybeSelector instanceof Selector)) {
  8798. return null;
  8799. }
  8800. return maybeSelector;
  8801. }
  8802. // the elements from the current selector so far
  8803. currentElements = [];
  8804. // the current list of new selectors to add to the path.
  8805. // We will build it up. We initiate it with one empty selector as we "multiply" the new selectors
  8806. // by the parents
  8807. newSelectors = [
  8808. []
  8809. ];
  8810. for (i = 0; (el = inSelector.elements[i]); i++) {
  8811. // non parent reference elements just get added
  8812. if (el.value !== '&') {
  8813. var nestedSelector = findNestedSelector(el);
  8814. if (nestedSelector != null) {
  8815. // merge the current list of non parent selector elements
  8816. // on to the current list of selectors to add
  8817. mergeElementsOnToSelectors(currentElements, newSelectors);
  8818. var nestedPaths = [], replaced, replacedNewSelectors = [];
  8819. replaced = replaceParentSelector(nestedPaths, context, nestedSelector);
  8820. hadParentSelector = hadParentSelector || replaced;
  8821. // the nestedPaths array should have only one member - replaceParentSelector does not multiply selectors
  8822. for (k = 0; k < nestedPaths.length; k++) {
  8823. var replacementSelector = createSelector(createParenthesis(nestedPaths[k], el), el);
  8824. addAllReplacementsIntoPath(newSelectors, [replacementSelector], el, inSelector, replacedNewSelectors);
  8825. }
  8826. newSelectors = replacedNewSelectors;
  8827. currentElements = [];
  8828. } else {
  8829. currentElements.push(el);
  8830. }
  8831. } else {
  8832. hadParentSelector = true;
  8833. // the new list of selectors to add
  8834. selectorsMultiplied = [];
  8835. // merge the current list of non parent selector elements
  8836. // on to the current list of selectors to add
  8837. mergeElementsOnToSelectors(currentElements, newSelectors);
  8838. // loop through our current selectors
  8839. for (j = 0; j < newSelectors.length; j++) {
  8840. sel = newSelectors[j];
  8841. // if we don't have any parent paths, the & might be in a mixin so that it can be used
  8842. // whether there are parents or not
  8843. if (context.length === 0) {
  8844. // the combinator used on el should now be applied to the next element instead so that
  8845. // it is not lost
  8846. if (sel.length > 0) {
  8847. sel[0].elements.push(new Element(el.combinator, '', el.isVariable, el._index, el._fileInfo));
  8848. }
  8849. selectorsMultiplied.push(sel);
  8850. }
  8851. else {
  8852. // and the parent selectors
  8853. for (k = 0; k < context.length; k++) {
  8854. // We need to put the current selectors
  8855. // then join the last selector's elements on to the parents selectors
  8856. var newSelectorPath = addReplacementIntoPath(sel, context[k], el, inSelector);
  8857. // add that to our new set of selectors
  8858. selectorsMultiplied.push(newSelectorPath);
  8859. }
  8860. }
  8861. }
  8862. // our new selectors has been multiplied, so reset the state
  8863. newSelectors = selectorsMultiplied;
  8864. currentElements = [];
  8865. }
  8866. }
  8867. // if we have any elements left over (e.g. .a& .b == .b)
  8868. // add them on to all the current selectors
  8869. mergeElementsOnToSelectors(currentElements, newSelectors);
  8870. for (i = 0; i < newSelectors.length; i++) {
  8871. length = newSelectors[i].length;
  8872. if (length > 0) {
  8873. paths.push(newSelectors[i]);
  8874. lastSelector = newSelectors[i][length - 1];
  8875. newSelectors[i][length - 1] = lastSelector.createDerived(lastSelector.elements, inSelector.extendList);
  8876. }
  8877. }
  8878. return hadParentSelector;
  8879. }
  8880. function deriveSelector(visibilityInfo, deriveFrom) {
  8881. var newSelector = deriveFrom.createDerived(deriveFrom.elements, deriveFrom.extendList, deriveFrom.evaldCondition);
  8882. newSelector.copyVisibilityInfo(visibilityInfo);
  8883. return newSelector;
  8884. }
  8885. // joinSelector code follows
  8886. var i, newPaths, hadParentSelector;
  8887. newPaths = [];
  8888. hadParentSelector = replaceParentSelector(newPaths, context, selector);
  8889. if (!hadParentSelector) {
  8890. if (context.length > 0) {
  8891. newPaths = [];
  8892. for (i = 0; i < context.length; i++) {
  8893. var concatenated = context[i].map(deriveSelector.bind(this, selector.visibilityInfo()));
  8894. concatenated.push(selector);
  8895. newPaths.push(concatenated);
  8896. }
  8897. }
  8898. else {
  8899. newPaths = [[selector]];
  8900. }
  8901. }
  8902. for (i = 0; i < newPaths.length; i++) {
  8903. paths.push(newPaths[i]);
  8904. }
  8905. };
  8906. module.exports = Ruleset;
  8907. },{"../contexts":13,"../functions/default":25,"../functions/function-registry":27,"../utils":89,"./anonymous":50,"./comment":57,"./debug-info":59,"./declaration":60,"./element":63,"./keyword":70,"./node":76,"./paren":78,"./selector":82}],82:[function(require,module,exports){
  8908. var Node = require('./node'),
  8909. Element = require('./element'),
  8910. LessError = require('../less-error');
  8911. var Selector = function (elements, extendList, condition, index, currentFileInfo, visibilityInfo) {
  8912. this.extendList = extendList;
  8913. this.condition = condition;
  8914. this.evaldCondition = !condition;
  8915. this._index = index;
  8916. this._fileInfo = currentFileInfo;
  8917. this.elements = this.getElements(elements);
  8918. this.mixinElements_ = undefined;
  8919. this.copyVisibilityInfo(visibilityInfo);
  8920. this.setParent(this.elements, this);
  8921. };
  8922. Selector.prototype = new Node();
  8923. Selector.prototype.type = 'Selector';
  8924. Selector.prototype.accept = function (visitor) {
  8925. if (this.elements) {
  8926. this.elements = visitor.visitArray(this.elements);
  8927. }
  8928. if (this.extendList) {
  8929. this.extendList = visitor.visitArray(this.extendList);
  8930. }
  8931. if (this.condition) {
  8932. this.condition = visitor.visit(this.condition);
  8933. }
  8934. };
  8935. Selector.prototype.createDerived = function(elements, extendList, evaldCondition) {
  8936. elements = this.getElements(elements);
  8937. var newSelector = new Selector(elements, extendList || this.extendList,
  8938. null, this.getIndex(), this.fileInfo(), this.visibilityInfo());
  8939. newSelector.evaldCondition = (evaldCondition != null) ? evaldCondition : this.evaldCondition;
  8940. newSelector.mediaEmpty = this.mediaEmpty;
  8941. return newSelector;
  8942. };
  8943. Selector.prototype.getElements = function(els) {
  8944. if (!els) {
  8945. return [new Element('', '&', false, this._index, this._fileInfo)];
  8946. }
  8947. if (typeof els === 'string') {
  8948. this.parse.parseNode(
  8949. els,
  8950. ['selector'],
  8951. this._index,
  8952. this._fileInfo,
  8953. function(err, result) {
  8954. if (err) {
  8955. throw new LessError({
  8956. index: err.index,
  8957. message: err.message
  8958. }, this.parse.imports, this._fileInfo.filename);
  8959. }
  8960. els = result[0].elements;
  8961. });
  8962. }
  8963. return els;
  8964. };
  8965. Selector.prototype.createEmptySelectors = function() {
  8966. var el = new Element('', '&', false, this._index, this._fileInfo),
  8967. sels = [new Selector([el], null, null, this._index, this._fileInfo)];
  8968. sels[0].mediaEmpty = true;
  8969. return sels;
  8970. };
  8971. Selector.prototype.match = function (other) {
  8972. var elements = this.elements,
  8973. len = elements.length,
  8974. olen, i;
  8975. other = other.mixinElements();
  8976. olen = other.length;
  8977. if (olen === 0 || len < olen) {
  8978. return 0;
  8979. } else {
  8980. for (i = 0; i < olen; i++) {
  8981. if (elements[i].value !== other[i]) {
  8982. return 0;
  8983. }
  8984. }
  8985. }
  8986. return olen; // return number of matched elements
  8987. };
  8988. Selector.prototype.mixinElements = function() {
  8989. if (this.mixinElements_) {
  8990. return this.mixinElements_;
  8991. }
  8992. var elements = this.elements.map( function(v) {
  8993. return v.combinator.value + (v.value.value || v.value);
  8994. }).join('').match(/[,&#\*\.\w-]([\w-]|(\\.))*/g);
  8995. if (elements) {
  8996. if (elements[0] === '&') {
  8997. elements.shift();
  8998. }
  8999. } else {
  9000. elements = [];
  9001. }
  9002. return (this.mixinElements_ = elements);
  9003. };
  9004. Selector.prototype.isJustParentSelector = function() {
  9005. return !this.mediaEmpty &&
  9006. this.elements.length === 1 &&
  9007. this.elements[0].value === '&' &&
  9008. (this.elements[0].combinator.value === ' ' || this.elements[0].combinator.value === '');
  9009. };
  9010. Selector.prototype.eval = function (context) {
  9011. var evaldCondition = this.condition && this.condition.eval(context),
  9012. elements = this.elements, extendList = this.extendList;
  9013. elements = elements && elements.map(function (e) { return e.eval(context); });
  9014. extendList = extendList && extendList.map(function(extend) { return extend.eval(context); });
  9015. return this.createDerived(elements, extendList, evaldCondition);
  9016. };
  9017. Selector.prototype.genCSS = function (context, output) {
  9018. var i, element;
  9019. if ((!context || !context.firstSelector) && this.elements[0].combinator.value === '') {
  9020. output.add(' ', this.fileInfo(), this.getIndex());
  9021. }
  9022. for (i = 0; i < this.elements.length; i++) {
  9023. element = this.elements[i];
  9024. element.genCSS(context, output);
  9025. }
  9026. };
  9027. Selector.prototype.getIsOutput = function() {
  9028. return this.evaldCondition;
  9029. };
  9030. module.exports = Selector;
  9031. },{"../less-error":38,"./element":63,"./node":76}],83:[function(require,module,exports){
  9032. var Node = require('./node');
  9033. var UnicodeDescriptor = function (value) {
  9034. this.value = value;
  9035. };
  9036. UnicodeDescriptor.prototype = new Node();
  9037. UnicodeDescriptor.prototype.type = 'UnicodeDescriptor';
  9038. module.exports = UnicodeDescriptor;
  9039. },{"./node":76}],84:[function(require,module,exports){
  9040. var Node = require('./node'),
  9041. unitConversions = require('../data/unit-conversions'),
  9042. utils = require('../utils');
  9043. var Unit = function (numerator, denominator, backupUnit) {
  9044. this.numerator = numerator ? utils.copyArray(numerator).sort() : [];
  9045. this.denominator = denominator ? utils.copyArray(denominator).sort() : [];
  9046. if (backupUnit) {
  9047. this.backupUnit = backupUnit;
  9048. } else if (numerator && numerator.length) {
  9049. this.backupUnit = numerator[0];
  9050. }
  9051. };
  9052. Unit.prototype = new Node();
  9053. Unit.prototype.type = 'Unit';
  9054. Unit.prototype.clone = function () {
  9055. return new Unit(utils.copyArray(this.numerator), utils.copyArray(this.denominator), this.backupUnit);
  9056. };
  9057. Unit.prototype.genCSS = function (context, output) {
  9058. // Dimension checks the unit is singular and throws an error if in strict math mode.
  9059. var strictUnits = context && context.strictUnits;
  9060. if (this.numerator.length === 1) {
  9061. output.add(this.numerator[0]); // the ideal situation
  9062. } else if (!strictUnits && this.backupUnit) {
  9063. output.add(this.backupUnit);
  9064. } else if (!strictUnits && this.denominator.length) {
  9065. output.add(this.denominator[0]);
  9066. }
  9067. };
  9068. Unit.prototype.toString = function () {
  9069. var i, returnStr = this.numerator.join('*');
  9070. for (i = 0; i < this.denominator.length; i++) {
  9071. returnStr += '/' + this.denominator[i];
  9072. }
  9073. return returnStr;
  9074. };
  9075. Unit.prototype.compare = function (other) {
  9076. return this.is(other.toString()) ? 0 : undefined;
  9077. };
  9078. Unit.prototype.is = function (unitString) {
  9079. return this.toString().toUpperCase() === unitString.toUpperCase();
  9080. };
  9081. Unit.prototype.isLength = function () {
  9082. return RegExp('^(px|em|ex|ch|rem|in|cm|mm|pc|pt|ex|vw|vh|vmin|vmax)$', 'gi').test(this.toCSS());
  9083. };
  9084. Unit.prototype.isEmpty = function () {
  9085. return this.numerator.length === 0 && this.denominator.length === 0;
  9086. };
  9087. Unit.prototype.isSingular = function() {
  9088. return this.numerator.length <= 1 && this.denominator.length === 0;
  9089. };
  9090. Unit.prototype.map = function(callback) {
  9091. var i;
  9092. for (i = 0; i < this.numerator.length; i++) {
  9093. this.numerator[i] = callback(this.numerator[i], false);
  9094. }
  9095. for (i = 0; i < this.denominator.length; i++) {
  9096. this.denominator[i] = callback(this.denominator[i], true);
  9097. }
  9098. };
  9099. Unit.prototype.usedUnits = function() {
  9100. var group, result = {}, mapUnit, groupName;
  9101. mapUnit = function (atomicUnit) {
  9102. /* jshint loopfunc:true */
  9103. if (group.hasOwnProperty(atomicUnit) && !result[groupName]) {
  9104. result[groupName] = atomicUnit;
  9105. }
  9106. return atomicUnit;
  9107. };
  9108. for (groupName in unitConversions) {
  9109. if (unitConversions.hasOwnProperty(groupName)) {
  9110. group = unitConversions[groupName];
  9111. this.map(mapUnit);
  9112. }
  9113. }
  9114. return result;
  9115. };
  9116. Unit.prototype.cancel = function () {
  9117. var counter = {}, atomicUnit, i;
  9118. for (i = 0; i < this.numerator.length; i++) {
  9119. atomicUnit = this.numerator[i];
  9120. counter[atomicUnit] = (counter[atomicUnit] || 0) + 1;
  9121. }
  9122. for (i = 0; i < this.denominator.length; i++) {
  9123. atomicUnit = this.denominator[i];
  9124. counter[atomicUnit] = (counter[atomicUnit] || 0) - 1;
  9125. }
  9126. this.numerator = [];
  9127. this.denominator = [];
  9128. for (atomicUnit in counter) {
  9129. if (counter.hasOwnProperty(atomicUnit)) {
  9130. var count = counter[atomicUnit];
  9131. if (count > 0) {
  9132. for (i = 0; i < count; i++) {
  9133. this.numerator.push(atomicUnit);
  9134. }
  9135. } else if (count < 0) {
  9136. for (i = 0; i < -count; i++) {
  9137. this.denominator.push(atomicUnit);
  9138. }
  9139. }
  9140. }
  9141. }
  9142. this.numerator.sort();
  9143. this.denominator.sort();
  9144. };
  9145. module.exports = Unit;
  9146. },{"../data/unit-conversions":16,"../utils":89,"./node":76}],85:[function(require,module,exports){
  9147. var Node = require('./node');
  9148. var URL = function (val, index, currentFileInfo, isEvald) {
  9149. this.value = val;
  9150. this._index = index;
  9151. this._fileInfo = currentFileInfo;
  9152. this.isEvald = isEvald;
  9153. };
  9154. URL.prototype = new Node();
  9155. URL.prototype.type = 'Url';
  9156. URL.prototype.accept = function (visitor) {
  9157. this.value = visitor.visit(this.value);
  9158. };
  9159. URL.prototype.genCSS = function (context, output) {
  9160. output.add('url(');
  9161. this.value.genCSS(context, output);
  9162. output.add(')');
  9163. };
  9164. URL.prototype.eval = function (context) {
  9165. var val = this.value.eval(context),
  9166. rootpath;
  9167. if (!this.isEvald) {
  9168. // Add the rootpath if the URL requires a rewrite
  9169. rootpath = this.fileInfo() && this.fileInfo().rootpath;
  9170. if (typeof rootpath === 'string' &&
  9171. typeof val.value === 'string' &&
  9172. context.pathRequiresRewrite(val.value)) {
  9173. if (!val.quote) {
  9174. rootpath = escapePath(rootpath);
  9175. }
  9176. val.value = context.rewritePath(val.value, rootpath);
  9177. } else {
  9178. val.value = context.normalizePath(val.value);
  9179. }
  9180. // Add url args if enabled
  9181. if (context.urlArgs) {
  9182. if (!val.value.match(/^\s*data:/)) {
  9183. var delimiter = val.value.indexOf('?') === -1 ? '?' : '&';
  9184. var urlArgs = delimiter + context.urlArgs;
  9185. if (val.value.indexOf('#') !== -1) {
  9186. val.value = val.value.replace('#', urlArgs + '#');
  9187. } else {
  9188. val.value += urlArgs;
  9189. }
  9190. }
  9191. }
  9192. }
  9193. return new URL(val, this.getIndex(), this.fileInfo(), true);
  9194. };
  9195. function escapePath(path) {
  9196. return path.replace(/[\(\)'"\s]/g, function(match) { return '\\' + match; });
  9197. }
  9198. module.exports = URL;
  9199. },{"./node":76}],86:[function(require,module,exports){
  9200. var Node = require('./node');
  9201. var Value = function (value) {
  9202. if (!value) {
  9203. throw new Error('Value requires an array argument');
  9204. }
  9205. if (!Array.isArray(value)) {
  9206. this.value = [ value ];
  9207. }
  9208. else {
  9209. this.value = value;
  9210. }
  9211. };
  9212. Value.prototype = new Node();
  9213. Value.prototype.type = 'Value';
  9214. Value.prototype.accept = function (visitor) {
  9215. if (this.value) {
  9216. this.value = visitor.visitArray(this.value);
  9217. }
  9218. };
  9219. Value.prototype.eval = function (context) {
  9220. if (this.value.length === 1) {
  9221. return this.value[0].eval(context);
  9222. } else {
  9223. return new Value(this.value.map(function (v) {
  9224. return v.eval(context);
  9225. }));
  9226. }
  9227. };
  9228. Value.prototype.genCSS = function (context, output) {
  9229. var i;
  9230. for (i = 0; i < this.value.length; i++) {
  9231. this.value[i].genCSS(context, output);
  9232. if (i + 1 < this.value.length) {
  9233. output.add((context && context.compress) ? ',' : ', ');
  9234. }
  9235. }
  9236. };
  9237. module.exports = Value;
  9238. },{"./node":76}],87:[function(require,module,exports){
  9239. var Node = require('./node'),
  9240. Variable = require('./variable'),
  9241. Ruleset = require('./ruleset'),
  9242. DetachedRuleset = require('./detached-ruleset'),
  9243. LessError = require('../less-error');
  9244. var VariableCall = function (variable, index, currentFileInfo) {
  9245. this.variable = variable;
  9246. this._index = index;
  9247. this._fileInfo = currentFileInfo;
  9248. this.allowRoot = true;
  9249. };
  9250. VariableCall.prototype = new Node();
  9251. VariableCall.prototype.type = 'VariableCall';
  9252. VariableCall.prototype.eval = function (context) {
  9253. var rules, detachedRuleset = new Variable(this.variable, this.getIndex(), this.fileInfo()).eval(context),
  9254. error = new LessError({message: 'Could not evaluate variable call ' + this.variable});
  9255. if (!detachedRuleset.ruleset) {
  9256. if (Array.isArray(detachedRuleset)) {
  9257. rules = detachedRuleset;
  9258. }
  9259. else if (Array.isArray(detachedRuleset.value)) {
  9260. rules = detachedRuleset.value;
  9261. }
  9262. else {
  9263. throw error;
  9264. }
  9265. detachedRuleset = new DetachedRuleset(new Ruleset('', rules));
  9266. }
  9267. if (detachedRuleset.ruleset) {
  9268. return detachedRuleset.callEval(context);
  9269. }
  9270. throw error;
  9271. };
  9272. module.exports = VariableCall;
  9273. },{"../less-error":38,"./detached-ruleset":61,"./node":76,"./ruleset":81,"./variable":88}],88:[function(require,module,exports){
  9274. var Node = require('./node'),
  9275. Call = require('./call');
  9276. var Variable = function (name, index, currentFileInfo) {
  9277. this.name = name;
  9278. this._index = index;
  9279. this._fileInfo = currentFileInfo;
  9280. };
  9281. Variable.prototype = new Node();
  9282. Variable.prototype.type = 'Variable';
  9283. Variable.prototype.eval = function (context) {
  9284. var variable, name = this.name;
  9285. if (name.indexOf('@@') === 0) {
  9286. name = '@' + new Variable(name.slice(1), this.getIndex(), this.fileInfo()).eval(context).value;
  9287. }
  9288. if (this.evaluating) {
  9289. throw { type: 'Name',
  9290. message: 'Recursive variable definition for ' + name,
  9291. filename: this.fileInfo().filename,
  9292. index: this.getIndex() };
  9293. }
  9294. this.evaluating = true;
  9295. variable = this.find(context.frames, function (frame) {
  9296. var v = frame.variable(name);
  9297. if (v) {
  9298. if (v.important) {
  9299. var importantScope = context.importantScope[context.importantScope.length - 1];
  9300. importantScope.important = v.important;
  9301. }
  9302. // If in calc, wrap vars in a function call to cascade evaluate args first
  9303. if (context.inCalc) {
  9304. return (new Call('_SELF', [v.value])).eval(context);
  9305. }
  9306. else {
  9307. return v.value.eval(context);
  9308. }
  9309. }
  9310. });
  9311. if (variable) {
  9312. this.evaluating = false;
  9313. return variable;
  9314. } else {
  9315. throw { type: 'Name',
  9316. message: 'variable ' + name + ' is undefined',
  9317. filename: this.fileInfo().filename,
  9318. index: this.getIndex() };
  9319. }
  9320. };
  9321. Variable.prototype.find = function (obj, fun) {
  9322. for (var i = 0, r; i < obj.length; i++) {
  9323. r = fun.call(obj, obj[i]);
  9324. if (r) { return r; }
  9325. }
  9326. return null;
  9327. };
  9328. module.exports = Variable;
  9329. },{"./call":54,"./node":76}],89:[function(require,module,exports){
  9330. /* jshint proto: true */
  9331. var Constants = require('./constants');
  9332. var utils = {
  9333. getLocation: function(index, inputStream) {
  9334. var n = index + 1,
  9335. line = null,
  9336. column = -1;
  9337. while (--n >= 0 && inputStream.charAt(n) !== '\n') {
  9338. column++;
  9339. }
  9340. if (typeof index === 'number') {
  9341. line = (inputStream.slice(0, index).match(/\n/g) || '').length;
  9342. }
  9343. return {
  9344. line: line,
  9345. column: column
  9346. };
  9347. },
  9348. copyArray: function(arr) {
  9349. var i, length = arr.length,
  9350. copy = new Array(length);
  9351. for (i = 0; i < length; i++) {
  9352. copy[i] = arr[i];
  9353. }
  9354. return copy;
  9355. },
  9356. clone: function (obj) {
  9357. var cloned = {};
  9358. for (var prop in obj) {
  9359. if (obj.hasOwnProperty(prop)) {
  9360. cloned[prop] = obj[prop];
  9361. }
  9362. }
  9363. return cloned;
  9364. },
  9365. copyOptions: function(obj1, obj2) {
  9366. var opts = utils.defaults(obj1, obj2);
  9367. if (opts.strictMath) {
  9368. opts.math = Constants.Math.STRICT_LEGACY;
  9369. }
  9370. // Back compat with changed relativeUrls option
  9371. if (opts.relativeUrls) {
  9372. opts.rewriteUrls = Constants.RewriteUrls.ALL;
  9373. }
  9374. if (typeof opts.math === 'string') {
  9375. switch (opts.math.toLowerCase()) {
  9376. case 'always':
  9377. opts.math = Constants.Math.ALWAYS;
  9378. break;
  9379. case 'parens-division':
  9380. opts.math = Constants.Math.PARENS_DIVISION;
  9381. break;
  9382. case 'strict':
  9383. case 'parens':
  9384. opts.math = Constants.Math.PARENS;
  9385. break;
  9386. case 'strict-legacy':
  9387. opts.math = Constants.Math.STRICT_LEGACY;
  9388. }
  9389. }
  9390. if (typeof opts.rewriteUrls === 'string') {
  9391. switch (opts.rewriteUrls.toLowerCase()) {
  9392. case 'off':
  9393. opts.rewriteUrls = Constants.RewriteUrls.OFF;
  9394. break;
  9395. case 'local':
  9396. opts.rewriteUrls = Constants.RewriteUrls.LOCAL;
  9397. break;
  9398. case 'all':
  9399. opts.rewriteUrls = Constants.RewriteUrls.ALL;
  9400. break;
  9401. }
  9402. }
  9403. return opts;
  9404. },
  9405. defaults: function(obj1, obj2) {
  9406. if (!obj2._defaults || obj2._defaults !== obj1) {
  9407. for (var prop in obj1) {
  9408. if (obj1.hasOwnProperty(prop)) {
  9409. if (!obj2.hasOwnProperty(prop)) {
  9410. obj2[prop] = obj1[prop];
  9411. }
  9412. else if (Array.isArray(obj1[prop])
  9413. && Array.isArray(obj2[prop])) {
  9414. obj1[prop].forEach(function(p) {
  9415. if (obj2[prop].indexOf(p) === -1) {
  9416. obj2[prop].push(p);
  9417. }
  9418. });
  9419. }
  9420. }
  9421. }
  9422. }
  9423. obj2._defaults = obj1;
  9424. return obj2;
  9425. },
  9426. merge: function(obj1, obj2) {
  9427. for (var prop in obj2) {
  9428. if (obj2.hasOwnProperty(prop)) {
  9429. obj1[prop] = obj2[prop];
  9430. }
  9431. }
  9432. return obj1;
  9433. },
  9434. flattenArray: function(arr, result) {
  9435. result = result || [];
  9436. for (var i = 0, length = arr.length; i < length; i++) {
  9437. var value = arr[i];
  9438. if (Array.isArray(value)) {
  9439. utils.flattenArray(value, result);
  9440. } else {
  9441. if (value !== undefined) {
  9442. result.push(value);
  9443. }
  9444. }
  9445. }
  9446. return result;
  9447. }
  9448. };
  9449. module.exports = utils;
  9450. },{"./constants":12}],90:[function(require,module,exports){
  9451. var tree = require('../tree'),
  9452. Visitor = require('./visitor'),
  9453. logger = require('../logger'),
  9454. utils = require('../utils');
  9455. /* jshint loopfunc:true */
  9456. var ExtendFinderVisitor = function() {
  9457. this._visitor = new Visitor(this);
  9458. this.contexts = [];
  9459. this.allExtendsStack = [[]];
  9460. };
  9461. ExtendFinderVisitor.prototype = {
  9462. run: function (root) {
  9463. root = this._visitor.visit(root);
  9464. root.allExtends = this.allExtendsStack[0];
  9465. return root;
  9466. },
  9467. visitDeclaration: function (declNode, visitArgs) {
  9468. visitArgs.visitDeeper = false;
  9469. },
  9470. visitMixinDefinition: function (mixinDefinitionNode, visitArgs) {
  9471. visitArgs.visitDeeper = false;
  9472. },
  9473. visitRuleset: function (rulesetNode, visitArgs) {
  9474. if (rulesetNode.root) {
  9475. return;
  9476. }
  9477. var i, j, extend, allSelectorsExtendList = [], extendList;
  9478. // get &:extend(.a); rules which apply to all selectors in this ruleset
  9479. var rules = rulesetNode.rules, ruleCnt = rules ? rules.length : 0;
  9480. for (i = 0; i < ruleCnt; i++) {
  9481. if (rulesetNode.rules[i] instanceof tree.Extend) {
  9482. allSelectorsExtendList.push(rules[i]);
  9483. rulesetNode.extendOnEveryPath = true;
  9484. }
  9485. }
  9486. // now find every selector and apply the extends that apply to all extends
  9487. // and the ones which apply to an individual extend
  9488. var paths = rulesetNode.paths;
  9489. for (i = 0; i < paths.length; i++) {
  9490. var selectorPath = paths[i],
  9491. selector = selectorPath[selectorPath.length - 1],
  9492. selExtendList = selector.extendList;
  9493. extendList = selExtendList ? utils.copyArray(selExtendList).concat(allSelectorsExtendList)
  9494. : allSelectorsExtendList;
  9495. if (extendList) {
  9496. extendList = extendList.map(function(allSelectorsExtend) {
  9497. return allSelectorsExtend.clone();
  9498. });
  9499. }
  9500. for (j = 0; j < extendList.length; j++) {
  9501. this.foundExtends = true;
  9502. extend = extendList[j];
  9503. extend.findSelfSelectors(selectorPath);
  9504. extend.ruleset = rulesetNode;
  9505. if (j === 0) { extend.firstExtendOnThisSelectorPath = true; }
  9506. this.allExtendsStack[this.allExtendsStack.length - 1].push(extend);
  9507. }
  9508. }
  9509. this.contexts.push(rulesetNode.selectors);
  9510. },
  9511. visitRulesetOut: function (rulesetNode) {
  9512. if (!rulesetNode.root) {
  9513. this.contexts.length = this.contexts.length - 1;
  9514. }
  9515. },
  9516. visitMedia: function (mediaNode, visitArgs) {
  9517. mediaNode.allExtends = [];
  9518. this.allExtendsStack.push(mediaNode.allExtends);
  9519. },
  9520. visitMediaOut: function (mediaNode) {
  9521. this.allExtendsStack.length = this.allExtendsStack.length - 1;
  9522. },
  9523. visitAtRule: function (atRuleNode, visitArgs) {
  9524. atRuleNode.allExtends = [];
  9525. this.allExtendsStack.push(atRuleNode.allExtends);
  9526. },
  9527. visitAtRuleOut: function (atRuleNode) {
  9528. this.allExtendsStack.length = this.allExtendsStack.length - 1;
  9529. }
  9530. };
  9531. var ProcessExtendsVisitor = function() {
  9532. this._visitor = new Visitor(this);
  9533. };
  9534. ProcessExtendsVisitor.prototype = {
  9535. run: function(root) {
  9536. var extendFinder = new ExtendFinderVisitor();
  9537. this.extendIndices = {};
  9538. extendFinder.run(root);
  9539. if (!extendFinder.foundExtends) { return root; }
  9540. root.allExtends = root.allExtends.concat(this.doExtendChaining(root.allExtends, root.allExtends));
  9541. this.allExtendsStack = [root.allExtends];
  9542. var newRoot = this._visitor.visit(root);
  9543. this.checkExtendsForNonMatched(root.allExtends);
  9544. return newRoot;
  9545. },
  9546. checkExtendsForNonMatched: function(extendList) {
  9547. var indices = this.extendIndices;
  9548. extendList.filter(function(extend) {
  9549. return !extend.hasFoundMatches && extend.parent_ids.length == 1;
  9550. }).forEach(function(extend) {
  9551. var selector = '_unknown_';
  9552. try {
  9553. selector = extend.selector.toCSS({});
  9554. }
  9555. catch (_) {}
  9556. if (!indices[extend.index + ' ' + selector]) {
  9557. indices[extend.index + ' ' + selector] = true;
  9558. logger.warn('extend \'' + selector + '\' has no matches');
  9559. }
  9560. });
  9561. },
  9562. doExtendChaining: function (extendsList, extendsListTarget, iterationCount) {
  9563. //
  9564. // chaining is different from normal extension.. if we extend an extend then we are not just copying, altering
  9565. // and pasting the selector we would do normally, but we are also adding an extend with the same target selector
  9566. // this means this new extend can then go and alter other extends
  9567. //
  9568. // this method deals with all the chaining work - without it, extend is flat and doesn't work on other extend selectors
  9569. // this is also the most expensive.. and a match on one selector can cause an extension of a selector we had already
  9570. // processed if we look at each selector at a time, as is done in visitRuleset
  9571. var extendIndex, targetExtendIndex, matches, extendsToAdd = [], newSelector, extendVisitor = this, selectorPath,
  9572. extend, targetExtend, newExtend;
  9573. iterationCount = iterationCount || 0;
  9574. // loop through comparing every extend with every target extend.
  9575. // a target extend is the one on the ruleset we are looking at copy/edit/pasting in place
  9576. // e.g. .a:extend(.b) {} and .b:extend(.c) {} then the first extend extends the second one
  9577. // and the second is the target.
  9578. // the separation into two lists allows us to process a subset of chains with a bigger set, as is the
  9579. // case when processing media queries
  9580. for (extendIndex = 0; extendIndex < extendsList.length; extendIndex++) {
  9581. for (targetExtendIndex = 0; targetExtendIndex < extendsListTarget.length; targetExtendIndex++) {
  9582. extend = extendsList[extendIndex];
  9583. targetExtend = extendsListTarget[targetExtendIndex];
  9584. // look for circular references
  9585. if ( extend.parent_ids.indexOf( targetExtend.object_id ) >= 0 ) { continue; }
  9586. // find a match in the target extends self selector (the bit before :extend)
  9587. selectorPath = [targetExtend.selfSelectors[0]];
  9588. matches = extendVisitor.findMatch(extend, selectorPath);
  9589. if (matches.length) {
  9590. extend.hasFoundMatches = true;
  9591. // we found a match, so for each self selector..
  9592. extend.selfSelectors.forEach(function(selfSelector) {
  9593. var info = targetExtend.visibilityInfo();
  9594. // process the extend as usual
  9595. newSelector = extendVisitor.extendSelector(matches, selectorPath, selfSelector, extend.isVisible());
  9596. // but now we create a new extend from it
  9597. newExtend = new(tree.Extend)(targetExtend.selector, targetExtend.option, 0, targetExtend.fileInfo(), info);
  9598. newExtend.selfSelectors = newSelector;
  9599. // add the extend onto the list of extends for that selector
  9600. newSelector[newSelector.length - 1].extendList = [newExtend];
  9601. // record that we need to add it.
  9602. extendsToAdd.push(newExtend);
  9603. newExtend.ruleset = targetExtend.ruleset;
  9604. // remember its parents for circular references
  9605. newExtend.parent_ids = newExtend.parent_ids.concat(targetExtend.parent_ids, extend.parent_ids);
  9606. // only process the selector once.. if we have :extend(.a,.b) then multiple
  9607. // extends will look at the same selector path, so when extending
  9608. // we know that any others will be duplicates in terms of what is added to the css
  9609. if (targetExtend.firstExtendOnThisSelectorPath) {
  9610. newExtend.firstExtendOnThisSelectorPath = true;
  9611. targetExtend.ruleset.paths.push(newSelector);
  9612. }
  9613. });
  9614. }
  9615. }
  9616. }
  9617. if (extendsToAdd.length) {
  9618. // try to detect circular references to stop a stack overflow.
  9619. // may no longer be needed.
  9620. this.extendChainCount++;
  9621. if (iterationCount > 100) {
  9622. var selectorOne = '{unable to calculate}';
  9623. var selectorTwo = '{unable to calculate}';
  9624. try {
  9625. selectorOne = extendsToAdd[0].selfSelectors[0].toCSS();
  9626. selectorTwo = extendsToAdd[0].selector.toCSS();
  9627. }
  9628. catch (e) {}
  9629. throw { message: 'extend circular reference detected. One of the circular extends is currently:' +
  9630. selectorOne + ':extend(' + selectorTwo + ')'};
  9631. }
  9632. // now process the new extends on the existing rules so that we can handle a extending b extending c extending
  9633. // d extending e...
  9634. return extendsToAdd.concat(extendVisitor.doExtendChaining(extendsToAdd, extendsListTarget, iterationCount + 1));
  9635. } else {
  9636. return extendsToAdd;
  9637. }
  9638. },
  9639. visitDeclaration: function (ruleNode, visitArgs) {
  9640. visitArgs.visitDeeper = false;
  9641. },
  9642. visitMixinDefinition: function (mixinDefinitionNode, visitArgs) {
  9643. visitArgs.visitDeeper = false;
  9644. },
  9645. visitSelector: function (selectorNode, visitArgs) {
  9646. visitArgs.visitDeeper = false;
  9647. },
  9648. visitRuleset: function (rulesetNode, visitArgs) {
  9649. if (rulesetNode.root) {
  9650. return;
  9651. }
  9652. var matches, pathIndex, extendIndex, allExtends = this.allExtendsStack[this.allExtendsStack.length - 1],
  9653. selectorsToAdd = [], extendVisitor = this, selectorPath;
  9654. // look at each selector path in the ruleset, find any extend matches and then copy, find and replace
  9655. for (extendIndex = 0; extendIndex < allExtends.length; extendIndex++) {
  9656. for (pathIndex = 0; pathIndex < rulesetNode.paths.length; pathIndex++) {
  9657. selectorPath = rulesetNode.paths[pathIndex];
  9658. // extending extends happens initially, before the main pass
  9659. if (rulesetNode.extendOnEveryPath) { continue; }
  9660. var extendList = selectorPath[selectorPath.length - 1].extendList;
  9661. if (extendList && extendList.length) { continue; }
  9662. matches = this.findMatch(allExtends[extendIndex], selectorPath);
  9663. if (matches.length) {
  9664. allExtends[extendIndex].hasFoundMatches = true;
  9665. allExtends[extendIndex].selfSelectors.forEach(function(selfSelector) {
  9666. var extendedSelectors;
  9667. extendedSelectors = extendVisitor.extendSelector(matches, selectorPath, selfSelector, allExtends[extendIndex].isVisible());
  9668. selectorsToAdd.push(extendedSelectors);
  9669. });
  9670. }
  9671. }
  9672. }
  9673. rulesetNode.paths = rulesetNode.paths.concat(selectorsToAdd);
  9674. },
  9675. findMatch: function (extend, haystackSelectorPath) {
  9676. //
  9677. // look through the haystack selector path to try and find the needle - extend.selector
  9678. // returns an array of selector matches that can then be replaced
  9679. //
  9680. var haystackSelectorIndex, hackstackSelector, hackstackElementIndex, haystackElement,
  9681. targetCombinator, i,
  9682. extendVisitor = this,
  9683. needleElements = extend.selector.elements,
  9684. potentialMatches = [], potentialMatch, matches = [];
  9685. // loop through the haystack elements
  9686. for (haystackSelectorIndex = 0; haystackSelectorIndex < haystackSelectorPath.length; haystackSelectorIndex++) {
  9687. hackstackSelector = haystackSelectorPath[haystackSelectorIndex];
  9688. for (hackstackElementIndex = 0; hackstackElementIndex < hackstackSelector.elements.length; hackstackElementIndex++) {
  9689. haystackElement = hackstackSelector.elements[hackstackElementIndex];
  9690. // if we allow elements before our match we can add a potential match every time. otherwise only at the first element.
  9691. if (extend.allowBefore || (haystackSelectorIndex === 0 && hackstackElementIndex === 0)) {
  9692. potentialMatches.push({pathIndex: haystackSelectorIndex, index: hackstackElementIndex, matched: 0,
  9693. initialCombinator: haystackElement.combinator});
  9694. }
  9695. for (i = 0; i < potentialMatches.length; i++) {
  9696. potentialMatch = potentialMatches[i];
  9697. // selectors add " " onto the first element. When we use & it joins the selectors together, but if we don't
  9698. // then each selector in haystackSelectorPath has a space before it added in the toCSS phase. so we need to
  9699. // work out what the resulting combinator will be
  9700. targetCombinator = haystackElement.combinator.value;
  9701. if (targetCombinator === '' && hackstackElementIndex === 0) {
  9702. targetCombinator = ' ';
  9703. }
  9704. // if we don't match, null our match to indicate failure
  9705. if (!extendVisitor.isElementValuesEqual(needleElements[potentialMatch.matched].value, haystackElement.value) ||
  9706. (potentialMatch.matched > 0 && needleElements[potentialMatch.matched].combinator.value !== targetCombinator)) {
  9707. potentialMatch = null;
  9708. } else {
  9709. potentialMatch.matched++;
  9710. }
  9711. // if we are still valid and have finished, test whether we have elements after and whether these are allowed
  9712. if (potentialMatch) {
  9713. potentialMatch.finished = potentialMatch.matched === needleElements.length;
  9714. if (potentialMatch.finished &&
  9715. (!extend.allowAfter &&
  9716. (hackstackElementIndex + 1 < hackstackSelector.elements.length || haystackSelectorIndex + 1 < haystackSelectorPath.length))) {
  9717. potentialMatch = null;
  9718. }
  9719. }
  9720. // if null we remove, if not, we are still valid, so either push as a valid match or continue
  9721. if (potentialMatch) {
  9722. if (potentialMatch.finished) {
  9723. potentialMatch.length = needleElements.length;
  9724. potentialMatch.endPathIndex = haystackSelectorIndex;
  9725. potentialMatch.endPathElementIndex = hackstackElementIndex + 1; // index after end of match
  9726. potentialMatches.length = 0; // we don't allow matches to overlap, so start matching again
  9727. matches.push(potentialMatch);
  9728. }
  9729. } else {
  9730. potentialMatches.splice(i, 1);
  9731. i--;
  9732. }
  9733. }
  9734. }
  9735. }
  9736. return matches;
  9737. },
  9738. isElementValuesEqual: function(elementValue1, elementValue2) {
  9739. if (typeof elementValue1 === 'string' || typeof elementValue2 === 'string') {
  9740. return elementValue1 === elementValue2;
  9741. }
  9742. if (elementValue1 instanceof tree.Attribute) {
  9743. if (elementValue1.op !== elementValue2.op || elementValue1.key !== elementValue2.key) {
  9744. return false;
  9745. }
  9746. if (!elementValue1.value || !elementValue2.value) {
  9747. if (elementValue1.value || elementValue2.value) {
  9748. return false;
  9749. }
  9750. return true;
  9751. }
  9752. elementValue1 = elementValue1.value.value || elementValue1.value;
  9753. elementValue2 = elementValue2.value.value || elementValue2.value;
  9754. return elementValue1 === elementValue2;
  9755. }
  9756. elementValue1 = elementValue1.value;
  9757. elementValue2 = elementValue2.value;
  9758. if (elementValue1 instanceof tree.Selector) {
  9759. if (!(elementValue2 instanceof tree.Selector) || elementValue1.elements.length !== elementValue2.elements.length) {
  9760. return false;
  9761. }
  9762. for (var i = 0; i < elementValue1.elements.length; i++) {
  9763. if (elementValue1.elements[i].combinator.value !== elementValue2.elements[i].combinator.value) {
  9764. if (i !== 0 || (elementValue1.elements[i].combinator.value || ' ') !== (elementValue2.elements[i].combinator.value || ' ')) {
  9765. return false;
  9766. }
  9767. }
  9768. if (!this.isElementValuesEqual(elementValue1.elements[i].value, elementValue2.elements[i].value)) {
  9769. return false;
  9770. }
  9771. }
  9772. return true;
  9773. }
  9774. return false;
  9775. },
  9776. extendSelector:function (matches, selectorPath, replacementSelector, isVisible) {
  9777. // for a set of matches, replace each match with the replacement selector
  9778. var currentSelectorPathIndex = 0,
  9779. currentSelectorPathElementIndex = 0,
  9780. path = [],
  9781. matchIndex,
  9782. selector,
  9783. firstElement,
  9784. match,
  9785. newElements;
  9786. for (matchIndex = 0; matchIndex < matches.length; matchIndex++) {
  9787. match = matches[matchIndex];
  9788. selector = selectorPath[match.pathIndex];
  9789. firstElement = new tree.Element(
  9790. match.initialCombinator,
  9791. replacementSelector.elements[0].value,
  9792. replacementSelector.elements[0].isVariable,
  9793. replacementSelector.elements[0].getIndex(),
  9794. replacementSelector.elements[0].fileInfo()
  9795. );
  9796. if (match.pathIndex > currentSelectorPathIndex && currentSelectorPathElementIndex > 0) {
  9797. path[path.length - 1].elements = path[path.length - 1]
  9798. .elements.concat(selectorPath[currentSelectorPathIndex].elements.slice(currentSelectorPathElementIndex));
  9799. currentSelectorPathElementIndex = 0;
  9800. currentSelectorPathIndex++;
  9801. }
  9802. newElements = selector.elements
  9803. .slice(currentSelectorPathElementIndex, match.index)
  9804. .concat([firstElement])
  9805. .concat(replacementSelector.elements.slice(1));
  9806. if (currentSelectorPathIndex === match.pathIndex && matchIndex > 0) {
  9807. path[path.length - 1].elements =
  9808. path[path.length - 1].elements.concat(newElements);
  9809. } else {
  9810. path = path.concat(selectorPath.slice(currentSelectorPathIndex, match.pathIndex));
  9811. path.push(new tree.Selector(
  9812. newElements
  9813. ));
  9814. }
  9815. currentSelectorPathIndex = match.endPathIndex;
  9816. currentSelectorPathElementIndex = match.endPathElementIndex;
  9817. if (currentSelectorPathElementIndex >= selectorPath[currentSelectorPathIndex].elements.length) {
  9818. currentSelectorPathElementIndex = 0;
  9819. currentSelectorPathIndex++;
  9820. }
  9821. }
  9822. if (currentSelectorPathIndex < selectorPath.length && currentSelectorPathElementIndex > 0) {
  9823. path[path.length - 1].elements = path[path.length - 1]
  9824. .elements.concat(selectorPath[currentSelectorPathIndex].elements.slice(currentSelectorPathElementIndex));
  9825. currentSelectorPathIndex++;
  9826. }
  9827. path = path.concat(selectorPath.slice(currentSelectorPathIndex, selectorPath.length));
  9828. path = path.map(function (currentValue) {
  9829. // we can re-use elements here, because the visibility property matters only for selectors
  9830. var derived = currentValue.createDerived(currentValue.elements);
  9831. if (isVisible) {
  9832. derived.ensureVisibility();
  9833. } else {
  9834. derived.ensureInvisibility();
  9835. }
  9836. return derived;
  9837. });
  9838. return path;
  9839. },
  9840. visitMedia: function (mediaNode, visitArgs) {
  9841. var newAllExtends = mediaNode.allExtends.concat(this.allExtendsStack[this.allExtendsStack.length - 1]);
  9842. newAllExtends = newAllExtends.concat(this.doExtendChaining(newAllExtends, mediaNode.allExtends));
  9843. this.allExtendsStack.push(newAllExtends);
  9844. },
  9845. visitMediaOut: function (mediaNode) {
  9846. var lastIndex = this.allExtendsStack.length - 1;
  9847. this.allExtendsStack.length = lastIndex;
  9848. },
  9849. visitAtRule: function (atRuleNode, visitArgs) {
  9850. var newAllExtends = atRuleNode.allExtends.concat(this.allExtendsStack[this.allExtendsStack.length - 1]);
  9851. newAllExtends = newAllExtends.concat(this.doExtendChaining(newAllExtends, atRuleNode.allExtends));
  9852. this.allExtendsStack.push(newAllExtends);
  9853. },
  9854. visitAtRuleOut: function (atRuleNode) {
  9855. var lastIndex = this.allExtendsStack.length - 1;
  9856. this.allExtendsStack.length = lastIndex;
  9857. }
  9858. };
  9859. module.exports = ProcessExtendsVisitor;
  9860. },{"../logger":39,"../tree":67,"../utils":89,"./visitor":97}],91:[function(require,module,exports){
  9861. function ImportSequencer(onSequencerEmpty) {
  9862. this.imports = [];
  9863. this.variableImports = [];
  9864. this._onSequencerEmpty = onSequencerEmpty;
  9865. this._currentDepth = 0;
  9866. }
  9867. ImportSequencer.prototype.addImport = function(callback) {
  9868. var importSequencer = this,
  9869. importItem = {
  9870. callback: callback,
  9871. args: null,
  9872. isReady: false
  9873. };
  9874. this.imports.push(importItem);
  9875. return function() {
  9876. importItem.args = Array.prototype.slice.call(arguments, 0);
  9877. importItem.isReady = true;
  9878. importSequencer.tryRun();
  9879. };
  9880. };
  9881. ImportSequencer.prototype.addVariableImport = function(callback) {
  9882. this.variableImports.push(callback);
  9883. };
  9884. ImportSequencer.prototype.tryRun = function() {
  9885. this._currentDepth++;
  9886. try {
  9887. while (true) {
  9888. while (this.imports.length > 0) {
  9889. var importItem = this.imports[0];
  9890. if (!importItem.isReady) {
  9891. return;
  9892. }
  9893. this.imports = this.imports.slice(1);
  9894. importItem.callback.apply(null, importItem.args);
  9895. }
  9896. if (this.variableImports.length === 0) {
  9897. break;
  9898. }
  9899. var variableImport = this.variableImports[0];
  9900. this.variableImports = this.variableImports.slice(1);
  9901. variableImport();
  9902. }
  9903. } finally {
  9904. this._currentDepth--;
  9905. }
  9906. if (this._currentDepth === 0 && this._onSequencerEmpty) {
  9907. this._onSequencerEmpty();
  9908. }
  9909. };
  9910. module.exports = ImportSequencer;
  9911. },{}],92:[function(require,module,exports){
  9912. var contexts = require('../contexts'),
  9913. Visitor = require('./visitor'),
  9914. ImportSequencer = require('./import-sequencer'),
  9915. utils = require('../utils');
  9916. var ImportVisitor = function(importer, finish) {
  9917. this._visitor = new Visitor(this);
  9918. this._importer = importer;
  9919. this._finish = finish;
  9920. this.context = new contexts.Eval();
  9921. this.importCount = 0;
  9922. this.onceFileDetectionMap = {};
  9923. this.recursionDetector = {};
  9924. this._sequencer = new ImportSequencer(this._onSequencerEmpty.bind(this));
  9925. };
  9926. ImportVisitor.prototype = {
  9927. isReplacing: false,
  9928. run: function (root) {
  9929. try {
  9930. // process the contents
  9931. this._visitor.visit(root);
  9932. }
  9933. catch (e) {
  9934. this.error = e;
  9935. }
  9936. this.isFinished = true;
  9937. this._sequencer.tryRun();
  9938. },
  9939. _onSequencerEmpty: function() {
  9940. if (!this.isFinished) {
  9941. return;
  9942. }
  9943. this._finish(this.error);
  9944. },
  9945. visitImport: function (importNode, visitArgs) {
  9946. var inlineCSS = importNode.options.inline;
  9947. if (!importNode.css || inlineCSS) {
  9948. var context = new contexts.Eval(this.context, utils.copyArray(this.context.frames));
  9949. var importParent = context.frames[0];
  9950. this.importCount++;
  9951. if (importNode.isVariableImport()) {
  9952. this._sequencer.addVariableImport(this.processImportNode.bind(this, importNode, context, importParent));
  9953. } else {
  9954. this.processImportNode(importNode, context, importParent);
  9955. }
  9956. }
  9957. visitArgs.visitDeeper = false;
  9958. },
  9959. processImportNode: function(importNode, context, importParent) {
  9960. var evaldImportNode,
  9961. inlineCSS = importNode.options.inline;
  9962. try {
  9963. evaldImportNode = importNode.evalForImport(context);
  9964. } catch (e) {
  9965. if (!e.filename) { e.index = importNode.getIndex(); e.filename = importNode.fileInfo().filename; }
  9966. // attempt to eval properly and treat as css
  9967. importNode.css = true;
  9968. // if that fails, this error will be thrown
  9969. importNode.error = e;
  9970. }
  9971. if (evaldImportNode && (!evaldImportNode.css || inlineCSS)) {
  9972. if (evaldImportNode.options.multiple) {
  9973. context.importMultiple = true;
  9974. }
  9975. // try appending if we haven't determined if it is css or not
  9976. var tryAppendLessExtension = evaldImportNode.css === undefined;
  9977. for (var i = 0; i < importParent.rules.length; i++) {
  9978. if (importParent.rules[i] === importNode) {
  9979. importParent.rules[i] = evaldImportNode;
  9980. break;
  9981. }
  9982. }
  9983. var onImported = this.onImported.bind(this, evaldImportNode, context),
  9984. sequencedOnImported = this._sequencer.addImport(onImported);
  9985. this._importer.push(evaldImportNode.getPath(), tryAppendLessExtension, evaldImportNode.fileInfo(),
  9986. evaldImportNode.options, sequencedOnImported);
  9987. } else {
  9988. this.importCount--;
  9989. if (this.isFinished) {
  9990. this._sequencer.tryRun();
  9991. }
  9992. }
  9993. },
  9994. onImported: function (importNode, context, e, root, importedAtRoot, fullPath) {
  9995. if (e) {
  9996. if (!e.filename) {
  9997. e.index = importNode.getIndex(); e.filename = importNode.fileInfo().filename;
  9998. }
  9999. this.error = e;
  10000. }
  10001. var importVisitor = this,
  10002. inlineCSS = importNode.options.inline,
  10003. isPlugin = importNode.options.isPlugin,
  10004. isOptional = importNode.options.optional,
  10005. duplicateImport = importedAtRoot || fullPath in importVisitor.recursionDetector;
  10006. if (!context.importMultiple) {
  10007. if (duplicateImport) {
  10008. importNode.skip = true;
  10009. } else {
  10010. importNode.skip = function() {
  10011. if (fullPath in importVisitor.onceFileDetectionMap) {
  10012. return true;
  10013. }
  10014. importVisitor.onceFileDetectionMap[fullPath] = true;
  10015. return false;
  10016. };
  10017. }
  10018. }
  10019. if (!fullPath && isOptional) {
  10020. importNode.skip = true;
  10021. }
  10022. if (root) {
  10023. importNode.root = root;
  10024. importNode.importedFilename = fullPath;
  10025. if (!inlineCSS && !isPlugin && (context.importMultiple || !duplicateImport)) {
  10026. importVisitor.recursionDetector[fullPath] = true;
  10027. var oldContext = this.context;
  10028. this.context = context;
  10029. try {
  10030. this._visitor.visit(root);
  10031. } catch (e) {
  10032. this.error = e;
  10033. }
  10034. this.context = oldContext;
  10035. }
  10036. }
  10037. importVisitor.importCount--;
  10038. if (importVisitor.isFinished) {
  10039. importVisitor._sequencer.tryRun();
  10040. }
  10041. },
  10042. visitDeclaration: function (declNode, visitArgs) {
  10043. if (declNode.value.type === 'DetachedRuleset') {
  10044. this.context.frames.unshift(declNode);
  10045. } else {
  10046. visitArgs.visitDeeper = false;
  10047. }
  10048. },
  10049. visitDeclarationOut: function(declNode) {
  10050. if (declNode.value.type === 'DetachedRuleset') {
  10051. this.context.frames.shift();
  10052. }
  10053. },
  10054. visitAtRule: function (atRuleNode, visitArgs) {
  10055. this.context.frames.unshift(atRuleNode);
  10056. },
  10057. visitAtRuleOut: function (atRuleNode) {
  10058. this.context.frames.shift();
  10059. },
  10060. visitMixinDefinition: function (mixinDefinitionNode, visitArgs) {
  10061. this.context.frames.unshift(mixinDefinitionNode);
  10062. },
  10063. visitMixinDefinitionOut: function (mixinDefinitionNode) {
  10064. this.context.frames.shift();
  10065. },
  10066. visitRuleset: function (rulesetNode, visitArgs) {
  10067. this.context.frames.unshift(rulesetNode);
  10068. },
  10069. visitRulesetOut: function (rulesetNode) {
  10070. this.context.frames.shift();
  10071. },
  10072. visitMedia: function (mediaNode, visitArgs) {
  10073. this.context.frames.unshift(mediaNode.rules[0]);
  10074. },
  10075. visitMediaOut: function (mediaNode) {
  10076. this.context.frames.shift();
  10077. }
  10078. };
  10079. module.exports = ImportVisitor;
  10080. },{"../contexts":13,"../utils":89,"./import-sequencer":91,"./visitor":97}],93:[function(require,module,exports){
  10081. var visitors = {
  10082. Visitor: require('./visitor'),
  10083. ImportVisitor: require('./import-visitor'),
  10084. MarkVisibleSelectorsVisitor: require('./set-tree-visibility-visitor'),
  10085. ExtendVisitor: require('./extend-visitor'),
  10086. JoinSelectorVisitor: require('./join-selector-visitor'),
  10087. ToCSSVisitor: require('./to-css-visitor')
  10088. };
  10089. module.exports = visitors;
  10090. },{"./extend-visitor":90,"./import-visitor":92,"./join-selector-visitor":94,"./set-tree-visibility-visitor":95,"./to-css-visitor":96,"./visitor":97}],94:[function(require,module,exports){
  10091. var Visitor = require('./visitor');
  10092. var JoinSelectorVisitor = function() {
  10093. this.contexts = [[]];
  10094. this._visitor = new Visitor(this);
  10095. };
  10096. JoinSelectorVisitor.prototype = {
  10097. run: function (root) {
  10098. return this._visitor.visit(root);
  10099. },
  10100. visitDeclaration: function (declNode, visitArgs) {
  10101. visitArgs.visitDeeper = false;
  10102. },
  10103. visitMixinDefinition: function (mixinDefinitionNode, visitArgs) {
  10104. visitArgs.visitDeeper = false;
  10105. },
  10106. visitRuleset: function (rulesetNode, visitArgs) {
  10107. var context = this.contexts[this.contexts.length - 1],
  10108. paths = [], selectors;
  10109. this.contexts.push(paths);
  10110. if (!rulesetNode.root) {
  10111. selectors = rulesetNode.selectors;
  10112. if (selectors) {
  10113. selectors = selectors.filter(function(selector) { return selector.getIsOutput(); });
  10114. rulesetNode.selectors = selectors.length ? selectors : (selectors = null);
  10115. if (selectors) { rulesetNode.joinSelectors(paths, context, selectors); }
  10116. }
  10117. if (!selectors) { rulesetNode.rules = null; }
  10118. rulesetNode.paths = paths;
  10119. }
  10120. },
  10121. visitRulesetOut: function (rulesetNode) {
  10122. this.contexts.length = this.contexts.length - 1;
  10123. },
  10124. visitMedia: function (mediaNode, visitArgs) {
  10125. var context = this.contexts[this.contexts.length - 1];
  10126. mediaNode.rules[0].root = (context.length === 0 || context[0].multiMedia);
  10127. },
  10128. visitAtRule: function (atRuleNode, visitArgs) {
  10129. var context = this.contexts[this.contexts.length - 1];
  10130. if (atRuleNode.rules && atRuleNode.rules.length) {
  10131. atRuleNode.rules[0].root = (atRuleNode.isRooted || context.length === 0 || null);
  10132. }
  10133. }
  10134. };
  10135. module.exports = JoinSelectorVisitor;
  10136. },{"./visitor":97}],95:[function(require,module,exports){
  10137. var SetTreeVisibilityVisitor = function(visible) {
  10138. this.visible = visible;
  10139. };
  10140. SetTreeVisibilityVisitor.prototype.run = function(root) {
  10141. this.visit(root);
  10142. };
  10143. SetTreeVisibilityVisitor.prototype.visitArray = function(nodes) {
  10144. if (!nodes) {
  10145. return nodes;
  10146. }
  10147. var cnt = nodes.length, i;
  10148. for (i = 0; i < cnt; i++) {
  10149. this.visit(nodes[i]);
  10150. }
  10151. return nodes;
  10152. };
  10153. SetTreeVisibilityVisitor.prototype.visit = function(node) {
  10154. if (!node) {
  10155. return node;
  10156. }
  10157. if (node.constructor === Array) {
  10158. return this.visitArray(node);
  10159. }
  10160. if (!node.blocksVisibility || node.blocksVisibility()) {
  10161. return node;
  10162. }
  10163. if (this.visible) {
  10164. node.ensureVisibility();
  10165. } else {
  10166. node.ensureInvisibility();
  10167. }
  10168. node.accept(this);
  10169. return node;
  10170. };
  10171. module.exports = SetTreeVisibilityVisitor;
  10172. },{}],96:[function(require,module,exports){
  10173. var tree = require('../tree'),
  10174. Visitor = require('./visitor');
  10175. var CSSVisitorUtils = function(context) {
  10176. this._visitor = new Visitor(this);
  10177. this._context = context;
  10178. };
  10179. CSSVisitorUtils.prototype = {
  10180. containsSilentNonBlockedChild: function(bodyRules) {
  10181. var rule;
  10182. if (!bodyRules) {
  10183. return false;
  10184. }
  10185. for (var r = 0; r < bodyRules.length; r++) {
  10186. rule = bodyRules[r];
  10187. if (rule.isSilent && rule.isSilent(this._context) && !rule.blocksVisibility()) {
  10188. // the atrule contains something that was referenced (likely by extend)
  10189. // therefore it needs to be shown in output too
  10190. return true;
  10191. }
  10192. }
  10193. return false;
  10194. },
  10195. keepOnlyVisibleChilds: function(owner) {
  10196. if (owner && owner.rules) {
  10197. owner.rules = owner.rules.filter(function(thing) {
  10198. return thing.isVisible();
  10199. });
  10200. }
  10201. },
  10202. isEmpty: function(owner) {
  10203. return (owner && owner.rules)
  10204. ? (owner.rules.length === 0) : true;
  10205. },
  10206. hasVisibleSelector: function(rulesetNode) {
  10207. return (rulesetNode && rulesetNode.paths)
  10208. ? (rulesetNode.paths.length > 0) : false;
  10209. },
  10210. resolveVisibility: function (node, originalRules) {
  10211. if (!node.blocksVisibility()) {
  10212. if (this.isEmpty(node) && !this.containsSilentNonBlockedChild(originalRules)) {
  10213. return ;
  10214. }
  10215. return node;
  10216. }
  10217. var compiledRulesBody = node.rules[0];
  10218. this.keepOnlyVisibleChilds(compiledRulesBody);
  10219. if (this.isEmpty(compiledRulesBody)) {
  10220. return ;
  10221. }
  10222. node.ensureVisibility();
  10223. node.removeVisibilityBlock();
  10224. return node;
  10225. },
  10226. isVisibleRuleset: function(rulesetNode) {
  10227. if (rulesetNode.firstRoot) {
  10228. return true;
  10229. }
  10230. if (this.isEmpty(rulesetNode)) {
  10231. return false;
  10232. }
  10233. if (!rulesetNode.root && !this.hasVisibleSelector(rulesetNode)) {
  10234. return false;
  10235. }
  10236. return true;
  10237. }
  10238. };
  10239. var ToCSSVisitor = function(context) {
  10240. this._visitor = new Visitor(this);
  10241. this._context = context;
  10242. this.utils = new CSSVisitorUtils(context);
  10243. };
  10244. ToCSSVisitor.prototype = {
  10245. isReplacing: true,
  10246. run: function (root) {
  10247. return this._visitor.visit(root);
  10248. },
  10249. visitDeclaration: function (declNode, visitArgs) {
  10250. if (declNode.blocksVisibility() || declNode.variable) {
  10251. return;
  10252. }
  10253. return declNode;
  10254. },
  10255. visitMixinDefinition: function (mixinNode, visitArgs) {
  10256. // mixin definitions do not get eval'd - this means they keep state
  10257. // so we have to clear that state here so it isn't used if toCSS is called twice
  10258. mixinNode.frames = [];
  10259. },
  10260. visitExtend: function (extendNode, visitArgs) {
  10261. },
  10262. visitComment: function (commentNode, visitArgs) {
  10263. if (commentNode.blocksVisibility() || commentNode.isSilent(this._context)) {
  10264. return;
  10265. }
  10266. return commentNode;
  10267. },
  10268. visitMedia: function(mediaNode, visitArgs) {
  10269. var originalRules = mediaNode.rules[0].rules;
  10270. mediaNode.accept(this._visitor);
  10271. visitArgs.visitDeeper = false;
  10272. return this.utils.resolveVisibility(mediaNode, originalRules);
  10273. },
  10274. visitImport: function (importNode, visitArgs) {
  10275. if (importNode.blocksVisibility()) {
  10276. return ;
  10277. }
  10278. return importNode;
  10279. },
  10280. visitAtRule: function(atRuleNode, visitArgs) {
  10281. if (atRuleNode.rules && atRuleNode.rules.length) {
  10282. return this.visitAtRuleWithBody(atRuleNode, visitArgs);
  10283. } else {
  10284. return this.visitAtRuleWithoutBody(atRuleNode, visitArgs);
  10285. }
  10286. },
  10287. visitAnonymous: function(anonymousNode, visitArgs) {
  10288. if (!anonymousNode.blocksVisibility()) {
  10289. anonymousNode.accept(this._visitor);
  10290. return anonymousNode;
  10291. }
  10292. },
  10293. visitAtRuleWithBody: function(atRuleNode, visitArgs) {
  10294. // if there is only one nested ruleset and that one has no path, then it is
  10295. // just fake ruleset
  10296. function hasFakeRuleset(atRuleNode) {
  10297. var bodyRules = atRuleNode.rules;
  10298. return bodyRules.length === 1 && (!bodyRules[0].paths || bodyRules[0].paths.length === 0);
  10299. }
  10300. function getBodyRules(atRuleNode) {
  10301. var nodeRules = atRuleNode.rules;
  10302. if (hasFakeRuleset(atRuleNode)) {
  10303. return nodeRules[0].rules;
  10304. }
  10305. return nodeRules;
  10306. }
  10307. // it is still true that it is only one ruleset in array
  10308. // this is last such moment
  10309. // process childs
  10310. var originalRules = getBodyRules(atRuleNode);
  10311. atRuleNode.accept(this._visitor);
  10312. visitArgs.visitDeeper = false;
  10313. if (!this.utils.isEmpty(atRuleNode)) {
  10314. this._mergeRules(atRuleNode.rules[0].rules);
  10315. }
  10316. return this.utils.resolveVisibility(atRuleNode, originalRules);
  10317. },
  10318. visitAtRuleWithoutBody: function(atRuleNode, visitArgs) {
  10319. if (atRuleNode.blocksVisibility()) {
  10320. return;
  10321. }
  10322. if (atRuleNode.name === '@charset') {
  10323. // Only output the debug info together with subsequent @charset definitions
  10324. // a comment (or @media statement) before the actual @charset atrule would
  10325. // be considered illegal css as it has to be on the first line
  10326. if (this.charset) {
  10327. if (atRuleNode.debugInfo) {
  10328. var comment = new tree.Comment('/* ' + atRuleNode.toCSS(this._context).replace(/\n/g, '') + ' */\n');
  10329. comment.debugInfo = atRuleNode.debugInfo;
  10330. return this._visitor.visit(comment);
  10331. }
  10332. return;
  10333. }
  10334. this.charset = true;
  10335. }
  10336. return atRuleNode;
  10337. },
  10338. checkValidNodes: function(rules, isRoot) {
  10339. if (!rules) {
  10340. return;
  10341. }
  10342. for (var i = 0; i < rules.length; i++) {
  10343. var ruleNode = rules[i];
  10344. if (isRoot && ruleNode instanceof tree.Declaration && !ruleNode.variable) {
  10345. throw { message: 'Properties must be inside selector blocks. They cannot be in the root',
  10346. index: ruleNode.getIndex(), filename: ruleNode.fileInfo() && ruleNode.fileInfo().filename};
  10347. }
  10348. if (ruleNode instanceof tree.Call) {
  10349. throw { message: 'Function \'' + ruleNode.name + '\' is undefined',
  10350. index: ruleNode.getIndex(), filename: ruleNode.fileInfo() && ruleNode.fileInfo().filename};
  10351. }
  10352. if (ruleNode.type && !ruleNode.allowRoot) {
  10353. throw { message: ruleNode.type + ' node returned by a function is not valid here',
  10354. index: ruleNode.getIndex(), filename: ruleNode.fileInfo() && ruleNode.fileInfo().filename};
  10355. }
  10356. }
  10357. },
  10358. visitRuleset: function (rulesetNode, visitArgs) {
  10359. // at this point rulesets are nested into each other
  10360. var rule, rulesets = [];
  10361. this.checkValidNodes(rulesetNode.rules, rulesetNode.firstRoot);
  10362. if (!rulesetNode.root) {
  10363. // remove invisible paths
  10364. this._compileRulesetPaths(rulesetNode);
  10365. // remove rulesets from this ruleset body and compile them separately
  10366. var nodeRules = rulesetNode.rules, nodeRuleCnt = nodeRules ? nodeRules.length : 0;
  10367. for (var i = 0; i < nodeRuleCnt; ) {
  10368. rule = nodeRules[i];
  10369. if (rule && rule.rules) {
  10370. // visit because we are moving them out from being a child
  10371. rulesets.push(this._visitor.visit(rule));
  10372. nodeRules.splice(i, 1);
  10373. nodeRuleCnt--;
  10374. continue;
  10375. }
  10376. i++;
  10377. }
  10378. // accept the visitor to remove rules and refactor itself
  10379. // then we can decide nogw whether we want it or not
  10380. // compile body
  10381. if (nodeRuleCnt > 0) {
  10382. rulesetNode.accept(this._visitor);
  10383. } else {
  10384. rulesetNode.rules = null;
  10385. }
  10386. visitArgs.visitDeeper = false;
  10387. } else { // if (! rulesetNode.root) {
  10388. rulesetNode.accept(this._visitor);
  10389. visitArgs.visitDeeper = false;
  10390. }
  10391. if (rulesetNode.rules) {
  10392. this._mergeRules(rulesetNode.rules);
  10393. this._removeDuplicateRules(rulesetNode.rules);
  10394. }
  10395. // now decide whether we keep the ruleset
  10396. if (this.utils.isVisibleRuleset(rulesetNode)) {
  10397. rulesetNode.ensureVisibility();
  10398. rulesets.splice(0, 0, rulesetNode);
  10399. }
  10400. if (rulesets.length === 1) {
  10401. return rulesets[0];
  10402. }
  10403. return rulesets;
  10404. },
  10405. _compileRulesetPaths: function(rulesetNode) {
  10406. if (rulesetNode.paths) {
  10407. rulesetNode.paths = rulesetNode.paths
  10408. .filter(function(p) {
  10409. var i;
  10410. if (p[0].elements[0].combinator.value === ' ') {
  10411. p[0].elements[0].combinator = new(tree.Combinator)('');
  10412. }
  10413. for (i = 0; i < p.length; i++) {
  10414. if (p[i].isVisible() && p[i].getIsOutput()) {
  10415. return true;
  10416. }
  10417. }
  10418. return false;
  10419. });
  10420. }
  10421. },
  10422. _removeDuplicateRules: function(rules) {
  10423. if (!rules) { return; }
  10424. // remove duplicates
  10425. var ruleCache = {},
  10426. ruleList, rule, i;
  10427. for (i = rules.length - 1; i >= 0 ; i--) {
  10428. rule = rules[i];
  10429. if (rule instanceof tree.Declaration) {
  10430. if (!ruleCache[rule.name]) {
  10431. ruleCache[rule.name] = rule;
  10432. } else {
  10433. ruleList = ruleCache[rule.name];
  10434. if (ruleList instanceof tree.Declaration) {
  10435. ruleList = ruleCache[rule.name] = [ruleCache[rule.name].toCSS(this._context)];
  10436. }
  10437. var ruleCSS = rule.toCSS(this._context);
  10438. if (ruleList.indexOf(ruleCSS) !== -1) {
  10439. rules.splice(i, 1);
  10440. } else {
  10441. ruleList.push(ruleCSS);
  10442. }
  10443. }
  10444. }
  10445. }
  10446. },
  10447. _mergeRules: function(rules) {
  10448. if (!rules) {
  10449. return;
  10450. }
  10451. var groups = {},
  10452. groupsArr = [];
  10453. for (var i = 0; i < rules.length; i++) {
  10454. var rule = rules[i];
  10455. if (rule.merge) {
  10456. var key = rule.name;
  10457. groups[key] ? rules.splice(i--, 1) :
  10458. groupsArr.push(groups[key] = []);
  10459. groups[key].push(rule);
  10460. }
  10461. }
  10462. groupsArr.forEach(function(group) {
  10463. if (group.length > 0) {
  10464. var result = group[0],
  10465. space = [],
  10466. comma = [new tree.Expression(space)];
  10467. group.forEach(function(rule) {
  10468. if ((rule.merge === '+') && (space.length > 0)) {
  10469. comma.push(new tree.Expression(space = []));
  10470. }
  10471. space.push(rule.value);
  10472. result.important = result.important || rule.important;
  10473. });
  10474. result.value = new tree.Value(comma);
  10475. }
  10476. });
  10477. }
  10478. };
  10479. module.exports = ToCSSVisitor;
  10480. },{"../tree":67,"./visitor":97}],97:[function(require,module,exports){
  10481. var tree = require('../tree');
  10482. var _visitArgs = { visitDeeper: true },
  10483. _hasIndexed = false;
  10484. function _noop(node) {
  10485. return node;
  10486. }
  10487. function indexNodeTypes(parent, ticker) {
  10488. // add .typeIndex to tree node types for lookup table
  10489. var key, child;
  10490. for (key in parent) {
  10491. /* eslint guard-for-in: 0 */
  10492. child = parent[key];
  10493. switch (typeof child) {
  10494. case 'function':
  10495. // ignore bound functions directly on tree which do not have a prototype
  10496. // or aren't nodes
  10497. if (child.prototype && child.prototype.type) {
  10498. child.prototype.typeIndex = ticker++;
  10499. }
  10500. break;
  10501. case 'object':
  10502. ticker = indexNodeTypes(child, ticker);
  10503. break;
  10504. }
  10505. }
  10506. return ticker;
  10507. }
  10508. var Visitor = function(implementation) {
  10509. this._implementation = implementation;
  10510. this._visitInCache = {};
  10511. this._visitOutCache = {};
  10512. if (!_hasIndexed) {
  10513. indexNodeTypes(tree, 1);
  10514. _hasIndexed = true;
  10515. }
  10516. };
  10517. Visitor.prototype = {
  10518. visit: function(node) {
  10519. if (!node) {
  10520. return node;
  10521. }
  10522. var nodeTypeIndex = node.typeIndex;
  10523. if (!nodeTypeIndex) {
  10524. // MixinCall args aren't a node type?
  10525. if (node.value && node.value.typeIndex) {
  10526. this.visit(node.value);
  10527. }
  10528. return node;
  10529. }
  10530. var impl = this._implementation,
  10531. func = this._visitInCache[nodeTypeIndex],
  10532. funcOut = this._visitOutCache[nodeTypeIndex],
  10533. visitArgs = _visitArgs,
  10534. fnName;
  10535. visitArgs.visitDeeper = true;
  10536. if (!func) {
  10537. fnName = 'visit' + node.type;
  10538. func = impl[fnName] || _noop;
  10539. funcOut = impl[fnName + 'Out'] || _noop;
  10540. this._visitInCache[nodeTypeIndex] = func;
  10541. this._visitOutCache[nodeTypeIndex] = funcOut;
  10542. }
  10543. if (func !== _noop) {
  10544. var newNode = func.call(impl, node, visitArgs);
  10545. if (node && impl.isReplacing) {
  10546. node = newNode;
  10547. }
  10548. }
  10549. if (visitArgs.visitDeeper && node && node.accept) {
  10550. node.accept(this);
  10551. }
  10552. if (funcOut != _noop) {
  10553. funcOut.call(impl, node);
  10554. }
  10555. return node;
  10556. },
  10557. visitArray: function(nodes, nonReplacing) {
  10558. if (!nodes) {
  10559. return nodes;
  10560. }
  10561. var cnt = nodes.length, i;
  10562. // Non-replacing
  10563. if (nonReplacing || !this._implementation.isReplacing) {
  10564. for (i = 0; i < cnt; i++) {
  10565. this.visit(nodes[i]);
  10566. }
  10567. return nodes;
  10568. }
  10569. // Replacing
  10570. var out = [];
  10571. for (i = 0; i < cnt; i++) {
  10572. var evald = this.visit(nodes[i]);
  10573. if (evald === undefined) { continue; }
  10574. if (!evald.splice) {
  10575. out.push(evald);
  10576. } else if (evald.length) {
  10577. this.flatten(evald, out);
  10578. }
  10579. }
  10580. return out;
  10581. },
  10582. flatten: function(arr, out) {
  10583. if (!out) {
  10584. out = [];
  10585. }
  10586. var cnt, i, item,
  10587. nestedCnt, j, nestedItem;
  10588. for (i = 0, cnt = arr.length; i < cnt; i++) {
  10589. item = arr[i];
  10590. if (item === undefined) {
  10591. continue;
  10592. }
  10593. if (!item.splice) {
  10594. out.push(item);
  10595. continue;
  10596. }
  10597. for (j = 0, nestedCnt = item.length; j < nestedCnt; j++) {
  10598. nestedItem = item[j];
  10599. if (nestedItem === undefined) {
  10600. continue;
  10601. }
  10602. if (!nestedItem.splice) {
  10603. out.push(nestedItem);
  10604. } else if (nestedItem.length) {
  10605. this.flatten(nestedItem, out);
  10606. }
  10607. }
  10608. }
  10609. return out;
  10610. }
  10611. };
  10612. module.exports = Visitor;
  10613. },{"../tree":67}],98:[function(require,module,exports){
  10614. "use strict";
  10615. // rawAsap provides everything we need except exception management.
  10616. var rawAsap = require("./raw");
  10617. // RawTasks are recycled to reduce GC churn.
  10618. var freeTasks = [];
  10619. // We queue errors to ensure they are thrown in right order (FIFO).
  10620. // Array-as-queue is good enough here, since we are just dealing with exceptions.
  10621. var pendingErrors = [];
  10622. var requestErrorThrow = rawAsap.makeRequestCallFromTimer(throwFirstError);
  10623. function throwFirstError() {
  10624. if (pendingErrors.length) {
  10625. throw pendingErrors.shift();
  10626. }
  10627. }
  10628. /**
  10629. * Calls a task as soon as possible after returning, in its own event, with priority
  10630. * over other events like animation, reflow, and repaint. An error thrown from an
  10631. * event will not interrupt, nor even substantially slow down the processing of
  10632. * other events, but will be rather postponed to a lower priority event.
  10633. * @param {{call}} task A callable object, typically a function that takes no
  10634. * arguments.
  10635. */
  10636. module.exports = asap;
  10637. function asap(task) {
  10638. var rawTask;
  10639. if (freeTasks.length) {
  10640. rawTask = freeTasks.pop();
  10641. } else {
  10642. rawTask = new RawTask();
  10643. }
  10644. rawTask.task = task;
  10645. rawAsap(rawTask);
  10646. }
  10647. // We wrap tasks with recyclable task objects. A task object implements
  10648. // `call`, just like a function.
  10649. function RawTask() {
  10650. this.task = null;
  10651. }
  10652. // The sole purpose of wrapping the task is to catch the exception and recycle
  10653. // the task object after its single use.
  10654. RawTask.prototype.call = function () {
  10655. try {
  10656. this.task.call();
  10657. } catch (error) {
  10658. if (asap.onerror) {
  10659. // This hook exists purely for testing purposes.
  10660. // Its name will be periodically randomized to break any code that
  10661. // depends on its existence.
  10662. asap.onerror(error);
  10663. } else {
  10664. // In a web browser, exceptions are not fatal. However, to avoid
  10665. // slowing down the queue of pending tasks, we rethrow the error in a
  10666. // lower priority turn.
  10667. pendingErrors.push(error);
  10668. requestErrorThrow();
  10669. }
  10670. } finally {
  10671. this.task = null;
  10672. freeTasks[freeTasks.length] = this;
  10673. }
  10674. };
  10675. },{"./raw":99}],99:[function(require,module,exports){
  10676. (function (global){
  10677. "use strict";
  10678. // Use the fastest means possible to execute a task in its own turn, with
  10679. // priority over other events including IO, animation, reflow, and redraw
  10680. // events in browsers.
  10681. //
  10682. // An exception thrown by a task will permanently interrupt the processing of
  10683. // subsequent tasks. The higher level `asap` function ensures that if an
  10684. // exception is thrown by a task, that the task queue will continue flushing as
  10685. // soon as possible, but if you use `rawAsap` directly, you are responsible to
  10686. // either ensure that no exceptions are thrown from your task, or to manually
  10687. // call `rawAsap.requestFlush` if an exception is thrown.
  10688. module.exports = rawAsap;
  10689. function rawAsap(task) {
  10690. if (!queue.length) {
  10691. requestFlush();
  10692. flushing = true;
  10693. }
  10694. // Equivalent to push, but avoids a function call.
  10695. queue[queue.length] = task;
  10696. }
  10697. var queue = [];
  10698. // Once a flush has been requested, no further calls to `requestFlush` are
  10699. // necessary until the next `flush` completes.
  10700. var flushing = false;
  10701. // `requestFlush` is an implementation-specific method that attempts to kick
  10702. // off a `flush` event as quickly as possible. `flush` will attempt to exhaust
  10703. // the event queue before yielding to the browser's own event loop.
  10704. var requestFlush;
  10705. // The position of the next task to execute in the task queue. This is
  10706. // preserved between calls to `flush` so that it can be resumed if
  10707. // a task throws an exception.
  10708. var index = 0;
  10709. // If a task schedules additional tasks recursively, the task queue can grow
  10710. // unbounded. To prevent memory exhaustion, the task queue will periodically
  10711. // truncate already-completed tasks.
  10712. var capacity = 1024;
  10713. // The flush function processes all tasks that have been scheduled with
  10714. // `rawAsap` unless and until one of those tasks throws an exception.
  10715. // If a task throws an exception, `flush` ensures that its state will remain
  10716. // consistent and will resume where it left off when called again.
  10717. // However, `flush` does not make any arrangements to be called again if an
  10718. // exception is thrown.
  10719. function flush() {
  10720. while (index < queue.length) {
  10721. var currentIndex = index;
  10722. // Advance the index before calling the task. This ensures that we will
  10723. // begin flushing on the next task the task throws an error.
  10724. index = index + 1;
  10725. queue[currentIndex].call();
  10726. // Prevent leaking memory for long chains of recursive calls to `asap`.
  10727. // If we call `asap` within tasks scheduled by `asap`, the queue will
  10728. // grow, but to avoid an O(n) walk for every task we execute, we don't
  10729. // shift tasks off the queue after they have been executed.
  10730. // Instead, we periodically shift 1024 tasks off the queue.
  10731. if (index > capacity) {
  10732. // Manually shift all values starting at the index back to the
  10733. // beginning of the queue.
  10734. for (var scan = 0, newLength = queue.length - index; scan < newLength; scan++) {
  10735. queue[scan] = queue[scan + index];
  10736. }
  10737. queue.length -= index;
  10738. index = 0;
  10739. }
  10740. }
  10741. queue.length = 0;
  10742. index = 0;
  10743. flushing = false;
  10744. }
  10745. // `requestFlush` is implemented using a strategy based on data collected from
  10746. // every available SauceLabs Selenium web driver worker at time of writing.
  10747. // https://docs.google.com/spreadsheets/d/1mG-5UYGup5qxGdEMWkhP6BWCz053NUb2E1QoUTU16uA/edit#gid=783724593
  10748. // Safari 6 and 6.1 for desktop, iPad, and iPhone are the only browsers that
  10749. // have WebKitMutationObserver but not un-prefixed MutationObserver.
  10750. // Must use `global` or `self` instead of `window` to work in both frames and web
  10751. // workers. `global` is a provision of Browserify, Mr, Mrs, or Mop.
  10752. /* globals self */
  10753. var scope = typeof global !== "undefined" ? global : self;
  10754. var BrowserMutationObserver = scope.MutationObserver || scope.WebKitMutationObserver;
  10755. // MutationObservers are desirable because they have high priority and work
  10756. // reliably everywhere they are implemented.
  10757. // They are implemented in all modern browsers.
  10758. //
  10759. // - Android 4-4.3
  10760. // - Chrome 26-34
  10761. // - Firefox 14-29
  10762. // - Internet Explorer 11
  10763. // - iPad Safari 6-7.1
  10764. // - iPhone Safari 7-7.1
  10765. // - Safari 6-7
  10766. if (typeof BrowserMutationObserver === "function") {
  10767. requestFlush = makeRequestCallFromMutationObserver(flush);
  10768. // MessageChannels are desirable because they give direct access to the HTML
  10769. // task queue, are implemented in Internet Explorer 10, Safari 5.0-1, and Opera
  10770. // 11-12, and in web workers in many engines.
  10771. // Although message channels yield to any queued rendering and IO tasks, they
  10772. // would be better than imposing the 4ms delay of timers.
  10773. // However, they do not work reliably in Internet Explorer or Safari.
  10774. // Internet Explorer 10 is the only browser that has setImmediate but does
  10775. // not have MutationObservers.
  10776. // Although setImmediate yields to the browser's renderer, it would be
  10777. // preferrable to falling back to setTimeout since it does not have
  10778. // the minimum 4ms penalty.
  10779. // Unfortunately there appears to be a bug in Internet Explorer 10 Mobile (and
  10780. // Desktop to a lesser extent) that renders both setImmediate and
  10781. // MessageChannel useless for the purposes of ASAP.
  10782. // https://github.com/kriskowal/q/issues/396
  10783. // Timers are implemented universally.
  10784. // We fall back to timers in workers in most engines, and in foreground
  10785. // contexts in the following browsers.
  10786. // However, note that even this simple case requires nuances to operate in a
  10787. // broad spectrum of browsers.
  10788. //
  10789. // - Firefox 3-13
  10790. // - Internet Explorer 6-9
  10791. // - iPad Safari 4.3
  10792. // - Lynx 2.8.7
  10793. } else {
  10794. requestFlush = makeRequestCallFromTimer(flush);
  10795. }
  10796. // `requestFlush` requests that the high priority event queue be flushed as
  10797. // soon as possible.
  10798. // This is useful to prevent an error thrown in a task from stalling the event
  10799. // queue if the exception handled by Node.js’s
  10800. // `process.on("uncaughtException")` or by a domain.
  10801. rawAsap.requestFlush = requestFlush;
  10802. // To request a high priority event, we induce a mutation observer by toggling
  10803. // the text of a text node between "1" and "-1".
  10804. function makeRequestCallFromMutationObserver(callback) {
  10805. var toggle = 1;
  10806. var observer = new BrowserMutationObserver(callback);
  10807. var node = document.createTextNode("");
  10808. observer.observe(node, {characterData: true});
  10809. return function requestCall() {
  10810. toggle = -toggle;
  10811. node.data = toggle;
  10812. };
  10813. }
  10814. // The message channel technique was discovered by Malte Ubl and was the
  10815. // original foundation for this library.
  10816. // http://www.nonblocking.io/2011/06/windownexttick.html
  10817. // Safari 6.0.5 (at least) intermittently fails to create message ports on a
  10818. // page's first load. Thankfully, this version of Safari supports
  10819. // MutationObservers, so we don't need to fall back in that case.
  10820. // function makeRequestCallFromMessageChannel(callback) {
  10821. // var channel = new MessageChannel();
  10822. // channel.port1.onmessage = callback;
  10823. // return function requestCall() {
  10824. // channel.port2.postMessage(0);
  10825. // };
  10826. // }
  10827. // For reasons explained above, we are also unable to use `setImmediate`
  10828. // under any circumstances.
  10829. // Even if we were, there is another bug in Internet Explorer 10.
  10830. // It is not sufficient to assign `setImmediate` to `requestFlush` because
  10831. // `setImmediate` must be called *by name* and therefore must be wrapped in a
  10832. // closure.
  10833. // Never forget.
  10834. // function makeRequestCallFromSetImmediate(callback) {
  10835. // return function requestCall() {
  10836. // setImmediate(callback);
  10837. // };
  10838. // }
  10839. // Safari 6.0 has a problem where timers will get lost while the user is
  10840. // scrolling. This problem does not impact ASAP because Safari 6.0 supports
  10841. // mutation observers, so that implementation is used instead.
  10842. // However, if we ever elect to use timers in Safari, the prevalent work-around
  10843. // is to add a scroll event listener that calls for a flush.
  10844. // `setTimeout` does not call the passed callback if the delay is less than
  10845. // approximately 7 in web workers in Firefox 8 through 18, and sometimes not
  10846. // even then.
  10847. function makeRequestCallFromTimer(callback) {
  10848. return function requestCall() {
  10849. // We dispatch a timeout with a specified delay of 0 for engines that
  10850. // can reliably accommodate that request. This will usually be snapped
  10851. // to a 4 milisecond delay, but once we're flushing, there's no delay
  10852. // between events.
  10853. var timeoutHandle = setTimeout(handleTimer, 0);
  10854. // However, since this timer gets frequently dropped in Firefox
  10855. // workers, we enlist an interval handle that will try to fire
  10856. // an event 20 times per second until it succeeds.
  10857. var intervalHandle = setInterval(handleTimer, 50);
  10858. function handleTimer() {
  10859. // Whichever timer succeeds will cancel both timers and
  10860. // execute the callback.
  10861. clearTimeout(timeoutHandle);
  10862. clearInterval(intervalHandle);
  10863. callback();
  10864. }
  10865. };
  10866. }
  10867. // This is for `asap.js` only.
  10868. // Its name will be periodically randomized to break any code that depends on
  10869. // its existence.
  10870. rawAsap.makeRequestCallFromTimer = makeRequestCallFromTimer;
  10871. // ASAP was originally a nextTick shim included in Q. This was factored out
  10872. // into this ASAP package. It was later adapted to RSVP which made further
  10873. // amendments. These decisions, particularly to marginalize MessageChannel and
  10874. // to capture the MutationObserver implementation in a closure, were integrated
  10875. // back into ASAP proper.
  10876. // https://github.com/tildeio/rsvp.js/blob/cddf7232546a9cf858524b75cde6f9edf72620a7/lib/rsvp/asap.js
  10877. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  10878. },{}],100:[function(require,module,exports){
  10879. 'use strict';
  10880. var asap = require('asap/raw');
  10881. function noop() {}
  10882. // States:
  10883. //
  10884. // 0 - pending
  10885. // 1 - fulfilled with _value
  10886. // 2 - rejected with _value
  10887. // 3 - adopted the state of another promise, _value
  10888. //
  10889. // once the state is no longer pending (0) it is immutable
  10890. // All `_` prefixed properties will be reduced to `_{random number}`
  10891. // at build time to obfuscate them and discourage their use.
  10892. // We don't use symbols or Object.defineProperty to fully hide them
  10893. // because the performance isn't good enough.
  10894. // to avoid using try/catch inside critical functions, we
  10895. // extract them to here.
  10896. var LAST_ERROR = null;
  10897. var IS_ERROR = {};
  10898. function getThen(obj) {
  10899. try {
  10900. return obj.then;
  10901. } catch (ex) {
  10902. LAST_ERROR = ex;
  10903. return IS_ERROR;
  10904. }
  10905. }
  10906. function tryCallOne(fn, a) {
  10907. try {
  10908. return fn(a);
  10909. } catch (ex) {
  10910. LAST_ERROR = ex;
  10911. return IS_ERROR;
  10912. }
  10913. }
  10914. function tryCallTwo(fn, a, b) {
  10915. try {
  10916. fn(a, b);
  10917. } catch (ex) {
  10918. LAST_ERROR = ex;
  10919. return IS_ERROR;
  10920. }
  10921. }
  10922. module.exports = Promise;
  10923. function Promise(fn) {
  10924. if (typeof this !== 'object') {
  10925. throw new TypeError('Promises must be constructed via new');
  10926. }
  10927. if (typeof fn !== 'function') {
  10928. throw new TypeError('Promise constructor\'s argument is not a function');
  10929. }
  10930. this._40 = 0;
  10931. this._65 = 0;
  10932. this._55 = null;
  10933. this._72 = null;
  10934. if (fn === noop) return;
  10935. doResolve(fn, this);
  10936. }
  10937. Promise._37 = null;
  10938. Promise._87 = null;
  10939. Promise._61 = noop;
  10940. Promise.prototype.then = function(onFulfilled, onRejected) {
  10941. if (this.constructor !== Promise) {
  10942. return safeThen(this, onFulfilled, onRejected);
  10943. }
  10944. var res = new Promise(noop);
  10945. handle(this, new Handler(onFulfilled, onRejected, res));
  10946. return res;
  10947. };
  10948. function safeThen(self, onFulfilled, onRejected) {
  10949. return new self.constructor(function (resolve, reject) {
  10950. var res = new Promise(noop);
  10951. res.then(resolve, reject);
  10952. handle(self, new Handler(onFulfilled, onRejected, res));
  10953. });
  10954. }
  10955. function handle(self, deferred) {
  10956. while (self._65 === 3) {
  10957. self = self._55;
  10958. }
  10959. if (Promise._37) {
  10960. Promise._37(self);
  10961. }
  10962. if (self._65 === 0) {
  10963. if (self._40 === 0) {
  10964. self._40 = 1;
  10965. self._72 = deferred;
  10966. return;
  10967. }
  10968. if (self._40 === 1) {
  10969. self._40 = 2;
  10970. self._72 = [self._72, deferred];
  10971. return;
  10972. }
  10973. self._72.push(deferred);
  10974. return;
  10975. }
  10976. handleResolved(self, deferred);
  10977. }
  10978. function handleResolved(self, deferred) {
  10979. asap(function() {
  10980. var cb = self._65 === 1 ? deferred.onFulfilled : deferred.onRejected;
  10981. if (cb === null) {
  10982. if (self._65 === 1) {
  10983. resolve(deferred.promise, self._55);
  10984. } else {
  10985. reject(deferred.promise, self._55);
  10986. }
  10987. return;
  10988. }
  10989. var ret = tryCallOne(cb, self._55);
  10990. if (ret === IS_ERROR) {
  10991. reject(deferred.promise, LAST_ERROR);
  10992. } else {
  10993. resolve(deferred.promise, ret);
  10994. }
  10995. });
  10996. }
  10997. function resolve(self, newValue) {
  10998. // Promise Resolution Procedure: https://github.com/promises-aplus/promises-spec#the-promise-resolution-procedure
  10999. if (newValue === self) {
  11000. return reject(
  11001. self,
  11002. new TypeError('A promise cannot be resolved with itself.')
  11003. );
  11004. }
  11005. if (
  11006. newValue &&
  11007. (typeof newValue === 'object' || typeof newValue === 'function')
  11008. ) {
  11009. var then = getThen(newValue);
  11010. if (then === IS_ERROR) {
  11011. return reject(self, LAST_ERROR);
  11012. }
  11013. if (
  11014. then === self.then &&
  11015. newValue instanceof Promise
  11016. ) {
  11017. self._65 = 3;
  11018. self._55 = newValue;
  11019. finale(self);
  11020. return;
  11021. } else if (typeof then === 'function') {
  11022. doResolve(then.bind(newValue), self);
  11023. return;
  11024. }
  11025. }
  11026. self._65 = 1;
  11027. self._55 = newValue;
  11028. finale(self);
  11029. }
  11030. function reject(self, newValue) {
  11031. self._65 = 2;
  11032. self._55 = newValue;
  11033. if (Promise._87) {
  11034. Promise._87(self, newValue);
  11035. }
  11036. finale(self);
  11037. }
  11038. function finale(self) {
  11039. if (self._40 === 1) {
  11040. handle(self, self._72);
  11041. self._72 = null;
  11042. }
  11043. if (self._40 === 2) {
  11044. for (var i = 0; i < self._72.length; i++) {
  11045. handle(self, self._72[i]);
  11046. }
  11047. self._72 = null;
  11048. }
  11049. }
  11050. function Handler(onFulfilled, onRejected, promise){
  11051. this.onFulfilled = typeof onFulfilled === 'function' ? onFulfilled : null;
  11052. this.onRejected = typeof onRejected === 'function' ? onRejected : null;
  11053. this.promise = promise;
  11054. }
  11055. /**
  11056. * Take a potentially misbehaving resolver function and make sure
  11057. * onFulfilled and onRejected are only called once.
  11058. *
  11059. * Makes no guarantees about asynchrony.
  11060. */
  11061. function doResolve(fn, promise) {
  11062. var done = false;
  11063. var res = tryCallTwo(fn, function (value) {
  11064. if (done) return;
  11065. done = true;
  11066. resolve(promise, value);
  11067. }, function (reason) {
  11068. if (done) return;
  11069. done = true;
  11070. reject(promise, reason);
  11071. });
  11072. if (!done && res === IS_ERROR) {
  11073. done = true;
  11074. reject(promise, LAST_ERROR);
  11075. }
  11076. }
  11077. },{"asap/raw":99}],101:[function(require,module,exports){
  11078. 'use strict';
  11079. //This file contains the ES6 extensions to the core Promises/A+ API
  11080. var Promise = require('./core.js');
  11081. module.exports = Promise;
  11082. /* Static Functions */
  11083. var TRUE = valuePromise(true);
  11084. var FALSE = valuePromise(false);
  11085. var NULL = valuePromise(null);
  11086. var UNDEFINED = valuePromise(undefined);
  11087. var ZERO = valuePromise(0);
  11088. var EMPTYSTRING = valuePromise('');
  11089. function valuePromise(value) {
  11090. var p = new Promise(Promise._61);
  11091. p._65 = 1;
  11092. p._55 = value;
  11093. return p;
  11094. }
  11095. Promise.resolve = function (value) {
  11096. if (value instanceof Promise) return value;
  11097. if (value === null) return NULL;
  11098. if (value === undefined) return UNDEFINED;
  11099. if (value === true) return TRUE;
  11100. if (value === false) return FALSE;
  11101. if (value === 0) return ZERO;
  11102. if (value === '') return EMPTYSTRING;
  11103. if (typeof value === 'object' || typeof value === 'function') {
  11104. try {
  11105. var then = value.then;
  11106. if (typeof then === 'function') {
  11107. return new Promise(then.bind(value));
  11108. }
  11109. } catch (ex) {
  11110. return new Promise(function (resolve, reject) {
  11111. reject(ex);
  11112. });
  11113. }
  11114. }
  11115. return valuePromise(value);
  11116. };
  11117. Promise.all = function (arr) {
  11118. var args = Array.prototype.slice.call(arr);
  11119. return new Promise(function (resolve, reject) {
  11120. if (args.length === 0) return resolve([]);
  11121. var remaining = args.length;
  11122. function res(i, val) {
  11123. if (val && (typeof val === 'object' || typeof val === 'function')) {
  11124. if (val instanceof Promise && val.then === Promise.prototype.then) {
  11125. while (val._65 === 3) {
  11126. val = val._55;
  11127. }
  11128. if (val._65 === 1) return res(i, val._55);
  11129. if (val._65 === 2) reject(val._55);
  11130. val.then(function (val) {
  11131. res(i, val);
  11132. }, reject);
  11133. return;
  11134. } else {
  11135. var then = val.then;
  11136. if (typeof then === 'function') {
  11137. var p = new Promise(then.bind(val));
  11138. p.then(function (val) {
  11139. res(i, val);
  11140. }, reject);
  11141. return;
  11142. }
  11143. }
  11144. }
  11145. args[i] = val;
  11146. if (--remaining === 0) {
  11147. resolve(args);
  11148. }
  11149. }
  11150. for (var i = 0; i < args.length; i++) {
  11151. res(i, args[i]);
  11152. }
  11153. });
  11154. };
  11155. Promise.reject = function (value) {
  11156. return new Promise(function (resolve, reject) {
  11157. reject(value);
  11158. });
  11159. };
  11160. Promise.race = function (values) {
  11161. return new Promise(function (resolve, reject) {
  11162. values.forEach(function(value){
  11163. Promise.resolve(value).then(resolve, reject);
  11164. });
  11165. });
  11166. };
  11167. /* Prototype Methods */
  11168. Promise.prototype['catch'] = function (onRejected) {
  11169. return this.then(null, onRejected);
  11170. };
  11171. },{"./core.js":100}],102:[function(require,module,exports){
  11172. // should work in any browser without browserify
  11173. if (typeof Promise.prototype.done !== 'function') {
  11174. Promise.prototype.done = function (onFulfilled, onRejected) {
  11175. var self = arguments.length ? this.then.apply(this, arguments) : this
  11176. self.then(null, function (err) {
  11177. setTimeout(function () {
  11178. throw err
  11179. }, 0)
  11180. })
  11181. }
  11182. }
  11183. },{}],103:[function(require,module,exports){
  11184. // not "use strict" so we can declare global "Promise"
  11185. var asap = require('asap');
  11186. if (typeof Promise === 'undefined') {
  11187. Promise = require('./lib/core.js')
  11188. require('./lib/es6-extensions.js')
  11189. }
  11190. require('./polyfill-done.js');
  11191. },{"./lib/core.js":100,"./lib/es6-extensions.js":101,"./polyfill-done.js":102,"asap":98}]},{},[2])(2)
  11192. });