You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

csso.js 513KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489
  1. (function (global, factory) {
  2. typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
  3. typeof define === 'function' && define.amd ? define(['exports'], factory) :
  4. (global = global || self, factory(global.csso = {}));
  5. }(this, (function (exports) { 'use strict';
  6. //
  7. // list
  8. // ┌──────┐
  9. // ┌──────────────┼─head │
  10. // │ │ tail─┼──────────────┐
  11. // │ └──────┘ │
  12. // ▼ ▼
  13. // item item item item
  14. // ┌──────┐ ┌──────┐ ┌──────┐ ┌──────┐
  15. // null ◀──┼─prev │◀───┼─prev │◀───┼─prev │◀───┼─prev │
  16. // │ next─┼───▶│ next─┼───▶│ next─┼───▶│ next─┼──▶ null
  17. // ├──────┤ ├──────┤ ├──────┤ ├──────┤
  18. // │ data │ │ data │ │ data │ │ data │
  19. // └──────┘ └──────┘ └──────┘ └──────┘
  20. //
  21. function createItem(data) {
  22. return {
  23. prev: null,
  24. next: null,
  25. data: data
  26. };
  27. }
  28. function allocateCursor(node, prev, next) {
  29. var cursor;
  30. if (cursors !== null) {
  31. cursor = cursors;
  32. cursors = cursors.cursor;
  33. cursor.prev = prev;
  34. cursor.next = next;
  35. cursor.cursor = node.cursor;
  36. } else {
  37. cursor = {
  38. prev: prev,
  39. next: next,
  40. cursor: node.cursor
  41. };
  42. }
  43. node.cursor = cursor;
  44. return cursor;
  45. }
  46. function releaseCursor(node) {
  47. var cursor = node.cursor;
  48. node.cursor = cursor.cursor;
  49. cursor.prev = null;
  50. cursor.next = null;
  51. cursor.cursor = cursors;
  52. cursors = cursor;
  53. }
  54. var cursors = null;
  55. var List = function() {
  56. this.cursor = null;
  57. this.head = null;
  58. this.tail = null;
  59. };
  60. List.createItem = createItem;
  61. List.prototype.createItem = createItem;
  62. List.prototype.updateCursors = function(prevOld, prevNew, nextOld, nextNew) {
  63. var cursor = this.cursor;
  64. while (cursor !== null) {
  65. if (cursor.prev === prevOld) {
  66. cursor.prev = prevNew;
  67. }
  68. if (cursor.next === nextOld) {
  69. cursor.next = nextNew;
  70. }
  71. cursor = cursor.cursor;
  72. }
  73. };
  74. List.prototype.getSize = function() {
  75. var size = 0;
  76. var cursor = this.head;
  77. while (cursor) {
  78. size++;
  79. cursor = cursor.next;
  80. }
  81. return size;
  82. };
  83. List.prototype.fromArray = function(array) {
  84. var cursor = null;
  85. this.head = null;
  86. for (var i = 0; i < array.length; i++) {
  87. var item = createItem(array[i]);
  88. if (cursor !== null) {
  89. cursor.next = item;
  90. } else {
  91. this.head = item;
  92. }
  93. item.prev = cursor;
  94. cursor = item;
  95. }
  96. this.tail = cursor;
  97. return this;
  98. };
  99. List.prototype.toArray = function() {
  100. var cursor = this.head;
  101. var result = [];
  102. while (cursor) {
  103. result.push(cursor.data);
  104. cursor = cursor.next;
  105. }
  106. return result;
  107. };
  108. List.prototype.toJSON = List.prototype.toArray;
  109. List.prototype.isEmpty = function() {
  110. return this.head === null;
  111. };
  112. List.prototype.first = function() {
  113. return this.head && this.head.data;
  114. };
  115. List.prototype.last = function() {
  116. return this.tail && this.tail.data;
  117. };
  118. List.prototype.each = function(fn, context) {
  119. var item;
  120. if (context === undefined) {
  121. context = this;
  122. }
  123. // push cursor
  124. var cursor = allocateCursor(this, null, this.head);
  125. while (cursor.next !== null) {
  126. item = cursor.next;
  127. cursor.next = item.next;
  128. fn.call(context, item.data, item, this);
  129. }
  130. // pop cursor
  131. releaseCursor(this);
  132. };
  133. List.prototype.forEach = List.prototype.each;
  134. List.prototype.eachRight = function(fn, context) {
  135. var item;
  136. if (context === undefined) {
  137. context = this;
  138. }
  139. // push cursor
  140. var cursor = allocateCursor(this, this.tail, null);
  141. while (cursor.prev !== null) {
  142. item = cursor.prev;
  143. cursor.prev = item.prev;
  144. fn.call(context, item.data, item, this);
  145. }
  146. // pop cursor
  147. releaseCursor(this);
  148. };
  149. List.prototype.forEachRight = List.prototype.eachRight;
  150. List.prototype.nextUntil = function(start, fn, context) {
  151. if (start === null) {
  152. return;
  153. }
  154. var item;
  155. if (context === undefined) {
  156. context = this;
  157. }
  158. // push cursor
  159. var cursor = allocateCursor(this, null, start);
  160. while (cursor.next !== null) {
  161. item = cursor.next;
  162. cursor.next = item.next;
  163. if (fn.call(context, item.data, item, this)) {
  164. break;
  165. }
  166. }
  167. // pop cursor
  168. releaseCursor(this);
  169. };
  170. List.prototype.prevUntil = function(start, fn, context) {
  171. if (start === null) {
  172. return;
  173. }
  174. var item;
  175. if (context === undefined) {
  176. context = this;
  177. }
  178. // push cursor
  179. var cursor = allocateCursor(this, start, null);
  180. while (cursor.prev !== null) {
  181. item = cursor.prev;
  182. cursor.prev = item.prev;
  183. if (fn.call(context, item.data, item, this)) {
  184. break;
  185. }
  186. }
  187. // pop cursor
  188. releaseCursor(this);
  189. };
  190. List.prototype.some = function(fn, context) {
  191. var cursor = this.head;
  192. if (context === undefined) {
  193. context = this;
  194. }
  195. while (cursor !== null) {
  196. if (fn.call(context, cursor.data, cursor, this)) {
  197. return true;
  198. }
  199. cursor = cursor.next;
  200. }
  201. return false;
  202. };
  203. List.prototype.map = function(fn, context) {
  204. var result = new List();
  205. var cursor = this.head;
  206. if (context === undefined) {
  207. context = this;
  208. }
  209. while (cursor !== null) {
  210. result.appendData(fn.call(context, cursor.data, cursor, this));
  211. cursor = cursor.next;
  212. }
  213. return result;
  214. };
  215. List.prototype.filter = function(fn, context) {
  216. var result = new List();
  217. var cursor = this.head;
  218. if (context === undefined) {
  219. context = this;
  220. }
  221. while (cursor !== null) {
  222. if (fn.call(context, cursor.data, cursor, this)) {
  223. result.appendData(cursor.data);
  224. }
  225. cursor = cursor.next;
  226. }
  227. return result;
  228. };
  229. List.prototype.clear = function() {
  230. this.head = null;
  231. this.tail = null;
  232. };
  233. List.prototype.copy = function() {
  234. var result = new List();
  235. var cursor = this.head;
  236. while (cursor !== null) {
  237. result.insert(createItem(cursor.data));
  238. cursor = cursor.next;
  239. }
  240. return result;
  241. };
  242. List.prototype.prepend = function(item) {
  243. // head
  244. // ^
  245. // item
  246. this.updateCursors(null, item, this.head, item);
  247. // insert to the beginning of the list
  248. if (this.head !== null) {
  249. // new item <- first item
  250. this.head.prev = item;
  251. // new item -> first item
  252. item.next = this.head;
  253. } else {
  254. // if list has no head, then it also has no tail
  255. // in this case tail points to the new item
  256. this.tail = item;
  257. }
  258. // head always points to new item
  259. this.head = item;
  260. return this;
  261. };
  262. List.prototype.prependData = function(data) {
  263. return this.prepend(createItem(data));
  264. };
  265. List.prototype.append = function(item) {
  266. return this.insert(item);
  267. };
  268. List.prototype.appendData = function(data) {
  269. return this.insert(createItem(data));
  270. };
  271. List.prototype.insert = function(item, before) {
  272. if (before !== undefined && before !== null) {
  273. // prev before
  274. // ^
  275. // item
  276. this.updateCursors(before.prev, item, before, item);
  277. if (before.prev === null) {
  278. // insert to the beginning of list
  279. if (this.head !== before) {
  280. throw new Error('before doesn\'t belong to list');
  281. }
  282. // since head points to before therefore list doesn't empty
  283. // no need to check tail
  284. this.head = item;
  285. before.prev = item;
  286. item.next = before;
  287. this.updateCursors(null, item);
  288. } else {
  289. // insert between two items
  290. before.prev.next = item;
  291. item.prev = before.prev;
  292. before.prev = item;
  293. item.next = before;
  294. }
  295. } else {
  296. // tail
  297. // ^
  298. // item
  299. this.updateCursors(this.tail, item, null, item);
  300. // insert to the ending of the list
  301. if (this.tail !== null) {
  302. // last item -> new item
  303. this.tail.next = item;
  304. // last item <- new item
  305. item.prev = this.tail;
  306. } else {
  307. // if list has no tail, then it also has no head
  308. // in this case head points to new item
  309. this.head = item;
  310. }
  311. // tail always points to new item
  312. this.tail = item;
  313. }
  314. return this;
  315. };
  316. List.prototype.insertData = function(data, before) {
  317. return this.insert(createItem(data), before);
  318. };
  319. List.prototype.remove = function(item) {
  320. // item
  321. // ^
  322. // prev next
  323. this.updateCursors(item, item.prev, item, item.next);
  324. if (item.prev !== null) {
  325. item.prev.next = item.next;
  326. } else {
  327. if (this.head !== item) {
  328. throw new Error('item doesn\'t belong to list');
  329. }
  330. this.head = item.next;
  331. }
  332. if (item.next !== null) {
  333. item.next.prev = item.prev;
  334. } else {
  335. if (this.tail !== item) {
  336. throw new Error('item doesn\'t belong to list');
  337. }
  338. this.tail = item.prev;
  339. }
  340. item.prev = null;
  341. item.next = null;
  342. return item;
  343. };
  344. List.prototype.push = function(data) {
  345. this.insert(createItem(data));
  346. };
  347. List.prototype.pop = function() {
  348. if (this.tail !== null) {
  349. return this.remove(this.tail);
  350. }
  351. };
  352. List.prototype.unshift = function(data) {
  353. this.prepend(createItem(data));
  354. };
  355. List.prototype.shift = function() {
  356. if (this.head !== null) {
  357. return this.remove(this.head);
  358. }
  359. };
  360. List.prototype.prependList = function(list) {
  361. return this.insertList(list, this.head);
  362. };
  363. List.prototype.appendList = function(list) {
  364. return this.insertList(list);
  365. };
  366. List.prototype.insertList = function(list, before) {
  367. // ignore empty lists
  368. if (list.head === null) {
  369. return this;
  370. }
  371. if (before !== undefined && before !== null) {
  372. this.updateCursors(before.prev, list.tail, before, list.head);
  373. // insert in the middle of dist list
  374. if (before.prev !== null) {
  375. // before.prev <-> list.head
  376. before.prev.next = list.head;
  377. list.head.prev = before.prev;
  378. } else {
  379. this.head = list.head;
  380. }
  381. before.prev = list.tail;
  382. list.tail.next = before;
  383. } else {
  384. this.updateCursors(this.tail, list.tail, null, list.head);
  385. // insert to end of the list
  386. if (this.tail !== null) {
  387. // if destination list has a tail, then it also has a head,
  388. // but head doesn't change
  389. // dest tail -> source head
  390. this.tail.next = list.head;
  391. // dest tail <- source head
  392. list.head.prev = this.tail;
  393. } else {
  394. // if list has no a tail, then it also has no a head
  395. // in this case points head to new item
  396. this.head = list.head;
  397. }
  398. // tail always start point to new item
  399. this.tail = list.tail;
  400. }
  401. list.head = null;
  402. list.tail = null;
  403. return this;
  404. };
  405. List.prototype.replace = function(oldItem, newItemOrList) {
  406. if ('head' in newItemOrList) {
  407. this.insertList(newItemOrList, oldItem);
  408. } else {
  409. this.insert(newItemOrList, oldItem);
  410. }
  411. this.remove(oldItem);
  412. };
  413. var List_1 = List;
  414. var createCustomError = function createCustomError(name, message) {
  415. // use Object.create(), because some VMs prevent setting line/column otherwise
  416. // (iOS Safari 10 even throws an exception)
  417. var error = Object.create(SyntaxError.prototype);
  418. var errorStack = new Error();
  419. error.name = name;
  420. error.message = message;
  421. Object.defineProperty(error, 'stack', {
  422. get: function() {
  423. return (errorStack.stack || '').replace(/^(.+\n){1,3}/, name + ': ' + message + '\n');
  424. }
  425. });
  426. return error;
  427. };
  428. var MAX_LINE_LENGTH = 100;
  429. var OFFSET_CORRECTION = 60;
  430. var TAB_REPLACEMENT = ' ';
  431. function sourceFragment(error, extraLines) {
  432. function processLines(start, end) {
  433. return lines.slice(start, end).map(function(line, idx) {
  434. var num = String(start + idx + 1);
  435. while (num.length < maxNumLength) {
  436. num = ' ' + num;
  437. }
  438. return num + ' |' + line;
  439. }).join('\n');
  440. }
  441. var lines = error.source.split(/\r\n?|\n|\f/);
  442. var line = error.line;
  443. var column = error.column;
  444. var startLine = Math.max(1, line - extraLines) - 1;
  445. var endLine = Math.min(line + extraLines, lines.length + 1);
  446. var maxNumLength = Math.max(4, String(endLine).length) + 1;
  447. var cutLeft = 0;
  448. // column correction according to replaced tab before column
  449. column += (TAB_REPLACEMENT.length - 1) * (lines[line - 1].substr(0, column - 1).match(/\t/g) || []).length;
  450. if (column > MAX_LINE_LENGTH) {
  451. cutLeft = column - OFFSET_CORRECTION + 3;
  452. column = OFFSET_CORRECTION - 2;
  453. }
  454. for (var i = startLine; i <= endLine; i++) {
  455. if (i >= 0 && i < lines.length) {
  456. lines[i] = lines[i].replace(/\t/g, TAB_REPLACEMENT);
  457. lines[i] =
  458. (cutLeft > 0 && lines[i].length > cutLeft ? '\u2026' : '') +
  459. lines[i].substr(cutLeft, MAX_LINE_LENGTH - 2) +
  460. (lines[i].length > cutLeft + MAX_LINE_LENGTH - 1 ? '\u2026' : '');
  461. }
  462. }
  463. return [
  464. processLines(startLine, line),
  465. new Array(column + maxNumLength + 2).join('-') + '^',
  466. processLines(line, endLine)
  467. ].filter(Boolean).join('\n');
  468. }
  469. var SyntaxError$1 = function(message, source, offset, line, column) {
  470. var error = createCustomError('SyntaxError', message);
  471. error.source = source;
  472. error.offset = offset;
  473. error.line = line;
  474. error.column = column;
  475. error.sourceFragment = function(extraLines) {
  476. return sourceFragment(error, isNaN(extraLines) ? 0 : extraLines);
  477. };
  478. Object.defineProperty(error, 'formattedMessage', {
  479. get: function() {
  480. return (
  481. 'Parse error: ' + error.message + '\n' +
  482. sourceFragment(error, 2)
  483. );
  484. }
  485. });
  486. // for backward capability
  487. error.parseError = {
  488. offset: offset,
  489. line: line,
  490. column: column
  491. };
  492. return error;
  493. };
  494. var _SyntaxError = SyntaxError$1;
  495. // CSS Syntax Module Level 3
  496. // https://www.w3.org/TR/css-syntax-3/
  497. var TYPE = {
  498. EOF: 0, // <EOF-token>
  499. Ident: 1, // <ident-token>
  500. Function: 2, // <function-token>
  501. AtKeyword: 3, // <at-keyword-token>
  502. Hash: 4, // <hash-token>
  503. String: 5, // <string-token>
  504. BadString: 6, // <bad-string-token>
  505. Url: 7, // <url-token>
  506. BadUrl: 8, // <bad-url-token>
  507. Delim: 9, // <delim-token>
  508. Number: 10, // <number-token>
  509. Percentage: 11, // <percentage-token>
  510. Dimension: 12, // <dimension-token>
  511. WhiteSpace: 13, // <whitespace-token>
  512. CDO: 14, // <CDO-token>
  513. CDC: 15, // <CDC-token>
  514. Colon: 16, // <colon-token> :
  515. Semicolon: 17, // <semicolon-token> ;
  516. Comma: 18, // <comma-token> ,
  517. LeftSquareBracket: 19, // <[-token>
  518. RightSquareBracket: 20, // <]-token>
  519. LeftParenthesis: 21, // <(-token>
  520. RightParenthesis: 22, // <)-token>
  521. LeftCurlyBracket: 23, // <{-token>
  522. RightCurlyBracket: 24, // <}-token>
  523. Comment: 25
  524. };
  525. var NAME = Object.keys(TYPE).reduce(function(result, key) {
  526. result[TYPE[key]] = key;
  527. return result;
  528. }, {});
  529. var _const = {
  530. TYPE: TYPE,
  531. NAME: NAME
  532. };
  533. var EOF = 0;
  534. // https://drafts.csswg.org/css-syntax-3/
  535. // § 4.2. Definitions
  536. // digit
  537. // A code point between U+0030 DIGIT ZERO (0) and U+0039 DIGIT NINE (9).
  538. function isDigit(code) {
  539. return code >= 0x0030 && code <= 0x0039;
  540. }
  541. // hex digit
  542. // A digit, or a code point between U+0041 LATIN CAPITAL LETTER A (A) and U+0046 LATIN CAPITAL LETTER F (F),
  543. // or a code point between U+0061 LATIN SMALL LETTER A (a) and U+0066 LATIN SMALL LETTER F (f).
  544. function isHexDigit(code) {
  545. return (
  546. isDigit(code) || // 0 .. 9
  547. (code >= 0x0041 && code <= 0x0046) || // A .. F
  548. (code >= 0x0061 && code <= 0x0066) // a .. f
  549. );
  550. }
  551. // uppercase letter
  552. // A code point between U+0041 LATIN CAPITAL LETTER A (A) and U+005A LATIN CAPITAL LETTER Z (Z).
  553. function isUppercaseLetter(code) {
  554. return code >= 0x0041 && code <= 0x005A;
  555. }
  556. // lowercase letter
  557. // A code point between U+0061 LATIN SMALL LETTER A (a) and U+007A LATIN SMALL LETTER Z (z).
  558. function isLowercaseLetter(code) {
  559. return code >= 0x0061 && code <= 0x007A;
  560. }
  561. // letter
  562. // An uppercase letter or a lowercase letter.
  563. function isLetter(code) {
  564. return isUppercaseLetter(code) || isLowercaseLetter(code);
  565. }
  566. // non-ASCII code point
  567. // A code point with a value equal to or greater than U+0080 <control>.
  568. function isNonAscii(code) {
  569. return code >= 0x0080;
  570. }
  571. // name-start code point
  572. // A letter, a non-ASCII code point, or U+005F LOW LINE (_).
  573. function isNameStart(code) {
  574. return isLetter(code) || isNonAscii(code) || code === 0x005F;
  575. }
  576. // name code point
  577. // A name-start code point, a digit, or U+002D HYPHEN-MINUS (-).
  578. function isName(code) {
  579. return isNameStart(code) || isDigit(code) || code === 0x002D;
  580. }
  581. // non-printable code point
  582. // A code point between U+0000 NULL and U+0008 BACKSPACE, or U+000B LINE TABULATION,
  583. // or a code point between U+000E SHIFT OUT and U+001F INFORMATION SEPARATOR ONE, or U+007F DELETE.
  584. function isNonPrintable(code) {
  585. return (
  586. (code >= 0x0000 && code <= 0x0008) ||
  587. (code === 0x000B) ||
  588. (code >= 0x000E && code <= 0x001F) ||
  589. (code === 0x007F)
  590. );
  591. }
  592. // newline
  593. // U+000A LINE FEED. Note that U+000D CARRIAGE RETURN and U+000C FORM FEED are not included in this definition,
  594. // as they are converted to U+000A LINE FEED during preprocessing.
  595. // TODO: we doesn't do a preprocessing, so check a code point for U+000D CARRIAGE RETURN and U+000C FORM FEED
  596. function isNewline(code) {
  597. return code === 0x000A || code === 0x000D || code === 0x000C;
  598. }
  599. // whitespace
  600. // A newline, U+0009 CHARACTER TABULATION, or U+0020 SPACE.
  601. function isWhiteSpace(code) {
  602. return isNewline(code) || code === 0x0020 || code === 0x0009;
  603. }
  604. // § 4.3.8. Check if two code points are a valid escape
  605. function isValidEscape(first, second) {
  606. // If the first code point is not U+005C REVERSE SOLIDUS (\), return false.
  607. if (first !== 0x005C) {
  608. return false;
  609. }
  610. // Otherwise, if the second code point is a newline or EOF, return false.
  611. if (isNewline(second) || second === EOF) {
  612. return false;
  613. }
  614. // Otherwise, return true.
  615. return true;
  616. }
  617. // § 4.3.9. Check if three code points would start an identifier
  618. function isIdentifierStart(first, second, third) {
  619. // Look at the first code point:
  620. // U+002D HYPHEN-MINUS
  621. if (first === 0x002D) {
  622. // If the second code point is a name-start code point or a U+002D HYPHEN-MINUS,
  623. // or the second and third code points are a valid escape, return true. Otherwise, return false.
  624. return (
  625. isNameStart(second) ||
  626. second === 0x002D ||
  627. isValidEscape(second, third)
  628. );
  629. }
  630. // name-start code point
  631. if (isNameStart(first)) {
  632. // Return true.
  633. return true;
  634. }
  635. // U+005C REVERSE SOLIDUS (\)
  636. if (first === 0x005C) {
  637. // If the first and second code points are a valid escape, return true. Otherwise, return false.
  638. return isValidEscape(first, second);
  639. }
  640. // anything else
  641. // Return false.
  642. return false;
  643. }
  644. // § 4.3.10. Check if three code points would start a number
  645. function isNumberStart(first, second, third) {
  646. // Look at the first code point:
  647. // U+002B PLUS SIGN (+)
  648. // U+002D HYPHEN-MINUS (-)
  649. if (first === 0x002B || first === 0x002D) {
  650. // If the second code point is a digit, return true.
  651. if (isDigit(second)) {
  652. return 2;
  653. }
  654. // Otherwise, if the second code point is a U+002E FULL STOP (.)
  655. // and the third code point is a digit, return true.
  656. // Otherwise, return false.
  657. return second === 0x002E && isDigit(third) ? 3 : 0;
  658. }
  659. // U+002E FULL STOP (.)
  660. if (first === 0x002E) {
  661. // If the second code point is a digit, return true. Otherwise, return false.
  662. return isDigit(second) ? 2 : 0;
  663. }
  664. // digit
  665. if (isDigit(first)) {
  666. // Return true.
  667. return 1;
  668. }
  669. // anything else
  670. // Return false.
  671. return 0;
  672. }
  673. //
  674. // Misc
  675. //
  676. // detect BOM (https://en.wikipedia.org/wiki/Byte_order_mark)
  677. function isBOM(code) {
  678. // UTF-16BE
  679. if (code === 0xFEFF) {
  680. return 1;
  681. }
  682. // UTF-16LE
  683. if (code === 0xFFFE) {
  684. return 1;
  685. }
  686. return 0;
  687. }
  688. // Fast code category
  689. //
  690. // https://drafts.csswg.org/css-syntax/#tokenizer-definitions
  691. // > non-ASCII code point
  692. // > A code point with a value equal to or greater than U+0080 <control>
  693. // > name-start code point
  694. // > A letter, a non-ASCII code point, or U+005F LOW LINE (_).
  695. // > name code point
  696. // > A name-start code point, a digit, or U+002D HYPHEN-MINUS (-)
  697. // That means only ASCII code points has a special meaning and we define a maps for 0..127 codes only
  698. var CATEGORY = new Array(0x80);
  699. charCodeCategory.Eof = 0x80;
  700. charCodeCategory.WhiteSpace = 0x82;
  701. charCodeCategory.Digit = 0x83;
  702. charCodeCategory.NameStart = 0x84;
  703. charCodeCategory.NonPrintable = 0x85;
  704. for (var i = 0; i < CATEGORY.length; i++) {
  705. switch (true) {
  706. case isWhiteSpace(i):
  707. CATEGORY[i] = charCodeCategory.WhiteSpace;
  708. break;
  709. case isDigit(i):
  710. CATEGORY[i] = charCodeCategory.Digit;
  711. break;
  712. case isNameStart(i):
  713. CATEGORY[i] = charCodeCategory.NameStart;
  714. break;
  715. case isNonPrintable(i):
  716. CATEGORY[i] = charCodeCategory.NonPrintable;
  717. break;
  718. default:
  719. CATEGORY[i] = i || charCodeCategory.Eof;
  720. }
  721. }
  722. function charCodeCategory(code) {
  723. return code < 0x80 ? CATEGORY[code] : charCodeCategory.NameStart;
  724. }
  725. var charCodeDefinitions = {
  726. isDigit: isDigit,
  727. isHexDigit: isHexDigit,
  728. isUppercaseLetter: isUppercaseLetter,
  729. isLowercaseLetter: isLowercaseLetter,
  730. isLetter: isLetter,
  731. isNonAscii: isNonAscii,
  732. isNameStart: isNameStart,
  733. isName: isName,
  734. isNonPrintable: isNonPrintable,
  735. isNewline: isNewline,
  736. isWhiteSpace: isWhiteSpace,
  737. isValidEscape: isValidEscape,
  738. isIdentifierStart: isIdentifierStart,
  739. isNumberStart: isNumberStart,
  740. isBOM: isBOM,
  741. charCodeCategory: charCodeCategory
  742. };
  743. var isDigit$1 = charCodeDefinitions.isDigit;
  744. var isHexDigit$1 = charCodeDefinitions.isHexDigit;
  745. var isUppercaseLetter$1 = charCodeDefinitions.isUppercaseLetter;
  746. var isName$1 = charCodeDefinitions.isName;
  747. var isWhiteSpace$1 = charCodeDefinitions.isWhiteSpace;
  748. var isValidEscape$1 = charCodeDefinitions.isValidEscape;
  749. function getCharCode(source, offset) {
  750. return offset < source.length ? source.charCodeAt(offset) : 0;
  751. }
  752. function getNewlineLength(source, offset, code) {
  753. if (code === 13 /* \r */ && getCharCode(source, offset + 1) === 10 /* \n */) {
  754. return 2;
  755. }
  756. return 1;
  757. }
  758. function cmpChar(testStr, offset, referenceCode) {
  759. var code = testStr.charCodeAt(offset);
  760. // code.toLowerCase() for A..Z
  761. if (isUppercaseLetter$1(code)) {
  762. code = code | 32;
  763. }
  764. return code === referenceCode;
  765. }
  766. function cmpStr(testStr, start, end, referenceStr) {
  767. if (end - start !== referenceStr.length) {
  768. return false;
  769. }
  770. if (start < 0 || end > testStr.length) {
  771. return false;
  772. }
  773. for (var i = start; i < end; i++) {
  774. var testCode = testStr.charCodeAt(i);
  775. var referenceCode = referenceStr.charCodeAt(i - start);
  776. // testCode.toLowerCase() for A..Z
  777. if (isUppercaseLetter$1(testCode)) {
  778. testCode = testCode | 32;
  779. }
  780. if (testCode !== referenceCode) {
  781. return false;
  782. }
  783. }
  784. return true;
  785. }
  786. function findWhiteSpaceStart(source, offset) {
  787. for (; offset >= 0; offset--) {
  788. if (!isWhiteSpace$1(source.charCodeAt(offset))) {
  789. break;
  790. }
  791. }
  792. return offset + 1;
  793. }
  794. function findWhiteSpaceEnd(source, offset) {
  795. for (; offset < source.length; offset++) {
  796. if (!isWhiteSpace$1(source.charCodeAt(offset))) {
  797. break;
  798. }
  799. }
  800. return offset;
  801. }
  802. function findDecimalNumberEnd(source, offset) {
  803. for (; offset < source.length; offset++) {
  804. if (!isDigit$1(source.charCodeAt(offset))) {
  805. break;
  806. }
  807. }
  808. return offset;
  809. }
  810. // § 4.3.7. Consume an escaped code point
  811. function consumeEscaped(source, offset) {
  812. // It assumes that the U+005C REVERSE SOLIDUS (\) has already been consumed and
  813. // that the next input code point has already been verified to be part of a valid escape.
  814. offset += 2;
  815. // hex digit
  816. if (isHexDigit$1(getCharCode(source, offset - 1))) {
  817. // Consume as many hex digits as possible, but no more than 5.
  818. // Note that this means 1-6 hex digits have been consumed in total.
  819. for (var maxOffset = Math.min(source.length, offset + 5); offset < maxOffset; offset++) {
  820. if (!isHexDigit$1(getCharCode(source, offset))) {
  821. break;
  822. }
  823. }
  824. // If the next input code point is whitespace, consume it as well.
  825. var code = getCharCode(source, offset);
  826. if (isWhiteSpace$1(code)) {
  827. offset += getNewlineLength(source, offset, code);
  828. }
  829. }
  830. return offset;
  831. }
  832. // §4.3.11. Consume a name
  833. // Note: This algorithm does not do the verification of the first few code points that are necessary
  834. // to ensure the returned code points would constitute an <ident-token>. If that is the intended use,
  835. // ensure that the stream starts with an identifier before calling this algorithm.
  836. function consumeName(source, offset) {
  837. // Let result initially be an empty string.
  838. // Repeatedly consume the next input code point from the stream:
  839. for (; offset < source.length; offset++) {
  840. var code = source.charCodeAt(offset);
  841. // name code point
  842. if (isName$1(code)) {
  843. // Append the code point to result.
  844. continue;
  845. }
  846. // the stream starts with a valid escape
  847. if (isValidEscape$1(code, getCharCode(source, offset + 1))) {
  848. // Consume an escaped code point. Append the returned code point to result.
  849. offset = consumeEscaped(source, offset) - 1;
  850. continue;
  851. }
  852. // anything else
  853. // Reconsume the current input code point. Return result.
  854. break;
  855. }
  856. return offset;
  857. }
  858. // §4.3.12. Consume a number
  859. function consumeNumber(source, offset) {
  860. var code = source.charCodeAt(offset);
  861. // 2. If the next input code point is U+002B PLUS SIGN (+) or U+002D HYPHEN-MINUS (-),
  862. // consume it and append it to repr.
  863. if (code === 0x002B || code === 0x002D) {
  864. code = source.charCodeAt(offset += 1);
  865. }
  866. // 3. While the next input code point is a digit, consume it and append it to repr.
  867. if (isDigit$1(code)) {
  868. offset = findDecimalNumberEnd(source, offset + 1);
  869. code = source.charCodeAt(offset);
  870. }
  871. // 4. If the next 2 input code points are U+002E FULL STOP (.) followed by a digit, then:
  872. if (code === 0x002E && isDigit$1(source.charCodeAt(offset + 1))) {
  873. // 4.1 Consume them.
  874. // 4.2 Append them to repr.
  875. code = source.charCodeAt(offset += 2);
  876. // 4.3 Set type to "number".
  877. // TODO
  878. // 4.4 While the next input code point is a digit, consume it and append it to repr.
  879. offset = findDecimalNumberEnd(source, offset);
  880. }
  881. // 5. If the next 2 or 3 input code points are U+0045 LATIN CAPITAL LETTER E (E)
  882. // or U+0065 LATIN SMALL LETTER E (e), ... , followed by a digit, then:
  883. if (cmpChar(source, offset, 101 /* e */)) {
  884. var sign = 0;
  885. code = source.charCodeAt(offset + 1);
  886. // ... optionally followed by U+002D HYPHEN-MINUS (-) or U+002B PLUS SIGN (+) ...
  887. if (code === 0x002D || code === 0x002B) {
  888. sign = 1;
  889. code = source.charCodeAt(offset + 2);
  890. }
  891. // ... followed by a digit
  892. if (isDigit$1(code)) {
  893. // 5.1 Consume them.
  894. // 5.2 Append them to repr.
  895. // 5.3 Set type to "number".
  896. // TODO
  897. // 5.4 While the next input code point is a digit, consume it and append it to repr.
  898. offset = findDecimalNumberEnd(source, offset + 1 + sign + 1);
  899. }
  900. }
  901. return offset;
  902. }
  903. // § 4.3.14. Consume the remnants of a bad url
  904. // ... its sole use is to consume enough of the input stream to reach a recovery point
  905. // where normal tokenizing can resume.
  906. function consumeBadUrlRemnants(source, offset) {
  907. // Repeatedly consume the next input code point from the stream:
  908. for (; offset < source.length; offset++) {
  909. var code = source.charCodeAt(offset);
  910. // U+0029 RIGHT PARENTHESIS ())
  911. // EOF
  912. if (code === 0x0029) {
  913. // Return.
  914. offset++;
  915. break;
  916. }
  917. if (isValidEscape$1(code, getCharCode(source, offset + 1))) {
  918. // Consume an escaped code point.
  919. // Note: This allows an escaped right parenthesis ("\)") to be encountered
  920. // without ending the <bad-url-token>. This is otherwise identical to
  921. // the "anything else" clause.
  922. offset = consumeEscaped(source, offset);
  923. }
  924. }
  925. return offset;
  926. }
  927. var utils = {
  928. consumeEscaped: consumeEscaped,
  929. consumeName: consumeName,
  930. consumeNumber: consumeNumber,
  931. consumeBadUrlRemnants: consumeBadUrlRemnants,
  932. cmpChar: cmpChar,
  933. cmpStr: cmpStr,
  934. getNewlineLength: getNewlineLength,
  935. findWhiteSpaceStart: findWhiteSpaceStart,
  936. findWhiteSpaceEnd: findWhiteSpaceEnd
  937. };
  938. var TYPE$1 = _const.TYPE;
  939. var NAME$1 = _const.NAME;
  940. var cmpStr$1 = utils.cmpStr;
  941. var EOF$1 = TYPE$1.EOF;
  942. var WHITESPACE = TYPE$1.WhiteSpace;
  943. var COMMENT = TYPE$1.Comment;
  944. var OFFSET_MASK = 0x00FFFFFF;
  945. var TYPE_SHIFT = 24;
  946. var TokenStream = function() {
  947. this.offsetAndType = null;
  948. this.balance = null;
  949. this.reset();
  950. };
  951. TokenStream.prototype = {
  952. reset: function() {
  953. this.eof = false;
  954. this.tokenIndex = -1;
  955. this.tokenType = 0;
  956. this.tokenStart = this.firstCharOffset;
  957. this.tokenEnd = this.firstCharOffset;
  958. },
  959. lookupType: function(offset) {
  960. offset += this.tokenIndex;
  961. if (offset < this.tokenCount) {
  962. return this.offsetAndType[offset] >> TYPE_SHIFT;
  963. }
  964. return EOF$1;
  965. },
  966. lookupOffset: function(offset) {
  967. offset += this.tokenIndex;
  968. if (offset < this.tokenCount) {
  969. return this.offsetAndType[offset - 1] & OFFSET_MASK;
  970. }
  971. return this.source.length;
  972. },
  973. lookupValue: function(offset, referenceStr) {
  974. offset += this.tokenIndex;
  975. if (offset < this.tokenCount) {
  976. return cmpStr$1(
  977. this.source,
  978. this.offsetAndType[offset - 1] & OFFSET_MASK,
  979. this.offsetAndType[offset] & OFFSET_MASK,
  980. referenceStr
  981. );
  982. }
  983. return false;
  984. },
  985. getTokenStart: function(tokenIndex) {
  986. if (tokenIndex === this.tokenIndex) {
  987. return this.tokenStart;
  988. }
  989. if (tokenIndex > 0) {
  990. return tokenIndex < this.tokenCount
  991. ? this.offsetAndType[tokenIndex - 1] & OFFSET_MASK
  992. : this.offsetAndType[this.tokenCount] & OFFSET_MASK;
  993. }
  994. return this.firstCharOffset;
  995. },
  996. // TODO: -> skipUntilBalanced
  997. getRawLength: function(startToken, mode) {
  998. var cursor = startToken;
  999. var balanceEnd;
  1000. var offset = this.offsetAndType[Math.max(cursor - 1, 0)] & OFFSET_MASK;
  1001. var type;
  1002. loop:
  1003. for (; cursor < this.tokenCount; cursor++) {
  1004. balanceEnd = this.balance[cursor];
  1005. // stop scanning on balance edge that points to offset before start token
  1006. if (balanceEnd < startToken) {
  1007. break loop;
  1008. }
  1009. type = this.offsetAndType[cursor] >> TYPE_SHIFT;
  1010. // check token is stop type
  1011. switch (mode(type, this.source, offset)) {
  1012. case 1:
  1013. break loop;
  1014. case 2:
  1015. cursor++;
  1016. break loop;
  1017. default:
  1018. offset = this.offsetAndType[cursor] & OFFSET_MASK;
  1019. // fast forward to the end of balanced block
  1020. if (this.balance[balanceEnd] === cursor) {
  1021. cursor = balanceEnd;
  1022. }
  1023. }
  1024. }
  1025. return cursor - this.tokenIndex;
  1026. },
  1027. isBalanceEdge: function(pos) {
  1028. return this.balance[this.tokenIndex] < pos;
  1029. },
  1030. isDelim: function(code, offset) {
  1031. if (offset) {
  1032. return (
  1033. this.lookupType(offset) === TYPE$1.Delim &&
  1034. this.source.charCodeAt(this.lookupOffset(offset)) === code
  1035. );
  1036. }
  1037. return (
  1038. this.tokenType === TYPE$1.Delim &&
  1039. this.source.charCodeAt(this.tokenStart) === code
  1040. );
  1041. },
  1042. getTokenValue: function() {
  1043. return this.source.substring(this.tokenStart, this.tokenEnd);
  1044. },
  1045. getTokenLength: function() {
  1046. return this.tokenEnd - this.tokenStart;
  1047. },
  1048. substrToCursor: function(start) {
  1049. return this.source.substring(start, this.tokenStart);
  1050. },
  1051. skipWS: function() {
  1052. for (var i = this.tokenIndex, skipTokenCount = 0; i < this.tokenCount; i++, skipTokenCount++) {
  1053. if ((this.offsetAndType[i] >> TYPE_SHIFT) !== WHITESPACE) {
  1054. break;
  1055. }
  1056. }
  1057. if (skipTokenCount > 0) {
  1058. this.skip(skipTokenCount);
  1059. }
  1060. },
  1061. skipSC: function() {
  1062. while (this.tokenType === WHITESPACE || this.tokenType === COMMENT) {
  1063. this.next();
  1064. }
  1065. },
  1066. skip: function(tokenCount) {
  1067. var next = this.tokenIndex + tokenCount;
  1068. if (next < this.tokenCount) {
  1069. this.tokenIndex = next;
  1070. this.tokenStart = this.offsetAndType[next - 1] & OFFSET_MASK;
  1071. next = this.offsetAndType[next];
  1072. this.tokenType = next >> TYPE_SHIFT;
  1073. this.tokenEnd = next & OFFSET_MASK;
  1074. } else {
  1075. this.tokenIndex = this.tokenCount;
  1076. this.next();
  1077. }
  1078. },
  1079. next: function() {
  1080. var next = this.tokenIndex + 1;
  1081. if (next < this.tokenCount) {
  1082. this.tokenIndex = next;
  1083. this.tokenStart = this.tokenEnd;
  1084. next = this.offsetAndType[next];
  1085. this.tokenType = next >> TYPE_SHIFT;
  1086. this.tokenEnd = next & OFFSET_MASK;
  1087. } else {
  1088. this.tokenIndex = this.tokenCount;
  1089. this.eof = true;
  1090. this.tokenType = EOF$1;
  1091. this.tokenStart = this.tokenEnd = this.source.length;
  1092. }
  1093. },
  1094. dump: function() {
  1095. var offset = this.firstCharOffset;
  1096. return Array.prototype.slice.call(this.offsetAndType, 0, this.tokenCount).map(function(item, idx) {
  1097. var start = offset;
  1098. var end = item & OFFSET_MASK;
  1099. offset = end;
  1100. return {
  1101. idx: idx,
  1102. type: NAME$1[item >> TYPE_SHIFT],
  1103. chunk: this.source.substring(start, end),
  1104. balance: this.balance[idx]
  1105. };
  1106. }, this);
  1107. }
  1108. };
  1109. var TokenStream_1 = TokenStream;
  1110. function noop(value) {
  1111. return value;
  1112. }
  1113. function generateMultiplier(multiplier) {
  1114. if (multiplier.min === 0 && multiplier.max === 0) {
  1115. return '*';
  1116. }
  1117. if (multiplier.min === 0 && multiplier.max === 1) {
  1118. return '?';
  1119. }
  1120. if (multiplier.min === 1 && multiplier.max === 0) {
  1121. return multiplier.comma ? '#' : '+';
  1122. }
  1123. if (multiplier.min === 1 && multiplier.max === 1) {
  1124. return '';
  1125. }
  1126. return (
  1127. (multiplier.comma ? '#' : '') +
  1128. (multiplier.min === multiplier.max
  1129. ? '{' + multiplier.min + '}'
  1130. : '{' + multiplier.min + ',' + (multiplier.max !== 0 ? multiplier.max : '') + '}'
  1131. )
  1132. );
  1133. }
  1134. function generateTypeOpts(node) {
  1135. switch (node.type) {
  1136. case 'Range':
  1137. return (
  1138. ' [' +
  1139. (node.min === null ? '-∞' : node.min) +
  1140. ',' +
  1141. (node.max === null ? '∞' : node.max) +
  1142. ']'
  1143. );
  1144. default:
  1145. throw new Error('Unknown node type `' + node.type + '`');
  1146. }
  1147. }
  1148. function generateSequence(node, decorate, forceBraces, compact) {
  1149. var combinator = node.combinator === ' ' || compact ? node.combinator : ' ' + node.combinator + ' ';
  1150. var result = node.terms.map(function(term) {
  1151. return generate(term, decorate, forceBraces, compact);
  1152. }).join(combinator);
  1153. if (node.explicit || forceBraces) {
  1154. result = (compact || result[0] === ',' ? '[' : '[ ') + result + (compact ? ']' : ' ]');
  1155. }
  1156. return result;
  1157. }
  1158. function generate(node, decorate, forceBraces, compact) {
  1159. var result;
  1160. switch (node.type) {
  1161. case 'Group':
  1162. result =
  1163. generateSequence(node, decorate, forceBraces, compact) +
  1164. (node.disallowEmpty ? '!' : '');
  1165. break;
  1166. case 'Multiplier':
  1167. // return since node is a composition
  1168. return (
  1169. generate(node.term, decorate, forceBraces, compact) +
  1170. decorate(generateMultiplier(node), node)
  1171. );
  1172. case 'Type':
  1173. result = '<' + node.name + (node.opts ? decorate(generateTypeOpts(node.opts), node.opts) : '') + '>';
  1174. break;
  1175. case 'Property':
  1176. result = '<\'' + node.name + '\'>';
  1177. break;
  1178. case 'Keyword':
  1179. result = node.name;
  1180. break;
  1181. case 'AtKeyword':
  1182. result = '@' + node.name;
  1183. break;
  1184. case 'Function':
  1185. result = node.name + '(';
  1186. break;
  1187. case 'String':
  1188. case 'Token':
  1189. result = node.value;
  1190. break;
  1191. case 'Comma':
  1192. result = ',';
  1193. break;
  1194. default:
  1195. throw new Error('Unknown node type `' + node.type + '`');
  1196. }
  1197. return decorate(result, node);
  1198. }
  1199. var generate_1 = function(node, options) {
  1200. var decorate = noop;
  1201. var forceBraces = false;
  1202. var compact = false;
  1203. if (typeof options === 'function') {
  1204. decorate = options;
  1205. } else if (options) {
  1206. forceBraces = Boolean(options.forceBraces);
  1207. compact = Boolean(options.compact);
  1208. if (typeof options.decorate === 'function') {
  1209. decorate = options.decorate;
  1210. }
  1211. }
  1212. return generate(node, decorate, forceBraces, compact);
  1213. };
  1214. function fromMatchResult(matchResult) {
  1215. var tokens = matchResult.tokens;
  1216. var longestMatch = matchResult.longestMatch;
  1217. var node = longestMatch < tokens.length ? tokens[longestMatch].node : null;
  1218. var mismatchOffset = -1;
  1219. var entries = 0;
  1220. var css = '';
  1221. for (var i = 0; i < tokens.length; i++) {
  1222. if (i === longestMatch) {
  1223. mismatchOffset = css.length;
  1224. }
  1225. if (node !== null && tokens[i].node === node) {
  1226. if (i <= longestMatch) {
  1227. entries++;
  1228. } else {
  1229. entries = 0;
  1230. }
  1231. }
  1232. css += tokens[i].value;
  1233. }
  1234. return {
  1235. node: node,
  1236. css: css,
  1237. mismatchOffset: mismatchOffset === -1 ? css.length : mismatchOffset,
  1238. last: node === null || entries > 1
  1239. };
  1240. }
  1241. function getLocation(node, point) {
  1242. var loc = node && node.loc && node.loc[point];
  1243. if (loc) {
  1244. return {
  1245. offset: loc.offset,
  1246. line: loc.line,
  1247. column: loc.column
  1248. };
  1249. }
  1250. return null;
  1251. }
  1252. var SyntaxReferenceError = function(type, referenceName) {
  1253. var error = createCustomError(
  1254. 'SyntaxReferenceError',
  1255. type + (referenceName ? ' `' + referenceName + '`' : '')
  1256. );
  1257. error.reference = referenceName;
  1258. return error;
  1259. };
  1260. var MatchError = function(message, syntax, node, matchResult) {
  1261. var error = createCustomError('SyntaxMatchError', message);
  1262. var details = fromMatchResult(matchResult);
  1263. var mismatchOffset = details.mismatchOffset || 0;
  1264. var badNode = details.node || node;
  1265. var end = getLocation(badNode, 'end');
  1266. var start = details.last ? end : getLocation(badNode, 'start');
  1267. var css = details.css;
  1268. error.rawMessage = message;
  1269. error.syntax = syntax ? generate_1(syntax) : '<generic>';
  1270. error.css = css;
  1271. error.mismatchOffset = mismatchOffset;
  1272. error.loc = {
  1273. source: (badNode && badNode.loc && badNode.loc.source) || '<unknown>',
  1274. start: start,
  1275. end: end
  1276. };
  1277. error.line = start ? start.line : undefined;
  1278. error.column = start ? start.column : undefined;
  1279. error.offset = start ? start.offset : undefined;
  1280. error.message = message + '\n' +
  1281. ' syntax: ' + error.syntax + '\n' +
  1282. ' value: ' + (error.css || '<empty string>') + '\n' +
  1283. ' --------' + new Array(error.mismatchOffset + 1).join('-') + '^';
  1284. return error;
  1285. };
  1286. var error = {
  1287. SyntaxReferenceError: SyntaxReferenceError,
  1288. MatchError: MatchError
  1289. };
  1290. var hasOwnProperty = Object.prototype.hasOwnProperty;
  1291. var keywords = Object.create(null);
  1292. var properties = Object.create(null);
  1293. var HYPHENMINUS = 45; // '-'.charCodeAt()
  1294. function isCustomProperty(str, offset) {
  1295. offset = offset || 0;
  1296. return str.length - offset >= 2 &&
  1297. str.charCodeAt(offset) === HYPHENMINUS &&
  1298. str.charCodeAt(offset + 1) === HYPHENMINUS;
  1299. }
  1300. function getVendorPrefix(str, offset) {
  1301. offset = offset || 0;
  1302. // verdor prefix should be at least 3 chars length
  1303. if (str.length - offset >= 3) {
  1304. // vendor prefix starts with hyper minus following non-hyper minus
  1305. if (str.charCodeAt(offset) === HYPHENMINUS &&
  1306. str.charCodeAt(offset + 1) !== HYPHENMINUS) {
  1307. // vendor prefix should contain a hyper minus at the ending
  1308. var secondDashIndex = str.indexOf('-', offset + 2);
  1309. if (secondDashIndex !== -1) {
  1310. return str.substring(offset, secondDashIndex + 1);
  1311. }
  1312. }
  1313. }
  1314. return '';
  1315. }
  1316. function getKeywordDescriptor(keyword) {
  1317. if (hasOwnProperty.call(keywords, keyword)) {
  1318. return keywords[keyword];
  1319. }
  1320. var name = keyword.toLowerCase();
  1321. if (hasOwnProperty.call(keywords, name)) {
  1322. return keywords[keyword] = keywords[name];
  1323. }
  1324. var custom = isCustomProperty(name, 0);
  1325. var vendor = !custom ? getVendorPrefix(name, 0) : '';
  1326. return keywords[keyword] = Object.freeze({
  1327. basename: name.substr(vendor.length),
  1328. name: name,
  1329. vendor: vendor,
  1330. prefix: vendor,
  1331. custom: custom
  1332. });
  1333. }
  1334. function getPropertyDescriptor(property) {
  1335. if (hasOwnProperty.call(properties, property)) {
  1336. return properties[property];
  1337. }
  1338. var name = property;
  1339. var hack = property[0];
  1340. if (hack === '/') {
  1341. hack = property[1] === '/' ? '//' : '/';
  1342. } else if (hack !== '_' &&
  1343. hack !== '*' &&
  1344. hack !== '$' &&
  1345. hack !== '#' &&
  1346. hack !== '+' &&
  1347. hack !== '&') {
  1348. hack = '';
  1349. }
  1350. var custom = isCustomProperty(name, hack.length);
  1351. // re-use result when possible (the same as for lower case)
  1352. if (!custom) {
  1353. name = name.toLowerCase();
  1354. if (hasOwnProperty.call(properties, name)) {
  1355. return properties[property] = properties[name];
  1356. }
  1357. }
  1358. var vendor = !custom ? getVendorPrefix(name, hack.length) : '';
  1359. var prefix = name.substr(0, hack.length + vendor.length);
  1360. return properties[property] = Object.freeze({
  1361. basename: name.substr(prefix.length),
  1362. name: name.substr(hack.length),
  1363. hack: hack,
  1364. vendor: vendor,
  1365. prefix: prefix,
  1366. custom: custom
  1367. });
  1368. }
  1369. var names = {
  1370. keyword: getKeywordDescriptor,
  1371. property: getPropertyDescriptor,
  1372. isCustomProperty: isCustomProperty,
  1373. vendorPrefix: getVendorPrefix
  1374. };
  1375. var MIN_SIZE = 16 * 1024;
  1376. var SafeUint32Array = typeof Uint32Array !== 'undefined' ? Uint32Array : Array; // fallback on Array when TypedArray is not supported
  1377. var adoptBuffer = function adoptBuffer(buffer, size) {
  1378. if (buffer === null || buffer.length < size) {
  1379. return new SafeUint32Array(Math.max(size + 1024, MIN_SIZE));
  1380. }
  1381. return buffer;
  1382. };
  1383. var TYPE$2 = _const.TYPE;
  1384. var isNewline$1 = charCodeDefinitions.isNewline;
  1385. var isName$2 = charCodeDefinitions.isName;
  1386. var isValidEscape$2 = charCodeDefinitions.isValidEscape;
  1387. var isNumberStart$1 = charCodeDefinitions.isNumberStart;
  1388. var isIdentifierStart$1 = charCodeDefinitions.isIdentifierStart;
  1389. var charCodeCategory$1 = charCodeDefinitions.charCodeCategory;
  1390. var isBOM$1 = charCodeDefinitions.isBOM;
  1391. var cmpStr$2 = utils.cmpStr;
  1392. var getNewlineLength$1 = utils.getNewlineLength;
  1393. var findWhiteSpaceEnd$1 = utils.findWhiteSpaceEnd;
  1394. var consumeEscaped$1 = utils.consumeEscaped;
  1395. var consumeName$1 = utils.consumeName;
  1396. var consumeNumber$1 = utils.consumeNumber;
  1397. var consumeBadUrlRemnants$1 = utils.consumeBadUrlRemnants;
  1398. var OFFSET_MASK$1 = 0x00FFFFFF;
  1399. var TYPE_SHIFT$1 = 24;
  1400. function tokenize(source, stream) {
  1401. function getCharCode(offset) {
  1402. return offset < sourceLength ? source.charCodeAt(offset) : 0;
  1403. }
  1404. // § 4.3.3. Consume a numeric token
  1405. function consumeNumericToken() {
  1406. // Consume a number and let number be the result.
  1407. offset = consumeNumber$1(source, offset);
  1408. // If the next 3 input code points would start an identifier, then:
  1409. if (isIdentifierStart$1(getCharCode(offset), getCharCode(offset + 1), getCharCode(offset + 2))) {
  1410. // Create a <dimension-token> with the same value and type flag as number, and a unit set initially to the empty string.
  1411. // Consume a name. Set the <dimension-token>’s unit to the returned value.
  1412. // Return the <dimension-token>.
  1413. type = TYPE$2.Dimension;
  1414. offset = consumeName$1(source, offset);
  1415. return;
  1416. }
  1417. // Otherwise, if the next input code point is U+0025 PERCENTAGE SIGN (%), consume it.
  1418. if (getCharCode(offset) === 0x0025) {
  1419. // Create a <percentage-token> with the same value as number, and return it.
  1420. type = TYPE$2.Percentage;
  1421. offset++;
  1422. return;
  1423. }
  1424. // Otherwise, create a <number-token> with the same value and type flag as number, and return it.
  1425. type = TYPE$2.Number;
  1426. }
  1427. // § 4.3.4. Consume an ident-like token
  1428. function consumeIdentLikeToken() {
  1429. const nameStartOffset = offset;
  1430. // Consume a name, and let string be the result.
  1431. offset = consumeName$1(source, offset);
  1432. // If string’s value is an ASCII case-insensitive match for "url",
  1433. // and the next input code point is U+0028 LEFT PARENTHESIS ((), consume it.
  1434. if (cmpStr$2(source, nameStartOffset, offset, 'url') && getCharCode(offset) === 0x0028) {
  1435. // While the next two input code points are whitespace, consume the next input code point.
  1436. offset = findWhiteSpaceEnd$1(source, offset + 1);
  1437. // If the next one or two input code points are U+0022 QUOTATION MARK ("), U+0027 APOSTROPHE ('),
  1438. // or whitespace followed by U+0022 QUOTATION MARK (") or U+0027 APOSTROPHE ('),
  1439. // then create a <function-token> with its value set to string and return it.
  1440. if (getCharCode(offset) === 0x0022 ||
  1441. getCharCode(offset) === 0x0027) {
  1442. type = TYPE$2.Function;
  1443. offset = nameStartOffset + 4;
  1444. return;
  1445. }
  1446. // Otherwise, consume a url token, and return it.
  1447. consumeUrlToken();
  1448. return;
  1449. }
  1450. // Otherwise, if the next input code point is U+0028 LEFT PARENTHESIS ((), consume it.
  1451. // Create a <function-token> with its value set to string and return it.
  1452. if (getCharCode(offset) === 0x0028) {
  1453. type = TYPE$2.Function;
  1454. offset++;
  1455. return;
  1456. }
  1457. // Otherwise, create an <ident-token> with its value set to string and return it.
  1458. type = TYPE$2.Ident;
  1459. }
  1460. // § 4.3.5. Consume a string token
  1461. function consumeStringToken(endingCodePoint) {
  1462. // This algorithm may be called with an ending code point, which denotes the code point
  1463. // that ends the string. If an ending code point is not specified,
  1464. // the current input code point is used.
  1465. if (!endingCodePoint) {
  1466. endingCodePoint = getCharCode(offset++);
  1467. }
  1468. // Initially create a <string-token> with its value set to the empty string.
  1469. type = TYPE$2.String;
  1470. // Repeatedly consume the next input code point from the stream:
  1471. for (; offset < source.length; offset++) {
  1472. var code = source.charCodeAt(offset);
  1473. switch (charCodeCategory$1(code)) {
  1474. // ending code point
  1475. case endingCodePoint:
  1476. // Return the <string-token>.
  1477. offset++;
  1478. return;
  1479. // EOF
  1480. case charCodeCategory$1.Eof:
  1481. // This is a parse error. Return the <string-token>.
  1482. return;
  1483. // newline
  1484. case charCodeCategory$1.WhiteSpace:
  1485. if (isNewline$1(code)) {
  1486. // This is a parse error. Reconsume the current input code point,
  1487. // create a <bad-string-token>, and return it.
  1488. offset += getNewlineLength$1(source, offset, code);
  1489. type = TYPE$2.BadString;
  1490. return;
  1491. }
  1492. break;
  1493. // U+005C REVERSE SOLIDUS (\)
  1494. case 0x005C:
  1495. // If the next input code point is EOF, do nothing.
  1496. if (offset === source.length - 1) {
  1497. break;
  1498. }
  1499. var nextCode = getCharCode(offset + 1);
  1500. // Otherwise, if the next input code point is a newline, consume it.
  1501. if (isNewline$1(nextCode)) {
  1502. offset += getNewlineLength$1(source, offset + 1, nextCode);
  1503. } else if (isValidEscape$2(code, nextCode)) {
  1504. // Otherwise, (the stream starts with a valid escape) consume
  1505. // an escaped code point and append the returned code point to
  1506. // the <string-token>’s value.
  1507. offset = consumeEscaped$1(source, offset) - 1;
  1508. }
  1509. break;
  1510. // anything else
  1511. // Append the current input code point to the <string-token>’s value.
  1512. }
  1513. }
  1514. }
  1515. // § 4.3.6. Consume a url token
  1516. // Note: This algorithm assumes that the initial "url(" has already been consumed.
  1517. // This algorithm also assumes that it’s being called to consume an "unquoted" value, like url(foo).
  1518. // A quoted value, like url("foo"), is parsed as a <function-token>. Consume an ident-like token
  1519. // automatically handles this distinction; this algorithm shouldn’t be called directly otherwise.
  1520. function consumeUrlToken() {
  1521. // Initially create a <url-token> with its value set to the empty string.
  1522. type = TYPE$2.Url;
  1523. // Consume as much whitespace as possible.
  1524. offset = findWhiteSpaceEnd$1(source, offset);
  1525. // Repeatedly consume the next input code point from the stream:
  1526. for (; offset < source.length; offset++) {
  1527. var code = source.charCodeAt(offset);
  1528. switch (charCodeCategory$1(code)) {
  1529. // U+0029 RIGHT PARENTHESIS ())
  1530. case 0x0029:
  1531. // Return the <url-token>.
  1532. offset++;
  1533. return;
  1534. // EOF
  1535. case charCodeCategory$1.Eof:
  1536. // This is a parse error. Return the <url-token>.
  1537. return;
  1538. // whitespace
  1539. case charCodeCategory$1.WhiteSpace:
  1540. // Consume as much whitespace as possible.
  1541. offset = findWhiteSpaceEnd$1(source, offset);
  1542. // If the next input code point is U+0029 RIGHT PARENTHESIS ()) or EOF,
  1543. // consume it and return the <url-token>
  1544. // (if EOF was encountered, this is a parse error);
  1545. if (getCharCode(offset) === 0x0029 || offset >= source.length) {
  1546. if (offset < source.length) {
  1547. offset++;
  1548. }
  1549. return;
  1550. }
  1551. // otherwise, consume the remnants of a bad url, create a <bad-url-token>,
  1552. // and return it.
  1553. offset = consumeBadUrlRemnants$1(source, offset);
  1554. type = TYPE$2.BadUrl;
  1555. return;
  1556. // U+0022 QUOTATION MARK (")
  1557. // U+0027 APOSTROPHE (')
  1558. // U+0028 LEFT PARENTHESIS (()
  1559. // non-printable code point
  1560. case 0x0022:
  1561. case 0x0027:
  1562. case 0x0028:
  1563. case charCodeCategory$1.NonPrintable:
  1564. // This is a parse error. Consume the remnants of a bad url,
  1565. // create a <bad-url-token>, and return it.
  1566. offset = consumeBadUrlRemnants$1(source, offset);
  1567. type = TYPE$2.BadUrl;
  1568. return;
  1569. // U+005C REVERSE SOLIDUS (\)
  1570. case 0x005C:
  1571. // If the stream starts with a valid escape, consume an escaped code point and
  1572. // append the returned code point to the <url-token>’s value.
  1573. if (isValidEscape$2(code, getCharCode(offset + 1))) {
  1574. offset = consumeEscaped$1(source, offset) - 1;
  1575. break;
  1576. }
  1577. // Otherwise, this is a parse error. Consume the remnants of a bad url,
  1578. // create a <bad-url-token>, and return it.
  1579. offset = consumeBadUrlRemnants$1(source, offset);
  1580. type = TYPE$2.BadUrl;
  1581. return;
  1582. // anything else
  1583. // Append the current input code point to the <url-token>’s value.
  1584. }
  1585. }
  1586. }
  1587. if (!stream) {
  1588. stream = new TokenStream_1();
  1589. }
  1590. // ensure source is a string
  1591. source = String(source || '');
  1592. var sourceLength = source.length;
  1593. var offsetAndType = adoptBuffer(stream.offsetAndType, sourceLength + 1); // +1 because of eof-token
  1594. var balance = adoptBuffer(stream.balance, sourceLength + 1);
  1595. var tokenCount = 0;
  1596. var start = isBOM$1(getCharCode(0));
  1597. var offset = start;
  1598. var balanceCloseType = 0;
  1599. var balanceStart = 0;
  1600. var balancePrev = 0;
  1601. // https://drafts.csswg.org/css-syntax-3/#consume-token
  1602. // § 4.3.1. Consume a token
  1603. while (offset < sourceLength) {
  1604. var code = source.charCodeAt(offset);
  1605. var type = 0;
  1606. balance[tokenCount] = sourceLength;
  1607. switch (charCodeCategory$1(code)) {
  1608. // whitespace
  1609. case charCodeCategory$1.WhiteSpace:
  1610. // Consume as much whitespace as possible. Return a <whitespace-token>.
  1611. type = TYPE$2.WhiteSpace;
  1612. offset = findWhiteSpaceEnd$1(source, offset + 1);
  1613. break;
  1614. // U+0022 QUOTATION MARK (")
  1615. case 0x0022:
  1616. // Consume a string token and return it.
  1617. consumeStringToken();
  1618. break;
  1619. // U+0023 NUMBER SIGN (#)
  1620. case 0x0023:
  1621. // If the next input code point is a name code point or the next two input code points are a valid escape, then:
  1622. if (isName$2(getCharCode(offset + 1)) || isValidEscape$2(getCharCode(offset + 1), getCharCode(offset + 2))) {
  1623. // Create a <hash-token>.
  1624. type = TYPE$2.Hash;
  1625. // If the next 3 input code points would start an identifier, set the <hash-token>’s type flag to "id".
  1626. // if (isIdentifierStart(getCharCode(offset + 1), getCharCode(offset + 2), getCharCode(offset + 3))) {
  1627. // // TODO: set id flag
  1628. // }
  1629. // Consume a name, and set the <hash-token>’s value to the returned string.
  1630. offset = consumeName$1(source, offset + 1);
  1631. // Return the <hash-token>.
  1632. } else {
  1633. // Otherwise, return a <delim-token> with its value set to the current input code point.
  1634. type = TYPE$2.Delim;
  1635. offset++;
  1636. }
  1637. break;
  1638. // U+0027 APOSTROPHE (')
  1639. case 0x0027:
  1640. // Consume a string token and return it.
  1641. consumeStringToken();
  1642. break;
  1643. // U+0028 LEFT PARENTHESIS (()
  1644. case 0x0028:
  1645. // Return a <(-token>.
  1646. type = TYPE$2.LeftParenthesis;
  1647. offset++;
  1648. break;
  1649. // U+0029 RIGHT PARENTHESIS ())
  1650. case 0x0029:
  1651. // Return a <)-token>.
  1652. type = TYPE$2.RightParenthesis;
  1653. offset++;
  1654. break;
  1655. // U+002B PLUS SIGN (+)
  1656. case 0x002B:
  1657. // If the input stream starts with a number, ...
  1658. if (isNumberStart$1(code, getCharCode(offset + 1), getCharCode(offset + 2))) {
  1659. // ... reconsume the current input code point, consume a numeric token, and return it.
  1660. consumeNumericToken();
  1661. } else {
  1662. // Otherwise, return a <delim-token> with its value set to the current input code point.
  1663. type = TYPE$2.Delim;
  1664. offset++;
  1665. }
  1666. break;
  1667. // U+002C COMMA (,)
  1668. case 0x002C:
  1669. // Return a <comma-token>.
  1670. type = TYPE$2.Comma;
  1671. offset++;
  1672. break;
  1673. // U+002D HYPHEN-MINUS (-)
  1674. case 0x002D:
  1675. // If the input stream starts with a number, reconsume the current input code point, consume a numeric token, and return it.
  1676. if (isNumberStart$1(code, getCharCode(offset + 1), getCharCode(offset + 2))) {
  1677. consumeNumericToken();
  1678. } else {
  1679. // Otherwise, if the next 2 input code points are U+002D HYPHEN-MINUS U+003E GREATER-THAN SIGN (->), consume them and return a <CDC-token>.
  1680. if (getCharCode(offset + 1) === 0x002D &&
  1681. getCharCode(offset + 2) === 0x003E) {
  1682. type = TYPE$2.CDC;
  1683. offset = offset + 3;
  1684. } else {
  1685. // Otherwise, if the input stream starts with an identifier, ...
  1686. if (isIdentifierStart$1(code, getCharCode(offset + 1), getCharCode(offset + 2))) {
  1687. // ... reconsume the current input code point, consume an ident-like token, and return it.
  1688. consumeIdentLikeToken();
  1689. } else {
  1690. // Otherwise, return a <delim-token> with its value set to the current input code point.
  1691. type = TYPE$2.Delim;
  1692. offset++;
  1693. }
  1694. }
  1695. }
  1696. break;
  1697. // U+002E FULL STOP (.)
  1698. case 0x002E:
  1699. // If the input stream starts with a number, ...
  1700. if (isNumberStart$1(code, getCharCode(offset + 1), getCharCode(offset + 2))) {
  1701. // ... reconsume the current input code point, consume a numeric token, and return it.
  1702. consumeNumericToken();
  1703. } else {
  1704. // Otherwise, return a <delim-token> with its value set to the current input code point.
  1705. type = TYPE$2.Delim;
  1706. offset++;
  1707. }
  1708. break;
  1709. // U+002F SOLIDUS (/)
  1710. case 0x002F:
  1711. // If the next two input code point are U+002F SOLIDUS (/) followed by a U+002A ASTERISK (*),
  1712. if (getCharCode(offset + 1) === 0x002A) {
  1713. // ... consume them and all following code points up to and including the first U+002A ASTERISK (*)
  1714. // followed by a U+002F SOLIDUS (/), or up to an EOF code point.
  1715. type = TYPE$2.Comment;
  1716. offset = source.indexOf('*/', offset + 2) + 2;
  1717. if (offset === 1) {
  1718. offset = source.length;
  1719. }
  1720. } else {
  1721. type = TYPE$2.Delim;
  1722. offset++;
  1723. }
  1724. break;
  1725. // U+003A COLON (:)
  1726. case 0x003A:
  1727. // Return a <colon-token>.
  1728. type = TYPE$2.Colon;
  1729. offset++;
  1730. break;
  1731. // U+003B SEMICOLON (;)
  1732. case 0x003B:
  1733. // Return a <semicolon-token>.
  1734. type = TYPE$2.Semicolon;
  1735. offset++;
  1736. break;
  1737. // U+003C LESS-THAN SIGN (<)
  1738. case 0x003C:
  1739. // If the next 3 input code points are U+0021 EXCLAMATION MARK U+002D HYPHEN-MINUS U+002D HYPHEN-MINUS (!--), ...
  1740. if (getCharCode(offset + 1) === 0x0021 &&
  1741. getCharCode(offset + 2) === 0x002D &&
  1742. getCharCode(offset + 3) === 0x002D) {
  1743. // ... consume them and return a <CDO-token>.
  1744. type = TYPE$2.CDO;
  1745. offset = offset + 4;
  1746. } else {
  1747. // Otherwise, return a <delim-token> with its value set to the current input code point.
  1748. type = TYPE$2.Delim;
  1749. offset++;
  1750. }
  1751. break;
  1752. // U+0040 COMMERCIAL AT (@)
  1753. case 0x0040:
  1754. // If the next 3 input code points would start an identifier, ...
  1755. if (isIdentifierStart$1(getCharCode(offset + 1), getCharCode(offset + 2), getCharCode(offset + 3))) {
  1756. // ... consume a name, create an <at-keyword-token> with its value set to the returned value, and return it.
  1757. type = TYPE$2.AtKeyword;
  1758. offset = consumeName$1(source, offset + 1);
  1759. } else {
  1760. // Otherwise, return a <delim-token> with its value set to the current input code point.
  1761. type = TYPE$2.Delim;
  1762. offset++;
  1763. }
  1764. break;
  1765. // U+005B LEFT SQUARE BRACKET ([)
  1766. case 0x005B:
  1767. // Return a <[-token>.
  1768. type = TYPE$2.LeftSquareBracket;
  1769. offset++;
  1770. break;
  1771. // U+005C REVERSE SOLIDUS (\)
  1772. case 0x005C:
  1773. // If the input stream starts with a valid escape, ...
  1774. if (isValidEscape$2(code, getCharCode(offset + 1))) {
  1775. // ... reconsume the current input code point, consume an ident-like token, and return it.
  1776. consumeIdentLikeToken();
  1777. } else {
  1778. // Otherwise, this is a parse error. Return a <delim-token> with its value set to the current input code point.
  1779. type = TYPE$2.Delim;
  1780. offset++;
  1781. }
  1782. break;
  1783. // U+005D RIGHT SQUARE BRACKET (])
  1784. case 0x005D:
  1785. // Return a <]-token>.
  1786. type = TYPE$2.RightSquareBracket;
  1787. offset++;
  1788. break;
  1789. // U+007B LEFT CURLY BRACKET ({)
  1790. case 0x007B:
  1791. // Return a <{-token>.
  1792. type = TYPE$2.LeftCurlyBracket;
  1793. offset++;
  1794. break;
  1795. // U+007D RIGHT CURLY BRACKET (})
  1796. case 0x007D:
  1797. // Return a <}-token>.
  1798. type = TYPE$2.RightCurlyBracket;
  1799. offset++;
  1800. break;
  1801. // digit
  1802. case charCodeCategory$1.Digit:
  1803. // Reconsume the current input code point, consume a numeric token, and return it.
  1804. consumeNumericToken();
  1805. break;
  1806. // name-start code point
  1807. case charCodeCategory$1.NameStart:
  1808. // Reconsume the current input code point, consume an ident-like token, and return it.
  1809. consumeIdentLikeToken();
  1810. break;
  1811. // EOF
  1812. case charCodeCategory$1.Eof:
  1813. // Return an <EOF-token>.
  1814. break;
  1815. // anything else
  1816. default:
  1817. // Return a <delim-token> with its value set to the current input code point.
  1818. type = TYPE$2.Delim;
  1819. offset++;
  1820. }
  1821. switch (type) {
  1822. case balanceCloseType:
  1823. balancePrev = balanceStart & OFFSET_MASK$1;
  1824. balanceStart = balance[balancePrev];
  1825. balanceCloseType = balanceStart >> TYPE_SHIFT$1;
  1826. balance[tokenCount] = balancePrev;
  1827. balance[balancePrev++] = tokenCount;
  1828. for (; balancePrev < tokenCount; balancePrev++) {
  1829. if (balance[balancePrev] === sourceLength) {
  1830. balance[balancePrev] = tokenCount;
  1831. }
  1832. }
  1833. break;
  1834. case TYPE$2.LeftParenthesis:
  1835. case TYPE$2.Function:
  1836. balance[tokenCount] = balanceStart;
  1837. balanceCloseType = TYPE$2.RightParenthesis;
  1838. balanceStart = (balanceCloseType << TYPE_SHIFT$1) | tokenCount;
  1839. break;
  1840. case TYPE$2.LeftSquareBracket:
  1841. balance[tokenCount] = balanceStart;
  1842. balanceCloseType = TYPE$2.RightSquareBracket;
  1843. balanceStart = (balanceCloseType << TYPE_SHIFT$1) | tokenCount;
  1844. break;
  1845. case TYPE$2.LeftCurlyBracket:
  1846. balance[tokenCount] = balanceStart;
  1847. balanceCloseType = TYPE$2.RightCurlyBracket;
  1848. balanceStart = (balanceCloseType << TYPE_SHIFT$1) | tokenCount;
  1849. break;
  1850. }
  1851. offsetAndType[tokenCount++] = (type << TYPE_SHIFT$1) | offset;
  1852. }
  1853. // finalize buffers
  1854. offsetAndType[tokenCount] = (TYPE$2.EOF << TYPE_SHIFT$1) | offset; // <EOF-token>
  1855. balance[tokenCount] = sourceLength;
  1856. balance[sourceLength] = sourceLength; // prevents false positive balance match with any token
  1857. while (balanceStart !== 0) {
  1858. balancePrev = balanceStart & OFFSET_MASK$1;
  1859. balanceStart = balance[balancePrev];
  1860. balance[balancePrev] = sourceLength;
  1861. }
  1862. // update stream
  1863. stream.source = source;
  1864. stream.firstCharOffset = start;
  1865. stream.offsetAndType = offsetAndType;
  1866. stream.tokenCount = tokenCount;
  1867. stream.balance = balance;
  1868. stream.reset();
  1869. stream.next();
  1870. return stream;
  1871. }
  1872. // extend tokenizer with constants
  1873. Object.keys(_const).forEach(function(key) {
  1874. tokenize[key] = _const[key];
  1875. });
  1876. // extend tokenizer with static methods from utils
  1877. Object.keys(charCodeDefinitions).forEach(function(key) {
  1878. tokenize[key] = charCodeDefinitions[key];
  1879. });
  1880. Object.keys(utils).forEach(function(key) {
  1881. tokenize[key] = utils[key];
  1882. });
  1883. var tokenizer = tokenize;
  1884. var isDigit$2 = tokenizer.isDigit;
  1885. var cmpChar$1 = tokenizer.cmpChar;
  1886. var TYPE$3 = tokenizer.TYPE;
  1887. var DELIM = TYPE$3.Delim;
  1888. var WHITESPACE$1 = TYPE$3.WhiteSpace;
  1889. var COMMENT$1 = TYPE$3.Comment;
  1890. var IDENT = TYPE$3.Ident;
  1891. var NUMBER = TYPE$3.Number;
  1892. var DIMENSION = TYPE$3.Dimension;
  1893. var PLUSSIGN = 0x002B; // U+002B PLUS SIGN (+)
  1894. var HYPHENMINUS$1 = 0x002D; // U+002D HYPHEN-MINUS (-)
  1895. var N = 0x006E; // U+006E LATIN SMALL LETTER N (n)
  1896. var DISALLOW_SIGN = true;
  1897. var ALLOW_SIGN = false;
  1898. function isDelim(token, code) {
  1899. return token !== null && token.type === DELIM && token.value.charCodeAt(0) === code;
  1900. }
  1901. function skipSC(token, offset, getNextToken) {
  1902. while (token !== null && (token.type === WHITESPACE$1 || token.type === COMMENT$1)) {
  1903. token = getNextToken(++offset);
  1904. }
  1905. return offset;
  1906. }
  1907. function checkInteger(token, valueOffset, disallowSign, offset) {
  1908. if (!token) {
  1909. return 0;
  1910. }
  1911. var code = token.value.charCodeAt(valueOffset);
  1912. if (code === PLUSSIGN || code === HYPHENMINUS$1) {
  1913. if (disallowSign) {
  1914. // Number sign is not allowed
  1915. return 0;
  1916. }
  1917. valueOffset++;
  1918. }
  1919. for (; valueOffset < token.value.length; valueOffset++) {
  1920. if (!isDigit$2(token.value.charCodeAt(valueOffset))) {
  1921. // Integer is expected
  1922. return 0;
  1923. }
  1924. }
  1925. return offset + 1;
  1926. }
  1927. // ... <signed-integer>
  1928. // ... ['+' | '-'] <signless-integer>
  1929. function consumeB(token, offset_, getNextToken) {
  1930. var sign = false;
  1931. var offset = skipSC(token, offset_, getNextToken);
  1932. token = getNextToken(offset);
  1933. if (token === null) {
  1934. return offset_;
  1935. }
  1936. if (token.type !== NUMBER) {
  1937. if (isDelim(token, PLUSSIGN) || isDelim(token, HYPHENMINUS$1)) {
  1938. sign = true;
  1939. offset = skipSC(getNextToken(++offset), offset, getNextToken);
  1940. token = getNextToken(offset);
  1941. if (token === null && token.type !== NUMBER) {
  1942. return 0;
  1943. }
  1944. } else {
  1945. return offset_;
  1946. }
  1947. }
  1948. if (!sign) {
  1949. var code = token.value.charCodeAt(0);
  1950. if (code !== PLUSSIGN && code !== HYPHENMINUS$1) {
  1951. // Number sign is expected
  1952. return 0;
  1953. }
  1954. }
  1955. return checkInteger(token, sign ? 0 : 1, sign, offset);
  1956. }
  1957. // An+B microsyntax https://www.w3.org/TR/css-syntax-3/#anb
  1958. var genericAnPlusB = function anPlusB(token, getNextToken) {
  1959. /* eslint-disable brace-style*/
  1960. var offset = 0;
  1961. if (!token) {
  1962. return 0;
  1963. }
  1964. // <integer>
  1965. if (token.type === NUMBER) {
  1966. return checkInteger(token, 0, ALLOW_SIGN, offset); // b
  1967. }
  1968. // -n
  1969. // -n <signed-integer>
  1970. // -n ['+' | '-'] <signless-integer>
  1971. // -n- <signless-integer>
  1972. // <dashndashdigit-ident>
  1973. else if (token.type === IDENT && token.value.charCodeAt(0) === HYPHENMINUS$1) {
  1974. // expect 1st char is N
  1975. if (!cmpChar$1(token.value, 1, N)) {
  1976. return 0;
  1977. }
  1978. switch (token.value.length) {
  1979. // -n
  1980. // -n <signed-integer>
  1981. // -n ['+' | '-'] <signless-integer>
  1982. case 2:
  1983. return consumeB(getNextToken(++offset), offset, getNextToken);
  1984. // -n- <signless-integer>
  1985. case 3:
  1986. if (token.value.charCodeAt(2) !== HYPHENMINUS$1) {
  1987. return 0;
  1988. }
  1989. offset = skipSC(getNextToken(++offset), offset, getNextToken);
  1990. token = getNextToken(offset);
  1991. return checkInteger(token, 0, DISALLOW_SIGN, offset);
  1992. // <dashndashdigit-ident>
  1993. default:
  1994. if (token.value.charCodeAt(2) !== HYPHENMINUS$1) {
  1995. return 0;
  1996. }
  1997. return checkInteger(token, 3, DISALLOW_SIGN, offset);
  1998. }
  1999. }
  2000. // '+'? n
  2001. // '+'? n <signed-integer>
  2002. // '+'? n ['+' | '-'] <signless-integer>
  2003. // '+'? n- <signless-integer>
  2004. // '+'? <ndashdigit-ident>
  2005. else if (token.type === IDENT || (isDelim(token, PLUSSIGN) && getNextToken(offset + 1).type === IDENT)) {
  2006. // just ignore a plus
  2007. if (token.type !== IDENT) {
  2008. token = getNextToken(++offset);
  2009. }
  2010. if (token === null || !cmpChar$1(token.value, 0, N)) {
  2011. return 0;
  2012. }
  2013. switch (token.value.length) {
  2014. // '+'? n
  2015. // '+'? n <signed-integer>
  2016. // '+'? n ['+' | '-'] <signless-integer>
  2017. case 1:
  2018. return consumeB(getNextToken(++offset), offset, getNextToken);
  2019. // '+'? n- <signless-integer>
  2020. case 2:
  2021. if (token.value.charCodeAt(1) !== HYPHENMINUS$1) {
  2022. return 0;
  2023. }
  2024. offset = skipSC(getNextToken(++offset), offset, getNextToken);
  2025. token = getNextToken(offset);
  2026. return checkInteger(token, 0, DISALLOW_SIGN, offset);
  2027. // '+'? <ndashdigit-ident>
  2028. default:
  2029. if (token.value.charCodeAt(1) !== HYPHENMINUS$1) {
  2030. return 0;
  2031. }
  2032. return checkInteger(token, 2, DISALLOW_SIGN, offset);
  2033. }
  2034. }
  2035. // <ndashdigit-dimension>
  2036. // <ndash-dimension> <signless-integer>
  2037. // <n-dimension>
  2038. // <n-dimension> <signed-integer>
  2039. // <n-dimension> ['+' | '-'] <signless-integer>
  2040. else if (token.type === DIMENSION) {
  2041. var code = token.value.charCodeAt(0);
  2042. var sign = code === PLUSSIGN || code === HYPHENMINUS$1 ? 1 : 0;
  2043. for (var i = sign; i < token.value.length; i++) {
  2044. if (!isDigit$2(token.value.charCodeAt(i))) {
  2045. break;
  2046. }
  2047. }
  2048. if (i === sign) {
  2049. // Integer is expected
  2050. return 0;
  2051. }
  2052. if (!cmpChar$1(token.value, i, N)) {
  2053. return 0;
  2054. }
  2055. // <n-dimension>
  2056. // <n-dimension> <signed-integer>
  2057. // <n-dimension> ['+' | '-'] <signless-integer>
  2058. if (i + 1 === token.value.length) {
  2059. return consumeB(getNextToken(++offset), offset, getNextToken);
  2060. } else {
  2061. if (token.value.charCodeAt(i + 1) !== HYPHENMINUS$1) {
  2062. return 0;
  2063. }
  2064. // <ndash-dimension> <signless-integer>
  2065. if (i + 2 === token.value.length) {
  2066. offset = skipSC(getNextToken(++offset), offset, getNextToken);
  2067. token = getNextToken(offset);
  2068. return checkInteger(token, 0, DISALLOW_SIGN, offset);
  2069. }
  2070. // <ndashdigit-dimension>
  2071. else {
  2072. return checkInteger(token, i + 2, DISALLOW_SIGN, offset);
  2073. }
  2074. }
  2075. }
  2076. return 0;
  2077. };
  2078. var isHexDigit$2 = tokenizer.isHexDigit;
  2079. var cmpChar$2 = tokenizer.cmpChar;
  2080. var TYPE$4 = tokenizer.TYPE;
  2081. var IDENT$1 = TYPE$4.Ident;
  2082. var DELIM$1 = TYPE$4.Delim;
  2083. var NUMBER$1 = TYPE$4.Number;
  2084. var DIMENSION$1 = TYPE$4.Dimension;
  2085. var PLUSSIGN$1 = 0x002B; // U+002B PLUS SIGN (+)
  2086. var HYPHENMINUS$2 = 0x002D; // U+002D HYPHEN-MINUS (-)
  2087. var QUESTIONMARK = 0x003F; // U+003F QUESTION MARK (?)
  2088. var U = 0x0075; // U+0075 LATIN SMALL LETTER U (u)
  2089. function isDelim$1(token, code) {
  2090. return token !== null && token.type === DELIM$1 && token.value.charCodeAt(0) === code;
  2091. }
  2092. function startsWith(token, code) {
  2093. return token.value.charCodeAt(0) === code;
  2094. }
  2095. function hexSequence(token, offset, allowDash) {
  2096. for (var pos = offset, hexlen = 0; pos < token.value.length; pos++) {
  2097. var code = token.value.charCodeAt(pos);
  2098. if (code === HYPHENMINUS$2 && allowDash && hexlen !== 0) {
  2099. if (hexSequence(token, offset + hexlen + 1, false) > 0) {
  2100. return 6; // dissallow following question marks
  2101. }
  2102. return 0; // dash at the ending of a hex sequence is not allowed
  2103. }
  2104. if (!isHexDigit$2(code)) {
  2105. return 0; // not a hex digit
  2106. }
  2107. if (++hexlen > 6) {
  2108. return 0; // too many hex digits
  2109. } }
  2110. return hexlen;
  2111. }
  2112. function withQuestionMarkSequence(consumed, length, getNextToken) {
  2113. if (!consumed) {
  2114. return 0; // nothing consumed
  2115. }
  2116. while (isDelim$1(getNextToken(length), QUESTIONMARK)) {
  2117. if (++consumed > 6) {
  2118. return 0; // too many question marks
  2119. }
  2120. length++;
  2121. }
  2122. return length;
  2123. }
  2124. // https://drafts.csswg.org/css-syntax/#urange
  2125. // Informally, the <urange> production has three forms:
  2126. // U+0001
  2127. // Defines a range consisting of a single code point, in this case the code point "1".
  2128. // U+0001-00ff
  2129. // Defines a range of codepoints between the first and the second value, in this case
  2130. // the range between "1" and "ff" (255 in decimal) inclusive.
  2131. // U+00??
  2132. // Defines a range of codepoints where the "?" characters range over all hex digits,
  2133. // in this case defining the same as the value U+0000-00ff.
  2134. // In each form, a maximum of 6 digits is allowed for each hexadecimal number (if you treat "?" as a hexadecimal digit).
  2135. //
  2136. // <urange> =
  2137. // u '+' <ident-token> '?'* |
  2138. // u <dimension-token> '?'* |
  2139. // u <number-token> '?'* |
  2140. // u <number-token> <dimension-token> |
  2141. // u <number-token> <number-token> |
  2142. // u '+' '?'+
  2143. var genericUrange = function urange(token, getNextToken) {
  2144. var length = 0;
  2145. // should start with `u` or `U`
  2146. if (token === null || token.type !== IDENT$1 || !cmpChar$2(token.value, 0, U)) {
  2147. return 0;
  2148. }
  2149. token = getNextToken(++length);
  2150. if (token === null) {
  2151. return 0;
  2152. }
  2153. // u '+' <ident-token> '?'*
  2154. // u '+' '?'+
  2155. if (isDelim$1(token, PLUSSIGN$1)) {
  2156. token = getNextToken(++length);
  2157. if (token === null) {
  2158. return 0;
  2159. }
  2160. if (token.type === IDENT$1) {
  2161. // u '+' <ident-token> '?'*
  2162. return withQuestionMarkSequence(hexSequence(token, 0, true), ++length, getNextToken);
  2163. }
  2164. if (isDelim$1(token, QUESTIONMARK)) {
  2165. // u '+' '?'+
  2166. return withQuestionMarkSequence(1, ++length, getNextToken);
  2167. }
  2168. // Hex digit or question mark is expected
  2169. return 0;
  2170. }
  2171. // u <number-token> '?'*
  2172. // u <number-token> <dimension-token>
  2173. // u <number-token> <number-token>
  2174. if (token.type === NUMBER$1) {
  2175. if (!startsWith(token, PLUSSIGN$1)) {
  2176. return 0;
  2177. }
  2178. var consumedHexLength = hexSequence(token, 1, true);
  2179. if (consumedHexLength === 0) {
  2180. return 0;
  2181. }
  2182. token = getNextToken(++length);
  2183. if (token === null) {
  2184. // u <number-token> <eof>
  2185. return length;
  2186. }
  2187. if (token.type === DIMENSION$1 || token.type === NUMBER$1) {
  2188. // u <number-token> <dimension-token>
  2189. // u <number-token> <number-token>
  2190. if (!startsWith(token, HYPHENMINUS$2) || !hexSequence(token, 1, false)) {
  2191. return 0;
  2192. }
  2193. return length + 1;
  2194. }
  2195. // u <number-token> '?'*
  2196. return withQuestionMarkSequence(consumedHexLength, length, getNextToken);
  2197. }
  2198. // u <dimension-token> '?'*
  2199. if (token.type === DIMENSION$1) {
  2200. if (!startsWith(token, PLUSSIGN$1)) {
  2201. return 0;
  2202. }
  2203. return withQuestionMarkSequence(hexSequence(token, 1, true), ++length, getNextToken);
  2204. }
  2205. return 0;
  2206. };
  2207. var isIdentifierStart$2 = tokenizer.isIdentifierStart;
  2208. var isHexDigit$3 = tokenizer.isHexDigit;
  2209. var isDigit$3 = tokenizer.isDigit;
  2210. var cmpStr$3 = tokenizer.cmpStr;
  2211. var consumeNumber$2 = tokenizer.consumeNumber;
  2212. var TYPE$5 = tokenizer.TYPE;
  2213. var cssWideKeywords = ['unset', 'initial', 'inherit'];
  2214. var calcFunctionNames = ['calc(', '-moz-calc(', '-webkit-calc('];
  2215. // https://www.w3.org/TR/css-values-3/#lengths
  2216. var LENGTH = {
  2217. // absolute length units
  2218. 'px': true,
  2219. 'mm': true,
  2220. 'cm': true,
  2221. 'in': true,
  2222. 'pt': true,
  2223. 'pc': true,
  2224. 'q': true,
  2225. // relative length units
  2226. 'em': true,
  2227. 'ex': true,
  2228. 'ch': true,
  2229. 'rem': true,
  2230. // viewport-percentage lengths
  2231. 'vh': true,
  2232. 'vw': true,
  2233. 'vmin': true,
  2234. 'vmax': true,
  2235. 'vm': true
  2236. };
  2237. var ANGLE = {
  2238. 'deg': true,
  2239. 'grad': true,
  2240. 'rad': true,
  2241. 'turn': true
  2242. };
  2243. var TIME = {
  2244. 's': true,
  2245. 'ms': true
  2246. };
  2247. var FREQUENCY = {
  2248. 'hz': true,
  2249. 'khz': true
  2250. };
  2251. // https://www.w3.org/TR/css-values-3/#resolution (https://drafts.csswg.org/css-values/#resolution)
  2252. var RESOLUTION = {
  2253. 'dpi': true,
  2254. 'dpcm': true,
  2255. 'dppx': true,
  2256. 'x': true // https://github.com/w3c/csswg-drafts/issues/461
  2257. };
  2258. // https://drafts.csswg.org/css-grid/#fr-unit
  2259. var FLEX = {
  2260. 'fr': true
  2261. };
  2262. // https://www.w3.org/TR/css3-speech/#mixing-props-voice-volume
  2263. var DECIBEL = {
  2264. 'db': true
  2265. };
  2266. // https://www.w3.org/TR/css3-speech/#voice-props-voice-pitch
  2267. var SEMITONES = {
  2268. 'st': true
  2269. };
  2270. // safe char code getter
  2271. function charCode(str, index) {
  2272. return index < str.length ? str.charCodeAt(index) : 0;
  2273. }
  2274. function eqStr(actual, expected) {
  2275. return cmpStr$3(actual, 0, actual.length, expected);
  2276. }
  2277. function eqStrAny(actual, expected) {
  2278. for (var i = 0; i < expected.length; i++) {
  2279. if (eqStr(actual, expected[i])) {
  2280. return true;
  2281. }
  2282. }
  2283. return false;
  2284. }
  2285. // IE postfix hack, i.e. 123\0 or 123px\9
  2286. function isPostfixIeHack(str, offset) {
  2287. if (offset !== str.length - 2) {
  2288. return false;
  2289. }
  2290. return (
  2291. str.charCodeAt(offset) === 0x005C && // U+005C REVERSE SOLIDUS (\)
  2292. isDigit$3(str.charCodeAt(offset + 1))
  2293. );
  2294. }
  2295. function outOfRange(opts, value, numEnd) {
  2296. if (opts && opts.type === 'Range') {
  2297. var num = Number(
  2298. numEnd !== undefined && numEnd !== value.length
  2299. ? value.substr(0, numEnd)
  2300. : value
  2301. );
  2302. if (isNaN(num)) {
  2303. return true;
  2304. }
  2305. if (opts.min !== null && num < opts.min) {
  2306. return true;
  2307. }
  2308. if (opts.max !== null && num > opts.max) {
  2309. return true;
  2310. }
  2311. }
  2312. return false;
  2313. }
  2314. function consumeFunction(token, getNextToken) {
  2315. var startIdx = token.index;
  2316. var length = 0;
  2317. // balanced token consuming
  2318. do {
  2319. length++;
  2320. if (token.balance <= startIdx) {
  2321. break;
  2322. }
  2323. } while (token = getNextToken(length));
  2324. return length;
  2325. }
  2326. // TODO: implement
  2327. // can be used wherever <length>, <frequency>, <angle>, <time>, <percentage>, <number>, or <integer> values are allowed
  2328. // https://drafts.csswg.org/css-values/#calc-notation
  2329. function calc(next) {
  2330. return function(token, getNextToken, opts) {
  2331. if (token === null) {
  2332. return 0;
  2333. }
  2334. if (token.type === TYPE$5.Function && eqStrAny(token.value, calcFunctionNames)) {
  2335. return consumeFunction(token, getNextToken);
  2336. }
  2337. return next(token, getNextToken, opts);
  2338. };
  2339. }
  2340. function tokenType(expectedTokenType) {
  2341. return function(token) {
  2342. if (token === null || token.type !== expectedTokenType) {
  2343. return 0;
  2344. }
  2345. return 1;
  2346. };
  2347. }
  2348. function func(name) {
  2349. name = name + '(';
  2350. return function(token, getNextToken) {
  2351. if (token !== null && eqStr(token.value, name)) {
  2352. return consumeFunction(token, getNextToken);
  2353. }
  2354. return 0;
  2355. };
  2356. }
  2357. // =========================
  2358. // Complex types
  2359. //
  2360. // https://drafts.csswg.org/css-values-4/#custom-idents
  2361. // 4.2. Author-defined Identifiers: the <custom-ident> type
  2362. // Some properties accept arbitrary author-defined identifiers as a component value.
  2363. // This generic data type is denoted by <custom-ident>, and represents any valid CSS identifier
  2364. // that would not be misinterpreted as a pre-defined keyword in that property’s value definition.
  2365. //
  2366. // See also: https://developer.mozilla.org/en-US/docs/Web/CSS/custom-ident
  2367. function customIdent(token) {
  2368. if (token === null || token.type !== TYPE$5.Ident) {
  2369. return 0;
  2370. }
  2371. var name = token.value.toLowerCase();
  2372. // The CSS-wide keywords are not valid <custom-ident>s
  2373. if (eqStrAny(name, cssWideKeywords)) {
  2374. return 0;
  2375. }
  2376. // The default keyword is reserved and is also not a valid <custom-ident>
  2377. if (eqStr(name, 'default')) {
  2378. return 0;
  2379. }
  2380. // TODO: ignore property specific keywords (as described https://developer.mozilla.org/en-US/docs/Web/CSS/custom-ident)
  2381. // Specifications using <custom-ident> must specify clearly what other keywords
  2382. // are excluded from <custom-ident>, if any—for example by saying that any pre-defined keywords
  2383. // in that property’s value definition are excluded. Excluded keywords are excluded
  2384. // in all ASCII case permutations.
  2385. return 1;
  2386. }
  2387. // https://drafts.csswg.org/css-variables/#typedef-custom-property-name
  2388. // A custom property is any property whose name starts with two dashes (U+002D HYPHEN-MINUS), like --foo.
  2389. // The <custom-property-name> production corresponds to this: it’s defined as any valid identifier
  2390. // that starts with two dashes, except -- itself, which is reserved for future use by CSS.
  2391. // NOTE: Current implementation treat `--` as a valid name since most (all?) major browsers treat it as valid.
  2392. function customPropertyName(token) {
  2393. // ... defined as any valid identifier
  2394. if (token === null || token.type !== TYPE$5.Ident) {
  2395. return 0;
  2396. }
  2397. // ... that starts with two dashes (U+002D HYPHEN-MINUS)
  2398. if (charCode(token.value, 0) !== 0x002D || charCode(token.value, 1) !== 0x002D) {
  2399. return 0;
  2400. }
  2401. return 1;
  2402. }
  2403. // https://drafts.csswg.org/css-color-4/#hex-notation
  2404. // The syntax of a <hex-color> is a <hash-token> token whose value consists of 3, 4, 6, or 8 hexadecimal digits.
  2405. // In other words, a hex color is written as a hash character, "#", followed by some number of digits 0-9 or
  2406. // letters a-f (the case of the letters doesn’t matter - #00ff00 is identical to #00FF00).
  2407. function hexColor(token) {
  2408. if (token === null || token.type !== TYPE$5.Hash) {
  2409. return 0;
  2410. }
  2411. var length = token.value.length;
  2412. // valid values (length): #rgb (4), #rgba (5), #rrggbb (7), #rrggbbaa (9)
  2413. if (length !== 4 && length !== 5 && length !== 7 && length !== 9) {
  2414. return 0;
  2415. }
  2416. for (var i = 1; i < length; i++) {
  2417. if (!isHexDigit$3(token.value.charCodeAt(i))) {
  2418. return 0;
  2419. }
  2420. }
  2421. return 1;
  2422. }
  2423. function idSelector(token) {
  2424. if (token === null || token.type !== TYPE$5.Hash) {
  2425. return 0;
  2426. }
  2427. if (!isIdentifierStart$2(charCode(token.value, 1), charCode(token.value, 2), charCode(token.value, 3))) {
  2428. return 0;
  2429. }
  2430. return 1;
  2431. }
  2432. // https://drafts.csswg.org/css-syntax/#any-value
  2433. // It represents the entirety of what a valid declaration can have as its value.
  2434. function declarationValue(token, getNextToken) {
  2435. if (!token) {
  2436. return 0;
  2437. }
  2438. var length = 0;
  2439. var level = 0;
  2440. var startIdx = token.index;
  2441. // The <declaration-value> production matches any sequence of one or more tokens,
  2442. // so long as the sequence ...
  2443. scan:
  2444. do {
  2445. switch (token.type) {
  2446. // ... does not contain <bad-string-token>, <bad-url-token>,
  2447. case TYPE$5.BadString:
  2448. case TYPE$5.BadUrl:
  2449. break scan;
  2450. // ... unmatched <)-token>, <]-token>, or <}-token>,
  2451. case TYPE$5.RightCurlyBracket:
  2452. case TYPE$5.RightParenthesis:
  2453. case TYPE$5.RightSquareBracket:
  2454. if (token.balance > token.index || token.balance < startIdx) {
  2455. break scan;
  2456. }
  2457. level--;
  2458. break;
  2459. // ... or top-level <semicolon-token> tokens
  2460. case TYPE$5.Semicolon:
  2461. if (level === 0) {
  2462. break scan;
  2463. }
  2464. break;
  2465. // ... or <delim-token> tokens with a value of "!"
  2466. case TYPE$5.Delim:
  2467. if (token.value === '!' && level === 0) {
  2468. break scan;
  2469. }
  2470. break;
  2471. case TYPE$5.Function:
  2472. case TYPE$5.LeftParenthesis:
  2473. case TYPE$5.LeftSquareBracket:
  2474. case TYPE$5.LeftCurlyBracket:
  2475. level++;
  2476. break;
  2477. }
  2478. length++;
  2479. // until balance closing
  2480. if (token.balance <= startIdx) {
  2481. break;
  2482. }
  2483. } while (token = getNextToken(length));
  2484. return length;
  2485. }
  2486. // https://drafts.csswg.org/css-syntax/#any-value
  2487. // The <any-value> production is identical to <declaration-value>, but also
  2488. // allows top-level <semicolon-token> tokens and <delim-token> tokens
  2489. // with a value of "!". It represents the entirety of what valid CSS can be in any context.
  2490. function anyValue(token, getNextToken) {
  2491. if (!token) {
  2492. return 0;
  2493. }
  2494. var startIdx = token.index;
  2495. var length = 0;
  2496. // The <any-value> production matches any sequence of one or more tokens,
  2497. // so long as the sequence ...
  2498. scan:
  2499. do {
  2500. switch (token.type) {
  2501. // ... does not contain <bad-string-token>, <bad-url-token>,
  2502. case TYPE$5.BadString:
  2503. case TYPE$5.BadUrl:
  2504. break scan;
  2505. // ... unmatched <)-token>, <]-token>, or <}-token>,
  2506. case TYPE$5.RightCurlyBracket:
  2507. case TYPE$5.RightParenthesis:
  2508. case TYPE$5.RightSquareBracket:
  2509. if (token.balance > token.index || token.balance < startIdx) {
  2510. break scan;
  2511. }
  2512. break;
  2513. }
  2514. length++;
  2515. // until balance closing
  2516. if (token.balance <= startIdx) {
  2517. break;
  2518. }
  2519. } while (token = getNextToken(length));
  2520. return length;
  2521. }
  2522. // =========================
  2523. // Dimensions
  2524. //
  2525. function dimension(type) {
  2526. return function(token, getNextToken, opts) {
  2527. if (token === null || token.type !== TYPE$5.Dimension) {
  2528. return 0;
  2529. }
  2530. var numberEnd = consumeNumber$2(token.value, 0);
  2531. // check unit
  2532. if (type !== null) {
  2533. // check for IE postfix hack, i.e. 123px\0 or 123px\9
  2534. var reverseSolidusOffset = token.value.indexOf('\\', numberEnd);
  2535. var unit = reverseSolidusOffset === -1 || !isPostfixIeHack(token.value, reverseSolidusOffset)
  2536. ? token.value.substr(numberEnd)
  2537. : token.value.substring(numberEnd, reverseSolidusOffset);
  2538. if (type.hasOwnProperty(unit.toLowerCase()) === false) {
  2539. return 0;
  2540. }
  2541. }
  2542. // check range if specified
  2543. if (outOfRange(opts, token.value, numberEnd)) {
  2544. return 0;
  2545. }
  2546. return 1;
  2547. };
  2548. }
  2549. // =========================
  2550. // Percentage
  2551. //
  2552. // §5.5. Percentages: the <percentage> type
  2553. // https://drafts.csswg.org/css-values-4/#percentages
  2554. function percentage(token, getNextToken, opts) {
  2555. // ... corresponds to the <percentage-token> production
  2556. if (token === null || token.type !== TYPE$5.Percentage) {
  2557. return 0;
  2558. }
  2559. // check range if specified
  2560. if (outOfRange(opts, token.value, token.value.length - 1)) {
  2561. return 0;
  2562. }
  2563. return 1;
  2564. }
  2565. // =========================
  2566. // Numeric
  2567. //
  2568. // https://drafts.csswg.org/css-values-4/#numbers
  2569. // The value <zero> represents a literal number with the value 0. Expressions that merely
  2570. // evaluate to a <number> with the value 0 (for example, calc(0)) do not match <zero>;
  2571. // only literal <number-token>s do.
  2572. function zero(next) {
  2573. if (typeof next !== 'function') {
  2574. next = function() {
  2575. return 0;
  2576. };
  2577. }
  2578. return function(token, getNextToken, opts) {
  2579. if (token !== null && token.type === TYPE$5.Number) {
  2580. if (Number(token.value) === 0) {
  2581. return 1;
  2582. }
  2583. }
  2584. return next(token, getNextToken, opts);
  2585. };
  2586. }
  2587. // § 5.3. Real Numbers: the <number> type
  2588. // https://drafts.csswg.org/css-values-4/#numbers
  2589. // Number values are denoted by <number>, and represent real numbers, possibly with a fractional component.
  2590. // ... It corresponds to the <number-token> production
  2591. function number(token, getNextToken, opts) {
  2592. if (token === null) {
  2593. return 0;
  2594. }
  2595. var numberEnd = consumeNumber$2(token.value, 0);
  2596. var isNumber = numberEnd === token.value.length;
  2597. if (!isNumber && !isPostfixIeHack(token.value, numberEnd)) {
  2598. return 0;
  2599. }
  2600. // check range if specified
  2601. if (outOfRange(opts, token.value, numberEnd)) {
  2602. return 0;
  2603. }
  2604. return 1;
  2605. }
  2606. // §5.2. Integers: the <integer> type
  2607. // https://drafts.csswg.org/css-values-4/#integers
  2608. function integer(token, getNextToken, opts) {
  2609. // ... corresponds to a subset of the <number-token> production
  2610. if (token === null || token.type !== TYPE$5.Number) {
  2611. return 0;
  2612. }
  2613. // The first digit of an integer may be immediately preceded by `-` or `+` to indicate the integer’s sign.
  2614. var i = token.value.charCodeAt(0) === 0x002B || // U+002B PLUS SIGN (+)
  2615. token.value.charCodeAt(0) === 0x002D ? 1 : 0; // U+002D HYPHEN-MINUS (-)
  2616. // When written literally, an integer is one or more decimal digits 0 through 9 ...
  2617. for (; i < token.value.length; i++) {
  2618. if (!isDigit$3(token.value.charCodeAt(i))) {
  2619. return 0;
  2620. }
  2621. }
  2622. // check range if specified
  2623. if (outOfRange(opts, token.value, i)) {
  2624. return 0;
  2625. }
  2626. return 1;
  2627. }
  2628. var generic = {
  2629. // token types
  2630. 'ident-token': tokenType(TYPE$5.Ident),
  2631. 'function-token': tokenType(TYPE$5.Function),
  2632. 'at-keyword-token': tokenType(TYPE$5.AtKeyword),
  2633. 'hash-token': tokenType(TYPE$5.Hash),
  2634. 'string-token': tokenType(TYPE$5.String),
  2635. 'bad-string-token': tokenType(TYPE$5.BadString),
  2636. 'url-token': tokenType(TYPE$5.Url),
  2637. 'bad-url-token': tokenType(TYPE$5.BadUrl),
  2638. 'delim-token': tokenType(TYPE$5.Delim),
  2639. 'number-token': tokenType(TYPE$5.Number),
  2640. 'percentage-token': tokenType(TYPE$5.Percentage),
  2641. 'dimension-token': tokenType(TYPE$5.Dimension),
  2642. 'whitespace-token': tokenType(TYPE$5.WhiteSpace),
  2643. 'CDO-token': tokenType(TYPE$5.CDO),
  2644. 'CDC-token': tokenType(TYPE$5.CDC),
  2645. 'colon-token': tokenType(TYPE$5.Colon),
  2646. 'semicolon-token': tokenType(TYPE$5.Semicolon),
  2647. 'comma-token': tokenType(TYPE$5.Comma),
  2648. '[-token': tokenType(TYPE$5.LeftSquareBracket),
  2649. ']-token': tokenType(TYPE$5.RightSquareBracket),
  2650. '(-token': tokenType(TYPE$5.LeftParenthesis),
  2651. ')-token': tokenType(TYPE$5.RightParenthesis),
  2652. '{-token': tokenType(TYPE$5.LeftCurlyBracket),
  2653. '}-token': tokenType(TYPE$5.RightCurlyBracket),
  2654. // token type aliases
  2655. 'string': tokenType(TYPE$5.String),
  2656. 'ident': tokenType(TYPE$5.Ident),
  2657. // complex types
  2658. 'custom-ident': customIdent,
  2659. 'custom-property-name': customPropertyName,
  2660. 'hex-color': hexColor,
  2661. 'id-selector': idSelector, // element( <id-selector> )
  2662. 'an-plus-b': genericAnPlusB,
  2663. 'urange': genericUrange,
  2664. 'declaration-value': declarationValue,
  2665. 'any-value': anyValue,
  2666. // dimensions
  2667. 'dimension': calc(dimension(null)),
  2668. 'angle': calc(dimension(ANGLE)),
  2669. 'decibel': calc(dimension(DECIBEL)),
  2670. 'frequency': calc(dimension(FREQUENCY)),
  2671. 'flex': calc(dimension(FLEX)),
  2672. 'length': calc(zero(dimension(LENGTH))),
  2673. 'resolution': calc(dimension(RESOLUTION)),
  2674. 'semitones': calc(dimension(SEMITONES)),
  2675. 'time': calc(dimension(TIME)),
  2676. // percentage
  2677. 'percentage': calc(percentage),
  2678. // numeric
  2679. 'zero': zero(),
  2680. 'number': calc(number),
  2681. 'integer': calc(integer),
  2682. // old IE stuff
  2683. '-ms-legacy-expression': func('expression')
  2684. };
  2685. var _SyntaxError$1 = function SyntaxError(message, input, offset) {
  2686. var error = createCustomError('SyntaxError', message);
  2687. error.input = input;
  2688. error.offset = offset;
  2689. error.rawMessage = message;
  2690. error.message = error.rawMessage + '\n' +
  2691. ' ' + error.input + '\n' +
  2692. '--' + new Array((error.offset || error.input.length) + 1).join('-') + '^';
  2693. return error;
  2694. };
  2695. var TAB = 9;
  2696. var N$1 = 10;
  2697. var F = 12;
  2698. var R = 13;
  2699. var SPACE = 32;
  2700. var Tokenizer = function(str) {
  2701. this.str = str;
  2702. this.pos = 0;
  2703. };
  2704. Tokenizer.prototype = {
  2705. charCodeAt: function(pos) {
  2706. return pos < this.str.length ? this.str.charCodeAt(pos) : 0;
  2707. },
  2708. charCode: function() {
  2709. return this.charCodeAt(this.pos);
  2710. },
  2711. nextCharCode: function() {
  2712. return this.charCodeAt(this.pos + 1);
  2713. },
  2714. nextNonWsCode: function(pos) {
  2715. return this.charCodeAt(this.findWsEnd(pos));
  2716. },
  2717. findWsEnd: function(pos) {
  2718. for (; pos < this.str.length; pos++) {
  2719. var code = this.str.charCodeAt(pos);
  2720. if (code !== R && code !== N$1 && code !== F && code !== SPACE && code !== TAB) {
  2721. break;
  2722. }
  2723. }
  2724. return pos;
  2725. },
  2726. substringToPos: function(end) {
  2727. return this.str.substring(this.pos, this.pos = end);
  2728. },
  2729. eat: function(code) {
  2730. if (this.charCode() !== code) {
  2731. this.error('Expect `' + String.fromCharCode(code) + '`');
  2732. }
  2733. this.pos++;
  2734. },
  2735. peek: function() {
  2736. return this.pos < this.str.length ? this.str.charAt(this.pos++) : '';
  2737. },
  2738. error: function(message) {
  2739. throw new _SyntaxError$1(message, this.str, this.pos);
  2740. }
  2741. };
  2742. var tokenizer$1 = Tokenizer;
  2743. var TAB$1 = 9;
  2744. var N$2 = 10;
  2745. var F$1 = 12;
  2746. var R$1 = 13;
  2747. var SPACE$1 = 32;
  2748. var EXCLAMATIONMARK = 33; // !
  2749. var NUMBERSIGN = 35; // #
  2750. var AMPERSAND = 38; // &
  2751. var APOSTROPHE = 39; // '
  2752. var LEFTPARENTHESIS = 40; // (
  2753. var RIGHTPARENTHESIS = 41; // )
  2754. var ASTERISK = 42; // *
  2755. var PLUSSIGN$2 = 43; // +
  2756. var COMMA = 44; // ,
  2757. var HYPERMINUS = 45; // -
  2758. var LESSTHANSIGN = 60; // <
  2759. var GREATERTHANSIGN = 62; // >
  2760. var QUESTIONMARK$1 = 63; // ?
  2761. var COMMERCIALAT = 64; // @
  2762. var LEFTSQUAREBRACKET = 91; // [
  2763. var RIGHTSQUAREBRACKET = 93; // ]
  2764. var LEFTCURLYBRACKET = 123; // {
  2765. var VERTICALLINE = 124; // |
  2766. var RIGHTCURLYBRACKET = 125; // }
  2767. var INFINITY = 8734; // ∞
  2768. var NAME_CHAR = createCharMap(function(ch) {
  2769. return /[a-zA-Z0-9\-]/.test(ch);
  2770. });
  2771. var COMBINATOR_PRECEDENCE = {
  2772. ' ': 1,
  2773. '&&': 2,
  2774. '||': 3,
  2775. '|': 4
  2776. };
  2777. function createCharMap(fn) {
  2778. var array = typeof Uint32Array === 'function' ? new Uint32Array(128) : new Array(128);
  2779. for (var i = 0; i < 128; i++) {
  2780. array[i] = fn(String.fromCharCode(i)) ? 1 : 0;
  2781. }
  2782. return array;
  2783. }
  2784. function scanSpaces(tokenizer) {
  2785. return tokenizer.substringToPos(
  2786. tokenizer.findWsEnd(tokenizer.pos)
  2787. );
  2788. }
  2789. function scanWord(tokenizer) {
  2790. var end = tokenizer.pos;
  2791. for (; end < tokenizer.str.length; end++) {
  2792. var code = tokenizer.str.charCodeAt(end);
  2793. if (code >= 128 || NAME_CHAR[code] === 0) {
  2794. break;
  2795. }
  2796. }
  2797. if (tokenizer.pos === end) {
  2798. tokenizer.error('Expect a keyword');
  2799. }
  2800. return tokenizer.substringToPos(end);
  2801. }
  2802. function scanNumber(tokenizer) {
  2803. var end = tokenizer.pos;
  2804. for (; end < tokenizer.str.length; end++) {
  2805. var code = tokenizer.str.charCodeAt(end);
  2806. if (code < 48 || code > 57) {
  2807. break;
  2808. }
  2809. }
  2810. if (tokenizer.pos === end) {
  2811. tokenizer.error('Expect a number');
  2812. }
  2813. return tokenizer.substringToPos(end);
  2814. }
  2815. function scanString(tokenizer) {
  2816. var end = tokenizer.str.indexOf('\'', tokenizer.pos + 1);
  2817. if (end === -1) {
  2818. tokenizer.pos = tokenizer.str.length;
  2819. tokenizer.error('Expect an apostrophe');
  2820. }
  2821. return tokenizer.substringToPos(end + 1);
  2822. }
  2823. function readMultiplierRange(tokenizer) {
  2824. var min = null;
  2825. var max = null;
  2826. tokenizer.eat(LEFTCURLYBRACKET);
  2827. min = scanNumber(tokenizer);
  2828. if (tokenizer.charCode() === COMMA) {
  2829. tokenizer.pos++;
  2830. if (tokenizer.charCode() !== RIGHTCURLYBRACKET) {
  2831. max = scanNumber(tokenizer);
  2832. }
  2833. } else {
  2834. max = min;
  2835. }
  2836. tokenizer.eat(RIGHTCURLYBRACKET);
  2837. return {
  2838. min: Number(min),
  2839. max: max ? Number(max) : 0
  2840. };
  2841. }
  2842. function readMultiplier(tokenizer) {
  2843. var range = null;
  2844. var comma = false;
  2845. switch (tokenizer.charCode()) {
  2846. case ASTERISK:
  2847. tokenizer.pos++;
  2848. range = {
  2849. min: 0,
  2850. max: 0
  2851. };
  2852. break;
  2853. case PLUSSIGN$2:
  2854. tokenizer.pos++;
  2855. range = {
  2856. min: 1,
  2857. max: 0
  2858. };
  2859. break;
  2860. case QUESTIONMARK$1:
  2861. tokenizer.pos++;
  2862. range = {
  2863. min: 0,
  2864. max: 1
  2865. };
  2866. break;
  2867. case NUMBERSIGN:
  2868. tokenizer.pos++;
  2869. comma = true;
  2870. if (tokenizer.charCode() === LEFTCURLYBRACKET) {
  2871. range = readMultiplierRange(tokenizer);
  2872. } else {
  2873. range = {
  2874. min: 1,
  2875. max: 0
  2876. };
  2877. }
  2878. break;
  2879. case LEFTCURLYBRACKET:
  2880. range = readMultiplierRange(tokenizer);
  2881. break;
  2882. default:
  2883. return null;
  2884. }
  2885. return {
  2886. type: 'Multiplier',
  2887. comma: comma,
  2888. min: range.min,
  2889. max: range.max,
  2890. term: null
  2891. };
  2892. }
  2893. function maybeMultiplied(tokenizer, node) {
  2894. var multiplier = readMultiplier(tokenizer);
  2895. if (multiplier !== null) {
  2896. multiplier.term = node;
  2897. return multiplier;
  2898. }
  2899. return node;
  2900. }
  2901. function maybeToken(tokenizer) {
  2902. var ch = tokenizer.peek();
  2903. if (ch === '') {
  2904. return null;
  2905. }
  2906. return {
  2907. type: 'Token',
  2908. value: ch
  2909. };
  2910. }
  2911. function readProperty(tokenizer) {
  2912. var name;
  2913. tokenizer.eat(LESSTHANSIGN);
  2914. tokenizer.eat(APOSTROPHE);
  2915. name = scanWord(tokenizer);
  2916. tokenizer.eat(APOSTROPHE);
  2917. tokenizer.eat(GREATERTHANSIGN);
  2918. return maybeMultiplied(tokenizer, {
  2919. type: 'Property',
  2920. name: name
  2921. });
  2922. }
  2923. // https://drafts.csswg.org/css-values-3/#numeric-ranges
  2924. // 4.1. Range Restrictions and Range Definition Notation
  2925. //
  2926. // Range restrictions can be annotated in the numeric type notation using CSS bracketed
  2927. // range notation—[min,max]—within the angle brackets, after the identifying keyword,
  2928. // indicating a closed range between (and including) min and max.
  2929. // For example, <integer [0, 10]> indicates an integer between 0 and 10, inclusive.
  2930. function readTypeRange(tokenizer) {
  2931. // use null for Infinity to make AST format JSON serializable/deserializable
  2932. var min = null; // -Infinity
  2933. var max = null; // Infinity
  2934. var sign = 1;
  2935. tokenizer.eat(LEFTSQUAREBRACKET);
  2936. if (tokenizer.charCode() === HYPERMINUS) {
  2937. tokenizer.peek();
  2938. sign = -1;
  2939. }
  2940. if (sign == -1 && tokenizer.charCode() === INFINITY) {
  2941. tokenizer.peek();
  2942. } else {
  2943. min = sign * Number(scanNumber(tokenizer));
  2944. }
  2945. scanSpaces(tokenizer);
  2946. tokenizer.eat(COMMA);
  2947. scanSpaces(tokenizer);
  2948. if (tokenizer.charCode() === INFINITY) {
  2949. tokenizer.peek();
  2950. } else {
  2951. sign = 1;
  2952. if (tokenizer.charCode() === HYPERMINUS) {
  2953. tokenizer.peek();
  2954. sign = -1;
  2955. }
  2956. max = sign * Number(scanNumber(tokenizer));
  2957. }
  2958. tokenizer.eat(RIGHTSQUAREBRACKET);
  2959. // If no range is indicated, either by using the bracketed range notation
  2960. // or in the property description, then [−∞,∞] is assumed.
  2961. if (min === null && max === null) {
  2962. return null;
  2963. }
  2964. return {
  2965. type: 'Range',
  2966. min: min,
  2967. max: max
  2968. };
  2969. }
  2970. function readType(tokenizer) {
  2971. var name;
  2972. var opts = null;
  2973. tokenizer.eat(LESSTHANSIGN);
  2974. name = scanWord(tokenizer);
  2975. if (tokenizer.charCode() === LEFTPARENTHESIS &&
  2976. tokenizer.nextCharCode() === RIGHTPARENTHESIS) {
  2977. tokenizer.pos += 2;
  2978. name += '()';
  2979. }
  2980. if (tokenizer.charCodeAt(tokenizer.findWsEnd(tokenizer.pos)) === LEFTSQUAREBRACKET) {
  2981. scanSpaces(tokenizer);
  2982. opts = readTypeRange(tokenizer);
  2983. }
  2984. tokenizer.eat(GREATERTHANSIGN);
  2985. return maybeMultiplied(tokenizer, {
  2986. type: 'Type',
  2987. name: name,
  2988. opts: opts
  2989. });
  2990. }
  2991. function readKeywordOrFunction(tokenizer) {
  2992. var name;
  2993. name = scanWord(tokenizer);
  2994. if (tokenizer.charCode() === LEFTPARENTHESIS) {
  2995. tokenizer.pos++;
  2996. return {
  2997. type: 'Function',
  2998. name: name
  2999. };
  3000. }
  3001. return maybeMultiplied(tokenizer, {
  3002. type: 'Keyword',
  3003. name: name
  3004. });
  3005. }
  3006. function regroupTerms(terms, combinators) {
  3007. function createGroup(terms, combinator) {
  3008. return {
  3009. type: 'Group',
  3010. terms: terms,
  3011. combinator: combinator,
  3012. disallowEmpty: false,
  3013. explicit: false
  3014. };
  3015. }
  3016. combinators = Object.keys(combinators).sort(function(a, b) {
  3017. return COMBINATOR_PRECEDENCE[a] - COMBINATOR_PRECEDENCE[b];
  3018. });
  3019. while (combinators.length > 0) {
  3020. var combinator = combinators.shift();
  3021. for (var i = 0, subgroupStart = 0; i < terms.length; i++) {
  3022. var term = terms[i];
  3023. if (term.type === 'Combinator') {
  3024. if (term.value === combinator) {
  3025. if (subgroupStart === -1) {
  3026. subgroupStart = i - 1;
  3027. }
  3028. terms.splice(i, 1);
  3029. i--;
  3030. } else {
  3031. if (subgroupStart !== -1 && i - subgroupStart > 1) {
  3032. terms.splice(
  3033. subgroupStart,
  3034. i - subgroupStart,
  3035. createGroup(terms.slice(subgroupStart, i), combinator)
  3036. );
  3037. i = subgroupStart + 1;
  3038. }
  3039. subgroupStart = -1;
  3040. }
  3041. }
  3042. }
  3043. if (subgroupStart !== -1 && combinators.length) {
  3044. terms.splice(
  3045. subgroupStart,
  3046. i - subgroupStart,
  3047. createGroup(terms.slice(subgroupStart, i), combinator)
  3048. );
  3049. }
  3050. }
  3051. return combinator;
  3052. }
  3053. function readImplicitGroup(tokenizer) {
  3054. var terms = [];
  3055. var combinators = {};
  3056. var token;
  3057. var prevToken = null;
  3058. var prevTokenPos = tokenizer.pos;
  3059. while (token = peek(tokenizer)) {
  3060. if (token.type !== 'Spaces') {
  3061. if (token.type === 'Combinator') {
  3062. // check for combinator in group beginning and double combinator sequence
  3063. if (prevToken === null || prevToken.type === 'Combinator') {
  3064. tokenizer.pos = prevTokenPos;
  3065. tokenizer.error('Unexpected combinator');
  3066. }
  3067. combinators[token.value] = true;
  3068. } else if (prevToken !== null && prevToken.type !== 'Combinator') {
  3069. combinators[' '] = true; // a b
  3070. terms.push({
  3071. type: 'Combinator',
  3072. value: ' '
  3073. });
  3074. }
  3075. terms.push(token);
  3076. prevToken = token;
  3077. prevTokenPos = tokenizer.pos;
  3078. }
  3079. }
  3080. // check for combinator in group ending
  3081. if (prevToken !== null && prevToken.type === 'Combinator') {
  3082. tokenizer.pos -= prevTokenPos;
  3083. tokenizer.error('Unexpected combinator');
  3084. }
  3085. return {
  3086. type: 'Group',
  3087. terms: terms,
  3088. combinator: regroupTerms(terms, combinators) || ' ',
  3089. disallowEmpty: false,
  3090. explicit: false
  3091. };
  3092. }
  3093. function readGroup(tokenizer) {
  3094. var result;
  3095. tokenizer.eat(LEFTSQUAREBRACKET);
  3096. result = readImplicitGroup(tokenizer);
  3097. tokenizer.eat(RIGHTSQUAREBRACKET);
  3098. result.explicit = true;
  3099. if (tokenizer.charCode() === EXCLAMATIONMARK) {
  3100. tokenizer.pos++;
  3101. result.disallowEmpty = true;
  3102. }
  3103. return result;
  3104. }
  3105. function peek(tokenizer) {
  3106. var code = tokenizer.charCode();
  3107. if (code < 128 && NAME_CHAR[code] === 1) {
  3108. return readKeywordOrFunction(tokenizer);
  3109. }
  3110. switch (code) {
  3111. case RIGHTSQUAREBRACKET:
  3112. // don't eat, stop scan a group
  3113. break;
  3114. case LEFTSQUAREBRACKET:
  3115. return maybeMultiplied(tokenizer, readGroup(tokenizer));
  3116. case LESSTHANSIGN:
  3117. return tokenizer.nextCharCode() === APOSTROPHE
  3118. ? readProperty(tokenizer)
  3119. : readType(tokenizer);
  3120. case VERTICALLINE:
  3121. return {
  3122. type: 'Combinator',
  3123. value: tokenizer.substringToPos(
  3124. tokenizer.nextCharCode() === VERTICALLINE
  3125. ? tokenizer.pos + 2
  3126. : tokenizer.pos + 1
  3127. )
  3128. };
  3129. case AMPERSAND:
  3130. tokenizer.pos++;
  3131. tokenizer.eat(AMPERSAND);
  3132. return {
  3133. type: 'Combinator',
  3134. value: '&&'
  3135. };
  3136. case COMMA:
  3137. tokenizer.pos++;
  3138. return {
  3139. type: 'Comma'
  3140. };
  3141. case APOSTROPHE:
  3142. return maybeMultiplied(tokenizer, {
  3143. type: 'String',
  3144. value: scanString(tokenizer)
  3145. });
  3146. case SPACE$1:
  3147. case TAB$1:
  3148. case N$2:
  3149. case R$1:
  3150. case F$1:
  3151. return {
  3152. type: 'Spaces',
  3153. value: scanSpaces(tokenizer)
  3154. };
  3155. case COMMERCIALAT:
  3156. code = tokenizer.nextCharCode();
  3157. if (code < 128 && NAME_CHAR[code] === 1) {
  3158. tokenizer.pos++;
  3159. return {
  3160. type: 'AtKeyword',
  3161. name: scanWord(tokenizer)
  3162. };
  3163. }
  3164. return maybeToken(tokenizer);
  3165. case ASTERISK:
  3166. case PLUSSIGN$2:
  3167. case QUESTIONMARK$1:
  3168. case NUMBERSIGN:
  3169. case EXCLAMATIONMARK:
  3170. // prohibited tokens (used as a multiplier start)
  3171. break;
  3172. case LEFTCURLYBRACKET:
  3173. // LEFTCURLYBRACKET is allowed since mdn/data uses it w/o quoting
  3174. // check next char isn't a number, because it's likely a disjoined multiplier
  3175. code = tokenizer.nextCharCode();
  3176. if (code < 48 || code > 57) {
  3177. return maybeToken(tokenizer);
  3178. }
  3179. break;
  3180. default:
  3181. return maybeToken(tokenizer);
  3182. }
  3183. }
  3184. function parse(source) {
  3185. var tokenizer = new tokenizer$1(source);
  3186. var result = readImplicitGroup(tokenizer);
  3187. if (tokenizer.pos !== source.length) {
  3188. tokenizer.error('Unexpected input');
  3189. }
  3190. // reduce redundant groups with single group term
  3191. if (result.terms.length === 1 && result.terms[0].type === 'Group') {
  3192. result = result.terms[0];
  3193. }
  3194. return result;
  3195. }
  3196. // warm up parse to elimitate code branches that never execute
  3197. // fix soft deoptimizations (insufficient type feedback)
  3198. parse('[a&&<b>#|<\'c\'>*||e() f{2} /,(% g#{1,2} h{2,})]!');
  3199. var parse_1 = parse;
  3200. var noop$1 = function() {};
  3201. function ensureFunction(value) {
  3202. return typeof value === 'function' ? value : noop$1;
  3203. }
  3204. var walk = function(node, options, context) {
  3205. function walk(node) {
  3206. enter.call(context, node);
  3207. switch (node.type) {
  3208. case 'Group':
  3209. node.terms.forEach(walk);
  3210. break;
  3211. case 'Multiplier':
  3212. walk(node.term);
  3213. break;
  3214. case 'Type':
  3215. case 'Property':
  3216. case 'Keyword':
  3217. case 'AtKeyword':
  3218. case 'Function':
  3219. case 'String':
  3220. case 'Token':
  3221. case 'Comma':
  3222. break;
  3223. default:
  3224. throw new Error('Unknown type: ' + node.type);
  3225. }
  3226. leave.call(context, node);
  3227. }
  3228. var enter = noop$1;
  3229. var leave = noop$1;
  3230. if (typeof options === 'function') {
  3231. enter = options;
  3232. } else if (options) {
  3233. enter = ensureFunction(options.enter);
  3234. leave = ensureFunction(options.leave);
  3235. }
  3236. if (enter === noop$1 && leave === noop$1) {
  3237. throw new Error('Neither `enter` nor `leave` walker handler is set or both aren\'t a function');
  3238. }
  3239. walk(node);
  3240. };
  3241. var tokenStream = new TokenStream_1();
  3242. var astToTokens = {
  3243. decorator: function(handlers) {
  3244. var curNode = null;
  3245. var prev = { len: 0, node: null };
  3246. var nodes = [prev];
  3247. var buffer = '';
  3248. return {
  3249. children: handlers.children,
  3250. node: function(node) {
  3251. var tmp = curNode;
  3252. curNode = node;
  3253. handlers.node.call(this, node);
  3254. curNode = tmp;
  3255. },
  3256. chunk: function(chunk) {
  3257. buffer += chunk;
  3258. if (prev.node !== curNode) {
  3259. nodes.push({
  3260. len: chunk.length,
  3261. node: curNode
  3262. });
  3263. } else {
  3264. prev.len += chunk.length;
  3265. }
  3266. },
  3267. result: function() {
  3268. return prepareTokens(buffer, nodes);
  3269. }
  3270. };
  3271. }
  3272. };
  3273. function prepareTokens(str, nodes) {
  3274. var tokens = [];
  3275. var nodesOffset = 0;
  3276. var nodesIndex = 0;
  3277. var currentNode = nodes ? nodes[nodesIndex].node : null;
  3278. tokenizer(str, tokenStream);
  3279. while (!tokenStream.eof) {
  3280. if (nodes) {
  3281. while (nodesIndex < nodes.length && nodesOffset + nodes[nodesIndex].len <= tokenStream.tokenStart) {
  3282. nodesOffset += nodes[nodesIndex++].len;
  3283. currentNode = nodes[nodesIndex].node;
  3284. }
  3285. }
  3286. tokens.push({
  3287. type: tokenStream.tokenType,
  3288. value: tokenStream.getTokenValue(),
  3289. index: tokenStream.tokenIndex, // TODO: remove it, temporary solution
  3290. balance: tokenStream.balance[tokenStream.tokenIndex], // TODO: remove it, temporary solution
  3291. node: currentNode
  3292. });
  3293. tokenStream.next();
  3294. // console.log({ ...tokens[tokens.length - 1], node: undefined });
  3295. }
  3296. return tokens;
  3297. }
  3298. var prepareTokens_1 = function(value, syntax) {
  3299. if (typeof value === 'string') {
  3300. return prepareTokens(value, null);
  3301. }
  3302. return syntax.generate(value, astToTokens);
  3303. };
  3304. var MATCH = { type: 'Match' };
  3305. var MISMATCH = { type: 'Mismatch' };
  3306. var DISALLOW_EMPTY = { type: 'DisallowEmpty' };
  3307. var LEFTPARENTHESIS$1 = 40; // (
  3308. var RIGHTPARENTHESIS$1 = 41; // )
  3309. function createCondition(match, thenBranch, elseBranch) {
  3310. // reduce node count
  3311. if (thenBranch === MATCH && elseBranch === MISMATCH) {
  3312. return match;
  3313. }
  3314. if (match === MATCH && thenBranch === MATCH && elseBranch === MATCH) {
  3315. return match;
  3316. }
  3317. if (match.type === 'If' && match.else === MISMATCH && thenBranch === MATCH) {
  3318. thenBranch = match.then;
  3319. match = match.match;
  3320. }
  3321. return {
  3322. type: 'If',
  3323. match: match,
  3324. then: thenBranch,
  3325. else: elseBranch
  3326. };
  3327. }
  3328. function isFunctionType(name) {
  3329. return (
  3330. name.length > 2 &&
  3331. name.charCodeAt(name.length - 2) === LEFTPARENTHESIS$1 &&
  3332. name.charCodeAt(name.length - 1) === RIGHTPARENTHESIS$1
  3333. );
  3334. }
  3335. function isEnumCapatible(term) {
  3336. return (
  3337. term.type === 'Keyword' ||
  3338. term.type === 'AtKeyword' ||
  3339. term.type === 'Function' ||
  3340. term.type === 'Type' && isFunctionType(term.name)
  3341. );
  3342. }
  3343. function buildGroupMatchGraph(combinator, terms, atLeastOneTermMatched) {
  3344. switch (combinator) {
  3345. case ' ':
  3346. // Juxtaposing components means that all of them must occur, in the given order.
  3347. //
  3348. // a b c
  3349. // =
  3350. // match a
  3351. // then match b
  3352. // then match c
  3353. // then MATCH
  3354. // else MISMATCH
  3355. // else MISMATCH
  3356. // else MISMATCH
  3357. var result = MATCH;
  3358. for (var i = terms.length - 1; i >= 0; i--) {
  3359. var term = terms[i];
  3360. result = createCondition(
  3361. term,
  3362. result,
  3363. MISMATCH
  3364. );
  3365. }
  3366. return result;
  3367. case '|':
  3368. // A bar (|) separates two or more alternatives: exactly one of them must occur.
  3369. //
  3370. // a | b | c
  3371. // =
  3372. // match a
  3373. // then MATCH
  3374. // else match b
  3375. // then MATCH
  3376. // else match c
  3377. // then MATCH
  3378. // else MISMATCH
  3379. var result = MISMATCH;
  3380. var map = null;
  3381. for (var i = terms.length - 1; i >= 0; i--) {
  3382. var term = terms[i];
  3383. // reduce sequence of keywords into a Enum
  3384. if (isEnumCapatible(term)) {
  3385. if (map === null && i > 0 && isEnumCapatible(terms[i - 1])) {
  3386. map = Object.create(null);
  3387. result = createCondition(
  3388. {
  3389. type: 'Enum',
  3390. map: map
  3391. },
  3392. MATCH,
  3393. result
  3394. );
  3395. }
  3396. if (map !== null) {
  3397. var key = (isFunctionType(term.name) ? term.name.slice(0, -1) : term.name).toLowerCase();
  3398. if (key in map === false) {
  3399. map[key] = term;
  3400. continue;
  3401. }
  3402. }
  3403. }
  3404. map = null;
  3405. // create a new conditonal node
  3406. result = createCondition(
  3407. term,
  3408. MATCH,
  3409. result
  3410. );
  3411. }
  3412. return result;
  3413. case '&&':
  3414. // A double ampersand (&&) separates two or more components,
  3415. // all of which must occur, in any order.
  3416. // Use MatchOnce for groups with a large number of terms,
  3417. // since &&-groups produces at least N!-node trees
  3418. if (terms.length > 5) {
  3419. return {
  3420. type: 'MatchOnce',
  3421. terms: terms,
  3422. all: true
  3423. };
  3424. }
  3425. // Use a combination tree for groups with small number of terms
  3426. //
  3427. // a && b && c
  3428. // =
  3429. // match a
  3430. // then [b && c]
  3431. // else match b
  3432. // then [a && c]
  3433. // else match c
  3434. // then [a && b]
  3435. // else MISMATCH
  3436. //
  3437. // a && b
  3438. // =
  3439. // match a
  3440. // then match b
  3441. // then MATCH
  3442. // else MISMATCH
  3443. // else match b
  3444. // then match a
  3445. // then MATCH
  3446. // else MISMATCH
  3447. // else MISMATCH
  3448. var result = MISMATCH;
  3449. for (var i = terms.length - 1; i >= 0; i--) {
  3450. var term = terms[i];
  3451. var thenClause;
  3452. if (terms.length > 1) {
  3453. thenClause = buildGroupMatchGraph(
  3454. combinator,
  3455. terms.filter(function(newGroupTerm) {
  3456. return newGroupTerm !== term;
  3457. }),
  3458. false
  3459. );
  3460. } else {
  3461. thenClause = MATCH;
  3462. }
  3463. result = createCondition(
  3464. term,
  3465. thenClause,
  3466. result
  3467. );
  3468. }
  3469. return result;
  3470. case '||':
  3471. // A double bar (||) separates two or more options:
  3472. // one or more of them must occur, in any order.
  3473. // Use MatchOnce for groups with a large number of terms,
  3474. // since ||-groups produces at least N!-node trees
  3475. if (terms.length > 5) {
  3476. return {
  3477. type: 'MatchOnce',
  3478. terms: terms,
  3479. all: false
  3480. };
  3481. }
  3482. // Use a combination tree for groups with small number of terms
  3483. //
  3484. // a || b || c
  3485. // =
  3486. // match a
  3487. // then [b || c]
  3488. // else match b
  3489. // then [a || c]
  3490. // else match c
  3491. // then [a || b]
  3492. // else MISMATCH
  3493. //
  3494. // a || b
  3495. // =
  3496. // match a
  3497. // then match b
  3498. // then MATCH
  3499. // else MATCH
  3500. // else match b
  3501. // then match a
  3502. // then MATCH
  3503. // else MATCH
  3504. // else MISMATCH
  3505. var result = atLeastOneTermMatched ? MATCH : MISMATCH;
  3506. for (var i = terms.length - 1; i >= 0; i--) {
  3507. var term = terms[i];
  3508. var thenClause;
  3509. if (terms.length > 1) {
  3510. thenClause = buildGroupMatchGraph(
  3511. combinator,
  3512. terms.filter(function(newGroupTerm) {
  3513. return newGroupTerm !== term;
  3514. }),
  3515. true
  3516. );
  3517. } else {
  3518. thenClause = MATCH;
  3519. }
  3520. result = createCondition(
  3521. term,
  3522. thenClause,
  3523. result
  3524. );
  3525. }
  3526. return result;
  3527. }
  3528. }
  3529. function buildMultiplierMatchGraph(node) {
  3530. var result = MATCH;
  3531. var matchTerm = buildMatchGraph(node.term);
  3532. if (node.max === 0) {
  3533. // disable repeating of empty match to prevent infinite loop
  3534. matchTerm = createCondition(
  3535. matchTerm,
  3536. DISALLOW_EMPTY,
  3537. MISMATCH
  3538. );
  3539. // an occurrence count is not limited, make a cycle;
  3540. // to collect more terms on each following matching mismatch
  3541. result = createCondition(
  3542. matchTerm,
  3543. null, // will be a loop
  3544. MISMATCH
  3545. );
  3546. result.then = createCondition(
  3547. MATCH,
  3548. MATCH,
  3549. result // make a loop
  3550. );
  3551. if (node.comma) {
  3552. result.then.else = createCondition(
  3553. { type: 'Comma', syntax: node },
  3554. result,
  3555. MISMATCH
  3556. );
  3557. }
  3558. } else {
  3559. // create a match node chain for [min .. max] interval with optional matches
  3560. for (var i = node.min || 1; i <= node.max; i++) {
  3561. if (node.comma && result !== MATCH) {
  3562. result = createCondition(
  3563. { type: 'Comma', syntax: node },
  3564. result,
  3565. MISMATCH
  3566. );
  3567. }
  3568. result = createCondition(
  3569. matchTerm,
  3570. createCondition(
  3571. MATCH,
  3572. MATCH,
  3573. result
  3574. ),
  3575. MISMATCH
  3576. );
  3577. }
  3578. }
  3579. if (node.min === 0) {
  3580. // allow zero match
  3581. result = createCondition(
  3582. MATCH,
  3583. MATCH,
  3584. result
  3585. );
  3586. } else {
  3587. // create a match node chain to collect [0 ... min - 1] required matches
  3588. for (var i = 0; i < node.min - 1; i++) {
  3589. if (node.comma && result !== MATCH) {
  3590. result = createCondition(
  3591. { type: 'Comma', syntax: node },
  3592. result,
  3593. MISMATCH
  3594. );
  3595. }
  3596. result = createCondition(
  3597. matchTerm,
  3598. result,
  3599. MISMATCH
  3600. );
  3601. }
  3602. }
  3603. return result;
  3604. }
  3605. function buildMatchGraph(node) {
  3606. if (typeof node === 'function') {
  3607. return {
  3608. type: 'Generic',
  3609. fn: node
  3610. };
  3611. }
  3612. switch (node.type) {
  3613. case 'Group':
  3614. var result = buildGroupMatchGraph(
  3615. node.combinator,
  3616. node.terms.map(buildMatchGraph),
  3617. false
  3618. );
  3619. if (node.disallowEmpty) {
  3620. result = createCondition(
  3621. result,
  3622. DISALLOW_EMPTY,
  3623. MISMATCH
  3624. );
  3625. }
  3626. return result;
  3627. case 'Multiplier':
  3628. return buildMultiplierMatchGraph(node);
  3629. case 'Type':
  3630. case 'Property':
  3631. return {
  3632. type: node.type,
  3633. name: node.name,
  3634. syntax: node
  3635. };
  3636. case 'Keyword':
  3637. return {
  3638. type: node.type,
  3639. name: node.name.toLowerCase(),
  3640. syntax: node
  3641. };
  3642. case 'AtKeyword':
  3643. return {
  3644. type: node.type,
  3645. name: '@' + node.name.toLowerCase(),
  3646. syntax: node
  3647. };
  3648. case 'Function':
  3649. return {
  3650. type: node.type,
  3651. name: node.name.toLowerCase() + '(',
  3652. syntax: node
  3653. };
  3654. case 'String':
  3655. // convert a one char length String to a Token
  3656. if (node.value.length === 3) {
  3657. return {
  3658. type: 'Token',
  3659. value: node.value.charAt(1),
  3660. syntax: node
  3661. };
  3662. }
  3663. // otherwise use it as is
  3664. return {
  3665. type: node.type,
  3666. value: node.value.substr(1, node.value.length - 2).replace(/\\'/g, '\''),
  3667. syntax: node
  3668. };
  3669. case 'Token':
  3670. return {
  3671. type: node.type,
  3672. value: node.value,
  3673. syntax: node
  3674. };
  3675. case 'Comma':
  3676. return {
  3677. type: node.type,
  3678. syntax: node
  3679. };
  3680. default:
  3681. throw new Error('Unknown node type:', node.type);
  3682. }
  3683. }
  3684. var matchGraph = {
  3685. MATCH: MATCH,
  3686. MISMATCH: MISMATCH,
  3687. DISALLOW_EMPTY: DISALLOW_EMPTY,
  3688. buildMatchGraph: function(syntaxTree, ref) {
  3689. if (typeof syntaxTree === 'string') {
  3690. syntaxTree = parse_1(syntaxTree);
  3691. }
  3692. return {
  3693. type: 'MatchGraph',
  3694. match: buildMatchGraph(syntaxTree),
  3695. syntax: ref || null,
  3696. source: syntaxTree
  3697. };
  3698. }
  3699. };
  3700. var hasOwnProperty$1 = Object.prototype.hasOwnProperty;
  3701. var MATCH$1 = matchGraph.MATCH;
  3702. var MISMATCH$1 = matchGraph.MISMATCH;
  3703. var DISALLOW_EMPTY$1 = matchGraph.DISALLOW_EMPTY;
  3704. var TYPE$6 = _const.TYPE;
  3705. var STUB = 0;
  3706. var TOKEN = 1;
  3707. var OPEN_SYNTAX = 2;
  3708. var CLOSE_SYNTAX = 3;
  3709. var EXIT_REASON_MATCH = 'Match';
  3710. var EXIT_REASON_MISMATCH = 'Mismatch';
  3711. var EXIT_REASON_ITERATION_LIMIT = 'Maximum iteration number exceeded (please fill an issue on https://github.com/csstree/csstree/issues)';
  3712. var ITERATION_LIMIT = 15000;
  3713. var totalIterationCount = 0;
  3714. function reverseList(list) {
  3715. var prev = null;
  3716. var next = null;
  3717. var item = list;
  3718. while (item !== null) {
  3719. next = item.prev;
  3720. item.prev = prev;
  3721. prev = item;
  3722. item = next;
  3723. }
  3724. return prev;
  3725. }
  3726. function areStringsEqualCaseInsensitive(testStr, referenceStr) {
  3727. if (testStr.length !== referenceStr.length) {
  3728. return false;
  3729. }
  3730. for (var i = 0; i < testStr.length; i++) {
  3731. var testCode = testStr.charCodeAt(i);
  3732. var referenceCode = referenceStr.charCodeAt(i);
  3733. // testCode.toLowerCase() for U+0041 LATIN CAPITAL LETTER A (A) .. U+005A LATIN CAPITAL LETTER Z (Z).
  3734. if (testCode >= 0x0041 && testCode <= 0x005A) {
  3735. testCode = testCode | 32;
  3736. }
  3737. if (testCode !== referenceCode) {
  3738. return false;
  3739. }
  3740. }
  3741. return true;
  3742. }
  3743. function isCommaContextStart(token) {
  3744. if (token === null) {
  3745. return true;
  3746. }
  3747. return (
  3748. token.type === TYPE$6.Comma ||
  3749. token.type === TYPE$6.Function ||
  3750. token.type === TYPE$6.LeftParenthesis ||
  3751. token.type === TYPE$6.LeftSquareBracket ||
  3752. token.type === TYPE$6.LeftCurlyBracket ||
  3753. token.type === TYPE$6.Delim
  3754. );
  3755. }
  3756. function isCommaContextEnd(token) {
  3757. if (token === null) {
  3758. return true;
  3759. }
  3760. return (
  3761. token.type === TYPE$6.RightParenthesis ||
  3762. token.type === TYPE$6.RightSquareBracket ||
  3763. token.type === TYPE$6.RightCurlyBracket ||
  3764. token.type === TYPE$6.Delim
  3765. );
  3766. }
  3767. function internalMatch(tokens, state, syntaxes) {
  3768. function moveToNextToken() {
  3769. do {
  3770. tokenIndex++;
  3771. token = tokenIndex < tokens.length ? tokens[tokenIndex] : null;
  3772. } while (token !== null && (token.type === TYPE$6.WhiteSpace || token.type === TYPE$6.Comment));
  3773. }
  3774. function getNextToken(offset) {
  3775. var nextIndex = tokenIndex + offset;
  3776. return nextIndex < tokens.length ? tokens[nextIndex] : null;
  3777. }
  3778. function stateSnapshotFromSyntax(nextState, prev) {
  3779. return {
  3780. nextState: nextState,
  3781. matchStack: matchStack,
  3782. syntaxStack: syntaxStack,
  3783. thenStack: thenStack,
  3784. tokenIndex: tokenIndex,
  3785. prev: prev
  3786. };
  3787. }
  3788. function pushThenStack(nextState) {
  3789. thenStack = {
  3790. nextState: nextState,
  3791. matchStack: matchStack,
  3792. syntaxStack: syntaxStack,
  3793. prev: thenStack
  3794. };
  3795. }
  3796. function pushElseStack(nextState) {
  3797. elseStack = stateSnapshotFromSyntax(nextState, elseStack);
  3798. }
  3799. function addTokenToMatch() {
  3800. matchStack = {
  3801. type: TOKEN,
  3802. syntax: state.syntax,
  3803. token: token,
  3804. prev: matchStack
  3805. };
  3806. moveToNextToken();
  3807. syntaxStash = null;
  3808. if (tokenIndex > longestMatch) {
  3809. longestMatch = tokenIndex;
  3810. }
  3811. }
  3812. function openSyntax() {
  3813. syntaxStack = {
  3814. syntax: state.syntax,
  3815. opts: state.syntax.opts || (syntaxStack !== null && syntaxStack.opts) || null,
  3816. prev: syntaxStack
  3817. };
  3818. matchStack = {
  3819. type: OPEN_SYNTAX,
  3820. syntax: state.syntax,
  3821. token: matchStack.token,
  3822. prev: matchStack
  3823. };
  3824. }
  3825. function closeSyntax() {
  3826. if (matchStack.type === OPEN_SYNTAX) {
  3827. matchStack = matchStack.prev;
  3828. } else {
  3829. matchStack = {
  3830. type: CLOSE_SYNTAX,
  3831. syntax: syntaxStack.syntax,
  3832. token: matchStack.token,
  3833. prev: matchStack
  3834. };
  3835. }
  3836. syntaxStack = syntaxStack.prev;
  3837. }
  3838. var syntaxStack = null;
  3839. var thenStack = null;
  3840. var elseStack = null;
  3841. // null – stashing allowed, nothing stashed
  3842. // false – stashing disabled, nothing stashed
  3843. // anithing else – fail stashable syntaxes, some syntax stashed
  3844. var syntaxStash = null;
  3845. var iterationCount = 0; // count iterations and prevent infinite loop
  3846. var exitReason = null;
  3847. var token = null;
  3848. var tokenIndex = -1;
  3849. var longestMatch = 0;
  3850. var matchStack = {
  3851. type: STUB,
  3852. syntax: null,
  3853. token: null,
  3854. prev: null
  3855. };
  3856. moveToNextToken();
  3857. while (exitReason === null && ++iterationCount < ITERATION_LIMIT) {
  3858. // function mapList(list, fn) {
  3859. // var result = [];
  3860. // while (list) {
  3861. // result.unshift(fn(list));
  3862. // list = list.prev;
  3863. // }
  3864. // return result;
  3865. // }
  3866. // console.log('--\n',
  3867. // '#' + iterationCount,
  3868. // require('util').inspect({
  3869. // match: mapList(matchStack, x => x.type === TOKEN ? x.token && x.token.value : x.syntax ? ({ [OPEN_SYNTAX]: '<', [CLOSE_SYNTAX]: '</' }[x.type] || x.type) + '!' + x.syntax.name : null),
  3870. // token: token && token.value,
  3871. // tokenIndex,
  3872. // syntax: syntax.type + (syntax.id ? ' #' + syntax.id : '')
  3873. // }, { depth: null })
  3874. // );
  3875. switch (state.type) {
  3876. case 'Match':
  3877. if (thenStack === null) {
  3878. // turn to MISMATCH when some tokens left unmatched
  3879. if (token !== null) {
  3880. // doesn't mismatch if just one token left and it's an IE hack
  3881. if (tokenIndex !== tokens.length - 1 || (token.value !== '\\0' && token.value !== '\\9')) {
  3882. state = MISMATCH$1;
  3883. break;
  3884. }
  3885. }
  3886. // break the main loop, return a result - MATCH
  3887. exitReason = EXIT_REASON_MATCH;
  3888. break;
  3889. }
  3890. // go to next syntax (`then` branch)
  3891. state = thenStack.nextState;
  3892. // check match is not empty
  3893. if (state === DISALLOW_EMPTY$1) {
  3894. if (thenStack.matchStack === matchStack) {
  3895. state = MISMATCH$1;
  3896. break;
  3897. } else {
  3898. state = MATCH$1;
  3899. }
  3900. }
  3901. // close syntax if needed
  3902. while (thenStack.syntaxStack !== syntaxStack) {
  3903. closeSyntax();
  3904. }
  3905. // pop stack
  3906. thenStack = thenStack.prev;
  3907. break;
  3908. case 'Mismatch':
  3909. // when some syntax is stashed
  3910. if (syntaxStash !== null && syntaxStash !== false) {
  3911. // there is no else branches or a branch reduce match stack
  3912. if (elseStack === null || tokenIndex > elseStack.tokenIndex) {
  3913. // restore state from the stash
  3914. elseStack = syntaxStash;
  3915. syntaxStash = false; // disable stashing
  3916. }
  3917. } else if (elseStack === null) {
  3918. // no else branches -> break the main loop
  3919. // return a result - MISMATCH
  3920. exitReason = EXIT_REASON_MISMATCH;
  3921. break;
  3922. }
  3923. // go to next syntax (`else` branch)
  3924. state = elseStack.nextState;
  3925. // restore all the rest stack states
  3926. thenStack = elseStack.thenStack;
  3927. syntaxStack = elseStack.syntaxStack;
  3928. matchStack = elseStack.matchStack;
  3929. tokenIndex = elseStack.tokenIndex;
  3930. token = tokenIndex < tokens.length ? tokens[tokenIndex] : null;
  3931. // pop stack
  3932. elseStack = elseStack.prev;
  3933. break;
  3934. case 'MatchGraph':
  3935. state = state.match;
  3936. break;
  3937. case 'If':
  3938. // IMPORTANT: else stack push must go first,
  3939. // since it stores the state of thenStack before changes
  3940. if (state.else !== MISMATCH$1) {
  3941. pushElseStack(state.else);
  3942. }
  3943. if (state.then !== MATCH$1) {
  3944. pushThenStack(state.then);
  3945. }
  3946. state = state.match;
  3947. break;
  3948. case 'MatchOnce':
  3949. state = {
  3950. type: 'MatchOnceBuffer',
  3951. syntax: state,
  3952. index: 0,
  3953. mask: 0
  3954. };
  3955. break;
  3956. case 'MatchOnceBuffer':
  3957. var terms = state.syntax.terms;
  3958. if (state.index === terms.length) {
  3959. // no matches at all or it's required all terms to be matched
  3960. if (state.mask === 0 || state.syntax.all) {
  3961. state = MISMATCH$1;
  3962. break;
  3963. }
  3964. // a partial match is ok
  3965. state = MATCH$1;
  3966. break;
  3967. }
  3968. // all terms are matched
  3969. if (state.mask === (1 << terms.length) - 1) {
  3970. state = MATCH$1;
  3971. break;
  3972. }
  3973. for (; state.index < terms.length; state.index++) {
  3974. var matchFlag = 1 << state.index;
  3975. if ((state.mask & matchFlag) === 0) {
  3976. // IMPORTANT: else stack push must go first,
  3977. // since it stores the state of thenStack before changes
  3978. pushElseStack(state);
  3979. pushThenStack({
  3980. type: 'AddMatchOnce',
  3981. syntax: state.syntax,
  3982. mask: state.mask | matchFlag
  3983. });
  3984. // match
  3985. state = terms[state.index++];
  3986. break;
  3987. }
  3988. }
  3989. break;
  3990. case 'AddMatchOnce':
  3991. state = {
  3992. type: 'MatchOnceBuffer',
  3993. syntax: state.syntax,
  3994. index: 0,
  3995. mask: state.mask
  3996. };
  3997. break;
  3998. case 'Enum':
  3999. if (token !== null) {
  4000. var name = token.value.toLowerCase();
  4001. // drop \0 and \9 hack from keyword name
  4002. if (name.indexOf('\\') !== -1) {
  4003. name = name.replace(/\\[09].*$/, '');
  4004. }
  4005. if (hasOwnProperty$1.call(state.map, name)) {
  4006. state = state.map[name];
  4007. break;
  4008. }
  4009. }
  4010. state = MISMATCH$1;
  4011. break;
  4012. case 'Generic':
  4013. var opts = syntaxStack !== null ? syntaxStack.opts : null;
  4014. var lastTokenIndex = tokenIndex + Math.floor(state.fn(token, getNextToken, opts));
  4015. if (!isNaN(lastTokenIndex) && lastTokenIndex > tokenIndex) {
  4016. while (tokenIndex < lastTokenIndex) {
  4017. addTokenToMatch();
  4018. }
  4019. state = MATCH$1;
  4020. } else {
  4021. state = MISMATCH$1;
  4022. }
  4023. break;
  4024. case 'Type':
  4025. case 'Property':
  4026. var syntaxDict = state.type === 'Type' ? 'types' : 'properties';
  4027. var dictSyntax = hasOwnProperty$1.call(syntaxes, syntaxDict) ? syntaxes[syntaxDict][state.name] : null;
  4028. if (!dictSyntax || !dictSyntax.match) {
  4029. throw new Error(
  4030. 'Bad syntax reference: ' +
  4031. (state.type === 'Type'
  4032. ? '<' + state.name + '>'
  4033. : '<\'' + state.name + '\'>')
  4034. );
  4035. }
  4036. // stash a syntax for types with low priority
  4037. if (syntaxStash !== false && token !== null && state.type === 'Type') {
  4038. var lowPriorityMatching =
  4039. // https://drafts.csswg.org/css-values-4/#custom-idents
  4040. // When parsing positionally-ambiguous keywords in a property value, a <custom-ident> production
  4041. // can only claim the keyword if no other unfulfilled production can claim it.
  4042. (state.name === 'custom-ident' && token.type === TYPE$6.Ident) ||
  4043. // https://drafts.csswg.org/css-values-4/#lengths
  4044. // ... if a `0` could be parsed as either a <number> or a <length> in a property (such as line-height),
  4045. // it must parse as a <number>
  4046. (state.name === 'length' && token.value === '0');
  4047. if (lowPriorityMatching) {
  4048. if (syntaxStash === null) {
  4049. syntaxStash = stateSnapshotFromSyntax(state, elseStack);
  4050. }
  4051. state = MISMATCH$1;
  4052. break;
  4053. }
  4054. }
  4055. openSyntax();
  4056. state = dictSyntax.match;
  4057. break;
  4058. case 'Keyword':
  4059. var name = state.name;
  4060. if (token !== null) {
  4061. var keywordName = token.value;
  4062. // drop \0 and \9 hack from keyword name
  4063. if (keywordName.indexOf('\\') !== -1) {
  4064. keywordName = keywordName.replace(/\\[09].*$/, '');
  4065. }
  4066. if (areStringsEqualCaseInsensitive(keywordName, name)) {
  4067. addTokenToMatch();
  4068. state = MATCH$1;
  4069. break;
  4070. }
  4071. }
  4072. state = MISMATCH$1;
  4073. break;
  4074. case 'AtKeyword':
  4075. case 'Function':
  4076. if (token !== null && areStringsEqualCaseInsensitive(token.value, state.name)) {
  4077. addTokenToMatch();
  4078. state = MATCH$1;
  4079. break;
  4080. }
  4081. state = MISMATCH$1;
  4082. break;
  4083. case 'Token':
  4084. if (token !== null && token.value === state.value) {
  4085. addTokenToMatch();
  4086. state = MATCH$1;
  4087. break;
  4088. }
  4089. state = MISMATCH$1;
  4090. break;
  4091. case 'Comma':
  4092. if (token !== null && token.type === TYPE$6.Comma) {
  4093. if (isCommaContextStart(matchStack.token)) {
  4094. state = MISMATCH$1;
  4095. } else {
  4096. addTokenToMatch();
  4097. state = isCommaContextEnd(token) ? MISMATCH$1 : MATCH$1;
  4098. }
  4099. } else {
  4100. state = isCommaContextStart(matchStack.token) || isCommaContextEnd(token) ? MATCH$1 : MISMATCH$1;
  4101. }
  4102. break;
  4103. case 'String':
  4104. var string = '';
  4105. for (var lastTokenIndex = tokenIndex; lastTokenIndex < tokens.length && string.length < state.value.length; lastTokenIndex++) {
  4106. string += tokens[lastTokenIndex].value;
  4107. }
  4108. if (areStringsEqualCaseInsensitive(string, state.value)) {
  4109. while (tokenIndex < lastTokenIndex) {
  4110. addTokenToMatch();
  4111. }
  4112. state = MATCH$1;
  4113. } else {
  4114. state = MISMATCH$1;
  4115. }
  4116. break;
  4117. default:
  4118. throw new Error('Unknown node type: ' + state.type);
  4119. }
  4120. }
  4121. totalIterationCount += iterationCount;
  4122. switch (exitReason) {
  4123. case null:
  4124. console.warn('[csstree-match] BREAK after ' + ITERATION_LIMIT + ' iterations');
  4125. exitReason = EXIT_REASON_ITERATION_LIMIT;
  4126. matchStack = null;
  4127. break;
  4128. case EXIT_REASON_MATCH:
  4129. while (syntaxStack !== null) {
  4130. closeSyntax();
  4131. }
  4132. break;
  4133. default:
  4134. matchStack = null;
  4135. }
  4136. return {
  4137. tokens: tokens,
  4138. reason: exitReason,
  4139. iterations: iterationCount,
  4140. match: matchStack,
  4141. longestMatch: longestMatch
  4142. };
  4143. }
  4144. function matchAsList(tokens, matchGraph, syntaxes) {
  4145. var matchResult = internalMatch(tokens, matchGraph, syntaxes || {});
  4146. if (matchResult.match !== null) {
  4147. var item = reverseList(matchResult.match).prev;
  4148. matchResult.match = [];
  4149. while (item !== null) {
  4150. switch (item.type) {
  4151. case STUB:
  4152. break;
  4153. case OPEN_SYNTAX:
  4154. case CLOSE_SYNTAX:
  4155. matchResult.match.push({
  4156. type: item.type,
  4157. syntax: item.syntax
  4158. });
  4159. break;
  4160. default:
  4161. matchResult.match.push({
  4162. token: item.token.value,
  4163. node: item.token.node
  4164. });
  4165. break;
  4166. }
  4167. item = item.prev;
  4168. }
  4169. }
  4170. return matchResult;
  4171. }
  4172. function matchAsTree(tokens, matchGraph, syntaxes) {
  4173. var matchResult = internalMatch(tokens, matchGraph, syntaxes || {});
  4174. if (matchResult.match === null) {
  4175. return matchResult;
  4176. }
  4177. var item = matchResult.match;
  4178. var host = matchResult.match = {
  4179. syntax: matchGraph.syntax || null,
  4180. match: []
  4181. };
  4182. var hostStack = [host];
  4183. // revert a list and start with 2nd item since 1st is a stub item
  4184. item = reverseList(item).prev;
  4185. // build a tree
  4186. while (item !== null) {
  4187. switch (item.type) {
  4188. case OPEN_SYNTAX:
  4189. host.match.push(host = {
  4190. syntax: item.syntax,
  4191. match: []
  4192. });
  4193. hostStack.push(host);
  4194. break;
  4195. case CLOSE_SYNTAX:
  4196. hostStack.pop();
  4197. host = hostStack[hostStack.length - 1];
  4198. break;
  4199. default:
  4200. host.match.push({
  4201. syntax: item.syntax || null,
  4202. token: item.token.value,
  4203. node: item.token.node
  4204. });
  4205. }
  4206. item = item.prev;
  4207. }
  4208. return matchResult;
  4209. }
  4210. var match = {
  4211. matchAsList: matchAsList,
  4212. matchAsTree: matchAsTree,
  4213. getTotalIterationCount: function() {
  4214. return totalIterationCount;
  4215. }
  4216. };
  4217. function getTrace(node) {
  4218. function shouldPutToTrace(syntax) {
  4219. if (syntax === null) {
  4220. return false;
  4221. }
  4222. return (
  4223. syntax.type === 'Type' ||
  4224. syntax.type === 'Property' ||
  4225. syntax.type === 'Keyword'
  4226. );
  4227. }
  4228. function hasMatch(matchNode) {
  4229. if (Array.isArray(matchNode.match)) {
  4230. // use for-loop for better perfomance
  4231. for (var i = 0; i < matchNode.match.length; i++) {
  4232. if (hasMatch(matchNode.match[i])) {
  4233. if (shouldPutToTrace(matchNode.syntax)) {
  4234. result.unshift(matchNode.syntax);
  4235. }
  4236. return true;
  4237. }
  4238. }
  4239. } else if (matchNode.node === node) {
  4240. result = shouldPutToTrace(matchNode.syntax)
  4241. ? [matchNode.syntax]
  4242. : [];
  4243. return true;
  4244. }
  4245. return false;
  4246. }
  4247. var result = null;
  4248. if (this.matched !== null) {
  4249. hasMatch(this.matched);
  4250. }
  4251. return result;
  4252. }
  4253. function testNode(match, node, fn) {
  4254. var trace = getTrace.call(match, node);
  4255. if (trace === null) {
  4256. return false;
  4257. }
  4258. return trace.some(fn);
  4259. }
  4260. function isType(node, type) {
  4261. return testNode(this, node, function(matchNode) {
  4262. return matchNode.type === 'Type' && matchNode.name === type;
  4263. });
  4264. }
  4265. function isProperty(node, property) {
  4266. return testNode(this, node, function(matchNode) {
  4267. return matchNode.type === 'Property' && matchNode.name === property;
  4268. });
  4269. }
  4270. function isKeyword(node) {
  4271. return testNode(this, node, function(matchNode) {
  4272. return matchNode.type === 'Keyword';
  4273. });
  4274. }
  4275. var trace = {
  4276. getTrace: getTrace,
  4277. isType: isType,
  4278. isProperty: isProperty,
  4279. isKeyword: isKeyword
  4280. };
  4281. function getFirstMatchNode(matchNode) {
  4282. if ('node' in matchNode) {
  4283. return matchNode.node;
  4284. }
  4285. return getFirstMatchNode(matchNode.match[0]);
  4286. }
  4287. function getLastMatchNode(matchNode) {
  4288. if ('node' in matchNode) {
  4289. return matchNode.node;
  4290. }
  4291. return getLastMatchNode(matchNode.match[matchNode.match.length - 1]);
  4292. }
  4293. function matchFragments(lexer, ast, match, type, name) {
  4294. function findFragments(matchNode) {
  4295. if (matchNode.syntax !== null &&
  4296. matchNode.syntax.type === type &&
  4297. matchNode.syntax.name === name) {
  4298. var start = getFirstMatchNode(matchNode);
  4299. var end = getLastMatchNode(matchNode);
  4300. lexer.syntax.walk(ast, function(node, item, list) {
  4301. if (node === start) {
  4302. var nodes = new List_1();
  4303. do {
  4304. nodes.appendData(item.data);
  4305. if (item.data === end) {
  4306. break;
  4307. }
  4308. item = item.next;
  4309. } while (item !== null);
  4310. fragments.push({
  4311. parent: list,
  4312. nodes: nodes
  4313. });
  4314. }
  4315. });
  4316. }
  4317. if (Array.isArray(matchNode.match)) {
  4318. matchNode.match.forEach(findFragments);
  4319. }
  4320. }
  4321. var fragments = [];
  4322. if (match.matched !== null) {
  4323. findFragments(match.matched);
  4324. }
  4325. return fragments;
  4326. }
  4327. var search = {
  4328. matchFragments: matchFragments
  4329. };
  4330. var hasOwnProperty$2 = Object.prototype.hasOwnProperty;
  4331. function isValidNumber(value) {
  4332. // Number.isInteger(value) && value >= 0
  4333. return (
  4334. typeof value === 'number' &&
  4335. isFinite(value) &&
  4336. Math.floor(value) === value &&
  4337. value >= 0
  4338. );
  4339. }
  4340. function isValidLocation(loc) {
  4341. return (
  4342. Boolean(loc) &&
  4343. isValidNumber(loc.offset) &&
  4344. isValidNumber(loc.line) &&
  4345. isValidNumber(loc.column)
  4346. );
  4347. }
  4348. function createNodeStructureChecker(type, fields) {
  4349. return function checkNode(node, warn) {
  4350. if (!node || node.constructor !== Object) {
  4351. return warn(node, 'Type of node should be an Object');
  4352. }
  4353. for (var key in node) {
  4354. var valid = true;
  4355. if (hasOwnProperty$2.call(node, key) === false) {
  4356. continue;
  4357. }
  4358. if (key === 'type') {
  4359. if (node.type !== type) {
  4360. warn(node, 'Wrong node type `' + node.type + '`, expected `' + type + '`');
  4361. }
  4362. } else if (key === 'loc') {
  4363. if (node.loc === null) {
  4364. continue;
  4365. } else if (node.loc && node.loc.constructor === Object) {
  4366. if (typeof node.loc.source !== 'string') {
  4367. key += '.source';
  4368. } else if (!isValidLocation(node.loc.start)) {
  4369. key += '.start';
  4370. } else if (!isValidLocation(node.loc.end)) {
  4371. key += '.end';
  4372. } else {
  4373. continue;
  4374. }
  4375. }
  4376. valid = false;
  4377. } else if (fields.hasOwnProperty(key)) {
  4378. for (var i = 0, valid = false; !valid && i < fields[key].length; i++) {
  4379. var fieldType = fields[key][i];
  4380. switch (fieldType) {
  4381. case String:
  4382. valid = typeof node[key] === 'string';
  4383. break;
  4384. case Boolean:
  4385. valid = typeof node[key] === 'boolean';
  4386. break;
  4387. case null:
  4388. valid = node[key] === null;
  4389. break;
  4390. default:
  4391. if (typeof fieldType === 'string') {
  4392. valid = node[key] && node[key].type === fieldType;
  4393. } else if (Array.isArray(fieldType)) {
  4394. valid = node[key] instanceof List_1;
  4395. }
  4396. }
  4397. }
  4398. } else {
  4399. warn(node, 'Unknown field `' + key + '` for ' + type + ' node type');
  4400. }
  4401. if (!valid) {
  4402. warn(node, 'Bad value for `' + type + '.' + key + '`');
  4403. }
  4404. }
  4405. for (var key in fields) {
  4406. if (hasOwnProperty$2.call(fields, key) &&
  4407. hasOwnProperty$2.call(node, key) === false) {
  4408. warn(node, 'Field `' + type + '.' + key + '` is missed');
  4409. }
  4410. }
  4411. };
  4412. }
  4413. function processStructure(name, nodeType) {
  4414. var structure = nodeType.structure;
  4415. var fields = {
  4416. type: String,
  4417. loc: true
  4418. };
  4419. var docs = {
  4420. type: '"' + name + '"'
  4421. };
  4422. for (var key in structure) {
  4423. if (hasOwnProperty$2.call(structure, key) === false) {
  4424. continue;
  4425. }
  4426. var docsTypes = [];
  4427. var fieldTypes = fields[key] = Array.isArray(structure[key])
  4428. ? structure[key].slice()
  4429. : [structure[key]];
  4430. for (var i = 0; i < fieldTypes.length; i++) {
  4431. var fieldType = fieldTypes[i];
  4432. if (fieldType === String || fieldType === Boolean) {
  4433. docsTypes.push(fieldType.name);
  4434. } else if (fieldType === null) {
  4435. docsTypes.push('null');
  4436. } else if (typeof fieldType === 'string') {
  4437. docsTypes.push('<' + fieldType + '>');
  4438. } else if (Array.isArray(fieldType)) {
  4439. docsTypes.push('List'); // TODO: use type enum
  4440. } else {
  4441. throw new Error('Wrong value `' + fieldType + '` in `' + name + '.' + key + '` structure definition');
  4442. }
  4443. }
  4444. docs[key] = docsTypes.join(' | ');
  4445. }
  4446. return {
  4447. docs: docs,
  4448. check: createNodeStructureChecker(name, fields)
  4449. };
  4450. }
  4451. var structure = {
  4452. getStructureFromConfig: function(config) {
  4453. var structure = {};
  4454. if (config.node) {
  4455. for (var name in config.node) {
  4456. if (hasOwnProperty$2.call(config.node, name)) {
  4457. var nodeType = config.node[name];
  4458. if (nodeType.structure) {
  4459. structure[name] = processStructure(name, nodeType);
  4460. } else {
  4461. throw new Error('Missed `structure` field in `' + name + '` node type definition');
  4462. }
  4463. }
  4464. }
  4465. }
  4466. return structure;
  4467. }
  4468. };
  4469. var SyntaxReferenceError$1 = error.SyntaxReferenceError;
  4470. var MatchError$1 = error.MatchError;
  4471. var buildMatchGraph$1 = matchGraph.buildMatchGraph;
  4472. var matchAsTree$1 = match.matchAsTree;
  4473. var getStructureFromConfig = structure.getStructureFromConfig;
  4474. var cssWideKeywords$1 = buildMatchGraph$1('inherit | initial | unset');
  4475. var cssWideKeywordsWithExpression = buildMatchGraph$1('inherit | initial | unset | <-ms-legacy-expression>');
  4476. function dumpMapSyntax(map, compact, syntaxAsAst) {
  4477. var result = {};
  4478. for (var name in map) {
  4479. if (map[name].syntax) {
  4480. result[name] = syntaxAsAst
  4481. ? map[name].syntax
  4482. : generate_1(map[name].syntax, { compact: compact });
  4483. }
  4484. }
  4485. return result;
  4486. }
  4487. function valueHasVar(tokens) {
  4488. for (var i = 0; i < tokens.length; i++) {
  4489. if (tokens[i].value.toLowerCase() === 'var(') {
  4490. return true;
  4491. }
  4492. }
  4493. return false;
  4494. }
  4495. function buildMatchResult(match, error, iterations) {
  4496. return {
  4497. matched: match,
  4498. iterations: iterations,
  4499. error: error,
  4500. getTrace: trace.getTrace,
  4501. isType: trace.isType,
  4502. isProperty: trace.isProperty,
  4503. isKeyword: trace.isKeyword
  4504. };
  4505. }
  4506. function matchSyntax(lexer, syntax, value, useCommon) {
  4507. var tokens = prepareTokens_1(value, lexer.syntax);
  4508. var result;
  4509. if (valueHasVar(tokens)) {
  4510. return buildMatchResult(null, new Error('Matching for a tree with var() is not supported'));
  4511. }
  4512. if (useCommon) {
  4513. result = matchAsTree$1(tokens, lexer.valueCommonSyntax, lexer);
  4514. }
  4515. if (!useCommon || !result.match) {
  4516. result = matchAsTree$1(tokens, syntax.match, lexer);
  4517. if (!result.match) {
  4518. return buildMatchResult(
  4519. null,
  4520. new MatchError$1(result.reason, syntax.syntax, value, result),
  4521. result.iterations
  4522. );
  4523. }
  4524. }
  4525. return buildMatchResult(result.match, null, result.iterations);
  4526. }
  4527. var Lexer = function(config, syntax, structure) {
  4528. this.valueCommonSyntax = cssWideKeywords$1;
  4529. this.syntax = syntax;
  4530. this.generic = false;
  4531. this.atrules = {};
  4532. this.properties = {};
  4533. this.types = {};
  4534. this.structure = structure || getStructureFromConfig(config);
  4535. if (config) {
  4536. if (config.types) {
  4537. for (var name in config.types) {
  4538. this.addType_(name, config.types[name]);
  4539. }
  4540. }
  4541. if (config.generic) {
  4542. this.generic = true;
  4543. for (var name in generic) {
  4544. this.addType_(name, generic[name]);
  4545. }
  4546. }
  4547. if (config.atrules) {
  4548. for (var name in config.atrules) {
  4549. this.addAtrule_(name, config.atrules[name]);
  4550. }
  4551. }
  4552. if (config.properties) {
  4553. for (var name in config.properties) {
  4554. this.addProperty_(name, config.properties[name]);
  4555. }
  4556. }
  4557. }
  4558. };
  4559. Lexer.prototype = {
  4560. structure: {},
  4561. checkStructure: function(ast) {
  4562. function collectWarning(node, message) {
  4563. warns.push({
  4564. node: node,
  4565. message: message
  4566. });
  4567. }
  4568. var structure = this.structure;
  4569. var warns = [];
  4570. this.syntax.walk(ast, function(node) {
  4571. if (structure.hasOwnProperty(node.type)) {
  4572. structure[node.type].check(node, collectWarning);
  4573. } else {
  4574. collectWarning(node, 'Unknown node type `' + node.type + '`');
  4575. }
  4576. });
  4577. return warns.length ? warns : false;
  4578. },
  4579. createDescriptor: function(syntax, type, name) {
  4580. var ref = {
  4581. type: type,
  4582. name: name
  4583. };
  4584. var descriptor = {
  4585. type: type,
  4586. name: name,
  4587. syntax: null,
  4588. match: null
  4589. };
  4590. if (typeof syntax === 'function') {
  4591. descriptor.match = buildMatchGraph$1(syntax, ref);
  4592. } else {
  4593. if (typeof syntax === 'string') {
  4594. // lazy parsing on first access
  4595. Object.defineProperty(descriptor, 'syntax', {
  4596. get: function() {
  4597. Object.defineProperty(descriptor, 'syntax', {
  4598. value: parse_1(syntax)
  4599. });
  4600. return descriptor.syntax;
  4601. }
  4602. });
  4603. } else {
  4604. descriptor.syntax = syntax;
  4605. }
  4606. // lazy graph build on first access
  4607. Object.defineProperty(descriptor, 'match', {
  4608. get: function() {
  4609. Object.defineProperty(descriptor, 'match', {
  4610. value: buildMatchGraph$1(descriptor.syntax, ref)
  4611. });
  4612. return descriptor.match;
  4613. }
  4614. });
  4615. }
  4616. return descriptor;
  4617. },
  4618. addAtrule_: function(name, syntax) {
  4619. this.atrules[name] = {
  4620. prelude: syntax.prelude ? this.createDescriptor(syntax.prelude, 'AtrulePrelude', name) : null,
  4621. descriptors: syntax.descriptors
  4622. ? Object.keys(syntax.descriptors).reduce((res, name) => {
  4623. res[name] = this.createDescriptor(syntax.descriptors[name], 'AtruleDescriptor', name);
  4624. return res;
  4625. }, {})
  4626. : null
  4627. };
  4628. },
  4629. addProperty_: function(name, syntax) {
  4630. this.properties[name] = this.createDescriptor(syntax, 'Property', name);
  4631. },
  4632. addType_: function(name, syntax) {
  4633. this.types[name] = this.createDescriptor(syntax, 'Type', name);
  4634. if (syntax === generic['-ms-legacy-expression']) {
  4635. this.valueCommonSyntax = cssWideKeywordsWithExpression;
  4636. }
  4637. },
  4638. matchAtrulePrelude: function(atruleName, prelude) {
  4639. var atrule = names.keyword(atruleName);
  4640. var atrulePreludeSyntax = atrule.vendor
  4641. ? this.getAtrulePrelude(atrule.name) || this.getAtrulePrelude(atrule.basename)
  4642. : this.getAtrulePrelude(atrule.name);
  4643. if (!atrulePreludeSyntax) {
  4644. if (atrule.basename in this.atrules) {
  4645. return buildMatchResult(null, new Error('At-rule `' + atruleName + '` should not contain a prelude'));
  4646. }
  4647. return buildMatchResult(null, new SyntaxReferenceError$1('Unknown at-rule', atruleName));
  4648. }
  4649. return matchSyntax(this, atrulePreludeSyntax, prelude, true);
  4650. },
  4651. matchAtruleDescriptor: function(atruleName, descriptorName, value) {
  4652. var atrule = names.keyword(atruleName);
  4653. var descriptor = names.keyword(descriptorName);
  4654. var atruleEntry = atrule.vendor
  4655. ? this.atrules[atrule.name] || this.atrules[atrule.basename]
  4656. : this.atrules[atrule.name];
  4657. if (!atruleEntry) {
  4658. return buildMatchResult(null, new SyntaxReferenceError$1('Unknown at-rule', atruleName));
  4659. }
  4660. if (!atruleEntry.descriptors) {
  4661. return buildMatchResult(null, new Error('At-rule `' + atruleName + '` has no known descriptors'));
  4662. }
  4663. var atruleDescriptorSyntax = descriptor.vendor
  4664. ? atruleEntry.descriptors[descriptor.name] || atruleEntry.descriptors[descriptor.basename]
  4665. : atruleEntry.descriptors[descriptor.name];
  4666. if (!atruleDescriptorSyntax) {
  4667. return buildMatchResult(null, new SyntaxReferenceError$1('Unknown at-rule descriptor', descriptorName));
  4668. }
  4669. return matchSyntax(this, atruleDescriptorSyntax, value, true);
  4670. },
  4671. matchDeclaration: function(node) {
  4672. if (node.type !== 'Declaration') {
  4673. return buildMatchResult(null, new Error('Not a Declaration node'));
  4674. }
  4675. return this.matchProperty(node.property, node.value);
  4676. },
  4677. matchProperty: function(propertyName, value) {
  4678. var property = names.property(propertyName);
  4679. // don't match syntax for a custom property
  4680. if (property.custom) {
  4681. return buildMatchResult(null, new Error('Lexer matching doesn\'t applicable for custom properties'));
  4682. }
  4683. var propertySyntax = property.vendor
  4684. ? this.getProperty(property.name) || this.getProperty(property.basename)
  4685. : this.getProperty(property.name);
  4686. if (!propertySyntax) {
  4687. return buildMatchResult(null, new SyntaxReferenceError$1('Unknown property', propertyName));
  4688. }
  4689. return matchSyntax(this, propertySyntax, value, true);
  4690. },
  4691. matchType: function(typeName, value) {
  4692. var typeSyntax = this.getType(typeName);
  4693. if (!typeSyntax) {
  4694. return buildMatchResult(null, new SyntaxReferenceError$1('Unknown type', typeName));
  4695. }
  4696. return matchSyntax(this, typeSyntax, value, false);
  4697. },
  4698. match: function(syntax, value) {
  4699. if (typeof syntax !== 'string' && (!syntax || !syntax.type)) {
  4700. return buildMatchResult(null, new SyntaxReferenceError$1('Bad syntax'));
  4701. }
  4702. if (typeof syntax === 'string' || !syntax.match) {
  4703. syntax = this.createDescriptor(syntax, 'Type', 'anonymous');
  4704. }
  4705. return matchSyntax(this, syntax, value, false);
  4706. },
  4707. findValueFragments: function(propertyName, value, type, name) {
  4708. return search.matchFragments(this, value, this.matchProperty(propertyName, value), type, name);
  4709. },
  4710. findDeclarationValueFragments: function(declaration, type, name) {
  4711. return search.matchFragments(this, declaration.value, this.matchDeclaration(declaration), type, name);
  4712. },
  4713. findAllFragments: function(ast, type, name) {
  4714. var result = [];
  4715. this.syntax.walk(ast, {
  4716. visit: 'Declaration',
  4717. enter: function(declaration) {
  4718. result.push.apply(result, this.findDeclarationValueFragments(declaration, type, name));
  4719. }.bind(this)
  4720. });
  4721. return result;
  4722. },
  4723. getAtrulePrelude: function(atruleName) {
  4724. return this.atrules.hasOwnProperty(atruleName) ? this.atrules[atruleName].prelude : null;
  4725. },
  4726. getAtruleDescriptor: function(atruleName, name) {
  4727. return this.atrules.hasOwnProperty(atruleName) && this.atrules.declarators
  4728. ? this.atrules[atruleName].declarators[name] || null
  4729. : null;
  4730. },
  4731. getProperty: function(name) {
  4732. return this.properties.hasOwnProperty(name) ? this.properties[name] : null;
  4733. },
  4734. getType: function(name) {
  4735. return this.types.hasOwnProperty(name) ? this.types[name] : null;
  4736. },
  4737. validate: function() {
  4738. function validate(syntax, name, broken, descriptor) {
  4739. if (broken.hasOwnProperty(name)) {
  4740. return broken[name];
  4741. }
  4742. broken[name] = false;
  4743. if (descriptor.syntax !== null) {
  4744. walk(descriptor.syntax, function(node) {
  4745. if (node.type !== 'Type' && node.type !== 'Property') {
  4746. return;
  4747. }
  4748. var map = node.type === 'Type' ? syntax.types : syntax.properties;
  4749. var brokenMap = node.type === 'Type' ? brokenTypes : brokenProperties;
  4750. if (!map.hasOwnProperty(node.name) || validate(syntax, node.name, brokenMap, map[node.name])) {
  4751. broken[name] = true;
  4752. }
  4753. }, this);
  4754. }
  4755. }
  4756. var brokenTypes = {};
  4757. var brokenProperties = {};
  4758. for (var key in this.types) {
  4759. validate(this, key, brokenTypes, this.types[key]);
  4760. }
  4761. for (var key in this.properties) {
  4762. validate(this, key, brokenProperties, this.properties[key]);
  4763. }
  4764. brokenTypes = Object.keys(brokenTypes).filter(function(name) {
  4765. return brokenTypes[name];
  4766. });
  4767. brokenProperties = Object.keys(brokenProperties).filter(function(name) {
  4768. return brokenProperties[name];
  4769. });
  4770. if (brokenTypes.length || brokenProperties.length) {
  4771. return {
  4772. types: brokenTypes,
  4773. properties: brokenProperties
  4774. };
  4775. }
  4776. return null;
  4777. },
  4778. dump: function(syntaxAsAst, pretty) {
  4779. return {
  4780. generic: this.generic,
  4781. types: dumpMapSyntax(this.types, !pretty, syntaxAsAst),
  4782. properties: dumpMapSyntax(this.properties, !pretty, syntaxAsAst)
  4783. };
  4784. },
  4785. toString: function() {
  4786. return JSON.stringify(this.dump());
  4787. }
  4788. };
  4789. var Lexer_1 = Lexer;
  4790. var definitionSyntax = {
  4791. SyntaxError: _SyntaxError$1,
  4792. parse: parse_1,
  4793. generate: generate_1,
  4794. walk: walk
  4795. };
  4796. var isBOM$2 = tokenizer.isBOM;
  4797. var N$3 = 10;
  4798. var F$2 = 12;
  4799. var R$2 = 13;
  4800. function computeLinesAndColumns(host, source) {
  4801. var sourceLength = source.length;
  4802. var lines = adoptBuffer(host.lines, sourceLength); // +1
  4803. var line = host.startLine;
  4804. var columns = adoptBuffer(host.columns, sourceLength);
  4805. var column = host.startColumn;
  4806. var startOffset = source.length > 0 ? isBOM$2(source.charCodeAt(0)) : 0;
  4807. for (var i = startOffset; i < sourceLength; i++) { // -1
  4808. var code = source.charCodeAt(i);
  4809. lines[i] = line;
  4810. columns[i] = column++;
  4811. if (code === N$3 || code === R$2 || code === F$2) {
  4812. if (code === R$2 && i + 1 < sourceLength && source.charCodeAt(i + 1) === N$3) {
  4813. i++;
  4814. lines[i] = line;
  4815. columns[i] = column;
  4816. }
  4817. line++;
  4818. column = 1;
  4819. }
  4820. }
  4821. lines[i] = line;
  4822. columns[i] = column;
  4823. host.lines = lines;
  4824. host.columns = columns;
  4825. }
  4826. var OffsetToLocation = function() {
  4827. this.lines = null;
  4828. this.columns = null;
  4829. this.linesAndColumnsComputed = false;
  4830. };
  4831. OffsetToLocation.prototype = {
  4832. setSource: function(source, startOffset, startLine, startColumn) {
  4833. this.source = source;
  4834. this.startOffset = typeof startOffset === 'undefined' ? 0 : startOffset;
  4835. this.startLine = typeof startLine === 'undefined' ? 1 : startLine;
  4836. this.startColumn = typeof startColumn === 'undefined' ? 1 : startColumn;
  4837. this.linesAndColumnsComputed = false;
  4838. },
  4839. ensureLinesAndColumnsComputed: function() {
  4840. if (!this.linesAndColumnsComputed) {
  4841. computeLinesAndColumns(this, this.source);
  4842. this.linesAndColumnsComputed = true;
  4843. }
  4844. },
  4845. getLocation: function(offset, filename) {
  4846. this.ensureLinesAndColumnsComputed();
  4847. return {
  4848. source: filename,
  4849. offset: this.startOffset + offset,
  4850. line: this.lines[offset],
  4851. column: this.columns[offset]
  4852. };
  4853. },
  4854. getLocationRange: function(start, end, filename) {
  4855. this.ensureLinesAndColumnsComputed();
  4856. return {
  4857. source: filename,
  4858. start: {
  4859. offset: this.startOffset + start,
  4860. line: this.lines[start],
  4861. column: this.columns[start]
  4862. },
  4863. end: {
  4864. offset: this.startOffset + end,
  4865. line: this.lines[end],
  4866. column: this.columns[end]
  4867. }
  4868. };
  4869. }
  4870. };
  4871. var OffsetToLocation_1 = OffsetToLocation;
  4872. var TYPE$7 = tokenizer.TYPE;
  4873. var WHITESPACE$2 = TYPE$7.WhiteSpace;
  4874. var COMMENT$2 = TYPE$7.Comment;
  4875. var sequence = function readSequence(recognizer) {
  4876. var children = this.createList();
  4877. var child = null;
  4878. var context = {
  4879. recognizer: recognizer,
  4880. space: null,
  4881. ignoreWS: false,
  4882. ignoreWSAfter: false
  4883. };
  4884. this.scanner.skipSC();
  4885. while (!this.scanner.eof) {
  4886. switch (this.scanner.tokenType) {
  4887. case COMMENT$2:
  4888. this.scanner.next();
  4889. continue;
  4890. case WHITESPACE$2:
  4891. if (context.ignoreWS) {
  4892. this.scanner.next();
  4893. } else {
  4894. context.space = this.WhiteSpace();
  4895. }
  4896. continue;
  4897. }
  4898. child = recognizer.getNode.call(this, context);
  4899. if (child === undefined) {
  4900. break;
  4901. }
  4902. if (context.space !== null) {
  4903. children.push(context.space);
  4904. context.space = null;
  4905. }
  4906. children.push(child);
  4907. if (context.ignoreWSAfter) {
  4908. context.ignoreWSAfter = false;
  4909. context.ignoreWS = true;
  4910. } else {
  4911. context.ignoreWS = false;
  4912. }
  4913. }
  4914. return children;
  4915. };
  4916. var findWhiteSpaceStart$1 = utils.findWhiteSpaceStart;
  4917. var noop$2 = function() {};
  4918. var TYPE$8 = _const.TYPE;
  4919. var NAME$2 = _const.NAME;
  4920. var WHITESPACE$3 = TYPE$8.WhiteSpace;
  4921. var IDENT$2 = TYPE$8.Ident;
  4922. var FUNCTION = TYPE$8.Function;
  4923. var URL = TYPE$8.Url;
  4924. var HASH = TYPE$8.Hash;
  4925. var PERCENTAGE = TYPE$8.Percentage;
  4926. var NUMBER$2 = TYPE$8.Number;
  4927. var NUMBERSIGN$1 = 0x0023; // U+0023 NUMBER SIGN (#)
  4928. var NULL = 0;
  4929. function createParseContext(name) {
  4930. return function() {
  4931. return this[name]();
  4932. };
  4933. }
  4934. function processConfig(config) {
  4935. var parserConfig = {
  4936. context: {},
  4937. scope: {},
  4938. atrule: {},
  4939. pseudo: {}
  4940. };
  4941. if (config.parseContext) {
  4942. for (var name in config.parseContext) {
  4943. switch (typeof config.parseContext[name]) {
  4944. case 'function':
  4945. parserConfig.context[name] = config.parseContext[name];
  4946. break;
  4947. case 'string':
  4948. parserConfig.context[name] = createParseContext(config.parseContext[name]);
  4949. break;
  4950. }
  4951. }
  4952. }
  4953. if (config.scope) {
  4954. for (var name in config.scope) {
  4955. parserConfig.scope[name] = config.scope[name];
  4956. }
  4957. }
  4958. if (config.atrule) {
  4959. for (var name in config.atrule) {
  4960. var atrule = config.atrule[name];
  4961. if (atrule.parse) {
  4962. parserConfig.atrule[name] = atrule.parse;
  4963. }
  4964. }
  4965. }
  4966. if (config.pseudo) {
  4967. for (var name in config.pseudo) {
  4968. var pseudo = config.pseudo[name];
  4969. if (pseudo.parse) {
  4970. parserConfig.pseudo[name] = pseudo.parse;
  4971. }
  4972. }
  4973. }
  4974. if (config.node) {
  4975. for (var name in config.node) {
  4976. parserConfig[name] = config.node[name].parse;
  4977. }
  4978. }
  4979. return parserConfig;
  4980. }
  4981. var create = function createParser(config) {
  4982. var parser = {
  4983. scanner: new TokenStream_1(),
  4984. locationMap: new OffsetToLocation_1(),
  4985. filename: '<unknown>',
  4986. needPositions: false,
  4987. onParseError: noop$2,
  4988. onParseErrorThrow: false,
  4989. parseAtrulePrelude: true,
  4990. parseRulePrelude: true,
  4991. parseValue: true,
  4992. parseCustomProperty: false,
  4993. readSequence: sequence,
  4994. createList: function() {
  4995. return new List_1();
  4996. },
  4997. createSingleNodeList: function(node) {
  4998. return new List_1().appendData(node);
  4999. },
  5000. getFirstListNode: function(list) {
  5001. return list && list.first();
  5002. },
  5003. getLastListNode: function(list) {
  5004. return list.last();
  5005. },
  5006. parseWithFallback: function(consumer, fallback) {
  5007. var startToken = this.scanner.tokenIndex;
  5008. try {
  5009. return consumer.call(this);
  5010. } catch (e) {
  5011. if (this.onParseErrorThrow) {
  5012. throw e;
  5013. }
  5014. var fallbackNode = fallback.call(this, startToken);
  5015. this.onParseErrorThrow = true;
  5016. this.onParseError(e, fallbackNode);
  5017. this.onParseErrorThrow = false;
  5018. return fallbackNode;
  5019. }
  5020. },
  5021. lookupNonWSType: function(offset) {
  5022. do {
  5023. var type = this.scanner.lookupType(offset++);
  5024. if (type !== WHITESPACE$3) {
  5025. return type;
  5026. }
  5027. } while (type !== NULL);
  5028. return NULL;
  5029. },
  5030. eat: function(tokenType) {
  5031. if (this.scanner.tokenType !== tokenType) {
  5032. var offset = this.scanner.tokenStart;
  5033. var message = NAME$2[tokenType] + ' is expected';
  5034. // tweak message and offset
  5035. switch (tokenType) {
  5036. case IDENT$2:
  5037. // when identifier is expected but there is a function or url
  5038. if (this.scanner.tokenType === FUNCTION || this.scanner.tokenType === URL) {
  5039. offset = this.scanner.tokenEnd - 1;
  5040. message = 'Identifier is expected but function found';
  5041. } else {
  5042. message = 'Identifier is expected';
  5043. }
  5044. break;
  5045. case HASH:
  5046. if (this.scanner.isDelim(NUMBERSIGN$1)) {
  5047. this.scanner.next();
  5048. offset++;
  5049. message = 'Name is expected';
  5050. }
  5051. break;
  5052. case PERCENTAGE:
  5053. if (this.scanner.tokenType === NUMBER$2) {
  5054. offset = this.scanner.tokenEnd;
  5055. message = 'Percent sign is expected';
  5056. }
  5057. break;
  5058. default:
  5059. // when test type is part of another token show error for current position + 1
  5060. // e.g. eat(HYPHENMINUS) will fail on "-foo", but pointing on "-" is odd
  5061. if (this.scanner.source.charCodeAt(this.scanner.tokenStart) === tokenType) {
  5062. offset = offset + 1;
  5063. }
  5064. }
  5065. this.error(message, offset);
  5066. }
  5067. this.scanner.next();
  5068. },
  5069. consume: function(tokenType) {
  5070. var value = this.scanner.getTokenValue();
  5071. this.eat(tokenType);
  5072. return value;
  5073. },
  5074. consumeFunctionName: function() {
  5075. var name = this.scanner.source.substring(this.scanner.tokenStart, this.scanner.tokenEnd - 1);
  5076. this.eat(FUNCTION);
  5077. return name;
  5078. },
  5079. getLocation: function(start, end) {
  5080. if (this.needPositions) {
  5081. return this.locationMap.getLocationRange(
  5082. start,
  5083. end,
  5084. this.filename
  5085. );
  5086. }
  5087. return null;
  5088. },
  5089. getLocationFromList: function(list) {
  5090. if (this.needPositions) {
  5091. var head = this.getFirstListNode(list);
  5092. var tail = this.getLastListNode(list);
  5093. return this.locationMap.getLocationRange(
  5094. head !== null ? head.loc.start.offset - this.locationMap.startOffset : this.scanner.tokenStart,
  5095. tail !== null ? tail.loc.end.offset - this.locationMap.startOffset : this.scanner.tokenStart,
  5096. this.filename
  5097. );
  5098. }
  5099. return null;
  5100. },
  5101. error: function(message, offset) {
  5102. var location = typeof offset !== 'undefined' && offset < this.scanner.source.length
  5103. ? this.locationMap.getLocation(offset)
  5104. : this.scanner.eof
  5105. ? this.locationMap.getLocation(findWhiteSpaceStart$1(this.scanner.source, this.scanner.source.length - 1))
  5106. : this.locationMap.getLocation(this.scanner.tokenStart);
  5107. throw new _SyntaxError(
  5108. message || 'Unexpected input',
  5109. this.scanner.source,
  5110. location.offset,
  5111. location.line,
  5112. location.column
  5113. );
  5114. }
  5115. };
  5116. config = processConfig(config || {});
  5117. for (var key in config) {
  5118. parser[key] = config[key];
  5119. }
  5120. return function(source, options) {
  5121. options = options || {};
  5122. var context = options.context || 'default';
  5123. var ast;
  5124. tokenizer(source, parser.scanner);
  5125. parser.locationMap.setSource(
  5126. source,
  5127. options.offset,
  5128. options.line,
  5129. options.column
  5130. );
  5131. parser.filename = options.filename || '<unknown>';
  5132. parser.needPositions = Boolean(options.positions);
  5133. parser.onParseError = typeof options.onParseError === 'function' ? options.onParseError : noop$2;
  5134. parser.onParseErrorThrow = false;
  5135. parser.parseAtrulePrelude = 'parseAtrulePrelude' in options ? Boolean(options.parseAtrulePrelude) : true;
  5136. parser.parseRulePrelude = 'parseRulePrelude' in options ? Boolean(options.parseRulePrelude) : true;
  5137. parser.parseValue = 'parseValue' in options ? Boolean(options.parseValue) : true;
  5138. parser.parseCustomProperty = 'parseCustomProperty' in options ? Boolean(options.parseCustomProperty) : false;
  5139. if (!parser.context.hasOwnProperty(context)) {
  5140. throw new Error('Unknown context `' + context + '`');
  5141. }
  5142. ast = parser.context[context].call(parser, options);
  5143. if (!parser.scanner.eof) {
  5144. parser.error();
  5145. }
  5146. return ast;
  5147. };
  5148. };
  5149. /* -*- Mode: js; js-indent-level: 2; -*- */
  5150. /*
  5151. * Copyright 2011 Mozilla Foundation and contributors
  5152. * Licensed under the New BSD license. See LICENSE or:
  5153. * http://opensource.org/licenses/BSD-3-Clause
  5154. */
  5155. var intToCharMap = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'.split('');
  5156. /**
  5157. * Encode an integer in the range of 0 to 63 to a single base 64 digit.
  5158. */
  5159. var encode = function (number) {
  5160. if (0 <= number && number < intToCharMap.length) {
  5161. return intToCharMap[number];
  5162. }
  5163. throw new TypeError("Must be between 0 and 63: " + number);
  5164. };
  5165. /**
  5166. * Decode a single base 64 character code digit to an integer. Returns -1 on
  5167. * failure.
  5168. */
  5169. var decode = function (charCode) {
  5170. var bigA = 65; // 'A'
  5171. var bigZ = 90; // 'Z'
  5172. var littleA = 97; // 'a'
  5173. var littleZ = 122; // 'z'
  5174. var zero = 48; // '0'
  5175. var nine = 57; // '9'
  5176. var plus = 43; // '+'
  5177. var slash = 47; // '/'
  5178. var littleOffset = 26;
  5179. var numberOffset = 52;
  5180. // 0 - 25: ABCDEFGHIJKLMNOPQRSTUVWXYZ
  5181. if (bigA <= charCode && charCode <= bigZ) {
  5182. return (charCode - bigA);
  5183. }
  5184. // 26 - 51: abcdefghijklmnopqrstuvwxyz
  5185. if (littleA <= charCode && charCode <= littleZ) {
  5186. return (charCode - littleA + littleOffset);
  5187. }
  5188. // 52 - 61: 0123456789
  5189. if (zero <= charCode && charCode <= nine) {
  5190. return (charCode - zero + numberOffset);
  5191. }
  5192. // 62: +
  5193. if (charCode == plus) {
  5194. return 62;
  5195. }
  5196. // 63: /
  5197. if (charCode == slash) {
  5198. return 63;
  5199. }
  5200. // Invalid base64 digit.
  5201. return -1;
  5202. };
  5203. var base64 = {
  5204. encode: encode,
  5205. decode: decode
  5206. };
  5207. /* -*- Mode: js; js-indent-level: 2; -*- */
  5208. /*
  5209. * Copyright 2011 Mozilla Foundation and contributors
  5210. * Licensed under the New BSD license. See LICENSE or:
  5211. * http://opensource.org/licenses/BSD-3-Clause
  5212. *
  5213. * Based on the Base 64 VLQ implementation in Closure Compiler:
  5214. * https://code.google.com/p/closure-compiler/source/browse/trunk/src/com/google/debugging/sourcemap/Base64VLQ.java
  5215. *
  5216. * Copyright 2011 The Closure Compiler Authors. All rights reserved.
  5217. * Redistribution and use in source and binary forms, with or without
  5218. * modification, are permitted provided that the following conditions are
  5219. * met:
  5220. *
  5221. * * Redistributions of source code must retain the above copyright
  5222. * notice, this list of conditions and the following disclaimer.
  5223. * * Redistributions in binary form must reproduce the above
  5224. * copyright notice, this list of conditions and the following
  5225. * disclaimer in the documentation and/or other materials provided
  5226. * with the distribution.
  5227. * * Neither the name of Google Inc. nor the names of its
  5228. * contributors may be used to endorse or promote products derived
  5229. * from this software without specific prior written permission.
  5230. *
  5231. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  5232. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  5233. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  5234. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  5235. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  5236. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  5237. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  5238. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  5239. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  5240. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  5241. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  5242. */
  5243. // A single base 64 digit can contain 6 bits of data. For the base 64 variable
  5244. // length quantities we use in the source map spec, the first bit is the sign,
  5245. // the next four bits are the actual value, and the 6th bit is the
  5246. // continuation bit. The continuation bit tells us whether there are more
  5247. // digits in this value following this digit.
  5248. //
  5249. // Continuation
  5250. // | Sign
  5251. // | |
  5252. // V V
  5253. // 101011
  5254. var VLQ_BASE_SHIFT = 5;
  5255. // binary: 100000
  5256. var VLQ_BASE = 1 << VLQ_BASE_SHIFT;
  5257. // binary: 011111
  5258. var VLQ_BASE_MASK = VLQ_BASE - 1;
  5259. // binary: 100000
  5260. var VLQ_CONTINUATION_BIT = VLQ_BASE;
  5261. /**
  5262. * Converts from a two-complement value to a value where the sign bit is
  5263. * placed in the least significant bit. For example, as decimals:
  5264. * 1 becomes 2 (10 binary), -1 becomes 3 (11 binary)
  5265. * 2 becomes 4 (100 binary), -2 becomes 5 (101 binary)
  5266. */
  5267. function toVLQSigned(aValue) {
  5268. return aValue < 0
  5269. ? ((-aValue) << 1) + 1
  5270. : (aValue << 1) + 0;
  5271. }
  5272. /**
  5273. * Converts to a two-complement value from a value where the sign bit is
  5274. * placed in the least significant bit. For example, as decimals:
  5275. * 2 (10 binary) becomes 1, 3 (11 binary) becomes -1
  5276. * 4 (100 binary) becomes 2, 5 (101 binary) becomes -2
  5277. */
  5278. function fromVLQSigned(aValue) {
  5279. var isNegative = (aValue & 1) === 1;
  5280. var shifted = aValue >> 1;
  5281. return isNegative
  5282. ? -shifted
  5283. : shifted;
  5284. }
  5285. /**
  5286. * Returns the base 64 VLQ encoded value.
  5287. */
  5288. var encode$1 = function base64VLQ_encode(aValue) {
  5289. var encoded = "";
  5290. var digit;
  5291. var vlq = toVLQSigned(aValue);
  5292. do {
  5293. digit = vlq & VLQ_BASE_MASK;
  5294. vlq >>>= VLQ_BASE_SHIFT;
  5295. if (vlq > 0) {
  5296. // There are still more digits in this value, so we must make sure the
  5297. // continuation bit is marked.
  5298. digit |= VLQ_CONTINUATION_BIT;
  5299. }
  5300. encoded += base64.encode(digit);
  5301. } while (vlq > 0);
  5302. return encoded;
  5303. };
  5304. /**
  5305. * Decodes the next base 64 VLQ value from the given string and returns the
  5306. * value and the rest of the string via the out parameter.
  5307. */
  5308. var decode$1 = function base64VLQ_decode(aStr, aIndex, aOutParam) {
  5309. var strLen = aStr.length;
  5310. var result = 0;
  5311. var shift = 0;
  5312. var continuation, digit;
  5313. do {
  5314. if (aIndex >= strLen) {
  5315. throw new Error("Expected more digits in base 64 VLQ value.");
  5316. }
  5317. digit = base64.decode(aStr.charCodeAt(aIndex++));
  5318. if (digit === -1) {
  5319. throw new Error("Invalid base64 digit: " + aStr.charAt(aIndex - 1));
  5320. }
  5321. continuation = !!(digit & VLQ_CONTINUATION_BIT);
  5322. digit &= VLQ_BASE_MASK;
  5323. result = result + (digit << shift);
  5324. shift += VLQ_BASE_SHIFT;
  5325. } while (continuation);
  5326. aOutParam.value = fromVLQSigned(result);
  5327. aOutParam.rest = aIndex;
  5328. };
  5329. var base64Vlq = {
  5330. encode: encode$1,
  5331. decode: decode$1
  5332. };
  5333. function createCommonjsModule(fn, module) {
  5334. return module = { exports: {} }, fn(module, module.exports), module.exports;
  5335. }
  5336. function getCjsExportFromNamespace (n) {
  5337. return n && n['default'] || n;
  5338. }
  5339. var util = createCommonjsModule(function (module, exports) {
  5340. /* -*- Mode: js; js-indent-level: 2; -*- */
  5341. /*
  5342. * Copyright 2011 Mozilla Foundation and contributors
  5343. * Licensed under the New BSD license. See LICENSE or:
  5344. * http://opensource.org/licenses/BSD-3-Clause
  5345. */
  5346. /**
  5347. * This is a helper function for getting values from parameter/options
  5348. * objects.
  5349. *
  5350. * @param args The object we are extracting values from
  5351. * @param name The name of the property we are getting.
  5352. * @param defaultValue An optional value to return if the property is missing
  5353. * from the object. If this is not specified and the property is missing, an
  5354. * error will be thrown.
  5355. */
  5356. function getArg(aArgs, aName, aDefaultValue) {
  5357. if (aName in aArgs) {
  5358. return aArgs[aName];
  5359. } else if (arguments.length === 3) {
  5360. return aDefaultValue;
  5361. } else {
  5362. throw new Error('"' + aName + '" is a required argument.');
  5363. }
  5364. }
  5365. exports.getArg = getArg;
  5366. var urlRegexp = /^(?:([\w+\-.]+):)?\/\/(?:(\w+:\w+)@)?([\w.-]*)(?::(\d+))?(.*)$/;
  5367. var dataUrlRegexp = /^data:.+\,.+$/;
  5368. function urlParse(aUrl) {
  5369. var match = aUrl.match(urlRegexp);
  5370. if (!match) {
  5371. return null;
  5372. }
  5373. return {
  5374. scheme: match[1],
  5375. auth: match[2],
  5376. host: match[3],
  5377. port: match[4],
  5378. path: match[5]
  5379. };
  5380. }
  5381. exports.urlParse = urlParse;
  5382. function urlGenerate(aParsedUrl) {
  5383. var url = '';
  5384. if (aParsedUrl.scheme) {
  5385. url += aParsedUrl.scheme + ':';
  5386. }
  5387. url += '//';
  5388. if (aParsedUrl.auth) {
  5389. url += aParsedUrl.auth + '@';
  5390. }
  5391. if (aParsedUrl.host) {
  5392. url += aParsedUrl.host;
  5393. }
  5394. if (aParsedUrl.port) {
  5395. url += ":" + aParsedUrl.port;
  5396. }
  5397. if (aParsedUrl.path) {
  5398. url += aParsedUrl.path;
  5399. }
  5400. return url;
  5401. }
  5402. exports.urlGenerate = urlGenerate;
  5403. /**
  5404. * Normalizes a path, or the path portion of a URL:
  5405. *
  5406. * - Replaces consecutive slashes with one slash.
  5407. * - Removes unnecessary '.' parts.
  5408. * - Removes unnecessary '<dir>/..' parts.
  5409. *
  5410. * Based on code in the Node.js 'path' core module.
  5411. *
  5412. * @param aPath The path or url to normalize.
  5413. */
  5414. function normalize(aPath) {
  5415. var path = aPath;
  5416. var url = urlParse(aPath);
  5417. if (url) {
  5418. if (!url.path) {
  5419. return aPath;
  5420. }
  5421. path = url.path;
  5422. }
  5423. var isAbsolute = exports.isAbsolute(path);
  5424. var parts = path.split(/\/+/);
  5425. for (var part, up = 0, i = parts.length - 1; i >= 0; i--) {
  5426. part = parts[i];
  5427. if (part === '.') {
  5428. parts.splice(i, 1);
  5429. } else if (part === '..') {
  5430. up++;
  5431. } else if (up > 0) {
  5432. if (part === '') {
  5433. // The first part is blank if the path is absolute. Trying to go
  5434. // above the root is a no-op. Therefore we can remove all '..' parts
  5435. // directly after the root.
  5436. parts.splice(i + 1, up);
  5437. up = 0;
  5438. } else {
  5439. parts.splice(i, 2);
  5440. up--;
  5441. }
  5442. }
  5443. }
  5444. path = parts.join('/');
  5445. if (path === '') {
  5446. path = isAbsolute ? '/' : '.';
  5447. }
  5448. if (url) {
  5449. url.path = path;
  5450. return urlGenerate(url);
  5451. }
  5452. return path;
  5453. }
  5454. exports.normalize = normalize;
  5455. /**
  5456. * Joins two paths/URLs.
  5457. *
  5458. * @param aRoot The root path or URL.
  5459. * @param aPath The path or URL to be joined with the root.
  5460. *
  5461. * - If aPath is a URL or a data URI, aPath is returned, unless aPath is a
  5462. * scheme-relative URL: Then the scheme of aRoot, if any, is prepended
  5463. * first.
  5464. * - Otherwise aPath is a path. If aRoot is a URL, then its path portion
  5465. * is updated with the result and aRoot is returned. Otherwise the result
  5466. * is returned.
  5467. * - If aPath is absolute, the result is aPath.
  5468. * - Otherwise the two paths are joined with a slash.
  5469. * - Joining for example 'http://' and 'www.example.com' is also supported.
  5470. */
  5471. function join(aRoot, aPath) {
  5472. if (aRoot === "") {
  5473. aRoot = ".";
  5474. }
  5475. if (aPath === "") {
  5476. aPath = ".";
  5477. }
  5478. var aPathUrl = urlParse(aPath);
  5479. var aRootUrl = urlParse(aRoot);
  5480. if (aRootUrl) {
  5481. aRoot = aRootUrl.path || '/';
  5482. }
  5483. // `join(foo, '//www.example.org')`
  5484. if (aPathUrl && !aPathUrl.scheme) {
  5485. if (aRootUrl) {
  5486. aPathUrl.scheme = aRootUrl.scheme;
  5487. }
  5488. return urlGenerate(aPathUrl);
  5489. }
  5490. if (aPathUrl || aPath.match(dataUrlRegexp)) {
  5491. return aPath;
  5492. }
  5493. // `join('http://', 'www.example.com')`
  5494. if (aRootUrl && !aRootUrl.host && !aRootUrl.path) {
  5495. aRootUrl.host = aPath;
  5496. return urlGenerate(aRootUrl);
  5497. }
  5498. var joined = aPath.charAt(0) === '/'
  5499. ? aPath
  5500. : normalize(aRoot.replace(/\/+$/, '') + '/' + aPath);
  5501. if (aRootUrl) {
  5502. aRootUrl.path = joined;
  5503. return urlGenerate(aRootUrl);
  5504. }
  5505. return joined;
  5506. }
  5507. exports.join = join;
  5508. exports.isAbsolute = function (aPath) {
  5509. return aPath.charAt(0) === '/' || urlRegexp.test(aPath);
  5510. };
  5511. /**
  5512. * Make a path relative to a URL or another path.
  5513. *
  5514. * @param aRoot The root path or URL.
  5515. * @param aPath The path or URL to be made relative to aRoot.
  5516. */
  5517. function relative(aRoot, aPath) {
  5518. if (aRoot === "") {
  5519. aRoot = ".";
  5520. }
  5521. aRoot = aRoot.replace(/\/$/, '');
  5522. // It is possible for the path to be above the root. In this case, simply
  5523. // checking whether the root is a prefix of the path won't work. Instead, we
  5524. // need to remove components from the root one by one, until either we find
  5525. // a prefix that fits, or we run out of components to remove.
  5526. var level = 0;
  5527. while (aPath.indexOf(aRoot + '/') !== 0) {
  5528. var index = aRoot.lastIndexOf("/");
  5529. if (index < 0) {
  5530. return aPath;
  5531. }
  5532. // If the only part of the root that is left is the scheme (i.e. http://,
  5533. // file:///, etc.), one or more slashes (/), or simply nothing at all, we
  5534. // have exhausted all components, so the path is not relative to the root.
  5535. aRoot = aRoot.slice(0, index);
  5536. if (aRoot.match(/^([^\/]+:\/)?\/*$/)) {
  5537. return aPath;
  5538. }
  5539. ++level;
  5540. }
  5541. // Make sure we add a "../" for each component we removed from the root.
  5542. return Array(level + 1).join("../") + aPath.substr(aRoot.length + 1);
  5543. }
  5544. exports.relative = relative;
  5545. var supportsNullProto = (function () {
  5546. var obj = Object.create(null);
  5547. return !('__proto__' in obj);
  5548. }());
  5549. function identity (s) {
  5550. return s;
  5551. }
  5552. /**
  5553. * Because behavior goes wacky when you set `__proto__` on objects, we
  5554. * have to prefix all the strings in our set with an arbitrary character.
  5555. *
  5556. * See https://github.com/mozilla/source-map/pull/31 and
  5557. * https://github.com/mozilla/source-map/issues/30
  5558. *
  5559. * @param String aStr
  5560. */
  5561. function toSetString(aStr) {
  5562. if (isProtoString(aStr)) {
  5563. return '$' + aStr;
  5564. }
  5565. return aStr;
  5566. }
  5567. exports.toSetString = supportsNullProto ? identity : toSetString;
  5568. function fromSetString(aStr) {
  5569. if (isProtoString(aStr)) {
  5570. return aStr.slice(1);
  5571. }
  5572. return aStr;
  5573. }
  5574. exports.fromSetString = supportsNullProto ? identity : fromSetString;
  5575. function isProtoString(s) {
  5576. if (!s) {
  5577. return false;
  5578. }
  5579. var length = s.length;
  5580. if (length < 9 /* "__proto__".length */) {
  5581. return false;
  5582. }
  5583. if (s.charCodeAt(length - 1) !== 95 /* '_' */ ||
  5584. s.charCodeAt(length - 2) !== 95 /* '_' */ ||
  5585. s.charCodeAt(length - 3) !== 111 /* 'o' */ ||
  5586. s.charCodeAt(length - 4) !== 116 /* 't' */ ||
  5587. s.charCodeAt(length - 5) !== 111 /* 'o' */ ||
  5588. s.charCodeAt(length - 6) !== 114 /* 'r' */ ||
  5589. s.charCodeAt(length - 7) !== 112 /* 'p' */ ||
  5590. s.charCodeAt(length - 8) !== 95 /* '_' */ ||
  5591. s.charCodeAt(length - 9) !== 95 /* '_' */) {
  5592. return false;
  5593. }
  5594. for (var i = length - 10; i >= 0; i--) {
  5595. if (s.charCodeAt(i) !== 36 /* '$' */) {
  5596. return false;
  5597. }
  5598. }
  5599. return true;
  5600. }
  5601. /**
  5602. * Comparator between two mappings where the original positions are compared.
  5603. *
  5604. * Optionally pass in `true` as `onlyCompareGenerated` to consider two
  5605. * mappings with the same original source/line/column, but different generated
  5606. * line and column the same. Useful when searching for a mapping with a
  5607. * stubbed out mapping.
  5608. */
  5609. function compareByOriginalPositions(mappingA, mappingB, onlyCompareOriginal) {
  5610. var cmp = strcmp(mappingA.source, mappingB.source);
  5611. if (cmp !== 0) {
  5612. return cmp;
  5613. }
  5614. cmp = mappingA.originalLine - mappingB.originalLine;
  5615. if (cmp !== 0) {
  5616. return cmp;
  5617. }
  5618. cmp = mappingA.originalColumn - mappingB.originalColumn;
  5619. if (cmp !== 0 || onlyCompareOriginal) {
  5620. return cmp;
  5621. }
  5622. cmp = mappingA.generatedColumn - mappingB.generatedColumn;
  5623. if (cmp !== 0) {
  5624. return cmp;
  5625. }
  5626. cmp = mappingA.generatedLine - mappingB.generatedLine;
  5627. if (cmp !== 0) {
  5628. return cmp;
  5629. }
  5630. return strcmp(mappingA.name, mappingB.name);
  5631. }
  5632. exports.compareByOriginalPositions = compareByOriginalPositions;
  5633. /**
  5634. * Comparator between two mappings with deflated source and name indices where
  5635. * the generated positions are compared.
  5636. *
  5637. * Optionally pass in `true` as `onlyCompareGenerated` to consider two
  5638. * mappings with the same generated line and column, but different
  5639. * source/name/original line and column the same. Useful when searching for a
  5640. * mapping with a stubbed out mapping.
  5641. */
  5642. function compareByGeneratedPositionsDeflated(mappingA, mappingB, onlyCompareGenerated) {
  5643. var cmp = mappingA.generatedLine - mappingB.generatedLine;
  5644. if (cmp !== 0) {
  5645. return cmp;
  5646. }
  5647. cmp = mappingA.generatedColumn - mappingB.generatedColumn;
  5648. if (cmp !== 0 || onlyCompareGenerated) {
  5649. return cmp;
  5650. }
  5651. cmp = strcmp(mappingA.source, mappingB.source);
  5652. if (cmp !== 0) {
  5653. return cmp;
  5654. }
  5655. cmp = mappingA.originalLine - mappingB.originalLine;
  5656. if (cmp !== 0) {
  5657. return cmp;
  5658. }
  5659. cmp = mappingA.originalColumn - mappingB.originalColumn;
  5660. if (cmp !== 0) {
  5661. return cmp;
  5662. }
  5663. return strcmp(mappingA.name, mappingB.name);
  5664. }
  5665. exports.compareByGeneratedPositionsDeflated = compareByGeneratedPositionsDeflated;
  5666. function strcmp(aStr1, aStr2) {
  5667. if (aStr1 === aStr2) {
  5668. return 0;
  5669. }
  5670. if (aStr1 === null) {
  5671. return 1; // aStr2 !== null
  5672. }
  5673. if (aStr2 === null) {
  5674. return -1; // aStr1 !== null
  5675. }
  5676. if (aStr1 > aStr2) {
  5677. return 1;
  5678. }
  5679. return -1;
  5680. }
  5681. /**
  5682. * Comparator between two mappings with inflated source and name strings where
  5683. * the generated positions are compared.
  5684. */
  5685. function compareByGeneratedPositionsInflated(mappingA, mappingB) {
  5686. var cmp = mappingA.generatedLine - mappingB.generatedLine;
  5687. if (cmp !== 0) {
  5688. return cmp;
  5689. }
  5690. cmp = mappingA.generatedColumn - mappingB.generatedColumn;
  5691. if (cmp !== 0) {
  5692. return cmp;
  5693. }
  5694. cmp = strcmp(mappingA.source, mappingB.source);
  5695. if (cmp !== 0) {
  5696. return cmp;
  5697. }
  5698. cmp = mappingA.originalLine - mappingB.originalLine;
  5699. if (cmp !== 0) {
  5700. return cmp;
  5701. }
  5702. cmp = mappingA.originalColumn - mappingB.originalColumn;
  5703. if (cmp !== 0) {
  5704. return cmp;
  5705. }
  5706. return strcmp(mappingA.name, mappingB.name);
  5707. }
  5708. exports.compareByGeneratedPositionsInflated = compareByGeneratedPositionsInflated;
  5709. /**
  5710. * Strip any JSON XSSI avoidance prefix from the string (as documented
  5711. * in the source maps specification), and then parse the string as
  5712. * JSON.
  5713. */
  5714. function parseSourceMapInput(str) {
  5715. return JSON.parse(str.replace(/^\)]}'[^\n]*\n/, ''));
  5716. }
  5717. exports.parseSourceMapInput = parseSourceMapInput;
  5718. /**
  5719. * Compute the URL of a source given the the source root, the source's
  5720. * URL, and the source map's URL.
  5721. */
  5722. function computeSourceURL(sourceRoot, sourceURL, sourceMapURL) {
  5723. sourceURL = sourceURL || '';
  5724. if (sourceRoot) {
  5725. // This follows what Chrome does.
  5726. if (sourceRoot[sourceRoot.length - 1] !== '/' && sourceURL[0] !== '/') {
  5727. sourceRoot += '/';
  5728. }
  5729. // The spec says:
  5730. // Line 4: An optional source root, useful for relocating source
  5731. // files on a server or removing repeated values in the
  5732. // “sources” entry. This value is prepended to the individual
  5733. // entries in the “source” field.
  5734. sourceURL = sourceRoot + sourceURL;
  5735. }
  5736. // Historically, SourceMapConsumer did not take the sourceMapURL as
  5737. // a parameter. This mode is still somewhat supported, which is why
  5738. // this code block is conditional. However, it's preferable to pass
  5739. // the source map URL to SourceMapConsumer, so that this function
  5740. // can implement the source URL resolution algorithm as outlined in
  5741. // the spec. This block is basically the equivalent of:
  5742. // new URL(sourceURL, sourceMapURL).toString()
  5743. // ... except it avoids using URL, which wasn't available in the
  5744. // older releases of node still supported by this library.
  5745. //
  5746. // The spec says:
  5747. // If the sources are not absolute URLs after prepending of the
  5748. // “sourceRoot”, the sources are resolved relative to the
  5749. // SourceMap (like resolving script src in a html document).
  5750. if (sourceMapURL) {
  5751. var parsed = urlParse(sourceMapURL);
  5752. if (!parsed) {
  5753. throw new Error("sourceMapURL could not be parsed");
  5754. }
  5755. if (parsed.path) {
  5756. // Strip the last path component, but keep the "/".
  5757. var index = parsed.path.lastIndexOf('/');
  5758. if (index >= 0) {
  5759. parsed.path = parsed.path.substring(0, index + 1);
  5760. }
  5761. }
  5762. sourceURL = join(urlGenerate(parsed), sourceURL);
  5763. }
  5764. return normalize(sourceURL);
  5765. }
  5766. exports.computeSourceURL = computeSourceURL;
  5767. });
  5768. var util_1 = util.getArg;
  5769. var util_2 = util.urlParse;
  5770. var util_3 = util.urlGenerate;
  5771. var util_4 = util.normalize;
  5772. var util_5 = util.join;
  5773. var util_6 = util.isAbsolute;
  5774. var util_7 = util.relative;
  5775. var util_8 = util.toSetString;
  5776. var util_9 = util.fromSetString;
  5777. var util_10 = util.compareByOriginalPositions;
  5778. var util_11 = util.compareByGeneratedPositionsDeflated;
  5779. var util_12 = util.compareByGeneratedPositionsInflated;
  5780. var util_13 = util.parseSourceMapInput;
  5781. var util_14 = util.computeSourceURL;
  5782. /* -*- Mode: js; js-indent-level: 2; -*- */
  5783. /*
  5784. * Copyright 2011 Mozilla Foundation and contributors
  5785. * Licensed under the New BSD license. See LICENSE or:
  5786. * http://opensource.org/licenses/BSD-3-Clause
  5787. */
  5788. var has = Object.prototype.hasOwnProperty;
  5789. var hasNativeMap = typeof Map !== "undefined";
  5790. /**
  5791. * A data structure which is a combination of an array and a set. Adding a new
  5792. * member is O(1), testing for membership is O(1), and finding the index of an
  5793. * element is O(1). Removing elements from the set is not supported. Only
  5794. * strings are supported for membership.
  5795. */
  5796. function ArraySet() {
  5797. this._array = [];
  5798. this._set = hasNativeMap ? new Map() : Object.create(null);
  5799. }
  5800. /**
  5801. * Static method for creating ArraySet instances from an existing array.
  5802. */
  5803. ArraySet.fromArray = function ArraySet_fromArray(aArray, aAllowDuplicates) {
  5804. var set = new ArraySet();
  5805. for (var i = 0, len = aArray.length; i < len; i++) {
  5806. set.add(aArray[i], aAllowDuplicates);
  5807. }
  5808. return set;
  5809. };
  5810. /**
  5811. * Return how many unique items are in this ArraySet. If duplicates have been
  5812. * added, than those do not count towards the size.
  5813. *
  5814. * @returns Number
  5815. */
  5816. ArraySet.prototype.size = function ArraySet_size() {
  5817. return hasNativeMap ? this._set.size : Object.getOwnPropertyNames(this._set).length;
  5818. };
  5819. /**
  5820. * Add the given string to this set.
  5821. *
  5822. * @param String aStr
  5823. */
  5824. ArraySet.prototype.add = function ArraySet_add(aStr, aAllowDuplicates) {
  5825. var sStr = hasNativeMap ? aStr : util.toSetString(aStr);
  5826. var isDuplicate = hasNativeMap ? this.has(aStr) : has.call(this._set, sStr);
  5827. var idx = this._array.length;
  5828. if (!isDuplicate || aAllowDuplicates) {
  5829. this._array.push(aStr);
  5830. }
  5831. if (!isDuplicate) {
  5832. if (hasNativeMap) {
  5833. this._set.set(aStr, idx);
  5834. } else {
  5835. this._set[sStr] = idx;
  5836. }
  5837. }
  5838. };
  5839. /**
  5840. * Is the given string a member of this set?
  5841. *
  5842. * @param String aStr
  5843. */
  5844. ArraySet.prototype.has = function ArraySet_has(aStr) {
  5845. if (hasNativeMap) {
  5846. return this._set.has(aStr);
  5847. } else {
  5848. var sStr = util.toSetString(aStr);
  5849. return has.call(this._set, sStr);
  5850. }
  5851. };
  5852. /**
  5853. * What is the index of the given string in the array?
  5854. *
  5855. * @param String aStr
  5856. */
  5857. ArraySet.prototype.indexOf = function ArraySet_indexOf(aStr) {
  5858. if (hasNativeMap) {
  5859. var idx = this._set.get(aStr);
  5860. if (idx >= 0) {
  5861. return idx;
  5862. }
  5863. } else {
  5864. var sStr = util.toSetString(aStr);
  5865. if (has.call(this._set, sStr)) {
  5866. return this._set[sStr];
  5867. }
  5868. }
  5869. throw new Error('"' + aStr + '" is not in the set.');
  5870. };
  5871. /**
  5872. * What is the element at the given index?
  5873. *
  5874. * @param Number aIdx
  5875. */
  5876. ArraySet.prototype.at = function ArraySet_at(aIdx) {
  5877. if (aIdx >= 0 && aIdx < this._array.length) {
  5878. return this._array[aIdx];
  5879. }
  5880. throw new Error('No element indexed by ' + aIdx);
  5881. };
  5882. /**
  5883. * Returns the array representation of this set (which has the proper indices
  5884. * indicated by indexOf). Note that this is a copy of the internal array used
  5885. * for storing the members so that no one can mess with internal state.
  5886. */
  5887. ArraySet.prototype.toArray = function ArraySet_toArray() {
  5888. return this._array.slice();
  5889. };
  5890. var ArraySet_1 = ArraySet;
  5891. var arraySet = {
  5892. ArraySet: ArraySet_1
  5893. };
  5894. /* -*- Mode: js; js-indent-level: 2; -*- */
  5895. /*
  5896. * Copyright 2014 Mozilla Foundation and contributors
  5897. * Licensed under the New BSD license. See LICENSE or:
  5898. * http://opensource.org/licenses/BSD-3-Clause
  5899. */
  5900. /**
  5901. * Determine whether mappingB is after mappingA with respect to generated
  5902. * position.
  5903. */
  5904. function generatedPositionAfter(mappingA, mappingB) {
  5905. // Optimized for most common case
  5906. var lineA = mappingA.generatedLine;
  5907. var lineB = mappingB.generatedLine;
  5908. var columnA = mappingA.generatedColumn;
  5909. var columnB = mappingB.generatedColumn;
  5910. return lineB > lineA || lineB == lineA && columnB >= columnA ||
  5911. util.compareByGeneratedPositionsInflated(mappingA, mappingB) <= 0;
  5912. }
  5913. /**
  5914. * A data structure to provide a sorted view of accumulated mappings in a
  5915. * performance conscious manner. It trades a neglibable overhead in general
  5916. * case for a large speedup in case of mappings being added in order.
  5917. */
  5918. function MappingList() {
  5919. this._array = [];
  5920. this._sorted = true;
  5921. // Serves as infimum
  5922. this._last = {generatedLine: -1, generatedColumn: 0};
  5923. }
  5924. /**
  5925. * Iterate through internal items. This method takes the same arguments that
  5926. * `Array.prototype.forEach` takes.
  5927. *
  5928. * NOTE: The order of the mappings is NOT guaranteed.
  5929. */
  5930. MappingList.prototype.unsortedForEach =
  5931. function MappingList_forEach(aCallback, aThisArg) {
  5932. this._array.forEach(aCallback, aThisArg);
  5933. };
  5934. /**
  5935. * Add the given source mapping.
  5936. *
  5937. * @param Object aMapping
  5938. */
  5939. MappingList.prototype.add = function MappingList_add(aMapping) {
  5940. if (generatedPositionAfter(this._last, aMapping)) {
  5941. this._last = aMapping;
  5942. this._array.push(aMapping);
  5943. } else {
  5944. this._sorted = false;
  5945. this._array.push(aMapping);
  5946. }
  5947. };
  5948. /**
  5949. * Returns the flat, sorted array of mappings. The mappings are sorted by
  5950. * generated position.
  5951. *
  5952. * WARNING: This method returns internal data without copying, for
  5953. * performance. The return value must NOT be mutated, and should be treated as
  5954. * an immutable borrow. If you want to take ownership, you must make your own
  5955. * copy.
  5956. */
  5957. MappingList.prototype.toArray = function MappingList_toArray() {
  5958. if (!this._sorted) {
  5959. this._array.sort(util.compareByGeneratedPositionsInflated);
  5960. this._sorted = true;
  5961. }
  5962. return this._array;
  5963. };
  5964. var MappingList_1 = MappingList;
  5965. var mappingList = {
  5966. MappingList: MappingList_1
  5967. };
  5968. /* -*- Mode: js; js-indent-level: 2; -*- */
  5969. /*
  5970. * Copyright 2011 Mozilla Foundation and contributors
  5971. * Licensed under the New BSD license. See LICENSE or:
  5972. * http://opensource.org/licenses/BSD-3-Clause
  5973. */
  5974. var ArraySet$1 = arraySet.ArraySet;
  5975. var MappingList$1 = mappingList.MappingList;
  5976. /**
  5977. * An instance of the SourceMapGenerator represents a source map which is
  5978. * being built incrementally. You may pass an object with the following
  5979. * properties:
  5980. *
  5981. * - file: The filename of the generated source.
  5982. * - sourceRoot: A root for all relative URLs in this source map.
  5983. */
  5984. function SourceMapGenerator(aArgs) {
  5985. if (!aArgs) {
  5986. aArgs = {};
  5987. }
  5988. this._file = util.getArg(aArgs, 'file', null);
  5989. this._sourceRoot = util.getArg(aArgs, 'sourceRoot', null);
  5990. this._skipValidation = util.getArg(aArgs, 'skipValidation', false);
  5991. this._sources = new ArraySet$1();
  5992. this._names = new ArraySet$1();
  5993. this._mappings = new MappingList$1();
  5994. this._sourcesContents = null;
  5995. }
  5996. SourceMapGenerator.prototype._version = 3;
  5997. /**
  5998. * Creates a new SourceMapGenerator based on a SourceMapConsumer
  5999. *
  6000. * @param aSourceMapConsumer The SourceMap.
  6001. */
  6002. SourceMapGenerator.fromSourceMap =
  6003. function SourceMapGenerator_fromSourceMap(aSourceMapConsumer) {
  6004. var sourceRoot = aSourceMapConsumer.sourceRoot;
  6005. var generator = new SourceMapGenerator({
  6006. file: aSourceMapConsumer.file,
  6007. sourceRoot: sourceRoot
  6008. });
  6009. aSourceMapConsumer.eachMapping(function (mapping) {
  6010. var newMapping = {
  6011. generated: {
  6012. line: mapping.generatedLine,
  6013. column: mapping.generatedColumn
  6014. }
  6015. };
  6016. if (mapping.source != null) {
  6017. newMapping.source = mapping.source;
  6018. if (sourceRoot != null) {
  6019. newMapping.source = util.relative(sourceRoot, newMapping.source);
  6020. }
  6021. newMapping.original = {
  6022. line: mapping.originalLine,
  6023. column: mapping.originalColumn
  6024. };
  6025. if (mapping.name != null) {
  6026. newMapping.name = mapping.name;
  6027. }
  6028. }
  6029. generator.addMapping(newMapping);
  6030. });
  6031. aSourceMapConsumer.sources.forEach(function (sourceFile) {
  6032. var sourceRelative = sourceFile;
  6033. if (sourceRoot !== null) {
  6034. sourceRelative = util.relative(sourceRoot, sourceFile);
  6035. }
  6036. if (!generator._sources.has(sourceRelative)) {
  6037. generator._sources.add(sourceRelative);
  6038. }
  6039. var content = aSourceMapConsumer.sourceContentFor(sourceFile);
  6040. if (content != null) {
  6041. generator.setSourceContent(sourceFile, content);
  6042. }
  6043. });
  6044. return generator;
  6045. };
  6046. /**
  6047. * Add a single mapping from original source line and column to the generated
  6048. * source's line and column for this source map being created. The mapping
  6049. * object should have the following properties:
  6050. *
  6051. * - generated: An object with the generated line and column positions.
  6052. * - original: An object with the original line and column positions.
  6053. * - source: The original source file (relative to the sourceRoot).
  6054. * - name: An optional original token name for this mapping.
  6055. */
  6056. SourceMapGenerator.prototype.addMapping =
  6057. function SourceMapGenerator_addMapping(aArgs) {
  6058. var generated = util.getArg(aArgs, 'generated');
  6059. var original = util.getArg(aArgs, 'original', null);
  6060. var source = util.getArg(aArgs, 'source', null);
  6061. var name = util.getArg(aArgs, 'name', null);
  6062. if (!this._skipValidation) {
  6063. this._validateMapping(generated, original, source, name);
  6064. }
  6065. if (source != null) {
  6066. source = String(source);
  6067. if (!this._sources.has(source)) {
  6068. this._sources.add(source);
  6069. }
  6070. }
  6071. if (name != null) {
  6072. name = String(name);
  6073. if (!this._names.has(name)) {
  6074. this._names.add(name);
  6075. }
  6076. }
  6077. this._mappings.add({
  6078. generatedLine: generated.line,
  6079. generatedColumn: generated.column,
  6080. originalLine: original != null && original.line,
  6081. originalColumn: original != null && original.column,
  6082. source: source,
  6083. name: name
  6084. });
  6085. };
  6086. /**
  6087. * Set the source content for a source file.
  6088. */
  6089. SourceMapGenerator.prototype.setSourceContent =
  6090. function SourceMapGenerator_setSourceContent(aSourceFile, aSourceContent) {
  6091. var source = aSourceFile;
  6092. if (this._sourceRoot != null) {
  6093. source = util.relative(this._sourceRoot, source);
  6094. }
  6095. if (aSourceContent != null) {
  6096. // Add the source content to the _sourcesContents map.
  6097. // Create a new _sourcesContents map if the property is null.
  6098. if (!this._sourcesContents) {
  6099. this._sourcesContents = Object.create(null);
  6100. }
  6101. this._sourcesContents[util.toSetString(source)] = aSourceContent;
  6102. } else if (this._sourcesContents) {
  6103. // Remove the source file from the _sourcesContents map.
  6104. // If the _sourcesContents map is empty, set the property to null.
  6105. delete this._sourcesContents[util.toSetString(source)];
  6106. if (Object.keys(this._sourcesContents).length === 0) {
  6107. this._sourcesContents = null;
  6108. }
  6109. }
  6110. };
  6111. /**
  6112. * Applies the mappings of a sub-source-map for a specific source file to the
  6113. * source map being generated. Each mapping to the supplied source file is
  6114. * rewritten using the supplied source map. Note: The resolution for the
  6115. * resulting mappings is the minimium of this map and the supplied map.
  6116. *
  6117. * @param aSourceMapConsumer The source map to be applied.
  6118. * @param aSourceFile Optional. The filename of the source file.
  6119. * If omitted, SourceMapConsumer's file property will be used.
  6120. * @param aSourceMapPath Optional. The dirname of the path to the source map
  6121. * to be applied. If relative, it is relative to the SourceMapConsumer.
  6122. * This parameter is needed when the two source maps aren't in the same
  6123. * directory, and the source map to be applied contains relative source
  6124. * paths. If so, those relative source paths need to be rewritten
  6125. * relative to the SourceMapGenerator.
  6126. */
  6127. SourceMapGenerator.prototype.applySourceMap =
  6128. function SourceMapGenerator_applySourceMap(aSourceMapConsumer, aSourceFile, aSourceMapPath) {
  6129. var sourceFile = aSourceFile;
  6130. // If aSourceFile is omitted, we will use the file property of the SourceMap
  6131. if (aSourceFile == null) {
  6132. if (aSourceMapConsumer.file == null) {
  6133. throw new Error(
  6134. 'SourceMapGenerator.prototype.applySourceMap requires either an explicit source file, ' +
  6135. 'or the source map\'s "file" property. Both were omitted.'
  6136. );
  6137. }
  6138. sourceFile = aSourceMapConsumer.file;
  6139. }
  6140. var sourceRoot = this._sourceRoot;
  6141. // Make "sourceFile" relative if an absolute Url is passed.
  6142. if (sourceRoot != null) {
  6143. sourceFile = util.relative(sourceRoot, sourceFile);
  6144. }
  6145. // Applying the SourceMap can add and remove items from the sources and
  6146. // the names array.
  6147. var newSources = new ArraySet$1();
  6148. var newNames = new ArraySet$1();
  6149. // Find mappings for the "sourceFile"
  6150. this._mappings.unsortedForEach(function (mapping) {
  6151. if (mapping.source === sourceFile && mapping.originalLine != null) {
  6152. // Check if it can be mapped by the source map, then update the mapping.
  6153. var original = aSourceMapConsumer.originalPositionFor({
  6154. line: mapping.originalLine,
  6155. column: mapping.originalColumn
  6156. });
  6157. if (original.source != null) {
  6158. // Copy mapping
  6159. mapping.source = original.source;
  6160. if (aSourceMapPath != null) {
  6161. mapping.source = util.join(aSourceMapPath, mapping.source);
  6162. }
  6163. if (sourceRoot != null) {
  6164. mapping.source = util.relative(sourceRoot, mapping.source);
  6165. }
  6166. mapping.originalLine = original.line;
  6167. mapping.originalColumn = original.column;
  6168. if (original.name != null) {
  6169. mapping.name = original.name;
  6170. }
  6171. }
  6172. }
  6173. var source = mapping.source;
  6174. if (source != null && !newSources.has(source)) {
  6175. newSources.add(source);
  6176. }
  6177. var name = mapping.name;
  6178. if (name != null && !newNames.has(name)) {
  6179. newNames.add(name);
  6180. }
  6181. }, this);
  6182. this._sources = newSources;
  6183. this._names = newNames;
  6184. // Copy sourcesContents of applied map.
  6185. aSourceMapConsumer.sources.forEach(function (sourceFile) {
  6186. var content = aSourceMapConsumer.sourceContentFor(sourceFile);
  6187. if (content != null) {
  6188. if (aSourceMapPath != null) {
  6189. sourceFile = util.join(aSourceMapPath, sourceFile);
  6190. }
  6191. if (sourceRoot != null) {
  6192. sourceFile = util.relative(sourceRoot, sourceFile);
  6193. }
  6194. this.setSourceContent(sourceFile, content);
  6195. }
  6196. }, this);
  6197. };
  6198. /**
  6199. * A mapping can have one of the three levels of data:
  6200. *
  6201. * 1. Just the generated position.
  6202. * 2. The Generated position, original position, and original source.
  6203. * 3. Generated and original position, original source, as well as a name
  6204. * token.
  6205. *
  6206. * To maintain consistency, we validate that any new mapping being added falls
  6207. * in to one of these categories.
  6208. */
  6209. SourceMapGenerator.prototype._validateMapping =
  6210. function SourceMapGenerator_validateMapping(aGenerated, aOriginal, aSource,
  6211. aName) {
  6212. // When aOriginal is truthy but has empty values for .line and .column,
  6213. // it is most likely a programmer error. In this case we throw a very
  6214. // specific error message to try to guide them the right way.
  6215. // For example: https://github.com/Polymer/polymer-bundler/pull/519
  6216. if (aOriginal && typeof aOriginal.line !== 'number' && typeof aOriginal.column !== 'number') {
  6217. throw new Error(
  6218. 'original.line and original.column are not numbers -- you probably meant to omit ' +
  6219. 'the original mapping entirely and only map the generated position. If so, pass ' +
  6220. 'null for the original mapping instead of an object with empty or null values.'
  6221. );
  6222. }
  6223. if (aGenerated && 'line' in aGenerated && 'column' in aGenerated
  6224. && aGenerated.line > 0 && aGenerated.column >= 0
  6225. && !aOriginal && !aSource && !aName) {
  6226. // Case 1.
  6227. return;
  6228. }
  6229. else if (aGenerated && 'line' in aGenerated && 'column' in aGenerated
  6230. && aOriginal && 'line' in aOriginal && 'column' in aOriginal
  6231. && aGenerated.line > 0 && aGenerated.column >= 0
  6232. && aOriginal.line > 0 && aOriginal.column >= 0
  6233. && aSource) {
  6234. // Cases 2 and 3.
  6235. return;
  6236. }
  6237. else {
  6238. throw new Error('Invalid mapping: ' + JSON.stringify({
  6239. generated: aGenerated,
  6240. source: aSource,
  6241. original: aOriginal,
  6242. name: aName
  6243. }));
  6244. }
  6245. };
  6246. /**
  6247. * Serialize the accumulated mappings in to the stream of base 64 VLQs
  6248. * specified by the source map format.
  6249. */
  6250. SourceMapGenerator.prototype._serializeMappings =
  6251. function SourceMapGenerator_serializeMappings() {
  6252. var previousGeneratedColumn = 0;
  6253. var previousGeneratedLine = 1;
  6254. var previousOriginalColumn = 0;
  6255. var previousOriginalLine = 0;
  6256. var previousName = 0;
  6257. var previousSource = 0;
  6258. var result = '';
  6259. var next;
  6260. var mapping;
  6261. var nameIdx;
  6262. var sourceIdx;
  6263. var mappings = this._mappings.toArray();
  6264. for (var i = 0, len = mappings.length; i < len; i++) {
  6265. mapping = mappings[i];
  6266. next = '';
  6267. if (mapping.generatedLine !== previousGeneratedLine) {
  6268. previousGeneratedColumn = 0;
  6269. while (mapping.generatedLine !== previousGeneratedLine) {
  6270. next += ';';
  6271. previousGeneratedLine++;
  6272. }
  6273. }
  6274. else {
  6275. if (i > 0) {
  6276. if (!util.compareByGeneratedPositionsInflated(mapping, mappings[i - 1])) {
  6277. continue;
  6278. }
  6279. next += ',';
  6280. }
  6281. }
  6282. next += base64Vlq.encode(mapping.generatedColumn
  6283. - previousGeneratedColumn);
  6284. previousGeneratedColumn = mapping.generatedColumn;
  6285. if (mapping.source != null) {
  6286. sourceIdx = this._sources.indexOf(mapping.source);
  6287. next += base64Vlq.encode(sourceIdx - previousSource);
  6288. previousSource = sourceIdx;
  6289. // lines are stored 0-based in SourceMap spec version 3
  6290. next += base64Vlq.encode(mapping.originalLine - 1
  6291. - previousOriginalLine);
  6292. previousOriginalLine = mapping.originalLine - 1;
  6293. next += base64Vlq.encode(mapping.originalColumn
  6294. - previousOriginalColumn);
  6295. previousOriginalColumn = mapping.originalColumn;
  6296. if (mapping.name != null) {
  6297. nameIdx = this._names.indexOf(mapping.name);
  6298. next += base64Vlq.encode(nameIdx - previousName);
  6299. previousName = nameIdx;
  6300. }
  6301. }
  6302. result += next;
  6303. }
  6304. return result;
  6305. };
  6306. SourceMapGenerator.prototype._generateSourcesContent =
  6307. function SourceMapGenerator_generateSourcesContent(aSources, aSourceRoot) {
  6308. return aSources.map(function (source) {
  6309. if (!this._sourcesContents) {
  6310. return null;
  6311. }
  6312. if (aSourceRoot != null) {
  6313. source = util.relative(aSourceRoot, source);
  6314. }
  6315. var key = util.toSetString(source);
  6316. return Object.prototype.hasOwnProperty.call(this._sourcesContents, key)
  6317. ? this._sourcesContents[key]
  6318. : null;
  6319. }, this);
  6320. };
  6321. /**
  6322. * Externalize the source map.
  6323. */
  6324. SourceMapGenerator.prototype.toJSON =
  6325. function SourceMapGenerator_toJSON() {
  6326. var map = {
  6327. version: this._version,
  6328. sources: this._sources.toArray(),
  6329. names: this._names.toArray(),
  6330. mappings: this._serializeMappings()
  6331. };
  6332. if (this._file != null) {
  6333. map.file = this._file;
  6334. }
  6335. if (this._sourceRoot != null) {
  6336. map.sourceRoot = this._sourceRoot;
  6337. }
  6338. if (this._sourcesContents) {
  6339. map.sourcesContent = this._generateSourcesContent(map.sources, map.sourceRoot);
  6340. }
  6341. return map;
  6342. };
  6343. /**
  6344. * Render the source map being generated to a string.
  6345. */
  6346. SourceMapGenerator.prototype.toString =
  6347. function SourceMapGenerator_toString() {
  6348. return JSON.stringify(this.toJSON());
  6349. };
  6350. var SourceMapGenerator_1 = SourceMapGenerator;
  6351. var sourceMapGenerator = {
  6352. SourceMapGenerator: SourceMapGenerator_1
  6353. };
  6354. var SourceMapGenerator$1 = sourceMapGenerator.SourceMapGenerator;
  6355. var trackNodes = {
  6356. Atrule: true,
  6357. Selector: true,
  6358. Declaration: true
  6359. };
  6360. var sourceMap = function generateSourceMap(handlers) {
  6361. var map = new SourceMapGenerator$1();
  6362. var line = 1;
  6363. var column = 0;
  6364. var generated = {
  6365. line: 1,
  6366. column: 0
  6367. };
  6368. var original = {
  6369. line: 0, // should be zero to add first mapping
  6370. column: 0
  6371. };
  6372. var sourceMappingActive = false;
  6373. var activatedGenerated = {
  6374. line: 1,
  6375. column: 0
  6376. };
  6377. var activatedMapping = {
  6378. generated: activatedGenerated
  6379. };
  6380. var handlersNode = handlers.node;
  6381. handlers.node = function(node) {
  6382. if (node.loc && node.loc.start && trackNodes.hasOwnProperty(node.type)) {
  6383. var nodeLine = node.loc.start.line;
  6384. var nodeColumn = node.loc.start.column - 1;
  6385. if (original.line !== nodeLine ||
  6386. original.column !== nodeColumn) {
  6387. original.line = nodeLine;
  6388. original.column = nodeColumn;
  6389. generated.line = line;
  6390. generated.column = column;
  6391. if (sourceMappingActive) {
  6392. sourceMappingActive = false;
  6393. if (generated.line !== activatedGenerated.line ||
  6394. generated.column !== activatedGenerated.column) {
  6395. map.addMapping(activatedMapping);
  6396. }
  6397. }
  6398. sourceMappingActive = true;
  6399. map.addMapping({
  6400. source: node.loc.source,
  6401. original: original,
  6402. generated: generated
  6403. });
  6404. }
  6405. }
  6406. handlersNode.call(this, node);
  6407. if (sourceMappingActive && trackNodes.hasOwnProperty(node.type)) {
  6408. activatedGenerated.line = line;
  6409. activatedGenerated.column = column;
  6410. }
  6411. };
  6412. var handlersChunk = handlers.chunk;
  6413. handlers.chunk = function(chunk) {
  6414. for (var i = 0; i < chunk.length; i++) {
  6415. if (chunk.charCodeAt(i) === 10) { // \n
  6416. line++;
  6417. column = 0;
  6418. } else {
  6419. column++;
  6420. }
  6421. }
  6422. handlersChunk(chunk);
  6423. };
  6424. var handlersResult = handlers.result;
  6425. handlers.result = function() {
  6426. if (sourceMappingActive) {
  6427. map.addMapping(activatedMapping);
  6428. }
  6429. return {
  6430. css: handlersResult(),
  6431. map: map
  6432. };
  6433. };
  6434. return handlers;
  6435. };
  6436. var hasOwnProperty$3 = Object.prototype.hasOwnProperty;
  6437. function processChildren(node, delimeter) {
  6438. var list = node.children;
  6439. var prev = null;
  6440. if (typeof delimeter !== 'function') {
  6441. list.forEach(this.node, this);
  6442. } else {
  6443. list.forEach(function(node) {
  6444. if (prev !== null) {
  6445. delimeter.call(this, prev);
  6446. }
  6447. this.node(node);
  6448. prev = node;
  6449. }, this);
  6450. }
  6451. }
  6452. var create$1 = function createGenerator(config) {
  6453. function processNode(node) {
  6454. if (hasOwnProperty$3.call(types, node.type)) {
  6455. types[node.type].call(this, node);
  6456. } else {
  6457. throw new Error('Unknown node type: ' + node.type);
  6458. }
  6459. }
  6460. var types = {};
  6461. if (config.node) {
  6462. for (var name in config.node) {
  6463. types[name] = config.node[name].generate;
  6464. }
  6465. }
  6466. return function(node, options) {
  6467. var buffer = '';
  6468. var handlers = {
  6469. children: processChildren,
  6470. node: processNode,
  6471. chunk: function(chunk) {
  6472. buffer += chunk;
  6473. },
  6474. result: function() {
  6475. return buffer;
  6476. }
  6477. };
  6478. if (options) {
  6479. if (typeof options.decorator === 'function') {
  6480. handlers = options.decorator(handlers);
  6481. }
  6482. if (options.sourceMap) {
  6483. handlers = sourceMap(handlers);
  6484. }
  6485. }
  6486. handlers.node(node);
  6487. return handlers.result();
  6488. };
  6489. };
  6490. var create$2 = function createConvertors(walk) {
  6491. return {
  6492. fromPlainObject: function(ast) {
  6493. walk(ast, {
  6494. enter: function(node) {
  6495. if (node.children && node.children instanceof List_1 === false) {
  6496. node.children = new List_1().fromArray(node.children);
  6497. }
  6498. }
  6499. });
  6500. return ast;
  6501. },
  6502. toPlainObject: function(ast) {
  6503. walk(ast, {
  6504. leave: function(node) {
  6505. if (node.children && node.children instanceof List_1) {
  6506. node.children = node.children.toArray();
  6507. }
  6508. }
  6509. });
  6510. return ast;
  6511. }
  6512. };
  6513. };
  6514. var hasOwnProperty$4 = Object.prototype.hasOwnProperty;
  6515. var noop$3 = function() {};
  6516. function ensureFunction$1(value) {
  6517. return typeof value === 'function' ? value : noop$3;
  6518. }
  6519. function invokeForType(fn, type) {
  6520. return function(node, item, list) {
  6521. if (node.type === type) {
  6522. fn.call(this, node, item, list);
  6523. }
  6524. };
  6525. }
  6526. function getWalkersFromStructure(name, nodeType) {
  6527. var structure = nodeType.structure;
  6528. var walkers = [];
  6529. for (var key in structure) {
  6530. if (hasOwnProperty$4.call(structure, key) === false) {
  6531. continue;
  6532. }
  6533. var fieldTypes = structure[key];
  6534. var walker = {
  6535. name: key,
  6536. type: false,
  6537. nullable: false
  6538. };
  6539. if (!Array.isArray(structure[key])) {
  6540. fieldTypes = [structure[key]];
  6541. }
  6542. for (var i = 0; i < fieldTypes.length; i++) {
  6543. var fieldType = fieldTypes[i];
  6544. if (fieldType === null) {
  6545. walker.nullable = true;
  6546. } else if (typeof fieldType === 'string') {
  6547. walker.type = 'node';
  6548. } else if (Array.isArray(fieldType)) {
  6549. walker.type = 'list';
  6550. }
  6551. }
  6552. if (walker.type) {
  6553. walkers.push(walker);
  6554. }
  6555. }
  6556. if (walkers.length) {
  6557. return {
  6558. context: nodeType.walkContext,
  6559. fields: walkers
  6560. };
  6561. }
  6562. return null;
  6563. }
  6564. function getTypesFromConfig(config) {
  6565. var types = {};
  6566. for (var name in config.node) {
  6567. if (hasOwnProperty$4.call(config.node, name)) {
  6568. var nodeType = config.node[name];
  6569. if (!nodeType.structure) {
  6570. throw new Error('Missed `structure` field in `' + name + '` node type definition');
  6571. }
  6572. types[name] = getWalkersFromStructure(name, nodeType);
  6573. }
  6574. }
  6575. return types;
  6576. }
  6577. function createTypeIterator(config, reverse) {
  6578. var fields = config.fields.slice();
  6579. var contextName = config.context;
  6580. var useContext = typeof contextName === 'string';
  6581. if (reverse) {
  6582. fields.reverse();
  6583. }
  6584. return function(node, context, walk) {
  6585. var prevContextValue;
  6586. if (useContext) {
  6587. prevContextValue = context[contextName];
  6588. context[contextName] = node;
  6589. }
  6590. for (var i = 0; i < fields.length; i++) {
  6591. var field = fields[i];
  6592. var ref = node[field.name];
  6593. if (!field.nullable || ref) {
  6594. if (field.type === 'list') {
  6595. if (reverse) {
  6596. ref.forEachRight(walk);
  6597. } else {
  6598. ref.forEach(walk);
  6599. }
  6600. } else {
  6601. walk(ref);
  6602. }
  6603. }
  6604. }
  6605. if (useContext) {
  6606. context[contextName] = prevContextValue;
  6607. }
  6608. };
  6609. }
  6610. function createFastTraveralMap(iterators) {
  6611. return {
  6612. Atrule: {
  6613. StyleSheet: iterators.StyleSheet,
  6614. Atrule: iterators.Atrule,
  6615. Rule: iterators.Rule,
  6616. Block: iterators.Block
  6617. },
  6618. Rule: {
  6619. StyleSheet: iterators.StyleSheet,
  6620. Atrule: iterators.Atrule,
  6621. Rule: iterators.Rule,
  6622. Block: iterators.Block
  6623. },
  6624. Declaration: {
  6625. StyleSheet: iterators.StyleSheet,
  6626. Atrule: iterators.Atrule,
  6627. Rule: iterators.Rule,
  6628. Block: iterators.Block,
  6629. DeclarationList: iterators.DeclarationList
  6630. }
  6631. };
  6632. }
  6633. var create$3 = function createWalker(config) {
  6634. var types = getTypesFromConfig(config);
  6635. var iteratorsNatural = {};
  6636. var iteratorsReverse = {};
  6637. for (var name in types) {
  6638. if (hasOwnProperty$4.call(types, name) && types[name] !== null) {
  6639. iteratorsNatural[name] = createTypeIterator(types[name], false);
  6640. iteratorsReverse[name] = createTypeIterator(types[name], true);
  6641. }
  6642. }
  6643. var fastTraversalIteratorsNatural = createFastTraveralMap(iteratorsNatural);
  6644. var fastTraversalIteratorsReverse = createFastTraveralMap(iteratorsReverse);
  6645. var walk = function(root, options) {
  6646. function walkNode(node, item, list) {
  6647. enter.call(context, node, item, list);
  6648. if (iterators.hasOwnProperty(node.type)) {
  6649. iterators[node.type](node, context, walkNode);
  6650. }
  6651. leave.call(context, node, item, list);
  6652. }
  6653. var enter = noop$3;
  6654. var leave = noop$3;
  6655. var iterators = iteratorsNatural;
  6656. var context = {
  6657. root: root,
  6658. stylesheet: null,
  6659. atrule: null,
  6660. atrulePrelude: null,
  6661. rule: null,
  6662. selector: null,
  6663. block: null,
  6664. declaration: null,
  6665. function: null
  6666. };
  6667. if (typeof options === 'function') {
  6668. enter = options;
  6669. } else if (options) {
  6670. enter = ensureFunction$1(options.enter);
  6671. leave = ensureFunction$1(options.leave);
  6672. if (options.reverse) {
  6673. iterators = iteratorsReverse;
  6674. }
  6675. if (options.visit) {
  6676. if (fastTraversalIteratorsNatural.hasOwnProperty(options.visit)) {
  6677. iterators = options.reverse
  6678. ? fastTraversalIteratorsReverse[options.visit]
  6679. : fastTraversalIteratorsNatural[options.visit];
  6680. } else if (!types.hasOwnProperty(options.visit)) {
  6681. throw new Error('Bad value `' + options.visit + '` for `visit` option (should be: ' + Object.keys(types).join(', ') + ')');
  6682. }
  6683. enter = invokeForType(enter, options.visit);
  6684. leave = invokeForType(leave, options.visit);
  6685. }
  6686. }
  6687. if (enter === noop$3 && leave === noop$3) {
  6688. throw new Error('Neither `enter` nor `leave` walker handler is set or both aren\'t a function');
  6689. }
  6690. // swap handlers in reverse mode to invert visit order
  6691. if (options.reverse) {
  6692. var tmp = enter;
  6693. enter = leave;
  6694. leave = tmp;
  6695. }
  6696. walkNode(root);
  6697. };
  6698. walk.find = function(ast, fn) {
  6699. var found = null;
  6700. walk(ast, function(node, item, list) {
  6701. if (found === null && fn.call(this, node, item, list)) {
  6702. found = node;
  6703. }
  6704. });
  6705. return found;
  6706. };
  6707. walk.findLast = function(ast, fn) {
  6708. var found = null;
  6709. walk(ast, {
  6710. reverse: true,
  6711. enter: function(node, item, list) {
  6712. if (found === null && fn.call(this, node, item, list)) {
  6713. found = node;
  6714. }
  6715. }
  6716. });
  6717. return found;
  6718. };
  6719. walk.findAll = function(ast, fn) {
  6720. var found = [];
  6721. walk(ast, function(node, item, list) {
  6722. if (fn.call(this, node, item, list)) {
  6723. found.push(node);
  6724. }
  6725. });
  6726. return found;
  6727. };
  6728. return walk;
  6729. };
  6730. var clone = function clone(node) {
  6731. var result = {};
  6732. for (var key in node) {
  6733. var value = node[key];
  6734. if (value) {
  6735. if (Array.isArray(value) || value instanceof List_1) {
  6736. value = value.map(clone);
  6737. } else if (value.constructor === Object) {
  6738. value = clone(value);
  6739. }
  6740. }
  6741. result[key] = value;
  6742. }
  6743. return result;
  6744. };
  6745. var hasOwnProperty$5 = Object.prototype.hasOwnProperty;
  6746. var shape = {
  6747. generic: true,
  6748. types: {},
  6749. atrules: {},
  6750. properties: {},
  6751. parseContext: {},
  6752. scope: {},
  6753. atrule: ['parse'],
  6754. pseudo: ['parse'],
  6755. node: ['name', 'structure', 'parse', 'generate', 'walkContext']
  6756. };
  6757. function isObject(value) {
  6758. return value && value.constructor === Object;
  6759. }
  6760. function copy(value) {
  6761. if (isObject(value)) {
  6762. return Object.assign({}, value);
  6763. } else {
  6764. return value;
  6765. }
  6766. }
  6767. function extend(dest, src) {
  6768. for (var key in src) {
  6769. if (hasOwnProperty$5.call(src, key)) {
  6770. if (isObject(dest[key])) {
  6771. extend(dest[key], copy(src[key]));
  6772. } else {
  6773. dest[key] = copy(src[key]);
  6774. }
  6775. }
  6776. }
  6777. }
  6778. function mix(dest, src, shape) {
  6779. for (var key in shape) {
  6780. if (hasOwnProperty$5.call(shape, key) === false) {
  6781. continue;
  6782. }
  6783. if (shape[key] === true) {
  6784. if (key in src) {
  6785. if (hasOwnProperty$5.call(src, key)) {
  6786. dest[key] = copy(src[key]);
  6787. }
  6788. }
  6789. } else if (shape[key]) {
  6790. if (isObject(shape[key])) {
  6791. var res = {};
  6792. extend(res, dest[key]);
  6793. extend(res, src[key]);
  6794. dest[key] = res;
  6795. } else if (Array.isArray(shape[key])) {
  6796. var res = {};
  6797. var innerShape = shape[key].reduce(function(s, k) {
  6798. s[k] = true;
  6799. return s;
  6800. }, {});
  6801. for (var name in dest[key]) {
  6802. if (hasOwnProperty$5.call(dest[key], name)) {
  6803. res[name] = {};
  6804. if (dest[key] && dest[key][name]) {
  6805. mix(res[name], dest[key][name], innerShape);
  6806. }
  6807. }
  6808. }
  6809. for (var name in src[key]) {
  6810. if (hasOwnProperty$5.call(src[key], name)) {
  6811. if (!res[name]) {
  6812. res[name] = {};
  6813. }
  6814. if (src[key] && src[key][name]) {
  6815. mix(res[name], src[key][name], innerShape);
  6816. }
  6817. }
  6818. }
  6819. dest[key] = res;
  6820. }
  6821. }
  6822. }
  6823. return dest;
  6824. }
  6825. var mix_1 = function(dest, src) {
  6826. return mix(dest, src, shape);
  6827. };
  6828. function createSyntax(config) {
  6829. var parse = create(config);
  6830. var walk = create$3(config);
  6831. var generate = create$1(config);
  6832. var convert = create$2(walk);
  6833. var syntax = {
  6834. List: List_1,
  6835. SyntaxError: _SyntaxError,
  6836. TokenStream: TokenStream_1,
  6837. Lexer: Lexer_1,
  6838. vendorPrefix: names.vendorPrefix,
  6839. keyword: names.keyword,
  6840. property: names.property,
  6841. isCustomProperty: names.isCustomProperty,
  6842. definitionSyntax: definitionSyntax,
  6843. lexer: null,
  6844. createLexer: function(config) {
  6845. return new Lexer_1(config, syntax, syntax.lexer.structure);
  6846. },
  6847. tokenize: tokenizer,
  6848. parse: parse,
  6849. walk: walk,
  6850. generate: generate,
  6851. find: walk.find,
  6852. findLast: walk.findLast,
  6853. findAll: walk.findAll,
  6854. clone: clone,
  6855. fromPlainObject: convert.fromPlainObject,
  6856. toPlainObject: convert.toPlainObject,
  6857. createSyntax: function(config) {
  6858. return createSyntax(mix_1({}, config));
  6859. },
  6860. fork: function(extension) {
  6861. var base = mix_1({}, config); // copy of config
  6862. return createSyntax(
  6863. typeof extension === 'function'
  6864. ? extension(base, Object.assign)
  6865. : mix_1(base, extension)
  6866. );
  6867. }
  6868. };
  6869. syntax.lexer = new Lexer_1({
  6870. generic: true,
  6871. types: config.types,
  6872. atrules: config.atrules,
  6873. properties: config.properties,
  6874. node: config.node
  6875. }, syntax);
  6876. return syntax;
  6877. }
  6878. var create_1 = function(config) {
  6879. return createSyntax(mix_1({}, config));
  6880. };
  6881. var create$4 = {
  6882. create: create_1
  6883. };
  6884. var generic$1 = true;
  6885. var types = {
  6886. "absolute-size": "xx-small|x-small|small|medium|large|x-large|xx-large",
  6887. "alpha-value": "<number>|<percentage>",
  6888. "angle-percentage": "<angle>|<percentage>",
  6889. "angular-color-hint": "<angle-percentage>",
  6890. "angular-color-stop": "<color>&&<color-stop-angle>?",
  6891. "angular-color-stop-list": "[<angular-color-stop> [, <angular-color-hint>]?]# , <angular-color-stop>",
  6892. "animateable-feature": "scroll-position|contents|<custom-ident>",
  6893. attachment: "scroll|fixed|local",
  6894. "attr()": "attr( <attr-name> <type-or-unit>? [, <attr-fallback>]? )",
  6895. "attr-matcher": "['~'|'|'|'^'|'$'|'*']? '='",
  6896. "attr-modifier": "i|s",
  6897. "attribute-selector": "'[' <wq-name> ']'|'[' <wq-name> <attr-matcher> [<string-token>|<ident-token>] <attr-modifier>? ']'",
  6898. "auto-repeat": "repeat( [auto-fill|auto-fit] , [<line-names>? <fixed-size>]+ <line-names>? )",
  6899. "auto-track-list": "[<line-names>? [<fixed-size>|<fixed-repeat>]]* <line-names>? <auto-repeat> [<line-names>? [<fixed-size>|<fixed-repeat>]]* <line-names>?",
  6900. "baseline-position": "[first|last]? baseline",
  6901. "basic-shape": "<inset()>|<circle()>|<ellipse()>|<polygon()>",
  6902. "bg-image": "none|<image>",
  6903. "bg-layer": "<bg-image>||<bg-position> [/ <bg-size>]?||<repeat-style>||<attachment>||<box>||<box>",
  6904. "bg-position": "[[left|center|right|top|bottom|<length-percentage>]|[left|center|right|<length-percentage>] [top|center|bottom|<length-percentage>]|[center|[left|right] <length-percentage>?]&&[center|[top|bottom] <length-percentage>?]]",
  6905. "bg-size": "[<length-percentage>|auto]{1,2}|cover|contain",
  6906. "blur()": "blur( <length> )",
  6907. "blend-mode": "normal|multiply|screen|overlay|darken|lighten|color-dodge|color-burn|hard-light|soft-light|difference|exclusion|hue|saturation|color|luminosity",
  6908. box: "border-box|padding-box|content-box",
  6909. "brightness()": "brightness( <number-percentage> )",
  6910. "calc()": "calc( <calc-sum> )",
  6911. "calc-sum": "<calc-product> [['+'|'-'] <calc-product>]*",
  6912. "calc-product": "<calc-value> ['*' <calc-value>|'/' <number>]*",
  6913. "calc-value": "<number>|<dimension>|<percentage>|( <calc-sum> )",
  6914. "cf-final-image": "<image>|<color>",
  6915. "cf-mixing-image": "<percentage>?&&<image>",
  6916. "circle()": "circle( [<shape-radius>]? [at <position>]? )",
  6917. "clamp()": "clamp( <calc-sum>#{3} )",
  6918. "class-selector": "'.' <ident-token>",
  6919. "clip-source": "<url>",
  6920. color: "<rgb()>|<rgba()>|<hsl()>|<hsla()>|<hex-color>|<named-color>|currentcolor|<deprecated-system-color>",
  6921. "color-stop": "<color-stop-length>|<color-stop-angle>",
  6922. "color-stop-angle": "<angle-percentage>{1,2}",
  6923. "color-stop-length": "<length-percentage>{1,2}",
  6924. "color-stop-list": "[<linear-color-stop> [, <linear-color-hint>]?]# , <linear-color-stop>",
  6925. combinator: "'>'|'+'|'~'|['||']",
  6926. "common-lig-values": "[common-ligatures|no-common-ligatures]",
  6927. compat: "searchfield|textarea|push-button|button-bevel|slider-horizontal|checkbox|radio|square-button|menulist|menulist-button|listbox|meter|progress-bar",
  6928. "composite-style": "clear|copy|source-over|source-in|source-out|source-atop|destination-over|destination-in|destination-out|destination-atop|xor",
  6929. "compositing-operator": "add|subtract|intersect|exclude",
  6930. "compound-selector": "[<type-selector>? <subclass-selector>* [<pseudo-element-selector> <pseudo-class-selector>*]*]!",
  6931. "compound-selector-list": "<compound-selector>#",
  6932. "complex-selector": "<compound-selector> [<combinator>? <compound-selector>]*",
  6933. "complex-selector-list": "<complex-selector>#",
  6934. "conic-gradient()": "conic-gradient( [from <angle>]? [at <position>]? , <angular-color-stop-list> )",
  6935. "contextual-alt-values": "[contextual|no-contextual]",
  6936. "content-distribution": "space-between|space-around|space-evenly|stretch",
  6937. "content-list": "[<string>|contents|<url>|<quote>|<attr()>|counter( <ident> , <'list-style-type'>? )]+",
  6938. "content-position": "center|start|end|flex-start|flex-end",
  6939. "content-replacement": "<image>",
  6940. "contrast()": "contrast( [<number-percentage>] )",
  6941. "counter()": "counter( <custom-ident> , [<counter-style>|none]? )",
  6942. "counter-style": "<counter-style-name>|symbols( )",
  6943. "counter-style-name": "<custom-ident>",
  6944. "counters()": "counters( <custom-ident> , <string> , [<counter-style>|none]? )",
  6945. "cross-fade()": "cross-fade( <cf-mixing-image> , <cf-final-image>? )",
  6946. "cubic-bezier-timing-function": "ease|ease-in|ease-out|ease-in-out|cubic-bezier( <number> , <number> , <number> , <number> )",
  6947. "deprecated-system-color": "ActiveBorder|ActiveCaption|AppWorkspace|Background|ButtonFace|ButtonHighlight|ButtonShadow|ButtonText|CaptionText|GrayText|Highlight|HighlightText|InactiveBorder|InactiveCaption|InactiveCaptionText|InfoBackground|InfoText|Menu|MenuText|Scrollbar|ThreeDDarkShadow|ThreeDFace|ThreeDHighlight|ThreeDLightShadow|ThreeDShadow|Window|WindowFrame|WindowText",
  6948. "discretionary-lig-values": "[discretionary-ligatures|no-discretionary-ligatures]",
  6949. "display-box": "contents|none",
  6950. "display-inside": "flow|flow-root|table|flex|grid|ruby",
  6951. "display-internal": "table-row-group|table-header-group|table-footer-group|table-row|table-cell|table-column-group|table-column|table-caption|ruby-base|ruby-text|ruby-base-container|ruby-text-container",
  6952. "display-legacy": "inline-block|inline-list-item|inline-table|inline-flex|inline-grid",
  6953. "display-listitem": "<display-outside>?&&[flow|flow-root]?&&list-item",
  6954. "display-outside": "block|inline|run-in",
  6955. "drop-shadow()": "drop-shadow( <length>{2,3} <color>? )",
  6956. "east-asian-variant-values": "[jis78|jis83|jis90|jis04|simplified|traditional]",
  6957. "east-asian-width-values": "[full-width|proportional-width]",
  6958. "element()": "element( <id-selector> )",
  6959. "ellipse()": "ellipse( [<shape-radius>{2}]? [at <position>]? )",
  6960. "ending-shape": "circle|ellipse",
  6961. "env()": "env( <custom-ident> , <declaration-value>? )",
  6962. "explicit-track-list": "[<line-names>? <track-size>]+ <line-names>?",
  6963. "family-name": "<string>|<custom-ident>+",
  6964. "feature-tag-value": "<string> [<integer>|on|off]?",
  6965. "feature-type": "@stylistic|@historical-forms|@styleset|@character-variant|@swash|@ornaments|@annotation",
  6966. "feature-value-block": "<feature-type> '{' <feature-value-declaration-list> '}'",
  6967. "feature-value-block-list": "<feature-value-block>+",
  6968. "feature-value-declaration": "<custom-ident> : <integer>+ ;",
  6969. "feature-value-declaration-list": "<feature-value-declaration>",
  6970. "feature-value-name": "<custom-ident>",
  6971. "fill-rule": "nonzero|evenodd",
  6972. "filter-function": "<blur()>|<brightness()>|<contrast()>|<drop-shadow()>|<grayscale()>|<hue-rotate()>|<invert()>|<opacity()>|<saturate()>|<sepia()>",
  6973. "filter-function-list": "[<filter-function>|<url>]+",
  6974. "final-bg-layer": "<'background-color'>||<bg-image>||<bg-position> [/ <bg-size>]?||<repeat-style>||<attachment>||<box>||<box>",
  6975. "fit-content()": "fit-content( [<length>|<percentage>] )",
  6976. "fixed-breadth": "<length-percentage>",
  6977. "fixed-repeat": "repeat( [<positive-integer>] , [<line-names>? <fixed-size>]+ <line-names>? )",
  6978. "fixed-size": "<fixed-breadth>|minmax( <fixed-breadth> , <track-breadth> )|minmax( <inflexible-breadth> , <fixed-breadth> )",
  6979. "font-stretch-absolute": "normal|ultra-condensed|extra-condensed|condensed|semi-condensed|semi-expanded|expanded|extra-expanded|ultra-expanded|<percentage>",
  6980. "font-variant-css21": "[normal|small-caps]",
  6981. "font-weight-absolute": "normal|bold|<number>",
  6982. "frequency-percentage": "<frequency>|<percentage>",
  6983. "general-enclosed": "[<function-token> <any-value> )]|( <ident> <any-value> )",
  6984. "generic-family": "serif|sans-serif|cursive|fantasy|monospace|-apple-system",
  6985. "generic-name": "serif|sans-serif|cursive|fantasy|monospace",
  6986. "geometry-box": "<shape-box>|fill-box|stroke-box|view-box",
  6987. gradient: "<linear-gradient()>|<repeating-linear-gradient()>|<radial-gradient()>|<repeating-radial-gradient()>|<conic-gradient()>|<-legacy-gradient>",
  6988. "grayscale()": "grayscale( <number-percentage> )",
  6989. "grid-line": "auto|<custom-ident>|[<integer>&&<custom-ident>?]|[span&&[<integer>||<custom-ident>]]",
  6990. "historical-lig-values": "[historical-ligatures|no-historical-ligatures]",
  6991. "hsl()": "hsl( <hue> <percentage> <percentage> [/ <alpha-value>]? )|hsl( <hue> , <percentage> , <percentage> , <alpha-value>? )",
  6992. "hsla()": "hsla( <hue> <percentage> <percentage> [/ <alpha-value>]? )|hsla( <hue> , <percentage> , <percentage> , <alpha-value>? )",
  6993. hue: "<number>|<angle>",
  6994. "hue-rotate()": "hue-rotate( <angle> )",
  6995. image: "<url>|<image()>|<image-set()>|<element()>|<cross-fade()>|<gradient>",
  6996. "image()": "image( <image-tags>? [<image-src>? , <color>?]! )",
  6997. "image-set()": "image-set( <image-set-option># )",
  6998. "image-set-option": "[<image>|<string>] <resolution>",
  6999. "image-src": "<url>|<string>",
  7000. "image-tags": "ltr|rtl",
  7001. "inflexible-breadth": "<length>|<percentage>|min-content|max-content|auto",
  7002. "inset()": "inset( <length-percentage>{1,4} [round <'border-radius'>]? )",
  7003. "invert()": "invert( <number-percentage> )",
  7004. "keyframes-name": "<custom-ident>|<string>",
  7005. "keyframe-block": "<keyframe-selector># { <declaration-list> }",
  7006. "keyframe-block-list": "<keyframe-block>+",
  7007. "keyframe-selector": "from|to|<percentage>",
  7008. "leader()": "leader( <leader-type> )",
  7009. "leader-type": "dotted|solid|space|<string>",
  7010. "length-percentage": "<length>|<percentage>",
  7011. "line-names": "'[' <custom-ident>* ']'",
  7012. "line-name-list": "[<line-names>|<name-repeat>]+",
  7013. "line-style": "none|hidden|dotted|dashed|solid|double|groove|ridge|inset|outset",
  7014. "line-width": "<length>|thin|medium|thick",
  7015. "linear-color-hint": "<length-percentage>",
  7016. "linear-color-stop": "<color> <color-stop-length>?",
  7017. "linear-gradient()": "linear-gradient( [<angle>|to <side-or-corner>]? , <color-stop-list> )",
  7018. "mask-layer": "<mask-reference>||<position> [/ <bg-size>]?||<repeat-style>||<geometry-box>||[<geometry-box>|no-clip]||<compositing-operator>||<masking-mode>",
  7019. "mask-position": "[<length-percentage>|left|center|right] [<length-percentage>|top|center|bottom]?",
  7020. "mask-reference": "none|<image>|<mask-source>",
  7021. "mask-source": "<url>",
  7022. "masking-mode": "alpha|luminance|match-source",
  7023. "matrix()": "matrix( <number>#{6} )",
  7024. "matrix3d()": "matrix3d( <number>#{16} )",
  7025. "max()": "max( <calc-sum># )",
  7026. "media-and": "<media-in-parens> [and <media-in-parens>]+",
  7027. "media-condition": "<media-not>|<media-and>|<media-or>|<media-in-parens>",
  7028. "media-condition-without-or": "<media-not>|<media-and>|<media-in-parens>",
  7029. "media-feature": "( [<mf-plain>|<mf-boolean>|<mf-range>] )",
  7030. "media-in-parens": "( <media-condition> )|<media-feature>|<general-enclosed>",
  7031. "media-not": "not <media-in-parens>",
  7032. "media-or": "<media-in-parens> [or <media-in-parens>]+",
  7033. "media-query": "<media-condition>|[not|only]? <media-type> [and <media-condition-without-or>]?",
  7034. "media-query-list": "<media-query>#",
  7035. "media-type": "<ident>",
  7036. "mf-boolean": "<mf-name>",
  7037. "mf-name": "<ident>",
  7038. "mf-plain": "<mf-name> : <mf-value>",
  7039. "mf-range": "<mf-name> ['<'|'>']? '='? <mf-value>|<mf-value> ['<'|'>']? '='? <mf-name>|<mf-value> '<' '='? <mf-name> '<' '='? <mf-value>|<mf-value> '>' '='? <mf-name> '>' '='? <mf-value>",
  7040. "mf-value": "<number>|<dimension>|<ident>|<ratio>",
  7041. "min()": "min( <calc-sum># )",
  7042. "minmax()": "minmax( [<length>|<percentage>|<flex>|min-content|max-content|auto] , [<length>|<percentage>|<flex>|min-content|max-content|auto] )",
  7043. "named-color": "transparent|aliceblue|antiquewhite|aqua|aquamarine|azure|beige|bisque|black|blanchedalmond|blue|blueviolet|brown|burlywood|cadetblue|chartreuse|chocolate|coral|cornflowerblue|cornsilk|crimson|cyan|darkblue|darkcyan|darkgoldenrod|darkgray|darkgreen|darkgrey|darkkhaki|darkmagenta|darkolivegreen|darkorange|darkorchid|darkred|darksalmon|darkseagreen|darkslateblue|darkslategray|darkslategrey|darkturquoise|darkviolet|deeppink|deepskyblue|dimgray|dimgrey|dodgerblue|firebrick|floralwhite|forestgreen|fuchsia|gainsboro|ghostwhite|gold|goldenrod|gray|green|greenyellow|grey|honeydew|hotpink|indianred|indigo|ivory|khaki|lavender|lavenderblush|lawngreen|lemonchiffon|lightblue|lightcoral|lightcyan|lightgoldenrodyellow|lightgray|lightgreen|lightgrey|lightpink|lightsalmon|lightseagreen|lightskyblue|lightslategray|lightslategrey|lightsteelblue|lightyellow|lime|limegreen|linen|magenta|maroon|mediumaquamarine|mediumblue|mediumorchid|mediumpurple|mediumseagreen|mediumslateblue|mediumspringgreen|mediumturquoise|mediumvioletred|midnightblue|mintcream|mistyrose|moccasin|navajowhite|navy|oldlace|olive|olivedrab|orange|orangered|orchid|palegoldenrod|palegreen|paleturquoise|palevioletred|papayawhip|peachpuff|peru|pink|plum|powderblue|purple|rebeccapurple|red|rosybrown|royalblue|saddlebrown|salmon|sandybrown|seagreen|seashell|sienna|silver|skyblue|slateblue|slategray|slategrey|snow|springgreen|steelblue|tan|teal|thistle|tomato|turquoise|violet|wheat|white|whitesmoke|yellow|yellowgreen|<-non-standard-color>",
  7044. "namespace-prefix": "<ident>",
  7045. "ns-prefix": "[<ident-token>|'*']? '|'",
  7046. "number-percentage": "<number>|<percentage>",
  7047. "numeric-figure-values": "[lining-nums|oldstyle-nums]",
  7048. "numeric-fraction-values": "[diagonal-fractions|stacked-fractions]",
  7049. "numeric-spacing-values": "[proportional-nums|tabular-nums]",
  7050. nth: "<an-plus-b>|even|odd",
  7051. "opacity()": "opacity( [<number-percentage>] )",
  7052. "overflow-position": "unsafe|safe",
  7053. "outline-radius": "<length>|<percentage>",
  7054. "page-body": "<declaration>? [; <page-body>]?|<page-margin-box> <page-body>",
  7055. "page-margin-box": "<page-margin-box-type> '{' <declaration-list> '}'",
  7056. "page-margin-box-type": "@top-left-corner|@top-left|@top-center|@top-right|@top-right-corner|@bottom-left-corner|@bottom-left|@bottom-center|@bottom-right|@bottom-right-corner|@left-top|@left-middle|@left-bottom|@right-top|@right-middle|@right-bottom",
  7057. "page-selector-list": "[<page-selector>#]?",
  7058. "page-selector": "<pseudo-page>+|<ident> <pseudo-page>*",
  7059. "perspective()": "perspective( <length> )",
  7060. "polygon()": "polygon( <fill-rule>? , [<length-percentage> <length-percentage>]# )",
  7061. position: "[[left|center|right]||[top|center|bottom]|[left|center|right|<length-percentage>] [top|center|bottom|<length-percentage>]?|[[left|right] <length-percentage>]&&[[top|bottom] <length-percentage>]]",
  7062. "pseudo-class-selector": "':' <ident-token>|':' <function-token> <any-value> ')'",
  7063. "pseudo-element-selector": "':' <pseudo-class-selector>",
  7064. "pseudo-page": ": [left|right|first|blank]",
  7065. quote: "open-quote|close-quote|no-open-quote|no-close-quote",
  7066. "radial-gradient()": "radial-gradient( [<ending-shape>||<size>]? [at <position>]? , <color-stop-list> )",
  7067. "relative-selector": "<combinator>? <complex-selector>",
  7068. "relative-selector-list": "<relative-selector>#",
  7069. "relative-size": "larger|smaller",
  7070. "repeat-style": "repeat-x|repeat-y|[repeat|space|round|no-repeat]{1,2}",
  7071. "repeating-linear-gradient()": "repeating-linear-gradient( [<angle>|to <side-or-corner>]? , <color-stop-list> )",
  7072. "repeating-radial-gradient()": "repeating-radial-gradient( [<ending-shape>||<size>]? [at <position>]? , <color-stop-list> )",
  7073. "rgb()": "rgb( <percentage>{3} [/ <alpha-value>]? )|rgb( <number>{3} [/ <alpha-value>]? )|rgb( <percentage>#{3} , <alpha-value>? )|rgb( <number>#{3} , <alpha-value>? )",
  7074. "rgba()": "rgba( <percentage>{3} [/ <alpha-value>]? )|rgba( <number>{3} [/ <alpha-value>]? )|rgba( <percentage>#{3} , <alpha-value>? )|rgba( <number>#{3} , <alpha-value>? )",
  7075. "rotate()": "rotate( [<angle>|<zero>] )",
  7076. "rotate3d()": "rotate3d( <number> , <number> , <number> , [<angle>|<zero>] )",
  7077. "rotateX()": "rotateX( [<angle>|<zero>] )",
  7078. "rotateY()": "rotateY( [<angle>|<zero>] )",
  7079. "rotateZ()": "rotateZ( [<angle>|<zero>] )",
  7080. "saturate()": "saturate( <number-percentage> )",
  7081. "scale()": "scale( <number> , <number>? )",
  7082. "scale3d()": "scale3d( <number> , <number> , <number> )",
  7083. "scaleX()": "scaleX( <number> )",
  7084. "scaleY()": "scaleY( <number> )",
  7085. "scaleZ()": "scaleZ( <number> )",
  7086. "self-position": "center|start|end|self-start|self-end|flex-start|flex-end",
  7087. "shape-radius": "<length-percentage>|closest-side|farthest-side",
  7088. "skew()": "skew( [<angle>|<zero>] , [<angle>|<zero>]? )",
  7089. "skewX()": "skewX( [<angle>|<zero>] )",
  7090. "skewY()": "skewY( [<angle>|<zero>] )",
  7091. "sepia()": "sepia( <number-percentage> )",
  7092. shadow: "inset?&&<length>{2,4}&&<color>?",
  7093. "shadow-t": "[<length>{2,3}&&<color>?]",
  7094. shape: "rect( <top> , <right> , <bottom> , <left> )|rect( <top> <right> <bottom> <left> )",
  7095. "shape-box": "<box>|margin-box",
  7096. "side-or-corner": "[left|right]||[top|bottom]",
  7097. "single-animation": "<time>||<timing-function>||<time>||<single-animation-iteration-count>||<single-animation-direction>||<single-animation-fill-mode>||<single-animation-play-state>||[none|<keyframes-name>]",
  7098. "single-animation-direction": "normal|reverse|alternate|alternate-reverse",
  7099. "single-animation-fill-mode": "none|forwards|backwards|both",
  7100. "single-animation-iteration-count": "infinite|<number>",
  7101. "single-animation-play-state": "running|paused",
  7102. "single-transition": "[none|<single-transition-property>]||<time>||<timing-function>||<time>",
  7103. "single-transition-property": "all|<custom-ident>",
  7104. size: "closest-side|farthest-side|closest-corner|farthest-corner|<length>|<length-percentage>{2}",
  7105. "step-position": "jump-start|jump-end|jump-none|jump-both|start|end",
  7106. "step-timing-function": "step-start|step-end|steps( <integer> [, <step-position>]? )",
  7107. "subclass-selector": "<id-selector>|<class-selector>|<attribute-selector>|<pseudo-class-selector>",
  7108. "supports-condition": "not <supports-in-parens>|<supports-in-parens> [and <supports-in-parens>]*|<supports-in-parens> [or <supports-in-parens>]*",
  7109. "supports-in-parens": "( <supports-condition> )|<supports-feature>|<general-enclosed>",
  7110. "supports-feature": "<supports-decl>|<supports-selector-fn>",
  7111. "supports-decl": "( <declaration> )",
  7112. "supports-selector-fn": "selector( <complex-selector> )",
  7113. symbol: "<string>|<image>|<custom-ident>",
  7114. target: "<target-counter()>|<target-counters()>|<target-text()>",
  7115. "target-counter()": "target-counter( [<string>|<url>] , <custom-ident> , <counter-style>? )",
  7116. "target-counters()": "target-counters( [<string>|<url>] , <custom-ident> , <string> , <counter-style>? )",
  7117. "target-text()": "target-text( [<string>|<url>] , [content|before|after|first-letter]? )",
  7118. "time-percentage": "<time>|<percentage>",
  7119. "timing-function": "linear|<cubic-bezier-timing-function>|<step-timing-function>",
  7120. "track-breadth": "<length-percentage>|<flex>|min-content|max-content|auto",
  7121. "track-list": "[<line-names>? [<track-size>|<track-repeat>]]+ <line-names>?",
  7122. "track-repeat": "repeat( [<positive-integer>] , [<line-names>? <track-size>]+ <line-names>? )",
  7123. "track-size": "<track-breadth>|minmax( <inflexible-breadth> , <track-breadth> )|fit-content( [<length>|<percentage>] )",
  7124. "transform-function": "<matrix()>|<translate()>|<translateX()>|<translateY()>|<scale()>|<scaleX()>|<scaleY()>|<rotate()>|<skew()>|<skewX()>|<skewY()>|<matrix3d()>|<translate3d()>|<translateZ()>|<scale3d()>|<scaleZ()>|<rotate3d()>|<rotateX()>|<rotateY()>|<rotateZ()>|<perspective()>",
  7125. "transform-list": "<transform-function>+",
  7126. "translate()": "translate( <length-percentage> , <length-percentage>? )",
  7127. "translate3d()": "translate3d( <length-percentage> , <length-percentage> , <length> )",
  7128. "translateX()": "translateX( <length-percentage> )",
  7129. "translateY()": "translateY( <length-percentage> )",
  7130. "translateZ()": "translateZ( <length> )",
  7131. "type-or-unit": "string|color|url|integer|number|length|angle|time|frequency|cap|ch|em|ex|ic|lh|rlh|rem|vb|vi|vw|vh|vmin|vmax|mm|Q|cm|in|pt|pc|px|deg|grad|rad|turn|ms|s|Hz|kHz|%",
  7132. "type-selector": "<wq-name>|<ns-prefix>? '*'",
  7133. "var()": "var( <custom-property-name> , <declaration-value>? )",
  7134. "viewport-length": "auto|<length-percentage>",
  7135. "wq-name": "<ns-prefix>? <ident-token>",
  7136. "-legacy-gradient": "<-webkit-gradient()>|<-legacy-linear-gradient>|<-legacy-repeating-linear-gradient>|<-legacy-radial-gradient>|<-legacy-repeating-radial-gradient>",
  7137. "-legacy-linear-gradient": "-moz-linear-gradient( <-legacy-linear-gradient-arguments> )|-webkit-linear-gradient( <-legacy-linear-gradient-arguments> )|-o-linear-gradient( <-legacy-linear-gradient-arguments> )",
  7138. "-legacy-repeating-linear-gradient": "-moz-repeating-linear-gradient( <-legacy-linear-gradient-arguments> )|-webkit-repeating-linear-gradient( <-legacy-linear-gradient-arguments> )|-o-repeating-linear-gradient( <-legacy-linear-gradient-arguments> )",
  7139. "-legacy-linear-gradient-arguments": "[<angle>|<side-or-corner>]? , <color-stop-list>",
  7140. "-legacy-radial-gradient": "-moz-radial-gradient( <-legacy-radial-gradient-arguments> )|-webkit-radial-gradient( <-legacy-radial-gradient-arguments> )|-o-radial-gradient( <-legacy-radial-gradient-arguments> )",
  7141. "-legacy-repeating-radial-gradient": "-moz-repeating-radial-gradient( <-legacy-radial-gradient-arguments> )|-webkit-repeating-radial-gradient( <-legacy-radial-gradient-arguments> )|-o-repeating-radial-gradient( <-legacy-radial-gradient-arguments> )",
  7142. "-legacy-radial-gradient-arguments": "[<position> ,]? [[[<-legacy-radial-gradient-shape>||<-legacy-radial-gradient-size>]|[<length>|<percentage>]{2}] ,]? <color-stop-list>",
  7143. "-legacy-radial-gradient-size": "closest-side|closest-corner|farthest-side|farthest-corner|contain|cover",
  7144. "-legacy-radial-gradient-shape": "circle|ellipse",
  7145. "-non-standard-font": "-apple-system-body|-apple-system-headline|-apple-system-subheadline|-apple-system-caption1|-apple-system-caption2|-apple-system-footnote|-apple-system-short-body|-apple-system-short-headline|-apple-system-short-subheadline|-apple-system-short-caption1|-apple-system-short-footnote|-apple-system-tall-body",
  7146. "-non-standard-color": "-moz-ButtonDefault|-moz-ButtonHoverFace|-moz-ButtonHoverText|-moz-CellHighlight|-moz-CellHighlightText|-moz-Combobox|-moz-ComboboxText|-moz-Dialog|-moz-DialogText|-moz-dragtargetzone|-moz-EvenTreeRow|-moz-Field|-moz-FieldText|-moz-html-CellHighlight|-moz-html-CellHighlightText|-moz-mac-accentdarkestshadow|-moz-mac-accentdarkshadow|-moz-mac-accentface|-moz-mac-accentlightesthighlight|-moz-mac-accentlightshadow|-moz-mac-accentregularhighlight|-moz-mac-accentregularshadow|-moz-mac-chrome-active|-moz-mac-chrome-inactive|-moz-mac-focusring|-moz-mac-menuselect|-moz-mac-menushadow|-moz-mac-menutextselect|-moz-MenuHover|-moz-MenuHoverText|-moz-MenuBarText|-moz-MenuBarHoverText|-moz-nativehyperlinktext|-moz-OddTreeRow|-moz-win-communicationstext|-moz-win-mediatext|-moz-activehyperlinktext|-moz-default-background-color|-moz-default-color|-moz-hyperlinktext|-moz-visitedhyperlinktext|-webkit-activelink|-webkit-focus-ring-color|-webkit-link|-webkit-text",
  7147. "-non-standard-image-rendering": "optimize-contrast|-moz-crisp-edges|-o-crisp-edges|-webkit-optimize-contrast",
  7148. "-non-standard-overflow": "-moz-scrollbars-none|-moz-scrollbars-horizontal|-moz-scrollbars-vertical|-moz-hidden-unscrollable",
  7149. "-non-standard-width": "min-intrinsic|intrinsic|-moz-min-content|-moz-max-content|-webkit-min-content|-webkit-max-content",
  7150. "-webkit-gradient()": "-webkit-gradient( <-webkit-gradient-type> , <-webkit-gradient-point> [, <-webkit-gradient-point>|, <-webkit-gradient-radius> , <-webkit-gradient-point>] [, <-webkit-gradient-radius>]? [, <-webkit-gradient-color-stop>]* )",
  7151. "-webkit-gradient-color-stop": "from( <color> )|color-stop( [<number-zero-one>|<percentage>] , <color> )|to( <color> )",
  7152. "-webkit-gradient-point": "[left|center|right|<length-percentage>] [top|center|bottom|<length-percentage>]",
  7153. "-webkit-gradient-radius": "<length>|<percentage>",
  7154. "-webkit-gradient-type": "linear|radial",
  7155. "-webkit-mask-box-repeat": "repeat|stretch|round",
  7156. "-webkit-mask-clip-style": "border|border-box|padding|padding-box|content|content-box|text",
  7157. "-ms-filter-function-list": "<-ms-filter-function>+",
  7158. "-ms-filter-function": "<-ms-filter-function-progid>|<-ms-filter-function-legacy>",
  7159. "-ms-filter-function-progid": "'progid:' [<ident-token> '.']* [<ident-token>|<function-token> <any-value>? )]",
  7160. "-ms-filter-function-legacy": "<ident-token>|<function-token> <any-value>? )",
  7161. "-ms-filter": "<string>",
  7162. age: "child|young|old",
  7163. "attr-name": "<wq-name>",
  7164. "attr-fallback": "<any-value>",
  7165. "border-radius": "<length-percentage>{1,2}",
  7166. bottom: "<length>|auto",
  7167. "generic-voice": "[<age>? <gender> <integer>?]",
  7168. gender: "male|female|neutral",
  7169. left: "<length>|auto",
  7170. "mask-image": "<mask-reference>#",
  7171. "name-repeat": "repeat( [<positive-integer>|auto-fill] , <line-names>+ )",
  7172. paint: "none|<color>|<url> [none|<color>]?|context-fill|context-stroke",
  7173. "path()": "path( <string> )",
  7174. ratio: "<integer> / <integer>",
  7175. right: "<length>|auto",
  7176. "svg-length": "<percentage>|<length>|<number>",
  7177. "svg-writing-mode": "lr-tb|rl-tb|tb-rl|lr|rl|tb",
  7178. top: "<length>|auto",
  7179. "track-group": "'(' [<string>* <track-minmax> <string>*]+ ')' ['[' <positive-integer> ']']?|<track-minmax>",
  7180. "track-list-v0": "[<string>* <track-group> <string>*]+|none",
  7181. "track-minmax": "minmax( <track-breadth> , <track-breadth> )|auto|<track-breadth>|fit-content",
  7182. x: "<number>",
  7183. y: "<number>",
  7184. declaration: "<ident-token> : <declaration-value>? ['!' important]?",
  7185. "declaration-list": "[<declaration>? ';']* <declaration>?",
  7186. url: "url( <string> <url-modifier>* )|<url-token>",
  7187. "url-modifier": "<ident>|<function-token> <any-value> )",
  7188. "number-zero-one": "<number [0,1]>",
  7189. "number-one-or-greater": "<number [1,∞]>",
  7190. "positive-integer": "<integer [0,∞]>"
  7191. };
  7192. var properties$1 = {
  7193. "--*": "<declaration-value>",
  7194. "-ms-accelerator": "false|true",
  7195. "-ms-block-progression": "tb|rl|bt|lr",
  7196. "-ms-content-zoom-chaining": "none|chained",
  7197. "-ms-content-zooming": "none|zoom",
  7198. "-ms-content-zoom-limit": "<'-ms-content-zoom-limit-min'> <'-ms-content-zoom-limit-max'>",
  7199. "-ms-content-zoom-limit-max": "<percentage>",
  7200. "-ms-content-zoom-limit-min": "<percentage>",
  7201. "-ms-content-zoom-snap": "<'-ms-content-zoom-snap-type'>||<'-ms-content-zoom-snap-points'>",
  7202. "-ms-content-zoom-snap-points": "snapInterval( <percentage> , <percentage> )|snapList( <percentage># )",
  7203. "-ms-content-zoom-snap-type": "none|proximity|mandatory",
  7204. "-ms-filter": "<string>",
  7205. "-ms-flow-from": "[none|<custom-ident>]#",
  7206. "-ms-flow-into": "[none|<custom-ident>]#",
  7207. "-ms-high-contrast-adjust": "auto|none",
  7208. "-ms-hyphenate-limit-chars": "auto|<integer>{1,3}",
  7209. "-ms-hyphenate-limit-lines": "no-limit|<integer>",
  7210. "-ms-hyphenate-limit-zone": "<percentage>|<length>",
  7211. "-ms-ime-align": "auto|after",
  7212. "-ms-overflow-style": "auto|none|scrollbar|-ms-autohiding-scrollbar",
  7213. "-ms-scrollbar-3dlight-color": "<color>",
  7214. "-ms-scrollbar-arrow-color": "<color>",
  7215. "-ms-scrollbar-base-color": "<color>",
  7216. "-ms-scrollbar-darkshadow-color": "<color>",
  7217. "-ms-scrollbar-face-color": "<color>",
  7218. "-ms-scrollbar-highlight-color": "<color>",
  7219. "-ms-scrollbar-shadow-color": "<color>",
  7220. "-ms-scrollbar-track-color": "<color>",
  7221. "-ms-scroll-chaining": "chained|none",
  7222. "-ms-scroll-limit": "<'-ms-scroll-limit-x-min'> <'-ms-scroll-limit-y-min'> <'-ms-scroll-limit-x-max'> <'-ms-scroll-limit-y-max'>",
  7223. "-ms-scroll-limit-x-max": "auto|<length>",
  7224. "-ms-scroll-limit-x-min": "<length>",
  7225. "-ms-scroll-limit-y-max": "auto|<length>",
  7226. "-ms-scroll-limit-y-min": "<length>",
  7227. "-ms-scroll-rails": "none|railed",
  7228. "-ms-scroll-snap-points-x": "snapInterval( <length-percentage> , <length-percentage> )|snapList( <length-percentage># )",
  7229. "-ms-scroll-snap-points-y": "snapInterval( <length-percentage> , <length-percentage> )|snapList( <length-percentage># )",
  7230. "-ms-scroll-snap-type": "none|proximity|mandatory",
  7231. "-ms-scroll-snap-x": "<'-ms-scroll-snap-type'> <'-ms-scroll-snap-points-x'>",
  7232. "-ms-scroll-snap-y": "<'-ms-scroll-snap-type'> <'-ms-scroll-snap-points-y'>",
  7233. "-ms-scroll-translation": "none|vertical-to-horizontal",
  7234. "-ms-text-autospace": "none|ideograph-alpha|ideograph-numeric|ideograph-parenthesis|ideograph-space",
  7235. "-ms-touch-select": "grippers|none",
  7236. "-ms-user-select": "none|element|text",
  7237. "-ms-wrap-flow": "auto|both|start|end|maximum|clear",
  7238. "-ms-wrap-margin": "<length>",
  7239. "-ms-wrap-through": "wrap|none",
  7240. "-moz-appearance": "none|button|button-arrow-down|button-arrow-next|button-arrow-previous|button-arrow-up|button-bevel|button-focus|caret|checkbox|checkbox-container|checkbox-label|checkmenuitem|dualbutton|groupbox|listbox|listitem|menuarrow|menubar|menucheckbox|menuimage|menuitem|menuitemtext|menulist|menulist-button|menulist-text|menulist-textfield|menupopup|menuradio|menuseparator|meterbar|meterchunk|progressbar|progressbar-vertical|progresschunk|progresschunk-vertical|radio|radio-container|radio-label|radiomenuitem|range|range-thumb|resizer|resizerpanel|scale-horizontal|scalethumbend|scalethumb-horizontal|scalethumbstart|scalethumbtick|scalethumb-vertical|scale-vertical|scrollbarbutton-down|scrollbarbutton-left|scrollbarbutton-right|scrollbarbutton-up|scrollbarthumb-horizontal|scrollbarthumb-vertical|scrollbartrack-horizontal|scrollbartrack-vertical|searchfield|separator|sheet|spinner|spinner-downbutton|spinner-textfield|spinner-upbutton|splitter|statusbar|statusbarpanel|tab|tabpanel|tabpanels|tab-scroll-arrow-back|tab-scroll-arrow-forward|textfield|textfield-multiline|toolbar|toolbarbutton|toolbarbutton-dropdown|toolbargripper|toolbox|tooltip|treeheader|treeheadercell|treeheadersortarrow|treeitem|treeline|treetwisty|treetwistyopen|treeview|-moz-mac-unified-toolbar|-moz-win-borderless-glass|-moz-win-browsertabbar-toolbox|-moz-win-communicationstext|-moz-win-communications-toolbox|-moz-win-exclude-glass|-moz-win-glass|-moz-win-mediatext|-moz-win-media-toolbox|-moz-window-button-box|-moz-window-button-box-maximized|-moz-window-button-close|-moz-window-button-maximize|-moz-window-button-minimize|-moz-window-button-restore|-moz-window-frame-bottom|-moz-window-frame-left|-moz-window-frame-right|-moz-window-titlebar|-moz-window-titlebar-maximized",
  7241. "-moz-binding": "<url>|none",
  7242. "-moz-border-bottom-colors": "<color>+|none",
  7243. "-moz-border-left-colors": "<color>+|none",
  7244. "-moz-border-right-colors": "<color>+|none",
  7245. "-moz-border-top-colors": "<color>+|none",
  7246. "-moz-context-properties": "none|[fill|fill-opacity|stroke|stroke-opacity]#",
  7247. "-moz-float-edge": "border-box|content-box|margin-box|padding-box",
  7248. "-moz-force-broken-image-icon": "<integer>",
  7249. "-moz-image-region": "<shape>|auto",
  7250. "-moz-orient": "inline|block|horizontal|vertical",
  7251. "-moz-outline-radius": "<outline-radius>{1,4} [/ <outline-radius>{1,4}]?",
  7252. "-moz-outline-radius-bottomleft": "<outline-radius>",
  7253. "-moz-outline-radius-bottomright": "<outline-radius>",
  7254. "-moz-outline-radius-topleft": "<outline-radius>",
  7255. "-moz-outline-radius-topright": "<outline-radius>",
  7256. "-moz-stack-sizing": "ignore|stretch-to-fit",
  7257. "-moz-text-blink": "none|blink",
  7258. "-moz-user-focus": "ignore|normal|select-after|select-before|select-menu|select-same|select-all|none",
  7259. "-moz-user-input": "auto|none|enabled|disabled",
  7260. "-moz-user-modify": "read-only|read-write|write-only",
  7261. "-moz-window-dragging": "drag|no-drag",
  7262. "-moz-window-shadow": "default|menu|tooltip|sheet|none",
  7263. "-webkit-appearance": "none|button|button-bevel|caps-lock-indicator|caret|checkbox|default-button|listbox|listitem|media-fullscreen-button|media-mute-button|media-play-button|media-seek-back-button|media-seek-forward-button|media-slider|media-sliderthumb|menulist|menulist-button|menulist-text|menulist-textfield|push-button|radio|scrollbarbutton-down|scrollbarbutton-left|scrollbarbutton-right|scrollbarbutton-up|scrollbargripper-horizontal|scrollbargripper-vertical|scrollbarthumb-horizontal|scrollbarthumb-vertical|scrollbartrack-horizontal|scrollbartrack-vertical|searchfield|searchfield-cancel-button|searchfield-decoration|searchfield-results-button|searchfield-results-decoration|slider-horizontal|slider-vertical|sliderthumb-horizontal|sliderthumb-vertical|square-button|textarea|textfield",
  7264. "-webkit-border-before": "<'border-width'>||<'border-style'>||<'color'>",
  7265. "-webkit-border-before-color": "<'color'>",
  7266. "-webkit-border-before-style": "<'border-style'>",
  7267. "-webkit-border-before-width": "<'border-width'>",
  7268. "-webkit-box-reflect": "[above|below|right|left]? <length>? <image>?",
  7269. "-webkit-line-clamp": "none|<integer>",
  7270. "-webkit-mask": "[<mask-reference>||<position> [/ <bg-size>]?||<repeat-style>||[<box>|border|padding|content|text]||[<box>|border|padding|content]]#",
  7271. "-webkit-mask-attachment": "<attachment>#",
  7272. "-webkit-mask-clip": "[<box>|border|padding|content|text]#",
  7273. "-webkit-mask-composite": "<composite-style>#",
  7274. "-webkit-mask-image": "<mask-reference>#",
  7275. "-webkit-mask-origin": "[<box>|border|padding|content]#",
  7276. "-webkit-mask-position": "<position>#",
  7277. "-webkit-mask-position-x": "[<length-percentage>|left|center|right]#",
  7278. "-webkit-mask-position-y": "[<length-percentage>|top|center|bottom]#",
  7279. "-webkit-mask-repeat": "<repeat-style>#",
  7280. "-webkit-mask-repeat-x": "repeat|no-repeat|space|round",
  7281. "-webkit-mask-repeat-y": "repeat|no-repeat|space|round",
  7282. "-webkit-mask-size": "<bg-size>#",
  7283. "-webkit-overflow-scrolling": "auto|touch",
  7284. "-webkit-tap-highlight-color": "<color>",
  7285. "-webkit-text-fill-color": "<color>",
  7286. "-webkit-text-stroke": "<length>||<color>",
  7287. "-webkit-text-stroke-color": "<color>",
  7288. "-webkit-text-stroke-width": "<length>",
  7289. "-webkit-touch-callout": "default|none",
  7290. "-webkit-user-modify": "read-only|read-write|read-write-plaintext-only",
  7291. "align-content": "normal|<baseline-position>|<content-distribution>|<overflow-position>? <content-position>",
  7292. "align-items": "normal|stretch|<baseline-position>|[<overflow-position>? <self-position>]",
  7293. "align-self": "auto|normal|stretch|<baseline-position>|<overflow-position>? <self-position>",
  7294. all: "initial|inherit|unset|revert",
  7295. animation: "<single-animation>#",
  7296. "animation-delay": "<time>#",
  7297. "animation-direction": "<single-animation-direction>#",
  7298. "animation-duration": "<time>#",
  7299. "animation-fill-mode": "<single-animation-fill-mode>#",
  7300. "animation-iteration-count": "<single-animation-iteration-count>#",
  7301. "animation-name": "[none|<keyframes-name>]#",
  7302. "animation-play-state": "<single-animation-play-state>#",
  7303. "animation-timing-function": "<timing-function>#",
  7304. appearance: "none|auto|button|textfield|<compat>",
  7305. azimuth: "<angle>|[[left-side|far-left|left|center-left|center|center-right|right|far-right|right-side]||behind]|leftwards|rightwards",
  7306. "backdrop-filter": "none|<filter-function-list>",
  7307. "backface-visibility": "visible|hidden",
  7308. background: "[<bg-layer> ,]* <final-bg-layer>",
  7309. "background-attachment": "<attachment>#",
  7310. "background-blend-mode": "<blend-mode>#",
  7311. "background-clip": "<box>#",
  7312. "background-color": "<color>",
  7313. "background-image": "<bg-image>#",
  7314. "background-origin": "<box>#",
  7315. "background-position": "<bg-position>#",
  7316. "background-position-x": "[center|[left|right|x-start|x-end]? <length-percentage>?]#",
  7317. "background-position-y": "[center|[top|bottom|y-start|y-end]? <length-percentage>?]#",
  7318. "background-repeat": "<repeat-style>#",
  7319. "background-size": "<bg-size>#",
  7320. "block-overflow": "clip|ellipsis|<string>",
  7321. "block-size": "<'width'>",
  7322. border: "<line-width>||<line-style>||<color>",
  7323. "border-block": "<'border-top-width'>||<'border-top-style'>||<'color'>",
  7324. "border-block-color": "<'border-top-color'>{1,2}",
  7325. "border-block-style": "<'border-top-style'>",
  7326. "border-block-width": "<'border-top-width'>",
  7327. "border-block-end": "<'border-top-width'>||<'border-top-style'>||<'color'>",
  7328. "border-block-end-color": "<'border-top-color'>",
  7329. "border-block-end-style": "<'border-top-style'>",
  7330. "border-block-end-width": "<'border-top-width'>",
  7331. "border-block-start": "<'border-top-width'>||<'border-top-style'>||<'color'>",
  7332. "border-block-start-color": "<'border-top-color'>",
  7333. "border-block-start-style": "<'border-top-style'>",
  7334. "border-block-start-width": "<'border-top-width'>",
  7335. "border-bottom": "<line-width>||<line-style>||<color>",
  7336. "border-bottom-color": "<'border-top-color'>",
  7337. "border-bottom-left-radius": "<length-percentage>{1,2}",
  7338. "border-bottom-right-radius": "<length-percentage>{1,2}",
  7339. "border-bottom-style": "<line-style>",
  7340. "border-bottom-width": "<line-width>",
  7341. "border-collapse": "collapse|separate",
  7342. "border-color": "<color>{1,4}",
  7343. "border-end-end-radius": "<length-percentage>{1,2}",
  7344. "border-end-start-radius": "<length-percentage>{1,2}",
  7345. "border-image": "<'border-image-source'>||<'border-image-slice'> [/ <'border-image-width'>|/ <'border-image-width'>? / <'border-image-outset'>]?||<'border-image-repeat'>",
  7346. "border-image-outset": "[<length>|<number>]{1,4}",
  7347. "border-image-repeat": "[stretch|repeat|round|space]{1,2}",
  7348. "border-image-slice": "<number-percentage>{1,4}&&fill?",
  7349. "border-image-source": "none|<image>",
  7350. "border-image-width": "[<length-percentage>|<number>|auto]{1,4}",
  7351. "border-inline": "<'border-top-width'>||<'border-top-style'>||<'color'>",
  7352. "border-inline-end": "<'border-top-width'>||<'border-top-style'>||<'color'>",
  7353. "border-inline-color": "<'border-top-color'>{1,2}",
  7354. "border-inline-style": "<'border-top-style'>",
  7355. "border-inline-width": "<'border-top-width'>",
  7356. "border-inline-end-color": "<'border-top-color'>",
  7357. "border-inline-end-style": "<'border-top-style'>",
  7358. "border-inline-end-width": "<'border-top-width'>",
  7359. "border-inline-start": "<'border-top-width'>||<'border-top-style'>||<'color'>",
  7360. "border-inline-start-color": "<'border-top-color'>",
  7361. "border-inline-start-style": "<'border-top-style'>",
  7362. "border-inline-start-width": "<'border-top-width'>",
  7363. "border-left": "<line-width>||<line-style>||<color>",
  7364. "border-left-color": "<color>",
  7365. "border-left-style": "<line-style>",
  7366. "border-left-width": "<line-width>",
  7367. "border-radius": "<length-percentage>{1,4} [/ <length-percentage>{1,4}]?",
  7368. "border-right": "<line-width>||<line-style>||<color>",
  7369. "border-right-color": "<color>",
  7370. "border-right-style": "<line-style>",
  7371. "border-right-width": "<line-width>",
  7372. "border-spacing": "<length> <length>?",
  7373. "border-start-end-radius": "<length-percentage>{1,2}",
  7374. "border-start-start-radius": "<length-percentage>{1,2}",
  7375. "border-style": "<line-style>{1,4}",
  7376. "border-top": "<line-width>||<line-style>||<color>",
  7377. "border-top-color": "<color>",
  7378. "border-top-left-radius": "<length-percentage>{1,2}",
  7379. "border-top-right-radius": "<length-percentage>{1,2}",
  7380. "border-top-style": "<line-style>",
  7381. "border-top-width": "<line-width>",
  7382. "border-width": "<line-width>{1,4}",
  7383. bottom: "<length>|<percentage>|auto",
  7384. "box-align": "start|center|end|baseline|stretch",
  7385. "box-decoration-break": "slice|clone",
  7386. "box-direction": "normal|reverse|inherit",
  7387. "box-flex": "<number>",
  7388. "box-flex-group": "<integer>",
  7389. "box-lines": "single|multiple",
  7390. "box-ordinal-group": "<integer>",
  7391. "box-orient": "horizontal|vertical|inline-axis|block-axis|inherit",
  7392. "box-pack": "start|center|end|justify",
  7393. "box-shadow": "none|<shadow>#",
  7394. "box-sizing": "content-box|border-box",
  7395. "break-after": "auto|avoid|always|all|avoid-page|page|left|right|recto|verso|avoid-column|column|avoid-region|region",
  7396. "break-before": "auto|avoid|always|all|avoid-page|page|left|right|recto|verso|avoid-column|column|avoid-region|region",
  7397. "break-inside": "auto|avoid|avoid-page|avoid-column|avoid-region",
  7398. "caption-side": "top|bottom|block-start|block-end|inline-start|inline-end",
  7399. "caret-color": "auto|<color>",
  7400. clear: "none|left|right|both|inline-start|inline-end",
  7401. clip: "<shape>|auto",
  7402. "clip-path": "<clip-source>|[<basic-shape>||<geometry-box>]|none",
  7403. color: "<color>",
  7404. "color-adjust": "economy|exact",
  7405. "column-count": "<integer>|auto",
  7406. "column-fill": "auto|balance|balance-all",
  7407. "column-gap": "normal|<length-percentage>",
  7408. "column-rule": "<'column-rule-width'>||<'column-rule-style'>||<'column-rule-color'>",
  7409. "column-rule-color": "<color>",
  7410. "column-rule-style": "<'border-style'>",
  7411. "column-rule-width": "<'border-width'>",
  7412. "column-span": "none|all",
  7413. "column-width": "<length>|auto",
  7414. columns: "<'column-width'>||<'column-count'>",
  7415. contain: "none|strict|content|[size||layout||style||paint]",
  7416. content: "normal|none|[<content-replacement>|<content-list>] [/ <string>]?",
  7417. "counter-increment": "[<custom-ident> <integer>?]+|none",
  7418. "counter-reset": "[<custom-ident> <integer>?]+|none",
  7419. "counter-set": "[<custom-ident> <integer>?]+|none",
  7420. cursor: "[[<url> [<x> <y>]? ,]* [auto|default|none|context-menu|help|pointer|progress|wait|cell|crosshair|text|vertical-text|alias|copy|move|no-drop|not-allowed|e-resize|n-resize|ne-resize|nw-resize|s-resize|se-resize|sw-resize|w-resize|ew-resize|ns-resize|nesw-resize|nwse-resize|col-resize|row-resize|all-scroll|zoom-in|zoom-out|grab|grabbing|hand|-webkit-grab|-webkit-grabbing|-webkit-zoom-in|-webkit-zoom-out|-moz-grab|-moz-grabbing|-moz-zoom-in|-moz-zoom-out]]",
  7421. direction: "ltr|rtl",
  7422. display: "block|contents|flex|flow|flow-root|grid|inline|inline-block|inline-flex|inline-grid|inline-list-item|inline-table|list-item|none|ruby|ruby-base|ruby-base-container|ruby-text|ruby-text-container|run-in|table|table-caption|table-cell|table-column|table-column-group|table-footer-group|table-header-group|table-row|table-row-group|-ms-flexbox|-ms-inline-flexbox|-ms-grid|-ms-inline-grid|-webkit-flex|-webkit-inline-flex|-webkit-box|-webkit-inline-box|-moz-inline-stack|-moz-box|-moz-inline-box",
  7423. "empty-cells": "show|hide",
  7424. filter: "none|<filter-function-list>|<-ms-filter-function-list>",
  7425. flex: "none|[<'flex-grow'> <'flex-shrink'>?||<'flex-basis'>]",
  7426. "flex-basis": "content|<'width'>",
  7427. "flex-direction": "row|row-reverse|column|column-reverse",
  7428. "flex-flow": "<'flex-direction'>||<'flex-wrap'>",
  7429. "flex-grow": "<number>",
  7430. "flex-shrink": "<number>",
  7431. "flex-wrap": "nowrap|wrap|wrap-reverse",
  7432. float: "left|right|none|inline-start|inline-end",
  7433. font: "[[<'font-style'>||<font-variant-css21>||<'font-weight'>||<'font-stretch'>]? <'font-size'> [/ <'line-height'>]? <'font-family'>]|caption|icon|menu|message-box|small-caption|status-bar",
  7434. "font-family": "[<family-name>|<generic-family>]#",
  7435. "font-feature-settings": "normal|<feature-tag-value>#",
  7436. "font-kerning": "auto|normal|none",
  7437. "font-language-override": "normal|<string>",
  7438. "font-optical-sizing": "auto|none",
  7439. "font-variation-settings": "normal|[<string> <number>]#",
  7440. "font-size": "<absolute-size>|<relative-size>|<length-percentage>",
  7441. "font-size-adjust": "none|<number>",
  7442. "font-stretch": "<font-stretch-absolute>",
  7443. "font-style": "normal|italic|oblique <angle>?",
  7444. "font-synthesis": "none|[weight||style]",
  7445. "font-variant": "normal|none|[<common-lig-values>||<discretionary-lig-values>||<historical-lig-values>||<contextual-alt-values>||stylistic( <feature-value-name> )||historical-forms||styleset( <feature-value-name># )||character-variant( <feature-value-name># )||swash( <feature-value-name> )||ornaments( <feature-value-name> )||annotation( <feature-value-name> )||[small-caps|all-small-caps|petite-caps|all-petite-caps|unicase|titling-caps]||<numeric-figure-values>||<numeric-spacing-values>||<numeric-fraction-values>||ordinal||slashed-zero||<east-asian-variant-values>||<east-asian-width-values>||ruby]",
  7446. "font-variant-alternates": "normal|[stylistic( <feature-value-name> )||historical-forms||styleset( <feature-value-name># )||character-variant( <feature-value-name># )||swash( <feature-value-name> )||ornaments( <feature-value-name> )||annotation( <feature-value-name> )]",
  7447. "font-variant-caps": "normal|small-caps|all-small-caps|petite-caps|all-petite-caps|unicase|titling-caps",
  7448. "font-variant-east-asian": "normal|[<east-asian-variant-values>||<east-asian-width-values>||ruby]",
  7449. "font-variant-ligatures": "normal|none|[<common-lig-values>||<discretionary-lig-values>||<historical-lig-values>||<contextual-alt-values>]",
  7450. "font-variant-numeric": "normal|[<numeric-figure-values>||<numeric-spacing-values>||<numeric-fraction-values>||ordinal||slashed-zero]",
  7451. "font-variant-position": "normal|sub|super",
  7452. "font-weight": "<font-weight-absolute>|bolder|lighter",
  7453. gap: "<'row-gap'> <'column-gap'>?",
  7454. grid: "<'grid-template'>|<'grid-template-rows'> / [auto-flow&&dense?] <'grid-auto-columns'>?|[auto-flow&&dense?] <'grid-auto-rows'>? / <'grid-template-columns'>",
  7455. "grid-area": "<grid-line> [/ <grid-line>]{0,3}",
  7456. "grid-auto-columns": "<track-size>+",
  7457. "grid-auto-flow": "[row|column]||dense",
  7458. "grid-auto-rows": "<track-size>+",
  7459. "grid-column": "<grid-line> [/ <grid-line>]?",
  7460. "grid-column-end": "<grid-line>",
  7461. "grid-column-gap": "<length-percentage>",
  7462. "grid-column-start": "<grid-line>",
  7463. "grid-gap": "<'grid-row-gap'> <'grid-column-gap'>?",
  7464. "grid-row": "<grid-line> [/ <grid-line>]?",
  7465. "grid-row-end": "<grid-line>",
  7466. "grid-row-gap": "<length-percentage>",
  7467. "grid-row-start": "<grid-line>",
  7468. "grid-template": "none|[<'grid-template-rows'> / <'grid-template-columns'>]|[<line-names>? <string> <track-size>? <line-names>?]+ [/ <explicit-track-list>]?",
  7469. "grid-template-areas": "none|<string>+",
  7470. "grid-template-columns": "none|<track-list>|<auto-track-list>",
  7471. "grid-template-rows": "none|<track-list>|<auto-track-list>",
  7472. "hanging-punctuation": "none|[first||[force-end|allow-end]||last]",
  7473. height: "[<length>|<percentage>]&&[border-box|content-box]?|available|min-content|max-content|fit-content|auto",
  7474. hyphens: "none|manual|auto",
  7475. "image-orientation": "from-image|<angle>|[<angle>? flip]",
  7476. "image-rendering": "auto|crisp-edges|pixelated|optimizeSpeed|optimizeQuality|<-non-standard-image-rendering>",
  7477. "image-resolution": "[from-image||<resolution>]&&snap?",
  7478. "ime-mode": "auto|normal|active|inactive|disabled",
  7479. "initial-letter": "normal|[<number> <integer>?]",
  7480. "initial-letter-align": "[auto|alphabetic|hanging|ideographic]",
  7481. "inline-size": "<'width'>",
  7482. inset: "<'top'>{1,4}",
  7483. "inset-block": "<'top'>{1,2}",
  7484. "inset-block-end": "<'top'>",
  7485. "inset-block-start": "<'top'>",
  7486. "inset-inline": "<'top'>{1,2}",
  7487. "inset-inline-end": "<'top'>",
  7488. "inset-inline-start": "<'top'>",
  7489. isolation: "auto|isolate",
  7490. "justify-content": "normal|<content-distribution>|<overflow-position>? [<content-position>|left|right]",
  7491. "justify-items": "normal|stretch|<baseline-position>|<overflow-position>? [<self-position>|left|right]|legacy|legacy&&[left|right|center]",
  7492. "justify-self": "auto|normal|stretch|<baseline-position>|<overflow-position>? [<self-position>|left|right]",
  7493. left: "<length>|<percentage>|auto",
  7494. "letter-spacing": "normal|<length-percentage>",
  7495. "line-break": "auto|loose|normal|strict",
  7496. "line-clamp": "none|<integer>",
  7497. "line-height": "normal|<number>|<length>|<percentage>",
  7498. "line-height-step": "<length>",
  7499. "list-style": "<'list-style-type'>||<'list-style-position'>||<'list-style-image'>",
  7500. "list-style-image": "<url>|none",
  7501. "list-style-position": "inside|outside",
  7502. "list-style-type": "<counter-style>|<string>|none",
  7503. margin: "[<length>|<percentage>|auto]{1,4}",
  7504. "margin-block": "<'margin-left'>{1,2}",
  7505. "margin-block-end": "<'margin-left'>",
  7506. "margin-block-start": "<'margin-left'>",
  7507. "margin-bottom": "<length>|<percentage>|auto",
  7508. "margin-inline": "<'margin-left'>{1,2}",
  7509. "margin-inline-end": "<'margin-left'>",
  7510. "margin-inline-start": "<'margin-left'>",
  7511. "margin-left": "<length>|<percentage>|auto",
  7512. "margin-right": "<length>|<percentage>|auto",
  7513. "margin-top": "<length>|<percentage>|auto",
  7514. mask: "<mask-layer>#",
  7515. "mask-border": "<'mask-border-source'>||<'mask-border-slice'> [/ <'mask-border-width'>? [/ <'mask-border-outset'>]?]?||<'mask-border-repeat'>||<'mask-border-mode'>",
  7516. "mask-border-mode": "luminance|alpha",
  7517. "mask-border-outset": "[<length>|<number>]{1,4}",
  7518. "mask-border-repeat": "[stretch|repeat|round|space]{1,2}",
  7519. "mask-border-slice": "<number-percentage>{1,4} fill?",
  7520. "mask-border-source": "none|<image>",
  7521. "mask-border-width": "[<length-percentage>|<number>|auto]{1,4}",
  7522. "mask-clip": "[<geometry-box>|no-clip]#",
  7523. "mask-composite": "<compositing-operator>#",
  7524. "mask-image": "<mask-reference>#",
  7525. "mask-mode": "<masking-mode>#",
  7526. "mask-origin": "<geometry-box>#",
  7527. "mask-position": "<position>#",
  7528. "mask-repeat": "<repeat-style>#",
  7529. "mask-size": "<bg-size>#",
  7530. "mask-type": "luminance|alpha",
  7531. "max-block-size": "<'max-width'>",
  7532. "max-height": "<length>|<percentage>|none|max-content|min-content|fit-content|fill-available",
  7533. "max-inline-size": "<'max-width'>",
  7534. "max-lines": "none|<integer>",
  7535. "max-width": "<length>|<percentage>|none|max-content|min-content|fit-content|fill-available|<-non-standard-width>",
  7536. "min-block-size": "<'min-width'>",
  7537. "min-height": "<length>|<percentage>|auto|max-content|min-content|fit-content|fill-available",
  7538. "min-inline-size": "<'min-width'>",
  7539. "min-width": "<length>|<percentage>|auto|max-content|min-content|fit-content|fill-available|<-non-standard-width>",
  7540. "mix-blend-mode": "<blend-mode>",
  7541. "object-fit": "fill|contain|cover|none|scale-down",
  7542. "object-position": "<position>",
  7543. offset: "[<'offset-position'>? [<'offset-path'> [<'offset-distance'>||<'offset-rotate'>]?]?]! [/ <'offset-anchor'>]?",
  7544. "offset-anchor": "auto|<position>",
  7545. "offset-distance": "<length-percentage>",
  7546. "offset-path": "none|ray( [<angle>&&<size>?&&contain?] )|<path()>|<url>|[<basic-shape>||<geometry-box>]",
  7547. "offset-position": "auto|<position>",
  7548. "offset-rotate": "[auto|reverse]||<angle>",
  7549. opacity: "<number-zero-one>",
  7550. order: "<integer>",
  7551. orphans: "<integer>",
  7552. outline: "[<'outline-color'>||<'outline-style'>||<'outline-width'>]",
  7553. "outline-color": "<color>|invert",
  7554. "outline-offset": "<length>",
  7555. "outline-style": "auto|<'border-style'>",
  7556. "outline-width": "<line-width>",
  7557. overflow: "[visible|hidden|clip|scroll|auto]{1,2}|<-non-standard-overflow>",
  7558. "overflow-anchor": "auto|none",
  7559. "overflow-block": "visible|hidden|clip|scroll|auto",
  7560. "overflow-clip-box": "padding-box|content-box",
  7561. "overflow-inline": "visible|hidden|clip|scroll|auto",
  7562. "overflow-wrap": "normal|break-word|anywhere",
  7563. "overflow-x": "visible|hidden|clip|scroll|auto",
  7564. "overflow-y": "visible|hidden|clip|scroll|auto",
  7565. "overscroll-behavior": "[contain|none|auto]{1,2}",
  7566. "overscroll-behavior-x": "contain|none|auto",
  7567. "overscroll-behavior-y": "contain|none|auto",
  7568. padding: "[<length>|<percentage>]{1,4}",
  7569. "padding-block": "<'padding-left'>{1,2}",
  7570. "padding-block-end": "<'padding-left'>",
  7571. "padding-block-start": "<'padding-left'>",
  7572. "padding-bottom": "<length>|<percentage>",
  7573. "padding-inline": "<'padding-left'>{1,2}",
  7574. "padding-inline-end": "<'padding-left'>",
  7575. "padding-inline-start": "<'padding-left'>",
  7576. "padding-left": "<length>|<percentage>",
  7577. "padding-right": "<length>|<percentage>",
  7578. "padding-top": "<length>|<percentage>",
  7579. "page-break-after": "auto|always|avoid|left|right|recto|verso",
  7580. "page-break-before": "auto|always|avoid|left|right|recto|verso",
  7581. "page-break-inside": "auto|avoid",
  7582. "paint-order": "normal|[fill||stroke||markers]",
  7583. perspective: "none|<length>",
  7584. "perspective-origin": "<position>",
  7585. "place-content": "<'align-content'> <'justify-content'>?",
  7586. "place-items": "<'align-items'> <'justify-items'>?",
  7587. "place-self": "<'align-self'> <'justify-self'>?",
  7588. "pointer-events": "auto|none|visiblePainted|visibleFill|visibleStroke|visible|painted|fill|stroke|all|inherit",
  7589. position: "static|relative|absolute|sticky|fixed|-webkit-sticky",
  7590. quotes: "none|[<string> <string>]+",
  7591. resize: "none|both|horizontal|vertical|block|inline",
  7592. right: "<length>|<percentage>|auto",
  7593. rotate: "none|<angle>|[x|y|z|<number>{3}]&&<angle>",
  7594. "row-gap": "normal|<length-percentage>",
  7595. "ruby-align": "start|center|space-between|space-around",
  7596. "ruby-merge": "separate|collapse|auto",
  7597. "ruby-position": "over|under|inter-character",
  7598. scale: "none|<number>{1,3}",
  7599. "scrollbar-color": "auto|dark|light|<color>{2}",
  7600. "scrollbar-width": "auto|thin|none",
  7601. "scroll-behavior": "auto|smooth",
  7602. "scroll-margin": "<length>{1,4}",
  7603. "scroll-margin-block": "<length>{1,2}",
  7604. "scroll-margin-block-start": "<length>",
  7605. "scroll-margin-block-end": "<length>",
  7606. "scroll-margin-bottom": "<length>",
  7607. "scroll-margin-inline": "<length>{1,2}",
  7608. "scroll-margin-inline-start": "<length>",
  7609. "scroll-margin-inline-end": "<length>",
  7610. "scroll-margin-left": "<length>",
  7611. "scroll-margin-right": "<length>",
  7612. "scroll-margin-top": "<length>",
  7613. "scroll-padding": "[auto|<length-percentage>]{1,4}",
  7614. "scroll-padding-block": "[auto|<length-percentage>]{1,2}",
  7615. "scroll-padding-block-start": "auto|<length-percentage>",
  7616. "scroll-padding-block-end": "auto|<length-percentage>",
  7617. "scroll-padding-bottom": "auto|<length-percentage>",
  7618. "scroll-padding-inline": "[auto|<length-percentage>]{1,2}",
  7619. "scroll-padding-inline-start": "auto|<length-percentage>",
  7620. "scroll-padding-inline-end": "auto|<length-percentage>",
  7621. "scroll-padding-left": "auto|<length-percentage>",
  7622. "scroll-padding-right": "auto|<length-percentage>",
  7623. "scroll-padding-top": "auto|<length-percentage>",
  7624. "scroll-snap-align": "[none|start|end|center]{1,2}",
  7625. "scroll-snap-coordinate": "none|<position>#",
  7626. "scroll-snap-destination": "<position>",
  7627. "scroll-snap-points-x": "none|repeat( <length-percentage> )",
  7628. "scroll-snap-points-y": "none|repeat( <length-percentage> )",
  7629. "scroll-snap-stop": "normal|always",
  7630. "scroll-snap-type": "none|[x|y|block|inline|both] [mandatory|proximity]?",
  7631. "scroll-snap-type-x": "none|mandatory|proximity",
  7632. "scroll-snap-type-y": "none|mandatory|proximity",
  7633. "shape-image-threshold": "<number>",
  7634. "shape-margin": "<length-percentage>",
  7635. "shape-outside": "none|<shape-box>||<basic-shape>|<image>",
  7636. "tab-size": "<integer>|<length>",
  7637. "table-layout": "auto|fixed",
  7638. "text-align": "start|end|left|right|center|justify|match-parent",
  7639. "text-align-last": "auto|start|end|left|right|center|justify",
  7640. "text-combine-upright": "none|all|[digits <integer>?]",
  7641. "text-decoration": "<'text-decoration-line'>||<'text-decoration-style'>||<'text-decoration-color'>",
  7642. "text-decoration-color": "<color>",
  7643. "text-decoration-line": "none|[underline||overline||line-through||blink]",
  7644. "text-decoration-skip": "none|[objects||[spaces|[leading-spaces||trailing-spaces]]||edges||box-decoration]",
  7645. "text-decoration-skip-ink": "auto|none",
  7646. "text-decoration-style": "solid|double|dotted|dashed|wavy",
  7647. "text-emphasis": "<'text-emphasis-style'>||<'text-emphasis-color'>",
  7648. "text-emphasis-color": "<color>",
  7649. "text-emphasis-position": "[over|under]&&[right|left]",
  7650. "text-emphasis-style": "none|[[filled|open]||[dot|circle|double-circle|triangle|sesame]]|<string>",
  7651. "text-indent": "<length-percentage>&&hanging?&&each-line?",
  7652. "text-justify": "auto|inter-character|inter-word|none",
  7653. "text-orientation": "mixed|upright|sideways",
  7654. "text-overflow": "[clip|ellipsis|<string>]{1,2}",
  7655. "text-rendering": "auto|optimizeSpeed|optimizeLegibility|geometricPrecision",
  7656. "text-shadow": "none|<shadow-t>#",
  7657. "text-size-adjust": "none|auto|<percentage>",
  7658. "text-transform": "none|capitalize|uppercase|lowercase|full-width|full-size-kana",
  7659. "text-underline-position": "auto|[under||[left|right]]",
  7660. top: "<length>|<percentage>|auto",
  7661. "touch-action": "auto|none|[[pan-x|pan-left|pan-right]||[pan-y|pan-up|pan-down]||pinch-zoom]|manipulation",
  7662. transform: "none|<transform-list>",
  7663. "transform-box": "border-box|fill-box|view-box",
  7664. "transform-origin": "[<length-percentage>|left|center|right|top|bottom]|[[<length-percentage>|left|center|right]&&[<length-percentage>|top|center|bottom]] <length>?",
  7665. "transform-style": "flat|preserve-3d",
  7666. transition: "<single-transition>#",
  7667. "transition-delay": "<time>#",
  7668. "transition-duration": "<time>#",
  7669. "transition-property": "none|<single-transition-property>#",
  7670. "transition-timing-function": "<timing-function>#",
  7671. translate: "none|<length-percentage> [<length-percentage> <length>?]?",
  7672. "unicode-bidi": "normal|embed|isolate|bidi-override|isolate-override|plaintext|-moz-isolate|-moz-isolate-override|-moz-plaintext|-webkit-isolate",
  7673. "user-select": "auto|text|none|contain|all",
  7674. "vertical-align": "baseline|sub|super|text-top|text-bottom|middle|top|bottom|<percentage>|<length>",
  7675. visibility: "visible|hidden|collapse",
  7676. "white-space": "normal|pre|nowrap|pre-wrap|pre-line",
  7677. widows: "<integer>",
  7678. width: "[<length>|<percentage>]&&[border-box|content-box]?|available|min-content|max-content|fit-content|auto",
  7679. "will-change": "auto|<animateable-feature>#",
  7680. "word-break": "normal|break-all|keep-all|break-word",
  7681. "word-spacing": "normal|<length-percentage>",
  7682. "word-wrap": "normal|break-word",
  7683. "writing-mode": "horizontal-tb|vertical-rl|vertical-lr|sideways-rl|sideways-lr|<svg-writing-mode>",
  7684. "z-index": "auto|<integer>",
  7685. zoom: "normal|reset|<number>|<percentage>",
  7686. "-moz-background-clip": "padding|border",
  7687. "-moz-border-radius-bottomleft": "<'border-bottom-left-radius'>",
  7688. "-moz-border-radius-bottomright": "<'border-bottom-right-radius'>",
  7689. "-moz-border-radius-topleft": "<'border-top-left-radius'>",
  7690. "-moz-border-radius-topright": "<'border-bottom-right-radius'>",
  7691. "-moz-control-character-visibility": "visible|hidden",
  7692. "-moz-osx-font-smoothing": "auto|grayscale",
  7693. "-moz-user-select": "none|text|all|-moz-none",
  7694. "-ms-flex-align": "start|end|center|baseline|stretch",
  7695. "-ms-flex-item-align": "auto|start|end|center|baseline|stretch",
  7696. "-ms-flex-line-pack": "start|end|center|justify|distribute|stretch",
  7697. "-ms-flex-negative": "<'flex-shrink'>",
  7698. "-ms-flex-pack": "start|end|center|justify|distribute",
  7699. "-ms-flex-order": "<integer>",
  7700. "-ms-flex-positive": "<'flex-grow'>",
  7701. "-ms-flex-preferred-size": "<'flex-basis'>",
  7702. "-ms-interpolation-mode": "nearest-neighbor|bicubic",
  7703. "-ms-grid-column-align": "start|end|center|stretch",
  7704. "-ms-grid-columns": "<track-list-v0>",
  7705. "-ms-grid-row-align": "start|end|center|stretch",
  7706. "-ms-grid-rows": "<track-list-v0>",
  7707. "-ms-hyphenate-limit-last": "none|always|column|page|spread",
  7708. "-webkit-background-clip": "[<box>|border|padding|content|text]#",
  7709. "-webkit-column-break-after": "always|auto|avoid",
  7710. "-webkit-column-break-before": "always|auto|avoid",
  7711. "-webkit-column-break-inside": "always|auto|avoid",
  7712. "-webkit-font-smoothing": "auto|none|antialiased|subpixel-antialiased",
  7713. "-webkit-mask-box-image": "[<url>|<gradient>|none] [<length-percentage>{4} <-webkit-mask-box-repeat>{2}]?",
  7714. "-webkit-print-color-adjust": "economy|exact",
  7715. "-webkit-text-security": "none|circle|disc|square",
  7716. "-webkit-user-drag": "none|element|auto",
  7717. "-webkit-user-select": "auto|none|text|all",
  7718. "alignment-baseline": "auto|baseline|before-edge|text-before-edge|middle|central|after-edge|text-after-edge|ideographic|alphabetic|hanging|mathematical",
  7719. "baseline-shift": "baseline|sub|super|<svg-length>",
  7720. behavior: "<url>+",
  7721. "clip-rule": "nonzero|evenodd",
  7722. cue: "<'cue-before'> <'cue-after'>?",
  7723. "cue-after": "<url> <decibel>?|none",
  7724. "cue-before": "<url> <decibel>?|none",
  7725. "dominant-baseline": "auto|use-script|no-change|reset-size|ideographic|alphabetic|hanging|mathematical|central|middle|text-after-edge|text-before-edge",
  7726. fill: "<paint>",
  7727. "fill-opacity": "<number-zero-one>",
  7728. "fill-rule": "nonzero|evenodd",
  7729. "glyph-orientation-horizontal": "<angle>",
  7730. "glyph-orientation-vertical": "<angle>",
  7731. kerning: "auto|<svg-length>",
  7732. marker: "none|<url>",
  7733. "marker-end": "none|<url>",
  7734. "marker-mid": "none|<url>",
  7735. "marker-start": "none|<url>",
  7736. pause: "<'pause-before'> <'pause-after'>?",
  7737. "pause-after": "<time>|none|x-weak|weak|medium|strong|x-strong",
  7738. "pause-before": "<time>|none|x-weak|weak|medium|strong|x-strong",
  7739. rest: "<'rest-before'> <'rest-after'>?",
  7740. "rest-after": "<time>|none|x-weak|weak|medium|strong|x-strong",
  7741. "rest-before": "<time>|none|x-weak|weak|medium|strong|x-strong",
  7742. "shape-rendering": "auto|optimizeSpeed|crispEdges|geometricPrecision",
  7743. src: "[<url> [format( <string># )]?|local( <family-name> )]#",
  7744. speak: "auto|none|normal",
  7745. "speak-as": "normal|spell-out||digits||[literal-punctuation|no-punctuation]",
  7746. stroke: "<paint>",
  7747. "stroke-dasharray": "none|[<svg-length>+]#",
  7748. "stroke-dashoffset": "<svg-length>",
  7749. "stroke-linecap": "butt|round|square",
  7750. "stroke-linejoin": "miter|round|bevel",
  7751. "stroke-miterlimit": "<number-one-or-greater>",
  7752. "stroke-opacity": "<number-zero-one>",
  7753. "stroke-width": "<svg-length>",
  7754. "text-anchor": "start|middle|end",
  7755. "unicode-range": "<urange>#",
  7756. "voice-balance": "<number>|left|center|right|leftwards|rightwards",
  7757. "voice-duration": "auto|<time>",
  7758. "voice-family": "[[<family-name>|<generic-voice>] ,]* [<family-name>|<generic-voice>]|preserve",
  7759. "voice-pitch": "<frequency>&&absolute|[[x-low|low|medium|high|x-high]||[<frequency>|<semitones>|<percentage>]]",
  7760. "voice-range": "<frequency>&&absolute|[[x-low|low|medium|high|x-high]||[<frequency>|<semitones>|<percentage>]]",
  7761. "voice-rate": "[normal|x-slow|slow|medium|fast|x-fast]||<percentage>",
  7762. "voice-stress": "normal|strong|moderate|none|reduced",
  7763. "voice-volume": "silent|[[x-soft|soft|medium|loud|x-loud]||<decibel>]"
  7764. };
  7765. var defaultSyntax = {
  7766. generic: generic$1,
  7767. types: types,
  7768. properties: properties$1
  7769. };
  7770. var defaultSyntax$1 = /*#__PURE__*/Object.freeze({
  7771. __proto__: null,
  7772. generic: generic$1,
  7773. types: types,
  7774. properties: properties$1,
  7775. 'default': defaultSyntax
  7776. });
  7777. var cmpChar$3 = tokenizer.cmpChar;
  7778. var isDigit$4 = tokenizer.isDigit;
  7779. var TYPE$9 = tokenizer.TYPE;
  7780. var WHITESPACE$4 = TYPE$9.WhiteSpace;
  7781. var COMMENT$3 = TYPE$9.Comment;
  7782. var IDENT$3 = TYPE$9.Ident;
  7783. var NUMBER$3 = TYPE$9.Number;
  7784. var DIMENSION$2 = TYPE$9.Dimension;
  7785. var PLUSSIGN$3 = 0x002B; // U+002B PLUS SIGN (+)
  7786. var HYPHENMINUS$3 = 0x002D; // U+002D HYPHEN-MINUS (-)
  7787. var N$4 = 0x006E; // U+006E LATIN SMALL LETTER N (n)
  7788. var DISALLOW_SIGN$1 = true;
  7789. var ALLOW_SIGN$1 = false;
  7790. function checkInteger$1(offset, disallowSign) {
  7791. var pos = this.scanner.tokenStart + offset;
  7792. var code = this.scanner.source.charCodeAt(pos);
  7793. if (code === PLUSSIGN$3 || code === HYPHENMINUS$3) {
  7794. if (disallowSign) {
  7795. this.error('Number sign is not allowed');
  7796. }
  7797. pos++;
  7798. }
  7799. for (; pos < this.scanner.tokenEnd; pos++) {
  7800. if (!isDigit$4(this.scanner.source.charCodeAt(pos))) {
  7801. this.error('Integer is expected', pos);
  7802. }
  7803. }
  7804. }
  7805. function checkTokenIsInteger(disallowSign) {
  7806. return checkInteger$1.call(this, 0, disallowSign);
  7807. }
  7808. function expectCharCode(offset, code) {
  7809. if (!cmpChar$3(this.scanner.source, this.scanner.tokenStart + offset, code)) {
  7810. var msg = '';
  7811. switch (code) {
  7812. case N$4:
  7813. msg = 'N is expected';
  7814. break;
  7815. case HYPHENMINUS$3:
  7816. msg = 'HyphenMinus is expected';
  7817. break;
  7818. }
  7819. this.error(msg, this.scanner.tokenStart + offset);
  7820. }
  7821. }
  7822. // ... <signed-integer>
  7823. // ... ['+' | '-'] <signless-integer>
  7824. function consumeB$1() {
  7825. var offset = 0;
  7826. var sign = 0;
  7827. var type = this.scanner.tokenType;
  7828. while (type === WHITESPACE$4 || type === COMMENT$3) {
  7829. type = this.scanner.lookupType(++offset);
  7830. }
  7831. if (type !== NUMBER$3) {
  7832. if (this.scanner.isDelim(PLUSSIGN$3, offset) ||
  7833. this.scanner.isDelim(HYPHENMINUS$3, offset)) {
  7834. sign = this.scanner.isDelim(PLUSSIGN$3, offset) ? PLUSSIGN$3 : HYPHENMINUS$3;
  7835. do {
  7836. type = this.scanner.lookupType(++offset);
  7837. } while (type === WHITESPACE$4 || type === COMMENT$3);
  7838. if (type !== NUMBER$3) {
  7839. this.scanner.skip(offset);
  7840. checkTokenIsInteger.call(this, DISALLOW_SIGN$1);
  7841. }
  7842. } else {
  7843. return null;
  7844. }
  7845. }
  7846. if (offset > 0) {
  7847. this.scanner.skip(offset);
  7848. }
  7849. if (sign === 0) {
  7850. type = this.scanner.source.charCodeAt(this.scanner.tokenStart);
  7851. if (type !== PLUSSIGN$3 && type !== HYPHENMINUS$3) {
  7852. this.error('Number sign is expected');
  7853. }
  7854. }
  7855. checkTokenIsInteger.call(this, sign !== 0);
  7856. return sign === HYPHENMINUS$3 ? '-' + this.consume(NUMBER$3) : this.consume(NUMBER$3);
  7857. }
  7858. // An+B microsyntax https://www.w3.org/TR/css-syntax-3/#anb
  7859. var AnPlusB = {
  7860. name: 'AnPlusB',
  7861. structure: {
  7862. a: [String, null],
  7863. b: [String, null]
  7864. },
  7865. parse: function() {
  7866. /* eslint-disable brace-style*/
  7867. var start = this.scanner.tokenStart;
  7868. var a = null;
  7869. var b = null;
  7870. // <integer>
  7871. if (this.scanner.tokenType === NUMBER$3) {
  7872. checkTokenIsInteger.call(this, ALLOW_SIGN$1);
  7873. b = this.consume(NUMBER$3);
  7874. }
  7875. // -n
  7876. // -n <signed-integer>
  7877. // -n ['+' | '-'] <signless-integer>
  7878. // -n- <signless-integer>
  7879. // <dashndashdigit-ident>
  7880. else if (this.scanner.tokenType === IDENT$3 && cmpChar$3(this.scanner.source, this.scanner.tokenStart, HYPHENMINUS$3)) {
  7881. a = '-1';
  7882. expectCharCode.call(this, 1, N$4);
  7883. switch (this.scanner.getTokenLength()) {
  7884. // -n
  7885. // -n <signed-integer>
  7886. // -n ['+' | '-'] <signless-integer>
  7887. case 2:
  7888. this.scanner.next();
  7889. b = consumeB$1.call(this);
  7890. break;
  7891. // -n- <signless-integer>
  7892. case 3:
  7893. expectCharCode.call(this, 2, HYPHENMINUS$3);
  7894. this.scanner.next();
  7895. this.scanner.skipSC();
  7896. checkTokenIsInteger.call(this, DISALLOW_SIGN$1);
  7897. b = '-' + this.consume(NUMBER$3);
  7898. break;
  7899. // <dashndashdigit-ident>
  7900. default:
  7901. expectCharCode.call(this, 2, HYPHENMINUS$3);
  7902. checkInteger$1.call(this, 3, DISALLOW_SIGN$1);
  7903. this.scanner.next();
  7904. b = this.scanner.substrToCursor(start + 2);
  7905. }
  7906. }
  7907. // '+'? n
  7908. // '+'? n <signed-integer>
  7909. // '+'? n ['+' | '-'] <signless-integer>
  7910. // '+'? n- <signless-integer>
  7911. // '+'? <ndashdigit-ident>
  7912. else if (this.scanner.tokenType === IDENT$3 || (this.scanner.isDelim(PLUSSIGN$3) && this.scanner.lookupType(1) === IDENT$3)) {
  7913. var sign = 0;
  7914. a = '1';
  7915. // just ignore a plus
  7916. if (this.scanner.isDelim(PLUSSIGN$3)) {
  7917. sign = 1;
  7918. this.scanner.next();
  7919. }
  7920. expectCharCode.call(this, 0, N$4);
  7921. switch (this.scanner.getTokenLength()) {
  7922. // '+'? n
  7923. // '+'? n <signed-integer>
  7924. // '+'? n ['+' | '-'] <signless-integer>
  7925. case 1:
  7926. this.scanner.next();
  7927. b = consumeB$1.call(this);
  7928. break;
  7929. // '+'? n- <signless-integer>
  7930. case 2:
  7931. expectCharCode.call(this, 1, HYPHENMINUS$3);
  7932. this.scanner.next();
  7933. this.scanner.skipSC();
  7934. checkTokenIsInteger.call(this, DISALLOW_SIGN$1);
  7935. b = '-' + this.consume(NUMBER$3);
  7936. break;
  7937. // '+'? <ndashdigit-ident>
  7938. default:
  7939. expectCharCode.call(this, 1, HYPHENMINUS$3);
  7940. checkInteger$1.call(this, 2, DISALLOW_SIGN$1);
  7941. this.scanner.next();
  7942. b = this.scanner.substrToCursor(start + sign + 1);
  7943. }
  7944. }
  7945. // <ndashdigit-dimension>
  7946. // <ndash-dimension> <signless-integer>
  7947. // <n-dimension>
  7948. // <n-dimension> <signed-integer>
  7949. // <n-dimension> ['+' | '-'] <signless-integer>
  7950. else if (this.scanner.tokenType === DIMENSION$2) {
  7951. var code = this.scanner.source.charCodeAt(this.scanner.tokenStart);
  7952. var sign = code === PLUSSIGN$3 || code === HYPHENMINUS$3;
  7953. for (var i = this.scanner.tokenStart + sign; i < this.scanner.tokenEnd; i++) {
  7954. if (!isDigit$4(this.scanner.source.charCodeAt(i))) {
  7955. break;
  7956. }
  7957. }
  7958. if (i === this.scanner.tokenStart + sign) {
  7959. this.error('Integer is expected', this.scanner.tokenStart + sign);
  7960. }
  7961. expectCharCode.call(this, i - this.scanner.tokenStart, N$4);
  7962. a = this.scanner.source.substring(start, i);
  7963. // <n-dimension>
  7964. // <n-dimension> <signed-integer>
  7965. // <n-dimension> ['+' | '-'] <signless-integer>
  7966. if (i + 1 === this.scanner.tokenEnd) {
  7967. this.scanner.next();
  7968. b = consumeB$1.call(this);
  7969. } else {
  7970. expectCharCode.call(this, i - this.scanner.tokenStart + 1, HYPHENMINUS$3);
  7971. // <ndash-dimension> <signless-integer>
  7972. if (i + 2 === this.scanner.tokenEnd) {
  7973. this.scanner.next();
  7974. this.scanner.skipSC();
  7975. checkTokenIsInteger.call(this, DISALLOW_SIGN$1);
  7976. b = '-' + this.consume(NUMBER$3);
  7977. }
  7978. // <ndashdigit-dimension>
  7979. else {
  7980. checkInteger$1.call(this, i - this.scanner.tokenStart + 2, DISALLOW_SIGN$1);
  7981. this.scanner.next();
  7982. b = this.scanner.substrToCursor(i + 1);
  7983. }
  7984. }
  7985. } else {
  7986. this.error();
  7987. }
  7988. if (a !== null && a.charCodeAt(0) === PLUSSIGN$3) {
  7989. a = a.substr(1);
  7990. }
  7991. if (b !== null && b.charCodeAt(0) === PLUSSIGN$3) {
  7992. b = b.substr(1);
  7993. }
  7994. return {
  7995. type: 'AnPlusB',
  7996. loc: this.getLocation(start, this.scanner.tokenStart),
  7997. a: a,
  7998. b: b
  7999. };
  8000. },
  8001. generate: function(node) {
  8002. var a = node.a !== null && node.a !== undefined;
  8003. var b = node.b !== null && node.b !== undefined;
  8004. if (a) {
  8005. this.chunk(
  8006. node.a === '+1' ? '+n' : // eslint-disable-line operator-linebreak, indent
  8007. node.a === '1' ? 'n' : // eslint-disable-line operator-linebreak, indent
  8008. node.a === '-1' ? '-n' : // eslint-disable-line operator-linebreak, indent
  8009. node.a + 'n' // eslint-disable-line operator-linebreak, indent
  8010. );
  8011. if (b) {
  8012. b = String(node.b);
  8013. if (b.charAt(0) === '-' || b.charAt(0) === '+') {
  8014. this.chunk(b.charAt(0));
  8015. this.chunk(b.substr(1));
  8016. } else {
  8017. this.chunk('+');
  8018. this.chunk(b);
  8019. }
  8020. }
  8021. } else {
  8022. this.chunk(String(node.b));
  8023. }
  8024. }
  8025. };
  8026. var TYPE$a = tokenizer.TYPE;
  8027. var WhiteSpace = TYPE$a.WhiteSpace;
  8028. var Semicolon = TYPE$a.Semicolon;
  8029. var LeftCurlyBracket = TYPE$a.LeftCurlyBracket;
  8030. var Delim = TYPE$a.Delim;
  8031. var EXCLAMATIONMARK$1 = 0x0021; // U+0021 EXCLAMATION MARK (!)
  8032. function getOffsetExcludeWS() {
  8033. if (this.scanner.tokenIndex > 0) {
  8034. if (this.scanner.lookupType(-1) === WhiteSpace) {
  8035. return this.scanner.tokenIndex > 1
  8036. ? this.scanner.getTokenStart(this.scanner.tokenIndex - 1)
  8037. : this.scanner.firstCharOffset;
  8038. }
  8039. }
  8040. return this.scanner.tokenStart;
  8041. }
  8042. // 0, 0, false
  8043. function balanceEnd() {
  8044. return 0;
  8045. }
  8046. // LEFTCURLYBRACKET, 0, false
  8047. function leftCurlyBracket(tokenType) {
  8048. return tokenType === LeftCurlyBracket ? 1 : 0;
  8049. }
  8050. // LEFTCURLYBRACKET, SEMICOLON, false
  8051. function leftCurlyBracketOrSemicolon(tokenType) {
  8052. return tokenType === LeftCurlyBracket || tokenType === Semicolon ? 1 : 0;
  8053. }
  8054. // EXCLAMATIONMARK, SEMICOLON, false
  8055. function exclamationMarkOrSemicolon(tokenType, source, offset) {
  8056. if (tokenType === Delim && source.charCodeAt(offset) === EXCLAMATIONMARK$1) {
  8057. return 1;
  8058. }
  8059. return tokenType === Semicolon ? 1 : 0;
  8060. }
  8061. // 0, SEMICOLON, true
  8062. function semicolonIncluded(tokenType) {
  8063. return tokenType === Semicolon ? 2 : 0;
  8064. }
  8065. var Raw = {
  8066. name: 'Raw',
  8067. structure: {
  8068. value: String
  8069. },
  8070. parse: function(startToken, mode, excludeWhiteSpace) {
  8071. var startOffset = this.scanner.getTokenStart(startToken);
  8072. var endOffset;
  8073. this.scanner.skip(
  8074. this.scanner.getRawLength(startToken, mode || balanceEnd)
  8075. );
  8076. if (excludeWhiteSpace && this.scanner.tokenStart > startOffset) {
  8077. endOffset = getOffsetExcludeWS.call(this);
  8078. } else {
  8079. endOffset = this.scanner.tokenStart;
  8080. }
  8081. return {
  8082. type: 'Raw',
  8083. loc: this.getLocation(startOffset, endOffset),
  8084. value: this.scanner.source.substring(startOffset, endOffset)
  8085. };
  8086. },
  8087. generate: function(node) {
  8088. this.chunk(node.value);
  8089. },
  8090. mode: {
  8091. default: balanceEnd,
  8092. leftCurlyBracket: leftCurlyBracket,
  8093. leftCurlyBracketOrSemicolon: leftCurlyBracketOrSemicolon,
  8094. exclamationMarkOrSemicolon: exclamationMarkOrSemicolon,
  8095. semicolonIncluded: semicolonIncluded
  8096. }
  8097. };
  8098. var TYPE$b = tokenizer.TYPE;
  8099. var rawMode = Raw.mode;
  8100. var ATKEYWORD = TYPE$b.AtKeyword;
  8101. var SEMICOLON = TYPE$b.Semicolon;
  8102. var LEFTCURLYBRACKET$1 = TYPE$b.LeftCurlyBracket;
  8103. var RIGHTCURLYBRACKET$1 = TYPE$b.RightCurlyBracket;
  8104. function consumeRaw(startToken) {
  8105. return this.Raw(startToken, rawMode.leftCurlyBracketOrSemicolon, true);
  8106. }
  8107. function isDeclarationBlockAtrule() {
  8108. for (var offset = 1, type; type = this.scanner.lookupType(offset); offset++) {
  8109. if (type === RIGHTCURLYBRACKET$1) {
  8110. return true;
  8111. }
  8112. if (type === LEFTCURLYBRACKET$1 ||
  8113. type === ATKEYWORD) {
  8114. return false;
  8115. }
  8116. }
  8117. return false;
  8118. }
  8119. var Atrule = {
  8120. name: 'Atrule',
  8121. structure: {
  8122. name: String,
  8123. prelude: ['AtrulePrelude', 'Raw', null],
  8124. block: ['Block', null]
  8125. },
  8126. parse: function() {
  8127. var start = this.scanner.tokenStart;
  8128. var name;
  8129. var nameLowerCase;
  8130. var prelude = null;
  8131. var block = null;
  8132. this.eat(ATKEYWORD);
  8133. name = this.scanner.substrToCursor(start + 1);
  8134. nameLowerCase = name.toLowerCase();
  8135. this.scanner.skipSC();
  8136. // parse prelude
  8137. if (this.scanner.eof === false &&
  8138. this.scanner.tokenType !== LEFTCURLYBRACKET$1 &&
  8139. this.scanner.tokenType !== SEMICOLON) {
  8140. if (this.parseAtrulePrelude) {
  8141. prelude = this.parseWithFallback(this.AtrulePrelude.bind(this, name), consumeRaw);
  8142. // turn empty AtrulePrelude into null
  8143. if (prelude.type === 'AtrulePrelude' && prelude.children.head === null) {
  8144. prelude = null;
  8145. }
  8146. } else {
  8147. prelude = consumeRaw.call(this, this.scanner.tokenIndex);
  8148. }
  8149. this.scanner.skipSC();
  8150. }
  8151. switch (this.scanner.tokenType) {
  8152. case SEMICOLON:
  8153. this.scanner.next();
  8154. break;
  8155. case LEFTCURLYBRACKET$1:
  8156. if (this.atrule.hasOwnProperty(nameLowerCase) &&
  8157. typeof this.atrule[nameLowerCase].block === 'function') {
  8158. block = this.atrule[nameLowerCase].block.call(this);
  8159. } else {
  8160. // TODO: should consume block content as Raw?
  8161. block = this.Block(isDeclarationBlockAtrule.call(this));
  8162. }
  8163. break;
  8164. }
  8165. return {
  8166. type: 'Atrule',
  8167. loc: this.getLocation(start, this.scanner.tokenStart),
  8168. name: name,
  8169. prelude: prelude,
  8170. block: block
  8171. };
  8172. },
  8173. generate: function(node) {
  8174. this.chunk('@');
  8175. this.chunk(node.name);
  8176. if (node.prelude !== null) {
  8177. this.chunk(' ');
  8178. this.node(node.prelude);
  8179. }
  8180. if (node.block) {
  8181. this.node(node.block);
  8182. } else {
  8183. this.chunk(';');
  8184. }
  8185. },
  8186. walkContext: 'atrule'
  8187. };
  8188. var TYPE$c = tokenizer.TYPE;
  8189. var SEMICOLON$1 = TYPE$c.Semicolon;
  8190. var LEFTCURLYBRACKET$2 = TYPE$c.LeftCurlyBracket;
  8191. var AtrulePrelude = {
  8192. name: 'AtrulePrelude',
  8193. structure: {
  8194. children: [[]]
  8195. },
  8196. parse: function(name) {
  8197. var children = null;
  8198. if (name !== null) {
  8199. name = name.toLowerCase();
  8200. }
  8201. this.scanner.skipSC();
  8202. if (this.atrule.hasOwnProperty(name) &&
  8203. typeof this.atrule[name].prelude === 'function') {
  8204. // custom consumer
  8205. children = this.atrule[name].prelude.call(this);
  8206. } else {
  8207. // default consumer
  8208. children = this.readSequence(this.scope.AtrulePrelude);
  8209. }
  8210. this.scanner.skipSC();
  8211. if (this.scanner.eof !== true &&
  8212. this.scanner.tokenType !== LEFTCURLYBRACKET$2 &&
  8213. this.scanner.tokenType !== SEMICOLON$1) {
  8214. this.error('Semicolon or block is expected');
  8215. }
  8216. if (children === null) {
  8217. children = this.createList();
  8218. }
  8219. return {
  8220. type: 'AtrulePrelude',
  8221. loc: this.getLocationFromList(children),
  8222. children: children
  8223. };
  8224. },
  8225. generate: function(node) {
  8226. this.children(node);
  8227. },
  8228. walkContext: 'atrulePrelude'
  8229. };
  8230. var TYPE$d = tokenizer.TYPE;
  8231. var IDENT$4 = TYPE$d.Ident;
  8232. var STRING = TYPE$d.String;
  8233. var COLON = TYPE$d.Colon;
  8234. var LEFTSQUAREBRACKET$1 = TYPE$d.LeftSquareBracket;
  8235. var RIGHTSQUAREBRACKET$1 = TYPE$d.RightSquareBracket;
  8236. var DOLLARSIGN = 0x0024; // U+0024 DOLLAR SIGN ($)
  8237. var ASTERISK$1 = 0x002A; // U+002A ASTERISK (*)
  8238. var EQUALSSIGN = 0x003D; // U+003D EQUALS SIGN (=)
  8239. var CIRCUMFLEXACCENT = 0x005E; // U+005E (^)
  8240. var VERTICALLINE$1 = 0x007C; // U+007C VERTICAL LINE (|)
  8241. var TILDE = 0x007E; // U+007E TILDE (~)
  8242. function getAttributeName() {
  8243. if (this.scanner.eof) {
  8244. this.error('Unexpected end of input');
  8245. }
  8246. var start = this.scanner.tokenStart;
  8247. var expectIdent = false;
  8248. var checkColon = true;
  8249. if (this.scanner.isDelim(ASTERISK$1)) {
  8250. expectIdent = true;
  8251. checkColon = false;
  8252. this.scanner.next();
  8253. } else if (!this.scanner.isDelim(VERTICALLINE$1)) {
  8254. this.eat(IDENT$4);
  8255. }
  8256. if (this.scanner.isDelim(VERTICALLINE$1)) {
  8257. if (this.scanner.source.charCodeAt(this.scanner.tokenStart + 1) !== EQUALSSIGN) {
  8258. this.scanner.next();
  8259. this.eat(IDENT$4);
  8260. } else if (expectIdent) {
  8261. this.error('Identifier is expected', this.scanner.tokenEnd);
  8262. }
  8263. } else if (expectIdent) {
  8264. this.error('Vertical line is expected');
  8265. }
  8266. if (checkColon && this.scanner.tokenType === COLON) {
  8267. this.scanner.next();
  8268. this.eat(IDENT$4);
  8269. }
  8270. return {
  8271. type: 'Identifier',
  8272. loc: this.getLocation(start, this.scanner.tokenStart),
  8273. name: this.scanner.substrToCursor(start)
  8274. };
  8275. }
  8276. function getOperator() {
  8277. var start = this.scanner.tokenStart;
  8278. var code = this.scanner.source.charCodeAt(start);
  8279. if (code !== EQUALSSIGN && // =
  8280. code !== TILDE && // ~=
  8281. code !== CIRCUMFLEXACCENT && // ^=
  8282. code !== DOLLARSIGN && // $=
  8283. code !== ASTERISK$1 && // *=
  8284. code !== VERTICALLINE$1 // |=
  8285. ) {
  8286. this.error('Attribute selector (=, ~=, ^=, $=, *=, |=) is expected');
  8287. }
  8288. this.scanner.next();
  8289. if (code !== EQUALSSIGN) {
  8290. if (!this.scanner.isDelim(EQUALSSIGN)) {
  8291. this.error('Equal sign is expected');
  8292. }
  8293. this.scanner.next();
  8294. }
  8295. return this.scanner.substrToCursor(start);
  8296. }
  8297. // '[' <wq-name> ']'
  8298. // '[' <wq-name> <attr-matcher> [ <string-token> | <ident-token> ] <attr-modifier>? ']'
  8299. var AttributeSelector = {
  8300. name: 'AttributeSelector',
  8301. structure: {
  8302. name: 'Identifier',
  8303. matcher: [String, null],
  8304. value: ['String', 'Identifier', null],
  8305. flags: [String, null]
  8306. },
  8307. parse: function() {
  8308. var start = this.scanner.tokenStart;
  8309. var name;
  8310. var matcher = null;
  8311. var value = null;
  8312. var flags = null;
  8313. this.eat(LEFTSQUAREBRACKET$1);
  8314. this.scanner.skipSC();
  8315. name = getAttributeName.call(this);
  8316. this.scanner.skipSC();
  8317. if (this.scanner.tokenType !== RIGHTSQUAREBRACKET$1) {
  8318. // avoid case `[name i]`
  8319. if (this.scanner.tokenType !== IDENT$4) {
  8320. matcher = getOperator.call(this);
  8321. this.scanner.skipSC();
  8322. value = this.scanner.tokenType === STRING
  8323. ? this.String()
  8324. : this.Identifier();
  8325. this.scanner.skipSC();
  8326. }
  8327. // attribute flags
  8328. if (this.scanner.tokenType === IDENT$4) {
  8329. flags = this.scanner.getTokenValue();
  8330. this.scanner.next();
  8331. this.scanner.skipSC();
  8332. }
  8333. }
  8334. this.eat(RIGHTSQUAREBRACKET$1);
  8335. return {
  8336. type: 'AttributeSelector',
  8337. loc: this.getLocation(start, this.scanner.tokenStart),
  8338. name: name,
  8339. matcher: matcher,
  8340. value: value,
  8341. flags: flags
  8342. };
  8343. },
  8344. generate: function(node) {
  8345. var flagsPrefix = ' ';
  8346. this.chunk('[');
  8347. this.node(node.name);
  8348. if (node.matcher !== null) {
  8349. this.chunk(node.matcher);
  8350. if (node.value !== null) {
  8351. this.node(node.value);
  8352. // space between string and flags is not required
  8353. if (node.value.type === 'String') {
  8354. flagsPrefix = '';
  8355. }
  8356. }
  8357. }
  8358. if (node.flags !== null) {
  8359. this.chunk(flagsPrefix);
  8360. this.chunk(node.flags);
  8361. }
  8362. this.chunk(']');
  8363. }
  8364. };
  8365. var TYPE$e = tokenizer.TYPE;
  8366. var rawMode$1 = Raw.mode;
  8367. var WHITESPACE$5 = TYPE$e.WhiteSpace;
  8368. var COMMENT$4 = TYPE$e.Comment;
  8369. var SEMICOLON$2 = TYPE$e.Semicolon;
  8370. var ATKEYWORD$1 = TYPE$e.AtKeyword;
  8371. var LEFTCURLYBRACKET$3 = TYPE$e.LeftCurlyBracket;
  8372. var RIGHTCURLYBRACKET$2 = TYPE$e.RightCurlyBracket;
  8373. function consumeRaw$1(startToken) {
  8374. return this.Raw(startToken, null, true);
  8375. }
  8376. function consumeRule() {
  8377. return this.parseWithFallback(this.Rule, consumeRaw$1);
  8378. }
  8379. function consumeRawDeclaration(startToken) {
  8380. return this.Raw(startToken, rawMode$1.semicolonIncluded, true);
  8381. }
  8382. function consumeDeclaration() {
  8383. if (this.scanner.tokenType === SEMICOLON$2) {
  8384. return consumeRawDeclaration.call(this, this.scanner.tokenIndex);
  8385. }
  8386. var node = this.parseWithFallback(this.Declaration, consumeRawDeclaration);
  8387. if (this.scanner.tokenType === SEMICOLON$2) {
  8388. this.scanner.next();
  8389. }
  8390. return node;
  8391. }
  8392. var Block = {
  8393. name: 'Block',
  8394. structure: {
  8395. children: [[
  8396. 'Atrule',
  8397. 'Rule',
  8398. 'Declaration'
  8399. ]]
  8400. },
  8401. parse: function(isDeclaration) {
  8402. var consumer = isDeclaration ? consumeDeclaration : consumeRule;
  8403. var start = this.scanner.tokenStart;
  8404. var children = this.createList();
  8405. this.eat(LEFTCURLYBRACKET$3);
  8406. scan:
  8407. while (!this.scanner.eof) {
  8408. switch (this.scanner.tokenType) {
  8409. case RIGHTCURLYBRACKET$2:
  8410. break scan;
  8411. case WHITESPACE$5:
  8412. case COMMENT$4:
  8413. this.scanner.next();
  8414. break;
  8415. case ATKEYWORD$1:
  8416. children.push(this.parseWithFallback(this.Atrule, consumeRaw$1));
  8417. break;
  8418. default:
  8419. children.push(consumer.call(this));
  8420. }
  8421. }
  8422. if (!this.scanner.eof) {
  8423. this.eat(RIGHTCURLYBRACKET$2);
  8424. }
  8425. return {
  8426. type: 'Block',
  8427. loc: this.getLocation(start, this.scanner.tokenStart),
  8428. children: children
  8429. };
  8430. },
  8431. generate: function(node) {
  8432. this.chunk('{');
  8433. this.children(node, function(prev) {
  8434. if (prev.type === 'Declaration') {
  8435. this.chunk(';');
  8436. }
  8437. });
  8438. this.chunk('}');
  8439. },
  8440. walkContext: 'block'
  8441. };
  8442. var TYPE$f = tokenizer.TYPE;
  8443. var LEFTSQUAREBRACKET$2 = TYPE$f.LeftSquareBracket;
  8444. var RIGHTSQUAREBRACKET$2 = TYPE$f.RightSquareBracket;
  8445. var Brackets = {
  8446. name: 'Brackets',
  8447. structure: {
  8448. children: [[]]
  8449. },
  8450. parse: function(readSequence, recognizer) {
  8451. var start = this.scanner.tokenStart;
  8452. var children = null;
  8453. this.eat(LEFTSQUAREBRACKET$2);
  8454. children = readSequence.call(this, recognizer);
  8455. if (!this.scanner.eof) {
  8456. this.eat(RIGHTSQUAREBRACKET$2);
  8457. }
  8458. return {
  8459. type: 'Brackets',
  8460. loc: this.getLocation(start, this.scanner.tokenStart),
  8461. children: children
  8462. };
  8463. },
  8464. generate: function(node) {
  8465. this.chunk('[');
  8466. this.children(node);
  8467. this.chunk(']');
  8468. }
  8469. };
  8470. var CDC = tokenizer.TYPE.CDC;
  8471. var CDC_1 = {
  8472. name: 'CDC',
  8473. structure: [],
  8474. parse: function() {
  8475. var start = this.scanner.tokenStart;
  8476. this.eat(CDC); // -->
  8477. return {
  8478. type: 'CDC',
  8479. loc: this.getLocation(start, this.scanner.tokenStart)
  8480. };
  8481. },
  8482. generate: function() {
  8483. this.chunk('-->');
  8484. }
  8485. };
  8486. var CDO = tokenizer.TYPE.CDO;
  8487. var CDO_1 = {
  8488. name: 'CDO',
  8489. structure: [],
  8490. parse: function() {
  8491. var start = this.scanner.tokenStart;
  8492. this.eat(CDO); // <!--
  8493. return {
  8494. type: 'CDO',
  8495. loc: this.getLocation(start, this.scanner.tokenStart)
  8496. };
  8497. },
  8498. generate: function() {
  8499. this.chunk('<!--');
  8500. }
  8501. };
  8502. var TYPE$g = tokenizer.TYPE;
  8503. var IDENT$5 = TYPE$g.Ident;
  8504. var FULLSTOP = 0x002E; // U+002E FULL STOP (.)
  8505. // '.' ident
  8506. var ClassSelector = {
  8507. name: 'ClassSelector',
  8508. structure: {
  8509. name: String
  8510. },
  8511. parse: function() {
  8512. if (!this.scanner.isDelim(FULLSTOP)) {
  8513. this.error('Full stop is expected');
  8514. }
  8515. this.scanner.next();
  8516. return {
  8517. type: 'ClassSelector',
  8518. loc: this.getLocation(this.scanner.tokenStart - 1, this.scanner.tokenEnd),
  8519. name: this.consume(IDENT$5)
  8520. };
  8521. },
  8522. generate: function(node) {
  8523. this.chunk('.');
  8524. this.chunk(node.name);
  8525. }
  8526. };
  8527. var TYPE$h = tokenizer.TYPE;
  8528. var IDENT$6 = TYPE$h.Ident;
  8529. var PLUSSIGN$4 = 0x002B; // U+002B PLUS SIGN (+)
  8530. var SOLIDUS = 0x002F; // U+002F SOLIDUS (/)
  8531. var GREATERTHANSIGN$1 = 0x003E; // U+003E GREATER-THAN SIGN (>)
  8532. var TILDE$1 = 0x007E; // U+007E TILDE (~)
  8533. // + | > | ~ | /deep/
  8534. var Combinator = {
  8535. name: 'Combinator',
  8536. structure: {
  8537. name: String
  8538. },
  8539. parse: function() {
  8540. var start = this.scanner.tokenStart;
  8541. var code = this.scanner.source.charCodeAt(this.scanner.tokenStart);
  8542. switch (code) {
  8543. case GREATERTHANSIGN$1:
  8544. case PLUSSIGN$4:
  8545. case TILDE$1:
  8546. this.scanner.next();
  8547. break;
  8548. case SOLIDUS:
  8549. this.scanner.next();
  8550. if (this.scanner.tokenType !== IDENT$6 || this.scanner.lookupValue(0, 'deep') === false) {
  8551. this.error('Identifier `deep` is expected');
  8552. }
  8553. this.scanner.next();
  8554. if (!this.scanner.isDelim(SOLIDUS)) {
  8555. this.error('Solidus is expected');
  8556. }
  8557. this.scanner.next();
  8558. break;
  8559. default:
  8560. this.error('Combinator is expected');
  8561. }
  8562. return {
  8563. type: 'Combinator',
  8564. loc: this.getLocation(start, this.scanner.tokenStart),
  8565. name: this.scanner.substrToCursor(start)
  8566. };
  8567. },
  8568. generate: function(node) {
  8569. this.chunk(node.name);
  8570. }
  8571. };
  8572. var TYPE$i = tokenizer.TYPE;
  8573. var COMMENT$5 = TYPE$i.Comment;
  8574. var ASTERISK$2 = 0x002A; // U+002A ASTERISK (*)
  8575. var SOLIDUS$1 = 0x002F; // U+002F SOLIDUS (/)
  8576. // '/*' .* '*/'
  8577. var Comment = {
  8578. name: 'Comment',
  8579. structure: {
  8580. value: String
  8581. },
  8582. parse: function() {
  8583. var start = this.scanner.tokenStart;
  8584. var end = this.scanner.tokenEnd;
  8585. this.eat(COMMENT$5);
  8586. if ((end - start + 2) >= 2 &&
  8587. this.scanner.source.charCodeAt(end - 2) === ASTERISK$2 &&
  8588. this.scanner.source.charCodeAt(end - 1) === SOLIDUS$1) {
  8589. end -= 2;
  8590. }
  8591. return {
  8592. type: 'Comment',
  8593. loc: this.getLocation(start, this.scanner.tokenStart),
  8594. value: this.scanner.source.substring(start + 2, end)
  8595. };
  8596. },
  8597. generate: function(node) {
  8598. this.chunk('/*');
  8599. this.chunk(node.value);
  8600. this.chunk('*/');
  8601. }
  8602. };
  8603. var isCustomProperty$1 = names.isCustomProperty;
  8604. var TYPE$j = tokenizer.TYPE;
  8605. var rawMode$2 = Raw.mode;
  8606. var IDENT$7 = TYPE$j.Ident;
  8607. var HASH$1 = TYPE$j.Hash;
  8608. var COLON$1 = TYPE$j.Colon;
  8609. var SEMICOLON$3 = TYPE$j.Semicolon;
  8610. var DELIM$2 = TYPE$j.Delim;
  8611. var EXCLAMATIONMARK$2 = 0x0021; // U+0021 EXCLAMATION MARK (!)
  8612. var NUMBERSIGN$2 = 0x0023; // U+0023 NUMBER SIGN (#)
  8613. var DOLLARSIGN$1 = 0x0024; // U+0024 DOLLAR SIGN ($)
  8614. var AMPERSAND$1 = 0x0026; // U+0026 ANPERSAND (&)
  8615. var ASTERISK$3 = 0x002A; // U+002A ASTERISK (*)
  8616. var PLUSSIGN$5 = 0x002B; // U+002B PLUS SIGN (+)
  8617. var SOLIDUS$2 = 0x002F; // U+002F SOLIDUS (/)
  8618. function consumeValueRaw(startToken) {
  8619. return this.Raw(startToken, rawMode$2.exclamationMarkOrSemicolon, true);
  8620. }
  8621. function consumeCustomPropertyRaw(startToken) {
  8622. return this.Raw(startToken, rawMode$2.exclamationMarkOrSemicolon, false);
  8623. }
  8624. function consumeValue() {
  8625. var startValueToken = this.scanner.tokenIndex;
  8626. var value = this.Value();
  8627. if (value.type !== 'Raw' &&
  8628. this.scanner.eof === false &&
  8629. this.scanner.tokenType !== SEMICOLON$3 &&
  8630. this.scanner.isDelim(EXCLAMATIONMARK$2) === false &&
  8631. this.scanner.isBalanceEdge(startValueToken) === false) {
  8632. this.error();
  8633. }
  8634. return value;
  8635. }
  8636. var Declaration = {
  8637. name: 'Declaration',
  8638. structure: {
  8639. important: [Boolean, String],
  8640. property: String,
  8641. value: ['Value', 'Raw']
  8642. },
  8643. parse: function() {
  8644. var start = this.scanner.tokenStart;
  8645. var startToken = this.scanner.tokenIndex;
  8646. var property = readProperty$1.call(this);
  8647. var customProperty = isCustomProperty$1(property);
  8648. var parseValue = customProperty ? this.parseCustomProperty : this.parseValue;
  8649. var consumeRaw = customProperty ? consumeCustomPropertyRaw : consumeValueRaw;
  8650. var important = false;
  8651. var value;
  8652. this.scanner.skipSC();
  8653. this.eat(COLON$1);
  8654. if (!customProperty) {
  8655. this.scanner.skipSC();
  8656. }
  8657. if (parseValue) {
  8658. value = this.parseWithFallback(consumeValue, consumeRaw);
  8659. } else {
  8660. value = consumeRaw.call(this, this.scanner.tokenIndex);
  8661. }
  8662. if (this.scanner.isDelim(EXCLAMATIONMARK$2)) {
  8663. important = getImportant.call(this);
  8664. this.scanner.skipSC();
  8665. }
  8666. // Do not include semicolon to range per spec
  8667. // https://drafts.csswg.org/css-syntax/#declaration-diagram
  8668. if (this.scanner.eof === false &&
  8669. this.scanner.tokenType !== SEMICOLON$3 &&
  8670. this.scanner.isBalanceEdge(startToken) === false) {
  8671. this.error();
  8672. }
  8673. return {
  8674. type: 'Declaration',
  8675. loc: this.getLocation(start, this.scanner.tokenStart),
  8676. important: important,
  8677. property: property,
  8678. value: value
  8679. };
  8680. },
  8681. generate: function(node) {
  8682. this.chunk(node.property);
  8683. this.chunk(':');
  8684. this.node(node.value);
  8685. if (node.important) {
  8686. this.chunk(node.important === true ? '!important' : '!' + node.important);
  8687. }
  8688. },
  8689. walkContext: 'declaration'
  8690. };
  8691. function readProperty$1() {
  8692. var start = this.scanner.tokenStart;
  8693. // hacks
  8694. if (this.scanner.tokenType === DELIM$2) {
  8695. switch (this.scanner.source.charCodeAt(this.scanner.tokenStart)) {
  8696. case ASTERISK$3:
  8697. case DOLLARSIGN$1:
  8698. case PLUSSIGN$5:
  8699. case NUMBERSIGN$2:
  8700. case AMPERSAND$1:
  8701. this.scanner.next();
  8702. break;
  8703. // TODO: not sure we should support this hack
  8704. case SOLIDUS$2:
  8705. this.scanner.next();
  8706. if (this.scanner.isDelim(SOLIDUS$2)) {
  8707. this.scanner.next();
  8708. }
  8709. break;
  8710. }
  8711. }
  8712. if (this.scanner.tokenType === HASH$1) {
  8713. this.eat(HASH$1);
  8714. } else {
  8715. this.eat(IDENT$7);
  8716. }
  8717. return this.scanner.substrToCursor(start);
  8718. }
  8719. // ! ws* important
  8720. function getImportant() {
  8721. this.eat(DELIM$2);
  8722. this.scanner.skipSC();
  8723. var important = this.consume(IDENT$7);
  8724. // store original value in case it differ from `important`
  8725. // for better original source restoring and hacks like `!ie` support
  8726. return important === 'important' ? true : important;
  8727. }
  8728. var TYPE$k = tokenizer.TYPE;
  8729. var rawMode$3 = Raw.mode;
  8730. var WHITESPACE$6 = TYPE$k.WhiteSpace;
  8731. var COMMENT$6 = TYPE$k.Comment;
  8732. var SEMICOLON$4 = TYPE$k.Semicolon;
  8733. function consumeRaw$2(startToken) {
  8734. return this.Raw(startToken, rawMode$3.semicolonIncluded, true);
  8735. }
  8736. var DeclarationList = {
  8737. name: 'DeclarationList',
  8738. structure: {
  8739. children: [[
  8740. 'Declaration'
  8741. ]]
  8742. },
  8743. parse: function() {
  8744. var children = this.createList();
  8745. while (!this.scanner.eof) {
  8746. switch (this.scanner.tokenType) {
  8747. case WHITESPACE$6:
  8748. case COMMENT$6:
  8749. case SEMICOLON$4:
  8750. this.scanner.next();
  8751. break;
  8752. default:
  8753. children.push(this.parseWithFallback(this.Declaration, consumeRaw$2));
  8754. }
  8755. }
  8756. return {
  8757. type: 'DeclarationList',
  8758. loc: this.getLocationFromList(children),
  8759. children: children
  8760. };
  8761. },
  8762. generate: function(node) {
  8763. this.children(node, function(prev) {
  8764. if (prev.type === 'Declaration') {
  8765. this.chunk(';');
  8766. }
  8767. });
  8768. }
  8769. };
  8770. var consumeNumber$3 = utils.consumeNumber;
  8771. var TYPE$l = tokenizer.TYPE;
  8772. var DIMENSION$3 = TYPE$l.Dimension;
  8773. var Dimension = {
  8774. name: 'Dimension',
  8775. structure: {
  8776. value: String,
  8777. unit: String
  8778. },
  8779. parse: function() {
  8780. var start = this.scanner.tokenStart;
  8781. var numberEnd = consumeNumber$3(this.scanner.source, start);
  8782. this.eat(DIMENSION$3);
  8783. return {
  8784. type: 'Dimension',
  8785. loc: this.getLocation(start, this.scanner.tokenStart),
  8786. value: this.scanner.source.substring(start, numberEnd),
  8787. unit: this.scanner.source.substring(numberEnd, this.scanner.tokenStart)
  8788. };
  8789. },
  8790. generate: function(node) {
  8791. this.chunk(node.value);
  8792. this.chunk(node.unit);
  8793. }
  8794. };
  8795. var TYPE$m = tokenizer.TYPE;
  8796. var RIGHTPARENTHESIS$2 = TYPE$m.RightParenthesis;
  8797. // <function-token> <sequence> )
  8798. var _Function = {
  8799. name: 'Function',
  8800. structure: {
  8801. name: String,
  8802. children: [[]]
  8803. },
  8804. parse: function(readSequence, recognizer) {
  8805. var start = this.scanner.tokenStart;
  8806. var name = this.consumeFunctionName();
  8807. var nameLowerCase = name.toLowerCase();
  8808. var children;
  8809. children = recognizer.hasOwnProperty(nameLowerCase)
  8810. ? recognizer[nameLowerCase].call(this, recognizer)
  8811. : readSequence.call(this, recognizer);
  8812. if (!this.scanner.eof) {
  8813. this.eat(RIGHTPARENTHESIS$2);
  8814. }
  8815. return {
  8816. type: 'Function',
  8817. loc: this.getLocation(start, this.scanner.tokenStart),
  8818. name: name,
  8819. children: children
  8820. };
  8821. },
  8822. generate: function(node) {
  8823. this.chunk(node.name);
  8824. this.chunk('(');
  8825. this.children(node);
  8826. this.chunk(')');
  8827. },
  8828. walkContext: 'function'
  8829. };
  8830. var TYPE$n = tokenizer.TYPE;
  8831. var HASH$2 = TYPE$n.Hash;
  8832. // '#' ident
  8833. var HexColor = {
  8834. name: 'HexColor',
  8835. structure: {
  8836. value: String
  8837. },
  8838. parse: function() {
  8839. var start = this.scanner.tokenStart;
  8840. this.eat(HASH$2);
  8841. return {
  8842. type: 'HexColor',
  8843. loc: this.getLocation(start, this.scanner.tokenStart),
  8844. value: this.scanner.substrToCursor(start + 1)
  8845. };
  8846. },
  8847. generate: function(node) {
  8848. this.chunk('#');
  8849. this.chunk(node.value);
  8850. }
  8851. };
  8852. var TYPE$o = tokenizer.TYPE;
  8853. var IDENT$8 = TYPE$o.Ident;
  8854. var Identifier = {
  8855. name: 'Identifier',
  8856. structure: {
  8857. name: String
  8858. },
  8859. parse: function() {
  8860. return {
  8861. type: 'Identifier',
  8862. loc: this.getLocation(this.scanner.tokenStart, this.scanner.tokenEnd),
  8863. name: this.consume(IDENT$8)
  8864. };
  8865. },
  8866. generate: function(node) {
  8867. this.chunk(node.name);
  8868. }
  8869. };
  8870. var TYPE$p = tokenizer.TYPE;
  8871. var HASH$3 = TYPE$p.Hash;
  8872. // <hash-token>
  8873. var IdSelector = {
  8874. name: 'IdSelector',
  8875. structure: {
  8876. name: String
  8877. },
  8878. parse: function() {
  8879. var start = this.scanner.tokenStart;
  8880. // TODO: check value is an ident
  8881. this.eat(HASH$3);
  8882. return {
  8883. type: 'IdSelector',
  8884. loc: this.getLocation(start, this.scanner.tokenStart),
  8885. name: this.scanner.substrToCursor(start + 1)
  8886. };
  8887. },
  8888. generate: function(node) {
  8889. this.chunk('#');
  8890. this.chunk(node.name);
  8891. }
  8892. };
  8893. var TYPE$q = tokenizer.TYPE;
  8894. var IDENT$9 = TYPE$q.Ident;
  8895. var NUMBER$4 = TYPE$q.Number;
  8896. var DIMENSION$4 = TYPE$q.Dimension;
  8897. var LEFTPARENTHESIS$2 = TYPE$q.LeftParenthesis;
  8898. var RIGHTPARENTHESIS$3 = TYPE$q.RightParenthesis;
  8899. var COLON$2 = TYPE$q.Colon;
  8900. var DELIM$3 = TYPE$q.Delim;
  8901. var MediaFeature = {
  8902. name: 'MediaFeature',
  8903. structure: {
  8904. name: String,
  8905. value: ['Identifier', 'Number', 'Dimension', 'Ratio', null]
  8906. },
  8907. parse: function() {
  8908. var start = this.scanner.tokenStart;
  8909. var name;
  8910. var value = null;
  8911. this.eat(LEFTPARENTHESIS$2);
  8912. this.scanner.skipSC();
  8913. name = this.consume(IDENT$9);
  8914. this.scanner.skipSC();
  8915. if (this.scanner.tokenType !== RIGHTPARENTHESIS$3) {
  8916. this.eat(COLON$2);
  8917. this.scanner.skipSC();
  8918. switch (this.scanner.tokenType) {
  8919. case NUMBER$4:
  8920. if (this.lookupNonWSType(1) === DELIM$3) {
  8921. value = this.Ratio();
  8922. } else {
  8923. value = this.Number();
  8924. }
  8925. break;
  8926. case DIMENSION$4:
  8927. value = this.Dimension();
  8928. break;
  8929. case IDENT$9:
  8930. value = this.Identifier();
  8931. break;
  8932. default:
  8933. this.error('Number, dimension, ratio or identifier is expected');
  8934. }
  8935. this.scanner.skipSC();
  8936. }
  8937. this.eat(RIGHTPARENTHESIS$3);
  8938. return {
  8939. type: 'MediaFeature',
  8940. loc: this.getLocation(start, this.scanner.tokenStart),
  8941. name: name,
  8942. value: value
  8943. };
  8944. },
  8945. generate: function(node) {
  8946. this.chunk('(');
  8947. this.chunk(node.name);
  8948. if (node.value !== null) {
  8949. this.chunk(':');
  8950. this.node(node.value);
  8951. }
  8952. this.chunk(')');
  8953. }
  8954. };
  8955. var TYPE$r = tokenizer.TYPE;
  8956. var WHITESPACE$7 = TYPE$r.WhiteSpace;
  8957. var COMMENT$7 = TYPE$r.Comment;
  8958. var IDENT$a = TYPE$r.Ident;
  8959. var LEFTPARENTHESIS$3 = TYPE$r.LeftParenthesis;
  8960. var MediaQuery = {
  8961. name: 'MediaQuery',
  8962. structure: {
  8963. children: [[
  8964. 'Identifier',
  8965. 'MediaFeature',
  8966. 'WhiteSpace'
  8967. ]]
  8968. },
  8969. parse: function() {
  8970. this.scanner.skipSC();
  8971. var children = this.createList();
  8972. var child = null;
  8973. var space = null;
  8974. scan:
  8975. while (!this.scanner.eof) {
  8976. switch (this.scanner.tokenType) {
  8977. case COMMENT$7:
  8978. this.scanner.next();
  8979. continue;
  8980. case WHITESPACE$7:
  8981. space = this.WhiteSpace();
  8982. continue;
  8983. case IDENT$a:
  8984. child = this.Identifier();
  8985. break;
  8986. case LEFTPARENTHESIS$3:
  8987. child = this.MediaFeature();
  8988. break;
  8989. default:
  8990. break scan;
  8991. }
  8992. if (space !== null) {
  8993. children.push(space);
  8994. space = null;
  8995. }
  8996. children.push(child);
  8997. }
  8998. if (child === null) {
  8999. this.error('Identifier or parenthesis is expected');
  9000. }
  9001. return {
  9002. type: 'MediaQuery',
  9003. loc: this.getLocationFromList(children),
  9004. children: children
  9005. };
  9006. },
  9007. generate: function(node) {
  9008. this.children(node);
  9009. }
  9010. };
  9011. var COMMA$1 = tokenizer.TYPE.Comma;
  9012. var MediaQueryList = {
  9013. name: 'MediaQueryList',
  9014. structure: {
  9015. children: [[
  9016. 'MediaQuery'
  9017. ]]
  9018. },
  9019. parse: function(relative) {
  9020. var children = this.createList();
  9021. this.scanner.skipSC();
  9022. while (!this.scanner.eof) {
  9023. children.push(this.MediaQuery(relative));
  9024. if (this.scanner.tokenType !== COMMA$1) {
  9025. break;
  9026. }
  9027. this.scanner.next();
  9028. }
  9029. return {
  9030. type: 'MediaQueryList',
  9031. loc: this.getLocationFromList(children),
  9032. children: children
  9033. };
  9034. },
  9035. generate: function(node) {
  9036. this.children(node, function() {
  9037. this.chunk(',');
  9038. });
  9039. }
  9040. };
  9041. var Nth = {
  9042. name: 'Nth',
  9043. structure: {
  9044. nth: ['AnPlusB', 'Identifier'],
  9045. selector: ['SelectorList', null]
  9046. },
  9047. parse: function(allowOfClause) {
  9048. this.scanner.skipSC();
  9049. var start = this.scanner.tokenStart;
  9050. var end = start;
  9051. var selector = null;
  9052. var query;
  9053. if (this.scanner.lookupValue(0, 'odd') || this.scanner.lookupValue(0, 'even')) {
  9054. query = this.Identifier();
  9055. } else {
  9056. query = this.AnPlusB();
  9057. }
  9058. this.scanner.skipSC();
  9059. if (allowOfClause && this.scanner.lookupValue(0, 'of')) {
  9060. this.scanner.next();
  9061. selector = this.SelectorList();
  9062. if (this.needPositions) {
  9063. end = this.getLastListNode(selector.children).loc.end.offset;
  9064. }
  9065. } else {
  9066. if (this.needPositions) {
  9067. end = query.loc.end.offset;
  9068. }
  9069. }
  9070. return {
  9071. type: 'Nth',
  9072. loc: this.getLocation(start, end),
  9073. nth: query,
  9074. selector: selector
  9075. };
  9076. },
  9077. generate: function(node) {
  9078. this.node(node.nth);
  9079. if (node.selector !== null) {
  9080. this.chunk(' of ');
  9081. this.node(node.selector);
  9082. }
  9083. }
  9084. };
  9085. var NUMBER$5 = tokenizer.TYPE.Number;
  9086. var _Number = {
  9087. name: 'Number',
  9088. structure: {
  9089. value: String
  9090. },
  9091. parse: function() {
  9092. return {
  9093. type: 'Number',
  9094. loc: this.getLocation(this.scanner.tokenStart, this.scanner.tokenEnd),
  9095. value: this.consume(NUMBER$5)
  9096. };
  9097. },
  9098. generate: function(node) {
  9099. this.chunk(node.value);
  9100. }
  9101. };
  9102. // '/' | '*' | ',' | ':' | '+' | '-'
  9103. var Operator = {
  9104. name: 'Operator',
  9105. structure: {
  9106. value: String
  9107. },
  9108. parse: function() {
  9109. var start = this.scanner.tokenStart;
  9110. this.scanner.next();
  9111. return {
  9112. type: 'Operator',
  9113. loc: this.getLocation(start, this.scanner.tokenStart),
  9114. value: this.scanner.substrToCursor(start)
  9115. };
  9116. },
  9117. generate: function(node) {
  9118. this.chunk(node.value);
  9119. }
  9120. };
  9121. var TYPE$s = tokenizer.TYPE;
  9122. var LEFTPARENTHESIS$4 = TYPE$s.LeftParenthesis;
  9123. var RIGHTPARENTHESIS$4 = TYPE$s.RightParenthesis;
  9124. var Parentheses = {
  9125. name: 'Parentheses',
  9126. structure: {
  9127. children: [[]]
  9128. },
  9129. parse: function(readSequence, recognizer) {
  9130. var start = this.scanner.tokenStart;
  9131. var children = null;
  9132. this.eat(LEFTPARENTHESIS$4);
  9133. children = readSequence.call(this, recognizer);
  9134. if (!this.scanner.eof) {
  9135. this.eat(RIGHTPARENTHESIS$4);
  9136. }
  9137. return {
  9138. type: 'Parentheses',
  9139. loc: this.getLocation(start, this.scanner.tokenStart),
  9140. children: children
  9141. };
  9142. },
  9143. generate: function(node) {
  9144. this.chunk('(');
  9145. this.children(node);
  9146. this.chunk(')');
  9147. }
  9148. };
  9149. var consumeNumber$4 = utils.consumeNumber;
  9150. var TYPE$t = tokenizer.TYPE;
  9151. var PERCENTAGE$1 = TYPE$t.Percentage;
  9152. var Percentage = {
  9153. name: 'Percentage',
  9154. structure: {
  9155. value: String
  9156. },
  9157. parse: function() {
  9158. var start = this.scanner.tokenStart;
  9159. var numberEnd = consumeNumber$4(this.scanner.source, start);
  9160. this.eat(PERCENTAGE$1);
  9161. return {
  9162. type: 'Percentage',
  9163. loc: this.getLocation(start, this.scanner.tokenStart),
  9164. value: this.scanner.source.substring(start, numberEnd)
  9165. };
  9166. },
  9167. generate: function(node) {
  9168. this.chunk(node.value);
  9169. this.chunk('%');
  9170. }
  9171. };
  9172. var TYPE$u = tokenizer.TYPE;
  9173. var IDENT$b = TYPE$u.Ident;
  9174. var FUNCTION$1 = TYPE$u.Function;
  9175. var COLON$3 = TYPE$u.Colon;
  9176. var RIGHTPARENTHESIS$5 = TYPE$u.RightParenthesis;
  9177. // : [ <ident> | <function-token> <any-value>? ) ]
  9178. var PseudoClassSelector = {
  9179. name: 'PseudoClassSelector',
  9180. structure: {
  9181. name: String,
  9182. children: [['Raw'], null]
  9183. },
  9184. parse: function() {
  9185. var start = this.scanner.tokenStart;
  9186. var children = null;
  9187. var name;
  9188. var nameLowerCase;
  9189. this.eat(COLON$3);
  9190. if (this.scanner.tokenType === FUNCTION$1) {
  9191. name = this.consumeFunctionName();
  9192. nameLowerCase = name.toLowerCase();
  9193. if (this.pseudo.hasOwnProperty(nameLowerCase)) {
  9194. this.scanner.skipSC();
  9195. children = this.pseudo[nameLowerCase].call(this);
  9196. this.scanner.skipSC();
  9197. } else {
  9198. children = this.createList();
  9199. children.push(
  9200. this.Raw(this.scanner.tokenIndex, null, false)
  9201. );
  9202. }
  9203. this.eat(RIGHTPARENTHESIS$5);
  9204. } else {
  9205. name = this.consume(IDENT$b);
  9206. }
  9207. return {
  9208. type: 'PseudoClassSelector',
  9209. loc: this.getLocation(start, this.scanner.tokenStart),
  9210. name: name,
  9211. children: children
  9212. };
  9213. },
  9214. generate: function(node) {
  9215. this.chunk(':');
  9216. this.chunk(node.name);
  9217. if (node.children !== null) {
  9218. this.chunk('(');
  9219. this.children(node);
  9220. this.chunk(')');
  9221. }
  9222. },
  9223. walkContext: 'function'
  9224. };
  9225. var TYPE$v = tokenizer.TYPE;
  9226. var IDENT$c = TYPE$v.Ident;
  9227. var FUNCTION$2 = TYPE$v.Function;
  9228. var COLON$4 = TYPE$v.Colon;
  9229. var RIGHTPARENTHESIS$6 = TYPE$v.RightParenthesis;
  9230. // :: [ <ident> | <function-token> <any-value>? ) ]
  9231. var PseudoElementSelector = {
  9232. name: 'PseudoElementSelector',
  9233. structure: {
  9234. name: String,
  9235. children: [['Raw'], null]
  9236. },
  9237. parse: function() {
  9238. var start = this.scanner.tokenStart;
  9239. var children = null;
  9240. var name;
  9241. var nameLowerCase;
  9242. this.eat(COLON$4);
  9243. this.eat(COLON$4);
  9244. if (this.scanner.tokenType === FUNCTION$2) {
  9245. name = this.consumeFunctionName();
  9246. nameLowerCase = name.toLowerCase();
  9247. if (this.pseudo.hasOwnProperty(nameLowerCase)) {
  9248. this.scanner.skipSC();
  9249. children = this.pseudo[nameLowerCase].call(this);
  9250. this.scanner.skipSC();
  9251. } else {
  9252. children = this.createList();
  9253. children.push(
  9254. this.Raw(this.scanner.tokenIndex, null, false)
  9255. );
  9256. }
  9257. this.eat(RIGHTPARENTHESIS$6);
  9258. } else {
  9259. name = this.consume(IDENT$c);
  9260. }
  9261. return {
  9262. type: 'PseudoElementSelector',
  9263. loc: this.getLocation(start, this.scanner.tokenStart),
  9264. name: name,
  9265. children: children
  9266. };
  9267. },
  9268. generate: function(node) {
  9269. this.chunk('::');
  9270. this.chunk(node.name);
  9271. if (node.children !== null) {
  9272. this.chunk('(');
  9273. this.children(node);
  9274. this.chunk(')');
  9275. }
  9276. },
  9277. walkContext: 'function'
  9278. };
  9279. var isDigit$5 = tokenizer.isDigit;
  9280. var TYPE$w = tokenizer.TYPE;
  9281. var NUMBER$6 = TYPE$w.Number;
  9282. var DELIM$4 = TYPE$w.Delim;
  9283. var SOLIDUS$3 = 0x002F; // U+002F SOLIDUS (/)
  9284. var FULLSTOP$1 = 0x002E; // U+002E FULL STOP (.)
  9285. // Terms of <ratio> should be a positive numbers (not zero or negative)
  9286. // (see https://drafts.csswg.org/mediaqueries-3/#values)
  9287. // However, -o-min-device-pixel-ratio takes fractional values as a ratio's term
  9288. // and this is using by various sites. Therefore we relax checking on parse
  9289. // to test a term is unsigned number without an exponent part.
  9290. // Additional checking may be applied on lexer validation.
  9291. function consumeNumber$5() {
  9292. this.scanner.skipWS();
  9293. var value = this.consume(NUMBER$6);
  9294. for (var i = 0; i < value.length; i++) {
  9295. var code = value.charCodeAt(i);
  9296. if (!isDigit$5(code) && code !== FULLSTOP$1) {
  9297. this.error('Unsigned number is expected', this.scanner.tokenStart - value.length + i);
  9298. }
  9299. }
  9300. if (Number(value) === 0) {
  9301. this.error('Zero number is not allowed', this.scanner.tokenStart - value.length);
  9302. }
  9303. return value;
  9304. }
  9305. // <positive-integer> S* '/' S* <positive-integer>
  9306. var Ratio = {
  9307. name: 'Ratio',
  9308. structure: {
  9309. left: String,
  9310. right: String
  9311. },
  9312. parse: function() {
  9313. var start = this.scanner.tokenStart;
  9314. var left = consumeNumber$5.call(this);
  9315. var right;
  9316. this.scanner.skipWS();
  9317. if (!this.scanner.isDelim(SOLIDUS$3)) {
  9318. this.error('Solidus is expected');
  9319. }
  9320. this.eat(DELIM$4);
  9321. right = consumeNumber$5.call(this);
  9322. return {
  9323. type: 'Ratio',
  9324. loc: this.getLocation(start, this.scanner.tokenStart),
  9325. left: left,
  9326. right: right
  9327. };
  9328. },
  9329. generate: function(node) {
  9330. this.chunk(node.left);
  9331. this.chunk('/');
  9332. this.chunk(node.right);
  9333. }
  9334. };
  9335. var TYPE$x = tokenizer.TYPE;
  9336. var rawMode$4 = Raw.mode;
  9337. var LEFTCURLYBRACKET$4 = TYPE$x.LeftCurlyBracket;
  9338. function consumeRaw$3(startToken) {
  9339. return this.Raw(startToken, rawMode$4.leftCurlyBracket, true);
  9340. }
  9341. function consumePrelude() {
  9342. var prelude = this.SelectorList();
  9343. if (prelude.type !== 'Raw' &&
  9344. this.scanner.eof === false &&
  9345. this.scanner.tokenType !== LEFTCURLYBRACKET$4) {
  9346. this.error();
  9347. }
  9348. return prelude;
  9349. }
  9350. var Rule = {
  9351. name: 'Rule',
  9352. structure: {
  9353. prelude: ['SelectorList', 'Raw'],
  9354. block: ['Block']
  9355. },
  9356. parse: function() {
  9357. var startToken = this.scanner.tokenIndex;
  9358. var startOffset = this.scanner.tokenStart;
  9359. var prelude;
  9360. var block;
  9361. if (this.parseRulePrelude) {
  9362. prelude = this.parseWithFallback(consumePrelude, consumeRaw$3);
  9363. } else {
  9364. prelude = consumeRaw$3.call(this, startToken);
  9365. }
  9366. block = this.Block(true);
  9367. return {
  9368. type: 'Rule',
  9369. loc: this.getLocation(startOffset, this.scanner.tokenStart),
  9370. prelude: prelude,
  9371. block: block
  9372. };
  9373. },
  9374. generate: function(node) {
  9375. this.node(node.prelude);
  9376. this.node(node.block);
  9377. },
  9378. walkContext: 'rule'
  9379. };
  9380. var Selector = {
  9381. name: 'Selector',
  9382. structure: {
  9383. children: [[
  9384. 'TypeSelector',
  9385. 'IdSelector',
  9386. 'ClassSelector',
  9387. 'AttributeSelector',
  9388. 'PseudoClassSelector',
  9389. 'PseudoElementSelector',
  9390. 'Combinator',
  9391. 'WhiteSpace'
  9392. ]]
  9393. },
  9394. parse: function() {
  9395. var children = this.readSequence(this.scope.Selector);
  9396. // nothing were consumed
  9397. if (this.getFirstListNode(children) === null) {
  9398. this.error('Selector is expected');
  9399. }
  9400. return {
  9401. type: 'Selector',
  9402. loc: this.getLocationFromList(children),
  9403. children: children
  9404. };
  9405. },
  9406. generate: function(node) {
  9407. this.children(node);
  9408. }
  9409. };
  9410. var TYPE$y = tokenizer.TYPE;
  9411. var COMMA$2 = TYPE$y.Comma;
  9412. var SelectorList = {
  9413. name: 'SelectorList',
  9414. structure: {
  9415. children: [[
  9416. 'Selector',
  9417. 'Raw'
  9418. ]]
  9419. },
  9420. parse: function() {
  9421. var children = this.createList();
  9422. while (!this.scanner.eof) {
  9423. children.push(this.Selector());
  9424. if (this.scanner.tokenType === COMMA$2) {
  9425. this.scanner.next();
  9426. continue;
  9427. }
  9428. break;
  9429. }
  9430. return {
  9431. type: 'SelectorList',
  9432. loc: this.getLocationFromList(children),
  9433. children: children
  9434. };
  9435. },
  9436. generate: function(node) {
  9437. this.children(node, function() {
  9438. this.chunk(',');
  9439. });
  9440. },
  9441. walkContext: 'selector'
  9442. };
  9443. var STRING$1 = tokenizer.TYPE.String;
  9444. var _String = {
  9445. name: 'String',
  9446. structure: {
  9447. value: String
  9448. },
  9449. parse: function() {
  9450. return {
  9451. type: 'String',
  9452. loc: this.getLocation(this.scanner.tokenStart, this.scanner.tokenEnd),
  9453. value: this.consume(STRING$1)
  9454. };
  9455. },
  9456. generate: function(node) {
  9457. this.chunk(node.value);
  9458. }
  9459. };
  9460. var TYPE$z = tokenizer.TYPE;
  9461. var WHITESPACE$8 = TYPE$z.WhiteSpace;
  9462. var COMMENT$8 = TYPE$z.Comment;
  9463. var ATKEYWORD$2 = TYPE$z.AtKeyword;
  9464. var CDO$1 = TYPE$z.CDO;
  9465. var CDC$1 = TYPE$z.CDC;
  9466. var EXCLAMATIONMARK$3 = 0x0021; // U+0021 EXCLAMATION MARK (!)
  9467. function consumeRaw$4(startToken) {
  9468. return this.Raw(startToken, null, false);
  9469. }
  9470. var StyleSheet = {
  9471. name: 'StyleSheet',
  9472. structure: {
  9473. children: [[
  9474. 'Comment',
  9475. 'CDO',
  9476. 'CDC',
  9477. 'Atrule',
  9478. 'Rule',
  9479. 'Raw'
  9480. ]]
  9481. },
  9482. parse: function() {
  9483. var start = this.scanner.tokenStart;
  9484. var children = this.createList();
  9485. var child;
  9486. while (!this.scanner.eof) {
  9487. switch (this.scanner.tokenType) {
  9488. case WHITESPACE$8:
  9489. this.scanner.next();
  9490. continue;
  9491. case COMMENT$8:
  9492. // ignore comments except exclamation comments (i.e. /*! .. */) on top level
  9493. if (this.scanner.source.charCodeAt(this.scanner.tokenStart + 2) !== EXCLAMATIONMARK$3) {
  9494. this.scanner.next();
  9495. continue;
  9496. }
  9497. child = this.Comment();
  9498. break;
  9499. case CDO$1: // <!--
  9500. child = this.CDO();
  9501. break;
  9502. case CDC$1: // -->
  9503. child = this.CDC();
  9504. break;
  9505. // CSS Syntax Module Level 3
  9506. // §2.2 Error handling
  9507. // At the "top level" of a stylesheet, an <at-keyword-token> starts an at-rule.
  9508. case ATKEYWORD$2:
  9509. child = this.parseWithFallback(this.Atrule, consumeRaw$4);
  9510. break;
  9511. // Anything else starts a qualified rule ...
  9512. default:
  9513. child = this.parseWithFallback(this.Rule, consumeRaw$4);
  9514. }
  9515. children.push(child);
  9516. }
  9517. return {
  9518. type: 'StyleSheet',
  9519. loc: this.getLocation(start, this.scanner.tokenStart),
  9520. children: children
  9521. };
  9522. },
  9523. generate: function(node) {
  9524. this.children(node);
  9525. },
  9526. walkContext: 'stylesheet'
  9527. };
  9528. var TYPE$A = tokenizer.TYPE;
  9529. var IDENT$d = TYPE$A.Ident;
  9530. var ASTERISK$4 = 0x002A; // U+002A ASTERISK (*)
  9531. var VERTICALLINE$2 = 0x007C; // U+007C VERTICAL LINE (|)
  9532. function eatIdentifierOrAsterisk() {
  9533. if (this.scanner.tokenType !== IDENT$d &&
  9534. this.scanner.isDelim(ASTERISK$4) === false) {
  9535. this.error('Identifier or asterisk is expected');
  9536. }
  9537. this.scanner.next();
  9538. }
  9539. // ident
  9540. // ident|ident
  9541. // ident|*
  9542. // *
  9543. // *|ident
  9544. // *|*
  9545. // |ident
  9546. // |*
  9547. var TypeSelector = {
  9548. name: 'TypeSelector',
  9549. structure: {
  9550. name: String
  9551. },
  9552. parse: function() {
  9553. var start = this.scanner.tokenStart;
  9554. if (this.scanner.isDelim(VERTICALLINE$2)) {
  9555. this.scanner.next();
  9556. eatIdentifierOrAsterisk.call(this);
  9557. } else {
  9558. eatIdentifierOrAsterisk.call(this);
  9559. if (this.scanner.isDelim(VERTICALLINE$2)) {
  9560. this.scanner.next();
  9561. eatIdentifierOrAsterisk.call(this);
  9562. }
  9563. }
  9564. return {
  9565. type: 'TypeSelector',
  9566. loc: this.getLocation(start, this.scanner.tokenStart),
  9567. name: this.scanner.substrToCursor(start)
  9568. };
  9569. },
  9570. generate: function(node) {
  9571. this.chunk(node.name);
  9572. }
  9573. };
  9574. var isHexDigit$4 = tokenizer.isHexDigit;
  9575. var cmpChar$4 = tokenizer.cmpChar;
  9576. var TYPE$B = tokenizer.TYPE;
  9577. var NAME$3 = tokenizer.NAME;
  9578. var IDENT$e = TYPE$B.Ident;
  9579. var NUMBER$7 = TYPE$B.Number;
  9580. var DIMENSION$5 = TYPE$B.Dimension;
  9581. var PLUSSIGN$6 = 0x002B; // U+002B PLUS SIGN (+)
  9582. var HYPHENMINUS$4 = 0x002D; // U+002D HYPHEN-MINUS (-)
  9583. var QUESTIONMARK$2 = 0x003F; // U+003F QUESTION MARK (?)
  9584. var U$1 = 0x0075; // U+0075 LATIN SMALL LETTER U (u)
  9585. function eatHexSequence(offset, allowDash) {
  9586. for (var pos = this.scanner.tokenStart + offset, len = 0; pos < this.scanner.tokenEnd; pos++) {
  9587. var code = this.scanner.source.charCodeAt(pos);
  9588. if (code === HYPHENMINUS$4 && allowDash && len !== 0) {
  9589. if (eatHexSequence.call(this, offset + len + 1, false) === 0) {
  9590. this.error();
  9591. }
  9592. return -1;
  9593. }
  9594. if (!isHexDigit$4(code)) {
  9595. this.error(
  9596. allowDash && len !== 0
  9597. ? 'HyphenMinus' + (len < 6 ? ' or hex digit' : '') + ' is expected'
  9598. : (len < 6 ? 'Hex digit is expected' : 'Unexpected input'),
  9599. pos
  9600. );
  9601. }
  9602. if (++len > 6) {
  9603. this.error('Too many hex digits', pos);
  9604. } }
  9605. this.scanner.next();
  9606. return len;
  9607. }
  9608. function eatQuestionMarkSequence(max) {
  9609. var count = 0;
  9610. while (this.scanner.isDelim(QUESTIONMARK$2)) {
  9611. if (++count > max) {
  9612. this.error('Too many question marks');
  9613. }
  9614. this.scanner.next();
  9615. }
  9616. }
  9617. function startsWith$1(code) {
  9618. if (this.scanner.source.charCodeAt(this.scanner.tokenStart) !== code) {
  9619. this.error(NAME$3[code] + ' is expected');
  9620. }
  9621. }
  9622. // https://drafts.csswg.org/css-syntax/#urange
  9623. // Informally, the <urange> production has three forms:
  9624. // U+0001
  9625. // Defines a range consisting of a single code point, in this case the code point "1".
  9626. // U+0001-00ff
  9627. // Defines a range of codepoints between the first and the second value, in this case
  9628. // the range between "1" and "ff" (255 in decimal) inclusive.
  9629. // U+00??
  9630. // Defines a range of codepoints where the "?" characters range over all hex digits,
  9631. // in this case defining the same as the value U+0000-00ff.
  9632. // In each form, a maximum of 6 digits is allowed for each hexadecimal number (if you treat "?" as a hexadecimal digit).
  9633. //
  9634. // <urange> =
  9635. // u '+' <ident-token> '?'* |
  9636. // u <dimension-token> '?'* |
  9637. // u <number-token> '?'* |
  9638. // u <number-token> <dimension-token> |
  9639. // u <number-token> <number-token> |
  9640. // u '+' '?'+
  9641. function scanUnicodeRange() {
  9642. var hexLength = 0;
  9643. // u '+' <ident-token> '?'*
  9644. // u '+' '?'+
  9645. if (this.scanner.isDelim(PLUSSIGN$6)) {
  9646. this.scanner.next();
  9647. if (this.scanner.tokenType === IDENT$e) {
  9648. hexLength = eatHexSequence.call(this, 0, true);
  9649. if (hexLength > 0) {
  9650. eatQuestionMarkSequence.call(this, 6 - hexLength);
  9651. }
  9652. return;
  9653. }
  9654. if (this.scanner.isDelim(QUESTIONMARK$2)) {
  9655. this.scanner.next();
  9656. eatQuestionMarkSequence.call(this, 5);
  9657. return;
  9658. }
  9659. this.error('Hex digit or question mark is expected');
  9660. return;
  9661. }
  9662. // u <number-token> '?'*
  9663. // u <number-token> <dimension-token>
  9664. // u <number-token> <number-token>
  9665. if (this.scanner.tokenType === NUMBER$7) {
  9666. startsWith$1.call(this, PLUSSIGN$6);
  9667. hexLength = eatHexSequence.call(this, 1, true);
  9668. if (this.scanner.isDelim(QUESTIONMARK$2)) {
  9669. eatQuestionMarkSequence.call(this, 6 - hexLength);
  9670. return;
  9671. }
  9672. if (this.scanner.tokenType === DIMENSION$5 ||
  9673. this.scanner.tokenType === NUMBER$7) {
  9674. startsWith$1.call(this, HYPHENMINUS$4);
  9675. eatHexSequence.call(this, 1, false);
  9676. return;
  9677. }
  9678. return;
  9679. }
  9680. // u <dimension-token> '?'*
  9681. if (this.scanner.tokenType === DIMENSION$5) {
  9682. startsWith$1.call(this, PLUSSIGN$6);
  9683. hexLength = eatHexSequence.call(this, 1, true);
  9684. if (hexLength > 0) {
  9685. eatQuestionMarkSequence.call(this, 6 - hexLength);
  9686. }
  9687. return;
  9688. }
  9689. this.error();
  9690. }
  9691. var UnicodeRange = {
  9692. name: 'UnicodeRange',
  9693. structure: {
  9694. value: String
  9695. },
  9696. parse: function() {
  9697. var start = this.scanner.tokenStart;
  9698. // U or u
  9699. if (!cmpChar$4(this.scanner.source, start, U$1)) {
  9700. this.error('U is expected');
  9701. }
  9702. if (!cmpChar$4(this.scanner.source, start + 1, PLUSSIGN$6)) {
  9703. this.error('Plus sign is expected');
  9704. }
  9705. this.scanner.next();
  9706. scanUnicodeRange.call(this);
  9707. return {
  9708. type: 'UnicodeRange',
  9709. loc: this.getLocation(start, this.scanner.tokenStart),
  9710. value: this.scanner.substrToCursor(start)
  9711. };
  9712. },
  9713. generate: function(node) {
  9714. this.chunk(node.value);
  9715. }
  9716. };
  9717. var isWhiteSpace$2 = tokenizer.isWhiteSpace;
  9718. var cmpStr$4 = tokenizer.cmpStr;
  9719. var TYPE$C = tokenizer.TYPE;
  9720. var FUNCTION$3 = TYPE$C.Function;
  9721. var URL$1 = TYPE$C.Url;
  9722. var RIGHTPARENTHESIS$7 = TYPE$C.RightParenthesis;
  9723. // <url-token> | <function-token> <string> )
  9724. var Url = {
  9725. name: 'Url',
  9726. structure: {
  9727. value: ['String', 'Raw']
  9728. },
  9729. parse: function() {
  9730. var start = this.scanner.tokenStart;
  9731. var value;
  9732. switch (this.scanner.tokenType) {
  9733. case URL$1:
  9734. var rawStart = start + 4;
  9735. var rawEnd = this.scanner.tokenEnd - 1;
  9736. while (rawStart < rawEnd && isWhiteSpace$2(this.scanner.source.charCodeAt(rawStart))) {
  9737. rawStart++;
  9738. }
  9739. while (rawStart < rawEnd && isWhiteSpace$2(this.scanner.source.charCodeAt(rawEnd - 1))) {
  9740. rawEnd--;
  9741. }
  9742. value = {
  9743. type: 'Raw',
  9744. loc: this.getLocation(rawStart, rawEnd),
  9745. value: this.scanner.source.substring(rawStart, rawEnd)
  9746. };
  9747. this.eat(URL$1);
  9748. break;
  9749. case FUNCTION$3:
  9750. if (!cmpStr$4(this.scanner.source, this.scanner.tokenStart, this.scanner.tokenEnd, 'url(')) {
  9751. this.error('Function name must be `url`');
  9752. }
  9753. this.eat(FUNCTION$3);
  9754. this.scanner.skipSC();
  9755. value = this.String();
  9756. this.scanner.skipSC();
  9757. this.eat(RIGHTPARENTHESIS$7);
  9758. break;
  9759. default:
  9760. this.error('Url or Function is expected');
  9761. }
  9762. return {
  9763. type: 'Url',
  9764. loc: this.getLocation(start, this.scanner.tokenStart),
  9765. value: value
  9766. };
  9767. },
  9768. generate: function(node) {
  9769. this.chunk('url');
  9770. this.chunk('(');
  9771. this.node(node.value);
  9772. this.chunk(')');
  9773. }
  9774. };
  9775. var Value = {
  9776. name: 'Value',
  9777. structure: {
  9778. children: [[]]
  9779. },
  9780. parse: function() {
  9781. var start = this.scanner.tokenStart;
  9782. var children = this.readSequence(this.scope.Value);
  9783. return {
  9784. type: 'Value',
  9785. loc: this.getLocation(start, this.scanner.tokenStart),
  9786. children: children
  9787. };
  9788. },
  9789. generate: function(node) {
  9790. this.children(node);
  9791. }
  9792. };
  9793. var WHITESPACE$9 = tokenizer.TYPE.WhiteSpace;
  9794. var SPACE$2 = Object.freeze({
  9795. type: 'WhiteSpace',
  9796. loc: null,
  9797. value: ' '
  9798. });
  9799. var WhiteSpace$1 = {
  9800. name: 'WhiteSpace',
  9801. structure: {
  9802. value: String
  9803. },
  9804. parse: function() {
  9805. this.eat(WHITESPACE$9);
  9806. return SPACE$2;
  9807. // return {
  9808. // type: 'WhiteSpace',
  9809. // loc: this.getLocation(this.scanner.tokenStart, this.scanner.tokenEnd),
  9810. // value: this.consume(WHITESPACE)
  9811. // };
  9812. },
  9813. generate: function(node) {
  9814. this.chunk(node.value);
  9815. }
  9816. };
  9817. var node = {
  9818. AnPlusB: AnPlusB,
  9819. Atrule: Atrule,
  9820. AtrulePrelude: AtrulePrelude,
  9821. AttributeSelector: AttributeSelector,
  9822. Block: Block,
  9823. Brackets: Brackets,
  9824. CDC: CDC_1,
  9825. CDO: CDO_1,
  9826. ClassSelector: ClassSelector,
  9827. Combinator: Combinator,
  9828. Comment: Comment,
  9829. Declaration: Declaration,
  9830. DeclarationList: DeclarationList,
  9831. Dimension: Dimension,
  9832. Function: _Function,
  9833. HexColor: HexColor,
  9834. Identifier: Identifier,
  9835. IdSelector: IdSelector,
  9836. MediaFeature: MediaFeature,
  9837. MediaQuery: MediaQuery,
  9838. MediaQueryList: MediaQueryList,
  9839. Nth: Nth,
  9840. Number: _Number,
  9841. Operator: Operator,
  9842. Parentheses: Parentheses,
  9843. Percentage: Percentage,
  9844. PseudoClassSelector: PseudoClassSelector,
  9845. PseudoElementSelector: PseudoElementSelector,
  9846. Ratio: Ratio,
  9847. Raw: Raw,
  9848. Rule: Rule,
  9849. Selector: Selector,
  9850. SelectorList: SelectorList,
  9851. String: _String,
  9852. StyleSheet: StyleSheet,
  9853. TypeSelector: TypeSelector,
  9854. UnicodeRange: UnicodeRange,
  9855. Url: Url,
  9856. Value: Value,
  9857. WhiteSpace: WhiteSpace$1
  9858. };
  9859. var data = getCjsExportFromNamespace(defaultSyntax$1);
  9860. var lexer = {
  9861. generic: true,
  9862. types: data.types,
  9863. atrules: data.atrules,
  9864. properties: data.properties,
  9865. node: node
  9866. };
  9867. var cmpChar$5 = tokenizer.cmpChar;
  9868. var cmpStr$5 = tokenizer.cmpStr;
  9869. var TYPE$D = tokenizer.TYPE;
  9870. var IDENT$f = TYPE$D.Ident;
  9871. var STRING$2 = TYPE$D.String;
  9872. var NUMBER$8 = TYPE$D.Number;
  9873. var FUNCTION$4 = TYPE$D.Function;
  9874. var URL$2 = TYPE$D.Url;
  9875. var HASH$4 = TYPE$D.Hash;
  9876. var DIMENSION$6 = TYPE$D.Dimension;
  9877. var PERCENTAGE$2 = TYPE$D.Percentage;
  9878. var LEFTPARENTHESIS$5 = TYPE$D.LeftParenthesis;
  9879. var LEFTSQUAREBRACKET$3 = TYPE$D.LeftSquareBracket;
  9880. var COMMA$3 = TYPE$D.Comma;
  9881. var DELIM$5 = TYPE$D.Delim;
  9882. var NUMBERSIGN$3 = 0x0023; // U+0023 NUMBER SIGN (#)
  9883. var ASTERISK$5 = 0x002A; // U+002A ASTERISK (*)
  9884. var PLUSSIGN$7 = 0x002B; // U+002B PLUS SIGN (+)
  9885. var HYPHENMINUS$5 = 0x002D; // U+002D HYPHEN-MINUS (-)
  9886. var SOLIDUS$4 = 0x002F; // U+002F SOLIDUS (/)
  9887. var U$2 = 0x0075; // U+0075 LATIN SMALL LETTER U (u)
  9888. var _default = function defaultRecognizer(context) {
  9889. switch (this.scanner.tokenType) {
  9890. case HASH$4:
  9891. return this.HexColor();
  9892. case COMMA$3:
  9893. context.space = null;
  9894. context.ignoreWSAfter = true;
  9895. return this.Operator();
  9896. case LEFTPARENTHESIS$5:
  9897. return this.Parentheses(this.readSequence, context.recognizer);
  9898. case LEFTSQUAREBRACKET$3:
  9899. return this.Brackets(this.readSequence, context.recognizer);
  9900. case STRING$2:
  9901. return this.String();
  9902. case DIMENSION$6:
  9903. return this.Dimension();
  9904. case PERCENTAGE$2:
  9905. return this.Percentage();
  9906. case NUMBER$8:
  9907. return this.Number();
  9908. case FUNCTION$4:
  9909. return cmpStr$5(this.scanner.source, this.scanner.tokenStart, this.scanner.tokenEnd, 'url(')
  9910. ? this.Url()
  9911. : this.Function(this.readSequence, context.recognizer);
  9912. case URL$2:
  9913. return this.Url();
  9914. case IDENT$f:
  9915. // check for unicode range, it should start with u+ or U+
  9916. if (cmpChar$5(this.scanner.source, this.scanner.tokenStart, U$2) &&
  9917. cmpChar$5(this.scanner.source, this.scanner.tokenStart + 1, PLUSSIGN$7)) {
  9918. return this.UnicodeRange();
  9919. } else {
  9920. return this.Identifier();
  9921. }
  9922. case DELIM$5:
  9923. var code = this.scanner.source.charCodeAt(this.scanner.tokenStart);
  9924. if (code === SOLIDUS$4 ||
  9925. code === ASTERISK$5 ||
  9926. code === PLUSSIGN$7 ||
  9927. code === HYPHENMINUS$5) {
  9928. return this.Operator(); // TODO: replace with Delim
  9929. }
  9930. // TODO: produce a node with Delim node type
  9931. if (code === NUMBERSIGN$3) {
  9932. this.error('Hex or identifier is expected', this.scanner.tokenStart + 1);
  9933. }
  9934. break;
  9935. }
  9936. };
  9937. var atrulePrelude = {
  9938. getNode: _default
  9939. };
  9940. var TYPE$E = tokenizer.TYPE;
  9941. var DELIM$6 = TYPE$E.Delim;
  9942. var IDENT$g = TYPE$E.Ident;
  9943. var DIMENSION$7 = TYPE$E.Dimension;
  9944. var PERCENTAGE$3 = TYPE$E.Percentage;
  9945. var NUMBER$9 = TYPE$E.Number;
  9946. var HASH$5 = TYPE$E.Hash;
  9947. var COLON$5 = TYPE$E.Colon;
  9948. var LEFTSQUAREBRACKET$4 = TYPE$E.LeftSquareBracket;
  9949. var NUMBERSIGN$4 = 0x0023; // U+0023 NUMBER SIGN (#)
  9950. var ASTERISK$6 = 0x002A; // U+002A ASTERISK (*)
  9951. var PLUSSIGN$8 = 0x002B; // U+002B PLUS SIGN (+)
  9952. var SOLIDUS$5 = 0x002F; // U+002F SOLIDUS (/)
  9953. var FULLSTOP$2 = 0x002E; // U+002E FULL STOP (.)
  9954. var GREATERTHANSIGN$2 = 0x003E; // U+003E GREATER-THAN SIGN (>)
  9955. var VERTICALLINE$3 = 0x007C; // U+007C VERTICAL LINE (|)
  9956. var TILDE$2 = 0x007E; // U+007E TILDE (~)
  9957. function getNode(context) {
  9958. switch (this.scanner.tokenType) {
  9959. case LEFTSQUAREBRACKET$4:
  9960. return this.AttributeSelector();
  9961. case HASH$5:
  9962. return this.IdSelector();
  9963. case COLON$5:
  9964. if (this.scanner.lookupType(1) === COLON$5) {
  9965. return this.PseudoElementSelector();
  9966. } else {
  9967. return this.PseudoClassSelector();
  9968. }
  9969. case IDENT$g:
  9970. return this.TypeSelector();
  9971. case NUMBER$9:
  9972. case PERCENTAGE$3:
  9973. return this.Percentage();
  9974. case DIMENSION$7:
  9975. // throws when .123ident
  9976. if (this.scanner.source.charCodeAt(this.scanner.tokenStart) === FULLSTOP$2) {
  9977. this.error('Identifier is expected', this.scanner.tokenStart + 1);
  9978. }
  9979. break;
  9980. case DELIM$6:
  9981. var code = this.scanner.source.charCodeAt(this.scanner.tokenStart);
  9982. switch (code) {
  9983. case PLUSSIGN$8:
  9984. case GREATERTHANSIGN$2:
  9985. case TILDE$2:
  9986. context.space = null;
  9987. context.ignoreWSAfter = true;
  9988. return this.Combinator();
  9989. case SOLIDUS$5: // /deep/
  9990. return this.Combinator();
  9991. case FULLSTOP$2:
  9992. return this.ClassSelector();
  9993. case ASTERISK$6:
  9994. case VERTICALLINE$3:
  9995. return this.TypeSelector();
  9996. case NUMBERSIGN$4:
  9997. return this.IdSelector();
  9998. }
  9999. break;
  10000. }
  10001. }
  10002. var selector = {
  10003. getNode: getNode
  10004. };
  10005. // https://drafts.csswg.org/css-images-4/#element-notation
  10006. // https://developer.mozilla.org/en-US/docs/Web/CSS/element
  10007. var element = function() {
  10008. this.scanner.skipSC();
  10009. var children = this.createSingleNodeList(
  10010. this.IdSelector()
  10011. );
  10012. this.scanner.skipSC();
  10013. return children;
  10014. };
  10015. // legacy IE function
  10016. // expression( <any-value> )
  10017. var expression = function() {
  10018. return this.createSingleNodeList(
  10019. this.Raw(this.scanner.tokenIndex, null, false)
  10020. );
  10021. };
  10022. var TYPE$F = tokenizer.TYPE;
  10023. var rawMode$5 = Raw.mode;
  10024. var COMMA$4 = TYPE$F.Comma;
  10025. // var( <ident> , <value>? )
  10026. var _var = function() {
  10027. var children = this.createList();
  10028. this.scanner.skipSC();
  10029. // NOTE: Don't check more than a first argument is an ident, rest checks are for lexer
  10030. children.push(this.Identifier());
  10031. this.scanner.skipSC();
  10032. if (this.scanner.tokenType === COMMA$4) {
  10033. children.push(this.Operator());
  10034. children.push(this.parseCustomProperty
  10035. ? this.Value(null)
  10036. : this.Raw(this.scanner.tokenIndex, rawMode$5.exclamationMarkOrSemicolon, false)
  10037. );
  10038. }
  10039. return children;
  10040. };
  10041. var value = {
  10042. getNode: _default,
  10043. '-moz-element': element,
  10044. 'element': element,
  10045. 'expression': expression,
  10046. 'var': _var
  10047. };
  10048. var scope = {
  10049. AtrulePrelude: atrulePrelude,
  10050. Selector: selector,
  10051. Value: value
  10052. };
  10053. var fontFace = {
  10054. parse: {
  10055. prelude: null,
  10056. block: function() {
  10057. return this.Block(true);
  10058. }
  10059. }
  10060. };
  10061. var TYPE$G = tokenizer.TYPE;
  10062. var STRING$3 = TYPE$G.String;
  10063. var IDENT$h = TYPE$G.Ident;
  10064. var URL$3 = TYPE$G.Url;
  10065. var FUNCTION$5 = TYPE$G.Function;
  10066. var LEFTPARENTHESIS$6 = TYPE$G.LeftParenthesis;
  10067. var _import = {
  10068. parse: {
  10069. prelude: function() {
  10070. var children = this.createList();
  10071. this.scanner.skipSC();
  10072. switch (this.scanner.tokenType) {
  10073. case STRING$3:
  10074. children.push(this.String());
  10075. break;
  10076. case URL$3:
  10077. case FUNCTION$5:
  10078. children.push(this.Url());
  10079. break;
  10080. default:
  10081. this.error('String or url() is expected');
  10082. }
  10083. if (this.lookupNonWSType(0) === IDENT$h ||
  10084. this.lookupNonWSType(0) === LEFTPARENTHESIS$6) {
  10085. children.push(this.WhiteSpace());
  10086. children.push(this.MediaQueryList());
  10087. }
  10088. return children;
  10089. },
  10090. block: null
  10091. }
  10092. };
  10093. var media = {
  10094. parse: {
  10095. prelude: function() {
  10096. return this.createSingleNodeList(
  10097. this.MediaQueryList()
  10098. );
  10099. },
  10100. block: function() {
  10101. return this.Block(false);
  10102. }
  10103. }
  10104. };
  10105. var page = {
  10106. parse: {
  10107. prelude: function() {
  10108. return this.createSingleNodeList(
  10109. this.SelectorList()
  10110. );
  10111. },
  10112. block: function() {
  10113. return this.Block(true);
  10114. }
  10115. }
  10116. };
  10117. var TYPE$H = tokenizer.TYPE;
  10118. var WHITESPACE$a = TYPE$H.WhiteSpace;
  10119. var COMMENT$9 = TYPE$H.Comment;
  10120. var IDENT$i = TYPE$H.Ident;
  10121. var FUNCTION$6 = TYPE$H.Function;
  10122. var COLON$6 = TYPE$H.Colon;
  10123. var LEFTPARENTHESIS$7 = TYPE$H.LeftParenthesis;
  10124. function consumeRaw$5() {
  10125. return this.createSingleNodeList(
  10126. this.Raw(this.scanner.tokenIndex, null, false)
  10127. );
  10128. }
  10129. function parentheses() {
  10130. this.scanner.skipSC();
  10131. if (this.scanner.tokenType === IDENT$i &&
  10132. this.lookupNonWSType(1) === COLON$6) {
  10133. return this.createSingleNodeList(
  10134. this.Declaration()
  10135. );
  10136. }
  10137. return readSequence.call(this);
  10138. }
  10139. function readSequence() {
  10140. var children = this.createList();
  10141. var space = null;
  10142. var child;
  10143. this.scanner.skipSC();
  10144. scan:
  10145. while (!this.scanner.eof) {
  10146. switch (this.scanner.tokenType) {
  10147. case WHITESPACE$a:
  10148. space = this.WhiteSpace();
  10149. continue;
  10150. case COMMENT$9:
  10151. this.scanner.next();
  10152. continue;
  10153. case FUNCTION$6:
  10154. child = this.Function(consumeRaw$5, this.scope.AtrulePrelude);
  10155. break;
  10156. case IDENT$i:
  10157. child = this.Identifier();
  10158. break;
  10159. case LEFTPARENTHESIS$7:
  10160. child = this.Parentheses(parentheses, this.scope.AtrulePrelude);
  10161. break;
  10162. default:
  10163. break scan;
  10164. }
  10165. if (space !== null) {
  10166. children.push(space);
  10167. space = null;
  10168. }
  10169. children.push(child);
  10170. }
  10171. return children;
  10172. }
  10173. var supports = {
  10174. parse: {
  10175. prelude: function() {
  10176. var children = readSequence.call(this);
  10177. if (this.getFirstListNode(children) === null) {
  10178. this.error('Condition is expected');
  10179. }
  10180. return children;
  10181. },
  10182. block: function() {
  10183. return this.Block(false);
  10184. }
  10185. }
  10186. };
  10187. var atrule = {
  10188. 'font-face': fontFace,
  10189. 'import': _import,
  10190. 'media': media,
  10191. 'page': page,
  10192. 'supports': supports
  10193. };
  10194. var dir = {
  10195. parse: function() {
  10196. return this.createSingleNodeList(
  10197. this.Identifier()
  10198. );
  10199. }
  10200. };
  10201. var has$1 = {
  10202. parse: function() {
  10203. return this.createSingleNodeList(
  10204. this.SelectorList()
  10205. );
  10206. }
  10207. };
  10208. var lang = {
  10209. parse: function() {
  10210. return this.createSingleNodeList(
  10211. this.Identifier()
  10212. );
  10213. }
  10214. };
  10215. var selectorList = {
  10216. parse: function selectorList() {
  10217. return this.createSingleNodeList(
  10218. this.SelectorList()
  10219. );
  10220. }
  10221. };
  10222. var matches = selectorList;
  10223. var not = selectorList;
  10224. var ALLOW_OF_CLAUSE = true;
  10225. var nthWithOfClause = {
  10226. parse: function nthWithOfClause() {
  10227. return this.createSingleNodeList(
  10228. this.Nth(ALLOW_OF_CLAUSE)
  10229. );
  10230. }
  10231. };
  10232. var nthChild = nthWithOfClause;
  10233. var nthLastChild = nthWithOfClause;
  10234. var DISALLOW_OF_CLAUSE = false;
  10235. var nth = {
  10236. parse: function nth() {
  10237. return this.createSingleNodeList(
  10238. this.Nth(DISALLOW_OF_CLAUSE)
  10239. );
  10240. }
  10241. };
  10242. var nthLastOfType = nth;
  10243. var nthOfType = nth;
  10244. var slotted = {
  10245. parse: function compoundSelector() {
  10246. return this.createSingleNodeList(
  10247. this.Selector()
  10248. );
  10249. }
  10250. };
  10251. var pseudo = {
  10252. 'dir': dir,
  10253. 'has': has$1,
  10254. 'lang': lang,
  10255. 'matches': matches,
  10256. 'not': not,
  10257. 'nth-child': nthChild,
  10258. 'nth-last-child': nthLastChild,
  10259. 'nth-last-of-type': nthLastOfType,
  10260. 'nth-of-type': nthOfType,
  10261. 'slotted': slotted
  10262. };
  10263. var parser = {
  10264. parseContext: {
  10265. default: 'StyleSheet',
  10266. stylesheet: 'StyleSheet',
  10267. atrule: 'Atrule',
  10268. atrulePrelude: function(options) {
  10269. return this.AtrulePrelude(options.atrule ? String(options.atrule) : null);
  10270. },
  10271. mediaQueryList: 'MediaQueryList',
  10272. mediaQuery: 'MediaQuery',
  10273. rule: 'Rule',
  10274. selectorList: 'SelectorList',
  10275. selector: 'Selector',
  10276. block: function() {
  10277. return this.Block(true);
  10278. },
  10279. declarationList: 'DeclarationList',
  10280. declaration: 'Declaration',
  10281. value: 'Value'
  10282. },
  10283. scope: scope,
  10284. atrule: atrule,
  10285. pseudo: pseudo,
  10286. node: node
  10287. };
  10288. var walker = {
  10289. node: node
  10290. };
  10291. function merge() {
  10292. var dest = {};
  10293. for (var i = 0; i < arguments.length; i++) {
  10294. var src = arguments[i];
  10295. for (var key in src) {
  10296. dest[key] = src[key];
  10297. }
  10298. }
  10299. return dest;
  10300. }
  10301. var syntax = create$4.create(
  10302. merge(
  10303. lexer,
  10304. parser,
  10305. walker
  10306. )
  10307. );
  10308. var lib = syntax;
  10309. var hasOwnProperty$6 = Object.prototype.hasOwnProperty;
  10310. function buildMap(list, caseInsensitive) {
  10311. var map = Object.create(null);
  10312. if (!Array.isArray(list)) {
  10313. return null;
  10314. }
  10315. for (var i = 0; i < list.length; i++) {
  10316. var name = list[i];
  10317. if (caseInsensitive) {
  10318. name = name.toLowerCase();
  10319. }
  10320. map[name] = true;
  10321. }
  10322. return map;
  10323. }
  10324. function buildList(data) {
  10325. if (!data) {
  10326. return null;
  10327. }
  10328. var tags = buildMap(data.tags, true);
  10329. var ids = buildMap(data.ids);
  10330. var classes = buildMap(data.classes);
  10331. if (tags === null &&
  10332. ids === null &&
  10333. classes === null) {
  10334. return null;
  10335. }
  10336. return {
  10337. tags: tags,
  10338. ids: ids,
  10339. classes: classes
  10340. };
  10341. }
  10342. function buildIndex(data) {
  10343. var scopes = false;
  10344. if (data.scopes && Array.isArray(data.scopes)) {
  10345. scopes = Object.create(null);
  10346. for (var i = 0; i < data.scopes.length; i++) {
  10347. var list = data.scopes[i];
  10348. if (!list || !Array.isArray(list)) {
  10349. throw new Error('Wrong usage format');
  10350. }
  10351. for (var j = 0; j < list.length; j++) {
  10352. var name = list[j];
  10353. if (hasOwnProperty$6.call(scopes, name)) {
  10354. throw new Error('Class can\'t be used for several scopes: ' + name);
  10355. }
  10356. scopes[name] = i + 1;
  10357. }
  10358. }
  10359. }
  10360. return {
  10361. whitelist: buildList(data),
  10362. blacklist: buildList(data.blacklist),
  10363. scopes: scopes
  10364. };
  10365. }
  10366. var usage = {
  10367. buildIndex: buildIndex
  10368. };
  10369. var utils$1 = {
  10370. hasNoChildren: function(node) {
  10371. return !node || !node.children || node.children.isEmpty();
  10372. },
  10373. isNodeChildrenList: function(node, list) {
  10374. return node !== null && node.children === list;
  10375. }
  10376. };
  10377. var resolveKeyword = lib.keyword;
  10378. var { hasNoChildren } = utils$1;
  10379. var Atrule$1 = function cleanAtrule(node, item, list) {
  10380. if (node.block) {
  10381. // otherwise removed at-rule don't prevent @import for removal
  10382. if (this.stylesheet !== null) {
  10383. this.stylesheet.firstAtrulesAllowed = false;
  10384. }
  10385. if (hasNoChildren(node.block)) {
  10386. list.remove(item);
  10387. return;
  10388. }
  10389. }
  10390. switch (node.name) {
  10391. case 'charset':
  10392. if (hasNoChildren(node.prelude)) {
  10393. list.remove(item);
  10394. return;
  10395. }
  10396. // if there is any rule before @charset -> remove it
  10397. if (item.prev) {
  10398. list.remove(item);
  10399. return;
  10400. }
  10401. break;
  10402. case 'import':
  10403. if (this.stylesheet === null || !this.stylesheet.firstAtrulesAllowed) {
  10404. list.remove(item);
  10405. return;
  10406. }
  10407. // if there are some rules that not an @import or @charset before @import
  10408. // remove it
  10409. list.prevUntil(item.prev, function(rule) {
  10410. if (rule.type === 'Atrule') {
  10411. if (rule.name === 'import' || rule.name === 'charset') {
  10412. return;
  10413. }
  10414. }
  10415. this.root.firstAtrulesAllowed = false;
  10416. list.remove(item);
  10417. return true;
  10418. }, this);
  10419. break;
  10420. default:
  10421. var name = resolveKeyword(node.name).basename;
  10422. if (name === 'keyframes' ||
  10423. name === 'media' ||
  10424. name === 'supports') {
  10425. // drop at-rule with no prelude
  10426. if (hasNoChildren(node.prelude) || hasNoChildren(node.block)) {
  10427. list.remove(item);
  10428. }
  10429. }
  10430. }
  10431. };
  10432. var Comment$1 = function cleanComment(data, item, list) {
  10433. list.remove(item);
  10434. };
  10435. var Declaration$1 = function cleanDeclartion(node, item, list) {
  10436. if (node.value.children && node.value.children.isEmpty()) {
  10437. list.remove(item);
  10438. }
  10439. };
  10440. var { isNodeChildrenList } = utils$1;
  10441. var Raw$1 = function cleanRaw(node, item, list) {
  10442. // raw in stylesheet or block children
  10443. if (isNodeChildrenList(this.stylesheet, list) ||
  10444. isNodeChildrenList(this.block, list)) {
  10445. list.remove(item);
  10446. }
  10447. };
  10448. var hasOwnProperty$7 = Object.prototype.hasOwnProperty;
  10449. var walk$1 = lib.walk;
  10450. var { hasNoChildren: hasNoChildren$1 } = utils$1;
  10451. function cleanUnused(selectorList, usageData) {
  10452. selectorList.children.each(function(selector, item, list) {
  10453. var shouldRemove = false;
  10454. walk$1(selector, function(node) {
  10455. // ignore nodes in nested selectors
  10456. if (this.selector === null || this.selector === selectorList) {
  10457. switch (node.type) {
  10458. case 'SelectorList':
  10459. // TODO: remove toLowerCase when pseudo selectors will be normalized
  10460. // ignore selectors inside :not()
  10461. if (this.function === null || this.function.name.toLowerCase() !== 'not') {
  10462. if (cleanUnused(node, usageData)) {
  10463. shouldRemove = true;
  10464. }
  10465. }
  10466. break;
  10467. case 'ClassSelector':
  10468. if (usageData.whitelist !== null &&
  10469. usageData.whitelist.classes !== null &&
  10470. !hasOwnProperty$7.call(usageData.whitelist.classes, node.name)) {
  10471. shouldRemove = true;
  10472. }
  10473. if (usageData.blacklist !== null &&
  10474. usageData.blacklist.classes !== null &&
  10475. hasOwnProperty$7.call(usageData.blacklist.classes, node.name)) {
  10476. shouldRemove = true;
  10477. }
  10478. break;
  10479. case 'IdSelector':
  10480. if (usageData.whitelist !== null &&
  10481. usageData.whitelist.ids !== null &&
  10482. !hasOwnProperty$7.call(usageData.whitelist.ids, node.name)) {
  10483. shouldRemove = true;
  10484. }
  10485. if (usageData.blacklist !== null &&
  10486. usageData.blacklist.ids !== null &&
  10487. hasOwnProperty$7.call(usageData.blacklist.ids, node.name)) {
  10488. shouldRemove = true;
  10489. }
  10490. break;
  10491. case 'TypeSelector':
  10492. // TODO: remove toLowerCase when type selectors will be normalized
  10493. // ignore universal selectors
  10494. if (node.name.charAt(node.name.length - 1) !== '*') {
  10495. if (usageData.whitelist !== null &&
  10496. usageData.whitelist.tags !== null &&
  10497. !hasOwnProperty$7.call(usageData.whitelist.tags, node.name.toLowerCase())) {
  10498. shouldRemove = true;
  10499. }
  10500. if (usageData.blacklist !== null &&
  10501. usageData.blacklist.tags !== null &&
  10502. hasOwnProperty$7.call(usageData.blacklist.tags, node.name.toLowerCase())) {
  10503. shouldRemove = true;
  10504. }
  10505. }
  10506. break;
  10507. }
  10508. }
  10509. });
  10510. if (shouldRemove) {
  10511. list.remove(item);
  10512. }
  10513. });
  10514. return selectorList.children.isEmpty();
  10515. }
  10516. var Rule$1 = function cleanRule(node, item, list, options) {
  10517. if (hasNoChildren$1(node.prelude) || hasNoChildren$1(node.block)) {
  10518. list.remove(item);
  10519. return;
  10520. }
  10521. var usageData = options.usage;
  10522. if (usageData && (usageData.whitelist !== null || usageData.blacklist !== null)) {
  10523. cleanUnused(node.prelude, usageData);
  10524. if (hasNoChildren$1(node.prelude)) {
  10525. list.remove(item);
  10526. return;
  10527. }
  10528. }
  10529. };
  10530. // remove useless universal selector
  10531. var TypeSelector$1 = function cleanTypeSelector(node, item, list) {
  10532. var name = item.data.name;
  10533. // check it's a non-namespaced universal selector
  10534. if (name !== '*') {
  10535. return;
  10536. }
  10537. // remove when universal selector before other selectors
  10538. var nextType = item.next && item.next.data.type;
  10539. if (nextType === 'IdSelector' ||
  10540. nextType === 'ClassSelector' ||
  10541. nextType === 'AttributeSelector' ||
  10542. nextType === 'PseudoClassSelector' ||
  10543. nextType === 'PseudoElementSelector') {
  10544. list.remove(item);
  10545. }
  10546. };
  10547. var { isNodeChildrenList: isNodeChildrenList$1 } = utils$1;
  10548. function isSafeOperator(node) {
  10549. return node.type === 'Operator' && node.value !== '+' && node.value !== '-';
  10550. }
  10551. var WhiteSpace$2 = function cleanWhitespace(node, item, list) {
  10552. // remove when first or last item in sequence
  10553. if (item.next === null || item.prev === null) {
  10554. list.remove(item);
  10555. return;
  10556. }
  10557. // white space in stylesheet or block children
  10558. if (isNodeChildrenList$1(this.stylesheet, list) ||
  10559. isNodeChildrenList$1(this.block, list)) {
  10560. list.remove(item);
  10561. return;
  10562. }
  10563. if (item.next.data.type === 'WhiteSpace') {
  10564. list.remove(item);
  10565. return;
  10566. }
  10567. if (isSafeOperator(item.prev.data) || isSafeOperator(item.next.data)) {
  10568. list.remove(item);
  10569. return;
  10570. }
  10571. };
  10572. var walk$2 = lib.walk;
  10573. var handlers = {
  10574. Atrule: Atrule$1,
  10575. Comment: Comment$1,
  10576. Declaration: Declaration$1,
  10577. Raw: Raw$1,
  10578. Rule: Rule$1,
  10579. TypeSelector: TypeSelector$1,
  10580. WhiteSpace: WhiteSpace$2
  10581. };
  10582. var clean = function(ast, options) {
  10583. walk$2(ast, {
  10584. leave: function(node, item, list) {
  10585. if (handlers.hasOwnProperty(node.type)) {
  10586. handlers[node.type].call(this, node, item, list, options);
  10587. }
  10588. }
  10589. });
  10590. };
  10591. var keyframes = function(node) {
  10592. node.block.children.each(function(rule) {
  10593. rule.prelude.children.each(function(simpleselector) {
  10594. simpleselector.children.each(function(data, item) {
  10595. if (data.type === 'Percentage' && data.value === '100') {
  10596. item.data = {
  10597. type: 'TypeSelector',
  10598. loc: data.loc,
  10599. name: 'to'
  10600. };
  10601. } else if (data.type === 'TypeSelector' && data.name === 'from') {
  10602. item.data = {
  10603. type: 'Percentage',
  10604. loc: data.loc,
  10605. value: '0'
  10606. };
  10607. }
  10608. });
  10609. });
  10610. });
  10611. };
  10612. var resolveKeyword$1 = lib.keyword;
  10613. var Atrule$2 = function(node) {
  10614. // compress @keyframe selectors
  10615. if (resolveKeyword$1(node.name).basename === 'keyframes') {
  10616. keyframes(node);
  10617. }
  10618. };
  10619. // Can unquote attribute detection
  10620. // Adopted implementation of Mathias Bynens
  10621. // https://github.com/mathiasbynens/mothereff.in/blob/master/unquoted-attributes/eff.js
  10622. var escapesRx = /\\([0-9A-Fa-f]{1,6})(\r\n|[ \t\n\f\r])?|\\./g;
  10623. var blockUnquoteRx = /^(-?\d|--)|[\u0000-\u002c\u002e\u002f\u003A-\u0040\u005B-\u005E\u0060\u007B-\u009f]/;
  10624. function canUnquote(value) {
  10625. if (value === '' || value === '-') {
  10626. return;
  10627. }
  10628. // Escapes are valid, so replace them with a valid non-empty string
  10629. value = value.replace(escapesRx, 'a');
  10630. return !blockUnquoteRx.test(value);
  10631. }
  10632. var AttributeSelector$1 = function(node) {
  10633. var attrValue = node.value;
  10634. if (!attrValue || attrValue.type !== 'String') {
  10635. return;
  10636. }
  10637. var unquotedValue = attrValue.value.replace(/^(.)(.*)\1$/, '$2');
  10638. if (canUnquote(unquotedValue)) {
  10639. node.value = {
  10640. type: 'Identifier',
  10641. loc: attrValue.loc,
  10642. name: unquotedValue
  10643. };
  10644. }
  10645. };
  10646. var font = function compressFont(node) {
  10647. var list = node.children;
  10648. list.eachRight(function(node, item) {
  10649. if (node.type === 'Identifier') {
  10650. if (node.name === 'bold') {
  10651. item.data = {
  10652. type: 'Number',
  10653. loc: node.loc,
  10654. value: '700'
  10655. };
  10656. } else if (node.name === 'normal') {
  10657. var prev = item.prev;
  10658. if (prev && prev.data.type === 'Operator' && prev.data.value === '/') {
  10659. this.remove(prev);
  10660. }
  10661. this.remove(item);
  10662. } else if (node.name === 'medium') {
  10663. var next = item.next;
  10664. if (!next || next.data.type !== 'Operator') {
  10665. this.remove(item);
  10666. }
  10667. }
  10668. }
  10669. });
  10670. // remove redundant spaces
  10671. list.each(function(node, item) {
  10672. if (node.type === 'WhiteSpace') {
  10673. if (!item.prev || !item.next || item.next.data.type === 'WhiteSpace') {
  10674. this.remove(item);
  10675. }
  10676. }
  10677. });
  10678. if (list.isEmpty()) {
  10679. list.insert(list.createItem({
  10680. type: 'Identifier',
  10681. name: 'normal'
  10682. }));
  10683. }
  10684. };
  10685. var fontWeight = function compressFontWeight(node) {
  10686. var value = node.children.head.data;
  10687. if (value.type === 'Identifier') {
  10688. switch (value.name) {
  10689. case 'normal':
  10690. node.children.head.data = {
  10691. type: 'Number',
  10692. loc: value.loc,
  10693. value: '400'
  10694. };
  10695. break;
  10696. case 'bold':
  10697. node.children.head.data = {
  10698. type: 'Number',
  10699. loc: value.loc,
  10700. value: '700'
  10701. };
  10702. break;
  10703. }
  10704. }
  10705. };
  10706. var List$1 = lib.List;
  10707. var background = function compressBackground(node) {
  10708. function lastType() {
  10709. if (buffer.length) {
  10710. return buffer[buffer.length - 1].type;
  10711. }
  10712. }
  10713. function flush() {
  10714. if (lastType() === 'WhiteSpace') {
  10715. buffer.pop();
  10716. }
  10717. if (!buffer.length) {
  10718. buffer.unshift(
  10719. {
  10720. type: 'Number',
  10721. loc: null,
  10722. value: '0'
  10723. },
  10724. {
  10725. type: 'WhiteSpace',
  10726. value: ' '
  10727. },
  10728. {
  10729. type: 'Number',
  10730. loc: null,
  10731. value: '0'
  10732. }
  10733. );
  10734. }
  10735. newValue.push.apply(newValue, buffer);
  10736. buffer = [];
  10737. }
  10738. var newValue = [];
  10739. var buffer = [];
  10740. node.children.each(function(node) {
  10741. if (node.type === 'Operator' && node.value === ',') {
  10742. flush();
  10743. newValue.push(node);
  10744. return;
  10745. }
  10746. // remove defaults
  10747. if (node.type === 'Identifier') {
  10748. if (node.name === 'transparent' ||
  10749. node.name === 'none' ||
  10750. node.name === 'repeat' ||
  10751. node.name === 'scroll') {
  10752. return;
  10753. }
  10754. }
  10755. // don't add redundant spaces
  10756. if (node.type === 'WhiteSpace' && (!buffer.length || lastType() === 'WhiteSpace')) {
  10757. return;
  10758. }
  10759. buffer.push(node);
  10760. });
  10761. flush();
  10762. node.children = new List$1().fromArray(newValue);
  10763. };
  10764. function removeItemAndRedundantWhiteSpace(list, item) {
  10765. var prev = item.prev;
  10766. var next = item.next;
  10767. if (next !== null) {
  10768. if (next.data.type === 'WhiteSpace' && (prev === null || prev.data.type === 'WhiteSpace')) {
  10769. list.remove(next);
  10770. }
  10771. } else if (prev !== null && prev.data.type === 'WhiteSpace') {
  10772. list.remove(prev);
  10773. }
  10774. list.remove(item);
  10775. }
  10776. var border = function compressBorder(node) {
  10777. node.children.each(function(node, item, list) {
  10778. if (node.type === 'Identifier' && node.name.toLowerCase() === 'none') {
  10779. if (list.head === list.tail) {
  10780. // replace `none` for zero when `none` is a single term
  10781. item.data = {
  10782. type: 'Number',
  10783. loc: node.loc,
  10784. value: '0'
  10785. };
  10786. } else {
  10787. removeItemAndRedundantWhiteSpace(list, item);
  10788. }
  10789. }
  10790. });
  10791. };
  10792. var resolveName = lib.property;
  10793. var handlers$1 = {
  10794. 'font': font,
  10795. 'font-weight': fontWeight,
  10796. 'background': background,
  10797. 'border': border,
  10798. 'outline': border
  10799. };
  10800. var Value$1 = function compressValue(node) {
  10801. if (!this.declaration) {
  10802. return;
  10803. }
  10804. var property = resolveName(this.declaration.property);
  10805. if (handlers$1.hasOwnProperty(property.basename)) {
  10806. handlers$1[property.basename](node);
  10807. }
  10808. };
  10809. var OMIT_PLUSSIGN = /^(?:\+|(-))?0*(\d*)(?:\.0*|(\.\d*?)0*)?$/;
  10810. var KEEP_PLUSSIGN = /^([\+\-])?0*(\d*)(?:\.0*|(\.\d*?)0*)?$/;
  10811. var unsafeToRemovePlusSignAfter = {
  10812. Dimension: true,
  10813. HexColor: true,
  10814. Identifier: true,
  10815. Number: true,
  10816. Raw: true,
  10817. UnicodeRange: true
  10818. };
  10819. function packNumber(value, item) {
  10820. // omit plus sign only if no prev or prev is safe type
  10821. var regexp = item && item.prev !== null && unsafeToRemovePlusSignAfter.hasOwnProperty(item.prev.data.type)
  10822. ? KEEP_PLUSSIGN
  10823. : OMIT_PLUSSIGN;
  10824. // 100 -> '100'
  10825. // 00100 -> '100'
  10826. // +100 -> '100' (only when safe, e.g. omitting plus sign for 1px+1px leads to single dimension instead of two)
  10827. // -100 -> '-100'
  10828. // 0.123 -> '.123'
  10829. // 0.12300 -> '.123'
  10830. // 0.0 -> ''
  10831. // 0 -> ''
  10832. // -0 -> '-'
  10833. value = String(value).replace(regexp, '$1$2$3');
  10834. if (value === '' || value === '-') {
  10835. value = '0';
  10836. }
  10837. return value;
  10838. }
  10839. var _Number$1 = function(node, item) {
  10840. node.value = packNumber(node.value, item);
  10841. };
  10842. var pack = packNumber;
  10843. _Number$1.pack = pack;
  10844. var packNumber$1 = _Number$1.pack;
  10845. var LENGTH_UNIT = {
  10846. // absolute length units
  10847. 'px': true,
  10848. 'mm': true,
  10849. 'cm': true,
  10850. 'in': true,
  10851. 'pt': true,
  10852. 'pc': true,
  10853. // relative length units
  10854. 'em': true,
  10855. 'ex': true,
  10856. 'ch': true,
  10857. 'rem': true,
  10858. // viewport-percentage lengths
  10859. 'vh': true,
  10860. 'vw': true,
  10861. 'vmin': true,
  10862. 'vmax': true,
  10863. 'vm': true
  10864. };
  10865. var Dimension$1 = function compressDimension(node, item) {
  10866. var value = packNumber$1(node.value, item);
  10867. node.value = value;
  10868. if (value === '0' && this.declaration !== null && this.atrulePrelude === null) {
  10869. var unit = node.unit.toLowerCase();
  10870. // only length values can be compressed
  10871. if (!LENGTH_UNIT.hasOwnProperty(unit)) {
  10872. return;
  10873. }
  10874. // issue #362: shouldn't remove unit in -ms-flex since it breaks flex in IE10/11
  10875. // issue #200: shouldn't remove unit in flex since it breaks flex in IE10/11
  10876. if (this.declaration.property === '-ms-flex' ||
  10877. this.declaration.property === 'flex') {
  10878. return;
  10879. }
  10880. // issue #222: don't remove units inside calc
  10881. if (this.function && this.function.name === 'calc') {
  10882. return;
  10883. }
  10884. item.data = {
  10885. type: 'Number',
  10886. loc: node.loc,
  10887. value: value
  10888. };
  10889. }
  10890. };
  10891. var lexer$1 = lib.lexer;
  10892. var packNumber$2 = _Number$1.pack;
  10893. var blacklist = new Set([
  10894. // see https://github.com/jakubpawlowicz/clean-css/issues/957
  10895. 'width',
  10896. 'min-width',
  10897. 'max-width',
  10898. 'height',
  10899. 'min-height',
  10900. 'max-height',
  10901. // issue #410: Don’t remove units in flex-basis value for (-ms-)flex shorthand
  10902. // issue #362: shouldn't remove unit in -ms-flex since it breaks flex in IE10/11
  10903. // issue #200: shouldn't remove unit in flex since it breaks flex in IE10/11
  10904. 'flex',
  10905. '-ms-flex'
  10906. ]);
  10907. var Percentage$1 = function compressPercentage(node, item) {
  10908. node.value = packNumber$2(node.value, item);
  10909. if (node.value === '0' && this.declaration && !blacklist.has(this.declaration.property)) {
  10910. // try to convert a number
  10911. item.data = {
  10912. type: 'Number',
  10913. loc: node.loc,
  10914. value: node.value
  10915. };
  10916. // that's ok only when new value matches on length
  10917. if (!lexer$1.matchDeclaration(this.declaration).isType(item.data, 'length')) {
  10918. // otherwise rollback changes
  10919. item.data = node;
  10920. }
  10921. }
  10922. };
  10923. var _String$1 = function(node) {
  10924. var value = node.value;
  10925. // remove escaped newlines, i.e.
  10926. // .a { content: "foo\
  10927. // bar"}
  10928. // ->
  10929. // .a { content: "foobar" }
  10930. value = value.replace(/\\(\r\n|\r|\n|\f)/g, '');
  10931. node.value = value;
  10932. };
  10933. var UNICODE = '\\\\[0-9a-f]{1,6}(\\r\\n|[ \\n\\r\\t\\f])?';
  10934. var ESCAPE = '(' + UNICODE + '|\\\\[^\\n\\r\\f0-9a-fA-F])';
  10935. var NONPRINTABLE = '\u0000\u0008\u000b\u000e-\u001f\u007f';
  10936. var SAFE_URL = new RegExp('^(' + ESCAPE + '|[^\"\'\\(\\)\\\\\\s' + NONPRINTABLE + '])*$', 'i');
  10937. var Url$1 = function(node) {
  10938. var value = node.value;
  10939. if (value.type !== 'String') {
  10940. return;
  10941. }
  10942. var quote = value.value[0];
  10943. var url = value.value.substr(1, value.value.length - 2);
  10944. // convert `\\` to `/`
  10945. url = url.replace(/\\\\/g, '/');
  10946. // remove quotes when safe
  10947. // https://www.w3.org/TR/css-syntax-3/#url-unquoted-diagram
  10948. if (SAFE_URL.test(url)) {
  10949. node.value = {
  10950. type: 'Raw',
  10951. loc: node.value.loc,
  10952. value: url
  10953. };
  10954. } else {
  10955. // use double quotes if string has no double quotes
  10956. // otherwise use original quotes
  10957. // TODO: make better quote type selection
  10958. node.value.value = url.indexOf('"') === -1 ? '"' + url + '"' : quote + url + quote;
  10959. }
  10960. };
  10961. var lexer$2 = lib.lexer;
  10962. var packNumber$3 = _Number$1.pack;
  10963. // http://www.w3.org/TR/css3-color/#svg-color
  10964. var NAME_TO_HEX = {
  10965. 'aliceblue': 'f0f8ff',
  10966. 'antiquewhite': 'faebd7',
  10967. 'aqua': '0ff',
  10968. 'aquamarine': '7fffd4',
  10969. 'azure': 'f0ffff',
  10970. 'beige': 'f5f5dc',
  10971. 'bisque': 'ffe4c4',
  10972. 'black': '000',
  10973. 'blanchedalmond': 'ffebcd',
  10974. 'blue': '00f',
  10975. 'blueviolet': '8a2be2',
  10976. 'brown': 'a52a2a',
  10977. 'burlywood': 'deb887',
  10978. 'cadetblue': '5f9ea0',
  10979. 'chartreuse': '7fff00',
  10980. 'chocolate': 'd2691e',
  10981. 'coral': 'ff7f50',
  10982. 'cornflowerblue': '6495ed',
  10983. 'cornsilk': 'fff8dc',
  10984. 'crimson': 'dc143c',
  10985. 'cyan': '0ff',
  10986. 'darkblue': '00008b',
  10987. 'darkcyan': '008b8b',
  10988. 'darkgoldenrod': 'b8860b',
  10989. 'darkgray': 'a9a9a9',
  10990. 'darkgrey': 'a9a9a9',
  10991. 'darkgreen': '006400',
  10992. 'darkkhaki': 'bdb76b',
  10993. 'darkmagenta': '8b008b',
  10994. 'darkolivegreen': '556b2f',
  10995. 'darkorange': 'ff8c00',
  10996. 'darkorchid': '9932cc',
  10997. 'darkred': '8b0000',
  10998. 'darksalmon': 'e9967a',
  10999. 'darkseagreen': '8fbc8f',
  11000. 'darkslateblue': '483d8b',
  11001. 'darkslategray': '2f4f4f',
  11002. 'darkslategrey': '2f4f4f',
  11003. 'darkturquoise': '00ced1',
  11004. 'darkviolet': '9400d3',
  11005. 'deeppink': 'ff1493',
  11006. 'deepskyblue': '00bfff',
  11007. 'dimgray': '696969',
  11008. 'dimgrey': '696969',
  11009. 'dodgerblue': '1e90ff',
  11010. 'firebrick': 'b22222',
  11011. 'floralwhite': 'fffaf0',
  11012. 'forestgreen': '228b22',
  11013. 'fuchsia': 'f0f',
  11014. 'gainsboro': 'dcdcdc',
  11015. 'ghostwhite': 'f8f8ff',
  11016. 'gold': 'ffd700',
  11017. 'goldenrod': 'daa520',
  11018. 'gray': '808080',
  11019. 'grey': '808080',
  11020. 'green': '008000',
  11021. 'greenyellow': 'adff2f',
  11022. 'honeydew': 'f0fff0',
  11023. 'hotpink': 'ff69b4',
  11024. 'indianred': 'cd5c5c',
  11025. 'indigo': '4b0082',
  11026. 'ivory': 'fffff0',
  11027. 'khaki': 'f0e68c',
  11028. 'lavender': 'e6e6fa',
  11029. 'lavenderblush': 'fff0f5',
  11030. 'lawngreen': '7cfc00',
  11031. 'lemonchiffon': 'fffacd',
  11032. 'lightblue': 'add8e6',
  11033. 'lightcoral': 'f08080',
  11034. 'lightcyan': 'e0ffff',
  11035. 'lightgoldenrodyellow': 'fafad2',
  11036. 'lightgray': 'd3d3d3',
  11037. 'lightgrey': 'd3d3d3',
  11038. 'lightgreen': '90ee90',
  11039. 'lightpink': 'ffb6c1',
  11040. 'lightsalmon': 'ffa07a',
  11041. 'lightseagreen': '20b2aa',
  11042. 'lightskyblue': '87cefa',
  11043. 'lightslategray': '789',
  11044. 'lightslategrey': '789',
  11045. 'lightsteelblue': 'b0c4de',
  11046. 'lightyellow': 'ffffe0',
  11047. 'lime': '0f0',
  11048. 'limegreen': '32cd32',
  11049. 'linen': 'faf0e6',
  11050. 'magenta': 'f0f',
  11051. 'maroon': '800000',
  11052. 'mediumaquamarine': '66cdaa',
  11053. 'mediumblue': '0000cd',
  11054. 'mediumorchid': 'ba55d3',
  11055. 'mediumpurple': '9370db',
  11056. 'mediumseagreen': '3cb371',
  11057. 'mediumslateblue': '7b68ee',
  11058. 'mediumspringgreen': '00fa9a',
  11059. 'mediumturquoise': '48d1cc',
  11060. 'mediumvioletred': 'c71585',
  11061. 'midnightblue': '191970',
  11062. 'mintcream': 'f5fffa',
  11063. 'mistyrose': 'ffe4e1',
  11064. 'moccasin': 'ffe4b5',
  11065. 'navajowhite': 'ffdead',
  11066. 'navy': '000080',
  11067. 'oldlace': 'fdf5e6',
  11068. 'olive': '808000',
  11069. 'olivedrab': '6b8e23',
  11070. 'orange': 'ffa500',
  11071. 'orangered': 'ff4500',
  11072. 'orchid': 'da70d6',
  11073. 'palegoldenrod': 'eee8aa',
  11074. 'palegreen': '98fb98',
  11075. 'paleturquoise': 'afeeee',
  11076. 'palevioletred': 'db7093',
  11077. 'papayawhip': 'ffefd5',
  11078. 'peachpuff': 'ffdab9',
  11079. 'peru': 'cd853f',
  11080. 'pink': 'ffc0cb',
  11081. 'plum': 'dda0dd',
  11082. 'powderblue': 'b0e0e6',
  11083. 'purple': '800080',
  11084. 'rebeccapurple': '639',
  11085. 'red': 'f00',
  11086. 'rosybrown': 'bc8f8f',
  11087. 'royalblue': '4169e1',
  11088. 'saddlebrown': '8b4513',
  11089. 'salmon': 'fa8072',
  11090. 'sandybrown': 'f4a460',
  11091. 'seagreen': '2e8b57',
  11092. 'seashell': 'fff5ee',
  11093. 'sienna': 'a0522d',
  11094. 'silver': 'c0c0c0',
  11095. 'skyblue': '87ceeb',
  11096. 'slateblue': '6a5acd',
  11097. 'slategray': '708090',
  11098. 'slategrey': '708090',
  11099. 'snow': 'fffafa',
  11100. 'springgreen': '00ff7f',
  11101. 'steelblue': '4682b4',
  11102. 'tan': 'd2b48c',
  11103. 'teal': '008080',
  11104. 'thistle': 'd8bfd8',
  11105. 'tomato': 'ff6347',
  11106. 'turquoise': '40e0d0',
  11107. 'violet': 'ee82ee',
  11108. 'wheat': 'f5deb3',
  11109. 'white': 'fff',
  11110. 'whitesmoke': 'f5f5f5',
  11111. 'yellow': 'ff0',
  11112. 'yellowgreen': '9acd32'
  11113. };
  11114. var HEX_TO_NAME = {
  11115. '800000': 'maroon',
  11116. '800080': 'purple',
  11117. '808000': 'olive',
  11118. '808080': 'gray',
  11119. '00ffff': 'cyan',
  11120. 'f0ffff': 'azure',
  11121. 'f5f5dc': 'beige',
  11122. 'ffe4c4': 'bisque',
  11123. '000000': 'black',
  11124. '0000ff': 'blue',
  11125. 'a52a2a': 'brown',
  11126. 'ff7f50': 'coral',
  11127. 'ffd700': 'gold',
  11128. '008000': 'green',
  11129. '4b0082': 'indigo',
  11130. 'fffff0': 'ivory',
  11131. 'f0e68c': 'khaki',
  11132. '00ff00': 'lime',
  11133. 'faf0e6': 'linen',
  11134. '000080': 'navy',
  11135. 'ffa500': 'orange',
  11136. 'da70d6': 'orchid',
  11137. 'cd853f': 'peru',
  11138. 'ffc0cb': 'pink',
  11139. 'dda0dd': 'plum',
  11140. 'f00': 'red',
  11141. 'ff0000': 'red',
  11142. 'fa8072': 'salmon',
  11143. 'a0522d': 'sienna',
  11144. 'c0c0c0': 'silver',
  11145. 'fffafa': 'snow',
  11146. 'd2b48c': 'tan',
  11147. '008080': 'teal',
  11148. 'ff6347': 'tomato',
  11149. 'ee82ee': 'violet',
  11150. 'f5deb3': 'wheat',
  11151. 'ffffff': 'white',
  11152. 'ffff00': 'yellow'
  11153. };
  11154. function hueToRgb(p, q, t) {
  11155. if (t < 0) {
  11156. t += 1;
  11157. }
  11158. if (t > 1) {
  11159. t -= 1;
  11160. }
  11161. if (t < 1 / 6) {
  11162. return p + (q - p) * 6 * t;
  11163. }
  11164. if (t < 1 / 2) {
  11165. return q;
  11166. }
  11167. if (t < 2 / 3) {
  11168. return p + (q - p) * (2 / 3 - t) * 6;
  11169. }
  11170. return p;
  11171. }
  11172. function hslToRgb(h, s, l, a) {
  11173. var r;
  11174. var g;
  11175. var b;
  11176. if (s === 0) {
  11177. r = g = b = l; // achromatic
  11178. } else {
  11179. var q = l < 0.5 ? l * (1 + s) : l + s - l * s;
  11180. var p = 2 * l - q;
  11181. r = hueToRgb(p, q, h + 1 / 3);
  11182. g = hueToRgb(p, q, h);
  11183. b = hueToRgb(p, q, h - 1 / 3);
  11184. }
  11185. return [
  11186. Math.round(r * 255),
  11187. Math.round(g * 255),
  11188. Math.round(b * 255),
  11189. a
  11190. ];
  11191. }
  11192. function toHex(value) {
  11193. value = value.toString(16);
  11194. return value.length === 1 ? '0' + value : value;
  11195. }
  11196. function parseFunctionArgs(functionArgs, count, rgb) {
  11197. var cursor = functionArgs.head;
  11198. var args = [];
  11199. var wasValue = false;
  11200. while (cursor !== null) {
  11201. var node = cursor.data;
  11202. var type = node.type;
  11203. switch (type) {
  11204. case 'Number':
  11205. case 'Percentage':
  11206. if (wasValue) {
  11207. return;
  11208. }
  11209. wasValue = true;
  11210. args.push({
  11211. type: type,
  11212. value: Number(node.value)
  11213. });
  11214. break;
  11215. case 'Operator':
  11216. if (node.value === ',') {
  11217. if (!wasValue) {
  11218. return;
  11219. }
  11220. wasValue = false;
  11221. } else if (wasValue || node.value !== '+') {
  11222. return;
  11223. }
  11224. break;
  11225. default:
  11226. // something we couldn't understand
  11227. return;
  11228. }
  11229. cursor = cursor.next;
  11230. }
  11231. if (args.length !== count) {
  11232. // invalid arguments count
  11233. // TODO: remove those tokens
  11234. return;
  11235. }
  11236. if (args.length === 4) {
  11237. if (args[3].type !== 'Number') {
  11238. // 4th argument should be a number
  11239. // TODO: remove those tokens
  11240. return;
  11241. }
  11242. args[3].type = 'Alpha';
  11243. }
  11244. if (rgb) {
  11245. if (args[0].type !== args[1].type || args[0].type !== args[2].type) {
  11246. // invalid color, numbers and percentage shouldn't be mixed
  11247. // TODO: remove those tokens
  11248. return;
  11249. }
  11250. } else {
  11251. if (args[0].type !== 'Number' ||
  11252. args[1].type !== 'Percentage' ||
  11253. args[2].type !== 'Percentage') {
  11254. // invalid color, for hsl values should be: number, percentage, percentage
  11255. // TODO: remove those tokens
  11256. return;
  11257. }
  11258. args[0].type = 'Angle';
  11259. }
  11260. return args.map(function(arg) {
  11261. var value = Math.max(0, arg.value);
  11262. switch (arg.type) {
  11263. case 'Number':
  11264. // fit value to [0..255] range
  11265. value = Math.min(value, 255);
  11266. break;
  11267. case 'Percentage':
  11268. // convert 0..100% to value in [0..255] range
  11269. value = Math.min(value, 100) / 100;
  11270. if (!rgb) {
  11271. return value;
  11272. }
  11273. value = 255 * value;
  11274. break;
  11275. case 'Angle':
  11276. // fit value to (-360..360) range
  11277. return (((value % 360) + 360) % 360) / 360;
  11278. case 'Alpha':
  11279. // fit value to [0..1] range
  11280. return Math.min(value, 1);
  11281. }
  11282. return Math.round(value);
  11283. });
  11284. }
  11285. function compressFunction(node, item, list) {
  11286. var functionName = node.name;
  11287. var args;
  11288. if (functionName === 'rgba' || functionName === 'hsla') {
  11289. args = parseFunctionArgs(node.children, 4, functionName === 'rgba');
  11290. if (!args) {
  11291. // something went wrong
  11292. return;
  11293. }
  11294. if (functionName === 'hsla') {
  11295. args = hslToRgb.apply(null, args);
  11296. node.name = 'rgba';
  11297. }
  11298. if (args[3] === 0) {
  11299. // try to replace `rgba(x, x, x, 0)` to `transparent`
  11300. // always replace `rgba(0, 0, 0, 0)` to `transparent`
  11301. // otherwise avoid replacement in gradients since it may break color transition
  11302. // http://stackoverflow.com/questions/11829410/css3-gradient-rendering-issues-from-transparent-to-white
  11303. var scopeFunctionName = this.function && this.function.name;
  11304. if ((args[0] === 0 && args[1] === 0 && args[2] === 0) ||
  11305. !/^(?:to|from|color-stop)$|gradient$/i.test(scopeFunctionName)) {
  11306. item.data = {
  11307. type: 'Identifier',
  11308. loc: node.loc,
  11309. name: 'transparent'
  11310. };
  11311. return;
  11312. }
  11313. }
  11314. if (args[3] !== 1) {
  11315. // replace argument values for normalized/interpolated
  11316. node.children.each(function(node, item, list) {
  11317. if (node.type === 'Operator') {
  11318. if (node.value !== ',') {
  11319. list.remove(item);
  11320. }
  11321. return;
  11322. }
  11323. item.data = {
  11324. type: 'Number',
  11325. loc: node.loc,
  11326. value: packNumber$3(args.shift(), null)
  11327. };
  11328. });
  11329. return;
  11330. }
  11331. // otherwise convert to rgb, i.e. rgba(255, 0, 0, 1) -> rgb(255, 0, 0)
  11332. functionName = 'rgb';
  11333. }
  11334. if (functionName === 'hsl') {
  11335. args = args || parseFunctionArgs(node.children, 3, false);
  11336. if (!args) {
  11337. // something went wrong
  11338. return;
  11339. }
  11340. // convert to rgb
  11341. args = hslToRgb.apply(null, args);
  11342. functionName = 'rgb';
  11343. }
  11344. if (functionName === 'rgb') {
  11345. args = args || parseFunctionArgs(node.children, 3, true);
  11346. if (!args) {
  11347. // something went wrong
  11348. return;
  11349. }
  11350. // check if color is not at the end and not followed by space
  11351. var next = item.next;
  11352. if (next && next.data.type !== 'WhiteSpace') {
  11353. list.insert(list.createItem({
  11354. type: 'WhiteSpace',
  11355. value: ' '
  11356. }), next);
  11357. }
  11358. item.data = {
  11359. type: 'HexColor',
  11360. loc: node.loc,
  11361. value: toHex(args[0]) + toHex(args[1]) + toHex(args[2])
  11362. };
  11363. compressHex(item.data, item);
  11364. }
  11365. }
  11366. function compressIdent(node, item) {
  11367. if (this.declaration === null) {
  11368. return;
  11369. }
  11370. var color = node.name.toLowerCase();
  11371. if (NAME_TO_HEX.hasOwnProperty(color) &&
  11372. lexer$2.matchDeclaration(this.declaration).isType(node, 'color')) {
  11373. var hex = NAME_TO_HEX[color];
  11374. if (hex.length + 1 <= color.length) {
  11375. // replace for shorter hex value
  11376. item.data = {
  11377. type: 'HexColor',
  11378. loc: node.loc,
  11379. value: hex
  11380. };
  11381. } else {
  11382. // special case for consistent colors
  11383. if (color === 'grey') {
  11384. color = 'gray';
  11385. }
  11386. // just replace value for lower cased name
  11387. node.name = color;
  11388. }
  11389. }
  11390. }
  11391. function compressHex(node, item) {
  11392. var color = node.value.toLowerCase();
  11393. // #112233 -> #123
  11394. if (color.length === 6 &&
  11395. color[0] === color[1] &&
  11396. color[2] === color[3] &&
  11397. color[4] === color[5]) {
  11398. color = color[0] + color[2] + color[4];
  11399. }
  11400. if (HEX_TO_NAME[color]) {
  11401. item.data = {
  11402. type: 'Identifier',
  11403. loc: node.loc,
  11404. name: HEX_TO_NAME[color]
  11405. };
  11406. } else {
  11407. node.value = color;
  11408. }
  11409. }
  11410. var color = {
  11411. compressFunction: compressFunction,
  11412. compressIdent: compressIdent,
  11413. compressHex: compressHex
  11414. };
  11415. var walk$3 = lib.walk;
  11416. var handlers$2 = {
  11417. Atrule: Atrule$2,
  11418. AttributeSelector: AttributeSelector$1,
  11419. Value: Value$1,
  11420. Dimension: Dimension$1,
  11421. Percentage: Percentage$1,
  11422. Number: _Number$1,
  11423. String: _String$1,
  11424. Url: Url$1,
  11425. HexColor: color.compressHex,
  11426. Identifier: color.compressIdent,
  11427. Function: color.compressFunction
  11428. };
  11429. var replace = function(ast) {
  11430. walk$3(ast, {
  11431. leave: function(node, item, list) {
  11432. if (handlers$2.hasOwnProperty(node.type)) {
  11433. handlers$2[node.type].call(this, node, item, list);
  11434. }
  11435. }
  11436. });
  11437. };
  11438. var generate$1 = lib.generate;
  11439. function Index() {
  11440. this.seed = 0;
  11441. this.map = Object.create(null);
  11442. }
  11443. Index.prototype.resolve = function(str) {
  11444. var index = this.map[str];
  11445. if (!index) {
  11446. index = ++this.seed;
  11447. this.map[str] = index;
  11448. }
  11449. return index;
  11450. };
  11451. var createDeclarationIndexer = function createDeclarationIndexer() {
  11452. var ids = new Index();
  11453. return function markDeclaration(node) {
  11454. var id = generate$1(node);
  11455. node.id = ids.resolve(id);
  11456. node.length = id.length;
  11457. node.fingerprint = null;
  11458. return node;
  11459. };
  11460. };
  11461. var specificity = function specificity(simpleSelector) {
  11462. var A = 0;
  11463. var B = 0;
  11464. var C = 0;
  11465. simpleSelector.children.each(function walk(node) {
  11466. switch (node.type) {
  11467. case 'SelectorList':
  11468. case 'Selector':
  11469. node.children.each(walk);
  11470. break;
  11471. case 'IdSelector':
  11472. A++;
  11473. break;
  11474. case 'ClassSelector':
  11475. case 'AttributeSelector':
  11476. B++;
  11477. break;
  11478. case 'PseudoClassSelector':
  11479. switch (node.name.toLowerCase()) {
  11480. case 'not':
  11481. node.children.each(walk);
  11482. break;
  11483. case 'before':
  11484. case 'after':
  11485. case 'first-line':
  11486. case 'first-letter':
  11487. C++;
  11488. break;
  11489. // TODO: support for :nth-*(.. of <SelectorList>), :matches(), :has()
  11490. default:
  11491. B++;
  11492. }
  11493. break;
  11494. case 'PseudoElementSelector':
  11495. C++;
  11496. break;
  11497. case 'TypeSelector':
  11498. // ignore universal selector
  11499. if (node.name.charAt(node.name.length - 1) !== '*') {
  11500. C++;
  11501. }
  11502. break;
  11503. }
  11504. });
  11505. return [A, B, C];
  11506. };
  11507. var generate$2 = lib.generate;
  11508. var nonFreezePseudoElements = {
  11509. 'first-letter': true,
  11510. 'first-line': true,
  11511. 'after': true,
  11512. 'before': true
  11513. };
  11514. var nonFreezePseudoClasses = {
  11515. 'link': true,
  11516. 'visited': true,
  11517. 'hover': true,
  11518. 'active': true,
  11519. 'first-letter': true,
  11520. 'first-line': true,
  11521. 'after': true,
  11522. 'before': true
  11523. };
  11524. var processSelector = function freeze(node, usageData) {
  11525. var pseudos = Object.create(null);
  11526. var hasPseudo = false;
  11527. node.prelude.children.each(function(simpleSelector) {
  11528. var tagName = '*';
  11529. var scope = 0;
  11530. simpleSelector.children.each(function(node) {
  11531. switch (node.type) {
  11532. case 'ClassSelector':
  11533. if (usageData && usageData.scopes) {
  11534. var classScope = usageData.scopes[node.name] || 0;
  11535. if (scope !== 0 && classScope !== scope) {
  11536. throw new Error('Selector can\'t has classes from different scopes: ' + generate$2(simpleSelector));
  11537. }
  11538. scope = classScope;
  11539. }
  11540. break;
  11541. case 'PseudoClassSelector':
  11542. var name = node.name.toLowerCase();
  11543. if (!nonFreezePseudoClasses.hasOwnProperty(name)) {
  11544. pseudos[name] = true;
  11545. hasPseudo = true;
  11546. }
  11547. break;
  11548. case 'PseudoElementSelector':
  11549. var name = node.name.toLowerCase();
  11550. if (!nonFreezePseudoElements.hasOwnProperty(name)) {
  11551. pseudos[name] = true;
  11552. hasPseudo = true;
  11553. }
  11554. break;
  11555. case 'TypeSelector':
  11556. tagName = node.name.toLowerCase();
  11557. break;
  11558. case 'AttributeSelector':
  11559. if (node.flags) {
  11560. pseudos['[' + node.flags.toLowerCase() + ']'] = true;
  11561. hasPseudo = true;
  11562. }
  11563. break;
  11564. case 'WhiteSpace':
  11565. case 'Combinator':
  11566. tagName = '*';
  11567. break;
  11568. }
  11569. });
  11570. simpleSelector.compareMarker = specificity(simpleSelector).toString();
  11571. simpleSelector.id = null; // pre-init property to avoid multiple hidden class
  11572. simpleSelector.id = generate$2(simpleSelector);
  11573. if (scope) {
  11574. simpleSelector.compareMarker += ':' + scope;
  11575. }
  11576. if (tagName !== '*') {
  11577. simpleSelector.compareMarker += ',' + tagName;
  11578. }
  11579. });
  11580. // add property to all rule nodes to avoid multiple hidden class
  11581. node.pseudoSignature = hasPseudo && Object.keys(pseudos).sort().join(',');
  11582. };
  11583. var resolveKeyword$2 = lib.keyword;
  11584. var walk$4 = lib.walk;
  11585. var generate$3 = lib.generate;
  11586. var prepare = function prepare(ast, options) {
  11587. var markDeclaration = createDeclarationIndexer();
  11588. walk$4(ast, {
  11589. visit: 'Rule',
  11590. enter: function processRule(node) {
  11591. node.block.children.each(markDeclaration);
  11592. processSelector(node, options.usage);
  11593. }
  11594. });
  11595. walk$4(ast, {
  11596. visit: 'Atrule',
  11597. enter: function(node) {
  11598. if (node.prelude) {
  11599. node.prelude.id = null; // pre-init property to avoid multiple hidden class for generate
  11600. node.prelude.id = generate$3(node.prelude);
  11601. }
  11602. // compare keyframe selectors by its values
  11603. // NOTE: still no clarification about problems with keyframes selector grouping (issue #197)
  11604. if (resolveKeyword$2(node.name).basename === 'keyframes') {
  11605. node.block.avoidRulesMerge = true; /* probably we don't need to prevent those merges for @keyframes
  11606. TODO: need to be checked */
  11607. node.block.children.each(function(rule) {
  11608. rule.prelude.children.each(function(simpleselector) {
  11609. simpleselector.compareMarker = simpleselector.id;
  11610. });
  11611. });
  11612. }
  11613. }
  11614. });
  11615. return {
  11616. declaration: markDeclaration
  11617. };
  11618. };
  11619. var List$2 = lib.List;
  11620. var resolveKeyword$3 = lib.keyword;
  11621. var hasOwnProperty$8 = Object.prototype.hasOwnProperty;
  11622. var walk$5 = lib.walk;
  11623. function addRuleToMap(map, item, list, single) {
  11624. var node = item.data;
  11625. var name = resolveKeyword$3(node.name).basename;
  11626. var id = node.name.toLowerCase() + '/' + (node.prelude ? node.prelude.id : null);
  11627. if (!hasOwnProperty$8.call(map, name)) {
  11628. map[name] = Object.create(null);
  11629. }
  11630. if (single) {
  11631. delete map[name][id];
  11632. }
  11633. if (!hasOwnProperty$8.call(map[name], id)) {
  11634. map[name][id] = new List$2();
  11635. }
  11636. map[name][id].append(list.remove(item));
  11637. }
  11638. function relocateAtrules(ast, options) {
  11639. var collected = Object.create(null);
  11640. var topInjectPoint = null;
  11641. ast.children.each(function(node, item, list) {
  11642. if (node.type === 'Atrule') {
  11643. var name = resolveKeyword$3(node.name).basename;
  11644. switch (name) {
  11645. case 'keyframes':
  11646. addRuleToMap(collected, item, list, true);
  11647. return;
  11648. case 'media':
  11649. if (options.forceMediaMerge) {
  11650. addRuleToMap(collected, item, list, false);
  11651. return;
  11652. }
  11653. break;
  11654. }
  11655. if (topInjectPoint === null &&
  11656. name !== 'charset' &&
  11657. name !== 'import') {
  11658. topInjectPoint = item;
  11659. }
  11660. } else {
  11661. if (topInjectPoint === null) {
  11662. topInjectPoint = item;
  11663. }
  11664. }
  11665. });
  11666. for (var atrule in collected) {
  11667. for (var id in collected[atrule]) {
  11668. ast.children.insertList(
  11669. collected[atrule][id],
  11670. atrule === 'media' ? null : topInjectPoint
  11671. );
  11672. }
  11673. }
  11674. }
  11675. function isMediaRule(node) {
  11676. return node.type === 'Atrule' && node.name === 'media';
  11677. }
  11678. function processAtrule(node, item, list) {
  11679. if (!isMediaRule(node)) {
  11680. return;
  11681. }
  11682. var prev = item.prev && item.prev.data;
  11683. if (!prev || !isMediaRule(prev)) {
  11684. return;
  11685. }
  11686. // merge @media with same query
  11687. if (node.prelude &&
  11688. prev.prelude &&
  11689. node.prelude.id === prev.prelude.id) {
  11690. prev.block.children.appendList(node.block.children);
  11691. list.remove(item);
  11692. // TODO: use it when we can refer to several points in source
  11693. // prev.loc = {
  11694. // primary: prev.loc,
  11695. // merged: node.loc
  11696. // };
  11697. }
  11698. }
  11699. var _1MergeAtrule = function rejoinAtrule(ast, options) {
  11700. relocateAtrules(ast, options);
  11701. walk$5(ast, {
  11702. visit: 'Atrule',
  11703. reverse: true,
  11704. enter: processAtrule
  11705. });
  11706. };
  11707. var hasOwnProperty$9 = Object.prototype.hasOwnProperty;
  11708. function isEqualSelectors(a, b) {
  11709. var cursor1 = a.head;
  11710. var cursor2 = b.head;
  11711. while (cursor1 !== null && cursor2 !== null && cursor1.data.id === cursor2.data.id) {
  11712. cursor1 = cursor1.next;
  11713. cursor2 = cursor2.next;
  11714. }
  11715. return cursor1 === null && cursor2 === null;
  11716. }
  11717. function isEqualDeclarations(a, b) {
  11718. var cursor1 = a.head;
  11719. var cursor2 = b.head;
  11720. while (cursor1 !== null && cursor2 !== null && cursor1.data.id === cursor2.data.id) {
  11721. cursor1 = cursor1.next;
  11722. cursor2 = cursor2.next;
  11723. }
  11724. return cursor1 === null && cursor2 === null;
  11725. }
  11726. function compareDeclarations(declarations1, declarations2) {
  11727. var result = {
  11728. eq: [],
  11729. ne1: [],
  11730. ne2: [],
  11731. ne2overrided: []
  11732. };
  11733. var fingerprints = Object.create(null);
  11734. var declarations2hash = Object.create(null);
  11735. for (var cursor = declarations2.head; cursor; cursor = cursor.next) {
  11736. declarations2hash[cursor.data.id] = true;
  11737. }
  11738. for (var cursor = declarations1.head; cursor; cursor = cursor.next) {
  11739. var data = cursor.data;
  11740. if (data.fingerprint) {
  11741. fingerprints[data.fingerprint] = data.important;
  11742. }
  11743. if (declarations2hash[data.id]) {
  11744. declarations2hash[data.id] = false;
  11745. result.eq.push(data);
  11746. } else {
  11747. result.ne1.push(data);
  11748. }
  11749. }
  11750. for (var cursor = declarations2.head; cursor; cursor = cursor.next) {
  11751. var data = cursor.data;
  11752. if (declarations2hash[data.id]) {
  11753. // when declarations1 has an overriding declaration, this is not a difference
  11754. // unless no !important is used on prev and !important is used on the following
  11755. if (!hasOwnProperty$9.call(fingerprints, data.fingerprint) ||
  11756. (!fingerprints[data.fingerprint] && data.important)) {
  11757. result.ne2.push(data);
  11758. }
  11759. result.ne2overrided.push(data);
  11760. }
  11761. }
  11762. return result;
  11763. }
  11764. function addSelectors(dest, source) {
  11765. source.each(function(sourceData) {
  11766. var newStr = sourceData.id;
  11767. var cursor = dest.head;
  11768. while (cursor) {
  11769. var nextStr = cursor.data.id;
  11770. if (nextStr === newStr) {
  11771. return;
  11772. }
  11773. if (nextStr > newStr) {
  11774. break;
  11775. }
  11776. cursor = cursor.next;
  11777. }
  11778. dest.insert(dest.createItem(sourceData), cursor);
  11779. });
  11780. return dest;
  11781. }
  11782. // check if simpleselectors has no equal specificity and element selector
  11783. function hasSimilarSelectors(selectors1, selectors2) {
  11784. var cursor1 = selectors1.head;
  11785. while (cursor1 !== null) {
  11786. var cursor2 = selectors2.head;
  11787. while (cursor2 !== null) {
  11788. if (cursor1.data.compareMarker === cursor2.data.compareMarker) {
  11789. return true;
  11790. }
  11791. cursor2 = cursor2.next;
  11792. }
  11793. cursor1 = cursor1.next;
  11794. }
  11795. return false;
  11796. }
  11797. // test node can't to be skipped
  11798. function unsafeToSkipNode(node) {
  11799. switch (node.type) {
  11800. case 'Rule':
  11801. // unsafe skip ruleset with selector similarities
  11802. return hasSimilarSelectors(node.prelude.children, this);
  11803. case 'Atrule':
  11804. // can skip at-rules with blocks
  11805. if (node.block) {
  11806. // unsafe skip at-rule if block contains something unsafe to skip
  11807. return node.block.children.some(unsafeToSkipNode, this);
  11808. }
  11809. break;
  11810. case 'Declaration':
  11811. return false;
  11812. }
  11813. // unsafe by default
  11814. return true;
  11815. }
  11816. var utils$2 = {
  11817. isEqualSelectors: isEqualSelectors,
  11818. isEqualDeclarations: isEqualDeclarations,
  11819. compareDeclarations: compareDeclarations,
  11820. addSelectors: addSelectors,
  11821. hasSimilarSelectors: hasSimilarSelectors,
  11822. unsafeToSkipNode: unsafeToSkipNode
  11823. };
  11824. var walk$6 = lib.walk;
  11825. function processRule(node, item, list) {
  11826. var selectors = node.prelude.children;
  11827. var declarations = node.block.children;
  11828. list.prevUntil(item.prev, function(prev) {
  11829. // skip non-ruleset node if safe
  11830. if (prev.type !== 'Rule') {
  11831. return utils$2.unsafeToSkipNode.call(selectors, prev);
  11832. }
  11833. var prevSelectors = prev.prelude.children;
  11834. var prevDeclarations = prev.block.children;
  11835. // try to join rulesets with equal pseudo signature
  11836. if (node.pseudoSignature === prev.pseudoSignature) {
  11837. // try to join by selectors
  11838. if (utils$2.isEqualSelectors(prevSelectors, selectors)) {
  11839. prevDeclarations.appendList(declarations);
  11840. list.remove(item);
  11841. return true;
  11842. }
  11843. // try to join by declarations
  11844. if (utils$2.isEqualDeclarations(declarations, prevDeclarations)) {
  11845. utils$2.addSelectors(prevSelectors, selectors);
  11846. list.remove(item);
  11847. return true;
  11848. }
  11849. }
  11850. // go to prev ruleset if has no selector similarities
  11851. return utils$2.hasSimilarSelectors(selectors, prevSelectors);
  11852. });
  11853. }
  11854. // NOTE: direction should be left to right, since rulesets merge to left
  11855. // ruleset. When direction right to left unmerged rulesets may prevent lookup
  11856. // TODO: remove initial merge
  11857. var _2InitialMergeRuleset = function initialMergeRule(ast) {
  11858. walk$6(ast, {
  11859. visit: 'Rule',
  11860. enter: processRule
  11861. });
  11862. };
  11863. var List$3 = lib.List;
  11864. var walk$7 = lib.walk;
  11865. function processRule$1(node, item, list) {
  11866. var selectors = node.prelude.children;
  11867. // generate new rule sets:
  11868. // .a, .b { color: red; }
  11869. // ->
  11870. // .a { color: red; }
  11871. // .b { color: red; }
  11872. // while there are more than 1 simple selector split for rulesets
  11873. while (selectors.head !== selectors.tail) {
  11874. var newSelectors = new List$3();
  11875. newSelectors.insert(selectors.remove(selectors.head));
  11876. list.insert(list.createItem({
  11877. type: 'Rule',
  11878. loc: node.loc,
  11879. prelude: {
  11880. type: 'SelectorList',
  11881. loc: node.prelude.loc,
  11882. children: newSelectors
  11883. },
  11884. block: {
  11885. type: 'Block',
  11886. loc: node.block.loc,
  11887. children: node.block.children.copy()
  11888. },
  11889. pseudoSignature: node.pseudoSignature
  11890. }), item);
  11891. }
  11892. }
  11893. var _3DisjoinRuleset = function disjoinRule(ast) {
  11894. walk$7(ast, {
  11895. visit: 'Rule',
  11896. reverse: true,
  11897. enter: processRule$1
  11898. });
  11899. };
  11900. var List$4 = lib.List;
  11901. var generate$4 = lib.generate;
  11902. var walk$8 = lib.walk;
  11903. var REPLACE = 1;
  11904. var REMOVE = 2;
  11905. var TOP = 0;
  11906. var RIGHT = 1;
  11907. var BOTTOM = 2;
  11908. var LEFT = 3;
  11909. var SIDES = ['top', 'right', 'bottom', 'left'];
  11910. var SIDE = {
  11911. 'margin-top': 'top',
  11912. 'margin-right': 'right',
  11913. 'margin-bottom': 'bottom',
  11914. 'margin-left': 'left',
  11915. 'padding-top': 'top',
  11916. 'padding-right': 'right',
  11917. 'padding-bottom': 'bottom',
  11918. 'padding-left': 'left',
  11919. 'border-top-color': 'top',
  11920. 'border-right-color': 'right',
  11921. 'border-bottom-color': 'bottom',
  11922. 'border-left-color': 'left',
  11923. 'border-top-width': 'top',
  11924. 'border-right-width': 'right',
  11925. 'border-bottom-width': 'bottom',
  11926. 'border-left-width': 'left',
  11927. 'border-top-style': 'top',
  11928. 'border-right-style': 'right',
  11929. 'border-bottom-style': 'bottom',
  11930. 'border-left-style': 'left'
  11931. };
  11932. var MAIN_PROPERTY = {
  11933. 'margin': 'margin',
  11934. 'margin-top': 'margin',
  11935. 'margin-right': 'margin',
  11936. 'margin-bottom': 'margin',
  11937. 'margin-left': 'margin',
  11938. 'padding': 'padding',
  11939. 'padding-top': 'padding',
  11940. 'padding-right': 'padding',
  11941. 'padding-bottom': 'padding',
  11942. 'padding-left': 'padding',
  11943. 'border-color': 'border-color',
  11944. 'border-top-color': 'border-color',
  11945. 'border-right-color': 'border-color',
  11946. 'border-bottom-color': 'border-color',
  11947. 'border-left-color': 'border-color',
  11948. 'border-width': 'border-width',
  11949. 'border-top-width': 'border-width',
  11950. 'border-right-width': 'border-width',
  11951. 'border-bottom-width': 'border-width',
  11952. 'border-left-width': 'border-width',
  11953. 'border-style': 'border-style',
  11954. 'border-top-style': 'border-style',
  11955. 'border-right-style': 'border-style',
  11956. 'border-bottom-style': 'border-style',
  11957. 'border-left-style': 'border-style'
  11958. };
  11959. function TRBL(name) {
  11960. this.name = name;
  11961. this.loc = null;
  11962. this.iehack = undefined;
  11963. this.sides = {
  11964. 'top': null,
  11965. 'right': null,
  11966. 'bottom': null,
  11967. 'left': null
  11968. };
  11969. }
  11970. TRBL.prototype.getValueSequence = function(declaration, count) {
  11971. var values = [];
  11972. var iehack = '';
  11973. var hasBadValues = declaration.value.children.some(function(child) {
  11974. var special = false;
  11975. switch (child.type) {
  11976. case 'Identifier':
  11977. switch (child.name) {
  11978. case '\\0':
  11979. case '\\9':
  11980. iehack = child.name;
  11981. return;
  11982. case 'inherit':
  11983. case 'initial':
  11984. case 'unset':
  11985. case 'revert':
  11986. special = child.name;
  11987. break;
  11988. }
  11989. break;
  11990. case 'Dimension':
  11991. switch (child.unit) {
  11992. // is not supported until IE11
  11993. case 'rem':
  11994. // v* units is too buggy across browsers and better
  11995. // don't merge values with those units
  11996. case 'vw':
  11997. case 'vh':
  11998. case 'vmin':
  11999. case 'vmax':
  12000. case 'vm': // IE9 supporting "vm" instead of "vmin".
  12001. special = child.unit;
  12002. break;
  12003. }
  12004. break;
  12005. case 'HexColor': // color
  12006. case 'Number':
  12007. case 'Percentage':
  12008. break;
  12009. case 'Function':
  12010. special = child.name;
  12011. break;
  12012. case 'WhiteSpace':
  12013. return false; // ignore space
  12014. default:
  12015. return true; // bad value
  12016. }
  12017. values.push({
  12018. node: child,
  12019. special: special,
  12020. important: declaration.important
  12021. });
  12022. });
  12023. if (hasBadValues || values.length > count) {
  12024. return false;
  12025. }
  12026. if (typeof this.iehack === 'string' && this.iehack !== iehack) {
  12027. return false;
  12028. }
  12029. this.iehack = iehack; // move outside
  12030. return values;
  12031. };
  12032. TRBL.prototype.canOverride = function(side, value) {
  12033. var currentValue = this.sides[side];
  12034. return !currentValue || (value.important && !currentValue.important);
  12035. };
  12036. TRBL.prototype.add = function(name, declaration) {
  12037. function attemptToAdd() {
  12038. var sides = this.sides;
  12039. var side = SIDE[name];
  12040. if (side) {
  12041. if (side in sides === false) {
  12042. return false;
  12043. }
  12044. var values = this.getValueSequence(declaration, 1);
  12045. if (!values || !values.length) {
  12046. return false;
  12047. }
  12048. // can mix only if specials are equal
  12049. for (var key in sides) {
  12050. if (sides[key] !== null && sides[key].special !== values[0].special) {
  12051. return false;
  12052. }
  12053. }
  12054. if (!this.canOverride(side, values[0])) {
  12055. return true;
  12056. }
  12057. sides[side] = values[0];
  12058. return true;
  12059. } else if (name === this.name) {
  12060. var values = this.getValueSequence(declaration, 4);
  12061. if (!values || !values.length) {
  12062. return false;
  12063. }
  12064. switch (values.length) {
  12065. case 1:
  12066. values[RIGHT] = values[TOP];
  12067. values[BOTTOM] = values[TOP];
  12068. values[LEFT] = values[TOP];
  12069. break;
  12070. case 2:
  12071. values[BOTTOM] = values[TOP];
  12072. values[LEFT] = values[RIGHT];
  12073. break;
  12074. case 3:
  12075. values[LEFT] = values[RIGHT];
  12076. break;
  12077. }
  12078. // can mix only if specials are equal
  12079. for (var i = 0; i < 4; i++) {
  12080. for (var key in sides) {
  12081. if (sides[key] !== null && sides[key].special !== values[i].special) {
  12082. return false;
  12083. }
  12084. }
  12085. }
  12086. for (var i = 0; i < 4; i++) {
  12087. if (this.canOverride(SIDES[i], values[i])) {
  12088. sides[SIDES[i]] = values[i];
  12089. }
  12090. }
  12091. return true;
  12092. }
  12093. }
  12094. if (!attemptToAdd.call(this)) {
  12095. return false;
  12096. }
  12097. // TODO: use it when we can refer to several points in source
  12098. // if (this.loc) {
  12099. // this.loc = {
  12100. // primary: this.loc,
  12101. // merged: declaration.loc
  12102. // };
  12103. // } else {
  12104. // this.loc = declaration.loc;
  12105. // }
  12106. if (!this.loc) {
  12107. this.loc = declaration.loc;
  12108. }
  12109. return true;
  12110. };
  12111. TRBL.prototype.isOkToMinimize = function() {
  12112. var top = this.sides.top;
  12113. var right = this.sides.right;
  12114. var bottom = this.sides.bottom;
  12115. var left = this.sides.left;
  12116. if (top && right && bottom && left) {
  12117. var important =
  12118. top.important +
  12119. right.important +
  12120. bottom.important +
  12121. left.important;
  12122. return important === 0 || important === 4;
  12123. }
  12124. return false;
  12125. };
  12126. TRBL.prototype.getValue = function() {
  12127. var result = new List$4();
  12128. var sides = this.sides;
  12129. var values = [
  12130. sides.top,
  12131. sides.right,
  12132. sides.bottom,
  12133. sides.left
  12134. ];
  12135. var stringValues = [
  12136. generate$4(sides.top.node),
  12137. generate$4(sides.right.node),
  12138. generate$4(sides.bottom.node),
  12139. generate$4(sides.left.node)
  12140. ];
  12141. if (stringValues[LEFT] === stringValues[RIGHT]) {
  12142. values.pop();
  12143. if (stringValues[BOTTOM] === stringValues[TOP]) {
  12144. values.pop();
  12145. if (stringValues[RIGHT] === stringValues[TOP]) {
  12146. values.pop();
  12147. }
  12148. }
  12149. }
  12150. for (var i = 0; i < values.length; i++) {
  12151. if (i) {
  12152. result.appendData({ type: 'WhiteSpace', value: ' ' });
  12153. }
  12154. result.appendData(values[i].node);
  12155. }
  12156. if (this.iehack) {
  12157. result.appendData({ type: 'WhiteSpace', value: ' ' });
  12158. result.appendData({
  12159. type: 'Identifier',
  12160. loc: null,
  12161. name: this.iehack
  12162. });
  12163. }
  12164. return {
  12165. type: 'Value',
  12166. loc: null,
  12167. children: result
  12168. };
  12169. };
  12170. TRBL.prototype.getDeclaration = function() {
  12171. return {
  12172. type: 'Declaration',
  12173. loc: this.loc,
  12174. important: this.sides.top.important,
  12175. property: this.name,
  12176. value: this.getValue()
  12177. };
  12178. };
  12179. function processRule$2(rule, shorts, shortDeclarations, lastShortSelector) {
  12180. var declarations = rule.block.children;
  12181. var selector = rule.prelude.children.first().id;
  12182. rule.block.children.eachRight(function(declaration, item) {
  12183. var property = declaration.property;
  12184. if (!MAIN_PROPERTY.hasOwnProperty(property)) {
  12185. return;
  12186. }
  12187. var key = MAIN_PROPERTY[property];
  12188. var shorthand;
  12189. var operation;
  12190. if (!lastShortSelector || selector === lastShortSelector) {
  12191. if (key in shorts) {
  12192. operation = REMOVE;
  12193. shorthand = shorts[key];
  12194. }
  12195. }
  12196. if (!shorthand || !shorthand.add(property, declaration)) {
  12197. operation = REPLACE;
  12198. shorthand = new TRBL(key);
  12199. // if can't parse value ignore it and break shorthand children
  12200. if (!shorthand.add(property, declaration)) {
  12201. lastShortSelector = null;
  12202. return;
  12203. }
  12204. }
  12205. shorts[key] = shorthand;
  12206. shortDeclarations.push({
  12207. operation: operation,
  12208. block: declarations,
  12209. item: item,
  12210. shorthand: shorthand
  12211. });
  12212. lastShortSelector = selector;
  12213. });
  12214. return lastShortSelector;
  12215. }
  12216. function processShorthands(shortDeclarations, markDeclaration) {
  12217. shortDeclarations.forEach(function(item) {
  12218. var shorthand = item.shorthand;
  12219. if (!shorthand.isOkToMinimize()) {
  12220. return;
  12221. }
  12222. if (item.operation === REPLACE) {
  12223. item.item.data = markDeclaration(shorthand.getDeclaration());
  12224. } else {
  12225. item.block.remove(item.item);
  12226. }
  12227. });
  12228. }
  12229. var _4RestructShorthand = function restructBlock(ast, indexer) {
  12230. var stylesheetMap = {};
  12231. var shortDeclarations = [];
  12232. walk$8(ast, {
  12233. visit: 'Rule',
  12234. reverse: true,
  12235. enter: function(node) {
  12236. var stylesheet = this.block || this.stylesheet;
  12237. var ruleId = (node.pseudoSignature || '') + '|' + node.prelude.children.first().id;
  12238. var ruleMap;
  12239. var shorts;
  12240. if (!stylesheetMap.hasOwnProperty(stylesheet.id)) {
  12241. ruleMap = {
  12242. lastShortSelector: null
  12243. };
  12244. stylesheetMap[stylesheet.id] = ruleMap;
  12245. } else {
  12246. ruleMap = stylesheetMap[stylesheet.id];
  12247. }
  12248. if (ruleMap.hasOwnProperty(ruleId)) {
  12249. shorts = ruleMap[ruleId];
  12250. } else {
  12251. shorts = {};
  12252. ruleMap[ruleId] = shorts;
  12253. }
  12254. ruleMap.lastShortSelector = processRule$2.call(this, node, shorts, shortDeclarations, ruleMap.lastShortSelector);
  12255. }
  12256. });
  12257. processShorthands(shortDeclarations, indexer.declaration);
  12258. };
  12259. var resolveProperty = lib.property;
  12260. var resolveKeyword$4 = lib.keyword;
  12261. var walk$9 = lib.walk;
  12262. var generate$5 = lib.generate;
  12263. var fingerprintId = 1;
  12264. var dontRestructure = {
  12265. 'src': 1 // https://github.com/afelix/csso/issues/50
  12266. };
  12267. var DONT_MIX_VALUE = {
  12268. // https://developer.mozilla.org/en-US/docs/Web/CSS/display#Browser_compatibility
  12269. 'display': /table|ruby|flex|-(flex)?box$|grid|contents|run-in/i,
  12270. // https://developer.mozilla.org/en/docs/Web/CSS/text-align
  12271. 'text-align': /^(start|end|match-parent|justify-all)$/i
  12272. };
  12273. var CURSOR_SAFE_VALUE = [
  12274. 'auto', 'crosshair', 'default', 'move', 'text', 'wait', 'help',
  12275. 'n-resize', 'e-resize', 's-resize', 'w-resize',
  12276. 'ne-resize', 'nw-resize', 'se-resize', 'sw-resize',
  12277. 'pointer', 'progress', 'not-allowed', 'no-drop', 'vertical-text', 'all-scroll',
  12278. 'col-resize', 'row-resize'
  12279. ];
  12280. var POSITION_SAFE_VALUE = [
  12281. 'static', 'relative', 'absolute', 'fixed'
  12282. ];
  12283. var NEEDLESS_TABLE = {
  12284. 'border-width': ['border'],
  12285. 'border-style': ['border'],
  12286. 'border-color': ['border'],
  12287. 'border-top': ['border'],
  12288. 'border-right': ['border'],
  12289. 'border-bottom': ['border'],
  12290. 'border-left': ['border'],
  12291. 'border-top-width': ['border-top', 'border-width', 'border'],
  12292. 'border-right-width': ['border-right', 'border-width', 'border'],
  12293. 'border-bottom-width': ['border-bottom', 'border-width', 'border'],
  12294. 'border-left-width': ['border-left', 'border-width', 'border'],
  12295. 'border-top-style': ['border-top', 'border-style', 'border'],
  12296. 'border-right-style': ['border-right', 'border-style', 'border'],
  12297. 'border-bottom-style': ['border-bottom', 'border-style', 'border'],
  12298. 'border-left-style': ['border-left', 'border-style', 'border'],
  12299. 'border-top-color': ['border-top', 'border-color', 'border'],
  12300. 'border-right-color': ['border-right', 'border-color', 'border'],
  12301. 'border-bottom-color': ['border-bottom', 'border-color', 'border'],
  12302. 'border-left-color': ['border-left', 'border-color', 'border'],
  12303. 'margin-top': ['margin'],
  12304. 'margin-right': ['margin'],
  12305. 'margin-bottom': ['margin'],
  12306. 'margin-left': ['margin'],
  12307. 'padding-top': ['padding'],
  12308. 'padding-right': ['padding'],
  12309. 'padding-bottom': ['padding'],
  12310. 'padding-left': ['padding'],
  12311. 'font-style': ['font'],
  12312. 'font-variant': ['font'],
  12313. 'font-weight': ['font'],
  12314. 'font-size': ['font'],
  12315. 'font-family': ['font'],
  12316. 'list-style-type': ['list-style'],
  12317. 'list-style-position': ['list-style'],
  12318. 'list-style-image': ['list-style']
  12319. };
  12320. function getPropertyFingerprint(propertyName, declaration, fingerprints) {
  12321. var realName = resolveProperty(propertyName).basename;
  12322. if (realName === 'background') {
  12323. return propertyName + ':' + generate$5(declaration.value);
  12324. }
  12325. var declarationId = declaration.id;
  12326. var fingerprint = fingerprints[declarationId];
  12327. if (!fingerprint) {
  12328. switch (declaration.value.type) {
  12329. case 'Value':
  12330. var vendorId = '';
  12331. var iehack = '';
  12332. var special = {};
  12333. var raw = false;
  12334. declaration.value.children.each(function walk(node) {
  12335. switch (node.type) {
  12336. case 'Value':
  12337. case 'Brackets':
  12338. case 'Parentheses':
  12339. node.children.each(walk);
  12340. break;
  12341. case 'Raw':
  12342. raw = true;
  12343. break;
  12344. case 'Identifier':
  12345. var name = node.name;
  12346. if (!vendorId) {
  12347. vendorId = resolveKeyword$4(name).vendor;
  12348. }
  12349. if (/\\[09]/.test(name)) {
  12350. iehack = RegExp.lastMatch;
  12351. }
  12352. if (realName === 'cursor') {
  12353. if (CURSOR_SAFE_VALUE.indexOf(name) === -1) {
  12354. special[name] = true;
  12355. }
  12356. } else if (realName === 'position') {
  12357. if (POSITION_SAFE_VALUE.indexOf(name) === -1) {
  12358. special[name] = true;
  12359. }
  12360. } else if (DONT_MIX_VALUE.hasOwnProperty(realName)) {
  12361. if (DONT_MIX_VALUE[realName].test(name)) {
  12362. special[name] = true;
  12363. }
  12364. }
  12365. break;
  12366. case 'Function':
  12367. var name = node.name;
  12368. if (!vendorId) {
  12369. vendorId = resolveKeyword$4(name).vendor;
  12370. }
  12371. if (name === 'rect') {
  12372. // there are 2 forms of rect:
  12373. // rect(<top>, <right>, <bottom>, <left>) - standart
  12374. // rect(<top> <right> <bottom> <left>) – backwards compatible syntax
  12375. // only the same form values can be merged
  12376. var hasComma = node.children.some(function(node) {
  12377. return node.type === 'Operator' && node.value === ',';
  12378. });
  12379. if (!hasComma) {
  12380. name = 'rect-backward';
  12381. }
  12382. }
  12383. special[name + '()'] = true;
  12384. // check nested tokens too
  12385. node.children.each(walk);
  12386. break;
  12387. case 'Dimension':
  12388. var unit = node.unit;
  12389. if (/\\[09]/.test(unit)) {
  12390. iehack = RegExp.lastMatch;
  12391. }
  12392. switch (unit) {
  12393. // is not supported until IE11
  12394. case 'rem':
  12395. // v* units is too buggy across browsers and better
  12396. // don't merge values with those units
  12397. case 'vw':
  12398. case 'vh':
  12399. case 'vmin':
  12400. case 'vmax':
  12401. case 'vm': // IE9 supporting "vm" instead of "vmin".
  12402. special[unit] = true;
  12403. break;
  12404. }
  12405. break;
  12406. }
  12407. });
  12408. fingerprint = raw
  12409. ? '!' + fingerprintId++
  12410. : '!' + Object.keys(special).sort() + '|' + iehack + vendorId;
  12411. break;
  12412. case 'Raw':
  12413. fingerprint = '!' + declaration.value.value;
  12414. break;
  12415. default:
  12416. fingerprint = generate$5(declaration.value);
  12417. }
  12418. fingerprints[declarationId] = fingerprint;
  12419. }
  12420. return propertyName + fingerprint;
  12421. }
  12422. function needless(props, declaration, fingerprints) {
  12423. var property = resolveProperty(declaration.property);
  12424. if (NEEDLESS_TABLE.hasOwnProperty(property.basename)) {
  12425. var table = NEEDLESS_TABLE[property.basename];
  12426. for (var i = 0; i < table.length; i++) {
  12427. var ppre = getPropertyFingerprint(property.prefix + table[i], declaration, fingerprints);
  12428. var prev = props.hasOwnProperty(ppre) ? props[ppre] : null;
  12429. if (prev && (!declaration.important || prev.item.data.important)) {
  12430. return prev;
  12431. }
  12432. }
  12433. }
  12434. }
  12435. function processRule$3(rule, item, list, props, fingerprints) {
  12436. var declarations = rule.block.children;
  12437. declarations.eachRight(function(declaration, declarationItem) {
  12438. var property = declaration.property;
  12439. var fingerprint = getPropertyFingerprint(property, declaration, fingerprints);
  12440. var prev = props[fingerprint];
  12441. if (prev && !dontRestructure.hasOwnProperty(property)) {
  12442. if (declaration.important && !prev.item.data.important) {
  12443. props[fingerprint] = {
  12444. block: declarations,
  12445. item: declarationItem
  12446. };
  12447. prev.block.remove(prev.item);
  12448. // TODO: use it when we can refer to several points in source
  12449. // declaration.loc = {
  12450. // primary: declaration.loc,
  12451. // merged: prev.item.data.loc
  12452. // };
  12453. } else {
  12454. declarations.remove(declarationItem);
  12455. // TODO: use it when we can refer to several points in source
  12456. // prev.item.data.loc = {
  12457. // primary: prev.item.data.loc,
  12458. // merged: declaration.loc
  12459. // };
  12460. }
  12461. } else {
  12462. var prev = needless(props, declaration, fingerprints);
  12463. if (prev) {
  12464. declarations.remove(declarationItem);
  12465. // TODO: use it when we can refer to several points in source
  12466. // prev.item.data.loc = {
  12467. // primary: prev.item.data.loc,
  12468. // merged: declaration.loc
  12469. // };
  12470. } else {
  12471. declaration.fingerprint = fingerprint;
  12472. props[fingerprint] = {
  12473. block: declarations,
  12474. item: declarationItem
  12475. };
  12476. }
  12477. }
  12478. });
  12479. if (declarations.isEmpty()) {
  12480. list.remove(item);
  12481. }
  12482. }
  12483. var _6RestructBlock = function restructBlock(ast) {
  12484. var stylesheetMap = {};
  12485. var fingerprints = Object.create(null);
  12486. walk$9(ast, {
  12487. visit: 'Rule',
  12488. reverse: true,
  12489. enter: function(node, item, list) {
  12490. var stylesheet = this.block || this.stylesheet;
  12491. var ruleId = (node.pseudoSignature || '') + '|' + node.prelude.children.first().id;
  12492. var ruleMap;
  12493. var props;
  12494. if (!stylesheetMap.hasOwnProperty(stylesheet.id)) {
  12495. ruleMap = {};
  12496. stylesheetMap[stylesheet.id] = ruleMap;
  12497. } else {
  12498. ruleMap = stylesheetMap[stylesheet.id];
  12499. }
  12500. if (ruleMap.hasOwnProperty(ruleId)) {
  12501. props = ruleMap[ruleId];
  12502. } else {
  12503. props = {};
  12504. ruleMap[ruleId] = props;
  12505. }
  12506. processRule$3.call(this, node, item, list, props, fingerprints);
  12507. }
  12508. });
  12509. };
  12510. var walk$a = lib.walk;
  12511. /*
  12512. At this step all rules has single simple selector. We try to join by equal
  12513. declaration blocks to first rule, e.g.
  12514. .a { color: red }
  12515. b { ... }
  12516. .b { color: red }
  12517. ->
  12518. .a, .b { color: red }
  12519. b { ... }
  12520. */
  12521. function processRule$4(node, item, list) {
  12522. var selectors = node.prelude.children;
  12523. var declarations = node.block.children;
  12524. var nodeCompareMarker = selectors.first().compareMarker;
  12525. var skippedCompareMarkers = {};
  12526. list.nextUntil(item.next, function(next, nextItem) {
  12527. // skip non-ruleset node if safe
  12528. if (next.type !== 'Rule') {
  12529. return utils$2.unsafeToSkipNode.call(selectors, next);
  12530. }
  12531. if (node.pseudoSignature !== next.pseudoSignature) {
  12532. return true;
  12533. }
  12534. var nextFirstSelector = next.prelude.children.head;
  12535. var nextDeclarations = next.block.children;
  12536. var nextCompareMarker = nextFirstSelector.data.compareMarker;
  12537. // if next ruleset has same marked as one of skipped then stop joining
  12538. if (nextCompareMarker in skippedCompareMarkers) {
  12539. return true;
  12540. }
  12541. // try to join by selectors
  12542. if (selectors.head === selectors.tail) {
  12543. if (selectors.first().id === nextFirstSelector.data.id) {
  12544. declarations.appendList(nextDeclarations);
  12545. list.remove(nextItem);
  12546. return;
  12547. }
  12548. }
  12549. // try to join by properties
  12550. if (utils$2.isEqualDeclarations(declarations, nextDeclarations)) {
  12551. var nextStr = nextFirstSelector.data.id;
  12552. selectors.some(function(data, item) {
  12553. var curStr = data.id;
  12554. if (nextStr < curStr) {
  12555. selectors.insert(nextFirstSelector, item);
  12556. return true;
  12557. }
  12558. if (!item.next) {
  12559. selectors.insert(nextFirstSelector);
  12560. return true;
  12561. }
  12562. });
  12563. list.remove(nextItem);
  12564. return;
  12565. }
  12566. // go to next ruleset if current one can be skipped (has no equal specificity nor element selector)
  12567. if (nextCompareMarker === nodeCompareMarker) {
  12568. return true;
  12569. }
  12570. skippedCompareMarkers[nextCompareMarker] = true;
  12571. });
  12572. }
  12573. var _7MergeRuleset = function mergeRule(ast) {
  12574. walk$a(ast, {
  12575. visit: 'Rule',
  12576. enter: processRule$4
  12577. });
  12578. };
  12579. var List$5 = lib.List;
  12580. var walk$b = lib.walk;
  12581. function calcSelectorLength(list) {
  12582. var length = 0;
  12583. list.each(function(data) {
  12584. length += data.id.length + 1;
  12585. });
  12586. return length - 1;
  12587. }
  12588. function calcDeclarationsLength(tokens) {
  12589. var length = 0;
  12590. for (var i = 0; i < tokens.length; i++) {
  12591. length += tokens[i].length;
  12592. }
  12593. return (
  12594. length + // declarations
  12595. tokens.length - 1 // delimeters
  12596. );
  12597. }
  12598. function processRule$5(node, item, list) {
  12599. var avoidRulesMerge = this.block !== null ? this.block.avoidRulesMerge : false;
  12600. var selectors = node.prelude.children;
  12601. var block = node.block;
  12602. var disallowDownMarkers = Object.create(null);
  12603. var allowMergeUp = true;
  12604. var allowMergeDown = true;
  12605. list.prevUntil(item.prev, function(prev, prevItem) {
  12606. var prevBlock = prev.block;
  12607. var prevType = prev.type;
  12608. if (prevType !== 'Rule') {
  12609. var unsafe = utils$2.unsafeToSkipNode.call(selectors, prev);
  12610. if (!unsafe && prevType === 'Atrule' && prevBlock) {
  12611. walk$b(prevBlock, {
  12612. visit: 'Rule',
  12613. enter: function(node) {
  12614. node.prelude.children.each(function(data) {
  12615. disallowDownMarkers[data.compareMarker] = true;
  12616. });
  12617. }
  12618. });
  12619. }
  12620. return unsafe;
  12621. }
  12622. var prevSelectors = prev.prelude.children;
  12623. if (node.pseudoSignature !== prev.pseudoSignature) {
  12624. return true;
  12625. }
  12626. allowMergeDown = !prevSelectors.some(function(selector) {
  12627. return selector.compareMarker in disallowDownMarkers;
  12628. });
  12629. // try prev ruleset if simpleselectors has no equal specifity and element selector
  12630. if (!allowMergeDown && !allowMergeUp) {
  12631. return true;
  12632. }
  12633. // try to join by selectors
  12634. if (allowMergeUp && utils$2.isEqualSelectors(prevSelectors, selectors)) {
  12635. prevBlock.children.appendList(block.children);
  12636. list.remove(item);
  12637. return true;
  12638. }
  12639. // try to join by properties
  12640. var diff = utils$2.compareDeclarations(block.children, prevBlock.children);
  12641. // console.log(diff.eq, diff.ne1, diff.ne2);
  12642. if (diff.eq.length) {
  12643. if (!diff.ne1.length && !diff.ne2.length) {
  12644. // equal blocks
  12645. if (allowMergeDown) {
  12646. utils$2.addSelectors(selectors, prevSelectors);
  12647. list.remove(prevItem);
  12648. }
  12649. return true;
  12650. } else if (!avoidRulesMerge) { /* probably we don't need to prevent those merges for @keyframes
  12651. TODO: need to be checked */
  12652. if (diff.ne1.length && !diff.ne2.length) {
  12653. // prevBlock is subset block
  12654. var selectorLength = calcSelectorLength(selectors);
  12655. var blockLength = calcDeclarationsLength(diff.eq); // declarations length
  12656. if (allowMergeUp && selectorLength < blockLength) {
  12657. utils$2.addSelectors(prevSelectors, selectors);
  12658. block.children = new List$5().fromArray(diff.ne1);
  12659. }
  12660. } else if (!diff.ne1.length && diff.ne2.length) {
  12661. // node is subset of prevBlock
  12662. var selectorLength = calcSelectorLength(prevSelectors);
  12663. var blockLength = calcDeclarationsLength(diff.eq); // declarations length
  12664. if (allowMergeDown && selectorLength < blockLength) {
  12665. utils$2.addSelectors(selectors, prevSelectors);
  12666. prevBlock.children = new List$5().fromArray(diff.ne2);
  12667. }
  12668. } else {
  12669. // diff.ne1.length && diff.ne2.length
  12670. // extract equal block
  12671. var newSelector = {
  12672. type: 'SelectorList',
  12673. loc: null,
  12674. children: utils$2.addSelectors(prevSelectors.copy(), selectors)
  12675. };
  12676. var newBlockLength = calcSelectorLength(newSelector.children) + 2; // selectors length + curly braces length
  12677. var blockLength = calcDeclarationsLength(diff.eq); // declarations length
  12678. // create new ruleset if declarations length greater than
  12679. // ruleset description overhead
  12680. if (blockLength >= newBlockLength) {
  12681. var newItem = list.createItem({
  12682. type: 'Rule',
  12683. loc: null,
  12684. prelude: newSelector,
  12685. block: {
  12686. type: 'Block',
  12687. loc: null,
  12688. children: new List$5().fromArray(diff.eq)
  12689. },
  12690. pseudoSignature: node.pseudoSignature
  12691. });
  12692. block.children = new List$5().fromArray(diff.ne1);
  12693. prevBlock.children = new List$5().fromArray(diff.ne2overrided);
  12694. if (allowMergeUp) {
  12695. list.insert(newItem, prevItem);
  12696. } else {
  12697. list.insert(newItem, item);
  12698. }
  12699. return true;
  12700. }
  12701. }
  12702. }
  12703. }
  12704. if (allowMergeUp) {
  12705. // TODO: disallow up merge only if any property interception only (i.e. diff.ne2overrided.length > 0);
  12706. // await property families to find property interception correctly
  12707. allowMergeUp = !prevSelectors.some(function(prevSelector) {
  12708. return selectors.some(function(selector) {
  12709. return selector.compareMarker === prevSelector.compareMarker;
  12710. });
  12711. });
  12712. }
  12713. prevSelectors.each(function(data) {
  12714. disallowDownMarkers[data.compareMarker] = true;
  12715. });
  12716. });
  12717. }
  12718. var _8RestructRuleset = function restructRule(ast) {
  12719. walk$b(ast, {
  12720. visit: 'Rule',
  12721. reverse: true,
  12722. enter: processRule$5
  12723. });
  12724. };
  12725. var restructure = function(ast, options) {
  12726. // prepare ast for restructing
  12727. var indexer = prepare(ast, options);
  12728. options.logger('prepare', ast);
  12729. _1MergeAtrule(ast, options);
  12730. options.logger('mergeAtrule', ast);
  12731. _2InitialMergeRuleset(ast);
  12732. options.logger('initialMergeRuleset', ast);
  12733. _3DisjoinRuleset(ast);
  12734. options.logger('disjoinRuleset', ast);
  12735. _4RestructShorthand(ast, indexer);
  12736. options.logger('restructShorthand', ast);
  12737. _6RestructBlock(ast);
  12738. options.logger('restructBlock', ast);
  12739. _7MergeRuleset(ast);
  12740. options.logger('mergeRuleset', ast);
  12741. _8RestructRuleset(ast);
  12742. options.logger('restructRuleset', ast);
  12743. };
  12744. var List$6 = lib.List;
  12745. var clone$1 = lib.clone;
  12746. var walk$c = lib.walk;
  12747. function readChunk(children, specialComments) {
  12748. var buffer = new List$6();
  12749. var nonSpaceTokenInBuffer = false;
  12750. var protectedComment;
  12751. children.nextUntil(children.head, function(node, item, list) {
  12752. if (node.type === 'Comment') {
  12753. if (!specialComments || node.value.charAt(0) !== '!') {
  12754. list.remove(item);
  12755. return;
  12756. }
  12757. if (nonSpaceTokenInBuffer || protectedComment) {
  12758. return true;
  12759. }
  12760. list.remove(item);
  12761. protectedComment = node;
  12762. return;
  12763. }
  12764. if (node.type !== 'WhiteSpace') {
  12765. nonSpaceTokenInBuffer = true;
  12766. }
  12767. buffer.insert(list.remove(item));
  12768. });
  12769. return {
  12770. comment: protectedComment,
  12771. stylesheet: {
  12772. type: 'StyleSheet',
  12773. loc: null,
  12774. children: buffer
  12775. }
  12776. };
  12777. }
  12778. function compressChunk(ast, firstAtrulesAllowed, num, options) {
  12779. options.logger('Compress block #' + num, null, true);
  12780. var seed = 1;
  12781. if (ast.type === 'StyleSheet') {
  12782. ast.firstAtrulesAllowed = firstAtrulesAllowed;
  12783. ast.id = seed++;
  12784. }
  12785. walk$c(ast, {
  12786. visit: 'Atrule',
  12787. enter: function markScopes(node) {
  12788. if (node.block !== null) {
  12789. node.block.id = seed++;
  12790. }
  12791. }
  12792. });
  12793. options.logger('init', ast);
  12794. // remove redundant
  12795. clean(ast, options);
  12796. options.logger('clean', ast);
  12797. // replace nodes for shortened forms
  12798. replace(ast);
  12799. options.logger('replace', ast);
  12800. // structure optimisations
  12801. if (options.restructuring) {
  12802. restructure(ast, options);
  12803. }
  12804. return ast;
  12805. }
  12806. function getCommentsOption(options) {
  12807. var comments = 'comments' in options ? options.comments : 'exclamation';
  12808. if (typeof comments === 'boolean') {
  12809. comments = comments ? 'exclamation' : false;
  12810. } else if (comments !== 'exclamation' && comments !== 'first-exclamation') {
  12811. comments = false;
  12812. }
  12813. return comments;
  12814. }
  12815. function getRestructureOption(options) {
  12816. if ('restructure' in options) {
  12817. return options.restructure;
  12818. }
  12819. return 'restructuring' in options ? options.restructuring : true;
  12820. }
  12821. function wrapBlock(block) {
  12822. return new List$6().appendData({
  12823. type: 'Rule',
  12824. loc: null,
  12825. prelude: {
  12826. type: 'SelectorList',
  12827. loc: null,
  12828. children: new List$6().appendData({
  12829. type: 'Selector',
  12830. loc: null,
  12831. children: new List$6().appendData({
  12832. type: 'TypeSelector',
  12833. loc: null,
  12834. name: 'x'
  12835. })
  12836. })
  12837. },
  12838. block: block
  12839. });
  12840. }
  12841. var compress = function compress(ast, options) {
  12842. ast = ast || { type: 'StyleSheet', loc: null, children: new List$6() };
  12843. options = options || {};
  12844. var compressOptions = {
  12845. logger: typeof options.logger === 'function' ? options.logger : function() {},
  12846. restructuring: getRestructureOption(options),
  12847. forceMediaMerge: Boolean(options.forceMediaMerge),
  12848. usage: options.usage ? usage.buildIndex(options.usage) : false
  12849. };
  12850. var specialComments = getCommentsOption(options);
  12851. var firstAtrulesAllowed = true;
  12852. var input;
  12853. var output = new List$6();
  12854. var chunk;
  12855. var chunkNum = 1;
  12856. var chunkChildren;
  12857. if (options.clone) {
  12858. ast = clone$1(ast);
  12859. }
  12860. if (ast.type === 'StyleSheet') {
  12861. input = ast.children;
  12862. ast.children = output;
  12863. } else {
  12864. input = wrapBlock(ast);
  12865. }
  12866. do {
  12867. chunk = readChunk(input, Boolean(specialComments));
  12868. compressChunk(chunk.stylesheet, firstAtrulesAllowed, chunkNum++, compressOptions);
  12869. chunkChildren = chunk.stylesheet.children;
  12870. if (chunk.comment) {
  12871. // add \n before comment if there is another content in output
  12872. if (!output.isEmpty()) {
  12873. output.insert(List$6.createItem({
  12874. type: 'Raw',
  12875. value: '\n'
  12876. }));
  12877. }
  12878. output.insert(List$6.createItem(chunk.comment));
  12879. // add \n after comment if chunk is not empty
  12880. if (!chunkChildren.isEmpty()) {
  12881. output.insert(List$6.createItem({
  12882. type: 'Raw',
  12883. value: '\n'
  12884. }));
  12885. }
  12886. }
  12887. if (firstAtrulesAllowed && !chunkChildren.isEmpty()) {
  12888. var lastRule = chunkChildren.last();
  12889. if (lastRule.type !== 'Atrule' ||
  12890. (lastRule.name !== 'import' && lastRule.name !== 'charset')) {
  12891. firstAtrulesAllowed = false;
  12892. }
  12893. }
  12894. if (specialComments !== 'exclamation') {
  12895. specialComments = false;
  12896. }
  12897. output.appendList(chunkChildren);
  12898. } while (!input.isEmpty());
  12899. return {
  12900. ast: ast
  12901. };
  12902. };
  12903. var version = "4.0.3";
  12904. var _package = {
  12905. version: version
  12906. };
  12907. var _package$1 = /*#__PURE__*/Object.freeze({
  12908. __proto__: null,
  12909. version: version,
  12910. 'default': _package
  12911. });
  12912. var require$$0 = getCjsExportFromNamespace(_package$1);
  12913. var parse$1 = lib.parse;
  12914. var generate$6 = lib.generate;
  12915. function debugOutput(name, options, startTime, data) {
  12916. if (options.debug) {
  12917. console.error('## ' + name + ' done in %d ms\n', Date.now() - startTime);
  12918. }
  12919. return data;
  12920. }
  12921. function createDefaultLogger(level) {
  12922. var lastDebug;
  12923. return function logger(title, ast) {
  12924. var line = title;
  12925. if (ast) {
  12926. line = '[' + ((Date.now() - lastDebug) / 1000).toFixed(3) + 's] ' + line;
  12927. }
  12928. if (level > 1 && ast) {
  12929. var css = generate$6(ast);
  12930. // when level 2, limit css to 256 symbols
  12931. if (level === 2 && css.length > 256) {
  12932. css = css.substr(0, 256) + '...';
  12933. }
  12934. line += '\n ' + css + '\n';
  12935. }
  12936. console.error(line);
  12937. lastDebug = Date.now();
  12938. };
  12939. }
  12940. function copy$1(obj) {
  12941. var result = {};
  12942. for (var key in obj) {
  12943. result[key] = obj[key];
  12944. }
  12945. return result;
  12946. }
  12947. function buildCompressOptions(options) {
  12948. options = copy$1(options);
  12949. if (typeof options.logger !== 'function' && options.debug) {
  12950. options.logger = createDefaultLogger(options.debug);
  12951. }
  12952. return options;
  12953. }
  12954. function runHandler(ast, options, handlers) {
  12955. if (!Array.isArray(handlers)) {
  12956. handlers = [handlers];
  12957. }
  12958. handlers.forEach(function(fn) {
  12959. fn(ast, options);
  12960. });
  12961. }
  12962. function minify(context, source, options) {
  12963. options = options || {};
  12964. var filename = options.filename || '<unknown>';
  12965. var result;
  12966. // parse
  12967. var ast = debugOutput('parsing', options, Date.now(),
  12968. parse$1(source, {
  12969. context: context,
  12970. filename: filename,
  12971. positions: Boolean(options.sourceMap)
  12972. })
  12973. );
  12974. // before compress handlers
  12975. if (options.beforeCompress) {
  12976. debugOutput('beforeCompress', options, Date.now(),
  12977. runHandler(ast, options, options.beforeCompress)
  12978. );
  12979. }
  12980. // compress
  12981. var compressResult = debugOutput('compress', options, Date.now(),
  12982. compress(ast, buildCompressOptions(options))
  12983. );
  12984. // after compress handlers
  12985. if (options.afterCompress) {
  12986. debugOutput('afterCompress', options, Date.now(),
  12987. runHandler(compressResult, options, options.afterCompress)
  12988. );
  12989. }
  12990. // generate
  12991. if (options.sourceMap) {
  12992. result = debugOutput('generate(sourceMap: true)', options, Date.now(), (function() {
  12993. var tmp = generate$6(compressResult.ast, { sourceMap: true });
  12994. tmp.map._file = filename; // since other tools can relay on file in source map transform chain
  12995. tmp.map.setSourceContent(filename, source);
  12996. return tmp;
  12997. }()));
  12998. } else {
  12999. result = debugOutput('generate', options, Date.now(), {
  13000. css: generate$6(compressResult.ast),
  13001. map: null
  13002. });
  13003. }
  13004. return result;
  13005. }
  13006. function minifyStylesheet(source, options) {
  13007. return minify('stylesheet', source, options);
  13008. }
  13009. function minifyBlock(source, options) {
  13010. return minify('declarationList', source, options);
  13011. }
  13012. var lib$1 = {
  13013. version: require$$0.version,
  13014. // main methods
  13015. minify: minifyStylesheet,
  13016. minifyBlock: minifyBlock,
  13017. // css syntax parser/walkers/generator/etc
  13018. syntax: Object.assign({
  13019. compress: compress
  13020. }, lib)
  13021. };
  13022. var lib_1 = lib$1.version;
  13023. var lib_2 = lib$1.minify;
  13024. var lib_3 = lib$1.minifyBlock;
  13025. var lib_4 = lib$1.syntax;
  13026. exports.default = lib$1;
  13027. exports.minify = lib_2;
  13028. exports.minifyBlock = lib_3;
  13029. exports.syntax = lib_4;
  13030. exports.version = lib_1;
  13031. Object.defineProperty(exports, '__esModule', { value: true });
  13032. })));