index.deno.mjs 150 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506
  1. function shiftNodesBeforeParent(node) {
  2. const parent = node.parent;
  3. const index = parent.index(node); // conditionally move previous siblings into a clone of the parent
  4. if (index) {
  5. parent.cloneBefore().removeAll().append(parent.nodes.slice(0, index));
  6. } // move the current node before the parent (and after the conditional clone)
  7. parent.before(node);
  8. return parent;
  9. }
  10. function cleanupParent(parent) {
  11. if (!parent.nodes.length) {
  12. parent.remove();
  13. }
  14. }
  15. var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
  16. function getDefaultExportFromCjs (x) {
  17. return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
  18. }
  19. var dist = {exports: {}};
  20. var processor = {exports: {}};
  21. var parser$1 = {exports: {}};
  22. var root$1 = {exports: {}};
  23. var container = {exports: {}};
  24. var node = {exports: {}};
  25. var util = {};
  26. var unesc = {exports: {}};
  27. (function (module, exports) {
  28. exports.__esModule = true;
  29. exports["default"] = unesc; // Many thanks for this post which made this migration much easier.
  30. // https://mathiasbynens.be/notes/css-escapes
  31. /**
  32. *
  33. * @param {string} str
  34. * @returns {[string, number]|undefined}
  35. */
  36. function gobbleHex(str) {
  37. var lower = str.toLowerCase();
  38. var hex = '';
  39. var spaceTerminated = false;
  40. for (var i = 0; i < 6 && lower[i] !== undefined; i++) {
  41. var code = lower.charCodeAt(i); // check to see if we are dealing with a valid hex char [a-f|0-9]
  42. var valid = code >= 97 && code <= 102 || code >= 48 && code <= 57; // https://drafts.csswg.org/css-syntax/#consume-escaped-code-point
  43. spaceTerminated = code === 32;
  44. if (!valid) {
  45. break;
  46. }
  47. hex += lower[i];
  48. }
  49. if (hex.length === 0) {
  50. return undefined;
  51. }
  52. var codePoint = parseInt(hex, 16);
  53. var isSurrogate = codePoint >= 0xD800 && codePoint <= 0xDFFF; // Add special case for
  54. // "If this number is zero, or is for a surrogate, or is greater than the maximum allowed code point"
  55. // https://drafts.csswg.org/css-syntax/#maximum-allowed-code-point
  56. if (isSurrogate || codePoint === 0x0000 || codePoint > 0x10FFFF) {
  57. return ["\uFFFD", hex.length + (spaceTerminated ? 1 : 0)];
  58. }
  59. return [String.fromCodePoint(codePoint), hex.length + (spaceTerminated ? 1 : 0)];
  60. }
  61. var CONTAINS_ESCAPE = /\\/;
  62. function unesc(str) {
  63. var needToProcess = CONTAINS_ESCAPE.test(str);
  64. if (!needToProcess) {
  65. return str;
  66. }
  67. var ret = "";
  68. for (var i = 0; i < str.length; i++) {
  69. if (str[i] === "\\") {
  70. var gobbled = gobbleHex(str.slice(i + 1, i + 7));
  71. if (gobbled !== undefined) {
  72. ret += gobbled[0];
  73. i += gobbled[1];
  74. continue;
  75. } // Retain a pair of \\ if double escaped `\\\\`
  76. // https://github.com/postcss/postcss-selector-parser/commit/268c9a7656fb53f543dc620aa5b73a30ec3ff20e
  77. if (str[i + 1] === "\\") {
  78. ret += "\\";
  79. i++;
  80. continue;
  81. } // if \\ is at the end of the string retain it
  82. // https://github.com/postcss/postcss-selector-parser/commit/01a6b346e3612ce1ab20219acc26abdc259ccefb
  83. if (str.length === i + 1) {
  84. ret += str[i];
  85. }
  86. continue;
  87. }
  88. ret += str[i];
  89. }
  90. return ret;
  91. }
  92. module.exports = exports.default;
  93. })(unesc, unesc.exports);
  94. var getProp = {exports: {}};
  95. (function (module, exports) {
  96. exports.__esModule = true;
  97. exports["default"] = getProp;
  98. function getProp(obj) {
  99. for (var _len = arguments.length, props = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
  100. props[_key - 1] = arguments[_key];
  101. }
  102. while (props.length > 0) {
  103. var prop = props.shift();
  104. if (!obj[prop]) {
  105. return undefined;
  106. }
  107. obj = obj[prop];
  108. }
  109. return obj;
  110. }
  111. module.exports = exports.default;
  112. })(getProp, getProp.exports);
  113. var ensureObject = {exports: {}};
  114. (function (module, exports) {
  115. exports.__esModule = true;
  116. exports["default"] = ensureObject;
  117. function ensureObject(obj) {
  118. for (var _len = arguments.length, props = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
  119. props[_key - 1] = arguments[_key];
  120. }
  121. while (props.length > 0) {
  122. var prop = props.shift();
  123. if (!obj[prop]) {
  124. obj[prop] = {};
  125. }
  126. obj = obj[prop];
  127. }
  128. }
  129. module.exports = exports.default;
  130. })(ensureObject, ensureObject.exports);
  131. var stripComments = {exports: {}};
  132. (function (module, exports) {
  133. exports.__esModule = true;
  134. exports["default"] = stripComments;
  135. function stripComments(str) {
  136. var s = "";
  137. var commentStart = str.indexOf("/*");
  138. var lastEnd = 0;
  139. while (commentStart >= 0) {
  140. s = s + str.slice(lastEnd, commentStart);
  141. var commentEnd = str.indexOf("*/", commentStart + 2);
  142. if (commentEnd < 0) {
  143. return s;
  144. }
  145. lastEnd = commentEnd + 2;
  146. commentStart = str.indexOf("/*", lastEnd);
  147. }
  148. s = s + str.slice(lastEnd);
  149. return s;
  150. }
  151. module.exports = exports.default;
  152. })(stripComments, stripComments.exports);
  153. util.__esModule = true;
  154. util.stripComments = util.ensureObject = util.getProp = util.unesc = void 0;
  155. var _unesc = _interopRequireDefault$1(unesc.exports);
  156. util.unesc = _unesc["default"];
  157. var _getProp = _interopRequireDefault$1(getProp.exports);
  158. util.getProp = _getProp["default"];
  159. var _ensureObject = _interopRequireDefault$1(ensureObject.exports);
  160. util.ensureObject = _ensureObject["default"];
  161. var _stripComments = _interopRequireDefault$1(stripComments.exports);
  162. util.stripComments = _stripComments["default"];
  163. function _interopRequireDefault$1(obj) {
  164. return obj && obj.__esModule ? obj : {
  165. "default": obj
  166. };
  167. }
  168. (function (module, exports) {
  169. exports.__esModule = true;
  170. exports["default"] = void 0;
  171. var _util = util;
  172. function _defineProperties(target, props) {
  173. for (var i = 0; i < props.length; i++) {
  174. var descriptor = props[i];
  175. descriptor.enumerable = descriptor.enumerable || false;
  176. descriptor.configurable = true;
  177. if ("value" in descriptor) descriptor.writable = true;
  178. Object.defineProperty(target, descriptor.key, descriptor);
  179. }
  180. }
  181. function _createClass(Constructor, protoProps, staticProps) {
  182. if (protoProps) _defineProperties(Constructor.prototype, protoProps);
  183. if (staticProps) _defineProperties(Constructor, staticProps);
  184. return Constructor;
  185. }
  186. var cloneNode = function cloneNode(obj, parent) {
  187. if (typeof obj !== 'object' || obj === null) {
  188. return obj;
  189. }
  190. var cloned = new obj.constructor();
  191. for (var i in obj) {
  192. if (!obj.hasOwnProperty(i)) {
  193. continue;
  194. }
  195. var value = obj[i];
  196. var type = typeof value;
  197. if (i === 'parent' && type === 'object') {
  198. if (parent) {
  199. cloned[i] = parent;
  200. }
  201. } else if (value instanceof Array) {
  202. cloned[i] = value.map(function (j) {
  203. return cloneNode(j, cloned);
  204. });
  205. } else {
  206. cloned[i] = cloneNode(value, cloned);
  207. }
  208. }
  209. return cloned;
  210. };
  211. var Node = /*#__PURE__*/function () {
  212. function Node(opts) {
  213. if (opts === void 0) {
  214. opts = {};
  215. }
  216. Object.assign(this, opts);
  217. this.spaces = this.spaces || {};
  218. this.spaces.before = this.spaces.before || '';
  219. this.spaces.after = this.spaces.after || '';
  220. }
  221. var _proto = Node.prototype;
  222. _proto.remove = function remove() {
  223. if (this.parent) {
  224. this.parent.removeChild(this);
  225. }
  226. this.parent = undefined;
  227. return this;
  228. };
  229. _proto.replaceWith = function replaceWith() {
  230. if (this.parent) {
  231. for (var index in arguments) {
  232. this.parent.insertBefore(this, arguments[index]);
  233. }
  234. this.remove();
  235. }
  236. return this;
  237. };
  238. _proto.next = function next() {
  239. return this.parent.at(this.parent.index(this) + 1);
  240. };
  241. _proto.prev = function prev() {
  242. return this.parent.at(this.parent.index(this) - 1);
  243. };
  244. _proto.clone = function clone(overrides) {
  245. if (overrides === void 0) {
  246. overrides = {};
  247. }
  248. var cloned = cloneNode(this);
  249. for (var name in overrides) {
  250. cloned[name] = overrides[name];
  251. }
  252. return cloned;
  253. }
  254. /**
  255. * Some non-standard syntax doesn't follow normal escaping rules for css.
  256. * This allows non standard syntax to be appended to an existing property
  257. * by specifying the escaped value. By specifying the escaped value,
  258. * illegal characters are allowed to be directly inserted into css output.
  259. * @param {string} name the property to set
  260. * @param {any} value the unescaped value of the property
  261. * @param {string} valueEscaped optional. the escaped value of the property.
  262. */
  263. ;
  264. _proto.appendToPropertyAndEscape = function appendToPropertyAndEscape(name, value, valueEscaped) {
  265. if (!this.raws) {
  266. this.raws = {};
  267. }
  268. var originalValue = this[name];
  269. var originalEscaped = this.raws[name];
  270. this[name] = originalValue + value; // this may trigger a setter that updates raws, so it has to be set first.
  271. if (originalEscaped || valueEscaped !== value) {
  272. this.raws[name] = (originalEscaped || originalValue) + valueEscaped;
  273. } else {
  274. delete this.raws[name]; // delete any escaped value that was created by the setter.
  275. }
  276. }
  277. /**
  278. * Some non-standard syntax doesn't follow normal escaping rules for css.
  279. * This allows the escaped value to be specified directly, allowing illegal
  280. * characters to be directly inserted into css output.
  281. * @param {string} name the property to set
  282. * @param {any} value the unescaped value of the property
  283. * @param {string} valueEscaped the escaped value of the property.
  284. */
  285. ;
  286. _proto.setPropertyAndEscape = function setPropertyAndEscape(name, value, valueEscaped) {
  287. if (!this.raws) {
  288. this.raws = {};
  289. }
  290. this[name] = value; // this may trigger a setter that updates raws, so it has to be set first.
  291. this.raws[name] = valueEscaped;
  292. }
  293. /**
  294. * When you want a value to passed through to CSS directly. This method
  295. * deletes the corresponding raw value causing the stringifier to fallback
  296. * to the unescaped value.
  297. * @param {string} name the property to set.
  298. * @param {any} value The value that is both escaped and unescaped.
  299. */
  300. ;
  301. _proto.setPropertyWithoutEscape = function setPropertyWithoutEscape(name, value) {
  302. this[name] = value; // this may trigger a setter that updates raws, so it has to be set first.
  303. if (this.raws) {
  304. delete this.raws[name];
  305. }
  306. }
  307. /**
  308. *
  309. * @param {number} line The number (starting with 1)
  310. * @param {number} column The column number (starting with 1)
  311. */
  312. ;
  313. _proto.isAtPosition = function isAtPosition(line, column) {
  314. if (this.source && this.source.start && this.source.end) {
  315. if (this.source.start.line > line) {
  316. return false;
  317. }
  318. if (this.source.end.line < line) {
  319. return false;
  320. }
  321. if (this.source.start.line === line && this.source.start.column > column) {
  322. return false;
  323. }
  324. if (this.source.end.line === line && this.source.end.column < column) {
  325. return false;
  326. }
  327. return true;
  328. }
  329. return undefined;
  330. };
  331. _proto.stringifyProperty = function stringifyProperty(name) {
  332. return this.raws && this.raws[name] || this[name];
  333. };
  334. _proto.valueToString = function valueToString() {
  335. return String(this.stringifyProperty("value"));
  336. };
  337. _proto.toString = function toString() {
  338. return [this.rawSpaceBefore, this.valueToString(), this.rawSpaceAfter].join('');
  339. };
  340. _createClass(Node, [{
  341. key: "rawSpaceBefore",
  342. get: function get() {
  343. var rawSpace = this.raws && this.raws.spaces && this.raws.spaces.before;
  344. if (rawSpace === undefined) {
  345. rawSpace = this.spaces && this.spaces.before;
  346. }
  347. return rawSpace || "";
  348. },
  349. set: function set(raw) {
  350. (0, _util.ensureObject)(this, "raws", "spaces");
  351. this.raws.spaces.before = raw;
  352. }
  353. }, {
  354. key: "rawSpaceAfter",
  355. get: function get() {
  356. var rawSpace = this.raws && this.raws.spaces && this.raws.spaces.after;
  357. if (rawSpace === undefined) {
  358. rawSpace = this.spaces.after;
  359. }
  360. return rawSpace || "";
  361. },
  362. set: function set(raw) {
  363. (0, _util.ensureObject)(this, "raws", "spaces");
  364. this.raws.spaces.after = raw;
  365. }
  366. }]);
  367. return Node;
  368. }();
  369. exports["default"] = Node;
  370. module.exports = exports.default;
  371. })(node, node.exports);
  372. var types = {};
  373. types.__esModule = true;
  374. types.UNIVERSAL = types.ATTRIBUTE = types.CLASS = types.COMBINATOR = types.COMMENT = types.ID = types.NESTING = types.PSEUDO = types.ROOT = types.SELECTOR = types.STRING = types.TAG = void 0;
  375. var TAG = 'tag';
  376. types.TAG = TAG;
  377. var STRING = 'string';
  378. types.STRING = STRING;
  379. var SELECTOR = 'selector';
  380. types.SELECTOR = SELECTOR;
  381. var ROOT = 'root';
  382. types.ROOT = ROOT;
  383. var PSEUDO = 'pseudo';
  384. types.PSEUDO = PSEUDO;
  385. var NESTING = 'nesting';
  386. types.NESTING = NESTING;
  387. var ID = 'id';
  388. types.ID = ID;
  389. var COMMENT = 'comment';
  390. types.COMMENT = COMMENT;
  391. var COMBINATOR = 'combinator';
  392. types.COMBINATOR = COMBINATOR;
  393. var CLASS = 'class';
  394. types.CLASS = CLASS;
  395. var ATTRIBUTE = 'attribute';
  396. types.ATTRIBUTE = ATTRIBUTE;
  397. var UNIVERSAL = 'universal';
  398. types.UNIVERSAL = UNIVERSAL;
  399. (function (module, exports) {
  400. exports.__esModule = true;
  401. exports["default"] = void 0;
  402. var _node = _interopRequireDefault(node.exports);
  403. var types$1 = _interopRequireWildcard(types);
  404. function _getRequireWildcardCache() {
  405. if (typeof WeakMap !== "function") return null;
  406. var cache = new WeakMap();
  407. _getRequireWildcardCache = function _getRequireWildcardCache() {
  408. return cache;
  409. };
  410. return cache;
  411. }
  412. function _interopRequireWildcard(obj) {
  413. if (obj && obj.__esModule) {
  414. return obj;
  415. }
  416. if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
  417. return {
  418. "default": obj
  419. };
  420. }
  421. var cache = _getRequireWildcardCache();
  422. if (cache && cache.has(obj)) {
  423. return cache.get(obj);
  424. }
  425. var newObj = {};
  426. var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
  427. for (var key in obj) {
  428. if (Object.prototype.hasOwnProperty.call(obj, key)) {
  429. var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
  430. if (desc && (desc.get || desc.set)) {
  431. Object.defineProperty(newObj, key, desc);
  432. } else {
  433. newObj[key] = obj[key];
  434. }
  435. }
  436. }
  437. newObj["default"] = obj;
  438. if (cache) {
  439. cache.set(obj, newObj);
  440. }
  441. return newObj;
  442. }
  443. function _interopRequireDefault(obj) {
  444. return obj && obj.__esModule ? obj : {
  445. "default": obj
  446. };
  447. }
  448. function _createForOfIteratorHelperLoose(o, allowArrayLike) {
  449. var it;
  450. if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) {
  451. if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
  452. if (it) o = it;
  453. var i = 0;
  454. return function () {
  455. if (i >= o.length) return {
  456. done: true
  457. };
  458. return {
  459. done: false,
  460. value: o[i++]
  461. };
  462. };
  463. }
  464. throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
  465. }
  466. it = o[Symbol.iterator]();
  467. return it.next.bind(it);
  468. }
  469. function _unsupportedIterableToArray(o, minLen) {
  470. if (!o) return;
  471. if (typeof o === "string") return _arrayLikeToArray(o, minLen);
  472. var n = Object.prototype.toString.call(o).slice(8, -1);
  473. if (n === "Object" && o.constructor) n = o.constructor.name;
  474. if (n === "Map" || n === "Set") return Array.from(o);
  475. if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
  476. }
  477. function _arrayLikeToArray(arr, len) {
  478. if (len == null || len > arr.length) len = arr.length;
  479. for (var i = 0, arr2 = new Array(len); i < len; i++) {
  480. arr2[i] = arr[i];
  481. }
  482. return arr2;
  483. }
  484. function _defineProperties(target, props) {
  485. for (var i = 0; i < props.length; i++) {
  486. var descriptor = props[i];
  487. descriptor.enumerable = descriptor.enumerable || false;
  488. descriptor.configurable = true;
  489. if ("value" in descriptor) descriptor.writable = true;
  490. Object.defineProperty(target, descriptor.key, descriptor);
  491. }
  492. }
  493. function _createClass(Constructor, protoProps, staticProps) {
  494. if (protoProps) _defineProperties(Constructor.prototype, protoProps);
  495. if (staticProps) _defineProperties(Constructor, staticProps);
  496. return Constructor;
  497. }
  498. function _inheritsLoose(subClass, superClass) {
  499. subClass.prototype = Object.create(superClass.prototype);
  500. subClass.prototype.constructor = subClass;
  501. _setPrototypeOf(subClass, superClass);
  502. }
  503. function _setPrototypeOf(o, p) {
  504. _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
  505. o.__proto__ = p;
  506. return o;
  507. };
  508. return _setPrototypeOf(o, p);
  509. }
  510. var Container = /*#__PURE__*/function (_Node) {
  511. _inheritsLoose(Container, _Node);
  512. function Container(opts) {
  513. var _this;
  514. _this = _Node.call(this, opts) || this;
  515. if (!_this.nodes) {
  516. _this.nodes = [];
  517. }
  518. return _this;
  519. }
  520. var _proto = Container.prototype;
  521. _proto.append = function append(selector) {
  522. selector.parent = this;
  523. this.nodes.push(selector);
  524. return this;
  525. };
  526. _proto.prepend = function prepend(selector) {
  527. selector.parent = this;
  528. this.nodes.unshift(selector);
  529. return this;
  530. };
  531. _proto.at = function at(index) {
  532. return this.nodes[index];
  533. };
  534. _proto.index = function index(child) {
  535. if (typeof child === 'number') {
  536. return child;
  537. }
  538. return this.nodes.indexOf(child);
  539. };
  540. _proto.removeChild = function removeChild(child) {
  541. child = this.index(child);
  542. this.at(child).parent = undefined;
  543. this.nodes.splice(child, 1);
  544. var index;
  545. for (var id in this.indexes) {
  546. index = this.indexes[id];
  547. if (index >= child) {
  548. this.indexes[id] = index - 1;
  549. }
  550. }
  551. return this;
  552. };
  553. _proto.removeAll = function removeAll() {
  554. for (var _iterator = _createForOfIteratorHelperLoose(this.nodes), _step; !(_step = _iterator()).done;) {
  555. var node = _step.value;
  556. node.parent = undefined;
  557. }
  558. this.nodes = [];
  559. return this;
  560. };
  561. _proto.empty = function empty() {
  562. return this.removeAll();
  563. };
  564. _proto.insertAfter = function insertAfter(oldNode, newNode) {
  565. newNode.parent = this;
  566. var oldIndex = this.index(oldNode);
  567. this.nodes.splice(oldIndex + 1, 0, newNode);
  568. newNode.parent = this;
  569. var index;
  570. for (var id in this.indexes) {
  571. index = this.indexes[id];
  572. if (oldIndex <= index) {
  573. this.indexes[id] = index + 1;
  574. }
  575. }
  576. return this;
  577. };
  578. _proto.insertBefore = function insertBefore(oldNode, newNode) {
  579. newNode.parent = this;
  580. var oldIndex = this.index(oldNode);
  581. this.nodes.splice(oldIndex, 0, newNode);
  582. newNode.parent = this;
  583. var index;
  584. for (var id in this.indexes) {
  585. index = this.indexes[id];
  586. if (index <= oldIndex) {
  587. this.indexes[id] = index + 1;
  588. }
  589. }
  590. return this;
  591. };
  592. _proto._findChildAtPosition = function _findChildAtPosition(line, col) {
  593. var found = undefined;
  594. this.each(function (node) {
  595. if (node.atPosition) {
  596. var foundChild = node.atPosition(line, col);
  597. if (foundChild) {
  598. found = foundChild;
  599. return false;
  600. }
  601. } else if (node.isAtPosition(line, col)) {
  602. found = node;
  603. return false;
  604. }
  605. });
  606. return found;
  607. }
  608. /**
  609. * Return the most specific node at the line and column number given.
  610. * The source location is based on the original parsed location, locations aren't
  611. * updated as selector nodes are mutated.
  612. *
  613. * Note that this location is relative to the location of the first character
  614. * of the selector, and not the location of the selector in the overall document
  615. * when used in conjunction with postcss.
  616. *
  617. * If not found, returns undefined.
  618. * @param {number} line The line number of the node to find. (1-based index)
  619. * @param {number} col The column number of the node to find. (1-based index)
  620. */
  621. ;
  622. _proto.atPosition = function atPosition(line, col) {
  623. if (this.isAtPosition(line, col)) {
  624. return this._findChildAtPosition(line, col) || this;
  625. } else {
  626. return undefined;
  627. }
  628. };
  629. _proto._inferEndPosition = function _inferEndPosition() {
  630. if (this.last && this.last.source && this.last.source.end) {
  631. this.source = this.source || {};
  632. this.source.end = this.source.end || {};
  633. Object.assign(this.source.end, this.last.source.end);
  634. }
  635. };
  636. _proto.each = function each(callback) {
  637. if (!this.lastEach) {
  638. this.lastEach = 0;
  639. }
  640. if (!this.indexes) {
  641. this.indexes = {};
  642. }
  643. this.lastEach++;
  644. var id = this.lastEach;
  645. this.indexes[id] = 0;
  646. if (!this.length) {
  647. return undefined;
  648. }
  649. var index, result;
  650. while (this.indexes[id] < this.length) {
  651. index = this.indexes[id];
  652. result = callback(this.at(index), index);
  653. if (result === false) {
  654. break;
  655. }
  656. this.indexes[id] += 1;
  657. }
  658. delete this.indexes[id];
  659. if (result === false) {
  660. return false;
  661. }
  662. };
  663. _proto.walk = function walk(callback) {
  664. return this.each(function (node, i) {
  665. var result = callback(node, i);
  666. if (result !== false && node.length) {
  667. result = node.walk(callback);
  668. }
  669. if (result === false) {
  670. return false;
  671. }
  672. });
  673. };
  674. _proto.walkAttributes = function walkAttributes(callback) {
  675. var _this2 = this;
  676. return this.walk(function (selector) {
  677. if (selector.type === types$1.ATTRIBUTE) {
  678. return callback.call(_this2, selector);
  679. }
  680. });
  681. };
  682. _proto.walkClasses = function walkClasses(callback) {
  683. var _this3 = this;
  684. return this.walk(function (selector) {
  685. if (selector.type === types$1.CLASS) {
  686. return callback.call(_this3, selector);
  687. }
  688. });
  689. };
  690. _proto.walkCombinators = function walkCombinators(callback) {
  691. var _this4 = this;
  692. return this.walk(function (selector) {
  693. if (selector.type === types$1.COMBINATOR) {
  694. return callback.call(_this4, selector);
  695. }
  696. });
  697. };
  698. _proto.walkComments = function walkComments(callback) {
  699. var _this5 = this;
  700. return this.walk(function (selector) {
  701. if (selector.type === types$1.COMMENT) {
  702. return callback.call(_this5, selector);
  703. }
  704. });
  705. };
  706. _proto.walkIds = function walkIds(callback) {
  707. var _this6 = this;
  708. return this.walk(function (selector) {
  709. if (selector.type === types$1.ID) {
  710. return callback.call(_this6, selector);
  711. }
  712. });
  713. };
  714. _proto.walkNesting = function walkNesting(callback) {
  715. var _this7 = this;
  716. return this.walk(function (selector) {
  717. if (selector.type === types$1.NESTING) {
  718. return callback.call(_this7, selector);
  719. }
  720. });
  721. };
  722. _proto.walkPseudos = function walkPseudos(callback) {
  723. var _this8 = this;
  724. return this.walk(function (selector) {
  725. if (selector.type === types$1.PSEUDO) {
  726. return callback.call(_this8, selector);
  727. }
  728. });
  729. };
  730. _proto.walkTags = function walkTags(callback) {
  731. var _this9 = this;
  732. return this.walk(function (selector) {
  733. if (selector.type === types$1.TAG) {
  734. return callback.call(_this9, selector);
  735. }
  736. });
  737. };
  738. _proto.walkUniversals = function walkUniversals(callback) {
  739. var _this10 = this;
  740. return this.walk(function (selector) {
  741. if (selector.type === types$1.UNIVERSAL) {
  742. return callback.call(_this10, selector);
  743. }
  744. });
  745. };
  746. _proto.split = function split(callback) {
  747. var _this11 = this;
  748. var current = [];
  749. return this.reduce(function (memo, node, index) {
  750. var split = callback.call(_this11, node);
  751. current.push(node);
  752. if (split) {
  753. memo.push(current);
  754. current = [];
  755. } else if (index === _this11.length - 1) {
  756. memo.push(current);
  757. }
  758. return memo;
  759. }, []);
  760. };
  761. _proto.map = function map(callback) {
  762. return this.nodes.map(callback);
  763. };
  764. _proto.reduce = function reduce(callback, memo) {
  765. return this.nodes.reduce(callback, memo);
  766. };
  767. _proto.every = function every(callback) {
  768. return this.nodes.every(callback);
  769. };
  770. _proto.some = function some(callback) {
  771. return this.nodes.some(callback);
  772. };
  773. _proto.filter = function filter(callback) {
  774. return this.nodes.filter(callback);
  775. };
  776. _proto.sort = function sort(callback) {
  777. return this.nodes.sort(callback);
  778. };
  779. _proto.toString = function toString() {
  780. return this.map(String).join('');
  781. };
  782. _createClass(Container, [{
  783. key: "first",
  784. get: function get() {
  785. return this.at(0);
  786. }
  787. }, {
  788. key: "last",
  789. get: function get() {
  790. return this.at(this.length - 1);
  791. }
  792. }, {
  793. key: "length",
  794. get: function get() {
  795. return this.nodes.length;
  796. }
  797. }]);
  798. return Container;
  799. }(_node["default"]);
  800. exports["default"] = Container;
  801. module.exports = exports.default;
  802. })(container, container.exports);
  803. (function (module, exports) {
  804. exports.__esModule = true;
  805. exports["default"] = void 0;
  806. var _container = _interopRequireDefault(container.exports);
  807. var _types = types;
  808. function _interopRequireDefault(obj) {
  809. return obj && obj.__esModule ? obj : {
  810. "default": obj
  811. };
  812. }
  813. function _defineProperties(target, props) {
  814. for (var i = 0; i < props.length; i++) {
  815. var descriptor = props[i];
  816. descriptor.enumerable = descriptor.enumerable || false;
  817. descriptor.configurable = true;
  818. if ("value" in descriptor) descriptor.writable = true;
  819. Object.defineProperty(target, descriptor.key, descriptor);
  820. }
  821. }
  822. function _createClass(Constructor, protoProps, staticProps) {
  823. if (protoProps) _defineProperties(Constructor.prototype, protoProps);
  824. if (staticProps) _defineProperties(Constructor, staticProps);
  825. return Constructor;
  826. }
  827. function _inheritsLoose(subClass, superClass) {
  828. subClass.prototype = Object.create(superClass.prototype);
  829. subClass.prototype.constructor = subClass;
  830. _setPrototypeOf(subClass, superClass);
  831. }
  832. function _setPrototypeOf(o, p) {
  833. _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
  834. o.__proto__ = p;
  835. return o;
  836. };
  837. return _setPrototypeOf(o, p);
  838. }
  839. var Root = /*#__PURE__*/function (_Container) {
  840. _inheritsLoose(Root, _Container);
  841. function Root(opts) {
  842. var _this;
  843. _this = _Container.call(this, opts) || this;
  844. _this.type = _types.ROOT;
  845. return _this;
  846. }
  847. var _proto = Root.prototype;
  848. _proto.toString = function toString() {
  849. var str = this.reduce(function (memo, selector) {
  850. memo.push(String(selector));
  851. return memo;
  852. }, []).join(',');
  853. return this.trailingComma ? str + ',' : str;
  854. };
  855. _proto.error = function error(message, options) {
  856. if (this._error) {
  857. return this._error(message, options);
  858. } else {
  859. return new Error(message);
  860. }
  861. };
  862. _createClass(Root, [{
  863. key: "errorGenerator",
  864. set: function set(handler) {
  865. this._error = handler;
  866. }
  867. }]);
  868. return Root;
  869. }(_container["default"]);
  870. exports["default"] = Root;
  871. module.exports = exports.default;
  872. })(root$1, root$1.exports);
  873. var selector$1 = {exports: {}};
  874. (function (module, exports) {
  875. exports.__esModule = true;
  876. exports["default"] = void 0;
  877. var _container = _interopRequireDefault(container.exports);
  878. var _types = types;
  879. function _interopRequireDefault(obj) {
  880. return obj && obj.__esModule ? obj : {
  881. "default": obj
  882. };
  883. }
  884. function _inheritsLoose(subClass, superClass) {
  885. subClass.prototype = Object.create(superClass.prototype);
  886. subClass.prototype.constructor = subClass;
  887. _setPrototypeOf(subClass, superClass);
  888. }
  889. function _setPrototypeOf(o, p) {
  890. _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
  891. o.__proto__ = p;
  892. return o;
  893. };
  894. return _setPrototypeOf(o, p);
  895. }
  896. var Selector = /*#__PURE__*/function (_Container) {
  897. _inheritsLoose(Selector, _Container);
  898. function Selector(opts) {
  899. var _this;
  900. _this = _Container.call(this, opts) || this;
  901. _this.type = _types.SELECTOR;
  902. return _this;
  903. }
  904. return Selector;
  905. }(_container["default"]);
  906. exports["default"] = Selector;
  907. module.exports = exports.default;
  908. })(selector$1, selector$1.exports);
  909. var className$1 = {exports: {}};
  910. /*! https://mths.be/cssesc v3.0.0 by @mathias */
  911. var object = {};
  912. var hasOwnProperty = object.hasOwnProperty;
  913. var merge = function merge(options, defaults) {
  914. if (!options) {
  915. return defaults;
  916. }
  917. var result = {};
  918. for (var key in defaults) {
  919. // `if (defaults.hasOwnProperty(key) { … }` is not needed here, since
  920. // only recognized option names are used.
  921. result[key] = hasOwnProperty.call(options, key) ? options[key] : defaults[key];
  922. }
  923. return result;
  924. };
  925. var regexAnySingleEscape = /[ -,\.\/:-@\[-\^`\{-~]/;
  926. var regexSingleEscape = /[ -,\.\/:-@\[\]\^`\{-~]/;
  927. var regexExcessiveSpaces = /(^|\\+)?(\\[A-F0-9]{1,6})\x20(?![a-fA-F0-9\x20])/g; // https://mathiasbynens.be/notes/css-escapes#css
  928. var cssesc = function cssesc(string, options) {
  929. options = merge(options, cssesc.options);
  930. if (options.quotes != 'single' && options.quotes != 'double') {
  931. options.quotes = 'single';
  932. }
  933. var quote = options.quotes == 'double' ? '"' : '\'';
  934. var isIdentifier = options.isIdentifier;
  935. var firstChar = string.charAt(0);
  936. var output = '';
  937. var counter = 0;
  938. var length = string.length;
  939. while (counter < length) {
  940. var character = string.charAt(counter++);
  941. var codePoint = character.charCodeAt();
  942. var value = void 0; // If it’s not a printable ASCII character…
  943. if (codePoint < 0x20 || codePoint > 0x7E) {
  944. if (codePoint >= 0xD800 && codePoint <= 0xDBFF && counter < length) {
  945. // It’s a high surrogate, and there is a next character.
  946. var extra = string.charCodeAt(counter++);
  947. if ((extra & 0xFC00) == 0xDC00) {
  948. // next character is low surrogate
  949. codePoint = ((codePoint & 0x3FF) << 10) + (extra & 0x3FF) + 0x10000;
  950. } else {
  951. // It’s an unmatched surrogate; only append this code unit, in case
  952. // the next code unit is the high surrogate of a surrogate pair.
  953. counter--;
  954. }
  955. }
  956. value = '\\' + codePoint.toString(16).toUpperCase() + ' ';
  957. } else {
  958. if (options.escapeEverything) {
  959. if (regexAnySingleEscape.test(character)) {
  960. value = '\\' + character;
  961. } else {
  962. value = '\\' + codePoint.toString(16).toUpperCase() + ' ';
  963. }
  964. } else if (/[\t\n\f\r\x0B]/.test(character)) {
  965. value = '\\' + codePoint.toString(16).toUpperCase() + ' ';
  966. } else if (character == '\\' || !isIdentifier && (character == '"' && quote == character || character == '\'' && quote == character) || isIdentifier && regexSingleEscape.test(character)) {
  967. value = '\\' + character;
  968. } else {
  969. value = character;
  970. }
  971. }
  972. output += value;
  973. }
  974. if (isIdentifier) {
  975. if (/^-[-\d]/.test(output)) {
  976. output = '\\-' + output.slice(1);
  977. } else if (/\d/.test(firstChar)) {
  978. output = '\\3' + firstChar + ' ' + output.slice(1);
  979. }
  980. } // Remove spaces after `\HEX` escapes that are not followed by a hex digit,
  981. // since they’re redundant. Note that this is only possible if the escape
  982. // sequence isn’t preceded by an odd number of backslashes.
  983. output = output.replace(regexExcessiveSpaces, function ($0, $1, $2) {
  984. if ($1 && $1.length % 2) {
  985. // It’s not safe to remove the space, so don’t.
  986. return $0;
  987. } // Strip the space.
  988. return ($1 || '') + $2;
  989. });
  990. if (!isIdentifier && options.wrap) {
  991. return quote + output + quote;
  992. }
  993. return output;
  994. }; // Expose default options (so they can be overridden globally).
  995. cssesc.options = {
  996. 'escapeEverything': false,
  997. 'isIdentifier': false,
  998. 'quotes': 'single',
  999. 'wrap': false
  1000. };
  1001. cssesc.version = '3.0.0';
  1002. var cssesc_1 = cssesc;
  1003. (function (module, exports) {
  1004. exports.__esModule = true;
  1005. exports["default"] = void 0;
  1006. var _cssesc = _interopRequireDefault(cssesc_1);
  1007. var _util = util;
  1008. var _node = _interopRequireDefault(node.exports);
  1009. var _types = types;
  1010. function _interopRequireDefault(obj) {
  1011. return obj && obj.__esModule ? obj : {
  1012. "default": obj
  1013. };
  1014. }
  1015. function _defineProperties(target, props) {
  1016. for (var i = 0; i < props.length; i++) {
  1017. var descriptor = props[i];
  1018. descriptor.enumerable = descriptor.enumerable || false;
  1019. descriptor.configurable = true;
  1020. if ("value" in descriptor) descriptor.writable = true;
  1021. Object.defineProperty(target, descriptor.key, descriptor);
  1022. }
  1023. }
  1024. function _createClass(Constructor, protoProps, staticProps) {
  1025. if (protoProps) _defineProperties(Constructor.prototype, protoProps);
  1026. if (staticProps) _defineProperties(Constructor, staticProps);
  1027. return Constructor;
  1028. }
  1029. function _inheritsLoose(subClass, superClass) {
  1030. subClass.prototype = Object.create(superClass.prototype);
  1031. subClass.prototype.constructor = subClass;
  1032. _setPrototypeOf(subClass, superClass);
  1033. }
  1034. function _setPrototypeOf(o, p) {
  1035. _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
  1036. o.__proto__ = p;
  1037. return o;
  1038. };
  1039. return _setPrototypeOf(o, p);
  1040. }
  1041. var ClassName = /*#__PURE__*/function (_Node) {
  1042. _inheritsLoose(ClassName, _Node);
  1043. function ClassName(opts) {
  1044. var _this;
  1045. _this = _Node.call(this, opts) || this;
  1046. _this.type = _types.CLASS;
  1047. _this._constructed = true;
  1048. return _this;
  1049. }
  1050. var _proto = ClassName.prototype;
  1051. _proto.valueToString = function valueToString() {
  1052. return '.' + _Node.prototype.valueToString.call(this);
  1053. };
  1054. _createClass(ClassName, [{
  1055. key: "value",
  1056. get: function get() {
  1057. return this._value;
  1058. },
  1059. set: function set(v) {
  1060. if (this._constructed) {
  1061. var escaped = (0, _cssesc["default"])(v, {
  1062. isIdentifier: true
  1063. });
  1064. if (escaped !== v) {
  1065. (0, _util.ensureObject)(this, "raws");
  1066. this.raws.value = escaped;
  1067. } else if (this.raws) {
  1068. delete this.raws.value;
  1069. }
  1070. }
  1071. this._value = v;
  1072. }
  1073. }]);
  1074. return ClassName;
  1075. }(_node["default"]);
  1076. exports["default"] = ClassName;
  1077. module.exports = exports.default;
  1078. })(className$1, className$1.exports);
  1079. var comment$2 = {exports: {}};
  1080. (function (module, exports) {
  1081. exports.__esModule = true;
  1082. exports["default"] = void 0;
  1083. var _node = _interopRequireDefault(node.exports);
  1084. var _types = types;
  1085. function _interopRequireDefault(obj) {
  1086. return obj && obj.__esModule ? obj : {
  1087. "default": obj
  1088. };
  1089. }
  1090. function _inheritsLoose(subClass, superClass) {
  1091. subClass.prototype = Object.create(superClass.prototype);
  1092. subClass.prototype.constructor = subClass;
  1093. _setPrototypeOf(subClass, superClass);
  1094. }
  1095. function _setPrototypeOf(o, p) {
  1096. _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
  1097. o.__proto__ = p;
  1098. return o;
  1099. };
  1100. return _setPrototypeOf(o, p);
  1101. }
  1102. var Comment = /*#__PURE__*/function (_Node) {
  1103. _inheritsLoose(Comment, _Node);
  1104. function Comment(opts) {
  1105. var _this;
  1106. _this = _Node.call(this, opts) || this;
  1107. _this.type = _types.COMMENT;
  1108. return _this;
  1109. }
  1110. return Comment;
  1111. }(_node["default"]);
  1112. exports["default"] = Comment;
  1113. module.exports = exports.default;
  1114. })(comment$2, comment$2.exports);
  1115. var id$1 = {exports: {}};
  1116. (function (module, exports) {
  1117. exports.__esModule = true;
  1118. exports["default"] = void 0;
  1119. var _node = _interopRequireDefault(node.exports);
  1120. var _types = types;
  1121. function _interopRequireDefault(obj) {
  1122. return obj && obj.__esModule ? obj : {
  1123. "default": obj
  1124. };
  1125. }
  1126. function _inheritsLoose(subClass, superClass) {
  1127. subClass.prototype = Object.create(superClass.prototype);
  1128. subClass.prototype.constructor = subClass;
  1129. _setPrototypeOf(subClass, superClass);
  1130. }
  1131. function _setPrototypeOf(o, p) {
  1132. _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
  1133. o.__proto__ = p;
  1134. return o;
  1135. };
  1136. return _setPrototypeOf(o, p);
  1137. }
  1138. var ID = /*#__PURE__*/function (_Node) {
  1139. _inheritsLoose(ID, _Node);
  1140. function ID(opts) {
  1141. var _this;
  1142. _this = _Node.call(this, opts) || this;
  1143. _this.type = _types.ID;
  1144. return _this;
  1145. }
  1146. var _proto = ID.prototype;
  1147. _proto.valueToString = function valueToString() {
  1148. return '#' + _Node.prototype.valueToString.call(this);
  1149. };
  1150. return ID;
  1151. }(_node["default"]);
  1152. exports["default"] = ID;
  1153. module.exports = exports.default;
  1154. })(id$1, id$1.exports);
  1155. var tag$1 = {exports: {}};
  1156. var namespace = {exports: {}};
  1157. (function (module, exports) {
  1158. exports.__esModule = true;
  1159. exports["default"] = void 0;
  1160. var _cssesc = _interopRequireDefault(cssesc_1);
  1161. var _util = util;
  1162. var _node = _interopRequireDefault(node.exports);
  1163. function _interopRequireDefault(obj) {
  1164. return obj && obj.__esModule ? obj : {
  1165. "default": obj
  1166. };
  1167. }
  1168. function _defineProperties(target, props) {
  1169. for (var i = 0; i < props.length; i++) {
  1170. var descriptor = props[i];
  1171. descriptor.enumerable = descriptor.enumerable || false;
  1172. descriptor.configurable = true;
  1173. if ("value" in descriptor) descriptor.writable = true;
  1174. Object.defineProperty(target, descriptor.key, descriptor);
  1175. }
  1176. }
  1177. function _createClass(Constructor, protoProps, staticProps) {
  1178. if (protoProps) _defineProperties(Constructor.prototype, protoProps);
  1179. if (staticProps) _defineProperties(Constructor, staticProps);
  1180. return Constructor;
  1181. }
  1182. function _inheritsLoose(subClass, superClass) {
  1183. subClass.prototype = Object.create(superClass.prototype);
  1184. subClass.prototype.constructor = subClass;
  1185. _setPrototypeOf(subClass, superClass);
  1186. }
  1187. function _setPrototypeOf(o, p) {
  1188. _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
  1189. o.__proto__ = p;
  1190. return o;
  1191. };
  1192. return _setPrototypeOf(o, p);
  1193. }
  1194. var Namespace = /*#__PURE__*/function (_Node) {
  1195. _inheritsLoose(Namespace, _Node);
  1196. function Namespace() {
  1197. return _Node.apply(this, arguments) || this;
  1198. }
  1199. var _proto = Namespace.prototype;
  1200. _proto.qualifiedName = function qualifiedName(value) {
  1201. if (this.namespace) {
  1202. return this.namespaceString + "|" + value;
  1203. } else {
  1204. return value;
  1205. }
  1206. };
  1207. _proto.valueToString = function valueToString() {
  1208. return this.qualifiedName(_Node.prototype.valueToString.call(this));
  1209. };
  1210. _createClass(Namespace, [{
  1211. key: "namespace",
  1212. get: function get() {
  1213. return this._namespace;
  1214. },
  1215. set: function set(namespace) {
  1216. if (namespace === true || namespace === "*" || namespace === "&") {
  1217. this._namespace = namespace;
  1218. if (this.raws) {
  1219. delete this.raws.namespace;
  1220. }
  1221. return;
  1222. }
  1223. var escaped = (0, _cssesc["default"])(namespace, {
  1224. isIdentifier: true
  1225. });
  1226. this._namespace = namespace;
  1227. if (escaped !== namespace) {
  1228. (0, _util.ensureObject)(this, "raws");
  1229. this.raws.namespace = escaped;
  1230. } else if (this.raws) {
  1231. delete this.raws.namespace;
  1232. }
  1233. }
  1234. }, {
  1235. key: "ns",
  1236. get: function get() {
  1237. return this._namespace;
  1238. },
  1239. set: function set(namespace) {
  1240. this.namespace = namespace;
  1241. }
  1242. }, {
  1243. key: "namespaceString",
  1244. get: function get() {
  1245. if (this.namespace) {
  1246. var ns = this.stringifyProperty("namespace");
  1247. if (ns === true) {
  1248. return '';
  1249. } else {
  1250. return ns;
  1251. }
  1252. } else {
  1253. return '';
  1254. }
  1255. }
  1256. }]);
  1257. return Namespace;
  1258. }(_node["default"]);
  1259. exports["default"] = Namespace;
  1260. module.exports = exports.default;
  1261. })(namespace, namespace.exports);
  1262. (function (module, exports) {
  1263. exports.__esModule = true;
  1264. exports["default"] = void 0;
  1265. var _namespace = _interopRequireDefault(namespace.exports);
  1266. var _types = types;
  1267. function _interopRequireDefault(obj) {
  1268. return obj && obj.__esModule ? obj : {
  1269. "default": obj
  1270. };
  1271. }
  1272. function _inheritsLoose(subClass, superClass) {
  1273. subClass.prototype = Object.create(superClass.prototype);
  1274. subClass.prototype.constructor = subClass;
  1275. _setPrototypeOf(subClass, superClass);
  1276. }
  1277. function _setPrototypeOf(o, p) {
  1278. _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
  1279. o.__proto__ = p;
  1280. return o;
  1281. };
  1282. return _setPrototypeOf(o, p);
  1283. }
  1284. var Tag = /*#__PURE__*/function (_Namespace) {
  1285. _inheritsLoose(Tag, _Namespace);
  1286. function Tag(opts) {
  1287. var _this;
  1288. _this = _Namespace.call(this, opts) || this;
  1289. _this.type = _types.TAG;
  1290. return _this;
  1291. }
  1292. return Tag;
  1293. }(_namespace["default"]);
  1294. exports["default"] = Tag;
  1295. module.exports = exports.default;
  1296. })(tag$1, tag$1.exports);
  1297. var string$1 = {exports: {}};
  1298. (function (module, exports) {
  1299. exports.__esModule = true;
  1300. exports["default"] = void 0;
  1301. var _node = _interopRequireDefault(node.exports);
  1302. var _types = types;
  1303. function _interopRequireDefault(obj) {
  1304. return obj && obj.__esModule ? obj : {
  1305. "default": obj
  1306. };
  1307. }
  1308. function _inheritsLoose(subClass, superClass) {
  1309. subClass.prototype = Object.create(superClass.prototype);
  1310. subClass.prototype.constructor = subClass;
  1311. _setPrototypeOf(subClass, superClass);
  1312. }
  1313. function _setPrototypeOf(o, p) {
  1314. _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
  1315. o.__proto__ = p;
  1316. return o;
  1317. };
  1318. return _setPrototypeOf(o, p);
  1319. }
  1320. var String = /*#__PURE__*/function (_Node) {
  1321. _inheritsLoose(String, _Node);
  1322. function String(opts) {
  1323. var _this;
  1324. _this = _Node.call(this, opts) || this;
  1325. _this.type = _types.STRING;
  1326. return _this;
  1327. }
  1328. return String;
  1329. }(_node["default"]);
  1330. exports["default"] = String;
  1331. module.exports = exports.default;
  1332. })(string$1, string$1.exports);
  1333. var pseudo$1 = {exports: {}};
  1334. (function (module, exports) {
  1335. exports.__esModule = true;
  1336. exports["default"] = void 0;
  1337. var _container = _interopRequireDefault(container.exports);
  1338. var _types = types;
  1339. function _interopRequireDefault(obj) {
  1340. return obj && obj.__esModule ? obj : {
  1341. "default": obj
  1342. };
  1343. }
  1344. function _inheritsLoose(subClass, superClass) {
  1345. subClass.prototype = Object.create(superClass.prototype);
  1346. subClass.prototype.constructor = subClass;
  1347. _setPrototypeOf(subClass, superClass);
  1348. }
  1349. function _setPrototypeOf(o, p) {
  1350. _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
  1351. o.__proto__ = p;
  1352. return o;
  1353. };
  1354. return _setPrototypeOf(o, p);
  1355. }
  1356. var Pseudo = /*#__PURE__*/function (_Container) {
  1357. _inheritsLoose(Pseudo, _Container);
  1358. function Pseudo(opts) {
  1359. var _this;
  1360. _this = _Container.call(this, opts) || this;
  1361. _this.type = _types.PSEUDO;
  1362. return _this;
  1363. }
  1364. var _proto = Pseudo.prototype;
  1365. _proto.toString = function toString() {
  1366. var params = this.length ? '(' + this.map(String).join(',') + ')' : '';
  1367. return [this.rawSpaceBefore, this.stringifyProperty("value"), params, this.rawSpaceAfter].join('');
  1368. };
  1369. return Pseudo;
  1370. }(_container["default"]);
  1371. exports["default"] = Pseudo;
  1372. module.exports = exports.default;
  1373. })(pseudo$1, pseudo$1.exports);
  1374. var attribute$1 = {};
  1375. /**
  1376. * Module exports.
  1377. */
  1378. var browser = deprecate;
  1379. /**
  1380. * Mark that a method should not be used.
  1381. * Returns a modified function which warns once by default.
  1382. *
  1383. * If `localStorage.noDeprecation = true` is set, then it is a no-op.
  1384. *
  1385. * If `localStorage.throwDeprecation = true` is set, then deprecated functions
  1386. * will throw an Error when invoked.
  1387. *
  1388. * If `localStorage.traceDeprecation = true` is set, then deprecated functions
  1389. * will invoke `console.trace()` instead of `console.error()`.
  1390. *
  1391. * @param {Function} fn - the function to deprecate
  1392. * @param {String} msg - the string to print to the console when `fn` is invoked
  1393. * @returns {Function} a new "deprecated" version of `fn`
  1394. * @api public
  1395. */
  1396. function deprecate(fn, msg) {
  1397. if (config('noDeprecation')) {
  1398. return fn;
  1399. }
  1400. var warned = false;
  1401. function deprecated() {
  1402. if (!warned) {
  1403. if (config('throwDeprecation')) {
  1404. throw new Error(msg);
  1405. } else if (config('traceDeprecation')) {
  1406. console.trace(msg);
  1407. } else {
  1408. console.warn(msg);
  1409. }
  1410. warned = true;
  1411. }
  1412. return fn.apply(this, arguments);
  1413. }
  1414. return deprecated;
  1415. }
  1416. /**
  1417. * Checks `localStorage` for boolean values for the given `name`.
  1418. *
  1419. * @param {String} name
  1420. * @returns {Boolean}
  1421. * @api private
  1422. */
  1423. function config(name) {
  1424. // accessing global.localStorage can trigger a DOMException in sandboxed iframes
  1425. try {
  1426. if (!commonjsGlobal.localStorage) return false;
  1427. } catch (_) {
  1428. return false;
  1429. }
  1430. var val = commonjsGlobal.localStorage[name];
  1431. if (null == val) return false;
  1432. return String(val).toLowerCase() === 'true';
  1433. }
  1434. (function (exports) {
  1435. exports.__esModule = true;
  1436. exports.unescapeValue = unescapeValue;
  1437. exports["default"] = void 0;
  1438. var _cssesc = _interopRequireDefault(cssesc_1);
  1439. var _unesc = _interopRequireDefault(unesc.exports);
  1440. var _namespace = _interopRequireDefault(namespace.exports);
  1441. var _types = types;
  1442. var _CSSESC_QUOTE_OPTIONS;
  1443. function _interopRequireDefault(obj) {
  1444. return obj && obj.__esModule ? obj : {
  1445. "default": obj
  1446. };
  1447. }
  1448. function _defineProperties(target, props) {
  1449. for (var i = 0; i < props.length; i++) {
  1450. var descriptor = props[i];
  1451. descriptor.enumerable = descriptor.enumerable || false;
  1452. descriptor.configurable = true;
  1453. if ("value" in descriptor) descriptor.writable = true;
  1454. Object.defineProperty(target, descriptor.key, descriptor);
  1455. }
  1456. }
  1457. function _createClass(Constructor, protoProps, staticProps) {
  1458. if (protoProps) _defineProperties(Constructor.prototype, protoProps);
  1459. if (staticProps) _defineProperties(Constructor, staticProps);
  1460. return Constructor;
  1461. }
  1462. function _inheritsLoose(subClass, superClass) {
  1463. subClass.prototype = Object.create(superClass.prototype);
  1464. subClass.prototype.constructor = subClass;
  1465. _setPrototypeOf(subClass, superClass);
  1466. }
  1467. function _setPrototypeOf(o, p) {
  1468. _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
  1469. o.__proto__ = p;
  1470. return o;
  1471. };
  1472. return _setPrototypeOf(o, p);
  1473. }
  1474. var deprecate = browser;
  1475. var WRAPPED_IN_QUOTES = /^('|")([^]*)\1$/;
  1476. var warnOfDeprecatedValueAssignment = deprecate(function () {}, "Assigning an attribute a value containing characters that might need to be escaped is deprecated. " + "Call attribute.setValue() instead.");
  1477. var warnOfDeprecatedQuotedAssignment = deprecate(function () {}, "Assigning attr.quoted is deprecated and has no effect. Assign to attr.quoteMark instead.");
  1478. var warnOfDeprecatedConstructor = deprecate(function () {}, "Constructing an Attribute selector with a value without specifying quoteMark is deprecated. Note: The value should be unescaped now.");
  1479. function unescapeValue(value) {
  1480. var deprecatedUsage = false;
  1481. var quoteMark = null;
  1482. var unescaped = value;
  1483. var m = unescaped.match(WRAPPED_IN_QUOTES);
  1484. if (m) {
  1485. quoteMark = m[1];
  1486. unescaped = m[2];
  1487. }
  1488. unescaped = (0, _unesc["default"])(unescaped);
  1489. if (unescaped !== value) {
  1490. deprecatedUsage = true;
  1491. }
  1492. return {
  1493. deprecatedUsage: deprecatedUsage,
  1494. unescaped: unescaped,
  1495. quoteMark: quoteMark
  1496. };
  1497. }
  1498. function handleDeprecatedContructorOpts(opts) {
  1499. if (opts.quoteMark !== undefined) {
  1500. return opts;
  1501. }
  1502. if (opts.value === undefined) {
  1503. return opts;
  1504. }
  1505. warnOfDeprecatedConstructor();
  1506. var _unescapeValue = unescapeValue(opts.value),
  1507. quoteMark = _unescapeValue.quoteMark,
  1508. unescaped = _unescapeValue.unescaped;
  1509. if (!opts.raws) {
  1510. opts.raws = {};
  1511. }
  1512. if (opts.raws.value === undefined) {
  1513. opts.raws.value = opts.value;
  1514. }
  1515. opts.value = unescaped;
  1516. opts.quoteMark = quoteMark;
  1517. return opts;
  1518. }
  1519. var Attribute = /*#__PURE__*/function (_Namespace) {
  1520. _inheritsLoose(Attribute, _Namespace);
  1521. function Attribute(opts) {
  1522. var _this;
  1523. if (opts === void 0) {
  1524. opts = {};
  1525. }
  1526. _this = _Namespace.call(this, handleDeprecatedContructorOpts(opts)) || this;
  1527. _this.type = _types.ATTRIBUTE;
  1528. _this.raws = _this.raws || {};
  1529. Object.defineProperty(_this.raws, 'unquoted', {
  1530. get: deprecate(function () {
  1531. return _this.value;
  1532. }, "attr.raws.unquoted is deprecated. Call attr.value instead."),
  1533. set: deprecate(function () {
  1534. return _this.value;
  1535. }, "Setting attr.raws.unquoted is deprecated and has no effect. attr.value is unescaped by default now.")
  1536. });
  1537. _this._constructed = true;
  1538. return _this;
  1539. }
  1540. /**
  1541. * Returns the Attribute's value quoted such that it would be legal to use
  1542. * in the value of a css file. The original value's quotation setting
  1543. * used for stringification is left unchanged. See `setValue(value, options)`
  1544. * if you want to control the quote settings of a new value for the attribute.
  1545. *
  1546. * You can also change the quotation used for the current value by setting quoteMark.
  1547. *
  1548. * Options:
  1549. * * quoteMark {'"' | "'" | null} - Use this value to quote the value. If this
  1550. * option is not set, the original value for quoteMark will be used. If
  1551. * indeterminate, a double quote is used. The legal values are:
  1552. * * `null` - the value will be unquoted and characters will be escaped as necessary.
  1553. * * `'` - the value will be quoted with a single quote and single quotes are escaped.
  1554. * * `"` - the value will be quoted with a double quote and double quotes are escaped.
  1555. * * preferCurrentQuoteMark {boolean} - if true, prefer the source quote mark
  1556. * over the quoteMark option value.
  1557. * * smart {boolean} - if true, will select a quote mark based on the value
  1558. * and the other options specified here. See the `smartQuoteMark()`
  1559. * method.
  1560. **/
  1561. var _proto = Attribute.prototype;
  1562. _proto.getQuotedValue = function getQuotedValue(options) {
  1563. if (options === void 0) {
  1564. options = {};
  1565. }
  1566. var quoteMark = this._determineQuoteMark(options);
  1567. var cssescopts = CSSESC_QUOTE_OPTIONS[quoteMark];
  1568. var escaped = (0, _cssesc["default"])(this._value, cssescopts);
  1569. return escaped;
  1570. };
  1571. _proto._determineQuoteMark = function _determineQuoteMark(options) {
  1572. return options.smart ? this.smartQuoteMark(options) : this.preferredQuoteMark(options);
  1573. }
  1574. /**
  1575. * Set the unescaped value with the specified quotation options. The value
  1576. * provided must not include any wrapping quote marks -- those quotes will
  1577. * be interpreted as part of the value and escaped accordingly.
  1578. */
  1579. ;
  1580. _proto.setValue = function setValue(value, options) {
  1581. if (options === void 0) {
  1582. options = {};
  1583. }
  1584. this._value = value;
  1585. this._quoteMark = this._determineQuoteMark(options);
  1586. this._syncRawValue();
  1587. }
  1588. /**
  1589. * Intelligently select a quoteMark value based on the value's contents. If
  1590. * the value is a legal CSS ident, it will not be quoted. Otherwise a quote
  1591. * mark will be picked that minimizes the number of escapes.
  1592. *
  1593. * If there's no clear winner, the quote mark from these options is used,
  1594. * then the source quote mark (this is inverted if `preferCurrentQuoteMark` is
  1595. * true). If the quoteMark is unspecified, a double quote is used.
  1596. *
  1597. * @param options This takes the quoteMark and preferCurrentQuoteMark options
  1598. * from the quoteValue method.
  1599. */
  1600. ;
  1601. _proto.smartQuoteMark = function smartQuoteMark(options) {
  1602. var v = this.value;
  1603. var numSingleQuotes = v.replace(/[^']/g, '').length;
  1604. var numDoubleQuotes = v.replace(/[^"]/g, '').length;
  1605. if (numSingleQuotes + numDoubleQuotes === 0) {
  1606. var escaped = (0, _cssesc["default"])(v, {
  1607. isIdentifier: true
  1608. });
  1609. if (escaped === v) {
  1610. return Attribute.NO_QUOTE;
  1611. } else {
  1612. var pref = this.preferredQuoteMark(options);
  1613. if (pref === Attribute.NO_QUOTE) {
  1614. // pick a quote mark that isn't none and see if it's smaller
  1615. var quote = this.quoteMark || options.quoteMark || Attribute.DOUBLE_QUOTE;
  1616. var opts = CSSESC_QUOTE_OPTIONS[quote];
  1617. var quoteValue = (0, _cssesc["default"])(v, opts);
  1618. if (quoteValue.length < escaped.length) {
  1619. return quote;
  1620. }
  1621. }
  1622. return pref;
  1623. }
  1624. } else if (numDoubleQuotes === numSingleQuotes) {
  1625. return this.preferredQuoteMark(options);
  1626. } else if (numDoubleQuotes < numSingleQuotes) {
  1627. return Attribute.DOUBLE_QUOTE;
  1628. } else {
  1629. return Attribute.SINGLE_QUOTE;
  1630. }
  1631. }
  1632. /**
  1633. * Selects the preferred quote mark based on the options and the current quote mark value.
  1634. * If you want the quote mark to depend on the attribute value, call `smartQuoteMark(opts)`
  1635. * instead.
  1636. */
  1637. ;
  1638. _proto.preferredQuoteMark = function preferredQuoteMark(options) {
  1639. var quoteMark = options.preferCurrentQuoteMark ? this.quoteMark : options.quoteMark;
  1640. if (quoteMark === undefined) {
  1641. quoteMark = options.preferCurrentQuoteMark ? options.quoteMark : this.quoteMark;
  1642. }
  1643. if (quoteMark === undefined) {
  1644. quoteMark = Attribute.DOUBLE_QUOTE;
  1645. }
  1646. return quoteMark;
  1647. };
  1648. _proto._syncRawValue = function _syncRawValue() {
  1649. var rawValue = (0, _cssesc["default"])(this._value, CSSESC_QUOTE_OPTIONS[this.quoteMark]);
  1650. if (rawValue === this._value) {
  1651. if (this.raws) {
  1652. delete this.raws.value;
  1653. }
  1654. } else {
  1655. this.raws.value = rawValue;
  1656. }
  1657. };
  1658. _proto._handleEscapes = function _handleEscapes(prop, value) {
  1659. if (this._constructed) {
  1660. var escaped = (0, _cssesc["default"])(value, {
  1661. isIdentifier: true
  1662. });
  1663. if (escaped !== value) {
  1664. this.raws[prop] = escaped;
  1665. } else {
  1666. delete this.raws[prop];
  1667. }
  1668. }
  1669. };
  1670. _proto._spacesFor = function _spacesFor(name) {
  1671. var attrSpaces = {
  1672. before: '',
  1673. after: ''
  1674. };
  1675. var spaces = this.spaces[name] || {};
  1676. var rawSpaces = this.raws.spaces && this.raws.spaces[name] || {};
  1677. return Object.assign(attrSpaces, spaces, rawSpaces);
  1678. };
  1679. _proto._stringFor = function _stringFor(name, spaceName, concat) {
  1680. if (spaceName === void 0) {
  1681. spaceName = name;
  1682. }
  1683. if (concat === void 0) {
  1684. concat = defaultAttrConcat;
  1685. }
  1686. var attrSpaces = this._spacesFor(spaceName);
  1687. return concat(this.stringifyProperty(name), attrSpaces);
  1688. }
  1689. /**
  1690. * returns the offset of the attribute part specified relative to the
  1691. * start of the node of the output string.
  1692. *
  1693. * * "ns" - alias for "namespace"
  1694. * * "namespace" - the namespace if it exists.
  1695. * * "attribute" - the attribute name
  1696. * * "attributeNS" - the start of the attribute or its namespace
  1697. * * "operator" - the match operator of the attribute
  1698. * * "value" - The value (string or identifier)
  1699. * * "insensitive" - the case insensitivity flag;
  1700. * @param part One of the possible values inside an attribute.
  1701. * @returns -1 if the name is invalid or the value doesn't exist in this attribute.
  1702. */
  1703. ;
  1704. _proto.offsetOf = function offsetOf(name) {
  1705. var count = 1;
  1706. var attributeSpaces = this._spacesFor("attribute");
  1707. count += attributeSpaces.before.length;
  1708. if (name === "namespace" || name === "ns") {
  1709. return this.namespace ? count : -1;
  1710. }
  1711. if (name === "attributeNS") {
  1712. return count;
  1713. }
  1714. count += this.namespaceString.length;
  1715. if (this.namespace) {
  1716. count += 1;
  1717. }
  1718. if (name === "attribute") {
  1719. return count;
  1720. }
  1721. count += this.stringifyProperty("attribute").length;
  1722. count += attributeSpaces.after.length;
  1723. var operatorSpaces = this._spacesFor("operator");
  1724. count += operatorSpaces.before.length;
  1725. var operator = this.stringifyProperty("operator");
  1726. if (name === "operator") {
  1727. return operator ? count : -1;
  1728. }
  1729. count += operator.length;
  1730. count += operatorSpaces.after.length;
  1731. var valueSpaces = this._spacesFor("value");
  1732. count += valueSpaces.before.length;
  1733. var value = this.stringifyProperty("value");
  1734. if (name === "value") {
  1735. return value ? count : -1;
  1736. }
  1737. count += value.length;
  1738. count += valueSpaces.after.length;
  1739. var insensitiveSpaces = this._spacesFor("insensitive");
  1740. count += insensitiveSpaces.before.length;
  1741. if (name === "insensitive") {
  1742. return this.insensitive ? count : -1;
  1743. }
  1744. return -1;
  1745. };
  1746. _proto.toString = function toString() {
  1747. var _this2 = this;
  1748. var selector = [this.rawSpaceBefore, '['];
  1749. selector.push(this._stringFor('qualifiedAttribute', 'attribute'));
  1750. if (this.operator && (this.value || this.value === '')) {
  1751. selector.push(this._stringFor('operator'));
  1752. selector.push(this._stringFor('value'));
  1753. selector.push(this._stringFor('insensitiveFlag', 'insensitive', function (attrValue, attrSpaces) {
  1754. if (attrValue.length > 0 && !_this2.quoted && attrSpaces.before.length === 0 && !(_this2.spaces.value && _this2.spaces.value.after)) {
  1755. attrSpaces.before = " ";
  1756. }
  1757. return defaultAttrConcat(attrValue, attrSpaces);
  1758. }));
  1759. }
  1760. selector.push(']');
  1761. selector.push(this.rawSpaceAfter);
  1762. return selector.join('');
  1763. };
  1764. _createClass(Attribute, [{
  1765. key: "quoted",
  1766. get: function get() {
  1767. var qm = this.quoteMark;
  1768. return qm === "'" || qm === '"';
  1769. },
  1770. set: function set(value) {
  1771. warnOfDeprecatedQuotedAssignment();
  1772. }
  1773. /**
  1774. * returns a single (`'`) or double (`"`) quote character if the value is quoted.
  1775. * returns `null` if the value is not quoted.
  1776. * returns `undefined` if the quotation state is unknown (this can happen when
  1777. * the attribute is constructed without specifying a quote mark.)
  1778. */
  1779. }, {
  1780. key: "quoteMark",
  1781. get: function get() {
  1782. return this._quoteMark;
  1783. }
  1784. /**
  1785. * Set the quote mark to be used by this attribute's value.
  1786. * If the quote mark changes, the raw (escaped) value at `attr.raws.value` of the attribute
  1787. * value is updated accordingly.
  1788. *
  1789. * @param {"'" | '"' | null} quoteMark The quote mark or `null` if the value should be unquoted.
  1790. */
  1791. ,
  1792. set: function set(quoteMark) {
  1793. if (!this._constructed) {
  1794. this._quoteMark = quoteMark;
  1795. return;
  1796. }
  1797. if (this._quoteMark !== quoteMark) {
  1798. this._quoteMark = quoteMark;
  1799. this._syncRawValue();
  1800. }
  1801. }
  1802. }, {
  1803. key: "qualifiedAttribute",
  1804. get: function get() {
  1805. return this.qualifiedName(this.raws.attribute || this.attribute);
  1806. }
  1807. }, {
  1808. key: "insensitiveFlag",
  1809. get: function get() {
  1810. return this.insensitive ? 'i' : '';
  1811. }
  1812. }, {
  1813. key: "value",
  1814. get: function get() {
  1815. return this._value;
  1816. }
  1817. /**
  1818. * Before 3.0, the value had to be set to an escaped value including any wrapped
  1819. * quote marks. In 3.0, the semantics of `Attribute.value` changed so that the value
  1820. * is unescaped during parsing and any quote marks are removed.
  1821. *
  1822. * Because the ambiguity of this semantic change, if you set `attr.value = newValue`,
  1823. * a deprecation warning is raised when the new value contains any characters that would
  1824. * require escaping (including if it contains wrapped quotes).
  1825. *
  1826. * Instead, you should call `attr.setValue(newValue, opts)` and pass options that describe
  1827. * how the new value is quoted.
  1828. */
  1829. ,
  1830. set: function set(v) {
  1831. if (this._constructed) {
  1832. var _unescapeValue2 = unescapeValue(v),
  1833. deprecatedUsage = _unescapeValue2.deprecatedUsage,
  1834. unescaped = _unescapeValue2.unescaped,
  1835. quoteMark = _unescapeValue2.quoteMark;
  1836. if (deprecatedUsage) {
  1837. warnOfDeprecatedValueAssignment();
  1838. }
  1839. if (unescaped === this._value && quoteMark === this._quoteMark) {
  1840. return;
  1841. }
  1842. this._value = unescaped;
  1843. this._quoteMark = quoteMark;
  1844. this._syncRawValue();
  1845. } else {
  1846. this._value = v;
  1847. }
  1848. }
  1849. }, {
  1850. key: "attribute",
  1851. get: function get() {
  1852. return this._attribute;
  1853. },
  1854. set: function set(name) {
  1855. this._handleEscapes("attribute", name);
  1856. this._attribute = name;
  1857. }
  1858. }]);
  1859. return Attribute;
  1860. }(_namespace["default"]);
  1861. exports["default"] = Attribute;
  1862. Attribute.NO_QUOTE = null;
  1863. Attribute.SINGLE_QUOTE = "'";
  1864. Attribute.DOUBLE_QUOTE = '"';
  1865. var CSSESC_QUOTE_OPTIONS = (_CSSESC_QUOTE_OPTIONS = {
  1866. "'": {
  1867. quotes: 'single',
  1868. wrap: true
  1869. },
  1870. '"': {
  1871. quotes: 'double',
  1872. wrap: true
  1873. }
  1874. }, _CSSESC_QUOTE_OPTIONS[null] = {
  1875. isIdentifier: true
  1876. }, _CSSESC_QUOTE_OPTIONS);
  1877. function defaultAttrConcat(attrValue, attrSpaces) {
  1878. return "" + attrSpaces.before + attrValue + attrSpaces.after;
  1879. }
  1880. })(attribute$1);
  1881. var universal$1 = {exports: {}};
  1882. (function (module, exports) {
  1883. exports.__esModule = true;
  1884. exports["default"] = void 0;
  1885. var _namespace = _interopRequireDefault(namespace.exports);
  1886. var _types = types;
  1887. function _interopRequireDefault(obj) {
  1888. return obj && obj.__esModule ? obj : {
  1889. "default": obj
  1890. };
  1891. }
  1892. function _inheritsLoose(subClass, superClass) {
  1893. subClass.prototype = Object.create(superClass.prototype);
  1894. subClass.prototype.constructor = subClass;
  1895. _setPrototypeOf(subClass, superClass);
  1896. }
  1897. function _setPrototypeOf(o, p) {
  1898. _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
  1899. o.__proto__ = p;
  1900. return o;
  1901. };
  1902. return _setPrototypeOf(o, p);
  1903. }
  1904. var Universal = /*#__PURE__*/function (_Namespace) {
  1905. _inheritsLoose(Universal, _Namespace);
  1906. function Universal(opts) {
  1907. var _this;
  1908. _this = _Namespace.call(this, opts) || this;
  1909. _this.type = _types.UNIVERSAL;
  1910. _this.value = '*';
  1911. return _this;
  1912. }
  1913. return Universal;
  1914. }(_namespace["default"]);
  1915. exports["default"] = Universal;
  1916. module.exports = exports.default;
  1917. })(universal$1, universal$1.exports);
  1918. var combinator$2 = {exports: {}};
  1919. (function (module, exports) {
  1920. exports.__esModule = true;
  1921. exports["default"] = void 0;
  1922. var _node = _interopRequireDefault(node.exports);
  1923. var _types = types;
  1924. function _interopRequireDefault(obj) {
  1925. return obj && obj.__esModule ? obj : {
  1926. "default": obj
  1927. };
  1928. }
  1929. function _inheritsLoose(subClass, superClass) {
  1930. subClass.prototype = Object.create(superClass.prototype);
  1931. subClass.prototype.constructor = subClass;
  1932. _setPrototypeOf(subClass, superClass);
  1933. }
  1934. function _setPrototypeOf(o, p) {
  1935. _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
  1936. o.__proto__ = p;
  1937. return o;
  1938. };
  1939. return _setPrototypeOf(o, p);
  1940. }
  1941. var Combinator = /*#__PURE__*/function (_Node) {
  1942. _inheritsLoose(Combinator, _Node);
  1943. function Combinator(opts) {
  1944. var _this;
  1945. _this = _Node.call(this, opts) || this;
  1946. _this.type = _types.COMBINATOR;
  1947. return _this;
  1948. }
  1949. return Combinator;
  1950. }(_node["default"]);
  1951. exports["default"] = Combinator;
  1952. module.exports = exports.default;
  1953. })(combinator$2, combinator$2.exports);
  1954. var nesting$1 = {exports: {}};
  1955. (function (module, exports) {
  1956. exports.__esModule = true;
  1957. exports["default"] = void 0;
  1958. var _node = _interopRequireDefault(node.exports);
  1959. var _types = types;
  1960. function _interopRequireDefault(obj) {
  1961. return obj && obj.__esModule ? obj : {
  1962. "default": obj
  1963. };
  1964. }
  1965. function _inheritsLoose(subClass, superClass) {
  1966. subClass.prototype = Object.create(superClass.prototype);
  1967. subClass.prototype.constructor = subClass;
  1968. _setPrototypeOf(subClass, superClass);
  1969. }
  1970. function _setPrototypeOf(o, p) {
  1971. _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
  1972. o.__proto__ = p;
  1973. return o;
  1974. };
  1975. return _setPrototypeOf(o, p);
  1976. }
  1977. var Nesting = /*#__PURE__*/function (_Node) {
  1978. _inheritsLoose(Nesting, _Node);
  1979. function Nesting(opts) {
  1980. var _this;
  1981. _this = _Node.call(this, opts) || this;
  1982. _this.type = _types.NESTING;
  1983. _this.value = '&';
  1984. return _this;
  1985. }
  1986. return Nesting;
  1987. }(_node["default"]);
  1988. exports["default"] = Nesting;
  1989. module.exports = exports.default;
  1990. })(nesting$1, nesting$1.exports);
  1991. var sortAscending = {exports: {}};
  1992. (function (module, exports) {
  1993. exports.__esModule = true;
  1994. exports["default"] = sortAscending;
  1995. function sortAscending(list) {
  1996. return list.sort(function (a, b) {
  1997. return a - b;
  1998. });
  1999. }
  2000. module.exports = exports.default;
  2001. })(sortAscending, sortAscending.exports);
  2002. var tokenize = {};
  2003. var tokenTypes = {};
  2004. tokenTypes.__esModule = true;
  2005. tokenTypes.combinator = tokenTypes.word = tokenTypes.comment = tokenTypes.str = tokenTypes.tab = tokenTypes.newline = tokenTypes.feed = tokenTypes.cr = tokenTypes.backslash = tokenTypes.bang = tokenTypes.slash = tokenTypes.doubleQuote = tokenTypes.singleQuote = tokenTypes.space = tokenTypes.greaterThan = tokenTypes.pipe = tokenTypes.equals = tokenTypes.plus = tokenTypes.caret = tokenTypes.tilde = tokenTypes.dollar = tokenTypes.closeSquare = tokenTypes.openSquare = tokenTypes.closeParenthesis = tokenTypes.openParenthesis = tokenTypes.semicolon = tokenTypes.colon = tokenTypes.comma = tokenTypes.at = tokenTypes.asterisk = tokenTypes.ampersand = void 0;
  2006. var ampersand = 38; // `&`.charCodeAt(0);
  2007. tokenTypes.ampersand = ampersand;
  2008. var asterisk = 42; // `*`.charCodeAt(0);
  2009. tokenTypes.asterisk = asterisk;
  2010. var at = 64; // `@`.charCodeAt(0);
  2011. tokenTypes.at = at;
  2012. var comma$1 = 44; // `,`.charCodeAt(0);
  2013. tokenTypes.comma = comma$1;
  2014. var colon = 58; // `:`.charCodeAt(0);
  2015. tokenTypes.colon = colon;
  2016. var semicolon = 59; // `;`.charCodeAt(0);
  2017. tokenTypes.semicolon = semicolon;
  2018. var openParenthesis = 40; // `(`.charCodeAt(0);
  2019. tokenTypes.openParenthesis = openParenthesis;
  2020. var closeParenthesis = 41; // `)`.charCodeAt(0);
  2021. tokenTypes.closeParenthesis = closeParenthesis;
  2022. var openSquare = 91; // `[`.charCodeAt(0);
  2023. tokenTypes.openSquare = openSquare;
  2024. var closeSquare = 93; // `]`.charCodeAt(0);
  2025. tokenTypes.closeSquare = closeSquare;
  2026. var dollar = 36; // `$`.charCodeAt(0);
  2027. tokenTypes.dollar = dollar;
  2028. var tilde = 126; // `~`.charCodeAt(0);
  2029. tokenTypes.tilde = tilde;
  2030. var caret = 94; // `^`.charCodeAt(0);
  2031. tokenTypes.caret = caret;
  2032. var plus = 43; // `+`.charCodeAt(0);
  2033. tokenTypes.plus = plus;
  2034. var equals = 61; // `=`.charCodeAt(0);
  2035. tokenTypes.equals = equals;
  2036. var pipe = 124; // `|`.charCodeAt(0);
  2037. tokenTypes.pipe = pipe;
  2038. var greaterThan = 62; // `>`.charCodeAt(0);
  2039. tokenTypes.greaterThan = greaterThan;
  2040. var space = 32; // ` `.charCodeAt(0);
  2041. tokenTypes.space = space;
  2042. var singleQuote = 39; // `'`.charCodeAt(0);
  2043. tokenTypes.singleQuote = singleQuote;
  2044. var doubleQuote = 34; // `"`.charCodeAt(0);
  2045. tokenTypes.doubleQuote = doubleQuote;
  2046. var slash = 47; // `/`.charCodeAt(0);
  2047. tokenTypes.slash = slash;
  2048. var bang = 33; // `!`.charCodeAt(0);
  2049. tokenTypes.bang = bang;
  2050. var backslash = 92; // '\\'.charCodeAt(0);
  2051. tokenTypes.backslash = backslash;
  2052. var cr = 13; // '\r'.charCodeAt(0);
  2053. tokenTypes.cr = cr;
  2054. var feed = 12; // '\f'.charCodeAt(0);
  2055. tokenTypes.feed = feed;
  2056. var newline = 10; // '\n'.charCodeAt(0);
  2057. tokenTypes.newline = newline;
  2058. var tab = 9; // '\t'.charCodeAt(0);
  2059. // Expose aliases primarily for readability.
  2060. tokenTypes.tab = tab;
  2061. var str = singleQuote; // No good single character representation!
  2062. tokenTypes.str = str;
  2063. var comment$1 = -1;
  2064. tokenTypes.comment = comment$1;
  2065. var word = -2;
  2066. tokenTypes.word = word;
  2067. var combinator$1 = -3;
  2068. tokenTypes.combinator = combinator$1;
  2069. (function (exports) {
  2070. exports.__esModule = true;
  2071. exports["default"] = tokenize;
  2072. exports.FIELDS = void 0;
  2073. var t = _interopRequireWildcard(tokenTypes);
  2074. var _unescapable, _wordDelimiters;
  2075. function _getRequireWildcardCache() {
  2076. if (typeof WeakMap !== "function") return null;
  2077. var cache = new WeakMap();
  2078. _getRequireWildcardCache = function _getRequireWildcardCache() {
  2079. return cache;
  2080. };
  2081. return cache;
  2082. }
  2083. function _interopRequireWildcard(obj) {
  2084. if (obj && obj.__esModule) {
  2085. return obj;
  2086. }
  2087. if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
  2088. return {
  2089. "default": obj
  2090. };
  2091. }
  2092. var cache = _getRequireWildcardCache();
  2093. if (cache && cache.has(obj)) {
  2094. return cache.get(obj);
  2095. }
  2096. var newObj = {};
  2097. var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
  2098. for (var key in obj) {
  2099. if (Object.prototype.hasOwnProperty.call(obj, key)) {
  2100. var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
  2101. if (desc && (desc.get || desc.set)) {
  2102. Object.defineProperty(newObj, key, desc);
  2103. } else {
  2104. newObj[key] = obj[key];
  2105. }
  2106. }
  2107. }
  2108. newObj["default"] = obj;
  2109. if (cache) {
  2110. cache.set(obj, newObj);
  2111. }
  2112. return newObj;
  2113. }
  2114. var unescapable = (_unescapable = {}, _unescapable[t.tab] = true, _unescapable[t.newline] = true, _unescapable[t.cr] = true, _unescapable[t.feed] = true, _unescapable);
  2115. var wordDelimiters = (_wordDelimiters = {}, _wordDelimiters[t.space] = true, _wordDelimiters[t.tab] = true, _wordDelimiters[t.newline] = true, _wordDelimiters[t.cr] = true, _wordDelimiters[t.feed] = true, _wordDelimiters[t.ampersand] = true, _wordDelimiters[t.asterisk] = true, _wordDelimiters[t.bang] = true, _wordDelimiters[t.comma] = true, _wordDelimiters[t.colon] = true, _wordDelimiters[t.semicolon] = true, _wordDelimiters[t.openParenthesis] = true, _wordDelimiters[t.closeParenthesis] = true, _wordDelimiters[t.openSquare] = true, _wordDelimiters[t.closeSquare] = true, _wordDelimiters[t.singleQuote] = true, _wordDelimiters[t.doubleQuote] = true, _wordDelimiters[t.plus] = true, _wordDelimiters[t.pipe] = true, _wordDelimiters[t.tilde] = true, _wordDelimiters[t.greaterThan] = true, _wordDelimiters[t.equals] = true, _wordDelimiters[t.dollar] = true, _wordDelimiters[t.caret] = true, _wordDelimiters[t.slash] = true, _wordDelimiters);
  2116. var hex = {};
  2117. var hexChars = "0123456789abcdefABCDEF";
  2118. for (var i = 0; i < hexChars.length; i++) {
  2119. hex[hexChars.charCodeAt(i)] = true;
  2120. }
  2121. /**
  2122. * Returns the last index of the bar css word
  2123. * @param {string} css The string in which the word begins
  2124. * @param {number} start The index into the string where word's first letter occurs
  2125. */
  2126. function consumeWord(css, start) {
  2127. var next = start;
  2128. var code;
  2129. do {
  2130. code = css.charCodeAt(next);
  2131. if (wordDelimiters[code]) {
  2132. return next - 1;
  2133. } else if (code === t.backslash) {
  2134. next = consumeEscape(css, next) + 1;
  2135. } else {
  2136. // All other characters are part of the word
  2137. next++;
  2138. }
  2139. } while (next < css.length);
  2140. return next - 1;
  2141. }
  2142. /**
  2143. * Returns the last index of the escape sequence
  2144. * @param {string} css The string in which the sequence begins
  2145. * @param {number} start The index into the string where escape character (`\`) occurs.
  2146. */
  2147. function consumeEscape(css, start) {
  2148. var next = start;
  2149. var code = css.charCodeAt(next + 1);
  2150. if (unescapable[code]) ; else if (hex[code]) {
  2151. var hexDigits = 0; // consume up to 6 hex chars
  2152. do {
  2153. next++;
  2154. hexDigits++;
  2155. code = css.charCodeAt(next + 1);
  2156. } while (hex[code] && hexDigits < 6); // if fewer than 6 hex chars, a trailing space ends the escape
  2157. if (hexDigits < 6 && code === t.space) {
  2158. next++;
  2159. }
  2160. } else {
  2161. // the next char is part of the current word
  2162. next++;
  2163. }
  2164. return next;
  2165. }
  2166. var FIELDS = {
  2167. TYPE: 0,
  2168. START_LINE: 1,
  2169. START_COL: 2,
  2170. END_LINE: 3,
  2171. END_COL: 4,
  2172. START_POS: 5,
  2173. END_POS: 6
  2174. };
  2175. exports.FIELDS = FIELDS;
  2176. function tokenize(input) {
  2177. var tokens = [];
  2178. var css = input.css.valueOf();
  2179. var _css = css,
  2180. length = _css.length;
  2181. var offset = -1;
  2182. var line = 1;
  2183. var start = 0;
  2184. var end = 0;
  2185. var code, content, endColumn, endLine, escaped, escapePos, last, lines, next, nextLine, nextOffset, quote, tokenType;
  2186. function unclosed(what, fix) {
  2187. if (input.safe) {
  2188. // fyi: this is never set to true.
  2189. css += fix;
  2190. next = css.length - 1;
  2191. } else {
  2192. throw input.error('Unclosed ' + what, line, start - offset, start);
  2193. }
  2194. }
  2195. while (start < length) {
  2196. code = css.charCodeAt(start);
  2197. if (code === t.newline) {
  2198. offset = start;
  2199. line += 1;
  2200. }
  2201. switch (code) {
  2202. case t.space:
  2203. case t.tab:
  2204. case t.newline:
  2205. case t.cr:
  2206. case t.feed:
  2207. next = start;
  2208. do {
  2209. next += 1;
  2210. code = css.charCodeAt(next);
  2211. if (code === t.newline) {
  2212. offset = next;
  2213. line += 1;
  2214. }
  2215. } while (code === t.space || code === t.newline || code === t.tab || code === t.cr || code === t.feed);
  2216. tokenType = t.space;
  2217. endLine = line;
  2218. endColumn = next - offset - 1;
  2219. end = next;
  2220. break;
  2221. case t.plus:
  2222. case t.greaterThan:
  2223. case t.tilde:
  2224. case t.pipe:
  2225. next = start;
  2226. do {
  2227. next += 1;
  2228. code = css.charCodeAt(next);
  2229. } while (code === t.plus || code === t.greaterThan || code === t.tilde || code === t.pipe);
  2230. tokenType = t.combinator;
  2231. endLine = line;
  2232. endColumn = start - offset;
  2233. end = next;
  2234. break;
  2235. // Consume these characters as single tokens.
  2236. case t.asterisk:
  2237. case t.ampersand:
  2238. case t.bang:
  2239. case t.comma:
  2240. case t.equals:
  2241. case t.dollar:
  2242. case t.caret:
  2243. case t.openSquare:
  2244. case t.closeSquare:
  2245. case t.colon:
  2246. case t.semicolon:
  2247. case t.openParenthesis:
  2248. case t.closeParenthesis:
  2249. next = start;
  2250. tokenType = code;
  2251. endLine = line;
  2252. endColumn = start - offset;
  2253. end = next + 1;
  2254. break;
  2255. case t.singleQuote:
  2256. case t.doubleQuote:
  2257. quote = code === t.singleQuote ? "'" : '"';
  2258. next = start;
  2259. do {
  2260. escaped = false;
  2261. next = css.indexOf(quote, next + 1);
  2262. if (next === -1) {
  2263. unclosed('quote', quote);
  2264. }
  2265. escapePos = next;
  2266. while (css.charCodeAt(escapePos - 1) === t.backslash) {
  2267. escapePos -= 1;
  2268. escaped = !escaped;
  2269. }
  2270. } while (escaped);
  2271. tokenType = t.str;
  2272. endLine = line;
  2273. endColumn = start - offset;
  2274. end = next + 1;
  2275. break;
  2276. default:
  2277. if (code === t.slash && css.charCodeAt(start + 1) === t.asterisk) {
  2278. next = css.indexOf('*/', start + 2) + 1;
  2279. if (next === 0) {
  2280. unclosed('comment', '*/');
  2281. }
  2282. content = css.slice(start, next + 1);
  2283. lines = content.split('\n');
  2284. last = lines.length - 1;
  2285. if (last > 0) {
  2286. nextLine = line + last;
  2287. nextOffset = next - lines[last].length;
  2288. } else {
  2289. nextLine = line;
  2290. nextOffset = offset;
  2291. }
  2292. tokenType = t.comment;
  2293. line = nextLine;
  2294. endLine = nextLine;
  2295. endColumn = next - nextOffset;
  2296. } else if (code === t.slash) {
  2297. next = start;
  2298. tokenType = code;
  2299. endLine = line;
  2300. endColumn = start - offset;
  2301. end = next + 1;
  2302. } else {
  2303. next = consumeWord(css, start);
  2304. tokenType = t.word;
  2305. endLine = line;
  2306. endColumn = next - offset;
  2307. }
  2308. end = next + 1;
  2309. break;
  2310. } // Ensure that the token structure remains consistent
  2311. tokens.push([tokenType, // [0] Token type
  2312. line, // [1] Starting line
  2313. start - offset, // [2] Starting column
  2314. endLine, // [3] Ending line
  2315. endColumn, // [4] Ending column
  2316. start, // [5] Start position / Source index
  2317. end // [6] End position
  2318. ]); // Reset offset for the next token
  2319. if (nextOffset) {
  2320. offset = nextOffset;
  2321. nextOffset = null;
  2322. }
  2323. start = end;
  2324. }
  2325. return tokens;
  2326. }
  2327. })(tokenize);
  2328. (function (module, exports) {
  2329. exports.__esModule = true;
  2330. exports["default"] = void 0;
  2331. var _root = _interopRequireDefault(root$1.exports);
  2332. var _selector = _interopRequireDefault(selector$1.exports);
  2333. var _className = _interopRequireDefault(className$1.exports);
  2334. var _comment = _interopRequireDefault(comment$2.exports);
  2335. var _id = _interopRequireDefault(id$1.exports);
  2336. var _tag = _interopRequireDefault(tag$1.exports);
  2337. var _string = _interopRequireDefault(string$1.exports);
  2338. var _pseudo = _interopRequireDefault(pseudo$1.exports);
  2339. var _attribute = _interopRequireWildcard(attribute$1);
  2340. var _universal = _interopRequireDefault(universal$1.exports);
  2341. var _combinator = _interopRequireDefault(combinator$2.exports);
  2342. var _nesting = _interopRequireDefault(nesting$1.exports);
  2343. var _sortAscending = _interopRequireDefault(sortAscending.exports);
  2344. var _tokenize = _interopRequireWildcard(tokenize);
  2345. var tokens = _interopRequireWildcard(tokenTypes);
  2346. var types$1 = _interopRequireWildcard(types);
  2347. var _util = util;
  2348. var _WHITESPACE_TOKENS, _Object$assign;
  2349. function _getRequireWildcardCache() {
  2350. if (typeof WeakMap !== "function") return null;
  2351. var cache = new WeakMap();
  2352. _getRequireWildcardCache = function _getRequireWildcardCache() {
  2353. return cache;
  2354. };
  2355. return cache;
  2356. }
  2357. function _interopRequireWildcard(obj) {
  2358. if (obj && obj.__esModule) {
  2359. return obj;
  2360. }
  2361. if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
  2362. return {
  2363. "default": obj
  2364. };
  2365. }
  2366. var cache = _getRequireWildcardCache();
  2367. if (cache && cache.has(obj)) {
  2368. return cache.get(obj);
  2369. }
  2370. var newObj = {};
  2371. var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
  2372. for (var key in obj) {
  2373. if (Object.prototype.hasOwnProperty.call(obj, key)) {
  2374. var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
  2375. if (desc && (desc.get || desc.set)) {
  2376. Object.defineProperty(newObj, key, desc);
  2377. } else {
  2378. newObj[key] = obj[key];
  2379. }
  2380. }
  2381. }
  2382. newObj["default"] = obj;
  2383. if (cache) {
  2384. cache.set(obj, newObj);
  2385. }
  2386. return newObj;
  2387. }
  2388. function _interopRequireDefault(obj) {
  2389. return obj && obj.__esModule ? obj : {
  2390. "default": obj
  2391. };
  2392. }
  2393. function _defineProperties(target, props) {
  2394. for (var i = 0; i < props.length; i++) {
  2395. var descriptor = props[i];
  2396. descriptor.enumerable = descriptor.enumerable || false;
  2397. descriptor.configurable = true;
  2398. if ("value" in descriptor) descriptor.writable = true;
  2399. Object.defineProperty(target, descriptor.key, descriptor);
  2400. }
  2401. }
  2402. function _createClass(Constructor, protoProps, staticProps) {
  2403. if (protoProps) _defineProperties(Constructor.prototype, protoProps);
  2404. if (staticProps) _defineProperties(Constructor, staticProps);
  2405. return Constructor;
  2406. }
  2407. var WHITESPACE_TOKENS = (_WHITESPACE_TOKENS = {}, _WHITESPACE_TOKENS[tokens.space] = true, _WHITESPACE_TOKENS[tokens.cr] = true, _WHITESPACE_TOKENS[tokens.feed] = true, _WHITESPACE_TOKENS[tokens.newline] = true, _WHITESPACE_TOKENS[tokens.tab] = true, _WHITESPACE_TOKENS);
  2408. var WHITESPACE_EQUIV_TOKENS = Object.assign({}, WHITESPACE_TOKENS, (_Object$assign = {}, _Object$assign[tokens.comment] = true, _Object$assign));
  2409. function tokenStart(token) {
  2410. return {
  2411. line: token[_tokenize.FIELDS.START_LINE],
  2412. column: token[_tokenize.FIELDS.START_COL]
  2413. };
  2414. }
  2415. function tokenEnd(token) {
  2416. return {
  2417. line: token[_tokenize.FIELDS.END_LINE],
  2418. column: token[_tokenize.FIELDS.END_COL]
  2419. };
  2420. }
  2421. function getSource(startLine, startColumn, endLine, endColumn) {
  2422. return {
  2423. start: {
  2424. line: startLine,
  2425. column: startColumn
  2426. },
  2427. end: {
  2428. line: endLine,
  2429. column: endColumn
  2430. }
  2431. };
  2432. }
  2433. function getTokenSource(token) {
  2434. return getSource(token[_tokenize.FIELDS.START_LINE], token[_tokenize.FIELDS.START_COL], token[_tokenize.FIELDS.END_LINE], token[_tokenize.FIELDS.END_COL]);
  2435. }
  2436. function getTokenSourceSpan(startToken, endToken) {
  2437. if (!startToken) {
  2438. return undefined;
  2439. }
  2440. return getSource(startToken[_tokenize.FIELDS.START_LINE], startToken[_tokenize.FIELDS.START_COL], endToken[_tokenize.FIELDS.END_LINE], endToken[_tokenize.FIELDS.END_COL]);
  2441. }
  2442. function unescapeProp(node, prop) {
  2443. var value = node[prop];
  2444. if (typeof value !== "string") {
  2445. return;
  2446. }
  2447. if (value.indexOf("\\") !== -1) {
  2448. (0, _util.ensureObject)(node, 'raws');
  2449. node[prop] = (0, _util.unesc)(value);
  2450. if (node.raws[prop] === undefined) {
  2451. node.raws[prop] = value;
  2452. }
  2453. }
  2454. return node;
  2455. }
  2456. function indexesOf(array, item) {
  2457. var i = -1;
  2458. var indexes = [];
  2459. while ((i = array.indexOf(item, i + 1)) !== -1) {
  2460. indexes.push(i);
  2461. }
  2462. return indexes;
  2463. }
  2464. function uniqs() {
  2465. var list = Array.prototype.concat.apply([], arguments);
  2466. return list.filter(function (item, i) {
  2467. return i === list.indexOf(item);
  2468. });
  2469. }
  2470. var Parser = /*#__PURE__*/function () {
  2471. function Parser(rule, options) {
  2472. if (options === void 0) {
  2473. options = {};
  2474. }
  2475. this.rule = rule;
  2476. this.options = Object.assign({
  2477. lossy: false,
  2478. safe: false
  2479. }, options);
  2480. this.position = 0;
  2481. this.css = typeof this.rule === 'string' ? this.rule : this.rule.selector;
  2482. this.tokens = (0, _tokenize["default"])({
  2483. css: this.css,
  2484. error: this._errorGenerator(),
  2485. safe: this.options.safe
  2486. });
  2487. var rootSource = getTokenSourceSpan(this.tokens[0], this.tokens[this.tokens.length - 1]);
  2488. this.root = new _root["default"]({
  2489. source: rootSource
  2490. });
  2491. this.root.errorGenerator = this._errorGenerator();
  2492. var selector = new _selector["default"]({
  2493. source: {
  2494. start: {
  2495. line: 1,
  2496. column: 1
  2497. }
  2498. }
  2499. });
  2500. this.root.append(selector);
  2501. this.current = selector;
  2502. this.loop();
  2503. }
  2504. var _proto = Parser.prototype;
  2505. _proto._errorGenerator = function _errorGenerator() {
  2506. var _this = this;
  2507. return function (message, errorOptions) {
  2508. if (typeof _this.rule === 'string') {
  2509. return new Error(message);
  2510. }
  2511. return _this.rule.error(message, errorOptions);
  2512. };
  2513. };
  2514. _proto.attribute = function attribute() {
  2515. var attr = [];
  2516. var startingToken = this.currToken;
  2517. this.position++;
  2518. while (this.position < this.tokens.length && this.currToken[_tokenize.FIELDS.TYPE] !== tokens.closeSquare) {
  2519. attr.push(this.currToken);
  2520. this.position++;
  2521. }
  2522. if (this.currToken[_tokenize.FIELDS.TYPE] !== tokens.closeSquare) {
  2523. return this.expected('closing square bracket', this.currToken[_tokenize.FIELDS.START_POS]);
  2524. }
  2525. var len = attr.length;
  2526. var node = {
  2527. source: getSource(startingToken[1], startingToken[2], this.currToken[3], this.currToken[4]),
  2528. sourceIndex: startingToken[_tokenize.FIELDS.START_POS]
  2529. };
  2530. if (len === 1 && !~[tokens.word].indexOf(attr[0][_tokenize.FIELDS.TYPE])) {
  2531. return this.expected('attribute', attr[0][_tokenize.FIELDS.START_POS]);
  2532. }
  2533. var pos = 0;
  2534. var spaceBefore = '';
  2535. var commentBefore = '';
  2536. var lastAdded = null;
  2537. var spaceAfterMeaningfulToken = false;
  2538. while (pos < len) {
  2539. var token = attr[pos];
  2540. var content = this.content(token);
  2541. var next = attr[pos + 1];
  2542. switch (token[_tokenize.FIELDS.TYPE]) {
  2543. case tokens.space:
  2544. // if (
  2545. // len === 1 ||
  2546. // pos === 0 && this.content(next) === '|'
  2547. // ) {
  2548. // return this.expected('attribute', token[TOKEN.START_POS], content);
  2549. // }
  2550. spaceAfterMeaningfulToken = true;
  2551. if (this.options.lossy) {
  2552. break;
  2553. }
  2554. if (lastAdded) {
  2555. (0, _util.ensureObject)(node, 'spaces', lastAdded);
  2556. var prevContent = node.spaces[lastAdded].after || '';
  2557. node.spaces[lastAdded].after = prevContent + content;
  2558. var existingComment = (0, _util.getProp)(node, 'raws', 'spaces', lastAdded, 'after') || null;
  2559. if (existingComment) {
  2560. node.raws.spaces[lastAdded].after = existingComment + content;
  2561. }
  2562. } else {
  2563. spaceBefore = spaceBefore + content;
  2564. commentBefore = commentBefore + content;
  2565. }
  2566. break;
  2567. case tokens.asterisk:
  2568. if (next[_tokenize.FIELDS.TYPE] === tokens.equals) {
  2569. node.operator = content;
  2570. lastAdded = 'operator';
  2571. } else if ((!node.namespace || lastAdded === "namespace" && !spaceAfterMeaningfulToken) && next) {
  2572. if (spaceBefore) {
  2573. (0, _util.ensureObject)(node, 'spaces', 'attribute');
  2574. node.spaces.attribute.before = spaceBefore;
  2575. spaceBefore = '';
  2576. }
  2577. if (commentBefore) {
  2578. (0, _util.ensureObject)(node, 'raws', 'spaces', 'attribute');
  2579. node.raws.spaces.attribute.before = spaceBefore;
  2580. commentBefore = '';
  2581. }
  2582. node.namespace = (node.namespace || "") + content;
  2583. var rawValue = (0, _util.getProp)(node, 'raws', 'namespace') || null;
  2584. if (rawValue) {
  2585. node.raws.namespace += content;
  2586. }
  2587. lastAdded = 'namespace';
  2588. }
  2589. spaceAfterMeaningfulToken = false;
  2590. break;
  2591. case tokens.dollar:
  2592. if (lastAdded === "value") {
  2593. var oldRawValue = (0, _util.getProp)(node, 'raws', 'value');
  2594. node.value += "$";
  2595. if (oldRawValue) {
  2596. node.raws.value = oldRawValue + "$";
  2597. }
  2598. break;
  2599. }
  2600. // Falls through
  2601. case tokens.caret:
  2602. if (next[_tokenize.FIELDS.TYPE] === tokens.equals) {
  2603. node.operator = content;
  2604. lastAdded = 'operator';
  2605. }
  2606. spaceAfterMeaningfulToken = false;
  2607. break;
  2608. case tokens.combinator:
  2609. if (content === '~' && next[_tokenize.FIELDS.TYPE] === tokens.equals) {
  2610. node.operator = content;
  2611. lastAdded = 'operator';
  2612. }
  2613. if (content !== '|') {
  2614. spaceAfterMeaningfulToken = false;
  2615. break;
  2616. }
  2617. if (next[_tokenize.FIELDS.TYPE] === tokens.equals) {
  2618. node.operator = content;
  2619. lastAdded = 'operator';
  2620. } else if (!node.namespace && !node.attribute) {
  2621. node.namespace = true;
  2622. }
  2623. spaceAfterMeaningfulToken = false;
  2624. break;
  2625. case tokens.word:
  2626. if (next && this.content(next) === '|' && attr[pos + 2] && attr[pos + 2][_tokenize.FIELDS.TYPE] !== tokens.equals && // this look-ahead probably fails with comment nodes involved.
  2627. !node.operator && !node.namespace) {
  2628. node.namespace = content;
  2629. lastAdded = 'namespace';
  2630. } else if (!node.attribute || lastAdded === "attribute" && !spaceAfterMeaningfulToken) {
  2631. if (spaceBefore) {
  2632. (0, _util.ensureObject)(node, 'spaces', 'attribute');
  2633. node.spaces.attribute.before = spaceBefore;
  2634. spaceBefore = '';
  2635. }
  2636. if (commentBefore) {
  2637. (0, _util.ensureObject)(node, 'raws', 'spaces', 'attribute');
  2638. node.raws.spaces.attribute.before = commentBefore;
  2639. commentBefore = '';
  2640. }
  2641. node.attribute = (node.attribute || "") + content;
  2642. var _rawValue = (0, _util.getProp)(node, 'raws', 'attribute') || null;
  2643. if (_rawValue) {
  2644. node.raws.attribute += content;
  2645. }
  2646. lastAdded = 'attribute';
  2647. } else if (!node.value && node.value !== "" || lastAdded === "value" && !spaceAfterMeaningfulToken) {
  2648. var _unescaped = (0, _util.unesc)(content);
  2649. var _oldRawValue = (0, _util.getProp)(node, 'raws', 'value') || '';
  2650. var oldValue = node.value || '';
  2651. node.value = oldValue + _unescaped;
  2652. node.quoteMark = null;
  2653. if (_unescaped !== content || _oldRawValue) {
  2654. (0, _util.ensureObject)(node, 'raws');
  2655. node.raws.value = (_oldRawValue || oldValue) + content;
  2656. }
  2657. lastAdded = 'value';
  2658. } else {
  2659. var insensitive = content === 'i' || content === "I";
  2660. if ((node.value || node.value === '') && (node.quoteMark || spaceAfterMeaningfulToken)) {
  2661. node.insensitive = insensitive;
  2662. if (!insensitive || content === "I") {
  2663. (0, _util.ensureObject)(node, 'raws');
  2664. node.raws.insensitiveFlag = content;
  2665. }
  2666. lastAdded = 'insensitive';
  2667. if (spaceBefore) {
  2668. (0, _util.ensureObject)(node, 'spaces', 'insensitive');
  2669. node.spaces.insensitive.before = spaceBefore;
  2670. spaceBefore = '';
  2671. }
  2672. if (commentBefore) {
  2673. (0, _util.ensureObject)(node, 'raws', 'spaces', 'insensitive');
  2674. node.raws.spaces.insensitive.before = commentBefore;
  2675. commentBefore = '';
  2676. }
  2677. } else if (node.value || node.value === '') {
  2678. lastAdded = 'value';
  2679. node.value += content;
  2680. if (node.raws.value) {
  2681. node.raws.value += content;
  2682. }
  2683. }
  2684. }
  2685. spaceAfterMeaningfulToken = false;
  2686. break;
  2687. case tokens.str:
  2688. if (!node.attribute || !node.operator) {
  2689. return this.error("Expected an attribute followed by an operator preceding the string.", {
  2690. index: token[_tokenize.FIELDS.START_POS]
  2691. });
  2692. }
  2693. var _unescapeValue = (0, _attribute.unescapeValue)(content),
  2694. unescaped = _unescapeValue.unescaped,
  2695. quoteMark = _unescapeValue.quoteMark;
  2696. node.value = unescaped;
  2697. node.quoteMark = quoteMark;
  2698. lastAdded = 'value';
  2699. (0, _util.ensureObject)(node, 'raws');
  2700. node.raws.value = content;
  2701. spaceAfterMeaningfulToken = false;
  2702. break;
  2703. case tokens.equals:
  2704. if (!node.attribute) {
  2705. return this.expected('attribute', token[_tokenize.FIELDS.START_POS], content);
  2706. }
  2707. if (node.value) {
  2708. return this.error('Unexpected "=" found; an operator was already defined.', {
  2709. index: token[_tokenize.FIELDS.START_POS]
  2710. });
  2711. }
  2712. node.operator = node.operator ? node.operator + content : content;
  2713. lastAdded = 'operator';
  2714. spaceAfterMeaningfulToken = false;
  2715. break;
  2716. case tokens.comment:
  2717. if (lastAdded) {
  2718. if (spaceAfterMeaningfulToken || next && next[_tokenize.FIELDS.TYPE] === tokens.space || lastAdded === 'insensitive') {
  2719. var lastComment = (0, _util.getProp)(node, 'spaces', lastAdded, 'after') || '';
  2720. var rawLastComment = (0, _util.getProp)(node, 'raws', 'spaces', lastAdded, 'after') || lastComment;
  2721. (0, _util.ensureObject)(node, 'raws', 'spaces', lastAdded);
  2722. node.raws.spaces[lastAdded].after = rawLastComment + content;
  2723. } else {
  2724. var lastValue = node[lastAdded] || '';
  2725. var rawLastValue = (0, _util.getProp)(node, 'raws', lastAdded) || lastValue;
  2726. (0, _util.ensureObject)(node, 'raws');
  2727. node.raws[lastAdded] = rawLastValue + content;
  2728. }
  2729. } else {
  2730. commentBefore = commentBefore + content;
  2731. }
  2732. break;
  2733. default:
  2734. return this.error("Unexpected \"" + content + "\" found.", {
  2735. index: token[_tokenize.FIELDS.START_POS]
  2736. });
  2737. }
  2738. pos++;
  2739. }
  2740. unescapeProp(node, "attribute");
  2741. unescapeProp(node, "namespace");
  2742. this.newNode(new _attribute["default"](node));
  2743. this.position++;
  2744. }
  2745. /**
  2746. * return a node containing meaningless garbage up to (but not including) the specified token position.
  2747. * if the token position is negative, all remaining tokens are consumed.
  2748. *
  2749. * This returns an array containing a single string node if all whitespace,
  2750. * otherwise an array of comment nodes with space before and after.
  2751. *
  2752. * These tokens are not added to the current selector, the caller can add them or use them to amend
  2753. * a previous node's space metadata.
  2754. *
  2755. * In lossy mode, this returns only comments.
  2756. */
  2757. ;
  2758. _proto.parseWhitespaceEquivalentTokens = function parseWhitespaceEquivalentTokens(stopPosition) {
  2759. if (stopPosition < 0) {
  2760. stopPosition = this.tokens.length;
  2761. }
  2762. var startPosition = this.position;
  2763. var nodes = [];
  2764. var space = "";
  2765. var lastComment = undefined;
  2766. do {
  2767. if (WHITESPACE_TOKENS[this.currToken[_tokenize.FIELDS.TYPE]]) {
  2768. if (!this.options.lossy) {
  2769. space += this.content();
  2770. }
  2771. } else if (this.currToken[_tokenize.FIELDS.TYPE] === tokens.comment) {
  2772. var spaces = {};
  2773. if (space) {
  2774. spaces.before = space;
  2775. space = "";
  2776. }
  2777. lastComment = new _comment["default"]({
  2778. value: this.content(),
  2779. source: getTokenSource(this.currToken),
  2780. sourceIndex: this.currToken[_tokenize.FIELDS.START_POS],
  2781. spaces: spaces
  2782. });
  2783. nodes.push(lastComment);
  2784. }
  2785. } while (++this.position < stopPosition);
  2786. if (space) {
  2787. if (lastComment) {
  2788. lastComment.spaces.after = space;
  2789. } else if (!this.options.lossy) {
  2790. var firstToken = this.tokens[startPosition];
  2791. var lastToken = this.tokens[this.position - 1];
  2792. nodes.push(new _string["default"]({
  2793. value: '',
  2794. source: getSource(firstToken[_tokenize.FIELDS.START_LINE], firstToken[_tokenize.FIELDS.START_COL], lastToken[_tokenize.FIELDS.END_LINE], lastToken[_tokenize.FIELDS.END_COL]),
  2795. sourceIndex: firstToken[_tokenize.FIELDS.START_POS],
  2796. spaces: {
  2797. before: space,
  2798. after: ''
  2799. }
  2800. }));
  2801. }
  2802. }
  2803. return nodes;
  2804. }
  2805. /**
  2806. *
  2807. * @param {*} nodes
  2808. */
  2809. ;
  2810. _proto.convertWhitespaceNodesToSpace = function convertWhitespaceNodesToSpace(nodes, requiredSpace) {
  2811. var _this2 = this;
  2812. if (requiredSpace === void 0) {
  2813. requiredSpace = false;
  2814. }
  2815. var space = "";
  2816. var rawSpace = "";
  2817. nodes.forEach(function (n) {
  2818. var spaceBefore = _this2.lossySpace(n.spaces.before, requiredSpace);
  2819. var rawSpaceBefore = _this2.lossySpace(n.rawSpaceBefore, requiredSpace);
  2820. space += spaceBefore + _this2.lossySpace(n.spaces.after, requiredSpace && spaceBefore.length === 0);
  2821. rawSpace += spaceBefore + n.value + _this2.lossySpace(n.rawSpaceAfter, requiredSpace && rawSpaceBefore.length === 0);
  2822. });
  2823. if (rawSpace === space) {
  2824. rawSpace = undefined;
  2825. }
  2826. var result = {
  2827. space: space,
  2828. rawSpace: rawSpace
  2829. };
  2830. return result;
  2831. };
  2832. _proto.isNamedCombinator = function isNamedCombinator(position) {
  2833. if (position === void 0) {
  2834. position = this.position;
  2835. }
  2836. return this.tokens[position + 0] && this.tokens[position + 0][_tokenize.FIELDS.TYPE] === tokens.slash && this.tokens[position + 1] && this.tokens[position + 1][_tokenize.FIELDS.TYPE] === tokens.word && this.tokens[position + 2] && this.tokens[position + 2][_tokenize.FIELDS.TYPE] === tokens.slash;
  2837. };
  2838. _proto.namedCombinator = function namedCombinator() {
  2839. if (this.isNamedCombinator()) {
  2840. var nameRaw = this.content(this.tokens[this.position + 1]);
  2841. var name = (0, _util.unesc)(nameRaw).toLowerCase();
  2842. var raws = {};
  2843. if (name !== nameRaw) {
  2844. raws.value = "/" + nameRaw + "/";
  2845. }
  2846. var node = new _combinator["default"]({
  2847. value: "/" + name + "/",
  2848. source: getSource(this.currToken[_tokenize.FIELDS.START_LINE], this.currToken[_tokenize.FIELDS.START_COL], this.tokens[this.position + 2][_tokenize.FIELDS.END_LINE], this.tokens[this.position + 2][_tokenize.FIELDS.END_COL]),
  2849. sourceIndex: this.currToken[_tokenize.FIELDS.START_POS],
  2850. raws: raws
  2851. });
  2852. this.position = this.position + 3;
  2853. return node;
  2854. } else {
  2855. this.unexpected();
  2856. }
  2857. };
  2858. _proto.combinator = function combinator() {
  2859. var _this3 = this;
  2860. if (this.content() === '|') {
  2861. return this.namespace();
  2862. } // We need to decide between a space that's a descendant combinator and meaningless whitespace at the end of a selector.
  2863. var nextSigTokenPos = this.locateNextMeaningfulToken(this.position);
  2864. if (nextSigTokenPos < 0 || this.tokens[nextSigTokenPos][_tokenize.FIELDS.TYPE] === tokens.comma) {
  2865. var nodes = this.parseWhitespaceEquivalentTokens(nextSigTokenPos);
  2866. if (nodes.length > 0) {
  2867. var last = this.current.last;
  2868. if (last) {
  2869. var _this$convertWhitespa = this.convertWhitespaceNodesToSpace(nodes),
  2870. space = _this$convertWhitespa.space,
  2871. rawSpace = _this$convertWhitespa.rawSpace;
  2872. if (rawSpace !== undefined) {
  2873. last.rawSpaceAfter += rawSpace;
  2874. }
  2875. last.spaces.after += space;
  2876. } else {
  2877. nodes.forEach(function (n) {
  2878. return _this3.newNode(n);
  2879. });
  2880. }
  2881. }
  2882. return;
  2883. }
  2884. var firstToken = this.currToken;
  2885. var spaceOrDescendantSelectorNodes = undefined;
  2886. if (nextSigTokenPos > this.position) {
  2887. spaceOrDescendantSelectorNodes = this.parseWhitespaceEquivalentTokens(nextSigTokenPos);
  2888. }
  2889. var node;
  2890. if (this.isNamedCombinator()) {
  2891. node = this.namedCombinator();
  2892. } else if (this.currToken[_tokenize.FIELDS.TYPE] === tokens.combinator) {
  2893. node = new _combinator["default"]({
  2894. value: this.content(),
  2895. source: getTokenSource(this.currToken),
  2896. sourceIndex: this.currToken[_tokenize.FIELDS.START_POS]
  2897. });
  2898. this.position++;
  2899. } else if (WHITESPACE_TOKENS[this.currToken[_tokenize.FIELDS.TYPE]]) ; else if (!spaceOrDescendantSelectorNodes) {
  2900. this.unexpected();
  2901. }
  2902. if (node) {
  2903. if (spaceOrDescendantSelectorNodes) {
  2904. var _this$convertWhitespa2 = this.convertWhitespaceNodesToSpace(spaceOrDescendantSelectorNodes),
  2905. _space = _this$convertWhitespa2.space,
  2906. _rawSpace = _this$convertWhitespa2.rawSpace;
  2907. node.spaces.before = _space;
  2908. node.rawSpaceBefore = _rawSpace;
  2909. }
  2910. } else {
  2911. // descendant combinator
  2912. var _this$convertWhitespa3 = this.convertWhitespaceNodesToSpace(spaceOrDescendantSelectorNodes, true),
  2913. _space2 = _this$convertWhitespa3.space,
  2914. _rawSpace2 = _this$convertWhitespa3.rawSpace;
  2915. if (!_rawSpace2) {
  2916. _rawSpace2 = _space2;
  2917. }
  2918. var spaces = {};
  2919. var raws = {
  2920. spaces: {}
  2921. };
  2922. if (_space2.endsWith(' ') && _rawSpace2.endsWith(' ')) {
  2923. spaces.before = _space2.slice(0, _space2.length - 1);
  2924. raws.spaces.before = _rawSpace2.slice(0, _rawSpace2.length - 1);
  2925. } else if (_space2.startsWith(' ') && _rawSpace2.startsWith(' ')) {
  2926. spaces.after = _space2.slice(1);
  2927. raws.spaces.after = _rawSpace2.slice(1);
  2928. } else {
  2929. raws.value = _rawSpace2;
  2930. }
  2931. node = new _combinator["default"]({
  2932. value: ' ',
  2933. source: getTokenSourceSpan(firstToken, this.tokens[this.position - 1]),
  2934. sourceIndex: firstToken[_tokenize.FIELDS.START_POS],
  2935. spaces: spaces,
  2936. raws: raws
  2937. });
  2938. }
  2939. if (this.currToken && this.currToken[_tokenize.FIELDS.TYPE] === tokens.space) {
  2940. node.spaces.after = this.optionalSpace(this.content());
  2941. this.position++;
  2942. }
  2943. return this.newNode(node);
  2944. };
  2945. _proto.comma = function comma() {
  2946. if (this.position === this.tokens.length - 1) {
  2947. this.root.trailingComma = true;
  2948. this.position++;
  2949. return;
  2950. }
  2951. this.current._inferEndPosition();
  2952. var selector = new _selector["default"]({
  2953. source: {
  2954. start: tokenStart(this.tokens[this.position + 1])
  2955. }
  2956. });
  2957. this.current.parent.append(selector);
  2958. this.current = selector;
  2959. this.position++;
  2960. };
  2961. _proto.comment = function comment() {
  2962. var current = this.currToken;
  2963. this.newNode(new _comment["default"]({
  2964. value: this.content(),
  2965. source: getTokenSource(current),
  2966. sourceIndex: current[_tokenize.FIELDS.START_POS]
  2967. }));
  2968. this.position++;
  2969. };
  2970. _proto.error = function error(message, opts) {
  2971. throw this.root.error(message, opts);
  2972. };
  2973. _proto.missingBackslash = function missingBackslash() {
  2974. return this.error('Expected a backslash preceding the semicolon.', {
  2975. index: this.currToken[_tokenize.FIELDS.START_POS]
  2976. });
  2977. };
  2978. _proto.missingParenthesis = function missingParenthesis() {
  2979. return this.expected('opening parenthesis', this.currToken[_tokenize.FIELDS.START_POS]);
  2980. };
  2981. _proto.missingSquareBracket = function missingSquareBracket() {
  2982. return this.expected('opening square bracket', this.currToken[_tokenize.FIELDS.START_POS]);
  2983. };
  2984. _proto.unexpected = function unexpected() {
  2985. return this.error("Unexpected '" + this.content() + "'. Escaping special characters with \\ may help.", this.currToken[_tokenize.FIELDS.START_POS]);
  2986. };
  2987. _proto.namespace = function namespace() {
  2988. var before = this.prevToken && this.content(this.prevToken) || true;
  2989. if (this.nextToken[_tokenize.FIELDS.TYPE] === tokens.word) {
  2990. this.position++;
  2991. return this.word(before);
  2992. } else if (this.nextToken[_tokenize.FIELDS.TYPE] === tokens.asterisk) {
  2993. this.position++;
  2994. return this.universal(before);
  2995. }
  2996. };
  2997. _proto.nesting = function nesting() {
  2998. if (this.nextToken) {
  2999. var nextContent = this.content(this.nextToken);
  3000. if (nextContent === "|") {
  3001. this.position++;
  3002. return;
  3003. }
  3004. }
  3005. var current = this.currToken;
  3006. this.newNode(new _nesting["default"]({
  3007. value: this.content(),
  3008. source: getTokenSource(current),
  3009. sourceIndex: current[_tokenize.FIELDS.START_POS]
  3010. }));
  3011. this.position++;
  3012. };
  3013. _proto.parentheses = function parentheses() {
  3014. var last = this.current.last;
  3015. var unbalanced = 1;
  3016. this.position++;
  3017. if (last && last.type === types$1.PSEUDO) {
  3018. var selector = new _selector["default"]({
  3019. source: {
  3020. start: tokenStart(this.tokens[this.position - 1])
  3021. }
  3022. });
  3023. var cache = this.current;
  3024. last.append(selector);
  3025. this.current = selector;
  3026. while (this.position < this.tokens.length && unbalanced) {
  3027. if (this.currToken[_tokenize.FIELDS.TYPE] === tokens.openParenthesis) {
  3028. unbalanced++;
  3029. }
  3030. if (this.currToken[_tokenize.FIELDS.TYPE] === tokens.closeParenthesis) {
  3031. unbalanced--;
  3032. }
  3033. if (unbalanced) {
  3034. this.parse();
  3035. } else {
  3036. this.current.source.end = tokenEnd(this.currToken);
  3037. this.current.parent.source.end = tokenEnd(this.currToken);
  3038. this.position++;
  3039. }
  3040. }
  3041. this.current = cache;
  3042. } else {
  3043. // I think this case should be an error. It's used to implement a basic parse of media queries
  3044. // but I don't think it's a good idea.
  3045. var parenStart = this.currToken;
  3046. var parenValue = "(";
  3047. var parenEnd;
  3048. while (this.position < this.tokens.length && unbalanced) {
  3049. if (this.currToken[_tokenize.FIELDS.TYPE] === tokens.openParenthesis) {
  3050. unbalanced++;
  3051. }
  3052. if (this.currToken[_tokenize.FIELDS.TYPE] === tokens.closeParenthesis) {
  3053. unbalanced--;
  3054. }
  3055. parenEnd = this.currToken;
  3056. parenValue += this.parseParenthesisToken(this.currToken);
  3057. this.position++;
  3058. }
  3059. if (last) {
  3060. last.appendToPropertyAndEscape("value", parenValue, parenValue);
  3061. } else {
  3062. this.newNode(new _string["default"]({
  3063. value: parenValue,
  3064. source: getSource(parenStart[_tokenize.FIELDS.START_LINE], parenStart[_tokenize.FIELDS.START_COL], parenEnd[_tokenize.FIELDS.END_LINE], parenEnd[_tokenize.FIELDS.END_COL]),
  3065. sourceIndex: parenStart[_tokenize.FIELDS.START_POS]
  3066. }));
  3067. }
  3068. }
  3069. if (unbalanced) {
  3070. return this.expected('closing parenthesis', this.currToken[_tokenize.FIELDS.START_POS]);
  3071. }
  3072. };
  3073. _proto.pseudo = function pseudo() {
  3074. var _this4 = this;
  3075. var pseudoStr = '';
  3076. var startingToken = this.currToken;
  3077. while (this.currToken && this.currToken[_tokenize.FIELDS.TYPE] === tokens.colon) {
  3078. pseudoStr += this.content();
  3079. this.position++;
  3080. }
  3081. if (!this.currToken) {
  3082. return this.expected(['pseudo-class', 'pseudo-element'], this.position - 1);
  3083. }
  3084. if (this.currToken[_tokenize.FIELDS.TYPE] === tokens.word) {
  3085. this.splitWord(false, function (first, length) {
  3086. pseudoStr += first;
  3087. _this4.newNode(new _pseudo["default"]({
  3088. value: pseudoStr,
  3089. source: getTokenSourceSpan(startingToken, _this4.currToken),
  3090. sourceIndex: startingToken[_tokenize.FIELDS.START_POS]
  3091. }));
  3092. if (length > 1 && _this4.nextToken && _this4.nextToken[_tokenize.FIELDS.TYPE] === tokens.openParenthesis) {
  3093. _this4.error('Misplaced parenthesis.', {
  3094. index: _this4.nextToken[_tokenize.FIELDS.START_POS]
  3095. });
  3096. }
  3097. });
  3098. } else {
  3099. return this.expected(['pseudo-class', 'pseudo-element'], this.currToken[_tokenize.FIELDS.START_POS]);
  3100. }
  3101. };
  3102. _proto.space = function space() {
  3103. var content = this.content(); // Handle space before and after the selector
  3104. if (this.position === 0 || this.prevToken[_tokenize.FIELDS.TYPE] === tokens.comma || this.prevToken[_tokenize.FIELDS.TYPE] === tokens.openParenthesis || this.current.nodes.every(function (node) {
  3105. return node.type === 'comment';
  3106. })) {
  3107. this.spaces = this.optionalSpace(content);
  3108. this.position++;
  3109. } else if (this.position === this.tokens.length - 1 || this.nextToken[_tokenize.FIELDS.TYPE] === tokens.comma || this.nextToken[_tokenize.FIELDS.TYPE] === tokens.closeParenthesis) {
  3110. this.current.last.spaces.after = this.optionalSpace(content);
  3111. this.position++;
  3112. } else {
  3113. this.combinator();
  3114. }
  3115. };
  3116. _proto.string = function string() {
  3117. var current = this.currToken;
  3118. this.newNode(new _string["default"]({
  3119. value: this.content(),
  3120. source: getTokenSource(current),
  3121. sourceIndex: current[_tokenize.FIELDS.START_POS]
  3122. }));
  3123. this.position++;
  3124. };
  3125. _proto.universal = function universal(namespace) {
  3126. var nextToken = this.nextToken;
  3127. if (nextToken && this.content(nextToken) === '|') {
  3128. this.position++;
  3129. return this.namespace();
  3130. }
  3131. var current = this.currToken;
  3132. this.newNode(new _universal["default"]({
  3133. value: this.content(),
  3134. source: getTokenSource(current),
  3135. sourceIndex: current[_tokenize.FIELDS.START_POS]
  3136. }), namespace);
  3137. this.position++;
  3138. };
  3139. _proto.splitWord = function splitWord(namespace, firstCallback) {
  3140. var _this5 = this;
  3141. var nextToken = this.nextToken;
  3142. var word = this.content();
  3143. while (nextToken && ~[tokens.dollar, tokens.caret, tokens.equals, tokens.word].indexOf(nextToken[_tokenize.FIELDS.TYPE])) {
  3144. this.position++;
  3145. var current = this.content();
  3146. word += current;
  3147. if (current.lastIndexOf('\\') === current.length - 1) {
  3148. var next = this.nextToken;
  3149. if (next && next[_tokenize.FIELDS.TYPE] === tokens.space) {
  3150. word += this.requiredSpace(this.content(next));
  3151. this.position++;
  3152. }
  3153. }
  3154. nextToken = this.nextToken;
  3155. }
  3156. var hasClass = indexesOf(word, '.').filter(function (i) {
  3157. // Allow escaped dot within class name
  3158. var escapedDot = word[i - 1] === '\\'; // Allow decimal numbers percent in @keyframes
  3159. var isKeyframesPercent = /^\d+\.\d+%$/.test(word);
  3160. return !escapedDot && !isKeyframesPercent;
  3161. });
  3162. var hasId = indexesOf(word, '#').filter(function (i) {
  3163. return word[i - 1] !== '\\';
  3164. }); // Eliminate Sass interpolations from the list of id indexes
  3165. var interpolations = indexesOf(word, '#{');
  3166. if (interpolations.length) {
  3167. hasId = hasId.filter(function (hashIndex) {
  3168. return !~interpolations.indexOf(hashIndex);
  3169. });
  3170. }
  3171. var indices = (0, _sortAscending["default"])(uniqs([0].concat(hasClass, hasId)));
  3172. indices.forEach(function (ind, i) {
  3173. var index = indices[i + 1] || word.length;
  3174. var value = word.slice(ind, index);
  3175. if (i === 0 && firstCallback) {
  3176. return firstCallback.call(_this5, value, indices.length);
  3177. }
  3178. var node;
  3179. var current = _this5.currToken;
  3180. var sourceIndex = current[_tokenize.FIELDS.START_POS] + indices[i];
  3181. var source = getSource(current[1], current[2] + ind, current[3], current[2] + (index - 1));
  3182. if (~hasClass.indexOf(ind)) {
  3183. var classNameOpts = {
  3184. value: value.slice(1),
  3185. source: source,
  3186. sourceIndex: sourceIndex
  3187. };
  3188. node = new _className["default"](unescapeProp(classNameOpts, "value"));
  3189. } else if (~hasId.indexOf(ind)) {
  3190. var idOpts = {
  3191. value: value.slice(1),
  3192. source: source,
  3193. sourceIndex: sourceIndex
  3194. };
  3195. node = new _id["default"](unescapeProp(idOpts, "value"));
  3196. } else {
  3197. var tagOpts = {
  3198. value: value,
  3199. source: source,
  3200. sourceIndex: sourceIndex
  3201. };
  3202. unescapeProp(tagOpts, "value");
  3203. node = new _tag["default"](tagOpts);
  3204. }
  3205. _this5.newNode(node, namespace); // Ensure that the namespace is used only once
  3206. namespace = null;
  3207. });
  3208. this.position++;
  3209. };
  3210. _proto.word = function word(namespace) {
  3211. var nextToken = this.nextToken;
  3212. if (nextToken && this.content(nextToken) === '|') {
  3213. this.position++;
  3214. return this.namespace();
  3215. }
  3216. return this.splitWord(namespace);
  3217. };
  3218. _proto.loop = function loop() {
  3219. while (this.position < this.tokens.length) {
  3220. this.parse(true);
  3221. }
  3222. this.current._inferEndPosition();
  3223. return this.root;
  3224. };
  3225. _proto.parse = function parse(throwOnParenthesis) {
  3226. switch (this.currToken[_tokenize.FIELDS.TYPE]) {
  3227. case tokens.space:
  3228. this.space();
  3229. break;
  3230. case tokens.comment:
  3231. this.comment();
  3232. break;
  3233. case tokens.openParenthesis:
  3234. this.parentheses();
  3235. break;
  3236. case tokens.closeParenthesis:
  3237. if (throwOnParenthesis) {
  3238. this.missingParenthesis();
  3239. }
  3240. break;
  3241. case tokens.openSquare:
  3242. this.attribute();
  3243. break;
  3244. case tokens.dollar:
  3245. case tokens.caret:
  3246. case tokens.equals:
  3247. case tokens.word:
  3248. this.word();
  3249. break;
  3250. case tokens.colon:
  3251. this.pseudo();
  3252. break;
  3253. case tokens.comma:
  3254. this.comma();
  3255. break;
  3256. case tokens.asterisk:
  3257. this.universal();
  3258. break;
  3259. case tokens.ampersand:
  3260. this.nesting();
  3261. break;
  3262. case tokens.slash:
  3263. case tokens.combinator:
  3264. this.combinator();
  3265. break;
  3266. case tokens.str:
  3267. this.string();
  3268. break;
  3269. // These cases throw; no break needed.
  3270. case tokens.closeSquare:
  3271. this.missingSquareBracket();
  3272. case tokens.semicolon:
  3273. this.missingBackslash();
  3274. default:
  3275. this.unexpected();
  3276. }
  3277. }
  3278. /**
  3279. * Helpers
  3280. */
  3281. ;
  3282. _proto.expected = function expected(description, index, found) {
  3283. if (Array.isArray(description)) {
  3284. var last = description.pop();
  3285. description = description.join(', ') + " or " + last;
  3286. }
  3287. var an = /^[aeiou]/.test(description[0]) ? 'an' : 'a';
  3288. if (!found) {
  3289. return this.error("Expected " + an + " " + description + ".", {
  3290. index: index
  3291. });
  3292. }
  3293. return this.error("Expected " + an + " " + description + ", found \"" + found + "\" instead.", {
  3294. index: index
  3295. });
  3296. };
  3297. _proto.requiredSpace = function requiredSpace(space) {
  3298. return this.options.lossy ? ' ' : space;
  3299. };
  3300. _proto.optionalSpace = function optionalSpace(space) {
  3301. return this.options.lossy ? '' : space;
  3302. };
  3303. _proto.lossySpace = function lossySpace(space, required) {
  3304. if (this.options.lossy) {
  3305. return required ? ' ' : '';
  3306. } else {
  3307. return space;
  3308. }
  3309. };
  3310. _proto.parseParenthesisToken = function parseParenthesisToken(token) {
  3311. var content = this.content(token);
  3312. if (token[_tokenize.FIELDS.TYPE] === tokens.space) {
  3313. return this.requiredSpace(content);
  3314. } else {
  3315. return content;
  3316. }
  3317. };
  3318. _proto.newNode = function newNode(node, namespace) {
  3319. if (namespace) {
  3320. if (/^ +$/.test(namespace)) {
  3321. if (!this.options.lossy) {
  3322. this.spaces = (this.spaces || '') + namespace;
  3323. }
  3324. namespace = true;
  3325. }
  3326. node.namespace = namespace;
  3327. unescapeProp(node, "namespace");
  3328. }
  3329. if (this.spaces) {
  3330. node.spaces.before = this.spaces;
  3331. this.spaces = '';
  3332. }
  3333. return this.current.append(node);
  3334. };
  3335. _proto.content = function content(token) {
  3336. if (token === void 0) {
  3337. token = this.currToken;
  3338. }
  3339. return this.css.slice(token[_tokenize.FIELDS.START_POS], token[_tokenize.FIELDS.END_POS]);
  3340. };
  3341. /**
  3342. * returns the index of the next non-whitespace, non-comment token.
  3343. * returns -1 if no meaningful token is found.
  3344. */
  3345. _proto.locateNextMeaningfulToken = function locateNextMeaningfulToken(startPosition) {
  3346. if (startPosition === void 0) {
  3347. startPosition = this.position + 1;
  3348. }
  3349. var searchPosition = startPosition;
  3350. while (searchPosition < this.tokens.length) {
  3351. if (WHITESPACE_EQUIV_TOKENS[this.tokens[searchPosition][_tokenize.FIELDS.TYPE]]) {
  3352. searchPosition++;
  3353. continue;
  3354. } else {
  3355. return searchPosition;
  3356. }
  3357. }
  3358. return -1;
  3359. };
  3360. _createClass(Parser, [{
  3361. key: "currToken",
  3362. get: function get() {
  3363. return this.tokens[this.position];
  3364. }
  3365. }, {
  3366. key: "nextToken",
  3367. get: function get() {
  3368. return this.tokens[this.position + 1];
  3369. }
  3370. }, {
  3371. key: "prevToken",
  3372. get: function get() {
  3373. return this.tokens[this.position - 1];
  3374. }
  3375. }]);
  3376. return Parser;
  3377. }();
  3378. exports["default"] = Parser;
  3379. module.exports = exports.default;
  3380. })(parser$1, parser$1.exports);
  3381. (function (module, exports) {
  3382. exports.__esModule = true;
  3383. exports["default"] = void 0;
  3384. var _parser = _interopRequireDefault(parser$1.exports);
  3385. function _interopRequireDefault(obj) {
  3386. return obj && obj.__esModule ? obj : {
  3387. "default": obj
  3388. };
  3389. }
  3390. var Processor = /*#__PURE__*/function () {
  3391. function Processor(func, options) {
  3392. this.func = func || function noop() {};
  3393. this.funcRes = null;
  3394. this.options = options;
  3395. }
  3396. var _proto = Processor.prototype;
  3397. _proto._shouldUpdateSelector = function _shouldUpdateSelector(rule, options) {
  3398. if (options === void 0) {
  3399. options = {};
  3400. }
  3401. var merged = Object.assign({}, this.options, options);
  3402. if (merged.updateSelector === false) {
  3403. return false;
  3404. } else {
  3405. return typeof rule !== "string";
  3406. }
  3407. };
  3408. _proto._isLossy = function _isLossy(options) {
  3409. if (options === void 0) {
  3410. options = {};
  3411. }
  3412. var merged = Object.assign({}, this.options, options);
  3413. if (merged.lossless === false) {
  3414. return true;
  3415. } else {
  3416. return false;
  3417. }
  3418. };
  3419. _proto._root = function _root(rule, options) {
  3420. if (options === void 0) {
  3421. options = {};
  3422. }
  3423. var parser = new _parser["default"](rule, this._parseOptions(options));
  3424. return parser.root;
  3425. };
  3426. _proto._parseOptions = function _parseOptions(options) {
  3427. return {
  3428. lossy: this._isLossy(options)
  3429. };
  3430. };
  3431. _proto._run = function _run(rule, options) {
  3432. var _this = this;
  3433. if (options === void 0) {
  3434. options = {};
  3435. }
  3436. return new Promise(function (resolve, reject) {
  3437. try {
  3438. var root = _this._root(rule, options);
  3439. Promise.resolve(_this.func(root)).then(function (transform) {
  3440. var string = undefined;
  3441. if (_this._shouldUpdateSelector(rule, options)) {
  3442. string = root.toString();
  3443. rule.selector = string;
  3444. }
  3445. return {
  3446. transform: transform,
  3447. root: root,
  3448. string: string
  3449. };
  3450. }).then(resolve, reject);
  3451. } catch (e) {
  3452. reject(e);
  3453. return;
  3454. }
  3455. });
  3456. };
  3457. _proto._runSync = function _runSync(rule, options) {
  3458. if (options === void 0) {
  3459. options = {};
  3460. }
  3461. var root = this._root(rule, options);
  3462. var transform = this.func(root);
  3463. if (transform && typeof transform.then === "function") {
  3464. throw new Error("Selector processor returned a promise to a synchronous call.");
  3465. }
  3466. var string = undefined;
  3467. if (options.updateSelector && typeof rule !== "string") {
  3468. string = root.toString();
  3469. rule.selector = string;
  3470. }
  3471. return {
  3472. transform: transform,
  3473. root: root,
  3474. string: string
  3475. };
  3476. }
  3477. /**
  3478. * Process rule into a selector AST.
  3479. *
  3480. * @param rule {postcss.Rule | string} The css selector to be processed
  3481. * @param options The options for processing
  3482. * @returns {Promise<parser.Root>} The AST of the selector after processing it.
  3483. */
  3484. ;
  3485. _proto.ast = function ast(rule, options) {
  3486. return this._run(rule, options).then(function (result) {
  3487. return result.root;
  3488. });
  3489. }
  3490. /**
  3491. * Process rule into a selector AST synchronously.
  3492. *
  3493. * @param rule {postcss.Rule | string} The css selector to be processed
  3494. * @param options The options for processing
  3495. * @returns {parser.Root} The AST of the selector after processing it.
  3496. */
  3497. ;
  3498. _proto.astSync = function astSync(rule, options) {
  3499. return this._runSync(rule, options).root;
  3500. }
  3501. /**
  3502. * Process a selector into a transformed value asynchronously
  3503. *
  3504. * @param rule {postcss.Rule | string} The css selector to be processed
  3505. * @param options The options for processing
  3506. * @returns {Promise<any>} The value returned by the processor.
  3507. */
  3508. ;
  3509. _proto.transform = function transform(rule, options) {
  3510. return this._run(rule, options).then(function (result) {
  3511. return result.transform;
  3512. });
  3513. }
  3514. /**
  3515. * Process a selector into a transformed value synchronously.
  3516. *
  3517. * @param rule {postcss.Rule | string} The css selector to be processed
  3518. * @param options The options for processing
  3519. * @returns {any} The value returned by the processor.
  3520. */
  3521. ;
  3522. _proto.transformSync = function transformSync(rule, options) {
  3523. return this._runSync(rule, options).transform;
  3524. }
  3525. /**
  3526. * Process a selector into a new selector string asynchronously.
  3527. *
  3528. * @param rule {postcss.Rule | string} The css selector to be processed
  3529. * @param options The options for processing
  3530. * @returns {string} the selector after processing.
  3531. */
  3532. ;
  3533. _proto.process = function process(rule, options) {
  3534. return this._run(rule, options).then(function (result) {
  3535. return result.string || result.root.toString();
  3536. });
  3537. }
  3538. /**
  3539. * Process a selector into a new selector string synchronously.
  3540. *
  3541. * @param rule {postcss.Rule | string} The css selector to be processed
  3542. * @param options The options for processing
  3543. * @returns {string} the selector after processing.
  3544. */
  3545. ;
  3546. _proto.processSync = function processSync(rule, options) {
  3547. var result = this._runSync(rule, options);
  3548. return result.string || result.root.toString();
  3549. };
  3550. return Processor;
  3551. }();
  3552. exports["default"] = Processor;
  3553. module.exports = exports.default;
  3554. })(processor, processor.exports);
  3555. var selectors = {};
  3556. var constructors = {};
  3557. constructors.__esModule = true;
  3558. constructors.universal = constructors.tag = constructors.string = constructors.selector = constructors.root = constructors.pseudo = constructors.nesting = constructors.id = constructors.comment = constructors.combinator = constructors.className = constructors.attribute = void 0;
  3559. var _attribute = _interopRequireDefault(attribute$1);
  3560. var _className = _interopRequireDefault(className$1.exports);
  3561. var _combinator = _interopRequireDefault(combinator$2.exports);
  3562. var _comment = _interopRequireDefault(comment$2.exports);
  3563. var _id = _interopRequireDefault(id$1.exports);
  3564. var _nesting = _interopRequireDefault(nesting$1.exports);
  3565. var _pseudo = _interopRequireDefault(pseudo$1.exports);
  3566. var _root = _interopRequireDefault(root$1.exports);
  3567. var _selector = _interopRequireDefault(selector$1.exports);
  3568. var _string = _interopRequireDefault(string$1.exports);
  3569. var _tag = _interopRequireDefault(tag$1.exports);
  3570. var _universal = _interopRequireDefault(universal$1.exports);
  3571. function _interopRequireDefault(obj) {
  3572. return obj && obj.__esModule ? obj : {
  3573. "default": obj
  3574. };
  3575. }
  3576. var attribute = function attribute(opts) {
  3577. return new _attribute["default"](opts);
  3578. };
  3579. constructors.attribute = attribute;
  3580. var className = function className(opts) {
  3581. return new _className["default"](opts);
  3582. };
  3583. constructors.className = className;
  3584. var combinator = function combinator(opts) {
  3585. return new _combinator["default"](opts);
  3586. };
  3587. constructors.combinator = combinator;
  3588. var comment = function comment(opts) {
  3589. return new _comment["default"](opts);
  3590. };
  3591. constructors.comment = comment;
  3592. var id = function id(opts) {
  3593. return new _id["default"](opts);
  3594. };
  3595. constructors.id = id;
  3596. var nesting = function nesting(opts) {
  3597. return new _nesting["default"](opts);
  3598. };
  3599. constructors.nesting = nesting;
  3600. var pseudo = function pseudo(opts) {
  3601. return new _pseudo["default"](opts);
  3602. };
  3603. constructors.pseudo = pseudo;
  3604. var root = function root(opts) {
  3605. return new _root["default"](opts);
  3606. };
  3607. constructors.root = root;
  3608. var selector = function selector(opts) {
  3609. return new _selector["default"](opts);
  3610. };
  3611. constructors.selector = selector;
  3612. var string = function string(opts) {
  3613. return new _string["default"](opts);
  3614. };
  3615. constructors.string = string;
  3616. var tag = function tag(opts) {
  3617. return new _tag["default"](opts);
  3618. };
  3619. constructors.tag = tag;
  3620. var universal = function universal(opts) {
  3621. return new _universal["default"](opts);
  3622. };
  3623. constructors.universal = universal;
  3624. var guards = {};
  3625. guards.__esModule = true;
  3626. guards.isNode = isNode;
  3627. guards.isPseudoElement = isPseudoElement;
  3628. guards.isPseudoClass = isPseudoClass;
  3629. guards.isContainer = isContainer;
  3630. guards.isNamespace = isNamespace;
  3631. guards.isUniversal = guards.isTag = guards.isString = guards.isSelector = guards.isRoot = guards.isPseudo = guards.isNesting = guards.isIdentifier = guards.isComment = guards.isCombinator = guards.isClassName = guards.isAttribute = void 0;
  3632. var _types = types;
  3633. var _IS_TYPE;
  3634. var IS_TYPE = (_IS_TYPE = {}, _IS_TYPE[_types.ATTRIBUTE] = true, _IS_TYPE[_types.CLASS] = true, _IS_TYPE[_types.COMBINATOR] = true, _IS_TYPE[_types.COMMENT] = true, _IS_TYPE[_types.ID] = true, _IS_TYPE[_types.NESTING] = true, _IS_TYPE[_types.PSEUDO] = true, _IS_TYPE[_types.ROOT] = true, _IS_TYPE[_types.SELECTOR] = true, _IS_TYPE[_types.STRING] = true, _IS_TYPE[_types.TAG] = true, _IS_TYPE[_types.UNIVERSAL] = true, _IS_TYPE);
  3635. function isNode(node) {
  3636. return typeof node === "object" && IS_TYPE[node.type];
  3637. }
  3638. function isNodeType(type, node) {
  3639. return isNode(node) && node.type === type;
  3640. }
  3641. var isAttribute = isNodeType.bind(null, _types.ATTRIBUTE);
  3642. guards.isAttribute = isAttribute;
  3643. var isClassName = isNodeType.bind(null, _types.CLASS);
  3644. guards.isClassName = isClassName;
  3645. var isCombinator = isNodeType.bind(null, _types.COMBINATOR);
  3646. guards.isCombinator = isCombinator;
  3647. var isComment = isNodeType.bind(null, _types.COMMENT);
  3648. guards.isComment = isComment;
  3649. var isIdentifier = isNodeType.bind(null, _types.ID);
  3650. guards.isIdentifier = isIdentifier;
  3651. var isNesting = isNodeType.bind(null, _types.NESTING);
  3652. guards.isNesting = isNesting;
  3653. var isPseudo$1 = isNodeType.bind(null, _types.PSEUDO);
  3654. guards.isPseudo = isPseudo$1;
  3655. var isRoot = isNodeType.bind(null, _types.ROOT);
  3656. guards.isRoot = isRoot;
  3657. var isSelector = isNodeType.bind(null, _types.SELECTOR);
  3658. guards.isSelector = isSelector;
  3659. var isString = isNodeType.bind(null, _types.STRING);
  3660. guards.isString = isString;
  3661. var isTag = isNodeType.bind(null, _types.TAG);
  3662. guards.isTag = isTag;
  3663. var isUniversal = isNodeType.bind(null, _types.UNIVERSAL);
  3664. guards.isUniversal = isUniversal;
  3665. function isPseudoElement(node) {
  3666. return isPseudo$1(node) && node.value && (node.value.startsWith("::") || node.value.toLowerCase() === ":before" || node.value.toLowerCase() === ":after");
  3667. }
  3668. function isPseudoClass(node) {
  3669. return isPseudo$1(node) && !isPseudoElement(node);
  3670. }
  3671. function isContainer(node) {
  3672. return !!(isNode(node) && node.walk);
  3673. }
  3674. function isNamespace(node) {
  3675. return isAttribute(node) || isTag(node);
  3676. }
  3677. (function (exports) {
  3678. exports.__esModule = true;
  3679. var _types = types;
  3680. Object.keys(_types).forEach(function (key) {
  3681. if (key === "default" || key === "__esModule") return;
  3682. if (key in exports && exports[key] === _types[key]) return;
  3683. exports[key] = _types[key];
  3684. });
  3685. var _constructors = constructors;
  3686. Object.keys(_constructors).forEach(function (key) {
  3687. if (key === "default" || key === "__esModule") return;
  3688. if (key in exports && exports[key] === _constructors[key]) return;
  3689. exports[key] = _constructors[key];
  3690. });
  3691. var _guards = guards;
  3692. Object.keys(_guards).forEach(function (key) {
  3693. if (key === "default" || key === "__esModule") return;
  3694. if (key in exports && exports[key] === _guards[key]) return;
  3695. exports[key] = _guards[key];
  3696. });
  3697. })(selectors);
  3698. (function (module, exports) {
  3699. exports.__esModule = true;
  3700. exports["default"] = void 0;
  3701. var _processor = _interopRequireDefault(processor.exports);
  3702. var selectors$1 = _interopRequireWildcard(selectors);
  3703. function _getRequireWildcardCache() {
  3704. if (typeof WeakMap !== "function") return null;
  3705. var cache = new WeakMap();
  3706. _getRequireWildcardCache = function _getRequireWildcardCache() {
  3707. return cache;
  3708. };
  3709. return cache;
  3710. }
  3711. function _interopRequireWildcard(obj) {
  3712. if (obj && obj.__esModule) {
  3713. return obj;
  3714. }
  3715. if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
  3716. return {
  3717. "default": obj
  3718. };
  3719. }
  3720. var cache = _getRequireWildcardCache();
  3721. if (cache && cache.has(obj)) {
  3722. return cache.get(obj);
  3723. }
  3724. var newObj = {};
  3725. var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
  3726. for (var key in obj) {
  3727. if (Object.prototype.hasOwnProperty.call(obj, key)) {
  3728. var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
  3729. if (desc && (desc.get || desc.set)) {
  3730. Object.defineProperty(newObj, key, desc);
  3731. } else {
  3732. newObj[key] = obj[key];
  3733. }
  3734. }
  3735. }
  3736. newObj["default"] = obj;
  3737. if (cache) {
  3738. cache.set(obj, newObj);
  3739. }
  3740. return newObj;
  3741. }
  3742. function _interopRequireDefault(obj) {
  3743. return obj && obj.__esModule ? obj : {
  3744. "default": obj
  3745. };
  3746. }
  3747. var parser = function parser(processor) {
  3748. return new _processor["default"](processor);
  3749. };
  3750. Object.assign(parser, selectors$1);
  3751. delete parser.__esModule;
  3752. var _default = parser;
  3753. exports["default"] = _default;
  3754. module.exports = exports.default;
  3755. })(dist, dist.exports);
  3756. var parser = /*@__PURE__*/getDefaultExportFromCjs(dist.exports);
  3757. function combinationsWithSizeN(set, n) {
  3758. // set is the list of parent selectors
  3759. // n is the amount of `&` selectors in the current selector.
  3760. // all combinations of values in the set with an array size of n must be generated to match the nesting selector behavior.
  3761. //
  3762. // for example :
  3763. // a current selector like: `& + & {}`
  3764. // with parent : `.foo, .bar {}`
  3765. //
  3766. // the set is `['.foo', '.bar']` and n is 2, the resulting combinations are:
  3767. // ['.foo', '.bar']
  3768. // ['.foo', '.foo']
  3769. // ['.bar', '.foo']
  3770. // ['.bar', '.bar']
  3771. //
  3772. // outputted like :
  3773. // .foo + .bar,
  3774. // .foo + .foo,
  3775. // .bar + .foo,
  3776. // .bar + .bar {}
  3777. if (n < 2) {
  3778. // should never happen and is checked by caller
  3779. throw new Error('n must be greater than 1');
  3780. }
  3781. if (set.length < 2) {
  3782. // should never happen and is checked by caller
  3783. throw new Error('s must be greater than 1');
  3784. }
  3785. if (Math.pow(set.length, n) > 10000) {
  3786. // Throwing is best here as a warning would be impossible to handle gracefully on our end.
  3787. // This will error mid transform and there is no possible fallback at this point.
  3788. // The user should reduce complexity.
  3789. throw new Error('Too many combinations when trying to resolve a nested selector with lists, reduce the complexity of your selectors');
  3790. }
  3791. const counters = [];
  3792. for (let i = 0; i < n; i++) {
  3793. counters[i] = 0;
  3794. }
  3795. const result = []; // eslint-disable-next-line no-constant-condition
  3796. while (true) {
  3797. const ss = [];
  3798. for (let i = n - 1; i >= 0; i--) {
  3799. let currentCounter = counters[i];
  3800. if (currentCounter >= set.length) {
  3801. currentCounter = 0;
  3802. counters[i] = 0;
  3803. if (i === 0) {
  3804. return result;
  3805. } else {
  3806. counters[i - 1] += 1;
  3807. }
  3808. }
  3809. ss[i] = set[currentCounter];
  3810. }
  3811. result.push(ss);
  3812. counters[counters.length - 1]++;
  3813. }
  3814. }
  3815. const isPseudo = parser.pseudo({
  3816. value: ':is'
  3817. });
  3818. function wrapMultipleTagSelectorsWithIsPseudo(node) {
  3819. // This is a fallback for broken selectors like:
  3820. // `h1h2`
  3821. // These selectors are also useless as `h1:is(h2)`.
  3822. // Wrapping with is only prevents accidentally forming other words which might have meaning.
  3823. const tagNodes = node.nodes.filter(x => {
  3824. return x.type === 'tag';
  3825. });
  3826. if (tagNodes.length > 1) {
  3827. tagNodes.slice(1).forEach(child => {
  3828. const isPseudoClone = isPseudo.clone();
  3829. child.replaceWith(isPseudoClone);
  3830. isPseudoClone.append(child);
  3831. });
  3832. }
  3833. }
  3834. function sortCompoundSelectorsInsideComplexSelector(node, wrapWithIsPseudo) {
  3835. let compound = [];
  3836. let foundOtherNesting = false;
  3837. const nodes = [...node.nodes];
  3838. for (let i = 0; i < nodes.length + 1; i++) {
  3839. const child = nodes[i];
  3840. if (!child || child.type === 'combinator') {
  3841. if (foundOtherNesting) {
  3842. // nesting walker will further manipulate the selector and revisit this function later.
  3843. // not skipping here will break the nesting walker as the order and contents of the nodes have changed too much.
  3844. compound = [];
  3845. continue;
  3846. }
  3847. if (compound.length > 1) {
  3848. const compoundSelector = parser.selector();
  3849. compound[0].replaceWith(compoundSelector);
  3850. compound.slice(1).forEach(compoundPart => {
  3851. compoundPart.remove();
  3852. });
  3853. compound.forEach(compoundPart => {
  3854. compoundSelector.append(compoundPart);
  3855. });
  3856. sortCompoundSelector(compoundSelector);
  3857. if (wrapWithIsPseudo) {
  3858. wrapMultipleTagSelectorsWithIsPseudo(compoundSelector);
  3859. }
  3860. compoundSelector.replaceWith(...compoundSelector.nodes);
  3861. }
  3862. compound = [];
  3863. continue;
  3864. }
  3865. if (child.type === 'nesting') {
  3866. foundOtherNesting = true;
  3867. }
  3868. compound.push(child);
  3869. }
  3870. }
  3871. function sortCompoundSelector(node) {
  3872. // compound selectors with nesting can be written with tag selectors as later parts.
  3873. // for example : `&h1`
  3874. //
  3875. // simply concating with parent selectors can lead to :
  3876. // `.fooh1`
  3877. //
  3878. // applying a sort where tag selectors are first will result in :
  3879. // `h1.foo`
  3880. node.nodes.sort((a, b) => {
  3881. if (a.type === b.type) {
  3882. return 0;
  3883. }
  3884. if (selectorTypeOrder[a.type] < selectorTypeOrder[b.type]) {
  3885. return -1;
  3886. }
  3887. return 1;
  3888. });
  3889. }
  3890. const selectorTypeOrder = {
  3891. universal: 0,
  3892. tag: 1,
  3893. id: 2,
  3894. class: 3,
  3895. attribute: 4,
  3896. pseudo: 5,
  3897. selector: 7,
  3898. string: 8,
  3899. root: 9,
  3900. comment: 10,
  3901. nesting: 9999
  3902. };
  3903. function nodesAreEquallySpecific(nodes) {
  3904. // Selector specificity is important when the parent selector is a list.
  3905. // These cases should be resolved with `:is()` pseudo.
  3906. // Since browser support for `:is()` is not great, we try to avoid it.
  3907. // If the selector specificity is equal for all items in the selector list, we don't need `:is`.
  3908. const specificities = nodes.map(node => {
  3909. return parser().astSync(node);
  3910. }).map(ast => {
  3911. return selectorSpecificity(ast);
  3912. });
  3913. const first = specificities[0];
  3914. for (let i = 1; i < specificities.length; i++) {
  3915. if (first.a === specificities[i].a && first.b === specificities[i].b && first.c === specificities[i].c) {
  3916. continue;
  3917. }
  3918. return false;
  3919. }
  3920. return true;
  3921. }
  3922. function selectorSpecificity(node) {
  3923. let a = 0;
  3924. let b = 0;
  3925. let c = 0;
  3926. if (node.type === 'id') {
  3927. a += 1;
  3928. } else if (node.type === 'tag') {
  3929. c += 1;
  3930. } else if (node.type === 'class') {
  3931. b += 1;
  3932. } else if (node.type === 'attribute') {
  3933. b += 1;
  3934. } else if (node.type === 'pseudo') {
  3935. switch (node.value) {
  3936. case '::after':
  3937. case ':after':
  3938. case '::backdrop':
  3939. case '::before':
  3940. case ':before':
  3941. case '::cue':
  3942. case '::cue-region':
  3943. case '::first-letter':
  3944. case ':first-letter':
  3945. case '::first-line':
  3946. case ':first-line':
  3947. case '::file-selector-button':
  3948. case '::grammar-error':
  3949. case '::marker':
  3950. case '::part':
  3951. case '::placeholder':
  3952. case '::selection':
  3953. case '::slotted':
  3954. case '::spelling-error':
  3955. case '::target-text':
  3956. c += 1;
  3957. break;
  3958. case ':is':
  3959. case ':has':
  3960. case ':not':
  3961. {
  3962. if (node.nodes && node.nodes.length > 0) {
  3963. let mostSpecificListItem = {
  3964. a: 0,
  3965. b: 0,
  3966. c: 0
  3967. };
  3968. node.nodes.forEach(child => {
  3969. const itemSpecificity = selectorSpecificity(child);
  3970. if (itemSpecificity.a > mostSpecificListItem.a) {
  3971. mostSpecificListItem = itemSpecificity;
  3972. return;
  3973. } else if (itemSpecificity.a < mostSpecificListItem.a) {
  3974. return;
  3975. }
  3976. if (itemSpecificity.b > mostSpecificListItem.b) {
  3977. mostSpecificListItem = itemSpecificity;
  3978. return;
  3979. } else if (itemSpecificity.b < mostSpecificListItem.b) {
  3980. return;
  3981. }
  3982. if (itemSpecificity.c > mostSpecificListItem.c) {
  3983. mostSpecificListItem = itemSpecificity;
  3984. return;
  3985. }
  3986. });
  3987. a += mostSpecificListItem.a;
  3988. b += mostSpecificListItem.b;
  3989. c += mostSpecificListItem.c;
  3990. }
  3991. break;
  3992. }
  3993. case 'where':
  3994. break;
  3995. case ':nth-child':
  3996. case ':nth-last-child':
  3997. {
  3998. const ofSeparatorIndex = node.nodes.findIndex(x => {
  3999. x.value === 'of';
  4000. });
  4001. if (ofSeparatorIndex > -1) {
  4002. const ofSpecificity = selectorSpecificity(parser.selector({
  4003. nodes: node.nodes.slice(ofSeparatorIndex + 1)
  4004. }));
  4005. a += ofSpecificity.a;
  4006. b += ofSpecificity.b;
  4007. c += ofSpecificity.c;
  4008. } else {
  4009. a += a;
  4010. b += b;
  4011. c += c;
  4012. }
  4013. }
  4014. break;
  4015. default:
  4016. b += 1;
  4017. }
  4018. } else if (node.nodes && node.nodes.length > 0) {
  4019. node.nodes.forEach(child => {
  4020. const specificity = selectorSpecificity(child);
  4021. a += specificity.a;
  4022. b += specificity.b;
  4023. c += specificity.c;
  4024. });
  4025. }
  4026. return {
  4027. a,
  4028. b,
  4029. c
  4030. };
  4031. }
  4032. function mergeSelectors(fromSelectors, toSelectors, opts) {
  4033. const fromListHasUniformSpecificity = nodesAreEquallySpecific(fromSelectors);
  4034. let fromSelectorsAST = [];
  4035. if (fromListHasUniformSpecificity || opts.noIsPseudoSelector) {
  4036. fromSelectorsAST = fromSelectors.map(selector => {
  4037. return parser().astSync(selector);
  4038. });
  4039. } else {
  4040. fromSelectorsAST = [parser().astSync(`:is(${fromSelectors.join(',')})`)];
  4041. }
  4042. let result = [];
  4043. for (let x = 0; x < toSelectors.length; x++) {
  4044. const toSelector = toSelectors[x];
  4045. let iterations = 1;
  4046. let fromSelectorCombinations = [];
  4047. let nestingCounter = 0;
  4048. parser().astSync(toSelector).walkNesting(() => {
  4049. nestingCounter++;
  4050. });
  4051. if (nestingCounter > 1 && fromSelectorsAST.length > 1) {
  4052. fromSelectorCombinations = combinationsWithSizeN(fromSelectorsAST, nestingCounter);
  4053. iterations = fromSelectorCombinations.length;
  4054. } else {
  4055. iterations = fromSelectorsAST.length;
  4056. for (let i = 0; i < fromSelectorsAST.length; i++) {
  4057. fromSelectorCombinations.push([]);
  4058. for (let j = 0; j < nestingCounter; j++) {
  4059. fromSelectorCombinations[i].push(fromSelectorsAST[i]);
  4060. }
  4061. }
  4062. }
  4063. for (let y = 0; y < iterations; y++) {
  4064. let counter = 0;
  4065. const toSelectorAST = parser().astSync(toSelector);
  4066. toSelectorAST.walk(nesting => {
  4067. if (nesting.type !== 'nesting') {
  4068. return;
  4069. }
  4070. let fromSelectorAST = fromSelectorCombinations[y][counter];
  4071. counter++; // If the from selector is simple we extract the first non root, non selector node
  4072. if (fromSelectorAST.type === 'root' && fromSelectorAST.nodes.length === 1) {
  4073. fromSelectorAST = fromSelectorAST.nodes[0];
  4074. }
  4075. const fromSelectorWithIsAST = parser().astSync(`:is(${fromSelectorAST.toString()})`);
  4076. const fromIsSimple = isSimpleSelector(fromSelectorAST.nodes[0]); // this function looks at the parent of the node passed as an argument
  4077. const fromIsCompound = isCompoundSelector(fromSelectorAST.nodes[0]); // this function looks at the parent of the node passed as an argument
  4078. const toIsSimple = isSimpleSelector(nesting);
  4079. const toIsCompound = isCompoundSelector(nesting); // Parent and child are simple
  4080. if (fromIsSimple && toIsSimple) {
  4081. nesting.replaceWith(fromSelectorAST.clone());
  4082. return;
  4083. } // Parent and child are simple or compound
  4084. if ((fromIsSimple || fromIsCompound) && (toIsSimple || toIsCompound)) {
  4085. const parent = nesting.parent;
  4086. if (fromIsSimple && fromSelectorAST.type === 'selector') {
  4087. // fromSelectorAST has type selector with a single child
  4088. nesting.replaceWith(fromSelectorAST.clone().nodes[0]);
  4089. } else {
  4090. // fromSelectorAST has type selector containing a compound selector
  4091. nesting.replaceWith(...fromSelectorAST.clone().nodes);
  4092. }
  4093. if (parent && parent.nodes.length > 1) {
  4094. sortCompoundSelector(parent);
  4095. if (!opts.noIsPseudoSelector) {
  4096. wrapMultipleTagSelectorsWithIsPseudo(parent);
  4097. }
  4098. }
  4099. return;
  4100. }
  4101. if (fromIsSimple) {
  4102. const parent = nesting.parent;
  4103. nesting.replaceWith(fromSelectorAST.clone().nodes[0]);
  4104. if (parent) {
  4105. sortCompoundSelectorsInsideComplexSelector(parent, !opts.noIsPseudoSelector);
  4106. }
  4107. return;
  4108. }
  4109. if (fromIsCompound) {
  4110. const parent = nesting.parent;
  4111. nesting.replaceWith(...fromSelectorAST.clone().nodes);
  4112. if (parent) {
  4113. sortCompoundSelectorsInsideComplexSelector(parent, !opts.noIsPseudoSelector);
  4114. }
  4115. return;
  4116. }
  4117. if (nestingIsFirstAndOnlyInSelectorWithEitherSpaceOrChildCombinator(nesting)) {
  4118. const parent = nesting.parent;
  4119. nesting.replaceWith(...fromSelectorAST.clone().nodes);
  4120. if (parent) {
  4121. sortCompoundSelectorsInsideComplexSelector(parent, !opts.noIsPseudoSelector);
  4122. }
  4123. return;
  4124. }
  4125. if (nestingIsNotInsideCompoundSelector(nesting)) {
  4126. const parent = nesting.parent;
  4127. nesting.replaceWith(...fromSelectorAST.clone().nodes);
  4128. if (parent) {
  4129. sortCompoundSelectorsInsideComplexSelector(parent, !opts.noIsPseudoSelector);
  4130. }
  4131. return;
  4132. }
  4133. const parent = nesting.parent;
  4134. if (opts.noIsPseudoSelector) {
  4135. nesting.replaceWith(...fromSelectorAST.clone().nodes);
  4136. } else {
  4137. nesting.replaceWith(...fromSelectorWithIsAST.clone().nodes);
  4138. }
  4139. if (parent) {
  4140. sortCompoundSelectorsInsideComplexSelector(parent, !opts.noIsPseudoSelector);
  4141. }
  4142. });
  4143. result.push(toSelectorAST.toString());
  4144. }
  4145. }
  4146. return result;
  4147. }
  4148. function isSimpleSelector(selector) {
  4149. if (selector.type === 'combinator') {
  4150. return false;
  4151. }
  4152. if (selector.parent && selector.parent.nodes.length > 1) {
  4153. return false;
  4154. }
  4155. return true;
  4156. }
  4157. function isCompoundSelector(selector, toSelector = null) {
  4158. if (isSimpleSelector(selector)) {
  4159. return false;
  4160. }
  4161. if (!selector.parent) {
  4162. return false;
  4163. }
  4164. const hasCombinators = !!selector.parent.nodes.find(x => {
  4165. return x.type === 'combinator' || x.type === 'comment';
  4166. });
  4167. if (hasCombinators) {
  4168. return false;
  4169. }
  4170. const hasExtraNesting = !!selector.parent.nodes.find(x => {
  4171. return x.type === 'nesting';
  4172. });
  4173. if (hasExtraNesting && toSelector && !isCompoundSelector(toSelector)) {
  4174. return false;
  4175. }
  4176. return true;
  4177. }
  4178. function nestingIsFirstAndOnlyInSelectorWithEitherSpaceOrChildCombinator(selector) {
  4179. if (!selector.parent) {
  4180. return false;
  4181. }
  4182. if (selector.parent.nodes.indexOf(selector) !== 0) {
  4183. return false;
  4184. }
  4185. for (let i = 1; i < selector.parent.nodes.length; i++) {
  4186. if (selector.parent.nodes[i].type === 'combinator' && selector.parent.nodes[i].value !== ' ' && selector.parent.nodes[i].value !== '>') {
  4187. return false;
  4188. }
  4189. }
  4190. return true;
  4191. }
  4192. function nestingIsNotInsideCompoundSelector(selector) {
  4193. if (isSimpleSelector(selector)) {
  4194. return true;
  4195. }
  4196. if (!selector.parent) {
  4197. return false;
  4198. }
  4199. for (let i = 0; i < selector.parent.nodes.length; i++) {
  4200. if (!selector.parent.nodes[i].type === 'nesting') {
  4201. continue;
  4202. }
  4203. if (!selector.parent.nodes[i].prev() && !selector.parent.nodes[i].next()) {
  4204. continue;
  4205. }
  4206. if (selector.parent.nodes[i].prev() && selector.parent.nodes[i].prev().type !== 'combinator') {
  4207. return false;
  4208. }
  4209. if (selector.parent.nodes[i].next() && selector.parent.nodes[i].next().type !== 'combinator') {
  4210. return false;
  4211. }
  4212. }
  4213. return true;
  4214. }
  4215. function transformRuleWithinRule(node, opts) {
  4216. // move previous siblings and the node to before the parent
  4217. const parent = shiftNodesBeforeParent(node); // update the selectors of the node to be merged with the parent
  4218. node.selectors = mergeSelectors(parent.selectors, node.selectors, opts); // merge similar rules back together
  4219. const areSameRule = node.type === 'rule' && parent.type === 'rule' && node.selector === parent.selector || node.type === 'atrule' && parent.type === 'atrule' && node.params === parent.params;
  4220. if (areSameRule) {
  4221. node.append(...parent.nodes);
  4222. } // conditionally cleanup an empty parent rule
  4223. cleanupParent(parent);
  4224. }
  4225. const isRuleWithinRule = node => node.type === 'rule' && Object(node.parent).type === 'rule' && node.selectors.every(selector => selector.trim().indexOf('&') === 0 && selector.indexOf('|') === -1);
  4226. const comma = string => {
  4227. let array = [];
  4228. let current = '';
  4229. let split = false;
  4230. let func = 0;
  4231. let quote = false;
  4232. let escape = false;
  4233. for (let letter of string) {
  4234. if (escape) {
  4235. escape = false;
  4236. } else if (letter === '\\') {
  4237. escape = true;
  4238. } else if (quote) {
  4239. if (letter === quote) {
  4240. quote = false;
  4241. }
  4242. } else if (letter === '"' || letter === '\'') {
  4243. quote = letter;
  4244. } else if (letter === '(') {
  4245. func += 1;
  4246. } else if (letter === ')') {
  4247. if (func > 0) {
  4248. func -= 1;
  4249. }
  4250. } else if (func === 0) {
  4251. if (letter === ',') {
  4252. split = true;
  4253. }
  4254. }
  4255. if (split) {
  4256. if (current !== '') {
  4257. array.push(current.trim());
  4258. }
  4259. current = '';
  4260. split = false;
  4261. } else {
  4262. current += letter;
  4263. }
  4264. }
  4265. array.push(current.trim());
  4266. return array;
  4267. };
  4268. function transformNestRuleWithinRule(node, walk, opts) {
  4269. // move previous siblings and the node to before the parent
  4270. const parent = shiftNodesBeforeParent(node); // clone the parent as a new rule with children appended to it
  4271. const rule = parent.clone().removeAll().append(node.nodes); // replace the node with the new rule
  4272. node.replaceWith(rule); // update the selectors of the node to be merged with the parent
  4273. rule.selectors = mergeSelectors(parent.selectors, comma(node.params), opts); // conditionally cleanup an empty parent rule
  4274. cleanupParent(parent); // walk the children of the new rule
  4275. walk(rule, opts);
  4276. }
  4277. const isNestRuleWithinRule = node => node.type === 'atrule' && node.name === 'nest' && Object(node.parent).type === 'rule' && comma(node.params).every(selector => selector.split('&').length >= 2 && selector.indexOf('|') === -1);
  4278. var validAtrules = ['container', 'document', 'media', 'supports'];
  4279. function atruleWithinRule(node, walk, opts) {
  4280. // move previous siblings and the node to before the parent
  4281. const parent = shiftNodesBeforeParent(node); // clone the parent as a new rule with children appended to it
  4282. const rule = parent.clone().removeAll().append(node.nodes); // append the new rule to the node
  4283. node.append(rule); // conditionally cleanup an empty parent rule
  4284. cleanupParent(parent); // walk the children of the new rule
  4285. walk(rule, opts);
  4286. }
  4287. const isAtruleWithinRule = node => node.type === 'atrule' && validAtrules.includes(node.name) && Object(node.parent).type === 'rule';
  4288. function mergeParams(fromParams, toParams) {
  4289. return comma(fromParams).map(params1 => comma(toParams).map(params2 => `${params1} and ${params2}`).join(', ')).join(', ');
  4290. }
  4291. /*
  4292. * DEPRECATED: In v7.0.0 these features will be removed as they are not part of
  4293. * the nesting proposal.
  4294. */
  4295. function transformAtruleWithinAtrule(node) {
  4296. // move previous siblings and the node to before the parent
  4297. const parent = shiftNodesBeforeParent(node); // update the params of the node to be merged with the parent
  4298. node.params = mergeParams(parent.params, node.params); // conditionally cleanup an empty parent rule
  4299. cleanupParent(parent);
  4300. }
  4301. const isAtruleWithinAtrule = node => node.type === 'atrule' && validAtrules.includes(node.name) && Object(node.parent).type === 'atrule' && node.name === node.parent.name;
  4302. function walk(node, opts) {
  4303. node.each(child => {
  4304. if (isRuleWithinRule(child)) {
  4305. transformRuleWithinRule(child, opts);
  4306. } else if (isNestRuleWithinRule(child)) {
  4307. transformNestRuleWithinRule(child, walk, opts);
  4308. } else if (isAtruleWithinRule(child)) {
  4309. atruleWithinRule(child, walk, opts);
  4310. } else if (isAtruleWithinAtrule(child)) {
  4311. transformAtruleWithinAtrule(child);
  4312. }
  4313. if (Object(child.nodes).length) {
  4314. walk(child, opts);
  4315. }
  4316. });
  4317. }
  4318. /**
  4319. * @param {{noIsPseudoSelector?: boolean}} opts
  4320. * @returns {import('postcss').Plugin}
  4321. */
  4322. function postcssNesting(opts) {
  4323. const noIsPseudoSelector = Object(opts).noIsPseudoSelector || false;
  4324. return {
  4325. postcssPlugin: 'postcss-nesting',
  4326. Rule(rule) {
  4327. walk(rule, {
  4328. noIsPseudoSelector: noIsPseudoSelector
  4329. });
  4330. }
  4331. };
  4332. }
  4333. postcssNesting.postcss = true;
  4334. export { postcssNesting as default };