feat(css/minifier): Compress more properties (#4130)

This commit is contained in:
Alexander Akait 2022-03-23 17:58:47 +03:00 committed by GitHub
parent 7053d6769a
commit 93866d0be5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
40 changed files with 547 additions and 20 deletions

View File

@ -5,6 +5,7 @@ use swc_common::{ast_node, EqIgnoreSpan, Span};
use crate::ComponentValue;
#[ast_node("Ident")]
#[derive(Eq, Hash, EqIgnoreSpan)]
pub struct Ident {
pub span: Span,
pub value: JsWord,
@ -12,6 +13,7 @@ pub struct Ident {
}
#[ast_node("CustomIdent")]
#[derive(Eq, Hash, EqIgnoreSpan)]
pub struct CustomIdent {
pub span: Span,
pub value: JsWord,
@ -19,6 +21,7 @@ pub struct CustomIdent {
}
#[ast_node("DashedIdent")]
#[derive(Eq, Hash, EqIgnoreSpan)]
pub struct DashedIdent {
pub span: Span,
pub value: JsWord,
@ -27,6 +30,7 @@ pub struct DashedIdent {
/// Quoted string.
#[ast_node("String")]
#[derive(Eq, Hash, EqIgnoreSpan)]
pub struct Str {
pub span: Span,
pub value: JsWord,
@ -44,6 +48,7 @@ pub enum DelimiterValue {
}
#[ast_node("Delimiter")]
#[derive(Eq, Hash, EqIgnoreSpan)]
pub struct Delimiter {
pub span: Span,
pub value: DelimiterValue,
@ -81,6 +86,7 @@ pub enum AbsoluteColorBase {
}
#[ast_node("HexColor")]
#[derive(Eq, Hash, EqIgnoreSpan)]
pub struct HexColor {
/// Includes `#`
pub span: Span,

View File

@ -13,27 +13,40 @@ impl CompressDeclaration {
node_1: Option<&ComponentValue>,
node_2: Option<&ComponentValue>,
) -> bool {
if let Some(ComponentValue::Dimension(Dimension::Length(Length {
value: value_1,
unit: unit_1,
..
}))) = node_1
{
if let Some(ComponentValue::Dimension(Dimension::Length(Length {
value: value_2,
unit: unit_2,
..
}))) = node_2
match (node_1, node_2) {
(
Some(ComponentValue::Dimension(Dimension::Length(Length {
value: value_1,
unit: unit_1,
..
}))),
Some(ComponentValue::Dimension(Dimension::Length(Length {
value: value_2,
unit: unit_2,
..
}))),
) if value_1.value == value_2.value
&& unit_1.value.to_lowercase() == unit_2.value.to_lowercase() =>
{
if value_1.value == value_2.value
&& unit_1.value.to_lowercase() == unit_2.value.to_lowercase()
{
return true;
}
true
}
(
Some(ComponentValue::Integer(Integer { value: 0, .. })),
Some(ComponentValue::Integer(Integer { value: 0, .. })),
) => true,
_ => false,
}
}
false
fn is_same_ident(
&self,
node_1: Option<&ComponentValue>,
node_2: Option<&ComponentValue>,
) -> bool {
matches!((node_1, node_2), (
Some(ComponentValue::Ident(Ident { value: value_1, .. })),
Some(ComponentValue::Ident(Ident { value: value_2, .. })),
) if value_1.to_lowercase() == value_2.to_lowercase())
}
}
@ -234,7 +247,8 @@ impl VisitMut for CompressDeclaration {
_ => {}
}
}
"padding" | "margin" | "inset" | "scroll-margin" | "scroll-padding"
"padding" | "margin" | "border-width" | "inset" | "scroll-margin"
| "scroll-padding"
if declaration.value.len() > 1 =>
{
let top = declaration.value.get(0);
@ -269,6 +283,30 @@ impl VisitMut for CompressDeclaration {
}
}
}
"padding-inline"
| "padding-block"
| "margin-inline"
| "margin-block"
| "margin-inline"
| "inset-inline"
| "inset-block"
| "border-inline-width"
| "border-block-width"
| "scroll-padding-inline"
| "scroll-padding-block"
| "scroll-margin-inline"
| "scroll-margin-block"
if declaration.value.len() == 2 =>
{
let first = declaration.value.get(0);
let second = declaration.value.get(1);
if self.is_same_dimension_length_nodes(first, second)
|| self.is_same_ident(first, second)
{
declaration.value.remove(1);
}
}
"font-weight" => {
declaration.value = declaration
.value
@ -340,6 +378,21 @@ impl VisitMut for CompressDeclaration {
}
}
}
"border-image-repeat"
| "mask-border-repeat"
| "-webkit-mask-box-image-repeat"
| "overscroll-behavior"
| "scroll-snap-align"
| "overflow"
if declaration.value.len() == 2 =>
{
let first = declaration.value.get(0);
let second = declaration.value.get(1);
if self.is_same_ident(first, second) {
declaration.value.remove(1);
}
}
_ => {}
}
}

View File

@ -0,0 +1,35 @@
.class-1 {
border-block-width: 10px;
}
.class-2 {
border-block-width: 1em .5em ;
}
.class-3 {
border-block-width: inherit;
}
.class-4 {
border-block-width: 10px 10px;
}
.class-5 {
border-block-width: 1rem 1rem;
}
.class-9 {
border-block-width: medium medium;
}
.class-10 {
border-block-width: thick thick;
}
.class-11 {
border-block-width: thin thin;
}
.class-12 {
border-block-width: medium thick;
}

View File

@ -0,0 +1 @@
.class-1{border-block-width:10px}.class-2{border-block-width:1em .5em}.class-3{border-block-width:inherit}.class-4{border-block-width:10px}.class-5{border-block-width:1rem}.class-9{border-block-width:medium}.class-10{border-block-width:thick}.class-11{border-block-width:thin}.class-12{border-block-width:medium thick}

View File

@ -0,0 +1,11 @@
.class-1 {
border-image-repeat: round stretch;
}
.class-2 {
border-image-repeat: round round;
}
.class-3 {
border-image-repeat: space space;
}

View File

@ -0,0 +1 @@
.class-1{border-image-repeat:round stretch}.class-2{border-image-repeat:round}.class-3{border-image-repeat:space}

View File

@ -0,0 +1,35 @@
.class-1 {
border-inline-width: 10px;
}
.class-2 {
border-inline-width: 1em .5em ;
}
.class-3 {
border-inline-width: inherit;
}
.class-4 {
border-inline-width: 10px 10px;
}
.class-5 {
border-inline-width: 1rem 1rem;
}
.class-9 {
border-inline-width: medium medium;
}
.class-10 {
border-inline-width: thick thick;
}
.class-11 {
border-inline-width: thin thin;
}
.class-12 {
border-inline-width: medium thick;
}

View File

@ -0,0 +1 @@
.class-1{border-inline-width:10px}.class-2{border-inline-width:1em .5em}.class-3{border-inline-width:inherit}.class-4{border-inline-width:10px}.class-5{border-inline-width:1rem}.class-9{border-inline-width:medium}.class-10{border-inline-width:thick}.class-11{border-inline-width:thin}.class-12{border-inline-width:medium thick}

View File

@ -0,0 +1,35 @@
.class-1 {
border-width:0 1px;
}
.class-2 {
border-width: 1px 2em 0 4rem;
}
.class-3 {
border-width: 1px 2em 1.5cm;
}
.class-4 {
border-width: thin;
}
.class-5 {
border-width: 2px 2px;
}
.class-6 {
border-width: 2px 2px 2px;
}
.class-7 {
border-width: 2px 2px 2px 2px;
}
.class-8 {
border-width: 2px 0 2px;
}
.class-9 {
border-width: 0 0 0 0;
}

View File

@ -0,0 +1 @@
.class-1{border-width:0 1px}.class-2{border-width:1px 2em 0 4rem}.class-3{border-width:1px 2em 1.5cm}.class-4{border-width:thin}.class-5{border-width:2px}.class-6{border-width:2px}.class-7{border-width:2px}.class-8{border-width:2px 0}.class-9{border-width:0}

View File

@ -0,0 +1,27 @@
.class-1 {
inset-block: 10px;
}
.class-2 {
inset-block: 1em .5em ;
}
.class-3 {
inset-block: inherit;
}
.class-4 {
inset-block: 10px 10px;
}
.class-5 {
inset-block: 1rem 1rem;
}
.class-9 {
inset-block: auto auto;
}
.class-10 {
inset-block: auto AUTO;
}

View File

@ -0,0 +1 @@
.class-1{inset-block:10px}.class-2{inset-block:1em .5em}.class-3{inset-block:inherit}.class-4{inset-block:10px}.class-5{inset-block:1rem}.class-9{inset-block:auto}.class-10{inset-block:auto}

View File

@ -0,0 +1,27 @@
.class-1 {
inset-inline: 10px;
}
.class-2 {
inset-inline: 1em .5em ;
}
.class-3 {
inset-inline: inherit;
}
.class-4 {
inset-inline: 10px 10px;
}
.class-5 {
inset-inline: 1rem 1rem;
}
.class-9 {
inset-inline: auto auto;
}
.class-10 {
inset-inline: auto AUTO;
}

View File

@ -0,0 +1 @@
.class-1{inset-inline:10px}.class-2{inset-inline:1em .5em}.class-3{inset-inline:inherit}.class-4{inset-inline:10px}.class-5{inset-inline:1rem}.class-9{inset-inline:auto}.class-10{inset-inline:auto}

View File

@ -0,0 +1,19 @@
.class-1 {
margin-block: 10px;
}
.class-2 {
margin-block: 1em .5em ;
}
.class-3 {
margin-block: inherit;
}
.class-4 {
margin-block: 10px 10px;
}
.class-5 {
margin-block: 1rem 1rem;
}

View File

@ -0,0 +1 @@
.class-1{margin-block:10px}.class-2{margin-block:1em .5em}.class-3{margin-block:inherit}.class-4{margin-block:10px}.class-5{margin-block:1rem}

View File

@ -0,0 +1,27 @@
.class-1 {
margin-inline: 10px;
}
.class-2 {
margin-inline: 1em .5em ;
}
.class-3 {
margin-inline: inherit;
}
.class-4 {
margin-inline: 10px 10px;
}
.class-5 {
margin-inline: 1rem 1rem;
}
.class-9 {
margin-inline: auto auto;
}
.class-10 {
margin-inline: auto AUTO;
}

View File

@ -0,0 +1 @@
.class-1{margin-inline:10px}.class-2{margin-inline:1em .5em}.class-3{margin-inline:inherit}.class-4{margin-inline:10px}.class-5{margin-inline:1rem}.class-9{margin-inline:auto}.class-10{margin-inline:auto}

View File

@ -0,0 +1,11 @@
.class-1 {
mask-border-repeat: round stretch;
}
.class-2 {
mask-border-repeat: round round;
}
.class-3 {
mask-border-repeat: space space;
}

View File

@ -0,0 +1 @@
.class-1{mask-border-repeat:round stretch}.class-2{mask-border-repeat:round}.class-3{mask-border-repeat:space}

View File

@ -0,0 +1,27 @@
.class-1 {
overflow: visible;
}
.class-2 {
overflow: hidden;
}
.class-3 {
overflow: clip;
}
.class-4 {
overflow: scroll;
}
.class-5 {
overflow: auto;
}
.class-6 {
overflow: hidden visible;
}
.class-7 {
overflow: scroll scroll;
}

View File

@ -0,0 +1 @@
.class-1{overflow:visible}.class-2{overflow:hidden}.class-3{overflow:clip}.class-4{overflow:scroll}.class-5{overflow:auto}.class-6{overflow:hidden visible}.class-7{overflow:scroll}

View File

@ -0,0 +1,35 @@
.class-1 {
overscroll-behavior: auto;
}
.class-2 {
overscroll-behavior: inherit;
}
.class-3 {
overscroll-behavior: initial;
}
.class-4 {
overscroll-behavior: revert;
}
.class-5 {
overscroll-behavior: unset;
}
.class-6 {
overscroll-behavior: auto contain;
}
.class-7 {
overscroll-behavior: auto auto;
}
.class-8 {
overscroll-behavior: contain contain;
}
.class-9 {
overscroll-behavior: none none;
}

View File

@ -0,0 +1 @@
.class-1{overscroll-behavior:auto}.class-2{overscroll-behavior:inherit}.class-3{overscroll-behavior:initial}.class-4{overscroll-behavior:revert}.class-5{overscroll-behavior:unset}.class-6{overscroll-behavior:auto contain}.class-7{overscroll-behavior:auto}.class-8{overscroll-behavior:contain}.class-9{overscroll-behavior:none}

View File

@ -0,0 +1,19 @@
.class-1 {
padding-block: 10px;
}
.class-2 {
padding-block: 1em .5em ;
}
.class-3 {
padding-block: inherit;
}
.class-4 {
padding-block: 10px 10px;
}
.class-5 {
padding-block: 1rem 1rem;
}

View File

@ -0,0 +1 @@
.class-1{padding-block:10px}.class-2{padding-block:1em .5em}.class-3{padding-block:inherit}.class-4{padding-block:10px}.class-5{padding-block:1rem}

View File

@ -0,0 +1,27 @@
.class-1 {
padding-inline: 10px;
}
.class-2 {
padding-inline: 1em .5em ;
}
.class-3 {
padding-inline: inherit;
}
.class-4 {
padding-inline: 10px 10px;
}
.class-5 {
padding-inline: 1rem 1rem;
}
.class-9 {
padding-inline: auto auto;
}
.class-10 {
padding-inline: auto AUTO;
}

View File

@ -0,0 +1 @@
.class-1{padding-inline:10px}.class-2{padding-inline:1em .5em}.class-3{padding-inline:inherit}.class-4{padding-inline:10px}.class-5{padding-inline:1rem}.class-9{padding-inline:auto}.class-10{padding-inline:auto}

View File

@ -0,0 +1,19 @@
.class-1 {
scroll-margin-block: 10px;
}
.class-2 {
scroll-margin-block: 1em .5em ;
}
.class-3 {
scroll-margin-block: inherit;
}
.class-4 {
scroll-margin-block: 10px 10px;
}
.class-5 {
scroll-margin-block: 1rem 1rem;
}

View File

@ -0,0 +1 @@
.class-1{scroll-margin-block:10px}.class-2{scroll-margin-block:1em .5em}.class-3{scroll-margin-block:inherit}.class-4{scroll-margin-block:10px}.class-5{scroll-margin-block:1rem}

View File

@ -0,0 +1,19 @@
.class-1 {
scroll-margin-inline: 10px;
}
.class-2 {
scroll-margin-inline: 1em .5em ;
}
.class-3 {
scroll-margin-inline: inherit;
}
.class-4 {
scroll-margin-inline: 10px 10px;
}
.class-5 {
scroll-margin-inline: 1rem 1rem;
}

View File

@ -0,0 +1 @@
.class-1{scroll-margin-inline:10px}.class-2{scroll-margin-inline:1em .5em}.class-3{scroll-margin-inline:inherit}.class-4{scroll-margin-inline:10px}.class-5{scroll-margin-inline:1rem}

View File

@ -0,0 +1,19 @@
.class-1 {
scroll-padding-block: 10px;
}
.class-2 {
scroll-padding-block: 1em .5em ;
}
.class-3 {
scroll-padding-block: inherit;
}
.class-4 {
scroll-padding-block: 10px 10px;
}
.class-5 {
scroll-padding-block: 1rem 1rem;
}

View File

@ -0,0 +1 @@
.class-1{scroll-padding-block:10px}.class-2{scroll-padding-block:1em .5em}.class-3{scroll-padding-block:inherit}.class-4{scroll-padding-block:10px}.class-5{scroll-padding-block:1rem}

View File

@ -0,0 +1,19 @@
.class-1 {
scroll-padding-inline: 10px;
}
.class-2 {
scroll-padding-inline: 1em .5em ;
}
.class-3 {
scroll-padding-inline: inherit;
}
.class-4 {
scroll-padding-inline: 10px 10px;
}
.class-5 {
scroll-padding-inline: 1rem 1rem;
}

View File

@ -0,0 +1 @@
.class-1{scroll-padding-inline:10px}.class-2{scroll-padding-inline:1em .5em}.class-3{scroll-padding-inline:inherit}.class-4{scroll-padding-inline:10px}.class-5{scroll-padding-inline:1rem}

View File

@ -0,0 +1,39 @@
.class-1 {
scroll-snap-align: none;
}
.class-2 {
scroll-snap-align: start end;
}
.class-3 {
scroll-snap-align: center;
}
.class-4 {
scroll-snap-align: inherit;
}
.class-5 {
scroll-snap-align: initial;
}
.class-6 {
scroll-snap-align: revert;
}
.class-7 {
scroll-snap-align: unset;
}
.class-8 {
scroll-snap-align: start start;
}
.class-9 {
scroll-snap-align: end end;
}
.class-10 {
scroll-snap-align: center center;
}

View File

@ -0,0 +1 @@
.class-1{scroll-snap-align:none}.class-2{scroll-snap-align:start end}.class-3{scroll-snap-align:center}.class-4{scroll-snap-align:inherit}.class-5{scroll-snap-align:initial}.class-6{scroll-snap-align:revert}.class-7{scroll-snap-align:unset}.class-8{scroll-snap-align:start}.class-9{scroll-snap-align:end}.class-10{scroll-snap-align:center}

View File

@ -1 +1 @@
.class1{width:0}.class2{width:100px}.class3{width:calc(100px + 0px)}.class4{width:caLc(100px + 0px)}.class5{padding:calc(1in + 0in*2)0 calc(0px)0}.class6{padding:calc(var(--foo,0px) + 10px)0}.class7{padding:max(10px,var(--foo,0px))0}.class8{right:max(100vw,0rem)}.class9{right:calc(max(100vw,0rem))}.class10{top:0}@media(min-width:0px){.foo{color:red}}@media(min-width:0){.bar{color:red}}.class11{font:normal normal 400 0/0 cursive}.class12{grid-template-columns:repeat(2,50px 0)100px}.class13{margin:0}.class14{transform:translate(0)}.class15{padding:min(1vw,0in)max(1vw,0px)clamp(0em,1vw,10px)0}.class16{padding:1px 0 2px 3px}.class17{padding:1px 2px 0 3px}.class18{width:0}.class19{width:0}.class20{top:0}.class21{width:0}.class22{width:.1mm}.class23{width:10cm}.class24{width:100cm}.class25{width:123mm}.class26{width:0}.class27{width:1cm}.class28{width:10cm}.class29{width:100cm}.class30{width:1mm}.class31{width:.123cm}.class32{width:.1mm}.class33{width:1.123cm}.class34{width:1q}.class35{width:40q}.class38{width:.25mm}.class39{width:1in}.class40{width:1in}.class41{width:2in}.class42{width:7.2pt}.class44{width:.72pt}.class45{width:1pc}.class46{width:1.2pt}.class47{width:.12pt}.class48{width:1in}.class49{width:2in}.class50{width:.6pc}.class51{width:1in}.class52{width:1mm}.class53{width:1in}.class54{width:1in}.class55{width:.5mm}.class56{width:80q}.class57{width:3cm}.class58{width:1px}.class59{width:4q}.class80{width:8q}.class81{width:12q}.class82{width:96q}.class83{width:.254cm}.class84{margin:-1px}.class85{width:1in}.class86{width:.254cm}.class87{width:.254mm}.class88{width:.025400000000000002mm}.class89{width:.00254mm}.class88{width:.6pc}.class89{width:1px}.class90{width:.075pt}
.class1{width:0}.class2{width:100px}.class3{width:calc(100px + 0px)}.class4{width:caLc(100px + 0px)}.class5{padding:calc(1in + 0in*2)0 calc(0px)}.class6{padding:calc(var(--foo,0px) + 10px)0 calc(var(--foo,0px) + 10px)}.class7{padding:max(10px,var(--foo,0px))0 max(10px,var(--foo,0px))}.class8{right:max(100vw,0rem)}.class9{right:calc(max(100vw,0rem))}.class10{top:0}@media(min-width:0px){.foo{color:red}}@media(min-width:0){.bar{color:red}}.class11{font:normal normal 400 0/0 cursive}.class12{grid-template-columns:repeat(2,50px 0)100px}.class13{margin:0}.class14{transform:translate(0)}.class15{padding:min(1vw,0in)max(1vw,0px)clamp(0em,1vw,10px)0}.class16{padding:1px 0 2px 3px}.class17{padding:1px 2px 0 3px}.class18{width:0}.class19{width:0}.class20{top:0}.class21{width:0}.class22{width:.1mm}.class23{width:10cm}.class24{width:100cm}.class25{width:123mm}.class26{width:0}.class27{width:1cm}.class28{width:10cm}.class29{width:100cm}.class30{width:1mm}.class31{width:.123cm}.class32{width:.1mm}.class33{width:1.123cm}.class34{width:1q}.class35{width:40q}.class38{width:.25mm}.class39{width:1in}.class40{width:1in}.class41{width:2in}.class42{width:7.2pt}.class44{width:.72pt}.class45{width:1pc}.class46{width:1.2pt}.class47{width:.12pt}.class48{width:1in}.class49{width:2in}.class50{width:.6pc}.class51{width:1in}.class52{width:1mm}.class53{width:1in}.class54{width:1in}.class55{width:.5mm}.class56{width:80q}.class57{width:3cm}.class58{width:1px}.class59{width:4q}.class80{width:8q}.class81{width:12q}.class82{width:96q}.class83{width:.254cm}.class84{margin:-1px}.class85{width:1in}.class86{width:.254cm}.class87{width:.254mm}.class88{width:.025400000000000002mm}.class89{width:.00254mm}.class88{width:.6pc}.class89{width:1px}.class90{width:.075pt}

File diff suppressed because one or more lines are too long