less.js 415 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331
  1. /**
  2. * Less - Leaner CSS v3.10.3
  3. * http://lesscss.org
  4. *
  5. * Copyright (c) 2009-2019, Alexis Sellier <self@cloudhead.net>
  6. * Licensed under the Apache-2.0 License.
  7. *
  8. * @license Apache-2.0
  9. */
  10. (function (global, factory) {
  11. typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
  12. typeof define === 'function' && define.amd ? define(factory) :
  13. (global = global || self, global.less = factory());
  14. }(this, function () { 'use strict';
  15. // Export a new default each time
  16. var defaultOptions = (function () {
  17. return {
  18. /* Inline Javascript - @plugin still allowed */
  19. javascriptEnabled: false,
  20. /* Outputs a makefile import dependency list to stdout. */
  21. depends: false,
  22. /* (DEPRECATED) Compress using less built-in compression.
  23. * This does an okay job but does not utilise all the tricks of
  24. * dedicated css compression. */
  25. compress: false,
  26. /* Runs the less parser and just reports errors without any output. */
  27. lint: false,
  28. /* Sets available include paths.
  29. * If the file in an @import rule does not exist at that exact location,
  30. * less will look for it at the location(s) passed to this option.
  31. * You might use this for instance to specify a path to a library which
  32. * you want to be referenced simply and relatively in the less files. */
  33. paths: [],
  34. /* color output in the terminal */
  35. color: true,
  36. /* The strictImports controls whether the compiler will allow an @import inside of either
  37. * @media blocks or (a later addition) other selector blocks.
  38. * See: https://github.com/less/less.js/issues/656 */
  39. strictImports: false,
  40. /* Allow Imports from Insecure HTTPS Hosts */
  41. insecure: false,
  42. /* Allows you to add a path to every generated import and url in your css.
  43. * This does not affect less import statements that are processed, just ones
  44. * that are left in the output css. */
  45. rootpath: '',
  46. /* By default URLs are kept as-is, so if you import a file in a sub-directory
  47. * that references an image, exactly the same URL will be output in the css.
  48. * This option allows you to re-write URL's in imported files so that the
  49. * URL is always relative to the base imported file */
  50. rewriteUrls: false,
  51. /* How to process math
  52. * 0 always - eagerly try to solve all operations
  53. * 1 parens-division - require parens for division "/"
  54. * 2 parens | strict - require parens for all operations
  55. * 3 strict-legacy - legacy strict behavior (super-strict)
  56. */
  57. math: 0,
  58. /* Without this option, less attempts to guess at the output unit when it does maths. */
  59. strictUnits: false,
  60. /* Effectively the declaration is put at the top of your base Less file,
  61. * meaning it can be used but it also can be overridden if this variable
  62. * is defined in the file. */
  63. globalVars: null,
  64. /* As opposed to the global variable option, this puts the declaration at the
  65. * end of your base file, meaning it will override anything defined in your Less file. */
  66. modifyVars: null,
  67. /* This option allows you to specify a argument to go on to every URL. */
  68. urlArgs: ''
  69. };
  70. });
  71. function extractId(href) {
  72. return href.replace(/^[a-z-]+:\/+?[^\/]+/, '') // Remove protocol & domain
  73. .replace(/[\?\&]livereload=\w+/, '') // Remove LiveReload cachebuster
  74. .replace(/^\//, '') // Remove root /
  75. .replace(/\.[a-zA-Z]+$/, '') // Remove simple extension
  76. .replace(/[^\.\w-]+/g, '-') // Replace illegal characters
  77. .replace(/\./g, ':'); // Replace dots with colons(for valid id)
  78. }
  79. function addDataAttr(options, tag) {
  80. for (var opt in tag.dataset) {
  81. if (tag.dataset.hasOwnProperty(opt)) {
  82. if (opt === 'env' || opt === 'dumpLineNumbers' || opt === 'rootpath' || opt === 'errorReporting') {
  83. options[opt] = tag.dataset[opt];
  84. } else {
  85. try {
  86. options[opt] = JSON.parse(tag.dataset[opt]);
  87. } catch (_) {}
  88. }
  89. }
  90. }
  91. }
  92. var browser = {
  93. createCSS: function createCSS(document, styles, sheet) {
  94. // Strip the query-string
  95. var href = sheet.href || ''; // If there is no title set, use the filename, minus the extension
  96. var id = "less:".concat(sheet.title || extractId(href)); // If this has already been inserted into the DOM, we may need to replace it
  97. var oldStyleNode = document.getElementById(id);
  98. var keepOldStyleNode = false; // Create a new stylesheet node for insertion or (if necessary) replacement
  99. var styleNode = document.createElement('style');
  100. styleNode.setAttribute('type', 'text/css');
  101. if (sheet.media) {
  102. styleNode.setAttribute('media', sheet.media);
  103. }
  104. styleNode.id = id;
  105. if (!styleNode.styleSheet) {
  106. styleNode.appendChild(document.createTextNode(styles)); // If new contents match contents of oldStyleNode, don't replace oldStyleNode
  107. keepOldStyleNode = oldStyleNode !== null && oldStyleNode.childNodes.length > 0 && styleNode.childNodes.length > 0 && oldStyleNode.firstChild.nodeValue === styleNode.firstChild.nodeValue;
  108. }
  109. var head = document.getElementsByTagName('head')[0]; // If there is no oldStyleNode, just append; otherwise, only append if we need
  110. // to replace oldStyleNode with an updated stylesheet
  111. if (oldStyleNode === null || keepOldStyleNode === false) {
  112. var nextEl = sheet && sheet.nextSibling || null;
  113. if (nextEl) {
  114. nextEl.parentNode.insertBefore(styleNode, nextEl);
  115. } else {
  116. head.appendChild(styleNode);
  117. }
  118. }
  119. if (oldStyleNode && keepOldStyleNode === false) {
  120. oldStyleNode.parentNode.removeChild(oldStyleNode);
  121. } // For IE.
  122. // This needs to happen *after* the style element is added to the DOM, otherwise IE 7 and 8 may crash.
  123. // See http://social.msdn.microsoft.com/Forums/en-US/7e081b65-878a-4c22-8e68-c10d39c2ed32/internet-explorer-crashes-appending-style-element-to-head
  124. if (styleNode.styleSheet) {
  125. try {
  126. styleNode.styleSheet.cssText = styles;
  127. } catch (e) {
  128. throw new Error('Couldn\'t reassign styleSheet.cssText.');
  129. }
  130. }
  131. },
  132. currentScript: function currentScript(window) {
  133. var document = window.document;
  134. return document.currentScript || function () {
  135. var scripts = document.getElementsByTagName('script');
  136. return scripts[scripts.length - 1];
  137. }();
  138. }
  139. };
  140. var addDefaultOptions = (function (window, options) {
  141. // use options from the current script tag data attribues
  142. addDataAttr(options, browser.currentScript(window));
  143. if (options.isFileProtocol === undefined) {
  144. options.isFileProtocol = /^(file|(chrome|safari)(-extension)?|resource|qrc|app):/.test(window.location.protocol);
  145. } // Load styles asynchronously (default: false)
  146. //
  147. // This is set to `false` by default, so that the body
  148. // doesn't start loading before the stylesheets are parsed.
  149. // Setting this to `true` can result in flickering.
  150. //
  151. options.async = options.async || false;
  152. options.fileAsync = options.fileAsync || false; // Interval between watch polls
  153. options.poll = options.poll || (options.isFileProtocol ? 1000 : 1500);
  154. options.env = options.env || (window.location.hostname == '127.0.0.1' || window.location.hostname == '0.0.0.0' || window.location.hostname == 'localhost' || window.location.port && window.location.port.length > 0 || options.isFileProtocol ? 'development' : 'production');
  155. var dumpLineNumbers = /!dumpLineNumbers:(comments|mediaquery|all)/.exec(window.location.hash);
  156. if (dumpLineNumbers) {
  157. options.dumpLineNumbers = dumpLineNumbers[1];
  158. }
  159. if (options.useFileCache === undefined) {
  160. options.useFileCache = true;
  161. }
  162. if (options.onReady === undefined) {
  163. options.onReady = true;
  164. }
  165. if (options.relativeUrls) {
  166. options.rewriteUrls = 'all';
  167. }
  168. });
  169. function _typeof(obj) {
  170. if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
  171. _typeof = function (obj) {
  172. return typeof obj;
  173. };
  174. } else {
  175. _typeof = function (obj) {
  176. return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
  177. };
  178. }
  179. return _typeof(obj);
  180. }
  181. function _classCallCheck(instance, Constructor) {
  182. if (!(instance instanceof Constructor)) {
  183. throw new TypeError("Cannot call a class as a function");
  184. }
  185. }
  186. function _defineProperties(target, props) {
  187. for (var i = 0; i < props.length; i++) {
  188. var descriptor = props[i];
  189. descriptor.enumerable = descriptor.enumerable || false;
  190. descriptor.configurable = true;
  191. if ("value" in descriptor) descriptor.writable = true;
  192. Object.defineProperty(target, descriptor.key, descriptor);
  193. }
  194. }
  195. function _createClass(Constructor, protoProps, staticProps) {
  196. if (protoProps) _defineProperties(Constructor.prototype, protoProps);
  197. if (staticProps) _defineProperties(Constructor, staticProps);
  198. return Constructor;
  199. }
  200. function _inherits(subClass, superClass) {
  201. if (typeof superClass !== "function" && superClass !== null) {
  202. throw new TypeError("Super expression must either be null or a function");
  203. }
  204. subClass.prototype = Object.create(superClass && superClass.prototype, {
  205. constructor: {
  206. value: subClass,
  207. writable: true,
  208. configurable: true
  209. }
  210. });
  211. if (superClass) _setPrototypeOf(subClass, superClass);
  212. }
  213. function _getPrototypeOf(o) {
  214. _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {
  215. return o.__proto__ || Object.getPrototypeOf(o);
  216. };
  217. return _getPrototypeOf(o);
  218. }
  219. function _setPrototypeOf(o, p) {
  220. _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
  221. o.__proto__ = p;
  222. return o;
  223. };
  224. return _setPrototypeOf(o, p);
  225. }
  226. function isNativeReflectConstruct() {
  227. if (typeof Reflect === "undefined" || !Reflect.construct) return false;
  228. if (Reflect.construct.sham) return false;
  229. if (typeof Proxy === "function") return true;
  230. try {
  231. Date.prototype.toString.call(Reflect.construct(Date, [], function () {}));
  232. return true;
  233. } catch (e) {
  234. return false;
  235. }
  236. }
  237. function _construct(Parent, args, Class) {
  238. if (isNativeReflectConstruct()) {
  239. _construct = Reflect.construct;
  240. } else {
  241. _construct = function _construct(Parent, args, Class) {
  242. var a = [null];
  243. a.push.apply(a, args);
  244. var Constructor = Function.bind.apply(Parent, a);
  245. var instance = new Constructor();
  246. if (Class) _setPrototypeOf(instance, Class.prototype);
  247. return instance;
  248. };
  249. }
  250. return _construct.apply(null, arguments);
  251. }
  252. function _assertThisInitialized(self) {
  253. if (self === void 0) {
  254. throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
  255. }
  256. return self;
  257. }
  258. function _possibleConstructorReturn(self, call) {
  259. if (call && (typeof call === "object" || typeof call === "function")) {
  260. return call;
  261. }
  262. return _assertThisInitialized(self);
  263. }
  264. function _toConsumableArray(arr) {
  265. return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread();
  266. }
  267. function _arrayWithoutHoles(arr) {
  268. if (Array.isArray(arr)) {
  269. for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) arr2[i] = arr[i];
  270. return arr2;
  271. }
  272. }
  273. function _iterableToArray(iter) {
  274. if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter);
  275. }
  276. function _nonIterableSpread() {
  277. throw new TypeError("Invalid attempt to spread non-iterable instance");
  278. }
  279. var colors = {
  280. 'aliceblue': '#f0f8ff',
  281. 'antiquewhite': '#faebd7',
  282. 'aqua': '#00ffff',
  283. 'aquamarine': '#7fffd4',
  284. 'azure': '#f0ffff',
  285. 'beige': '#f5f5dc',
  286. 'bisque': '#ffe4c4',
  287. 'black': '#000000',
  288. 'blanchedalmond': '#ffebcd',
  289. 'blue': '#0000ff',
  290. 'blueviolet': '#8a2be2',
  291. 'brown': '#a52a2a',
  292. 'burlywood': '#deb887',
  293. 'cadetblue': '#5f9ea0',
  294. 'chartreuse': '#7fff00',
  295. 'chocolate': '#d2691e',
  296. 'coral': '#ff7f50',
  297. 'cornflowerblue': '#6495ed',
  298. 'cornsilk': '#fff8dc',
  299. 'crimson': '#dc143c',
  300. 'cyan': '#00ffff',
  301. 'darkblue': '#00008b',
  302. 'darkcyan': '#008b8b',
  303. 'darkgoldenrod': '#b8860b',
  304. 'darkgray': '#a9a9a9',
  305. 'darkgrey': '#a9a9a9',
  306. 'darkgreen': '#006400',
  307. 'darkkhaki': '#bdb76b',
  308. 'darkmagenta': '#8b008b',
  309. 'darkolivegreen': '#556b2f',
  310. 'darkorange': '#ff8c00',
  311. 'darkorchid': '#9932cc',
  312. 'darkred': '#8b0000',
  313. 'darksalmon': '#e9967a',
  314. 'darkseagreen': '#8fbc8f',
  315. 'darkslateblue': '#483d8b',
  316. 'darkslategray': '#2f4f4f',
  317. 'darkslategrey': '#2f4f4f',
  318. 'darkturquoise': '#00ced1',
  319. 'darkviolet': '#9400d3',
  320. 'deeppink': '#ff1493',
  321. 'deepskyblue': '#00bfff',
  322. 'dimgray': '#696969',
  323. 'dimgrey': '#696969',
  324. 'dodgerblue': '#1e90ff',
  325. 'firebrick': '#b22222',
  326. 'floralwhite': '#fffaf0',
  327. 'forestgreen': '#228b22',
  328. 'fuchsia': '#ff00ff',
  329. 'gainsboro': '#dcdcdc',
  330. 'ghostwhite': '#f8f8ff',
  331. 'gold': '#ffd700',
  332. 'goldenrod': '#daa520',
  333. 'gray': '#808080',
  334. 'grey': '#808080',
  335. 'green': '#008000',
  336. 'greenyellow': '#adff2f',
  337. 'honeydew': '#f0fff0',
  338. 'hotpink': '#ff69b4',
  339. 'indianred': '#cd5c5c',
  340. 'indigo': '#4b0082',
  341. 'ivory': '#fffff0',
  342. 'khaki': '#f0e68c',
  343. 'lavender': '#e6e6fa',
  344. 'lavenderblush': '#fff0f5',
  345. 'lawngreen': '#7cfc00',
  346. 'lemonchiffon': '#fffacd',
  347. 'lightblue': '#add8e6',
  348. 'lightcoral': '#f08080',
  349. 'lightcyan': '#e0ffff',
  350. 'lightgoldenrodyellow': '#fafad2',
  351. 'lightgray': '#d3d3d3',
  352. 'lightgrey': '#d3d3d3',
  353. 'lightgreen': '#90ee90',
  354. 'lightpink': '#ffb6c1',
  355. 'lightsalmon': '#ffa07a',
  356. 'lightseagreen': '#20b2aa',
  357. 'lightskyblue': '#87cefa',
  358. 'lightslategray': '#778899',
  359. 'lightslategrey': '#778899',
  360. 'lightsteelblue': '#b0c4de',
  361. 'lightyellow': '#ffffe0',
  362. 'lime': '#00ff00',
  363. 'limegreen': '#32cd32',
  364. 'linen': '#faf0e6',
  365. 'magenta': '#ff00ff',
  366. 'maroon': '#800000',
  367. 'mediumaquamarine': '#66cdaa',
  368. 'mediumblue': '#0000cd',
  369. 'mediumorchid': '#ba55d3',
  370. 'mediumpurple': '#9370d8',
  371. 'mediumseagreen': '#3cb371',
  372. 'mediumslateblue': '#7b68ee',
  373. 'mediumspringgreen': '#00fa9a',
  374. 'mediumturquoise': '#48d1cc',
  375. 'mediumvioletred': '#c71585',
  376. 'midnightblue': '#191970',
  377. 'mintcream': '#f5fffa',
  378. 'mistyrose': '#ffe4e1',
  379. 'moccasin': '#ffe4b5',
  380. 'navajowhite': '#ffdead',
  381. 'navy': '#000080',
  382. 'oldlace': '#fdf5e6',
  383. 'olive': '#808000',
  384. 'olivedrab': '#6b8e23',
  385. 'orange': '#ffa500',
  386. 'orangered': '#ff4500',
  387. 'orchid': '#da70d6',
  388. 'palegoldenrod': '#eee8aa',
  389. 'palegreen': '#98fb98',
  390. 'paleturquoise': '#afeeee',
  391. 'palevioletred': '#d87093',
  392. 'papayawhip': '#ffefd5',
  393. 'peachpuff': '#ffdab9',
  394. 'peru': '#cd853f',
  395. 'pink': '#ffc0cb',
  396. 'plum': '#dda0dd',
  397. 'powderblue': '#b0e0e6',
  398. 'purple': '#800080',
  399. 'rebeccapurple': '#663399',
  400. 'red': '#ff0000',
  401. 'rosybrown': '#bc8f8f',
  402. 'royalblue': '#4169e1',
  403. 'saddlebrown': '#8b4513',
  404. 'salmon': '#fa8072',
  405. 'sandybrown': '#f4a460',
  406. 'seagreen': '#2e8b57',
  407. 'seashell': '#fff5ee',
  408. 'sienna': '#a0522d',
  409. 'silver': '#c0c0c0',
  410. 'skyblue': '#87ceeb',
  411. 'slateblue': '#6a5acd',
  412. 'slategray': '#708090',
  413. 'slategrey': '#708090',
  414. 'snow': '#fffafa',
  415. 'springgreen': '#00ff7f',
  416. 'steelblue': '#4682b4',
  417. 'tan': '#d2b48c',
  418. 'teal': '#008080',
  419. 'thistle': '#d8bfd8',
  420. 'tomato': '#ff6347',
  421. 'turquoise': '#40e0d0',
  422. 'violet': '#ee82ee',
  423. 'wheat': '#f5deb3',
  424. 'white': '#ffffff',
  425. 'whitesmoke': '#f5f5f5',
  426. 'yellow': '#ffff00',
  427. 'yellowgreen': '#9acd32'
  428. };
  429. var unitConversions = {
  430. length: {
  431. 'm': 1,
  432. 'cm': 0.01,
  433. 'mm': 0.001,
  434. 'in': 0.0254,
  435. 'px': 0.0254 / 96,
  436. 'pt': 0.0254 / 72,
  437. 'pc': 0.0254 / 72 * 12
  438. },
  439. duration: {
  440. 's': 1,
  441. 'ms': 0.001
  442. },
  443. angle: {
  444. 'rad': 1 / (2 * Math.PI),
  445. 'deg': 1 / 360,
  446. 'grad': 1 / 400,
  447. 'turn': 1
  448. }
  449. };
  450. var data = {
  451. colors: colors,
  452. unitConversions: unitConversions
  453. };
  454. var Node =
  455. /*#__PURE__*/
  456. function () {
  457. function Node() {
  458. _classCallCheck(this, Node);
  459. this.parent = null;
  460. this.visibilityBlocks = undefined;
  461. this.nodeVisible = undefined;
  462. this.rootNode = null;
  463. this.parsed = null;
  464. var self = this;
  465. Object.defineProperty(this, 'currentFileInfo', {
  466. get: function get() {
  467. return self.fileInfo();
  468. }
  469. });
  470. Object.defineProperty(this, 'index', {
  471. get: function get() {
  472. return self.getIndex();
  473. }
  474. });
  475. }
  476. _createClass(Node, [{
  477. key: "setParent",
  478. value: function setParent(nodes, parent) {
  479. function set(node) {
  480. if (node && node instanceof Node) {
  481. node.parent = parent;
  482. }
  483. }
  484. if (Array.isArray(nodes)) {
  485. nodes.forEach(set);
  486. } else {
  487. set(nodes);
  488. }
  489. }
  490. }, {
  491. key: "getIndex",
  492. value: function getIndex() {
  493. return this._index || this.parent && this.parent.getIndex() || 0;
  494. }
  495. }, {
  496. key: "fileInfo",
  497. value: function fileInfo() {
  498. return this._fileInfo || this.parent && this.parent.fileInfo() || {};
  499. }
  500. }, {
  501. key: "isRulesetLike",
  502. value: function isRulesetLike() {
  503. return false;
  504. }
  505. }, {
  506. key: "toCSS",
  507. value: function toCSS(context) {
  508. var strs = [];
  509. this.genCSS(context, {
  510. add: function add(chunk, fileInfo, index) {
  511. strs.push(chunk);
  512. },
  513. isEmpty: function isEmpty() {
  514. return strs.length === 0;
  515. }
  516. });
  517. return strs.join('');
  518. }
  519. }, {
  520. key: "genCSS",
  521. value: function genCSS(context, output) {
  522. output.add(this.value);
  523. }
  524. }, {
  525. key: "accept",
  526. value: function accept(visitor) {
  527. this.value = visitor.visit(this.value);
  528. }
  529. }, {
  530. key: "eval",
  531. value: function _eval() {
  532. return this;
  533. }
  534. }, {
  535. key: "_operate",
  536. value: function _operate(context, op, a, b) {
  537. switch (op) {
  538. case '+':
  539. return a + b;
  540. case '-':
  541. return a - b;
  542. case '*':
  543. return a * b;
  544. case '/':
  545. return a / b;
  546. }
  547. }
  548. }, {
  549. key: "fround",
  550. value: function fround(context, value) {
  551. var precision = context && context.numPrecision; // add "epsilon" to ensure numbers like 1.000000005 (represented as 1.000000004999...) are properly rounded:
  552. return precision ? Number((value + 2e-16).toFixed(precision)) : value;
  553. } // Returns true if this node represents root of ast imported by reference
  554. }, {
  555. key: "blocksVisibility",
  556. value: function blocksVisibility() {
  557. if (this.visibilityBlocks == null) {
  558. this.visibilityBlocks = 0;
  559. }
  560. return this.visibilityBlocks !== 0;
  561. }
  562. }, {
  563. key: "addVisibilityBlock",
  564. value: function addVisibilityBlock() {
  565. if (this.visibilityBlocks == null) {
  566. this.visibilityBlocks = 0;
  567. }
  568. this.visibilityBlocks = this.visibilityBlocks + 1;
  569. }
  570. }, {
  571. key: "removeVisibilityBlock",
  572. value: function removeVisibilityBlock() {
  573. if (this.visibilityBlocks == null) {
  574. this.visibilityBlocks = 0;
  575. }
  576. this.visibilityBlocks = this.visibilityBlocks - 1;
  577. } // Turns on node visibility - if called node will be shown in output regardless
  578. // of whether it comes from import by reference or not
  579. }, {
  580. key: "ensureVisibility",
  581. value: function ensureVisibility() {
  582. this.nodeVisible = true;
  583. } // Turns off node visibility - if called node will NOT be shown in output regardless
  584. // of whether it comes from import by reference or not
  585. }, {
  586. key: "ensureInvisibility",
  587. value: function ensureInvisibility() {
  588. this.nodeVisible = false;
  589. } // return values:
  590. // false - the node must not be visible
  591. // true - the node must be visible
  592. // undefined or null - the node has the same visibility as its parent
  593. }, {
  594. key: "isVisible",
  595. value: function isVisible() {
  596. return this.nodeVisible;
  597. }
  598. }, {
  599. key: "visibilityInfo",
  600. value: function visibilityInfo() {
  601. return {
  602. visibilityBlocks: this.visibilityBlocks,
  603. nodeVisible: this.nodeVisible
  604. };
  605. }
  606. }, {
  607. key: "copyVisibilityInfo",
  608. value: function copyVisibilityInfo(info) {
  609. if (!info) {
  610. return;
  611. }
  612. this.visibilityBlocks = info.visibilityBlocks;
  613. this.nodeVisible = info.nodeVisible;
  614. }
  615. }]);
  616. return Node;
  617. }();
  618. Node.compare = function (a, b) {
  619. /* returns:
  620. -1: a < b
  621. 0: a = b
  622. 1: a > b
  623. and *any* other value for a != b (e.g. undefined, NaN, -2 etc.) */
  624. if (a.compare && // for "symmetric results" force toCSS-based comparison
  625. // of Quoted or Anonymous if either value is one of those
  626. !(b.type === 'Quoted' || b.type === 'Anonymous')) {
  627. return a.compare(b);
  628. } else if (b.compare) {
  629. return -b.compare(a);
  630. } else if (a.type !== b.type) {
  631. return undefined;
  632. }
  633. a = a.value;
  634. b = b.value;
  635. if (!Array.isArray(a)) {
  636. return a === b ? 0 : undefined;
  637. }
  638. if (a.length !== b.length) {
  639. return undefined;
  640. }
  641. for (var i = 0; i < a.length; i++) {
  642. if (Node.compare(a[i], b[i]) !== 0) {
  643. return undefined;
  644. }
  645. }
  646. return 0;
  647. };
  648. Node.numericCompare = function (a, b) {
  649. return a < b ? -1 : a === b ? 0 : a > b ? 1 : undefined;
  650. };
  651. // RGB Colors - #ff0014, #eee
  652. //
  653. var Color =
  654. /*#__PURE__*/
  655. function (_Node) {
  656. _inherits(Color, _Node);
  657. function Color(rgb, a, originalForm) {
  658. var _this;
  659. _classCallCheck(this, Color);
  660. _this = _possibleConstructorReturn(this, _getPrototypeOf(Color).call(this));
  661. var self = _assertThisInitialized(_this); //
  662. // The end goal here, is to parse the arguments
  663. // into an integer triplet, such as `128, 255, 0`
  664. //
  665. // This facilitates operations and conversions.
  666. //
  667. if (Array.isArray(rgb)) {
  668. _this.rgb = rgb;
  669. } else if (rgb.length >= 6) {
  670. _this.rgb = [];
  671. rgb.match(/.{2}/g).map(function (c, i) {
  672. if (i < 3) {
  673. self.rgb.push(parseInt(c, 16));
  674. } else {
  675. self.alpha = parseInt(c, 16) / 255;
  676. }
  677. });
  678. } else {
  679. _this.rgb = [];
  680. rgb.split('').map(function (c, i) {
  681. if (i < 3) {
  682. self.rgb.push(parseInt(c + c, 16));
  683. } else {
  684. self.alpha = parseInt(c + c, 16) / 255;
  685. }
  686. });
  687. }
  688. _this.alpha = _this.alpha || (typeof a === 'number' ? a : 1);
  689. if (typeof originalForm !== 'undefined') {
  690. _this.value = originalForm;
  691. }
  692. return _this;
  693. }
  694. _createClass(Color, [{
  695. key: "luma",
  696. value: function luma() {
  697. var r = this.rgb[0] / 255;
  698. var g = this.rgb[1] / 255;
  699. var b = this.rgb[2] / 255;
  700. r = r <= 0.03928 ? r / 12.92 : Math.pow((r + 0.055) / 1.055, 2.4);
  701. g = g <= 0.03928 ? g / 12.92 : Math.pow((g + 0.055) / 1.055, 2.4);
  702. b = b <= 0.03928 ? b / 12.92 : Math.pow((b + 0.055) / 1.055, 2.4);
  703. return 0.2126 * r + 0.7152 * g + 0.0722 * b;
  704. }
  705. }, {
  706. key: "genCSS",
  707. value: function genCSS(context, output) {
  708. output.add(this.toCSS(context));
  709. }
  710. }, {
  711. key: "toCSS",
  712. value: function toCSS(context, doNotCompress) {
  713. var compress = context && context.compress && !doNotCompress;
  714. var color;
  715. var alpha;
  716. var colorFunction;
  717. var args = []; // `value` is set if this color was originally
  718. // converted from a named color string so we need
  719. // to respect this and try to output named color too.
  720. alpha = this.fround(context, this.alpha);
  721. if (this.value) {
  722. if (this.value.indexOf('rgb') === 0) {
  723. if (alpha < 1) {
  724. colorFunction = 'rgba';
  725. }
  726. } else if (this.value.indexOf('hsl') === 0) {
  727. if (alpha < 1) {
  728. colorFunction = 'hsla';
  729. } else {
  730. colorFunction = 'hsl';
  731. }
  732. } else {
  733. return this.value;
  734. }
  735. } else {
  736. if (alpha < 1) {
  737. colorFunction = 'rgba';
  738. }
  739. }
  740. switch (colorFunction) {
  741. case 'rgba':
  742. args = this.rgb.map(function (c) {
  743. return clamp(Math.round(c), 255);
  744. }).concat(clamp(alpha, 1));
  745. break;
  746. case 'hsla':
  747. args.push(clamp(alpha, 1));
  748. case 'hsl':
  749. color = this.toHSL();
  750. args = [this.fround(context, color.h), "".concat(this.fround(context, color.s * 100), "%"), "".concat(this.fround(context, color.l * 100), "%")].concat(args);
  751. }
  752. if (colorFunction) {
  753. // Values are capped between `0` and `255`, rounded and zero-padded.
  754. return "".concat(colorFunction, "(").concat(args.join(",".concat(compress ? '' : ' ')), ")");
  755. }
  756. color = this.toRGB();
  757. if (compress) {
  758. var splitcolor = color.split(''); // Convert color to short format
  759. if (splitcolor[1] === splitcolor[2] && splitcolor[3] === splitcolor[4] && splitcolor[5] === splitcolor[6]) {
  760. color = "#".concat(splitcolor[1]).concat(splitcolor[3]).concat(splitcolor[5]);
  761. }
  762. }
  763. return color;
  764. } //
  765. // Operations have to be done per-channel, if not,
  766. // channels will spill onto each other. Once we have
  767. // our result, in the form of an integer triplet,
  768. // we create a new Color node to hold the result.
  769. //
  770. }, {
  771. key: "operate",
  772. value: function operate(context, op, other) {
  773. var rgb = new Array(3);
  774. var alpha = this.alpha * (1 - other.alpha) + other.alpha;
  775. for (var c = 0; c < 3; c++) {
  776. rgb[c] = this._operate(context, op, this.rgb[c], other.rgb[c]);
  777. }
  778. return new Color(rgb, alpha);
  779. }
  780. }, {
  781. key: "toRGB",
  782. value: function toRGB() {
  783. return toHex(this.rgb);
  784. }
  785. }, {
  786. key: "toHSL",
  787. value: function toHSL() {
  788. var r = this.rgb[0] / 255;
  789. var g = this.rgb[1] / 255;
  790. var b = this.rgb[2] / 255;
  791. var a = this.alpha;
  792. var max = Math.max(r, g, b);
  793. var min = Math.min(r, g, b);
  794. var h;
  795. var s;
  796. var l = (max + min) / 2;
  797. var d = max - min;
  798. if (max === min) {
  799. h = s = 0;
  800. } else {
  801. s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
  802. switch (max) {
  803. case r:
  804. h = (g - b) / d + (g < b ? 6 : 0);
  805. break;
  806. case g:
  807. h = (b - r) / d + 2;
  808. break;
  809. case b:
  810. h = (r - g) / d + 4;
  811. break;
  812. }
  813. h /= 6;
  814. }
  815. return {
  816. h: h * 360,
  817. s: s,
  818. l: l,
  819. a: a
  820. };
  821. } // Adapted from http://mjijackson.com/2008/02/rgb-to-hsl-and-rgb-to-hsv-color-model-conversion-algorithms-in-javascript
  822. }, {
  823. key: "toHSV",
  824. value: function toHSV() {
  825. var r = this.rgb[0] / 255;
  826. var g = this.rgb[1] / 255;
  827. var b = this.rgb[2] / 255;
  828. var a = this.alpha;
  829. var max = Math.max(r, g, b);
  830. var min = Math.min(r, g, b);
  831. var h;
  832. var s;
  833. var v = max;
  834. var d = max - min;
  835. if (max === 0) {
  836. s = 0;
  837. } else {
  838. s = d / max;
  839. }
  840. if (max === min) {
  841. h = 0;
  842. } else {
  843. switch (max) {
  844. case r:
  845. h = (g - b) / d + (g < b ? 6 : 0);
  846. break;
  847. case g:
  848. h = (b - r) / d + 2;
  849. break;
  850. case b:
  851. h = (r - g) / d + 4;
  852. break;
  853. }
  854. h /= 6;
  855. }
  856. return {
  857. h: h * 360,
  858. s: s,
  859. v: v,
  860. a: a
  861. };
  862. }
  863. }, {
  864. key: "toARGB",
  865. value: function toARGB() {
  866. return toHex([this.alpha * 255].concat(this.rgb));
  867. }
  868. }, {
  869. key: "compare",
  870. value: function compare(x) {
  871. return x.rgb && x.rgb[0] === this.rgb[0] && x.rgb[1] === this.rgb[1] && x.rgb[2] === this.rgb[2] && x.alpha === this.alpha ? 0 : undefined;
  872. }
  873. }]);
  874. return Color;
  875. }(Node);
  876. Color.prototype.type = 'Color';
  877. function clamp(v, max) {
  878. return Math.min(Math.max(v, 0), max);
  879. }
  880. function toHex(v) {
  881. return "#".concat(v.map(function (c) {
  882. c = clamp(Math.round(c), 255);
  883. return (c < 16 ? '0' : '') + c.toString(16);
  884. }).join(''));
  885. }
  886. Color.fromKeyword = function (keyword) {
  887. var c;
  888. var key = keyword.toLowerCase();
  889. if (colors.hasOwnProperty(key)) {
  890. c = new Color(colors[key].slice(1));
  891. } else if (key === 'transparent') {
  892. c = new Color([0, 0, 0], 0);
  893. }
  894. if (c) {
  895. c.value = keyword;
  896. return c;
  897. }
  898. };
  899. var Paren =
  900. /*#__PURE__*/
  901. function (_Node) {
  902. _inherits(Paren, _Node);
  903. function Paren(node) {
  904. var _this;
  905. _classCallCheck(this, Paren);
  906. _this = _possibleConstructorReturn(this, _getPrototypeOf(Paren).call(this));
  907. _this.value = node;
  908. return _this;
  909. }
  910. _createClass(Paren, [{
  911. key: "genCSS",
  912. value: function genCSS(context, output) {
  913. output.add('(');
  914. this.value.genCSS(context, output);
  915. output.add(')');
  916. }
  917. }, {
  918. key: "eval",
  919. value: function _eval(context) {
  920. return new Paren(this.value.eval(context));
  921. }
  922. }]);
  923. return Paren;
  924. }(Node);
  925. Paren.prototype.type = 'Paren';
  926. var _noSpaceCombinators = {
  927. '': true,
  928. ' ': true,
  929. '|': true
  930. };
  931. var Combinator =
  932. /*#__PURE__*/
  933. function (_Node) {
  934. _inherits(Combinator, _Node);
  935. function Combinator(value) {
  936. var _this;
  937. _classCallCheck(this, Combinator);
  938. _this = _possibleConstructorReturn(this, _getPrototypeOf(Combinator).call(this));
  939. if (value === ' ') {
  940. _this.value = ' ';
  941. _this.emptyOrWhitespace = true;
  942. } else {
  943. _this.value = value ? value.trim() : '';
  944. _this.emptyOrWhitespace = _this.value === '';
  945. }
  946. return _this;
  947. }
  948. _createClass(Combinator, [{
  949. key: "genCSS",
  950. value: function genCSS(context, output) {
  951. var spaceOrEmpty = context.compress || _noSpaceCombinators[this.value] ? '' : ' ';
  952. output.add(spaceOrEmpty + this.value + spaceOrEmpty);
  953. }
  954. }]);
  955. return Combinator;
  956. }(Node);
  957. Combinator.prototype.type = 'Combinator';
  958. var Element =
  959. /*#__PURE__*/
  960. function (_Node) {
  961. _inherits(Element, _Node);
  962. function Element(combinator, value, isVariable, index, currentFileInfo, visibilityInfo) {
  963. var _this;
  964. _classCallCheck(this, Element);
  965. _this = _possibleConstructorReturn(this, _getPrototypeOf(Element).call(this));
  966. _this.combinator = combinator instanceof Combinator ? combinator : new Combinator(combinator);
  967. if (typeof value === 'string') {
  968. _this.value = value.trim();
  969. } else if (value) {
  970. _this.value = value;
  971. } else {
  972. _this.value = '';
  973. }
  974. _this.isVariable = isVariable;
  975. _this._index = index;
  976. _this._fileInfo = currentFileInfo;
  977. _this.copyVisibilityInfo(visibilityInfo);
  978. _this.setParent(_this.combinator, _assertThisInitialized(_this));
  979. return _this;
  980. }
  981. _createClass(Element, [{
  982. key: "accept",
  983. value: function accept(visitor) {
  984. var value = this.value;
  985. this.combinator = visitor.visit(this.combinator);
  986. if (_typeof(value) === 'object') {
  987. this.value = visitor.visit(value);
  988. }
  989. }
  990. }, {
  991. key: "eval",
  992. value: function _eval(context) {
  993. return new Element(this.combinator, this.value.eval ? this.value.eval(context) : this.value, this.isVariable, this.getIndex(), this.fileInfo(), this.visibilityInfo());
  994. }
  995. }, {
  996. key: "clone",
  997. value: function clone() {
  998. return new Element(this.combinator, this.value, this.isVariable, this.getIndex(), this.fileInfo(), this.visibilityInfo());
  999. }
  1000. }, {
  1001. key: "genCSS",
  1002. value: function genCSS(context, output) {
  1003. output.add(this.toCSS(context), this.fileInfo(), this.getIndex());
  1004. }
  1005. }, {
  1006. key: "toCSS",
  1007. value: function toCSS() {
  1008. var context = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  1009. var value = this.value;
  1010. var firstSelector = context.firstSelector;
  1011. if (value instanceof Paren) {
  1012. // selector in parens should not be affected by outer selector
  1013. // flags (breaks only interpolated selectors - see #1973)
  1014. context.firstSelector = true;
  1015. }
  1016. value = value.toCSS ? value.toCSS(context) : value;
  1017. context.firstSelector = firstSelector;
  1018. if (value === '' && this.combinator.value.charAt(0) === '&') {
  1019. return '';
  1020. } else {
  1021. return this.combinator.toCSS(context) + value;
  1022. }
  1023. }
  1024. }]);
  1025. return Element;
  1026. }(Node);
  1027. Element.prototype.type = 'Element';
  1028. var Math$1 = {
  1029. ALWAYS: 0,
  1030. PARENS_DIVISION: 1,
  1031. PARENS: 2,
  1032. STRICT_LEGACY: 3
  1033. };
  1034. var RewriteUrls = {
  1035. OFF: 0,
  1036. LOCAL: 1,
  1037. ALL: 2
  1038. };
  1039. function createCommonjsModule(fn, module) {
  1040. return module = { exports: {} }, fn(module, module.exports), module.exports;
  1041. }
  1042. var clone_1 = createCommonjsModule(function (module) {
  1043. var clone = (function() {
  1044. function _instanceof(obj, type) {
  1045. return type != null && obj instanceof type;
  1046. }
  1047. var nativeMap;
  1048. try {
  1049. nativeMap = Map;
  1050. } catch(_) {
  1051. // maybe a reference error because no `Map`. Give it a dummy value that no
  1052. // value will ever be an instanceof.
  1053. nativeMap = function() {};
  1054. }
  1055. var nativeSet;
  1056. try {
  1057. nativeSet = Set;
  1058. } catch(_) {
  1059. nativeSet = function() {};
  1060. }
  1061. var nativePromise;
  1062. try {
  1063. nativePromise = Promise;
  1064. } catch(_) {
  1065. nativePromise = function() {};
  1066. }
  1067. /**
  1068. * Clones (copies) an Object using deep copying.
  1069. *
  1070. * This function supports circular references by default, but if you are certain
  1071. * there are no circular references in your object, you can save some CPU time
  1072. * by calling clone(obj, false).
  1073. *
  1074. * Caution: if `circular` is false and `parent` contains circular references,
  1075. * your program may enter an infinite loop and crash.
  1076. *
  1077. * @param `parent` - the object to be cloned
  1078. * @param `circular` - set to true if the object to be cloned may contain
  1079. * circular references. (optional - true by default)
  1080. * @param `depth` - set to a number if the object is only to be cloned to
  1081. * a particular depth. (optional - defaults to Infinity)
  1082. * @param `prototype` - sets the prototype to be used when cloning an object.
  1083. * (optional - defaults to parent prototype).
  1084. * @param `includeNonEnumerable` - set to true if the non-enumerable properties
  1085. * should be cloned as well. Non-enumerable properties on the prototype
  1086. * chain will be ignored. (optional - false by default)
  1087. */
  1088. function clone(parent, circular, depth, prototype, includeNonEnumerable) {
  1089. if (typeof circular === 'object') {
  1090. depth = circular.depth;
  1091. prototype = circular.prototype;
  1092. includeNonEnumerable = circular.includeNonEnumerable;
  1093. circular = circular.circular;
  1094. }
  1095. // maintain two arrays for circular references, where corresponding parents
  1096. // and children have the same index
  1097. var allParents = [];
  1098. var allChildren = [];
  1099. var useBuffer = typeof Buffer != 'undefined';
  1100. if (typeof circular == 'undefined')
  1101. circular = true;
  1102. if (typeof depth == 'undefined')
  1103. depth = Infinity;
  1104. // recurse this function so we don't reset allParents and allChildren
  1105. function _clone(parent, depth) {
  1106. // cloning null always returns null
  1107. if (parent === null)
  1108. return null;
  1109. if (depth === 0)
  1110. return parent;
  1111. var child;
  1112. var proto;
  1113. if (typeof parent != 'object') {
  1114. return parent;
  1115. }
  1116. if (_instanceof(parent, nativeMap)) {
  1117. child = new nativeMap();
  1118. } else if (_instanceof(parent, nativeSet)) {
  1119. child = new nativeSet();
  1120. } else if (_instanceof(parent, nativePromise)) {
  1121. child = new nativePromise(function (resolve, reject) {
  1122. parent.then(function(value) {
  1123. resolve(_clone(value, depth - 1));
  1124. }, function(err) {
  1125. reject(_clone(err, depth - 1));
  1126. });
  1127. });
  1128. } else if (clone.__isArray(parent)) {
  1129. child = [];
  1130. } else if (clone.__isRegExp(parent)) {
  1131. child = new RegExp(parent.source, __getRegExpFlags(parent));
  1132. if (parent.lastIndex) child.lastIndex = parent.lastIndex;
  1133. } else if (clone.__isDate(parent)) {
  1134. child = new Date(parent.getTime());
  1135. } else if (useBuffer && Buffer.isBuffer(parent)) {
  1136. if (Buffer.allocUnsafe) {
  1137. // Node.js >= 4.5.0
  1138. child = Buffer.allocUnsafe(parent.length);
  1139. } else {
  1140. // Older Node.js versions
  1141. child = new Buffer(parent.length);
  1142. }
  1143. parent.copy(child);
  1144. return child;
  1145. } else if (_instanceof(parent, Error)) {
  1146. child = Object.create(parent);
  1147. } else {
  1148. if (typeof prototype == 'undefined') {
  1149. proto = Object.getPrototypeOf(parent);
  1150. child = Object.create(proto);
  1151. }
  1152. else {
  1153. child = Object.create(prototype);
  1154. proto = prototype;
  1155. }
  1156. }
  1157. if (circular) {
  1158. var index = allParents.indexOf(parent);
  1159. if (index != -1) {
  1160. return allChildren[index];
  1161. }
  1162. allParents.push(parent);
  1163. allChildren.push(child);
  1164. }
  1165. if (_instanceof(parent, nativeMap)) {
  1166. parent.forEach(function(value, key) {
  1167. var keyChild = _clone(key, depth - 1);
  1168. var valueChild = _clone(value, depth - 1);
  1169. child.set(keyChild, valueChild);
  1170. });
  1171. }
  1172. if (_instanceof(parent, nativeSet)) {
  1173. parent.forEach(function(value) {
  1174. var entryChild = _clone(value, depth - 1);
  1175. child.add(entryChild);
  1176. });
  1177. }
  1178. for (var i in parent) {
  1179. var attrs;
  1180. if (proto) {
  1181. attrs = Object.getOwnPropertyDescriptor(proto, i);
  1182. }
  1183. if (attrs && attrs.set == null) {
  1184. continue;
  1185. }
  1186. child[i] = _clone(parent[i], depth - 1);
  1187. }
  1188. if (Object.getOwnPropertySymbols) {
  1189. var symbols = Object.getOwnPropertySymbols(parent);
  1190. for (var i = 0; i < symbols.length; i++) {
  1191. // Don't need to worry about cloning a symbol because it is a primitive,
  1192. // like a number or string.
  1193. var symbol = symbols[i];
  1194. var descriptor = Object.getOwnPropertyDescriptor(parent, symbol);
  1195. if (descriptor && !descriptor.enumerable && !includeNonEnumerable) {
  1196. continue;
  1197. }
  1198. child[symbol] = _clone(parent[symbol], depth - 1);
  1199. if (!descriptor.enumerable) {
  1200. Object.defineProperty(child, symbol, {
  1201. enumerable: false
  1202. });
  1203. }
  1204. }
  1205. }
  1206. if (includeNonEnumerable) {
  1207. var allPropertyNames = Object.getOwnPropertyNames(parent);
  1208. for (var i = 0; i < allPropertyNames.length; i++) {
  1209. var propertyName = allPropertyNames[i];
  1210. var descriptor = Object.getOwnPropertyDescriptor(parent, propertyName);
  1211. if (descriptor && descriptor.enumerable) {
  1212. continue;
  1213. }
  1214. child[propertyName] = _clone(parent[propertyName], depth - 1);
  1215. Object.defineProperty(child, propertyName, {
  1216. enumerable: false
  1217. });
  1218. }
  1219. }
  1220. return child;
  1221. }
  1222. return _clone(parent, depth);
  1223. }
  1224. /**
  1225. * Simple flat clone using prototype, accepts only objects, usefull for property
  1226. * override on FLAT configuration object (no nested props).
  1227. *
  1228. * USE WITH CAUTION! This may not behave as you wish if you do not know how this
  1229. * works.
  1230. */
  1231. clone.clonePrototype = function clonePrototype(parent) {
  1232. if (parent === null)
  1233. return null;
  1234. var c = function () {};
  1235. c.prototype = parent;
  1236. return new c();
  1237. };
  1238. // private utility functions
  1239. function __objToStr(o) {
  1240. return Object.prototype.toString.call(o);
  1241. }
  1242. clone.__objToStr = __objToStr;
  1243. function __isDate(o) {
  1244. return typeof o === 'object' && __objToStr(o) === '[object Date]';
  1245. }
  1246. clone.__isDate = __isDate;
  1247. function __isArray(o) {
  1248. return typeof o === 'object' && __objToStr(o) === '[object Array]';
  1249. }
  1250. clone.__isArray = __isArray;
  1251. function __isRegExp(o) {
  1252. return typeof o === 'object' && __objToStr(o) === '[object RegExp]';
  1253. }
  1254. clone.__isRegExp = __isRegExp;
  1255. function __getRegExpFlags(re) {
  1256. var flags = '';
  1257. if (re.global) flags += 'g';
  1258. if (re.ignoreCase) flags += 'i';
  1259. if (re.multiline) flags += 'm';
  1260. return flags;
  1261. }
  1262. clone.__getRegExpFlags = __getRegExpFlags;
  1263. return clone;
  1264. })();
  1265. if ( module.exports) {
  1266. module.exports = clone;
  1267. }
  1268. });
  1269. /* jshint proto: true */
  1270. function getLocation(index, inputStream) {
  1271. var n = index + 1;
  1272. var line = null;
  1273. var column = -1;
  1274. while (--n >= 0 && inputStream.charAt(n) !== '\n') {
  1275. column++;
  1276. }
  1277. if (typeof index === 'number') {
  1278. line = (inputStream.slice(0, index).match(/\n/g) || '').length;
  1279. }
  1280. return {
  1281. line: line,
  1282. column: column
  1283. };
  1284. }
  1285. function copyArray(arr) {
  1286. var i;
  1287. var length = arr.length;
  1288. var copy = new Array(length);
  1289. for (i = 0; i < length; i++) {
  1290. copy[i] = arr[i];
  1291. }
  1292. return copy;
  1293. }
  1294. function clone(obj) {
  1295. var cloned = {};
  1296. for (var prop in obj) {
  1297. if (obj.hasOwnProperty(prop)) {
  1298. cloned[prop] = obj[prop];
  1299. }
  1300. }
  1301. return cloned;
  1302. }
  1303. function defaults(obj1, obj2) {
  1304. var newObj = obj2 || {};
  1305. if (!obj2._defaults) {
  1306. newObj = {};
  1307. var _defaults = clone_1(obj1);
  1308. newObj._defaults = _defaults;
  1309. var cloned = obj2 ? clone_1(obj2) : {};
  1310. Object.assign(newObj, _defaults, cloned);
  1311. }
  1312. return newObj;
  1313. }
  1314. function copyOptions(obj1, obj2) {
  1315. if (obj2 && obj2._defaults) {
  1316. return obj2;
  1317. }
  1318. var opts = defaults(obj1, obj2);
  1319. if (opts.strictMath) {
  1320. opts.math = Math$1.STRICT_LEGACY;
  1321. } // Back compat with changed relativeUrls option
  1322. if (opts.relativeUrls) {
  1323. opts.rewriteUrls = RewriteUrls.ALL;
  1324. }
  1325. if (typeof opts.math === 'string') {
  1326. switch (opts.math.toLowerCase()) {
  1327. case 'always':
  1328. opts.math = Math$1.ALWAYS;
  1329. break;
  1330. case 'parens-division':
  1331. opts.math = Math$1.PARENS_DIVISION;
  1332. break;
  1333. case 'strict':
  1334. case 'parens':
  1335. opts.math = Math$1.PARENS;
  1336. break;
  1337. case 'strict-legacy':
  1338. opts.math = Math$1.STRICT_LEGACY;
  1339. }
  1340. }
  1341. if (typeof opts.rewriteUrls === 'string') {
  1342. switch (opts.rewriteUrls.toLowerCase()) {
  1343. case 'off':
  1344. opts.rewriteUrls = RewriteUrls.OFF;
  1345. break;
  1346. case 'local':
  1347. opts.rewriteUrls = RewriteUrls.LOCAL;
  1348. break;
  1349. case 'all':
  1350. opts.rewriteUrls = RewriteUrls.ALL;
  1351. break;
  1352. }
  1353. }
  1354. return opts;
  1355. }
  1356. function merge(obj1, obj2) {
  1357. for (var prop in obj2) {
  1358. if (obj2.hasOwnProperty(prop)) {
  1359. obj1[prop] = obj2[prop];
  1360. }
  1361. }
  1362. return obj1;
  1363. }
  1364. function flattenArray(arr) {
  1365. var result = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
  1366. for (var i = 0, length = arr.length; i < length; i++) {
  1367. var value = arr[i];
  1368. if (Array.isArray(value)) {
  1369. flattenArray(value, result);
  1370. } else {
  1371. if (value !== undefined) {
  1372. result.push(value);
  1373. }
  1374. }
  1375. }
  1376. return result;
  1377. }
  1378. var utils = /*#__PURE__*/Object.freeze({
  1379. getLocation: getLocation,
  1380. copyArray: copyArray,
  1381. clone: clone,
  1382. defaults: defaults,
  1383. copyOptions: copyOptions,
  1384. merge: merge,
  1385. flattenArray: flattenArray
  1386. });
  1387. /**
  1388. * This is a centralized class of any error that could be thrown internally (mostly by the parser).
  1389. * Besides standard .message it keeps some additional data like a path to the file where the error
  1390. * occurred along with line and column numbers.
  1391. *
  1392. * @class
  1393. * @extends Error
  1394. * @type {module.LessError}
  1395. *
  1396. * @prop {string} type
  1397. * @prop {string} filename
  1398. * @prop {number} index
  1399. * @prop {number} line
  1400. * @prop {number} column
  1401. * @prop {number} callLine
  1402. * @prop {number} callExtract
  1403. * @prop {string[]} extract
  1404. *
  1405. * @param {Object} e - An error object to wrap around or just a descriptive object
  1406. * @param {Object} fileContentMap - An object with file contents in 'contents' property (like importManager) @todo - move to fileManager?
  1407. * @param {string} [currentFilename]
  1408. */
  1409. var LessError = function LessError(e, fileContentMap, currentFilename) {
  1410. Error.call(this);
  1411. var filename = e.filename || currentFilename;
  1412. this.message = e.message;
  1413. this.stack = e.stack;
  1414. if (fileContentMap && filename) {
  1415. var input = fileContentMap.contents[filename];
  1416. var loc = getLocation(e.index, input);
  1417. var line = loc.line;
  1418. var col = loc.column;
  1419. var callLine = e.call && getLocation(e.call, input).line;
  1420. var lines = input ? input.split('\n') : '';
  1421. this.type = e.type || 'Syntax';
  1422. this.filename = filename;
  1423. this.index = e.index;
  1424. this.line = typeof line === 'number' ? line + 1 : null;
  1425. this.column = col;
  1426. if (!this.line && this.stack) {
  1427. var found = this.stack.match(/(<anonymous>|Function):(\d+):(\d+)/);
  1428. if (found) {
  1429. if (found[2]) {
  1430. this.line = parseInt(found[2]) - 2;
  1431. }
  1432. if (found[3]) {
  1433. this.column = parseInt(found[3]);
  1434. }
  1435. }
  1436. }
  1437. this.callLine = callLine + 1;
  1438. this.callExtract = lines[callLine];
  1439. this.extract = [lines[this.line - 2], lines[this.line - 1], lines[this.line]];
  1440. }
  1441. };
  1442. if (typeof Object.create === 'undefined') {
  1443. var F = function F() {};
  1444. F.prototype = Error.prototype;
  1445. LessError.prototype = new F();
  1446. } else {
  1447. LessError.prototype = Object.create(Error.prototype);
  1448. }
  1449. LessError.prototype.constructor = LessError;
  1450. /**
  1451. * An overridden version of the default Object.prototype.toString
  1452. * which uses additional information to create a helpful message.
  1453. *
  1454. * @param {Object} options
  1455. * @returns {string}
  1456. */
  1457. LessError.prototype.toString = function () {
  1458. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  1459. var message = '';
  1460. var extract = this.extract || [];
  1461. var error = [];
  1462. var stylize = function stylize(str) {
  1463. return str;
  1464. };
  1465. if (options.stylize) {
  1466. var type = _typeof(options.stylize);
  1467. if (type !== 'function') {
  1468. throw Error("options.stylize should be a function, got a ".concat(type, "!"));
  1469. }
  1470. stylize = options.stylize;
  1471. }
  1472. if (this.line !== null) {
  1473. if (typeof extract[0] === 'string') {
  1474. error.push(stylize("".concat(this.line - 1, " ").concat(extract[0]), 'grey'));
  1475. }
  1476. if (typeof extract[1] === 'string') {
  1477. var errorTxt = "".concat(this.line, " ");
  1478. if (extract[1]) {
  1479. errorTxt += extract[1].slice(0, this.column) + stylize(stylize(stylize(extract[1].substr(this.column, 1), 'bold') + extract[1].slice(this.column + 1), 'red'), 'inverse');
  1480. }
  1481. error.push(errorTxt);
  1482. }
  1483. if (typeof extract[2] === 'string') {
  1484. error.push(stylize("".concat(this.line + 1, " ").concat(extract[2]), 'grey'));
  1485. }
  1486. error = "".concat(error.join('\n') + stylize('', 'reset'), "\n");
  1487. }
  1488. message += stylize("".concat(this.type, "Error: ").concat(this.message), 'red');
  1489. if (this.filename) {
  1490. message += stylize(' in ', 'red') + this.filename;
  1491. }
  1492. if (this.line) {
  1493. message += stylize(" on line ".concat(this.line, ", column ").concat(this.column + 1, ":"), 'grey');
  1494. }
  1495. message += "\n".concat(error);
  1496. if (this.callLine) {
  1497. message += "".concat(stylize('from ', 'red') + (this.filename || ''), "/n");
  1498. message += "".concat(stylize(this.callLine, 'grey'), " ").concat(this.callExtract, "/n");
  1499. }
  1500. return message;
  1501. };
  1502. var Selector =
  1503. /*#__PURE__*/
  1504. function (_Node) {
  1505. _inherits(Selector, _Node);
  1506. function Selector(elements, extendList, condition, index, currentFileInfo, visibilityInfo) {
  1507. var _this;
  1508. _classCallCheck(this, Selector);
  1509. _this = _possibleConstructorReturn(this, _getPrototypeOf(Selector).call(this));
  1510. _this.extendList = extendList;
  1511. _this.condition = condition;
  1512. _this.evaldCondition = !condition;
  1513. _this._index = index;
  1514. _this._fileInfo = currentFileInfo;
  1515. _this.elements = _this.getElements(elements);
  1516. _this.mixinElements_ = undefined;
  1517. _this.copyVisibilityInfo(visibilityInfo);
  1518. _this.setParent(_this.elements, _assertThisInitialized(_this));
  1519. return _this;
  1520. }
  1521. _createClass(Selector, [{
  1522. key: "accept",
  1523. value: function accept(visitor) {
  1524. if (this.elements) {
  1525. this.elements = visitor.visitArray(this.elements);
  1526. }
  1527. if (this.extendList) {
  1528. this.extendList = visitor.visitArray(this.extendList);
  1529. }
  1530. if (this.condition) {
  1531. this.condition = visitor.visit(this.condition);
  1532. }
  1533. }
  1534. }, {
  1535. key: "createDerived",
  1536. value: function createDerived(elements, extendList, evaldCondition) {
  1537. elements = this.getElements(elements);
  1538. var newSelector = new Selector(elements, extendList || this.extendList, null, this.getIndex(), this.fileInfo(), this.visibilityInfo());
  1539. newSelector.evaldCondition = evaldCondition != null ? evaldCondition : this.evaldCondition;
  1540. newSelector.mediaEmpty = this.mediaEmpty;
  1541. return newSelector;
  1542. }
  1543. }, {
  1544. key: "getElements",
  1545. value: function getElements(els) {
  1546. if (!els) {
  1547. return [new Element('', '&', false, this._index, this._fileInfo)];
  1548. }
  1549. if (typeof els === 'string') {
  1550. this.parse.parseNode(els, ['selector'], this._index, this._fileInfo, function (err, result) {
  1551. if (err) {
  1552. throw new LessError({
  1553. index: err.index,
  1554. message: err.message
  1555. }, this.parse.imports, this._fileInfo.filename);
  1556. }
  1557. els = result[0].elements;
  1558. });
  1559. }
  1560. return els;
  1561. }
  1562. }, {
  1563. key: "createEmptySelectors",
  1564. value: function createEmptySelectors() {
  1565. var el = new Element('', '&', false, this._index, this._fileInfo);
  1566. var sels = [new Selector([el], null, null, this._index, this._fileInfo)];
  1567. sels[0].mediaEmpty = true;
  1568. return sels;
  1569. }
  1570. }, {
  1571. key: "match",
  1572. value: function match(other) {
  1573. var elements = this.elements;
  1574. var len = elements.length;
  1575. var olen;
  1576. var i;
  1577. other = other.mixinElements();
  1578. olen = other.length;
  1579. if (olen === 0 || len < olen) {
  1580. return 0;
  1581. } else {
  1582. for (i = 0; i < olen; i++) {
  1583. if (elements[i].value !== other[i]) {
  1584. return 0;
  1585. }
  1586. }
  1587. }
  1588. return olen; // return number of matched elements
  1589. }
  1590. }, {
  1591. key: "mixinElements",
  1592. value: function mixinElements() {
  1593. if (this.mixinElements_) {
  1594. return this.mixinElements_;
  1595. }
  1596. var elements = this.elements.map(function (v) {
  1597. return v.combinator.value + (v.value.value || v.value);
  1598. }).join('').match(/[,&#\*\.\w-]([\w-]|(\\.))*/g);
  1599. if (elements) {
  1600. if (elements[0] === '&') {
  1601. elements.shift();
  1602. }
  1603. } else {
  1604. elements = [];
  1605. }
  1606. return this.mixinElements_ = elements;
  1607. }
  1608. }, {
  1609. key: "isJustParentSelector",
  1610. value: function isJustParentSelector() {
  1611. return !this.mediaEmpty && this.elements.length === 1 && this.elements[0].value === '&' && (this.elements[0].combinator.value === ' ' || this.elements[0].combinator.value === '');
  1612. }
  1613. }, {
  1614. key: "eval",
  1615. value: function _eval(context) {
  1616. var evaldCondition = this.condition && this.condition.eval(context);
  1617. var elements = this.elements;
  1618. var extendList = this.extendList;
  1619. elements = elements && elements.map(function (e) {
  1620. return e.eval(context);
  1621. });
  1622. extendList = extendList && extendList.map(function (extend) {
  1623. return extend.eval(context);
  1624. });
  1625. return this.createDerived(elements, extendList, evaldCondition);
  1626. }
  1627. }, {
  1628. key: "genCSS",
  1629. value: function genCSS(context, output) {
  1630. var i;
  1631. var element;
  1632. if ((!context || !context.firstSelector) && this.elements[0].combinator.value === '') {
  1633. output.add(' ', this.fileInfo(), this.getIndex());
  1634. }
  1635. for (i = 0; i < this.elements.length; i++) {
  1636. element = this.elements[i];
  1637. element.genCSS(context, output);
  1638. }
  1639. }
  1640. }, {
  1641. key: "getIsOutput",
  1642. value: function getIsOutput() {
  1643. return this.evaldCondition;
  1644. }
  1645. }]);
  1646. return Selector;
  1647. }(Node);
  1648. Selector.prototype.type = 'Selector';
  1649. var Value =
  1650. /*#__PURE__*/
  1651. function (_Node) {
  1652. _inherits(Value, _Node);
  1653. function Value(value) {
  1654. var _this;
  1655. _classCallCheck(this, Value);
  1656. _this = _possibleConstructorReturn(this, _getPrototypeOf(Value).call(this));
  1657. if (!value) {
  1658. throw new Error('Value requires an array argument');
  1659. }
  1660. if (!Array.isArray(value)) {
  1661. _this.value = [value];
  1662. } else {
  1663. _this.value = value;
  1664. }
  1665. return _this;
  1666. }
  1667. _createClass(Value, [{
  1668. key: "accept",
  1669. value: function accept(visitor) {
  1670. if (this.value) {
  1671. this.value = visitor.visitArray(this.value);
  1672. }
  1673. }
  1674. }, {
  1675. key: "eval",
  1676. value: function _eval(context) {
  1677. if (this.value.length === 1) {
  1678. return this.value[0].eval(context);
  1679. } else {
  1680. return new Value(this.value.map(function (v) {
  1681. return v.eval(context);
  1682. }));
  1683. }
  1684. }
  1685. }, {
  1686. key: "genCSS",
  1687. value: function genCSS(context, output) {
  1688. var i;
  1689. for (i = 0; i < this.value.length; i++) {
  1690. this.value[i].genCSS(context, output);
  1691. if (i + 1 < this.value.length) {
  1692. output.add(context && context.compress ? ',' : ', ');
  1693. }
  1694. }
  1695. }
  1696. }]);
  1697. return Value;
  1698. }(Node);
  1699. Value.prototype.type = 'Value';
  1700. var Keyword =
  1701. /*#__PURE__*/
  1702. function (_Node) {
  1703. _inherits(Keyword, _Node);
  1704. function Keyword(value) {
  1705. var _this;
  1706. _classCallCheck(this, Keyword);
  1707. _this = _possibleConstructorReturn(this, _getPrototypeOf(Keyword).call(this));
  1708. _this.value = value;
  1709. return _this;
  1710. }
  1711. _createClass(Keyword, [{
  1712. key: "genCSS",
  1713. value: function genCSS(context, output) {
  1714. if (this.value === '%') {
  1715. throw {
  1716. type: 'Syntax',
  1717. message: 'Invalid % without number'
  1718. };
  1719. }
  1720. output.add(this.value);
  1721. }
  1722. }]);
  1723. return Keyword;
  1724. }(Node);
  1725. Keyword.prototype.type = 'Keyword';
  1726. Keyword.True = new Keyword('true');
  1727. Keyword.False = new Keyword('false');
  1728. var Anonymous =
  1729. /*#__PURE__*/
  1730. function (_Node) {
  1731. _inherits(Anonymous, _Node);
  1732. function Anonymous(value, index, currentFileInfo, mapLines, rulesetLike, visibilityInfo) {
  1733. var _this;
  1734. _classCallCheck(this, Anonymous);
  1735. _this = _possibleConstructorReturn(this, _getPrototypeOf(Anonymous).call(this));
  1736. _this.value = value;
  1737. _this._index = index;
  1738. _this._fileInfo = currentFileInfo;
  1739. _this.mapLines = mapLines;
  1740. _this.rulesetLike = typeof rulesetLike === 'undefined' ? false : rulesetLike;
  1741. _this.allowRoot = true;
  1742. _this.copyVisibilityInfo(visibilityInfo);
  1743. return _this;
  1744. }
  1745. _createClass(Anonymous, [{
  1746. key: "eval",
  1747. value: function _eval() {
  1748. return new Anonymous(this.value, this._index, this._fileInfo, this.mapLines, this.rulesetLike, this.visibilityInfo());
  1749. }
  1750. }, {
  1751. key: "compare",
  1752. value: function compare(other) {
  1753. return other.toCSS && this.toCSS() === other.toCSS() ? 0 : undefined;
  1754. }
  1755. }, {
  1756. key: "isRulesetLike",
  1757. value: function isRulesetLike() {
  1758. return this.rulesetLike;
  1759. }
  1760. }, {
  1761. key: "genCSS",
  1762. value: function genCSS(context, output) {
  1763. this.nodeVisible = Boolean(this.value);
  1764. if (this.nodeVisible) {
  1765. output.add(this.value, this._fileInfo, this._index, this.mapLines);
  1766. }
  1767. }
  1768. }]);
  1769. return Anonymous;
  1770. }(Node);
  1771. Anonymous.prototype.type = 'Anonymous';
  1772. var MATH = Math$1;
  1773. var Declaration =
  1774. /*#__PURE__*/
  1775. function (_Node) {
  1776. _inherits(Declaration, _Node);
  1777. function Declaration(name, value, important, merge, index, currentFileInfo, inline, variable) {
  1778. var _this;
  1779. _classCallCheck(this, Declaration);
  1780. _this = _possibleConstructorReturn(this, _getPrototypeOf(Declaration).call(this));
  1781. _this.name = name;
  1782. _this.value = value instanceof Node ? value : new Value([value ? new Anonymous(value) : null]);
  1783. _this.important = important ? " ".concat(important.trim()) : '';
  1784. _this.merge = merge;
  1785. _this._index = index;
  1786. _this._fileInfo = currentFileInfo;
  1787. _this.inline = inline || false;
  1788. _this.variable = variable !== undefined ? variable : name.charAt && name.charAt(0) === '@';
  1789. _this.allowRoot = true;
  1790. _this.setParent(_this.value, _assertThisInitialized(_this));
  1791. return _this;
  1792. }
  1793. _createClass(Declaration, [{
  1794. key: "genCSS",
  1795. value: function genCSS(context, output) {
  1796. output.add(this.name + (context.compress ? ':' : ': '), this.fileInfo(), this.getIndex());
  1797. try {
  1798. this.value.genCSS(context, output);
  1799. } catch (e) {
  1800. e.index = this._index;
  1801. e.filename = this._fileInfo.filename;
  1802. throw e;
  1803. }
  1804. output.add(this.important + (this.inline || context.lastRule && context.compress ? '' : ';'), this._fileInfo, this._index);
  1805. }
  1806. }, {
  1807. key: "eval",
  1808. value: function _eval(context) {
  1809. var mathBypass = false;
  1810. var prevMath;
  1811. var name = this.name;
  1812. var evaldValue;
  1813. var variable = this.variable;
  1814. if (typeof name !== 'string') {
  1815. // expand 'primitive' name directly to get
  1816. // things faster (~10% for benchmark.less):
  1817. name = name.length === 1 && name[0] instanceof Keyword ? name[0].value : evalName(context, name);
  1818. variable = false; // never treat expanded interpolation as new variable name
  1819. } // @todo remove when parens-division is default
  1820. if (name === 'font' && context.math === MATH.ALWAYS) {
  1821. mathBypass = true;
  1822. prevMath = context.math;
  1823. context.math = MATH.PARENS_DIVISION;
  1824. }
  1825. try {
  1826. context.importantScope.push({});
  1827. evaldValue = this.value.eval(context);
  1828. if (!this.variable && evaldValue.type === 'DetachedRuleset') {
  1829. throw {
  1830. message: 'Rulesets cannot be evaluated on a property.',
  1831. index: this.getIndex(),
  1832. filename: this.fileInfo().filename
  1833. };
  1834. }
  1835. var important = this.important;
  1836. var importantResult = context.importantScope.pop();
  1837. if (!important && importantResult.important) {
  1838. important = importantResult.important;
  1839. }
  1840. return new Declaration(name, evaldValue, important, this.merge, this.getIndex(), this.fileInfo(), this.inline, variable);
  1841. } catch (e) {
  1842. if (typeof e.index !== 'number') {
  1843. e.index = this.getIndex();
  1844. e.filename = this.fileInfo().filename;
  1845. }
  1846. throw e;
  1847. } finally {
  1848. if (mathBypass) {
  1849. context.math = prevMath;
  1850. }
  1851. }
  1852. }
  1853. }, {
  1854. key: "makeImportant",
  1855. value: function makeImportant() {
  1856. return new Declaration(this.name, this.value, '!important', this.merge, this.getIndex(), this.fileInfo(), this.inline);
  1857. }
  1858. }]);
  1859. return Declaration;
  1860. }(Node);
  1861. function evalName(context, name) {
  1862. var value = '';
  1863. var i;
  1864. var n = name.length;
  1865. var output = {
  1866. add: function add(s) {
  1867. value += s;
  1868. }
  1869. };
  1870. for (i = 0; i < n; i++) {
  1871. name[i].eval(context).genCSS(context, output);
  1872. }
  1873. return value;
  1874. }
  1875. Declaration.prototype.type = 'Declaration';
  1876. var debugInfo = function debugInfo(context, ctx, lineSeparator) {
  1877. var result = '';
  1878. if (context.dumpLineNumbers && !context.compress) {
  1879. switch (context.dumpLineNumbers) {
  1880. case 'comments':
  1881. result = debugInfo.asComment(ctx);
  1882. break;
  1883. case 'mediaquery':
  1884. result = debugInfo.asMediaQuery(ctx);
  1885. break;
  1886. case 'all':
  1887. result = debugInfo.asComment(ctx) + (lineSeparator || '') + debugInfo.asMediaQuery(ctx);
  1888. break;
  1889. }
  1890. }
  1891. return result;
  1892. };
  1893. debugInfo.asComment = function (ctx) {
  1894. return "/* line ".concat(ctx.debugInfo.lineNumber, ", ").concat(ctx.debugInfo.fileName, " */\n");
  1895. };
  1896. debugInfo.asMediaQuery = function (ctx) {
  1897. var filenameWithProtocol = ctx.debugInfo.fileName;
  1898. if (!/^[a-z]+:\/\//i.test(filenameWithProtocol)) {
  1899. filenameWithProtocol = "file://".concat(filenameWithProtocol);
  1900. }
  1901. return "@media -sass-debug-info{filename{font-family:".concat(filenameWithProtocol.replace(/([.:\/\\])/g, function (a) {
  1902. if (a == '\\') {
  1903. a = '\/';
  1904. }
  1905. return "\\".concat(a);
  1906. }), "}line{font-family:\\00003").concat(ctx.debugInfo.lineNumber, "}}\n");
  1907. };
  1908. var Comment =
  1909. /*#__PURE__*/
  1910. function (_Node) {
  1911. _inherits(Comment, _Node);
  1912. function Comment(value, isLineComment, index, currentFileInfo) {
  1913. var _this;
  1914. _classCallCheck(this, Comment);
  1915. _this = _possibleConstructorReturn(this, _getPrototypeOf(Comment).call(this));
  1916. _this.value = value;
  1917. _this.isLineComment = isLineComment;
  1918. _this._index = index;
  1919. _this._fileInfo = currentFileInfo;
  1920. _this.allowRoot = true;
  1921. return _this;
  1922. }
  1923. _createClass(Comment, [{
  1924. key: "genCSS",
  1925. value: function genCSS(context, output) {
  1926. if (this.debugInfo) {
  1927. output.add(debugInfo(context, this), this.fileInfo(), this.getIndex());
  1928. }
  1929. output.add(this.value);
  1930. }
  1931. }, {
  1932. key: "isSilent",
  1933. value: function isSilent(context) {
  1934. var isCompressed = context.compress && this.value[2] !== '!';
  1935. return this.isLineComment || isCompressed;
  1936. }
  1937. }]);
  1938. return Comment;
  1939. }(Node);
  1940. Comment.prototype.type = 'Comment';
  1941. var contexts = {};
  1942. var copyFromOriginal = function copyFromOriginal(original, destination, propertiesToCopy) {
  1943. if (!original) {
  1944. return;
  1945. }
  1946. for (var i = 0; i < propertiesToCopy.length; i++) {
  1947. if (original.hasOwnProperty(propertiesToCopy[i])) {
  1948. destination[propertiesToCopy[i]] = original[propertiesToCopy[i]];
  1949. }
  1950. }
  1951. };
  1952. /*
  1953. parse is used whilst parsing
  1954. */
  1955. var parseCopyProperties = [// options
  1956. 'paths', // option - unmodified - paths to search for imports on
  1957. 'rewriteUrls', // option - whether to adjust URL's to be relative
  1958. 'rootpath', // option - rootpath to append to URL's
  1959. 'strictImports', // option -
  1960. 'insecure', // option - whether to allow imports from insecure ssl hosts
  1961. 'dumpLineNumbers', // option - whether to dump line numbers
  1962. 'compress', // option - whether to compress
  1963. 'syncImport', // option - whether to import synchronously
  1964. 'chunkInput', // option - whether to chunk input. more performant but causes parse issues.
  1965. 'mime', // browser only - mime type for sheet import
  1966. 'useFileCache', // browser only - whether to use the per file session cache
  1967. // context
  1968. 'processImports', // option & context - whether to process imports. if false then imports will not be imported.
  1969. // Used by the import manager to stop multiple import visitors being created.
  1970. 'pluginManager' // Used as the plugin manager for the session
  1971. ];
  1972. contexts.Parse = function (options) {
  1973. copyFromOriginal(options, this, parseCopyProperties);
  1974. if (typeof this.paths === 'string') {
  1975. this.paths = [this.paths];
  1976. }
  1977. };
  1978. var evalCopyProperties = ['paths', // additional include paths
  1979. 'compress', // whether to compress
  1980. 'math', // whether math has to be within parenthesis
  1981. 'strictUnits', // whether units need to evaluate correctly
  1982. 'sourceMap', // whether to output a source map
  1983. 'importMultiple', // whether we are currently importing multiple copies
  1984. 'urlArgs', // whether to add args into url tokens
  1985. 'javascriptEnabled', // option - whether Inline JavaScript is enabled. if undefined, defaults to false
  1986. 'pluginManager', // Used as the plugin manager for the session
  1987. 'importantScope', // used to bubble up !important statements
  1988. 'rewriteUrls' // option - whether to adjust URL's to be relative
  1989. ];
  1990. function isPathRelative(path) {
  1991. return !/^(?:[a-z-]+:|\/|#)/i.test(path);
  1992. }
  1993. function isPathLocalRelative(path) {
  1994. return path.charAt(0) === '.';
  1995. }
  1996. contexts.Eval =
  1997. /*#__PURE__*/
  1998. function () {
  1999. function _class(options, frames) {
  2000. _classCallCheck(this, _class);
  2001. copyFromOriginal(options, this, evalCopyProperties);
  2002. if (typeof this.paths === 'string') {
  2003. this.paths = [this.paths];
  2004. }
  2005. this.frames = frames || [];
  2006. this.importantScope = this.importantScope || [];
  2007. this.inCalc = false;
  2008. this.mathOn = true;
  2009. }
  2010. _createClass(_class, [{
  2011. key: "enterCalc",
  2012. value: function enterCalc() {
  2013. if (!this.calcStack) {
  2014. this.calcStack = [];
  2015. }
  2016. this.calcStack.push(true);
  2017. this.inCalc = true;
  2018. }
  2019. }, {
  2020. key: "exitCalc",
  2021. value: function exitCalc() {
  2022. this.calcStack.pop();
  2023. if (!this.calcStack) {
  2024. this.inCalc = false;
  2025. }
  2026. }
  2027. }, {
  2028. key: "inParenthesis",
  2029. value: function inParenthesis() {
  2030. if (!this.parensStack) {
  2031. this.parensStack = [];
  2032. }
  2033. this.parensStack.push(true);
  2034. }
  2035. }, {
  2036. key: "outOfParenthesis",
  2037. value: function outOfParenthesis() {
  2038. this.parensStack.pop();
  2039. }
  2040. }, {
  2041. key: "isMathOn",
  2042. value: function isMathOn(op) {
  2043. if (!this.mathOn) {
  2044. return false;
  2045. }
  2046. if (op === '/' && this.math !== Math$1.ALWAYS && (!this.parensStack || !this.parensStack.length)) {
  2047. return false;
  2048. }
  2049. if (this.math > Math$1.PARENS_DIVISION) {
  2050. return this.parensStack && this.parensStack.length;
  2051. }
  2052. return true;
  2053. }
  2054. }, {
  2055. key: "pathRequiresRewrite",
  2056. value: function pathRequiresRewrite(path) {
  2057. var isRelative = this.rewriteUrls === RewriteUrls.LOCAL ? isPathLocalRelative : isPathRelative;
  2058. return isRelative(path);
  2059. }
  2060. }, {
  2061. key: "rewritePath",
  2062. value: function rewritePath(path, rootpath) {
  2063. var newPath;
  2064. rootpath = rootpath || '';
  2065. newPath = this.normalizePath(rootpath + path); // If a path was explicit relative and the rootpath was not an absolute path
  2066. // we must ensure that the new path is also explicit relative.
  2067. if (isPathLocalRelative(path) && isPathRelative(rootpath) && isPathLocalRelative(newPath) === false) {
  2068. newPath = "./".concat(newPath);
  2069. }
  2070. return newPath;
  2071. }
  2072. }, {
  2073. key: "normalizePath",
  2074. value: function normalizePath(path) {
  2075. var segments = path.split('/').reverse();
  2076. var segment;
  2077. path = [];
  2078. while (segments.length !== 0) {
  2079. segment = segments.pop();
  2080. switch (segment) {
  2081. case '.':
  2082. break;
  2083. case '..':
  2084. if (path.length === 0 || path[path.length - 1] === '..') {
  2085. path.push(segment);
  2086. } else {
  2087. path.pop();
  2088. }
  2089. break;
  2090. default:
  2091. path.push(segment);
  2092. break;
  2093. }
  2094. }
  2095. return path.join('/');
  2096. }
  2097. }]);
  2098. return _class;
  2099. }();
  2100. function makeRegistry(base) {
  2101. return {
  2102. _data: {},
  2103. add: function add(name, func) {
  2104. // precautionary case conversion, as later querying of
  2105. // the registry by function-caller uses lower case as well.
  2106. name = name.toLowerCase();
  2107. if (this._data.hasOwnProperty(name)) ;
  2108. this._data[name] = func;
  2109. },
  2110. addMultiple: function addMultiple(functions) {
  2111. var _this = this;
  2112. Object.keys(functions).forEach(function (name) {
  2113. _this.add(name, functions[name]);
  2114. });
  2115. },
  2116. get: function get(name) {
  2117. return this._data[name] || base && base.get(name);
  2118. },
  2119. getLocalFunctions: function getLocalFunctions() {
  2120. return this._data;
  2121. },
  2122. inherit: function inherit() {
  2123. return makeRegistry(this);
  2124. },
  2125. create: function create(base) {
  2126. return makeRegistry(base);
  2127. }
  2128. };
  2129. }
  2130. var functionRegistry = makeRegistry(null);
  2131. var defaultFunc = {
  2132. eval: function _eval() {
  2133. var v = this.value_;
  2134. var e = this.error_;
  2135. if (e) {
  2136. throw e;
  2137. }
  2138. if (v != null) {
  2139. return v ? Keyword.True : Keyword.False;
  2140. }
  2141. },
  2142. value: function value(v) {
  2143. this.value_ = v;
  2144. },
  2145. error: function error(e) {
  2146. this.error_ = e;
  2147. },
  2148. reset: function reset() {
  2149. this.value_ = this.error_ = null;
  2150. }
  2151. };
  2152. var Ruleset =
  2153. /*#__PURE__*/
  2154. function (_Node) {
  2155. _inherits(Ruleset, _Node);
  2156. function Ruleset(selectors, rules, strictImports, visibilityInfo) {
  2157. var _this;
  2158. _classCallCheck(this, Ruleset);
  2159. _this = _possibleConstructorReturn(this, _getPrototypeOf(Ruleset).call(this));
  2160. _this.selectors = selectors;
  2161. _this.rules = rules;
  2162. _this._lookups = {};
  2163. _this._variables = null;
  2164. _this._properties = null;
  2165. _this.strictImports = strictImports;
  2166. _this.copyVisibilityInfo(visibilityInfo);
  2167. _this.allowRoot = true;
  2168. _this.setParent(_this.selectors, _assertThisInitialized(_this));
  2169. _this.setParent(_this.rules, _assertThisInitialized(_this));
  2170. return _this;
  2171. }
  2172. _createClass(Ruleset, [{
  2173. key: "isRulesetLike",
  2174. value: function isRulesetLike() {
  2175. return true;
  2176. }
  2177. }, {
  2178. key: "accept",
  2179. value: function accept(visitor) {
  2180. if (this.paths) {
  2181. this.paths = visitor.visitArray(this.paths, true);
  2182. } else if (this.selectors) {
  2183. this.selectors = visitor.visitArray(this.selectors);
  2184. }
  2185. if (this.rules && this.rules.length) {
  2186. this.rules = visitor.visitArray(this.rules);
  2187. }
  2188. }
  2189. }, {
  2190. key: "eval",
  2191. value: function _eval(context) {
  2192. var selectors;
  2193. var selCnt;
  2194. var selector;
  2195. var i;
  2196. var hasVariable;
  2197. var hasOnePassingSelector = false;
  2198. if (this.selectors && (selCnt = this.selectors.length)) {
  2199. selectors = new Array(selCnt);
  2200. defaultFunc.error({
  2201. type: 'Syntax',
  2202. message: 'it is currently only allowed in parametric mixin guards,'
  2203. });
  2204. for (i = 0; i < selCnt; i++) {
  2205. selector = this.selectors[i].eval(context);
  2206. for (var j = 0; j < selector.elements.length; j++) {
  2207. if (selector.elements[j].isVariable) {
  2208. hasVariable = true;
  2209. break;
  2210. }
  2211. }
  2212. selectors[i] = selector;
  2213. if (selector.evaldCondition) {
  2214. hasOnePassingSelector = true;
  2215. }
  2216. }
  2217. if (hasVariable) {
  2218. var toParseSelectors = new Array(selCnt);
  2219. for (i = 0; i < selCnt; i++) {
  2220. selector = selectors[i];
  2221. toParseSelectors[i] = selector.toCSS(context);
  2222. }
  2223. this.parse.parseNode(toParseSelectors.join(','), ["selectors"], selectors[0].getIndex(), selectors[0].fileInfo(), function (err, result) {
  2224. if (result) {
  2225. selectors = flattenArray(result);
  2226. }
  2227. });
  2228. }
  2229. defaultFunc.reset();
  2230. } else {
  2231. hasOnePassingSelector = true;
  2232. }
  2233. var rules = this.rules ? copyArray(this.rules) : null;
  2234. var ruleset = new Ruleset(selectors, rules, this.strictImports, this.visibilityInfo());
  2235. var rule;
  2236. var subRule;
  2237. ruleset.originalRuleset = this;
  2238. ruleset.root = this.root;
  2239. ruleset.firstRoot = this.firstRoot;
  2240. ruleset.allowImports = this.allowImports;
  2241. if (this.debugInfo) {
  2242. ruleset.debugInfo = this.debugInfo;
  2243. }
  2244. if (!hasOnePassingSelector) {
  2245. rules.length = 0;
  2246. } // inherit a function registry from the frames stack when possible;
  2247. // otherwise from the global registry
  2248. ruleset.functionRegistry = function (frames) {
  2249. var i = 0;
  2250. var n = frames.length;
  2251. var found;
  2252. for (; i !== n; ++i) {
  2253. found = frames[i].functionRegistry;
  2254. if (found) {
  2255. return found;
  2256. }
  2257. }
  2258. return functionRegistry;
  2259. }(context.frames).inherit(); // push the current ruleset to the frames stack
  2260. var ctxFrames = context.frames;
  2261. ctxFrames.unshift(ruleset); // currrent selectors
  2262. var ctxSelectors = context.selectors;
  2263. if (!ctxSelectors) {
  2264. context.selectors = ctxSelectors = [];
  2265. }
  2266. ctxSelectors.unshift(this.selectors); // Evaluate imports
  2267. if (ruleset.root || ruleset.allowImports || !ruleset.strictImports) {
  2268. ruleset.evalImports(context);
  2269. } // Store the frames around mixin definitions,
  2270. // so they can be evaluated like closures when the time comes.
  2271. var rsRules = ruleset.rules;
  2272. for (i = 0; rule = rsRules[i]; i++) {
  2273. if (rule.evalFirst) {
  2274. rsRules[i] = rule.eval(context);
  2275. }
  2276. }
  2277. var mediaBlockCount = context.mediaBlocks && context.mediaBlocks.length || 0; // Evaluate mixin calls.
  2278. for (i = 0; rule = rsRules[i]; i++) {
  2279. if (rule.type === 'MixinCall') {
  2280. /* jshint loopfunc:true */
  2281. rules = rule.eval(context).filter(function (r) {
  2282. if (r instanceof Declaration && r.variable) {
  2283. // do not pollute the scope if the variable is
  2284. // already there. consider returning false here
  2285. // but we need a way to "return" variable from mixins
  2286. return !ruleset.variable(r.name);
  2287. }
  2288. return true;
  2289. });
  2290. rsRules.splice.apply(rsRules, _toConsumableArray([i, 1].concat(rules)));
  2291. i += rules.length - 1;
  2292. ruleset.resetCache();
  2293. } else if (rule.type === 'VariableCall') {
  2294. /* jshint loopfunc:true */
  2295. rules = rule.eval(context).rules.filter(function (r) {
  2296. if (r instanceof Declaration && r.variable) {
  2297. // do not pollute the scope at all
  2298. return false;
  2299. }
  2300. return true;
  2301. });
  2302. rsRules.splice.apply(rsRules, _toConsumableArray([i, 1].concat(rules)));
  2303. i += rules.length - 1;
  2304. ruleset.resetCache();
  2305. }
  2306. } // Evaluate everything else
  2307. for (i = 0; rule = rsRules[i]; i++) {
  2308. if (!rule.evalFirst) {
  2309. rsRules[i] = rule = rule.eval ? rule.eval(context) : rule;
  2310. }
  2311. } // Evaluate everything else
  2312. for (i = 0; rule = rsRules[i]; i++) {
  2313. // for rulesets, check if it is a css guard and can be removed
  2314. if (rule instanceof Ruleset && rule.selectors && rule.selectors.length === 1) {
  2315. // check if it can be folded in (e.g. & where)
  2316. if (rule.selectors[0] && rule.selectors[0].isJustParentSelector()) {
  2317. rsRules.splice(i--, 1);
  2318. for (var j = 0; subRule = rule.rules[j]; j++) {
  2319. if (subRule instanceof Node) {
  2320. subRule.copyVisibilityInfo(rule.visibilityInfo());
  2321. if (!(subRule instanceof Declaration) || !subRule.variable) {
  2322. rsRules.splice(++i, 0, subRule);
  2323. }
  2324. }
  2325. }
  2326. }
  2327. }
  2328. } // Pop the stack
  2329. ctxFrames.shift();
  2330. ctxSelectors.shift();
  2331. if (context.mediaBlocks) {
  2332. for (i = mediaBlockCount; i < context.mediaBlocks.length; i++) {
  2333. context.mediaBlocks[i].bubbleSelectors(selectors);
  2334. }
  2335. }
  2336. return ruleset;
  2337. }
  2338. }, {
  2339. key: "evalImports",
  2340. value: function evalImports(context) {
  2341. var rules = this.rules;
  2342. var i;
  2343. var importRules;
  2344. if (!rules) {
  2345. return;
  2346. }
  2347. for (i = 0; i < rules.length; i++) {
  2348. if (rules[i].type === 'Import') {
  2349. importRules = rules[i].eval(context);
  2350. if (importRules && (importRules.length || importRules.length === 0)) {
  2351. rules.splice.apply(rules, _toConsumableArray([i, 1].concat(importRules)));
  2352. i += importRules.length - 1;
  2353. } else {
  2354. rules.splice(i, 1, importRules);
  2355. }
  2356. this.resetCache();
  2357. }
  2358. }
  2359. }
  2360. }, {
  2361. key: "makeImportant",
  2362. value: function makeImportant() {
  2363. var result = new Ruleset(this.selectors, this.rules.map(function (r) {
  2364. if (r.makeImportant) {
  2365. return r.makeImportant();
  2366. } else {
  2367. return r;
  2368. }
  2369. }), this.strictImports, this.visibilityInfo());
  2370. return result;
  2371. }
  2372. }, {
  2373. key: "matchArgs",
  2374. value: function matchArgs(args) {
  2375. return !args || args.length === 0;
  2376. } // lets you call a css selector with a guard
  2377. }, {
  2378. key: "matchCondition",
  2379. value: function matchCondition(args, context) {
  2380. var lastSelector = this.selectors[this.selectors.length - 1];
  2381. if (!lastSelector.evaldCondition) {
  2382. return false;
  2383. }
  2384. if (lastSelector.condition && !lastSelector.condition.eval(new contexts.Eval(context, context.frames))) {
  2385. return false;
  2386. }
  2387. return true;
  2388. }
  2389. }, {
  2390. key: "resetCache",
  2391. value: function resetCache() {
  2392. this._rulesets = null;
  2393. this._variables = null;
  2394. this._properties = null;
  2395. this._lookups = {};
  2396. }
  2397. }, {
  2398. key: "variables",
  2399. value: function variables() {
  2400. if (!this._variables) {
  2401. this._variables = !this.rules ? {} : this.rules.reduce(function (hash, r) {
  2402. if (r instanceof Declaration && r.variable === true) {
  2403. hash[r.name] = r;
  2404. } // when evaluating variables in an import statement, imports have not been eval'd
  2405. // so we need to go inside import statements.
  2406. // guard against root being a string (in the case of inlined less)
  2407. if (r.type === 'Import' && r.root && r.root.variables) {
  2408. var vars = r.root.variables();
  2409. for (var name in vars) {
  2410. if (vars.hasOwnProperty(name)) {
  2411. hash[name] = r.root.variable(name);
  2412. }
  2413. }
  2414. }
  2415. return hash;
  2416. }, {});
  2417. }
  2418. return this._variables;
  2419. }
  2420. }, {
  2421. key: "properties",
  2422. value: function properties() {
  2423. if (!this._properties) {
  2424. this._properties = !this.rules ? {} : this.rules.reduce(function (hash, r) {
  2425. if (r instanceof Declaration && r.variable !== true) {
  2426. var name = r.name.length === 1 && r.name[0] instanceof Keyword ? r.name[0].value : r.name; // Properties don't overwrite as they can merge
  2427. if (!hash["$".concat(name)]) {
  2428. hash["$".concat(name)] = [r];
  2429. } else {
  2430. hash["$".concat(name)].push(r);
  2431. }
  2432. }
  2433. return hash;
  2434. }, {});
  2435. }
  2436. return this._properties;
  2437. }
  2438. }, {
  2439. key: "variable",
  2440. value: function variable(name) {
  2441. var decl = this.variables()[name];
  2442. if (decl) {
  2443. return this.parseValue(decl);
  2444. }
  2445. }
  2446. }, {
  2447. key: "property",
  2448. value: function property(name) {
  2449. var decl = this.properties()[name];
  2450. if (decl) {
  2451. return this.parseValue(decl);
  2452. }
  2453. }
  2454. }, {
  2455. key: "lastDeclaration",
  2456. value: function lastDeclaration() {
  2457. for (var i = this.rules.length; i > 0; i--) {
  2458. var decl = this.rules[i - 1];
  2459. if (decl instanceof Declaration) {
  2460. return this.parseValue(decl);
  2461. }
  2462. }
  2463. }
  2464. }, {
  2465. key: "parseValue",
  2466. value: function parseValue(toParse) {
  2467. var self = this;
  2468. function transformDeclaration(decl) {
  2469. if (decl.value instanceof Anonymous && !decl.parsed) {
  2470. if (typeof decl.value.value === 'string') {
  2471. this.parse.parseNode(decl.value.value, ['value', 'important'], decl.value.getIndex(), decl.fileInfo(), function (err, result) {
  2472. if (err) {
  2473. decl.parsed = true;
  2474. }
  2475. if (result) {
  2476. decl.value = result[0];
  2477. decl.important = result[1] || '';
  2478. decl.parsed = true;
  2479. }
  2480. });
  2481. } else {
  2482. decl.parsed = true;
  2483. }
  2484. return decl;
  2485. } else {
  2486. return decl;
  2487. }
  2488. }
  2489. if (!Array.isArray(toParse)) {
  2490. return transformDeclaration.call(self, toParse);
  2491. } else {
  2492. var nodes = [];
  2493. toParse.forEach(function (n) {
  2494. nodes.push(transformDeclaration.call(self, n));
  2495. });
  2496. return nodes;
  2497. }
  2498. }
  2499. }, {
  2500. key: "rulesets",
  2501. value: function rulesets() {
  2502. if (!this.rules) {
  2503. return [];
  2504. }
  2505. var filtRules = [];
  2506. var rules = this.rules;
  2507. var i;
  2508. var rule;
  2509. for (i = 0; rule = rules[i]; i++) {
  2510. if (rule.isRuleset) {
  2511. filtRules.push(rule);
  2512. }
  2513. }
  2514. return filtRules;
  2515. }
  2516. }, {
  2517. key: "prependRule",
  2518. value: function prependRule(rule) {
  2519. var rules = this.rules;
  2520. if (rules) {
  2521. rules.unshift(rule);
  2522. } else {
  2523. this.rules = [rule];
  2524. }
  2525. this.setParent(rule, this);
  2526. }
  2527. }, {
  2528. key: "find",
  2529. value: function find(selector) {
  2530. var self = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this;
  2531. var filter = arguments.length > 2 ? arguments[2] : undefined;
  2532. var rules = [];
  2533. var match;
  2534. var foundMixins;
  2535. var key = selector.toCSS();
  2536. if (key in this._lookups) {
  2537. return this._lookups[key];
  2538. }
  2539. this.rulesets().forEach(function (rule) {
  2540. if (rule !== self) {
  2541. for (var j = 0; j < rule.selectors.length; j++) {
  2542. match = selector.match(rule.selectors[j]);
  2543. if (match) {
  2544. if (selector.elements.length > match) {
  2545. if (!filter || filter(rule)) {
  2546. foundMixins = rule.find(new Selector(selector.elements.slice(match)), self, filter);
  2547. for (var i = 0; i < foundMixins.length; ++i) {
  2548. foundMixins[i].path.push(rule);
  2549. }
  2550. Array.prototype.push.apply(rules, foundMixins);
  2551. }
  2552. } else {
  2553. rules.push({
  2554. rule: rule,
  2555. path: []
  2556. });
  2557. }
  2558. break;
  2559. }
  2560. }
  2561. }
  2562. });
  2563. this._lookups[key] = rules;
  2564. return rules;
  2565. }
  2566. }, {
  2567. key: "genCSS",
  2568. value: function genCSS(context, output) {
  2569. var i;
  2570. var j;
  2571. var charsetRuleNodes = [];
  2572. var ruleNodes = [];
  2573. var // Line number debugging
  2574. debugInfo$1;
  2575. var rule;
  2576. var path;
  2577. context.tabLevel = context.tabLevel || 0;
  2578. if (!this.root) {
  2579. context.tabLevel++;
  2580. }
  2581. var tabRuleStr = context.compress ? '' : Array(context.tabLevel + 1).join(' ');
  2582. var tabSetStr = context.compress ? '' : Array(context.tabLevel).join(' ');
  2583. var sep;
  2584. var charsetNodeIndex = 0;
  2585. var importNodeIndex = 0;
  2586. for (i = 0; rule = this.rules[i]; i++) {
  2587. if (rule instanceof Comment) {
  2588. if (importNodeIndex === i) {
  2589. importNodeIndex++;
  2590. }
  2591. ruleNodes.push(rule);
  2592. } else if (rule.isCharset && rule.isCharset()) {
  2593. ruleNodes.splice(charsetNodeIndex, 0, rule);
  2594. charsetNodeIndex++;
  2595. importNodeIndex++;
  2596. } else if (rule.type === 'Import') {
  2597. ruleNodes.splice(importNodeIndex, 0, rule);
  2598. importNodeIndex++;
  2599. } else {
  2600. ruleNodes.push(rule);
  2601. }
  2602. }
  2603. ruleNodes = charsetRuleNodes.concat(ruleNodes); // If this is the root node, we don't render
  2604. // a selector, or {}.
  2605. if (!this.root) {
  2606. debugInfo$1 = debugInfo(context, this, tabSetStr);
  2607. if (debugInfo$1) {
  2608. output.add(debugInfo$1);
  2609. output.add(tabSetStr);
  2610. }
  2611. var paths = this.paths;
  2612. var pathCnt = paths.length;
  2613. var pathSubCnt;
  2614. sep = context.compress ? ',' : ",\n".concat(tabSetStr);
  2615. for (i = 0; i < pathCnt; i++) {
  2616. path = paths[i];
  2617. if (!(pathSubCnt = path.length)) {
  2618. continue;
  2619. }
  2620. if (i > 0) {
  2621. output.add(sep);
  2622. }
  2623. context.firstSelector = true;
  2624. path[0].genCSS(context, output);
  2625. context.firstSelector = false;
  2626. for (j = 1; j < pathSubCnt; j++) {
  2627. path[j].genCSS(context, output);
  2628. }
  2629. }
  2630. output.add((context.compress ? '{' : ' {\n') + tabRuleStr);
  2631. } // Compile rules and rulesets
  2632. for (i = 0; rule = ruleNodes[i]; i++) {
  2633. if (i + 1 === ruleNodes.length) {
  2634. context.lastRule = true;
  2635. }
  2636. var currentLastRule = context.lastRule;
  2637. if (rule.isRulesetLike(rule)) {
  2638. context.lastRule = false;
  2639. }
  2640. if (rule.genCSS) {
  2641. rule.genCSS(context, output);
  2642. } else if (rule.value) {
  2643. output.add(rule.value.toString());
  2644. }
  2645. context.lastRule = currentLastRule;
  2646. if (!context.lastRule && rule.isVisible()) {
  2647. output.add(context.compress ? '' : "\n".concat(tabRuleStr));
  2648. } else {
  2649. context.lastRule = false;
  2650. }
  2651. }
  2652. if (!this.root) {
  2653. output.add(context.compress ? '}' : "\n".concat(tabSetStr, "}"));
  2654. context.tabLevel--;
  2655. }
  2656. if (!output.isEmpty() && !context.compress && this.firstRoot) {
  2657. output.add('\n');
  2658. }
  2659. }
  2660. }, {
  2661. key: "joinSelectors",
  2662. value: function joinSelectors(paths, context, selectors) {
  2663. for (var s = 0; s < selectors.length; s++) {
  2664. this.joinSelector(paths, context, selectors[s]);
  2665. }
  2666. }
  2667. }, {
  2668. key: "joinSelector",
  2669. value: function joinSelector(paths, context, selector) {
  2670. function createParenthesis(elementsToPak, originalElement) {
  2671. var replacementParen;
  2672. var j;
  2673. if (elementsToPak.length === 0) {
  2674. replacementParen = new Paren(elementsToPak[0]);
  2675. } else {
  2676. var insideParent = new Array(elementsToPak.length);
  2677. for (j = 0; j < elementsToPak.length; j++) {
  2678. insideParent[j] = new Element(null, elementsToPak[j], originalElement.isVariable, originalElement._index, originalElement._fileInfo);
  2679. }
  2680. replacementParen = new Paren(new Selector(insideParent));
  2681. }
  2682. return replacementParen;
  2683. }
  2684. function createSelector(containedElement, originalElement) {
  2685. var element;
  2686. var selector;
  2687. element = new Element(null, containedElement, originalElement.isVariable, originalElement._index, originalElement._fileInfo);
  2688. selector = new Selector([element]);
  2689. return selector;
  2690. } // joins selector path from `beginningPath` with selector path in `addPath`
  2691. // `replacedElement` contains element that is being replaced by `addPath`
  2692. // returns concatenated path
  2693. function addReplacementIntoPath(beginningPath, addPath, replacedElement, originalSelector) {
  2694. var newSelectorPath;
  2695. var lastSelector;
  2696. var newJoinedSelector; // our new selector path
  2697. newSelectorPath = []; // construct the joined selector - if & is the first thing this will be empty,
  2698. // if not newJoinedSelector will be the last set of elements in the selector
  2699. if (beginningPath.length > 0) {
  2700. newSelectorPath = copyArray(beginningPath);
  2701. lastSelector = newSelectorPath.pop();
  2702. newJoinedSelector = originalSelector.createDerived(copyArray(lastSelector.elements));
  2703. } else {
  2704. newJoinedSelector = originalSelector.createDerived([]);
  2705. }
  2706. if (addPath.length > 0) {
  2707. // /deep/ is a CSS4 selector - (removed, so should deprecate)
  2708. // that is valid without anything in front of it
  2709. // so if the & does not have a combinator that is "" or " " then
  2710. // and there is a combinator on the parent, then grab that.
  2711. // this also allows + a { & .b { .a & { ... though not sure why you would want to do that
  2712. var combinator = replacedElement.combinator;
  2713. var parentEl = addPath[0].elements[0];
  2714. if (combinator.emptyOrWhitespace && !parentEl.combinator.emptyOrWhitespace) {
  2715. combinator = parentEl.combinator;
  2716. } // join the elements so far with the first part of the parent
  2717. newJoinedSelector.elements.push(new Element(combinator, parentEl.value, replacedElement.isVariable, replacedElement._index, replacedElement._fileInfo));
  2718. newJoinedSelector.elements = newJoinedSelector.elements.concat(addPath[0].elements.slice(1));
  2719. } // now add the joined selector - but only if it is not empty
  2720. if (newJoinedSelector.elements.length !== 0) {
  2721. newSelectorPath.push(newJoinedSelector);
  2722. } // put together the parent selectors after the join (e.g. the rest of the parent)
  2723. if (addPath.length > 1) {
  2724. var restOfPath = addPath.slice(1);
  2725. restOfPath = restOfPath.map(function (selector) {
  2726. return selector.createDerived(selector.elements, []);
  2727. });
  2728. newSelectorPath = newSelectorPath.concat(restOfPath);
  2729. }
  2730. return newSelectorPath;
  2731. } // joins selector path from `beginningPath` with every selector path in `addPaths` array
  2732. // `replacedElement` contains element that is being replaced by `addPath`
  2733. // returns array with all concatenated paths
  2734. function addAllReplacementsIntoPath(beginningPath, addPaths, replacedElement, originalSelector, result) {
  2735. var j;
  2736. for (j = 0; j < beginningPath.length; j++) {
  2737. var newSelectorPath = addReplacementIntoPath(beginningPath[j], addPaths, replacedElement, originalSelector);
  2738. result.push(newSelectorPath);
  2739. }
  2740. return result;
  2741. }
  2742. function mergeElementsOnToSelectors(elements, selectors) {
  2743. var i;
  2744. var sel;
  2745. if (elements.length === 0) {
  2746. return;
  2747. }
  2748. if (selectors.length === 0) {
  2749. selectors.push([new Selector(elements)]);
  2750. return;
  2751. }
  2752. for (i = 0; sel = selectors[i]; i++) {
  2753. // if the previous thing in sel is a parent this needs to join on to it
  2754. if (sel.length > 0) {
  2755. sel[sel.length - 1] = sel[sel.length - 1].createDerived(sel[sel.length - 1].elements.concat(elements));
  2756. } else {
  2757. sel.push(new Selector(elements));
  2758. }
  2759. }
  2760. } // replace all parent selectors inside `inSelector` by content of `context` array
  2761. // resulting selectors are returned inside `paths` array
  2762. // returns true if `inSelector` contained at least one parent selector
  2763. function replaceParentSelector(paths, context, inSelector) {
  2764. // The paths are [[Selector]]
  2765. // The first list is a list of comma separated selectors
  2766. // The inner list is a list of inheritance separated selectors
  2767. // e.g.
  2768. // .a, .b {
  2769. // .c {
  2770. // }
  2771. // }
  2772. // == [[.a] [.c]] [[.b] [.c]]
  2773. //
  2774. var i;
  2775. var j;
  2776. var k;
  2777. var currentElements;
  2778. var newSelectors;
  2779. var selectorsMultiplied;
  2780. var sel;
  2781. var el;
  2782. var hadParentSelector = false;
  2783. var length;
  2784. var lastSelector;
  2785. function findNestedSelector(element) {
  2786. var maybeSelector;
  2787. if (!(element.value instanceof Paren)) {
  2788. return null;
  2789. }
  2790. maybeSelector = element.value.value;
  2791. if (!(maybeSelector instanceof Selector)) {
  2792. return null;
  2793. }
  2794. return maybeSelector;
  2795. } // the elements from the current selector so far
  2796. currentElements = []; // the current list of new selectors to add to the path.
  2797. // We will build it up. We initiate it with one empty selector as we "multiply" the new selectors
  2798. // by the parents
  2799. newSelectors = [[]];
  2800. for (i = 0; el = inSelector.elements[i]; i++) {
  2801. // non parent reference elements just get added
  2802. if (el.value !== '&') {
  2803. var nestedSelector = findNestedSelector(el);
  2804. if (nestedSelector != null) {
  2805. // merge the current list of non parent selector elements
  2806. // on to the current list of selectors to add
  2807. mergeElementsOnToSelectors(currentElements, newSelectors);
  2808. var nestedPaths = [];
  2809. var replaced = void 0;
  2810. var replacedNewSelectors = [];
  2811. replaced = replaceParentSelector(nestedPaths, context, nestedSelector);
  2812. hadParentSelector = hadParentSelector || replaced; // the nestedPaths array should have only one member - replaceParentSelector does not multiply selectors
  2813. for (k = 0; k < nestedPaths.length; k++) {
  2814. var replacementSelector = createSelector(createParenthesis(nestedPaths[k], el), el);
  2815. addAllReplacementsIntoPath(newSelectors, [replacementSelector], el, inSelector, replacedNewSelectors);
  2816. }
  2817. newSelectors = replacedNewSelectors;
  2818. currentElements = [];
  2819. } else {
  2820. currentElements.push(el);
  2821. }
  2822. } else {
  2823. hadParentSelector = true; // the new list of selectors to add
  2824. selectorsMultiplied = []; // merge the current list of non parent selector elements
  2825. // on to the current list of selectors to add
  2826. mergeElementsOnToSelectors(currentElements, newSelectors); // loop through our current selectors
  2827. for (j = 0; j < newSelectors.length; j++) {
  2828. sel = newSelectors[j]; // if we don't have any parent paths, the & might be in a mixin so that it can be used
  2829. // whether there are parents or not
  2830. if (context.length === 0) {
  2831. // the combinator used on el should now be applied to the next element instead so that
  2832. // it is not lost
  2833. if (sel.length > 0) {
  2834. sel[0].elements.push(new Element(el.combinator, '', el.isVariable, el._index, el._fileInfo));
  2835. }
  2836. selectorsMultiplied.push(sel);
  2837. } else {
  2838. // and the parent selectors
  2839. for (k = 0; k < context.length; k++) {
  2840. // We need to put the current selectors
  2841. // then join the last selector's elements on to the parents selectors
  2842. var newSelectorPath = addReplacementIntoPath(sel, context[k], el, inSelector); // add that to our new set of selectors
  2843. selectorsMultiplied.push(newSelectorPath);
  2844. }
  2845. }
  2846. } // our new selectors has been multiplied, so reset the state
  2847. newSelectors = selectorsMultiplied;
  2848. currentElements = [];
  2849. }
  2850. } // if we have any elements left over (e.g. .a& .b == .b)
  2851. // add them on to all the current selectors
  2852. mergeElementsOnToSelectors(currentElements, newSelectors);
  2853. for (i = 0; i < newSelectors.length; i++) {
  2854. length = newSelectors[i].length;
  2855. if (length > 0) {
  2856. paths.push(newSelectors[i]);
  2857. lastSelector = newSelectors[i][length - 1];
  2858. newSelectors[i][length - 1] = lastSelector.createDerived(lastSelector.elements, inSelector.extendList);
  2859. }
  2860. }
  2861. return hadParentSelector;
  2862. }
  2863. function deriveSelector(visibilityInfo, deriveFrom) {
  2864. var newSelector = deriveFrom.createDerived(deriveFrom.elements, deriveFrom.extendList, deriveFrom.evaldCondition);
  2865. newSelector.copyVisibilityInfo(visibilityInfo);
  2866. return newSelector;
  2867. } // joinSelector code follows
  2868. var i;
  2869. var newPaths;
  2870. var hadParentSelector;
  2871. newPaths = [];
  2872. hadParentSelector = replaceParentSelector(newPaths, context, selector);
  2873. if (!hadParentSelector) {
  2874. if (context.length > 0) {
  2875. newPaths = [];
  2876. for (i = 0; i < context.length; i++) {
  2877. var concatenated = context[i].map(deriveSelector.bind(this, selector.visibilityInfo()));
  2878. concatenated.push(selector);
  2879. newPaths.push(concatenated);
  2880. }
  2881. } else {
  2882. newPaths = [[selector]];
  2883. }
  2884. }
  2885. for (i = 0; i < newPaths.length; i++) {
  2886. paths.push(newPaths[i]);
  2887. }
  2888. }
  2889. }]);
  2890. return Ruleset;
  2891. }(Node);
  2892. Ruleset.prototype.type = 'Ruleset';
  2893. Ruleset.prototype.isRuleset = true;
  2894. var AtRule =
  2895. /*#__PURE__*/
  2896. function (_Node) {
  2897. _inherits(AtRule, _Node);
  2898. function AtRule(name, value, rules, index, currentFileInfo, debugInfo, isRooted, visibilityInfo) {
  2899. var _this;
  2900. _classCallCheck(this, AtRule);
  2901. _this = _possibleConstructorReturn(this, _getPrototypeOf(AtRule).call(this));
  2902. var i;
  2903. _this.name = name;
  2904. _this.value = value instanceof Node ? value : value ? new Anonymous(value) : value;
  2905. if (rules) {
  2906. if (Array.isArray(rules)) {
  2907. _this.rules = rules;
  2908. } else {
  2909. _this.rules = [rules];
  2910. _this.rules[0].selectors = new Selector([], null, null, index, currentFileInfo).createEmptySelectors();
  2911. }
  2912. for (i = 0; i < _this.rules.length; i++) {
  2913. _this.rules[i].allowImports = true;
  2914. }
  2915. _this.setParent(_this.rules, _assertThisInitialized(_this));
  2916. }
  2917. _this._index = index;
  2918. _this._fileInfo = currentFileInfo;
  2919. _this.debugInfo = debugInfo;
  2920. _this.isRooted = isRooted || false;
  2921. _this.copyVisibilityInfo(visibilityInfo);
  2922. _this.allowRoot = true;
  2923. return _this;
  2924. }
  2925. _createClass(AtRule, [{
  2926. key: "accept",
  2927. value: function accept(visitor) {
  2928. var value = this.value;
  2929. var rules = this.rules;
  2930. if (rules) {
  2931. this.rules = visitor.visitArray(rules);
  2932. }
  2933. if (value) {
  2934. this.value = visitor.visit(value);
  2935. }
  2936. }
  2937. }, {
  2938. key: "isRulesetLike",
  2939. value: function isRulesetLike() {
  2940. return this.rules || !this.isCharset();
  2941. }
  2942. }, {
  2943. key: "isCharset",
  2944. value: function isCharset() {
  2945. return '@charset' === this.name;
  2946. }
  2947. }, {
  2948. key: "genCSS",
  2949. value: function genCSS(context, output) {
  2950. var value = this.value;
  2951. var rules = this.rules;
  2952. output.add(this.name, this.fileInfo(), this.getIndex());
  2953. if (value) {
  2954. output.add(' ');
  2955. value.genCSS(context, output);
  2956. }
  2957. if (rules) {
  2958. this.outputRuleset(context, output, rules);
  2959. } else {
  2960. output.add(';');
  2961. }
  2962. }
  2963. }, {
  2964. key: "eval",
  2965. value: function _eval(context) {
  2966. var mediaPathBackup;
  2967. var mediaBlocksBackup;
  2968. var value = this.value;
  2969. var rules = this.rules; // media stored inside other atrule should not bubble over it
  2970. // backpup media bubbling information
  2971. mediaPathBackup = context.mediaPath;
  2972. mediaBlocksBackup = context.mediaBlocks; // deleted media bubbling information
  2973. context.mediaPath = [];
  2974. context.mediaBlocks = [];
  2975. if (value) {
  2976. value = value.eval(context);
  2977. }
  2978. if (rules) {
  2979. // assuming that there is only one rule at this point - that is how parser constructs the rule
  2980. rules = [rules[0].eval(context)];
  2981. rules[0].root = true;
  2982. } // restore media bubbling information
  2983. context.mediaPath = mediaPathBackup;
  2984. context.mediaBlocks = mediaBlocksBackup;
  2985. return new AtRule(this.name, value, rules, this.getIndex(), this.fileInfo(), this.debugInfo, this.isRooted, this.visibilityInfo());
  2986. }
  2987. }, {
  2988. key: "variable",
  2989. value: function variable(name) {
  2990. if (this.rules) {
  2991. // assuming that there is only one rule at this point - that is how parser constructs the rule
  2992. return Ruleset.prototype.variable.call(this.rules[0], name);
  2993. }
  2994. }
  2995. }, {
  2996. key: "find",
  2997. value: function find() {
  2998. if (this.rules) {
  2999. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  3000. args[_key] = arguments[_key];
  3001. }
  3002. // assuming that there is only one rule at this point - that is how parser constructs the rule
  3003. return Ruleset.prototype.find.apply(this.rules[0], args);
  3004. }
  3005. }
  3006. }, {
  3007. key: "rulesets",
  3008. value: function rulesets() {
  3009. if (this.rules) {
  3010. // assuming that there is only one rule at this point - that is how parser constructs the rule
  3011. return Ruleset.prototype.rulesets.apply(this.rules[0]);
  3012. }
  3013. }
  3014. }, {
  3015. key: "outputRuleset",
  3016. value: function outputRuleset(context, output, rules) {
  3017. var ruleCnt = rules.length;
  3018. var i;
  3019. context.tabLevel = (context.tabLevel | 0) + 1; // Compressed
  3020. if (context.compress) {
  3021. output.add('{');
  3022. for (i = 0; i < ruleCnt; i++) {
  3023. rules[i].genCSS(context, output);
  3024. }
  3025. output.add('}');
  3026. context.tabLevel--;
  3027. return;
  3028. } // Non-compressed
  3029. var tabSetStr = "\n".concat(Array(context.tabLevel).join(' '));
  3030. var tabRuleStr = "".concat(tabSetStr, " ");
  3031. if (!ruleCnt) {
  3032. output.add(" {".concat(tabSetStr, "}"));
  3033. } else {
  3034. output.add(" {".concat(tabRuleStr));
  3035. rules[0].genCSS(context, output);
  3036. for (i = 1; i < ruleCnt; i++) {
  3037. output.add(tabRuleStr);
  3038. rules[i].genCSS(context, output);
  3039. }
  3040. output.add("".concat(tabSetStr, "}"));
  3041. }
  3042. context.tabLevel--;
  3043. }
  3044. }]);
  3045. return AtRule;
  3046. }(Node);
  3047. AtRule.prototype.type = 'AtRule';
  3048. var DetachedRuleset =
  3049. /*#__PURE__*/
  3050. function (_Node) {
  3051. _inherits(DetachedRuleset, _Node);
  3052. function DetachedRuleset(ruleset, frames) {
  3053. var _this;
  3054. _classCallCheck(this, DetachedRuleset);
  3055. _this = _possibleConstructorReturn(this, _getPrototypeOf(DetachedRuleset).call(this));
  3056. _this.ruleset = ruleset;
  3057. _this.frames = frames;
  3058. _this.setParent(_this.ruleset, _assertThisInitialized(_this));
  3059. return _this;
  3060. }
  3061. _createClass(DetachedRuleset, [{
  3062. key: "accept",
  3063. value: function accept(visitor) {
  3064. this.ruleset = visitor.visit(this.ruleset);
  3065. }
  3066. }, {
  3067. key: "eval",
  3068. value: function _eval(context) {
  3069. var frames = this.frames || copyArray(context.frames);
  3070. return new DetachedRuleset(this.ruleset, frames);
  3071. }
  3072. }, {
  3073. key: "callEval",
  3074. value: function callEval(context) {
  3075. return this.ruleset.eval(this.frames ? new contexts.Eval(context, this.frames.concat(context.frames)) : context);
  3076. }
  3077. }]);
  3078. return DetachedRuleset;
  3079. }(Node);
  3080. DetachedRuleset.prototype.type = 'DetachedRuleset';
  3081. DetachedRuleset.prototype.evalFirst = true;
  3082. var Unit =
  3083. /*#__PURE__*/
  3084. function (_Node) {
  3085. _inherits(Unit, _Node);
  3086. function Unit(numerator, denominator, backupUnit) {
  3087. var _this;
  3088. _classCallCheck(this, Unit);
  3089. _this = _possibleConstructorReturn(this, _getPrototypeOf(Unit).call(this));
  3090. _this.numerator = numerator ? copyArray(numerator).sort() : [];
  3091. _this.denominator = denominator ? copyArray(denominator).sort() : [];
  3092. if (backupUnit) {
  3093. _this.backupUnit = backupUnit;
  3094. } else if (numerator && numerator.length) {
  3095. _this.backupUnit = numerator[0];
  3096. }
  3097. return _this;
  3098. }
  3099. _createClass(Unit, [{
  3100. key: "clone",
  3101. value: function clone() {
  3102. return new Unit(copyArray(this.numerator), copyArray(this.denominator), this.backupUnit);
  3103. }
  3104. }, {
  3105. key: "genCSS",
  3106. value: function genCSS(context, output) {
  3107. // Dimension checks the unit is singular and throws an error if in strict math mode.
  3108. var strictUnits = context && context.strictUnits;
  3109. if (this.numerator.length === 1) {
  3110. output.add(this.numerator[0]); // the ideal situation
  3111. } else if (!strictUnits && this.backupUnit) {
  3112. output.add(this.backupUnit);
  3113. } else if (!strictUnits && this.denominator.length) {
  3114. output.add(this.denominator[0]);
  3115. }
  3116. }
  3117. }, {
  3118. key: "toString",
  3119. value: function toString() {
  3120. var i;
  3121. var returnStr = this.numerator.join('*');
  3122. for (i = 0; i < this.denominator.length; i++) {
  3123. returnStr += "/".concat(this.denominator[i]);
  3124. }
  3125. return returnStr;
  3126. }
  3127. }, {
  3128. key: "compare",
  3129. value: function compare(other) {
  3130. return this.is(other.toString()) ? 0 : undefined;
  3131. }
  3132. }, {
  3133. key: "is",
  3134. value: function is(unitString) {
  3135. return this.toString().toUpperCase() === unitString.toUpperCase();
  3136. }
  3137. }, {
  3138. key: "isLength",
  3139. value: function isLength() {
  3140. return RegExp('^(px|em|ex|ch|rem|in|cm|mm|pc|pt|ex|vw|vh|vmin|vmax)$', 'gi').test(this.toCSS());
  3141. }
  3142. }, {
  3143. key: "isEmpty",
  3144. value: function isEmpty() {
  3145. return this.numerator.length === 0 && this.denominator.length === 0;
  3146. }
  3147. }, {
  3148. key: "isSingular",
  3149. value: function isSingular() {
  3150. return this.numerator.length <= 1 && this.denominator.length === 0;
  3151. }
  3152. }, {
  3153. key: "map",
  3154. value: function map(callback) {
  3155. var i;
  3156. for (i = 0; i < this.numerator.length; i++) {
  3157. this.numerator[i] = callback(this.numerator[i], false);
  3158. }
  3159. for (i = 0; i < this.denominator.length; i++) {
  3160. this.denominator[i] = callback(this.denominator[i], true);
  3161. }
  3162. }
  3163. }, {
  3164. key: "usedUnits",
  3165. value: function usedUnits() {
  3166. var group;
  3167. var result = {};
  3168. var mapUnit;
  3169. var groupName;
  3170. mapUnit = function mapUnit(atomicUnit) {
  3171. /* jshint loopfunc:true */
  3172. if (group.hasOwnProperty(atomicUnit) && !result[groupName]) {
  3173. result[groupName] = atomicUnit;
  3174. }
  3175. return atomicUnit;
  3176. };
  3177. for (groupName in unitConversions) {
  3178. if (unitConversions.hasOwnProperty(groupName)) {
  3179. group = unitConversions[groupName];
  3180. this.map(mapUnit);
  3181. }
  3182. }
  3183. return result;
  3184. }
  3185. }, {
  3186. key: "cancel",
  3187. value: function cancel() {
  3188. var counter = {};
  3189. var atomicUnit;
  3190. var i;
  3191. for (i = 0; i < this.numerator.length; i++) {
  3192. atomicUnit = this.numerator[i];
  3193. counter[atomicUnit] = (counter[atomicUnit] || 0) + 1;
  3194. }
  3195. for (i = 0; i < this.denominator.length; i++) {
  3196. atomicUnit = this.denominator[i];
  3197. counter[atomicUnit] = (counter[atomicUnit] || 0) - 1;
  3198. }
  3199. this.numerator = [];
  3200. this.denominator = [];
  3201. for (atomicUnit in counter) {
  3202. if (counter.hasOwnProperty(atomicUnit)) {
  3203. var count = counter[atomicUnit];
  3204. if (count > 0) {
  3205. for (i = 0; i < count; i++) {
  3206. this.numerator.push(atomicUnit);
  3207. }
  3208. } else if (count < 0) {
  3209. for (i = 0; i < -count; i++) {
  3210. this.denominator.push(atomicUnit);
  3211. }
  3212. }
  3213. }
  3214. }
  3215. this.numerator.sort();
  3216. this.denominator.sort();
  3217. }
  3218. }]);
  3219. return Unit;
  3220. }(Node);
  3221. Unit.prototype.type = 'Unit';
  3222. // A number with a unit
  3223. //
  3224. var Dimension =
  3225. /*#__PURE__*/
  3226. function (_Node) {
  3227. _inherits(Dimension, _Node);
  3228. function Dimension(value, unit) {
  3229. var _this;
  3230. _classCallCheck(this, Dimension);
  3231. _this = _possibleConstructorReturn(this, _getPrototypeOf(Dimension).call(this));
  3232. _this.value = parseFloat(value);
  3233. if (isNaN(_this.value)) {
  3234. throw new Error('Dimension is not a number.');
  3235. }
  3236. _this.unit = unit && unit instanceof Unit ? unit : new Unit(unit ? [unit] : undefined);
  3237. _this.setParent(_this.unit, _assertThisInitialized(_this));
  3238. return _this;
  3239. }
  3240. _createClass(Dimension, [{
  3241. key: "accept",
  3242. value: function accept(visitor) {
  3243. this.unit = visitor.visit(this.unit);
  3244. }
  3245. }, {
  3246. key: "eval",
  3247. value: function _eval(context) {
  3248. return this;
  3249. }
  3250. }, {
  3251. key: "toColor",
  3252. value: function toColor() {
  3253. return new Color([this.value, this.value, this.value]);
  3254. }
  3255. }, {
  3256. key: "genCSS",
  3257. value: function genCSS(context, output) {
  3258. if (context && context.strictUnits && !this.unit.isSingular()) {
  3259. throw new Error("Multiple units in dimension. Correct the units or use the unit function. Bad unit: ".concat(this.unit.toString()));
  3260. }
  3261. var value = this.fround(context, this.value);
  3262. var strValue = String(value);
  3263. if (value !== 0 && value < 0.000001 && value > -0.000001) {
  3264. // would be output 1e-6 etc.
  3265. strValue = value.toFixed(20).replace(/0+$/, '');
  3266. }
  3267. if (context && context.compress) {
  3268. // Zero values doesn't need a unit
  3269. if (value === 0 && this.unit.isLength()) {
  3270. output.add(strValue);
  3271. return;
  3272. } // Float values doesn't need a leading zero
  3273. if (value > 0 && value < 1) {
  3274. strValue = strValue.substr(1);
  3275. }
  3276. }
  3277. output.add(strValue);
  3278. this.unit.genCSS(context, output);
  3279. } // In an operation between two Dimensions,
  3280. // we default to the first Dimension's unit,
  3281. // so `1px + 2` will yield `3px`.
  3282. }, {
  3283. key: "operate",
  3284. value: function operate(context, op, other) {
  3285. /* jshint noempty:false */
  3286. var value = this._operate(context, op, this.value, other.value);
  3287. var unit = this.unit.clone();
  3288. if (op === '+' || op === '-') {
  3289. if (unit.numerator.length === 0 && unit.denominator.length === 0) {
  3290. unit = other.unit.clone();
  3291. if (this.unit.backupUnit) {
  3292. unit.backupUnit = this.unit.backupUnit;
  3293. }
  3294. } else if (other.unit.numerator.length === 0 && unit.denominator.length === 0) ; else {
  3295. other = other.convertTo(this.unit.usedUnits());
  3296. if (context.strictUnits && other.unit.toString() !== unit.toString()) {
  3297. throw new Error("Incompatible units. Change the units or use the unit function. " + "Bad units: '".concat(unit.toString(), "' and '").concat(other.unit.toString(), "'."));
  3298. }
  3299. value = this._operate(context, op, this.value, other.value);
  3300. }
  3301. } else if (op === '*') {
  3302. unit.numerator = unit.numerator.concat(other.unit.numerator).sort();
  3303. unit.denominator = unit.denominator.concat(other.unit.denominator).sort();
  3304. unit.cancel();
  3305. } else if (op === '/') {
  3306. unit.numerator = unit.numerator.concat(other.unit.denominator).sort();
  3307. unit.denominator = unit.denominator.concat(other.unit.numerator).sort();
  3308. unit.cancel();
  3309. }
  3310. return new Dimension(value, unit);
  3311. }
  3312. }, {
  3313. key: "compare",
  3314. value: function compare(other) {
  3315. var a;
  3316. var b;
  3317. if (!(other instanceof Dimension)) {
  3318. return undefined;
  3319. }
  3320. if (this.unit.isEmpty() || other.unit.isEmpty()) {
  3321. a = this;
  3322. b = other;
  3323. } else {
  3324. a = this.unify();
  3325. b = other.unify();
  3326. if (a.unit.compare(b.unit) !== 0) {
  3327. return undefined;
  3328. }
  3329. }
  3330. return Node.numericCompare(a.value, b.value);
  3331. }
  3332. }, {
  3333. key: "unify",
  3334. value: function unify() {
  3335. return this.convertTo({
  3336. length: 'px',
  3337. duration: 's',
  3338. angle: 'rad'
  3339. });
  3340. }
  3341. }, {
  3342. key: "convertTo",
  3343. value: function convertTo(conversions) {
  3344. var value = this.value;
  3345. var unit = this.unit.clone();
  3346. var i;
  3347. var groupName;
  3348. var group;
  3349. var targetUnit;
  3350. var derivedConversions = {};
  3351. var applyUnit;
  3352. if (typeof conversions === 'string') {
  3353. for (i in unitConversions) {
  3354. if (unitConversions[i].hasOwnProperty(conversions)) {
  3355. derivedConversions = {};
  3356. derivedConversions[i] = conversions;
  3357. }
  3358. }
  3359. conversions = derivedConversions;
  3360. }
  3361. applyUnit = function applyUnit(atomicUnit, denominator) {
  3362. /* jshint loopfunc:true */
  3363. if (group.hasOwnProperty(atomicUnit)) {
  3364. if (denominator) {
  3365. value = value / (group[atomicUnit] / group[targetUnit]);
  3366. } else {
  3367. value = value * (group[atomicUnit] / group[targetUnit]);
  3368. }
  3369. return targetUnit;
  3370. }
  3371. return atomicUnit;
  3372. };
  3373. for (groupName in conversions) {
  3374. if (conversions.hasOwnProperty(groupName)) {
  3375. targetUnit = conversions[groupName];
  3376. group = unitConversions[groupName];
  3377. unit.map(applyUnit);
  3378. }
  3379. }
  3380. unit.cancel();
  3381. return new Dimension(value, unit);
  3382. }
  3383. }]);
  3384. return Dimension;
  3385. }(Node);
  3386. Dimension.prototype.type = 'Dimension';
  3387. var MATH$1 = Math$1;
  3388. var Operation =
  3389. /*#__PURE__*/
  3390. function (_Node) {
  3391. _inherits(Operation, _Node);
  3392. function Operation(op, operands, isSpaced) {
  3393. var _this;
  3394. _classCallCheck(this, Operation);
  3395. _this = _possibleConstructorReturn(this, _getPrototypeOf(Operation).call(this));
  3396. _this.op = op.trim();
  3397. _this.operands = operands;
  3398. _this.isSpaced = isSpaced;
  3399. return _this;
  3400. }
  3401. _createClass(Operation, [{
  3402. key: "accept",
  3403. value: function accept(visitor) {
  3404. this.operands = visitor.visitArray(this.operands);
  3405. }
  3406. }, {
  3407. key: "eval",
  3408. value: function _eval(context) {
  3409. var a = this.operands[0].eval(context);
  3410. var b = this.operands[1].eval(context);
  3411. var op;
  3412. if (context.isMathOn(this.op)) {
  3413. op = this.op === './' ? '/' : this.op;
  3414. if (a instanceof Dimension && b instanceof Color) {
  3415. a = a.toColor();
  3416. }
  3417. if (b instanceof Dimension && a instanceof Color) {
  3418. b = b.toColor();
  3419. }
  3420. if (!a.operate) {
  3421. if (a instanceof Operation && a.op === '/' && context.math === MATH$1.PARENS_DIVISION) {
  3422. return new Operation(this.op, [a, b], this.isSpaced);
  3423. }
  3424. throw {
  3425. type: 'Operation',
  3426. message: 'Operation on an invalid type'
  3427. };
  3428. }
  3429. return a.operate(context, op, b);
  3430. } else {
  3431. return new Operation(this.op, [a, b], this.isSpaced);
  3432. }
  3433. }
  3434. }, {
  3435. key: "genCSS",
  3436. value: function genCSS(context, output) {
  3437. this.operands[0].genCSS(context, output);
  3438. if (this.isSpaced) {
  3439. output.add(' ');
  3440. }
  3441. output.add(this.op);
  3442. if (this.isSpaced) {
  3443. output.add(' ');
  3444. }
  3445. this.operands[1].genCSS(context, output);
  3446. }
  3447. }]);
  3448. return Operation;
  3449. }(Node);
  3450. Operation.prototype.type = 'Operation';
  3451. var MATH$2 = Math$1;
  3452. var Expression =
  3453. /*#__PURE__*/
  3454. function (_Node) {
  3455. _inherits(Expression, _Node);
  3456. function Expression(value, noSpacing) {
  3457. var _this;
  3458. _classCallCheck(this, Expression);
  3459. _this = _possibleConstructorReturn(this, _getPrototypeOf(Expression).call(this));
  3460. _this.value = value;
  3461. _this.noSpacing = noSpacing;
  3462. if (!value) {
  3463. throw new Error('Expression requires an array parameter');
  3464. }
  3465. return _this;
  3466. }
  3467. _createClass(Expression, [{
  3468. key: "accept",
  3469. value: function accept(visitor) {
  3470. this.value = visitor.visitArray(this.value);
  3471. }
  3472. }, {
  3473. key: "eval",
  3474. value: function _eval(context) {
  3475. var returnValue;
  3476. var mathOn = context.isMathOn();
  3477. var inParenthesis = this.parens && (context.math !== MATH$2.STRICT_LEGACY || !this.parensInOp);
  3478. var doubleParen = false;
  3479. if (inParenthesis) {
  3480. context.inParenthesis();
  3481. }
  3482. if (this.value.length > 1) {
  3483. returnValue = new Expression(this.value.map(function (e) {
  3484. if (!e.eval) {
  3485. return e;
  3486. }
  3487. return e.eval(context);
  3488. }), this.noSpacing);
  3489. } else if (this.value.length === 1) {
  3490. if (this.value[0].parens && !this.value[0].parensInOp && !context.inCalc) {
  3491. doubleParen = true;
  3492. }
  3493. returnValue = this.value[0].eval(context);
  3494. } else {
  3495. returnValue = this;
  3496. }
  3497. if (inParenthesis) {
  3498. context.outOfParenthesis();
  3499. }
  3500. if (this.parens && this.parensInOp && !mathOn && !doubleParen && !(returnValue instanceof Dimension)) {
  3501. returnValue = new Paren(returnValue);
  3502. }
  3503. return returnValue;
  3504. }
  3505. }, {
  3506. key: "genCSS",
  3507. value: function genCSS(context, output) {
  3508. for (var i = 0; i < this.value.length; i++) {
  3509. this.value[i].genCSS(context, output);
  3510. if (!this.noSpacing && i + 1 < this.value.length) {
  3511. output.add(' ');
  3512. }
  3513. }
  3514. }
  3515. }, {
  3516. key: "throwAwayComments",
  3517. value: function throwAwayComments() {
  3518. this.value = this.value.filter(function (v) {
  3519. return !(v instanceof Comment);
  3520. });
  3521. }
  3522. }]);
  3523. return Expression;
  3524. }(Node);
  3525. Expression.prototype.type = 'Expression';
  3526. var functionCaller =
  3527. /*#__PURE__*/
  3528. function () {
  3529. function functionCaller(name, context, index, currentFileInfo) {
  3530. _classCallCheck(this, functionCaller);
  3531. this.name = name.toLowerCase();
  3532. this.index = index;
  3533. this.context = context;
  3534. this.currentFileInfo = currentFileInfo;
  3535. this.func = context.frames[0].functionRegistry.get(this.name);
  3536. }
  3537. _createClass(functionCaller, [{
  3538. key: "isValid",
  3539. value: function isValid() {
  3540. return Boolean(this.func);
  3541. }
  3542. }, {
  3543. key: "call",
  3544. value: function call(args) {
  3545. // This code is terrible and should be replaced as per this issue...
  3546. // https://github.com/less/less.js/issues/2477
  3547. if (Array.isArray(args)) {
  3548. args = args.filter(function (item) {
  3549. if (item.type === 'Comment') {
  3550. return false;
  3551. }
  3552. return true;
  3553. }).map(function (item) {
  3554. if (item.type === 'Expression') {
  3555. var subNodes = item.value.filter(function (item) {
  3556. if (item.type === 'Comment') {
  3557. return false;
  3558. }
  3559. return true;
  3560. });
  3561. if (subNodes.length === 1) {
  3562. return subNodes[0];
  3563. } else {
  3564. return new Expression(subNodes);
  3565. }
  3566. }
  3567. return item;
  3568. });
  3569. }
  3570. return this.func.apply(this, _toConsumableArray(args));
  3571. }
  3572. }]);
  3573. return functionCaller;
  3574. }();
  3575. // A function call node.
  3576. //
  3577. var Call =
  3578. /*#__PURE__*/
  3579. function (_Node) {
  3580. _inherits(Call, _Node);
  3581. function Call(name, args, index, currentFileInfo) {
  3582. var _this;
  3583. _classCallCheck(this, Call);
  3584. _this = _possibleConstructorReturn(this, _getPrototypeOf(Call).call(this));
  3585. _this.name = name;
  3586. _this.args = args;
  3587. _this.calc = name === 'calc';
  3588. _this._index = index;
  3589. _this._fileInfo = currentFileInfo;
  3590. return _this;
  3591. }
  3592. _createClass(Call, [{
  3593. key: "accept",
  3594. value: function accept(visitor) {
  3595. if (this.args) {
  3596. this.args = visitor.visitArray(this.args);
  3597. }
  3598. } //
  3599. // When evaluating a function call,
  3600. // we either find the function in the functionRegistry,
  3601. // in which case we call it, passing the evaluated arguments,
  3602. // if this returns null or we cannot find the function, we
  3603. // simply print it out as it appeared originally [2].
  3604. //
  3605. // The reason why we evaluate the arguments, is in the case where
  3606. // we try to pass a variable to a function, like: `saturate(@color)`.
  3607. // The function should receive the value, not the variable.
  3608. //
  3609. }, {
  3610. key: "eval",
  3611. value: function _eval(context) {
  3612. /**
  3613. * Turn off math for calc(), and switch back on for evaluating nested functions
  3614. */
  3615. var currentMathContext = context.mathOn;
  3616. context.mathOn = !this.calc;
  3617. if (this.calc || context.inCalc) {
  3618. context.enterCalc();
  3619. }
  3620. var args = this.args.map(function (a) {
  3621. return a.eval(context);
  3622. });
  3623. if (this.calc || context.inCalc) {
  3624. context.exitCalc();
  3625. }
  3626. context.mathOn = currentMathContext;
  3627. var result;
  3628. var funcCaller = new functionCaller(this.name, context, this.getIndex(), this.fileInfo());
  3629. if (funcCaller.isValid()) {
  3630. try {
  3631. result = funcCaller.call(args);
  3632. } catch (e) {
  3633. throw {
  3634. type: e.type || 'Runtime',
  3635. message: "error evaluating function `".concat(this.name, "`").concat(e.message ? ": ".concat(e.message) : ''),
  3636. index: this.getIndex(),
  3637. filename: this.fileInfo().filename,
  3638. line: e.lineNumber,
  3639. column: e.columnNumber
  3640. };
  3641. }
  3642. if (result !== null && result !== undefined) {
  3643. // Results that that are not nodes are cast as Anonymous nodes
  3644. // Falsy values or booleans are returned as empty nodes
  3645. if (!(result instanceof Node)) {
  3646. if (!result || result === true) {
  3647. result = new Anonymous(null);
  3648. } else {
  3649. result = new Anonymous(result.toString());
  3650. }
  3651. }
  3652. result._index = this._index;
  3653. result._fileInfo = this._fileInfo;
  3654. return result;
  3655. }
  3656. }
  3657. return new Call(this.name, args, this.getIndex(), this.fileInfo());
  3658. }
  3659. }, {
  3660. key: "genCSS",
  3661. value: function genCSS(context, output) {
  3662. output.add("".concat(this.name, "("), this.fileInfo(), this.getIndex());
  3663. for (var i = 0; i < this.args.length; i++) {
  3664. this.args[i].genCSS(context, output);
  3665. if (i + 1 < this.args.length) {
  3666. output.add(', ');
  3667. }
  3668. }
  3669. output.add(')');
  3670. }
  3671. }]);
  3672. return Call;
  3673. }(Node);
  3674. Call.prototype.type = 'Call';
  3675. var Variable =
  3676. /*#__PURE__*/
  3677. function (_Node) {
  3678. _inherits(Variable, _Node);
  3679. function Variable(name, index, currentFileInfo) {
  3680. var _this;
  3681. _classCallCheck(this, Variable);
  3682. _this = _possibleConstructorReturn(this, _getPrototypeOf(Variable).call(this));
  3683. _this.name = name;
  3684. _this._index = index;
  3685. _this._fileInfo = currentFileInfo;
  3686. return _this;
  3687. }
  3688. _createClass(Variable, [{
  3689. key: "eval",
  3690. value: function _eval(context) {
  3691. var variable;
  3692. var name = this.name;
  3693. if (name.indexOf('@@') === 0) {
  3694. name = "@".concat(new Variable(name.slice(1), this.getIndex(), this.fileInfo()).eval(context).value);
  3695. }
  3696. if (this.evaluating) {
  3697. throw {
  3698. type: 'Name',
  3699. message: "Recursive variable definition for ".concat(name),
  3700. filename: this.fileInfo().filename,
  3701. index: this.getIndex()
  3702. };
  3703. }
  3704. this.evaluating = true;
  3705. variable = this.find(context.frames, function (frame) {
  3706. var v = frame.variable(name);
  3707. if (v) {
  3708. if (v.important) {
  3709. var importantScope = context.importantScope[context.importantScope.length - 1];
  3710. importantScope.important = v.important;
  3711. } // If in calc, wrap vars in a function call to cascade evaluate args first
  3712. if (context.inCalc) {
  3713. return new Call('_SELF', [v.value]).eval(context);
  3714. } else {
  3715. return v.value.eval(context);
  3716. }
  3717. }
  3718. });
  3719. if (variable) {
  3720. this.evaluating = false;
  3721. return variable;
  3722. } else {
  3723. throw {
  3724. type: 'Name',
  3725. message: "variable ".concat(name, " is undefined"),
  3726. filename: this.fileInfo().filename,
  3727. index: this.getIndex()
  3728. };
  3729. }
  3730. }
  3731. }, {
  3732. key: "find",
  3733. value: function find(obj, fun) {
  3734. for (var i = 0, r; i < obj.length; i++) {
  3735. r = fun.call(obj, obj[i]);
  3736. if (r) {
  3737. return r;
  3738. }
  3739. }
  3740. return null;
  3741. }
  3742. }]);
  3743. return Variable;
  3744. }(Node);
  3745. Variable.prototype.type = 'Variable';
  3746. var Property =
  3747. /*#__PURE__*/
  3748. function (_Node) {
  3749. _inherits(Property, _Node);
  3750. function Property(name, index, currentFileInfo) {
  3751. var _this;
  3752. _classCallCheck(this, Property);
  3753. _this = _possibleConstructorReturn(this, _getPrototypeOf(Property).call(this));
  3754. _this.name = name;
  3755. _this._index = index;
  3756. _this._fileInfo = currentFileInfo;
  3757. return _this;
  3758. }
  3759. _createClass(Property, [{
  3760. key: "eval",
  3761. value: function _eval(context) {
  3762. var property;
  3763. var name = this.name; // TODO: shorten this reference
  3764. var mergeRules = context.pluginManager.less.visitors.ToCSSVisitor.prototype._mergeRules;
  3765. if (this.evaluating) {
  3766. throw {
  3767. type: 'Name',
  3768. message: "Recursive property reference for ".concat(name),
  3769. filename: this.fileInfo().filename,
  3770. index: this.getIndex()
  3771. };
  3772. }
  3773. this.evaluating = true;
  3774. property = this.find(context.frames, function (frame) {
  3775. var v;
  3776. var vArr = frame.property(name);
  3777. if (vArr) {
  3778. for (var i = 0; i < vArr.length; i++) {
  3779. v = vArr[i];
  3780. vArr[i] = new Declaration(v.name, v.value, v.important, v.merge, v.index, v.currentFileInfo, v.inline, v.variable);
  3781. }
  3782. mergeRules(vArr);
  3783. v = vArr[vArr.length - 1];
  3784. if (v.important) {
  3785. var importantScope = context.importantScope[context.importantScope.length - 1];
  3786. importantScope.important = v.important;
  3787. }
  3788. v = v.value.eval(context);
  3789. return v;
  3790. }
  3791. });
  3792. if (property) {
  3793. this.evaluating = false;
  3794. return property;
  3795. } else {
  3796. throw {
  3797. type: 'Name',
  3798. message: "Property '".concat(name, "' is undefined"),
  3799. filename: this.currentFileInfo.filename,
  3800. index: this.index
  3801. };
  3802. }
  3803. }
  3804. }, {
  3805. key: "find",
  3806. value: function find(obj, fun) {
  3807. for (var i = 0, r; i < obj.length; i++) {
  3808. r = fun.call(obj, obj[i]);
  3809. if (r) {
  3810. return r;
  3811. }
  3812. }
  3813. return null;
  3814. }
  3815. }]);
  3816. return Property;
  3817. }(Node);
  3818. Property.prototype.type = 'Property';
  3819. var Attribute =
  3820. /*#__PURE__*/
  3821. function (_Node) {
  3822. _inherits(Attribute, _Node);
  3823. function Attribute(key, op, value) {
  3824. var _this;
  3825. _classCallCheck(this, Attribute);
  3826. _this = _possibleConstructorReturn(this, _getPrototypeOf(Attribute).call(this));
  3827. _this.key = key;
  3828. _this.op = op;
  3829. _this.value = value;
  3830. return _this;
  3831. }
  3832. _createClass(Attribute, [{
  3833. key: "eval",
  3834. value: function _eval(context) {
  3835. return new Attribute(this.key.eval ? this.key.eval(context) : this.key, this.op, this.value && this.value.eval ? this.value.eval(context) : this.value);
  3836. }
  3837. }, {
  3838. key: "genCSS",
  3839. value: function genCSS(context, output) {
  3840. output.add(this.toCSS(context));
  3841. }
  3842. }, {
  3843. key: "toCSS",
  3844. value: function toCSS(context) {
  3845. var value = this.key.toCSS ? this.key.toCSS(context) : this.key;
  3846. if (this.op) {
  3847. value += this.op;
  3848. value += this.value.toCSS ? this.value.toCSS(context) : this.value;
  3849. }
  3850. return "[".concat(value, "]");
  3851. }
  3852. }]);
  3853. return Attribute;
  3854. }(Node);
  3855. Attribute.prototype.type = 'Attribute';
  3856. var Quoted =
  3857. /*#__PURE__*/
  3858. function (_Node) {
  3859. _inherits(Quoted, _Node);
  3860. function Quoted(str, content, escaped, index, currentFileInfo) {
  3861. var _this;
  3862. _classCallCheck(this, Quoted);
  3863. _this = _possibleConstructorReturn(this, _getPrototypeOf(Quoted).call(this));
  3864. _this.escaped = escaped == null ? true : escaped;
  3865. _this.value = content || '';
  3866. _this.quote = str.charAt(0);
  3867. _this._index = index;
  3868. _this._fileInfo = currentFileInfo;
  3869. _this.variableRegex = /@\{([\w-]+)\}/g;
  3870. _this.propRegex = /\$\{([\w-]+)\}/g;
  3871. _this.allowRoot = escaped;
  3872. return _this;
  3873. }
  3874. _createClass(Quoted, [{
  3875. key: "genCSS",
  3876. value: function genCSS(context, output) {
  3877. if (!this.escaped) {
  3878. output.add(this.quote, this.fileInfo(), this.getIndex());
  3879. }
  3880. output.add(this.value);
  3881. if (!this.escaped) {
  3882. output.add(this.quote);
  3883. }
  3884. }
  3885. }, {
  3886. key: "containsVariables",
  3887. value: function containsVariables() {
  3888. return this.value.match(this.variableRegex);
  3889. }
  3890. }, {
  3891. key: "eval",
  3892. value: function _eval(context) {
  3893. var that = this;
  3894. var value = this.value;
  3895. var variableReplacement = function variableReplacement(_, name) {
  3896. var v = new Variable("@".concat(name), that.getIndex(), that.fileInfo()).eval(context, true);
  3897. return v instanceof Quoted ? v.value : v.toCSS();
  3898. };
  3899. var propertyReplacement = function propertyReplacement(_, name) {
  3900. var v = new Property("$".concat(name), that.getIndex(), that.fileInfo()).eval(context, true);
  3901. return v instanceof Quoted ? v.value : v.toCSS();
  3902. };
  3903. function iterativeReplace(value, regexp, replacementFnc) {
  3904. var evaluatedValue = value;
  3905. do {
  3906. value = evaluatedValue.toString();
  3907. evaluatedValue = value.replace(regexp, replacementFnc);
  3908. } while (value !== evaluatedValue);
  3909. return evaluatedValue;
  3910. }
  3911. value = iterativeReplace(value, this.variableRegex, variableReplacement);
  3912. value = iterativeReplace(value, this.propRegex, propertyReplacement);
  3913. return new Quoted(this.quote + value + this.quote, value, this.escaped, this.getIndex(), this.fileInfo());
  3914. }
  3915. }, {
  3916. key: "compare",
  3917. value: function compare(other) {
  3918. // when comparing quoted strings allow the quote to differ
  3919. if (other.type === 'Quoted' && !this.escaped && !other.escaped) {
  3920. return Node.numericCompare(this.value, other.value);
  3921. } else {
  3922. return other.toCSS && this.toCSS() === other.toCSS() ? 0 : undefined;
  3923. }
  3924. }
  3925. }]);
  3926. return Quoted;
  3927. }(Node);
  3928. Quoted.prototype.type = 'Quoted';
  3929. var URL =
  3930. /*#__PURE__*/
  3931. function (_Node) {
  3932. _inherits(URL, _Node);
  3933. function URL(val, index, currentFileInfo, isEvald) {
  3934. var _this;
  3935. _classCallCheck(this, URL);
  3936. _this = _possibleConstructorReturn(this, _getPrototypeOf(URL).call(this));
  3937. _this.value = val;
  3938. _this._index = index;
  3939. _this._fileInfo = currentFileInfo;
  3940. _this.isEvald = isEvald;
  3941. return _this;
  3942. }
  3943. _createClass(URL, [{
  3944. key: "accept",
  3945. value: function accept(visitor) {
  3946. this.value = visitor.visit(this.value);
  3947. }
  3948. }, {
  3949. key: "genCSS",
  3950. value: function genCSS(context, output) {
  3951. output.add('url(');
  3952. this.value.genCSS(context, output);
  3953. output.add(')');
  3954. }
  3955. }, {
  3956. key: "eval",
  3957. value: function _eval(context) {
  3958. var val = this.value.eval(context);
  3959. var rootpath;
  3960. if (!this.isEvald) {
  3961. // Add the rootpath if the URL requires a rewrite
  3962. rootpath = this.fileInfo() && this.fileInfo().rootpath;
  3963. if (typeof rootpath === 'string' && typeof val.value === 'string' && context.pathRequiresRewrite(val.value)) {
  3964. if (!val.quote) {
  3965. rootpath = escapePath(rootpath);
  3966. }
  3967. val.value = context.rewritePath(val.value, rootpath);
  3968. } else {
  3969. val.value = context.normalizePath(val.value);
  3970. } // Add url args if enabled
  3971. if (context.urlArgs) {
  3972. if (!val.value.match(/^\s*data:/)) {
  3973. var delimiter = val.value.indexOf('?') === -1 ? '?' : '&';
  3974. var urlArgs = delimiter + context.urlArgs;
  3975. if (val.value.indexOf('#') !== -1) {
  3976. val.value = val.value.replace('#', "".concat(urlArgs, "#"));
  3977. } else {
  3978. val.value += urlArgs;
  3979. }
  3980. }
  3981. }
  3982. }
  3983. return new URL(val, this.getIndex(), this.fileInfo(), true);
  3984. }
  3985. }]);
  3986. return URL;
  3987. }(Node);
  3988. URL.prototype.type = 'Url';
  3989. function escapePath(path) {
  3990. return path.replace(/[\(\)'"\s]/g, function (match) {
  3991. return "\\".concat(match);
  3992. });
  3993. }
  3994. var Media =
  3995. /*#__PURE__*/
  3996. function (_AtRule) {
  3997. _inherits(Media, _AtRule);
  3998. function Media(value, features, index, currentFileInfo, visibilityInfo) {
  3999. var _this;
  4000. _classCallCheck(this, Media);
  4001. _this = _possibleConstructorReturn(this, _getPrototypeOf(Media).call(this));
  4002. _this._index = index;
  4003. _this._fileInfo = currentFileInfo;
  4004. var selectors = new Selector([], null, null, _this._index, _this._fileInfo).createEmptySelectors();
  4005. _this.features = new Value(features);
  4006. _this.rules = [new Ruleset(selectors, value)];
  4007. _this.rules[0].allowImports = true;
  4008. _this.copyVisibilityInfo(visibilityInfo);
  4009. _this.allowRoot = true;
  4010. _this.setParent(selectors, _assertThisInitialized(_this));
  4011. _this.setParent(_this.features, _assertThisInitialized(_this));
  4012. _this.setParent(_this.rules, _assertThisInitialized(_this));
  4013. return _this;
  4014. }
  4015. _createClass(Media, [{
  4016. key: "isRulesetLike",
  4017. value: function isRulesetLike() {
  4018. return true;
  4019. }
  4020. }, {
  4021. key: "accept",
  4022. value: function accept(visitor) {
  4023. if (this.features) {
  4024. this.features = visitor.visit(this.features);
  4025. }
  4026. if (this.rules) {
  4027. this.rules = visitor.visitArray(this.rules);
  4028. }
  4029. }
  4030. }, {
  4031. key: "genCSS",
  4032. value: function genCSS(context, output) {
  4033. output.add('@media ', this._fileInfo, this._index);
  4034. this.features.genCSS(context, output);
  4035. this.outputRuleset(context, output, this.rules);
  4036. }
  4037. }, {
  4038. key: "eval",
  4039. value: function _eval(context) {
  4040. if (!context.mediaBlocks) {
  4041. context.mediaBlocks = [];
  4042. context.mediaPath = [];
  4043. }
  4044. var media = new Media(null, [], this._index, this._fileInfo, this.visibilityInfo());
  4045. if (this.debugInfo) {
  4046. this.rules[0].debugInfo = this.debugInfo;
  4047. media.debugInfo = this.debugInfo;
  4048. }
  4049. media.features = this.features.eval(context);
  4050. context.mediaPath.push(media);
  4051. context.mediaBlocks.push(media);
  4052. this.rules[0].functionRegistry = context.frames[0].functionRegistry.inherit();
  4053. context.frames.unshift(this.rules[0]);
  4054. media.rules = [this.rules[0].eval(context)];
  4055. context.frames.shift();
  4056. context.mediaPath.pop();
  4057. return context.mediaPath.length === 0 ? media.evalTop(context) : media.evalNested(context);
  4058. }
  4059. }, {
  4060. key: "evalTop",
  4061. value: function evalTop(context) {
  4062. var result = this; // Render all dependent Media blocks.
  4063. if (context.mediaBlocks.length > 1) {
  4064. var selectors = new Selector([], null, null, this.getIndex(), this.fileInfo()).createEmptySelectors();
  4065. result = new Ruleset(selectors, context.mediaBlocks);
  4066. result.multiMedia = true;
  4067. result.copyVisibilityInfo(this.visibilityInfo());
  4068. this.setParent(result, this);
  4069. }
  4070. delete context.mediaBlocks;
  4071. delete context.mediaPath;
  4072. return result;
  4073. }
  4074. }, {
  4075. key: "evalNested",
  4076. value: function evalNested(context) {
  4077. var i;
  4078. var value;
  4079. var path = context.mediaPath.concat([this]); // Extract the media-query conditions separated with `,` (OR).
  4080. for (i = 0; i < path.length; i++) {
  4081. value = path[i].features instanceof Value ? path[i].features.value : path[i].features;
  4082. path[i] = Array.isArray(value) ? value : [value];
  4083. } // Trace all permutations to generate the resulting media-query.
  4084. //
  4085. // (a, b and c) with nested (d, e) ->
  4086. // a and d
  4087. // a and e
  4088. // b and c and d
  4089. // b and c and e
  4090. this.features = new Value(this.permute(path).map(function (path) {
  4091. path = path.map(function (fragment) {
  4092. return fragment.toCSS ? fragment : new Anonymous(fragment);
  4093. });
  4094. for (i = path.length - 1; i > 0; i--) {
  4095. path.splice(i, 0, new Anonymous('and'));
  4096. }
  4097. return new Expression(path);
  4098. }));
  4099. this.setParent(this.features, this); // Fake a tree-node that doesn't output anything.
  4100. return new Ruleset([], []);
  4101. }
  4102. }, {
  4103. key: "permute",
  4104. value: function permute(arr) {
  4105. if (arr.length === 0) {
  4106. return [];
  4107. } else if (arr.length === 1) {
  4108. return arr[0];
  4109. } else {
  4110. var result = [];
  4111. var rest = this.permute(arr.slice(1));
  4112. for (var i = 0; i < rest.length; i++) {
  4113. for (var j = 0; j < arr[0].length; j++) {
  4114. result.push([arr[0][j]].concat(rest[i]));
  4115. }
  4116. }
  4117. return result;
  4118. }
  4119. }
  4120. }, {
  4121. key: "bubbleSelectors",
  4122. value: function bubbleSelectors(selectors) {
  4123. if (!selectors) {
  4124. return;
  4125. }
  4126. this.rules = [new Ruleset(copyArray(selectors), [this.rules[0]])];
  4127. this.setParent(this.rules, this);
  4128. }
  4129. }]);
  4130. return Media;
  4131. }(AtRule);
  4132. Media.prototype.type = 'Media';
  4133. // CSS @import node
  4134. //
  4135. // The general strategy here is that we don't want to wait
  4136. // for the parsing to be completed, before we start importing
  4137. // the file. That's because in the context of a browser,
  4138. // most of the time will be spent waiting for the server to respond.
  4139. //
  4140. // On creation, we push the import path to our import queue, though
  4141. // `import,push`, we also pass it a callback, which it'll call once
  4142. // the file has been fetched, and parsed.
  4143. //
  4144. var Import =
  4145. /*#__PURE__*/
  4146. function (_Node) {
  4147. _inherits(Import, _Node);
  4148. function Import(path, features, options, index, currentFileInfo, visibilityInfo) {
  4149. var _this;
  4150. _classCallCheck(this, Import);
  4151. _this = _possibleConstructorReturn(this, _getPrototypeOf(Import).call(this));
  4152. _this.options = options;
  4153. _this._index = index;
  4154. _this._fileInfo = currentFileInfo;
  4155. _this.path = path;
  4156. _this.features = features;
  4157. _this.allowRoot = true;
  4158. if (_this.options.less !== undefined || _this.options.inline) {
  4159. _this.css = !_this.options.less || _this.options.inline;
  4160. } else {
  4161. var pathValue = _this.getPath();
  4162. if (pathValue && /[#\.\&\?]css([\?;].*)?$/.test(pathValue)) {
  4163. _this.css = true;
  4164. }
  4165. }
  4166. _this.copyVisibilityInfo(visibilityInfo);
  4167. _this.setParent(_this.features, _assertThisInitialized(_this));
  4168. _this.setParent(_this.path, _assertThisInitialized(_this));
  4169. return _this;
  4170. }
  4171. _createClass(Import, [{
  4172. key: "accept",
  4173. value: function accept(visitor) {
  4174. if (this.features) {
  4175. this.features = visitor.visit(this.features);
  4176. }
  4177. this.path = visitor.visit(this.path);
  4178. if (!this.options.isPlugin && !this.options.inline && this.root) {
  4179. this.root = visitor.visit(this.root);
  4180. }
  4181. }
  4182. }, {
  4183. key: "genCSS",
  4184. value: function genCSS(context, output) {
  4185. if (this.css && this.path._fileInfo.reference === undefined) {
  4186. output.add('@import ', this._fileInfo, this._index);
  4187. this.path.genCSS(context, output);
  4188. if (this.features) {
  4189. output.add(' ');
  4190. this.features.genCSS(context, output);
  4191. }
  4192. output.add(';');
  4193. }
  4194. }
  4195. }, {
  4196. key: "getPath",
  4197. value: function getPath() {
  4198. return this.path instanceof URL ? this.path.value.value : this.path.value;
  4199. }
  4200. }, {
  4201. key: "isVariableImport",
  4202. value: function isVariableImport() {
  4203. var path = this.path;
  4204. if (path instanceof URL) {
  4205. path = path.value;
  4206. }
  4207. if (path instanceof Quoted) {
  4208. return path.containsVariables();
  4209. }
  4210. return true;
  4211. }
  4212. }, {
  4213. key: "evalForImport",
  4214. value: function evalForImport(context) {
  4215. var path = this.path;
  4216. if (path instanceof URL) {
  4217. path = path.value;
  4218. }
  4219. return new Import(path.eval(context), this.features, this.options, this._index, this._fileInfo, this.visibilityInfo());
  4220. }
  4221. }, {
  4222. key: "evalPath",
  4223. value: function evalPath(context) {
  4224. var path = this.path.eval(context);
  4225. var fileInfo = this._fileInfo;
  4226. if (!(path instanceof URL)) {
  4227. // Add the rootpath if the URL requires a rewrite
  4228. var pathValue = path.value;
  4229. if (fileInfo && pathValue && context.pathRequiresRewrite(pathValue)) {
  4230. path.value = context.rewritePath(pathValue, fileInfo.rootpath);
  4231. } else {
  4232. path.value = context.normalizePath(path.value);
  4233. }
  4234. }
  4235. return path;
  4236. }
  4237. }, {
  4238. key: "eval",
  4239. value: function _eval(context) {
  4240. var result = this.doEval(context);
  4241. if (this.options.reference || this.blocksVisibility()) {
  4242. if (result.length || result.length === 0) {
  4243. result.forEach(function (node) {
  4244. node.addVisibilityBlock();
  4245. });
  4246. } else {
  4247. result.addVisibilityBlock();
  4248. }
  4249. }
  4250. return result;
  4251. }
  4252. }, {
  4253. key: "doEval",
  4254. value: function doEval(context) {
  4255. var ruleset;
  4256. var registry;
  4257. var features = this.features && this.features.eval(context);
  4258. if (this.options.isPlugin) {
  4259. if (this.root && this.root.eval) {
  4260. try {
  4261. this.root.eval(context);
  4262. } catch (e) {
  4263. e.message = 'Plugin error during evaluation';
  4264. throw new LessError(e, this.root.imports, this.root.filename);
  4265. }
  4266. }
  4267. registry = context.frames[0] && context.frames[0].functionRegistry;
  4268. if (registry && this.root && this.root.functions) {
  4269. registry.addMultiple(this.root.functions);
  4270. }
  4271. return [];
  4272. }
  4273. if (this.skip) {
  4274. if (typeof this.skip === 'function') {
  4275. this.skip = this.skip();
  4276. }
  4277. if (this.skip) {
  4278. return [];
  4279. }
  4280. }
  4281. if (this.options.inline) {
  4282. var contents = new Anonymous(this.root, 0, {
  4283. filename: this.importedFilename,
  4284. reference: this.path._fileInfo && this.path._fileInfo.reference
  4285. }, true, true);
  4286. return this.features ? new Media([contents], this.features.value) : [contents];
  4287. } else if (this.css) {
  4288. var newImport = new Import(this.evalPath(context), features, this.options, this._index);
  4289. if (!newImport.css && this.error) {
  4290. throw this.error;
  4291. }
  4292. return newImport;
  4293. } else {
  4294. ruleset = new Ruleset(null, copyArray(this.root.rules));
  4295. ruleset.evalImports(context);
  4296. return this.features ? new Media(ruleset.rules, this.features.value) : ruleset.rules;
  4297. }
  4298. }
  4299. }]);
  4300. return Import;
  4301. }(Node);
  4302. Import.prototype.type = 'Import';
  4303. var JsEvalNode =
  4304. /*#__PURE__*/
  4305. function (_Node) {
  4306. _inherits(JsEvalNode, _Node);
  4307. function JsEvalNode() {
  4308. _classCallCheck(this, JsEvalNode);
  4309. return _possibleConstructorReturn(this, _getPrototypeOf(JsEvalNode).apply(this, arguments));
  4310. }
  4311. _createClass(JsEvalNode, [{
  4312. key: "evaluateJavaScript",
  4313. value: function evaluateJavaScript(expression, context) {
  4314. var result;
  4315. var that = this;
  4316. var evalContext = {};
  4317. if (!context.javascriptEnabled) {
  4318. throw {
  4319. message: 'Inline JavaScript is not enabled. Is it set in your options?',
  4320. filename: this.fileInfo().filename,
  4321. index: this.getIndex()
  4322. };
  4323. }
  4324. expression = expression.replace(/@\{([\w-]+)\}/g, function (_, name) {
  4325. return that.jsify(new Variable("@".concat(name), that.getIndex(), that.fileInfo()).eval(context));
  4326. });
  4327. try {
  4328. expression = new Function("return (".concat(expression, ")"));
  4329. } catch (e) {
  4330. throw {
  4331. message: "JavaScript evaluation error: ".concat(e.message, " from `").concat(expression, "`"),
  4332. filename: this.fileInfo().filename,
  4333. index: this.getIndex()
  4334. };
  4335. }
  4336. var variables = context.frames[0].variables();
  4337. for (var k in variables) {
  4338. if (variables.hasOwnProperty(k)) {
  4339. /* jshint loopfunc:true */
  4340. evalContext[k.slice(1)] = {
  4341. value: variables[k].value,
  4342. toJS: function toJS() {
  4343. return this.value.eval(context).toCSS();
  4344. }
  4345. };
  4346. }
  4347. }
  4348. try {
  4349. result = expression.call(evalContext);
  4350. } catch (e) {
  4351. throw {
  4352. message: "JavaScript evaluation error: '".concat(e.name, ": ").concat(e.message.replace(/["]/g, '\''), "'"),
  4353. filename: this.fileInfo().filename,
  4354. index: this.getIndex()
  4355. };
  4356. }
  4357. return result;
  4358. }
  4359. }, {
  4360. key: "jsify",
  4361. value: function jsify(obj) {
  4362. if (Array.isArray(obj.value) && obj.value.length > 1) {
  4363. return "[".concat(obj.value.map(function (v) {
  4364. return v.toCSS();
  4365. }).join(', '), "]");
  4366. } else {
  4367. return obj.toCSS();
  4368. }
  4369. }
  4370. }]);
  4371. return JsEvalNode;
  4372. }(Node);
  4373. var JavaScript =
  4374. /*#__PURE__*/
  4375. function (_JsEvalNode) {
  4376. _inherits(JavaScript, _JsEvalNode);
  4377. function JavaScript(string, escaped, index, currentFileInfo) {
  4378. var _this;
  4379. _classCallCheck(this, JavaScript);
  4380. _this = _possibleConstructorReturn(this, _getPrototypeOf(JavaScript).call(this));
  4381. _this.escaped = escaped;
  4382. _this.expression = string;
  4383. _this._index = index;
  4384. _this._fileInfo = currentFileInfo;
  4385. return _this;
  4386. }
  4387. _createClass(JavaScript, [{
  4388. key: "eval",
  4389. value: function _eval(context) {
  4390. var result = this.evaluateJavaScript(this.expression, context);
  4391. var type = _typeof(result);
  4392. if (type === 'number' && !isNaN(result)) {
  4393. return new Dimension(result);
  4394. } else if (type === 'string') {
  4395. return new Quoted("\"".concat(result, "\""), result, this.escaped, this._index);
  4396. } else if (Array.isArray(result)) {
  4397. return new Anonymous(result.join(', '));
  4398. } else {
  4399. return new Anonymous(result);
  4400. }
  4401. }
  4402. }]);
  4403. return JavaScript;
  4404. }(JsEvalNode);
  4405. JavaScript.prototype.type = 'JavaScript';
  4406. var Assignment =
  4407. /*#__PURE__*/
  4408. function (_Node) {
  4409. _inherits(Assignment, _Node);
  4410. function Assignment(key, val) {
  4411. var _this;
  4412. _classCallCheck(this, Assignment);
  4413. _this = _possibleConstructorReturn(this, _getPrototypeOf(Assignment).call(this));
  4414. _this.key = key;
  4415. _this.value = val;
  4416. return _this;
  4417. }
  4418. _createClass(Assignment, [{
  4419. key: "accept",
  4420. value: function accept(visitor) {
  4421. this.value = visitor.visit(this.value);
  4422. }
  4423. }, {
  4424. key: "eval",
  4425. value: function _eval(context) {
  4426. if (this.value.eval) {
  4427. return new Assignment(this.key, this.value.eval(context));
  4428. }
  4429. return this;
  4430. }
  4431. }, {
  4432. key: "genCSS",
  4433. value: function genCSS(context, output) {
  4434. output.add("".concat(this.key, "="));
  4435. if (this.value.genCSS) {
  4436. this.value.genCSS(context, output);
  4437. } else {
  4438. output.add(this.value);
  4439. }
  4440. }
  4441. }]);
  4442. return Assignment;
  4443. }(Node);
  4444. Assignment.prototype.type = 'Assignment';
  4445. var Condition =
  4446. /*#__PURE__*/
  4447. function (_Node) {
  4448. _inherits(Condition, _Node);
  4449. function Condition(op, l, r, i, negate) {
  4450. var _this;
  4451. _classCallCheck(this, Condition);
  4452. _this = _possibleConstructorReturn(this, _getPrototypeOf(Condition).call(this));
  4453. _this.op = op.trim();
  4454. _this.lvalue = l;
  4455. _this.rvalue = r;
  4456. _this._index = i;
  4457. _this.negate = negate;
  4458. return _this;
  4459. }
  4460. _createClass(Condition, [{
  4461. key: "accept",
  4462. value: function accept(visitor) {
  4463. this.lvalue = visitor.visit(this.lvalue);
  4464. this.rvalue = visitor.visit(this.rvalue);
  4465. }
  4466. }, {
  4467. key: "eval",
  4468. value: function _eval(context) {
  4469. var result = function (op, a, b) {
  4470. switch (op) {
  4471. case 'and':
  4472. return a && b;
  4473. case 'or':
  4474. return a || b;
  4475. default:
  4476. switch (Node.compare(a, b)) {
  4477. case -1:
  4478. return op === '<' || op === '=<' || op === '<=';
  4479. case 0:
  4480. return op === '=' || op === '>=' || op === '=<' || op === '<=';
  4481. case 1:
  4482. return op === '>' || op === '>=';
  4483. default:
  4484. return false;
  4485. }
  4486. }
  4487. }(this.op, this.lvalue.eval(context), this.rvalue.eval(context));
  4488. return this.negate ? !result : result;
  4489. }
  4490. }]);
  4491. return Condition;
  4492. }(Node);
  4493. Condition.prototype.type = 'Condition';
  4494. var UnicodeDescriptor =
  4495. /*#__PURE__*/
  4496. function (_Node) {
  4497. _inherits(UnicodeDescriptor, _Node);
  4498. function UnicodeDescriptor(value) {
  4499. var _this;
  4500. _classCallCheck(this, UnicodeDescriptor);
  4501. _this = _possibleConstructorReturn(this, _getPrototypeOf(UnicodeDescriptor).call(this));
  4502. _this.value = value;
  4503. return _this;
  4504. }
  4505. return UnicodeDescriptor;
  4506. }(Node);
  4507. UnicodeDescriptor.prototype.type = 'UnicodeDescriptor';
  4508. var Negative =
  4509. /*#__PURE__*/
  4510. function (_Node) {
  4511. _inherits(Negative, _Node);
  4512. function Negative(node) {
  4513. var _this;
  4514. _classCallCheck(this, Negative);
  4515. _this = _possibleConstructorReturn(this, _getPrototypeOf(Negative).call(this));
  4516. _this.value = node;
  4517. return _this;
  4518. }
  4519. _createClass(Negative, [{
  4520. key: "genCSS",
  4521. value: function genCSS(context, output) {
  4522. output.add('-');
  4523. this.value.genCSS(context, output);
  4524. }
  4525. }, {
  4526. key: "eval",
  4527. value: function _eval(context) {
  4528. if (context.isMathOn()) {
  4529. return new Operation('*', [new Dimension(-1), this.value]).eval(context);
  4530. }
  4531. return new Negative(this.value.eval(context));
  4532. }
  4533. }]);
  4534. return Negative;
  4535. }(Node);
  4536. Negative.prototype.type = 'Negative';
  4537. var Extend =
  4538. /*#__PURE__*/
  4539. function (_Node) {
  4540. _inherits(Extend, _Node);
  4541. function Extend(selector, option, index, currentFileInfo, visibilityInfo) {
  4542. var _this;
  4543. _classCallCheck(this, Extend);
  4544. _this = _possibleConstructorReturn(this, _getPrototypeOf(Extend).call(this));
  4545. _this.selector = selector;
  4546. _this.option = option;
  4547. _this.object_id = Extend.next_id++;
  4548. _this.parent_ids = [_this.object_id];
  4549. _this._index = index;
  4550. _this._fileInfo = currentFileInfo;
  4551. _this.copyVisibilityInfo(visibilityInfo);
  4552. _this.allowRoot = true;
  4553. switch (option) {
  4554. case 'all':
  4555. _this.allowBefore = true;
  4556. _this.allowAfter = true;
  4557. break;
  4558. default:
  4559. _this.allowBefore = false;
  4560. _this.allowAfter = false;
  4561. break;
  4562. }
  4563. _this.setParent(_this.selector, _assertThisInitialized(_this));
  4564. return _this;
  4565. }
  4566. _createClass(Extend, [{
  4567. key: "accept",
  4568. value: function accept(visitor) {
  4569. this.selector = visitor.visit(this.selector);
  4570. }
  4571. }, {
  4572. key: "eval",
  4573. value: function _eval(context) {
  4574. return new Extend(this.selector.eval(context), this.option, this.getIndex(), this.fileInfo(), this.visibilityInfo());
  4575. }
  4576. }, {
  4577. key: "clone",
  4578. value: function clone(context) {
  4579. return new Extend(this.selector, this.option, this.getIndex(), this.fileInfo(), this.visibilityInfo());
  4580. } // it concatenates (joins) all selectors in selector array
  4581. }, {
  4582. key: "findSelfSelectors",
  4583. value: function findSelfSelectors(selectors) {
  4584. var selfElements = [];
  4585. var i;
  4586. var selectorElements;
  4587. for (i = 0; i < selectors.length; i++) {
  4588. selectorElements = selectors[i].elements; // duplicate the logic in genCSS function inside the selector node.
  4589. // future TODO - move both logics into the selector joiner visitor
  4590. if (i > 0 && selectorElements.length && selectorElements[0].combinator.value === '') {
  4591. selectorElements[0].combinator.value = ' ';
  4592. }
  4593. selfElements = selfElements.concat(selectors[i].elements);
  4594. }
  4595. this.selfSelectors = [new Selector(selfElements)];
  4596. this.selfSelectors[0].copyVisibilityInfo(this.visibilityInfo());
  4597. }
  4598. }]);
  4599. return Extend;
  4600. }(Node);
  4601. Extend.next_id = 0;
  4602. Extend.prototype.type = 'Extend';
  4603. var VariableCall =
  4604. /*#__PURE__*/
  4605. function (_Node) {
  4606. _inherits(VariableCall, _Node);
  4607. function VariableCall(variable, index, currentFileInfo) {
  4608. var _this;
  4609. _classCallCheck(this, VariableCall);
  4610. _this = _possibleConstructorReturn(this, _getPrototypeOf(VariableCall).call(this));
  4611. _this.variable = variable;
  4612. _this._index = index;
  4613. _this._fileInfo = currentFileInfo;
  4614. _this.allowRoot = true;
  4615. return _this;
  4616. }
  4617. _createClass(VariableCall, [{
  4618. key: "eval",
  4619. value: function _eval(context) {
  4620. var rules;
  4621. var detachedRuleset = new Variable(this.variable, this.getIndex(), this.fileInfo()).eval(context);
  4622. var error = new LessError({
  4623. message: "Could not evaluate variable call ".concat(this.variable)
  4624. });
  4625. if (!detachedRuleset.ruleset) {
  4626. if (detachedRuleset.rules) {
  4627. rules = detachedRuleset;
  4628. } else if (Array.isArray(detachedRuleset)) {
  4629. rules = new Ruleset('', detachedRuleset);
  4630. } else if (Array.isArray(detachedRuleset.value)) {
  4631. rules = new Ruleset('', detachedRuleset.value);
  4632. } else {
  4633. throw error;
  4634. }
  4635. detachedRuleset = new DetachedRuleset(rules);
  4636. }
  4637. if (detachedRuleset.ruleset) {
  4638. return detachedRuleset.callEval(context);
  4639. }
  4640. throw error;
  4641. }
  4642. }]);
  4643. return VariableCall;
  4644. }(Node);
  4645. VariableCall.prototype.type = 'VariableCall';
  4646. var NamespaceValue =
  4647. /*#__PURE__*/
  4648. function (_Node) {
  4649. _inherits(NamespaceValue, _Node);
  4650. function NamespaceValue(ruleCall, lookups, important, index, fileInfo) {
  4651. var _this;
  4652. _classCallCheck(this, NamespaceValue);
  4653. _this = _possibleConstructorReturn(this, _getPrototypeOf(NamespaceValue).call(this));
  4654. _this.value = ruleCall;
  4655. _this.lookups = lookups;
  4656. _this.important = important;
  4657. _this._index = index;
  4658. _this._fileInfo = fileInfo;
  4659. return _this;
  4660. }
  4661. _createClass(NamespaceValue, [{
  4662. key: "eval",
  4663. value: function _eval(context) {
  4664. var i;
  4665. var name;
  4666. var rules = this.value.eval(context);
  4667. for (i = 0; i < this.lookups.length; i++) {
  4668. name = this.lookups[i];
  4669. /**
  4670. * Eval'd DRs return rulesets.
  4671. * Eval'd mixins return rules, so let's make a ruleset if we need it.
  4672. * We need to do this because of late parsing of values
  4673. */
  4674. if (Array.isArray(rules)) {
  4675. rules = new Ruleset([new Selector()], rules);
  4676. }
  4677. if (name === '') {
  4678. rules = rules.lastDeclaration();
  4679. } else if (name.charAt(0) === '@') {
  4680. if (name.charAt(1) === '@') {
  4681. name = "@".concat(new Variable(name.substr(1)).eval(context).value);
  4682. }
  4683. if (rules.variables) {
  4684. rules = rules.variable(name);
  4685. }
  4686. if (!rules) {
  4687. throw {
  4688. type: 'Name',
  4689. message: "variable ".concat(name, " not found"),
  4690. filename: this.fileInfo().filename,
  4691. index: this.getIndex()
  4692. };
  4693. }
  4694. } else {
  4695. if (name.substring(0, 2) === '$@') {
  4696. name = "$".concat(new Variable(name.substr(1)).eval(context).value);
  4697. } else {
  4698. name = name.charAt(0) === '$' ? name : "$".concat(name);
  4699. }
  4700. if (rules.properties) {
  4701. rules = rules.property(name);
  4702. }
  4703. if (!rules) {
  4704. throw {
  4705. type: 'Name',
  4706. message: "property \"".concat(name.substr(1), "\" not found"),
  4707. filename: this.fileInfo().filename,
  4708. index: this.getIndex()
  4709. };
  4710. } // Properties are an array of values, since a ruleset can have multiple props.
  4711. // We pick the last one (the "cascaded" value)
  4712. rules = rules[rules.length - 1];
  4713. }
  4714. if (rules.value) {
  4715. rules = rules.eval(context).value;
  4716. }
  4717. if (rules.ruleset) {
  4718. rules = rules.ruleset.eval(context);
  4719. }
  4720. }
  4721. return rules;
  4722. }
  4723. }]);
  4724. return NamespaceValue;
  4725. }(Node);
  4726. NamespaceValue.prototype.type = 'NamespaceValue';
  4727. var Definition =
  4728. /*#__PURE__*/
  4729. function (_Ruleset) {
  4730. _inherits(Definition, _Ruleset);
  4731. function Definition(name, params, rules, condition, variadic, frames, visibilityInfo) {
  4732. var _this;
  4733. _classCallCheck(this, Definition);
  4734. _this = _possibleConstructorReturn(this, _getPrototypeOf(Definition).call(this));
  4735. _this.name = name || 'anonymous mixin';
  4736. _this.selectors = [new Selector([new Element(null, name, false, _this._index, _this._fileInfo)])];
  4737. _this.params = params;
  4738. _this.condition = condition;
  4739. _this.variadic = variadic;
  4740. _this.arity = params.length;
  4741. _this.rules = rules;
  4742. _this._lookups = {};
  4743. var optionalParameters = [];
  4744. _this.required = params.reduce(function (count, p) {
  4745. if (!p.name || p.name && !p.value) {
  4746. return count + 1;
  4747. } else {
  4748. optionalParameters.push(p.name);
  4749. return count;
  4750. }
  4751. }, 0);
  4752. _this.optionalParameters = optionalParameters;
  4753. _this.frames = frames;
  4754. _this.copyVisibilityInfo(visibilityInfo);
  4755. _this.allowRoot = true;
  4756. return _this;
  4757. }
  4758. _createClass(Definition, [{
  4759. key: "accept",
  4760. value: function accept(visitor) {
  4761. if (this.params && this.params.length) {
  4762. this.params = visitor.visitArray(this.params);
  4763. }
  4764. this.rules = visitor.visitArray(this.rules);
  4765. if (this.condition) {
  4766. this.condition = visitor.visit(this.condition);
  4767. }
  4768. }
  4769. }, {
  4770. key: "evalParams",
  4771. value: function evalParams(context, mixinEnv, args, evaldArguments) {
  4772. /* jshint boss:true */
  4773. var frame = new Ruleset(null, null);
  4774. var varargs;
  4775. var arg;
  4776. var params = copyArray(this.params);
  4777. var i;
  4778. var j;
  4779. var val;
  4780. var name;
  4781. var isNamedFound;
  4782. var argIndex;
  4783. var argsLength = 0;
  4784. if (mixinEnv.frames && mixinEnv.frames[0] && mixinEnv.frames[0].functionRegistry) {
  4785. frame.functionRegistry = mixinEnv.frames[0].functionRegistry.inherit();
  4786. }
  4787. mixinEnv = new contexts.Eval(mixinEnv, [frame].concat(mixinEnv.frames));
  4788. if (args) {
  4789. args = copyArray(args);
  4790. argsLength = args.length;
  4791. for (i = 0; i < argsLength; i++) {
  4792. arg = args[i];
  4793. if (name = arg && arg.name) {
  4794. isNamedFound = false;
  4795. for (j = 0; j < params.length; j++) {
  4796. if (!evaldArguments[j] && name === params[j].name) {
  4797. evaldArguments[j] = arg.value.eval(context);
  4798. frame.prependRule(new Declaration(name, arg.value.eval(context)));
  4799. isNamedFound = true;
  4800. break;
  4801. }
  4802. }
  4803. if (isNamedFound) {
  4804. args.splice(i, 1);
  4805. i--;
  4806. continue;
  4807. } else {
  4808. throw {
  4809. type: 'Runtime',
  4810. message: "Named argument for ".concat(this.name, " ").concat(args[i].name, " not found")
  4811. };
  4812. }
  4813. }
  4814. }
  4815. }
  4816. argIndex = 0;
  4817. for (i = 0; i < params.length; i++) {
  4818. if (evaldArguments[i]) {
  4819. continue;
  4820. }
  4821. arg = args && args[argIndex];
  4822. if (name = params[i].name) {
  4823. if (params[i].variadic) {
  4824. varargs = [];
  4825. for (j = argIndex; j < argsLength; j++) {
  4826. varargs.push(args[j].value.eval(context));
  4827. }
  4828. frame.prependRule(new Declaration(name, new Expression(varargs).eval(context)));
  4829. } else {
  4830. val = arg && arg.value;
  4831. if (val) {
  4832. // This was a mixin call, pass in a detached ruleset of it's eval'd rules
  4833. if (Array.isArray(val)) {
  4834. val = new DetachedRuleset(new Ruleset('', val));
  4835. } else {
  4836. val = val.eval(context);
  4837. }
  4838. } else if (params[i].value) {
  4839. val = params[i].value.eval(mixinEnv);
  4840. frame.resetCache();
  4841. } else {
  4842. throw {
  4843. type: 'Runtime',
  4844. message: "wrong number of arguments for ".concat(this.name, " (").concat(argsLength, " for ").concat(this.arity, ")")
  4845. };
  4846. }
  4847. frame.prependRule(new Declaration(name, val));
  4848. evaldArguments[i] = val;
  4849. }
  4850. }
  4851. if (params[i].variadic && args) {
  4852. for (j = argIndex; j < argsLength; j++) {
  4853. evaldArguments[j] = args[j].value.eval(context);
  4854. }
  4855. }
  4856. argIndex++;
  4857. }
  4858. return frame;
  4859. }
  4860. }, {
  4861. key: "makeImportant",
  4862. value: function makeImportant() {
  4863. var rules = !this.rules ? this.rules : this.rules.map(function (r) {
  4864. if (r.makeImportant) {
  4865. return r.makeImportant(true);
  4866. } else {
  4867. return r;
  4868. }
  4869. });
  4870. var result = new Definition(this.name, this.params, rules, this.condition, this.variadic, this.frames);
  4871. return result;
  4872. }
  4873. }, {
  4874. key: "eval",
  4875. value: function _eval(context) {
  4876. return new Definition(this.name, this.params, this.rules, this.condition, this.variadic, this.frames || copyArray(context.frames));
  4877. }
  4878. }, {
  4879. key: "evalCall",
  4880. value: function evalCall(context, args, important) {
  4881. var _arguments = [];
  4882. var mixinFrames = this.frames ? this.frames.concat(context.frames) : context.frames;
  4883. var frame = this.evalParams(context, new contexts.Eval(context, mixinFrames), args, _arguments);
  4884. var rules;
  4885. var ruleset;
  4886. frame.prependRule(new Declaration('@arguments', new Expression(_arguments).eval(context)));
  4887. rules = copyArray(this.rules);
  4888. ruleset = new Ruleset(null, rules);
  4889. ruleset.originalRuleset = this;
  4890. ruleset = ruleset.eval(new contexts.Eval(context, [this, frame].concat(mixinFrames)));
  4891. if (important) {
  4892. ruleset = ruleset.makeImportant();
  4893. }
  4894. return ruleset;
  4895. }
  4896. }, {
  4897. key: "matchCondition",
  4898. value: function matchCondition(args, context) {
  4899. if (this.condition && !this.condition.eval(new contexts.Eval(context, [this.evalParams(context,
  4900. /* the parameter variables */
  4901. new contexts.Eval(context, this.frames ? this.frames.concat(context.frames) : context.frames), args, [])].concat(this.frames || []) // the parent namespace/mixin frames
  4902. .concat(context.frames)))) {
  4903. // the current environment frames
  4904. return false;
  4905. }
  4906. return true;
  4907. }
  4908. }, {
  4909. key: "matchArgs",
  4910. value: function matchArgs(args, context) {
  4911. var allArgsCnt = args && args.length || 0;
  4912. var len;
  4913. var optionalParameters = this.optionalParameters;
  4914. var requiredArgsCnt = !args ? 0 : args.reduce(function (count, p) {
  4915. if (optionalParameters.indexOf(p.name) < 0) {
  4916. return count + 1;
  4917. } else {
  4918. return count;
  4919. }
  4920. }, 0);
  4921. if (!this.variadic) {
  4922. if (requiredArgsCnt < this.required) {
  4923. return false;
  4924. }
  4925. if (allArgsCnt > this.params.length) {
  4926. return false;
  4927. }
  4928. } else {
  4929. if (requiredArgsCnt < this.required - 1) {
  4930. return false;
  4931. }
  4932. } // check patterns
  4933. len = Math.min(requiredArgsCnt, this.arity);
  4934. for (var i = 0; i < len; i++) {
  4935. if (!this.params[i].name && !this.params[i].variadic) {
  4936. if (args[i].value.eval(context).toCSS() != this.params[i].value.eval(context).toCSS()) {
  4937. return false;
  4938. }
  4939. }
  4940. }
  4941. return true;
  4942. }
  4943. }]);
  4944. return Definition;
  4945. }(Ruleset);
  4946. Definition.prototype.type = 'MixinDefinition';
  4947. Definition.prototype.evalFirst = true;
  4948. var MixinCall =
  4949. /*#__PURE__*/
  4950. function (_Node) {
  4951. _inherits(MixinCall, _Node);
  4952. function MixinCall(elements, args, index, currentFileInfo, important) {
  4953. var _this;
  4954. _classCallCheck(this, MixinCall);
  4955. _this = _possibleConstructorReturn(this, _getPrototypeOf(MixinCall).call(this));
  4956. _this.selector = new Selector(elements);
  4957. _this.arguments = args || [];
  4958. _this._index = index;
  4959. _this._fileInfo = currentFileInfo;
  4960. _this.important = important;
  4961. _this.allowRoot = true;
  4962. _this.setParent(_this.selector, _assertThisInitialized(_this));
  4963. return _this;
  4964. }
  4965. _createClass(MixinCall, [{
  4966. key: "accept",
  4967. value: function accept(visitor) {
  4968. if (this.selector) {
  4969. this.selector = visitor.visit(this.selector);
  4970. }
  4971. if (this.arguments.length) {
  4972. this.arguments = visitor.visitArray(this.arguments);
  4973. }
  4974. }
  4975. }, {
  4976. key: "eval",
  4977. value: function _eval(context) {
  4978. var mixins;
  4979. var mixin;
  4980. var mixinPath;
  4981. var args = [];
  4982. var arg;
  4983. var argValue;
  4984. var rules = [];
  4985. var match = false;
  4986. var i;
  4987. var m;
  4988. var f;
  4989. var isRecursive;
  4990. var isOneFound;
  4991. var candidates = [];
  4992. var candidate;
  4993. var conditionResult = [];
  4994. var defaultResult;
  4995. var defFalseEitherCase = -1;
  4996. var defNone = 0;
  4997. var defTrue = 1;
  4998. var defFalse = 2;
  4999. var count;
  5000. var originalRuleset;
  5001. var noArgumentsFilter;
  5002. this.selector = this.selector.eval(context);
  5003. function calcDefGroup(mixin, mixinPath) {
  5004. var f;
  5005. var p;
  5006. var namespace;
  5007. for (f = 0; f < 2; f++) {
  5008. conditionResult[f] = true;
  5009. defaultFunc.value(f);
  5010. for (p = 0; p < mixinPath.length && conditionResult[f]; p++) {
  5011. namespace = mixinPath[p];
  5012. if (namespace.matchCondition) {
  5013. conditionResult[f] = conditionResult[f] && namespace.matchCondition(null, context);
  5014. }
  5015. }
  5016. if (mixin.matchCondition) {
  5017. conditionResult[f] = conditionResult[f] && mixin.matchCondition(args, context);
  5018. }
  5019. }
  5020. if (conditionResult[0] || conditionResult[1]) {
  5021. if (conditionResult[0] != conditionResult[1]) {
  5022. return conditionResult[1] ? defTrue : defFalse;
  5023. }
  5024. return defNone;
  5025. }
  5026. return defFalseEitherCase;
  5027. }
  5028. for (i = 0; i < this.arguments.length; i++) {
  5029. arg = this.arguments[i];
  5030. argValue = arg.value.eval(context);
  5031. if (arg.expand && Array.isArray(argValue.value)) {
  5032. argValue = argValue.value;
  5033. for (m = 0; m < argValue.length; m++) {
  5034. args.push({
  5035. value: argValue[m]
  5036. });
  5037. }
  5038. } else {
  5039. args.push({
  5040. name: arg.name,
  5041. value: argValue
  5042. });
  5043. }
  5044. }
  5045. noArgumentsFilter = function noArgumentsFilter(rule) {
  5046. return rule.matchArgs(null, context);
  5047. };
  5048. for (i = 0; i < context.frames.length; i++) {
  5049. if ((mixins = context.frames[i].find(this.selector, null, noArgumentsFilter)).length > 0) {
  5050. isOneFound = true; // To make `default()` function independent of definition order we have two "subpasses" here.
  5051. // At first we evaluate each guard *twice* (with `default() == true` and `default() == false`),
  5052. // and build candidate list with corresponding flags. Then, when we know all possible matches,
  5053. // we make a final decision.
  5054. for (m = 0; m < mixins.length; m++) {
  5055. mixin = mixins[m].rule;
  5056. mixinPath = mixins[m].path;
  5057. isRecursive = false;
  5058. for (f = 0; f < context.frames.length; f++) {
  5059. if (!(mixin instanceof Definition) && mixin === (context.frames[f].originalRuleset || context.frames[f])) {
  5060. isRecursive = true;
  5061. break;
  5062. }
  5063. }
  5064. if (isRecursive) {
  5065. continue;
  5066. }
  5067. if (mixin.matchArgs(args, context)) {
  5068. candidate = {
  5069. mixin: mixin,
  5070. group: calcDefGroup(mixin, mixinPath)
  5071. };
  5072. if (candidate.group !== defFalseEitherCase) {
  5073. candidates.push(candidate);
  5074. }
  5075. match = true;
  5076. }
  5077. }
  5078. defaultFunc.reset();
  5079. count = [0, 0, 0];
  5080. for (m = 0; m < candidates.length; m++) {
  5081. count[candidates[m].group]++;
  5082. }
  5083. if (count[defNone] > 0) {
  5084. defaultResult = defFalse;
  5085. } else {
  5086. defaultResult = defTrue;
  5087. if (count[defTrue] + count[defFalse] > 1) {
  5088. throw {
  5089. type: 'Runtime',
  5090. message: "Ambiguous use of `default()` found when matching for `".concat(this.format(args), "`"),
  5091. index: this.getIndex(),
  5092. filename: this.fileInfo().filename
  5093. };
  5094. }
  5095. }
  5096. for (m = 0; m < candidates.length; m++) {
  5097. candidate = candidates[m].group;
  5098. if (candidate === defNone || candidate === defaultResult) {
  5099. try {
  5100. mixin = candidates[m].mixin;
  5101. if (!(mixin instanceof Definition)) {
  5102. originalRuleset = mixin.originalRuleset || mixin;
  5103. mixin = new Definition('', [], mixin.rules, null, false, null, originalRuleset.visibilityInfo());
  5104. mixin.originalRuleset = originalRuleset;
  5105. }
  5106. var newRules = mixin.evalCall(context, args, this.important).rules;
  5107. this._setVisibilityToReplacement(newRules);
  5108. Array.prototype.push.apply(rules, newRules);
  5109. } catch (e) {
  5110. throw {
  5111. message: e.message,
  5112. index: this.getIndex(),
  5113. filename: this.fileInfo().filename,
  5114. stack: e.stack
  5115. };
  5116. }
  5117. }
  5118. }
  5119. if (match) {
  5120. return rules;
  5121. }
  5122. }
  5123. }
  5124. if (isOneFound) {
  5125. throw {
  5126. type: 'Runtime',
  5127. message: "No matching definition was found for `".concat(this.format(args), "`"),
  5128. index: this.getIndex(),
  5129. filename: this.fileInfo().filename
  5130. };
  5131. } else {
  5132. throw {
  5133. type: 'Name',
  5134. message: "".concat(this.selector.toCSS().trim(), " is undefined"),
  5135. index: this.getIndex(),
  5136. filename: this.fileInfo().filename
  5137. };
  5138. }
  5139. }
  5140. }, {
  5141. key: "_setVisibilityToReplacement",
  5142. value: function _setVisibilityToReplacement(replacement) {
  5143. var i;
  5144. var rule;
  5145. if (this.blocksVisibility()) {
  5146. for (i = 0; i < replacement.length; i++) {
  5147. rule = replacement[i];
  5148. rule.addVisibilityBlock();
  5149. }
  5150. }
  5151. }
  5152. }, {
  5153. key: "format",
  5154. value: function format(args) {
  5155. return "".concat(this.selector.toCSS().trim(), "(").concat(args ? args.map(function (a) {
  5156. var argValue = '';
  5157. if (a.name) {
  5158. argValue += "".concat(a.name, ":");
  5159. }
  5160. if (a.value.toCSS) {
  5161. argValue += a.value.toCSS();
  5162. } else {
  5163. argValue += '???';
  5164. }
  5165. return argValue;
  5166. }).join(', ') : '', ")");
  5167. }
  5168. }]);
  5169. return MixinCall;
  5170. }(Node);
  5171. MixinCall.prototype.type = 'MixinCall';
  5172. var tree = {
  5173. Node: Node,
  5174. Color: Color,
  5175. AtRule: AtRule,
  5176. DetachedRuleset: DetachedRuleset,
  5177. Operation: Operation,
  5178. Dimension: Dimension,
  5179. Unit: Unit,
  5180. Keyword: Keyword,
  5181. Variable: Variable,
  5182. Property: Property,
  5183. Ruleset: Ruleset,
  5184. Element: Element,
  5185. Attribute: Attribute,
  5186. Combinator: Combinator,
  5187. Selector: Selector,
  5188. Quoted: Quoted,
  5189. Expression: Expression,
  5190. Declaration: Declaration,
  5191. Call: Call,
  5192. URL: URL,
  5193. Import: Import,
  5194. Comment: Comment,
  5195. Anonymous: Anonymous,
  5196. Value: Value,
  5197. JavaScript: JavaScript,
  5198. Assignment: Assignment,
  5199. Condition: Condition,
  5200. Paren: Paren,
  5201. Media: Media,
  5202. UnicodeDescriptor: UnicodeDescriptor,
  5203. Negative: Negative,
  5204. Extend: Extend,
  5205. VariableCall: VariableCall,
  5206. NamespaceValue: NamespaceValue,
  5207. mixin: {
  5208. Call: MixinCall,
  5209. Definition: Definition
  5210. }
  5211. };
  5212. var logger = {
  5213. error: function error(msg) {
  5214. this._fireEvent('error', msg);
  5215. },
  5216. warn: function warn(msg) {
  5217. this._fireEvent('warn', msg);
  5218. },
  5219. info: function info(msg) {
  5220. this._fireEvent('info', msg);
  5221. },
  5222. debug: function debug(msg) {
  5223. this._fireEvent('debug', msg);
  5224. },
  5225. addListener: function addListener(listener) {
  5226. this._listeners.push(listener);
  5227. },
  5228. removeListener: function removeListener(listener) {
  5229. for (var i = 0; i < this._listeners.length; i++) {
  5230. if (this._listeners[i] === listener) {
  5231. this._listeners.splice(i, 1);
  5232. return;
  5233. }
  5234. }
  5235. },
  5236. _fireEvent: function _fireEvent(type, msg) {
  5237. for (var i = 0; i < this._listeners.length; i++) {
  5238. var logFunction = this._listeners[i][type];
  5239. if (logFunction) {
  5240. logFunction(msg);
  5241. }
  5242. }
  5243. },
  5244. _listeners: []
  5245. };
  5246. var environment =
  5247. /*#__PURE__*/
  5248. function () {
  5249. function environment(externalEnvironment, fileManagers) {
  5250. _classCallCheck(this, environment);
  5251. this.fileManagers = fileManagers || [];
  5252. externalEnvironment = externalEnvironment || {};
  5253. var optionalFunctions = ['encodeBase64', 'mimeLookup', 'charsetLookup', 'getSourceMapGenerator'];
  5254. var requiredFunctions = [];
  5255. var functions = requiredFunctions.concat(optionalFunctions);
  5256. for (var i = 0; i < functions.length; i++) {
  5257. var propName = functions[i];
  5258. var environmentFunc = externalEnvironment[propName];
  5259. if (environmentFunc) {
  5260. this[propName] = environmentFunc.bind(externalEnvironment);
  5261. } else if (i < requiredFunctions.length) {
  5262. this.warn("missing required function in environment - ".concat(propName));
  5263. }
  5264. }
  5265. }
  5266. _createClass(environment, [{
  5267. key: "getFileManager",
  5268. value: function getFileManager(filename, currentDirectory, options, environment, isSync) {
  5269. if (!filename) {
  5270. logger.warn('getFileManager called with no filename.. Please report this issue. continuing.');
  5271. }
  5272. if (currentDirectory == null) {
  5273. logger.warn('getFileManager called with null directory.. Please report this issue. continuing.');
  5274. }
  5275. var fileManagers = this.fileManagers;
  5276. if (options.pluginManager) {
  5277. fileManagers = [].concat(fileManagers).concat(options.pluginManager.getFileManagers());
  5278. }
  5279. for (var i = fileManagers.length - 1; i >= 0; i--) {
  5280. var fileManager = fileManagers[i];
  5281. if (fileManager[isSync ? 'supportsSync' : 'supports'](filename, currentDirectory, options, environment)) {
  5282. return fileManager;
  5283. }
  5284. }
  5285. return null;
  5286. }
  5287. }, {
  5288. key: "addFileManager",
  5289. value: function addFileManager(fileManager) {
  5290. this.fileManagers.push(fileManager);
  5291. }
  5292. }, {
  5293. key: "clearFileManagers",
  5294. value: function clearFileManagers() {
  5295. this.fileManagers = [];
  5296. }
  5297. }]);
  5298. return environment;
  5299. }();
  5300. var AbstractFileManager =
  5301. /*#__PURE__*/
  5302. function () {
  5303. function AbstractFileManager() {
  5304. _classCallCheck(this, AbstractFileManager);
  5305. }
  5306. _createClass(AbstractFileManager, [{
  5307. key: "getPath",
  5308. value: function getPath(filename) {
  5309. var j = filename.lastIndexOf('?');
  5310. if (j > 0) {
  5311. filename = filename.slice(0, j);
  5312. }
  5313. j = filename.lastIndexOf('/');
  5314. if (j < 0) {
  5315. j = filename.lastIndexOf('\\');
  5316. }
  5317. if (j < 0) {
  5318. return '';
  5319. }
  5320. return filename.slice(0, j + 1);
  5321. }
  5322. }, {
  5323. key: "tryAppendExtension",
  5324. value: function tryAppendExtension(path, ext) {
  5325. return /(\.[a-z]*$)|([\?;].*)$/.test(path) ? path : path + ext;
  5326. }
  5327. }, {
  5328. key: "tryAppendLessExtension",
  5329. value: function tryAppendLessExtension(path) {
  5330. return this.tryAppendExtension(path, '.less');
  5331. }
  5332. }, {
  5333. key: "supportsSync",
  5334. value: function supportsSync() {
  5335. return false;
  5336. }
  5337. }, {
  5338. key: "alwaysMakePathsAbsolute",
  5339. value: function alwaysMakePathsAbsolute() {
  5340. return false;
  5341. }
  5342. }, {
  5343. key: "isPathAbsolute",
  5344. value: function isPathAbsolute(filename) {
  5345. return /^(?:[a-z-]+:|\/|\\|#)/i.test(filename);
  5346. } // TODO: pull out / replace?
  5347. }, {
  5348. key: "join",
  5349. value: function join(basePath, laterPath) {
  5350. if (!basePath) {
  5351. return laterPath;
  5352. }
  5353. return basePath + laterPath;
  5354. }
  5355. }, {
  5356. key: "pathDiff",
  5357. value: function pathDiff(url, baseUrl) {
  5358. // diff between two paths to create a relative path
  5359. var urlParts = this.extractUrlParts(url);
  5360. var baseUrlParts = this.extractUrlParts(baseUrl);
  5361. var i;
  5362. var max;
  5363. var urlDirectories;
  5364. var baseUrlDirectories;
  5365. var diff = '';
  5366. if (urlParts.hostPart !== baseUrlParts.hostPart) {
  5367. return '';
  5368. }
  5369. max = Math.max(baseUrlParts.directories.length, urlParts.directories.length);
  5370. for (i = 0; i < max; i++) {
  5371. if (baseUrlParts.directories[i] !== urlParts.directories[i]) {
  5372. break;
  5373. }
  5374. }
  5375. baseUrlDirectories = baseUrlParts.directories.slice(i);
  5376. urlDirectories = urlParts.directories.slice(i);
  5377. for (i = 0; i < baseUrlDirectories.length - 1; i++) {
  5378. diff += '../';
  5379. }
  5380. for (i = 0; i < urlDirectories.length - 1; i++) {
  5381. diff += "".concat(urlDirectories[i], "/");
  5382. }
  5383. return diff;
  5384. }
  5385. }, {
  5386. key: "extractUrlParts",
  5387. // helper function, not part of API
  5388. value: function extractUrlParts(url, baseUrl) {
  5389. // urlParts[1] = protocol://hostname/ OR /
  5390. // urlParts[2] = / if path relative to host base
  5391. // urlParts[3] = directories
  5392. // urlParts[4] = filename
  5393. // urlParts[5] = parameters
  5394. var urlPartsRegex = /^((?:[a-z-]+:)?\/{2}(?:[^\/\?#]*\/)|([\/\\]))?((?:[^\/\\\?#]*[\/\\])*)([^\/\\\?#]*)([#\?].*)?$/i;
  5395. var urlParts = url.match(urlPartsRegex);
  5396. var returner = {};
  5397. var rawDirectories = [];
  5398. var directories = [];
  5399. var i;
  5400. var baseUrlParts;
  5401. if (!urlParts) {
  5402. throw new Error("Could not parse sheet href - '".concat(url, "'"));
  5403. } // Stylesheets in IE don't always return the full path
  5404. if (baseUrl && (!urlParts[1] || urlParts[2])) {
  5405. baseUrlParts = baseUrl.match(urlPartsRegex);
  5406. if (!baseUrlParts) {
  5407. throw new Error("Could not parse page url - '".concat(baseUrl, "'"));
  5408. }
  5409. urlParts[1] = urlParts[1] || baseUrlParts[1] || '';
  5410. if (!urlParts[2]) {
  5411. urlParts[3] = baseUrlParts[3] + urlParts[3];
  5412. }
  5413. }
  5414. if (urlParts[3]) {
  5415. rawDirectories = urlParts[3].replace(/\\/g, '/').split('/'); // collapse '..' and skip '.'
  5416. for (i = 0; i < rawDirectories.length; i++) {
  5417. if (rawDirectories[i] === '..') {
  5418. directories.pop();
  5419. } else if (rawDirectories[i] !== '.') {
  5420. directories.push(rawDirectories[i]);
  5421. }
  5422. }
  5423. }
  5424. returner.hostPart = urlParts[1];
  5425. returner.directories = directories;
  5426. returner.rawPath = (urlParts[1] || '') + rawDirectories.join('/');
  5427. returner.path = (urlParts[1] || '') + directories.join('/');
  5428. returner.filename = urlParts[4];
  5429. returner.fileUrl = returner.path + (urlParts[4] || '');
  5430. returner.url = returner.fileUrl + (urlParts[5] || '');
  5431. return returner;
  5432. }
  5433. }]);
  5434. return AbstractFileManager;
  5435. }();
  5436. var AbstractPluginLoader =
  5437. /*#__PURE__*/
  5438. function () {
  5439. function AbstractPluginLoader() {
  5440. _classCallCheck(this, AbstractPluginLoader);
  5441. // Implemented by Node.js plugin loader
  5442. this.require = function () {
  5443. return null;
  5444. };
  5445. }
  5446. _createClass(AbstractPluginLoader, [{
  5447. key: "evalPlugin",
  5448. value: function evalPlugin(contents, context, imports, pluginOptions, fileInfo) {
  5449. var loader;
  5450. var registry;
  5451. var pluginObj;
  5452. var localModule;
  5453. var pluginManager;
  5454. var filename;
  5455. var result;
  5456. pluginManager = context.pluginManager;
  5457. if (fileInfo) {
  5458. if (typeof fileInfo === 'string') {
  5459. filename = fileInfo;
  5460. } else {
  5461. filename = fileInfo.filename;
  5462. }
  5463. }
  5464. var shortname = new this.less.FileManager().extractUrlParts(filename).filename;
  5465. if (filename) {
  5466. pluginObj = pluginManager.get(filename);
  5467. if (pluginObj) {
  5468. result = this.trySetOptions(pluginObj, filename, shortname, pluginOptions);
  5469. if (result) {
  5470. return result;
  5471. }
  5472. try {
  5473. if (pluginObj.use) {
  5474. pluginObj.use.call(this.context, pluginObj);
  5475. }
  5476. } catch (e) {
  5477. e.message = e.message || 'Error during @plugin call';
  5478. return new LessError(e, imports, filename);
  5479. }
  5480. return pluginObj;
  5481. }
  5482. }
  5483. localModule = {
  5484. exports: {},
  5485. pluginManager: pluginManager,
  5486. fileInfo: fileInfo
  5487. };
  5488. registry = functionRegistry.create();
  5489. var registerPlugin = function registerPlugin(obj) {
  5490. pluginObj = obj;
  5491. };
  5492. try {
  5493. loader = new Function('module', 'require', 'registerPlugin', 'functions', 'tree', 'less', 'fileInfo', contents);
  5494. loader(localModule, this.require(filename), registerPlugin, registry, this.less.tree, this.less, fileInfo);
  5495. } catch (e) {
  5496. return new LessError(e, imports, filename);
  5497. }
  5498. if (!pluginObj) {
  5499. pluginObj = localModule.exports;
  5500. }
  5501. pluginObj = this.validatePlugin(pluginObj, filename, shortname);
  5502. if (pluginObj instanceof LessError) {
  5503. return pluginObj;
  5504. }
  5505. if (pluginObj) {
  5506. pluginObj.imports = imports;
  5507. pluginObj.filename = filename; // For < 3.x (or unspecified minVersion) - setOptions() before install()
  5508. if (!pluginObj.minVersion || this.compareVersion('3.0.0', pluginObj.minVersion) < 0) {
  5509. result = this.trySetOptions(pluginObj, filename, shortname, pluginOptions);
  5510. if (result) {
  5511. return result;
  5512. }
  5513. } // Run on first load
  5514. pluginManager.addPlugin(pluginObj, fileInfo.filename, registry);
  5515. pluginObj.functions = registry.getLocalFunctions(); // Need to call setOptions again because the pluginObj might have functions
  5516. result = this.trySetOptions(pluginObj, filename, shortname, pluginOptions);
  5517. if (result) {
  5518. return result;
  5519. } // Run every @plugin call
  5520. try {
  5521. if (pluginObj.use) {
  5522. pluginObj.use.call(this.context, pluginObj);
  5523. }
  5524. } catch (e) {
  5525. e.message = e.message || 'Error during @plugin call';
  5526. return new LessError(e, imports, filename);
  5527. }
  5528. } else {
  5529. return new LessError({
  5530. message: 'Not a valid plugin'
  5531. }, imports, filename);
  5532. }
  5533. return pluginObj;
  5534. }
  5535. }, {
  5536. key: "trySetOptions",
  5537. value: function trySetOptions(plugin, filename, name, options) {
  5538. if (options && !plugin.setOptions) {
  5539. return new LessError({
  5540. message: "Options have been provided but the plugin ".concat(name, " does not support any options.")
  5541. });
  5542. }
  5543. try {
  5544. plugin.setOptions && plugin.setOptions(options);
  5545. } catch (e) {
  5546. return new LessError(e);
  5547. }
  5548. }
  5549. }, {
  5550. key: "validatePlugin",
  5551. value: function validatePlugin(plugin, filename, name) {
  5552. if (plugin) {
  5553. // support plugins being a function
  5554. // so that the plugin can be more usable programmatically
  5555. if (typeof plugin === 'function') {
  5556. plugin = new plugin();
  5557. }
  5558. if (plugin.minVersion) {
  5559. if (this.compareVersion(plugin.minVersion, this.less.version) < 0) {
  5560. return new LessError({
  5561. message: "Plugin ".concat(name, " requires version ").concat(this.versionToString(plugin.minVersion))
  5562. });
  5563. }
  5564. }
  5565. return plugin;
  5566. }
  5567. return null;
  5568. }
  5569. }, {
  5570. key: "compareVersion",
  5571. value: function compareVersion(aVersion, bVersion) {
  5572. if (typeof aVersion === 'string') {
  5573. aVersion = aVersion.match(/^(\d+)\.?(\d+)?\.?(\d+)?/);
  5574. aVersion.shift();
  5575. }
  5576. for (var i = 0; i < aVersion.length; i++) {
  5577. if (aVersion[i] !== bVersion[i]) {
  5578. return parseInt(aVersion[i]) > parseInt(bVersion[i]) ? -1 : 1;
  5579. }
  5580. }
  5581. return 0;
  5582. }
  5583. }, {
  5584. key: "versionToString",
  5585. value: function versionToString(version) {
  5586. var versionString = '';
  5587. for (var i = 0; i < version.length; i++) {
  5588. versionString += (versionString ? '.' : '') + version[i];
  5589. }
  5590. return versionString;
  5591. }
  5592. }, {
  5593. key: "printUsage",
  5594. value: function printUsage(plugins) {
  5595. for (var i = 0; i < plugins.length; i++) {
  5596. var plugin = plugins[i];
  5597. if (plugin.printUsage) {
  5598. plugin.printUsage();
  5599. }
  5600. }
  5601. }
  5602. }]);
  5603. return AbstractPluginLoader;
  5604. }();
  5605. var _visitArgs = {
  5606. visitDeeper: true
  5607. };
  5608. var _hasIndexed = false;
  5609. function _noop(node) {
  5610. return node;
  5611. }
  5612. function indexNodeTypes(parent, ticker) {
  5613. // add .typeIndex to tree node types for lookup table
  5614. var key;
  5615. var child;
  5616. for (key in parent) {
  5617. /* eslint guard-for-in: 0 */
  5618. child = parent[key];
  5619. switch (_typeof(child)) {
  5620. case 'function':
  5621. // ignore bound functions directly on tree which do not have a prototype
  5622. // or aren't nodes
  5623. if (child.prototype && child.prototype.type) {
  5624. child.prototype.typeIndex = ticker++;
  5625. }
  5626. break;
  5627. case 'object':
  5628. ticker = indexNodeTypes(child, ticker);
  5629. break;
  5630. }
  5631. }
  5632. return ticker;
  5633. }
  5634. var Visitor =
  5635. /*#__PURE__*/
  5636. function () {
  5637. function Visitor(implementation) {
  5638. _classCallCheck(this, Visitor);
  5639. this._implementation = implementation;
  5640. this._visitInCache = {};
  5641. this._visitOutCache = {};
  5642. if (!_hasIndexed) {
  5643. indexNodeTypes(tree, 1);
  5644. _hasIndexed = true;
  5645. }
  5646. }
  5647. _createClass(Visitor, [{
  5648. key: "visit",
  5649. value: function visit(node) {
  5650. if (!node) {
  5651. return node;
  5652. }
  5653. var nodeTypeIndex = node.typeIndex;
  5654. if (!nodeTypeIndex) {
  5655. // MixinCall args aren't a node type?
  5656. if (node.value && node.value.typeIndex) {
  5657. this.visit(node.value);
  5658. }
  5659. return node;
  5660. }
  5661. var impl = this._implementation;
  5662. var func = this._visitInCache[nodeTypeIndex];
  5663. var funcOut = this._visitOutCache[nodeTypeIndex];
  5664. var visitArgs = _visitArgs;
  5665. var fnName;
  5666. visitArgs.visitDeeper = true;
  5667. if (!func) {
  5668. fnName = "visit".concat(node.type);
  5669. func = impl[fnName] || _noop;
  5670. funcOut = impl["".concat(fnName, "Out")] || _noop;
  5671. this._visitInCache[nodeTypeIndex] = func;
  5672. this._visitOutCache[nodeTypeIndex] = funcOut;
  5673. }
  5674. if (func !== _noop) {
  5675. var newNode = func.call(impl, node, visitArgs);
  5676. if (node && impl.isReplacing) {
  5677. node = newNode;
  5678. }
  5679. }
  5680. if (visitArgs.visitDeeper && node && node.accept) {
  5681. node.accept(this);
  5682. }
  5683. if (funcOut != _noop) {
  5684. funcOut.call(impl, node);
  5685. }
  5686. return node;
  5687. }
  5688. }, {
  5689. key: "visitArray",
  5690. value: function visitArray(nodes, nonReplacing) {
  5691. if (!nodes) {
  5692. return nodes;
  5693. }
  5694. var cnt = nodes.length;
  5695. var i; // Non-replacing
  5696. if (nonReplacing || !this._implementation.isReplacing) {
  5697. for (i = 0; i < cnt; i++) {
  5698. this.visit(nodes[i]);
  5699. }
  5700. return nodes;
  5701. } // Replacing
  5702. var out = [];
  5703. for (i = 0; i < cnt; i++) {
  5704. var evald = this.visit(nodes[i]);
  5705. if (evald === undefined) {
  5706. continue;
  5707. }
  5708. if (!evald.splice) {
  5709. out.push(evald);
  5710. } else if (evald.length) {
  5711. this.flatten(evald, out);
  5712. }
  5713. }
  5714. return out;
  5715. }
  5716. }, {
  5717. key: "flatten",
  5718. value: function flatten(arr, out) {
  5719. if (!out) {
  5720. out = [];
  5721. }
  5722. var cnt;
  5723. var i;
  5724. var item;
  5725. var nestedCnt;
  5726. var j;
  5727. var nestedItem;
  5728. for (i = 0, cnt = arr.length; i < cnt; i++) {
  5729. item = arr[i];
  5730. if (item === undefined) {
  5731. continue;
  5732. }
  5733. if (!item.splice) {
  5734. out.push(item);
  5735. continue;
  5736. }
  5737. for (j = 0, nestedCnt = item.length; j < nestedCnt; j++) {
  5738. nestedItem = item[j];
  5739. if (nestedItem === undefined) {
  5740. continue;
  5741. }
  5742. if (!nestedItem.splice) {
  5743. out.push(nestedItem);
  5744. } else if (nestedItem.length) {
  5745. this.flatten(nestedItem, out);
  5746. }
  5747. }
  5748. }
  5749. return out;
  5750. }
  5751. }]);
  5752. return Visitor;
  5753. }();
  5754. var ImportSequencer =
  5755. /*#__PURE__*/
  5756. function () {
  5757. function ImportSequencer(onSequencerEmpty) {
  5758. _classCallCheck(this, ImportSequencer);
  5759. this.imports = [];
  5760. this.variableImports = [];
  5761. this._onSequencerEmpty = onSequencerEmpty;
  5762. this._currentDepth = 0;
  5763. }
  5764. _createClass(ImportSequencer, [{
  5765. key: "addImport",
  5766. value: function addImport(callback) {
  5767. var importSequencer = this;
  5768. var importItem = {
  5769. callback: callback,
  5770. args: null,
  5771. isReady: false
  5772. };
  5773. this.imports.push(importItem);
  5774. return function () {
  5775. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  5776. args[_key] = arguments[_key];
  5777. }
  5778. importItem.args = Array.prototype.slice.call(args, 0);
  5779. importItem.isReady = true;
  5780. importSequencer.tryRun();
  5781. };
  5782. }
  5783. }, {
  5784. key: "addVariableImport",
  5785. value: function addVariableImport(callback) {
  5786. this.variableImports.push(callback);
  5787. }
  5788. }, {
  5789. key: "tryRun",
  5790. value: function tryRun() {
  5791. this._currentDepth++;
  5792. try {
  5793. while (true) {
  5794. while (this.imports.length > 0) {
  5795. var importItem = this.imports[0];
  5796. if (!importItem.isReady) {
  5797. return;
  5798. }
  5799. this.imports = this.imports.slice(1);
  5800. importItem.callback.apply(null, importItem.args);
  5801. }
  5802. if (this.variableImports.length === 0) {
  5803. break;
  5804. }
  5805. var variableImport = this.variableImports[0];
  5806. this.variableImports = this.variableImports.slice(1);
  5807. variableImport();
  5808. }
  5809. } finally {
  5810. this._currentDepth--;
  5811. }
  5812. if (this._currentDepth === 0 && this._onSequencerEmpty) {
  5813. this._onSequencerEmpty();
  5814. }
  5815. }
  5816. }]);
  5817. return ImportSequencer;
  5818. }();
  5819. var ImportVisitor = function ImportVisitor(importer, finish) {
  5820. this._visitor = new Visitor(this);
  5821. this._importer = importer;
  5822. this._finish = finish;
  5823. this.context = new contexts.Eval();
  5824. this.importCount = 0;
  5825. this.onceFileDetectionMap = {};
  5826. this.recursionDetector = {};
  5827. this._sequencer = new ImportSequencer(this._onSequencerEmpty.bind(this));
  5828. };
  5829. ImportVisitor.prototype = {
  5830. isReplacing: false,
  5831. run: function run(root) {
  5832. try {
  5833. // process the contents
  5834. this._visitor.visit(root);
  5835. } catch (e) {
  5836. this.error = e;
  5837. }
  5838. this.isFinished = true;
  5839. this._sequencer.tryRun();
  5840. },
  5841. _onSequencerEmpty: function _onSequencerEmpty() {
  5842. if (!this.isFinished) {
  5843. return;
  5844. }
  5845. this._finish(this.error);
  5846. },
  5847. visitImport: function visitImport(importNode, visitArgs) {
  5848. var inlineCSS = importNode.options.inline;
  5849. if (!importNode.css || inlineCSS) {
  5850. var context = new contexts.Eval(this.context, copyArray(this.context.frames));
  5851. var importParent = context.frames[0];
  5852. this.importCount++;
  5853. if (importNode.isVariableImport()) {
  5854. this._sequencer.addVariableImport(this.processImportNode.bind(this, importNode, context, importParent));
  5855. } else {
  5856. this.processImportNode(importNode, context, importParent);
  5857. }
  5858. }
  5859. visitArgs.visitDeeper = false;
  5860. },
  5861. processImportNode: function processImportNode(importNode, context, importParent) {
  5862. var evaldImportNode;
  5863. var inlineCSS = importNode.options.inline;
  5864. try {
  5865. evaldImportNode = importNode.evalForImport(context);
  5866. } catch (e) {
  5867. if (!e.filename) {
  5868. e.index = importNode.getIndex();
  5869. e.filename = importNode.fileInfo().filename;
  5870. } // attempt to eval properly and treat as css
  5871. importNode.css = true; // if that fails, this error will be thrown
  5872. importNode.error = e;
  5873. }
  5874. if (evaldImportNode && (!evaldImportNode.css || inlineCSS)) {
  5875. if (evaldImportNode.options.multiple) {
  5876. context.importMultiple = true;
  5877. } // try appending if we haven't determined if it is css or not
  5878. var tryAppendLessExtension = evaldImportNode.css === undefined;
  5879. for (var i = 0; i < importParent.rules.length; i++) {
  5880. if (importParent.rules[i] === importNode) {
  5881. importParent.rules[i] = evaldImportNode;
  5882. break;
  5883. }
  5884. }
  5885. var onImported = this.onImported.bind(this, evaldImportNode, context);
  5886. var sequencedOnImported = this._sequencer.addImport(onImported);
  5887. this._importer.push(evaldImportNode.getPath(), tryAppendLessExtension, evaldImportNode.fileInfo(), evaldImportNode.options, sequencedOnImported);
  5888. } else {
  5889. this.importCount--;
  5890. if (this.isFinished) {
  5891. this._sequencer.tryRun();
  5892. }
  5893. }
  5894. },
  5895. onImported: function onImported(importNode, context, e, root, importedAtRoot, fullPath) {
  5896. if (e) {
  5897. if (!e.filename) {
  5898. e.index = importNode.getIndex();
  5899. e.filename = importNode.fileInfo().filename;
  5900. }
  5901. this.error = e;
  5902. }
  5903. var importVisitor = this;
  5904. var inlineCSS = importNode.options.inline;
  5905. var isPlugin = importNode.options.isPlugin;
  5906. var isOptional = importNode.options.optional;
  5907. var duplicateImport = importedAtRoot || fullPath in importVisitor.recursionDetector;
  5908. if (!context.importMultiple) {
  5909. if (duplicateImport) {
  5910. importNode.skip = true;
  5911. } else {
  5912. importNode.skip = function () {
  5913. if (fullPath in importVisitor.onceFileDetectionMap) {
  5914. return true;
  5915. }
  5916. importVisitor.onceFileDetectionMap[fullPath] = true;
  5917. return false;
  5918. };
  5919. }
  5920. }
  5921. if (!fullPath && isOptional) {
  5922. importNode.skip = true;
  5923. }
  5924. if (root) {
  5925. importNode.root = root;
  5926. importNode.importedFilename = fullPath;
  5927. if (!inlineCSS && !isPlugin && (context.importMultiple || !duplicateImport)) {
  5928. importVisitor.recursionDetector[fullPath] = true;
  5929. var oldContext = this.context;
  5930. this.context = context;
  5931. try {
  5932. this._visitor.visit(root);
  5933. } catch (e) {
  5934. this.error = e;
  5935. }
  5936. this.context = oldContext;
  5937. }
  5938. }
  5939. importVisitor.importCount--;
  5940. if (importVisitor.isFinished) {
  5941. importVisitor._sequencer.tryRun();
  5942. }
  5943. },
  5944. visitDeclaration: function visitDeclaration(declNode, visitArgs) {
  5945. if (declNode.value.type === 'DetachedRuleset') {
  5946. this.context.frames.unshift(declNode);
  5947. } else {
  5948. visitArgs.visitDeeper = false;
  5949. }
  5950. },
  5951. visitDeclarationOut: function visitDeclarationOut(declNode) {
  5952. if (declNode.value.type === 'DetachedRuleset') {
  5953. this.context.frames.shift();
  5954. }
  5955. },
  5956. visitAtRule: function visitAtRule(atRuleNode, visitArgs) {
  5957. this.context.frames.unshift(atRuleNode);
  5958. },
  5959. visitAtRuleOut: function visitAtRuleOut(atRuleNode) {
  5960. this.context.frames.shift();
  5961. },
  5962. visitMixinDefinition: function visitMixinDefinition(mixinDefinitionNode, visitArgs) {
  5963. this.context.frames.unshift(mixinDefinitionNode);
  5964. },
  5965. visitMixinDefinitionOut: function visitMixinDefinitionOut(mixinDefinitionNode) {
  5966. this.context.frames.shift();
  5967. },
  5968. visitRuleset: function visitRuleset(rulesetNode, visitArgs) {
  5969. this.context.frames.unshift(rulesetNode);
  5970. },
  5971. visitRulesetOut: function visitRulesetOut(rulesetNode) {
  5972. this.context.frames.shift();
  5973. },
  5974. visitMedia: function visitMedia(mediaNode, visitArgs) {
  5975. this.context.frames.unshift(mediaNode.rules[0]);
  5976. },
  5977. visitMediaOut: function visitMediaOut(mediaNode) {
  5978. this.context.frames.shift();
  5979. }
  5980. };
  5981. var SetTreeVisibilityVisitor =
  5982. /*#__PURE__*/
  5983. function () {
  5984. function SetTreeVisibilityVisitor(visible) {
  5985. _classCallCheck(this, SetTreeVisibilityVisitor);
  5986. this.visible = visible;
  5987. }
  5988. _createClass(SetTreeVisibilityVisitor, [{
  5989. key: "run",
  5990. value: function run(root) {
  5991. this.visit(root);
  5992. }
  5993. }, {
  5994. key: "visitArray",
  5995. value: function visitArray(nodes) {
  5996. if (!nodes) {
  5997. return nodes;
  5998. }
  5999. var cnt = nodes.length;
  6000. var i;
  6001. for (i = 0; i < cnt; i++) {
  6002. this.visit(nodes[i]);
  6003. }
  6004. return nodes;
  6005. }
  6006. }, {
  6007. key: "visit",
  6008. value: function visit(node) {
  6009. if (!node) {
  6010. return node;
  6011. }
  6012. if (node.constructor === Array) {
  6013. return this.visitArray(node);
  6014. }
  6015. if (!node.blocksVisibility || node.blocksVisibility()) {
  6016. return node;
  6017. }
  6018. if (this.visible) {
  6019. node.ensureVisibility();
  6020. } else {
  6021. node.ensureInvisibility();
  6022. }
  6023. node.accept(this);
  6024. return node;
  6025. }
  6026. }]);
  6027. return SetTreeVisibilityVisitor;
  6028. }();
  6029. /* jshint loopfunc:true */
  6030. var ExtendFinderVisitor =
  6031. /*#__PURE__*/
  6032. function () {
  6033. function ExtendFinderVisitor() {
  6034. _classCallCheck(this, ExtendFinderVisitor);
  6035. this._visitor = new Visitor(this);
  6036. this.contexts = [];
  6037. this.allExtendsStack = [[]];
  6038. }
  6039. _createClass(ExtendFinderVisitor, [{
  6040. key: "run",
  6041. value: function run(root) {
  6042. root = this._visitor.visit(root);
  6043. root.allExtends = this.allExtendsStack[0];
  6044. return root;
  6045. }
  6046. }, {
  6047. key: "visitDeclaration",
  6048. value: function visitDeclaration(declNode, visitArgs) {
  6049. visitArgs.visitDeeper = false;
  6050. }
  6051. }, {
  6052. key: "visitMixinDefinition",
  6053. value: function visitMixinDefinition(mixinDefinitionNode, visitArgs) {
  6054. visitArgs.visitDeeper = false;
  6055. }
  6056. }, {
  6057. key: "visitRuleset",
  6058. value: function visitRuleset(rulesetNode, visitArgs) {
  6059. if (rulesetNode.root) {
  6060. return;
  6061. }
  6062. var i;
  6063. var j;
  6064. var extend;
  6065. var allSelectorsExtendList = [];
  6066. var extendList; // get &:extend(.a); rules which apply to all selectors in this ruleset
  6067. var rules = rulesetNode.rules;
  6068. var ruleCnt = rules ? rules.length : 0;
  6069. for (i = 0; i < ruleCnt; i++) {
  6070. if (rulesetNode.rules[i] instanceof tree.Extend) {
  6071. allSelectorsExtendList.push(rules[i]);
  6072. rulesetNode.extendOnEveryPath = true;
  6073. }
  6074. } // now find every selector and apply the extends that apply to all extends
  6075. // and the ones which apply to an individual extend
  6076. var paths = rulesetNode.paths;
  6077. for (i = 0; i < paths.length; i++) {
  6078. var selectorPath = paths[i];
  6079. var selector = selectorPath[selectorPath.length - 1];
  6080. var selExtendList = selector.extendList;
  6081. extendList = selExtendList ? copyArray(selExtendList).concat(allSelectorsExtendList) : allSelectorsExtendList;
  6082. if (extendList) {
  6083. extendList = extendList.map(function (allSelectorsExtend) {
  6084. return allSelectorsExtend.clone();
  6085. });
  6086. }
  6087. for (j = 0; j < extendList.length; j++) {
  6088. this.foundExtends = true;
  6089. extend = extendList[j];
  6090. extend.findSelfSelectors(selectorPath);
  6091. extend.ruleset = rulesetNode;
  6092. if (j === 0) {
  6093. extend.firstExtendOnThisSelectorPath = true;
  6094. }
  6095. this.allExtendsStack[this.allExtendsStack.length - 1].push(extend);
  6096. }
  6097. }
  6098. this.contexts.push(rulesetNode.selectors);
  6099. }
  6100. }, {
  6101. key: "visitRulesetOut",
  6102. value: function visitRulesetOut(rulesetNode) {
  6103. if (!rulesetNode.root) {
  6104. this.contexts.length = this.contexts.length - 1;
  6105. }
  6106. }
  6107. }, {
  6108. key: "visitMedia",
  6109. value: function visitMedia(mediaNode, visitArgs) {
  6110. mediaNode.allExtends = [];
  6111. this.allExtendsStack.push(mediaNode.allExtends);
  6112. }
  6113. }, {
  6114. key: "visitMediaOut",
  6115. value: function visitMediaOut(mediaNode) {
  6116. this.allExtendsStack.length = this.allExtendsStack.length - 1;
  6117. }
  6118. }, {
  6119. key: "visitAtRule",
  6120. value: function visitAtRule(atRuleNode, visitArgs) {
  6121. atRuleNode.allExtends = [];
  6122. this.allExtendsStack.push(atRuleNode.allExtends);
  6123. }
  6124. }, {
  6125. key: "visitAtRuleOut",
  6126. value: function visitAtRuleOut(atRuleNode) {
  6127. this.allExtendsStack.length = this.allExtendsStack.length - 1;
  6128. }
  6129. }]);
  6130. return ExtendFinderVisitor;
  6131. }();
  6132. var ProcessExtendsVisitor =
  6133. /*#__PURE__*/
  6134. function () {
  6135. function ProcessExtendsVisitor() {
  6136. _classCallCheck(this, ProcessExtendsVisitor);
  6137. this._visitor = new Visitor(this);
  6138. }
  6139. _createClass(ProcessExtendsVisitor, [{
  6140. key: "run",
  6141. value: function run(root) {
  6142. var extendFinder = new ExtendFinderVisitor();
  6143. this.extendIndices = {};
  6144. extendFinder.run(root);
  6145. if (!extendFinder.foundExtends) {
  6146. return root;
  6147. }
  6148. root.allExtends = root.allExtends.concat(this.doExtendChaining(root.allExtends, root.allExtends));
  6149. this.allExtendsStack = [root.allExtends];
  6150. var newRoot = this._visitor.visit(root);
  6151. this.checkExtendsForNonMatched(root.allExtends);
  6152. return newRoot;
  6153. }
  6154. }, {
  6155. key: "checkExtendsForNonMatched",
  6156. value: function checkExtendsForNonMatched(extendList) {
  6157. var indices = this.extendIndices;
  6158. extendList.filter(function (extend) {
  6159. return !extend.hasFoundMatches && extend.parent_ids.length == 1;
  6160. }).forEach(function (extend) {
  6161. var selector = '_unknown_';
  6162. try {
  6163. selector = extend.selector.toCSS({});
  6164. } catch (_) {}
  6165. if (!indices["".concat(extend.index, " ").concat(selector)]) {
  6166. indices["".concat(extend.index, " ").concat(selector)] = true;
  6167. logger.warn("extend '".concat(selector, "' has no matches"));
  6168. }
  6169. });
  6170. }
  6171. }, {
  6172. key: "doExtendChaining",
  6173. value: function doExtendChaining(extendsList, extendsListTarget, iterationCount) {
  6174. //
  6175. // chaining is different from normal extension.. if we extend an extend then we are not just copying, altering
  6176. // and pasting the selector we would do normally, but we are also adding an extend with the same target selector
  6177. // this means this new extend can then go and alter other extends
  6178. //
  6179. // this method deals with all the chaining work - without it, extend is flat and doesn't work on other extend selectors
  6180. // this is also the most expensive.. and a match on one selector can cause an extension of a selector we had already
  6181. // processed if we look at each selector at a time, as is done in visitRuleset
  6182. var extendIndex;
  6183. var targetExtendIndex;
  6184. var matches;
  6185. var extendsToAdd = [];
  6186. var newSelector;
  6187. var extendVisitor = this;
  6188. var selectorPath;
  6189. var extend;
  6190. var targetExtend;
  6191. var newExtend;
  6192. iterationCount = iterationCount || 0; // loop through comparing every extend with every target extend.
  6193. // a target extend is the one on the ruleset we are looking at copy/edit/pasting in place
  6194. // e.g. .a:extend(.b) {} and .b:extend(.c) {} then the first extend extends the second one
  6195. // and the second is the target.
  6196. // the separation into two lists allows us to process a subset of chains with a bigger set, as is the
  6197. // case when processing media queries
  6198. for (extendIndex = 0; extendIndex < extendsList.length; extendIndex++) {
  6199. for (targetExtendIndex = 0; targetExtendIndex < extendsListTarget.length; targetExtendIndex++) {
  6200. extend = extendsList[extendIndex];
  6201. targetExtend = extendsListTarget[targetExtendIndex]; // look for circular references
  6202. if (extend.parent_ids.indexOf(targetExtend.object_id) >= 0) {
  6203. continue;
  6204. } // find a match in the target extends self selector (the bit before :extend)
  6205. selectorPath = [targetExtend.selfSelectors[0]];
  6206. matches = extendVisitor.findMatch(extend, selectorPath);
  6207. if (matches.length) {
  6208. extend.hasFoundMatches = true; // we found a match, so for each self selector..
  6209. extend.selfSelectors.forEach(function (selfSelector) {
  6210. var info = targetExtend.visibilityInfo(); // process the extend as usual
  6211. newSelector = extendVisitor.extendSelector(matches, selectorPath, selfSelector, extend.isVisible()); // but now we create a new extend from it
  6212. newExtend = new tree.Extend(targetExtend.selector, targetExtend.option, 0, targetExtend.fileInfo(), info);
  6213. newExtend.selfSelectors = newSelector; // add the extend onto the list of extends for that selector
  6214. newSelector[newSelector.length - 1].extendList = [newExtend]; // record that we need to add it.
  6215. extendsToAdd.push(newExtend);
  6216. newExtend.ruleset = targetExtend.ruleset; // remember its parents for circular references
  6217. newExtend.parent_ids = newExtend.parent_ids.concat(targetExtend.parent_ids, extend.parent_ids); // only process the selector once.. if we have :extend(.a,.b) then multiple
  6218. // extends will look at the same selector path, so when extending
  6219. // we know that any others will be duplicates in terms of what is added to the css
  6220. if (targetExtend.firstExtendOnThisSelectorPath) {
  6221. newExtend.firstExtendOnThisSelectorPath = true;
  6222. targetExtend.ruleset.paths.push(newSelector);
  6223. }
  6224. });
  6225. }
  6226. }
  6227. }
  6228. if (extendsToAdd.length) {
  6229. // try to detect circular references to stop a stack overflow.
  6230. // may no longer be needed.
  6231. this.extendChainCount++;
  6232. if (iterationCount > 100) {
  6233. var selectorOne = '{unable to calculate}';
  6234. var selectorTwo = '{unable to calculate}';
  6235. try {
  6236. selectorOne = extendsToAdd[0].selfSelectors[0].toCSS();
  6237. selectorTwo = extendsToAdd[0].selector.toCSS();
  6238. } catch (e) {}
  6239. throw {
  6240. message: "extend circular reference detected. One of the circular extends is currently:".concat(selectorOne, ":extend(").concat(selectorTwo, ")")
  6241. };
  6242. } // now process the new extends on the existing rules so that we can handle a extending b extending c extending
  6243. // d extending e...
  6244. return extendsToAdd.concat(extendVisitor.doExtendChaining(extendsToAdd, extendsListTarget, iterationCount + 1));
  6245. } else {
  6246. return extendsToAdd;
  6247. }
  6248. }
  6249. }, {
  6250. key: "visitDeclaration",
  6251. value: function visitDeclaration(ruleNode, visitArgs) {
  6252. visitArgs.visitDeeper = false;
  6253. }
  6254. }, {
  6255. key: "visitMixinDefinition",
  6256. value: function visitMixinDefinition(mixinDefinitionNode, visitArgs) {
  6257. visitArgs.visitDeeper = false;
  6258. }
  6259. }, {
  6260. key: "visitSelector",
  6261. value: function visitSelector(selectorNode, visitArgs) {
  6262. visitArgs.visitDeeper = false;
  6263. }
  6264. }, {
  6265. key: "visitRuleset",
  6266. value: function visitRuleset(rulesetNode, visitArgs) {
  6267. if (rulesetNode.root) {
  6268. return;
  6269. }
  6270. var matches;
  6271. var pathIndex;
  6272. var extendIndex;
  6273. var allExtends = this.allExtendsStack[this.allExtendsStack.length - 1];
  6274. var selectorsToAdd = [];
  6275. var extendVisitor = this;
  6276. var selectorPath; // look at each selector path in the ruleset, find any extend matches and then copy, find and replace
  6277. for (extendIndex = 0; extendIndex < allExtends.length; extendIndex++) {
  6278. for (pathIndex = 0; pathIndex < rulesetNode.paths.length; pathIndex++) {
  6279. selectorPath = rulesetNode.paths[pathIndex]; // extending extends happens initially, before the main pass
  6280. if (rulesetNode.extendOnEveryPath) {
  6281. continue;
  6282. }
  6283. var extendList = selectorPath[selectorPath.length - 1].extendList;
  6284. if (extendList && extendList.length) {
  6285. continue;
  6286. }
  6287. matches = this.findMatch(allExtends[extendIndex], selectorPath);
  6288. if (matches.length) {
  6289. allExtends[extendIndex].hasFoundMatches = true;
  6290. allExtends[extendIndex].selfSelectors.forEach(function (selfSelector) {
  6291. var extendedSelectors;
  6292. extendedSelectors = extendVisitor.extendSelector(matches, selectorPath, selfSelector, allExtends[extendIndex].isVisible());
  6293. selectorsToAdd.push(extendedSelectors);
  6294. });
  6295. }
  6296. }
  6297. }
  6298. rulesetNode.paths = rulesetNode.paths.concat(selectorsToAdd);
  6299. }
  6300. }, {
  6301. key: "findMatch",
  6302. value: function findMatch(extend, haystackSelectorPath) {
  6303. //
  6304. // look through the haystack selector path to try and find the needle - extend.selector
  6305. // returns an array of selector matches that can then be replaced
  6306. //
  6307. var haystackSelectorIndex;
  6308. var hackstackSelector;
  6309. var hackstackElementIndex;
  6310. var haystackElement;
  6311. var targetCombinator;
  6312. var i;
  6313. var extendVisitor = this;
  6314. var needleElements = extend.selector.elements;
  6315. var potentialMatches = [];
  6316. var potentialMatch;
  6317. var matches = []; // loop through the haystack elements
  6318. for (haystackSelectorIndex = 0; haystackSelectorIndex < haystackSelectorPath.length; haystackSelectorIndex++) {
  6319. hackstackSelector = haystackSelectorPath[haystackSelectorIndex];
  6320. for (hackstackElementIndex = 0; hackstackElementIndex < hackstackSelector.elements.length; hackstackElementIndex++) {
  6321. haystackElement = hackstackSelector.elements[hackstackElementIndex]; // if we allow elements before our match we can add a potential match every time. otherwise only at the first element.
  6322. if (extend.allowBefore || haystackSelectorIndex === 0 && hackstackElementIndex === 0) {
  6323. potentialMatches.push({
  6324. pathIndex: haystackSelectorIndex,
  6325. index: hackstackElementIndex,
  6326. matched: 0,
  6327. initialCombinator: haystackElement.combinator
  6328. });
  6329. }
  6330. for (i = 0; i < potentialMatches.length; i++) {
  6331. potentialMatch = potentialMatches[i]; // selectors add " " onto the first element. When we use & it joins the selectors together, but if we don't
  6332. // then each selector in haystackSelectorPath has a space before it added in the toCSS phase. so we need to
  6333. // work out what the resulting combinator will be
  6334. targetCombinator = haystackElement.combinator.value;
  6335. if (targetCombinator === '' && hackstackElementIndex === 0) {
  6336. targetCombinator = ' ';
  6337. } // if we don't match, null our match to indicate failure
  6338. if (!extendVisitor.isElementValuesEqual(needleElements[potentialMatch.matched].value, haystackElement.value) || potentialMatch.matched > 0 && needleElements[potentialMatch.matched].combinator.value !== targetCombinator) {
  6339. potentialMatch = null;
  6340. } else {
  6341. potentialMatch.matched++;
  6342. } // if we are still valid and have finished, test whether we have elements after and whether these are allowed
  6343. if (potentialMatch) {
  6344. potentialMatch.finished = potentialMatch.matched === needleElements.length;
  6345. if (potentialMatch.finished && !extend.allowAfter && (hackstackElementIndex + 1 < hackstackSelector.elements.length || haystackSelectorIndex + 1 < haystackSelectorPath.length)) {
  6346. potentialMatch = null;
  6347. }
  6348. } // if null we remove, if not, we are still valid, so either push as a valid match or continue
  6349. if (potentialMatch) {
  6350. if (potentialMatch.finished) {
  6351. potentialMatch.length = needleElements.length;
  6352. potentialMatch.endPathIndex = haystackSelectorIndex;
  6353. potentialMatch.endPathElementIndex = hackstackElementIndex + 1; // index after end of match
  6354. potentialMatches.length = 0; // we don't allow matches to overlap, so start matching again
  6355. matches.push(potentialMatch);
  6356. }
  6357. } else {
  6358. potentialMatches.splice(i, 1);
  6359. i--;
  6360. }
  6361. }
  6362. }
  6363. }
  6364. return matches;
  6365. }
  6366. }, {
  6367. key: "isElementValuesEqual",
  6368. value: function isElementValuesEqual(elementValue1, elementValue2) {
  6369. if (typeof elementValue1 === 'string' || typeof elementValue2 === 'string') {
  6370. return elementValue1 === elementValue2;
  6371. }
  6372. if (elementValue1 instanceof tree.Attribute) {
  6373. if (elementValue1.op !== elementValue2.op || elementValue1.key !== elementValue2.key) {
  6374. return false;
  6375. }
  6376. if (!elementValue1.value || !elementValue2.value) {
  6377. if (elementValue1.value || elementValue2.value) {
  6378. return false;
  6379. }
  6380. return true;
  6381. }
  6382. elementValue1 = elementValue1.value.value || elementValue1.value;
  6383. elementValue2 = elementValue2.value.value || elementValue2.value;
  6384. return elementValue1 === elementValue2;
  6385. }
  6386. elementValue1 = elementValue1.value;
  6387. elementValue2 = elementValue2.value;
  6388. if (elementValue1 instanceof tree.Selector) {
  6389. if (!(elementValue2 instanceof tree.Selector) || elementValue1.elements.length !== elementValue2.elements.length) {
  6390. return false;
  6391. }
  6392. for (var i = 0; i < elementValue1.elements.length; i++) {
  6393. if (elementValue1.elements[i].combinator.value !== elementValue2.elements[i].combinator.value) {
  6394. if (i !== 0 || (elementValue1.elements[i].combinator.value || ' ') !== (elementValue2.elements[i].combinator.value || ' ')) {
  6395. return false;
  6396. }
  6397. }
  6398. if (!this.isElementValuesEqual(elementValue1.elements[i].value, elementValue2.elements[i].value)) {
  6399. return false;
  6400. }
  6401. }
  6402. return true;
  6403. }
  6404. return false;
  6405. }
  6406. }, {
  6407. key: "extendSelector",
  6408. value: function extendSelector(matches, selectorPath, replacementSelector, isVisible) {
  6409. // for a set of matches, replace each match with the replacement selector
  6410. var currentSelectorPathIndex = 0;
  6411. var currentSelectorPathElementIndex = 0;
  6412. var path = [];
  6413. var matchIndex;
  6414. var selector;
  6415. var firstElement;
  6416. var match;
  6417. var newElements;
  6418. for (matchIndex = 0; matchIndex < matches.length; matchIndex++) {
  6419. match = matches[matchIndex];
  6420. selector = selectorPath[match.pathIndex];
  6421. firstElement = new tree.Element(match.initialCombinator, replacementSelector.elements[0].value, replacementSelector.elements[0].isVariable, replacementSelector.elements[0].getIndex(), replacementSelector.elements[0].fileInfo());
  6422. if (match.pathIndex > currentSelectorPathIndex && currentSelectorPathElementIndex > 0) {
  6423. path[path.length - 1].elements = path[path.length - 1].elements.concat(selectorPath[currentSelectorPathIndex].elements.slice(currentSelectorPathElementIndex));
  6424. currentSelectorPathElementIndex = 0;
  6425. currentSelectorPathIndex++;
  6426. }
  6427. newElements = selector.elements.slice(currentSelectorPathElementIndex, match.index).concat([firstElement]).concat(replacementSelector.elements.slice(1));
  6428. if (currentSelectorPathIndex === match.pathIndex && matchIndex > 0) {
  6429. path[path.length - 1].elements = path[path.length - 1].elements.concat(newElements);
  6430. } else {
  6431. path = path.concat(selectorPath.slice(currentSelectorPathIndex, match.pathIndex));
  6432. path.push(new tree.Selector(newElements));
  6433. }
  6434. currentSelectorPathIndex = match.endPathIndex;
  6435. currentSelectorPathElementIndex = match.endPathElementIndex;
  6436. if (currentSelectorPathElementIndex >= selectorPath[currentSelectorPathIndex].elements.length) {
  6437. currentSelectorPathElementIndex = 0;
  6438. currentSelectorPathIndex++;
  6439. }
  6440. }
  6441. if (currentSelectorPathIndex < selectorPath.length && currentSelectorPathElementIndex > 0) {
  6442. path[path.length - 1].elements = path[path.length - 1].elements.concat(selectorPath[currentSelectorPathIndex].elements.slice(currentSelectorPathElementIndex));
  6443. currentSelectorPathIndex++;
  6444. }
  6445. path = path.concat(selectorPath.slice(currentSelectorPathIndex, selectorPath.length));
  6446. path = path.map(function (currentValue) {
  6447. // we can re-use elements here, because the visibility property matters only for selectors
  6448. var derived = currentValue.createDerived(currentValue.elements);
  6449. if (isVisible) {
  6450. derived.ensureVisibility();
  6451. } else {
  6452. derived.ensureInvisibility();
  6453. }
  6454. return derived;
  6455. });
  6456. return path;
  6457. }
  6458. }, {
  6459. key: "visitMedia",
  6460. value: function visitMedia(mediaNode, visitArgs) {
  6461. var newAllExtends = mediaNode.allExtends.concat(this.allExtendsStack[this.allExtendsStack.length - 1]);
  6462. newAllExtends = newAllExtends.concat(this.doExtendChaining(newAllExtends, mediaNode.allExtends));
  6463. this.allExtendsStack.push(newAllExtends);
  6464. }
  6465. }, {
  6466. key: "visitMediaOut",
  6467. value: function visitMediaOut(mediaNode) {
  6468. var lastIndex = this.allExtendsStack.length - 1;
  6469. this.allExtendsStack.length = lastIndex;
  6470. }
  6471. }, {
  6472. key: "visitAtRule",
  6473. value: function visitAtRule(atRuleNode, visitArgs) {
  6474. var newAllExtends = atRuleNode.allExtends.concat(this.allExtendsStack[this.allExtendsStack.length - 1]);
  6475. newAllExtends = newAllExtends.concat(this.doExtendChaining(newAllExtends, atRuleNode.allExtends));
  6476. this.allExtendsStack.push(newAllExtends);
  6477. }
  6478. }, {
  6479. key: "visitAtRuleOut",
  6480. value: function visitAtRuleOut(atRuleNode) {
  6481. var lastIndex = this.allExtendsStack.length - 1;
  6482. this.allExtendsStack.length = lastIndex;
  6483. }
  6484. }]);
  6485. return ProcessExtendsVisitor;
  6486. }();
  6487. var JoinSelectorVisitor =
  6488. /*#__PURE__*/
  6489. function () {
  6490. function JoinSelectorVisitor() {
  6491. _classCallCheck(this, JoinSelectorVisitor);
  6492. this.contexts = [[]];
  6493. this._visitor = new Visitor(this);
  6494. }
  6495. _createClass(JoinSelectorVisitor, [{
  6496. key: "run",
  6497. value: function run(root) {
  6498. return this._visitor.visit(root);
  6499. }
  6500. }, {
  6501. key: "visitDeclaration",
  6502. value: function visitDeclaration(declNode, visitArgs) {
  6503. visitArgs.visitDeeper = false;
  6504. }
  6505. }, {
  6506. key: "visitMixinDefinition",
  6507. value: function visitMixinDefinition(mixinDefinitionNode, visitArgs) {
  6508. visitArgs.visitDeeper = false;
  6509. }
  6510. }, {
  6511. key: "visitRuleset",
  6512. value: function visitRuleset(rulesetNode, visitArgs) {
  6513. var context = this.contexts[this.contexts.length - 1];
  6514. var paths = [];
  6515. var selectors;
  6516. this.contexts.push(paths);
  6517. if (!rulesetNode.root) {
  6518. selectors = rulesetNode.selectors;
  6519. if (selectors) {
  6520. selectors = selectors.filter(function (selector) {
  6521. return selector.getIsOutput();
  6522. });
  6523. rulesetNode.selectors = selectors.length ? selectors : selectors = null;
  6524. if (selectors) {
  6525. rulesetNode.joinSelectors(paths, context, selectors);
  6526. }
  6527. }
  6528. if (!selectors) {
  6529. rulesetNode.rules = null;
  6530. }
  6531. rulesetNode.paths = paths;
  6532. }
  6533. }
  6534. }, {
  6535. key: "visitRulesetOut",
  6536. value: function visitRulesetOut(rulesetNode) {
  6537. this.contexts.length = this.contexts.length - 1;
  6538. }
  6539. }, {
  6540. key: "visitMedia",
  6541. value: function visitMedia(mediaNode, visitArgs) {
  6542. var context = this.contexts[this.contexts.length - 1];
  6543. mediaNode.rules[0].root = context.length === 0 || context[0].multiMedia;
  6544. }
  6545. }, {
  6546. key: "visitAtRule",
  6547. value: function visitAtRule(atRuleNode, visitArgs) {
  6548. var context = this.contexts[this.contexts.length - 1];
  6549. if (atRuleNode.rules && atRuleNode.rules.length) {
  6550. atRuleNode.rules[0].root = atRuleNode.isRooted || context.length === 0 || null;
  6551. }
  6552. }
  6553. }]);
  6554. return JoinSelectorVisitor;
  6555. }();
  6556. var CSSVisitorUtils =
  6557. /*#__PURE__*/
  6558. function () {
  6559. function CSSVisitorUtils(context) {
  6560. _classCallCheck(this, CSSVisitorUtils);
  6561. this._visitor = new Visitor(this);
  6562. this._context = context;
  6563. }
  6564. _createClass(CSSVisitorUtils, [{
  6565. key: "containsSilentNonBlockedChild",
  6566. value: function containsSilentNonBlockedChild(bodyRules) {
  6567. var rule;
  6568. if (!bodyRules) {
  6569. return false;
  6570. }
  6571. for (var r = 0; r < bodyRules.length; r++) {
  6572. rule = bodyRules[r];
  6573. if (rule.isSilent && rule.isSilent(this._context) && !rule.blocksVisibility()) {
  6574. // the atrule contains something that was referenced (likely by extend)
  6575. // therefore it needs to be shown in output too
  6576. return true;
  6577. }
  6578. }
  6579. return false;
  6580. }
  6581. }, {
  6582. key: "keepOnlyVisibleChilds",
  6583. value: function keepOnlyVisibleChilds(owner) {
  6584. if (owner && owner.rules) {
  6585. owner.rules = owner.rules.filter(function (thing) {
  6586. return thing.isVisible();
  6587. });
  6588. }
  6589. }
  6590. }, {
  6591. key: "isEmpty",
  6592. value: function isEmpty(owner) {
  6593. return owner && owner.rules ? owner.rules.length === 0 : true;
  6594. }
  6595. }, {
  6596. key: "hasVisibleSelector",
  6597. value: function hasVisibleSelector(rulesetNode) {
  6598. return rulesetNode && rulesetNode.paths ? rulesetNode.paths.length > 0 : false;
  6599. }
  6600. }, {
  6601. key: "resolveVisibility",
  6602. value: function resolveVisibility(node, originalRules) {
  6603. if (!node.blocksVisibility()) {
  6604. if (this.isEmpty(node) && !this.containsSilentNonBlockedChild(originalRules)) {
  6605. return;
  6606. }
  6607. return node;
  6608. }
  6609. var compiledRulesBody = node.rules[0];
  6610. this.keepOnlyVisibleChilds(compiledRulesBody);
  6611. if (this.isEmpty(compiledRulesBody)) {
  6612. return;
  6613. }
  6614. node.ensureVisibility();
  6615. node.removeVisibilityBlock();
  6616. return node;
  6617. }
  6618. }, {
  6619. key: "isVisibleRuleset",
  6620. value: function isVisibleRuleset(rulesetNode) {
  6621. if (rulesetNode.firstRoot) {
  6622. return true;
  6623. }
  6624. if (this.isEmpty(rulesetNode)) {
  6625. return false;
  6626. }
  6627. if (!rulesetNode.root && !this.hasVisibleSelector(rulesetNode)) {
  6628. return false;
  6629. }
  6630. return true;
  6631. }
  6632. }]);
  6633. return CSSVisitorUtils;
  6634. }();
  6635. var ToCSSVisitor = function ToCSSVisitor(context) {
  6636. this._visitor = new Visitor(this);
  6637. this._context = context;
  6638. this.utils = new CSSVisitorUtils(context);
  6639. };
  6640. ToCSSVisitor.prototype = {
  6641. isReplacing: true,
  6642. run: function run(root) {
  6643. return this._visitor.visit(root);
  6644. },
  6645. visitDeclaration: function visitDeclaration(declNode, visitArgs) {
  6646. if (declNode.blocksVisibility() || declNode.variable) {
  6647. return;
  6648. }
  6649. return declNode;
  6650. },
  6651. visitMixinDefinition: function visitMixinDefinition(mixinNode, visitArgs) {
  6652. // mixin definitions do not get eval'd - this means they keep state
  6653. // so we have to clear that state here so it isn't used if toCSS is called twice
  6654. mixinNode.frames = [];
  6655. },
  6656. visitExtend: function visitExtend(extendNode, visitArgs) {},
  6657. visitComment: function visitComment(commentNode, visitArgs) {
  6658. if (commentNode.blocksVisibility() || commentNode.isSilent(this._context)) {
  6659. return;
  6660. }
  6661. return commentNode;
  6662. },
  6663. visitMedia: function visitMedia(mediaNode, visitArgs) {
  6664. var originalRules = mediaNode.rules[0].rules;
  6665. mediaNode.accept(this._visitor);
  6666. visitArgs.visitDeeper = false;
  6667. return this.utils.resolveVisibility(mediaNode, originalRules);
  6668. },
  6669. visitImport: function visitImport(importNode, visitArgs) {
  6670. if (importNode.blocksVisibility()) {
  6671. return;
  6672. }
  6673. return importNode;
  6674. },
  6675. visitAtRule: function visitAtRule(atRuleNode, visitArgs) {
  6676. if (atRuleNode.rules && atRuleNode.rules.length) {
  6677. return this.visitAtRuleWithBody(atRuleNode, visitArgs);
  6678. } else {
  6679. return this.visitAtRuleWithoutBody(atRuleNode, visitArgs);
  6680. }
  6681. },
  6682. visitAnonymous: function visitAnonymous(anonymousNode, visitArgs) {
  6683. if (!anonymousNode.blocksVisibility()) {
  6684. anonymousNode.accept(this._visitor);
  6685. return anonymousNode;
  6686. }
  6687. },
  6688. visitAtRuleWithBody: function visitAtRuleWithBody(atRuleNode, visitArgs) {
  6689. // if there is only one nested ruleset and that one has no path, then it is
  6690. // just fake ruleset
  6691. function hasFakeRuleset(atRuleNode) {
  6692. var bodyRules = atRuleNode.rules;
  6693. return bodyRules.length === 1 && (!bodyRules[0].paths || bodyRules[0].paths.length === 0);
  6694. }
  6695. function getBodyRules(atRuleNode) {
  6696. var nodeRules = atRuleNode.rules;
  6697. if (hasFakeRuleset(atRuleNode)) {
  6698. return nodeRules[0].rules;
  6699. }
  6700. return nodeRules;
  6701. } // it is still true that it is only one ruleset in array
  6702. // this is last such moment
  6703. // process childs
  6704. var originalRules = getBodyRules(atRuleNode);
  6705. atRuleNode.accept(this._visitor);
  6706. visitArgs.visitDeeper = false;
  6707. if (!this.utils.isEmpty(atRuleNode)) {
  6708. this._mergeRules(atRuleNode.rules[0].rules);
  6709. }
  6710. return this.utils.resolveVisibility(atRuleNode, originalRules);
  6711. },
  6712. visitAtRuleWithoutBody: function visitAtRuleWithoutBody(atRuleNode, visitArgs) {
  6713. if (atRuleNode.blocksVisibility()) {
  6714. return;
  6715. }
  6716. if (atRuleNode.name === '@charset') {
  6717. // Only output the debug info together with subsequent @charset definitions
  6718. // a comment (or @media statement) before the actual @charset atrule would
  6719. // be considered illegal css as it has to be on the first line
  6720. if (this.charset) {
  6721. if (atRuleNode.debugInfo) {
  6722. var comment = new tree.Comment("/* ".concat(atRuleNode.toCSS(this._context).replace(/\n/g, ''), " */\n"));
  6723. comment.debugInfo = atRuleNode.debugInfo;
  6724. return this._visitor.visit(comment);
  6725. }
  6726. return;
  6727. }
  6728. this.charset = true;
  6729. }
  6730. return atRuleNode;
  6731. },
  6732. checkValidNodes: function checkValidNodes(rules, isRoot) {
  6733. if (!rules) {
  6734. return;
  6735. }
  6736. for (var i = 0; i < rules.length; i++) {
  6737. var ruleNode = rules[i];
  6738. if (isRoot && ruleNode instanceof tree.Declaration && !ruleNode.variable) {
  6739. throw {
  6740. message: 'Properties must be inside selector blocks. They cannot be in the root',
  6741. index: ruleNode.getIndex(),
  6742. filename: ruleNode.fileInfo() && ruleNode.fileInfo().filename
  6743. };
  6744. }
  6745. if (ruleNode instanceof tree.Call) {
  6746. throw {
  6747. message: "Function '".concat(ruleNode.name, "' is undefined"),
  6748. index: ruleNode.getIndex(),
  6749. filename: ruleNode.fileInfo() && ruleNode.fileInfo().filename
  6750. };
  6751. }
  6752. if (ruleNode.type && !ruleNode.allowRoot) {
  6753. throw {
  6754. message: "".concat(ruleNode.type, " node returned by a function is not valid here"),
  6755. index: ruleNode.getIndex(),
  6756. filename: ruleNode.fileInfo() && ruleNode.fileInfo().filename
  6757. };
  6758. }
  6759. }
  6760. },
  6761. visitRuleset: function visitRuleset(rulesetNode, visitArgs) {
  6762. // at this point rulesets are nested into each other
  6763. var rule;
  6764. var rulesets = [];
  6765. this.checkValidNodes(rulesetNode.rules, rulesetNode.firstRoot);
  6766. if (!rulesetNode.root) {
  6767. // remove invisible paths
  6768. this._compileRulesetPaths(rulesetNode); // remove rulesets from this ruleset body and compile them separately
  6769. var nodeRules = rulesetNode.rules;
  6770. var nodeRuleCnt = nodeRules ? nodeRules.length : 0;
  6771. for (var i = 0; i < nodeRuleCnt;) {
  6772. rule = nodeRules[i];
  6773. if (rule && rule.rules) {
  6774. // visit because we are moving them out from being a child
  6775. rulesets.push(this._visitor.visit(rule));
  6776. nodeRules.splice(i, 1);
  6777. nodeRuleCnt--;
  6778. continue;
  6779. }
  6780. i++;
  6781. } // accept the visitor to remove rules and refactor itself
  6782. // then we can decide nogw whether we want it or not
  6783. // compile body
  6784. if (nodeRuleCnt > 0) {
  6785. rulesetNode.accept(this._visitor);
  6786. } else {
  6787. rulesetNode.rules = null;
  6788. }
  6789. visitArgs.visitDeeper = false;
  6790. } else {
  6791. // if (! rulesetNode.root) {
  6792. rulesetNode.accept(this._visitor);
  6793. visitArgs.visitDeeper = false;
  6794. }
  6795. if (rulesetNode.rules) {
  6796. this._mergeRules(rulesetNode.rules);
  6797. this._removeDuplicateRules(rulesetNode.rules);
  6798. } // now decide whether we keep the ruleset
  6799. if (this.utils.isVisibleRuleset(rulesetNode)) {
  6800. rulesetNode.ensureVisibility();
  6801. rulesets.splice(0, 0, rulesetNode);
  6802. }
  6803. if (rulesets.length === 1) {
  6804. return rulesets[0];
  6805. }
  6806. return rulesets;
  6807. },
  6808. _compileRulesetPaths: function _compileRulesetPaths(rulesetNode) {
  6809. if (rulesetNode.paths) {
  6810. rulesetNode.paths = rulesetNode.paths.filter(function (p) {
  6811. var i;
  6812. if (p[0].elements[0].combinator.value === ' ') {
  6813. p[0].elements[0].combinator = new tree.Combinator('');
  6814. }
  6815. for (i = 0; i < p.length; i++) {
  6816. if (p[i].isVisible() && p[i].getIsOutput()) {
  6817. return true;
  6818. }
  6819. }
  6820. return false;
  6821. });
  6822. }
  6823. },
  6824. _removeDuplicateRules: function _removeDuplicateRules(rules) {
  6825. if (!rules) {
  6826. return;
  6827. } // remove duplicates
  6828. var ruleCache = {};
  6829. var ruleList;
  6830. var rule;
  6831. var i;
  6832. for (i = rules.length - 1; i >= 0; i--) {
  6833. rule = rules[i];
  6834. if (rule instanceof tree.Declaration) {
  6835. if (!ruleCache[rule.name]) {
  6836. ruleCache[rule.name] = rule;
  6837. } else {
  6838. ruleList = ruleCache[rule.name];
  6839. if (ruleList instanceof tree.Declaration) {
  6840. ruleList = ruleCache[rule.name] = [ruleCache[rule.name].toCSS(this._context)];
  6841. }
  6842. var ruleCSS = rule.toCSS(this._context);
  6843. if (ruleList.indexOf(ruleCSS) !== -1) {
  6844. rules.splice(i, 1);
  6845. } else {
  6846. ruleList.push(ruleCSS);
  6847. }
  6848. }
  6849. }
  6850. }
  6851. },
  6852. _mergeRules: function _mergeRules(rules) {
  6853. if (!rules) {
  6854. return;
  6855. }
  6856. var groups = {};
  6857. var groupsArr = [];
  6858. for (var i = 0; i < rules.length; i++) {
  6859. var rule = rules[i];
  6860. if (rule.merge) {
  6861. var key = rule.name;
  6862. groups[key] ? rules.splice(i--, 1) : groupsArr.push(groups[key] = []);
  6863. groups[key].push(rule);
  6864. }
  6865. }
  6866. groupsArr.forEach(function (group) {
  6867. if (group.length > 0) {
  6868. var result = group[0];
  6869. var space = [];
  6870. var comma = [new tree.Expression(space)];
  6871. group.forEach(function (rule) {
  6872. if (rule.merge === '+' && space.length > 0) {
  6873. comma.push(new tree.Expression(space = []));
  6874. }
  6875. space.push(rule.value);
  6876. result.important = result.important || rule.important;
  6877. });
  6878. result.value = new tree.Value(comma);
  6879. }
  6880. });
  6881. }
  6882. };
  6883. var visitors = {
  6884. Visitor: Visitor,
  6885. ImportVisitor: ImportVisitor,
  6886. MarkVisibleSelectorsVisitor: SetTreeVisibilityVisitor,
  6887. ExtendVisitor: ProcessExtendsVisitor,
  6888. JoinSelectorVisitor: JoinSelectorVisitor,
  6889. ToCSSVisitor: ToCSSVisitor
  6890. };
  6891. // Split the input into chunks.
  6892. var chunker = (function (input, fail) {
  6893. var len = input.length;
  6894. var level = 0;
  6895. var parenLevel = 0;
  6896. var lastOpening;
  6897. var lastOpeningParen;
  6898. var lastMultiComment;
  6899. var lastMultiCommentEndBrace;
  6900. var chunks = [];
  6901. var emitFrom = 0;
  6902. var chunkerCurrentIndex;
  6903. var currentChunkStartIndex;
  6904. var cc;
  6905. var cc2;
  6906. var matched;
  6907. function emitChunk(force) {
  6908. var len = chunkerCurrentIndex - emitFrom;
  6909. if (len < 512 && !force || !len) {
  6910. return;
  6911. }
  6912. chunks.push(input.slice(emitFrom, chunkerCurrentIndex + 1));
  6913. emitFrom = chunkerCurrentIndex + 1;
  6914. }
  6915. for (chunkerCurrentIndex = 0; chunkerCurrentIndex < len; chunkerCurrentIndex++) {
  6916. cc = input.charCodeAt(chunkerCurrentIndex);
  6917. if (cc >= 97 && cc <= 122 || cc < 34) {
  6918. // a-z or whitespace
  6919. continue;
  6920. }
  6921. switch (cc) {
  6922. case 40:
  6923. // (
  6924. parenLevel++;
  6925. lastOpeningParen = chunkerCurrentIndex;
  6926. continue;
  6927. case 41:
  6928. // )
  6929. if (--parenLevel < 0) {
  6930. return fail('missing opening `(`', chunkerCurrentIndex);
  6931. }
  6932. continue;
  6933. case 59:
  6934. // ;
  6935. if (!parenLevel) {
  6936. emitChunk();
  6937. }
  6938. continue;
  6939. case 123:
  6940. // {
  6941. level++;
  6942. lastOpening = chunkerCurrentIndex;
  6943. continue;
  6944. case 125:
  6945. // }
  6946. if (--level < 0) {
  6947. return fail('missing opening `{`', chunkerCurrentIndex);
  6948. }
  6949. if (!level && !parenLevel) {
  6950. emitChunk();
  6951. }
  6952. continue;
  6953. case 92:
  6954. // \
  6955. if (chunkerCurrentIndex < len - 1) {
  6956. chunkerCurrentIndex++;
  6957. continue;
  6958. }
  6959. return fail('unescaped `\\`', chunkerCurrentIndex);
  6960. case 34:
  6961. case 39:
  6962. case 96:
  6963. // ", ' and `
  6964. matched = 0;
  6965. currentChunkStartIndex = chunkerCurrentIndex;
  6966. for (chunkerCurrentIndex = chunkerCurrentIndex + 1; chunkerCurrentIndex < len; chunkerCurrentIndex++) {
  6967. cc2 = input.charCodeAt(chunkerCurrentIndex);
  6968. if (cc2 > 96) {
  6969. continue;
  6970. }
  6971. if (cc2 == cc) {
  6972. matched = 1;
  6973. break;
  6974. }
  6975. if (cc2 == 92) {
  6976. // \
  6977. if (chunkerCurrentIndex == len - 1) {
  6978. return fail('unescaped `\\`', chunkerCurrentIndex);
  6979. }
  6980. chunkerCurrentIndex++;
  6981. }
  6982. }
  6983. if (matched) {
  6984. continue;
  6985. }
  6986. return fail("unmatched `".concat(String.fromCharCode(cc), "`"), currentChunkStartIndex);
  6987. case 47:
  6988. // /, check for comment
  6989. if (parenLevel || chunkerCurrentIndex == len - 1) {
  6990. continue;
  6991. }
  6992. cc2 = input.charCodeAt(chunkerCurrentIndex + 1);
  6993. if (cc2 == 47) {
  6994. // //, find lnfeed
  6995. for (chunkerCurrentIndex = chunkerCurrentIndex + 2; chunkerCurrentIndex < len; chunkerCurrentIndex++) {
  6996. cc2 = input.charCodeAt(chunkerCurrentIndex);
  6997. if (cc2 <= 13 && (cc2 == 10 || cc2 == 13)) {
  6998. break;
  6999. }
  7000. }
  7001. } else if (cc2 == 42) {
  7002. // /*, find */
  7003. lastMultiComment = currentChunkStartIndex = chunkerCurrentIndex;
  7004. for (chunkerCurrentIndex = chunkerCurrentIndex + 2; chunkerCurrentIndex < len - 1; chunkerCurrentIndex++) {
  7005. cc2 = input.charCodeAt(chunkerCurrentIndex);
  7006. if (cc2 == 125) {
  7007. lastMultiCommentEndBrace = chunkerCurrentIndex;
  7008. }
  7009. if (cc2 != 42) {
  7010. continue;
  7011. }
  7012. if (input.charCodeAt(chunkerCurrentIndex + 1) == 47) {
  7013. break;
  7014. }
  7015. }
  7016. if (chunkerCurrentIndex == len - 1) {
  7017. return fail('missing closing `*/`', currentChunkStartIndex);
  7018. }
  7019. chunkerCurrentIndex++;
  7020. }
  7021. continue;
  7022. case 42:
  7023. // *, check for unmatched */
  7024. if (chunkerCurrentIndex < len - 1 && input.charCodeAt(chunkerCurrentIndex + 1) == 47) {
  7025. return fail('unmatched `/*`', chunkerCurrentIndex);
  7026. }
  7027. continue;
  7028. }
  7029. }
  7030. if (level !== 0) {
  7031. if (lastMultiComment > lastOpening && lastMultiCommentEndBrace > lastMultiComment) {
  7032. return fail('missing closing `}` or `*/`', lastOpening);
  7033. } else {
  7034. return fail('missing closing `}`', lastOpening);
  7035. }
  7036. } else if (parenLevel !== 0) {
  7037. return fail('missing closing `)`', lastOpeningParen);
  7038. }
  7039. emitChunk(true);
  7040. return chunks;
  7041. });
  7042. var getParserInput = (function () {
  7043. var // Less input string
  7044. input;
  7045. var // current chunk
  7046. j;
  7047. var // holds state for backtracking
  7048. saveStack = [];
  7049. var // furthest index the parser has gone to
  7050. furthest;
  7051. var // if this is furthest we got to, this is the probably cause
  7052. furthestPossibleErrorMessage;
  7053. var // chunkified input
  7054. chunks;
  7055. var // current chunk
  7056. current;
  7057. var // index of current chunk, in `input`
  7058. currentPos;
  7059. var parserInput = {};
  7060. var CHARCODE_SPACE = 32;
  7061. var CHARCODE_TAB = 9;
  7062. var CHARCODE_LF = 10;
  7063. var CHARCODE_CR = 13;
  7064. var CHARCODE_PLUS = 43;
  7065. var CHARCODE_COMMA = 44;
  7066. var CHARCODE_FORWARD_SLASH = 47;
  7067. var CHARCODE_9 = 57;
  7068. function skipWhitespace(length) {
  7069. var oldi = parserInput.i;
  7070. var oldj = j;
  7071. var curr = parserInput.i - currentPos;
  7072. var endIndex = parserInput.i + current.length - curr;
  7073. var mem = parserInput.i += length;
  7074. var inp = input;
  7075. var c;
  7076. var nextChar;
  7077. var comment;
  7078. for (; parserInput.i < endIndex; parserInput.i++) {
  7079. c = inp.charCodeAt(parserInput.i);
  7080. if (parserInput.autoCommentAbsorb && c === CHARCODE_FORWARD_SLASH) {
  7081. nextChar = inp.charAt(parserInput.i + 1);
  7082. if (nextChar === '/') {
  7083. comment = {
  7084. index: parserInput.i,
  7085. isLineComment: true
  7086. };
  7087. var nextNewLine = inp.indexOf('\n', parserInput.i + 2);
  7088. if (nextNewLine < 0) {
  7089. nextNewLine = endIndex;
  7090. }
  7091. parserInput.i = nextNewLine;
  7092. comment.text = inp.substr(comment.index, parserInput.i - comment.index);
  7093. parserInput.commentStore.push(comment);
  7094. continue;
  7095. } else if (nextChar === '*') {
  7096. var nextStarSlash = inp.indexOf('*/', parserInput.i + 2);
  7097. if (nextStarSlash >= 0) {
  7098. comment = {
  7099. index: parserInput.i,
  7100. text: inp.substr(parserInput.i, nextStarSlash + 2 - parserInput.i),
  7101. isLineComment: false
  7102. };
  7103. parserInput.i += comment.text.length - 1;
  7104. parserInput.commentStore.push(comment);
  7105. continue;
  7106. }
  7107. }
  7108. break;
  7109. }
  7110. if (c !== CHARCODE_SPACE && c !== CHARCODE_LF && c !== CHARCODE_TAB && c !== CHARCODE_CR) {
  7111. break;
  7112. }
  7113. }
  7114. current = current.slice(length + parserInput.i - mem + curr);
  7115. currentPos = parserInput.i;
  7116. if (!current.length) {
  7117. if (j < chunks.length - 1) {
  7118. current = chunks[++j];
  7119. skipWhitespace(0); // skip space at the beginning of a chunk
  7120. return true; // things changed
  7121. }
  7122. parserInput.finished = true;
  7123. }
  7124. return oldi !== parserInput.i || oldj !== j;
  7125. }
  7126. parserInput.save = function () {
  7127. currentPos = parserInput.i;
  7128. saveStack.push({
  7129. current: current,
  7130. i: parserInput.i,
  7131. j: j
  7132. });
  7133. };
  7134. parserInput.restore = function (possibleErrorMessage) {
  7135. if (parserInput.i > furthest || parserInput.i === furthest && possibleErrorMessage && !furthestPossibleErrorMessage) {
  7136. furthest = parserInput.i;
  7137. furthestPossibleErrorMessage = possibleErrorMessage;
  7138. }
  7139. var state = saveStack.pop();
  7140. current = state.current;
  7141. currentPos = parserInput.i = state.i;
  7142. j = state.j;
  7143. };
  7144. parserInput.forget = function () {
  7145. saveStack.pop();
  7146. };
  7147. parserInput.isWhitespace = function (offset) {
  7148. var pos = parserInput.i + (offset || 0);
  7149. var code = input.charCodeAt(pos);
  7150. return code === CHARCODE_SPACE || code === CHARCODE_CR || code === CHARCODE_TAB || code === CHARCODE_LF;
  7151. }; // Specialization of $(tok)
  7152. parserInput.$re = function (tok) {
  7153. if (parserInput.i > currentPos) {
  7154. current = current.slice(parserInput.i - currentPos);
  7155. currentPos = parserInput.i;
  7156. }
  7157. var m = tok.exec(current);
  7158. if (!m) {
  7159. return null;
  7160. }
  7161. skipWhitespace(m[0].length);
  7162. if (typeof m === 'string') {
  7163. return m;
  7164. }
  7165. return m.length === 1 ? m[0] : m;
  7166. };
  7167. parserInput.$char = function (tok) {
  7168. if (input.charAt(parserInput.i) !== tok) {
  7169. return null;
  7170. }
  7171. skipWhitespace(1);
  7172. return tok;
  7173. };
  7174. parserInput.$str = function (tok) {
  7175. var tokLength = tok.length; // https://jsperf.com/string-startswith/21
  7176. for (var i = 0; i < tokLength; i++) {
  7177. if (input.charAt(parserInput.i + i) !== tok.charAt(i)) {
  7178. return null;
  7179. }
  7180. }
  7181. skipWhitespace(tokLength);
  7182. return tok;
  7183. };
  7184. parserInput.$quoted = function (loc) {
  7185. var pos = loc || parserInput.i;
  7186. var startChar = input.charAt(pos);
  7187. if (startChar !== '\'' && startChar !== '"') {
  7188. return;
  7189. }
  7190. var length = input.length;
  7191. var currentPosition = pos;
  7192. for (var i = 1; i + currentPosition < length; i++) {
  7193. var nextChar = input.charAt(i + currentPosition);
  7194. switch (nextChar) {
  7195. case '\\':
  7196. i++;
  7197. continue;
  7198. case '\r':
  7199. case '\n':
  7200. break;
  7201. case startChar:
  7202. var str = input.substr(currentPosition, i + 1);
  7203. if (!loc && loc !== 0) {
  7204. skipWhitespace(i + 1);
  7205. return str;
  7206. }
  7207. return [startChar, str];
  7208. default:
  7209. }
  7210. }
  7211. return null;
  7212. };
  7213. /**
  7214. * Permissive parsing. Ignores everything except matching {} [] () and quotes
  7215. * until matching token (outside of blocks)
  7216. */
  7217. parserInput.$parseUntil = function (tok) {
  7218. var quote = '';
  7219. var returnVal = null;
  7220. var inComment = false;
  7221. var blockDepth = 0;
  7222. var blockStack = [];
  7223. var parseGroups = [];
  7224. var length = input.length;
  7225. var startPos = parserInput.i;
  7226. var lastPos = parserInput.i;
  7227. var i = parserInput.i;
  7228. var loop = true;
  7229. var testChar;
  7230. if (typeof tok === 'string') {
  7231. testChar = function testChar(char) {
  7232. return char === tok;
  7233. };
  7234. } else {
  7235. testChar = function testChar(char) {
  7236. return tok.test(char);
  7237. };
  7238. }
  7239. do {
  7240. var nextChar = input.charAt(i);
  7241. if (blockDepth === 0 && testChar(nextChar)) {
  7242. returnVal = input.substr(lastPos, i - lastPos);
  7243. if (returnVal) {
  7244. parseGroups.push(returnVal);
  7245. } else {
  7246. parseGroups.push(' ');
  7247. }
  7248. returnVal = parseGroups;
  7249. skipWhitespace(i - startPos);
  7250. loop = false;
  7251. } else {
  7252. if (inComment) {
  7253. if (nextChar === '*' && input.charAt(i + 1) === '/') {
  7254. i++;
  7255. blockDepth--;
  7256. inComment = false;
  7257. }
  7258. i++;
  7259. continue;
  7260. }
  7261. switch (nextChar) {
  7262. case '\\':
  7263. i++;
  7264. nextChar = input.charAt(i);
  7265. parseGroups.push(input.substr(lastPos, i - lastPos + 1));
  7266. lastPos = i + 1;
  7267. break;
  7268. case '/':
  7269. if (input.charAt(i + 1) === '*') {
  7270. i++;
  7271. inComment = true;
  7272. blockDepth++;
  7273. }
  7274. break;
  7275. case '\'':
  7276. case '"':
  7277. quote = parserInput.$quoted(i);
  7278. if (quote) {
  7279. parseGroups.push(input.substr(lastPos, i - lastPos), quote);
  7280. i += quote[1].length - 1;
  7281. lastPos = i + 1;
  7282. } else {
  7283. skipWhitespace(i - startPos);
  7284. returnVal = nextChar;
  7285. loop = false;
  7286. }
  7287. break;
  7288. case '{':
  7289. blockStack.push('}');
  7290. blockDepth++;
  7291. break;
  7292. case '(':
  7293. blockStack.push(')');
  7294. blockDepth++;
  7295. break;
  7296. case '[':
  7297. blockStack.push(']');
  7298. blockDepth++;
  7299. break;
  7300. case '}':
  7301. case ')':
  7302. case ']':
  7303. var expected = blockStack.pop();
  7304. if (nextChar === expected) {
  7305. blockDepth--;
  7306. } else {
  7307. // move the parser to the error and return expected
  7308. skipWhitespace(i - startPos);
  7309. returnVal = expected;
  7310. loop = false;
  7311. }
  7312. }
  7313. i++;
  7314. if (i > length) {
  7315. loop = false;
  7316. }
  7317. }
  7318. } while (loop);
  7319. return returnVal ? returnVal : null;
  7320. };
  7321. parserInput.autoCommentAbsorb = true;
  7322. parserInput.commentStore = [];
  7323. parserInput.finished = false; // Same as $(), but don't change the state of the parser,
  7324. // just return the match.
  7325. parserInput.peek = function (tok) {
  7326. if (typeof tok === 'string') {
  7327. // https://jsperf.com/string-startswith/21
  7328. for (var i = 0; i < tok.length; i++) {
  7329. if (input.charAt(parserInput.i + i) !== tok.charAt(i)) {
  7330. return false;
  7331. }
  7332. }
  7333. return true;
  7334. } else {
  7335. return tok.test(current);
  7336. }
  7337. }; // Specialization of peek()
  7338. // TODO remove or change some currentChar calls to peekChar
  7339. parserInput.peekChar = function (tok) {
  7340. return input.charAt(parserInput.i) === tok;
  7341. };
  7342. parserInput.currentChar = function () {
  7343. return input.charAt(parserInput.i);
  7344. };
  7345. parserInput.prevChar = function () {
  7346. return input.charAt(parserInput.i - 1);
  7347. };
  7348. parserInput.getInput = function () {
  7349. return input;
  7350. };
  7351. parserInput.peekNotNumeric = function () {
  7352. var c = input.charCodeAt(parserInput.i); // Is the first char of the dimension 0-9, '.', '+' or '-'
  7353. return c > CHARCODE_9 || c < CHARCODE_PLUS || c === CHARCODE_FORWARD_SLASH || c === CHARCODE_COMMA;
  7354. };
  7355. parserInput.start = function (str, chunkInput, failFunction) {
  7356. input = str;
  7357. parserInput.i = j = currentPos = furthest = 0; // chunking apparently makes things quicker (but my tests indicate
  7358. // it might actually make things slower in node at least)
  7359. // and it is a non-perfect parse - it can't recognise
  7360. // unquoted urls, meaning it can't distinguish comments
  7361. // meaning comments with quotes or {}() in them get 'counted'
  7362. // and then lead to parse errors.
  7363. // In addition if the chunking chunks in the wrong place we might
  7364. // not be able to parse a parser statement in one go
  7365. // this is officially deprecated but can be switched on via an option
  7366. // in the case it causes too much performance issues.
  7367. if (chunkInput) {
  7368. chunks = chunker(str, failFunction);
  7369. } else {
  7370. chunks = [str];
  7371. }
  7372. current = chunks[0];
  7373. skipWhitespace(0);
  7374. };
  7375. parserInput.end = function () {
  7376. var message;
  7377. var isFinished = parserInput.i >= input.length;
  7378. if (parserInput.i < furthest) {
  7379. message = furthestPossibleErrorMessage;
  7380. parserInput.i = furthest;
  7381. }
  7382. return {
  7383. isFinished: isFinished,
  7384. furthest: parserInput.i,
  7385. furthestPossibleErrorMessage: message,
  7386. furthestReachedEnd: parserInput.i >= input.length - 1,
  7387. furthestChar: input[parserInput.i]
  7388. };
  7389. };
  7390. return parserInput;
  7391. });
  7392. // less.js - parser
  7393. //
  7394. // A relatively straight-forward predictive parser.
  7395. // There is no tokenization/lexing stage, the input is parsed
  7396. // in one sweep.
  7397. //
  7398. // To make the parser fast enough to run in the browser, several
  7399. // optimization had to be made:
  7400. //
  7401. // - Matching and slicing on a huge input is often cause of slowdowns.
  7402. // The solution is to chunkify the input into smaller strings.
  7403. // The chunks are stored in the `chunks` var,
  7404. // `j` holds the current chunk index, and `currentPos` holds
  7405. // the index of the current chunk in relation to `input`.
  7406. // This gives us an almost 4x speed-up.
  7407. //
  7408. // - In many cases, we don't need to match individual tokens;
  7409. // for example, if a value doesn't hold any variables, operations
  7410. // or dynamic references, the parser can effectively 'skip' it,
  7411. // treating it as a literal.
  7412. // An example would be '1px solid #000' - which evaluates to itself,
  7413. // we don't need to know what the individual components are.
  7414. // The drawback, of course is that you don't get the benefits of
  7415. // syntax-checking on the CSS. This gives us a 50% speed-up in the parser,
  7416. // and a smaller speed-up in the code-gen.
  7417. //
  7418. //
  7419. // Token matching is done with the `$` function, which either takes
  7420. // a terminal string or regexp, or a non-terminal function to call.
  7421. // It also takes care of moving all the indices forwards.
  7422. //
  7423. var Parser = function Parser(context, imports, fileInfo) {
  7424. var parsers;
  7425. var parserInput = getParserInput();
  7426. function error(msg, type) {
  7427. throw new LessError({
  7428. index: parserInput.i,
  7429. filename: fileInfo.filename,
  7430. type: type || 'Syntax',
  7431. message: msg
  7432. }, imports);
  7433. }
  7434. function expect(arg, msg) {
  7435. // some older browsers return typeof 'function' for RegExp
  7436. var result = arg instanceof Function ? arg.call(parsers) : parserInput.$re(arg);
  7437. if (result) {
  7438. return result;
  7439. }
  7440. error(msg || (typeof arg === 'string' ? "expected '".concat(arg, "' got '").concat(parserInput.currentChar(), "'") : 'unexpected token'));
  7441. } // Specialization of expect()
  7442. function expectChar(arg, msg) {
  7443. if (parserInput.$char(arg)) {
  7444. return arg;
  7445. }
  7446. error(msg || "expected '".concat(arg, "' got '").concat(parserInput.currentChar(), "'"));
  7447. }
  7448. function getDebugInfo(index) {
  7449. var filename = fileInfo.filename;
  7450. return {
  7451. lineNumber: getLocation(index, parserInput.getInput()).line + 1,
  7452. fileName: filename
  7453. };
  7454. }
  7455. /**
  7456. * Used after initial parsing to create nodes on the fly
  7457. *
  7458. * @param {String} str - string to parse
  7459. * @param {Array} parseList - array of parsers to run input through e.g. ["value", "important"]
  7460. * @param {Number} currentIndex - start number to begin indexing
  7461. * @param {Object} fileInfo - fileInfo to attach to created nodes
  7462. */
  7463. function parseNode(str, parseList, currentIndex, fileInfo, callback) {
  7464. var result;
  7465. var returnNodes = [];
  7466. var parser = parserInput;
  7467. try {
  7468. parser.start(str, false, function fail(msg, index) {
  7469. callback({
  7470. message: msg,
  7471. index: index + currentIndex
  7472. });
  7473. });
  7474. for (var x = 0, p, i; p = parseList[x]; x++) {
  7475. i = parser.i;
  7476. result = parsers[p]();
  7477. if (result) {
  7478. try {
  7479. result._index = i + currentIndex;
  7480. result._fileInfo = fileInfo;
  7481. } catch (e) {}
  7482. returnNodes.push(result);
  7483. } else {
  7484. returnNodes.push(null);
  7485. }
  7486. }
  7487. var endInfo = parser.end();
  7488. if (endInfo.isFinished) {
  7489. callback(null, returnNodes);
  7490. } else {
  7491. callback(true, null);
  7492. }
  7493. } catch (e) {
  7494. throw new LessError({
  7495. index: e.index + currentIndex,
  7496. message: e.message
  7497. }, imports, fileInfo.filename);
  7498. }
  7499. } //
  7500. // The Parser
  7501. //
  7502. return {
  7503. parserInput: parserInput,
  7504. imports: imports,
  7505. fileInfo: fileInfo,
  7506. parseNode: parseNode,
  7507. //
  7508. // Parse an input string into an abstract syntax tree,
  7509. // @param str A string containing 'less' markup
  7510. // @param callback call `callback` when done.
  7511. // @param [additionalData] An optional map which can contains vars - a map (key, value) of variables to apply
  7512. //
  7513. parse: function parse(str, callback, additionalData) {
  7514. var root;
  7515. var error = null;
  7516. var globalVars;
  7517. var modifyVars;
  7518. var ignored;
  7519. var preText = '';
  7520. globalVars = additionalData && additionalData.globalVars ? "".concat(Parser.serializeVars(additionalData.globalVars), "\n") : '';
  7521. modifyVars = additionalData && additionalData.modifyVars ? "\n".concat(Parser.serializeVars(additionalData.modifyVars)) : '';
  7522. if (context.pluginManager) {
  7523. var preProcessors = context.pluginManager.getPreProcessors();
  7524. for (var i = 0; i < preProcessors.length; i++) {
  7525. str = preProcessors[i].process(str, {
  7526. context: context,
  7527. imports: imports,
  7528. fileInfo: fileInfo
  7529. });
  7530. }
  7531. }
  7532. if (globalVars || additionalData && additionalData.banner) {
  7533. preText = (additionalData && additionalData.banner ? additionalData.banner : '') + globalVars;
  7534. ignored = imports.contentsIgnoredChars;
  7535. ignored[fileInfo.filename] = ignored[fileInfo.filename] || 0;
  7536. ignored[fileInfo.filename] += preText.length;
  7537. }
  7538. str = str.replace(/\r\n?/g, '\n'); // Remove potential UTF Byte Order Mark
  7539. str = preText + str.replace(/^\uFEFF/, '') + modifyVars;
  7540. imports.contents[fileInfo.filename] = str; // Start with the primary rule.
  7541. // The whole syntax tree is held under a Ruleset node,
  7542. // with the `root` property set to true, so no `{}` are
  7543. // output. The callback is called when the input is parsed.
  7544. try {
  7545. parserInput.start(str, context.chunkInput, function fail(msg, index) {
  7546. throw new LessError({
  7547. index: index,
  7548. type: 'Parse',
  7549. message: msg,
  7550. filename: fileInfo.filename
  7551. }, imports);
  7552. });
  7553. tree.Node.prototype.parse = this;
  7554. root = new tree.Ruleset(null, this.parsers.primary());
  7555. tree.Node.prototype.rootNode = root;
  7556. root.root = true;
  7557. root.firstRoot = true;
  7558. root.functionRegistry = functionRegistry.inherit();
  7559. } catch (e) {
  7560. return callback(new LessError(e, imports, fileInfo.filename));
  7561. } // If `i` is smaller than the `input.length - 1`,
  7562. // it means the parser wasn't able to parse the whole
  7563. // string, so we've got a parsing error.
  7564. //
  7565. // We try to extract a \n delimited string,
  7566. // showing the line where the parse error occurred.
  7567. // We split it up into two parts (the part which parsed,
  7568. // and the part which didn't), so we can color them differently.
  7569. var endInfo = parserInput.end();
  7570. if (!endInfo.isFinished) {
  7571. var message = endInfo.furthestPossibleErrorMessage;
  7572. if (!message) {
  7573. message = 'Unrecognised input';
  7574. if (endInfo.furthestChar === '}') {
  7575. message += '. Possibly missing opening \'{\'';
  7576. } else if (endInfo.furthestChar === ')') {
  7577. message += '. Possibly missing opening \'(\'';
  7578. } else if (endInfo.furthestReachedEnd) {
  7579. message += '. Possibly missing something';
  7580. }
  7581. }
  7582. error = new LessError({
  7583. type: 'Parse',
  7584. message: message,
  7585. index: endInfo.furthest,
  7586. filename: fileInfo.filename
  7587. }, imports);
  7588. }
  7589. var finish = function finish(e) {
  7590. e = error || e || imports.error;
  7591. if (e) {
  7592. if (!(e instanceof LessError)) {
  7593. e = new LessError(e, imports, fileInfo.filename);
  7594. }
  7595. return callback(e);
  7596. } else {
  7597. return callback(null, root);
  7598. }
  7599. };
  7600. if (context.processImports !== false) {
  7601. new visitors.ImportVisitor(imports, finish).run(root);
  7602. } else {
  7603. return finish();
  7604. }
  7605. },
  7606. //
  7607. // Here in, the parsing rules/functions
  7608. //
  7609. // The basic structure of the syntax tree generated is as follows:
  7610. //
  7611. // Ruleset -> Declaration -> Value -> Expression -> Entity
  7612. //
  7613. // Here's some Less code:
  7614. //
  7615. // .class {
  7616. // color: #fff;
  7617. // border: 1px solid #000;
  7618. // width: @w + 4px;
  7619. // > .child {...}
  7620. // }
  7621. //
  7622. // And here's what the parse tree might look like:
  7623. //
  7624. // Ruleset (Selector '.class', [
  7625. // Declaration ("color", Value ([Expression [Color #fff]]))
  7626. // Declaration ("border", Value ([Expression [Dimension 1px][Keyword "solid"][Color #000]]))
  7627. // Declaration ("width", Value ([Expression [Operation " + " [Variable "@w"][Dimension 4px]]]))
  7628. // Ruleset (Selector [Element '>', '.child'], [...])
  7629. // ])
  7630. //
  7631. // In general, most rules will try to parse a token with the `$re()` function, and if the return
  7632. // value is truly, will return a new node, of the relevant type. Sometimes, we need to check
  7633. // first, before parsing, that's when we use `peek()`.
  7634. //
  7635. parsers: parsers = {
  7636. //
  7637. // The `primary` rule is the *entry* and *exit* point of the parser.
  7638. // The rules here can appear at any level of the parse tree.
  7639. //
  7640. // The recursive nature of the grammar is an interplay between the `block`
  7641. // rule, which represents `{ ... }`, the `ruleset` rule, and this `primary` rule,
  7642. // as represented by this simplified grammar:
  7643. //
  7644. // primary → (ruleset | declaration)+
  7645. // ruleset → selector+ block
  7646. // block → '{' primary '}'
  7647. //
  7648. // Only at one point is the primary rule not called from the
  7649. // block rule: at the root level.
  7650. //
  7651. primary: function primary() {
  7652. var mixin = this.mixin;
  7653. var root = [];
  7654. var node;
  7655. while (true) {
  7656. while (true) {
  7657. node = this.comment();
  7658. if (!node) {
  7659. break;
  7660. }
  7661. root.push(node);
  7662. } // always process comments before deciding if finished
  7663. if (parserInput.finished) {
  7664. break;
  7665. }
  7666. if (parserInput.peek('}')) {
  7667. break;
  7668. }
  7669. node = this.extendRule();
  7670. if (node) {
  7671. root = root.concat(node);
  7672. continue;
  7673. }
  7674. node = mixin.definition() || this.declaration() || this.ruleset() || mixin.call(false, false) || this.variableCall() || this.entities.call() || this.atrule();
  7675. if (node) {
  7676. root.push(node);
  7677. } else {
  7678. var foundSemiColon = false;
  7679. while (parserInput.$char(';')) {
  7680. foundSemiColon = true;
  7681. }
  7682. if (!foundSemiColon) {
  7683. break;
  7684. }
  7685. }
  7686. }
  7687. return root;
  7688. },
  7689. // comments are collected by the main parsing mechanism and then assigned to nodes
  7690. // where the current structure allows it
  7691. comment: function comment() {
  7692. if (parserInput.commentStore.length) {
  7693. var comment = parserInput.commentStore.shift();
  7694. return new tree.Comment(comment.text, comment.isLineComment, comment.index, fileInfo);
  7695. }
  7696. },
  7697. //
  7698. // Entities are tokens which can be found inside an Expression
  7699. //
  7700. entities: {
  7701. mixinLookup: function mixinLookup() {
  7702. return parsers.mixin.call(true, true);
  7703. },
  7704. //
  7705. // A string, which supports escaping " and '
  7706. //
  7707. // "milky way" 'he\'s the one!'
  7708. //
  7709. quoted: function quoted(forceEscaped) {
  7710. var str;
  7711. var index = parserInput.i;
  7712. var isEscaped = false;
  7713. parserInput.save();
  7714. if (parserInput.$char('~')) {
  7715. isEscaped = true;
  7716. } else if (forceEscaped) {
  7717. parserInput.restore();
  7718. return;
  7719. }
  7720. str = parserInput.$quoted();
  7721. if (!str) {
  7722. parserInput.restore();
  7723. return;
  7724. }
  7725. parserInput.forget();
  7726. return new tree.Quoted(str.charAt(0), str.substr(1, str.length - 2), isEscaped, index, fileInfo);
  7727. },
  7728. //
  7729. // A catch-all word, such as:
  7730. //
  7731. // black border-collapse
  7732. //
  7733. keyword: function keyword() {
  7734. var k = parserInput.$char('%') || parserInput.$re(/^\[?(?:[\w-]|\\(?:[A-Fa-f0-9]{1,6} ?|[^A-Fa-f0-9]))+\]?/);
  7735. if (k) {
  7736. return tree.Color.fromKeyword(k) || new tree.Keyword(k);
  7737. }
  7738. },
  7739. //
  7740. // A function call
  7741. //
  7742. // rgb(255, 0, 255)
  7743. //
  7744. // The arguments are parsed with the `entities.arguments` parser.
  7745. //
  7746. call: function call() {
  7747. var name;
  7748. var args;
  7749. var func;
  7750. var index = parserInput.i; // http://jsperf.com/case-insensitive-regex-vs-strtolower-then-regex/18
  7751. if (parserInput.peek(/^url\(/i)) {
  7752. return;
  7753. }
  7754. parserInput.save();
  7755. name = parserInput.$re(/^([\w-]+|%|progid:[\w\.]+)\(/);
  7756. if (!name) {
  7757. parserInput.forget();
  7758. return;
  7759. }
  7760. name = name[1];
  7761. func = this.customFuncCall(name);
  7762. if (func) {
  7763. args = func.parse();
  7764. if (args && func.stop) {
  7765. parserInput.forget();
  7766. return args;
  7767. }
  7768. }
  7769. args = this.arguments(args);
  7770. if (!parserInput.$char(')')) {
  7771. parserInput.restore('Could not parse call arguments or missing \')\'');
  7772. return;
  7773. }
  7774. parserInput.forget();
  7775. return new tree.Call(name, args, index, fileInfo);
  7776. },
  7777. //
  7778. // Parsing rules for functions with non-standard args, e.g.:
  7779. //
  7780. // boolean(not(2 > 1))
  7781. //
  7782. // This is a quick prototype, to be modified/improved when
  7783. // more custom-parsed funcs come (e.g. `selector(...)`)
  7784. //
  7785. customFuncCall: function customFuncCall(name) {
  7786. /* Ideally the table is to be moved out of here for faster perf.,
  7787. but it's quite tricky since it relies on all these `parsers`
  7788. and `expect` available only here */
  7789. return {
  7790. alpha: f(parsers.ieAlpha, true),
  7791. boolean: f(condition),
  7792. 'if': f(condition)
  7793. }[name.toLowerCase()];
  7794. function f(parse, stop) {
  7795. return {
  7796. parse: parse,
  7797. // parsing function
  7798. stop: stop // when true - stop after parse() and return its result,
  7799. // otherwise continue for plain args
  7800. };
  7801. }
  7802. function condition() {
  7803. return [expect(parsers.condition, 'expected condition')];
  7804. }
  7805. },
  7806. arguments: function _arguments(prevArgs) {
  7807. var argsComma = prevArgs || [];
  7808. var argsSemiColon = [];
  7809. var isSemiColonSeparated;
  7810. var value;
  7811. parserInput.save();
  7812. while (true) {
  7813. if (prevArgs) {
  7814. prevArgs = false;
  7815. } else {
  7816. value = parsers.detachedRuleset() || this.assignment() || parsers.expression();
  7817. if (!value) {
  7818. break;
  7819. }
  7820. if (value.value && value.value.length == 1) {
  7821. value = value.value[0];
  7822. }
  7823. argsComma.push(value);
  7824. }
  7825. if (parserInput.$char(',')) {
  7826. continue;
  7827. }
  7828. if (parserInput.$char(';') || isSemiColonSeparated) {
  7829. isSemiColonSeparated = true;
  7830. value = argsComma.length < 1 ? argsComma[0] : new tree.Value(argsComma);
  7831. argsSemiColon.push(value);
  7832. argsComma = [];
  7833. }
  7834. }
  7835. parserInput.forget();
  7836. return isSemiColonSeparated ? argsSemiColon : argsComma;
  7837. },
  7838. literal: function literal() {
  7839. return this.dimension() || this.color() || this.quoted() || this.unicodeDescriptor();
  7840. },
  7841. // Assignments are argument entities for calls.
  7842. // They are present in ie filter properties as shown below.
  7843. //
  7844. // filter: progid:DXImageTransform.Microsoft.Alpha( *opacity=50* )
  7845. //
  7846. assignment: function assignment() {
  7847. var key;
  7848. var value;
  7849. parserInput.save();
  7850. key = parserInput.$re(/^\w+(?=\s?=)/i);
  7851. if (!key) {
  7852. parserInput.restore();
  7853. return;
  7854. }
  7855. if (!parserInput.$char('=')) {
  7856. parserInput.restore();
  7857. return;
  7858. }
  7859. value = parsers.entity();
  7860. if (value) {
  7861. parserInput.forget();
  7862. return new tree.Assignment(key, value);
  7863. } else {
  7864. parserInput.restore();
  7865. }
  7866. },
  7867. //
  7868. // Parse url() tokens
  7869. //
  7870. // We use a specific rule for urls, because they don't really behave like
  7871. // standard function calls. The difference is that the argument doesn't have
  7872. // to be enclosed within a string, so it can't be parsed as an Expression.
  7873. //
  7874. url: function url() {
  7875. var value;
  7876. var index = parserInput.i;
  7877. parserInput.autoCommentAbsorb = false;
  7878. if (!parserInput.$str('url(')) {
  7879. parserInput.autoCommentAbsorb = true;
  7880. return;
  7881. }
  7882. value = this.quoted() || this.variable() || this.property() || parserInput.$re(/^(?:(?:\\[\(\)'"])|[^\(\)'"])+/) || '';
  7883. parserInput.autoCommentAbsorb = true;
  7884. expectChar(')');
  7885. return new tree.URL(value.value != null || value instanceof tree.Variable || value instanceof tree.Property ? value : new tree.Anonymous(value, index), index, fileInfo);
  7886. },
  7887. //
  7888. // A Variable entity, such as `@fink`, in
  7889. //
  7890. // width: @fink + 2px
  7891. //
  7892. // We use a different parser for variable definitions,
  7893. // see `parsers.variable`.
  7894. //
  7895. variable: function variable() {
  7896. var ch;
  7897. var name;
  7898. var index = parserInput.i;
  7899. parserInput.save();
  7900. if (parserInput.currentChar() === '@' && (name = parserInput.$re(/^@@?[\w-]+/))) {
  7901. ch = parserInput.currentChar();
  7902. if (ch === '(' || ch === '[' && !parserInput.prevChar().match(/^\s/)) {
  7903. // this may be a VariableCall lookup
  7904. var result = parsers.variableCall(name);
  7905. if (result) {
  7906. parserInput.forget();
  7907. return result;
  7908. }
  7909. }
  7910. parserInput.forget();
  7911. return new tree.Variable(name, index, fileInfo);
  7912. }
  7913. parserInput.restore();
  7914. },
  7915. // A variable entity using the protective {} e.g. @{var}
  7916. variableCurly: function variableCurly() {
  7917. var curly;
  7918. var index = parserInput.i;
  7919. if (parserInput.currentChar() === '@' && (curly = parserInput.$re(/^@\{([\w-]+)\}/))) {
  7920. return new tree.Variable("@".concat(curly[1]), index, fileInfo);
  7921. }
  7922. },
  7923. //
  7924. // A Property accessor, such as `$color`, in
  7925. //
  7926. // background-color: $color
  7927. //
  7928. property: function property() {
  7929. var name;
  7930. var index = parserInput.i;
  7931. if (parserInput.currentChar() === '$' && (name = parserInput.$re(/^\$[\w-]+/))) {
  7932. return new tree.Property(name, index, fileInfo);
  7933. }
  7934. },
  7935. // A property entity useing the protective {} e.g. ${prop}
  7936. propertyCurly: function propertyCurly() {
  7937. var curly;
  7938. var index = parserInput.i;
  7939. if (parserInput.currentChar() === '$' && (curly = parserInput.$re(/^\$\{([\w-]+)\}/))) {
  7940. return new tree.Property("$".concat(curly[1]), index, fileInfo);
  7941. }
  7942. },
  7943. //
  7944. // A Hexadecimal color
  7945. //
  7946. // #4F3C2F
  7947. //
  7948. // `rgb` and `hsl` colors are parsed through the `entities.call` parser.
  7949. //
  7950. color: function color() {
  7951. var rgb;
  7952. parserInput.save();
  7953. if (parserInput.currentChar() === '#' && (rgb = parserInput.$re(/^#([A-Fa-f0-9]{8}|[A-Fa-f0-9]{6}|[A-Fa-f0-9]{3,4})([\w.#\[])?/))) {
  7954. if (!rgb[2]) {
  7955. parserInput.forget();
  7956. return new tree.Color(rgb[1], undefined, rgb[0]);
  7957. }
  7958. }
  7959. parserInput.restore();
  7960. },
  7961. colorKeyword: function colorKeyword() {
  7962. parserInput.save();
  7963. var autoCommentAbsorb = parserInput.autoCommentAbsorb;
  7964. parserInput.autoCommentAbsorb = false;
  7965. var k = parserInput.$re(/^[_A-Za-z-][_A-Za-z0-9-]+/);
  7966. parserInput.autoCommentAbsorb = autoCommentAbsorb;
  7967. if (!k) {
  7968. parserInput.forget();
  7969. return;
  7970. }
  7971. parserInput.restore();
  7972. var color = tree.Color.fromKeyword(k);
  7973. if (color) {
  7974. parserInput.$str(k);
  7975. return color;
  7976. }
  7977. },
  7978. //
  7979. // A Dimension, that is, a number and a unit
  7980. //
  7981. // 0.5em 95%
  7982. //
  7983. dimension: function dimension() {
  7984. if (parserInput.peekNotNumeric()) {
  7985. return;
  7986. }
  7987. var value = parserInput.$re(/^([+-]?\d*\.?\d+)(%|[a-z_]+)?/i);
  7988. if (value) {
  7989. return new tree.Dimension(value[1], value[2]);
  7990. }
  7991. },
  7992. //
  7993. // A unicode descriptor, as is used in unicode-range
  7994. //
  7995. // U+0?? or U+00A1-00A9
  7996. //
  7997. unicodeDescriptor: function unicodeDescriptor() {
  7998. var ud;
  7999. ud = parserInput.$re(/^U\+[0-9a-fA-F?]+(\-[0-9a-fA-F?]+)?/);
  8000. if (ud) {
  8001. return new tree.UnicodeDescriptor(ud[0]);
  8002. }
  8003. },
  8004. //
  8005. // JavaScript code to be evaluated
  8006. //
  8007. // `window.location.href`
  8008. //
  8009. javascript: function javascript() {
  8010. var js;
  8011. var index = parserInput.i;
  8012. parserInput.save();
  8013. var escape = parserInput.$char('~');
  8014. var jsQuote = parserInput.$char('`');
  8015. if (!jsQuote) {
  8016. parserInput.restore();
  8017. return;
  8018. }
  8019. js = parserInput.$re(/^[^`]*`/);
  8020. if (js) {
  8021. parserInput.forget();
  8022. return new tree.JavaScript(js.substr(0, js.length - 1), Boolean(escape), index, fileInfo);
  8023. }
  8024. parserInput.restore('invalid javascript definition');
  8025. }
  8026. },
  8027. //
  8028. // The variable part of a variable definition. Used in the `rule` parser
  8029. //
  8030. // @fink:
  8031. //
  8032. variable: function variable() {
  8033. var name;
  8034. if (parserInput.currentChar() === '@' && (name = parserInput.$re(/^(@[\w-]+)\s*:/))) {
  8035. return name[1];
  8036. }
  8037. },
  8038. //
  8039. // Call a variable value to retrieve a detached ruleset
  8040. // or a value from a detached ruleset's rules.
  8041. //
  8042. // @fink();
  8043. // @fink;
  8044. // color: @fink[@color];
  8045. //
  8046. variableCall: function variableCall(parsedName) {
  8047. var lookups;
  8048. var important;
  8049. var i = parserInput.i;
  8050. var inValue = !!parsedName;
  8051. var name = parsedName;
  8052. parserInput.save();
  8053. if (name || parserInput.currentChar() === '@' && (name = parserInput.$re(/^(@[\w-]+)(\(\s*\))?/))) {
  8054. lookups = this.mixin.ruleLookups();
  8055. if (!lookups && (inValue && parserInput.$str('()') !== '()' || name[2] !== '()')) {
  8056. parserInput.restore('Missing \'[...]\' lookup in variable call');
  8057. return;
  8058. }
  8059. if (!inValue) {
  8060. name = name[1];
  8061. }
  8062. if (lookups && parsers.important()) {
  8063. important = true;
  8064. }
  8065. var call = new tree.VariableCall(name, i, fileInfo);
  8066. if (!inValue && parsers.end()) {
  8067. parserInput.forget();
  8068. return call;
  8069. } else {
  8070. parserInput.forget();
  8071. return new tree.NamespaceValue(call, lookups, important, i, fileInfo);
  8072. }
  8073. }
  8074. parserInput.restore();
  8075. },
  8076. //
  8077. // extend syntax - used to extend selectors
  8078. //
  8079. extend: function extend(isRule) {
  8080. var elements;
  8081. var e;
  8082. var index = parserInput.i;
  8083. var option;
  8084. var extendList;
  8085. var extend;
  8086. if (!parserInput.$str(isRule ? '&:extend(' : ':extend(')) {
  8087. return;
  8088. }
  8089. do {
  8090. option = null;
  8091. elements = null;
  8092. while (!(option = parserInput.$re(/^(all)(?=\s*(\)|,))/))) {
  8093. e = this.element();
  8094. if (!e) {
  8095. break;
  8096. }
  8097. if (elements) {
  8098. elements.push(e);
  8099. } else {
  8100. elements = [e];
  8101. }
  8102. }
  8103. option = option && option[1];
  8104. if (!elements) {
  8105. error('Missing target selector for :extend().');
  8106. }
  8107. extend = new tree.Extend(new tree.Selector(elements), option, index, fileInfo);
  8108. if (extendList) {
  8109. extendList.push(extend);
  8110. } else {
  8111. extendList = [extend];
  8112. }
  8113. } while (parserInput.$char(','));
  8114. expect(/^\)/);
  8115. if (isRule) {
  8116. expect(/^;/);
  8117. }
  8118. return extendList;
  8119. },
  8120. //
  8121. // extendRule - used in a rule to extend all the parent selectors
  8122. //
  8123. extendRule: function extendRule() {
  8124. return this.extend(true);
  8125. },
  8126. //
  8127. // Mixins
  8128. //
  8129. mixin: {
  8130. //
  8131. // A Mixin call, with an optional argument list
  8132. //
  8133. // #mixins > .square(#fff);
  8134. // #mixins.square(#fff);
  8135. // .rounded(4px, black);
  8136. // .button;
  8137. //
  8138. // We can lookup / return a value using the lookup syntax:
  8139. //
  8140. // color: #mixin.square(#fff)[@color];
  8141. //
  8142. // The `while` loop is there because mixins can be
  8143. // namespaced, but we only support the child and descendant
  8144. // selector for now.
  8145. //
  8146. call: function call(inValue, getLookup) {
  8147. var s = parserInput.currentChar();
  8148. var important = false;
  8149. var lookups;
  8150. var index = parserInput.i;
  8151. var elements;
  8152. var args;
  8153. var hasParens;
  8154. if (s !== '.' && s !== '#') {
  8155. return;
  8156. }
  8157. parserInput.save(); // stop us absorbing part of an invalid selector
  8158. elements = this.elements();
  8159. if (elements) {
  8160. if (parserInput.$char('(')) {
  8161. args = this.args(true).args;
  8162. expectChar(')');
  8163. hasParens = true;
  8164. }
  8165. if (getLookup !== false) {
  8166. lookups = this.ruleLookups();
  8167. }
  8168. if (getLookup === true && !lookups) {
  8169. parserInput.restore();
  8170. return;
  8171. }
  8172. if (inValue && !lookups && !hasParens) {
  8173. // This isn't a valid in-value mixin call
  8174. parserInput.restore();
  8175. return;
  8176. }
  8177. if (!inValue && parsers.important()) {
  8178. important = true;
  8179. }
  8180. if (inValue || parsers.end()) {
  8181. parserInput.forget();
  8182. var mixin = new tree.mixin.Call(elements, args, index, fileInfo, !lookups && important);
  8183. if (lookups) {
  8184. return new tree.NamespaceValue(mixin, lookups, important);
  8185. } else {
  8186. return mixin;
  8187. }
  8188. }
  8189. }
  8190. parserInput.restore();
  8191. },
  8192. /**
  8193. * Matching elements for mixins
  8194. * (Start with . or # and can have > )
  8195. */
  8196. elements: function elements() {
  8197. var elements;
  8198. var e;
  8199. var c;
  8200. var elem;
  8201. var elemIndex;
  8202. var re = /^[#.](?:[\w-]|\\(?:[A-Fa-f0-9]{1,6} ?|[^A-Fa-f0-9]))+/;
  8203. while (true) {
  8204. elemIndex = parserInput.i;
  8205. e = parserInput.$re(re);
  8206. if (!e) {
  8207. break;
  8208. }
  8209. elem = new tree.Element(c, e, false, elemIndex, fileInfo);
  8210. if (elements) {
  8211. elements.push(elem);
  8212. } else {
  8213. elements = [elem];
  8214. }
  8215. c = parserInput.$char('>');
  8216. }
  8217. return elements;
  8218. },
  8219. args: function args(isCall) {
  8220. var entities = parsers.entities;
  8221. var returner = {
  8222. args: null,
  8223. variadic: false
  8224. };
  8225. var expressions = [];
  8226. var argsSemiColon = [];
  8227. var argsComma = [];
  8228. var isSemiColonSeparated;
  8229. var expressionContainsNamed;
  8230. var name;
  8231. var nameLoop;
  8232. var value;
  8233. var arg;
  8234. var expand;
  8235. var hasSep = true;
  8236. parserInput.save();
  8237. while (true) {
  8238. if (isCall) {
  8239. arg = parsers.detachedRuleset() || parsers.expression();
  8240. } else {
  8241. parserInput.commentStore.length = 0;
  8242. if (parserInput.$str('...')) {
  8243. returner.variadic = true;
  8244. if (parserInput.$char(';') && !isSemiColonSeparated) {
  8245. isSemiColonSeparated = true;
  8246. }
  8247. (isSemiColonSeparated ? argsSemiColon : argsComma).push({
  8248. variadic: true
  8249. });
  8250. break;
  8251. }
  8252. arg = entities.variable() || entities.property() || entities.literal() || entities.keyword() || this.call(true);
  8253. }
  8254. if (!arg || !hasSep) {
  8255. break;
  8256. }
  8257. nameLoop = null;
  8258. if (arg.throwAwayComments) {
  8259. arg.throwAwayComments();
  8260. }
  8261. value = arg;
  8262. var val = null;
  8263. if (isCall) {
  8264. // Variable
  8265. if (arg.value && arg.value.length == 1) {
  8266. val = arg.value[0];
  8267. }
  8268. } else {
  8269. val = arg;
  8270. }
  8271. if (val && (val instanceof tree.Variable || val instanceof tree.Property)) {
  8272. if (parserInput.$char(':')) {
  8273. if (expressions.length > 0) {
  8274. if (isSemiColonSeparated) {
  8275. error('Cannot mix ; and , as delimiter types');
  8276. }
  8277. expressionContainsNamed = true;
  8278. }
  8279. value = parsers.detachedRuleset() || parsers.expression();
  8280. if (!value) {
  8281. if (isCall) {
  8282. error('could not understand value for named argument');
  8283. } else {
  8284. parserInput.restore();
  8285. returner.args = [];
  8286. return returner;
  8287. }
  8288. }
  8289. nameLoop = name = val.name;
  8290. } else if (parserInput.$str('...')) {
  8291. if (!isCall) {
  8292. returner.variadic = true;
  8293. if (parserInput.$char(';') && !isSemiColonSeparated) {
  8294. isSemiColonSeparated = true;
  8295. }
  8296. (isSemiColonSeparated ? argsSemiColon : argsComma).push({
  8297. name: arg.name,
  8298. variadic: true
  8299. });
  8300. break;
  8301. } else {
  8302. expand = true;
  8303. }
  8304. } else if (!isCall) {
  8305. name = nameLoop = val.name;
  8306. value = null;
  8307. }
  8308. }
  8309. if (value) {
  8310. expressions.push(value);
  8311. }
  8312. argsComma.push({
  8313. name: nameLoop,
  8314. value: value,
  8315. expand: expand
  8316. });
  8317. if (parserInput.$char(',')) {
  8318. hasSep = true;
  8319. continue;
  8320. }
  8321. hasSep = parserInput.$char(';') === ';';
  8322. if (hasSep || isSemiColonSeparated) {
  8323. if (expressionContainsNamed) {
  8324. error('Cannot mix ; and , as delimiter types');
  8325. }
  8326. isSemiColonSeparated = true;
  8327. if (expressions.length > 1) {
  8328. value = new tree.Value(expressions);
  8329. }
  8330. argsSemiColon.push({
  8331. name: name,
  8332. value: value,
  8333. expand: expand
  8334. });
  8335. name = null;
  8336. expressions = [];
  8337. expressionContainsNamed = false;
  8338. }
  8339. }
  8340. parserInput.forget();
  8341. returner.args = isSemiColonSeparated ? argsSemiColon : argsComma;
  8342. return returner;
  8343. },
  8344. //
  8345. // A Mixin definition, with a list of parameters
  8346. //
  8347. // .rounded (@radius: 2px, @color) {
  8348. // ...
  8349. // }
  8350. //
  8351. // Until we have a finer grained state-machine, we have to
  8352. // do a look-ahead, to make sure we don't have a mixin call.
  8353. // See the `rule` function for more information.
  8354. //
  8355. // We start by matching `.rounded (`, and then proceed on to
  8356. // the argument list, which has optional default values.
  8357. // We store the parameters in `params`, with a `value` key,
  8358. // if there is a value, such as in the case of `@radius`.
  8359. //
  8360. // Once we've got our params list, and a closing `)`, we parse
  8361. // the `{...}` block.
  8362. //
  8363. definition: function definition() {
  8364. var name;
  8365. var params = [];
  8366. var match;
  8367. var ruleset;
  8368. var cond;
  8369. var variadic = false;
  8370. if (parserInput.currentChar() !== '.' && parserInput.currentChar() !== '#' || parserInput.peek(/^[^{]*\}/)) {
  8371. return;
  8372. }
  8373. parserInput.save();
  8374. match = parserInput.$re(/^([#.](?:[\w-]|\\(?:[A-Fa-f0-9]{1,6} ?|[^A-Fa-f0-9]))+)\s*\(/);
  8375. if (match) {
  8376. name = match[1];
  8377. var argInfo = this.args(false);
  8378. params = argInfo.args;
  8379. variadic = argInfo.variadic; // .mixincall("@{a}");
  8380. // looks a bit like a mixin definition..
  8381. // also
  8382. // .mixincall(@a: {rule: set;});
  8383. // so we have to be nice and restore
  8384. if (!parserInput.$char(')')) {
  8385. parserInput.restore('Missing closing \')\'');
  8386. return;
  8387. }
  8388. parserInput.commentStore.length = 0;
  8389. if (parserInput.$str('when')) {
  8390. // Guard
  8391. cond = expect(parsers.conditions, 'expected condition');
  8392. }
  8393. ruleset = parsers.block();
  8394. if (ruleset) {
  8395. parserInput.forget();
  8396. return new tree.mixin.Definition(name, params, ruleset, cond, variadic);
  8397. } else {
  8398. parserInput.restore();
  8399. }
  8400. } else {
  8401. parserInput.forget();
  8402. }
  8403. },
  8404. ruleLookups: function ruleLookups() {
  8405. var rule;
  8406. var lookups = [];
  8407. if (parserInput.currentChar() !== '[') {
  8408. return;
  8409. }
  8410. while (true) {
  8411. parserInput.save();
  8412. rule = this.lookupValue();
  8413. if (!rule && rule !== '') {
  8414. parserInput.restore();
  8415. break;
  8416. }
  8417. lookups.push(rule);
  8418. parserInput.forget();
  8419. }
  8420. if (lookups.length > 0) {
  8421. return lookups;
  8422. }
  8423. },
  8424. lookupValue: function lookupValue() {
  8425. parserInput.save();
  8426. if (!parserInput.$char('[')) {
  8427. parserInput.restore();
  8428. return;
  8429. }
  8430. var name = parserInput.$re(/^(?:[@$]{0,2})[_a-zA-Z0-9-]*/);
  8431. if (!parserInput.$char(']')) {
  8432. parserInput.restore();
  8433. return;
  8434. }
  8435. if (name || name === '') {
  8436. parserInput.forget();
  8437. return name;
  8438. }
  8439. parserInput.restore();
  8440. }
  8441. },
  8442. //
  8443. // Entities are the smallest recognized token,
  8444. // and can be found inside a rule's value.
  8445. //
  8446. entity: function entity() {
  8447. var entities = this.entities;
  8448. return this.comment() || entities.literal() || entities.variable() || entities.url() || entities.property() || entities.call() || entities.keyword() || this.mixin.call(true) || entities.javascript();
  8449. },
  8450. //
  8451. // A Declaration terminator. Note that we use `peek()` to check for '}',
  8452. // because the `block` rule will be expecting it, but we still need to make sure
  8453. // it's there, if ';' was omitted.
  8454. //
  8455. end: function end() {
  8456. return parserInput.$char(';') || parserInput.peek('}');
  8457. },
  8458. //
  8459. // IE's alpha function
  8460. //
  8461. // alpha(opacity=88)
  8462. //
  8463. ieAlpha: function ieAlpha() {
  8464. var value; // http://jsperf.com/case-insensitive-regex-vs-strtolower-then-regex/18
  8465. if (!parserInput.$re(/^opacity=/i)) {
  8466. return;
  8467. }
  8468. value = parserInput.$re(/^\d+/);
  8469. if (!value) {
  8470. value = expect(parsers.entities.variable, 'Could not parse alpha');
  8471. value = "@{".concat(value.name.slice(1), "}");
  8472. }
  8473. expectChar(')');
  8474. return new tree.Quoted('', "alpha(opacity=".concat(value, ")"));
  8475. },
  8476. //
  8477. // A Selector Element
  8478. //
  8479. // div
  8480. // + h1
  8481. // #socks
  8482. // input[type="text"]
  8483. //
  8484. // Elements are the building blocks for Selectors,
  8485. // they are made out of a `Combinator` (see combinator rule),
  8486. // and an element name, such as a tag a class, or `*`.
  8487. //
  8488. element: function element() {
  8489. var e;
  8490. var c;
  8491. var v;
  8492. var index = parserInput.i;
  8493. c = this.combinator();
  8494. e = parserInput.$re(/^(?:\d+\.\d+|\d+)%/) || parserInput.$re(/^(?:[.#]?|:*)(?:[\w-]|[^\x00-\x9f]|\\(?:[A-Fa-f0-9]{1,6} ?|[^A-Fa-f0-9]))+/) || parserInput.$char('*') || parserInput.$char('&') || this.attribute() || parserInput.$re(/^\([^&()@]+\)/) || parserInput.$re(/^[\.#:](?=@)/) || this.entities.variableCurly();
  8495. if (!e) {
  8496. parserInput.save();
  8497. if (parserInput.$char('(')) {
  8498. if ((v = this.selector(false)) && parserInput.$char(')')) {
  8499. e = new tree.Paren(v);
  8500. parserInput.forget();
  8501. } else {
  8502. parserInput.restore('Missing closing \')\'');
  8503. }
  8504. } else {
  8505. parserInput.forget();
  8506. }
  8507. }
  8508. if (e) {
  8509. return new tree.Element(c, e, e instanceof tree.Variable, index, fileInfo);
  8510. }
  8511. },
  8512. //
  8513. // Combinators combine elements together, in a Selector.
  8514. //
  8515. // Because our parser isn't white-space sensitive, special care
  8516. // has to be taken, when parsing the descendant combinator, ` `,
  8517. // as it's an empty space. We have to check the previous character
  8518. // in the input, to see if it's a ` ` character. More info on how
  8519. // we deal with this in *combinator.js*.
  8520. //
  8521. combinator: function combinator() {
  8522. var c = parserInput.currentChar();
  8523. if (c === '/') {
  8524. parserInput.save();
  8525. var slashedCombinator = parserInput.$re(/^\/[a-z]+\//i);
  8526. if (slashedCombinator) {
  8527. parserInput.forget();
  8528. return new tree.Combinator(slashedCombinator);
  8529. }
  8530. parserInput.restore();
  8531. }
  8532. if (c === '>' || c === '+' || c === '~' || c === '|' || c === '^') {
  8533. parserInput.i++;
  8534. if (c === '^' && parserInput.currentChar() === '^') {
  8535. c = '^^';
  8536. parserInput.i++;
  8537. }
  8538. while (parserInput.isWhitespace()) {
  8539. parserInput.i++;
  8540. }
  8541. return new tree.Combinator(c);
  8542. } else if (parserInput.isWhitespace(-1)) {
  8543. return new tree.Combinator(' ');
  8544. } else {
  8545. return new tree.Combinator(null);
  8546. }
  8547. },
  8548. //
  8549. // A CSS Selector
  8550. // with less extensions e.g. the ability to extend and guard
  8551. //
  8552. // .class > div + h1
  8553. // li a:hover
  8554. //
  8555. // Selectors are made out of one or more Elements, see above.
  8556. //
  8557. selector: function selector(isLess) {
  8558. var index = parserInput.i;
  8559. var elements;
  8560. var extendList;
  8561. var c;
  8562. var e;
  8563. var allExtends;
  8564. var when;
  8565. var condition;
  8566. isLess = isLess !== false;
  8567. while (isLess && (extendList = this.extend()) || isLess && (when = parserInput.$str('when')) || (e = this.element())) {
  8568. if (when) {
  8569. condition = expect(this.conditions, 'expected condition');
  8570. } else if (condition) {
  8571. error('CSS guard can only be used at the end of selector');
  8572. } else if (extendList) {
  8573. if (allExtends) {
  8574. allExtends = allExtends.concat(extendList);
  8575. } else {
  8576. allExtends = extendList;
  8577. }
  8578. } else {
  8579. if (allExtends) {
  8580. error('Extend can only be used at the end of selector');
  8581. }
  8582. c = parserInput.currentChar();
  8583. if (elements) {
  8584. elements.push(e);
  8585. } else {
  8586. elements = [e];
  8587. }
  8588. e = null;
  8589. }
  8590. if (c === '{' || c === '}' || c === ';' || c === ',' || c === ')') {
  8591. break;
  8592. }
  8593. }
  8594. if (elements) {
  8595. return new tree.Selector(elements, allExtends, condition, index, fileInfo);
  8596. }
  8597. if (allExtends) {
  8598. error('Extend must be used to extend a selector, it cannot be used on its own');
  8599. }
  8600. },
  8601. selectors: function selectors() {
  8602. var s;
  8603. var selectors;
  8604. while (true) {
  8605. s = this.selector();
  8606. if (!s) {
  8607. break;
  8608. }
  8609. if (selectors) {
  8610. selectors.push(s);
  8611. } else {
  8612. selectors = [s];
  8613. }
  8614. parserInput.commentStore.length = 0;
  8615. if (s.condition && selectors.length > 1) {
  8616. error("Guards are only currently allowed on a single selector.");
  8617. }
  8618. if (!parserInput.$char(',')) {
  8619. break;
  8620. }
  8621. if (s.condition) {
  8622. error("Guards are only currently allowed on a single selector.");
  8623. }
  8624. parserInput.commentStore.length = 0;
  8625. }
  8626. return selectors;
  8627. },
  8628. attribute: function attribute() {
  8629. if (!parserInput.$char('[')) {
  8630. return;
  8631. }
  8632. var entities = this.entities;
  8633. var key;
  8634. var val;
  8635. var op;
  8636. if (!(key = entities.variableCurly())) {
  8637. key = expect(/^(?:[_A-Za-z0-9-\*]*\|)?(?:[_A-Za-z0-9-]|\\.)+/);
  8638. }
  8639. op = parserInput.$re(/^[|~*$^]?=/);
  8640. if (op) {
  8641. val = entities.quoted() || parserInput.$re(/^[0-9]+%/) || parserInput.$re(/^[\w-]+/) || entities.variableCurly();
  8642. }
  8643. expectChar(']');
  8644. return new tree.Attribute(key, op, val);
  8645. },
  8646. //
  8647. // The `block` rule is used by `ruleset` and `mixin.definition`.
  8648. // It's a wrapper around the `primary` rule, with added `{}`.
  8649. //
  8650. block: function block() {
  8651. var content;
  8652. if (parserInput.$char('{') && (content = this.primary()) && parserInput.$char('}')) {
  8653. return content;
  8654. }
  8655. },
  8656. blockRuleset: function blockRuleset() {
  8657. var block = this.block();
  8658. if (block) {
  8659. block = new tree.Ruleset(null, block);
  8660. }
  8661. return block;
  8662. },
  8663. detachedRuleset: function detachedRuleset() {
  8664. var argInfo;
  8665. var params;
  8666. var variadic;
  8667. parserInput.save();
  8668. if (parserInput.$re(/^[.#]\(/)) {
  8669. /**
  8670. * DR args currently only implemented for each() function, and not
  8671. * yet settable as `@dr: #(@arg) {}`
  8672. * This should be done when DRs are merged with mixins.
  8673. * See: https://github.com/less/less-meta/issues/16
  8674. */
  8675. argInfo = this.mixin.args(false);
  8676. params = argInfo.args;
  8677. variadic = argInfo.variadic;
  8678. if (!parserInput.$char(')')) {
  8679. parserInput.restore();
  8680. return;
  8681. }
  8682. }
  8683. var blockRuleset = this.blockRuleset();
  8684. if (blockRuleset) {
  8685. parserInput.forget();
  8686. if (params) {
  8687. return new tree.mixin.Definition(null, params, blockRuleset, null, variadic);
  8688. }
  8689. return new tree.DetachedRuleset(blockRuleset);
  8690. }
  8691. parserInput.restore();
  8692. },
  8693. //
  8694. // div, .class, body > p {...}
  8695. //
  8696. ruleset: function ruleset() {
  8697. var selectors;
  8698. var rules;
  8699. var debugInfo;
  8700. parserInput.save();
  8701. if (context.dumpLineNumbers) {
  8702. debugInfo = getDebugInfo(parserInput.i);
  8703. }
  8704. selectors = this.selectors();
  8705. if (selectors && (rules = this.block())) {
  8706. parserInput.forget();
  8707. var ruleset = new tree.Ruleset(selectors, rules, context.strictImports);
  8708. if (context.dumpLineNumbers) {
  8709. ruleset.debugInfo = debugInfo;
  8710. }
  8711. return ruleset;
  8712. } else {
  8713. parserInput.restore();
  8714. }
  8715. },
  8716. declaration: function declaration() {
  8717. var name;
  8718. var value;
  8719. var index = parserInput.i;
  8720. var hasDR;
  8721. var c = parserInput.currentChar();
  8722. var important;
  8723. var merge;
  8724. var isVariable;
  8725. if (c === '.' || c === '#' || c === '&' || c === ':') {
  8726. return;
  8727. }
  8728. parserInput.save();
  8729. name = this.variable() || this.ruleProperty();
  8730. if (name) {
  8731. isVariable = typeof name === 'string';
  8732. if (isVariable) {
  8733. value = this.detachedRuleset();
  8734. if (value) {
  8735. hasDR = true;
  8736. }
  8737. }
  8738. parserInput.commentStore.length = 0;
  8739. if (!value) {
  8740. // a name returned by this.ruleProperty() is always an array of the form:
  8741. // [string-1, ..., string-n, ""] or [string-1, ..., string-n, "+"]
  8742. // where each item is a tree.Keyword or tree.Variable
  8743. merge = !isVariable && name.length > 1 && name.pop().value; // Custom property values get permissive parsing
  8744. if (name[0].value && name[0].value.slice(0, 2) === '--') {
  8745. value = this.permissiveValue();
  8746. } // Try to store values as anonymous
  8747. // If we need the value later we'll re-parse it in ruleset.parseValue
  8748. else {
  8749. value = this.anonymousValue();
  8750. }
  8751. if (value) {
  8752. parserInput.forget(); // anonymous values absorb the end ';' which is required for them to work
  8753. return new tree.Declaration(name, value, false, merge, index, fileInfo);
  8754. }
  8755. if (!value) {
  8756. value = this.value();
  8757. }
  8758. if (value) {
  8759. important = this.important();
  8760. } else if (isVariable) {
  8761. // As a last resort, try permissiveValue
  8762. value = this.permissiveValue();
  8763. }
  8764. }
  8765. if (value && (this.end() || hasDR)) {
  8766. parserInput.forget();
  8767. return new tree.Declaration(name, value, important, merge, index, fileInfo);
  8768. } else {
  8769. parserInput.restore();
  8770. }
  8771. } else {
  8772. parserInput.restore();
  8773. }
  8774. },
  8775. anonymousValue: function anonymousValue() {
  8776. var index = parserInput.i;
  8777. var match = parserInput.$re(/^([^.#@\$+\/'"*`(;{}-]*);/);
  8778. if (match) {
  8779. return new tree.Anonymous(match[1], index);
  8780. }
  8781. },
  8782. /**
  8783. * Used for custom properties, at-rules, and variables (as fallback)
  8784. * Parses almost anything inside of {} [] () "" blocks
  8785. * until it reaches outer-most tokens.
  8786. *
  8787. * First, it will try to parse comments and entities to reach
  8788. * the end. This is mostly like the Expression parser except no
  8789. * math is allowed.
  8790. */
  8791. permissiveValue: function permissiveValue(untilTokens) {
  8792. var i;
  8793. var e;
  8794. var done;
  8795. var value;
  8796. var tok = untilTokens || ';';
  8797. var index = parserInput.i;
  8798. var result = [];
  8799. function testCurrentChar() {
  8800. var char = parserInput.currentChar();
  8801. if (typeof tok === 'string') {
  8802. return char === tok;
  8803. } else {
  8804. return tok.test(char);
  8805. }
  8806. }
  8807. if (testCurrentChar()) {
  8808. return;
  8809. }
  8810. value = [];
  8811. do {
  8812. e = this.comment();
  8813. if (e) {
  8814. value.push(e);
  8815. continue;
  8816. }
  8817. e = this.entity();
  8818. if (e) {
  8819. value.push(e);
  8820. }
  8821. } while (e);
  8822. done = testCurrentChar();
  8823. if (value.length > 0) {
  8824. value = new tree.Expression(value);
  8825. if (done) {
  8826. return value;
  8827. } else {
  8828. result.push(value);
  8829. } // Preserve space before $parseUntil as it will not
  8830. if (parserInput.prevChar() === ' ') {
  8831. result.push(new tree.Anonymous(' ', index));
  8832. }
  8833. }
  8834. parserInput.save();
  8835. value = parserInput.$parseUntil(tok);
  8836. if (value) {
  8837. if (typeof value === 'string') {
  8838. error("Expected '".concat(value, "'"), 'Parse');
  8839. }
  8840. if (value.length === 1 && value[0] === ' ') {
  8841. parserInput.forget();
  8842. return new tree.Anonymous('', index);
  8843. }
  8844. var item;
  8845. for (i = 0; i < value.length; i++) {
  8846. item = value[i];
  8847. if (Array.isArray(item)) {
  8848. // Treat actual quotes as normal quoted values
  8849. result.push(new tree.Quoted(item[0], item[1], true, index, fileInfo));
  8850. } else {
  8851. if (i === value.length - 1) {
  8852. item = item.trim();
  8853. } // Treat like quoted values, but replace vars like unquoted expressions
  8854. var quote = new tree.Quoted('\'', item, true, index, fileInfo);
  8855. quote.variableRegex = /@([\w-]+)/g;
  8856. quote.propRegex = /\$([\w-]+)/g;
  8857. result.push(quote);
  8858. }
  8859. }
  8860. parserInput.forget();
  8861. return new tree.Expression(result, true);
  8862. }
  8863. parserInput.restore();
  8864. },
  8865. //
  8866. // An @import atrule
  8867. //
  8868. // @import "lib";
  8869. //
  8870. // Depending on our environment, importing is done differently:
  8871. // In the browser, it's an XHR request, in Node, it would be a
  8872. // file-system operation. The function used for importing is
  8873. // stored in `import`, which we pass to the Import constructor.
  8874. //
  8875. 'import': function _import() {
  8876. var path;
  8877. var features;
  8878. var index = parserInput.i;
  8879. var dir = parserInput.$re(/^@import?\s+/);
  8880. if (dir) {
  8881. var options = (dir ? this.importOptions() : null) || {};
  8882. if (path = this.entities.quoted() || this.entities.url()) {
  8883. features = this.mediaFeatures();
  8884. if (!parserInput.$char(';')) {
  8885. parserInput.i = index;
  8886. error('missing semi-colon or unrecognised media features on import');
  8887. }
  8888. features = features && new tree.Value(features);
  8889. return new tree.Import(path, features, options, index, fileInfo);
  8890. } else {
  8891. parserInput.i = index;
  8892. error('malformed import statement');
  8893. }
  8894. }
  8895. },
  8896. importOptions: function importOptions() {
  8897. var o;
  8898. var options = {};
  8899. var optionName;
  8900. var value; // list of options, surrounded by parens
  8901. if (!parserInput.$char('(')) {
  8902. return null;
  8903. }
  8904. do {
  8905. o = this.importOption();
  8906. if (o) {
  8907. optionName = o;
  8908. value = true;
  8909. switch (optionName) {
  8910. case 'css':
  8911. optionName = 'less';
  8912. value = false;
  8913. break;
  8914. case 'once':
  8915. optionName = 'multiple';
  8916. value = false;
  8917. break;
  8918. }
  8919. options[optionName] = value;
  8920. if (!parserInput.$char(',')) {
  8921. break;
  8922. }
  8923. }
  8924. } while (o);
  8925. expectChar(')');
  8926. return options;
  8927. },
  8928. importOption: function importOption() {
  8929. var opt = parserInput.$re(/^(less|css|multiple|once|inline|reference|optional)/);
  8930. if (opt) {
  8931. return opt[1];
  8932. }
  8933. },
  8934. mediaFeature: function mediaFeature() {
  8935. var entities = this.entities;
  8936. var nodes = [];
  8937. var e;
  8938. var p;
  8939. parserInput.save();
  8940. do {
  8941. e = entities.keyword() || entities.variable() || entities.mixinLookup();
  8942. if (e) {
  8943. nodes.push(e);
  8944. } else if (parserInput.$char('(')) {
  8945. p = this.property();
  8946. e = this.value();
  8947. if (parserInput.$char(')')) {
  8948. if (p && e) {
  8949. nodes.push(new tree.Paren(new tree.Declaration(p, e, null, null, parserInput.i, fileInfo, true)));
  8950. } else if (e) {
  8951. nodes.push(new tree.Paren(e));
  8952. } else {
  8953. error('badly formed media feature definition');
  8954. }
  8955. } else {
  8956. error('Missing closing \')\'', 'Parse');
  8957. }
  8958. }
  8959. } while (e);
  8960. parserInput.forget();
  8961. if (nodes.length > 0) {
  8962. return new tree.Expression(nodes);
  8963. }
  8964. },
  8965. mediaFeatures: function mediaFeatures() {
  8966. var entities = this.entities;
  8967. var features = [];
  8968. var e;
  8969. do {
  8970. e = this.mediaFeature();
  8971. if (e) {
  8972. features.push(e);
  8973. if (!parserInput.$char(',')) {
  8974. break;
  8975. }
  8976. } else {
  8977. e = entities.variable() || entities.mixinLookup();
  8978. if (e) {
  8979. features.push(e);
  8980. if (!parserInput.$char(',')) {
  8981. break;
  8982. }
  8983. }
  8984. }
  8985. } while (e);
  8986. return features.length > 0 ? features : null;
  8987. },
  8988. media: function media() {
  8989. var features;
  8990. var rules;
  8991. var media;
  8992. var debugInfo;
  8993. var index = parserInput.i;
  8994. if (context.dumpLineNumbers) {
  8995. debugInfo = getDebugInfo(index);
  8996. }
  8997. parserInput.save();
  8998. if (parserInput.$str('@media')) {
  8999. features = this.mediaFeatures();
  9000. rules = this.block();
  9001. if (!rules) {
  9002. error('media definitions require block statements after any features');
  9003. }
  9004. parserInput.forget();
  9005. media = new tree.Media(rules, features, index, fileInfo);
  9006. if (context.dumpLineNumbers) {
  9007. media.debugInfo = debugInfo;
  9008. }
  9009. return media;
  9010. }
  9011. parserInput.restore();
  9012. },
  9013. //
  9014. // A @plugin directive, used to import plugins dynamically.
  9015. //
  9016. // @plugin (args) "lib";
  9017. //
  9018. plugin: function plugin() {
  9019. var path;
  9020. var args;
  9021. var options;
  9022. var index = parserInput.i;
  9023. var dir = parserInput.$re(/^@plugin?\s+/);
  9024. if (dir) {
  9025. args = this.pluginArgs();
  9026. if (args) {
  9027. options = {
  9028. pluginArgs: args,
  9029. isPlugin: true
  9030. };
  9031. } else {
  9032. options = {
  9033. isPlugin: true
  9034. };
  9035. }
  9036. if (path = this.entities.quoted() || this.entities.url()) {
  9037. if (!parserInput.$char(';')) {
  9038. parserInput.i = index;
  9039. error('missing semi-colon on @plugin');
  9040. }
  9041. return new tree.Import(path, null, options, index, fileInfo);
  9042. } else {
  9043. parserInput.i = index;
  9044. error('malformed @plugin statement');
  9045. }
  9046. }
  9047. },
  9048. pluginArgs: function pluginArgs() {
  9049. // list of options, surrounded by parens
  9050. parserInput.save();
  9051. if (!parserInput.$char('(')) {
  9052. parserInput.restore();
  9053. return null;
  9054. }
  9055. var args = parserInput.$re(/^\s*([^\);]+)\)\s*/);
  9056. if (args[1]) {
  9057. parserInput.forget();
  9058. return args[1].trim();
  9059. } else {
  9060. parserInput.restore();
  9061. return null;
  9062. }
  9063. },
  9064. //
  9065. // A CSS AtRule
  9066. //
  9067. // @charset "utf-8";
  9068. //
  9069. atrule: function atrule() {
  9070. var index = parserInput.i;
  9071. var name;
  9072. var value;
  9073. var rules;
  9074. var nonVendorSpecificName;
  9075. var hasIdentifier;
  9076. var hasExpression;
  9077. var hasUnknown;
  9078. var hasBlock = true;
  9079. var isRooted = true;
  9080. if (parserInput.currentChar() !== '@') {
  9081. return;
  9082. }
  9083. value = this['import']() || this.plugin() || this.media();
  9084. if (value) {
  9085. return value;
  9086. }
  9087. parserInput.save();
  9088. name = parserInput.$re(/^@[a-z-]+/);
  9089. if (!name) {
  9090. return;
  9091. }
  9092. nonVendorSpecificName = name;
  9093. if (name.charAt(1) == '-' && name.indexOf('-', 2) > 0) {
  9094. nonVendorSpecificName = "@".concat(name.slice(name.indexOf('-', 2) + 1));
  9095. }
  9096. switch (nonVendorSpecificName) {
  9097. case '@charset':
  9098. hasIdentifier = true;
  9099. hasBlock = false;
  9100. break;
  9101. case '@namespace':
  9102. hasExpression = true;
  9103. hasBlock = false;
  9104. break;
  9105. case '@keyframes':
  9106. case '@counter-style':
  9107. hasIdentifier = true;
  9108. break;
  9109. case '@document':
  9110. case '@supports':
  9111. hasUnknown = true;
  9112. isRooted = false;
  9113. break;
  9114. default:
  9115. hasUnknown = true;
  9116. break;
  9117. }
  9118. parserInput.commentStore.length = 0;
  9119. if (hasIdentifier) {
  9120. value = this.entity();
  9121. if (!value) {
  9122. error("expected ".concat(name, " identifier"));
  9123. }
  9124. } else if (hasExpression) {
  9125. value = this.expression();
  9126. if (!value) {
  9127. error("expected ".concat(name, " expression"));
  9128. }
  9129. } else if (hasUnknown) {
  9130. value = this.permissiveValue(/^[{;]/);
  9131. hasBlock = parserInput.currentChar() === '{';
  9132. if (!value) {
  9133. if (!hasBlock && parserInput.currentChar() !== ';') {
  9134. error("".concat(name, " rule is missing block or ending semi-colon"));
  9135. }
  9136. } else if (!value.value) {
  9137. value = null;
  9138. }
  9139. }
  9140. if (hasBlock) {
  9141. rules = this.blockRuleset();
  9142. }
  9143. if (rules || !hasBlock && value && parserInput.$char(';')) {
  9144. parserInput.forget();
  9145. return new tree.AtRule(name, value, rules, index, fileInfo, context.dumpLineNumbers ? getDebugInfo(index) : null, isRooted);
  9146. }
  9147. parserInput.restore('at-rule options not recognised');
  9148. },
  9149. //
  9150. // A Value is a comma-delimited list of Expressions
  9151. //
  9152. // font-family: Baskerville, Georgia, serif;
  9153. //
  9154. // In a Rule, a Value represents everything after the `:`,
  9155. // and before the `;`.
  9156. //
  9157. value: function value() {
  9158. var e;
  9159. var expressions = [];
  9160. var index = parserInput.i;
  9161. do {
  9162. e = this.expression();
  9163. if (e) {
  9164. expressions.push(e);
  9165. if (!parserInput.$char(',')) {
  9166. break;
  9167. }
  9168. }
  9169. } while (e);
  9170. if (expressions.length > 0) {
  9171. return new tree.Value(expressions, index);
  9172. }
  9173. },
  9174. important: function important() {
  9175. if (parserInput.currentChar() === '!') {
  9176. return parserInput.$re(/^! *important/);
  9177. }
  9178. },
  9179. sub: function sub() {
  9180. var a;
  9181. var e;
  9182. parserInput.save();
  9183. if (parserInput.$char('(')) {
  9184. a = this.addition();
  9185. if (a && parserInput.$char(')')) {
  9186. parserInput.forget();
  9187. e = new tree.Expression([a]);
  9188. e.parens = true;
  9189. return e;
  9190. }
  9191. parserInput.restore('Expected \')\'');
  9192. return;
  9193. }
  9194. parserInput.restore();
  9195. },
  9196. multiplication: function multiplication() {
  9197. var m;
  9198. var a;
  9199. var op;
  9200. var operation;
  9201. var isSpaced;
  9202. m = this.operand();
  9203. if (m) {
  9204. isSpaced = parserInput.isWhitespace(-1);
  9205. while (true) {
  9206. if (parserInput.peek(/^\/[*\/]/)) {
  9207. break;
  9208. }
  9209. parserInput.save();
  9210. op = parserInput.$char('/') || parserInput.$char('*') || parserInput.$str('./');
  9211. if (!op) {
  9212. parserInput.forget();
  9213. break;
  9214. }
  9215. a = this.operand();
  9216. if (!a) {
  9217. parserInput.restore();
  9218. break;
  9219. }
  9220. parserInput.forget();
  9221. m.parensInOp = true;
  9222. a.parensInOp = true;
  9223. operation = new tree.Operation(op, [operation || m, a], isSpaced);
  9224. isSpaced = parserInput.isWhitespace(-1);
  9225. }
  9226. return operation || m;
  9227. }
  9228. },
  9229. addition: function addition() {
  9230. var m;
  9231. var a;
  9232. var op;
  9233. var operation;
  9234. var isSpaced;
  9235. m = this.multiplication();
  9236. if (m) {
  9237. isSpaced = parserInput.isWhitespace(-1);
  9238. while (true) {
  9239. op = parserInput.$re(/^[-+]\s+/) || !isSpaced && (parserInput.$char('+') || parserInput.$char('-'));
  9240. if (!op) {
  9241. break;
  9242. }
  9243. a = this.multiplication();
  9244. if (!a) {
  9245. break;
  9246. }
  9247. m.parensInOp = true;
  9248. a.parensInOp = true;
  9249. operation = new tree.Operation(op, [operation || m, a], isSpaced);
  9250. isSpaced = parserInput.isWhitespace(-1);
  9251. }
  9252. return operation || m;
  9253. }
  9254. },
  9255. conditions: function conditions() {
  9256. var a;
  9257. var b;
  9258. var index = parserInput.i;
  9259. var condition;
  9260. a = this.condition(true);
  9261. if (a) {
  9262. while (true) {
  9263. if (!parserInput.peek(/^,\s*(not\s*)?\(/) || !parserInput.$char(',')) {
  9264. break;
  9265. }
  9266. b = this.condition(true);
  9267. if (!b) {
  9268. break;
  9269. }
  9270. condition = new tree.Condition('or', condition || a, b, index);
  9271. }
  9272. return condition || a;
  9273. }
  9274. },
  9275. condition: function condition(needsParens) {
  9276. var result;
  9277. var logical;
  9278. var next;
  9279. function or() {
  9280. return parserInput.$str('or');
  9281. }
  9282. result = this.conditionAnd(needsParens);
  9283. if (!result) {
  9284. return;
  9285. }
  9286. logical = or();
  9287. if (logical) {
  9288. next = this.condition(needsParens);
  9289. if (next) {
  9290. result = new tree.Condition(logical, result, next);
  9291. } else {
  9292. return;
  9293. }
  9294. }
  9295. return result;
  9296. },
  9297. conditionAnd: function conditionAnd(needsParens) {
  9298. var result;
  9299. var logical;
  9300. var next;
  9301. var self = this;
  9302. function insideCondition() {
  9303. var cond = self.negatedCondition(needsParens) || self.parenthesisCondition(needsParens);
  9304. if (!cond && !needsParens) {
  9305. return self.atomicCondition(needsParens);
  9306. }
  9307. return cond;
  9308. }
  9309. function and() {
  9310. return parserInput.$str('and');
  9311. }
  9312. result = insideCondition();
  9313. if (!result) {
  9314. return;
  9315. }
  9316. logical = and();
  9317. if (logical) {
  9318. next = this.conditionAnd(needsParens);
  9319. if (next) {
  9320. result = new tree.Condition(logical, result, next);
  9321. } else {
  9322. return;
  9323. }
  9324. }
  9325. return result;
  9326. },
  9327. negatedCondition: function negatedCondition(needsParens) {
  9328. if (parserInput.$str('not')) {
  9329. var result = this.parenthesisCondition(needsParens);
  9330. if (result) {
  9331. result.negate = !result.negate;
  9332. }
  9333. return result;
  9334. }
  9335. },
  9336. parenthesisCondition: function parenthesisCondition(needsParens) {
  9337. function tryConditionFollowedByParenthesis(me) {
  9338. var body;
  9339. parserInput.save();
  9340. body = me.condition(needsParens);
  9341. if (!body) {
  9342. parserInput.restore();
  9343. return;
  9344. }
  9345. if (!parserInput.$char(')')) {
  9346. parserInput.restore();
  9347. return;
  9348. }
  9349. parserInput.forget();
  9350. return body;
  9351. }
  9352. var body;
  9353. parserInput.save();
  9354. if (!parserInput.$str('(')) {
  9355. parserInput.restore();
  9356. return;
  9357. }
  9358. body = tryConditionFollowedByParenthesis(this);
  9359. if (body) {
  9360. parserInput.forget();
  9361. return body;
  9362. }
  9363. body = this.atomicCondition(needsParens);
  9364. if (!body) {
  9365. parserInput.restore();
  9366. return;
  9367. }
  9368. if (!parserInput.$char(')')) {
  9369. parserInput.restore("expected ')' got '".concat(parserInput.currentChar(), "'"));
  9370. return;
  9371. }
  9372. parserInput.forget();
  9373. return body;
  9374. },
  9375. atomicCondition: function atomicCondition(needsParens) {
  9376. var entities = this.entities;
  9377. var index = parserInput.i;
  9378. var a;
  9379. var b;
  9380. var c;
  9381. var op;
  9382. function cond() {
  9383. return this.addition() || entities.keyword() || entities.quoted() || entities.mixinLookup();
  9384. }
  9385. cond = cond.bind(this);
  9386. a = cond();
  9387. if (a) {
  9388. if (parserInput.$char('>')) {
  9389. if (parserInput.$char('=')) {
  9390. op = '>=';
  9391. } else {
  9392. op = '>';
  9393. }
  9394. } else if (parserInput.$char('<')) {
  9395. if (parserInput.$char('=')) {
  9396. op = '<=';
  9397. } else {
  9398. op = '<';
  9399. }
  9400. } else if (parserInput.$char('=')) {
  9401. if (parserInput.$char('>')) {
  9402. op = '=>';
  9403. } else if (parserInput.$char('<')) {
  9404. op = '=<';
  9405. } else {
  9406. op = '=';
  9407. }
  9408. }
  9409. if (op) {
  9410. b = cond();
  9411. if (b) {
  9412. c = new tree.Condition(op, a, b, index, false);
  9413. } else {
  9414. error('expected expression');
  9415. }
  9416. } else {
  9417. c = new tree.Condition('=', a, new tree.Keyword('true'), index, false);
  9418. }
  9419. return c;
  9420. }
  9421. },
  9422. //
  9423. // An operand is anything that can be part of an operation,
  9424. // such as a Color, or a Variable
  9425. //
  9426. operand: function operand() {
  9427. var entities = this.entities;
  9428. var negate;
  9429. if (parserInput.peek(/^-[@\$\(]/)) {
  9430. negate = parserInput.$char('-');
  9431. }
  9432. var o = this.sub() || entities.dimension() || entities.color() || entities.variable() || entities.property() || entities.call() || entities.quoted(true) || entities.colorKeyword() || entities.mixinLookup();
  9433. if (negate) {
  9434. o.parensInOp = true;
  9435. o = new tree.Negative(o);
  9436. }
  9437. return o;
  9438. },
  9439. //
  9440. // Expressions either represent mathematical operations,
  9441. // or white-space delimited Entities.
  9442. //
  9443. // 1px solid black
  9444. // @var * 2
  9445. //
  9446. expression: function expression() {
  9447. var entities = [];
  9448. var e;
  9449. var delim;
  9450. var index = parserInput.i;
  9451. do {
  9452. e = this.comment();
  9453. if (e) {
  9454. entities.push(e);
  9455. continue;
  9456. }
  9457. e = this.addition() || this.entity();
  9458. if (e) {
  9459. entities.push(e); // operations do not allow keyword "/" dimension (e.g. small/20px) so we support that here
  9460. if (!parserInput.peek(/^\/[\/*]/)) {
  9461. delim = parserInput.$char('/');
  9462. if (delim) {
  9463. entities.push(new tree.Anonymous(delim, index));
  9464. }
  9465. }
  9466. }
  9467. } while (e);
  9468. if (entities.length > 0) {
  9469. return new tree.Expression(entities);
  9470. }
  9471. },
  9472. property: function property() {
  9473. var name = parserInput.$re(/^(\*?-?[_a-zA-Z0-9-]+)\s*:/);
  9474. if (name) {
  9475. return name[1];
  9476. }
  9477. },
  9478. ruleProperty: function ruleProperty() {
  9479. var name = [];
  9480. var index = [];
  9481. var s;
  9482. var k;
  9483. parserInput.save();
  9484. var simpleProperty = parserInput.$re(/^([_a-zA-Z0-9-]+)\s*:/);
  9485. if (simpleProperty) {
  9486. name = [new tree.Keyword(simpleProperty[1])];
  9487. parserInput.forget();
  9488. return name;
  9489. }
  9490. function match(re) {
  9491. var i = parserInput.i;
  9492. var chunk = parserInput.$re(re);
  9493. if (chunk) {
  9494. index.push(i);
  9495. return name.push(chunk[1]);
  9496. }
  9497. }
  9498. match(/^(\*?)/);
  9499. while (true) {
  9500. if (!match(/^((?:[\w-]+)|(?:[@\$]\{[\w-]+\}))/)) {
  9501. break;
  9502. }
  9503. }
  9504. if (name.length > 1 && match(/^((?:\+_|\+)?)\s*:/)) {
  9505. parserInput.forget(); // at last, we have the complete match now. move forward,
  9506. // convert name particles to tree objects and return:
  9507. if (name[0] === '') {
  9508. name.shift();
  9509. index.shift();
  9510. }
  9511. for (k = 0; k < name.length; k++) {
  9512. s = name[k];
  9513. name[k] = s.charAt(0) !== '@' && s.charAt(0) !== '$' ? new tree.Keyword(s) : s.charAt(0) === '@' ? new tree.Variable("@".concat(s.slice(2, -1)), index[k], fileInfo) : new tree.Property("$".concat(s.slice(2, -1)), index[k], fileInfo);
  9514. }
  9515. return name;
  9516. }
  9517. parserInput.restore();
  9518. }
  9519. }
  9520. };
  9521. };
  9522. Parser.serializeVars = function (vars) {
  9523. var s = '';
  9524. for (var name in vars) {
  9525. if (Object.hasOwnProperty.call(vars, name)) {
  9526. var value = vars[name];
  9527. s += "".concat((name[0] === '@' ? '' : '@') + name, ": ").concat(value).concat(String(value).slice(-1) === ';' ? '' : ';');
  9528. }
  9529. }
  9530. return s;
  9531. };
  9532. function boolean(condition) {
  9533. return condition ? Keyword.True : Keyword.False;
  9534. }
  9535. function If(condition, trueValue, falseValue) {
  9536. return condition ? trueValue : falseValue || new Anonymous();
  9537. }
  9538. var boolean$1 = {
  9539. boolean: boolean,
  9540. 'if': If
  9541. };
  9542. var colorFunctions;
  9543. function clamp$1(val) {
  9544. return Math.min(1, Math.max(0, val));
  9545. }
  9546. function hsla(origColor, hsl) {
  9547. var color = colorFunctions.hsla(hsl.h, hsl.s, hsl.l, hsl.a);
  9548. if (color) {
  9549. if (origColor.value && /^(rgb|hsl)/.test(origColor.value)) {
  9550. color.value = origColor.value;
  9551. } else {
  9552. color.value = 'rgb';
  9553. }
  9554. return color;
  9555. }
  9556. }
  9557. function toHSL(color) {
  9558. if (color.toHSL) {
  9559. return color.toHSL();
  9560. } else {
  9561. throw new Error('Argument cannot be evaluated to a color');
  9562. }
  9563. }
  9564. function toHSV(color) {
  9565. if (color.toHSV) {
  9566. return color.toHSV();
  9567. } else {
  9568. throw new Error('Argument cannot be evaluated to a color');
  9569. }
  9570. }
  9571. function number(n) {
  9572. if (n instanceof Dimension) {
  9573. return parseFloat(n.unit.is('%') ? n.value / 100 : n.value);
  9574. } else if (typeof n === 'number') {
  9575. return n;
  9576. } else {
  9577. throw {
  9578. type: 'Argument',
  9579. message: 'color functions take numbers as parameters'
  9580. };
  9581. }
  9582. }
  9583. function scaled(n, size) {
  9584. if (n instanceof Dimension && n.unit.is('%')) {
  9585. return parseFloat(n.value * size / 100);
  9586. } else {
  9587. return number(n);
  9588. }
  9589. }
  9590. colorFunctions = {
  9591. rgb: function rgb(r, g, b) {
  9592. var color = colorFunctions.rgba(r, g, b, 1.0);
  9593. if (color) {
  9594. color.value = 'rgb';
  9595. return color;
  9596. }
  9597. },
  9598. rgba: function rgba(r, g, b, a) {
  9599. try {
  9600. if (r instanceof Color) {
  9601. if (g) {
  9602. a = number(g);
  9603. } else {
  9604. a = r.alpha;
  9605. }
  9606. return new Color(r.rgb, a, 'rgba');
  9607. }
  9608. var rgb = [r, g, b].map(function (c) {
  9609. return scaled(c, 255);
  9610. });
  9611. a = number(a);
  9612. return new Color(rgb, a, 'rgba');
  9613. } catch (e) {}
  9614. },
  9615. hsl: function hsl(h, s, l) {
  9616. var color = colorFunctions.hsla(h, s, l, 1.0);
  9617. if (color) {
  9618. color.value = 'hsl';
  9619. return color;
  9620. }
  9621. },
  9622. hsla: function hsla(h, s, l, a) {
  9623. try {
  9624. var hue = function hue(h) {
  9625. h = h < 0 ? h + 1 : h > 1 ? h - 1 : h;
  9626. if (h * 6 < 1) {
  9627. return m1 + (m2 - m1) * h * 6;
  9628. } else if (h * 2 < 1) {
  9629. return m2;
  9630. } else if (h * 3 < 2) {
  9631. return m1 + (m2 - m1) * (2 / 3 - h) * 6;
  9632. } else {
  9633. return m1;
  9634. }
  9635. };
  9636. if (h instanceof Color) {
  9637. if (s) {
  9638. a = number(s);
  9639. } else {
  9640. a = h.alpha;
  9641. }
  9642. return new Color(h.rgb, a, 'hsla');
  9643. }
  9644. var m1;
  9645. var m2;
  9646. h = number(h) % 360 / 360;
  9647. s = clamp$1(number(s));
  9648. l = clamp$1(number(l));
  9649. a = clamp$1(number(a));
  9650. m2 = l <= 0.5 ? l * (s + 1) : l + s - l * s;
  9651. m1 = l * 2 - m2;
  9652. var rgb = [hue(h + 1 / 3) * 255, hue(h) * 255, hue(h - 1 / 3) * 255];
  9653. a = number(a);
  9654. return new Color(rgb, a, 'hsla');
  9655. } catch (e) {}
  9656. },
  9657. hsv: function hsv(h, s, v) {
  9658. return colorFunctions.hsva(h, s, v, 1.0);
  9659. },
  9660. hsva: function hsva(h, s, v, a) {
  9661. h = number(h) % 360 / 360 * 360;
  9662. s = number(s);
  9663. v = number(v);
  9664. a = number(a);
  9665. var i;
  9666. var f;
  9667. i = Math.floor(h / 60 % 6);
  9668. f = h / 60 - i;
  9669. var vs = [v, v * (1 - s), v * (1 - f * s), v * (1 - (1 - f) * s)];
  9670. var perm = [[0, 3, 1], [2, 0, 1], [1, 0, 3], [1, 2, 0], [3, 1, 0], [0, 1, 2]];
  9671. return colorFunctions.rgba(vs[perm[i][0]] * 255, vs[perm[i][1]] * 255, vs[perm[i][2]] * 255, a);
  9672. },
  9673. hue: function hue(color) {
  9674. return new Dimension(toHSL(color).h);
  9675. },
  9676. saturation: function saturation(color) {
  9677. return new Dimension(toHSL(color).s * 100, '%');
  9678. },
  9679. lightness: function lightness(color) {
  9680. return new Dimension(toHSL(color).l * 100, '%');
  9681. },
  9682. hsvhue: function hsvhue(color) {
  9683. return new Dimension(toHSV(color).h);
  9684. },
  9685. hsvsaturation: function hsvsaturation(color) {
  9686. return new Dimension(toHSV(color).s * 100, '%');
  9687. },
  9688. hsvvalue: function hsvvalue(color) {
  9689. return new Dimension(toHSV(color).v * 100, '%');
  9690. },
  9691. red: function red(color) {
  9692. return new Dimension(color.rgb[0]);
  9693. },
  9694. green: function green(color) {
  9695. return new Dimension(color.rgb[1]);
  9696. },
  9697. blue: function blue(color) {
  9698. return new Dimension(color.rgb[2]);
  9699. },
  9700. alpha: function alpha(color) {
  9701. return new Dimension(toHSL(color).a);
  9702. },
  9703. luma: function luma(color) {
  9704. return new Dimension(color.luma() * color.alpha * 100, '%');
  9705. },
  9706. luminance: function luminance(color) {
  9707. var luminance = 0.2126 * color.rgb[0] / 255 + 0.7152 * color.rgb[1] / 255 + 0.0722 * color.rgb[2] / 255;
  9708. return new Dimension(luminance * color.alpha * 100, '%');
  9709. },
  9710. saturate: function saturate(color, amount, method) {
  9711. // filter: saturate(3.2);
  9712. // should be kept as is, so check for color
  9713. if (!color.rgb) {
  9714. return null;
  9715. }
  9716. var hsl = toHSL(color);
  9717. if (typeof method !== 'undefined' && method.value === 'relative') {
  9718. hsl.s += hsl.s * amount.value / 100;
  9719. } else {
  9720. hsl.s += amount.value / 100;
  9721. }
  9722. hsl.s = clamp$1(hsl.s);
  9723. return hsla(color, hsl);
  9724. },
  9725. desaturate: function desaturate(color, amount, method) {
  9726. var hsl = toHSL(color);
  9727. if (typeof method !== 'undefined' && method.value === 'relative') {
  9728. hsl.s -= hsl.s * amount.value / 100;
  9729. } else {
  9730. hsl.s -= amount.value / 100;
  9731. }
  9732. hsl.s = clamp$1(hsl.s);
  9733. return hsla(color, hsl);
  9734. },
  9735. lighten: function lighten(color, amount, method) {
  9736. var hsl = toHSL(color);
  9737. if (typeof method !== 'undefined' && method.value === 'relative') {
  9738. hsl.l += hsl.l * amount.value / 100;
  9739. } else {
  9740. hsl.l += amount.value / 100;
  9741. }
  9742. hsl.l = clamp$1(hsl.l);
  9743. return hsla(color, hsl);
  9744. },
  9745. darken: function darken(color, amount, method) {
  9746. var hsl = toHSL(color);
  9747. if (typeof method !== 'undefined' && method.value === 'relative') {
  9748. hsl.l -= hsl.l * amount.value / 100;
  9749. } else {
  9750. hsl.l -= amount.value / 100;
  9751. }
  9752. hsl.l = clamp$1(hsl.l);
  9753. return hsla(color, hsl);
  9754. },
  9755. fadein: function fadein(color, amount, method) {
  9756. var hsl = toHSL(color);
  9757. if (typeof method !== 'undefined' && method.value === 'relative') {
  9758. hsl.a += hsl.a * amount.value / 100;
  9759. } else {
  9760. hsl.a += amount.value / 100;
  9761. }
  9762. hsl.a = clamp$1(hsl.a);
  9763. return hsla(color, hsl);
  9764. },
  9765. fadeout: function fadeout(color, amount, method) {
  9766. var hsl = toHSL(color);
  9767. if (typeof method !== 'undefined' && method.value === 'relative') {
  9768. hsl.a -= hsl.a * amount.value / 100;
  9769. } else {
  9770. hsl.a -= amount.value / 100;
  9771. }
  9772. hsl.a = clamp$1(hsl.a);
  9773. return hsla(color, hsl);
  9774. },
  9775. fade: function fade(color, amount) {
  9776. var hsl = toHSL(color);
  9777. hsl.a = amount.value / 100;
  9778. hsl.a = clamp$1(hsl.a);
  9779. return hsla(color, hsl);
  9780. },
  9781. spin: function spin(color, amount) {
  9782. var hsl = toHSL(color);
  9783. var hue = (hsl.h + amount.value) % 360;
  9784. hsl.h = hue < 0 ? 360 + hue : hue;
  9785. return hsla(color, hsl);
  9786. },
  9787. //
  9788. // Copyright (c) 2006-2009 Hampton Catlin, Natalie Weizenbaum, and Chris Eppstein
  9789. // http://sass-lang.com
  9790. //
  9791. mix: function mix(color1, color2, weight) {
  9792. if (!weight) {
  9793. weight = new Dimension(50);
  9794. }
  9795. var p = weight.value / 100.0;
  9796. var w = p * 2 - 1;
  9797. var a = toHSL(color1).a - toHSL(color2).a;
  9798. var w1 = ((w * a == -1 ? w : (w + a) / (1 + w * a)) + 1) / 2.0;
  9799. var w2 = 1 - w1;
  9800. var rgb = [color1.rgb[0] * w1 + color2.rgb[0] * w2, color1.rgb[1] * w1 + color2.rgb[1] * w2, color1.rgb[2] * w1 + color2.rgb[2] * w2];
  9801. var alpha = color1.alpha * p + color2.alpha * (1 - p);
  9802. return new Color(rgb, alpha);
  9803. },
  9804. greyscale: function greyscale(color) {
  9805. return colorFunctions.desaturate(color, new Dimension(100));
  9806. },
  9807. contrast: function contrast(color, dark, light, threshold) {
  9808. // filter: contrast(3.2);
  9809. // should be kept as is, so check for color
  9810. if (!color.rgb) {
  9811. return null;
  9812. }
  9813. if (typeof light === 'undefined') {
  9814. light = colorFunctions.rgba(255, 255, 255, 1.0);
  9815. }
  9816. if (typeof dark === 'undefined') {
  9817. dark = colorFunctions.rgba(0, 0, 0, 1.0);
  9818. } // Figure out which is actually light and dark:
  9819. if (dark.luma() > light.luma()) {
  9820. var t = light;
  9821. light = dark;
  9822. dark = t;
  9823. }
  9824. if (typeof threshold === 'undefined') {
  9825. threshold = 0.43;
  9826. } else {
  9827. threshold = number(threshold);
  9828. }
  9829. if (color.luma() < threshold) {
  9830. return light;
  9831. } else {
  9832. return dark;
  9833. }
  9834. },
  9835. // Changes made in 2.7.0 - Reverted in 3.0.0
  9836. // contrast: function (color, color1, color2, threshold) {
  9837. // // Return which of `color1` and `color2` has the greatest contrast with `color`
  9838. // // according to the standard WCAG contrast ratio calculation.
  9839. // // http://www.w3.org/TR/WCAG20/#contrast-ratiodef
  9840. // // The threshold param is no longer used, in line with SASS.
  9841. // // filter: contrast(3.2);
  9842. // // should be kept as is, so check for color
  9843. // if (!color.rgb) {
  9844. // return null;
  9845. // }
  9846. // if (typeof color1 === 'undefined') {
  9847. // color1 = colorFunctions.rgba(0, 0, 0, 1.0);
  9848. // }
  9849. // if (typeof color2 === 'undefined') {
  9850. // color2 = colorFunctions.rgba(255, 255, 255, 1.0);
  9851. // }
  9852. // var contrast1, contrast2;
  9853. // var luma = color.luma();
  9854. // var luma1 = color1.luma();
  9855. // var luma2 = color2.luma();
  9856. // // Calculate contrast ratios for each color
  9857. // if (luma > luma1) {
  9858. // contrast1 = (luma + 0.05) / (luma1 + 0.05);
  9859. // } else {
  9860. // contrast1 = (luma1 + 0.05) / (luma + 0.05);
  9861. // }
  9862. // if (luma > luma2) {
  9863. // contrast2 = (luma + 0.05) / (luma2 + 0.05);
  9864. // } else {
  9865. // contrast2 = (luma2 + 0.05) / (luma + 0.05);
  9866. // }
  9867. // if (contrast1 > contrast2) {
  9868. // return color1;
  9869. // } else {
  9870. // return color2;
  9871. // }
  9872. // },
  9873. argb: function argb(color) {
  9874. return new Anonymous(color.toARGB());
  9875. },
  9876. color: function color(c) {
  9877. if (c instanceof Quoted && /^#([A-Fa-f0-9]{8}|[A-Fa-f0-9]{6}|[A-Fa-f0-9]{3,4})$/i.test(c.value)) {
  9878. var val = c.value.slice(1);
  9879. return new Color(val, undefined, "#".concat(val));
  9880. }
  9881. if (c instanceof Color || (c = Color.fromKeyword(c.value))) {
  9882. c.value = undefined;
  9883. return c;
  9884. }
  9885. throw {
  9886. type: 'Argument',
  9887. message: 'argument must be a color keyword or 3|4|6|8 digit hex e.g. #FFF'
  9888. };
  9889. },
  9890. tint: function tint(color, amount) {
  9891. return colorFunctions.mix(colorFunctions.rgb(255, 255, 255), color, amount);
  9892. },
  9893. shade: function shade(color, amount) {
  9894. return colorFunctions.mix(colorFunctions.rgb(0, 0, 0), color, amount);
  9895. }
  9896. };
  9897. var color = colorFunctions;
  9898. // ref: http://www.w3.org/TR/compositing-1
  9899. function colorBlend(mode, color1, color2) {
  9900. var ab = color1.alpha; // result
  9901. var // backdrop
  9902. cb;
  9903. var as = color2.alpha;
  9904. var // source
  9905. cs;
  9906. var ar;
  9907. var cr;
  9908. var r = [];
  9909. ar = as + ab * (1 - as);
  9910. for (var i = 0; i < 3; i++) {
  9911. cb = color1.rgb[i] / 255;
  9912. cs = color2.rgb[i] / 255;
  9913. cr = mode(cb, cs);
  9914. if (ar) {
  9915. cr = (as * cs + ab * (cb - as * (cb + cs - cr))) / ar;
  9916. }
  9917. r[i] = cr * 255;
  9918. }
  9919. return new Color(r, ar);
  9920. }
  9921. var colorBlendModeFunctions = {
  9922. multiply: function multiply(cb, cs) {
  9923. return cb * cs;
  9924. },
  9925. screen: function screen(cb, cs) {
  9926. return cb + cs - cb * cs;
  9927. },
  9928. overlay: function overlay(cb, cs) {
  9929. cb *= 2;
  9930. return cb <= 1 ? colorBlendModeFunctions.multiply(cb, cs) : colorBlendModeFunctions.screen(cb - 1, cs);
  9931. },
  9932. softlight: function softlight(cb, cs) {
  9933. var d = 1;
  9934. var e = cb;
  9935. if (cs > 0.5) {
  9936. e = 1;
  9937. d = cb > 0.25 ? Math.sqrt(cb) : ((16 * cb - 12) * cb + 4) * cb;
  9938. }
  9939. return cb - (1 - 2 * cs) * e * (d - cb);
  9940. },
  9941. hardlight: function hardlight(cb, cs) {
  9942. return colorBlendModeFunctions.overlay(cs, cb);
  9943. },
  9944. difference: function difference(cb, cs) {
  9945. return Math.abs(cb - cs);
  9946. },
  9947. exclusion: function exclusion(cb, cs) {
  9948. return cb + cs - 2 * cb * cs;
  9949. },
  9950. // non-w3c functions:
  9951. average: function average(cb, cs) {
  9952. return (cb + cs) / 2;
  9953. },
  9954. negation: function negation(cb, cs) {
  9955. return 1 - Math.abs(cb + cs - 1);
  9956. }
  9957. };
  9958. for (var f in colorBlendModeFunctions) {
  9959. if (colorBlendModeFunctions.hasOwnProperty(f)) {
  9960. colorBlend[f] = colorBlend.bind(null, colorBlendModeFunctions[f]);
  9961. }
  9962. }
  9963. var dataUri = (function (environment) {
  9964. var fallback = function fallback(functionThis, node) {
  9965. return new URL(node, functionThis.index, functionThis.currentFileInfo).eval(functionThis.context);
  9966. };
  9967. return {
  9968. 'data-uri': function dataUri(mimetypeNode, filePathNode) {
  9969. if (!filePathNode) {
  9970. filePathNode = mimetypeNode;
  9971. mimetypeNode = null;
  9972. }
  9973. var mimetype = mimetypeNode && mimetypeNode.value;
  9974. var filePath = filePathNode.value;
  9975. var currentFileInfo = this.currentFileInfo;
  9976. var currentDirectory = currentFileInfo.rewriteUrls ? currentFileInfo.currentDirectory : currentFileInfo.entryPath;
  9977. var fragmentStart = filePath.indexOf('#');
  9978. var fragment = '';
  9979. if (fragmentStart !== -1) {
  9980. fragment = filePath.slice(fragmentStart);
  9981. filePath = filePath.slice(0, fragmentStart);
  9982. }
  9983. var context = clone(this.context);
  9984. context.rawBuffer = true;
  9985. var fileManager = environment.getFileManager(filePath, currentDirectory, context, environment, true);
  9986. if (!fileManager) {
  9987. return fallback(this, filePathNode);
  9988. }
  9989. var useBase64 = false; // detect the mimetype if not given
  9990. if (!mimetypeNode) {
  9991. mimetype = environment.mimeLookup(filePath);
  9992. if (mimetype === 'image/svg+xml') {
  9993. useBase64 = false;
  9994. } else {
  9995. // use base 64 unless it's an ASCII or UTF-8 format
  9996. var charset = environment.charsetLookup(mimetype);
  9997. useBase64 = ['US-ASCII', 'UTF-8'].indexOf(charset) < 0;
  9998. }
  9999. if (useBase64) {
  10000. mimetype += ';base64';
  10001. }
  10002. } else {
  10003. useBase64 = /;base64$/.test(mimetype);
  10004. }
  10005. var fileSync = fileManager.loadFileSync(filePath, currentDirectory, context, environment);
  10006. if (!fileSync.contents) {
  10007. logger.warn("Skipped data-uri embedding of ".concat(filePath, " because file not found"));
  10008. return fallback(this, filePathNode || mimetypeNode);
  10009. }
  10010. var buf = fileSync.contents;
  10011. if (useBase64 && !environment.encodeBase64) {
  10012. return fallback(this, filePathNode);
  10013. }
  10014. buf = useBase64 ? environment.encodeBase64(buf) : encodeURIComponent(buf);
  10015. var uri = "data:".concat(mimetype, ",").concat(buf).concat(fragment);
  10016. return new URL(new Quoted("\"".concat(uri, "\""), uri, false, this.index, this.currentFileInfo), this.index, this.currentFileInfo);
  10017. }
  10018. };
  10019. });
  10020. var getItemsFromNode = function getItemsFromNode(node) {
  10021. // handle non-array values as an array of length 1
  10022. // return 'undefined' if index is invalid
  10023. var items = Array.isArray(node.value) ? node.value : Array(node);
  10024. return items;
  10025. };
  10026. var list = {
  10027. _SELF: function _SELF(n) {
  10028. return n;
  10029. },
  10030. extract: function extract(values, index) {
  10031. // (1-based index)
  10032. index = index.value - 1;
  10033. return getItemsFromNode(values)[index];
  10034. },
  10035. length: function length(values) {
  10036. return new Dimension(getItemsFromNode(values).length);
  10037. },
  10038. /**
  10039. * Creates a Less list of incremental values.
  10040. * Modeled after Lodash's range function, also exists natively in PHP
  10041. *
  10042. * @param {Dimension} [start=1]
  10043. * @param {Dimension} end - e.g. 10 or 10px - unit is added to output
  10044. * @param {Dimension} [step=1]
  10045. */
  10046. range: function range(start, end, step) {
  10047. var from;
  10048. var to;
  10049. var stepValue = 1;
  10050. var list = [];
  10051. if (end) {
  10052. to = end;
  10053. from = start.value;
  10054. if (step) {
  10055. stepValue = step.value;
  10056. }
  10057. } else {
  10058. from = 1;
  10059. to = start;
  10060. }
  10061. for (var i = from; i <= to.value; i += stepValue) {
  10062. list.push(new Dimension(i, to.unit));
  10063. }
  10064. return new Expression(list);
  10065. },
  10066. each: function each(list, rs) {
  10067. var rules = [];
  10068. var newRules;
  10069. var iterator;
  10070. if (list.value && !(list instanceof Quoted)) {
  10071. if (Array.isArray(list.value)) {
  10072. iterator = list.value;
  10073. } else {
  10074. iterator = [list.value];
  10075. }
  10076. } else if (list.ruleset) {
  10077. iterator = list.ruleset.rules;
  10078. } else if (list.rules) {
  10079. iterator = list.rules;
  10080. } else if (Array.isArray(list)) {
  10081. iterator = list;
  10082. } else {
  10083. iterator = [list];
  10084. }
  10085. var valueName = '@value';
  10086. var keyName = '@key';
  10087. var indexName = '@index';
  10088. if (rs.params) {
  10089. valueName = rs.params[0] && rs.params[0].name;
  10090. keyName = rs.params[1] && rs.params[1].name;
  10091. indexName = rs.params[2] && rs.params[2].name;
  10092. rs = rs.rules;
  10093. } else {
  10094. rs = rs.ruleset;
  10095. }
  10096. for (var i = 0; i < iterator.length; i++) {
  10097. var key = void 0;
  10098. var value = void 0;
  10099. var item = iterator[i];
  10100. if (item instanceof Declaration) {
  10101. key = typeof item.name === 'string' ? item.name : item.name[0].value;
  10102. value = item.value;
  10103. } else {
  10104. key = new Dimension(i + 1);
  10105. value = item;
  10106. }
  10107. if (item instanceof Comment) {
  10108. continue;
  10109. }
  10110. newRules = rs.rules.slice(0);
  10111. if (valueName) {
  10112. newRules.push(new Declaration(valueName, value, false, false, this.index, this.currentFileInfo));
  10113. }
  10114. if (indexName) {
  10115. newRules.push(new Declaration(indexName, new Dimension(i + 1), false, false, this.index, this.currentFileInfo));
  10116. }
  10117. if (keyName) {
  10118. newRules.push(new Declaration(keyName, key, false, false, this.index, this.currentFileInfo));
  10119. }
  10120. rules.push(new Ruleset([new Selector([new Element("", '&')])], newRules, rs.strictImports, rs.visibilityInfo()));
  10121. }
  10122. return new Ruleset([new Selector([new Element("", '&')])], rules, rs.strictImports, rs.visibilityInfo()).eval(this.context);
  10123. }
  10124. };
  10125. var MathHelper = function MathHelper(fn, unit, n) {
  10126. if (!(n instanceof Dimension)) {
  10127. throw {
  10128. type: 'Argument',
  10129. message: 'argument must be a number'
  10130. };
  10131. }
  10132. if (unit == null) {
  10133. unit = n.unit;
  10134. } else {
  10135. n = n.unify();
  10136. }
  10137. return new Dimension(fn(parseFloat(n.value)), unit);
  10138. };
  10139. var mathFunctions = {
  10140. // name, unit
  10141. ceil: null,
  10142. floor: null,
  10143. sqrt: null,
  10144. abs: null,
  10145. tan: '',
  10146. sin: '',
  10147. cos: '',
  10148. atan: 'rad',
  10149. asin: 'rad',
  10150. acos: 'rad'
  10151. };
  10152. for (var f$1 in mathFunctions) {
  10153. if (mathFunctions.hasOwnProperty(f$1)) {
  10154. mathFunctions[f$1] = MathHelper.bind(null, Math[f$1], mathFunctions[f$1]);
  10155. }
  10156. }
  10157. mathFunctions.round = function (n, f) {
  10158. var fraction = typeof f === 'undefined' ? 0 : f.value;
  10159. return MathHelper(function (num) {
  10160. return num.toFixed(fraction);
  10161. }, null, n);
  10162. };
  10163. var minMax = function minMax(isMin, args) {
  10164. args = Array.prototype.slice.call(args);
  10165. switch (args.length) {
  10166. case 0:
  10167. throw {
  10168. type: 'Argument',
  10169. message: 'one or more arguments required'
  10170. };
  10171. }
  10172. var i; // key is the unit.toString() for unified Dimension values,
  10173. var j;
  10174. var current;
  10175. var currentUnified;
  10176. var referenceUnified;
  10177. var unit;
  10178. var unitStatic;
  10179. var unitClone;
  10180. var // elems only contains original argument values.
  10181. order = [];
  10182. var values = {}; // value is the index into the order array.
  10183. for (i = 0; i < args.length; i++) {
  10184. current = args[i];
  10185. if (!(current instanceof Dimension)) {
  10186. if (Array.isArray(args[i].value)) {
  10187. Array.prototype.push.apply(args, Array.prototype.slice.call(args[i].value));
  10188. }
  10189. continue;
  10190. }
  10191. currentUnified = current.unit.toString() === '' && unitClone !== undefined ? new Dimension(current.value, unitClone).unify() : current.unify();
  10192. unit = currentUnified.unit.toString() === '' && unitStatic !== undefined ? unitStatic : currentUnified.unit.toString();
  10193. unitStatic = unit !== '' && unitStatic === undefined || unit !== '' && order[0].unify().unit.toString() === '' ? unit : unitStatic;
  10194. unitClone = unit !== '' && unitClone === undefined ? current.unit.toString() : unitClone;
  10195. j = values[''] !== undefined && unit !== '' && unit === unitStatic ? values[''] : values[unit];
  10196. if (j === undefined) {
  10197. if (unitStatic !== undefined && unit !== unitStatic) {
  10198. throw {
  10199. type: 'Argument',
  10200. message: 'incompatible types'
  10201. };
  10202. }
  10203. values[unit] = order.length;
  10204. order.push(current);
  10205. continue;
  10206. }
  10207. referenceUnified = order[j].unit.toString() === '' && unitClone !== undefined ? new Dimension(order[j].value, unitClone).unify() : order[j].unify();
  10208. if (isMin && currentUnified.value < referenceUnified.value || !isMin && currentUnified.value > referenceUnified.value) {
  10209. order[j] = current;
  10210. }
  10211. }
  10212. if (order.length == 1) {
  10213. return order[0];
  10214. }
  10215. args = order.map(function (a) {
  10216. return a.toCSS(this.context);
  10217. }).join(this.context.compress ? ',' : ', ');
  10218. return new Anonymous("".concat(isMin ? 'min' : 'max', "(").concat(args, ")"));
  10219. };
  10220. var number$1 = {
  10221. min: function min() {
  10222. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  10223. args[_key] = arguments[_key];
  10224. }
  10225. return minMax(true, args);
  10226. },
  10227. max: function max() {
  10228. for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
  10229. args[_key2] = arguments[_key2];
  10230. }
  10231. return minMax(false, args);
  10232. },
  10233. convert: function convert(val, unit) {
  10234. return val.convertTo(unit.value);
  10235. },
  10236. pi: function pi() {
  10237. return new Dimension(Math.PI);
  10238. },
  10239. mod: function mod(a, b) {
  10240. return new Dimension(a.value % b.value, a.unit);
  10241. },
  10242. pow: function pow(x, y) {
  10243. if (typeof x === 'number' && typeof y === 'number') {
  10244. x = new Dimension(x);
  10245. y = new Dimension(y);
  10246. } else if (!(x instanceof Dimension) || !(y instanceof Dimension)) {
  10247. throw {
  10248. type: 'Argument',
  10249. message: 'arguments must be numbers'
  10250. };
  10251. }
  10252. return new Dimension(Math.pow(x.value, y.value), x.unit);
  10253. },
  10254. percentage: function percentage(n) {
  10255. var result = MathHelper(function (num) {
  10256. return num * 100;
  10257. }, '%', n);
  10258. return result;
  10259. }
  10260. };
  10261. var string = {
  10262. e: function e(str) {
  10263. return new Quoted('"', str instanceof JavaScript ? str.evaluated : str.value, true);
  10264. },
  10265. escape: function escape(str) {
  10266. return new Anonymous(encodeURI(str.value).replace(/=/g, '%3D').replace(/:/g, '%3A').replace(/#/g, '%23').replace(/;/g, '%3B').replace(/\(/g, '%28').replace(/\)/g, '%29'));
  10267. },
  10268. replace: function replace(string, pattern, replacement, flags) {
  10269. var result = string.value;
  10270. replacement = replacement.type === 'Quoted' ? replacement.value : replacement.toCSS();
  10271. result = result.replace(new RegExp(pattern.value, flags ? flags.value : ''), replacement);
  10272. return new Quoted(string.quote || '', result, string.escaped);
  10273. },
  10274. '%': function _(string
  10275. /* arg, arg, ... */
  10276. ) {
  10277. var args = Array.prototype.slice.call(arguments, 1);
  10278. var result = string.value;
  10279. var _loop = function _loop(i) {
  10280. /* jshint loopfunc:true */
  10281. result = result.replace(/%[sda]/i, function (token) {
  10282. var value = args[i].type === 'Quoted' && token.match(/s/i) ? args[i].value : args[i].toCSS();
  10283. return token.match(/[A-Z]$/) ? encodeURIComponent(value) : value;
  10284. });
  10285. };
  10286. for (var i = 0; i < args.length; i++) {
  10287. _loop(i);
  10288. }
  10289. result = result.replace(/%%/g, '%');
  10290. return new Quoted(string.quote || '', result, string.escaped);
  10291. }
  10292. };
  10293. var svg = (function (environment) {
  10294. return {
  10295. 'svg-gradient': function svgGradient(direction) {
  10296. var stops;
  10297. var gradientDirectionSvg;
  10298. var gradientType = 'linear';
  10299. var rectangleDimension = 'x="0" y="0" width="1" height="1"';
  10300. var renderEnv = {
  10301. compress: false
  10302. };
  10303. var returner;
  10304. var directionValue = direction.toCSS(renderEnv);
  10305. var i;
  10306. var color;
  10307. var position;
  10308. var positionValue;
  10309. var alpha;
  10310. function throwArgumentDescriptor() {
  10311. throw {
  10312. type: 'Argument',
  10313. message: 'svg-gradient expects direction, start_color [start_position], [color position,]...,' + ' end_color [end_position] or direction, color list'
  10314. };
  10315. }
  10316. if (arguments.length == 2) {
  10317. if (arguments[1].value.length < 2) {
  10318. throwArgumentDescriptor();
  10319. }
  10320. stops = arguments[1].value;
  10321. } else if (arguments.length < 3) {
  10322. throwArgumentDescriptor();
  10323. } else {
  10324. stops = Array.prototype.slice.call(arguments, 1);
  10325. }
  10326. switch (directionValue) {
  10327. case 'to bottom':
  10328. gradientDirectionSvg = 'x1="0%" y1="0%" x2="0%" y2="100%"';
  10329. break;
  10330. case 'to right':
  10331. gradientDirectionSvg = 'x1="0%" y1="0%" x2="100%" y2="0%"';
  10332. break;
  10333. case 'to bottom right':
  10334. gradientDirectionSvg = 'x1="0%" y1="0%" x2="100%" y2="100%"';
  10335. break;
  10336. case 'to top right':
  10337. gradientDirectionSvg = 'x1="0%" y1="100%" x2="100%" y2="0%"';
  10338. break;
  10339. case 'ellipse':
  10340. case 'ellipse at center':
  10341. gradientType = 'radial';
  10342. gradientDirectionSvg = 'cx="50%" cy="50%" r="75%"';
  10343. rectangleDimension = 'x="-50" y="-50" width="101" height="101"';
  10344. break;
  10345. default:
  10346. throw {
  10347. type: 'Argument',
  10348. message: 'svg-gradient direction must be \'to bottom\', \'to right\',' + ' \'to bottom right\', \'to top right\' or \'ellipse at center\''
  10349. };
  10350. }
  10351. returner = "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 1 1\"><".concat(gradientType, "Gradient id=\"g\" ").concat(gradientDirectionSvg, ">");
  10352. for (i = 0; i < stops.length; i += 1) {
  10353. if (stops[i] instanceof Expression) {
  10354. color = stops[i].value[0];
  10355. position = stops[i].value[1];
  10356. } else {
  10357. color = stops[i];
  10358. position = undefined;
  10359. }
  10360. if (!(color instanceof Color) || !((i === 0 || i + 1 === stops.length) && position === undefined) && !(position instanceof Dimension)) {
  10361. throwArgumentDescriptor();
  10362. }
  10363. positionValue = position ? position.toCSS(renderEnv) : i === 0 ? '0%' : '100%';
  10364. alpha = color.alpha;
  10365. returner += "<stop offset=\"".concat(positionValue, "\" stop-color=\"").concat(color.toRGB(), "\"").concat(alpha < 1 ? " stop-opacity=\"".concat(alpha, "\"") : '', "/>");
  10366. }
  10367. returner += "</".concat(gradientType, "Gradient><rect ").concat(rectangleDimension, " fill=\"url(#g)\" /></svg>");
  10368. returner = encodeURIComponent(returner);
  10369. returner = "data:image/svg+xml,".concat(returner);
  10370. return new URL(new Quoted("'".concat(returner, "'"), returner, false, this.index, this.currentFileInfo), this.index, this.currentFileInfo);
  10371. }
  10372. };
  10373. });
  10374. var isa = function isa(n, Type) {
  10375. return n instanceof Type ? Keyword.True : Keyword.False;
  10376. };
  10377. var isunit = function isunit(n, unit) {
  10378. if (unit === undefined) {
  10379. throw {
  10380. type: 'Argument',
  10381. message: 'missing the required second argument to isunit.'
  10382. };
  10383. }
  10384. unit = typeof unit.value === 'string' ? unit.value : unit;
  10385. if (typeof unit !== 'string') {
  10386. throw {
  10387. type: 'Argument',
  10388. message: 'Second argument to isunit should be a unit or a string.'
  10389. };
  10390. }
  10391. return n instanceof Dimension && n.unit.is(unit) ? Keyword.True : Keyword.False;
  10392. };
  10393. var types = {
  10394. isruleset: function isruleset(n) {
  10395. return isa(n, DetachedRuleset);
  10396. },
  10397. iscolor: function iscolor(n) {
  10398. return isa(n, Color);
  10399. },
  10400. isnumber: function isnumber(n) {
  10401. return isa(n, Dimension);
  10402. },
  10403. isstring: function isstring(n) {
  10404. return isa(n, Quoted);
  10405. },
  10406. iskeyword: function iskeyword(n) {
  10407. return isa(n, Keyword);
  10408. },
  10409. isurl: function isurl(n) {
  10410. return isa(n, URL);
  10411. },
  10412. ispixel: function ispixel(n) {
  10413. return isunit(n, 'px');
  10414. },
  10415. ispercentage: function ispercentage(n) {
  10416. return isunit(n, '%');
  10417. },
  10418. isem: function isem(n) {
  10419. return isunit(n, 'em');
  10420. },
  10421. isunit: isunit,
  10422. unit: function unit(val, _unit) {
  10423. if (!(val instanceof Dimension)) {
  10424. throw {
  10425. type: 'Argument',
  10426. message: "the first argument to unit must be a number".concat(val instanceof Operation ? '. Have you forgotten parenthesis?' : '')
  10427. };
  10428. }
  10429. if (_unit) {
  10430. if (_unit instanceof Keyword) {
  10431. _unit = _unit.value;
  10432. } else {
  10433. _unit = _unit.toCSS();
  10434. }
  10435. } else {
  10436. _unit = '';
  10437. }
  10438. return new Dimension(val.value, _unit);
  10439. },
  10440. 'get-unit': function getUnit(n) {
  10441. return new Anonymous(n.unit);
  10442. }
  10443. };
  10444. var Functions = (function (environment) {
  10445. var functions = {
  10446. functionRegistry: functionRegistry,
  10447. functionCaller: functionCaller
  10448. }; // register functions
  10449. functionRegistry.addMultiple(boolean$1);
  10450. functionRegistry.add('default', defaultFunc.eval.bind(defaultFunc));
  10451. functionRegistry.addMultiple(color);
  10452. functionRegistry.addMultiple(colorBlend);
  10453. functionRegistry.addMultiple(dataUri(environment));
  10454. functionRegistry.addMultiple(list);
  10455. functionRegistry.addMultiple(mathFunctions);
  10456. functionRegistry.addMultiple(number$1);
  10457. functionRegistry.addMultiple(string);
  10458. functionRegistry.addMultiple(svg());
  10459. functionRegistry.addMultiple(types);
  10460. return functions;
  10461. });
  10462. var sourceMapOutput = (function (environment) {
  10463. var SourceMapOutput =
  10464. /*#__PURE__*/
  10465. function () {
  10466. function SourceMapOutput(options) {
  10467. _classCallCheck(this, SourceMapOutput);
  10468. this._css = [];
  10469. this._rootNode = options.rootNode;
  10470. this._contentsMap = options.contentsMap;
  10471. this._contentsIgnoredCharsMap = options.contentsIgnoredCharsMap;
  10472. if (options.sourceMapFilename) {
  10473. this._sourceMapFilename = options.sourceMapFilename.replace(/\\/g, '/');
  10474. }
  10475. this._outputFilename = options.outputFilename;
  10476. this.sourceMapURL = options.sourceMapURL;
  10477. if (options.sourceMapBasepath) {
  10478. this._sourceMapBasepath = options.sourceMapBasepath.replace(/\\/g, '/');
  10479. }
  10480. if (options.sourceMapRootpath) {
  10481. this._sourceMapRootpath = options.sourceMapRootpath.replace(/\\/g, '/');
  10482. if (this._sourceMapRootpath.charAt(this._sourceMapRootpath.length - 1) !== '/') {
  10483. this._sourceMapRootpath += '/';
  10484. }
  10485. } else {
  10486. this._sourceMapRootpath = '';
  10487. }
  10488. this._outputSourceFiles = options.outputSourceFiles;
  10489. this._sourceMapGeneratorConstructor = environment.getSourceMapGenerator();
  10490. this._lineNumber = 0;
  10491. this._column = 0;
  10492. }
  10493. _createClass(SourceMapOutput, [{
  10494. key: "removeBasepath",
  10495. value: function removeBasepath(path) {
  10496. if (this._sourceMapBasepath && path.indexOf(this._sourceMapBasepath) === 0) {
  10497. path = path.substring(this._sourceMapBasepath.length);
  10498. if (path.charAt(0) === '\\' || path.charAt(0) === '/') {
  10499. path = path.substring(1);
  10500. }
  10501. }
  10502. return path;
  10503. }
  10504. }, {
  10505. key: "normalizeFilename",
  10506. value: function normalizeFilename(filename) {
  10507. filename = filename.replace(/\\/g, '/');
  10508. filename = this.removeBasepath(filename);
  10509. return (this._sourceMapRootpath || '') + filename;
  10510. }
  10511. }, {
  10512. key: "add",
  10513. value: function add(chunk, fileInfo, index, mapLines) {
  10514. // ignore adding empty strings
  10515. if (!chunk) {
  10516. return;
  10517. }
  10518. var lines;
  10519. var sourceLines;
  10520. var columns;
  10521. var sourceColumns;
  10522. var i;
  10523. if (fileInfo && fileInfo.filename) {
  10524. var inputSource = this._contentsMap[fileInfo.filename]; // remove vars/banner added to the top of the file
  10525. if (this._contentsIgnoredCharsMap[fileInfo.filename]) {
  10526. // adjust the index
  10527. index -= this._contentsIgnoredCharsMap[fileInfo.filename];
  10528. if (index < 0) {
  10529. index = 0;
  10530. } // adjust the source
  10531. inputSource = inputSource.slice(this._contentsIgnoredCharsMap[fileInfo.filename]);
  10532. } // ignore empty content
  10533. if (inputSource === undefined) {
  10534. return;
  10535. }
  10536. inputSource = inputSource.substring(0, index);
  10537. sourceLines = inputSource.split('\n');
  10538. sourceColumns = sourceLines[sourceLines.length - 1];
  10539. }
  10540. lines = chunk.split('\n');
  10541. columns = lines[lines.length - 1];
  10542. if (fileInfo && fileInfo.filename) {
  10543. if (!mapLines) {
  10544. this._sourceMapGenerator.addMapping({
  10545. generated: {
  10546. line: this._lineNumber + 1,
  10547. column: this._column
  10548. },
  10549. original: {
  10550. line: sourceLines.length,
  10551. column: sourceColumns.length
  10552. },
  10553. source: this.normalizeFilename(fileInfo.filename)
  10554. });
  10555. } else {
  10556. for (i = 0; i < lines.length; i++) {
  10557. this._sourceMapGenerator.addMapping({
  10558. generated: {
  10559. line: this._lineNumber + i + 1,
  10560. column: i === 0 ? this._column : 0
  10561. },
  10562. original: {
  10563. line: sourceLines.length + i,
  10564. column: i === 0 ? sourceColumns.length : 0
  10565. },
  10566. source: this.normalizeFilename(fileInfo.filename)
  10567. });
  10568. }
  10569. }
  10570. }
  10571. if (lines.length === 1) {
  10572. this._column += columns.length;
  10573. } else {
  10574. this._lineNumber += lines.length - 1;
  10575. this._column = columns.length;
  10576. }
  10577. this._css.push(chunk);
  10578. }
  10579. }, {
  10580. key: "isEmpty",
  10581. value: function isEmpty() {
  10582. return this._css.length === 0;
  10583. }
  10584. }, {
  10585. key: "toCSS",
  10586. value: function toCSS(context) {
  10587. this._sourceMapGenerator = new this._sourceMapGeneratorConstructor({
  10588. file: this._outputFilename,
  10589. sourceRoot: null
  10590. });
  10591. if (this._outputSourceFiles) {
  10592. for (var filename in this._contentsMap) {
  10593. if (this._contentsMap.hasOwnProperty(filename)) {
  10594. var source = this._contentsMap[filename];
  10595. if (this._contentsIgnoredCharsMap[filename]) {
  10596. source = source.slice(this._contentsIgnoredCharsMap[filename]);
  10597. }
  10598. this._sourceMapGenerator.setSourceContent(this.normalizeFilename(filename), source);
  10599. }
  10600. }
  10601. }
  10602. this._rootNode.genCSS(context, this);
  10603. if (this._css.length > 0) {
  10604. var sourceMapURL;
  10605. var sourceMapContent = JSON.stringify(this._sourceMapGenerator.toJSON());
  10606. if (this.sourceMapURL) {
  10607. sourceMapURL = this.sourceMapURL;
  10608. } else if (this._sourceMapFilename) {
  10609. sourceMapURL = this._sourceMapFilename;
  10610. }
  10611. this.sourceMapURL = sourceMapURL;
  10612. this.sourceMap = sourceMapContent;
  10613. }
  10614. return this._css.join('');
  10615. }
  10616. }]);
  10617. return SourceMapOutput;
  10618. }();
  10619. return SourceMapOutput;
  10620. });
  10621. var sourceMapBuilder = (function (SourceMapOutput, environment) {
  10622. var SourceMapBuilder =
  10623. /*#__PURE__*/
  10624. function () {
  10625. function SourceMapBuilder(options) {
  10626. _classCallCheck(this, SourceMapBuilder);
  10627. this.options = options;
  10628. }
  10629. _createClass(SourceMapBuilder, [{
  10630. key: "toCSS",
  10631. value: function toCSS(rootNode, options, imports) {
  10632. var sourceMapOutput = new SourceMapOutput({
  10633. contentsIgnoredCharsMap: imports.contentsIgnoredChars,
  10634. rootNode: rootNode,
  10635. contentsMap: imports.contents,
  10636. sourceMapFilename: this.options.sourceMapFilename,
  10637. sourceMapURL: this.options.sourceMapURL,
  10638. outputFilename: this.options.sourceMapOutputFilename,
  10639. sourceMapBasepath: this.options.sourceMapBasepath,
  10640. sourceMapRootpath: this.options.sourceMapRootpath,
  10641. outputSourceFiles: this.options.outputSourceFiles,
  10642. sourceMapGenerator: this.options.sourceMapGenerator,
  10643. sourceMapFileInline: this.options.sourceMapFileInline
  10644. });
  10645. var css = sourceMapOutput.toCSS(options);
  10646. this.sourceMap = sourceMapOutput.sourceMap;
  10647. this.sourceMapURL = sourceMapOutput.sourceMapURL;
  10648. if (this.options.sourceMapInputFilename) {
  10649. this.sourceMapInputFilename = sourceMapOutput.normalizeFilename(this.options.sourceMapInputFilename);
  10650. }
  10651. if (this.options.sourceMapBasepath !== undefined && this.sourceMapURL !== undefined) {
  10652. this.sourceMapURL = sourceMapOutput.removeBasepath(this.sourceMapURL);
  10653. }
  10654. return css + this.getCSSAppendage();
  10655. }
  10656. }, {
  10657. key: "getCSSAppendage",
  10658. value: function getCSSAppendage() {
  10659. var sourceMapURL = this.sourceMapURL;
  10660. if (this.options.sourceMapFileInline) {
  10661. if (this.sourceMap === undefined) {
  10662. return '';
  10663. }
  10664. sourceMapURL = "data:application/json;base64,".concat(environment.encodeBase64(this.sourceMap));
  10665. }
  10666. if (sourceMapURL) {
  10667. return "/*# sourceMappingURL=".concat(sourceMapURL, " */");
  10668. }
  10669. return '';
  10670. }
  10671. }, {
  10672. key: "getExternalSourceMap",
  10673. value: function getExternalSourceMap() {
  10674. return this.sourceMap;
  10675. }
  10676. }, {
  10677. key: "setExternalSourceMap",
  10678. value: function setExternalSourceMap(sourceMap) {
  10679. this.sourceMap = sourceMap;
  10680. }
  10681. }, {
  10682. key: "isInline",
  10683. value: function isInline() {
  10684. return this.options.sourceMapFileInline;
  10685. }
  10686. }, {
  10687. key: "getSourceMapURL",
  10688. value: function getSourceMapURL() {
  10689. return this.sourceMapURL;
  10690. }
  10691. }, {
  10692. key: "getOutputFilename",
  10693. value: function getOutputFilename() {
  10694. return this.options.sourceMapOutputFilename;
  10695. }
  10696. }, {
  10697. key: "getInputFilename",
  10698. value: function getInputFilename() {
  10699. return this.sourceMapInputFilename;
  10700. }
  10701. }]);
  10702. return SourceMapBuilder;
  10703. }();
  10704. return SourceMapBuilder;
  10705. });
  10706. var transformTree = (function (root) {
  10707. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  10708. var evaldRoot;
  10709. var variables = options.variables;
  10710. var evalEnv = new contexts.Eval(options); //
  10711. // Allows setting variables with a hash, so:
  10712. //
  10713. // `{ color: new tree.Color('#f01') }` will become:
  10714. //
  10715. // new tree.Declaration('@color',
  10716. // new tree.Value([
  10717. // new tree.Expression([
  10718. // new tree.Color('#f01')
  10719. // ])
  10720. // ])
  10721. // )
  10722. //
  10723. if (_typeof(variables) === 'object' && !Array.isArray(variables)) {
  10724. variables = Object.keys(variables).map(function (k) {
  10725. var value = variables[k];
  10726. if (!(value instanceof tree.Value)) {
  10727. if (!(value instanceof tree.Expression)) {
  10728. value = new tree.Expression([value]);
  10729. }
  10730. value = new tree.Value([value]);
  10731. }
  10732. return new tree.Declaration("@".concat(k), value, false, null, 0);
  10733. });
  10734. evalEnv.frames = [new tree.Ruleset(null, variables)];
  10735. }
  10736. var visitors$1 = [new visitors.JoinSelectorVisitor(), new visitors.MarkVisibleSelectorsVisitor(true), new visitors.ExtendVisitor(), new visitors.ToCSSVisitor({
  10737. compress: Boolean(options.compress)
  10738. })];
  10739. var preEvalVisitors = [];
  10740. var v;
  10741. var visitorIterator;
  10742. /**
  10743. * first() / get() allows visitors to be added while visiting
  10744. *
  10745. * @todo Add scoping for visitors just like functions for @plugin; right now they're global
  10746. */
  10747. if (options.pluginManager) {
  10748. visitorIterator = options.pluginManager.visitor();
  10749. for (var i = 0; i < 2; i++) {
  10750. visitorIterator.first();
  10751. while (v = visitorIterator.get()) {
  10752. if (v.isPreEvalVisitor) {
  10753. if (i === 0 || preEvalVisitors.indexOf(v) === -1) {
  10754. preEvalVisitors.push(v);
  10755. v.run(root);
  10756. }
  10757. } else {
  10758. if (i === 0 || visitors$1.indexOf(v) === -1) {
  10759. if (v.isPreVisitor) {
  10760. visitors$1.unshift(v);
  10761. } else {
  10762. visitors$1.push(v);
  10763. }
  10764. }
  10765. }
  10766. }
  10767. }
  10768. }
  10769. evaldRoot = root.eval(evalEnv);
  10770. for (var i = 0; i < visitors$1.length; i++) {
  10771. visitors$1[i].run(evaldRoot);
  10772. } // Run any remaining visitors added after eval pass
  10773. if (options.pluginManager) {
  10774. visitorIterator.first();
  10775. while (v = visitorIterator.get()) {
  10776. if (visitors$1.indexOf(v) === -1 && preEvalVisitors.indexOf(v) === -1) {
  10777. v.run(evaldRoot);
  10778. }
  10779. }
  10780. }
  10781. return evaldRoot;
  10782. });
  10783. var parseTree = (function (SourceMapBuilder) {
  10784. var ParseTree =
  10785. /*#__PURE__*/
  10786. function () {
  10787. function ParseTree(root, imports) {
  10788. _classCallCheck(this, ParseTree);
  10789. this.root = root;
  10790. this.imports = imports;
  10791. }
  10792. _createClass(ParseTree, [{
  10793. key: "toCSS",
  10794. value: function toCSS(options) {
  10795. var evaldRoot;
  10796. var result = {};
  10797. var sourceMapBuilder;
  10798. try {
  10799. evaldRoot = transformTree(this.root, options);
  10800. } catch (e) {
  10801. throw new LessError(e, this.imports);
  10802. }
  10803. try {
  10804. var compress = Boolean(options.compress);
  10805. if (compress) {
  10806. logger.warn('The compress option has been deprecated. ' + 'We recommend you use a dedicated css minifier, for instance see less-plugin-clean-css.');
  10807. }
  10808. var toCSSOptions = {
  10809. compress: compress,
  10810. dumpLineNumbers: options.dumpLineNumbers,
  10811. strictUnits: Boolean(options.strictUnits),
  10812. numPrecision: 8
  10813. };
  10814. if (options.sourceMap) {
  10815. sourceMapBuilder = new SourceMapBuilder(options.sourceMap);
  10816. result.css = sourceMapBuilder.toCSS(evaldRoot, toCSSOptions, this.imports);
  10817. } else {
  10818. result.css = evaldRoot.toCSS(toCSSOptions);
  10819. }
  10820. } catch (e) {
  10821. throw new LessError(e, this.imports);
  10822. }
  10823. if (options.pluginManager) {
  10824. var postProcessors = options.pluginManager.getPostProcessors();
  10825. for (var i = 0; i < postProcessors.length; i++) {
  10826. result.css = postProcessors[i].process(result.css, {
  10827. sourceMap: sourceMapBuilder,
  10828. options: options,
  10829. imports: this.imports
  10830. });
  10831. }
  10832. }
  10833. if (options.sourceMap) {
  10834. result.map = sourceMapBuilder.getExternalSourceMap();
  10835. }
  10836. result.imports = [];
  10837. for (var file in this.imports.files) {
  10838. if (this.imports.files.hasOwnProperty(file) && file !== this.imports.rootFilename) {
  10839. result.imports.push(file);
  10840. }
  10841. }
  10842. return result;
  10843. }
  10844. }]);
  10845. return ParseTree;
  10846. }();
  10847. return ParseTree;
  10848. });
  10849. var importManager = (function (environment) {
  10850. // FileInfo = {
  10851. // 'rewriteUrls' - option - whether to adjust URL's to be relative
  10852. // 'filename' - full resolved filename of current file
  10853. // 'rootpath' - path to append to normal URLs for this node
  10854. // 'currentDirectory' - path to the current file, absolute
  10855. // 'rootFilename' - filename of the base file
  10856. // 'entryPath' - absolute path to the entry file
  10857. // 'reference' - whether the file should not be output and only output parts that are referenced
  10858. var ImportManager =
  10859. /*#__PURE__*/
  10860. function () {
  10861. function ImportManager(less, context, rootFileInfo) {
  10862. _classCallCheck(this, ImportManager);
  10863. this.less = less;
  10864. this.rootFilename = rootFileInfo.filename;
  10865. this.paths = context.paths || []; // Search paths, when importing
  10866. this.contents = {}; // map - filename to contents of all the files
  10867. this.contentsIgnoredChars = {}; // map - filename to lines at the beginning of each file to ignore
  10868. this.mime = context.mime;
  10869. this.error = null;
  10870. this.context = context; // Deprecated? Unused outside of here, could be useful.
  10871. this.queue = []; // Files which haven't been imported yet
  10872. this.files = {}; // Holds the imported parse trees.
  10873. }
  10874. /**
  10875. * Add an import to be imported
  10876. * @param path - the raw path
  10877. * @param tryAppendExtension - whether to try appending a file extension (.less or .js if the path has no extension)
  10878. * @param currentFileInfo - the current file info (used for instance to work out relative paths)
  10879. * @param importOptions - import options
  10880. * @param callback - callback for when it is imported
  10881. */
  10882. _createClass(ImportManager, [{
  10883. key: "push",
  10884. value: function push(path, tryAppendExtension, currentFileInfo, importOptions, callback) {
  10885. var importManager = this;
  10886. var pluginLoader = this.context.pluginManager.Loader;
  10887. this.queue.push(path);
  10888. var fileParsedFunc = function fileParsedFunc(e, root, fullPath) {
  10889. importManager.queue.splice(importManager.queue.indexOf(path), 1); // Remove the path from the queue
  10890. var importedEqualsRoot = fullPath === importManager.rootFilename;
  10891. if (importOptions.optional && e) {
  10892. callback(null, {
  10893. rules: []
  10894. }, false, null);
  10895. logger.info("The file ".concat(fullPath, " was skipped because it was not found and the import was marked optional."));
  10896. } else {
  10897. // Inline imports aren't cached here.
  10898. // If we start to cache them, please make sure they won't conflict with non-inline imports of the
  10899. // same name as they used to do before this comment and the condition below have been added.
  10900. if (!importManager.files[fullPath] && !importOptions.inline) {
  10901. importManager.files[fullPath] = {
  10902. root: root,
  10903. options: importOptions
  10904. };
  10905. }
  10906. if (e && !importManager.error) {
  10907. importManager.error = e;
  10908. }
  10909. callback(e, root, importedEqualsRoot, fullPath);
  10910. }
  10911. };
  10912. var newFileInfo = {
  10913. rewriteUrls: this.context.rewriteUrls,
  10914. entryPath: currentFileInfo.entryPath,
  10915. rootpath: currentFileInfo.rootpath,
  10916. rootFilename: currentFileInfo.rootFilename
  10917. };
  10918. var fileManager = environment.getFileManager(path, currentFileInfo.currentDirectory, this.context, environment);
  10919. if (!fileManager) {
  10920. fileParsedFunc({
  10921. message: "Could not find a file-manager for ".concat(path)
  10922. });
  10923. return;
  10924. }
  10925. var loadFileCallback = function loadFileCallback(loadedFile) {
  10926. var plugin;
  10927. var resolvedFilename = loadedFile.filename;
  10928. var contents = loadedFile.contents.replace(/^\uFEFF/, ''); // Pass on an updated rootpath if path of imported file is relative and file
  10929. // is in a (sub|sup) directory
  10930. //
  10931. // Examples:
  10932. // - If path of imported file is 'module/nav/nav.less' and rootpath is 'less/',
  10933. // then rootpath should become 'less/module/nav/'
  10934. // - If path of imported file is '../mixins.less' and rootpath is 'less/',
  10935. // then rootpath should become 'less/../'
  10936. newFileInfo.currentDirectory = fileManager.getPath(resolvedFilename);
  10937. if (newFileInfo.rewriteUrls) {
  10938. newFileInfo.rootpath = fileManager.join(importManager.context.rootpath || '', fileManager.pathDiff(newFileInfo.currentDirectory, newFileInfo.entryPath));
  10939. if (!fileManager.isPathAbsolute(newFileInfo.rootpath) && fileManager.alwaysMakePathsAbsolute()) {
  10940. newFileInfo.rootpath = fileManager.join(newFileInfo.entryPath, newFileInfo.rootpath);
  10941. }
  10942. }
  10943. newFileInfo.filename = resolvedFilename;
  10944. var newEnv = new contexts.Parse(importManager.context);
  10945. newEnv.processImports = false;
  10946. importManager.contents[resolvedFilename] = contents;
  10947. if (currentFileInfo.reference || importOptions.reference) {
  10948. newFileInfo.reference = true;
  10949. }
  10950. if (importOptions.isPlugin) {
  10951. plugin = pluginLoader.evalPlugin(contents, newEnv, importManager, importOptions.pluginArgs, newFileInfo);
  10952. if (plugin instanceof LessError) {
  10953. fileParsedFunc(plugin, null, resolvedFilename);
  10954. } else {
  10955. fileParsedFunc(null, plugin, resolvedFilename);
  10956. }
  10957. } else if (importOptions.inline) {
  10958. fileParsedFunc(null, contents, resolvedFilename);
  10959. } else {
  10960. // import (multiple) parse trees apparently get altered and can't be cached.
  10961. // TODO: investigate why this is
  10962. if (importManager.files[resolvedFilename] && !importManager.files[resolvedFilename].options.multiple && !importOptions.multiple) {
  10963. fileParsedFunc(null, importManager.files[resolvedFilename].root, resolvedFilename);
  10964. } else {
  10965. new Parser(newEnv, importManager, newFileInfo).parse(contents, function (e, root) {
  10966. fileParsedFunc(e, root, resolvedFilename);
  10967. });
  10968. }
  10969. }
  10970. };
  10971. var promise;
  10972. var context = clone(this.context);
  10973. if (tryAppendExtension) {
  10974. context.ext = importOptions.isPlugin ? '.js' : '.less';
  10975. }
  10976. if (importOptions.isPlugin) {
  10977. context.mime = 'application/javascript';
  10978. promise = pluginLoader.loadPlugin(path, currentFileInfo.currentDirectory, context, environment, fileManager);
  10979. } else {
  10980. promise = fileManager.loadFile(path, currentFileInfo.currentDirectory, context, environment, function (err, loadedFile) {
  10981. if (err) {
  10982. fileParsedFunc(err);
  10983. } else {
  10984. loadFileCallback(loadedFile);
  10985. }
  10986. });
  10987. }
  10988. if (promise) {
  10989. promise.then(loadFileCallback, fileParsedFunc);
  10990. }
  10991. }
  10992. }]);
  10993. return ImportManager;
  10994. }();
  10995. return ImportManager;
  10996. });
  10997. var Render = (function (environment, ParseTree, ImportManager) {
  10998. var render = function render(input, options, callback) {
  10999. if (typeof options === 'function') {
  11000. callback = options;
  11001. options = copyOptions(this.options, {});
  11002. } else {
  11003. options = copyOptions(this.options, options || {});
  11004. }
  11005. if (!callback) {
  11006. var self = this;
  11007. return new Promise(function (resolve, reject) {
  11008. render.call(self, input, options, function (err, output) {
  11009. if (err) {
  11010. reject(err);
  11011. } else {
  11012. resolve(output);
  11013. }
  11014. });
  11015. });
  11016. } else {
  11017. this.parse(input, options, function (err, root, imports, options) {
  11018. if (err) {
  11019. return callback(err);
  11020. }
  11021. var result;
  11022. try {
  11023. var parseTree = new ParseTree(root, imports);
  11024. result = parseTree.toCSS(options);
  11025. } catch (err) {
  11026. return callback(err);
  11027. }
  11028. callback(null, result);
  11029. });
  11030. }
  11031. };
  11032. return render;
  11033. });
  11034. /**
  11035. * Plugin Manager
  11036. */
  11037. var PluginManager =
  11038. /*#__PURE__*/
  11039. function () {
  11040. function PluginManager(less) {
  11041. _classCallCheck(this, PluginManager);
  11042. this.less = less;
  11043. this.visitors = [];
  11044. this.preProcessors = [];
  11045. this.postProcessors = [];
  11046. this.installedPlugins = [];
  11047. this.fileManagers = [];
  11048. this.iterator = -1;
  11049. this.pluginCache = {};
  11050. this.Loader = new less.PluginLoader(less);
  11051. }
  11052. /**
  11053. * Adds all the plugins in the array
  11054. * @param {Array} plugins
  11055. */
  11056. _createClass(PluginManager, [{
  11057. key: "addPlugins",
  11058. value: function addPlugins(plugins) {
  11059. if (plugins) {
  11060. for (var i = 0; i < plugins.length; i++) {
  11061. this.addPlugin(plugins[i]);
  11062. }
  11063. }
  11064. }
  11065. /**
  11066. *
  11067. * @param plugin
  11068. * @param {String} filename
  11069. */
  11070. }, {
  11071. key: "addPlugin",
  11072. value: function addPlugin(plugin, filename, functionRegistry) {
  11073. this.installedPlugins.push(plugin);
  11074. if (filename) {
  11075. this.pluginCache[filename] = plugin;
  11076. }
  11077. if (plugin.install) {
  11078. plugin.install(this.less, this, functionRegistry || this.less.functions.functionRegistry);
  11079. }
  11080. }
  11081. /**
  11082. *
  11083. * @param filename
  11084. */
  11085. }, {
  11086. key: "get",
  11087. value: function get(filename) {
  11088. return this.pluginCache[filename];
  11089. }
  11090. /**
  11091. * Adds a visitor. The visitor object has options on itself to determine
  11092. * when it should run.
  11093. * @param visitor
  11094. */
  11095. }, {
  11096. key: "addVisitor",
  11097. value: function addVisitor(visitor) {
  11098. this.visitors.push(visitor);
  11099. }
  11100. /**
  11101. * Adds a pre processor object
  11102. * @param {object} preProcessor
  11103. * @param {number} priority - guidelines 1 = before import, 1000 = import, 2000 = after import
  11104. */
  11105. }, {
  11106. key: "addPreProcessor",
  11107. value: function addPreProcessor(preProcessor, priority) {
  11108. var indexToInsertAt;
  11109. for (indexToInsertAt = 0; indexToInsertAt < this.preProcessors.length; indexToInsertAt++) {
  11110. if (this.preProcessors[indexToInsertAt].priority >= priority) {
  11111. break;
  11112. }
  11113. }
  11114. this.preProcessors.splice(indexToInsertAt, 0, {
  11115. preProcessor: preProcessor,
  11116. priority: priority
  11117. });
  11118. }
  11119. /**
  11120. * Adds a post processor object
  11121. * @param {object} postProcessor
  11122. * @param {number} priority - guidelines 1 = before compression, 1000 = compression, 2000 = after compression
  11123. */
  11124. }, {
  11125. key: "addPostProcessor",
  11126. value: function addPostProcessor(postProcessor, priority) {
  11127. var indexToInsertAt;
  11128. for (indexToInsertAt = 0; indexToInsertAt < this.postProcessors.length; indexToInsertAt++) {
  11129. if (this.postProcessors[indexToInsertAt].priority >= priority) {
  11130. break;
  11131. }
  11132. }
  11133. this.postProcessors.splice(indexToInsertAt, 0, {
  11134. postProcessor: postProcessor,
  11135. priority: priority
  11136. });
  11137. }
  11138. /**
  11139. *
  11140. * @param manager
  11141. */
  11142. }, {
  11143. key: "addFileManager",
  11144. value: function addFileManager(manager) {
  11145. this.fileManagers.push(manager);
  11146. }
  11147. /**
  11148. *
  11149. * @returns {Array}
  11150. * @private
  11151. */
  11152. }, {
  11153. key: "getPreProcessors",
  11154. value: function getPreProcessors() {
  11155. var preProcessors = [];
  11156. for (var i = 0; i < this.preProcessors.length; i++) {
  11157. preProcessors.push(this.preProcessors[i].preProcessor);
  11158. }
  11159. return preProcessors;
  11160. }
  11161. /**
  11162. *
  11163. * @returns {Array}
  11164. * @private
  11165. */
  11166. }, {
  11167. key: "getPostProcessors",
  11168. value: function getPostProcessors() {
  11169. var postProcessors = [];
  11170. for (var i = 0; i < this.postProcessors.length; i++) {
  11171. postProcessors.push(this.postProcessors[i].postProcessor);
  11172. }
  11173. return postProcessors;
  11174. }
  11175. /**
  11176. *
  11177. * @returns {Array}
  11178. * @private
  11179. */
  11180. }, {
  11181. key: "getVisitors",
  11182. value: function getVisitors() {
  11183. return this.visitors;
  11184. }
  11185. }, {
  11186. key: "visitor",
  11187. value: function visitor() {
  11188. var self = this;
  11189. return {
  11190. first: function first() {
  11191. self.iterator = -1;
  11192. return self.visitors[self.iterator];
  11193. },
  11194. get: function get() {
  11195. self.iterator += 1;
  11196. return self.visitors[self.iterator];
  11197. }
  11198. };
  11199. }
  11200. /**
  11201. *
  11202. * @returns {Array}
  11203. * @private
  11204. */
  11205. }, {
  11206. key: "getFileManagers",
  11207. value: function getFileManagers() {
  11208. return this.fileManagers;
  11209. }
  11210. }]);
  11211. return PluginManager;
  11212. }();
  11213. var pm;
  11214. function PluginManagerFactory(less, newFactory) {
  11215. if (newFactory || !pm) {
  11216. pm = new PluginManager(less);
  11217. }
  11218. return pm;
  11219. }
  11220. var Parse = (function (environment, ParseTree, ImportManager) {
  11221. var parse = function parse(input, options, callback) {
  11222. if (typeof options === 'function') {
  11223. callback = options;
  11224. options = copyOptions(this.options, {});
  11225. } else {
  11226. options = copyOptions(this.options, options || {});
  11227. }
  11228. if (!callback) {
  11229. var self = this;
  11230. return new Promise(function (resolve, reject) {
  11231. parse.call(self, input, options, function (err, output) {
  11232. if (err) {
  11233. reject(err);
  11234. } else {
  11235. resolve(output);
  11236. }
  11237. });
  11238. });
  11239. } else {
  11240. var context;
  11241. var rootFileInfo;
  11242. var pluginManager = new PluginManagerFactory(this, !options.reUsePluginManager);
  11243. options.pluginManager = pluginManager;
  11244. context = new contexts.Parse(options);
  11245. if (options.rootFileInfo) {
  11246. rootFileInfo = options.rootFileInfo;
  11247. } else {
  11248. var filename = options.filename || 'input';
  11249. var entryPath = filename.replace(/[^\/\\]*$/, '');
  11250. rootFileInfo = {
  11251. filename: filename,
  11252. rewriteUrls: context.rewriteUrls,
  11253. rootpath: context.rootpath || '',
  11254. currentDirectory: entryPath,
  11255. entryPath: entryPath,
  11256. rootFilename: filename
  11257. }; // add in a missing trailing slash
  11258. if (rootFileInfo.rootpath && rootFileInfo.rootpath.slice(-1) !== '/') {
  11259. rootFileInfo.rootpath += '/';
  11260. }
  11261. }
  11262. var imports = new ImportManager(this, context, rootFileInfo);
  11263. this.importManager = imports; // TODO: allow the plugins to be just a list of paths or names
  11264. // Do an async plugin queue like lessc
  11265. if (options.plugins) {
  11266. options.plugins.forEach(function (plugin) {
  11267. var evalResult;
  11268. var contents;
  11269. if (plugin.fileContent) {
  11270. contents = plugin.fileContent.replace(/^\uFEFF/, '');
  11271. evalResult = pluginManager.Loader.evalPlugin(contents, context, imports, plugin.options, plugin.filename);
  11272. if (evalResult instanceof LessError) {
  11273. return callback(evalResult);
  11274. }
  11275. } else {
  11276. pluginManager.addPlugin(plugin);
  11277. }
  11278. });
  11279. }
  11280. new Parser(context, imports, rootFileInfo).parse(input, function (e, root) {
  11281. if (e) {
  11282. return callback(e);
  11283. }
  11284. callback(null, root, imports, options);
  11285. }, options);
  11286. }
  11287. };
  11288. return parse;
  11289. });
  11290. var lessRoot = (function (environment$1, fileManagers) {
  11291. /**
  11292. * @todo
  11293. * This original code could be improved quite a bit.
  11294. * Many classes / modules currently add side-effects / mutations to passed in objects,
  11295. * which makes it hard to refactor and reason about.
  11296. */
  11297. environment$1 = new environment(environment$1, fileManagers);
  11298. var SourceMapOutput = sourceMapOutput(environment$1);
  11299. var SourceMapBuilder = sourceMapBuilder(SourceMapOutput, environment$1);
  11300. var ParseTree = parseTree(SourceMapBuilder);
  11301. var ImportManager = importManager(environment$1);
  11302. var render = Render(environment$1, ParseTree);
  11303. var parse = Parse(environment$1, ParseTree, ImportManager);
  11304. var functions = Functions(environment$1);
  11305. /**
  11306. * @todo
  11307. * This root properties / methods need to be organized.
  11308. * It's not clear what should / must be public and why.
  11309. */
  11310. var initial = {
  11311. version: [3, 10, 3],
  11312. data: data,
  11313. tree: tree,
  11314. Environment: environment,
  11315. AbstractFileManager: AbstractFileManager,
  11316. AbstractPluginLoader: AbstractPluginLoader,
  11317. environment: environment$1,
  11318. visitors: visitors,
  11319. Parser: Parser,
  11320. functions: functions,
  11321. contexts: contexts,
  11322. SourceMapOutput: SourceMapOutput,
  11323. SourceMapBuilder: SourceMapBuilder,
  11324. ParseTree: ParseTree,
  11325. ImportManager: ImportManager,
  11326. render: render,
  11327. parse: parse,
  11328. LessError: LessError,
  11329. transformTree: transformTree,
  11330. utils: utils,
  11331. PluginManager: PluginManagerFactory,
  11332. logger: logger
  11333. }; // Create a public API
  11334. var ctor = function ctor(t) {
  11335. return function () {
  11336. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  11337. args[_key] = arguments[_key];
  11338. }
  11339. return _construct(t, args);
  11340. };
  11341. };
  11342. var t;
  11343. var api = Object.create(initial);
  11344. for (var n in initial.tree) {
  11345. /* eslint guard-for-in: 0 */
  11346. t = initial.tree[n];
  11347. if (typeof t === 'function') {
  11348. api[n.toLowerCase()] = ctor(t);
  11349. } else {
  11350. api[n] = Object.create(null);
  11351. for (var o in t) {
  11352. /* eslint guard-for-in: 0 */
  11353. api[n][o.toLowerCase()] = ctor(t[o]);
  11354. }
  11355. }
  11356. }
  11357. return api;
  11358. });
  11359. var options;
  11360. var logger$1;
  11361. var fileCache = {}; // TODOS - move log somewhere. pathDiff and doing something similar in node. use pathDiff in the other browser file for the initial load
  11362. var FileManager =
  11363. /*#__PURE__*/
  11364. function (_AbstractFileManager) {
  11365. _inherits(FileManager, _AbstractFileManager);
  11366. function FileManager() {
  11367. _classCallCheck(this, FileManager);
  11368. return _possibleConstructorReturn(this, _getPrototypeOf(FileManager).apply(this, arguments));
  11369. }
  11370. _createClass(FileManager, [{
  11371. key: "alwaysMakePathsAbsolute",
  11372. value: function alwaysMakePathsAbsolute() {
  11373. return true;
  11374. }
  11375. }, {
  11376. key: "join",
  11377. value: function join(basePath, laterPath) {
  11378. if (!basePath) {
  11379. return laterPath;
  11380. }
  11381. return this.extractUrlParts(laterPath, basePath).path;
  11382. }
  11383. }, {
  11384. key: "doXHR",
  11385. value: function doXHR(url, type, callback, errback) {
  11386. var xhr = new XMLHttpRequest();
  11387. var async = options.isFileProtocol ? options.fileAsync : true;
  11388. if (typeof xhr.overrideMimeType === 'function') {
  11389. xhr.overrideMimeType('text/css');
  11390. }
  11391. logger$1.debug("XHR: Getting '".concat(url, "'"));
  11392. xhr.open('GET', url, async);
  11393. xhr.setRequestHeader('Accept', type || 'text/x-less, text/css; q=0.9, */*; q=0.5');
  11394. xhr.send(null);
  11395. function handleResponse(xhr, callback, errback) {
  11396. if (xhr.status >= 200 && xhr.status < 300) {
  11397. callback(xhr.responseText, xhr.getResponseHeader('Last-Modified'));
  11398. } else if (typeof errback === 'function') {
  11399. errback(xhr.status, url);
  11400. }
  11401. }
  11402. if (options.isFileProtocol && !options.fileAsync) {
  11403. if (xhr.status === 0 || xhr.status >= 200 && xhr.status < 300) {
  11404. callback(xhr.responseText);
  11405. } else {
  11406. errback(xhr.status, url);
  11407. }
  11408. } else if (async) {
  11409. xhr.onreadystatechange = function () {
  11410. if (xhr.readyState == 4) {
  11411. handleResponse(xhr, callback, errback);
  11412. }
  11413. };
  11414. } else {
  11415. handleResponse(xhr, callback, errback);
  11416. }
  11417. }
  11418. }, {
  11419. key: "supports",
  11420. value: function supports() {
  11421. return true;
  11422. }
  11423. }, {
  11424. key: "clearFileCache",
  11425. value: function clearFileCache() {
  11426. fileCache = {};
  11427. }
  11428. }, {
  11429. key: "loadFile",
  11430. value: function loadFile(filename, currentDirectory, options, environment) {
  11431. // TODO: Add prefix support like less-node?
  11432. // What about multiple paths?
  11433. if (currentDirectory && !this.isPathAbsolute(filename)) {
  11434. filename = currentDirectory + filename;
  11435. }
  11436. filename = options.ext ? this.tryAppendExtension(filename, options.ext) : filename;
  11437. options = options || {}; // sheet may be set to the stylesheet for the initial load or a collection of properties including
  11438. // some context variables for imports
  11439. var hrefParts = this.extractUrlParts(filename, window.location.href);
  11440. var href = hrefParts.url;
  11441. var self = this;
  11442. return new Promise(function (resolve, reject) {
  11443. if (options.useFileCache && fileCache[href]) {
  11444. try {
  11445. var lessText = fileCache[href];
  11446. return resolve({
  11447. contents: lessText,
  11448. filename: href,
  11449. webInfo: {
  11450. lastModified: new Date()
  11451. }
  11452. });
  11453. } catch (e) {
  11454. return reject({
  11455. filename: href,
  11456. message: "Error loading file ".concat(href, " error was ").concat(e.message)
  11457. });
  11458. }
  11459. }
  11460. self.doXHR(href, options.mime, function doXHRCallback(data, lastModified) {
  11461. // per file cache
  11462. fileCache[href] = data; // Use remote copy (re-parse)
  11463. resolve({
  11464. contents: data,
  11465. filename: href,
  11466. webInfo: {
  11467. lastModified: lastModified
  11468. }
  11469. });
  11470. }, function doXHRError(status, url) {
  11471. reject({
  11472. type: 'File',
  11473. message: "'".concat(url, "' wasn't found (").concat(status, ")"),
  11474. href: href
  11475. });
  11476. });
  11477. });
  11478. }
  11479. }]);
  11480. return FileManager;
  11481. }(AbstractFileManager);
  11482. var FM = (function (opts, log) {
  11483. options = opts;
  11484. logger$1 = log;
  11485. return FileManager;
  11486. });
  11487. /**
  11488. * Browser Plugin Loader
  11489. */
  11490. var PluginLoader =
  11491. /*#__PURE__*/
  11492. function (_AbstractPluginLoader) {
  11493. _inherits(PluginLoader, _AbstractPluginLoader);
  11494. function PluginLoader(less) {
  11495. var _this;
  11496. _classCallCheck(this, PluginLoader);
  11497. _this = _possibleConstructorReturn(this, _getPrototypeOf(PluginLoader).call(this));
  11498. _this.less = less; // Should we shim this.require for browser? Probably not?
  11499. return _this;
  11500. }
  11501. _createClass(PluginLoader, [{
  11502. key: "loadPlugin",
  11503. value: function loadPlugin(filename, basePath, context, environment, fileManager) {
  11504. return new Promise(function (fulfill, reject) {
  11505. fileManager.loadFile(filename, basePath, context, environment).then(fulfill).catch(reject);
  11506. });
  11507. }
  11508. }]);
  11509. return PluginLoader;
  11510. }(AbstractPluginLoader);
  11511. var LogListener = (function (less, options) {
  11512. var logLevel_debug = 4;
  11513. var logLevel_info = 3;
  11514. var logLevel_warn = 2;
  11515. var logLevel_error = 1; // The amount of logging in the javascript console.
  11516. // 3 - Debug, information and errors
  11517. // 2 - Information and errors
  11518. // 1 - Errors
  11519. // 0 - None
  11520. // Defaults to 2
  11521. options.logLevel = typeof options.logLevel !== 'undefined' ? options.logLevel : options.env === 'development' ? logLevel_info : logLevel_error;
  11522. if (!options.loggers) {
  11523. options.loggers = [{
  11524. debug: function debug(msg) {
  11525. if (options.logLevel >= logLevel_debug) {
  11526. console.log(msg);
  11527. }
  11528. },
  11529. info: function info(msg) {
  11530. if (options.logLevel >= logLevel_info) {
  11531. console.log(msg);
  11532. }
  11533. },
  11534. warn: function warn(msg) {
  11535. if (options.logLevel >= logLevel_warn) {
  11536. console.warn(msg);
  11537. }
  11538. },
  11539. error: function error(msg) {
  11540. if (options.logLevel >= logLevel_error) {
  11541. console.error(msg);
  11542. }
  11543. }
  11544. }];
  11545. }
  11546. for (var i = 0; i < options.loggers.length; i++) {
  11547. less.logger.addListener(options.loggers[i]);
  11548. }
  11549. });
  11550. var ErrorReporting = (function (window, less, options) {
  11551. function errorHTML(e, rootHref) {
  11552. var id = "less-error-message:".concat(extractId(rootHref || ''));
  11553. var template = '<li><label>{line}</label><pre class="{class}">{content}</pre></li>';
  11554. var elem = window.document.createElement('div');
  11555. var timer;
  11556. var content;
  11557. var errors = [];
  11558. var filename = e.filename || rootHref;
  11559. var filenameNoPath = filename.match(/([^\/]+(\?.*)?)$/)[1];
  11560. elem.id = id;
  11561. elem.className = 'less-error-message';
  11562. content = "<h3>".concat(e.type || 'Syntax', "Error: ").concat(e.message || 'There is an error in your .less file') + "</h3><p>in <a href=\"".concat(filename, "\">").concat(filenameNoPath, "</a> ");
  11563. var errorline = function errorline(e, i, classname) {
  11564. if (e.extract[i] !== undefined) {
  11565. errors.push(template.replace(/\{line\}/, (parseInt(e.line, 10) || 0) + (i - 1)).replace(/\{class\}/, classname).replace(/\{content\}/, e.extract[i]));
  11566. }
  11567. };
  11568. if (e.line) {
  11569. errorline(e, 0, '');
  11570. errorline(e, 1, 'line');
  11571. errorline(e, 2, '');
  11572. content += "on line ".concat(e.line, ", column ").concat(e.column + 1, ":</p><ul>").concat(errors.join(''), "</ul>");
  11573. }
  11574. if (e.stack && (e.extract || options.logLevel >= 4)) {
  11575. content += "<br/>Stack Trace</br />".concat(e.stack.split('\n').slice(1).join('<br/>'));
  11576. }
  11577. elem.innerHTML = content; // CSS for error messages
  11578. browser.createCSS(window.document, ['.less-error-message ul, .less-error-message li {', 'list-style-type: none;', 'margin-right: 15px;', 'padding: 4px 0;', 'margin: 0;', '}', '.less-error-message label {', 'font-size: 12px;', 'margin-right: 15px;', 'padding: 4px 0;', 'color: #cc7777;', '}', '.less-error-message pre {', 'color: #dd6666;', 'padding: 4px 0;', 'margin: 0;', 'display: inline-block;', '}', '.less-error-message pre.line {', 'color: #ff0000;', '}', '.less-error-message h3 {', 'font-size: 20px;', 'font-weight: bold;', 'padding: 15px 0 5px 0;', 'margin: 0;', '}', '.less-error-message a {', 'color: #10a', '}', '.less-error-message .error {', 'color: red;', 'font-weight: bold;', 'padding-bottom: 2px;', 'border-bottom: 1px dashed red;', '}'].join('\n'), {
  11579. title: 'error-message'
  11580. });
  11581. elem.style.cssText = ['font-family: Arial, sans-serif', 'border: 1px solid #e00', 'background-color: #eee', 'border-radius: 5px', '-webkit-border-radius: 5px', '-moz-border-radius: 5px', 'color: #e00', 'padding: 15px', 'margin-bottom: 15px'].join(';');
  11582. if (options.env === 'development') {
  11583. timer = setInterval(function () {
  11584. var document = window.document;
  11585. var body = document.body;
  11586. if (body) {
  11587. if (document.getElementById(id)) {
  11588. body.replaceChild(elem, document.getElementById(id));
  11589. } else {
  11590. body.insertBefore(elem, body.firstChild);
  11591. }
  11592. clearInterval(timer);
  11593. }
  11594. }, 10);
  11595. }
  11596. }
  11597. function removeErrorHTML(path) {
  11598. var node = window.document.getElementById("less-error-message:".concat(extractId(path)));
  11599. if (node) {
  11600. node.parentNode.removeChild(node);
  11601. }
  11602. }
  11603. function removeError(path) {
  11604. if (!options.errorReporting || options.errorReporting === 'html') {
  11605. removeErrorHTML(path);
  11606. } else if (options.errorReporting === 'console') ; else if (typeof options.errorReporting === 'function') {
  11607. options.errorReporting('remove', path);
  11608. }
  11609. }
  11610. function errorConsole(e, rootHref) {
  11611. var template = '{line} {content}';
  11612. var filename = e.filename || rootHref;
  11613. var errors = [];
  11614. var content = "".concat(e.type || 'Syntax', "Error: ").concat(e.message || 'There is an error in your .less file', " in ").concat(filename);
  11615. var errorline = function errorline(e, i, classname) {
  11616. if (e.extract[i] !== undefined) {
  11617. errors.push(template.replace(/\{line\}/, (parseInt(e.line, 10) || 0) + (i - 1)).replace(/\{class\}/, classname).replace(/\{content\}/, e.extract[i]));
  11618. }
  11619. };
  11620. if (e.line) {
  11621. errorline(e, 0, '');
  11622. errorline(e, 1, 'line');
  11623. errorline(e, 2, '');
  11624. content += " on line ".concat(e.line, ", column ").concat(e.column + 1, ":\n").concat(errors.join('\n'));
  11625. }
  11626. if (e.stack && (e.extract || options.logLevel >= 4)) {
  11627. content += "\nStack Trace\n".concat(e.stack);
  11628. }
  11629. less.logger.error(content);
  11630. }
  11631. function error(e, rootHref) {
  11632. if (!options.errorReporting || options.errorReporting === 'html') {
  11633. errorHTML(e, rootHref);
  11634. } else if (options.errorReporting === 'console') {
  11635. errorConsole(e, rootHref);
  11636. } else if (typeof options.errorReporting === 'function') {
  11637. options.errorReporting('add', e, rootHref);
  11638. }
  11639. }
  11640. return {
  11641. add: error,
  11642. remove: removeError
  11643. };
  11644. });
  11645. // Cache system is a bit outdated and could do with work
  11646. var Cache = (function (window, options, logger) {
  11647. var cache = null;
  11648. if (options.env !== 'development') {
  11649. try {
  11650. cache = typeof window.localStorage === 'undefined' ? null : window.localStorage;
  11651. } catch (_) {}
  11652. }
  11653. return {
  11654. setCSS: function setCSS(path, lastModified, modifyVars, styles) {
  11655. if (cache) {
  11656. logger.info("saving ".concat(path, " to cache."));
  11657. try {
  11658. cache.setItem(path, styles);
  11659. cache.setItem("".concat(path, ":timestamp"), lastModified);
  11660. if (modifyVars) {
  11661. cache.setItem("".concat(path, ":vars"), JSON.stringify(modifyVars));
  11662. }
  11663. } catch (e) {
  11664. // TODO - could do with adding more robust error handling
  11665. logger.error("failed to save \"".concat(path, "\" to local storage for caching."));
  11666. }
  11667. }
  11668. },
  11669. getCSS: function getCSS(path, webInfo, modifyVars) {
  11670. var css = cache && cache.getItem(path);
  11671. var timestamp = cache && cache.getItem("".concat(path, ":timestamp"));
  11672. var vars = cache && cache.getItem("".concat(path, ":vars"));
  11673. modifyVars = modifyVars || {};
  11674. vars = vars || "{}"; // if not set, treat as the JSON representation of an empty object
  11675. if (timestamp && webInfo.lastModified && new Date(webInfo.lastModified).valueOf() === new Date(timestamp).valueOf() && JSON.stringify(modifyVars) === vars) {
  11676. // Use local copy
  11677. return css;
  11678. }
  11679. }
  11680. };
  11681. });
  11682. var ImageSize = (function () {
  11683. function _imageSize() {
  11684. throw {
  11685. type: 'Runtime',
  11686. message: 'Image size functions are not supported in browser version of less'
  11687. };
  11688. }
  11689. var imageFunctions = {
  11690. 'image-size': function imageSize(filePathNode) {
  11691. _imageSize();
  11692. return -1;
  11693. },
  11694. 'image-width': function imageWidth(filePathNode) {
  11695. _imageSize();
  11696. return -1;
  11697. },
  11698. 'image-height': function imageHeight(filePathNode) {
  11699. _imageSize();
  11700. return -1;
  11701. }
  11702. };
  11703. functionRegistry.addMultiple(imageFunctions);
  11704. });
  11705. //
  11706. var root = (function (window, options) {
  11707. var document = window.document;
  11708. var less = lessRoot();
  11709. less.options = options;
  11710. var environment = less.environment;
  11711. var FileManager = FM(options, less.logger);
  11712. var fileManager = new FileManager();
  11713. environment.addFileManager(fileManager);
  11714. less.FileManager = FileManager;
  11715. less.PluginLoader = PluginLoader;
  11716. LogListener(less, options);
  11717. var errors = ErrorReporting(window, less, options);
  11718. var cache = less.cache = options.cache || Cache(window, options, less.logger);
  11719. ImageSize(less.environment); // Setup user functions - Deprecate?
  11720. if (options.functions) {
  11721. less.functions.functionRegistry.addMultiple(options.functions);
  11722. }
  11723. var typePattern = /^text\/(x-)?less$/;
  11724. function clone(obj) {
  11725. var cloned = {};
  11726. for (var prop in obj) {
  11727. if (obj.hasOwnProperty(prop)) {
  11728. cloned[prop] = obj[prop];
  11729. }
  11730. }
  11731. return cloned;
  11732. } // only really needed for phantom
  11733. function bind(func, thisArg) {
  11734. var curryArgs = Array.prototype.slice.call(arguments, 2);
  11735. return function () {
  11736. var args = curryArgs.concat(Array.prototype.slice.call(arguments, 0));
  11737. return func.apply(thisArg, args);
  11738. };
  11739. }
  11740. function loadStyles(modifyVars) {
  11741. var styles = document.getElementsByTagName('style');
  11742. var style;
  11743. for (var i = 0; i < styles.length; i++) {
  11744. style = styles[i];
  11745. if (style.type.match(typePattern)) {
  11746. var instanceOptions = clone(options);
  11747. instanceOptions.modifyVars = modifyVars;
  11748. var lessText = style.innerHTML || '';
  11749. instanceOptions.filename = document.location.href.replace(/#.*$/, '');
  11750. /* jshint loopfunc:true */
  11751. // use closure to store current style
  11752. less.render(lessText, instanceOptions, bind(function (style, e, result) {
  11753. if (e) {
  11754. errors.add(e, 'inline');
  11755. } else {
  11756. style.type = 'text/css';
  11757. if (style.styleSheet) {
  11758. style.styleSheet.cssText = result.css;
  11759. } else {
  11760. style.innerHTML = result.css;
  11761. }
  11762. }
  11763. }, null, style));
  11764. }
  11765. }
  11766. }
  11767. function loadStyleSheet(sheet, callback, reload, remaining, modifyVars) {
  11768. var instanceOptions = clone(options);
  11769. addDataAttr(instanceOptions, sheet);
  11770. instanceOptions.mime = sheet.type;
  11771. if (modifyVars) {
  11772. instanceOptions.modifyVars = modifyVars;
  11773. }
  11774. function loadInitialFileCallback(loadedFile) {
  11775. var data = loadedFile.contents;
  11776. var path = loadedFile.filename;
  11777. var webInfo = loadedFile.webInfo;
  11778. var newFileInfo = {
  11779. currentDirectory: fileManager.getPath(path),
  11780. filename: path,
  11781. rootFilename: path,
  11782. rewriteUrls: instanceOptions.rewriteUrls
  11783. };
  11784. newFileInfo.entryPath = newFileInfo.currentDirectory;
  11785. newFileInfo.rootpath = instanceOptions.rootpath || newFileInfo.currentDirectory;
  11786. if (webInfo) {
  11787. webInfo.remaining = remaining;
  11788. var css = cache.getCSS(path, webInfo, instanceOptions.modifyVars);
  11789. if (!reload && css) {
  11790. webInfo.local = true;
  11791. callback(null, css, data, sheet, webInfo, path);
  11792. return;
  11793. }
  11794. } // TODO add tests around how this behaves when reloading
  11795. errors.remove(path);
  11796. instanceOptions.rootFileInfo = newFileInfo;
  11797. less.render(data, instanceOptions, function (e, result) {
  11798. if (e) {
  11799. e.href = path;
  11800. callback(e);
  11801. } else {
  11802. cache.setCSS(sheet.href, webInfo.lastModified, instanceOptions.modifyVars, result.css);
  11803. callback(null, result.css, data, sheet, webInfo, path);
  11804. }
  11805. });
  11806. }
  11807. fileManager.loadFile(sheet.href, null, instanceOptions, environment).then(function (loadedFile) {
  11808. loadInitialFileCallback(loadedFile);
  11809. }).catch(function (err) {
  11810. console.log(err);
  11811. callback(err);
  11812. });
  11813. }
  11814. function loadStyleSheets(callback, reload, modifyVars) {
  11815. for (var i = 0; i < less.sheets.length; i++) {
  11816. loadStyleSheet(less.sheets[i], callback, reload, less.sheets.length - (i + 1), modifyVars);
  11817. }
  11818. }
  11819. function initRunningMode() {
  11820. if (less.env === 'development') {
  11821. less.watchTimer = setInterval(function () {
  11822. if (less.watchMode) {
  11823. fileManager.clearFileCache();
  11824. loadStyleSheets(function (e, css, _, sheet, webInfo) {
  11825. if (e) {
  11826. errors.add(e, e.href || sheet.href);
  11827. } else if (css) {
  11828. browser.createCSS(window.document, css, sheet);
  11829. }
  11830. });
  11831. }
  11832. }, options.poll);
  11833. }
  11834. } //
  11835. // Watch mode
  11836. //
  11837. less.watch = function () {
  11838. if (!less.watchMode) {
  11839. less.env = 'development';
  11840. initRunningMode();
  11841. }
  11842. this.watchMode = true;
  11843. return true;
  11844. };
  11845. less.unwatch = function () {
  11846. clearInterval(less.watchTimer);
  11847. this.watchMode = false;
  11848. return false;
  11849. }; //
  11850. // Synchronously get all <link> tags with the 'rel' attribute set to
  11851. // "stylesheet/less".
  11852. //
  11853. less.registerStylesheetsImmediately = function () {
  11854. var links = document.getElementsByTagName('link');
  11855. less.sheets = [];
  11856. for (var i = 0; i < links.length; i++) {
  11857. if (links[i].rel === 'stylesheet/less' || links[i].rel.match(/stylesheet/) && links[i].type.match(typePattern)) {
  11858. less.sheets.push(links[i]);
  11859. }
  11860. }
  11861. }; //
  11862. // Asynchronously get all <link> tags with the 'rel' attribute set to
  11863. // "stylesheet/less", returning a Promise.
  11864. //
  11865. less.registerStylesheets = function () {
  11866. return new Promise(function (resolve, reject) {
  11867. less.registerStylesheetsImmediately();
  11868. resolve();
  11869. });
  11870. }; //
  11871. // With this function, it's possible to alter variables and re-render
  11872. // CSS without reloading less-files
  11873. //
  11874. less.modifyVars = function (record) {
  11875. return less.refresh(true, record, false);
  11876. };
  11877. less.refresh = function (reload, modifyVars, clearFileCache) {
  11878. if ((reload || clearFileCache) && clearFileCache !== false) {
  11879. fileManager.clearFileCache();
  11880. }
  11881. return new Promise(function (resolve, reject) {
  11882. var startTime;
  11883. var endTime;
  11884. var totalMilliseconds;
  11885. var remainingSheets;
  11886. startTime = endTime = new Date(); // Set counter for remaining unprocessed sheets
  11887. remainingSheets = less.sheets.length;
  11888. if (remainingSheets === 0) {
  11889. endTime = new Date();
  11890. totalMilliseconds = endTime - startTime;
  11891. less.logger.info('Less has finished and no sheets were loaded.');
  11892. resolve({
  11893. startTime: startTime,
  11894. endTime: endTime,
  11895. totalMilliseconds: totalMilliseconds,
  11896. sheets: less.sheets.length
  11897. });
  11898. } else {
  11899. // Relies on less.sheets array, callback seems to be guaranteed to be called for every element of the array
  11900. loadStyleSheets(function (e, css, _, sheet, webInfo) {
  11901. if (e) {
  11902. errors.add(e, e.href || sheet.href);
  11903. reject(e);
  11904. return;
  11905. }
  11906. if (webInfo.local) {
  11907. less.logger.info("Loading ".concat(sheet.href, " from cache."));
  11908. } else {
  11909. less.logger.info("Rendered ".concat(sheet.href, " successfully."));
  11910. }
  11911. browser.createCSS(window.document, css, sheet);
  11912. less.logger.info("CSS for ".concat(sheet.href, " generated in ").concat(new Date() - endTime, "ms")); // Count completed sheet
  11913. remainingSheets--; // Check if the last remaining sheet was processed and then call the promise
  11914. if (remainingSheets === 0) {
  11915. totalMilliseconds = new Date() - startTime;
  11916. less.logger.info("Less has finished. CSS generated in ".concat(totalMilliseconds, "ms"));
  11917. resolve({
  11918. startTime: startTime,
  11919. endTime: endTime,
  11920. totalMilliseconds: totalMilliseconds,
  11921. sheets: less.sheets.length
  11922. });
  11923. }
  11924. endTime = new Date();
  11925. }, reload, modifyVars);
  11926. }
  11927. loadStyles(modifyVars);
  11928. });
  11929. };
  11930. less.refreshStyles = loadStyles;
  11931. return less;
  11932. });
  11933. /**
  11934. * Kicks off less and compiles any stylesheets
  11935. * used in the browser distributed version of less
  11936. * to kick-start less using the browser api
  11937. */
  11938. var options$1 = defaultOptions();
  11939. if (window.less) {
  11940. for (var key in window.less) {
  11941. if (window.less.hasOwnProperty(key)) {
  11942. options$1[key] = window.less[key];
  11943. }
  11944. }
  11945. }
  11946. addDefaultOptions(window, options$1);
  11947. options$1.plugins = options$1.plugins || [];
  11948. if (window.LESS_PLUGINS) {
  11949. options$1.plugins = options$1.plugins.concat(window.LESS_PLUGINS);
  11950. }
  11951. var less = root(window, options$1);
  11952. window.less = less;
  11953. var css;
  11954. var head;
  11955. var style; // Always restore page visibility
  11956. function resolveOrReject(data) {
  11957. if (data.filename) {
  11958. console.warn(data);
  11959. }
  11960. if (!options$1.async) {
  11961. head.removeChild(style);
  11962. }
  11963. }
  11964. if (options$1.onReady) {
  11965. if (/!watch/.test(window.location.hash)) {
  11966. less.watch();
  11967. } // Simulate synchronous stylesheet loading by hiding page rendering
  11968. if (!options$1.async) {
  11969. css = 'body { display: none !important }';
  11970. head = document.head || document.getElementsByTagName('head')[0];
  11971. style = document.createElement('style');
  11972. style.type = 'text/css';
  11973. if (style.styleSheet) {
  11974. style.styleSheet.cssText = css;
  11975. } else {
  11976. style.appendChild(document.createTextNode(css));
  11977. }
  11978. head.appendChild(style);
  11979. }
  11980. less.registerStylesheetsImmediately();
  11981. less.pageLoadFinished = less.refresh(less.env === 'development').then(resolveOrReject, resolveOrReject);
  11982. }
  11983. return less;
  11984. }));