Skip to content

Commit

Permalink
nth and lang selectors support
Browse files Browse the repository at this point in the history
  • Loading branch information
thescientist13 committed Nov 3, 2022
1 parent 8049c09 commit 935e292
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 2 deletions.
27 changes: 27 additions & 0 deletions packages/cli/src/plugins/resource/plugin-standard-css.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,12 @@ function bundleCss(body, url) {

switch (name) {

case 'lang':
case 'not':
case 'nth-child':
case 'nth-last-child':
case 'nth-of-type':
case 'nth-last-of-type':
optimizedCss += '(';
break;
default:
Expand All @@ -57,6 +62,23 @@ function bundleCss(body, url) {
optimizedCss += '[';
} else if (type === 'Combinator') {
optimizedCss += name;
} else if (type === 'Nth') {
const { nth } = node;

switch (nth.type) {

case 'AnPlusB':
if (nth.a) {
optimizedCss += nth.a === '-1' ? '-n' : `${nth.a}n`;
}
if (nth.b) {
optimizedCss += nth.a ? `+${nth.b}` : nth.b;
}
break;
default:
break;

}
} else if (type === 'Declaration') {
optimizedCss += `${node.property}:`;
} else if (type === 'Url' && this.atrule?.name !== 'import') {
Expand Down Expand Up @@ -116,7 +138,12 @@ function bundleCss(body, url) {
case 'PseudoClassSelector':
switch (node.name) {

case 'lang':
case 'not':
case 'nth-child':
case 'nth-last-child':
case 'nth-last-of-type':
case 'nth-of-type':
optimizedCss += ')';
break;
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,18 @@ p::first-line{color:blue;width:100%!important;}

pre[class*='language-']{color:#ccc;background:none;}

:not(pre)>code[class*='language-']{background:#2d2d2d;}
dd:only-of-type{background-color:bisque;}

:not(pre)>code[class*='language-']{background:#2d2d2d;}

li:nth-child(-n+3){border:2px solid orange;margin-bottom:1px;}

li:nth-child(even){background-color:lightyellow;}

li:nth-last-child(5n){border:2px solid orange;margin-top:1px;}

dd:nth-last-of-type(odd){border:2px solid orange;}

p:nth-of-type(2n+1){color:red;}

*:lang(en-US){outline:2px solid deeppink;}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,36 @@ pre[class*="language-"] {
background: none;
}

dd:only-of-type {
background-color: bisque;
}

:not(pre) > code[class*="language-"] {
background: #2d2d2d;
background: #2d2d2d;
}

li:nth-child(-n+3) {
border: 2px solid orange;
margin-bottom: 1px;
}

li:nth-child(even) {
background-color: lightyellow;
}

li:nth-last-child(5n) {
border: 2px solid orange;
margin-top: 1px;
}

dd:nth-last-of-type(odd) {
border: 2px solid orange;
}

p:nth-of-type(2n + 1) {
color: red;
}

*:lang(en-US) {
outline: 2px solid deeppink;
}

0 comments on commit 935e292

Please sign in to comment.