less.js 385 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299
  1. import {
  2. __commonJS
  3. } from "./chunk-4EOJPDL2.js";
  4. // node_modules/less/dist/less.js
  5. var require_less = __commonJS({
  6. "node_modules/less/dist/less.js"(exports, module) {
  7. (function(global, factory) {
  8. typeof exports === "object" && typeof module !== "undefined" ? module.exports = factory() : typeof define === "function" && define.amd ? define(factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, global.less = factory());
  9. })(exports, function() {
  10. "use strict";
  11. function defaultOptions() {
  12. return {
  13. /* Inline Javascript - @plugin still allowed */
  14. javascriptEnabled: false,
  15. /* Outputs a makefile import dependency list to stdout. */
  16. depends: false,
  17. /* (DEPRECATED) Compress using less built-in compression.
  18. * This does an okay job but does not utilise all the tricks of
  19. * dedicated css compression. */
  20. compress: false,
  21. /* Runs the less parser and just reports errors without any output. */
  22. lint: false,
  23. /* Sets available include paths.
  24. * If the file in an @import rule does not exist at that exact location,
  25. * less will look for it at the location(s) passed to this option.
  26. * You might use this for instance to specify a path to a library which
  27. * you want to be referenced simply and relatively in the less files. */
  28. paths: [],
  29. /* color output in the terminal */
  30. color: true,
  31. /* The strictImports controls whether the compiler will allow an @import inside of either
  32. * @media blocks or (a later addition) other selector blocks.
  33. * See: https://github.com/less/less.js/issues/656 */
  34. strictImports: false,
  35. /* Allow Imports from Insecure HTTPS Hosts */
  36. insecure: false,
  37. /* Allows you to add a path to every generated import and url in your css.
  38. * This does not affect less import statements that are processed, just ones
  39. * that are left in the output css. */
  40. rootpath: "",
  41. /* By default URLs are kept as-is, so if you import a file in a sub-directory
  42. * that references an image, exactly the same URL will be output in the css.
  43. * This option allows you to re-write URL's in imported files so that the
  44. * URL is always relative to the base imported file */
  45. rewriteUrls: false,
  46. /* How to process math
  47. * 0 always - eagerly try to solve all operations
  48. * 1 parens-division - require parens for division "/"
  49. * 2 parens | strict - require parens for all operations
  50. * 3 strict-legacy - legacy strict behavior (super-strict)
  51. */
  52. math: 1,
  53. /* Without this option, less attempts to guess at the output unit when it does maths. */
  54. strictUnits: false,
  55. /* Effectively the declaration is put at the top of your base Less file,
  56. * meaning it can be used but it also can be overridden if this variable
  57. * is defined in the file. */
  58. globalVars: null,
  59. /* As opposed to the global variable option, this puts the declaration at the
  60. * end of your base file, meaning it will override anything defined in your Less file. */
  61. modifyVars: null,
  62. /* This option allows you to specify a argument to go on to every URL. */
  63. urlArgs: ""
  64. };
  65. }
  66. function extractId(href) {
  67. return href.replace(/^[a-z-]+:\/+?[^\/]+/, "").replace(/[\?\&]livereload=\w+/, "").replace(/^\//, "").replace(/\.[a-zA-Z]+$/, "").replace(/[^\.\w-]+/g, "-").replace(/\./g, ":");
  68. }
  69. function addDataAttr(options2, tag) {
  70. if (!tag) {
  71. return;
  72. }
  73. for (var opt in tag.dataset) {
  74. if (tag.dataset.hasOwnProperty(opt)) {
  75. if (opt === "env" || opt === "dumpLineNumbers" || opt === "rootpath" || opt === "errorReporting") {
  76. options2[opt] = tag.dataset[opt];
  77. } else {
  78. try {
  79. options2[opt] = JSON.parse(tag.dataset[opt]);
  80. } catch (_) {
  81. }
  82. }
  83. }
  84. }
  85. }
  86. var browser = {
  87. createCSS: function(document2, styles, sheet) {
  88. var href = sheet.href || "";
  89. var id = "less:" + (sheet.title || extractId(href));
  90. var oldStyleNode = document2.getElementById(id);
  91. var keepOldStyleNode = false;
  92. var styleNode = document2.createElement("style");
  93. styleNode.setAttribute("type", "text/css");
  94. if (sheet.media) {
  95. styleNode.setAttribute("media", sheet.media);
  96. }
  97. styleNode.id = id;
  98. if (!styleNode.styleSheet) {
  99. styleNode.appendChild(document2.createTextNode(styles));
  100. keepOldStyleNode = oldStyleNode !== null && oldStyleNode.childNodes.length > 0 && styleNode.childNodes.length > 0 && oldStyleNode.firstChild.nodeValue === styleNode.firstChild.nodeValue;
  101. }
  102. var head2 = document2.getElementsByTagName("head")[0];
  103. if (oldStyleNode === null || keepOldStyleNode === false) {
  104. var nextEl = sheet && sheet.nextSibling || null;
  105. if (nextEl) {
  106. nextEl.parentNode.insertBefore(styleNode, nextEl);
  107. } else {
  108. head2.appendChild(styleNode);
  109. }
  110. }
  111. if (oldStyleNode && keepOldStyleNode === false) {
  112. oldStyleNode.parentNode.removeChild(oldStyleNode);
  113. }
  114. if (styleNode.styleSheet) {
  115. try {
  116. styleNode.styleSheet.cssText = styles;
  117. } catch (e) {
  118. throw new Error("Couldn't reassign styleSheet.cssText.");
  119. }
  120. }
  121. },
  122. currentScript: function(window2) {
  123. var document2 = window2.document;
  124. return document2.currentScript || function() {
  125. var scripts = document2.getElementsByTagName("script");
  126. return scripts[scripts.length - 1];
  127. }();
  128. }
  129. };
  130. var addDefaultOptions = function(window2, options2) {
  131. addDataAttr(options2, browser.currentScript(window2));
  132. if (options2.isFileProtocol === void 0) {
  133. options2.isFileProtocol = /^(file|(chrome|safari)(-extension)?|resource|qrc|app):/.test(window2.location.protocol);
  134. }
  135. options2.async = options2.async || false;
  136. options2.fileAsync = options2.fileAsync || false;
  137. options2.poll = options2.poll || (options2.isFileProtocol ? 1e3 : 1500);
  138. options2.env = options2.env || (window2.location.hostname == "127.0.0.1" || window2.location.hostname == "0.0.0.0" || window2.location.hostname == "localhost" || window2.location.port && window2.location.port.length > 0 || options2.isFileProtocol ? "development" : "production");
  139. var dumpLineNumbers = /!dumpLineNumbers:(comments|mediaquery|all)/.exec(window2.location.hash);
  140. if (dumpLineNumbers) {
  141. options2.dumpLineNumbers = dumpLineNumbers[1];
  142. }
  143. if (options2.useFileCache === void 0) {
  144. options2.useFileCache = true;
  145. }
  146. if (options2.onReady === void 0) {
  147. options2.onReady = true;
  148. }
  149. if (options2.relativeUrls) {
  150. options2.rewriteUrls = "all";
  151. }
  152. };
  153. var logger$1 = {
  154. error: function(msg) {
  155. this._fireEvent("error", msg);
  156. },
  157. warn: function(msg) {
  158. this._fireEvent("warn", msg);
  159. },
  160. info: function(msg) {
  161. this._fireEvent("info", msg);
  162. },
  163. debug: function(msg) {
  164. this._fireEvent("debug", msg);
  165. },
  166. addListener: function(listener) {
  167. this._listeners.push(listener);
  168. },
  169. removeListener: function(listener) {
  170. for (var i = 0; i < this._listeners.length; i++) {
  171. if (this._listeners[i] === listener) {
  172. this._listeners.splice(i, 1);
  173. return;
  174. }
  175. }
  176. },
  177. _fireEvent: function(type, msg) {
  178. for (var i = 0; i < this._listeners.length; i++) {
  179. var logFunction = this._listeners[i][type];
  180. if (logFunction) {
  181. logFunction(msg);
  182. }
  183. }
  184. },
  185. _listeners: []
  186. };
  187. var Environment = (
  188. /** @class */
  189. function() {
  190. function Environment2(externalEnvironment, fileManagers) {
  191. this.fileManagers = fileManagers || [];
  192. externalEnvironment = externalEnvironment || {};
  193. var optionalFunctions = ["encodeBase64", "mimeLookup", "charsetLookup", "getSourceMapGenerator"];
  194. var requiredFunctions = [];
  195. var functions2 = requiredFunctions.concat(optionalFunctions);
  196. for (var i = 0; i < functions2.length; i++) {
  197. var propName = functions2[i];
  198. var environmentFunc = externalEnvironment[propName];
  199. if (environmentFunc) {
  200. this[propName] = environmentFunc.bind(externalEnvironment);
  201. } else if (i < requiredFunctions.length) {
  202. this.warn("missing required function in environment - " + propName);
  203. }
  204. }
  205. }
  206. Environment2.prototype.getFileManager = function(filename, currentDirectory, options2, environment, isSync) {
  207. if (!filename) {
  208. logger$1.warn("getFileManager called with no filename.. Please report this issue. continuing.");
  209. }
  210. if (currentDirectory == null) {
  211. logger$1.warn("getFileManager called with null directory.. Please report this issue. continuing.");
  212. }
  213. var fileManagers = this.fileManagers;
  214. if (options2.pluginManager) {
  215. fileManagers = [].concat(fileManagers).concat(options2.pluginManager.getFileManagers());
  216. }
  217. for (var i = fileManagers.length - 1; i >= 0; i--) {
  218. var fileManager = fileManagers[i];
  219. if (fileManager[isSync ? "supportsSync" : "supports"](filename, currentDirectory, options2, environment)) {
  220. return fileManager;
  221. }
  222. }
  223. return null;
  224. };
  225. Environment2.prototype.addFileManager = function(fileManager) {
  226. this.fileManagers.push(fileManager);
  227. };
  228. Environment2.prototype.clearFileManagers = function() {
  229. this.fileManagers = [];
  230. };
  231. return Environment2;
  232. }()
  233. );
  234. var colors = {
  235. "aliceblue": "#f0f8ff",
  236. "antiquewhite": "#faebd7",
  237. "aqua": "#00ffff",
  238. "aquamarine": "#7fffd4",
  239. "azure": "#f0ffff",
  240. "beige": "#f5f5dc",
  241. "bisque": "#ffe4c4",
  242. "black": "#000000",
  243. "blanchedalmond": "#ffebcd",
  244. "blue": "#0000ff",
  245. "blueviolet": "#8a2be2",
  246. "brown": "#a52a2a",
  247. "burlywood": "#deb887",
  248. "cadetblue": "#5f9ea0",
  249. "chartreuse": "#7fff00",
  250. "chocolate": "#d2691e",
  251. "coral": "#ff7f50",
  252. "cornflowerblue": "#6495ed",
  253. "cornsilk": "#fff8dc",
  254. "crimson": "#dc143c",
  255. "cyan": "#00ffff",
  256. "darkblue": "#00008b",
  257. "darkcyan": "#008b8b",
  258. "darkgoldenrod": "#b8860b",
  259. "darkgray": "#a9a9a9",
  260. "darkgrey": "#a9a9a9",
  261. "darkgreen": "#006400",
  262. "darkkhaki": "#bdb76b",
  263. "darkmagenta": "#8b008b",
  264. "darkolivegreen": "#556b2f",
  265. "darkorange": "#ff8c00",
  266. "darkorchid": "#9932cc",
  267. "darkred": "#8b0000",
  268. "darksalmon": "#e9967a",
  269. "darkseagreen": "#8fbc8f",
  270. "darkslateblue": "#483d8b",
  271. "darkslategray": "#2f4f4f",
  272. "darkslategrey": "#2f4f4f",
  273. "darkturquoise": "#00ced1",
  274. "darkviolet": "#9400d3",
  275. "deeppink": "#ff1493",
  276. "deepskyblue": "#00bfff",
  277. "dimgray": "#696969",
  278. "dimgrey": "#696969",
  279. "dodgerblue": "#1e90ff",
  280. "firebrick": "#b22222",
  281. "floralwhite": "#fffaf0",
  282. "forestgreen": "#228b22",
  283. "fuchsia": "#ff00ff",
  284. "gainsboro": "#dcdcdc",
  285. "ghostwhite": "#f8f8ff",
  286. "gold": "#ffd700",
  287. "goldenrod": "#daa520",
  288. "gray": "#808080",
  289. "grey": "#808080",
  290. "green": "#008000",
  291. "greenyellow": "#adff2f",
  292. "honeydew": "#f0fff0",
  293. "hotpink": "#ff69b4",
  294. "indianred": "#cd5c5c",
  295. "indigo": "#4b0082",
  296. "ivory": "#fffff0",
  297. "khaki": "#f0e68c",
  298. "lavender": "#e6e6fa",
  299. "lavenderblush": "#fff0f5",
  300. "lawngreen": "#7cfc00",
  301. "lemonchiffon": "#fffacd",
  302. "lightblue": "#add8e6",
  303. "lightcoral": "#f08080",
  304. "lightcyan": "#e0ffff",
  305. "lightgoldenrodyellow": "#fafad2",
  306. "lightgray": "#d3d3d3",
  307. "lightgrey": "#d3d3d3",
  308. "lightgreen": "#90ee90",
  309. "lightpink": "#ffb6c1",
  310. "lightsalmon": "#ffa07a",
  311. "lightseagreen": "#20b2aa",
  312. "lightskyblue": "#87cefa",
  313. "lightslategray": "#778899",
  314. "lightslategrey": "#778899",
  315. "lightsteelblue": "#b0c4de",
  316. "lightyellow": "#ffffe0",
  317. "lime": "#00ff00",
  318. "limegreen": "#32cd32",
  319. "linen": "#faf0e6",
  320. "magenta": "#ff00ff",
  321. "maroon": "#800000",
  322. "mediumaquamarine": "#66cdaa",
  323. "mediumblue": "#0000cd",
  324. "mediumorchid": "#ba55d3",
  325. "mediumpurple": "#9370d8",
  326. "mediumseagreen": "#3cb371",
  327. "mediumslateblue": "#7b68ee",
  328. "mediumspringgreen": "#00fa9a",
  329. "mediumturquoise": "#48d1cc",
  330. "mediumvioletred": "#c71585",
  331. "midnightblue": "#191970",
  332. "mintcream": "#f5fffa",
  333. "mistyrose": "#ffe4e1",
  334. "moccasin": "#ffe4b5",
  335. "navajowhite": "#ffdead",
  336. "navy": "#000080",
  337. "oldlace": "#fdf5e6",
  338. "olive": "#808000",
  339. "olivedrab": "#6b8e23",
  340. "orange": "#ffa500",
  341. "orangered": "#ff4500",
  342. "orchid": "#da70d6",
  343. "palegoldenrod": "#eee8aa",
  344. "palegreen": "#98fb98",
  345. "paleturquoise": "#afeeee",
  346. "palevioletred": "#d87093",
  347. "papayawhip": "#ffefd5",
  348. "peachpuff": "#ffdab9",
  349. "peru": "#cd853f",
  350. "pink": "#ffc0cb",
  351. "plum": "#dda0dd",
  352. "powderblue": "#b0e0e6",
  353. "purple": "#800080",
  354. "rebeccapurple": "#663399",
  355. "red": "#ff0000",
  356. "rosybrown": "#bc8f8f",
  357. "royalblue": "#4169e1",
  358. "saddlebrown": "#8b4513",
  359. "salmon": "#fa8072",
  360. "sandybrown": "#f4a460",
  361. "seagreen": "#2e8b57",
  362. "seashell": "#fff5ee",
  363. "sienna": "#a0522d",
  364. "silver": "#c0c0c0",
  365. "skyblue": "#87ceeb",
  366. "slateblue": "#6a5acd",
  367. "slategray": "#708090",
  368. "slategrey": "#708090",
  369. "snow": "#fffafa",
  370. "springgreen": "#00ff7f",
  371. "steelblue": "#4682b4",
  372. "tan": "#d2b48c",
  373. "teal": "#008080",
  374. "thistle": "#d8bfd8",
  375. "tomato": "#ff6347",
  376. "turquoise": "#40e0d0",
  377. "violet": "#ee82ee",
  378. "wheat": "#f5deb3",
  379. "white": "#ffffff",
  380. "whitesmoke": "#f5f5f5",
  381. "yellow": "#ffff00",
  382. "yellowgreen": "#9acd32"
  383. };
  384. var unitConversions = {
  385. length: {
  386. "m": 1,
  387. "cm": 0.01,
  388. "mm": 1e-3,
  389. "in": 0.0254,
  390. "px": 0.0254 / 96,
  391. "pt": 0.0254 / 72,
  392. "pc": 0.0254 / 72 * 12
  393. },
  394. duration: {
  395. "s": 1,
  396. "ms": 1e-3
  397. },
  398. angle: {
  399. "rad": 1 / (2 * Math.PI),
  400. "deg": 1 / 360,
  401. "grad": 1 / 400,
  402. "turn": 1
  403. }
  404. };
  405. var data = { colors, unitConversions };
  406. var Node = (
  407. /** @class */
  408. function() {
  409. function Node2() {
  410. this.parent = null;
  411. this.visibilityBlocks = void 0;
  412. this.nodeVisible = void 0;
  413. this.rootNode = null;
  414. this.parsed = null;
  415. }
  416. Object.defineProperty(Node2.prototype, "currentFileInfo", {
  417. get: function() {
  418. return this.fileInfo();
  419. },
  420. enumerable: false,
  421. configurable: true
  422. });
  423. Object.defineProperty(Node2.prototype, "index", {
  424. get: function() {
  425. return this.getIndex();
  426. },
  427. enumerable: false,
  428. configurable: true
  429. });
  430. Node2.prototype.setParent = function(nodes, parent) {
  431. function set(node) {
  432. if (node && node instanceof Node2) {
  433. node.parent = parent;
  434. }
  435. }
  436. if (Array.isArray(nodes)) {
  437. nodes.forEach(set);
  438. } else {
  439. set(nodes);
  440. }
  441. };
  442. Node2.prototype.getIndex = function() {
  443. return this._index || this.parent && this.parent.getIndex() || 0;
  444. };
  445. Node2.prototype.fileInfo = function() {
  446. return this._fileInfo || this.parent && this.parent.fileInfo() || {};
  447. };
  448. Node2.prototype.isRulesetLike = function() {
  449. return false;
  450. };
  451. Node2.prototype.toCSS = function(context) {
  452. var strs = [];
  453. this.genCSS(context, {
  454. add: function(chunk, fileInfo, index) {
  455. strs.push(chunk);
  456. },
  457. isEmpty: function() {
  458. return strs.length === 0;
  459. }
  460. });
  461. return strs.join("");
  462. };
  463. Node2.prototype.genCSS = function(context, output) {
  464. output.add(this.value);
  465. };
  466. Node2.prototype.accept = function(visitor) {
  467. this.value = visitor.visit(this.value);
  468. };
  469. Node2.prototype.eval = function() {
  470. return this;
  471. };
  472. Node2.prototype._operate = function(context, op, a, b) {
  473. switch (op) {
  474. case "+":
  475. return a + b;
  476. case "-":
  477. return a - b;
  478. case "*":
  479. return a * b;
  480. case "/":
  481. return a / b;
  482. }
  483. };
  484. Node2.prototype.fround = function(context, value) {
  485. var precision = context && context.numPrecision;
  486. return precision ? Number((value + 2e-16).toFixed(precision)) : value;
  487. };
  488. Node2.compare = function(a, b) {
  489. if (a.compare && // for "symmetric results" force toCSS-based comparison
  490. // of Quoted or Anonymous if either value is one of those
  491. !(b.type === "Quoted" || b.type === "Anonymous")) {
  492. return a.compare(b);
  493. } else if (b.compare) {
  494. return -b.compare(a);
  495. } else if (a.type !== b.type) {
  496. return void 0;
  497. }
  498. a = a.value;
  499. b = b.value;
  500. if (!Array.isArray(a)) {
  501. return a === b ? 0 : void 0;
  502. }
  503. if (a.length !== b.length) {
  504. return void 0;
  505. }
  506. for (var i = 0; i < a.length; i++) {
  507. if (Node2.compare(a[i], b[i]) !== 0) {
  508. return void 0;
  509. }
  510. }
  511. return 0;
  512. };
  513. Node2.numericCompare = function(a, b) {
  514. return a < b ? -1 : a === b ? 0 : a > b ? 1 : void 0;
  515. };
  516. Node2.prototype.blocksVisibility = function() {
  517. if (this.visibilityBlocks == null) {
  518. this.visibilityBlocks = 0;
  519. }
  520. return this.visibilityBlocks !== 0;
  521. };
  522. Node2.prototype.addVisibilityBlock = function() {
  523. if (this.visibilityBlocks == null) {
  524. this.visibilityBlocks = 0;
  525. }
  526. this.visibilityBlocks = this.visibilityBlocks + 1;
  527. };
  528. Node2.prototype.removeVisibilityBlock = function() {
  529. if (this.visibilityBlocks == null) {
  530. this.visibilityBlocks = 0;
  531. }
  532. this.visibilityBlocks = this.visibilityBlocks - 1;
  533. };
  534. Node2.prototype.ensureVisibility = function() {
  535. this.nodeVisible = true;
  536. };
  537. Node2.prototype.ensureInvisibility = function() {
  538. this.nodeVisible = false;
  539. };
  540. Node2.prototype.isVisible = function() {
  541. return this.nodeVisible;
  542. };
  543. Node2.prototype.visibilityInfo = function() {
  544. return {
  545. visibilityBlocks: this.visibilityBlocks,
  546. nodeVisible: this.nodeVisible
  547. };
  548. };
  549. Node2.prototype.copyVisibilityInfo = function(info) {
  550. if (!info) {
  551. return;
  552. }
  553. this.visibilityBlocks = info.visibilityBlocks;
  554. this.nodeVisible = info.nodeVisible;
  555. };
  556. return Node2;
  557. }()
  558. );
  559. var Color = function(rgb, a, originalForm) {
  560. var self2 = this;
  561. if (Array.isArray(rgb)) {
  562. this.rgb = rgb;
  563. } else if (rgb.length >= 6) {
  564. this.rgb = [];
  565. rgb.match(/.{2}/g).map(function(c, i) {
  566. if (i < 3) {
  567. self2.rgb.push(parseInt(c, 16));
  568. } else {
  569. self2.alpha = parseInt(c, 16) / 255;
  570. }
  571. });
  572. } else {
  573. this.rgb = [];
  574. rgb.split("").map(function(c, i) {
  575. if (i < 3) {
  576. self2.rgb.push(parseInt(c + c, 16));
  577. } else {
  578. self2.alpha = parseInt(c + c, 16) / 255;
  579. }
  580. });
  581. }
  582. this.alpha = this.alpha || (typeof a === "number" ? a : 1);
  583. if (typeof originalForm !== "undefined") {
  584. this.value = originalForm;
  585. }
  586. };
  587. Color.prototype = Object.assign(new Node(), {
  588. type: "Color",
  589. luma: function() {
  590. var r = this.rgb[0] / 255, g = this.rgb[1] / 255, b = this.rgb[2] / 255;
  591. r = r <= 0.03928 ? r / 12.92 : Math.pow((r + 0.055) / 1.055, 2.4);
  592. g = g <= 0.03928 ? g / 12.92 : Math.pow((g + 0.055) / 1.055, 2.4);
  593. b = b <= 0.03928 ? b / 12.92 : Math.pow((b + 0.055) / 1.055, 2.4);
  594. return 0.2126 * r + 0.7152 * g + 0.0722 * b;
  595. },
  596. genCSS: function(context, output) {
  597. output.add(this.toCSS(context));
  598. },
  599. toCSS: function(context, doNotCompress) {
  600. var compress = context && context.compress && !doNotCompress;
  601. var color2;
  602. var alpha;
  603. var colorFunction;
  604. var args = [];
  605. alpha = this.fround(context, this.alpha);
  606. if (this.value) {
  607. if (this.value.indexOf("rgb") === 0) {
  608. if (alpha < 1) {
  609. colorFunction = "rgba";
  610. }
  611. } else if (this.value.indexOf("hsl") === 0) {
  612. if (alpha < 1) {
  613. colorFunction = "hsla";
  614. } else {
  615. colorFunction = "hsl";
  616. }
  617. } else {
  618. return this.value;
  619. }
  620. } else {
  621. if (alpha < 1) {
  622. colorFunction = "rgba";
  623. }
  624. }
  625. switch (colorFunction) {
  626. case "rgba":
  627. args = this.rgb.map(function(c) {
  628. return clamp$1(Math.round(c), 255);
  629. }).concat(clamp$1(alpha, 1));
  630. break;
  631. case "hsla":
  632. args.push(clamp$1(alpha, 1));
  633. case "hsl":
  634. color2 = this.toHSL();
  635. args = [
  636. this.fround(context, color2.h),
  637. this.fround(context, color2.s * 100) + "%",
  638. this.fround(context, color2.l * 100) + "%"
  639. ].concat(args);
  640. }
  641. if (colorFunction) {
  642. return colorFunction + "(" + args.join("," + (compress ? "" : " ")) + ")";
  643. }
  644. color2 = this.toRGB();
  645. if (compress) {
  646. var splitcolor = color2.split("");
  647. if (splitcolor[1] === splitcolor[2] && splitcolor[3] === splitcolor[4] && splitcolor[5] === splitcolor[6]) {
  648. color2 = "#" + splitcolor[1] + splitcolor[3] + splitcolor[5];
  649. }
  650. }
  651. return color2;
  652. },
  653. //
  654. // Operations have to be done per-channel, if not,
  655. // channels will spill onto each other. Once we have
  656. // our result, in the form of an integer triplet,
  657. // we create a new Color node to hold the result.
  658. //
  659. operate: function(context, op, other) {
  660. var rgb = new Array(3);
  661. var alpha = this.alpha * (1 - other.alpha) + other.alpha;
  662. for (var c = 0; c < 3; c++) {
  663. rgb[c] = this._operate(context, op, this.rgb[c], other.rgb[c]);
  664. }
  665. return new Color(rgb, alpha);
  666. },
  667. toRGB: function() {
  668. return toHex(this.rgb);
  669. },
  670. toHSL: function() {
  671. var r = this.rgb[0] / 255, g = this.rgb[1] / 255, b = this.rgb[2] / 255, a = this.alpha;
  672. var max = Math.max(r, g, b), min = Math.min(r, g, b);
  673. var h;
  674. var s;
  675. var l = (max + min) / 2;
  676. var d = max - min;
  677. if (max === min) {
  678. h = s = 0;
  679. } else {
  680. s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
  681. switch (max) {
  682. case r:
  683. h = (g - b) / d + (g < b ? 6 : 0);
  684. break;
  685. case g:
  686. h = (b - r) / d + 2;
  687. break;
  688. case b:
  689. h = (r - g) / d + 4;
  690. break;
  691. }
  692. h /= 6;
  693. }
  694. return { h: h * 360, s, l, a };
  695. },
  696. // Adapted from http://mjijackson.com/2008/02/rgb-to-hsl-and-rgb-to-hsv-color-model-conversion-algorithms-in-javascript
  697. toHSV: function() {
  698. var r = this.rgb[0] / 255, g = this.rgb[1] / 255, b = this.rgb[2] / 255, a = this.alpha;
  699. var max = Math.max(r, g, b), min = Math.min(r, g, b);
  700. var h;
  701. var s;
  702. var v = max;
  703. var d = max - min;
  704. if (max === 0) {
  705. s = 0;
  706. } else {
  707. s = d / max;
  708. }
  709. if (max === min) {
  710. h = 0;
  711. } else {
  712. switch (max) {
  713. case r:
  714. h = (g - b) / d + (g < b ? 6 : 0);
  715. break;
  716. case g:
  717. h = (b - r) / d + 2;
  718. break;
  719. case b:
  720. h = (r - g) / d + 4;
  721. break;
  722. }
  723. h /= 6;
  724. }
  725. return { h: h * 360, s, v, a };
  726. },
  727. toARGB: function() {
  728. return toHex([this.alpha * 255].concat(this.rgb));
  729. },
  730. compare: function(x) {
  731. 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 : void 0;
  732. }
  733. });
  734. Color.fromKeyword = function(keyword) {
  735. var c;
  736. var key2 = keyword.toLowerCase();
  737. if (colors.hasOwnProperty(key2)) {
  738. c = new Color(colors[key2].slice(1));
  739. } else if (key2 === "transparent") {
  740. c = new Color([0, 0, 0], 0);
  741. }
  742. if (c) {
  743. c.value = keyword;
  744. return c;
  745. }
  746. };
  747. function clamp$1(v, max) {
  748. return Math.min(Math.max(v, 0), max);
  749. }
  750. function toHex(v) {
  751. return "#" + v.map(function(c) {
  752. c = clamp$1(Math.round(c), 255);
  753. return (c < 16 ? "0" : "") + c.toString(16);
  754. }).join("");
  755. }
  756. var Paren = function(node) {
  757. this.value = node;
  758. };
  759. Paren.prototype = Object.assign(new Node(), {
  760. type: "Paren",
  761. genCSS: function(context, output) {
  762. output.add("(");
  763. this.value.genCSS(context, output);
  764. output.add(")");
  765. },
  766. eval: function(context) {
  767. return new Paren(this.value.eval(context));
  768. }
  769. });
  770. var _noSpaceCombinators = {
  771. "": true,
  772. " ": true,
  773. "|": true
  774. };
  775. var Combinator = function(value) {
  776. if (value === " ") {
  777. this.value = " ";
  778. this.emptyOrWhitespace = true;
  779. } else {
  780. this.value = value ? value.trim() : "";
  781. this.emptyOrWhitespace = this.value === "";
  782. }
  783. };
  784. Combinator.prototype = Object.assign(new Node(), {
  785. type: "Combinator",
  786. genCSS: function(context, output) {
  787. var spaceOrEmpty = context.compress || _noSpaceCombinators[this.value] ? "" : " ";
  788. output.add(spaceOrEmpty + this.value + spaceOrEmpty);
  789. }
  790. });
  791. var Element = function(combinator, value, isVariable, index, currentFileInfo, visibilityInfo) {
  792. this.combinator = combinator instanceof Combinator ? combinator : new Combinator(combinator);
  793. if (typeof value === "string") {
  794. this.value = value.trim();
  795. } else if (value) {
  796. this.value = value;
  797. } else {
  798. this.value = "";
  799. }
  800. this.isVariable = isVariable;
  801. this._index = index;
  802. this._fileInfo = currentFileInfo;
  803. this.copyVisibilityInfo(visibilityInfo);
  804. this.setParent(this.combinator, this);
  805. };
  806. Element.prototype = Object.assign(new Node(), {
  807. type: "Element",
  808. accept: function(visitor) {
  809. var value = this.value;
  810. this.combinator = visitor.visit(this.combinator);
  811. if (typeof value === "object") {
  812. this.value = visitor.visit(value);
  813. }
  814. },
  815. eval: function(context) {
  816. return new Element(this.combinator, this.value.eval ? this.value.eval(context) : this.value, this.isVariable, this.getIndex(), this.fileInfo(), this.visibilityInfo());
  817. },
  818. clone: function() {
  819. return new Element(this.combinator, this.value, this.isVariable, this.getIndex(), this.fileInfo(), this.visibilityInfo());
  820. },
  821. genCSS: function(context, output) {
  822. output.add(this.toCSS(context), this.fileInfo(), this.getIndex());
  823. },
  824. toCSS: function(context) {
  825. context = context || {};
  826. var value = this.value;
  827. var firstSelector = context.firstSelector;
  828. if (value instanceof Paren) {
  829. context.firstSelector = true;
  830. }
  831. value = value.toCSS ? value.toCSS(context) : value;
  832. context.firstSelector = firstSelector;
  833. if (value === "" && this.combinator.value.charAt(0) === "&") {
  834. return "";
  835. } else {
  836. return this.combinator.toCSS(context) + value;
  837. }
  838. }
  839. });
  840. var Math$1 = {
  841. ALWAYS: 0,
  842. PARENS_DIVISION: 1,
  843. PARENS: 2
  844. // removed - STRICT_LEGACY: 3
  845. };
  846. var RewriteUrls = {
  847. OFF: 0,
  848. LOCAL: 1,
  849. ALL: 2
  850. };
  851. function getType(payload) {
  852. return Object.prototype.toString.call(payload).slice(8, -1);
  853. }
  854. function isPlainObject(payload) {
  855. if (getType(payload) !== "Object")
  856. return false;
  857. return payload.constructor === Object && Object.getPrototypeOf(payload) === Object.prototype;
  858. }
  859. function isArray(payload) {
  860. return getType(payload) === "Array";
  861. }
  862. function __spreadArrays() {
  863. for (var s = 0, i = 0, il = arguments.length; i < il; i++)
  864. s += arguments[i].length;
  865. for (var r = Array(s), k = 0, i = 0; i < il; i++)
  866. for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
  867. r[k] = a[j];
  868. return r;
  869. }
  870. function assignProp(carry, key2, newVal, originalObject, includeNonenumerable) {
  871. var propType = {}.propertyIsEnumerable.call(originalObject, key2) ? "enumerable" : "nonenumerable";
  872. if (propType === "enumerable")
  873. carry[key2] = newVal;
  874. if (includeNonenumerable && propType === "nonenumerable") {
  875. Object.defineProperty(carry, key2, {
  876. value: newVal,
  877. enumerable: false,
  878. writable: true,
  879. configurable: true
  880. });
  881. }
  882. }
  883. function copy(target, options2) {
  884. if (options2 === void 0) {
  885. options2 = {};
  886. }
  887. if (isArray(target))
  888. return target.map(function(i) {
  889. return copy(i, options2);
  890. });
  891. if (!isPlainObject(target))
  892. return target;
  893. var props = Object.getOwnPropertyNames(target);
  894. var symbols = Object.getOwnPropertySymbols(target);
  895. return __spreadArrays(props, symbols).reduce(function(carry, key2) {
  896. if (isArray(options2.props) && !options2.props.includes(key2)) {
  897. return carry;
  898. }
  899. var val = target[key2];
  900. var newVal = copy(val, options2);
  901. assignProp(carry, key2, newVal, target, options2.nonenumerable);
  902. return carry;
  903. }, {});
  904. }
  905. function getLocation(index, inputStream) {
  906. var n = index + 1;
  907. var line = null;
  908. var column = -1;
  909. while (--n >= 0 && inputStream.charAt(n) !== "\n") {
  910. column++;
  911. }
  912. if (typeof index === "number") {
  913. line = (inputStream.slice(0, index).match(/\n/g) || "").length;
  914. }
  915. return {
  916. line,
  917. column
  918. };
  919. }
  920. function copyArray(arr) {
  921. var i;
  922. var length = arr.length;
  923. var copy2 = new Array(length);
  924. for (i = 0; i < length; i++) {
  925. copy2[i] = arr[i];
  926. }
  927. return copy2;
  928. }
  929. function clone(obj) {
  930. var cloned = {};
  931. for (var prop in obj) {
  932. if (obj.hasOwnProperty(prop)) {
  933. cloned[prop] = obj[prop];
  934. }
  935. }
  936. return cloned;
  937. }
  938. function defaults(obj1, obj2) {
  939. var newObj = obj2 || {};
  940. if (!obj2._defaults) {
  941. newObj = {};
  942. var defaults_1 = copy(obj1);
  943. newObj._defaults = defaults_1;
  944. var cloned = obj2 ? copy(obj2) : {};
  945. Object.assign(newObj, defaults_1, cloned);
  946. }
  947. return newObj;
  948. }
  949. function copyOptions(obj1, obj2) {
  950. if (obj2 && obj2._defaults) {
  951. return obj2;
  952. }
  953. var opts = defaults(obj1, obj2);
  954. if (opts.strictMath) {
  955. opts.math = Math$1.PARENS;
  956. }
  957. if (opts.relativeUrls) {
  958. opts.rewriteUrls = RewriteUrls.ALL;
  959. }
  960. if (typeof opts.math === "string") {
  961. switch (opts.math.toLowerCase()) {
  962. case "always":
  963. opts.math = Math$1.ALWAYS;
  964. break;
  965. case "parens-division":
  966. opts.math = Math$1.PARENS_DIVISION;
  967. break;
  968. case "strict":
  969. case "parens":
  970. opts.math = Math$1.PARENS;
  971. break;
  972. default:
  973. opts.math = Math$1.PARENS;
  974. }
  975. }
  976. if (typeof opts.rewriteUrls === "string") {
  977. switch (opts.rewriteUrls.toLowerCase()) {
  978. case "off":
  979. opts.rewriteUrls = RewriteUrls.OFF;
  980. break;
  981. case "local":
  982. opts.rewriteUrls = RewriteUrls.LOCAL;
  983. break;
  984. case "all":
  985. opts.rewriteUrls = RewriteUrls.ALL;
  986. break;
  987. }
  988. }
  989. return opts;
  990. }
  991. function merge(obj1, obj2) {
  992. for (var prop in obj2) {
  993. if (obj2.hasOwnProperty(prop)) {
  994. obj1[prop] = obj2[prop];
  995. }
  996. }
  997. return obj1;
  998. }
  999. function flattenArray(arr, result) {
  1000. if (result === void 0) {
  1001. result = [];
  1002. }
  1003. for (var i = 0, length_1 = arr.length; i < length_1; i++) {
  1004. var value = arr[i];
  1005. if (Array.isArray(value)) {
  1006. flattenArray(value, result);
  1007. } else {
  1008. if (value !== void 0) {
  1009. result.push(value);
  1010. }
  1011. }
  1012. }
  1013. return result;
  1014. }
  1015. var utils = Object.freeze({
  1016. __proto__: null,
  1017. getLocation,
  1018. copyArray,
  1019. clone,
  1020. defaults,
  1021. copyOptions,
  1022. merge,
  1023. flattenArray
  1024. });
  1025. var anonymousFunc = /(<anonymous>|Function):(\d+):(\d+)/;
  1026. var LessError = function(e, fileContentMap, currentFilename) {
  1027. Error.call(this);
  1028. var filename = e.filename || currentFilename;
  1029. this.message = e.message;
  1030. this.stack = e.stack;
  1031. if (fileContentMap && filename) {
  1032. var input = fileContentMap.contents[filename];
  1033. var loc = getLocation(e.index, input);
  1034. var line = loc.line;
  1035. var col = loc.column;
  1036. var callLine = e.call && getLocation(e.call, input).line;
  1037. var lines = input ? input.split("\n") : "";
  1038. this.type = e.type || "Syntax";
  1039. this.filename = filename;
  1040. this.index = e.index;
  1041. this.line = typeof line === "number" ? line + 1 : null;
  1042. this.column = col;
  1043. if (!this.line && this.stack) {
  1044. var found = this.stack.match(anonymousFunc);
  1045. var func = new Function("a", "throw new Error()");
  1046. var lineAdjust = 0;
  1047. try {
  1048. func();
  1049. } catch (e2) {
  1050. var match = e2.stack.match(anonymousFunc);
  1051. var line = parseInt(match[2]);
  1052. lineAdjust = 1 - line;
  1053. }
  1054. if (found) {
  1055. if (found[2]) {
  1056. this.line = parseInt(found[2]) + lineAdjust;
  1057. }
  1058. if (found[3]) {
  1059. this.column = parseInt(found[3]);
  1060. }
  1061. }
  1062. }
  1063. this.callLine = callLine + 1;
  1064. this.callExtract = lines[callLine];
  1065. this.extract = [
  1066. lines[this.line - 2],
  1067. lines[this.line - 1],
  1068. lines[this.line]
  1069. ];
  1070. }
  1071. };
  1072. if (typeof Object.create === "undefined") {
  1073. var F = function() {
  1074. };
  1075. F.prototype = Error.prototype;
  1076. LessError.prototype = new F();
  1077. } else {
  1078. LessError.prototype = Object.create(Error.prototype);
  1079. }
  1080. LessError.prototype.constructor = LessError;
  1081. LessError.prototype.toString = function(options2) {
  1082. options2 = options2 || {};
  1083. var message = "";
  1084. var extract = this.extract || [];
  1085. var error = [];
  1086. var stylize = function(str) {
  1087. return str;
  1088. };
  1089. if (options2.stylize) {
  1090. var type = typeof options2.stylize;
  1091. if (type !== "function") {
  1092. throw Error("options.stylize should be a function, got a " + type + "!");
  1093. }
  1094. stylize = options2.stylize;
  1095. }
  1096. if (this.line !== null) {
  1097. if (typeof extract[0] === "string") {
  1098. error.push(stylize(this.line - 1 + " " + extract[0], "grey"));
  1099. }
  1100. if (typeof extract[1] === "string") {
  1101. var errorTxt = this.line + " ";
  1102. if (extract[1]) {
  1103. 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");
  1104. }
  1105. error.push(errorTxt);
  1106. }
  1107. if (typeof extract[2] === "string") {
  1108. error.push(stylize(this.line + 1 + " " + extract[2], "grey"));
  1109. }
  1110. error = error.join("\n") + stylize("", "reset") + "\n";
  1111. }
  1112. message += stylize(this.type + "Error: " + this.message, "red");
  1113. if (this.filename) {
  1114. message += stylize(" in ", "red") + this.filename;
  1115. }
  1116. if (this.line) {
  1117. message += stylize(" on line " + this.line + ", column " + (this.column + 1) + ":", "grey");
  1118. }
  1119. message += "\n" + error;
  1120. if (this.callLine) {
  1121. message += stylize("from ", "red") + (this.filename || "") + "/n";
  1122. message += stylize(this.callLine, "grey") + " " + this.callExtract + "/n";
  1123. }
  1124. return message;
  1125. };
  1126. var Selector = function(elements, extendList, condition, index, currentFileInfo, visibilityInfo) {
  1127. this.extendList = extendList;
  1128. this.condition = condition;
  1129. this.evaldCondition = !condition;
  1130. this._index = index;
  1131. this._fileInfo = currentFileInfo;
  1132. this.elements = this.getElements(elements);
  1133. this.mixinElements_ = void 0;
  1134. this.copyVisibilityInfo(visibilityInfo);
  1135. this.setParent(this.elements, this);
  1136. };
  1137. Selector.prototype = Object.assign(new Node(), {
  1138. type: "Selector",
  1139. accept: function(visitor) {
  1140. if (this.elements) {
  1141. this.elements = visitor.visitArray(this.elements);
  1142. }
  1143. if (this.extendList) {
  1144. this.extendList = visitor.visitArray(this.extendList);
  1145. }
  1146. if (this.condition) {
  1147. this.condition = visitor.visit(this.condition);
  1148. }
  1149. },
  1150. createDerived: function(elements, extendList, evaldCondition) {
  1151. elements = this.getElements(elements);
  1152. var newSelector = new Selector(elements, extendList || this.extendList, null, this.getIndex(), this.fileInfo(), this.visibilityInfo());
  1153. newSelector.evaldCondition = evaldCondition != null ? evaldCondition : this.evaldCondition;
  1154. newSelector.mediaEmpty = this.mediaEmpty;
  1155. return newSelector;
  1156. },
  1157. getElements: function(els) {
  1158. if (!els) {
  1159. return [new Element("", "&", false, this._index, this._fileInfo)];
  1160. }
  1161. if (typeof els === "string") {
  1162. this.parse.parseNode(els, ["selector"], this._index, this._fileInfo, function(err, result) {
  1163. if (err) {
  1164. throw new LessError({
  1165. index: err.index,
  1166. message: err.message
  1167. }, this.parse.imports, this._fileInfo.filename);
  1168. }
  1169. els = result[0].elements;
  1170. });
  1171. }
  1172. return els;
  1173. },
  1174. createEmptySelectors: function() {
  1175. var el = new Element("", "&", false, this._index, this._fileInfo), sels = [new Selector([el], null, null, this._index, this._fileInfo)];
  1176. sels[0].mediaEmpty = true;
  1177. return sels;
  1178. },
  1179. match: function(other) {
  1180. var elements = this.elements;
  1181. var len = elements.length;
  1182. var olen;
  1183. var i;
  1184. other = other.mixinElements();
  1185. olen = other.length;
  1186. if (olen === 0 || len < olen) {
  1187. return 0;
  1188. } else {
  1189. for (i = 0; i < olen; i++) {
  1190. if (elements[i].value !== other[i]) {
  1191. return 0;
  1192. }
  1193. }
  1194. }
  1195. return olen;
  1196. },
  1197. mixinElements: function() {
  1198. if (this.mixinElements_) {
  1199. return this.mixinElements_;
  1200. }
  1201. var elements = this.elements.map(function(v) {
  1202. return v.combinator.value + (v.value.value || v.value);
  1203. }).join("").match(/[,&#\*\.\w-]([\w-]|(\\.))*/g);
  1204. if (elements) {
  1205. if (elements[0] === "&") {
  1206. elements.shift();
  1207. }
  1208. } else {
  1209. elements = [];
  1210. }
  1211. return this.mixinElements_ = elements;
  1212. },
  1213. isJustParentSelector: function() {
  1214. return !this.mediaEmpty && this.elements.length === 1 && this.elements[0].value === "&" && (this.elements[0].combinator.value === " " || this.elements[0].combinator.value === "");
  1215. },
  1216. eval: function(context) {
  1217. var evaldCondition = this.condition && this.condition.eval(context);
  1218. var elements = this.elements;
  1219. var extendList = this.extendList;
  1220. elements = elements && elements.map(function(e) {
  1221. return e.eval(context);
  1222. });
  1223. extendList = extendList && extendList.map(function(extend) {
  1224. return extend.eval(context);
  1225. });
  1226. return this.createDerived(elements, extendList, evaldCondition);
  1227. },
  1228. genCSS: function(context, output) {
  1229. var i, element;
  1230. if ((!context || !context.firstSelector) && this.elements[0].combinator.value === "") {
  1231. output.add(" ", this.fileInfo(), this.getIndex());
  1232. }
  1233. for (i = 0; i < this.elements.length; i++) {
  1234. element = this.elements[i];
  1235. element.genCSS(context, output);
  1236. }
  1237. },
  1238. getIsOutput: function() {
  1239. return this.evaldCondition;
  1240. }
  1241. });
  1242. var Value = function(value) {
  1243. if (!value) {
  1244. throw new Error("Value requires an array argument");
  1245. }
  1246. if (!Array.isArray(value)) {
  1247. this.value = [value];
  1248. } else {
  1249. this.value = value;
  1250. }
  1251. };
  1252. Value.prototype = Object.assign(new Node(), {
  1253. type: "Value",
  1254. accept: function(visitor) {
  1255. if (this.value) {
  1256. this.value = visitor.visitArray(this.value);
  1257. }
  1258. },
  1259. eval: function(context) {
  1260. if (this.value.length === 1) {
  1261. return this.value[0].eval(context);
  1262. } else {
  1263. return new Value(this.value.map(function(v) {
  1264. return v.eval(context);
  1265. }));
  1266. }
  1267. },
  1268. genCSS: function(context, output) {
  1269. var i;
  1270. for (i = 0; i < this.value.length; i++) {
  1271. this.value[i].genCSS(context, output);
  1272. if (i + 1 < this.value.length) {
  1273. output.add(context && context.compress ? "," : ", ");
  1274. }
  1275. }
  1276. }
  1277. });
  1278. var Keyword = function(value) {
  1279. this.value = value;
  1280. };
  1281. Keyword.prototype = Object.assign(new Node(), {
  1282. type: "Keyword",
  1283. genCSS: function(context, output) {
  1284. if (this.value === "%") {
  1285. throw { type: "Syntax", message: "Invalid % without number" };
  1286. }
  1287. output.add(this.value);
  1288. }
  1289. });
  1290. Keyword.True = new Keyword("true");
  1291. Keyword.False = new Keyword("false");
  1292. var Anonymous = function(value, index, currentFileInfo, mapLines, rulesetLike, visibilityInfo) {
  1293. this.value = value;
  1294. this._index = index;
  1295. this._fileInfo = currentFileInfo;
  1296. this.mapLines = mapLines;
  1297. this.rulesetLike = typeof rulesetLike === "undefined" ? false : rulesetLike;
  1298. this.allowRoot = true;
  1299. this.copyVisibilityInfo(visibilityInfo);
  1300. };
  1301. Anonymous.prototype = Object.assign(new Node(), {
  1302. type: "Anonymous",
  1303. eval: function() {
  1304. return new Anonymous(this.value, this._index, this._fileInfo, this.mapLines, this.rulesetLike, this.visibilityInfo());
  1305. },
  1306. compare: function(other) {
  1307. return other.toCSS && this.toCSS() === other.toCSS() ? 0 : void 0;
  1308. },
  1309. isRulesetLike: function() {
  1310. return this.rulesetLike;
  1311. },
  1312. genCSS: function(context, output) {
  1313. this.nodeVisible = Boolean(this.value);
  1314. if (this.nodeVisible) {
  1315. output.add(this.value, this._fileInfo, this._index, this.mapLines);
  1316. }
  1317. }
  1318. });
  1319. var MATH$1 = Math$1;
  1320. function evalName(context, name) {
  1321. var value = "";
  1322. var i;
  1323. var n = name.length;
  1324. var output = { add: function(s) {
  1325. value += s;
  1326. } };
  1327. for (i = 0; i < n; i++) {
  1328. name[i].eval(context).genCSS(context, output);
  1329. }
  1330. return value;
  1331. }
  1332. var Declaration = function(name, value, important, merge2, index, currentFileInfo, inline, variable) {
  1333. this.name = name;
  1334. this.value = value instanceof Node ? value : new Value([value ? new Anonymous(value) : null]);
  1335. this.important = important ? " " + important.trim() : "";
  1336. this.merge = merge2;
  1337. this._index = index;
  1338. this._fileInfo = currentFileInfo;
  1339. this.inline = inline || false;
  1340. this.variable = variable !== void 0 ? variable : name.charAt && name.charAt(0) === "@";
  1341. this.allowRoot = true;
  1342. this.setParent(this.value, this);
  1343. };
  1344. Declaration.prototype = Object.assign(new Node(), {
  1345. type: "Declaration",
  1346. genCSS: function(context, output) {
  1347. output.add(this.name + (context.compress ? ":" : ": "), this.fileInfo(), this.getIndex());
  1348. try {
  1349. this.value.genCSS(context, output);
  1350. } catch (e) {
  1351. e.index = this._index;
  1352. e.filename = this._fileInfo.filename;
  1353. throw e;
  1354. }
  1355. output.add(this.important + (this.inline || context.lastRule && context.compress ? "" : ";"), this._fileInfo, this._index);
  1356. },
  1357. eval: function(context) {
  1358. var mathBypass = false, prevMath, name = this.name, evaldValue, variable = this.variable;
  1359. if (typeof name !== "string") {
  1360. name = name.length === 1 && name[0] instanceof Keyword ? name[0].value : evalName(context, name);
  1361. variable = false;
  1362. }
  1363. if (name === "font" && context.math === MATH$1.ALWAYS) {
  1364. mathBypass = true;
  1365. prevMath = context.math;
  1366. context.math = MATH$1.PARENS_DIVISION;
  1367. }
  1368. try {
  1369. context.importantScope.push({});
  1370. evaldValue = this.value.eval(context);
  1371. if (!this.variable && evaldValue.type === "DetachedRuleset") {
  1372. throw {
  1373. message: "Rulesets cannot be evaluated on a property.",
  1374. index: this.getIndex(),
  1375. filename: this.fileInfo().filename
  1376. };
  1377. }
  1378. var important = this.important;
  1379. var importantResult = context.importantScope.pop();
  1380. if (!important && importantResult.important) {
  1381. important = importantResult.important;
  1382. }
  1383. return new Declaration(name, evaldValue, important, this.merge, this.getIndex(), this.fileInfo(), this.inline, variable);
  1384. } catch (e) {
  1385. if (typeof e.index !== "number") {
  1386. e.index = this.getIndex();
  1387. e.filename = this.fileInfo().filename;
  1388. }
  1389. throw e;
  1390. } finally {
  1391. if (mathBypass) {
  1392. context.math = prevMath;
  1393. }
  1394. }
  1395. },
  1396. makeImportant: function() {
  1397. return new Declaration(this.name, this.value, "!important", this.merge, this.getIndex(), this.fileInfo(), this.inline);
  1398. }
  1399. });
  1400. function asComment(ctx) {
  1401. return "/* line " + ctx.debugInfo.lineNumber + ", " + ctx.debugInfo.fileName + " */\n";
  1402. }
  1403. function asMediaQuery(ctx) {
  1404. var filenameWithProtocol = ctx.debugInfo.fileName;
  1405. if (!/^[a-z]+:\/\//i.test(filenameWithProtocol)) {
  1406. filenameWithProtocol = "file://" + filenameWithProtocol;
  1407. }
  1408. return "@media -sass-debug-info{filename{font-family:" + filenameWithProtocol.replace(/([.:\/\\])/g, function(a) {
  1409. if (a == "\\") {
  1410. a = "/";
  1411. }
  1412. return "\\" + a;
  1413. }) + "}line{font-family:\\00003" + ctx.debugInfo.lineNumber + "}}\n";
  1414. }
  1415. function debugInfo(context, ctx, lineSeparator) {
  1416. var result = "";
  1417. if (context.dumpLineNumbers && !context.compress) {
  1418. switch (context.dumpLineNumbers) {
  1419. case "comments":
  1420. result = asComment(ctx);
  1421. break;
  1422. case "mediaquery":
  1423. result = asMediaQuery(ctx);
  1424. break;
  1425. case "all":
  1426. result = asComment(ctx) + (lineSeparator || "") + asMediaQuery(ctx);
  1427. break;
  1428. }
  1429. }
  1430. return result;
  1431. }
  1432. var Comment = function(value, isLineComment, index, currentFileInfo) {
  1433. this.value = value;
  1434. this.isLineComment = isLineComment;
  1435. this._index = index;
  1436. this._fileInfo = currentFileInfo;
  1437. this.allowRoot = true;
  1438. };
  1439. Comment.prototype = Object.assign(new Node(), {
  1440. type: "Comment",
  1441. genCSS: function(context, output) {
  1442. if (this.debugInfo) {
  1443. output.add(debugInfo(context, this), this.fileInfo(), this.getIndex());
  1444. }
  1445. output.add(this.value);
  1446. },
  1447. isSilent: function(context) {
  1448. var isCompressed = context.compress && this.value[2] !== "!";
  1449. return this.isLineComment || isCompressed;
  1450. }
  1451. });
  1452. var contexts = {};
  1453. var copyFromOriginal = function copyFromOriginal2(original, destination, propertiesToCopy) {
  1454. if (!original) {
  1455. return;
  1456. }
  1457. for (var i = 0; i < propertiesToCopy.length; i++) {
  1458. if (original.hasOwnProperty(propertiesToCopy[i])) {
  1459. destination[propertiesToCopy[i]] = original[propertiesToCopy[i]];
  1460. }
  1461. }
  1462. };
  1463. var parseCopyProperties = [
  1464. // options
  1465. "paths",
  1466. "rewriteUrls",
  1467. "rootpath",
  1468. "strictImports",
  1469. "insecure",
  1470. "dumpLineNumbers",
  1471. "compress",
  1472. "syncImport",
  1473. "chunkInput",
  1474. "mime",
  1475. "useFileCache",
  1476. // context
  1477. "processImports",
  1478. // Used by the import manager to stop multiple import visitors being created.
  1479. "pluginManager"
  1480. // Used as the plugin manager for the session
  1481. ];
  1482. contexts.Parse = function(options2) {
  1483. copyFromOriginal(options2, this, parseCopyProperties);
  1484. if (typeof this.paths === "string") {
  1485. this.paths = [this.paths];
  1486. }
  1487. };
  1488. var evalCopyProperties = [
  1489. "paths",
  1490. "compress",
  1491. "math",
  1492. "strictUnits",
  1493. "sourceMap",
  1494. "importMultiple",
  1495. "urlArgs",
  1496. "javascriptEnabled",
  1497. "pluginManager",
  1498. "importantScope",
  1499. "rewriteUrls"
  1500. // option - whether to adjust URL's to be relative
  1501. ];
  1502. contexts.Eval = function(options2, frames) {
  1503. copyFromOriginal(options2, this, evalCopyProperties);
  1504. if (typeof this.paths === "string") {
  1505. this.paths = [this.paths];
  1506. }
  1507. this.frames = frames || [];
  1508. this.importantScope = this.importantScope || [];
  1509. };
  1510. contexts.Eval.prototype.enterCalc = function() {
  1511. if (!this.calcStack) {
  1512. this.calcStack = [];
  1513. }
  1514. this.calcStack.push(true);
  1515. this.inCalc = true;
  1516. };
  1517. contexts.Eval.prototype.exitCalc = function() {
  1518. this.calcStack.pop();
  1519. if (!this.calcStack.length) {
  1520. this.inCalc = false;
  1521. }
  1522. };
  1523. contexts.Eval.prototype.inParenthesis = function() {
  1524. if (!this.parensStack) {
  1525. this.parensStack = [];
  1526. }
  1527. this.parensStack.push(true);
  1528. };
  1529. contexts.Eval.prototype.outOfParenthesis = function() {
  1530. this.parensStack.pop();
  1531. };
  1532. contexts.Eval.prototype.inCalc = false;
  1533. contexts.Eval.prototype.mathOn = true;
  1534. contexts.Eval.prototype.isMathOn = function(op) {
  1535. if (!this.mathOn) {
  1536. return false;
  1537. }
  1538. if (op === "/" && this.math !== Math$1.ALWAYS && (!this.parensStack || !this.parensStack.length)) {
  1539. return false;
  1540. }
  1541. if (this.math > Math$1.PARENS_DIVISION) {
  1542. return this.parensStack && this.parensStack.length;
  1543. }
  1544. return true;
  1545. };
  1546. contexts.Eval.prototype.pathRequiresRewrite = function(path) {
  1547. var isRelative = this.rewriteUrls === RewriteUrls.LOCAL ? isPathLocalRelative : isPathRelative;
  1548. return isRelative(path);
  1549. };
  1550. contexts.Eval.prototype.rewritePath = function(path, rootpath) {
  1551. var newPath;
  1552. rootpath = rootpath || "";
  1553. newPath = this.normalizePath(rootpath + path);
  1554. if (isPathLocalRelative(path) && isPathRelative(rootpath) && isPathLocalRelative(newPath) === false) {
  1555. newPath = "./" + newPath;
  1556. }
  1557. return newPath;
  1558. };
  1559. contexts.Eval.prototype.normalizePath = function(path) {
  1560. var segments = path.split("/").reverse();
  1561. var segment;
  1562. path = [];
  1563. while (segments.length !== 0) {
  1564. segment = segments.pop();
  1565. switch (segment) {
  1566. case ".":
  1567. break;
  1568. case "..":
  1569. if (path.length === 0 || path[path.length - 1] === "..") {
  1570. path.push(segment);
  1571. } else {
  1572. path.pop();
  1573. }
  1574. break;
  1575. default:
  1576. path.push(segment);
  1577. break;
  1578. }
  1579. }
  1580. return path.join("/");
  1581. };
  1582. function isPathRelative(path) {
  1583. return !/^(?:[a-z-]+:|\/|#)/i.test(path);
  1584. }
  1585. function isPathLocalRelative(path) {
  1586. return path.charAt(0) === ".";
  1587. }
  1588. function makeRegistry(base) {
  1589. return {
  1590. _data: {},
  1591. add: function(name, func) {
  1592. name = name.toLowerCase();
  1593. if (this._data.hasOwnProperty(name))
  1594. ;
  1595. this._data[name] = func;
  1596. },
  1597. addMultiple: function(functions2) {
  1598. var _this = this;
  1599. Object.keys(functions2).forEach(function(name) {
  1600. _this.add(name, functions2[name]);
  1601. });
  1602. },
  1603. get: function(name) {
  1604. return this._data[name] || base && base.get(name);
  1605. },
  1606. getLocalFunctions: function() {
  1607. return this._data;
  1608. },
  1609. inherit: function() {
  1610. return makeRegistry(this);
  1611. },
  1612. create: function(base2) {
  1613. return makeRegistry(base2);
  1614. }
  1615. };
  1616. }
  1617. var functionRegistry = makeRegistry(null);
  1618. var defaultFunc = {
  1619. eval: function() {
  1620. var v = this.value_;
  1621. var e = this.error_;
  1622. if (e) {
  1623. throw e;
  1624. }
  1625. if (v != null) {
  1626. return v ? Keyword.True : Keyword.False;
  1627. }
  1628. },
  1629. value: function(v) {
  1630. this.value_ = v;
  1631. },
  1632. error: function(e) {
  1633. this.error_ = e;
  1634. },
  1635. reset: function() {
  1636. this.value_ = this.error_ = null;
  1637. }
  1638. };
  1639. var Ruleset = function(selectors, rules, strictImports, visibilityInfo) {
  1640. this.selectors = selectors;
  1641. this.rules = rules;
  1642. this._lookups = {};
  1643. this._variables = null;
  1644. this._properties = null;
  1645. this.strictImports = strictImports;
  1646. this.copyVisibilityInfo(visibilityInfo);
  1647. this.allowRoot = true;
  1648. this.setParent(this.selectors, this);
  1649. this.setParent(this.rules, this);
  1650. };
  1651. Ruleset.prototype = Object.assign(new Node(), {
  1652. type: "Ruleset",
  1653. isRuleset: true,
  1654. isRulesetLike: function() {
  1655. return true;
  1656. },
  1657. accept: function(visitor) {
  1658. if (this.paths) {
  1659. this.paths = visitor.visitArray(this.paths, true);
  1660. } else if (this.selectors) {
  1661. this.selectors = visitor.visitArray(this.selectors);
  1662. }
  1663. if (this.rules && this.rules.length) {
  1664. this.rules = visitor.visitArray(this.rules);
  1665. }
  1666. },
  1667. eval: function(context) {
  1668. var selectors;
  1669. var selCnt;
  1670. var selector;
  1671. var i;
  1672. var hasVariable;
  1673. var hasOnePassingSelector = false;
  1674. if (this.selectors && (selCnt = this.selectors.length)) {
  1675. selectors = new Array(selCnt);
  1676. defaultFunc.error({
  1677. type: "Syntax",
  1678. message: "it is currently only allowed in parametric mixin guards,"
  1679. });
  1680. for (i = 0; i < selCnt; i++) {
  1681. selector = this.selectors[i].eval(context);
  1682. for (var j = 0; j < selector.elements.length; j++) {
  1683. if (selector.elements[j].isVariable) {
  1684. hasVariable = true;
  1685. break;
  1686. }
  1687. }
  1688. selectors[i] = selector;
  1689. if (selector.evaldCondition) {
  1690. hasOnePassingSelector = true;
  1691. }
  1692. }
  1693. if (hasVariable) {
  1694. var toParseSelectors = new Array(selCnt);
  1695. for (i = 0; i < selCnt; i++) {
  1696. selector = selectors[i];
  1697. toParseSelectors[i] = selector.toCSS(context);
  1698. }
  1699. this.parse.parseNode(toParseSelectors.join(","), ["selectors"], selectors[0].getIndex(), selectors[0].fileInfo(), function(err, result) {
  1700. if (result) {
  1701. selectors = flattenArray(result);
  1702. }
  1703. });
  1704. }
  1705. defaultFunc.reset();
  1706. } else {
  1707. hasOnePassingSelector = true;
  1708. }
  1709. var rules = this.rules ? copyArray(this.rules) : null;
  1710. var ruleset = new Ruleset(selectors, rules, this.strictImports, this.visibilityInfo());
  1711. var rule;
  1712. var subRule;
  1713. ruleset.originalRuleset = this;
  1714. ruleset.root = this.root;
  1715. ruleset.firstRoot = this.firstRoot;
  1716. ruleset.allowImports = this.allowImports;
  1717. if (this.debugInfo) {
  1718. ruleset.debugInfo = this.debugInfo;
  1719. }
  1720. if (!hasOnePassingSelector) {
  1721. rules.length = 0;
  1722. }
  1723. ruleset.functionRegistry = function(frames) {
  1724. var i2 = 0;
  1725. var n = frames.length;
  1726. var found;
  1727. for (; i2 !== n; ++i2) {
  1728. found = frames[i2].functionRegistry;
  1729. if (found) {
  1730. return found;
  1731. }
  1732. }
  1733. return functionRegistry;
  1734. }(context.frames).inherit();
  1735. var ctxFrames = context.frames;
  1736. ctxFrames.unshift(ruleset);
  1737. var ctxSelectors = context.selectors;
  1738. if (!ctxSelectors) {
  1739. context.selectors = ctxSelectors = [];
  1740. }
  1741. ctxSelectors.unshift(this.selectors);
  1742. if (ruleset.root || ruleset.allowImports || !ruleset.strictImports) {
  1743. ruleset.evalImports(context);
  1744. }
  1745. var rsRules = ruleset.rules;
  1746. for (i = 0; rule = rsRules[i]; i++) {
  1747. if (rule.evalFirst) {
  1748. rsRules[i] = rule.eval(context);
  1749. }
  1750. }
  1751. var mediaBlockCount = context.mediaBlocks && context.mediaBlocks.length || 0;
  1752. for (i = 0; rule = rsRules[i]; i++) {
  1753. if (rule.type === "MixinCall") {
  1754. rules = rule.eval(context).filter(function(r) {
  1755. if (r instanceof Declaration && r.variable) {
  1756. return !ruleset.variable(r.name);
  1757. }
  1758. return true;
  1759. });
  1760. rsRules.splice.apply(rsRules, [i, 1].concat(rules));
  1761. i += rules.length - 1;
  1762. ruleset.resetCache();
  1763. } else if (rule.type === "VariableCall") {
  1764. rules = rule.eval(context).rules.filter(function(r) {
  1765. if (r instanceof Declaration && r.variable) {
  1766. return false;
  1767. }
  1768. return true;
  1769. });
  1770. rsRules.splice.apply(rsRules, [i, 1].concat(rules));
  1771. i += rules.length - 1;
  1772. ruleset.resetCache();
  1773. }
  1774. }
  1775. for (i = 0; rule = rsRules[i]; i++) {
  1776. if (!rule.evalFirst) {
  1777. rsRules[i] = rule = rule.eval ? rule.eval(context) : rule;
  1778. }
  1779. }
  1780. for (i = 0; rule = rsRules[i]; i++) {
  1781. if (rule instanceof Ruleset && rule.selectors && rule.selectors.length === 1) {
  1782. if (rule.selectors[0] && rule.selectors[0].isJustParentSelector()) {
  1783. rsRules.splice(i--, 1);
  1784. for (var j = 0; subRule = rule.rules[j]; j++) {
  1785. if (subRule instanceof Node) {
  1786. subRule.copyVisibilityInfo(rule.visibilityInfo());
  1787. if (!(subRule instanceof Declaration) || !subRule.variable) {
  1788. rsRules.splice(++i, 0, subRule);
  1789. }
  1790. }
  1791. }
  1792. }
  1793. }
  1794. }
  1795. ctxFrames.shift();
  1796. ctxSelectors.shift();
  1797. if (context.mediaBlocks) {
  1798. for (i = mediaBlockCount; i < context.mediaBlocks.length; i++) {
  1799. context.mediaBlocks[i].bubbleSelectors(selectors);
  1800. }
  1801. }
  1802. return ruleset;
  1803. },
  1804. evalImports: function(context) {
  1805. var rules = this.rules;
  1806. var i;
  1807. var importRules;
  1808. if (!rules) {
  1809. return;
  1810. }
  1811. for (i = 0; i < rules.length; i++) {
  1812. if (rules[i].type === "Import") {
  1813. importRules = rules[i].eval(context);
  1814. if (importRules && (importRules.length || importRules.length === 0)) {
  1815. rules.splice.apply(rules, [i, 1].concat(importRules));
  1816. i += importRules.length - 1;
  1817. } else {
  1818. rules.splice(i, 1, importRules);
  1819. }
  1820. this.resetCache();
  1821. }
  1822. }
  1823. },
  1824. makeImportant: function() {
  1825. var result = new Ruleset(this.selectors, this.rules.map(function(r) {
  1826. if (r.makeImportant) {
  1827. return r.makeImportant();
  1828. } else {
  1829. return r;
  1830. }
  1831. }), this.strictImports, this.visibilityInfo());
  1832. return result;
  1833. },
  1834. matchArgs: function(args) {
  1835. return !args || args.length === 0;
  1836. },
  1837. // lets you call a css selector with a guard
  1838. matchCondition: function(args, context) {
  1839. var lastSelector = this.selectors[this.selectors.length - 1];
  1840. if (!lastSelector.evaldCondition) {
  1841. return false;
  1842. }
  1843. if (lastSelector.condition && !lastSelector.condition.eval(new contexts.Eval(context, context.frames))) {
  1844. return false;
  1845. }
  1846. return true;
  1847. },
  1848. resetCache: function() {
  1849. this._rulesets = null;
  1850. this._variables = null;
  1851. this._properties = null;
  1852. this._lookups = {};
  1853. },
  1854. variables: function() {
  1855. if (!this._variables) {
  1856. this._variables = !this.rules ? {} : this.rules.reduce(function(hash, r) {
  1857. if (r instanceof Declaration && r.variable === true) {
  1858. hash[r.name] = r;
  1859. }
  1860. if (r.type === "Import" && r.root && r.root.variables) {
  1861. var vars = r.root.variables();
  1862. for (var name_1 in vars) {
  1863. if (vars.hasOwnProperty(name_1)) {
  1864. hash[name_1] = r.root.variable(name_1);
  1865. }
  1866. }
  1867. }
  1868. return hash;
  1869. }, {});
  1870. }
  1871. return this._variables;
  1872. },
  1873. properties: function() {
  1874. if (!this._properties) {
  1875. this._properties = !this.rules ? {} : this.rules.reduce(function(hash, r) {
  1876. if (r instanceof Declaration && r.variable !== true) {
  1877. var name_2 = r.name.length === 1 && r.name[0] instanceof Keyword ? r.name[0].value : r.name;
  1878. if (!hash["$" + name_2]) {
  1879. hash["$" + name_2] = [r];
  1880. } else {
  1881. hash["$" + name_2].push(r);
  1882. }
  1883. }
  1884. return hash;
  1885. }, {});
  1886. }
  1887. return this._properties;
  1888. },
  1889. variable: function(name) {
  1890. var decl = this.variables()[name];
  1891. if (decl) {
  1892. return this.parseValue(decl);
  1893. }
  1894. },
  1895. property: function(name) {
  1896. var decl = this.properties()[name];
  1897. if (decl) {
  1898. return this.parseValue(decl);
  1899. }
  1900. },
  1901. lastDeclaration: function() {
  1902. for (var i = this.rules.length; i > 0; i--) {
  1903. var decl = this.rules[i - 1];
  1904. if (decl instanceof Declaration) {
  1905. return this.parseValue(decl);
  1906. }
  1907. }
  1908. },
  1909. parseValue: function(toParse) {
  1910. var self2 = this;
  1911. function transformDeclaration(decl) {
  1912. if (decl.value instanceof Anonymous && !decl.parsed) {
  1913. if (typeof decl.value.value === "string") {
  1914. this.parse.parseNode(decl.value.value, ["value", "important"], decl.value.getIndex(), decl.fileInfo(), function(err, result) {
  1915. if (err) {
  1916. decl.parsed = true;
  1917. }
  1918. if (result) {
  1919. decl.value = result[0];
  1920. decl.important = result[1] || "";
  1921. decl.parsed = true;
  1922. }
  1923. });
  1924. } else {
  1925. decl.parsed = true;
  1926. }
  1927. return decl;
  1928. } else {
  1929. return decl;
  1930. }
  1931. }
  1932. if (!Array.isArray(toParse)) {
  1933. return transformDeclaration.call(self2, toParse);
  1934. } else {
  1935. var nodes_1 = [];
  1936. toParse.forEach(function(n) {
  1937. nodes_1.push(transformDeclaration.call(self2, n));
  1938. });
  1939. return nodes_1;
  1940. }
  1941. },
  1942. rulesets: function() {
  1943. if (!this.rules) {
  1944. return [];
  1945. }
  1946. var filtRules = [];
  1947. var rules = this.rules;
  1948. var i;
  1949. var rule;
  1950. for (i = 0; rule = rules[i]; i++) {
  1951. if (rule.isRuleset) {
  1952. filtRules.push(rule);
  1953. }
  1954. }
  1955. return filtRules;
  1956. },
  1957. prependRule: function(rule) {
  1958. var rules = this.rules;
  1959. if (rules) {
  1960. rules.unshift(rule);
  1961. } else {
  1962. this.rules = [rule];
  1963. }
  1964. this.setParent(rule, this);
  1965. },
  1966. find: function(selector, self2, filter) {
  1967. self2 = self2 || this;
  1968. var rules = [];
  1969. var match;
  1970. var foundMixins;
  1971. var key2 = selector.toCSS();
  1972. if (key2 in this._lookups) {
  1973. return this._lookups[key2];
  1974. }
  1975. this.rulesets().forEach(function(rule) {
  1976. if (rule !== self2) {
  1977. for (var j = 0; j < rule.selectors.length; j++) {
  1978. match = selector.match(rule.selectors[j]);
  1979. if (match) {
  1980. if (selector.elements.length > match) {
  1981. if (!filter || filter(rule)) {
  1982. foundMixins = rule.find(new Selector(selector.elements.slice(match)), self2, filter);
  1983. for (var i = 0; i < foundMixins.length; ++i) {
  1984. foundMixins[i].path.push(rule);
  1985. }
  1986. Array.prototype.push.apply(rules, foundMixins);
  1987. }
  1988. } else {
  1989. rules.push({ rule, path: [] });
  1990. }
  1991. break;
  1992. }
  1993. }
  1994. }
  1995. });
  1996. this._lookups[key2] = rules;
  1997. return rules;
  1998. },
  1999. genCSS: function(context, output) {
  2000. var i;
  2001. var j;
  2002. var charsetRuleNodes = [];
  2003. var ruleNodes = [];
  2004. var debugInfo$1;
  2005. var rule;
  2006. var path;
  2007. context.tabLevel = context.tabLevel || 0;
  2008. if (!this.root) {
  2009. context.tabLevel++;
  2010. }
  2011. var tabRuleStr = context.compress ? "" : Array(context.tabLevel + 1).join(" ");
  2012. var tabSetStr = context.compress ? "" : Array(context.tabLevel).join(" ");
  2013. var sep;
  2014. var charsetNodeIndex = 0;
  2015. var importNodeIndex = 0;
  2016. for (i = 0; rule = this.rules[i]; i++) {
  2017. if (rule instanceof Comment) {
  2018. if (importNodeIndex === i) {
  2019. importNodeIndex++;
  2020. }
  2021. ruleNodes.push(rule);
  2022. } else if (rule.isCharset && rule.isCharset()) {
  2023. ruleNodes.splice(charsetNodeIndex, 0, rule);
  2024. charsetNodeIndex++;
  2025. importNodeIndex++;
  2026. } else if (rule.type === "Import") {
  2027. ruleNodes.splice(importNodeIndex, 0, rule);
  2028. importNodeIndex++;
  2029. } else {
  2030. ruleNodes.push(rule);
  2031. }
  2032. }
  2033. ruleNodes = charsetRuleNodes.concat(ruleNodes);
  2034. if (!this.root) {
  2035. debugInfo$1 = debugInfo(context, this, tabSetStr);
  2036. if (debugInfo$1) {
  2037. output.add(debugInfo$1);
  2038. output.add(tabSetStr);
  2039. }
  2040. var paths = this.paths;
  2041. var pathCnt = paths.length;
  2042. var pathSubCnt = void 0;
  2043. sep = context.compress ? "," : ",\n" + tabSetStr;
  2044. for (i = 0; i < pathCnt; i++) {
  2045. path = paths[i];
  2046. if (!(pathSubCnt = path.length)) {
  2047. continue;
  2048. }
  2049. if (i > 0) {
  2050. output.add(sep);
  2051. }
  2052. context.firstSelector = true;
  2053. path[0].genCSS(context, output);
  2054. context.firstSelector = false;
  2055. for (j = 1; j < pathSubCnt; j++) {
  2056. path[j].genCSS(context, output);
  2057. }
  2058. }
  2059. output.add((context.compress ? "{" : " {\n") + tabRuleStr);
  2060. }
  2061. for (i = 0; rule = ruleNodes[i]; i++) {
  2062. if (i + 1 === ruleNodes.length) {
  2063. context.lastRule = true;
  2064. }
  2065. var currentLastRule = context.lastRule;
  2066. if (rule.isRulesetLike(rule)) {
  2067. context.lastRule = false;
  2068. }
  2069. if (rule.genCSS) {
  2070. rule.genCSS(context, output);
  2071. } else if (rule.value) {
  2072. output.add(rule.value.toString());
  2073. }
  2074. context.lastRule = currentLastRule;
  2075. if (!context.lastRule && rule.isVisible()) {
  2076. output.add(context.compress ? "" : "\n" + tabRuleStr);
  2077. } else {
  2078. context.lastRule = false;
  2079. }
  2080. }
  2081. if (!this.root) {
  2082. output.add(context.compress ? "}" : "\n" + tabSetStr + "}");
  2083. context.tabLevel--;
  2084. }
  2085. if (!output.isEmpty() && !context.compress && this.firstRoot) {
  2086. output.add("\n");
  2087. }
  2088. },
  2089. joinSelectors: function(paths, context, selectors) {
  2090. for (var s = 0; s < selectors.length; s++) {
  2091. this.joinSelector(paths, context, selectors[s]);
  2092. }
  2093. },
  2094. joinSelector: function(paths, context, selector) {
  2095. function createParenthesis(elementsToPak, originalElement) {
  2096. var replacementParen, j;
  2097. if (elementsToPak.length === 0) {
  2098. replacementParen = new Paren(elementsToPak[0]);
  2099. } else {
  2100. var insideParent = new Array(elementsToPak.length);
  2101. for (j = 0; j < elementsToPak.length; j++) {
  2102. insideParent[j] = new Element(null, elementsToPak[j], originalElement.isVariable, originalElement._index, originalElement._fileInfo);
  2103. }
  2104. replacementParen = new Paren(new Selector(insideParent));
  2105. }
  2106. return replacementParen;
  2107. }
  2108. function createSelector(containedElement, originalElement) {
  2109. var element, selector2;
  2110. element = new Element(null, containedElement, originalElement.isVariable, originalElement._index, originalElement._fileInfo);
  2111. selector2 = new Selector([element]);
  2112. return selector2;
  2113. }
  2114. function addReplacementIntoPath(beginningPath, addPath, replacedElement, originalSelector) {
  2115. var newSelectorPath, lastSelector, newJoinedSelector;
  2116. newSelectorPath = [];
  2117. if (beginningPath.length > 0) {
  2118. newSelectorPath = copyArray(beginningPath);
  2119. lastSelector = newSelectorPath.pop();
  2120. newJoinedSelector = originalSelector.createDerived(copyArray(lastSelector.elements));
  2121. } else {
  2122. newJoinedSelector = originalSelector.createDerived([]);
  2123. }
  2124. if (addPath.length > 0) {
  2125. var combinator = replacedElement.combinator;
  2126. var parentEl = addPath[0].elements[0];
  2127. if (combinator.emptyOrWhitespace && !parentEl.combinator.emptyOrWhitespace) {
  2128. combinator = parentEl.combinator;
  2129. }
  2130. newJoinedSelector.elements.push(new Element(combinator, parentEl.value, replacedElement.isVariable, replacedElement._index, replacedElement._fileInfo));
  2131. newJoinedSelector.elements = newJoinedSelector.elements.concat(addPath[0].elements.slice(1));
  2132. }
  2133. if (newJoinedSelector.elements.length !== 0) {
  2134. newSelectorPath.push(newJoinedSelector);
  2135. }
  2136. if (addPath.length > 1) {
  2137. var restOfPath = addPath.slice(1);
  2138. restOfPath = restOfPath.map(function(selector2) {
  2139. return selector2.createDerived(selector2.elements, []);
  2140. });
  2141. newSelectorPath = newSelectorPath.concat(restOfPath);
  2142. }
  2143. return newSelectorPath;
  2144. }
  2145. function addAllReplacementsIntoPath(beginningPath, addPaths, replacedElement, originalSelector, result) {
  2146. var j;
  2147. for (j = 0; j < beginningPath.length; j++) {
  2148. var newSelectorPath = addReplacementIntoPath(beginningPath[j], addPaths, replacedElement, originalSelector);
  2149. result.push(newSelectorPath);
  2150. }
  2151. return result;
  2152. }
  2153. function mergeElementsOnToSelectors(elements, selectors) {
  2154. var i2, sel;
  2155. if (elements.length === 0) {
  2156. return;
  2157. }
  2158. if (selectors.length === 0) {
  2159. selectors.push([new Selector(elements)]);
  2160. return;
  2161. }
  2162. for (i2 = 0; sel = selectors[i2]; i2++) {
  2163. if (sel.length > 0) {
  2164. sel[sel.length - 1] = sel[sel.length - 1].createDerived(sel[sel.length - 1].elements.concat(elements));
  2165. } else {
  2166. sel.push(new Selector(elements));
  2167. }
  2168. }
  2169. }
  2170. function replaceParentSelector(paths2, context2, inSelector) {
  2171. var i2, j, k, currentElements, newSelectors, selectorsMultiplied, sel, el, hadParentSelector2 = false, length, lastSelector;
  2172. function findNestedSelector(element) {
  2173. var maybeSelector;
  2174. if (!(element.value instanceof Paren)) {
  2175. return null;
  2176. }
  2177. maybeSelector = element.value.value;
  2178. if (!(maybeSelector instanceof Selector)) {
  2179. return null;
  2180. }
  2181. return maybeSelector;
  2182. }
  2183. currentElements = [];
  2184. newSelectors = [
  2185. []
  2186. ];
  2187. for (i2 = 0; el = inSelector.elements[i2]; i2++) {
  2188. if (el.value !== "&") {
  2189. var nestedSelector = findNestedSelector(el);
  2190. if (nestedSelector != null) {
  2191. mergeElementsOnToSelectors(currentElements, newSelectors);
  2192. var nestedPaths = [];
  2193. var replaced = void 0;
  2194. var replacedNewSelectors = [];
  2195. replaced = replaceParentSelector(nestedPaths, context2, nestedSelector);
  2196. hadParentSelector2 = hadParentSelector2 || replaced;
  2197. for (k = 0; k < nestedPaths.length; k++) {
  2198. var replacementSelector = createSelector(createParenthesis(nestedPaths[k], el), el);
  2199. addAllReplacementsIntoPath(newSelectors, [replacementSelector], el, inSelector, replacedNewSelectors);
  2200. }
  2201. newSelectors = replacedNewSelectors;
  2202. currentElements = [];
  2203. } else {
  2204. currentElements.push(el);
  2205. }
  2206. } else {
  2207. hadParentSelector2 = true;
  2208. selectorsMultiplied = [];
  2209. mergeElementsOnToSelectors(currentElements, newSelectors);
  2210. for (j = 0; j < newSelectors.length; j++) {
  2211. sel = newSelectors[j];
  2212. if (context2.length === 0) {
  2213. if (sel.length > 0) {
  2214. sel[0].elements.push(new Element(el.combinator, "", el.isVariable, el._index, el._fileInfo));
  2215. }
  2216. selectorsMultiplied.push(sel);
  2217. } else {
  2218. for (k = 0; k < context2.length; k++) {
  2219. var newSelectorPath = addReplacementIntoPath(sel, context2[k], el, inSelector);
  2220. selectorsMultiplied.push(newSelectorPath);
  2221. }
  2222. }
  2223. }
  2224. newSelectors = selectorsMultiplied;
  2225. currentElements = [];
  2226. }
  2227. }
  2228. mergeElementsOnToSelectors(currentElements, newSelectors);
  2229. for (i2 = 0; i2 < newSelectors.length; i2++) {
  2230. length = newSelectors[i2].length;
  2231. if (length > 0) {
  2232. paths2.push(newSelectors[i2]);
  2233. lastSelector = newSelectors[i2][length - 1];
  2234. newSelectors[i2][length - 1] = lastSelector.createDerived(lastSelector.elements, inSelector.extendList);
  2235. }
  2236. }
  2237. return hadParentSelector2;
  2238. }
  2239. function deriveSelector(visibilityInfo, deriveFrom) {
  2240. var newSelector = deriveFrom.createDerived(deriveFrom.elements, deriveFrom.extendList, deriveFrom.evaldCondition);
  2241. newSelector.copyVisibilityInfo(visibilityInfo);
  2242. return newSelector;
  2243. }
  2244. var i, newPaths, hadParentSelector;
  2245. newPaths = [];
  2246. hadParentSelector = replaceParentSelector(newPaths, context, selector);
  2247. if (!hadParentSelector) {
  2248. if (context.length > 0) {
  2249. newPaths = [];
  2250. for (i = 0; i < context.length; i++) {
  2251. var concatenated = context[i].map(deriveSelector.bind(this, selector.visibilityInfo()));
  2252. concatenated.push(selector);
  2253. newPaths.push(concatenated);
  2254. }
  2255. } else {
  2256. newPaths = [[selector]];
  2257. }
  2258. }
  2259. for (i = 0; i < newPaths.length; i++) {
  2260. paths.push(newPaths[i]);
  2261. }
  2262. }
  2263. });
  2264. var AtRule = function(name, value, rules, index, currentFileInfo, debugInfo2, isRooted, visibilityInfo) {
  2265. var i;
  2266. this.name = name;
  2267. this.value = value instanceof Node ? value : value ? new Anonymous(value) : value;
  2268. if (rules) {
  2269. if (Array.isArray(rules)) {
  2270. this.rules = rules;
  2271. } else {
  2272. this.rules = [rules];
  2273. this.rules[0].selectors = new Selector([], null, null, index, currentFileInfo).createEmptySelectors();
  2274. }
  2275. for (i = 0; i < this.rules.length; i++) {
  2276. this.rules[i].allowImports = true;
  2277. }
  2278. this.setParent(this.rules, this);
  2279. }
  2280. this._index = index;
  2281. this._fileInfo = currentFileInfo;
  2282. this.debugInfo = debugInfo2;
  2283. this.isRooted = isRooted || false;
  2284. this.copyVisibilityInfo(visibilityInfo);
  2285. this.allowRoot = true;
  2286. };
  2287. AtRule.prototype = Object.assign(new Node(), {
  2288. type: "AtRule",
  2289. accept: function(visitor) {
  2290. var value = this.value, rules = this.rules;
  2291. if (rules) {
  2292. this.rules = visitor.visitArray(rules);
  2293. }
  2294. if (value) {
  2295. this.value = visitor.visit(value);
  2296. }
  2297. },
  2298. isRulesetLike: function() {
  2299. return this.rules || !this.isCharset();
  2300. },
  2301. isCharset: function() {
  2302. return "@charset" === this.name;
  2303. },
  2304. genCSS: function(context, output) {
  2305. var value = this.value, rules = this.rules;
  2306. output.add(this.name, this.fileInfo(), this.getIndex());
  2307. if (value) {
  2308. output.add(" ");
  2309. value.genCSS(context, output);
  2310. }
  2311. if (rules) {
  2312. this.outputRuleset(context, output, rules);
  2313. } else {
  2314. output.add(";");
  2315. }
  2316. },
  2317. eval: function(context) {
  2318. var mediaPathBackup, mediaBlocksBackup, value = this.value, rules = this.rules;
  2319. mediaPathBackup = context.mediaPath;
  2320. mediaBlocksBackup = context.mediaBlocks;
  2321. context.mediaPath = [];
  2322. context.mediaBlocks = [];
  2323. if (value) {
  2324. value = value.eval(context);
  2325. }
  2326. if (rules) {
  2327. rules = [rules[0].eval(context)];
  2328. rules[0].root = true;
  2329. }
  2330. context.mediaPath = mediaPathBackup;
  2331. context.mediaBlocks = mediaBlocksBackup;
  2332. return new AtRule(this.name, value, rules, this.getIndex(), this.fileInfo(), this.debugInfo, this.isRooted, this.visibilityInfo());
  2333. },
  2334. variable: function(name) {
  2335. if (this.rules) {
  2336. return Ruleset.prototype.variable.call(this.rules[0], name);
  2337. }
  2338. },
  2339. find: function() {
  2340. if (this.rules) {
  2341. return Ruleset.prototype.find.apply(this.rules[0], arguments);
  2342. }
  2343. },
  2344. rulesets: function() {
  2345. if (this.rules) {
  2346. return Ruleset.prototype.rulesets.apply(this.rules[0]);
  2347. }
  2348. },
  2349. outputRuleset: function(context, output, rules) {
  2350. var ruleCnt = rules.length;
  2351. var i;
  2352. context.tabLevel = (context.tabLevel | 0) + 1;
  2353. if (context.compress) {
  2354. output.add("{");
  2355. for (i = 0; i < ruleCnt; i++) {
  2356. rules[i].genCSS(context, output);
  2357. }
  2358. output.add("}");
  2359. context.tabLevel--;
  2360. return;
  2361. }
  2362. var tabSetStr = "\n" + Array(context.tabLevel).join(" "), tabRuleStr = tabSetStr + " ";
  2363. if (!ruleCnt) {
  2364. output.add(" {" + tabSetStr + "}");
  2365. } else {
  2366. output.add(" {" + tabRuleStr);
  2367. rules[0].genCSS(context, output);
  2368. for (i = 1; i < ruleCnt; i++) {
  2369. output.add(tabRuleStr);
  2370. rules[i].genCSS(context, output);
  2371. }
  2372. output.add(tabSetStr + "}");
  2373. }
  2374. context.tabLevel--;
  2375. }
  2376. });
  2377. var DetachedRuleset = function(ruleset, frames) {
  2378. this.ruleset = ruleset;
  2379. this.frames = frames;
  2380. this.setParent(this.ruleset, this);
  2381. };
  2382. DetachedRuleset.prototype = Object.assign(new Node(), {
  2383. type: "DetachedRuleset",
  2384. evalFirst: true,
  2385. accept: function(visitor) {
  2386. this.ruleset = visitor.visit(this.ruleset);
  2387. },
  2388. eval: function(context) {
  2389. var frames = this.frames || copyArray(context.frames);
  2390. return new DetachedRuleset(this.ruleset, frames);
  2391. },
  2392. callEval: function(context) {
  2393. return this.ruleset.eval(this.frames ? new contexts.Eval(context, this.frames.concat(context.frames)) : context);
  2394. }
  2395. });
  2396. var Unit = function(numerator, denominator, backupUnit) {
  2397. this.numerator = numerator ? copyArray(numerator).sort() : [];
  2398. this.denominator = denominator ? copyArray(denominator).sort() : [];
  2399. if (backupUnit) {
  2400. this.backupUnit = backupUnit;
  2401. } else if (numerator && numerator.length) {
  2402. this.backupUnit = numerator[0];
  2403. }
  2404. };
  2405. Unit.prototype = Object.assign(new Node(), {
  2406. type: "Unit",
  2407. clone: function() {
  2408. return new Unit(copyArray(this.numerator), copyArray(this.denominator), this.backupUnit);
  2409. },
  2410. genCSS: function(context, output) {
  2411. var strictUnits = context && context.strictUnits;
  2412. if (this.numerator.length === 1) {
  2413. output.add(this.numerator[0]);
  2414. } else if (!strictUnits && this.backupUnit) {
  2415. output.add(this.backupUnit);
  2416. } else if (!strictUnits && this.denominator.length) {
  2417. output.add(this.denominator[0]);
  2418. }
  2419. },
  2420. toString: function() {
  2421. var i, returnStr = this.numerator.join("*");
  2422. for (i = 0; i < this.denominator.length; i++) {
  2423. returnStr += "/" + this.denominator[i];
  2424. }
  2425. return returnStr;
  2426. },
  2427. compare: function(other) {
  2428. return this.is(other.toString()) ? 0 : void 0;
  2429. },
  2430. is: function(unitString) {
  2431. return this.toString().toUpperCase() === unitString.toUpperCase();
  2432. },
  2433. isLength: function() {
  2434. return RegExp("^(px|em|ex|ch|rem|in|cm|mm|pc|pt|ex|vw|vh|vmin|vmax)$", "gi").test(this.toCSS());
  2435. },
  2436. isEmpty: function() {
  2437. return this.numerator.length === 0 && this.denominator.length === 0;
  2438. },
  2439. isSingular: function() {
  2440. return this.numerator.length <= 1 && this.denominator.length === 0;
  2441. },
  2442. map: function(callback) {
  2443. var i;
  2444. for (i = 0; i < this.numerator.length; i++) {
  2445. this.numerator[i] = callback(this.numerator[i], false);
  2446. }
  2447. for (i = 0; i < this.denominator.length; i++) {
  2448. this.denominator[i] = callback(this.denominator[i], true);
  2449. }
  2450. },
  2451. usedUnits: function() {
  2452. var group;
  2453. var result = {};
  2454. var mapUnit;
  2455. var groupName;
  2456. mapUnit = function(atomicUnit) {
  2457. if (group.hasOwnProperty(atomicUnit) && !result[groupName]) {
  2458. result[groupName] = atomicUnit;
  2459. }
  2460. return atomicUnit;
  2461. };
  2462. for (groupName in unitConversions) {
  2463. if (unitConversions.hasOwnProperty(groupName)) {
  2464. group = unitConversions[groupName];
  2465. this.map(mapUnit);
  2466. }
  2467. }
  2468. return result;
  2469. },
  2470. cancel: function() {
  2471. var counter = {};
  2472. var atomicUnit;
  2473. var i;
  2474. for (i = 0; i < this.numerator.length; i++) {
  2475. atomicUnit = this.numerator[i];
  2476. counter[atomicUnit] = (counter[atomicUnit] || 0) + 1;
  2477. }
  2478. for (i = 0; i < this.denominator.length; i++) {
  2479. atomicUnit = this.denominator[i];
  2480. counter[atomicUnit] = (counter[atomicUnit] || 0) - 1;
  2481. }
  2482. this.numerator = [];
  2483. this.denominator = [];
  2484. for (atomicUnit in counter) {
  2485. if (counter.hasOwnProperty(atomicUnit)) {
  2486. var count = counter[atomicUnit];
  2487. if (count > 0) {
  2488. for (i = 0; i < count; i++) {
  2489. this.numerator.push(atomicUnit);
  2490. }
  2491. } else if (count < 0) {
  2492. for (i = 0; i < -count; i++) {
  2493. this.denominator.push(atomicUnit);
  2494. }
  2495. }
  2496. }
  2497. }
  2498. this.numerator.sort();
  2499. this.denominator.sort();
  2500. }
  2501. });
  2502. var Dimension = function(value, unit) {
  2503. this.value = parseFloat(value);
  2504. if (isNaN(this.value)) {
  2505. throw new Error("Dimension is not a number.");
  2506. }
  2507. this.unit = unit && unit instanceof Unit ? unit : new Unit(unit ? [unit] : void 0);
  2508. this.setParent(this.unit, this);
  2509. };
  2510. Dimension.prototype = Object.assign(new Node(), {
  2511. type: "Dimension",
  2512. accept: function(visitor) {
  2513. this.unit = visitor.visit(this.unit);
  2514. },
  2515. eval: function(context) {
  2516. return this;
  2517. },
  2518. toColor: function() {
  2519. return new Color([this.value, this.value, this.value]);
  2520. },
  2521. genCSS: function(context, output) {
  2522. if (context && context.strictUnits && !this.unit.isSingular()) {
  2523. throw new Error("Multiple units in dimension. Correct the units or use the unit function. Bad unit: " + this.unit.toString());
  2524. }
  2525. var value = this.fround(context, this.value);
  2526. var strValue = String(value);
  2527. if (value !== 0 && value < 1e-6 && value > -1e-6) {
  2528. strValue = value.toFixed(20).replace(/0+$/, "");
  2529. }
  2530. if (context && context.compress) {
  2531. if (value === 0 && this.unit.isLength()) {
  2532. output.add(strValue);
  2533. return;
  2534. }
  2535. if (value > 0 && value < 1) {
  2536. strValue = strValue.substr(1);
  2537. }
  2538. }
  2539. output.add(strValue);
  2540. this.unit.genCSS(context, output);
  2541. },
  2542. // In an operation between two Dimensions,
  2543. // we default to the first Dimension's unit,
  2544. // so `1px + 2` will yield `3px`.
  2545. operate: function(context, op, other) {
  2546. var value = this._operate(context, op, this.value, other.value);
  2547. var unit = this.unit.clone();
  2548. if (op === "+" || op === "-") {
  2549. if (unit.numerator.length === 0 && unit.denominator.length === 0) {
  2550. unit = other.unit.clone();
  2551. if (this.unit.backupUnit) {
  2552. unit.backupUnit = this.unit.backupUnit;
  2553. }
  2554. } else if (other.unit.numerator.length === 0 && unit.denominator.length === 0)
  2555. ;
  2556. else {
  2557. other = other.convertTo(this.unit.usedUnits());
  2558. if (context.strictUnits && other.unit.toString() !== unit.toString()) {
  2559. throw new Error("Incompatible units. Change the units or use the unit function. " + ("Bad units: '" + unit.toString() + "' and '" + other.unit.toString() + "'."));
  2560. }
  2561. value = this._operate(context, op, this.value, other.value);
  2562. }
  2563. } else if (op === "*") {
  2564. unit.numerator = unit.numerator.concat(other.unit.numerator).sort();
  2565. unit.denominator = unit.denominator.concat(other.unit.denominator).sort();
  2566. unit.cancel();
  2567. } else if (op === "/") {
  2568. unit.numerator = unit.numerator.concat(other.unit.denominator).sort();
  2569. unit.denominator = unit.denominator.concat(other.unit.numerator).sort();
  2570. unit.cancel();
  2571. }
  2572. return new Dimension(value, unit);
  2573. },
  2574. compare: function(other) {
  2575. var a, b;
  2576. if (!(other instanceof Dimension)) {
  2577. return void 0;
  2578. }
  2579. if (this.unit.isEmpty() || other.unit.isEmpty()) {
  2580. a = this;
  2581. b = other;
  2582. } else {
  2583. a = this.unify();
  2584. b = other.unify();
  2585. if (a.unit.compare(b.unit) !== 0) {
  2586. return void 0;
  2587. }
  2588. }
  2589. return Node.numericCompare(a.value, b.value);
  2590. },
  2591. unify: function() {
  2592. return this.convertTo({ length: "px", duration: "s", angle: "rad" });
  2593. },
  2594. convertTo: function(conversions) {
  2595. var value = this.value;
  2596. var unit = this.unit.clone();
  2597. var i;
  2598. var groupName;
  2599. var group;
  2600. var targetUnit;
  2601. var derivedConversions = {};
  2602. var applyUnit;
  2603. if (typeof conversions === "string") {
  2604. for (i in unitConversions) {
  2605. if (unitConversions[i].hasOwnProperty(conversions)) {
  2606. derivedConversions = {};
  2607. derivedConversions[i] = conversions;
  2608. }
  2609. }
  2610. conversions = derivedConversions;
  2611. }
  2612. applyUnit = function(atomicUnit, denominator) {
  2613. if (group.hasOwnProperty(atomicUnit)) {
  2614. if (denominator) {
  2615. value = value / (group[atomicUnit] / group[targetUnit]);
  2616. } else {
  2617. value = value * (group[atomicUnit] / group[targetUnit]);
  2618. }
  2619. return targetUnit;
  2620. }
  2621. return atomicUnit;
  2622. };
  2623. for (groupName in conversions) {
  2624. if (conversions.hasOwnProperty(groupName)) {
  2625. targetUnit = conversions[groupName];
  2626. group = unitConversions[groupName];
  2627. unit.map(applyUnit);
  2628. }
  2629. }
  2630. unit.cancel();
  2631. return new Dimension(value, unit);
  2632. }
  2633. });
  2634. var MATH = Math$1;
  2635. var Operation = function(op, operands, isSpaced) {
  2636. this.op = op.trim();
  2637. this.operands = operands;
  2638. this.isSpaced = isSpaced;
  2639. };
  2640. Operation.prototype = Object.assign(new Node(), {
  2641. type: "Operation",
  2642. accept: function(visitor) {
  2643. this.operands = visitor.visitArray(this.operands);
  2644. },
  2645. eval: function(context) {
  2646. var a = this.operands[0].eval(context), b = this.operands[1].eval(context), op;
  2647. if (context.isMathOn(this.op)) {
  2648. op = this.op === "./" ? "/" : this.op;
  2649. if (a instanceof Dimension && b instanceof Color) {
  2650. a = a.toColor();
  2651. }
  2652. if (b instanceof Dimension && a instanceof Color) {
  2653. b = b.toColor();
  2654. }
  2655. if (!a.operate || !b.operate) {
  2656. if ((a instanceof Operation || b instanceof Operation) && a.op === "/" && context.math === MATH.PARENS_DIVISION) {
  2657. return new Operation(this.op, [a, b], this.isSpaced);
  2658. }
  2659. throw {
  2660. type: "Operation",
  2661. message: "Operation on an invalid type"
  2662. };
  2663. }
  2664. return a.operate(context, op, b);
  2665. } else {
  2666. return new Operation(this.op, [a, b], this.isSpaced);
  2667. }
  2668. },
  2669. genCSS: function(context, output) {
  2670. this.operands[0].genCSS(context, output);
  2671. if (this.isSpaced) {
  2672. output.add(" ");
  2673. }
  2674. output.add(this.op);
  2675. if (this.isSpaced) {
  2676. output.add(" ");
  2677. }
  2678. this.operands[1].genCSS(context, output);
  2679. }
  2680. });
  2681. function __spreadArray(to, from, pack) {
  2682. if (pack || arguments.length === 2)
  2683. for (var i = 0, l = from.length, ar; i < l; i++) {
  2684. if (ar || !(i in from)) {
  2685. if (!ar)
  2686. ar = Array.prototype.slice.call(from, 0, i);
  2687. ar[i] = from[i];
  2688. }
  2689. }
  2690. return to.concat(ar || from);
  2691. }
  2692. var Expression = function(value, noSpacing) {
  2693. this.value = value;
  2694. this.noSpacing = noSpacing;
  2695. if (!value) {
  2696. throw new Error("Expression requires an array parameter");
  2697. }
  2698. };
  2699. Expression.prototype = Object.assign(new Node(), {
  2700. type: "Expression",
  2701. accept: function(visitor) {
  2702. this.value = visitor.visitArray(this.value);
  2703. },
  2704. eval: function(context) {
  2705. var returnValue;
  2706. var mathOn = context.isMathOn();
  2707. var inParenthesis = this.parens;
  2708. var doubleParen = false;
  2709. if (inParenthesis) {
  2710. context.inParenthesis();
  2711. }
  2712. if (this.value.length > 1) {
  2713. returnValue = new Expression(this.value.map(function(e) {
  2714. if (!e.eval) {
  2715. return e;
  2716. }
  2717. return e.eval(context);
  2718. }), this.noSpacing);
  2719. } else if (this.value.length === 1) {
  2720. if (this.value[0].parens && !this.value[0].parensInOp && !context.inCalc) {
  2721. doubleParen = true;
  2722. }
  2723. returnValue = this.value[0].eval(context);
  2724. } else {
  2725. returnValue = this;
  2726. }
  2727. if (inParenthesis) {
  2728. context.outOfParenthesis();
  2729. }
  2730. if (this.parens && this.parensInOp && !mathOn && !doubleParen && !(returnValue instanceof Dimension)) {
  2731. returnValue = new Paren(returnValue);
  2732. }
  2733. return returnValue;
  2734. },
  2735. genCSS: function(context, output) {
  2736. for (var i = 0; i < this.value.length; i++) {
  2737. this.value[i].genCSS(context, output);
  2738. if (!this.noSpacing && i + 1 < this.value.length) {
  2739. output.add(" ");
  2740. }
  2741. }
  2742. },
  2743. throwAwayComments: function() {
  2744. this.value = this.value.filter(function(v) {
  2745. return !(v instanceof Comment);
  2746. });
  2747. }
  2748. });
  2749. var functionCaller = (
  2750. /** @class */
  2751. function() {
  2752. function functionCaller2(name, context, index, currentFileInfo) {
  2753. this.name = name.toLowerCase();
  2754. this.index = index;
  2755. this.context = context;
  2756. this.currentFileInfo = currentFileInfo;
  2757. this.func = context.frames[0].functionRegistry.get(this.name);
  2758. }
  2759. functionCaller2.prototype.isValid = function() {
  2760. return Boolean(this.func);
  2761. };
  2762. functionCaller2.prototype.call = function(args) {
  2763. var _this = this;
  2764. if (!Array.isArray(args)) {
  2765. args = [args];
  2766. }
  2767. var evalArgs = this.func.evalArgs;
  2768. if (evalArgs !== false) {
  2769. args = args.map(function(a) {
  2770. return a.eval(_this.context);
  2771. });
  2772. }
  2773. var commentFilter = function(item) {
  2774. return !(item.type === "Comment");
  2775. };
  2776. args = args.filter(commentFilter).map(function(item) {
  2777. if (item.type === "Expression") {
  2778. var subNodes = item.value.filter(commentFilter);
  2779. if (subNodes.length === 1) {
  2780. if (item.parens && subNodes[0].op === "/") {
  2781. return item;
  2782. }
  2783. return subNodes[0];
  2784. } else {
  2785. return new Expression(subNodes);
  2786. }
  2787. }
  2788. return item;
  2789. });
  2790. if (evalArgs === false) {
  2791. return this.func.apply(this, __spreadArray([this.context], args));
  2792. }
  2793. return this.func.apply(this, args);
  2794. };
  2795. return functionCaller2;
  2796. }()
  2797. );
  2798. var Call = function(name, args, index, currentFileInfo) {
  2799. this.name = name;
  2800. this.args = args;
  2801. this.calc = name === "calc";
  2802. this._index = index;
  2803. this._fileInfo = currentFileInfo;
  2804. };
  2805. Call.prototype = Object.assign(new Node(), {
  2806. type: "Call",
  2807. accept: function(visitor) {
  2808. if (this.args) {
  2809. this.args = visitor.visitArray(this.args);
  2810. }
  2811. },
  2812. //
  2813. // When evaluating a function call,
  2814. // we either find the function in the functionRegistry,
  2815. // in which case we call it, passing the evaluated arguments,
  2816. // if this returns null or we cannot find the function, we
  2817. // simply print it out as it appeared originally [2].
  2818. //
  2819. // The reason why we evaluate the arguments, is in the case where
  2820. // we try to pass a variable to a function, like: `saturate(@color)`.
  2821. // The function should receive the value, not the variable.
  2822. //
  2823. eval: function(context) {
  2824. var _this = this;
  2825. var currentMathContext = context.mathOn;
  2826. context.mathOn = !this.calc;
  2827. if (this.calc || context.inCalc) {
  2828. context.enterCalc();
  2829. }
  2830. var exitCalc = function() {
  2831. if (_this.calc || context.inCalc) {
  2832. context.exitCalc();
  2833. }
  2834. context.mathOn = currentMathContext;
  2835. };
  2836. var result;
  2837. var funcCaller = new functionCaller(this.name, context, this.getIndex(), this.fileInfo());
  2838. if (funcCaller.isValid()) {
  2839. try {
  2840. result = funcCaller.call(this.args);
  2841. exitCalc();
  2842. } catch (e) {
  2843. if (e.hasOwnProperty("line") && e.hasOwnProperty("column")) {
  2844. throw e;
  2845. }
  2846. throw {
  2847. type: e.type || "Runtime",
  2848. message: "Error evaluating function `" + this.name + "`" + (e.message ? ": " + e.message : ""),
  2849. index: this.getIndex(),
  2850. filename: this.fileInfo().filename,
  2851. line: e.lineNumber,
  2852. column: e.columnNumber
  2853. };
  2854. }
  2855. }
  2856. if (result !== null && result !== void 0) {
  2857. if (!(result instanceof Node)) {
  2858. if (!result || result === true) {
  2859. result = new Anonymous(null);
  2860. } else {
  2861. result = new Anonymous(result.toString());
  2862. }
  2863. }
  2864. result._index = this._index;
  2865. result._fileInfo = this._fileInfo;
  2866. return result;
  2867. }
  2868. var args = this.args.map(function(a) {
  2869. return a.eval(context);
  2870. });
  2871. exitCalc();
  2872. return new Call(this.name, args, this.getIndex(), this.fileInfo());
  2873. },
  2874. genCSS: function(context, output) {
  2875. output.add(this.name + "(", this.fileInfo(), this.getIndex());
  2876. for (var i = 0; i < this.args.length; i++) {
  2877. this.args[i].genCSS(context, output);
  2878. if (i + 1 < this.args.length) {
  2879. output.add(", ");
  2880. }
  2881. }
  2882. output.add(")");
  2883. }
  2884. });
  2885. var Variable = function(name, index, currentFileInfo) {
  2886. this.name = name;
  2887. this._index = index;
  2888. this._fileInfo = currentFileInfo;
  2889. };
  2890. Variable.prototype = Object.assign(new Node(), {
  2891. type: "Variable",
  2892. eval: function(context) {
  2893. var variable, name = this.name;
  2894. if (name.indexOf("@@") === 0) {
  2895. name = "@" + new Variable(name.slice(1), this.getIndex(), this.fileInfo()).eval(context).value;
  2896. }
  2897. if (this.evaluating) {
  2898. throw {
  2899. type: "Name",
  2900. message: "Recursive variable definition for " + name,
  2901. filename: this.fileInfo().filename,
  2902. index: this.getIndex()
  2903. };
  2904. }
  2905. this.evaluating = true;
  2906. variable = this.find(context.frames, function(frame) {
  2907. var v = frame.variable(name);
  2908. if (v) {
  2909. if (v.important) {
  2910. var importantScope = context.importantScope[context.importantScope.length - 1];
  2911. importantScope.important = v.important;
  2912. }
  2913. if (context.inCalc) {
  2914. return new Call("_SELF", [v.value]).eval(context);
  2915. } else {
  2916. return v.value.eval(context);
  2917. }
  2918. }
  2919. });
  2920. if (variable) {
  2921. this.evaluating = false;
  2922. return variable;
  2923. } else {
  2924. throw {
  2925. type: "Name",
  2926. message: "variable " + name + " is undefined",
  2927. filename: this.fileInfo().filename,
  2928. index: this.getIndex()
  2929. };
  2930. }
  2931. },
  2932. find: function(obj, fun) {
  2933. for (var i = 0, r = void 0; i < obj.length; i++) {
  2934. r = fun.call(obj, obj[i]);
  2935. if (r) {
  2936. return r;
  2937. }
  2938. }
  2939. return null;
  2940. }
  2941. });
  2942. var Property = function(name, index, currentFileInfo) {
  2943. this.name = name;
  2944. this._index = index;
  2945. this._fileInfo = currentFileInfo;
  2946. };
  2947. Property.prototype = Object.assign(new Node(), {
  2948. type: "Property",
  2949. eval: function(context) {
  2950. var property;
  2951. var name = this.name;
  2952. var mergeRules = context.pluginManager.less.visitors.ToCSSVisitor.prototype._mergeRules;
  2953. if (this.evaluating) {
  2954. throw {
  2955. type: "Name",
  2956. message: "Recursive property reference for " + name,
  2957. filename: this.fileInfo().filename,
  2958. index: this.getIndex()
  2959. };
  2960. }
  2961. this.evaluating = true;
  2962. property = this.find(context.frames, function(frame) {
  2963. var v;
  2964. var vArr = frame.property(name);
  2965. if (vArr) {
  2966. for (var i = 0; i < vArr.length; i++) {
  2967. v = vArr[i];
  2968. vArr[i] = new Declaration(v.name, v.value, v.important, v.merge, v.index, v.currentFileInfo, v.inline, v.variable);
  2969. }
  2970. mergeRules(vArr);
  2971. v = vArr[vArr.length - 1];
  2972. if (v.important) {
  2973. var importantScope = context.importantScope[context.importantScope.length - 1];
  2974. importantScope.important = v.important;
  2975. }
  2976. v = v.value.eval(context);
  2977. return v;
  2978. }
  2979. });
  2980. if (property) {
  2981. this.evaluating = false;
  2982. return property;
  2983. } else {
  2984. throw {
  2985. type: "Name",
  2986. message: "Property '" + name + "' is undefined",
  2987. filename: this.currentFileInfo.filename,
  2988. index: this.index
  2989. };
  2990. }
  2991. },
  2992. find: function(obj, fun) {
  2993. for (var i = 0, r = void 0; i < obj.length; i++) {
  2994. r = fun.call(obj, obj[i]);
  2995. if (r) {
  2996. return r;
  2997. }
  2998. }
  2999. return null;
  3000. }
  3001. });
  3002. var Attribute = function(key2, op, value, cif) {
  3003. this.key = key2;
  3004. this.op = op;
  3005. this.value = value;
  3006. this.cif = cif;
  3007. };
  3008. Attribute.prototype = Object.assign(new Node(), {
  3009. type: "Attribute",
  3010. eval: function(context) {
  3011. 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, this.cif);
  3012. },
  3013. genCSS: function(context, output) {
  3014. output.add(this.toCSS(context));
  3015. },
  3016. toCSS: function(context) {
  3017. var value = this.key.toCSS ? this.key.toCSS(context) : this.key;
  3018. if (this.op) {
  3019. value += this.op;
  3020. value += this.value.toCSS ? this.value.toCSS(context) : this.value;
  3021. }
  3022. if (this.cif) {
  3023. value = value + " " + this.cif;
  3024. }
  3025. return "[" + value + "]";
  3026. }
  3027. });
  3028. var Quoted = function(str, content, escaped, index, currentFileInfo) {
  3029. this.escaped = escaped == null ? true : escaped;
  3030. this.value = content || "";
  3031. this.quote = str.charAt(0);
  3032. this._index = index;
  3033. this._fileInfo = currentFileInfo;
  3034. this.variableRegex = /@\{([\w-]+)\}/g;
  3035. this.propRegex = /\$\{([\w-]+)\}/g;
  3036. this.allowRoot = escaped;
  3037. };
  3038. Quoted.prototype = Object.assign(new Node(), {
  3039. type: "Quoted",
  3040. genCSS: function(context, output) {
  3041. if (!this.escaped) {
  3042. output.add(this.quote, this.fileInfo(), this.getIndex());
  3043. }
  3044. output.add(this.value);
  3045. if (!this.escaped) {
  3046. output.add(this.quote);
  3047. }
  3048. },
  3049. containsVariables: function() {
  3050. return this.value.match(this.variableRegex);
  3051. },
  3052. eval: function(context) {
  3053. var that = this;
  3054. var value = this.value;
  3055. var variableReplacement = function(_, name) {
  3056. var v = new Variable("@" + name, that.getIndex(), that.fileInfo()).eval(context, true);
  3057. return v instanceof Quoted ? v.value : v.toCSS();
  3058. };
  3059. var propertyReplacement = function(_, name) {
  3060. var v = new Property("$" + name, that.getIndex(), that.fileInfo()).eval(context, true);
  3061. return v instanceof Quoted ? v.value : v.toCSS();
  3062. };
  3063. function iterativeReplace(value2, regexp, replacementFnc) {
  3064. var evaluatedValue = value2;
  3065. do {
  3066. value2 = evaluatedValue.toString();
  3067. evaluatedValue = value2.replace(regexp, replacementFnc);
  3068. } while (value2 !== evaluatedValue);
  3069. return evaluatedValue;
  3070. }
  3071. value = iterativeReplace(value, this.variableRegex, variableReplacement);
  3072. value = iterativeReplace(value, this.propRegex, propertyReplacement);
  3073. return new Quoted(this.quote + value + this.quote, value, this.escaped, this.getIndex(), this.fileInfo());
  3074. },
  3075. compare: function(other) {
  3076. if (other.type === "Quoted" && !this.escaped && !other.escaped) {
  3077. return Node.numericCompare(this.value, other.value);
  3078. } else {
  3079. return other.toCSS && this.toCSS() === other.toCSS() ? 0 : void 0;
  3080. }
  3081. }
  3082. });
  3083. function escapePath(path) {
  3084. return path.replace(/[\(\)'"\s]/g, function(match) {
  3085. return "\\" + match;
  3086. });
  3087. }
  3088. var URL = function(val, index, currentFileInfo, isEvald) {
  3089. this.value = val;
  3090. this._index = index;
  3091. this._fileInfo = currentFileInfo;
  3092. this.isEvald = isEvald;
  3093. };
  3094. URL.prototype = Object.assign(new Node(), {
  3095. type: "Url",
  3096. accept: function(visitor) {
  3097. this.value = visitor.visit(this.value);
  3098. },
  3099. genCSS: function(context, output) {
  3100. output.add("url(");
  3101. this.value.genCSS(context, output);
  3102. output.add(")");
  3103. },
  3104. eval: function(context) {
  3105. var val = this.value.eval(context);
  3106. var rootpath;
  3107. if (!this.isEvald) {
  3108. rootpath = this.fileInfo() && this.fileInfo().rootpath;
  3109. if (typeof rootpath === "string" && typeof val.value === "string" && context.pathRequiresRewrite(val.value)) {
  3110. if (!val.quote) {
  3111. rootpath = escapePath(rootpath);
  3112. }
  3113. val.value = context.rewritePath(val.value, rootpath);
  3114. } else {
  3115. val.value = context.normalizePath(val.value);
  3116. }
  3117. if (context.urlArgs) {
  3118. if (!val.value.match(/^\s*data:/)) {
  3119. var delimiter = val.value.indexOf("?") === -1 ? "?" : "&";
  3120. var urlArgs = delimiter + context.urlArgs;
  3121. if (val.value.indexOf("#") !== -1) {
  3122. val.value = val.value.replace("#", urlArgs + "#");
  3123. } else {
  3124. val.value += urlArgs;
  3125. }
  3126. }
  3127. }
  3128. }
  3129. return new URL(val, this.getIndex(), this.fileInfo(), true);
  3130. }
  3131. });
  3132. var Media = function(value, features, index, currentFileInfo, visibilityInfo) {
  3133. this._index = index;
  3134. this._fileInfo = currentFileInfo;
  3135. var selectors = new Selector([], null, null, this._index, this._fileInfo).createEmptySelectors();
  3136. this.features = new Value(features);
  3137. this.rules = [new Ruleset(selectors, value)];
  3138. this.rules[0].allowImports = true;
  3139. this.copyVisibilityInfo(visibilityInfo);
  3140. this.allowRoot = true;
  3141. this.setParent(selectors, this);
  3142. this.setParent(this.features, this);
  3143. this.setParent(this.rules, this);
  3144. };
  3145. Media.prototype = Object.assign(new AtRule(), {
  3146. type: "Media",
  3147. isRulesetLike: function() {
  3148. return true;
  3149. },
  3150. accept: function(visitor) {
  3151. if (this.features) {
  3152. this.features = visitor.visit(this.features);
  3153. }
  3154. if (this.rules) {
  3155. this.rules = visitor.visitArray(this.rules);
  3156. }
  3157. },
  3158. genCSS: function(context, output) {
  3159. output.add("@media ", this._fileInfo, this._index);
  3160. this.features.genCSS(context, output);
  3161. this.outputRuleset(context, output, this.rules);
  3162. },
  3163. eval: function(context) {
  3164. if (!context.mediaBlocks) {
  3165. context.mediaBlocks = [];
  3166. context.mediaPath = [];
  3167. }
  3168. var media = new Media(null, [], this._index, this._fileInfo, this.visibilityInfo());
  3169. if (this.debugInfo) {
  3170. this.rules[0].debugInfo = this.debugInfo;
  3171. media.debugInfo = this.debugInfo;
  3172. }
  3173. media.features = this.features.eval(context);
  3174. context.mediaPath.push(media);
  3175. context.mediaBlocks.push(media);
  3176. this.rules[0].functionRegistry = context.frames[0].functionRegistry.inherit();
  3177. context.frames.unshift(this.rules[0]);
  3178. media.rules = [this.rules[0].eval(context)];
  3179. context.frames.shift();
  3180. context.mediaPath.pop();
  3181. return context.mediaPath.length === 0 ? media.evalTop(context) : media.evalNested(context);
  3182. },
  3183. evalTop: function(context) {
  3184. var result = this;
  3185. if (context.mediaBlocks.length > 1) {
  3186. var selectors = new Selector([], null, null, this.getIndex(), this.fileInfo()).createEmptySelectors();
  3187. result = new Ruleset(selectors, context.mediaBlocks);
  3188. result.multiMedia = true;
  3189. result.copyVisibilityInfo(this.visibilityInfo());
  3190. this.setParent(result, this);
  3191. }
  3192. delete context.mediaBlocks;
  3193. delete context.mediaPath;
  3194. return result;
  3195. },
  3196. evalNested: function(context) {
  3197. var i;
  3198. var value;
  3199. var path = context.mediaPath.concat([this]);
  3200. for (i = 0; i < path.length; i++) {
  3201. value = path[i].features instanceof Value ? path[i].features.value : path[i].features;
  3202. path[i] = Array.isArray(value) ? value : [value];
  3203. }
  3204. this.features = new Value(this.permute(path).map(function(path2) {
  3205. path2 = path2.map(function(fragment) {
  3206. return fragment.toCSS ? fragment : new Anonymous(fragment);
  3207. });
  3208. for (i = path2.length - 1; i > 0; i--) {
  3209. path2.splice(i, 0, new Anonymous("and"));
  3210. }
  3211. return new Expression(path2);
  3212. }));
  3213. this.setParent(this.features, this);
  3214. return new Ruleset([], []);
  3215. },
  3216. permute: function(arr) {
  3217. if (arr.length === 0) {
  3218. return [];
  3219. } else if (arr.length === 1) {
  3220. return arr[0];
  3221. } else {
  3222. var result = [];
  3223. var rest = this.permute(arr.slice(1));
  3224. for (var i = 0; i < rest.length; i++) {
  3225. for (var j = 0; j < arr[0].length; j++) {
  3226. result.push([arr[0][j]].concat(rest[i]));
  3227. }
  3228. }
  3229. return result;
  3230. }
  3231. },
  3232. bubbleSelectors: function(selectors) {
  3233. if (!selectors) {
  3234. return;
  3235. }
  3236. this.rules = [new Ruleset(copyArray(selectors), [this.rules[0]])];
  3237. this.setParent(this.rules, this);
  3238. }
  3239. });
  3240. var Import = function(path, features, options2, index, currentFileInfo, visibilityInfo) {
  3241. this.options = options2;
  3242. this._index = index;
  3243. this._fileInfo = currentFileInfo;
  3244. this.path = path;
  3245. this.features = features;
  3246. this.allowRoot = true;
  3247. if (this.options.less !== void 0 || this.options.inline) {
  3248. this.css = !this.options.less || this.options.inline;
  3249. } else {
  3250. var pathValue = this.getPath();
  3251. if (pathValue && /[#\.\&\?]css([\?;].*)?$/.test(pathValue)) {
  3252. this.css = true;
  3253. }
  3254. }
  3255. this.copyVisibilityInfo(visibilityInfo);
  3256. this.setParent(this.features, this);
  3257. this.setParent(this.path, this);
  3258. };
  3259. Import.prototype = Object.assign(new Node(), {
  3260. type: "Import",
  3261. accept: function(visitor) {
  3262. if (this.features) {
  3263. this.features = visitor.visit(this.features);
  3264. }
  3265. this.path = visitor.visit(this.path);
  3266. if (!this.options.isPlugin && !this.options.inline && this.root) {
  3267. this.root = visitor.visit(this.root);
  3268. }
  3269. },
  3270. genCSS: function(context, output) {
  3271. if (this.css && this.path._fileInfo.reference === void 0) {
  3272. output.add("@import ", this._fileInfo, this._index);
  3273. this.path.genCSS(context, output);
  3274. if (this.features) {
  3275. output.add(" ");
  3276. this.features.genCSS(context, output);
  3277. }
  3278. output.add(";");
  3279. }
  3280. },
  3281. getPath: function() {
  3282. return this.path instanceof URL ? this.path.value.value : this.path.value;
  3283. },
  3284. isVariableImport: function() {
  3285. var path = this.path;
  3286. if (path instanceof URL) {
  3287. path = path.value;
  3288. }
  3289. if (path instanceof Quoted) {
  3290. return path.containsVariables();
  3291. }
  3292. return true;
  3293. },
  3294. evalForImport: function(context) {
  3295. var path = this.path;
  3296. if (path instanceof URL) {
  3297. path = path.value;
  3298. }
  3299. return new Import(path.eval(context), this.features, this.options, this._index, this._fileInfo, this.visibilityInfo());
  3300. },
  3301. evalPath: function(context) {
  3302. var path = this.path.eval(context);
  3303. var fileInfo = this._fileInfo;
  3304. if (!(path instanceof URL)) {
  3305. var pathValue = path.value;
  3306. if (fileInfo && pathValue && context.pathRequiresRewrite(pathValue)) {
  3307. path.value = context.rewritePath(pathValue, fileInfo.rootpath);
  3308. } else {
  3309. path.value = context.normalizePath(path.value);
  3310. }
  3311. }
  3312. return path;
  3313. },
  3314. eval: function(context) {
  3315. var result = this.doEval(context);
  3316. if (this.options.reference || this.blocksVisibility()) {
  3317. if (result.length || result.length === 0) {
  3318. result.forEach(function(node) {
  3319. node.addVisibilityBlock();
  3320. });
  3321. } else {
  3322. result.addVisibilityBlock();
  3323. }
  3324. }
  3325. return result;
  3326. },
  3327. doEval: function(context) {
  3328. var ruleset;
  3329. var registry;
  3330. var features = this.features && this.features.eval(context);
  3331. if (this.options.isPlugin) {
  3332. if (this.root && this.root.eval) {
  3333. try {
  3334. this.root.eval(context);
  3335. } catch (e) {
  3336. e.message = "Plugin error during evaluation";
  3337. throw new LessError(e, this.root.imports, this.root.filename);
  3338. }
  3339. }
  3340. registry = context.frames[0] && context.frames[0].functionRegistry;
  3341. if (registry && this.root && this.root.functions) {
  3342. registry.addMultiple(this.root.functions);
  3343. }
  3344. return [];
  3345. }
  3346. if (this.skip) {
  3347. if (typeof this.skip === "function") {
  3348. this.skip = this.skip();
  3349. }
  3350. if (this.skip) {
  3351. return [];
  3352. }
  3353. }
  3354. if (this.options.inline) {
  3355. var contents = new Anonymous(this.root, 0, {
  3356. filename: this.importedFilename,
  3357. reference: this.path._fileInfo && this.path._fileInfo.reference
  3358. }, true, true);
  3359. return this.features ? new Media([contents], this.features.value) : [contents];
  3360. } else if (this.css) {
  3361. var newImport = new Import(this.evalPath(context), features, this.options, this._index);
  3362. if (!newImport.css && this.error) {
  3363. throw this.error;
  3364. }
  3365. return newImport;
  3366. } else if (this.root) {
  3367. ruleset = new Ruleset(null, copyArray(this.root.rules));
  3368. ruleset.evalImports(context);
  3369. return this.features ? new Media(ruleset.rules, this.features.value) : ruleset.rules;
  3370. } else {
  3371. return [];
  3372. }
  3373. }
  3374. });
  3375. var JsEvalNode = function() {
  3376. };
  3377. JsEvalNode.prototype = Object.assign(new Node(), {
  3378. evaluateJavaScript: function(expression, context) {
  3379. var result;
  3380. var that = this;
  3381. var evalContext = {};
  3382. if (!context.javascriptEnabled) {
  3383. throw {
  3384. message: "Inline JavaScript is not enabled. Is it set in your options?",
  3385. filename: this.fileInfo().filename,
  3386. index: this.getIndex()
  3387. };
  3388. }
  3389. expression = expression.replace(/@\{([\w-]+)\}/g, function(_, name) {
  3390. return that.jsify(new Variable("@" + name, that.getIndex(), that.fileInfo()).eval(context));
  3391. });
  3392. try {
  3393. expression = new Function("return (" + expression + ")");
  3394. } catch (e) {
  3395. throw {
  3396. message: "JavaScript evaluation error: " + e.message + " from `" + expression + "`",
  3397. filename: this.fileInfo().filename,
  3398. index: this.getIndex()
  3399. };
  3400. }
  3401. var variables = context.frames[0].variables();
  3402. for (var k in variables) {
  3403. if (variables.hasOwnProperty(k)) {
  3404. evalContext[k.slice(1)] = {
  3405. value: variables[k].value,
  3406. toJS: function() {
  3407. return this.value.eval(context).toCSS();
  3408. }
  3409. };
  3410. }
  3411. }
  3412. try {
  3413. result = expression.call(evalContext);
  3414. } catch (e) {
  3415. throw {
  3416. message: "JavaScript evaluation error: '" + e.name + ": " + e.message.replace(/["]/g, "'") + "'",
  3417. filename: this.fileInfo().filename,
  3418. index: this.getIndex()
  3419. };
  3420. }
  3421. return result;
  3422. },
  3423. jsify: function(obj) {
  3424. if (Array.isArray(obj.value) && obj.value.length > 1) {
  3425. return "[" + obj.value.map(function(v) {
  3426. return v.toCSS();
  3427. }).join(", ") + "]";
  3428. } else {
  3429. return obj.toCSS();
  3430. }
  3431. }
  3432. });
  3433. var JavaScript = function(string2, escaped, index, currentFileInfo) {
  3434. this.escaped = escaped;
  3435. this.expression = string2;
  3436. this._index = index;
  3437. this._fileInfo = currentFileInfo;
  3438. };
  3439. JavaScript.prototype = Object.assign(new JsEvalNode(), {
  3440. type: "JavaScript",
  3441. eval: function(context) {
  3442. var result = this.evaluateJavaScript(this.expression, context);
  3443. var type = typeof result;
  3444. if (type === "number" && !isNaN(result)) {
  3445. return new Dimension(result);
  3446. } else if (type === "string") {
  3447. return new Quoted('"' + result + '"', result, this.escaped, this._index);
  3448. } else if (Array.isArray(result)) {
  3449. return new Anonymous(result.join(", "));
  3450. } else {
  3451. return new Anonymous(result);
  3452. }
  3453. }
  3454. });
  3455. var Assignment = function(key2, val) {
  3456. this.key = key2;
  3457. this.value = val;
  3458. };
  3459. Assignment.prototype = Object.assign(new Node(), {
  3460. type: "Assignment",
  3461. accept: function(visitor) {
  3462. this.value = visitor.visit(this.value);
  3463. },
  3464. eval: function(context) {
  3465. if (this.value.eval) {
  3466. return new Assignment(this.key, this.value.eval(context));
  3467. }
  3468. return this;
  3469. },
  3470. genCSS: function(context, output) {
  3471. output.add(this.key + "=");
  3472. if (this.value.genCSS) {
  3473. this.value.genCSS(context, output);
  3474. } else {
  3475. output.add(this.value);
  3476. }
  3477. }
  3478. });
  3479. var Condition = function(op, l, r, i, negate) {
  3480. this.op = op.trim();
  3481. this.lvalue = l;
  3482. this.rvalue = r;
  3483. this._index = i;
  3484. this.negate = negate;
  3485. };
  3486. Condition.prototype = Object.assign(new Node(), {
  3487. type: "Condition",
  3488. accept: function(visitor) {
  3489. this.lvalue = visitor.visit(this.lvalue);
  3490. this.rvalue = visitor.visit(this.rvalue);
  3491. },
  3492. eval: function(context) {
  3493. var result = function(op, a, b) {
  3494. switch (op) {
  3495. case "and":
  3496. return a && b;
  3497. case "or":
  3498. return a || b;
  3499. default:
  3500. switch (Node.compare(a, b)) {
  3501. case -1:
  3502. return op === "<" || op === "=<" || op === "<=";
  3503. case 0:
  3504. return op === "=" || op === ">=" || op === "=<" || op === "<=";
  3505. case 1:
  3506. return op === ">" || op === ">=";
  3507. default:
  3508. return false;
  3509. }
  3510. }
  3511. }(this.op, this.lvalue.eval(context), this.rvalue.eval(context));
  3512. return this.negate ? !result : result;
  3513. }
  3514. });
  3515. var UnicodeDescriptor = function(value) {
  3516. this.value = value;
  3517. };
  3518. UnicodeDescriptor.prototype = Object.assign(new Node(), {
  3519. type: "UnicodeDescriptor"
  3520. });
  3521. var Negative = function(node) {
  3522. this.value = node;
  3523. };
  3524. Negative.prototype = Object.assign(new Node(), {
  3525. type: "Negative",
  3526. genCSS: function(context, output) {
  3527. output.add("-");
  3528. this.value.genCSS(context, output);
  3529. },
  3530. eval: function(context) {
  3531. if (context.isMathOn()) {
  3532. return new Operation("*", [new Dimension(-1), this.value]).eval(context);
  3533. }
  3534. return new Negative(this.value.eval(context));
  3535. }
  3536. });
  3537. var Extend = function(selector, option, index, currentFileInfo, visibilityInfo) {
  3538. this.selector = selector;
  3539. this.option = option;
  3540. this.object_id = Extend.next_id++;
  3541. this.parent_ids = [this.object_id];
  3542. this._index = index;
  3543. this._fileInfo = currentFileInfo;
  3544. this.copyVisibilityInfo(visibilityInfo);
  3545. this.allowRoot = true;
  3546. switch (option) {
  3547. case "all":
  3548. this.allowBefore = true;
  3549. this.allowAfter = true;
  3550. break;
  3551. default:
  3552. this.allowBefore = false;
  3553. this.allowAfter = false;
  3554. break;
  3555. }
  3556. this.setParent(this.selector, this);
  3557. };
  3558. Extend.prototype = Object.assign(new Node(), {
  3559. type: "Extend",
  3560. accept: function(visitor) {
  3561. this.selector = visitor.visit(this.selector);
  3562. },
  3563. eval: function(context) {
  3564. return new Extend(this.selector.eval(context), this.option, this.getIndex(), this.fileInfo(), this.visibilityInfo());
  3565. },
  3566. clone: function(context) {
  3567. return new Extend(this.selector, this.option, this.getIndex(), this.fileInfo(), this.visibilityInfo());
  3568. },
  3569. // it concatenates (joins) all selectors in selector array
  3570. findSelfSelectors: function(selectors) {
  3571. var selfElements = [], i, selectorElements;
  3572. for (i = 0; i < selectors.length; i++) {
  3573. selectorElements = selectors[i].elements;
  3574. if (i > 0 && selectorElements.length && selectorElements[0].combinator.value === "") {
  3575. selectorElements[0].combinator.value = " ";
  3576. }
  3577. selfElements = selfElements.concat(selectors[i].elements);
  3578. }
  3579. this.selfSelectors = [new Selector(selfElements)];
  3580. this.selfSelectors[0].copyVisibilityInfo(this.visibilityInfo());
  3581. }
  3582. });
  3583. Extend.next_id = 0;
  3584. var VariableCall = function(variable, index, currentFileInfo) {
  3585. this.variable = variable;
  3586. this._index = index;
  3587. this._fileInfo = currentFileInfo;
  3588. this.allowRoot = true;
  3589. };
  3590. VariableCall.prototype = Object.assign(new Node(), {
  3591. type: "VariableCall",
  3592. eval: function(context) {
  3593. var rules;
  3594. var detachedRuleset = new Variable(this.variable, this.getIndex(), this.fileInfo()).eval(context);
  3595. var error = new LessError({ message: "Could not evaluate variable call " + this.variable });
  3596. if (!detachedRuleset.ruleset) {
  3597. if (detachedRuleset.rules) {
  3598. rules = detachedRuleset;
  3599. } else if (Array.isArray(detachedRuleset)) {
  3600. rules = new Ruleset("", detachedRuleset);
  3601. } else if (Array.isArray(detachedRuleset.value)) {
  3602. rules = new Ruleset("", detachedRuleset.value);
  3603. } else {
  3604. throw error;
  3605. }
  3606. detachedRuleset = new DetachedRuleset(rules);
  3607. }
  3608. if (detachedRuleset.ruleset) {
  3609. return detachedRuleset.callEval(context);
  3610. }
  3611. throw error;
  3612. }
  3613. });
  3614. var NamespaceValue = function(ruleCall, lookups, index, fileInfo) {
  3615. this.value = ruleCall;
  3616. this.lookups = lookups;
  3617. this._index = index;
  3618. this._fileInfo = fileInfo;
  3619. };
  3620. NamespaceValue.prototype = Object.assign(new Node(), {
  3621. type: "NamespaceValue",
  3622. eval: function(context) {
  3623. var i, name, rules = this.value.eval(context);
  3624. for (i = 0; i < this.lookups.length; i++) {
  3625. name = this.lookups[i];
  3626. if (Array.isArray(rules)) {
  3627. rules = new Ruleset([new Selector()], rules);
  3628. }
  3629. if (name === "") {
  3630. rules = rules.lastDeclaration();
  3631. } else if (name.charAt(0) === "@") {
  3632. if (name.charAt(1) === "@") {
  3633. name = "@" + new Variable(name.substr(1)).eval(context).value;
  3634. }
  3635. if (rules.variables) {
  3636. rules = rules.variable(name);
  3637. }
  3638. if (!rules) {
  3639. throw {
  3640. type: "Name",
  3641. message: "variable " + name + " not found",
  3642. filename: this.fileInfo().filename,
  3643. index: this.getIndex()
  3644. };
  3645. }
  3646. } else {
  3647. if (name.substring(0, 2) === "$@") {
  3648. name = "$" + new Variable(name.substr(1)).eval(context).value;
  3649. } else {
  3650. name = name.charAt(0) === "$" ? name : "$" + name;
  3651. }
  3652. if (rules.properties) {
  3653. rules = rules.property(name);
  3654. }
  3655. if (!rules) {
  3656. throw {
  3657. type: "Name",
  3658. message: 'property "' + name.substr(1) + '" not found',
  3659. filename: this.fileInfo().filename,
  3660. index: this.getIndex()
  3661. };
  3662. }
  3663. rules = rules[rules.length - 1];
  3664. }
  3665. if (rules.value) {
  3666. rules = rules.eval(context).value;
  3667. }
  3668. if (rules.ruleset) {
  3669. rules = rules.ruleset.eval(context);
  3670. }
  3671. }
  3672. return rules;
  3673. }
  3674. });
  3675. var Definition = function(name, params, rules, condition, variadic, frames, visibilityInfo) {
  3676. this.name = name || "anonymous mixin";
  3677. this.selectors = [new Selector([new Element(null, name, false, this._index, this._fileInfo)])];
  3678. this.params = params;
  3679. this.condition = condition;
  3680. this.variadic = variadic;
  3681. this.arity = params.length;
  3682. this.rules = rules;
  3683. this._lookups = {};
  3684. var optionalParameters = [];
  3685. this.required = params.reduce(function(count, p) {
  3686. if (!p.name || p.name && !p.value) {
  3687. return count + 1;
  3688. } else {
  3689. optionalParameters.push(p.name);
  3690. return count;
  3691. }
  3692. }, 0);
  3693. this.optionalParameters = optionalParameters;
  3694. this.frames = frames;
  3695. this.copyVisibilityInfo(visibilityInfo);
  3696. this.allowRoot = true;
  3697. };
  3698. Definition.prototype = Object.assign(new Ruleset(), {
  3699. type: "MixinDefinition",
  3700. evalFirst: true,
  3701. accept: function(visitor) {
  3702. if (this.params && this.params.length) {
  3703. this.params = visitor.visitArray(this.params);
  3704. }
  3705. this.rules = visitor.visitArray(this.rules);
  3706. if (this.condition) {
  3707. this.condition = visitor.visit(this.condition);
  3708. }
  3709. },
  3710. evalParams: function(context, mixinEnv, args, evaldArguments) {
  3711. var frame = new Ruleset(null, null);
  3712. var varargs;
  3713. var arg;
  3714. var params = copyArray(this.params);
  3715. var i;
  3716. var j;
  3717. var val;
  3718. var name;
  3719. var isNamedFound;
  3720. var argIndex;
  3721. var argsLength = 0;
  3722. if (mixinEnv.frames && mixinEnv.frames[0] && mixinEnv.frames[0].functionRegistry) {
  3723. frame.functionRegistry = mixinEnv.frames[0].functionRegistry.inherit();
  3724. }
  3725. mixinEnv = new contexts.Eval(mixinEnv, [frame].concat(mixinEnv.frames));
  3726. if (args) {
  3727. args = copyArray(args);
  3728. argsLength = args.length;
  3729. for (i = 0; i < argsLength; i++) {
  3730. arg = args[i];
  3731. if (name = arg && arg.name) {
  3732. isNamedFound = false;
  3733. for (j = 0; j < params.length; j++) {
  3734. if (!evaldArguments[j] && name === params[j].name) {
  3735. evaldArguments[j] = arg.value.eval(context);
  3736. frame.prependRule(new Declaration(name, arg.value.eval(context)));
  3737. isNamedFound = true;
  3738. break;
  3739. }
  3740. }
  3741. if (isNamedFound) {
  3742. args.splice(i, 1);
  3743. i--;
  3744. continue;
  3745. } else {
  3746. throw { type: "Runtime", message: "Named argument for " + this.name + " " + args[i].name + " not found" };
  3747. }
  3748. }
  3749. }
  3750. }
  3751. argIndex = 0;
  3752. for (i = 0; i < params.length; i++) {
  3753. if (evaldArguments[i]) {
  3754. continue;
  3755. }
  3756. arg = args && args[argIndex];
  3757. if (name = params[i].name) {
  3758. if (params[i].variadic) {
  3759. varargs = [];
  3760. for (j = argIndex; j < argsLength; j++) {
  3761. varargs.push(args[j].value.eval(context));
  3762. }
  3763. frame.prependRule(new Declaration(name, new Expression(varargs).eval(context)));
  3764. } else {
  3765. val = arg && arg.value;
  3766. if (val) {
  3767. if (Array.isArray(val)) {
  3768. val = new DetachedRuleset(new Ruleset("", val));
  3769. } else {
  3770. val = val.eval(context);
  3771. }
  3772. } else if (params[i].value) {
  3773. val = params[i].value.eval(mixinEnv);
  3774. frame.resetCache();
  3775. } else {
  3776. throw { type: "Runtime", message: "wrong number of arguments for " + this.name + " (" + argsLength + " for " + this.arity + ")" };
  3777. }
  3778. frame.prependRule(new Declaration(name, val));
  3779. evaldArguments[i] = val;
  3780. }
  3781. }
  3782. if (params[i].variadic && args) {
  3783. for (j = argIndex; j < argsLength; j++) {
  3784. evaldArguments[j] = args[j].value.eval(context);
  3785. }
  3786. }
  3787. argIndex++;
  3788. }
  3789. return frame;
  3790. },
  3791. makeImportant: function() {
  3792. var rules = !this.rules ? this.rules : this.rules.map(function(r) {
  3793. if (r.makeImportant) {
  3794. return r.makeImportant(true);
  3795. } else {
  3796. return r;
  3797. }
  3798. });
  3799. var result = new Definition(this.name, this.params, rules, this.condition, this.variadic, this.frames);
  3800. return result;
  3801. },
  3802. eval: function(context) {
  3803. return new Definition(this.name, this.params, this.rules, this.condition, this.variadic, this.frames || copyArray(context.frames));
  3804. },
  3805. evalCall: function(context, args, important) {
  3806. var _arguments = [];
  3807. var mixinFrames = this.frames ? this.frames.concat(context.frames) : context.frames;
  3808. var frame = this.evalParams(context, new contexts.Eval(context, mixinFrames), args, _arguments);
  3809. var rules;
  3810. var ruleset;
  3811. frame.prependRule(new Declaration("@arguments", new Expression(_arguments).eval(context)));
  3812. rules = copyArray(this.rules);
  3813. ruleset = new Ruleset(null, rules);
  3814. ruleset.originalRuleset = this;
  3815. ruleset = ruleset.eval(new contexts.Eval(context, [this, frame].concat(mixinFrames)));
  3816. if (important) {
  3817. ruleset = ruleset.makeImportant();
  3818. }
  3819. return ruleset;
  3820. },
  3821. matchCondition: function(args, context) {
  3822. if (this.condition && !this.condition.eval(new contexts.Eval(context, [this.evalParams(
  3823. context,
  3824. /* the parameter variables */
  3825. new contexts.Eval(context, this.frames ? this.frames.concat(context.frames) : context.frames),
  3826. args,
  3827. []
  3828. )].concat(this.frames || []).concat(context.frames)))) {
  3829. return false;
  3830. }
  3831. return true;
  3832. },
  3833. matchArgs: function(args, context) {
  3834. var allArgsCnt = args && args.length || 0;
  3835. var len;
  3836. var optionalParameters = this.optionalParameters;
  3837. var requiredArgsCnt = !args ? 0 : args.reduce(function(count, p) {
  3838. if (optionalParameters.indexOf(p.name) < 0) {
  3839. return count + 1;
  3840. } else {
  3841. return count;
  3842. }
  3843. }, 0);
  3844. if (!this.variadic) {
  3845. if (requiredArgsCnt < this.required) {
  3846. return false;
  3847. }
  3848. if (allArgsCnt > this.params.length) {
  3849. return false;
  3850. }
  3851. } else {
  3852. if (requiredArgsCnt < this.required - 1) {
  3853. return false;
  3854. }
  3855. }
  3856. len = Math.min(requiredArgsCnt, this.arity);
  3857. for (var i = 0; i < len; i++) {
  3858. if (!this.params[i].name && !this.params[i].variadic) {
  3859. if (args[i].value.eval(context).toCSS() != this.params[i].value.eval(context).toCSS()) {
  3860. return false;
  3861. }
  3862. }
  3863. }
  3864. return true;
  3865. }
  3866. });
  3867. var MixinCall = function(elements, args, index, currentFileInfo, important) {
  3868. this.selector = new Selector(elements);
  3869. this.arguments = args || [];
  3870. this._index = index;
  3871. this._fileInfo = currentFileInfo;
  3872. this.important = important;
  3873. this.allowRoot = true;
  3874. this.setParent(this.selector, this);
  3875. };
  3876. MixinCall.prototype = Object.assign(new Node(), {
  3877. type: "MixinCall",
  3878. accept: function(visitor) {
  3879. if (this.selector) {
  3880. this.selector = visitor.visit(this.selector);
  3881. }
  3882. if (this.arguments.length) {
  3883. this.arguments = visitor.visitArray(this.arguments);
  3884. }
  3885. },
  3886. eval: function(context) {
  3887. var mixins;
  3888. var mixin;
  3889. var mixinPath;
  3890. var args = [];
  3891. var arg;
  3892. var argValue;
  3893. var rules = [];
  3894. var match = false;
  3895. var i;
  3896. var m;
  3897. var f2;
  3898. var isRecursive;
  3899. var isOneFound;
  3900. var candidates = [];
  3901. var candidate;
  3902. var conditionResult = [];
  3903. var defaultResult;
  3904. var defFalseEitherCase = -1;
  3905. var defNone = 0;
  3906. var defTrue = 1;
  3907. var defFalse = 2;
  3908. var count;
  3909. var originalRuleset;
  3910. var noArgumentsFilter;
  3911. this.selector = this.selector.eval(context);
  3912. function calcDefGroup(mixin2, mixinPath2) {
  3913. var f3, p, namespace;
  3914. for (f3 = 0; f3 < 2; f3++) {
  3915. conditionResult[f3] = true;
  3916. defaultFunc.value(f3);
  3917. for (p = 0; p < mixinPath2.length && conditionResult[f3]; p++) {
  3918. namespace = mixinPath2[p];
  3919. if (namespace.matchCondition) {
  3920. conditionResult[f3] = conditionResult[f3] && namespace.matchCondition(null, context);
  3921. }
  3922. }
  3923. if (mixin2.matchCondition) {
  3924. conditionResult[f3] = conditionResult[f3] && mixin2.matchCondition(args, context);
  3925. }
  3926. }
  3927. if (conditionResult[0] || conditionResult[1]) {
  3928. if (conditionResult[0] != conditionResult[1]) {
  3929. return conditionResult[1] ? defTrue : defFalse;
  3930. }
  3931. return defNone;
  3932. }
  3933. return defFalseEitherCase;
  3934. }
  3935. for (i = 0; i < this.arguments.length; i++) {
  3936. arg = this.arguments[i];
  3937. argValue = arg.value.eval(context);
  3938. if (arg.expand && Array.isArray(argValue.value)) {
  3939. argValue = argValue.value;
  3940. for (m = 0; m < argValue.length; m++) {
  3941. args.push({ value: argValue[m] });
  3942. }
  3943. } else {
  3944. args.push({ name: arg.name, value: argValue });
  3945. }
  3946. }
  3947. noArgumentsFilter = function(rule) {
  3948. return rule.matchArgs(null, context);
  3949. };
  3950. for (i = 0; i < context.frames.length; i++) {
  3951. if ((mixins = context.frames[i].find(this.selector, null, noArgumentsFilter)).length > 0) {
  3952. isOneFound = true;
  3953. for (m = 0; m < mixins.length; m++) {
  3954. mixin = mixins[m].rule;
  3955. mixinPath = mixins[m].path;
  3956. isRecursive = false;
  3957. for (f2 = 0; f2 < context.frames.length; f2++) {
  3958. if (!(mixin instanceof Definition) && mixin === (context.frames[f2].originalRuleset || context.frames[f2])) {
  3959. isRecursive = true;
  3960. break;
  3961. }
  3962. }
  3963. if (isRecursive) {
  3964. continue;
  3965. }
  3966. if (mixin.matchArgs(args, context)) {
  3967. candidate = { mixin, group: calcDefGroup(mixin, mixinPath) };
  3968. if (candidate.group !== defFalseEitherCase) {
  3969. candidates.push(candidate);
  3970. }
  3971. match = true;
  3972. }
  3973. }
  3974. defaultFunc.reset();
  3975. count = [0, 0, 0];
  3976. for (m = 0; m < candidates.length; m++) {
  3977. count[candidates[m].group]++;
  3978. }
  3979. if (count[defNone] > 0) {
  3980. defaultResult = defFalse;
  3981. } else {
  3982. defaultResult = defTrue;
  3983. if (count[defTrue] + count[defFalse] > 1) {
  3984. throw {
  3985. type: "Runtime",
  3986. message: "Ambiguous use of `default()` found when matching for `" + this.format(args) + "`",
  3987. index: this.getIndex(),
  3988. filename: this.fileInfo().filename
  3989. };
  3990. }
  3991. }
  3992. for (m = 0; m < candidates.length; m++) {
  3993. candidate = candidates[m].group;
  3994. if (candidate === defNone || candidate === defaultResult) {
  3995. try {
  3996. mixin = candidates[m].mixin;
  3997. if (!(mixin instanceof Definition)) {
  3998. originalRuleset = mixin.originalRuleset || mixin;
  3999. mixin = new Definition("", [], mixin.rules, null, false, null, originalRuleset.visibilityInfo());
  4000. mixin.originalRuleset = originalRuleset;
  4001. }
  4002. var newRules = mixin.evalCall(context, args, this.important).rules;
  4003. this._setVisibilityToReplacement(newRules);
  4004. Array.prototype.push.apply(rules, newRules);
  4005. } catch (e) {
  4006. throw { message: e.message, index: this.getIndex(), filename: this.fileInfo().filename, stack: e.stack };
  4007. }
  4008. }
  4009. }
  4010. if (match) {
  4011. return rules;
  4012. }
  4013. }
  4014. }
  4015. if (isOneFound) {
  4016. throw {
  4017. type: "Runtime",
  4018. message: "No matching definition was found for `" + this.format(args) + "`",
  4019. index: this.getIndex(),
  4020. filename: this.fileInfo().filename
  4021. };
  4022. } else {
  4023. throw {
  4024. type: "Name",
  4025. message: this.selector.toCSS().trim() + " is undefined",
  4026. index: this.getIndex(),
  4027. filename: this.fileInfo().filename
  4028. };
  4029. }
  4030. },
  4031. _setVisibilityToReplacement: function(replacement) {
  4032. var i, rule;
  4033. if (this.blocksVisibility()) {
  4034. for (i = 0; i < replacement.length; i++) {
  4035. rule = replacement[i];
  4036. rule.addVisibilityBlock();
  4037. }
  4038. }
  4039. },
  4040. format: function(args) {
  4041. return this.selector.toCSS().trim() + "(" + (args ? args.map(function(a) {
  4042. var argValue = "";
  4043. if (a.name) {
  4044. argValue += a.name + ":";
  4045. }
  4046. if (a.value.toCSS) {
  4047. argValue += a.value.toCSS();
  4048. } else {
  4049. argValue += "???";
  4050. }
  4051. return argValue;
  4052. }).join(", ") : "") + ")";
  4053. }
  4054. });
  4055. var tree = {
  4056. Node,
  4057. Color,
  4058. AtRule,
  4059. DetachedRuleset,
  4060. Operation,
  4061. Dimension,
  4062. Unit,
  4063. Keyword,
  4064. Variable,
  4065. Property,
  4066. Ruleset,
  4067. Element,
  4068. Attribute,
  4069. Combinator,
  4070. Selector,
  4071. Quoted,
  4072. Expression,
  4073. Declaration,
  4074. Call,
  4075. URL,
  4076. Import,
  4077. Comment,
  4078. Anonymous,
  4079. Value,
  4080. JavaScript,
  4081. Assignment,
  4082. Condition,
  4083. Paren,
  4084. Media,
  4085. UnicodeDescriptor,
  4086. Negative,
  4087. Extend,
  4088. VariableCall,
  4089. NamespaceValue,
  4090. mixin: {
  4091. Call: MixinCall,
  4092. Definition
  4093. }
  4094. };
  4095. var AbstractFileManager = (
  4096. /** @class */
  4097. function() {
  4098. function AbstractFileManager2() {
  4099. }
  4100. AbstractFileManager2.prototype.getPath = function(filename) {
  4101. var j = filename.lastIndexOf("?");
  4102. if (j > 0) {
  4103. filename = filename.slice(0, j);
  4104. }
  4105. j = filename.lastIndexOf("/");
  4106. if (j < 0) {
  4107. j = filename.lastIndexOf("\\");
  4108. }
  4109. if (j < 0) {
  4110. return "";
  4111. }
  4112. return filename.slice(0, j + 1);
  4113. };
  4114. AbstractFileManager2.prototype.tryAppendExtension = function(path, ext) {
  4115. return /(\.[a-z]*$)|([\?;].*)$/.test(path) ? path : path + ext;
  4116. };
  4117. AbstractFileManager2.prototype.tryAppendLessExtension = function(path) {
  4118. return this.tryAppendExtension(path, ".less");
  4119. };
  4120. AbstractFileManager2.prototype.supportsSync = function() {
  4121. return false;
  4122. };
  4123. AbstractFileManager2.prototype.alwaysMakePathsAbsolute = function() {
  4124. return false;
  4125. };
  4126. AbstractFileManager2.prototype.isPathAbsolute = function(filename) {
  4127. return /^(?:[a-z-]+:|\/|\\|#)/i.test(filename);
  4128. };
  4129. AbstractFileManager2.prototype.join = function(basePath, laterPath) {
  4130. if (!basePath) {
  4131. return laterPath;
  4132. }
  4133. return basePath + laterPath;
  4134. };
  4135. AbstractFileManager2.prototype.pathDiff = function(url, baseUrl) {
  4136. var urlParts = this.extractUrlParts(url);
  4137. var baseUrlParts = this.extractUrlParts(baseUrl);
  4138. var i;
  4139. var max;
  4140. var urlDirectories;
  4141. var baseUrlDirectories;
  4142. var diff = "";
  4143. if (urlParts.hostPart !== baseUrlParts.hostPart) {
  4144. return "";
  4145. }
  4146. max = Math.max(baseUrlParts.directories.length, urlParts.directories.length);
  4147. for (i = 0; i < max; i++) {
  4148. if (baseUrlParts.directories[i] !== urlParts.directories[i]) {
  4149. break;
  4150. }
  4151. }
  4152. baseUrlDirectories = baseUrlParts.directories.slice(i);
  4153. urlDirectories = urlParts.directories.slice(i);
  4154. for (i = 0; i < baseUrlDirectories.length - 1; i++) {
  4155. diff += "../";
  4156. }
  4157. for (i = 0; i < urlDirectories.length - 1; i++) {
  4158. diff += urlDirectories[i] + "/";
  4159. }
  4160. return diff;
  4161. };
  4162. AbstractFileManager2.prototype.extractUrlParts = function(url, baseUrl) {
  4163. var urlPartsRegex = /^((?:[a-z-]+:)?\/{2}(?:[^\/\?#]*\/)|([\/\\]))?((?:[^\/\\\?#]*[\/\\])*)([^\/\\\?#]*)([#\?].*)?$/i;
  4164. var urlParts = url.match(urlPartsRegex);
  4165. var returner = {};
  4166. var rawDirectories = [];
  4167. var directories = [];
  4168. var i;
  4169. var baseUrlParts;
  4170. if (!urlParts) {
  4171. throw new Error("Could not parse sheet href - '" + url + "'");
  4172. }
  4173. if (baseUrl && (!urlParts[1] || urlParts[2])) {
  4174. baseUrlParts = baseUrl.match(urlPartsRegex);
  4175. if (!baseUrlParts) {
  4176. throw new Error("Could not parse page url - '" + baseUrl + "'");
  4177. }
  4178. urlParts[1] = urlParts[1] || baseUrlParts[1] || "";
  4179. if (!urlParts[2]) {
  4180. urlParts[3] = baseUrlParts[3] + urlParts[3];
  4181. }
  4182. }
  4183. if (urlParts[3]) {
  4184. rawDirectories = urlParts[3].replace(/\\/g, "/").split("/");
  4185. for (i = 0; i < rawDirectories.length; i++) {
  4186. if (rawDirectories[i] === "..") {
  4187. directories.pop();
  4188. } else if (rawDirectories[i] !== ".") {
  4189. directories.push(rawDirectories[i]);
  4190. }
  4191. }
  4192. }
  4193. returner.hostPart = urlParts[1];
  4194. returner.directories = directories;
  4195. returner.rawPath = (urlParts[1] || "") + rawDirectories.join("/");
  4196. returner.path = (urlParts[1] || "") + directories.join("/");
  4197. returner.filename = urlParts[4];
  4198. returner.fileUrl = returner.path + (urlParts[4] || "");
  4199. returner.url = returner.fileUrl + (urlParts[5] || "");
  4200. return returner;
  4201. };
  4202. return AbstractFileManager2;
  4203. }()
  4204. );
  4205. var AbstractPluginLoader = (
  4206. /** @class */
  4207. function() {
  4208. function AbstractPluginLoader2() {
  4209. this.require = function() {
  4210. return null;
  4211. };
  4212. }
  4213. AbstractPluginLoader2.prototype.evalPlugin = function(contents, context, imports, pluginOptions, fileInfo) {
  4214. var loader, registry, pluginObj, localModule, pluginManager, filename, result;
  4215. pluginManager = context.pluginManager;
  4216. if (fileInfo) {
  4217. if (typeof fileInfo === "string") {
  4218. filename = fileInfo;
  4219. } else {
  4220. filename = fileInfo.filename;
  4221. }
  4222. }
  4223. var shortname = new this.less.FileManager().extractUrlParts(filename).filename;
  4224. if (filename) {
  4225. pluginObj = pluginManager.get(filename);
  4226. if (pluginObj) {
  4227. result = this.trySetOptions(pluginObj, filename, shortname, pluginOptions);
  4228. if (result) {
  4229. return result;
  4230. }
  4231. try {
  4232. if (pluginObj.use) {
  4233. pluginObj.use.call(this.context, pluginObj);
  4234. }
  4235. } catch (e) {
  4236. e.message = e.message || "Error during @plugin call";
  4237. return new LessError(e, imports, filename);
  4238. }
  4239. return pluginObj;
  4240. }
  4241. }
  4242. localModule = {
  4243. exports: {},
  4244. pluginManager,
  4245. fileInfo
  4246. };
  4247. registry = functionRegistry.create();
  4248. var registerPlugin = function(obj) {
  4249. pluginObj = obj;
  4250. };
  4251. try {
  4252. loader = new Function("module", "require", "registerPlugin", "functions", "tree", "less", "fileInfo", contents);
  4253. loader(localModule, this.require(filename), registerPlugin, registry, this.less.tree, this.less, fileInfo);
  4254. } catch (e) {
  4255. return new LessError(e, imports, filename);
  4256. }
  4257. if (!pluginObj) {
  4258. pluginObj = localModule.exports;
  4259. }
  4260. pluginObj = this.validatePlugin(pluginObj, filename, shortname);
  4261. if (pluginObj instanceof LessError) {
  4262. return pluginObj;
  4263. }
  4264. if (pluginObj) {
  4265. pluginObj.imports = imports;
  4266. pluginObj.filename = filename;
  4267. if (!pluginObj.minVersion || this.compareVersion("3.0.0", pluginObj.minVersion) < 0) {
  4268. result = this.trySetOptions(pluginObj, filename, shortname, pluginOptions);
  4269. if (result) {
  4270. return result;
  4271. }
  4272. }
  4273. pluginManager.addPlugin(pluginObj, fileInfo.filename, registry);
  4274. pluginObj.functions = registry.getLocalFunctions();
  4275. result = this.trySetOptions(pluginObj, filename, shortname, pluginOptions);
  4276. if (result) {
  4277. return result;
  4278. }
  4279. try {
  4280. if (pluginObj.use) {
  4281. pluginObj.use.call(this.context, pluginObj);
  4282. }
  4283. } catch (e) {
  4284. e.message = e.message || "Error during @plugin call";
  4285. return new LessError(e, imports, filename);
  4286. }
  4287. } else {
  4288. return new LessError({ message: "Not a valid plugin" }, imports, filename);
  4289. }
  4290. return pluginObj;
  4291. };
  4292. AbstractPluginLoader2.prototype.trySetOptions = function(plugin, filename, name, options2) {
  4293. if (options2 && !plugin.setOptions) {
  4294. return new LessError({
  4295. message: "Options have been provided but the plugin " + name + " does not support any options."
  4296. });
  4297. }
  4298. try {
  4299. plugin.setOptions && plugin.setOptions(options2);
  4300. } catch (e) {
  4301. return new LessError(e);
  4302. }
  4303. };
  4304. AbstractPluginLoader2.prototype.validatePlugin = function(plugin, filename, name) {
  4305. if (plugin) {
  4306. if (typeof plugin === "function") {
  4307. plugin = new plugin();
  4308. }
  4309. if (plugin.minVersion) {
  4310. if (this.compareVersion(plugin.minVersion, this.less.version) < 0) {
  4311. return new LessError({
  4312. message: "Plugin " + name + " requires version " + this.versionToString(plugin.minVersion)
  4313. });
  4314. }
  4315. }
  4316. return plugin;
  4317. }
  4318. return null;
  4319. };
  4320. AbstractPluginLoader2.prototype.compareVersion = function(aVersion, bVersion) {
  4321. if (typeof aVersion === "string") {
  4322. aVersion = aVersion.match(/^(\d+)\.?(\d+)?\.?(\d+)?/);
  4323. aVersion.shift();
  4324. }
  4325. for (var i = 0; i < aVersion.length; i++) {
  4326. if (aVersion[i] !== bVersion[i]) {
  4327. return parseInt(aVersion[i]) > parseInt(bVersion[i]) ? -1 : 1;
  4328. }
  4329. }
  4330. return 0;
  4331. };
  4332. AbstractPluginLoader2.prototype.versionToString = function(version2) {
  4333. var versionString = "";
  4334. for (var i = 0; i < version2.length; i++) {
  4335. versionString += (versionString ? "." : "") + version2[i];
  4336. }
  4337. return versionString;
  4338. };
  4339. AbstractPluginLoader2.prototype.printUsage = function(plugins) {
  4340. for (var i = 0; i < plugins.length; i++) {
  4341. var plugin = plugins[i];
  4342. if (plugin.printUsage) {
  4343. plugin.printUsage();
  4344. }
  4345. }
  4346. };
  4347. return AbstractPluginLoader2;
  4348. }()
  4349. );
  4350. var _visitArgs = { visitDeeper: true };
  4351. var _hasIndexed = false;
  4352. function _noop(node) {
  4353. return node;
  4354. }
  4355. function indexNodeTypes(parent, ticker) {
  4356. var key2, child;
  4357. for (key2 in parent) {
  4358. child = parent[key2];
  4359. switch (typeof child) {
  4360. case "function":
  4361. if (child.prototype && child.prototype.type) {
  4362. child.prototype.typeIndex = ticker++;
  4363. }
  4364. break;
  4365. case "object":
  4366. ticker = indexNodeTypes(child, ticker);
  4367. break;
  4368. }
  4369. }
  4370. return ticker;
  4371. }
  4372. var Visitor = (
  4373. /** @class */
  4374. function() {
  4375. function Visitor2(implementation) {
  4376. this._implementation = implementation;
  4377. this._visitInCache = {};
  4378. this._visitOutCache = {};
  4379. if (!_hasIndexed) {
  4380. indexNodeTypes(tree, 1);
  4381. _hasIndexed = true;
  4382. }
  4383. }
  4384. Visitor2.prototype.visit = function(node) {
  4385. if (!node) {
  4386. return node;
  4387. }
  4388. var nodeTypeIndex = node.typeIndex;
  4389. if (!nodeTypeIndex) {
  4390. if (node.value && node.value.typeIndex) {
  4391. this.visit(node.value);
  4392. }
  4393. return node;
  4394. }
  4395. var impl = this._implementation;
  4396. var func = this._visitInCache[nodeTypeIndex];
  4397. var funcOut = this._visitOutCache[nodeTypeIndex];
  4398. var visitArgs = _visitArgs;
  4399. var fnName;
  4400. visitArgs.visitDeeper = true;
  4401. if (!func) {
  4402. fnName = "visit" + node.type;
  4403. func = impl[fnName] || _noop;
  4404. funcOut = impl[fnName + "Out"] || _noop;
  4405. this._visitInCache[nodeTypeIndex] = func;
  4406. this._visitOutCache[nodeTypeIndex] = funcOut;
  4407. }
  4408. if (func !== _noop) {
  4409. var newNode = func.call(impl, node, visitArgs);
  4410. if (node && impl.isReplacing) {
  4411. node = newNode;
  4412. }
  4413. }
  4414. if (visitArgs.visitDeeper && node) {
  4415. if (node.length) {
  4416. for (var i = 0, cnt = node.length; i < cnt; i++) {
  4417. if (node[i].accept) {
  4418. node[i].accept(this);
  4419. }
  4420. }
  4421. } else if (node.accept) {
  4422. node.accept(this);
  4423. }
  4424. }
  4425. if (funcOut != _noop) {
  4426. funcOut.call(impl, node);
  4427. }
  4428. return node;
  4429. };
  4430. Visitor2.prototype.visitArray = function(nodes, nonReplacing) {
  4431. if (!nodes) {
  4432. return nodes;
  4433. }
  4434. var cnt = nodes.length;
  4435. var i;
  4436. if (nonReplacing || !this._implementation.isReplacing) {
  4437. for (i = 0; i < cnt; i++) {
  4438. this.visit(nodes[i]);
  4439. }
  4440. return nodes;
  4441. }
  4442. var out = [];
  4443. for (i = 0; i < cnt; i++) {
  4444. var evald = this.visit(nodes[i]);
  4445. if (evald === void 0) {
  4446. continue;
  4447. }
  4448. if (!evald.splice) {
  4449. out.push(evald);
  4450. } else if (evald.length) {
  4451. this.flatten(evald, out);
  4452. }
  4453. }
  4454. return out;
  4455. };
  4456. Visitor2.prototype.flatten = function(arr, out) {
  4457. if (!out) {
  4458. out = [];
  4459. }
  4460. var cnt, i, item, nestedCnt, j, nestedItem;
  4461. for (i = 0, cnt = arr.length; i < cnt; i++) {
  4462. item = arr[i];
  4463. if (item === void 0) {
  4464. continue;
  4465. }
  4466. if (!item.splice) {
  4467. out.push(item);
  4468. continue;
  4469. }
  4470. for (j = 0, nestedCnt = item.length; j < nestedCnt; j++) {
  4471. nestedItem = item[j];
  4472. if (nestedItem === void 0) {
  4473. continue;
  4474. }
  4475. if (!nestedItem.splice) {
  4476. out.push(nestedItem);
  4477. } else if (nestedItem.length) {
  4478. this.flatten(nestedItem, out);
  4479. }
  4480. }
  4481. }
  4482. return out;
  4483. };
  4484. return Visitor2;
  4485. }()
  4486. );
  4487. var ImportSequencer = (
  4488. /** @class */
  4489. function() {
  4490. function ImportSequencer2(onSequencerEmpty) {
  4491. this.imports = [];
  4492. this.variableImports = [];
  4493. this._onSequencerEmpty = onSequencerEmpty;
  4494. this._currentDepth = 0;
  4495. }
  4496. ImportSequencer2.prototype.addImport = function(callback) {
  4497. var importSequencer = this, importItem = {
  4498. callback,
  4499. args: null,
  4500. isReady: false
  4501. };
  4502. this.imports.push(importItem);
  4503. return function() {
  4504. importItem.args = Array.prototype.slice.call(arguments, 0);
  4505. importItem.isReady = true;
  4506. importSequencer.tryRun();
  4507. };
  4508. };
  4509. ImportSequencer2.prototype.addVariableImport = function(callback) {
  4510. this.variableImports.push(callback);
  4511. };
  4512. ImportSequencer2.prototype.tryRun = function() {
  4513. this._currentDepth++;
  4514. try {
  4515. while (true) {
  4516. while (this.imports.length > 0) {
  4517. var importItem = this.imports[0];
  4518. if (!importItem.isReady) {
  4519. return;
  4520. }
  4521. this.imports = this.imports.slice(1);
  4522. importItem.callback.apply(null, importItem.args);
  4523. }
  4524. if (this.variableImports.length === 0) {
  4525. break;
  4526. }
  4527. var variableImport = this.variableImports[0];
  4528. this.variableImports = this.variableImports.slice(1);
  4529. variableImport();
  4530. }
  4531. } finally {
  4532. this._currentDepth--;
  4533. }
  4534. if (this._currentDepth === 0 && this._onSequencerEmpty) {
  4535. this._onSequencerEmpty();
  4536. }
  4537. };
  4538. return ImportSequencer2;
  4539. }()
  4540. );
  4541. var ImportVisitor = function(importer, finish) {
  4542. this._visitor = new Visitor(this);
  4543. this._importer = importer;
  4544. this._finish = finish;
  4545. this.context = new contexts.Eval();
  4546. this.importCount = 0;
  4547. this.onceFileDetectionMap = {};
  4548. this.recursionDetector = {};
  4549. this._sequencer = new ImportSequencer(this._onSequencerEmpty.bind(this));
  4550. };
  4551. ImportVisitor.prototype = {
  4552. isReplacing: false,
  4553. run: function(root2) {
  4554. try {
  4555. this._visitor.visit(root2);
  4556. } catch (e) {
  4557. this.error = e;
  4558. }
  4559. this.isFinished = true;
  4560. this._sequencer.tryRun();
  4561. },
  4562. _onSequencerEmpty: function() {
  4563. if (!this.isFinished) {
  4564. return;
  4565. }
  4566. this._finish(this.error);
  4567. },
  4568. visitImport: function(importNode, visitArgs) {
  4569. var inlineCSS = importNode.options.inline;
  4570. if (!importNode.css || inlineCSS) {
  4571. var context = new contexts.Eval(this.context, copyArray(this.context.frames));
  4572. var importParent = context.frames[0];
  4573. this.importCount++;
  4574. if (importNode.isVariableImport()) {
  4575. this._sequencer.addVariableImport(this.processImportNode.bind(this, importNode, context, importParent));
  4576. } else {
  4577. this.processImportNode(importNode, context, importParent);
  4578. }
  4579. }
  4580. visitArgs.visitDeeper = false;
  4581. },
  4582. processImportNode: function(importNode, context, importParent) {
  4583. var evaldImportNode;
  4584. var inlineCSS = importNode.options.inline;
  4585. try {
  4586. evaldImportNode = importNode.evalForImport(context);
  4587. } catch (e) {
  4588. if (!e.filename) {
  4589. e.index = importNode.getIndex();
  4590. e.filename = importNode.fileInfo().filename;
  4591. }
  4592. importNode.css = true;
  4593. importNode.error = e;
  4594. }
  4595. if (evaldImportNode && (!evaldImportNode.css || inlineCSS)) {
  4596. if (evaldImportNode.options.multiple) {
  4597. context.importMultiple = true;
  4598. }
  4599. var tryAppendLessExtension = evaldImportNode.css === void 0;
  4600. for (var i = 0; i < importParent.rules.length; i++) {
  4601. if (importParent.rules[i] === importNode) {
  4602. importParent.rules[i] = evaldImportNode;
  4603. break;
  4604. }
  4605. }
  4606. var onImported = this.onImported.bind(this, evaldImportNode, context), sequencedOnImported = this._sequencer.addImport(onImported);
  4607. this._importer.push(evaldImportNode.getPath(), tryAppendLessExtension, evaldImportNode.fileInfo(), evaldImportNode.options, sequencedOnImported);
  4608. } else {
  4609. this.importCount--;
  4610. if (this.isFinished) {
  4611. this._sequencer.tryRun();
  4612. }
  4613. }
  4614. },
  4615. onImported: function(importNode, context, e, root2, importedAtRoot, fullPath) {
  4616. if (e) {
  4617. if (!e.filename) {
  4618. e.index = importNode.getIndex();
  4619. e.filename = importNode.fileInfo().filename;
  4620. }
  4621. this.error = e;
  4622. }
  4623. var importVisitor = this, inlineCSS = importNode.options.inline, isPlugin = importNode.options.isPlugin, isOptional = importNode.options.optional, duplicateImport = importedAtRoot || fullPath in importVisitor.recursionDetector;
  4624. if (!context.importMultiple) {
  4625. if (duplicateImport) {
  4626. importNode.skip = true;
  4627. } else {
  4628. importNode.skip = function() {
  4629. if (fullPath in importVisitor.onceFileDetectionMap) {
  4630. return true;
  4631. }
  4632. importVisitor.onceFileDetectionMap[fullPath] = true;
  4633. return false;
  4634. };
  4635. }
  4636. }
  4637. if (!fullPath && isOptional) {
  4638. importNode.skip = true;
  4639. }
  4640. if (root2) {
  4641. importNode.root = root2;
  4642. importNode.importedFilename = fullPath;
  4643. if (!inlineCSS && !isPlugin && (context.importMultiple || !duplicateImport)) {
  4644. importVisitor.recursionDetector[fullPath] = true;
  4645. var oldContext = this.context;
  4646. this.context = context;
  4647. try {
  4648. this._visitor.visit(root2);
  4649. } catch (e2) {
  4650. this.error = e2;
  4651. }
  4652. this.context = oldContext;
  4653. }
  4654. }
  4655. importVisitor.importCount--;
  4656. if (importVisitor.isFinished) {
  4657. importVisitor._sequencer.tryRun();
  4658. }
  4659. },
  4660. visitDeclaration: function(declNode, visitArgs) {
  4661. if (declNode.value.type === "DetachedRuleset") {
  4662. this.context.frames.unshift(declNode);
  4663. } else {
  4664. visitArgs.visitDeeper = false;
  4665. }
  4666. },
  4667. visitDeclarationOut: function(declNode) {
  4668. if (declNode.value.type === "DetachedRuleset") {
  4669. this.context.frames.shift();
  4670. }
  4671. },
  4672. visitAtRule: function(atRuleNode, visitArgs) {
  4673. this.context.frames.unshift(atRuleNode);
  4674. },
  4675. visitAtRuleOut: function(atRuleNode) {
  4676. this.context.frames.shift();
  4677. },
  4678. visitMixinDefinition: function(mixinDefinitionNode, visitArgs) {
  4679. this.context.frames.unshift(mixinDefinitionNode);
  4680. },
  4681. visitMixinDefinitionOut: function(mixinDefinitionNode) {
  4682. this.context.frames.shift();
  4683. },
  4684. visitRuleset: function(rulesetNode, visitArgs) {
  4685. this.context.frames.unshift(rulesetNode);
  4686. },
  4687. visitRulesetOut: function(rulesetNode) {
  4688. this.context.frames.shift();
  4689. },
  4690. visitMedia: function(mediaNode, visitArgs) {
  4691. this.context.frames.unshift(mediaNode.rules[0]);
  4692. },
  4693. visitMediaOut: function(mediaNode) {
  4694. this.context.frames.shift();
  4695. }
  4696. };
  4697. var SetTreeVisibilityVisitor = (
  4698. /** @class */
  4699. function() {
  4700. function SetTreeVisibilityVisitor2(visible) {
  4701. this.visible = visible;
  4702. }
  4703. SetTreeVisibilityVisitor2.prototype.run = function(root2) {
  4704. this.visit(root2);
  4705. };
  4706. SetTreeVisibilityVisitor2.prototype.visitArray = function(nodes) {
  4707. if (!nodes) {
  4708. return nodes;
  4709. }
  4710. var cnt = nodes.length;
  4711. var i;
  4712. for (i = 0; i < cnt; i++) {
  4713. this.visit(nodes[i]);
  4714. }
  4715. return nodes;
  4716. };
  4717. SetTreeVisibilityVisitor2.prototype.visit = function(node) {
  4718. if (!node) {
  4719. return node;
  4720. }
  4721. if (node.constructor === Array) {
  4722. return this.visitArray(node);
  4723. }
  4724. if (!node.blocksVisibility || node.blocksVisibility()) {
  4725. return node;
  4726. }
  4727. if (this.visible) {
  4728. node.ensureVisibility();
  4729. } else {
  4730. node.ensureInvisibility();
  4731. }
  4732. node.accept(this);
  4733. return node;
  4734. };
  4735. return SetTreeVisibilityVisitor2;
  4736. }()
  4737. );
  4738. var ExtendFinderVisitor = (
  4739. /** @class */
  4740. function() {
  4741. function ExtendFinderVisitor2() {
  4742. this._visitor = new Visitor(this);
  4743. this.contexts = [];
  4744. this.allExtendsStack = [[]];
  4745. }
  4746. ExtendFinderVisitor2.prototype.run = function(root2) {
  4747. root2 = this._visitor.visit(root2);
  4748. root2.allExtends = this.allExtendsStack[0];
  4749. return root2;
  4750. };
  4751. ExtendFinderVisitor2.prototype.visitDeclaration = function(declNode, visitArgs) {
  4752. visitArgs.visitDeeper = false;
  4753. };
  4754. ExtendFinderVisitor2.prototype.visitMixinDefinition = function(mixinDefinitionNode, visitArgs) {
  4755. visitArgs.visitDeeper = false;
  4756. };
  4757. ExtendFinderVisitor2.prototype.visitRuleset = function(rulesetNode, visitArgs) {
  4758. if (rulesetNode.root) {
  4759. return;
  4760. }
  4761. var i;
  4762. var j;
  4763. var extend;
  4764. var allSelectorsExtendList = [];
  4765. var extendList;
  4766. var rules = rulesetNode.rules, ruleCnt = rules ? rules.length : 0;
  4767. for (i = 0; i < ruleCnt; i++) {
  4768. if (rulesetNode.rules[i] instanceof tree.Extend) {
  4769. allSelectorsExtendList.push(rules[i]);
  4770. rulesetNode.extendOnEveryPath = true;
  4771. }
  4772. }
  4773. var paths = rulesetNode.paths;
  4774. for (i = 0; i < paths.length; i++) {
  4775. var selectorPath = paths[i], selector = selectorPath[selectorPath.length - 1], selExtendList = selector.extendList;
  4776. extendList = selExtendList ? copyArray(selExtendList).concat(allSelectorsExtendList) : allSelectorsExtendList;
  4777. if (extendList) {
  4778. extendList = extendList.map(function(allSelectorsExtend) {
  4779. return allSelectorsExtend.clone();
  4780. });
  4781. }
  4782. for (j = 0; j < extendList.length; j++) {
  4783. this.foundExtends = true;
  4784. extend = extendList[j];
  4785. extend.findSelfSelectors(selectorPath);
  4786. extend.ruleset = rulesetNode;
  4787. if (j === 0) {
  4788. extend.firstExtendOnThisSelectorPath = true;
  4789. }
  4790. this.allExtendsStack[this.allExtendsStack.length - 1].push(extend);
  4791. }
  4792. }
  4793. this.contexts.push(rulesetNode.selectors);
  4794. };
  4795. ExtendFinderVisitor2.prototype.visitRulesetOut = function(rulesetNode) {
  4796. if (!rulesetNode.root) {
  4797. this.contexts.length = this.contexts.length - 1;
  4798. }
  4799. };
  4800. ExtendFinderVisitor2.prototype.visitMedia = function(mediaNode, visitArgs) {
  4801. mediaNode.allExtends = [];
  4802. this.allExtendsStack.push(mediaNode.allExtends);
  4803. };
  4804. ExtendFinderVisitor2.prototype.visitMediaOut = function(mediaNode) {
  4805. this.allExtendsStack.length = this.allExtendsStack.length - 1;
  4806. };
  4807. ExtendFinderVisitor2.prototype.visitAtRule = function(atRuleNode, visitArgs) {
  4808. atRuleNode.allExtends = [];
  4809. this.allExtendsStack.push(atRuleNode.allExtends);
  4810. };
  4811. ExtendFinderVisitor2.prototype.visitAtRuleOut = function(atRuleNode) {
  4812. this.allExtendsStack.length = this.allExtendsStack.length - 1;
  4813. };
  4814. return ExtendFinderVisitor2;
  4815. }()
  4816. );
  4817. var ProcessExtendsVisitor = (
  4818. /** @class */
  4819. function() {
  4820. function ProcessExtendsVisitor2() {
  4821. this._visitor = new Visitor(this);
  4822. }
  4823. ProcessExtendsVisitor2.prototype.run = function(root2) {
  4824. var extendFinder = new ExtendFinderVisitor();
  4825. this.extendIndices = {};
  4826. extendFinder.run(root2);
  4827. if (!extendFinder.foundExtends) {
  4828. return root2;
  4829. }
  4830. root2.allExtends = root2.allExtends.concat(this.doExtendChaining(root2.allExtends, root2.allExtends));
  4831. this.allExtendsStack = [root2.allExtends];
  4832. var newRoot = this._visitor.visit(root2);
  4833. this.checkExtendsForNonMatched(root2.allExtends);
  4834. return newRoot;
  4835. };
  4836. ProcessExtendsVisitor2.prototype.checkExtendsForNonMatched = function(extendList) {
  4837. var indices = this.extendIndices;
  4838. extendList.filter(function(extend) {
  4839. return !extend.hasFoundMatches && extend.parent_ids.length == 1;
  4840. }).forEach(function(extend) {
  4841. var selector = "_unknown_";
  4842. try {
  4843. selector = extend.selector.toCSS({});
  4844. } catch (_) {
  4845. }
  4846. if (!indices[extend.index + " " + selector]) {
  4847. indices[extend.index + " " + selector] = true;
  4848. logger$1.warn("extend '" + selector + "' has no matches");
  4849. }
  4850. });
  4851. };
  4852. ProcessExtendsVisitor2.prototype.doExtendChaining = function(extendsList, extendsListTarget, iterationCount) {
  4853. var extendIndex;
  4854. var targetExtendIndex;
  4855. var matches;
  4856. var extendsToAdd = [];
  4857. var newSelector;
  4858. var extendVisitor = this;
  4859. var selectorPath;
  4860. var extend;
  4861. var targetExtend;
  4862. var newExtend;
  4863. iterationCount = iterationCount || 0;
  4864. for (extendIndex = 0; extendIndex < extendsList.length; extendIndex++) {
  4865. for (targetExtendIndex = 0; targetExtendIndex < extendsListTarget.length; targetExtendIndex++) {
  4866. extend = extendsList[extendIndex];
  4867. targetExtend = extendsListTarget[targetExtendIndex];
  4868. if (extend.parent_ids.indexOf(targetExtend.object_id) >= 0) {
  4869. continue;
  4870. }
  4871. selectorPath = [targetExtend.selfSelectors[0]];
  4872. matches = extendVisitor.findMatch(extend, selectorPath);
  4873. if (matches.length) {
  4874. extend.hasFoundMatches = true;
  4875. extend.selfSelectors.forEach(function(selfSelector) {
  4876. var info = targetExtend.visibilityInfo();
  4877. newSelector = extendVisitor.extendSelector(matches, selectorPath, selfSelector, extend.isVisible());
  4878. newExtend = new tree.Extend(targetExtend.selector, targetExtend.option, 0, targetExtend.fileInfo(), info);
  4879. newExtend.selfSelectors = newSelector;
  4880. newSelector[newSelector.length - 1].extendList = [newExtend];
  4881. extendsToAdd.push(newExtend);
  4882. newExtend.ruleset = targetExtend.ruleset;
  4883. newExtend.parent_ids = newExtend.parent_ids.concat(targetExtend.parent_ids, extend.parent_ids);
  4884. if (targetExtend.firstExtendOnThisSelectorPath) {
  4885. newExtend.firstExtendOnThisSelectorPath = true;
  4886. targetExtend.ruleset.paths.push(newSelector);
  4887. }
  4888. });
  4889. }
  4890. }
  4891. }
  4892. if (extendsToAdd.length) {
  4893. this.extendChainCount++;
  4894. if (iterationCount > 100) {
  4895. var selectorOne = "{unable to calculate}";
  4896. var selectorTwo = "{unable to calculate}";
  4897. try {
  4898. selectorOne = extendsToAdd[0].selfSelectors[0].toCSS();
  4899. selectorTwo = extendsToAdd[0].selector.toCSS();
  4900. } catch (e) {
  4901. }
  4902. throw { message: "extend circular reference detected. One of the circular extends is currently:" + selectorOne + ":extend(" + selectorTwo + ")" };
  4903. }
  4904. return extendsToAdd.concat(extendVisitor.doExtendChaining(extendsToAdd, extendsListTarget, iterationCount + 1));
  4905. } else {
  4906. return extendsToAdd;
  4907. }
  4908. };
  4909. ProcessExtendsVisitor2.prototype.visitDeclaration = function(ruleNode, visitArgs) {
  4910. visitArgs.visitDeeper = false;
  4911. };
  4912. ProcessExtendsVisitor2.prototype.visitMixinDefinition = function(mixinDefinitionNode, visitArgs) {
  4913. visitArgs.visitDeeper = false;
  4914. };
  4915. ProcessExtendsVisitor2.prototype.visitSelector = function(selectorNode, visitArgs) {
  4916. visitArgs.visitDeeper = false;
  4917. };
  4918. ProcessExtendsVisitor2.prototype.visitRuleset = function(rulesetNode, visitArgs) {
  4919. if (rulesetNode.root) {
  4920. return;
  4921. }
  4922. var matches;
  4923. var pathIndex;
  4924. var extendIndex;
  4925. var allExtends = this.allExtendsStack[this.allExtendsStack.length - 1];
  4926. var selectorsToAdd = [];
  4927. var extendVisitor = this;
  4928. var selectorPath;
  4929. for (extendIndex = 0; extendIndex < allExtends.length; extendIndex++) {
  4930. for (pathIndex = 0; pathIndex < rulesetNode.paths.length; pathIndex++) {
  4931. selectorPath = rulesetNode.paths[pathIndex];
  4932. if (rulesetNode.extendOnEveryPath) {
  4933. continue;
  4934. }
  4935. var extendList = selectorPath[selectorPath.length - 1].extendList;
  4936. if (extendList && extendList.length) {
  4937. continue;
  4938. }
  4939. matches = this.findMatch(allExtends[extendIndex], selectorPath);
  4940. if (matches.length) {
  4941. allExtends[extendIndex].hasFoundMatches = true;
  4942. allExtends[extendIndex].selfSelectors.forEach(function(selfSelector) {
  4943. var extendedSelectors;
  4944. extendedSelectors = extendVisitor.extendSelector(matches, selectorPath, selfSelector, allExtends[extendIndex].isVisible());
  4945. selectorsToAdd.push(extendedSelectors);
  4946. });
  4947. }
  4948. }
  4949. }
  4950. rulesetNode.paths = rulesetNode.paths.concat(selectorsToAdd);
  4951. };
  4952. ProcessExtendsVisitor2.prototype.findMatch = function(extend, haystackSelectorPath) {
  4953. var haystackSelectorIndex;
  4954. var hackstackSelector;
  4955. var hackstackElementIndex;
  4956. var haystackElement;
  4957. var targetCombinator;
  4958. var i;
  4959. var extendVisitor = this;
  4960. var needleElements = extend.selector.elements;
  4961. var potentialMatches = [];
  4962. var potentialMatch;
  4963. var matches = [];
  4964. for (haystackSelectorIndex = 0; haystackSelectorIndex < haystackSelectorPath.length; haystackSelectorIndex++) {
  4965. hackstackSelector = haystackSelectorPath[haystackSelectorIndex];
  4966. for (hackstackElementIndex = 0; hackstackElementIndex < hackstackSelector.elements.length; hackstackElementIndex++) {
  4967. haystackElement = hackstackSelector.elements[hackstackElementIndex];
  4968. if (extend.allowBefore || haystackSelectorIndex === 0 && hackstackElementIndex === 0) {
  4969. potentialMatches.push({
  4970. pathIndex: haystackSelectorIndex,
  4971. index: hackstackElementIndex,
  4972. matched: 0,
  4973. initialCombinator: haystackElement.combinator
  4974. });
  4975. }
  4976. for (i = 0; i < potentialMatches.length; i++) {
  4977. potentialMatch = potentialMatches[i];
  4978. targetCombinator = haystackElement.combinator.value;
  4979. if (targetCombinator === "" && hackstackElementIndex === 0) {
  4980. targetCombinator = " ";
  4981. }
  4982. if (!extendVisitor.isElementValuesEqual(needleElements[potentialMatch.matched].value, haystackElement.value) || potentialMatch.matched > 0 && needleElements[potentialMatch.matched].combinator.value !== targetCombinator) {
  4983. potentialMatch = null;
  4984. } else {
  4985. potentialMatch.matched++;
  4986. }
  4987. if (potentialMatch) {
  4988. potentialMatch.finished = potentialMatch.matched === needleElements.length;
  4989. if (potentialMatch.finished && (!extend.allowAfter && (hackstackElementIndex + 1 < hackstackSelector.elements.length || haystackSelectorIndex + 1 < haystackSelectorPath.length))) {
  4990. potentialMatch = null;
  4991. }
  4992. }
  4993. if (potentialMatch) {
  4994. if (potentialMatch.finished) {
  4995. potentialMatch.length = needleElements.length;
  4996. potentialMatch.endPathIndex = haystackSelectorIndex;
  4997. potentialMatch.endPathElementIndex = hackstackElementIndex + 1;
  4998. potentialMatches.length = 0;
  4999. matches.push(potentialMatch);
  5000. }
  5001. } else {
  5002. potentialMatches.splice(i, 1);
  5003. i--;
  5004. }
  5005. }
  5006. }
  5007. }
  5008. return matches;
  5009. };
  5010. ProcessExtendsVisitor2.prototype.isElementValuesEqual = function(elementValue1, elementValue2) {
  5011. if (typeof elementValue1 === "string" || typeof elementValue2 === "string") {
  5012. return elementValue1 === elementValue2;
  5013. }
  5014. if (elementValue1 instanceof tree.Attribute) {
  5015. if (elementValue1.op !== elementValue2.op || elementValue1.key !== elementValue2.key) {
  5016. return false;
  5017. }
  5018. if (!elementValue1.value || !elementValue2.value) {
  5019. if (elementValue1.value || elementValue2.value) {
  5020. return false;
  5021. }
  5022. return true;
  5023. }
  5024. elementValue1 = elementValue1.value.value || elementValue1.value;
  5025. elementValue2 = elementValue2.value.value || elementValue2.value;
  5026. return elementValue1 === elementValue2;
  5027. }
  5028. elementValue1 = elementValue1.value;
  5029. elementValue2 = elementValue2.value;
  5030. if (elementValue1 instanceof tree.Selector) {
  5031. if (!(elementValue2 instanceof tree.Selector) || elementValue1.elements.length !== elementValue2.elements.length) {
  5032. return false;
  5033. }
  5034. for (var i = 0; i < elementValue1.elements.length; i++) {
  5035. if (elementValue1.elements[i].combinator.value !== elementValue2.elements[i].combinator.value) {
  5036. if (i !== 0 || (elementValue1.elements[i].combinator.value || " ") !== (elementValue2.elements[i].combinator.value || " ")) {
  5037. return false;
  5038. }
  5039. }
  5040. if (!this.isElementValuesEqual(elementValue1.elements[i].value, elementValue2.elements[i].value)) {
  5041. return false;
  5042. }
  5043. }
  5044. return true;
  5045. }
  5046. return false;
  5047. };
  5048. ProcessExtendsVisitor2.prototype.extendSelector = function(matches, selectorPath, replacementSelector, isVisible) {
  5049. var currentSelectorPathIndex = 0, currentSelectorPathElementIndex = 0, path = [], matchIndex, selector, firstElement, match, newElements;
  5050. for (matchIndex = 0; matchIndex < matches.length; matchIndex++) {
  5051. match = matches[matchIndex];
  5052. selector = selectorPath[match.pathIndex];
  5053. firstElement = new tree.Element(match.initialCombinator, replacementSelector.elements[0].value, replacementSelector.elements[0].isVariable, replacementSelector.elements[0].getIndex(), replacementSelector.elements[0].fileInfo());
  5054. if (match.pathIndex > currentSelectorPathIndex && currentSelectorPathElementIndex > 0) {
  5055. path[path.length - 1].elements = path[path.length - 1].elements.concat(selectorPath[currentSelectorPathIndex].elements.slice(currentSelectorPathElementIndex));
  5056. currentSelectorPathElementIndex = 0;
  5057. currentSelectorPathIndex++;
  5058. }
  5059. newElements = selector.elements.slice(currentSelectorPathElementIndex, match.index).concat([firstElement]).concat(replacementSelector.elements.slice(1));
  5060. if (currentSelectorPathIndex === match.pathIndex && matchIndex > 0) {
  5061. path[path.length - 1].elements = path[path.length - 1].elements.concat(newElements);
  5062. } else {
  5063. path = path.concat(selectorPath.slice(currentSelectorPathIndex, match.pathIndex));
  5064. path.push(new tree.Selector(newElements));
  5065. }
  5066. currentSelectorPathIndex = match.endPathIndex;
  5067. currentSelectorPathElementIndex = match.endPathElementIndex;
  5068. if (currentSelectorPathElementIndex >= selectorPath[currentSelectorPathIndex].elements.length) {
  5069. currentSelectorPathElementIndex = 0;
  5070. currentSelectorPathIndex++;
  5071. }
  5072. }
  5073. if (currentSelectorPathIndex < selectorPath.length && currentSelectorPathElementIndex > 0) {
  5074. path[path.length - 1].elements = path[path.length - 1].elements.concat(selectorPath[currentSelectorPathIndex].elements.slice(currentSelectorPathElementIndex));
  5075. currentSelectorPathIndex++;
  5076. }
  5077. path = path.concat(selectorPath.slice(currentSelectorPathIndex, selectorPath.length));
  5078. path = path.map(function(currentValue) {
  5079. var derived = currentValue.createDerived(currentValue.elements);
  5080. if (isVisible) {
  5081. derived.ensureVisibility();
  5082. } else {
  5083. derived.ensureInvisibility();
  5084. }
  5085. return derived;
  5086. });
  5087. return path;
  5088. };
  5089. ProcessExtendsVisitor2.prototype.visitMedia = function(mediaNode, visitArgs) {
  5090. var newAllExtends = mediaNode.allExtends.concat(this.allExtendsStack[this.allExtendsStack.length - 1]);
  5091. newAllExtends = newAllExtends.concat(this.doExtendChaining(newAllExtends, mediaNode.allExtends));
  5092. this.allExtendsStack.push(newAllExtends);
  5093. };
  5094. ProcessExtendsVisitor2.prototype.visitMediaOut = function(mediaNode) {
  5095. var lastIndex = this.allExtendsStack.length - 1;
  5096. this.allExtendsStack.length = lastIndex;
  5097. };
  5098. ProcessExtendsVisitor2.prototype.visitAtRule = function(atRuleNode, visitArgs) {
  5099. var newAllExtends = atRuleNode.allExtends.concat(this.allExtendsStack[this.allExtendsStack.length - 1]);
  5100. newAllExtends = newAllExtends.concat(this.doExtendChaining(newAllExtends, atRuleNode.allExtends));
  5101. this.allExtendsStack.push(newAllExtends);
  5102. };
  5103. ProcessExtendsVisitor2.prototype.visitAtRuleOut = function(atRuleNode) {
  5104. var lastIndex = this.allExtendsStack.length - 1;
  5105. this.allExtendsStack.length = lastIndex;
  5106. };
  5107. return ProcessExtendsVisitor2;
  5108. }()
  5109. );
  5110. var JoinSelectorVisitor = (
  5111. /** @class */
  5112. function() {
  5113. function JoinSelectorVisitor2() {
  5114. this.contexts = [[]];
  5115. this._visitor = new Visitor(this);
  5116. }
  5117. JoinSelectorVisitor2.prototype.run = function(root2) {
  5118. return this._visitor.visit(root2);
  5119. };
  5120. JoinSelectorVisitor2.prototype.visitDeclaration = function(declNode, visitArgs) {
  5121. visitArgs.visitDeeper = false;
  5122. };
  5123. JoinSelectorVisitor2.prototype.visitMixinDefinition = function(mixinDefinitionNode, visitArgs) {
  5124. visitArgs.visitDeeper = false;
  5125. };
  5126. JoinSelectorVisitor2.prototype.visitRuleset = function(rulesetNode, visitArgs) {
  5127. var context = this.contexts[this.contexts.length - 1];
  5128. var paths = [];
  5129. var selectors;
  5130. this.contexts.push(paths);
  5131. if (!rulesetNode.root) {
  5132. selectors = rulesetNode.selectors;
  5133. if (selectors) {
  5134. selectors = selectors.filter(function(selector) {
  5135. return selector.getIsOutput();
  5136. });
  5137. rulesetNode.selectors = selectors.length ? selectors : selectors = null;
  5138. if (selectors) {
  5139. rulesetNode.joinSelectors(paths, context, selectors);
  5140. }
  5141. }
  5142. if (!selectors) {
  5143. rulesetNode.rules = null;
  5144. }
  5145. rulesetNode.paths = paths;
  5146. }
  5147. };
  5148. JoinSelectorVisitor2.prototype.visitRulesetOut = function(rulesetNode) {
  5149. this.contexts.length = this.contexts.length - 1;
  5150. };
  5151. JoinSelectorVisitor2.prototype.visitMedia = function(mediaNode, visitArgs) {
  5152. var context = this.contexts[this.contexts.length - 1];
  5153. mediaNode.rules[0].root = context.length === 0 || context[0].multiMedia;
  5154. };
  5155. JoinSelectorVisitor2.prototype.visitAtRule = function(atRuleNode, visitArgs) {
  5156. var context = this.contexts[this.contexts.length - 1];
  5157. if (atRuleNode.rules && atRuleNode.rules.length) {
  5158. atRuleNode.rules[0].root = atRuleNode.isRooted || context.length === 0 || null;
  5159. }
  5160. };
  5161. return JoinSelectorVisitor2;
  5162. }()
  5163. );
  5164. var CSSVisitorUtils = (
  5165. /** @class */
  5166. function() {
  5167. function CSSVisitorUtils2(context) {
  5168. this._visitor = new Visitor(this);
  5169. this._context = context;
  5170. }
  5171. CSSVisitorUtils2.prototype.containsSilentNonBlockedChild = function(bodyRules) {
  5172. var rule;
  5173. if (!bodyRules) {
  5174. return false;
  5175. }
  5176. for (var r = 0; r < bodyRules.length; r++) {
  5177. rule = bodyRules[r];
  5178. if (rule.isSilent && rule.isSilent(this._context) && !rule.blocksVisibility()) {
  5179. return true;
  5180. }
  5181. }
  5182. return false;
  5183. };
  5184. CSSVisitorUtils2.prototype.keepOnlyVisibleChilds = function(owner) {
  5185. if (owner && owner.rules) {
  5186. owner.rules = owner.rules.filter(function(thing) {
  5187. return thing.isVisible();
  5188. });
  5189. }
  5190. };
  5191. CSSVisitorUtils2.prototype.isEmpty = function(owner) {
  5192. return owner && owner.rules ? owner.rules.length === 0 : true;
  5193. };
  5194. CSSVisitorUtils2.prototype.hasVisibleSelector = function(rulesetNode) {
  5195. return rulesetNode && rulesetNode.paths ? rulesetNode.paths.length > 0 : false;
  5196. };
  5197. CSSVisitorUtils2.prototype.resolveVisibility = function(node, originalRules) {
  5198. if (!node.blocksVisibility()) {
  5199. if (this.isEmpty(node) && !this.containsSilentNonBlockedChild(originalRules)) {
  5200. return;
  5201. }
  5202. return node;
  5203. }
  5204. var compiledRulesBody = node.rules[0];
  5205. this.keepOnlyVisibleChilds(compiledRulesBody);
  5206. if (this.isEmpty(compiledRulesBody)) {
  5207. return;
  5208. }
  5209. node.ensureVisibility();
  5210. node.removeVisibilityBlock();
  5211. return node;
  5212. };
  5213. CSSVisitorUtils2.prototype.isVisibleRuleset = function(rulesetNode) {
  5214. if (rulesetNode.firstRoot) {
  5215. return true;
  5216. }
  5217. if (this.isEmpty(rulesetNode)) {
  5218. return false;
  5219. }
  5220. if (!rulesetNode.root && !this.hasVisibleSelector(rulesetNode)) {
  5221. return false;
  5222. }
  5223. return true;
  5224. };
  5225. return CSSVisitorUtils2;
  5226. }()
  5227. );
  5228. var ToCSSVisitor = function(context) {
  5229. this._visitor = new Visitor(this);
  5230. this._context = context;
  5231. this.utils = new CSSVisitorUtils(context);
  5232. };
  5233. ToCSSVisitor.prototype = {
  5234. isReplacing: true,
  5235. run: function(root2) {
  5236. return this._visitor.visit(root2);
  5237. },
  5238. visitDeclaration: function(declNode, visitArgs) {
  5239. if (declNode.blocksVisibility() || declNode.variable) {
  5240. return;
  5241. }
  5242. return declNode;
  5243. },
  5244. visitMixinDefinition: function(mixinNode, visitArgs) {
  5245. mixinNode.frames = [];
  5246. },
  5247. visitExtend: function(extendNode, visitArgs) {
  5248. },
  5249. visitComment: function(commentNode, visitArgs) {
  5250. if (commentNode.blocksVisibility() || commentNode.isSilent(this._context)) {
  5251. return;
  5252. }
  5253. return commentNode;
  5254. },
  5255. visitMedia: function(mediaNode, visitArgs) {
  5256. var originalRules = mediaNode.rules[0].rules;
  5257. mediaNode.accept(this._visitor);
  5258. visitArgs.visitDeeper = false;
  5259. return this.utils.resolveVisibility(mediaNode, originalRules);
  5260. },
  5261. visitImport: function(importNode, visitArgs) {
  5262. if (importNode.blocksVisibility()) {
  5263. return;
  5264. }
  5265. return importNode;
  5266. },
  5267. visitAtRule: function(atRuleNode, visitArgs) {
  5268. if (atRuleNode.rules && atRuleNode.rules.length) {
  5269. return this.visitAtRuleWithBody(atRuleNode, visitArgs);
  5270. } else {
  5271. return this.visitAtRuleWithoutBody(atRuleNode, visitArgs);
  5272. }
  5273. },
  5274. visitAnonymous: function(anonymousNode, visitArgs) {
  5275. if (!anonymousNode.blocksVisibility()) {
  5276. anonymousNode.accept(this._visitor);
  5277. return anonymousNode;
  5278. }
  5279. },
  5280. visitAtRuleWithBody: function(atRuleNode, visitArgs) {
  5281. function hasFakeRuleset(atRuleNode2) {
  5282. var bodyRules = atRuleNode2.rules;
  5283. return bodyRules.length === 1 && (!bodyRules[0].paths || bodyRules[0].paths.length === 0);
  5284. }
  5285. function getBodyRules(atRuleNode2) {
  5286. var nodeRules = atRuleNode2.rules;
  5287. if (hasFakeRuleset(atRuleNode2)) {
  5288. return nodeRules[0].rules;
  5289. }
  5290. return nodeRules;
  5291. }
  5292. var originalRules = getBodyRules(atRuleNode);
  5293. atRuleNode.accept(this._visitor);
  5294. visitArgs.visitDeeper = false;
  5295. if (!this.utils.isEmpty(atRuleNode)) {
  5296. this._mergeRules(atRuleNode.rules[0].rules);
  5297. }
  5298. return this.utils.resolveVisibility(atRuleNode, originalRules);
  5299. },
  5300. visitAtRuleWithoutBody: function(atRuleNode, visitArgs) {
  5301. if (atRuleNode.blocksVisibility()) {
  5302. return;
  5303. }
  5304. if (atRuleNode.name === "@charset") {
  5305. if (this.charset) {
  5306. if (atRuleNode.debugInfo) {
  5307. var comment = new tree.Comment("/* " + atRuleNode.toCSS(this._context).replace(/\n/g, "") + " */\n");
  5308. comment.debugInfo = atRuleNode.debugInfo;
  5309. return this._visitor.visit(comment);
  5310. }
  5311. return;
  5312. }
  5313. this.charset = true;
  5314. }
  5315. return atRuleNode;
  5316. },
  5317. checkValidNodes: function(rules, isRoot) {
  5318. if (!rules) {
  5319. return;
  5320. }
  5321. for (var i = 0; i < rules.length; i++) {
  5322. var ruleNode = rules[i];
  5323. if (isRoot && ruleNode instanceof tree.Declaration && !ruleNode.variable) {
  5324. throw {
  5325. message: "Properties must be inside selector blocks. They cannot be in the root",
  5326. index: ruleNode.getIndex(),
  5327. filename: ruleNode.fileInfo() && ruleNode.fileInfo().filename
  5328. };
  5329. }
  5330. if (ruleNode instanceof tree.Call) {
  5331. throw {
  5332. message: "Function '" + ruleNode.name + "' did not return a root node",
  5333. index: ruleNode.getIndex(),
  5334. filename: ruleNode.fileInfo() && ruleNode.fileInfo().filename
  5335. };
  5336. }
  5337. if (ruleNode.type && !ruleNode.allowRoot) {
  5338. throw {
  5339. message: ruleNode.type + " node returned by a function is not valid here",
  5340. index: ruleNode.getIndex(),
  5341. filename: ruleNode.fileInfo() && ruleNode.fileInfo().filename
  5342. };
  5343. }
  5344. }
  5345. },
  5346. visitRuleset: function(rulesetNode, visitArgs) {
  5347. var rule;
  5348. var rulesets = [];
  5349. this.checkValidNodes(rulesetNode.rules, rulesetNode.firstRoot);
  5350. if (!rulesetNode.root) {
  5351. this._compileRulesetPaths(rulesetNode);
  5352. var nodeRules = rulesetNode.rules;
  5353. var nodeRuleCnt = nodeRules ? nodeRules.length : 0;
  5354. for (var i = 0; i < nodeRuleCnt; ) {
  5355. rule = nodeRules[i];
  5356. if (rule && rule.rules) {
  5357. rulesets.push(this._visitor.visit(rule));
  5358. nodeRules.splice(i, 1);
  5359. nodeRuleCnt--;
  5360. continue;
  5361. }
  5362. i++;
  5363. }
  5364. if (nodeRuleCnt > 0) {
  5365. rulesetNode.accept(this._visitor);
  5366. } else {
  5367. rulesetNode.rules = null;
  5368. }
  5369. visitArgs.visitDeeper = false;
  5370. } else {
  5371. rulesetNode.accept(this._visitor);
  5372. visitArgs.visitDeeper = false;
  5373. }
  5374. if (rulesetNode.rules) {
  5375. this._mergeRules(rulesetNode.rules);
  5376. this._removeDuplicateRules(rulesetNode.rules);
  5377. }
  5378. if (this.utils.isVisibleRuleset(rulesetNode)) {
  5379. rulesetNode.ensureVisibility();
  5380. rulesets.splice(0, 0, rulesetNode);
  5381. }
  5382. if (rulesets.length === 1) {
  5383. return rulesets[0];
  5384. }
  5385. return rulesets;
  5386. },
  5387. _compileRulesetPaths: function(rulesetNode) {
  5388. if (rulesetNode.paths) {
  5389. rulesetNode.paths = rulesetNode.paths.filter(function(p) {
  5390. var i;
  5391. if (p[0].elements[0].combinator.value === " ") {
  5392. p[0].elements[0].combinator = new tree.Combinator("");
  5393. }
  5394. for (i = 0; i < p.length; i++) {
  5395. if (p[i].isVisible() && p[i].getIsOutput()) {
  5396. return true;
  5397. }
  5398. }
  5399. return false;
  5400. });
  5401. }
  5402. },
  5403. _removeDuplicateRules: function(rules) {
  5404. if (!rules) {
  5405. return;
  5406. }
  5407. var ruleCache = {};
  5408. var ruleList;
  5409. var rule;
  5410. var i;
  5411. for (i = rules.length - 1; i >= 0; i--) {
  5412. rule = rules[i];
  5413. if (rule instanceof tree.Declaration) {
  5414. if (!ruleCache[rule.name]) {
  5415. ruleCache[rule.name] = rule;
  5416. } else {
  5417. ruleList = ruleCache[rule.name];
  5418. if (ruleList instanceof tree.Declaration) {
  5419. ruleList = ruleCache[rule.name] = [ruleCache[rule.name].toCSS(this._context)];
  5420. }
  5421. var ruleCSS = rule.toCSS(this._context);
  5422. if (ruleList.indexOf(ruleCSS) !== -1) {
  5423. rules.splice(i, 1);
  5424. } else {
  5425. ruleList.push(ruleCSS);
  5426. }
  5427. }
  5428. }
  5429. }
  5430. },
  5431. _mergeRules: function(rules) {
  5432. if (!rules) {
  5433. return;
  5434. }
  5435. var groups = {};
  5436. var groupsArr = [];
  5437. for (var i = 0; i < rules.length; i++) {
  5438. var rule = rules[i];
  5439. if (rule.merge) {
  5440. var key2 = rule.name;
  5441. groups[key2] ? rules.splice(i--, 1) : groupsArr.push(groups[key2] = []);
  5442. groups[key2].push(rule);
  5443. }
  5444. }
  5445. groupsArr.forEach(function(group) {
  5446. if (group.length > 0) {
  5447. var result_1 = group[0];
  5448. var space_1 = [];
  5449. var comma_1 = [new tree.Expression(space_1)];
  5450. group.forEach(function(rule2) {
  5451. if (rule2.merge === "+" && space_1.length > 0) {
  5452. comma_1.push(new tree.Expression(space_1 = []));
  5453. }
  5454. space_1.push(rule2.value);
  5455. result_1.important = result_1.important || rule2.important;
  5456. });
  5457. result_1.value = new tree.Value(comma_1);
  5458. }
  5459. });
  5460. }
  5461. };
  5462. var visitors = {
  5463. Visitor,
  5464. ImportVisitor,
  5465. MarkVisibleSelectorsVisitor: SetTreeVisibilityVisitor,
  5466. ExtendVisitor: ProcessExtendsVisitor,
  5467. JoinSelectorVisitor,
  5468. ToCSSVisitor
  5469. };
  5470. function chunker(input, fail) {
  5471. var len = input.length;
  5472. var level = 0;
  5473. var parenLevel = 0;
  5474. var lastOpening;
  5475. var lastOpeningParen;
  5476. var lastMultiComment;
  5477. var lastMultiCommentEndBrace;
  5478. var chunks = [];
  5479. var emitFrom = 0;
  5480. var chunkerCurrentIndex;
  5481. var currentChunkStartIndex;
  5482. var cc;
  5483. var cc2;
  5484. var matched;
  5485. function emitChunk(force) {
  5486. var len2 = chunkerCurrentIndex - emitFrom;
  5487. if (len2 < 512 && !force || !len2) {
  5488. return;
  5489. }
  5490. chunks.push(input.slice(emitFrom, chunkerCurrentIndex + 1));
  5491. emitFrom = chunkerCurrentIndex + 1;
  5492. }
  5493. for (chunkerCurrentIndex = 0; chunkerCurrentIndex < len; chunkerCurrentIndex++) {
  5494. cc = input.charCodeAt(chunkerCurrentIndex);
  5495. if (cc >= 97 && cc <= 122 || cc < 34) {
  5496. continue;
  5497. }
  5498. switch (cc) {
  5499. case 40:
  5500. parenLevel++;
  5501. lastOpeningParen = chunkerCurrentIndex;
  5502. continue;
  5503. case 41:
  5504. if (--parenLevel < 0) {
  5505. return fail("missing opening `(`", chunkerCurrentIndex);
  5506. }
  5507. continue;
  5508. case 59:
  5509. if (!parenLevel) {
  5510. emitChunk();
  5511. }
  5512. continue;
  5513. case 123:
  5514. level++;
  5515. lastOpening = chunkerCurrentIndex;
  5516. continue;
  5517. case 125:
  5518. if (--level < 0) {
  5519. return fail("missing opening `{`", chunkerCurrentIndex);
  5520. }
  5521. if (!level && !parenLevel) {
  5522. emitChunk();
  5523. }
  5524. continue;
  5525. case 92:
  5526. if (chunkerCurrentIndex < len - 1) {
  5527. chunkerCurrentIndex++;
  5528. continue;
  5529. }
  5530. return fail("unescaped `\\`", chunkerCurrentIndex);
  5531. case 34:
  5532. case 39:
  5533. case 96:
  5534. matched = 0;
  5535. currentChunkStartIndex = chunkerCurrentIndex;
  5536. for (chunkerCurrentIndex = chunkerCurrentIndex + 1; chunkerCurrentIndex < len; chunkerCurrentIndex++) {
  5537. cc2 = input.charCodeAt(chunkerCurrentIndex);
  5538. if (cc2 > 96) {
  5539. continue;
  5540. }
  5541. if (cc2 == cc) {
  5542. matched = 1;
  5543. break;
  5544. }
  5545. if (cc2 == 92) {
  5546. if (chunkerCurrentIndex == len - 1) {
  5547. return fail("unescaped `\\`", chunkerCurrentIndex);
  5548. }
  5549. chunkerCurrentIndex++;
  5550. }
  5551. }
  5552. if (matched) {
  5553. continue;
  5554. }
  5555. return fail("unmatched `" + String.fromCharCode(cc) + "`", currentChunkStartIndex);
  5556. case 47:
  5557. if (parenLevel || chunkerCurrentIndex == len - 1) {
  5558. continue;
  5559. }
  5560. cc2 = input.charCodeAt(chunkerCurrentIndex + 1);
  5561. if (cc2 == 47) {
  5562. for (chunkerCurrentIndex = chunkerCurrentIndex + 2; chunkerCurrentIndex < len; chunkerCurrentIndex++) {
  5563. cc2 = input.charCodeAt(chunkerCurrentIndex);
  5564. if (cc2 <= 13 && (cc2 == 10 || cc2 == 13)) {
  5565. break;
  5566. }
  5567. }
  5568. } else if (cc2 == 42) {
  5569. lastMultiComment = currentChunkStartIndex = chunkerCurrentIndex;
  5570. for (chunkerCurrentIndex = chunkerCurrentIndex + 2; chunkerCurrentIndex < len - 1; chunkerCurrentIndex++) {
  5571. cc2 = input.charCodeAt(chunkerCurrentIndex);
  5572. if (cc2 == 125) {
  5573. lastMultiCommentEndBrace = chunkerCurrentIndex;
  5574. }
  5575. if (cc2 != 42) {
  5576. continue;
  5577. }
  5578. if (input.charCodeAt(chunkerCurrentIndex + 1) == 47) {
  5579. break;
  5580. }
  5581. }
  5582. if (chunkerCurrentIndex == len - 1) {
  5583. return fail("missing closing `*/`", currentChunkStartIndex);
  5584. }
  5585. chunkerCurrentIndex++;
  5586. }
  5587. continue;
  5588. case 42:
  5589. if (chunkerCurrentIndex < len - 1 && input.charCodeAt(chunkerCurrentIndex + 1) == 47) {
  5590. return fail("unmatched `/*`", chunkerCurrentIndex);
  5591. }
  5592. continue;
  5593. }
  5594. }
  5595. if (level !== 0) {
  5596. if (lastMultiComment > lastOpening && lastMultiCommentEndBrace > lastMultiComment) {
  5597. return fail("missing closing `}` or `*/`", lastOpening);
  5598. } else {
  5599. return fail("missing closing `}`", lastOpening);
  5600. }
  5601. } else if (parenLevel !== 0) {
  5602. return fail("missing closing `)`", lastOpeningParen);
  5603. }
  5604. emitChunk(true);
  5605. return chunks;
  5606. }
  5607. var getParserInput = function() {
  5608. var input;
  5609. var j;
  5610. var saveStack = [];
  5611. var furthest;
  5612. var furthestPossibleErrorMessage;
  5613. var chunks;
  5614. var current;
  5615. var currentPos;
  5616. var parserInput = {};
  5617. var CHARCODE_SPACE = 32;
  5618. var CHARCODE_TAB = 9;
  5619. var CHARCODE_LF = 10;
  5620. var CHARCODE_CR = 13;
  5621. var CHARCODE_PLUS = 43;
  5622. var CHARCODE_COMMA = 44;
  5623. var CHARCODE_FORWARD_SLASH = 47;
  5624. var CHARCODE_9 = 57;
  5625. function skipWhitespace(length) {
  5626. var oldi = parserInput.i;
  5627. var oldj = j;
  5628. var curr = parserInput.i - currentPos;
  5629. var endIndex = parserInput.i + current.length - curr;
  5630. var mem = parserInput.i += length;
  5631. var inp = input;
  5632. var c;
  5633. var nextChar;
  5634. var comment;
  5635. for (; parserInput.i < endIndex; parserInput.i++) {
  5636. c = inp.charCodeAt(parserInput.i);
  5637. if (parserInput.autoCommentAbsorb && c === CHARCODE_FORWARD_SLASH) {
  5638. nextChar = inp.charAt(parserInput.i + 1);
  5639. if (nextChar === "/") {
  5640. comment = { index: parserInput.i, isLineComment: true };
  5641. var nextNewLine = inp.indexOf("\n", parserInput.i + 2);
  5642. if (nextNewLine < 0) {
  5643. nextNewLine = endIndex;
  5644. }
  5645. parserInput.i = nextNewLine;
  5646. comment.text = inp.substr(comment.index, parserInput.i - comment.index);
  5647. parserInput.commentStore.push(comment);
  5648. continue;
  5649. } else if (nextChar === "*") {
  5650. var nextStarSlash = inp.indexOf("*/", parserInput.i + 2);
  5651. if (nextStarSlash >= 0) {
  5652. comment = {
  5653. index: parserInput.i,
  5654. text: inp.substr(parserInput.i, nextStarSlash + 2 - parserInput.i),
  5655. isLineComment: false
  5656. };
  5657. parserInput.i += comment.text.length - 1;
  5658. parserInput.commentStore.push(comment);
  5659. continue;
  5660. }
  5661. }
  5662. break;
  5663. }
  5664. if (c !== CHARCODE_SPACE && c !== CHARCODE_LF && c !== CHARCODE_TAB && c !== CHARCODE_CR) {
  5665. break;
  5666. }
  5667. }
  5668. current = current.slice(length + parserInput.i - mem + curr);
  5669. currentPos = parserInput.i;
  5670. if (!current.length) {
  5671. if (j < chunks.length - 1) {
  5672. current = chunks[++j];
  5673. skipWhitespace(0);
  5674. return true;
  5675. }
  5676. parserInput.finished = true;
  5677. }
  5678. return oldi !== parserInput.i || oldj !== j;
  5679. }
  5680. parserInput.save = function() {
  5681. currentPos = parserInput.i;
  5682. saveStack.push({ current, i: parserInput.i, j });
  5683. };
  5684. parserInput.restore = function(possibleErrorMessage) {
  5685. if (parserInput.i > furthest || parserInput.i === furthest && possibleErrorMessage && !furthestPossibleErrorMessage) {
  5686. furthest = parserInput.i;
  5687. furthestPossibleErrorMessage = possibleErrorMessage;
  5688. }
  5689. var state = saveStack.pop();
  5690. current = state.current;
  5691. currentPos = parserInput.i = state.i;
  5692. j = state.j;
  5693. };
  5694. parserInput.forget = function() {
  5695. saveStack.pop();
  5696. };
  5697. parserInput.isWhitespace = function(offset) {
  5698. var pos = parserInput.i + (offset || 0);
  5699. var code = input.charCodeAt(pos);
  5700. return code === CHARCODE_SPACE || code === CHARCODE_CR || code === CHARCODE_TAB || code === CHARCODE_LF;
  5701. };
  5702. parserInput.$re = function(tok) {
  5703. if (parserInput.i > currentPos) {
  5704. current = current.slice(parserInput.i - currentPos);
  5705. currentPos = parserInput.i;
  5706. }
  5707. var m = tok.exec(current);
  5708. if (!m) {
  5709. return null;
  5710. }
  5711. skipWhitespace(m[0].length);
  5712. if (typeof m === "string") {
  5713. return m;
  5714. }
  5715. return m.length === 1 ? m[0] : m;
  5716. };
  5717. parserInput.$char = function(tok) {
  5718. if (input.charAt(parserInput.i) !== tok) {
  5719. return null;
  5720. }
  5721. skipWhitespace(1);
  5722. return tok;
  5723. };
  5724. parserInput.$str = function(tok) {
  5725. var tokLength = tok.length;
  5726. for (var i = 0; i < tokLength; i++) {
  5727. if (input.charAt(parserInput.i + i) !== tok.charAt(i)) {
  5728. return null;
  5729. }
  5730. }
  5731. skipWhitespace(tokLength);
  5732. return tok;
  5733. };
  5734. parserInput.$quoted = function(loc) {
  5735. var pos = loc || parserInput.i;
  5736. var startChar = input.charAt(pos);
  5737. if (startChar !== "'" && startChar !== '"') {
  5738. return;
  5739. }
  5740. var length = input.length;
  5741. var currentPosition = pos;
  5742. for (var i = 1; i + currentPosition < length; i++) {
  5743. var nextChar = input.charAt(i + currentPosition);
  5744. switch (nextChar) {
  5745. case "\\":
  5746. i++;
  5747. continue;
  5748. case "\r":
  5749. case "\n":
  5750. break;
  5751. case startChar:
  5752. var str = input.substr(currentPosition, i + 1);
  5753. if (!loc && loc !== 0) {
  5754. skipWhitespace(i + 1);
  5755. return str;
  5756. }
  5757. return [startChar, str];
  5758. }
  5759. }
  5760. return null;
  5761. };
  5762. parserInput.$parseUntil = function(tok) {
  5763. var quote = "";
  5764. var returnVal = null;
  5765. var inComment = false;
  5766. var blockDepth = 0;
  5767. var blockStack = [];
  5768. var parseGroups = [];
  5769. var length = input.length;
  5770. var startPos = parserInput.i;
  5771. var lastPos = parserInput.i;
  5772. var i = parserInput.i;
  5773. var loop = true;
  5774. var testChar;
  5775. if (typeof tok === "string") {
  5776. testChar = function(char) {
  5777. return char === tok;
  5778. };
  5779. } else {
  5780. testChar = function(char) {
  5781. return tok.test(char);
  5782. };
  5783. }
  5784. do {
  5785. var nextChar = input.charAt(i);
  5786. if (blockDepth === 0 && testChar(nextChar)) {
  5787. returnVal = input.substr(lastPos, i - lastPos);
  5788. if (returnVal) {
  5789. parseGroups.push(returnVal);
  5790. } else {
  5791. parseGroups.push(" ");
  5792. }
  5793. returnVal = parseGroups;
  5794. skipWhitespace(i - startPos);
  5795. loop = false;
  5796. } else {
  5797. if (inComment) {
  5798. if (nextChar === "*" && input.charAt(i + 1) === "/") {
  5799. i++;
  5800. blockDepth--;
  5801. inComment = false;
  5802. }
  5803. i++;
  5804. continue;
  5805. }
  5806. switch (nextChar) {
  5807. case "\\":
  5808. i++;
  5809. nextChar = input.charAt(i);
  5810. parseGroups.push(input.substr(lastPos, i - lastPos + 1));
  5811. lastPos = i + 1;
  5812. break;
  5813. case "/":
  5814. if (input.charAt(i + 1) === "*") {
  5815. i++;
  5816. inComment = true;
  5817. blockDepth++;
  5818. }
  5819. break;
  5820. case "'":
  5821. case '"':
  5822. quote = parserInput.$quoted(i);
  5823. if (quote) {
  5824. parseGroups.push(input.substr(lastPos, i - lastPos), quote);
  5825. i += quote[1].length - 1;
  5826. lastPos = i + 1;
  5827. } else {
  5828. skipWhitespace(i - startPos);
  5829. returnVal = nextChar;
  5830. loop = false;
  5831. }
  5832. break;
  5833. case "{":
  5834. blockStack.push("}");
  5835. blockDepth++;
  5836. break;
  5837. case "(":
  5838. blockStack.push(")");
  5839. blockDepth++;
  5840. break;
  5841. case "[":
  5842. blockStack.push("]");
  5843. blockDepth++;
  5844. break;
  5845. case "}":
  5846. case ")":
  5847. case "]":
  5848. var expected = blockStack.pop();
  5849. if (nextChar === expected) {
  5850. blockDepth--;
  5851. } else {
  5852. skipWhitespace(i - startPos);
  5853. returnVal = expected;
  5854. loop = false;
  5855. }
  5856. }
  5857. i++;
  5858. if (i > length) {
  5859. loop = false;
  5860. }
  5861. }
  5862. } while (loop);
  5863. return returnVal ? returnVal : null;
  5864. };
  5865. parserInput.autoCommentAbsorb = true;
  5866. parserInput.commentStore = [];
  5867. parserInput.finished = false;
  5868. parserInput.peek = function(tok) {
  5869. if (typeof tok === "string") {
  5870. for (var i = 0; i < tok.length; i++) {
  5871. if (input.charAt(parserInput.i + i) !== tok.charAt(i)) {
  5872. return false;
  5873. }
  5874. }
  5875. return true;
  5876. } else {
  5877. return tok.test(current);
  5878. }
  5879. };
  5880. parserInput.peekChar = function(tok) {
  5881. return input.charAt(parserInput.i) === tok;
  5882. };
  5883. parserInput.currentChar = function() {
  5884. return input.charAt(parserInput.i);
  5885. };
  5886. parserInput.prevChar = function() {
  5887. return input.charAt(parserInput.i - 1);
  5888. };
  5889. parserInput.getInput = function() {
  5890. return input;
  5891. };
  5892. parserInput.peekNotNumeric = function() {
  5893. var c = input.charCodeAt(parserInput.i);
  5894. return c > CHARCODE_9 || c < CHARCODE_PLUS || c === CHARCODE_FORWARD_SLASH || c === CHARCODE_COMMA;
  5895. };
  5896. parserInput.start = function(str, chunkInput, failFunction) {
  5897. input = str;
  5898. parserInput.i = j = currentPos = furthest = 0;
  5899. if (chunkInput) {
  5900. chunks = chunker(str, failFunction);
  5901. } else {
  5902. chunks = [str];
  5903. }
  5904. current = chunks[0];
  5905. skipWhitespace(0);
  5906. };
  5907. parserInput.end = function() {
  5908. var message;
  5909. var isFinished = parserInput.i >= input.length;
  5910. if (parserInput.i < furthest) {
  5911. message = furthestPossibleErrorMessage;
  5912. parserInput.i = furthest;
  5913. }
  5914. return {
  5915. isFinished,
  5916. furthest: parserInput.i,
  5917. furthestPossibleErrorMessage: message,
  5918. furthestReachedEnd: parserInput.i >= input.length - 1,
  5919. furthestChar: input[parserInput.i]
  5920. };
  5921. };
  5922. return parserInput;
  5923. };
  5924. var Parser = function Parser2(context, imports, fileInfo) {
  5925. var parsers;
  5926. var parserInput = getParserInput();
  5927. function error(msg, type) {
  5928. throw new LessError({
  5929. index: parserInput.i,
  5930. filename: fileInfo.filename,
  5931. type: type || "Syntax",
  5932. message: msg
  5933. }, imports);
  5934. }
  5935. function expect(arg, msg) {
  5936. var result = arg instanceof Function ? arg.call(parsers) : parserInput.$re(arg);
  5937. if (result) {
  5938. return result;
  5939. }
  5940. error(msg || (typeof arg === "string" ? "expected '" + arg + "' got '" + parserInput.currentChar() + "'" : "unexpected token"));
  5941. }
  5942. function expectChar(arg, msg) {
  5943. if (parserInput.$char(arg)) {
  5944. return arg;
  5945. }
  5946. error(msg || "expected '" + arg + "' got '" + parserInput.currentChar() + "'");
  5947. }
  5948. function getDebugInfo(index) {
  5949. var filename = fileInfo.filename;
  5950. return {
  5951. lineNumber: getLocation(index, parserInput.getInput()).line + 1,
  5952. fileName: filename
  5953. };
  5954. }
  5955. function parseNode(str, parseList, currentIndex, fileInfo2, callback) {
  5956. var result;
  5957. var returnNodes = [];
  5958. var parser = parserInput;
  5959. try {
  5960. parser.start(str, false, function fail(msg, index) {
  5961. callback({
  5962. message: msg,
  5963. index: index + currentIndex
  5964. });
  5965. });
  5966. for (var x = 0, p = void 0, i = void 0; p = parseList[x]; x++) {
  5967. i = parser.i;
  5968. result = parsers[p]();
  5969. if (result) {
  5970. try {
  5971. result._index = i + currentIndex;
  5972. result._fileInfo = fileInfo2;
  5973. } catch (e) {
  5974. }
  5975. returnNodes.push(result);
  5976. } else {
  5977. returnNodes.push(null);
  5978. }
  5979. }
  5980. var endInfo = parser.end();
  5981. if (endInfo.isFinished) {
  5982. callback(null, returnNodes);
  5983. } else {
  5984. callback(true, null);
  5985. }
  5986. } catch (e) {
  5987. throw new LessError({
  5988. index: e.index + currentIndex,
  5989. message: e.message
  5990. }, imports, fileInfo2.filename);
  5991. }
  5992. }
  5993. return {
  5994. parserInput,
  5995. imports,
  5996. fileInfo,
  5997. parseNode,
  5998. //
  5999. // Parse an input string into an abstract syntax tree,
  6000. // @param str A string containing 'less' markup
  6001. // @param callback call `callback` when done.
  6002. // @param [additionalData] An optional map which can contains vars - a map (key, value) of variables to apply
  6003. //
  6004. parse: function(str, callback, additionalData) {
  6005. var root2;
  6006. var err = null;
  6007. var globalVars;
  6008. var modifyVars;
  6009. var ignored;
  6010. var preText = "";
  6011. if (additionalData && additionalData.disablePluginRule) {
  6012. parsers.plugin = function() {
  6013. var dir = parserInput.$re(/^@plugin?\s+/);
  6014. if (dir) {
  6015. error("@plugin statements are not allowed when disablePluginRule is set to true");
  6016. }
  6017. };
  6018. }
  6019. globalVars = additionalData && additionalData.globalVars ? Parser2.serializeVars(additionalData.globalVars) + "\n" : "";
  6020. modifyVars = additionalData && additionalData.modifyVars ? "\n" + Parser2.serializeVars(additionalData.modifyVars) : "";
  6021. if (context.pluginManager) {
  6022. var preProcessors = context.pluginManager.getPreProcessors();
  6023. for (var i = 0; i < preProcessors.length; i++) {
  6024. str = preProcessors[i].process(str, { context, imports, fileInfo });
  6025. }
  6026. }
  6027. if (globalVars || additionalData && additionalData.banner) {
  6028. preText = (additionalData && additionalData.banner ? additionalData.banner : "") + globalVars;
  6029. ignored = imports.contentsIgnoredChars;
  6030. ignored[fileInfo.filename] = ignored[fileInfo.filename] || 0;
  6031. ignored[fileInfo.filename] += preText.length;
  6032. }
  6033. str = str.replace(/\r\n?/g, "\n");
  6034. str = preText + str.replace(/^\uFEFF/, "") + modifyVars;
  6035. imports.contents[fileInfo.filename] = str;
  6036. try {
  6037. parserInput.start(str, context.chunkInput, function fail(msg, index) {
  6038. throw new LessError({
  6039. index,
  6040. type: "Parse",
  6041. message: msg,
  6042. filename: fileInfo.filename
  6043. }, imports);
  6044. });
  6045. tree.Node.prototype.parse = this;
  6046. root2 = new tree.Ruleset(null, this.parsers.primary());
  6047. tree.Node.prototype.rootNode = root2;
  6048. root2.root = true;
  6049. root2.firstRoot = true;
  6050. root2.functionRegistry = functionRegistry.inherit();
  6051. } catch (e) {
  6052. return callback(new LessError(e, imports, fileInfo.filename));
  6053. }
  6054. var endInfo = parserInput.end();
  6055. if (!endInfo.isFinished) {
  6056. var message = endInfo.furthestPossibleErrorMessage;
  6057. if (!message) {
  6058. message = "Unrecognised input";
  6059. if (endInfo.furthestChar === "}") {
  6060. message += ". Possibly missing opening '{'";
  6061. } else if (endInfo.furthestChar === ")") {
  6062. message += ". Possibly missing opening '('";
  6063. } else if (endInfo.furthestReachedEnd) {
  6064. message += ". Possibly missing something";
  6065. }
  6066. }
  6067. err = new LessError({
  6068. type: "Parse",
  6069. message,
  6070. index: endInfo.furthest,
  6071. filename: fileInfo.filename
  6072. }, imports);
  6073. }
  6074. var finish = function(e) {
  6075. e = err || e || imports.error;
  6076. if (e) {
  6077. if (!(e instanceof LessError)) {
  6078. e = new LessError(e, imports, fileInfo.filename);
  6079. }
  6080. return callback(e);
  6081. } else {
  6082. return callback(null, root2);
  6083. }
  6084. };
  6085. if (context.processImports !== false) {
  6086. new visitors.ImportVisitor(imports, finish).run(root2);
  6087. } else {
  6088. return finish();
  6089. }
  6090. },
  6091. //
  6092. // Here in, the parsing rules/functions
  6093. //
  6094. // The basic structure of the syntax tree generated is as follows:
  6095. //
  6096. // Ruleset -> Declaration -> Value -> Expression -> Entity
  6097. //
  6098. // Here's some Less code:
  6099. //
  6100. // .class {
  6101. // color: #fff;
  6102. // border: 1px solid #000;
  6103. // width: @w + 4px;
  6104. // > .child {...}
  6105. // }
  6106. //
  6107. // And here's what the parse tree might look like:
  6108. //
  6109. // Ruleset (Selector '.class', [
  6110. // Declaration ("color", Value ([Expression [Color #fff]]))
  6111. // Declaration ("border", Value ([Expression [Dimension 1px][Keyword "solid"][Color #000]]))
  6112. // Declaration ("width", Value ([Expression [Operation " + " [Variable "@w"][Dimension 4px]]]))
  6113. // Ruleset (Selector [Element '>', '.child'], [...])
  6114. // ])
  6115. //
  6116. // In general, most rules will try to parse a token with the `$re()` function, and if the return
  6117. // value is truly, will return a new node, of the relevant type. Sometimes, we need to check
  6118. // first, before parsing, that's when we use `peek()`.
  6119. //
  6120. parsers: parsers = {
  6121. //
  6122. // The `primary` rule is the *entry* and *exit* point of the parser.
  6123. // The rules here can appear at any level of the parse tree.
  6124. //
  6125. // The recursive nature of the grammar is an interplay between the `block`
  6126. // rule, which represents `{ ... }`, the `ruleset` rule, and this `primary` rule,
  6127. // as represented by this simplified grammar:
  6128. //
  6129. // primary → (ruleset | declaration)+
  6130. // ruleset → selector+ block
  6131. // block → '{' primary '}'
  6132. //
  6133. // Only at one point is the primary rule not called from the
  6134. // block rule: at the root level.
  6135. //
  6136. primary: function() {
  6137. var mixin = this.mixin;
  6138. var root2 = [];
  6139. var node;
  6140. while (true) {
  6141. while (true) {
  6142. node = this.comment();
  6143. if (!node) {
  6144. break;
  6145. }
  6146. root2.push(node);
  6147. }
  6148. if (parserInput.finished) {
  6149. break;
  6150. }
  6151. if (parserInput.peek("}")) {
  6152. break;
  6153. }
  6154. node = this.extendRule();
  6155. if (node) {
  6156. root2 = root2.concat(node);
  6157. continue;
  6158. }
  6159. node = mixin.definition() || this.declaration() || mixin.call(false, false) || this.ruleset() || this.variableCall() || this.entities.call() || this.atrule();
  6160. if (node) {
  6161. root2.push(node);
  6162. } else {
  6163. var foundSemiColon = false;
  6164. while (parserInput.$char(";")) {
  6165. foundSemiColon = true;
  6166. }
  6167. if (!foundSemiColon) {
  6168. break;
  6169. }
  6170. }
  6171. }
  6172. return root2;
  6173. },
  6174. // comments are collected by the main parsing mechanism and then assigned to nodes
  6175. // where the current structure allows it
  6176. comment: function() {
  6177. if (parserInput.commentStore.length) {
  6178. var comment = parserInput.commentStore.shift();
  6179. return new tree.Comment(comment.text, comment.isLineComment, comment.index, fileInfo);
  6180. }
  6181. },
  6182. //
  6183. // Entities are tokens which can be found inside an Expression
  6184. //
  6185. entities: {
  6186. mixinLookup: function() {
  6187. return parsers.mixin.call(true, true);
  6188. },
  6189. //
  6190. // A string, which supports escaping " and '
  6191. //
  6192. // "milky way" 'he\'s the one!'
  6193. //
  6194. quoted: function(forceEscaped) {
  6195. var str;
  6196. var index = parserInput.i;
  6197. var isEscaped = false;
  6198. parserInput.save();
  6199. if (parserInput.$char("~")) {
  6200. isEscaped = true;
  6201. } else if (forceEscaped) {
  6202. parserInput.restore();
  6203. return;
  6204. }
  6205. str = parserInput.$quoted();
  6206. if (!str) {
  6207. parserInput.restore();
  6208. return;
  6209. }
  6210. parserInput.forget();
  6211. return new tree.Quoted(str.charAt(0), str.substr(1, str.length - 2), isEscaped, index, fileInfo);
  6212. },
  6213. //
  6214. // A catch-all word, such as:
  6215. //
  6216. // black border-collapse
  6217. //
  6218. keyword: function() {
  6219. var k = parserInput.$char("%") || parserInput.$re(/^\[?(?:[\w-]|\\(?:[A-Fa-f0-9]{1,6} ?|[^A-Fa-f0-9]))+\]?/);
  6220. if (k) {
  6221. return tree.Color.fromKeyword(k) || new tree.Keyword(k);
  6222. }
  6223. },
  6224. //
  6225. // A function call
  6226. //
  6227. // rgb(255, 0, 255)
  6228. //
  6229. // The arguments are parsed with the `entities.arguments` parser.
  6230. //
  6231. call: function() {
  6232. var name;
  6233. var args;
  6234. var func;
  6235. var index = parserInput.i;
  6236. if (parserInput.peek(/^url\(/i)) {
  6237. return;
  6238. }
  6239. parserInput.save();
  6240. name = parserInput.$re(/^([\w-]+|%|~|progid:[\w\.]+)\(/);
  6241. if (!name) {
  6242. parserInput.forget();
  6243. return;
  6244. }
  6245. name = name[1];
  6246. func = this.customFuncCall(name);
  6247. if (func) {
  6248. args = func.parse();
  6249. if (args && func.stop) {
  6250. parserInput.forget();
  6251. return args;
  6252. }
  6253. }
  6254. args = this.arguments(args);
  6255. if (!parserInput.$char(")")) {
  6256. parserInput.restore("Could not parse call arguments or missing ')'");
  6257. return;
  6258. }
  6259. parserInput.forget();
  6260. return new tree.Call(name, args, index, fileInfo);
  6261. },
  6262. //
  6263. // Parsing rules for functions with non-standard args, e.g.:
  6264. //
  6265. // boolean(not(2 > 1))
  6266. //
  6267. // This is a quick prototype, to be modified/improved when
  6268. // more custom-parsed funcs come (e.g. `selector(...)`)
  6269. //
  6270. customFuncCall: function(name) {
  6271. return {
  6272. alpha: f2(parsers.ieAlpha, true),
  6273. boolean: f2(condition),
  6274. "if": f2(condition)
  6275. }[name.toLowerCase()];
  6276. function f2(parse, stop) {
  6277. return {
  6278. parse,
  6279. stop
  6280. // when true - stop after parse() and return its result,
  6281. // otherwise continue for plain args
  6282. };
  6283. }
  6284. function condition() {
  6285. return [expect(parsers.condition, "expected condition")];
  6286. }
  6287. },
  6288. arguments: function(prevArgs) {
  6289. var argsComma = prevArgs || [];
  6290. var argsSemiColon = [];
  6291. var isSemiColonSeparated;
  6292. var value;
  6293. parserInput.save();
  6294. while (true) {
  6295. if (prevArgs) {
  6296. prevArgs = false;
  6297. } else {
  6298. value = parsers.detachedRuleset() || this.assignment() || parsers.expression();
  6299. if (!value) {
  6300. break;
  6301. }
  6302. if (value.value && value.value.length == 1) {
  6303. value = value.value[0];
  6304. }
  6305. argsComma.push(value);
  6306. }
  6307. if (parserInput.$char(",")) {
  6308. continue;
  6309. }
  6310. if (parserInput.$char(";") || isSemiColonSeparated) {
  6311. isSemiColonSeparated = true;
  6312. value = argsComma.length < 1 ? argsComma[0] : new tree.Value(argsComma);
  6313. argsSemiColon.push(value);
  6314. argsComma = [];
  6315. }
  6316. }
  6317. parserInput.forget();
  6318. return isSemiColonSeparated ? argsSemiColon : argsComma;
  6319. },
  6320. literal: function() {
  6321. return this.dimension() || this.color() || this.quoted() || this.unicodeDescriptor();
  6322. },
  6323. // Assignments are argument entities for calls.
  6324. // They are present in ie filter properties as shown below.
  6325. //
  6326. // filter: progid:DXImageTransform.Microsoft.Alpha( *opacity=50* )
  6327. //
  6328. assignment: function() {
  6329. var key2;
  6330. var value;
  6331. parserInput.save();
  6332. key2 = parserInput.$re(/^\w+(?=\s?=)/i);
  6333. if (!key2) {
  6334. parserInput.restore();
  6335. return;
  6336. }
  6337. if (!parserInput.$char("=")) {
  6338. parserInput.restore();
  6339. return;
  6340. }
  6341. value = parsers.entity();
  6342. if (value) {
  6343. parserInput.forget();
  6344. return new tree.Assignment(key2, value);
  6345. } else {
  6346. parserInput.restore();
  6347. }
  6348. },
  6349. //
  6350. // Parse url() tokens
  6351. //
  6352. // We use a specific rule for urls, because they don't really behave like
  6353. // standard function calls. The difference is that the argument doesn't have
  6354. // to be enclosed within a string, so it can't be parsed as an Expression.
  6355. //
  6356. url: function() {
  6357. var value;
  6358. var index = parserInput.i;
  6359. parserInput.autoCommentAbsorb = false;
  6360. if (!parserInput.$str("url(")) {
  6361. parserInput.autoCommentAbsorb = true;
  6362. return;
  6363. }
  6364. value = this.quoted() || this.variable() || this.property() || parserInput.$re(/^(?:(?:\\[\(\)'"])|[^\(\)'"])+/) || "";
  6365. parserInput.autoCommentAbsorb = true;
  6366. expectChar(")");
  6367. return new tree.URL(value.value != null || value instanceof tree.Variable || value instanceof tree.Property ? value : new tree.Anonymous(value, index), index, fileInfo);
  6368. },
  6369. //
  6370. // A Variable entity, such as `@fink`, in
  6371. //
  6372. // width: @fink + 2px
  6373. //
  6374. // We use a different parser for variable definitions,
  6375. // see `parsers.variable`.
  6376. //
  6377. variable: function() {
  6378. var ch;
  6379. var name;
  6380. var index = parserInput.i;
  6381. parserInput.save();
  6382. if (parserInput.currentChar() === "@" && (name = parserInput.$re(/^@@?[\w-]+/))) {
  6383. ch = parserInput.currentChar();
  6384. if (ch === "(" || ch === "[" && !parserInput.prevChar().match(/^\s/)) {
  6385. var result = parsers.variableCall(name);
  6386. if (result) {
  6387. parserInput.forget();
  6388. return result;
  6389. }
  6390. }
  6391. parserInput.forget();
  6392. return new tree.Variable(name, index, fileInfo);
  6393. }
  6394. parserInput.restore();
  6395. },
  6396. // A variable entity using the protective {} e.g. @{var}
  6397. variableCurly: function() {
  6398. var curly;
  6399. var index = parserInput.i;
  6400. if (parserInput.currentChar() === "@" && (curly = parserInput.$re(/^@\{([\w-]+)\}/))) {
  6401. return new tree.Variable("@" + curly[1], index, fileInfo);
  6402. }
  6403. },
  6404. //
  6405. // A Property accessor, such as `$color`, in
  6406. //
  6407. // background-color: $color
  6408. //
  6409. property: function() {
  6410. var name;
  6411. var index = parserInput.i;
  6412. if (parserInput.currentChar() === "$" && (name = parserInput.$re(/^\$[\w-]+/))) {
  6413. return new tree.Property(name, index, fileInfo);
  6414. }
  6415. },
  6416. // A property entity useing the protective {} e.g. ${prop}
  6417. propertyCurly: function() {
  6418. var curly;
  6419. var index = parserInput.i;
  6420. if (parserInput.currentChar() === "$" && (curly = parserInput.$re(/^\$\{([\w-]+)\}/))) {
  6421. return new tree.Property("$" + curly[1], index, fileInfo);
  6422. }
  6423. },
  6424. //
  6425. // A Hexadecimal color
  6426. //
  6427. // #4F3C2F
  6428. //
  6429. // `rgb` and `hsl` colors are parsed through the `entities.call` parser.
  6430. //
  6431. color: function() {
  6432. var rgb;
  6433. parserInput.save();
  6434. if (parserInput.currentChar() === "#" && (rgb = parserInput.$re(/^#([A-Fa-f0-9]{8}|[A-Fa-f0-9]{6}|[A-Fa-f0-9]{3,4})([\w.#\[])?/))) {
  6435. if (!rgb[2]) {
  6436. parserInput.forget();
  6437. return new tree.Color(rgb[1], void 0, rgb[0]);
  6438. }
  6439. }
  6440. parserInput.restore();
  6441. },
  6442. colorKeyword: function() {
  6443. parserInput.save();
  6444. var autoCommentAbsorb = parserInput.autoCommentAbsorb;
  6445. parserInput.autoCommentAbsorb = false;
  6446. var k = parserInput.$re(/^[_A-Za-z-][_A-Za-z0-9-]+/);
  6447. parserInput.autoCommentAbsorb = autoCommentAbsorb;
  6448. if (!k) {
  6449. parserInput.forget();
  6450. return;
  6451. }
  6452. parserInput.restore();
  6453. var color2 = tree.Color.fromKeyword(k);
  6454. if (color2) {
  6455. parserInput.$str(k);
  6456. return color2;
  6457. }
  6458. },
  6459. //
  6460. // A Dimension, that is, a number and a unit
  6461. //
  6462. // 0.5em 95%
  6463. //
  6464. dimension: function() {
  6465. if (parserInput.peekNotNumeric()) {
  6466. return;
  6467. }
  6468. var value = parserInput.$re(/^([+-]?\d*\.?\d+)(%|[a-z_]+)?/i);
  6469. if (value) {
  6470. return new tree.Dimension(value[1], value[2]);
  6471. }
  6472. },
  6473. //
  6474. // A unicode descriptor, as is used in unicode-range
  6475. //
  6476. // U+0?? or U+00A1-00A9
  6477. //
  6478. unicodeDescriptor: function() {
  6479. var ud;
  6480. ud = parserInput.$re(/^U\+[0-9a-fA-F?]+(\-[0-9a-fA-F?]+)?/);
  6481. if (ud) {
  6482. return new tree.UnicodeDescriptor(ud[0]);
  6483. }
  6484. },
  6485. //
  6486. // JavaScript code to be evaluated
  6487. //
  6488. // `window.location.href`
  6489. //
  6490. javascript: function() {
  6491. var js;
  6492. var index = parserInput.i;
  6493. parserInput.save();
  6494. var escape = parserInput.$char("~");
  6495. var jsQuote = parserInput.$char("`");
  6496. if (!jsQuote) {
  6497. parserInput.restore();
  6498. return;
  6499. }
  6500. js = parserInput.$re(/^[^`]*`/);
  6501. if (js) {
  6502. parserInput.forget();
  6503. return new tree.JavaScript(js.substr(0, js.length - 1), Boolean(escape), index, fileInfo);
  6504. }
  6505. parserInput.restore("invalid javascript definition");
  6506. }
  6507. },
  6508. //
  6509. // The variable part of a variable definition. Used in the `rule` parser
  6510. //
  6511. // @fink:
  6512. //
  6513. variable: function() {
  6514. var name;
  6515. if (parserInput.currentChar() === "@" && (name = parserInput.$re(/^(@[\w-]+)\s*:/))) {
  6516. return name[1];
  6517. }
  6518. },
  6519. //
  6520. // Call a variable value to retrieve a detached ruleset
  6521. // or a value from a detached ruleset's rules.
  6522. //
  6523. // @fink();
  6524. // @fink;
  6525. // color: @fink[@color];
  6526. //
  6527. variableCall: function(parsedName) {
  6528. var lookups;
  6529. var i = parserInput.i;
  6530. var inValue = !!parsedName;
  6531. var name = parsedName;
  6532. parserInput.save();
  6533. if (name || parserInput.currentChar() === "@" && (name = parserInput.$re(/^(@[\w-]+)(\(\s*\))?/))) {
  6534. lookups = this.mixin.ruleLookups();
  6535. if (!lookups && (inValue && parserInput.$str("()") !== "()" || name[2] !== "()")) {
  6536. parserInput.restore("Missing '[...]' lookup in variable call");
  6537. return;
  6538. }
  6539. if (!inValue) {
  6540. name = name[1];
  6541. }
  6542. var call = new tree.VariableCall(name, i, fileInfo);
  6543. if (!inValue && parsers.end()) {
  6544. parserInput.forget();
  6545. return call;
  6546. } else {
  6547. parserInput.forget();
  6548. return new tree.NamespaceValue(call, lookups, i, fileInfo);
  6549. }
  6550. }
  6551. parserInput.restore();
  6552. },
  6553. //
  6554. // extend syntax - used to extend selectors
  6555. //
  6556. extend: function(isRule) {
  6557. var elements;
  6558. var e;
  6559. var index = parserInput.i;
  6560. var option;
  6561. var extendList;
  6562. var extend;
  6563. if (!parserInput.$str(isRule ? "&:extend(" : ":extend(")) {
  6564. return;
  6565. }
  6566. do {
  6567. option = null;
  6568. elements = null;
  6569. while (!(option = parserInput.$re(/^(all)(?=\s*(\)|,))/))) {
  6570. e = this.element();
  6571. if (!e) {
  6572. break;
  6573. }
  6574. if (elements) {
  6575. elements.push(e);
  6576. } else {
  6577. elements = [e];
  6578. }
  6579. }
  6580. option = option && option[1];
  6581. if (!elements) {
  6582. error("Missing target selector for :extend().");
  6583. }
  6584. extend = new tree.Extend(new tree.Selector(elements), option, index, fileInfo);
  6585. if (extendList) {
  6586. extendList.push(extend);
  6587. } else {
  6588. extendList = [extend];
  6589. }
  6590. } while (parserInput.$char(","));
  6591. expect(/^\)/);
  6592. if (isRule) {
  6593. expect(/^;/);
  6594. }
  6595. return extendList;
  6596. },
  6597. //
  6598. // extendRule - used in a rule to extend all the parent selectors
  6599. //
  6600. extendRule: function() {
  6601. return this.extend(true);
  6602. },
  6603. //
  6604. // Mixins
  6605. //
  6606. mixin: {
  6607. //
  6608. // A Mixin call, with an optional argument list
  6609. //
  6610. // #mixins > .square(#fff);
  6611. // #mixins.square(#fff);
  6612. // .rounded(4px, black);
  6613. // .button;
  6614. //
  6615. // We can lookup / return a value using the lookup syntax:
  6616. //
  6617. // color: #mixin.square(#fff)[@color];
  6618. //
  6619. // The `while` loop is there because mixins can be
  6620. // namespaced, but we only support the child and descendant
  6621. // selector for now.
  6622. //
  6623. call: function(inValue, getLookup) {
  6624. var s = parserInput.currentChar();
  6625. var important = false;
  6626. var lookups;
  6627. var index = parserInput.i;
  6628. var elements;
  6629. var args;
  6630. var hasParens;
  6631. if (s !== "." && s !== "#") {
  6632. return;
  6633. }
  6634. parserInput.save();
  6635. elements = this.elements();
  6636. if (elements) {
  6637. if (parserInput.$char("(")) {
  6638. args = this.args(true).args;
  6639. expectChar(")");
  6640. hasParens = true;
  6641. }
  6642. if (getLookup !== false) {
  6643. lookups = this.ruleLookups();
  6644. }
  6645. if (getLookup === true && !lookups) {
  6646. parserInput.restore();
  6647. return;
  6648. }
  6649. if (inValue && !lookups && !hasParens) {
  6650. parserInput.restore();
  6651. return;
  6652. }
  6653. if (!inValue && parsers.important()) {
  6654. important = true;
  6655. }
  6656. if (inValue || parsers.end()) {
  6657. parserInput.forget();
  6658. var mixin = new tree.mixin.Call(elements, args, index, fileInfo, !lookups && important);
  6659. if (lookups) {
  6660. return new tree.NamespaceValue(mixin, lookups);
  6661. } else {
  6662. return mixin;
  6663. }
  6664. }
  6665. }
  6666. parserInput.restore();
  6667. },
  6668. /**
  6669. * Matching elements for mixins
  6670. * (Start with . or # and can have > )
  6671. */
  6672. elements: function() {
  6673. var elements;
  6674. var e;
  6675. var c;
  6676. var elem;
  6677. var elemIndex;
  6678. var re = /^[#.](?:[\w-]|\\(?:[A-Fa-f0-9]{1,6} ?|[^A-Fa-f0-9]))+/;
  6679. while (true) {
  6680. elemIndex = parserInput.i;
  6681. e = parserInput.$re(re);
  6682. if (!e) {
  6683. break;
  6684. }
  6685. elem = new tree.Element(c, e, false, elemIndex, fileInfo);
  6686. if (elements) {
  6687. elements.push(elem);
  6688. } else {
  6689. elements = [elem];
  6690. }
  6691. c = parserInput.$char(">");
  6692. }
  6693. return elements;
  6694. },
  6695. args: function(isCall) {
  6696. var entities = parsers.entities;
  6697. var returner = { args: null, variadic: false };
  6698. var expressions = [];
  6699. var argsSemiColon = [];
  6700. var argsComma = [];
  6701. var isSemiColonSeparated;
  6702. var expressionContainsNamed;
  6703. var name;
  6704. var nameLoop;
  6705. var value;
  6706. var arg;
  6707. var expand;
  6708. var hasSep = true;
  6709. parserInput.save();
  6710. while (true) {
  6711. if (isCall) {
  6712. arg = parsers.detachedRuleset() || parsers.expression();
  6713. } else {
  6714. parserInput.commentStore.length = 0;
  6715. if (parserInput.$str("...")) {
  6716. returner.variadic = true;
  6717. if (parserInput.$char(";") && !isSemiColonSeparated) {
  6718. isSemiColonSeparated = true;
  6719. }
  6720. (isSemiColonSeparated ? argsSemiColon : argsComma).push({ variadic: true });
  6721. break;
  6722. }
  6723. arg = entities.variable() || entities.property() || entities.literal() || entities.keyword() || this.call(true);
  6724. }
  6725. if (!arg || !hasSep) {
  6726. break;
  6727. }
  6728. nameLoop = null;
  6729. if (arg.throwAwayComments) {
  6730. arg.throwAwayComments();
  6731. }
  6732. value = arg;
  6733. var val = null;
  6734. if (isCall) {
  6735. if (arg.value && arg.value.length == 1) {
  6736. val = arg.value[0];
  6737. }
  6738. } else {
  6739. val = arg;
  6740. }
  6741. if (val && (val instanceof tree.Variable || val instanceof tree.Property)) {
  6742. if (parserInput.$char(":")) {
  6743. if (expressions.length > 0) {
  6744. if (isSemiColonSeparated) {
  6745. error("Cannot mix ; and , as delimiter types");
  6746. }
  6747. expressionContainsNamed = true;
  6748. }
  6749. value = parsers.detachedRuleset() || parsers.expression();
  6750. if (!value) {
  6751. if (isCall) {
  6752. error("could not understand value for named argument");
  6753. } else {
  6754. parserInput.restore();
  6755. returner.args = [];
  6756. return returner;
  6757. }
  6758. }
  6759. nameLoop = name = val.name;
  6760. } else if (parserInput.$str("...")) {
  6761. if (!isCall) {
  6762. returner.variadic = true;
  6763. if (parserInput.$char(";") && !isSemiColonSeparated) {
  6764. isSemiColonSeparated = true;
  6765. }
  6766. (isSemiColonSeparated ? argsSemiColon : argsComma).push({ name: arg.name, variadic: true });
  6767. break;
  6768. } else {
  6769. expand = true;
  6770. }
  6771. } else if (!isCall) {
  6772. name = nameLoop = val.name;
  6773. value = null;
  6774. }
  6775. }
  6776. if (value) {
  6777. expressions.push(value);
  6778. }
  6779. argsComma.push({ name: nameLoop, value, expand });
  6780. if (parserInput.$char(",")) {
  6781. hasSep = true;
  6782. continue;
  6783. }
  6784. hasSep = parserInput.$char(";") === ";";
  6785. if (hasSep || isSemiColonSeparated) {
  6786. if (expressionContainsNamed) {
  6787. error("Cannot mix ; and , as delimiter types");
  6788. }
  6789. isSemiColonSeparated = true;
  6790. if (expressions.length > 1) {
  6791. value = new tree.Value(expressions);
  6792. }
  6793. argsSemiColon.push({ name, value, expand });
  6794. name = null;
  6795. expressions = [];
  6796. expressionContainsNamed = false;
  6797. }
  6798. }
  6799. parserInput.forget();
  6800. returner.args = isSemiColonSeparated ? argsSemiColon : argsComma;
  6801. return returner;
  6802. },
  6803. //
  6804. // A Mixin definition, with a list of parameters
  6805. //
  6806. // .rounded (@radius: 2px, @color) {
  6807. // ...
  6808. // }
  6809. //
  6810. // Until we have a finer grained state-machine, we have to
  6811. // do a look-ahead, to make sure we don't have a mixin call.
  6812. // See the `rule` function for more information.
  6813. //
  6814. // We start by matching `.rounded (`, and then proceed on to
  6815. // the argument list, which has optional default values.
  6816. // We store the parameters in `params`, with a `value` key,
  6817. // if there is a value, such as in the case of `@radius`.
  6818. //
  6819. // Once we've got our params list, and a closing `)`, we parse
  6820. // the `{...}` block.
  6821. //
  6822. definition: function() {
  6823. var name;
  6824. var params = [];
  6825. var match;
  6826. var ruleset;
  6827. var cond;
  6828. var variadic = false;
  6829. if (parserInput.currentChar() !== "." && parserInput.currentChar() !== "#" || parserInput.peek(/^[^{]*\}/)) {
  6830. return;
  6831. }
  6832. parserInput.save();
  6833. match = parserInput.$re(/^([#.](?:[\w-]|\\(?:[A-Fa-f0-9]{1,6} ?|[^A-Fa-f0-9]))+)\s*\(/);
  6834. if (match) {
  6835. name = match[1];
  6836. var argInfo = this.args(false);
  6837. params = argInfo.args;
  6838. variadic = argInfo.variadic;
  6839. if (!parserInput.$char(")")) {
  6840. parserInput.restore("Missing closing ')'");
  6841. return;
  6842. }
  6843. parserInput.commentStore.length = 0;
  6844. if (parserInput.$str("when")) {
  6845. cond = expect(parsers.conditions, "expected condition");
  6846. }
  6847. ruleset = parsers.block();
  6848. if (ruleset) {
  6849. parserInput.forget();
  6850. return new tree.mixin.Definition(name, params, ruleset, cond, variadic);
  6851. } else {
  6852. parserInput.restore();
  6853. }
  6854. } else {
  6855. parserInput.restore();
  6856. }
  6857. },
  6858. ruleLookups: function() {
  6859. var rule;
  6860. var lookups = [];
  6861. if (parserInput.currentChar() !== "[") {
  6862. return;
  6863. }
  6864. while (true) {
  6865. parserInput.save();
  6866. rule = this.lookupValue();
  6867. if (!rule && rule !== "") {
  6868. parserInput.restore();
  6869. break;
  6870. }
  6871. lookups.push(rule);
  6872. parserInput.forget();
  6873. }
  6874. if (lookups.length > 0) {
  6875. return lookups;
  6876. }
  6877. },
  6878. lookupValue: function() {
  6879. parserInput.save();
  6880. if (!parserInput.$char("[")) {
  6881. parserInput.restore();
  6882. return;
  6883. }
  6884. var name = parserInput.$re(/^(?:[@$]{0,2})[_a-zA-Z0-9-]*/);
  6885. if (!parserInput.$char("]")) {
  6886. parserInput.restore();
  6887. return;
  6888. }
  6889. if (name || name === "") {
  6890. parserInput.forget();
  6891. return name;
  6892. }
  6893. parserInput.restore();
  6894. }
  6895. },
  6896. //
  6897. // Entities are the smallest recognized token,
  6898. // and can be found inside a rule's value.
  6899. //
  6900. entity: function() {
  6901. var entities = this.entities;
  6902. return this.comment() || entities.literal() || entities.variable() || entities.url() || entities.property() || entities.call() || entities.keyword() || this.mixin.call(true) || entities.javascript();
  6903. },
  6904. //
  6905. // A Declaration terminator. Note that we use `peek()` to check for '}',
  6906. // because the `block` rule will be expecting it, but we still need to make sure
  6907. // it's there, if ';' was omitted.
  6908. //
  6909. end: function() {
  6910. return parserInput.$char(";") || parserInput.peek("}");
  6911. },
  6912. //
  6913. // IE's alpha function
  6914. //
  6915. // alpha(opacity=88)
  6916. //
  6917. ieAlpha: function() {
  6918. var value;
  6919. if (!parserInput.$re(/^opacity=/i)) {
  6920. return;
  6921. }
  6922. value = parserInput.$re(/^\d+/);
  6923. if (!value) {
  6924. value = expect(parsers.entities.variable, "Could not parse alpha");
  6925. value = "@{" + value.name.slice(1) + "}";
  6926. }
  6927. expectChar(")");
  6928. return new tree.Quoted("", "alpha(opacity=" + value + ")");
  6929. },
  6930. //
  6931. // A Selector Element
  6932. //
  6933. // div
  6934. // + h1
  6935. // #socks
  6936. // input[type="text"]
  6937. //
  6938. // Elements are the building blocks for Selectors,
  6939. // they are made out of a `Combinator` (see combinator rule),
  6940. // and an element name, such as a tag a class, or `*`.
  6941. //
  6942. element: function() {
  6943. var e;
  6944. var c;
  6945. var v;
  6946. var index = parserInput.i;
  6947. c = this.combinator();
  6948. 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();
  6949. if (!e) {
  6950. parserInput.save();
  6951. if (parserInput.$char("(")) {
  6952. if ((v = this.selector(false)) && parserInput.$char(")")) {
  6953. e = new tree.Paren(v);
  6954. parserInput.forget();
  6955. } else {
  6956. parserInput.restore("Missing closing ')'");
  6957. }
  6958. } else {
  6959. parserInput.forget();
  6960. }
  6961. }
  6962. if (e) {
  6963. return new tree.Element(c, e, e instanceof tree.Variable, index, fileInfo);
  6964. }
  6965. },
  6966. //
  6967. // Combinators combine elements together, in a Selector.
  6968. //
  6969. // Because our parser isn't white-space sensitive, special care
  6970. // has to be taken, when parsing the descendant combinator, ` `,
  6971. // as it's an empty space. We have to check the previous character
  6972. // in the input, to see if it's a ` ` character. More info on how
  6973. // we deal with this in *combinator.js*.
  6974. //
  6975. combinator: function() {
  6976. var c = parserInput.currentChar();
  6977. if (c === "/") {
  6978. parserInput.save();
  6979. var slashedCombinator = parserInput.$re(/^\/[a-z]+\//i);
  6980. if (slashedCombinator) {
  6981. parserInput.forget();
  6982. return new tree.Combinator(slashedCombinator);
  6983. }
  6984. parserInput.restore();
  6985. }
  6986. if (c === ">" || c === "+" || c === "~" || c === "|" || c === "^") {
  6987. parserInput.i++;
  6988. if (c === "^" && parserInput.currentChar() === "^") {
  6989. c = "^^";
  6990. parserInput.i++;
  6991. }
  6992. while (parserInput.isWhitespace()) {
  6993. parserInput.i++;
  6994. }
  6995. return new tree.Combinator(c);
  6996. } else if (parserInput.isWhitespace(-1)) {
  6997. return new tree.Combinator(" ");
  6998. } else {
  6999. return new tree.Combinator(null);
  7000. }
  7001. },
  7002. //
  7003. // A CSS Selector
  7004. // with less extensions e.g. the ability to extend and guard
  7005. //
  7006. // .class > div + h1
  7007. // li a:hover
  7008. //
  7009. // Selectors are made out of one or more Elements, see above.
  7010. //
  7011. selector: function(isLess) {
  7012. var index = parserInput.i;
  7013. var elements;
  7014. var extendList;
  7015. var c;
  7016. var e;
  7017. var allExtends;
  7018. var when;
  7019. var condition;
  7020. isLess = isLess !== false;
  7021. while (isLess && (extendList = this.extend()) || isLess && (when = parserInput.$str("when")) || (e = this.element())) {
  7022. if (when) {
  7023. condition = expect(this.conditions, "expected condition");
  7024. } else if (condition) {
  7025. error("CSS guard can only be used at the end of selector");
  7026. } else if (extendList) {
  7027. if (allExtends) {
  7028. allExtends = allExtends.concat(extendList);
  7029. } else {
  7030. allExtends = extendList;
  7031. }
  7032. } else {
  7033. if (allExtends) {
  7034. error("Extend can only be used at the end of selector");
  7035. }
  7036. c = parserInput.currentChar();
  7037. if (elements) {
  7038. elements.push(e);
  7039. } else {
  7040. elements = [e];
  7041. }
  7042. e = null;
  7043. }
  7044. if (c === "{" || c === "}" || c === ";" || c === "," || c === ")") {
  7045. break;
  7046. }
  7047. }
  7048. if (elements) {
  7049. return new tree.Selector(elements, allExtends, condition, index, fileInfo);
  7050. }
  7051. if (allExtends) {
  7052. error("Extend must be used to extend a selector, it cannot be used on its own");
  7053. }
  7054. },
  7055. selectors: function() {
  7056. var s;
  7057. var selectors;
  7058. while (true) {
  7059. s = this.selector();
  7060. if (!s) {
  7061. break;
  7062. }
  7063. if (selectors) {
  7064. selectors.push(s);
  7065. } else {
  7066. selectors = [s];
  7067. }
  7068. parserInput.commentStore.length = 0;
  7069. if (s.condition && selectors.length > 1) {
  7070. error("Guards are only currently allowed on a single selector.");
  7071. }
  7072. if (!parserInput.$char(",")) {
  7073. break;
  7074. }
  7075. if (s.condition) {
  7076. error("Guards are only currently allowed on a single selector.");
  7077. }
  7078. parserInput.commentStore.length = 0;
  7079. }
  7080. return selectors;
  7081. },
  7082. attribute: function() {
  7083. if (!parserInput.$char("[")) {
  7084. return;
  7085. }
  7086. var entities = this.entities;
  7087. var key2;
  7088. var val;
  7089. var op;
  7090. var cif;
  7091. if (!(key2 = entities.variableCurly())) {
  7092. key2 = expect(/^(?:[_A-Za-z0-9-\*]*\|)?(?:[_A-Za-z0-9-]|\\.)+/);
  7093. }
  7094. op = parserInput.$re(/^[|~*$^]?=/);
  7095. if (op) {
  7096. val = entities.quoted() || parserInput.$re(/^[0-9]+%/) || parserInput.$re(/^[\w-]+/) || entities.variableCurly();
  7097. if (val) {
  7098. cif = parserInput.$re(/^[iIsS]/);
  7099. }
  7100. }
  7101. expectChar("]");
  7102. return new tree.Attribute(key2, op, val, cif);
  7103. },
  7104. //
  7105. // The `block` rule is used by `ruleset` and `mixin.definition`.
  7106. // It's a wrapper around the `primary` rule, with added `{}`.
  7107. //
  7108. block: function() {
  7109. var content;
  7110. if (parserInput.$char("{") && (content = this.primary()) && parserInput.$char("}")) {
  7111. return content;
  7112. }
  7113. },
  7114. blockRuleset: function() {
  7115. var block = this.block();
  7116. if (block) {
  7117. block = new tree.Ruleset(null, block);
  7118. }
  7119. return block;
  7120. },
  7121. detachedRuleset: function() {
  7122. var argInfo;
  7123. var params;
  7124. var variadic;
  7125. parserInput.save();
  7126. if (parserInput.$re(/^[.#]\(/)) {
  7127. argInfo = this.mixin.args(false);
  7128. params = argInfo.args;
  7129. variadic = argInfo.variadic;
  7130. if (!parserInput.$char(")")) {
  7131. parserInput.restore();
  7132. return;
  7133. }
  7134. }
  7135. var blockRuleset = this.blockRuleset();
  7136. if (blockRuleset) {
  7137. parserInput.forget();
  7138. if (params) {
  7139. return new tree.mixin.Definition(null, params, blockRuleset, null, variadic);
  7140. }
  7141. return new tree.DetachedRuleset(blockRuleset);
  7142. }
  7143. parserInput.restore();
  7144. },
  7145. //
  7146. // div, .class, body > p {...}
  7147. //
  7148. ruleset: function() {
  7149. var selectors;
  7150. var rules;
  7151. var debugInfo2;
  7152. parserInput.save();
  7153. if (context.dumpLineNumbers) {
  7154. debugInfo2 = getDebugInfo(parserInput.i);
  7155. }
  7156. selectors = this.selectors();
  7157. if (selectors && (rules = this.block())) {
  7158. parserInput.forget();
  7159. var ruleset = new tree.Ruleset(selectors, rules, context.strictImports);
  7160. if (context.dumpLineNumbers) {
  7161. ruleset.debugInfo = debugInfo2;
  7162. }
  7163. return ruleset;
  7164. } else {
  7165. parserInput.restore();
  7166. }
  7167. },
  7168. declaration: function() {
  7169. var name;
  7170. var value;
  7171. var index = parserInput.i;
  7172. var hasDR;
  7173. var c = parserInput.currentChar();
  7174. var important;
  7175. var merge2;
  7176. var isVariable;
  7177. if (c === "." || c === "#" || c === "&" || c === ":") {
  7178. return;
  7179. }
  7180. parserInput.save();
  7181. name = this.variable() || this.ruleProperty();
  7182. if (name) {
  7183. isVariable = typeof name === "string";
  7184. if (isVariable) {
  7185. value = this.detachedRuleset();
  7186. if (value) {
  7187. hasDR = true;
  7188. }
  7189. }
  7190. parserInput.commentStore.length = 0;
  7191. if (!value) {
  7192. merge2 = !isVariable && name.length > 1 && name.pop().value;
  7193. if (name[0].value && name[0].value.slice(0, 2) === "--") {
  7194. value = this.permissiveValue();
  7195. } else {
  7196. value = this.anonymousValue();
  7197. }
  7198. if (value) {
  7199. parserInput.forget();
  7200. return new tree.Declaration(name, value, false, merge2, index, fileInfo);
  7201. }
  7202. if (!value) {
  7203. value = this.value();
  7204. }
  7205. if (value) {
  7206. important = this.important();
  7207. } else if (isVariable) {
  7208. value = this.permissiveValue();
  7209. }
  7210. }
  7211. if (value && (this.end() || hasDR)) {
  7212. parserInput.forget();
  7213. return new tree.Declaration(name, value, important, merge2, index, fileInfo);
  7214. } else {
  7215. parserInput.restore();
  7216. }
  7217. } else {
  7218. parserInput.restore();
  7219. }
  7220. },
  7221. anonymousValue: function() {
  7222. var index = parserInput.i;
  7223. var match = parserInput.$re(/^([^.#@\$+\/'"*`(;{}-]*);/);
  7224. if (match) {
  7225. return new tree.Anonymous(match[1], index);
  7226. }
  7227. },
  7228. /**
  7229. * Used for custom properties, at-rules, and variables (as fallback)
  7230. * Parses almost anything inside of {} [] () "" blocks
  7231. * until it reaches outer-most tokens.
  7232. *
  7233. * First, it will try to parse comments and entities to reach
  7234. * the end. This is mostly like the Expression parser except no
  7235. * math is allowed.
  7236. */
  7237. permissiveValue: function(untilTokens) {
  7238. var i;
  7239. var e;
  7240. var done;
  7241. var value;
  7242. var tok = untilTokens || ";";
  7243. var index = parserInput.i;
  7244. var result = [];
  7245. function testCurrentChar() {
  7246. var char = parserInput.currentChar();
  7247. if (typeof tok === "string") {
  7248. return char === tok;
  7249. } else {
  7250. return tok.test(char);
  7251. }
  7252. }
  7253. if (testCurrentChar()) {
  7254. return;
  7255. }
  7256. value = [];
  7257. do {
  7258. e = this.comment();
  7259. if (e) {
  7260. value.push(e);
  7261. continue;
  7262. }
  7263. e = this.entity();
  7264. if (e) {
  7265. value.push(e);
  7266. }
  7267. } while (e);
  7268. done = testCurrentChar();
  7269. if (value.length > 0) {
  7270. value = new tree.Expression(value);
  7271. if (done) {
  7272. return value;
  7273. } else {
  7274. result.push(value);
  7275. }
  7276. if (parserInput.prevChar() === " ") {
  7277. result.push(new tree.Anonymous(" ", index));
  7278. }
  7279. }
  7280. parserInput.save();
  7281. value = parserInput.$parseUntil(tok);
  7282. if (value) {
  7283. if (typeof value === "string") {
  7284. error("Expected '" + value + "'", "Parse");
  7285. }
  7286. if (value.length === 1 && value[0] === " ") {
  7287. parserInput.forget();
  7288. return new tree.Anonymous("", index);
  7289. }
  7290. var item = void 0;
  7291. for (i = 0; i < value.length; i++) {
  7292. item = value[i];
  7293. if (Array.isArray(item)) {
  7294. result.push(new tree.Quoted(item[0], item[1], true, index, fileInfo));
  7295. } else {
  7296. if (i === value.length - 1) {
  7297. item = item.trim();
  7298. }
  7299. var quote = new tree.Quoted("'", item, true, index, fileInfo);
  7300. quote.variableRegex = /@([\w-]+)/g;
  7301. quote.propRegex = /\$([\w-]+)/g;
  7302. result.push(quote);
  7303. }
  7304. }
  7305. parserInput.forget();
  7306. return new tree.Expression(result, true);
  7307. }
  7308. parserInput.restore();
  7309. },
  7310. //
  7311. // An @import atrule
  7312. //
  7313. // @import "lib";
  7314. //
  7315. // Depending on our environment, importing is done differently:
  7316. // In the browser, it's an XHR request, in Node, it would be a
  7317. // file-system operation. The function used for importing is
  7318. // stored in `import`, which we pass to the Import constructor.
  7319. //
  7320. "import": function() {
  7321. var path;
  7322. var features;
  7323. var index = parserInput.i;
  7324. var dir = parserInput.$re(/^@import\s+/);
  7325. if (dir) {
  7326. var options2 = (dir ? this.importOptions() : null) || {};
  7327. if (path = this.entities.quoted() || this.entities.url()) {
  7328. features = this.mediaFeatures();
  7329. if (!parserInput.$char(";")) {
  7330. parserInput.i = index;
  7331. error("missing semi-colon or unrecognised media features on import");
  7332. }
  7333. features = features && new tree.Value(features);
  7334. return new tree.Import(path, features, options2, index, fileInfo);
  7335. } else {
  7336. parserInput.i = index;
  7337. error("malformed import statement");
  7338. }
  7339. }
  7340. },
  7341. importOptions: function() {
  7342. var o;
  7343. var options2 = {};
  7344. var optionName;
  7345. var value;
  7346. if (!parserInput.$char("(")) {
  7347. return null;
  7348. }
  7349. do {
  7350. o = this.importOption();
  7351. if (o) {
  7352. optionName = o;
  7353. value = true;
  7354. switch (optionName) {
  7355. case "css":
  7356. optionName = "less";
  7357. value = false;
  7358. break;
  7359. case "once":
  7360. optionName = "multiple";
  7361. value = false;
  7362. break;
  7363. }
  7364. options2[optionName] = value;
  7365. if (!parserInput.$char(",")) {
  7366. break;
  7367. }
  7368. }
  7369. } while (o);
  7370. expectChar(")");
  7371. return options2;
  7372. },
  7373. importOption: function() {
  7374. var opt = parserInput.$re(/^(less|css|multiple|once|inline|reference|optional)/);
  7375. if (opt) {
  7376. return opt[1];
  7377. }
  7378. },
  7379. mediaFeature: function() {
  7380. var entities = this.entities;
  7381. var nodes = [];
  7382. var e;
  7383. var p;
  7384. parserInput.save();
  7385. do {
  7386. e = entities.keyword() || entities.variable() || entities.mixinLookup();
  7387. if (e) {
  7388. nodes.push(e);
  7389. } else if (parserInput.$char("(")) {
  7390. p = this.property();
  7391. e = this.value();
  7392. if (parserInput.$char(")")) {
  7393. if (p && e) {
  7394. nodes.push(new tree.Paren(new tree.Declaration(p, e, null, null, parserInput.i, fileInfo, true)));
  7395. } else if (e) {
  7396. nodes.push(new tree.Paren(e));
  7397. } else {
  7398. error("badly formed media feature definition");
  7399. }
  7400. } else {
  7401. error("Missing closing ')'", "Parse");
  7402. }
  7403. }
  7404. } while (e);
  7405. parserInput.forget();
  7406. if (nodes.length > 0) {
  7407. return new tree.Expression(nodes);
  7408. }
  7409. },
  7410. mediaFeatures: function() {
  7411. var entities = this.entities;
  7412. var features = [];
  7413. var e;
  7414. do {
  7415. e = this.mediaFeature();
  7416. if (e) {
  7417. features.push(e);
  7418. if (!parserInput.$char(",")) {
  7419. break;
  7420. }
  7421. } else {
  7422. e = entities.variable() || entities.mixinLookup();
  7423. if (e) {
  7424. features.push(e);
  7425. if (!parserInput.$char(",")) {
  7426. break;
  7427. }
  7428. }
  7429. }
  7430. } while (e);
  7431. return features.length > 0 ? features : null;
  7432. },
  7433. media: function() {
  7434. var features;
  7435. var rules;
  7436. var media;
  7437. var debugInfo2;
  7438. var index = parserInput.i;
  7439. if (context.dumpLineNumbers) {
  7440. debugInfo2 = getDebugInfo(index);
  7441. }
  7442. parserInput.save();
  7443. if (parserInput.$str("@media")) {
  7444. features = this.mediaFeatures();
  7445. rules = this.block();
  7446. if (!rules) {
  7447. error("media definitions require block statements after any features");
  7448. }
  7449. parserInput.forget();
  7450. media = new tree.Media(rules, features, index, fileInfo);
  7451. if (context.dumpLineNumbers) {
  7452. media.debugInfo = debugInfo2;
  7453. }
  7454. return media;
  7455. }
  7456. parserInput.restore();
  7457. },
  7458. //
  7459. // A @plugin directive, used to import plugins dynamically.
  7460. //
  7461. // @plugin (args) "lib";
  7462. //
  7463. plugin: function() {
  7464. var path;
  7465. var args;
  7466. var options2;
  7467. var index = parserInput.i;
  7468. var dir = parserInput.$re(/^@plugin\s+/);
  7469. if (dir) {
  7470. args = this.pluginArgs();
  7471. if (args) {
  7472. options2 = {
  7473. pluginArgs: args,
  7474. isPlugin: true
  7475. };
  7476. } else {
  7477. options2 = { isPlugin: true };
  7478. }
  7479. if (path = this.entities.quoted() || this.entities.url()) {
  7480. if (!parserInput.$char(";")) {
  7481. parserInput.i = index;
  7482. error("missing semi-colon on @plugin");
  7483. }
  7484. return new tree.Import(path, null, options2, index, fileInfo);
  7485. } else {
  7486. parserInput.i = index;
  7487. error("malformed @plugin statement");
  7488. }
  7489. }
  7490. },
  7491. pluginArgs: function() {
  7492. parserInput.save();
  7493. if (!parserInput.$char("(")) {
  7494. parserInput.restore();
  7495. return null;
  7496. }
  7497. var args = parserInput.$re(/^\s*([^\);]+)\)\s*/);
  7498. if (args[1]) {
  7499. parserInput.forget();
  7500. return args[1].trim();
  7501. } else {
  7502. parserInput.restore();
  7503. return null;
  7504. }
  7505. },
  7506. //
  7507. // A CSS AtRule
  7508. //
  7509. // @charset "utf-8";
  7510. //
  7511. atrule: function() {
  7512. var index = parserInput.i;
  7513. var name;
  7514. var value;
  7515. var rules;
  7516. var nonVendorSpecificName;
  7517. var hasIdentifier;
  7518. var hasExpression;
  7519. var hasUnknown;
  7520. var hasBlock = true;
  7521. var isRooted = true;
  7522. if (parserInput.currentChar() !== "@") {
  7523. return;
  7524. }
  7525. value = this["import"]() || this.plugin() || this.media();
  7526. if (value) {
  7527. return value;
  7528. }
  7529. parserInput.save();
  7530. name = parserInput.$re(/^@[a-z-]+/);
  7531. if (!name) {
  7532. return;
  7533. }
  7534. nonVendorSpecificName = name;
  7535. if (name.charAt(1) == "-" && name.indexOf("-", 2) > 0) {
  7536. nonVendorSpecificName = "@" + name.slice(name.indexOf("-", 2) + 1);
  7537. }
  7538. switch (nonVendorSpecificName) {
  7539. case "@charset":
  7540. hasIdentifier = true;
  7541. hasBlock = false;
  7542. break;
  7543. case "@namespace":
  7544. hasExpression = true;
  7545. hasBlock = false;
  7546. break;
  7547. case "@keyframes":
  7548. case "@counter-style":
  7549. hasIdentifier = true;
  7550. break;
  7551. case "@document":
  7552. case "@supports":
  7553. hasUnknown = true;
  7554. isRooted = false;
  7555. break;
  7556. default:
  7557. hasUnknown = true;
  7558. break;
  7559. }
  7560. parserInput.commentStore.length = 0;
  7561. if (hasIdentifier) {
  7562. value = this.entity();
  7563. if (!value) {
  7564. error("expected " + name + " identifier");
  7565. }
  7566. } else if (hasExpression) {
  7567. value = this.expression();
  7568. if (!value) {
  7569. error("expected " + name + " expression");
  7570. }
  7571. } else if (hasUnknown) {
  7572. value = this.permissiveValue(/^[{;]/);
  7573. hasBlock = parserInput.currentChar() === "{";
  7574. if (!value) {
  7575. if (!hasBlock && parserInput.currentChar() !== ";") {
  7576. error(name + " rule is missing block or ending semi-colon");
  7577. }
  7578. } else if (!value.value) {
  7579. value = null;
  7580. }
  7581. }
  7582. if (hasBlock) {
  7583. rules = this.blockRuleset();
  7584. }
  7585. if (rules || !hasBlock && value && parserInput.$char(";")) {
  7586. parserInput.forget();
  7587. return new tree.AtRule(name, value, rules, index, fileInfo, context.dumpLineNumbers ? getDebugInfo(index) : null, isRooted);
  7588. }
  7589. parserInput.restore("at-rule options not recognised");
  7590. },
  7591. //
  7592. // A Value is a comma-delimited list of Expressions
  7593. //
  7594. // font-family: Baskerville, Georgia, serif;
  7595. //
  7596. // In a Rule, a Value represents everything after the `:`,
  7597. // and before the `;`.
  7598. //
  7599. value: function() {
  7600. var e;
  7601. var expressions = [];
  7602. var index = parserInput.i;
  7603. do {
  7604. e = this.expression();
  7605. if (e) {
  7606. expressions.push(e);
  7607. if (!parserInput.$char(",")) {
  7608. break;
  7609. }
  7610. }
  7611. } while (e);
  7612. if (expressions.length > 0) {
  7613. return new tree.Value(expressions, index);
  7614. }
  7615. },
  7616. important: function() {
  7617. if (parserInput.currentChar() === "!") {
  7618. return parserInput.$re(/^! *important/);
  7619. }
  7620. },
  7621. sub: function() {
  7622. var a;
  7623. var e;
  7624. parserInput.save();
  7625. if (parserInput.$char("(")) {
  7626. a = this.addition();
  7627. if (a && parserInput.$char(")")) {
  7628. parserInput.forget();
  7629. e = new tree.Expression([a]);
  7630. e.parens = true;
  7631. return e;
  7632. }
  7633. parserInput.restore("Expected ')'");
  7634. return;
  7635. }
  7636. parserInput.restore();
  7637. },
  7638. multiplication: function() {
  7639. var m;
  7640. var a;
  7641. var op;
  7642. var operation;
  7643. var isSpaced;
  7644. m = this.operand();
  7645. if (m) {
  7646. isSpaced = parserInput.isWhitespace(-1);
  7647. while (true) {
  7648. if (parserInput.peek(/^\/[*\/]/)) {
  7649. break;
  7650. }
  7651. parserInput.save();
  7652. op = parserInput.$char("/") || parserInput.$char("*") || parserInput.$str("./");
  7653. if (!op) {
  7654. parserInput.forget();
  7655. break;
  7656. }
  7657. a = this.operand();
  7658. if (!a) {
  7659. parserInput.restore();
  7660. break;
  7661. }
  7662. parserInput.forget();
  7663. m.parensInOp = true;
  7664. a.parensInOp = true;
  7665. operation = new tree.Operation(op, [operation || m, a], isSpaced);
  7666. isSpaced = parserInput.isWhitespace(-1);
  7667. }
  7668. return operation || m;
  7669. }
  7670. },
  7671. addition: function() {
  7672. var m;
  7673. var a;
  7674. var op;
  7675. var operation;
  7676. var isSpaced;
  7677. m = this.multiplication();
  7678. if (m) {
  7679. isSpaced = parserInput.isWhitespace(-1);
  7680. while (true) {
  7681. op = parserInput.$re(/^[-+]\s+/) || !isSpaced && (parserInput.$char("+") || parserInput.$char("-"));
  7682. if (!op) {
  7683. break;
  7684. }
  7685. a = this.multiplication();
  7686. if (!a) {
  7687. break;
  7688. }
  7689. m.parensInOp = true;
  7690. a.parensInOp = true;
  7691. operation = new tree.Operation(op, [operation || m, a], isSpaced);
  7692. isSpaced = parserInput.isWhitespace(-1);
  7693. }
  7694. return operation || m;
  7695. }
  7696. },
  7697. conditions: function() {
  7698. var a;
  7699. var b;
  7700. var index = parserInput.i;
  7701. var condition;
  7702. a = this.condition(true);
  7703. if (a) {
  7704. while (true) {
  7705. if (!parserInput.peek(/^,\s*(not\s*)?\(/) || !parserInput.$char(",")) {
  7706. break;
  7707. }
  7708. b = this.condition(true);
  7709. if (!b) {
  7710. break;
  7711. }
  7712. condition = new tree.Condition("or", condition || a, b, index);
  7713. }
  7714. return condition || a;
  7715. }
  7716. },
  7717. condition: function(needsParens) {
  7718. var result;
  7719. var logical;
  7720. var next;
  7721. function or() {
  7722. return parserInput.$str("or");
  7723. }
  7724. result = this.conditionAnd(needsParens);
  7725. if (!result) {
  7726. return;
  7727. }
  7728. logical = or();
  7729. if (logical) {
  7730. next = this.condition(needsParens);
  7731. if (next) {
  7732. result = new tree.Condition(logical, result, next);
  7733. } else {
  7734. return;
  7735. }
  7736. }
  7737. return result;
  7738. },
  7739. conditionAnd: function(needsParens) {
  7740. var result;
  7741. var logical;
  7742. var next;
  7743. var self2 = this;
  7744. function insideCondition() {
  7745. var cond = self2.negatedCondition(needsParens) || self2.parenthesisCondition(needsParens);
  7746. if (!cond && !needsParens) {
  7747. return self2.atomicCondition(needsParens);
  7748. }
  7749. return cond;
  7750. }
  7751. function and() {
  7752. return parserInput.$str("and");
  7753. }
  7754. result = insideCondition();
  7755. if (!result) {
  7756. return;
  7757. }
  7758. logical = and();
  7759. if (logical) {
  7760. next = this.conditionAnd(needsParens);
  7761. if (next) {
  7762. result = new tree.Condition(logical, result, next);
  7763. } else {
  7764. return;
  7765. }
  7766. }
  7767. return result;
  7768. },
  7769. negatedCondition: function(needsParens) {
  7770. if (parserInput.$str("not")) {
  7771. var result = this.parenthesisCondition(needsParens);
  7772. if (result) {
  7773. result.negate = !result.negate;
  7774. }
  7775. return result;
  7776. }
  7777. },
  7778. parenthesisCondition: function(needsParens) {
  7779. function tryConditionFollowedByParenthesis(me) {
  7780. var body2;
  7781. parserInput.save();
  7782. body2 = me.condition(needsParens);
  7783. if (!body2) {
  7784. parserInput.restore();
  7785. return;
  7786. }
  7787. if (!parserInput.$char(")")) {
  7788. parserInput.restore();
  7789. return;
  7790. }
  7791. parserInput.forget();
  7792. return body2;
  7793. }
  7794. var body;
  7795. parserInput.save();
  7796. if (!parserInput.$str("(")) {
  7797. parserInput.restore();
  7798. return;
  7799. }
  7800. body = tryConditionFollowedByParenthesis(this);
  7801. if (body) {
  7802. parserInput.forget();
  7803. return body;
  7804. }
  7805. body = this.atomicCondition(needsParens);
  7806. if (!body) {
  7807. parserInput.restore();
  7808. return;
  7809. }
  7810. if (!parserInput.$char(")")) {
  7811. parserInput.restore("expected ')' got '" + parserInput.currentChar() + "'");
  7812. return;
  7813. }
  7814. parserInput.forget();
  7815. return body;
  7816. },
  7817. atomicCondition: function(needsParens) {
  7818. var entities = this.entities;
  7819. var index = parserInput.i;
  7820. var a;
  7821. var b;
  7822. var c;
  7823. var op;
  7824. function cond() {
  7825. return this.addition() || entities.keyword() || entities.quoted() || entities.mixinLookup();
  7826. }
  7827. cond = cond.bind(this);
  7828. a = cond();
  7829. if (a) {
  7830. if (parserInput.$char(">")) {
  7831. if (parserInput.$char("=")) {
  7832. op = ">=";
  7833. } else {
  7834. op = ">";
  7835. }
  7836. } else if (parserInput.$char("<")) {
  7837. if (parserInput.$char("=")) {
  7838. op = "<=";
  7839. } else {
  7840. op = "<";
  7841. }
  7842. } else if (parserInput.$char("=")) {
  7843. if (parserInput.$char(">")) {
  7844. op = "=>";
  7845. } else if (parserInput.$char("<")) {
  7846. op = "=<";
  7847. } else {
  7848. op = "=";
  7849. }
  7850. }
  7851. if (op) {
  7852. b = cond();
  7853. if (b) {
  7854. c = new tree.Condition(op, a, b, index, false);
  7855. } else {
  7856. error("expected expression");
  7857. }
  7858. } else {
  7859. c = new tree.Condition("=", a, new tree.Keyword("true"), index, false);
  7860. }
  7861. return c;
  7862. }
  7863. },
  7864. //
  7865. // An operand is anything that can be part of an operation,
  7866. // such as a Color, or a Variable
  7867. //
  7868. operand: function() {
  7869. var entities = this.entities;
  7870. var negate;
  7871. if (parserInput.peek(/^-[@\$\(]/)) {
  7872. negate = parserInput.$char("-");
  7873. }
  7874. var o = this.sub() || entities.dimension() || entities.color() || entities.variable() || entities.property() || entities.call() || entities.quoted(true) || entities.colorKeyword() || entities.mixinLookup();
  7875. if (negate) {
  7876. o.parensInOp = true;
  7877. o = new tree.Negative(o);
  7878. }
  7879. return o;
  7880. },
  7881. //
  7882. // Expressions either represent mathematical operations,
  7883. // or white-space delimited Entities.
  7884. //
  7885. // 1px solid black
  7886. // @var * 2
  7887. //
  7888. expression: function() {
  7889. var entities = [];
  7890. var e;
  7891. var delim;
  7892. var index = parserInput.i;
  7893. do {
  7894. e = this.comment();
  7895. if (e) {
  7896. entities.push(e);
  7897. continue;
  7898. }
  7899. e = this.addition() || this.entity();
  7900. if (e instanceof tree.Comment) {
  7901. e = null;
  7902. }
  7903. if (e) {
  7904. entities.push(e);
  7905. if (!parserInput.peek(/^\/[\/*]/)) {
  7906. delim = parserInput.$char("/");
  7907. if (delim) {
  7908. entities.push(new tree.Anonymous(delim, index));
  7909. }
  7910. }
  7911. }
  7912. } while (e);
  7913. if (entities.length > 0) {
  7914. return new tree.Expression(entities);
  7915. }
  7916. },
  7917. property: function() {
  7918. var name = parserInput.$re(/^(\*?-?[_a-zA-Z0-9-]+)\s*:/);
  7919. if (name) {
  7920. return name[1];
  7921. }
  7922. },
  7923. ruleProperty: function() {
  7924. var name = [];
  7925. var index = [];
  7926. var s;
  7927. var k;
  7928. parserInput.save();
  7929. var simpleProperty = parserInput.$re(/^([_a-zA-Z0-9-]+)\s*:/);
  7930. if (simpleProperty) {
  7931. name = [new tree.Keyword(simpleProperty[1])];
  7932. parserInput.forget();
  7933. return name;
  7934. }
  7935. function match(re) {
  7936. var i = parserInput.i;
  7937. var chunk = parserInput.$re(re);
  7938. if (chunk) {
  7939. index.push(i);
  7940. return name.push(chunk[1]);
  7941. }
  7942. }
  7943. match(/^(\*?)/);
  7944. while (true) {
  7945. if (!match(/^((?:[\w-]+)|(?:[@\$]\{[\w-]+\}))/)) {
  7946. break;
  7947. }
  7948. }
  7949. if (name.length > 1 && match(/^((?:\+_|\+)?)\s*:/)) {
  7950. parserInput.forget();
  7951. if (name[0] === "") {
  7952. name.shift();
  7953. index.shift();
  7954. }
  7955. for (k = 0; k < name.length; k++) {
  7956. s = name[k];
  7957. name[k] = s.charAt(0) !== "@" && s.charAt(0) !== "$" ? new tree.Keyword(s) : s.charAt(0) === "@" ? new tree.Variable("@" + s.slice(2, -1), index[k], fileInfo) : new tree.Property("$" + s.slice(2, -1), index[k], fileInfo);
  7958. }
  7959. return name;
  7960. }
  7961. parserInput.restore();
  7962. }
  7963. }
  7964. };
  7965. };
  7966. Parser.serializeVars = function(vars) {
  7967. var s = "";
  7968. for (var name_1 in vars) {
  7969. if (Object.hasOwnProperty.call(vars, name_1)) {
  7970. var value = vars[name_1];
  7971. s += (name_1[0] === "@" ? "" : "@") + name_1 + ": " + value + (String(value).slice(-1) === ";" ? "" : ";");
  7972. }
  7973. }
  7974. return s;
  7975. };
  7976. function boolean(condition) {
  7977. return condition ? Keyword.True : Keyword.False;
  7978. }
  7979. function If(context, condition, trueValue, falseValue) {
  7980. return condition.eval(context) ? trueValue.eval(context) : falseValue ? falseValue.eval(context) : new Anonymous();
  7981. }
  7982. If.evalArgs = false;
  7983. function isdefined(context, variable) {
  7984. try {
  7985. variable.eval(context);
  7986. return Keyword.True;
  7987. } catch (e) {
  7988. return Keyword.False;
  7989. }
  7990. }
  7991. isdefined.evalArgs = false;
  7992. var boolean$1 = { isdefined, boolean, "if": If };
  7993. var colorFunctions;
  7994. function clamp(val) {
  7995. return Math.min(1, Math.max(0, val));
  7996. }
  7997. function hsla(origColor, hsl) {
  7998. var color2 = colorFunctions.hsla(hsl.h, hsl.s, hsl.l, hsl.a);
  7999. if (color2) {
  8000. if (origColor.value && /^(rgb|hsl)/.test(origColor.value)) {
  8001. color2.value = origColor.value;
  8002. } else {
  8003. color2.value = "rgb";
  8004. }
  8005. return color2;
  8006. }
  8007. }
  8008. function toHSL(color2) {
  8009. if (color2.toHSL) {
  8010. return color2.toHSL();
  8011. } else {
  8012. throw new Error("Argument cannot be evaluated to a color");
  8013. }
  8014. }
  8015. function toHSV(color2) {
  8016. if (color2.toHSV) {
  8017. return color2.toHSV();
  8018. } else {
  8019. throw new Error("Argument cannot be evaluated to a color");
  8020. }
  8021. }
  8022. function number$1(n) {
  8023. if (n instanceof Dimension) {
  8024. return parseFloat(n.unit.is("%") ? n.value / 100 : n.value);
  8025. } else if (typeof n === "number") {
  8026. return n;
  8027. } else {
  8028. throw {
  8029. type: "Argument",
  8030. message: "color functions take numbers as parameters"
  8031. };
  8032. }
  8033. }
  8034. function scaled(n, size) {
  8035. if (n instanceof Dimension && n.unit.is("%")) {
  8036. return parseFloat(n.value * size / 100);
  8037. } else {
  8038. return number$1(n);
  8039. }
  8040. }
  8041. colorFunctions = {
  8042. rgb: function(r, g, b) {
  8043. var a = 1;
  8044. if (r instanceof Expression) {
  8045. var val = r.value;
  8046. r = val[0];
  8047. g = val[1];
  8048. b = val[2];
  8049. if (b instanceof Operation) {
  8050. var op = b;
  8051. b = op.operands[0];
  8052. a = op.operands[1];
  8053. }
  8054. }
  8055. var color2 = colorFunctions.rgba(r, g, b, a);
  8056. if (color2) {
  8057. color2.value = "rgb";
  8058. return color2;
  8059. }
  8060. },
  8061. rgba: function(r, g, b, a) {
  8062. try {
  8063. if (r instanceof Color) {
  8064. if (g) {
  8065. a = number$1(g);
  8066. } else {
  8067. a = r.alpha;
  8068. }
  8069. return new Color(r.rgb, a, "rgba");
  8070. }
  8071. var rgb = [r, g, b].map(function(c) {
  8072. return scaled(c, 255);
  8073. });
  8074. a = number$1(a);
  8075. return new Color(rgb, a, "rgba");
  8076. } catch (e) {
  8077. }
  8078. },
  8079. hsl: function(h, s, l) {
  8080. var a = 1;
  8081. if (h instanceof Expression) {
  8082. var val = h.value;
  8083. h = val[0];
  8084. s = val[1];
  8085. l = val[2];
  8086. if (l instanceof Operation) {
  8087. var op = l;
  8088. l = op.operands[0];
  8089. a = op.operands[1];
  8090. }
  8091. }
  8092. var color2 = colorFunctions.hsla(h, s, l, a);
  8093. if (color2) {
  8094. color2.value = "hsl";
  8095. return color2;
  8096. }
  8097. },
  8098. hsla: function(h, s, l, a) {
  8099. try {
  8100. let hue = function(h2) {
  8101. h2 = h2 < 0 ? h2 + 1 : h2 > 1 ? h2 - 1 : h2;
  8102. if (h2 * 6 < 1) {
  8103. return m1_1 + (m2_1 - m1_1) * h2 * 6;
  8104. } else if (h2 * 2 < 1) {
  8105. return m2_1;
  8106. } else if (h2 * 3 < 2) {
  8107. return m1_1 + (m2_1 - m1_1) * (2 / 3 - h2) * 6;
  8108. } else {
  8109. return m1_1;
  8110. }
  8111. };
  8112. if (h instanceof Color) {
  8113. if (s) {
  8114. a = number$1(s);
  8115. } else {
  8116. a = h.alpha;
  8117. }
  8118. return new Color(h.rgb, a, "hsla");
  8119. }
  8120. var m1_1;
  8121. var m2_1;
  8122. h = number$1(h) % 360 / 360;
  8123. s = clamp(number$1(s));
  8124. l = clamp(number$1(l));
  8125. a = clamp(number$1(a));
  8126. m2_1 = l <= 0.5 ? l * (s + 1) : l + s - l * s;
  8127. m1_1 = l * 2 - m2_1;
  8128. var rgb = [
  8129. hue(h + 1 / 3) * 255,
  8130. hue(h) * 255,
  8131. hue(h - 1 / 3) * 255
  8132. ];
  8133. a = number$1(a);
  8134. return new Color(rgb, a, "hsla");
  8135. } catch (e) {
  8136. }
  8137. },
  8138. hsv: function(h, s, v) {
  8139. return colorFunctions.hsva(h, s, v, 1);
  8140. },
  8141. hsva: function(h, s, v, a) {
  8142. h = number$1(h) % 360 / 360 * 360;
  8143. s = number$1(s);
  8144. v = number$1(v);
  8145. a = number$1(a);
  8146. var i;
  8147. var f2;
  8148. i = Math.floor(h / 60 % 6);
  8149. f2 = h / 60 - i;
  8150. var vs = [
  8151. v,
  8152. v * (1 - s),
  8153. v * (1 - f2 * s),
  8154. v * (1 - (1 - f2) * s)
  8155. ];
  8156. var perm = [
  8157. [0, 3, 1],
  8158. [2, 0, 1],
  8159. [1, 0, 3],
  8160. [1, 2, 0],
  8161. [3, 1, 0],
  8162. [0, 1, 2]
  8163. ];
  8164. return colorFunctions.rgba(vs[perm[i][0]] * 255, vs[perm[i][1]] * 255, vs[perm[i][2]] * 255, a);
  8165. },
  8166. hue: function(color2) {
  8167. return new Dimension(toHSL(color2).h);
  8168. },
  8169. saturation: function(color2) {
  8170. return new Dimension(toHSL(color2).s * 100, "%");
  8171. },
  8172. lightness: function(color2) {
  8173. return new Dimension(toHSL(color2).l * 100, "%");
  8174. },
  8175. hsvhue: function(color2) {
  8176. return new Dimension(toHSV(color2).h);
  8177. },
  8178. hsvsaturation: function(color2) {
  8179. return new Dimension(toHSV(color2).s * 100, "%");
  8180. },
  8181. hsvvalue: function(color2) {
  8182. return new Dimension(toHSV(color2).v * 100, "%");
  8183. },
  8184. red: function(color2) {
  8185. return new Dimension(color2.rgb[0]);
  8186. },
  8187. green: function(color2) {
  8188. return new Dimension(color2.rgb[1]);
  8189. },
  8190. blue: function(color2) {
  8191. return new Dimension(color2.rgb[2]);
  8192. },
  8193. alpha: function(color2) {
  8194. return new Dimension(toHSL(color2).a);
  8195. },
  8196. luma: function(color2) {
  8197. return new Dimension(color2.luma() * color2.alpha * 100, "%");
  8198. },
  8199. luminance: function(color2) {
  8200. var luminance = 0.2126 * color2.rgb[0] / 255 + 0.7152 * color2.rgb[1] / 255 + 0.0722 * color2.rgb[2] / 255;
  8201. return new Dimension(luminance * color2.alpha * 100, "%");
  8202. },
  8203. saturate: function(color2, amount, method) {
  8204. if (!color2.rgb) {
  8205. return null;
  8206. }
  8207. var hsl = toHSL(color2);
  8208. if (typeof method !== "undefined" && method.value === "relative") {
  8209. hsl.s += hsl.s * amount.value / 100;
  8210. } else {
  8211. hsl.s += amount.value / 100;
  8212. }
  8213. hsl.s = clamp(hsl.s);
  8214. return hsla(color2, hsl);
  8215. },
  8216. desaturate: function(color2, amount, method) {
  8217. var hsl = toHSL(color2);
  8218. if (typeof method !== "undefined" && method.value === "relative") {
  8219. hsl.s -= hsl.s * amount.value / 100;
  8220. } else {
  8221. hsl.s -= amount.value / 100;
  8222. }
  8223. hsl.s = clamp(hsl.s);
  8224. return hsla(color2, hsl);
  8225. },
  8226. lighten: function(color2, amount, method) {
  8227. var hsl = toHSL(color2);
  8228. if (typeof method !== "undefined" && method.value === "relative") {
  8229. hsl.l += hsl.l * amount.value / 100;
  8230. } else {
  8231. hsl.l += amount.value / 100;
  8232. }
  8233. hsl.l = clamp(hsl.l);
  8234. return hsla(color2, hsl);
  8235. },
  8236. darken: function(color2, amount, method) {
  8237. var hsl = toHSL(color2);
  8238. if (typeof method !== "undefined" && method.value === "relative") {
  8239. hsl.l -= hsl.l * amount.value / 100;
  8240. } else {
  8241. hsl.l -= amount.value / 100;
  8242. }
  8243. hsl.l = clamp(hsl.l);
  8244. return hsla(color2, hsl);
  8245. },
  8246. fadein: function(color2, amount, method) {
  8247. var hsl = toHSL(color2);
  8248. if (typeof method !== "undefined" && method.value === "relative") {
  8249. hsl.a += hsl.a * amount.value / 100;
  8250. } else {
  8251. hsl.a += amount.value / 100;
  8252. }
  8253. hsl.a = clamp(hsl.a);
  8254. return hsla(color2, hsl);
  8255. },
  8256. fadeout: function(color2, amount, method) {
  8257. var hsl = toHSL(color2);
  8258. if (typeof method !== "undefined" && method.value === "relative") {
  8259. hsl.a -= hsl.a * amount.value / 100;
  8260. } else {
  8261. hsl.a -= amount.value / 100;
  8262. }
  8263. hsl.a = clamp(hsl.a);
  8264. return hsla(color2, hsl);
  8265. },
  8266. fade: function(color2, amount) {
  8267. var hsl = toHSL(color2);
  8268. hsl.a = amount.value / 100;
  8269. hsl.a = clamp(hsl.a);
  8270. return hsla(color2, hsl);
  8271. },
  8272. spin: function(color2, amount) {
  8273. var hsl = toHSL(color2);
  8274. var hue = (hsl.h + amount.value) % 360;
  8275. hsl.h = hue < 0 ? 360 + hue : hue;
  8276. return hsla(color2, hsl);
  8277. },
  8278. //
  8279. // Copyright (c) 2006-2009 Hampton Catlin, Natalie Weizenbaum, and Chris Eppstein
  8280. // http://sass-lang.com
  8281. //
  8282. mix: function(color1, color2, weight) {
  8283. if (!weight) {
  8284. weight = new Dimension(50);
  8285. }
  8286. var p = weight.value / 100;
  8287. var w = p * 2 - 1;
  8288. var a = toHSL(color1).a - toHSL(color2).a;
  8289. var w1 = ((w * a == -1 ? w : (w + a) / (1 + w * a)) + 1) / 2;
  8290. var w2 = 1 - w1;
  8291. var rgb = [
  8292. color1.rgb[0] * w1 + color2.rgb[0] * w2,
  8293. color1.rgb[1] * w1 + color2.rgb[1] * w2,
  8294. color1.rgb[2] * w1 + color2.rgb[2] * w2
  8295. ];
  8296. var alpha = color1.alpha * p + color2.alpha * (1 - p);
  8297. return new Color(rgb, alpha);
  8298. },
  8299. greyscale: function(color2) {
  8300. return colorFunctions.desaturate(color2, new Dimension(100));
  8301. },
  8302. contrast: function(color2, dark, light, threshold) {
  8303. if (!color2.rgb) {
  8304. return null;
  8305. }
  8306. if (typeof light === "undefined") {
  8307. light = colorFunctions.rgba(255, 255, 255, 1);
  8308. }
  8309. if (typeof dark === "undefined") {
  8310. dark = colorFunctions.rgba(0, 0, 0, 1);
  8311. }
  8312. if (dark.luma() > light.luma()) {
  8313. var t = light;
  8314. light = dark;
  8315. dark = t;
  8316. }
  8317. if (typeof threshold === "undefined") {
  8318. threshold = 0.43;
  8319. } else {
  8320. threshold = number$1(threshold);
  8321. }
  8322. if (color2.luma() < threshold) {
  8323. return light;
  8324. } else {
  8325. return dark;
  8326. }
  8327. },
  8328. // Changes made in 2.7.0 - Reverted in 3.0.0
  8329. // contrast: function (color, color1, color2, threshold) {
  8330. // // Return which of `color1` and `color2` has the greatest contrast with `color`
  8331. // // according to the standard WCAG contrast ratio calculation.
  8332. // // http://www.w3.org/TR/WCAG20/#contrast-ratiodef
  8333. // // The threshold param is no longer used, in line with SASS.
  8334. // // filter: contrast(3.2);
  8335. // // should be kept as is, so check for color
  8336. // if (!color.rgb) {
  8337. // return null;
  8338. // }
  8339. // if (typeof color1 === 'undefined') {
  8340. // color1 = colorFunctions.rgba(0, 0, 0, 1.0);
  8341. // }
  8342. // if (typeof color2 === 'undefined') {
  8343. // color2 = colorFunctions.rgba(255, 255, 255, 1.0);
  8344. // }
  8345. // var contrast1, contrast2;
  8346. // var luma = color.luma();
  8347. // var luma1 = color1.luma();
  8348. // var luma2 = color2.luma();
  8349. // // Calculate contrast ratios for each color
  8350. // if (luma > luma1) {
  8351. // contrast1 = (luma + 0.05) / (luma1 + 0.05);
  8352. // } else {
  8353. // contrast1 = (luma1 + 0.05) / (luma + 0.05);
  8354. // }
  8355. // if (luma > luma2) {
  8356. // contrast2 = (luma + 0.05) / (luma2 + 0.05);
  8357. // } else {
  8358. // contrast2 = (luma2 + 0.05) / (luma + 0.05);
  8359. // }
  8360. // if (contrast1 > contrast2) {
  8361. // return color1;
  8362. // } else {
  8363. // return color2;
  8364. // }
  8365. // },
  8366. argb: function(color2) {
  8367. return new Anonymous(color2.toARGB());
  8368. },
  8369. color: function(c) {
  8370. if (c instanceof Quoted && /^#([A-Fa-f0-9]{8}|[A-Fa-f0-9]{6}|[A-Fa-f0-9]{3,4})$/i.test(c.value)) {
  8371. var val = c.value.slice(1);
  8372. return new Color(val, void 0, "#" + val);
  8373. }
  8374. if (c instanceof Color || (c = Color.fromKeyword(c.value))) {
  8375. c.value = void 0;
  8376. return c;
  8377. }
  8378. throw {
  8379. type: "Argument",
  8380. message: "argument must be a color keyword or 3|4|6|8 digit hex e.g. #FFF"
  8381. };
  8382. },
  8383. tint: function(color2, amount) {
  8384. return colorFunctions.mix(colorFunctions.rgb(255, 255, 255), color2, amount);
  8385. },
  8386. shade: function(color2, amount) {
  8387. return colorFunctions.mix(colorFunctions.rgb(0, 0, 0), color2, amount);
  8388. }
  8389. };
  8390. var color = colorFunctions;
  8391. function colorBlend(mode, color1, color2) {
  8392. var ab = color1.alpha;
  8393. var cb;
  8394. var as = color2.alpha;
  8395. var cs;
  8396. var ar;
  8397. var cr;
  8398. var r = [];
  8399. ar = as + ab * (1 - as);
  8400. for (var i = 0; i < 3; i++) {
  8401. cb = color1.rgb[i] / 255;
  8402. cs = color2.rgb[i] / 255;
  8403. cr = mode(cb, cs);
  8404. if (ar) {
  8405. cr = (as * cs + ab * (cb - as * (cb + cs - cr))) / ar;
  8406. }
  8407. r[i] = cr * 255;
  8408. }
  8409. return new Color(r, ar);
  8410. }
  8411. var colorBlendModeFunctions = {
  8412. multiply: function(cb, cs) {
  8413. return cb * cs;
  8414. },
  8415. screen: function(cb, cs) {
  8416. return cb + cs - cb * cs;
  8417. },
  8418. overlay: function(cb, cs) {
  8419. cb *= 2;
  8420. return cb <= 1 ? colorBlendModeFunctions.multiply(cb, cs) : colorBlendModeFunctions.screen(cb - 1, cs);
  8421. },
  8422. softlight: function(cb, cs) {
  8423. var d = 1;
  8424. var e = cb;
  8425. if (cs > 0.5) {
  8426. e = 1;
  8427. d = cb > 0.25 ? Math.sqrt(cb) : ((16 * cb - 12) * cb + 4) * cb;
  8428. }
  8429. return cb - (1 - 2 * cs) * e * (d - cb);
  8430. },
  8431. hardlight: function(cb, cs) {
  8432. return colorBlendModeFunctions.overlay(cs, cb);
  8433. },
  8434. difference: function(cb, cs) {
  8435. return Math.abs(cb - cs);
  8436. },
  8437. exclusion: function(cb, cs) {
  8438. return cb + cs - 2 * cb * cs;
  8439. },
  8440. // non-w3c functions:
  8441. average: function(cb, cs) {
  8442. return (cb + cs) / 2;
  8443. },
  8444. negation: function(cb, cs) {
  8445. return 1 - Math.abs(cb + cs - 1);
  8446. }
  8447. };
  8448. for (var f$1 in colorBlendModeFunctions) {
  8449. if (colorBlendModeFunctions.hasOwnProperty(f$1)) {
  8450. colorBlend[f$1] = colorBlend.bind(null, colorBlendModeFunctions[f$1]);
  8451. }
  8452. }
  8453. var dataUri = function(environment) {
  8454. var fallback = function(functionThis, node) {
  8455. return new URL(node, functionThis.index, functionThis.currentFileInfo).eval(functionThis.context);
  8456. };
  8457. return { "data-uri": function(mimetypeNode, filePathNode) {
  8458. if (!filePathNode) {
  8459. filePathNode = mimetypeNode;
  8460. mimetypeNode = null;
  8461. }
  8462. var mimetype = mimetypeNode && mimetypeNode.value;
  8463. var filePath = filePathNode.value;
  8464. var currentFileInfo = this.currentFileInfo;
  8465. var currentDirectory = currentFileInfo.rewriteUrls ? currentFileInfo.currentDirectory : currentFileInfo.entryPath;
  8466. var fragmentStart = filePath.indexOf("#");
  8467. var fragment = "";
  8468. if (fragmentStart !== -1) {
  8469. fragment = filePath.slice(fragmentStart);
  8470. filePath = filePath.slice(0, fragmentStart);
  8471. }
  8472. var context = clone(this.context);
  8473. context.rawBuffer = true;
  8474. var fileManager = environment.getFileManager(filePath, currentDirectory, context, environment, true);
  8475. if (!fileManager) {
  8476. return fallback(this, filePathNode);
  8477. }
  8478. var useBase64 = false;
  8479. if (!mimetypeNode) {
  8480. mimetype = environment.mimeLookup(filePath);
  8481. if (mimetype === "image/svg+xml") {
  8482. useBase64 = false;
  8483. } else {
  8484. var charset = environment.charsetLookup(mimetype);
  8485. useBase64 = ["US-ASCII", "UTF-8"].indexOf(charset) < 0;
  8486. }
  8487. if (useBase64) {
  8488. mimetype += ";base64";
  8489. }
  8490. } else {
  8491. useBase64 = /;base64$/.test(mimetype);
  8492. }
  8493. var fileSync = fileManager.loadFileSync(filePath, currentDirectory, context, environment);
  8494. if (!fileSync.contents) {
  8495. logger$1.warn("Skipped data-uri embedding of " + filePath + " because file not found");
  8496. return fallback(this, filePathNode || mimetypeNode);
  8497. }
  8498. var buf = fileSync.contents;
  8499. if (useBase64 && !environment.encodeBase64) {
  8500. return fallback(this, filePathNode);
  8501. }
  8502. buf = useBase64 ? environment.encodeBase64(buf) : encodeURIComponent(buf);
  8503. var uri = "data:" + mimetype + "," + buf + fragment;
  8504. return new URL(new Quoted('"' + uri + '"', uri, false, this.index, this.currentFileInfo), this.index, this.currentFileInfo);
  8505. } };
  8506. };
  8507. var getItemsFromNode = function(node) {
  8508. var items = Array.isArray(node.value) ? node.value : Array(node);
  8509. return items;
  8510. };
  8511. var list = {
  8512. _SELF: function(n) {
  8513. return n;
  8514. },
  8515. "~": function() {
  8516. var expr = [];
  8517. for (var _i = 0; _i < arguments.length; _i++) {
  8518. expr[_i] = arguments[_i];
  8519. }
  8520. if (expr.length === 1) {
  8521. return expr[0];
  8522. }
  8523. return new Value(expr);
  8524. },
  8525. extract: function(values, index) {
  8526. index = index.value - 1;
  8527. return getItemsFromNode(values)[index];
  8528. },
  8529. length: function(values) {
  8530. return new Dimension(getItemsFromNode(values).length);
  8531. },
  8532. /**
  8533. * Creates a Less list of incremental values.
  8534. * Modeled after Lodash's range function, also exists natively in PHP
  8535. *
  8536. * @param {Dimension} [start=1]
  8537. * @param {Dimension} end - e.g. 10 or 10px - unit is added to output
  8538. * @param {Dimension} [step=1]
  8539. */
  8540. range: function(start, end, step) {
  8541. var from;
  8542. var to;
  8543. var stepValue = 1;
  8544. var list2 = [];
  8545. if (end) {
  8546. to = end;
  8547. from = start.value;
  8548. if (step) {
  8549. stepValue = step.value;
  8550. }
  8551. } else {
  8552. from = 1;
  8553. to = start;
  8554. }
  8555. for (var i = from; i <= to.value; i += stepValue) {
  8556. list2.push(new Dimension(i, to.unit));
  8557. }
  8558. return new Expression(list2);
  8559. },
  8560. each: function(list2, rs) {
  8561. var _this = this;
  8562. var rules = [];
  8563. var newRules;
  8564. var iterator;
  8565. var tryEval = function(val) {
  8566. if (val instanceof Node) {
  8567. return val.eval(_this.context);
  8568. }
  8569. return val;
  8570. };
  8571. if (list2.value && !(list2 instanceof Quoted)) {
  8572. if (Array.isArray(list2.value)) {
  8573. iterator = list2.value.map(tryEval);
  8574. } else {
  8575. iterator = [tryEval(list2.value)];
  8576. }
  8577. } else if (list2.ruleset) {
  8578. iterator = tryEval(list2.ruleset).rules;
  8579. } else if (list2.rules) {
  8580. iterator = list2.rules.map(tryEval);
  8581. } else if (Array.isArray(list2)) {
  8582. iterator = list2.map(tryEval);
  8583. } else {
  8584. iterator = [tryEval(list2)];
  8585. }
  8586. var valueName = "@value";
  8587. var keyName = "@key";
  8588. var indexName = "@index";
  8589. if (rs.params) {
  8590. valueName = rs.params[0] && rs.params[0].name;
  8591. keyName = rs.params[1] && rs.params[1].name;
  8592. indexName = rs.params[2] && rs.params[2].name;
  8593. rs = rs.rules;
  8594. } else {
  8595. rs = rs.ruleset;
  8596. }
  8597. for (var i = 0; i < iterator.length; i++) {
  8598. var key2 = void 0;
  8599. var value = void 0;
  8600. var item = iterator[i];
  8601. if (item instanceof Declaration) {
  8602. key2 = typeof item.name === "string" ? item.name : item.name[0].value;
  8603. value = item.value;
  8604. } else {
  8605. key2 = new Dimension(i + 1);
  8606. value = item;
  8607. }
  8608. if (item instanceof Comment) {
  8609. continue;
  8610. }
  8611. newRules = rs.rules.slice(0);
  8612. if (valueName) {
  8613. newRules.push(new Declaration(valueName, value, false, false, this.index, this.currentFileInfo));
  8614. }
  8615. if (indexName) {
  8616. newRules.push(new Declaration(indexName, new Dimension(i + 1), false, false, this.index, this.currentFileInfo));
  8617. }
  8618. if (keyName) {
  8619. newRules.push(new Declaration(keyName, key2, false, false, this.index, this.currentFileInfo));
  8620. }
  8621. rules.push(new Ruleset([new Selector([new Element("", "&")])], newRules, rs.strictImports, rs.visibilityInfo()));
  8622. }
  8623. return new Ruleset([new Selector([new Element("", "&")])], rules, rs.strictImports, rs.visibilityInfo()).eval(this.context);
  8624. }
  8625. };
  8626. var MathHelper = function(fn, unit, n) {
  8627. if (!(n instanceof Dimension)) {
  8628. throw { type: "Argument", message: "argument must be a number" };
  8629. }
  8630. if (unit == null) {
  8631. unit = n.unit;
  8632. } else {
  8633. n = n.unify();
  8634. }
  8635. return new Dimension(fn(parseFloat(n.value)), unit);
  8636. };
  8637. var mathFunctions = {
  8638. // name, unit
  8639. ceil: null,
  8640. floor: null,
  8641. sqrt: null,
  8642. abs: null,
  8643. tan: "",
  8644. sin: "",
  8645. cos: "",
  8646. atan: "rad",
  8647. asin: "rad",
  8648. acos: "rad"
  8649. };
  8650. for (var f in mathFunctions) {
  8651. if (mathFunctions.hasOwnProperty(f)) {
  8652. mathFunctions[f] = MathHelper.bind(null, Math[f], mathFunctions[f]);
  8653. }
  8654. }
  8655. mathFunctions.round = function(n, f2) {
  8656. var fraction = typeof f2 === "undefined" ? 0 : f2.value;
  8657. return MathHelper(function(num) {
  8658. return num.toFixed(fraction);
  8659. }, null, n);
  8660. };
  8661. var minMax = function(isMin, args) {
  8662. args = Array.prototype.slice.call(args);
  8663. switch (args.length) {
  8664. case 0:
  8665. throw { type: "Argument", message: "one or more arguments required" };
  8666. }
  8667. var i;
  8668. var j;
  8669. var current;
  8670. var currentUnified;
  8671. var referenceUnified;
  8672. var unit;
  8673. var unitStatic;
  8674. var unitClone;
  8675. var order = [];
  8676. var values = {};
  8677. for (i = 0; i < args.length; i++) {
  8678. current = args[i];
  8679. if (!(current instanceof Dimension)) {
  8680. if (Array.isArray(args[i].value)) {
  8681. Array.prototype.push.apply(args, Array.prototype.slice.call(args[i].value));
  8682. }
  8683. continue;
  8684. }
  8685. currentUnified = current.unit.toString() === "" && unitClone !== void 0 ? new Dimension(current.value, unitClone).unify() : current.unify();
  8686. unit = currentUnified.unit.toString() === "" && unitStatic !== void 0 ? unitStatic : currentUnified.unit.toString();
  8687. unitStatic = unit !== "" && unitStatic === void 0 || unit !== "" && order[0].unify().unit.toString() === "" ? unit : unitStatic;
  8688. unitClone = unit !== "" && unitClone === void 0 ? current.unit.toString() : unitClone;
  8689. j = values[""] !== void 0 && unit !== "" && unit === unitStatic ? values[""] : values[unit];
  8690. if (j === void 0) {
  8691. if (unitStatic !== void 0 && unit !== unitStatic) {
  8692. throw { type: "Argument", message: "incompatible types" };
  8693. }
  8694. values[unit] = order.length;
  8695. order.push(current);
  8696. continue;
  8697. }
  8698. referenceUnified = order[j].unit.toString() === "" && unitClone !== void 0 ? new Dimension(order[j].value, unitClone).unify() : order[j].unify();
  8699. if (isMin && currentUnified.value < referenceUnified.value || !isMin && currentUnified.value > referenceUnified.value) {
  8700. order[j] = current;
  8701. }
  8702. }
  8703. if (order.length == 1) {
  8704. return order[0];
  8705. }
  8706. args = order.map(function(a) {
  8707. return a.toCSS(this.context);
  8708. }).join(this.context.compress ? "," : ", ");
  8709. return new Anonymous((isMin ? "min" : "max") + "(" + args + ")");
  8710. };
  8711. var number = {
  8712. min: function() {
  8713. var args = [];
  8714. for (var _i = 0; _i < arguments.length; _i++) {
  8715. args[_i] = arguments[_i];
  8716. }
  8717. try {
  8718. return minMax(true, args);
  8719. } catch (e) {
  8720. }
  8721. },
  8722. max: function() {
  8723. var args = [];
  8724. for (var _i = 0; _i < arguments.length; _i++) {
  8725. args[_i] = arguments[_i];
  8726. }
  8727. try {
  8728. return minMax(false, args);
  8729. } catch (e) {
  8730. }
  8731. },
  8732. convert: function(val, unit) {
  8733. return val.convertTo(unit.value);
  8734. },
  8735. pi: function() {
  8736. return new Dimension(Math.PI);
  8737. },
  8738. mod: function(a, b) {
  8739. return new Dimension(a.value % b.value, a.unit);
  8740. },
  8741. pow: function(x, y) {
  8742. if (typeof x === "number" && typeof y === "number") {
  8743. x = new Dimension(x);
  8744. y = new Dimension(y);
  8745. } else if (!(x instanceof Dimension) || !(y instanceof Dimension)) {
  8746. throw { type: "Argument", message: "arguments must be numbers" };
  8747. }
  8748. return new Dimension(Math.pow(x.value, y.value), x.unit);
  8749. },
  8750. percentage: function(n) {
  8751. var result = MathHelper(function(num) {
  8752. return num * 100;
  8753. }, "%", n);
  8754. return result;
  8755. }
  8756. };
  8757. var string = {
  8758. e: function(str) {
  8759. return new Quoted('"', str instanceof JavaScript ? str.evaluated : str.value, true);
  8760. },
  8761. escape: function(str) {
  8762. return new Anonymous(encodeURI(str.value).replace(/=/g, "%3D").replace(/:/g, "%3A").replace(/#/g, "%23").replace(/;/g, "%3B").replace(/\(/g, "%28").replace(/\)/g, "%29"));
  8763. },
  8764. replace: function(string2, pattern, replacement, flags) {
  8765. var result = string2.value;
  8766. replacement = replacement.type === "Quoted" ? replacement.value : replacement.toCSS();
  8767. result = result.replace(new RegExp(pattern.value, flags ? flags.value : ""), replacement);
  8768. return new Quoted(string2.quote || "", result, string2.escaped);
  8769. },
  8770. "%": function(string2) {
  8771. var args = Array.prototype.slice.call(arguments, 1);
  8772. var result = string2.value;
  8773. var _loop_1 = function(i2) {
  8774. result = result.replace(/%[sda]/i, function(token) {
  8775. var value = args[i2].type === "Quoted" && token.match(/s/i) ? args[i2].value : args[i2].toCSS();
  8776. return token.match(/[A-Z]$/) ? encodeURIComponent(value) : value;
  8777. });
  8778. };
  8779. for (var i = 0; i < args.length; i++) {
  8780. _loop_1(i);
  8781. }
  8782. result = result.replace(/%%/g, "%");
  8783. return new Quoted(string2.quote || "", result, string2.escaped);
  8784. }
  8785. };
  8786. var svg = function(environment) {
  8787. return { "svg-gradient": function(direction) {
  8788. var stops;
  8789. var gradientDirectionSvg;
  8790. var gradientType = "linear";
  8791. var rectangleDimension = 'x="0" y="0" width="1" height="1"';
  8792. var renderEnv = { compress: false };
  8793. var returner;
  8794. var directionValue = direction.toCSS(renderEnv);
  8795. var i;
  8796. var color2;
  8797. var position;
  8798. var positionValue;
  8799. var alpha;
  8800. function throwArgumentDescriptor() {
  8801. throw {
  8802. type: "Argument",
  8803. message: "svg-gradient expects direction, start_color [start_position], [color position,]..., end_color [end_position] or direction, color list"
  8804. };
  8805. }
  8806. if (arguments.length == 2) {
  8807. if (arguments[1].value.length < 2) {
  8808. throwArgumentDescriptor();
  8809. }
  8810. stops = arguments[1].value;
  8811. } else if (arguments.length < 3) {
  8812. throwArgumentDescriptor();
  8813. } else {
  8814. stops = Array.prototype.slice.call(arguments, 1);
  8815. }
  8816. switch (directionValue) {
  8817. case "to bottom":
  8818. gradientDirectionSvg = 'x1="0%" y1="0%" x2="0%" y2="100%"';
  8819. break;
  8820. case "to right":
  8821. gradientDirectionSvg = 'x1="0%" y1="0%" x2="100%" y2="0%"';
  8822. break;
  8823. case "to bottom right":
  8824. gradientDirectionSvg = 'x1="0%" y1="0%" x2="100%" y2="100%"';
  8825. break;
  8826. case "to top right":
  8827. gradientDirectionSvg = 'x1="0%" y1="100%" x2="100%" y2="0%"';
  8828. break;
  8829. case "ellipse":
  8830. case "ellipse at center":
  8831. gradientType = "radial";
  8832. gradientDirectionSvg = 'cx="50%" cy="50%" r="75%"';
  8833. rectangleDimension = 'x="-50" y="-50" width="101" height="101"';
  8834. break;
  8835. default:
  8836. throw { type: "Argument", message: "svg-gradient direction must be 'to bottom', 'to right', 'to bottom right', 'to top right' or 'ellipse at center'" };
  8837. }
  8838. returner = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1 1"><' + gradientType + 'Gradient id="g" ' + gradientDirectionSvg + ">";
  8839. for (i = 0; i < stops.length; i += 1) {
  8840. if (stops[i] instanceof Expression) {
  8841. color2 = stops[i].value[0];
  8842. position = stops[i].value[1];
  8843. } else {
  8844. color2 = stops[i];
  8845. position = void 0;
  8846. }
  8847. if (!(color2 instanceof Color) || !((i === 0 || i + 1 === stops.length) && position === void 0) && !(position instanceof Dimension)) {
  8848. throwArgumentDescriptor();
  8849. }
  8850. positionValue = position ? position.toCSS(renderEnv) : i === 0 ? "0%" : "100%";
  8851. alpha = color2.alpha;
  8852. returner += '<stop offset="' + positionValue + '" stop-color="' + color2.toRGB() + '"' + (alpha < 1 ? ' stop-opacity="' + alpha + '"' : "") + "/>";
  8853. }
  8854. returner += "</" + gradientType + "Gradient><rect " + rectangleDimension + ' fill="url(#g)" /></svg>';
  8855. returner = encodeURIComponent(returner);
  8856. returner = "data:image/svg+xml," + returner;
  8857. return new URL(new Quoted("'" + returner + "'", returner, false, this.index, this.currentFileInfo), this.index, this.currentFileInfo);
  8858. } };
  8859. };
  8860. var isa = function(n, Type) {
  8861. return n instanceof Type ? Keyword.True : Keyword.False;
  8862. };
  8863. var isunit = function(n, unit) {
  8864. if (unit === void 0) {
  8865. throw { type: "Argument", message: "missing the required second argument to isunit." };
  8866. }
  8867. unit = typeof unit.value === "string" ? unit.value : unit;
  8868. if (typeof unit !== "string") {
  8869. throw { type: "Argument", message: "Second argument to isunit should be a unit or a string." };
  8870. }
  8871. return n instanceof Dimension && n.unit.is(unit) ? Keyword.True : Keyword.False;
  8872. };
  8873. var types = {
  8874. isruleset: function(n) {
  8875. return isa(n, DetachedRuleset);
  8876. },
  8877. iscolor: function(n) {
  8878. return isa(n, Color);
  8879. },
  8880. isnumber: function(n) {
  8881. return isa(n, Dimension);
  8882. },
  8883. isstring: function(n) {
  8884. return isa(n, Quoted);
  8885. },
  8886. iskeyword: function(n) {
  8887. return isa(n, Keyword);
  8888. },
  8889. isurl: function(n) {
  8890. return isa(n, URL);
  8891. },
  8892. ispixel: function(n) {
  8893. return isunit(n, "px");
  8894. },
  8895. ispercentage: function(n) {
  8896. return isunit(n, "%");
  8897. },
  8898. isem: function(n) {
  8899. return isunit(n, "em");
  8900. },
  8901. isunit,
  8902. unit: function(val, unit) {
  8903. if (!(val instanceof Dimension)) {
  8904. throw {
  8905. type: "Argument",
  8906. message: "the first argument to unit must be a number" + (val instanceof Operation ? ". Have you forgotten parenthesis?" : "")
  8907. };
  8908. }
  8909. if (unit) {
  8910. if (unit instanceof Keyword) {
  8911. unit = unit.value;
  8912. } else {
  8913. unit = unit.toCSS();
  8914. }
  8915. } else {
  8916. unit = "";
  8917. }
  8918. return new Dimension(val.value, unit);
  8919. },
  8920. "get-unit": function(n) {
  8921. return new Anonymous(n.unit);
  8922. }
  8923. };
  8924. var functions = function(environment) {
  8925. var functions2 = { functionRegistry, functionCaller };
  8926. functionRegistry.addMultiple(boolean$1);
  8927. functionRegistry.add("default", defaultFunc.eval.bind(defaultFunc));
  8928. functionRegistry.addMultiple(color);
  8929. functionRegistry.addMultiple(colorBlend);
  8930. functionRegistry.addMultiple(dataUri(environment));
  8931. functionRegistry.addMultiple(list);
  8932. functionRegistry.addMultiple(mathFunctions);
  8933. functionRegistry.addMultiple(number);
  8934. functionRegistry.addMultiple(string);
  8935. functionRegistry.addMultiple(svg());
  8936. functionRegistry.addMultiple(types);
  8937. return functions2;
  8938. };
  8939. function transformTree(root2, options2) {
  8940. options2 = options2 || {};
  8941. var evaldRoot;
  8942. var variables = options2.variables;
  8943. var evalEnv = new contexts.Eval(options2);
  8944. if (typeof variables === "object" && !Array.isArray(variables)) {
  8945. variables = Object.keys(variables).map(function(k) {
  8946. var value = variables[k];
  8947. if (!(value instanceof tree.Value)) {
  8948. if (!(value instanceof tree.Expression)) {
  8949. value = new tree.Expression([value]);
  8950. }
  8951. value = new tree.Value([value]);
  8952. }
  8953. return new tree.Declaration("@" + k, value, false, null, 0);
  8954. });
  8955. evalEnv.frames = [new tree.Ruleset(null, variables)];
  8956. }
  8957. var visitors$1 = [
  8958. new visitors.JoinSelectorVisitor(),
  8959. new visitors.MarkVisibleSelectorsVisitor(true),
  8960. new visitors.ExtendVisitor(),
  8961. new visitors.ToCSSVisitor({ compress: Boolean(options2.compress) })
  8962. ];
  8963. var preEvalVisitors = [];
  8964. var v;
  8965. var visitorIterator;
  8966. if (options2.pluginManager) {
  8967. visitorIterator = options2.pluginManager.visitor();
  8968. for (var i = 0; i < 2; i++) {
  8969. visitorIterator.first();
  8970. while (v = visitorIterator.get()) {
  8971. if (v.isPreEvalVisitor) {
  8972. if (i === 0 || preEvalVisitors.indexOf(v) === -1) {
  8973. preEvalVisitors.push(v);
  8974. v.run(root2);
  8975. }
  8976. } else {
  8977. if (i === 0 || visitors$1.indexOf(v) === -1) {
  8978. if (v.isPreVisitor) {
  8979. visitors$1.unshift(v);
  8980. } else {
  8981. visitors$1.push(v);
  8982. }
  8983. }
  8984. }
  8985. }
  8986. }
  8987. }
  8988. evaldRoot = root2.eval(evalEnv);
  8989. for (var i = 0; i < visitors$1.length; i++) {
  8990. visitors$1[i].run(evaldRoot);
  8991. }
  8992. if (options2.pluginManager) {
  8993. visitorIterator.first();
  8994. while (v = visitorIterator.get()) {
  8995. if (visitors$1.indexOf(v) === -1 && preEvalVisitors.indexOf(v) === -1) {
  8996. v.run(evaldRoot);
  8997. }
  8998. }
  8999. }
  9000. return evaldRoot;
  9001. }
  9002. var PluginManager = (
  9003. /** @class */
  9004. function() {
  9005. function PluginManager2(less2) {
  9006. this.less = less2;
  9007. this.visitors = [];
  9008. this.preProcessors = [];
  9009. this.postProcessors = [];
  9010. this.installedPlugins = [];
  9011. this.fileManagers = [];
  9012. this.iterator = -1;
  9013. this.pluginCache = {};
  9014. this.Loader = new less2.PluginLoader(less2);
  9015. }
  9016. PluginManager2.prototype.addPlugins = function(plugins) {
  9017. if (plugins) {
  9018. for (var i = 0; i < plugins.length; i++) {
  9019. this.addPlugin(plugins[i]);
  9020. }
  9021. }
  9022. };
  9023. PluginManager2.prototype.addPlugin = function(plugin, filename, functionRegistry2) {
  9024. this.installedPlugins.push(plugin);
  9025. if (filename) {
  9026. this.pluginCache[filename] = plugin;
  9027. }
  9028. if (plugin.install) {
  9029. plugin.install(this.less, this, functionRegistry2 || this.less.functions.functionRegistry);
  9030. }
  9031. };
  9032. PluginManager2.prototype.get = function(filename) {
  9033. return this.pluginCache[filename];
  9034. };
  9035. PluginManager2.prototype.addVisitor = function(visitor) {
  9036. this.visitors.push(visitor);
  9037. };
  9038. PluginManager2.prototype.addPreProcessor = function(preProcessor, priority) {
  9039. var indexToInsertAt;
  9040. for (indexToInsertAt = 0; indexToInsertAt < this.preProcessors.length; indexToInsertAt++) {
  9041. if (this.preProcessors[indexToInsertAt].priority >= priority) {
  9042. break;
  9043. }
  9044. }
  9045. this.preProcessors.splice(indexToInsertAt, 0, { preProcessor, priority });
  9046. };
  9047. PluginManager2.prototype.addPostProcessor = function(postProcessor, priority) {
  9048. var indexToInsertAt;
  9049. for (indexToInsertAt = 0; indexToInsertAt < this.postProcessors.length; indexToInsertAt++) {
  9050. if (this.postProcessors[indexToInsertAt].priority >= priority) {
  9051. break;
  9052. }
  9053. }
  9054. this.postProcessors.splice(indexToInsertAt, 0, { postProcessor, priority });
  9055. };
  9056. PluginManager2.prototype.addFileManager = function(manager) {
  9057. this.fileManagers.push(manager);
  9058. };
  9059. PluginManager2.prototype.getPreProcessors = function() {
  9060. var preProcessors = [];
  9061. for (var i = 0; i < this.preProcessors.length; i++) {
  9062. preProcessors.push(this.preProcessors[i].preProcessor);
  9063. }
  9064. return preProcessors;
  9065. };
  9066. PluginManager2.prototype.getPostProcessors = function() {
  9067. var postProcessors = [];
  9068. for (var i = 0; i < this.postProcessors.length; i++) {
  9069. postProcessors.push(this.postProcessors[i].postProcessor);
  9070. }
  9071. return postProcessors;
  9072. };
  9073. PluginManager2.prototype.getVisitors = function() {
  9074. return this.visitors;
  9075. };
  9076. PluginManager2.prototype.visitor = function() {
  9077. var self2 = this;
  9078. return {
  9079. first: function() {
  9080. self2.iterator = -1;
  9081. return self2.visitors[self2.iterator];
  9082. },
  9083. get: function() {
  9084. self2.iterator += 1;
  9085. return self2.visitors[self2.iterator];
  9086. }
  9087. };
  9088. };
  9089. PluginManager2.prototype.getFileManagers = function() {
  9090. return this.fileManagers;
  9091. };
  9092. return PluginManager2;
  9093. }()
  9094. );
  9095. var pm;
  9096. var PluginManagerFactory = function(less2, newFactory) {
  9097. if (newFactory || !pm) {
  9098. pm = new PluginManager(less2);
  9099. }
  9100. return pm;
  9101. };
  9102. function SourceMapOutput(environment) {
  9103. var SourceMapOutput2 = (
  9104. /** @class */
  9105. function() {
  9106. function SourceMapOutput3(options2) {
  9107. this._css = [];
  9108. this._rootNode = options2.rootNode;
  9109. this._contentsMap = options2.contentsMap;
  9110. this._contentsIgnoredCharsMap = options2.contentsIgnoredCharsMap;
  9111. if (options2.sourceMapFilename) {
  9112. this._sourceMapFilename = options2.sourceMapFilename.replace(/\\/g, "/");
  9113. }
  9114. this._outputFilename = options2.outputFilename;
  9115. this.sourceMapURL = options2.sourceMapURL;
  9116. if (options2.sourceMapBasepath) {
  9117. this._sourceMapBasepath = options2.sourceMapBasepath.replace(/\\/g, "/");
  9118. }
  9119. if (options2.sourceMapRootpath) {
  9120. this._sourceMapRootpath = options2.sourceMapRootpath.replace(/\\/g, "/");
  9121. if (this._sourceMapRootpath.charAt(this._sourceMapRootpath.length - 1) !== "/") {
  9122. this._sourceMapRootpath += "/";
  9123. }
  9124. } else {
  9125. this._sourceMapRootpath = "";
  9126. }
  9127. this._outputSourceFiles = options2.outputSourceFiles;
  9128. this._sourceMapGeneratorConstructor = environment.getSourceMapGenerator();
  9129. this._lineNumber = 0;
  9130. this._column = 0;
  9131. }
  9132. SourceMapOutput3.prototype.removeBasepath = function(path) {
  9133. if (this._sourceMapBasepath && path.indexOf(this._sourceMapBasepath) === 0) {
  9134. path = path.substring(this._sourceMapBasepath.length);
  9135. if (path.charAt(0) === "\\" || path.charAt(0) === "/") {
  9136. path = path.substring(1);
  9137. }
  9138. }
  9139. return path;
  9140. };
  9141. SourceMapOutput3.prototype.normalizeFilename = function(filename) {
  9142. filename = filename.replace(/\\/g, "/");
  9143. filename = this.removeBasepath(filename);
  9144. return (this._sourceMapRootpath || "") + filename;
  9145. };
  9146. SourceMapOutput3.prototype.add = function(chunk, fileInfo, index, mapLines) {
  9147. if (!chunk) {
  9148. return;
  9149. }
  9150. var lines, sourceLines, columns, sourceColumns, i;
  9151. if (fileInfo && fileInfo.filename) {
  9152. var inputSource = this._contentsMap[fileInfo.filename];
  9153. if (this._contentsIgnoredCharsMap[fileInfo.filename]) {
  9154. index -= this._contentsIgnoredCharsMap[fileInfo.filename];
  9155. if (index < 0) {
  9156. index = 0;
  9157. }
  9158. inputSource = inputSource.slice(this._contentsIgnoredCharsMap[fileInfo.filename]);
  9159. }
  9160. if (inputSource === void 0) {
  9161. this._css.push(chunk);
  9162. return;
  9163. }
  9164. inputSource = inputSource.substring(0, index);
  9165. sourceLines = inputSource.split("\n");
  9166. sourceColumns = sourceLines[sourceLines.length - 1];
  9167. }
  9168. lines = chunk.split("\n");
  9169. columns = lines[lines.length - 1];
  9170. if (fileInfo && fileInfo.filename) {
  9171. if (!mapLines) {
  9172. this._sourceMapGenerator.addMapping({
  9173. generated: { line: this._lineNumber + 1, column: this._column },
  9174. original: { line: sourceLines.length, column: sourceColumns.length },
  9175. source: this.normalizeFilename(fileInfo.filename)
  9176. });
  9177. } else {
  9178. for (i = 0; i < lines.length; i++) {
  9179. this._sourceMapGenerator.addMapping({
  9180. generated: { line: this._lineNumber + i + 1, column: i === 0 ? this._column : 0 },
  9181. original: { line: sourceLines.length + i, column: i === 0 ? sourceColumns.length : 0 },
  9182. source: this.normalizeFilename(fileInfo.filename)
  9183. });
  9184. }
  9185. }
  9186. }
  9187. if (lines.length === 1) {
  9188. this._column += columns.length;
  9189. } else {
  9190. this._lineNumber += lines.length - 1;
  9191. this._column = columns.length;
  9192. }
  9193. this._css.push(chunk);
  9194. };
  9195. SourceMapOutput3.prototype.isEmpty = function() {
  9196. return this._css.length === 0;
  9197. };
  9198. SourceMapOutput3.prototype.toCSS = function(context) {
  9199. this._sourceMapGenerator = new this._sourceMapGeneratorConstructor({ file: this._outputFilename, sourceRoot: null });
  9200. if (this._outputSourceFiles) {
  9201. for (var filename in this._contentsMap) {
  9202. if (this._contentsMap.hasOwnProperty(filename)) {
  9203. var source = this._contentsMap[filename];
  9204. if (this._contentsIgnoredCharsMap[filename]) {
  9205. source = source.slice(this._contentsIgnoredCharsMap[filename]);
  9206. }
  9207. this._sourceMapGenerator.setSourceContent(this.normalizeFilename(filename), source);
  9208. }
  9209. }
  9210. }
  9211. this._rootNode.genCSS(context, this);
  9212. if (this._css.length > 0) {
  9213. var sourceMapURL = void 0;
  9214. var sourceMapContent = JSON.stringify(this._sourceMapGenerator.toJSON());
  9215. if (this.sourceMapURL) {
  9216. sourceMapURL = this.sourceMapURL;
  9217. } else if (this._sourceMapFilename) {
  9218. sourceMapURL = this._sourceMapFilename;
  9219. }
  9220. this.sourceMapURL = sourceMapURL;
  9221. this.sourceMap = sourceMapContent;
  9222. }
  9223. return this._css.join("");
  9224. };
  9225. return SourceMapOutput3;
  9226. }()
  9227. );
  9228. return SourceMapOutput2;
  9229. }
  9230. function SourceMapBuilder(SourceMapOutput2, environment) {
  9231. var SourceMapBuilder2 = (
  9232. /** @class */
  9233. function() {
  9234. function SourceMapBuilder3(options2) {
  9235. this.options = options2;
  9236. }
  9237. SourceMapBuilder3.prototype.toCSS = function(rootNode, options2, imports) {
  9238. var sourceMapOutput = new SourceMapOutput2({
  9239. contentsIgnoredCharsMap: imports.contentsIgnoredChars,
  9240. rootNode,
  9241. contentsMap: imports.contents,
  9242. sourceMapFilename: this.options.sourceMapFilename,
  9243. sourceMapURL: this.options.sourceMapURL,
  9244. outputFilename: this.options.sourceMapOutputFilename,
  9245. sourceMapBasepath: this.options.sourceMapBasepath,
  9246. sourceMapRootpath: this.options.sourceMapRootpath,
  9247. outputSourceFiles: this.options.outputSourceFiles,
  9248. sourceMapGenerator: this.options.sourceMapGenerator,
  9249. sourceMapFileInline: this.options.sourceMapFileInline,
  9250. disableSourcemapAnnotation: this.options.disableSourcemapAnnotation
  9251. });
  9252. var css2 = sourceMapOutput.toCSS(options2);
  9253. this.sourceMap = sourceMapOutput.sourceMap;
  9254. this.sourceMapURL = sourceMapOutput.sourceMapURL;
  9255. if (this.options.sourceMapInputFilename) {
  9256. this.sourceMapInputFilename = sourceMapOutput.normalizeFilename(this.options.sourceMapInputFilename);
  9257. }
  9258. if (this.options.sourceMapBasepath !== void 0 && this.sourceMapURL !== void 0) {
  9259. this.sourceMapURL = sourceMapOutput.removeBasepath(this.sourceMapURL);
  9260. }
  9261. return css2 + this.getCSSAppendage();
  9262. };
  9263. SourceMapBuilder3.prototype.getCSSAppendage = function() {
  9264. var sourceMapURL = this.sourceMapURL;
  9265. if (this.options.sourceMapFileInline) {
  9266. if (this.sourceMap === void 0) {
  9267. return "";
  9268. }
  9269. sourceMapURL = "data:application/json;base64," + environment.encodeBase64(this.sourceMap);
  9270. }
  9271. if (this.options.disableSourcemapAnnotation) {
  9272. return "";
  9273. }
  9274. if (sourceMapURL) {
  9275. return "/*# sourceMappingURL=" + sourceMapURL + " */";
  9276. }
  9277. return "";
  9278. };
  9279. SourceMapBuilder3.prototype.getExternalSourceMap = function() {
  9280. return this.sourceMap;
  9281. };
  9282. SourceMapBuilder3.prototype.setExternalSourceMap = function(sourceMap) {
  9283. this.sourceMap = sourceMap;
  9284. };
  9285. SourceMapBuilder3.prototype.isInline = function() {
  9286. return this.options.sourceMapFileInline;
  9287. };
  9288. SourceMapBuilder3.prototype.getSourceMapURL = function() {
  9289. return this.sourceMapURL;
  9290. };
  9291. SourceMapBuilder3.prototype.getOutputFilename = function() {
  9292. return this.options.sourceMapOutputFilename;
  9293. };
  9294. SourceMapBuilder3.prototype.getInputFilename = function() {
  9295. return this.sourceMapInputFilename;
  9296. };
  9297. return SourceMapBuilder3;
  9298. }()
  9299. );
  9300. return SourceMapBuilder2;
  9301. }
  9302. function ParseTree(SourceMapBuilder2) {
  9303. var ParseTree2 = (
  9304. /** @class */
  9305. function() {
  9306. function ParseTree3(root2, imports) {
  9307. this.root = root2;
  9308. this.imports = imports;
  9309. }
  9310. ParseTree3.prototype.toCSS = function(options2) {
  9311. var evaldRoot;
  9312. var result = {};
  9313. var sourceMapBuilder;
  9314. try {
  9315. evaldRoot = transformTree(this.root, options2);
  9316. } catch (e) {
  9317. throw new LessError(e, this.imports);
  9318. }
  9319. try {
  9320. var compress = Boolean(options2.compress);
  9321. if (compress) {
  9322. logger$1.warn("The compress option has been deprecated. We recommend you use a dedicated css minifier, for instance see less-plugin-clean-css.");
  9323. }
  9324. var toCSSOptions = {
  9325. compress,
  9326. dumpLineNumbers: options2.dumpLineNumbers,
  9327. strictUnits: Boolean(options2.strictUnits),
  9328. numPrecision: 8
  9329. };
  9330. if (options2.sourceMap) {
  9331. sourceMapBuilder = new SourceMapBuilder2(options2.sourceMap);
  9332. result.css = sourceMapBuilder.toCSS(evaldRoot, toCSSOptions, this.imports);
  9333. } else {
  9334. result.css = evaldRoot.toCSS(toCSSOptions);
  9335. }
  9336. } catch (e) {
  9337. throw new LessError(e, this.imports);
  9338. }
  9339. if (options2.pluginManager) {
  9340. var postProcessors = options2.pluginManager.getPostProcessors();
  9341. for (var i = 0; i < postProcessors.length; i++) {
  9342. result.css = postProcessors[i].process(result.css, { sourceMap: sourceMapBuilder, options: options2, imports: this.imports });
  9343. }
  9344. }
  9345. if (options2.sourceMap) {
  9346. result.map = sourceMapBuilder.getExternalSourceMap();
  9347. }
  9348. result.imports = [];
  9349. for (var file in this.imports.files) {
  9350. if (this.imports.files.hasOwnProperty(file) && file !== this.imports.rootFilename) {
  9351. result.imports.push(file);
  9352. }
  9353. }
  9354. return result;
  9355. };
  9356. return ParseTree3;
  9357. }()
  9358. );
  9359. return ParseTree2;
  9360. }
  9361. function ImportManager(environment) {
  9362. var ImportManager2 = (
  9363. /** @class */
  9364. function() {
  9365. function ImportManager3(less2, context, rootFileInfo) {
  9366. this.less = less2;
  9367. this.rootFilename = rootFileInfo.filename;
  9368. this.paths = context.paths || [];
  9369. this.contents = {};
  9370. this.contentsIgnoredChars = {};
  9371. this.mime = context.mime;
  9372. this.error = null;
  9373. this.context = context;
  9374. this.queue = [];
  9375. this.files = {};
  9376. }
  9377. ImportManager3.prototype.push = function(path, tryAppendExtension, currentFileInfo, importOptions, callback) {
  9378. var importManager = this, pluginLoader = this.context.pluginManager.Loader;
  9379. this.queue.push(path);
  9380. var fileParsedFunc = function(e, root2, fullPath) {
  9381. importManager.queue.splice(importManager.queue.indexOf(path), 1);
  9382. var importedEqualsRoot = fullPath === importManager.rootFilename;
  9383. if (importOptions.optional && e) {
  9384. callback(null, { rules: [] }, false, null);
  9385. logger$1.info("The file " + fullPath + " was skipped because it was not found and the import was marked optional.");
  9386. } else {
  9387. if (!importManager.files[fullPath] && !importOptions.inline) {
  9388. importManager.files[fullPath] = { root: root2, options: importOptions };
  9389. }
  9390. if (e && !importManager.error) {
  9391. importManager.error = e;
  9392. }
  9393. callback(e, root2, importedEqualsRoot, fullPath);
  9394. }
  9395. };
  9396. var newFileInfo = {
  9397. rewriteUrls: this.context.rewriteUrls,
  9398. entryPath: currentFileInfo.entryPath,
  9399. rootpath: currentFileInfo.rootpath,
  9400. rootFilename: currentFileInfo.rootFilename
  9401. };
  9402. var fileManager = environment.getFileManager(path, currentFileInfo.currentDirectory, this.context, environment);
  9403. if (!fileManager) {
  9404. fileParsedFunc({ message: "Could not find a file-manager for " + path });
  9405. return;
  9406. }
  9407. var loadFileCallback = function(loadedFile2) {
  9408. var plugin;
  9409. var resolvedFilename = loadedFile2.filename;
  9410. var contents = loadedFile2.contents.replace(/^\uFEFF/, "");
  9411. newFileInfo.currentDirectory = fileManager.getPath(resolvedFilename);
  9412. if (newFileInfo.rewriteUrls) {
  9413. newFileInfo.rootpath = fileManager.join(importManager.context.rootpath || "", fileManager.pathDiff(newFileInfo.currentDirectory, newFileInfo.entryPath));
  9414. if (!fileManager.isPathAbsolute(newFileInfo.rootpath) && fileManager.alwaysMakePathsAbsolute()) {
  9415. newFileInfo.rootpath = fileManager.join(newFileInfo.entryPath, newFileInfo.rootpath);
  9416. }
  9417. }
  9418. newFileInfo.filename = resolvedFilename;
  9419. var newEnv = new contexts.Parse(importManager.context);
  9420. newEnv.processImports = false;
  9421. importManager.contents[resolvedFilename] = contents;
  9422. if (currentFileInfo.reference || importOptions.reference) {
  9423. newFileInfo.reference = true;
  9424. }
  9425. if (importOptions.isPlugin) {
  9426. plugin = pluginLoader.evalPlugin(contents, newEnv, importManager, importOptions.pluginArgs, newFileInfo);
  9427. if (plugin instanceof LessError) {
  9428. fileParsedFunc(plugin, null, resolvedFilename);
  9429. } else {
  9430. fileParsedFunc(null, plugin, resolvedFilename);
  9431. }
  9432. } else if (importOptions.inline) {
  9433. fileParsedFunc(null, contents, resolvedFilename);
  9434. } else {
  9435. if (importManager.files[resolvedFilename] && !importManager.files[resolvedFilename].options.multiple && !importOptions.multiple) {
  9436. fileParsedFunc(null, importManager.files[resolvedFilename].root, resolvedFilename);
  9437. } else {
  9438. new Parser(newEnv, importManager, newFileInfo).parse(contents, function(e, root2) {
  9439. fileParsedFunc(e, root2, resolvedFilename);
  9440. });
  9441. }
  9442. }
  9443. };
  9444. var loadedFile;
  9445. var promise;
  9446. var context = clone(this.context);
  9447. if (tryAppendExtension) {
  9448. context.ext = importOptions.isPlugin ? ".js" : ".less";
  9449. }
  9450. if (importOptions.isPlugin) {
  9451. context.mime = "application/javascript";
  9452. if (context.syncImport) {
  9453. loadedFile = pluginLoader.loadPluginSync(path, currentFileInfo.currentDirectory, context, environment, fileManager);
  9454. } else {
  9455. promise = pluginLoader.loadPlugin(path, currentFileInfo.currentDirectory, context, environment, fileManager);
  9456. }
  9457. } else {
  9458. if (context.syncImport) {
  9459. loadedFile = fileManager.loadFileSync(path, currentFileInfo.currentDirectory, context, environment);
  9460. } else {
  9461. promise = fileManager.loadFile(path, currentFileInfo.currentDirectory, context, environment, function(err, loadedFile2) {
  9462. if (err) {
  9463. fileParsedFunc(err);
  9464. } else {
  9465. loadFileCallback(loadedFile2);
  9466. }
  9467. });
  9468. }
  9469. }
  9470. if (loadedFile) {
  9471. if (!loadedFile.filename) {
  9472. fileParsedFunc(loadedFile);
  9473. } else {
  9474. loadFileCallback(loadedFile);
  9475. }
  9476. } else if (promise) {
  9477. promise.then(loadFileCallback, fileParsedFunc);
  9478. }
  9479. };
  9480. return ImportManager3;
  9481. }()
  9482. );
  9483. return ImportManager2;
  9484. }
  9485. function Parse(environment, ParseTree2, ImportManager2) {
  9486. var parse = function(input, options2, callback) {
  9487. if (typeof options2 === "function") {
  9488. callback = options2;
  9489. options2 = copyOptions(this.options, {});
  9490. } else {
  9491. options2 = copyOptions(this.options, options2 || {});
  9492. }
  9493. if (!callback) {
  9494. var self_1 = this;
  9495. return new Promise(function(resolve, reject) {
  9496. parse.call(self_1, input, options2, function(err, output) {
  9497. if (err) {
  9498. reject(err);
  9499. } else {
  9500. resolve(output);
  9501. }
  9502. });
  9503. });
  9504. } else {
  9505. var context_1;
  9506. var rootFileInfo = void 0;
  9507. var pluginManager_1 = new PluginManagerFactory(this, !options2.reUsePluginManager);
  9508. options2.pluginManager = pluginManager_1;
  9509. context_1 = new contexts.Parse(options2);
  9510. if (options2.rootFileInfo) {
  9511. rootFileInfo = options2.rootFileInfo;
  9512. } else {
  9513. var filename = options2.filename || "input";
  9514. var entryPath = filename.replace(/[^\/\\]*$/, "");
  9515. rootFileInfo = {
  9516. filename,
  9517. rewriteUrls: context_1.rewriteUrls,
  9518. rootpath: context_1.rootpath || "",
  9519. currentDirectory: entryPath,
  9520. entryPath,
  9521. rootFilename: filename
  9522. };
  9523. if (rootFileInfo.rootpath && rootFileInfo.rootpath.slice(-1) !== "/") {
  9524. rootFileInfo.rootpath += "/";
  9525. }
  9526. }
  9527. var imports_1 = new ImportManager2(this, context_1, rootFileInfo);
  9528. this.importManager = imports_1;
  9529. if (options2.plugins) {
  9530. options2.plugins.forEach(function(plugin) {
  9531. var evalResult, contents;
  9532. if (plugin.fileContent) {
  9533. contents = plugin.fileContent.replace(/^\uFEFF/, "");
  9534. evalResult = pluginManager_1.Loader.evalPlugin(contents, context_1, imports_1, plugin.options, plugin.filename);
  9535. if (evalResult instanceof LessError) {
  9536. return callback(evalResult);
  9537. }
  9538. } else {
  9539. pluginManager_1.addPlugin(plugin);
  9540. }
  9541. });
  9542. }
  9543. new Parser(context_1, imports_1, rootFileInfo).parse(input, function(e, root2) {
  9544. if (e) {
  9545. return callback(e);
  9546. }
  9547. callback(null, root2, imports_1, options2);
  9548. }, options2);
  9549. }
  9550. };
  9551. return parse;
  9552. }
  9553. function Render(environment, ParseTree2, ImportManager2) {
  9554. var render = function(input, options2, callback) {
  9555. if (typeof options2 === "function") {
  9556. callback = options2;
  9557. options2 = copyOptions(this.options, {});
  9558. } else {
  9559. options2 = copyOptions(this.options, options2 || {});
  9560. }
  9561. if (!callback) {
  9562. var self_1 = this;
  9563. return new Promise(function(resolve, reject) {
  9564. render.call(self_1, input, options2, function(err, output) {
  9565. if (err) {
  9566. reject(err);
  9567. } else {
  9568. resolve(output);
  9569. }
  9570. });
  9571. });
  9572. } else {
  9573. this.parse(input, options2, function(err, root2, imports, options3) {
  9574. if (err) {
  9575. return callback(err);
  9576. }
  9577. var result;
  9578. try {
  9579. var parseTree = new ParseTree2(root2, imports);
  9580. result = parseTree.toCSS(options3);
  9581. } catch (err2) {
  9582. return callback(err2);
  9583. }
  9584. callback(null, result);
  9585. });
  9586. }
  9587. };
  9588. return render;
  9589. }
  9590. var version = "4.1.3";
  9591. function parseNodeVersion(version2) {
  9592. var match = version2.match(/^v(\d{1,2})\.(\d{1,2})\.(\d{1,2})(?:-([0-9A-Za-z-.]+))?(?:\+([0-9A-Za-z-.]+))?$/);
  9593. if (!match) {
  9594. throw new Error("Unable to parse: " + version2);
  9595. }
  9596. var res = {
  9597. major: parseInt(match[1], 10),
  9598. minor: parseInt(match[2], 10),
  9599. patch: parseInt(match[3], 10),
  9600. pre: match[4] || "",
  9601. build: match[5] || ""
  9602. };
  9603. return res;
  9604. }
  9605. var parseNodeVersion_1 = parseNodeVersion;
  9606. function lessRoot(environment, fileManagers) {
  9607. var sourceMapOutput, sourceMapBuilder, parseTree, importManager;
  9608. environment = new Environment(environment, fileManagers);
  9609. sourceMapOutput = SourceMapOutput(environment);
  9610. sourceMapBuilder = SourceMapBuilder(sourceMapOutput, environment);
  9611. parseTree = ParseTree(sourceMapBuilder);
  9612. importManager = ImportManager(environment);
  9613. var render = Render(environment, parseTree);
  9614. var parse = Parse(environment, parseTree, importManager);
  9615. var v = parseNodeVersion_1("v" + version);
  9616. var initial = {
  9617. version: [v.major, v.minor, v.patch],
  9618. data,
  9619. tree,
  9620. Environment,
  9621. AbstractFileManager,
  9622. AbstractPluginLoader,
  9623. environment,
  9624. visitors,
  9625. Parser,
  9626. functions: functions(environment),
  9627. contexts,
  9628. SourceMapOutput: sourceMapOutput,
  9629. SourceMapBuilder: sourceMapBuilder,
  9630. ParseTree: parseTree,
  9631. ImportManager: importManager,
  9632. render,
  9633. parse,
  9634. LessError,
  9635. transformTree,
  9636. utils,
  9637. PluginManager: PluginManagerFactory,
  9638. logger: logger$1
  9639. };
  9640. var ctor = function(t2) {
  9641. return function() {
  9642. var obj = Object.create(t2.prototype);
  9643. t2.apply(obj, Array.prototype.slice.call(arguments, 0));
  9644. return obj;
  9645. };
  9646. };
  9647. var t;
  9648. var api = Object.create(initial);
  9649. for (var n in initial.tree) {
  9650. t = initial.tree[n];
  9651. if (typeof t === "function") {
  9652. api[n.toLowerCase()] = ctor(t);
  9653. } else {
  9654. api[n] = /* @__PURE__ */ Object.create(null);
  9655. for (var o in t) {
  9656. api[n][o.toLowerCase()] = ctor(t[o]);
  9657. }
  9658. }
  9659. }
  9660. initial.parse = initial.parse.bind(api);
  9661. initial.render = initial.render.bind(api);
  9662. return api;
  9663. }
  9664. var options$1;
  9665. var logger;
  9666. var fileCache = {};
  9667. var FileManager = function() {
  9668. };
  9669. FileManager.prototype = Object.assign(new AbstractFileManager(), {
  9670. alwaysMakePathsAbsolute: function() {
  9671. return true;
  9672. },
  9673. join: function(basePath, laterPath) {
  9674. if (!basePath) {
  9675. return laterPath;
  9676. }
  9677. return this.extractUrlParts(laterPath, basePath).path;
  9678. },
  9679. doXHR: function(url, type, callback, errback) {
  9680. var xhr = new XMLHttpRequest();
  9681. var async = options$1.isFileProtocol ? options$1.fileAsync : true;
  9682. if (typeof xhr.overrideMimeType === "function") {
  9683. xhr.overrideMimeType("text/css");
  9684. }
  9685. logger.debug("XHR: Getting '" + url + "'");
  9686. xhr.open("GET", url, async);
  9687. xhr.setRequestHeader("Accept", type || "text/x-less, text/css; q=0.9, */*; q=0.5");
  9688. xhr.send(null);
  9689. function handleResponse(xhr2, callback2, errback2) {
  9690. if (xhr2.status >= 200 && xhr2.status < 300) {
  9691. callback2(xhr2.responseText, xhr2.getResponseHeader("Last-Modified"));
  9692. } else if (typeof errback2 === "function") {
  9693. errback2(xhr2.status, url);
  9694. }
  9695. }
  9696. if (options$1.isFileProtocol && !options$1.fileAsync) {
  9697. if (xhr.status === 0 || xhr.status >= 200 && xhr.status < 300) {
  9698. callback(xhr.responseText);
  9699. } else {
  9700. errback(xhr.status, url);
  9701. }
  9702. } else if (async) {
  9703. xhr.onreadystatechange = function() {
  9704. if (xhr.readyState == 4) {
  9705. handleResponse(xhr, callback, errback);
  9706. }
  9707. };
  9708. } else {
  9709. handleResponse(xhr, callback, errback);
  9710. }
  9711. },
  9712. supports: function() {
  9713. return true;
  9714. },
  9715. clearFileCache: function() {
  9716. fileCache = {};
  9717. },
  9718. loadFile: function(filename, currentDirectory, options2, environment) {
  9719. if (currentDirectory && !this.isPathAbsolute(filename)) {
  9720. filename = currentDirectory + filename;
  9721. }
  9722. filename = options2.ext ? this.tryAppendExtension(filename, options2.ext) : filename;
  9723. options2 = options2 || {};
  9724. var hrefParts = this.extractUrlParts(filename, window.location.href);
  9725. var href = hrefParts.url;
  9726. var self2 = this;
  9727. return new Promise(function(resolve, reject) {
  9728. if (options2.useFileCache && fileCache[href]) {
  9729. try {
  9730. var lessText = fileCache[href];
  9731. return resolve({ contents: lessText, filename: href, webInfo: { lastModified: new Date() } });
  9732. } catch (e) {
  9733. return reject({ filename: href, message: "Error loading file " + href + " error was " + e.message });
  9734. }
  9735. }
  9736. self2.doXHR(href, options2.mime, function doXHRCallback(data2, lastModified) {
  9737. fileCache[href] = data2;
  9738. resolve({ contents: data2, filename: href, webInfo: { lastModified } });
  9739. }, function doXHRError(status, url) {
  9740. reject({ type: "File", message: "'" + url + "' wasn't found (" + status + ")", href });
  9741. });
  9742. });
  9743. }
  9744. });
  9745. var FM = function(opts, log) {
  9746. options$1 = opts;
  9747. logger = log;
  9748. return FileManager;
  9749. };
  9750. var PluginLoader = function(less2) {
  9751. this.less = less2;
  9752. };
  9753. PluginLoader.prototype = Object.assign(new AbstractPluginLoader(), {
  9754. loadPlugin: function(filename, basePath, context, environment, fileManager) {
  9755. return new Promise(function(fulfill, reject) {
  9756. fileManager.loadFile(filename, basePath, context, environment).then(fulfill).catch(reject);
  9757. });
  9758. }
  9759. });
  9760. var LogListener = function(less2, options2) {
  9761. var logLevel_debug = 4;
  9762. var logLevel_info = 3;
  9763. var logLevel_warn = 2;
  9764. var logLevel_error = 1;
  9765. options2.logLevel = typeof options2.logLevel !== "undefined" ? options2.logLevel : options2.env === "development" ? logLevel_info : logLevel_error;
  9766. if (!options2.loggers) {
  9767. options2.loggers = [{
  9768. debug: function(msg) {
  9769. if (options2.logLevel >= logLevel_debug) {
  9770. console.log(msg);
  9771. }
  9772. },
  9773. info: function(msg) {
  9774. if (options2.logLevel >= logLevel_info) {
  9775. console.log(msg);
  9776. }
  9777. },
  9778. warn: function(msg) {
  9779. if (options2.logLevel >= logLevel_warn) {
  9780. console.warn(msg);
  9781. }
  9782. },
  9783. error: function(msg) {
  9784. if (options2.logLevel >= logLevel_error) {
  9785. console.error(msg);
  9786. }
  9787. }
  9788. }];
  9789. }
  9790. for (var i = 0; i < options2.loggers.length; i++) {
  9791. less2.logger.addListener(options2.loggers[i]);
  9792. }
  9793. };
  9794. var ErrorReporting = function(window2, less2, options2) {
  9795. function errorHTML(e, rootHref) {
  9796. var id = "less-error-message:" + extractId(rootHref || "");
  9797. var template = '<li><label>{line}</label><pre class="{class}">{content}</pre></li>';
  9798. var elem = window2.document.createElement("div");
  9799. var timer;
  9800. var content;
  9801. var errors = [];
  9802. var filename = e.filename || rootHref;
  9803. var filenameNoPath = filename.match(/([^\/]+(\?.*)?)$/)[1];
  9804. elem.id = id;
  9805. elem.className = "less-error-message";
  9806. content = "<h3>" + (e.type || "Syntax") + "Error: " + (e.message || "There is an error in your .less file") + ('</h3><p>in <a href="' + filename + '">' + filenameNoPath + "</a> ");
  9807. var errorline = function(e2, i, classname) {
  9808. if (e2.extract[i] !== void 0) {
  9809. errors.push(template.replace(/\{line\}/, (parseInt(e2.line, 10) || 0) + (i - 1)).replace(/\{class\}/, classname).replace(/\{content\}/, e2.extract[i]));
  9810. }
  9811. };
  9812. if (e.line) {
  9813. errorline(e, 0, "");
  9814. errorline(e, 1, "line");
  9815. errorline(e, 2, "");
  9816. content += "on line " + e.line + ", column " + (e.column + 1) + ":</p><ul>" + errors.join("") + "</ul>";
  9817. }
  9818. if (e.stack && (e.extract || options2.logLevel >= 4)) {
  9819. content += "<br/>Stack Trace</br />" + e.stack.split("\n").slice(1).join("<br/>");
  9820. }
  9821. elem.innerHTML = content;
  9822. browser.createCSS(window2.document, [
  9823. ".less-error-message ul, .less-error-message li {",
  9824. "list-style-type: none;",
  9825. "margin-right: 15px;",
  9826. "padding: 4px 0;",
  9827. "margin: 0;",
  9828. "}",
  9829. ".less-error-message label {",
  9830. "font-size: 12px;",
  9831. "margin-right: 15px;",
  9832. "padding: 4px 0;",
  9833. "color: #cc7777;",
  9834. "}",
  9835. ".less-error-message pre {",
  9836. "color: #dd6666;",
  9837. "padding: 4px 0;",
  9838. "margin: 0;",
  9839. "display: inline-block;",
  9840. "}",
  9841. ".less-error-message pre.line {",
  9842. "color: #ff0000;",
  9843. "}",
  9844. ".less-error-message h3 {",
  9845. "font-size: 20px;",
  9846. "font-weight: bold;",
  9847. "padding: 15px 0 5px 0;",
  9848. "margin: 0;",
  9849. "}",
  9850. ".less-error-message a {",
  9851. "color: #10a",
  9852. "}",
  9853. ".less-error-message .error {",
  9854. "color: red;",
  9855. "font-weight: bold;",
  9856. "padding-bottom: 2px;",
  9857. "border-bottom: 1px dashed red;",
  9858. "}"
  9859. ].join("\n"), { title: "error-message" });
  9860. elem.style.cssText = [
  9861. "font-family: Arial, sans-serif",
  9862. "border: 1px solid #e00",
  9863. "background-color: #eee",
  9864. "border-radius: 5px",
  9865. "-webkit-border-radius: 5px",
  9866. "-moz-border-radius: 5px",
  9867. "color: #e00",
  9868. "padding: 15px",
  9869. "margin-bottom: 15px"
  9870. ].join(";");
  9871. if (options2.env === "development") {
  9872. timer = setInterval(function() {
  9873. var document2 = window2.document;
  9874. var body = document2.body;
  9875. if (body) {
  9876. if (document2.getElementById(id)) {
  9877. body.replaceChild(elem, document2.getElementById(id));
  9878. } else {
  9879. body.insertBefore(elem, body.firstChild);
  9880. }
  9881. clearInterval(timer);
  9882. }
  9883. }, 10);
  9884. }
  9885. }
  9886. function removeErrorHTML(path) {
  9887. var node = window2.document.getElementById("less-error-message:" + extractId(path));
  9888. if (node) {
  9889. node.parentNode.removeChild(node);
  9890. }
  9891. }
  9892. function removeError(path) {
  9893. if (!options2.errorReporting || options2.errorReporting === "html") {
  9894. removeErrorHTML(path);
  9895. } else if (options2.errorReporting === "console")
  9896. ;
  9897. else if (typeof options2.errorReporting === "function") {
  9898. options2.errorReporting("remove", path);
  9899. }
  9900. }
  9901. function errorConsole(e, rootHref) {
  9902. var template = "{line} {content}";
  9903. var filename = e.filename || rootHref;
  9904. var errors = [];
  9905. var content = (e.type || "Syntax") + "Error: " + (e.message || "There is an error in your .less file") + " in " + filename;
  9906. var errorline = function(e2, i, classname) {
  9907. if (e2.extract[i] !== void 0) {
  9908. errors.push(template.replace(/\{line\}/, (parseInt(e2.line, 10) || 0) + (i - 1)).replace(/\{class\}/, classname).replace(/\{content\}/, e2.extract[i]));
  9909. }
  9910. };
  9911. if (e.line) {
  9912. errorline(e, 0, "");
  9913. errorline(e, 1, "line");
  9914. errorline(e, 2, "");
  9915. content += " on line " + e.line + ", column " + (e.column + 1) + ":\n" + errors.join("\n");
  9916. }
  9917. if (e.stack && (e.extract || options2.logLevel >= 4)) {
  9918. content += "\nStack Trace\n" + e.stack;
  9919. }
  9920. less2.logger.error(content);
  9921. }
  9922. function error(e, rootHref) {
  9923. if (!options2.errorReporting || options2.errorReporting === "html") {
  9924. errorHTML(e, rootHref);
  9925. } else if (options2.errorReporting === "console") {
  9926. errorConsole(e, rootHref);
  9927. } else if (typeof options2.errorReporting === "function") {
  9928. options2.errorReporting("add", e, rootHref);
  9929. }
  9930. }
  9931. return {
  9932. add: error,
  9933. remove: removeError
  9934. };
  9935. };
  9936. var Cache = function(window2, options2, logger2) {
  9937. var cache = null;
  9938. if (options2.env !== "development") {
  9939. try {
  9940. cache = typeof window2.localStorage === "undefined" ? null : window2.localStorage;
  9941. } catch (_) {
  9942. }
  9943. }
  9944. return {
  9945. setCSS: function(path, lastModified, modifyVars, styles) {
  9946. if (cache) {
  9947. logger2.info("saving " + path + " to cache.");
  9948. try {
  9949. cache.setItem(path, styles);
  9950. cache.setItem(path + ":timestamp", lastModified);
  9951. if (modifyVars) {
  9952. cache.setItem(path + ":vars", JSON.stringify(modifyVars));
  9953. }
  9954. } catch (e) {
  9955. logger2.error('failed to save "' + path + '" to local storage for caching.');
  9956. }
  9957. }
  9958. },
  9959. getCSS: function(path, webInfo, modifyVars) {
  9960. var css2 = cache && cache.getItem(path);
  9961. var timestamp = cache && cache.getItem(path + ":timestamp");
  9962. var vars = cache && cache.getItem(path + ":vars");
  9963. modifyVars = modifyVars || {};
  9964. vars = vars || "{}";
  9965. if (timestamp && webInfo.lastModified && new Date(webInfo.lastModified).valueOf() === new Date(timestamp).valueOf() && JSON.stringify(modifyVars) === vars) {
  9966. return css2;
  9967. }
  9968. }
  9969. };
  9970. };
  9971. var ImageSize = function() {
  9972. function imageSize() {
  9973. throw {
  9974. type: "Runtime",
  9975. message: "Image size functions are not supported in browser version of less"
  9976. };
  9977. }
  9978. var imageFunctions = {
  9979. "image-size": function(filePathNode) {
  9980. imageSize();
  9981. return -1;
  9982. },
  9983. "image-width": function(filePathNode) {
  9984. imageSize();
  9985. return -1;
  9986. },
  9987. "image-height": function(filePathNode) {
  9988. imageSize();
  9989. return -1;
  9990. }
  9991. };
  9992. functionRegistry.addMultiple(imageFunctions);
  9993. };
  9994. var root = function(window2, options2) {
  9995. var document2 = window2.document;
  9996. var less2 = lessRoot();
  9997. less2.options = options2;
  9998. var environment = less2.environment;
  9999. var FileManager2 = FM(options2, less2.logger);
  10000. var fileManager = new FileManager2();
  10001. environment.addFileManager(fileManager);
  10002. less2.FileManager = FileManager2;
  10003. less2.PluginLoader = PluginLoader;
  10004. LogListener(less2, options2);
  10005. var errors = ErrorReporting(window2, less2, options2);
  10006. var cache = less2.cache = options2.cache || Cache(window2, options2, less2.logger);
  10007. ImageSize(less2.environment);
  10008. if (options2.functions) {
  10009. less2.functions.functionRegistry.addMultiple(options2.functions);
  10010. }
  10011. var typePattern = /^text\/(x-)?less$/;
  10012. function clone2(obj) {
  10013. var cloned = {};
  10014. for (var prop in obj) {
  10015. if (obj.hasOwnProperty(prop)) {
  10016. cloned[prop] = obj[prop];
  10017. }
  10018. }
  10019. return cloned;
  10020. }
  10021. function bind(func, thisArg) {
  10022. var curryArgs = Array.prototype.slice.call(arguments, 2);
  10023. return function() {
  10024. var args = curryArgs.concat(Array.prototype.slice.call(arguments, 0));
  10025. return func.apply(thisArg, args);
  10026. };
  10027. }
  10028. function loadStyles(modifyVars) {
  10029. var styles = document2.getElementsByTagName("style");
  10030. var style2;
  10031. for (var i = 0; i < styles.length; i++) {
  10032. style2 = styles[i];
  10033. if (style2.type.match(typePattern)) {
  10034. var instanceOptions = clone2(options2);
  10035. instanceOptions.modifyVars = modifyVars;
  10036. var lessText = style2.innerHTML || "";
  10037. instanceOptions.filename = document2.location.href.replace(/#.*$/, "");
  10038. less2.render(lessText, instanceOptions, bind(function(style3, e, result) {
  10039. if (e) {
  10040. errors.add(e, "inline");
  10041. } else {
  10042. style3.type = "text/css";
  10043. if (style3.styleSheet) {
  10044. style3.styleSheet.cssText = result.css;
  10045. } else {
  10046. style3.innerHTML = result.css;
  10047. }
  10048. }
  10049. }, null, style2));
  10050. }
  10051. }
  10052. }
  10053. function loadStyleSheet(sheet, callback, reload, remaining, modifyVars) {
  10054. var instanceOptions = clone2(options2);
  10055. addDataAttr(instanceOptions, sheet);
  10056. instanceOptions.mime = sheet.type;
  10057. if (modifyVars) {
  10058. instanceOptions.modifyVars = modifyVars;
  10059. }
  10060. function loadInitialFileCallback(loadedFile) {
  10061. var data2 = loadedFile.contents;
  10062. var path = loadedFile.filename;
  10063. var webInfo = loadedFile.webInfo;
  10064. var newFileInfo = {
  10065. currentDirectory: fileManager.getPath(path),
  10066. filename: path,
  10067. rootFilename: path,
  10068. rewriteUrls: instanceOptions.rewriteUrls
  10069. };
  10070. newFileInfo.entryPath = newFileInfo.currentDirectory;
  10071. newFileInfo.rootpath = instanceOptions.rootpath || newFileInfo.currentDirectory;
  10072. if (webInfo) {
  10073. webInfo.remaining = remaining;
  10074. var css2 = cache.getCSS(path, webInfo, instanceOptions.modifyVars);
  10075. if (!reload && css2) {
  10076. webInfo.local = true;
  10077. callback(null, css2, data2, sheet, webInfo, path);
  10078. return;
  10079. }
  10080. }
  10081. errors.remove(path);
  10082. instanceOptions.rootFileInfo = newFileInfo;
  10083. less2.render(data2, instanceOptions, function(e, result) {
  10084. if (e) {
  10085. e.href = path;
  10086. callback(e);
  10087. } else {
  10088. cache.setCSS(sheet.href, webInfo.lastModified, instanceOptions.modifyVars, result.css);
  10089. callback(null, result.css, data2, sheet, webInfo, path);
  10090. }
  10091. });
  10092. }
  10093. fileManager.loadFile(sheet.href, null, instanceOptions, environment).then(function(loadedFile) {
  10094. loadInitialFileCallback(loadedFile);
  10095. }).catch(function(err) {
  10096. console.log(err);
  10097. callback(err);
  10098. });
  10099. }
  10100. function loadStyleSheets(callback, reload, modifyVars) {
  10101. for (var i = 0; i < less2.sheets.length; i++) {
  10102. loadStyleSheet(less2.sheets[i], callback, reload, less2.sheets.length - (i + 1), modifyVars);
  10103. }
  10104. }
  10105. function initRunningMode() {
  10106. if (less2.env === "development") {
  10107. less2.watchTimer = setInterval(function() {
  10108. if (less2.watchMode) {
  10109. fileManager.clearFileCache();
  10110. loadStyleSheets(function(e, css2, _, sheet, webInfo) {
  10111. if (e) {
  10112. errors.add(e, e.href || sheet.href);
  10113. } else if (css2) {
  10114. browser.createCSS(window2.document, css2, sheet);
  10115. }
  10116. });
  10117. }
  10118. }, options2.poll);
  10119. }
  10120. }
  10121. less2.watch = function() {
  10122. if (!less2.watchMode) {
  10123. less2.env = "development";
  10124. initRunningMode();
  10125. }
  10126. this.watchMode = true;
  10127. return true;
  10128. };
  10129. less2.unwatch = function() {
  10130. clearInterval(less2.watchTimer);
  10131. this.watchMode = false;
  10132. return false;
  10133. };
  10134. less2.registerStylesheetsImmediately = function() {
  10135. var links = document2.getElementsByTagName("link");
  10136. less2.sheets = [];
  10137. for (var i = 0; i < links.length; i++) {
  10138. if (links[i].rel === "stylesheet/less" || links[i].rel.match(/stylesheet/) && links[i].type.match(typePattern)) {
  10139. less2.sheets.push(links[i]);
  10140. }
  10141. }
  10142. };
  10143. less2.registerStylesheets = function() {
  10144. return new Promise(function(resolve, reject) {
  10145. less2.registerStylesheetsImmediately();
  10146. resolve();
  10147. });
  10148. };
  10149. less2.modifyVars = function(record) {
  10150. return less2.refresh(true, record, false);
  10151. };
  10152. less2.refresh = function(reload, modifyVars, clearFileCache) {
  10153. if ((reload || clearFileCache) && clearFileCache !== false) {
  10154. fileManager.clearFileCache();
  10155. }
  10156. return new Promise(function(resolve, reject) {
  10157. var startTime;
  10158. var endTime;
  10159. var totalMilliseconds;
  10160. var remainingSheets;
  10161. startTime = endTime = new Date();
  10162. remainingSheets = less2.sheets.length;
  10163. if (remainingSheets === 0) {
  10164. endTime = new Date();
  10165. totalMilliseconds = endTime - startTime;
  10166. less2.logger.info("Less has finished and no sheets were loaded.");
  10167. resolve({
  10168. startTime,
  10169. endTime,
  10170. totalMilliseconds,
  10171. sheets: less2.sheets.length
  10172. });
  10173. } else {
  10174. loadStyleSheets(function(e, css2, _, sheet, webInfo) {
  10175. if (e) {
  10176. errors.add(e, e.href || sheet.href);
  10177. reject(e);
  10178. return;
  10179. }
  10180. if (webInfo.local) {
  10181. less2.logger.info("Loading " + sheet.href + " from cache.");
  10182. } else {
  10183. less2.logger.info("Rendered " + sheet.href + " successfully.");
  10184. }
  10185. browser.createCSS(window2.document, css2, sheet);
  10186. less2.logger.info("CSS for " + sheet.href + " generated in " + (new Date() - endTime) + "ms");
  10187. remainingSheets--;
  10188. if (remainingSheets === 0) {
  10189. totalMilliseconds = new Date() - startTime;
  10190. less2.logger.info("Less has finished. CSS generated in " + totalMilliseconds + "ms");
  10191. resolve({
  10192. startTime,
  10193. endTime,
  10194. totalMilliseconds,
  10195. sheets: less2.sheets.length
  10196. });
  10197. }
  10198. endTime = new Date();
  10199. }, reload, modifyVars);
  10200. }
  10201. loadStyles(modifyVars);
  10202. });
  10203. };
  10204. less2.refreshStyles = loadStyles;
  10205. return less2;
  10206. };
  10207. var options = defaultOptions();
  10208. if (window.less) {
  10209. for (var key in window.less) {
  10210. if (window.less.hasOwnProperty(key)) {
  10211. options[key] = window.less[key];
  10212. }
  10213. }
  10214. }
  10215. addDefaultOptions(window, options);
  10216. options.plugins = options.plugins || [];
  10217. if (window.LESS_PLUGINS) {
  10218. options.plugins = options.plugins.concat(window.LESS_PLUGINS);
  10219. }
  10220. var less = root(window, options);
  10221. window.less = less;
  10222. var css;
  10223. var head;
  10224. var style;
  10225. function resolveOrReject(data2) {
  10226. if (data2.filename) {
  10227. console.warn(data2);
  10228. }
  10229. if (!options.async) {
  10230. head.removeChild(style);
  10231. }
  10232. }
  10233. if (options.onReady) {
  10234. if (/!watch/.test(window.location.hash)) {
  10235. less.watch();
  10236. }
  10237. if (!options.async) {
  10238. css = "body { display: none !important }";
  10239. head = document.head || document.getElementsByTagName("head")[0];
  10240. style = document.createElement("style");
  10241. style.type = "text/css";
  10242. if (style.styleSheet) {
  10243. style.styleSheet.cssText = css;
  10244. } else {
  10245. style.appendChild(document.createTextNode(css));
  10246. }
  10247. head.appendChild(style);
  10248. }
  10249. less.registerStylesheetsImmediately();
  10250. less.pageLoadFinished = less.refresh(less.env === "development").then(resolveOrReject, resolveOrReject);
  10251. }
  10252. return less;
  10253. });
  10254. }
  10255. });
  10256. export default require_less();
  10257. /*! Bundled license information:
  10258. less/dist/less.js:
  10259. (**
  10260. * Less - Leaner CSS v4.1.3
  10261. * http://lesscss.org
  10262. *
  10263. * Copyright (c) 2009-2022, Alexis Sellier <self@cloudhead.net>
  10264. * Licensed under the Apache-2.0 License.
  10265. *
  10266. * @license Apache-2.0
  10267. *)
  10268. (*! *****************************************************************************
  10269. Copyright (c) Microsoft Corporation. All rights reserved.
  10270. Licensed under the Apache License, Version 2.0 (the "License"); you may not use
  10271. this file except in compliance with the License. You may obtain a copy of the
  10272. License at http://www.apache.org/licenses/LICENSE-2.0
  10273. THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  10274. KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
  10275. WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
  10276. MERCHANTABLITY OR NON-INFRINGEMENT.
  10277. See the Apache Version 2.0 License for specific language governing permissions
  10278. and limitations under the License.
  10279. ***************************************************************************** *)
  10280. (*! *****************************************************************************
  10281. Copyright (c) Microsoft Corporation.
  10282. Permission to use, copy, modify, and/or distribute this software for any
  10283. purpose with or without fee is hereby granted.
  10284. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
  10285. REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  10286. AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
  10287. INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  10288. LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
  10289. OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  10290. PERFORMANCE OF THIS SOFTWARE.
  10291. ***************************************************************************** *)
  10292. */
  10293. //# sourceMappingURL=less.js.map