SimpleCSSCompiler 1.0.0-beta
See the version list below for details.
dotnet add package SimpleCSSCompiler --version 1.0.0-beta
NuGet\Install-Package SimpleCSSCompiler -Version 1.0.0-beta
<PackageReference Include="SimpleCSSCompiler" Version="1.0.0-beta" />
paket add SimpleCSSCompiler --version 1.0.0-beta
#r "nuget: SimpleCSSCompiler, 1.0.0-beta"
// Install SimpleCSSCompiler as a Cake Addin #addin nuget:?package=SimpleCSSCompiler&version=1.0.0-beta&prerelease // Install SimpleCSSCompiler as a Cake Tool #tool nuget:?package=SimpleCSSCompiler&version=1.0.0-beta&prerelease
Simple CSS compiler
This small module can compile CSS with the following features into a legacy CSS file that is more compatible with most browsers.
It can compile CSS with nesting and single-line comments into legacy CSS code, also minifies it.
It can compile:
@import url("https://foo.bar/");
div {
display: block;
width: 400px; // it does support comments
/* native multi-line comments too */
height: 300px;
> a {
align-self: center;
& :hover {
color: red;
}
}
& .test {
font-size: 20px;
}
}
@media (max-width: 700px) {
div.test {
width: 100%;
}
}
Into:
@import url("https://foo.bar/");
div {
display: block;
width: 400px;
height: 300px
}
div.test {
font-size: 20px
}
div > a {
align-self: center
}
div > a:hover {
color: red
}
@media (max-width: 700px) {
div.test {
width: 100%
}
}
Only with:
string css = CypherPotato.SimpleCSSCompiler.Compile(prettyCss);
It's all you need.
Specification
The syntax is very similar to what other CSS preprocessors already deliver, the difference is that in the concatenation operator of the "&" selector, the space between the operator and the selector is ignored, and is immediately included next to the parent selector, example:
div {
& :hover {
color: blue;
}
}
Will translate to:
div:hover {
color: blue
}
If you want an space between div
and :hover
, just remove the &
symbol before the selector.
Also, it propagates the selectors when they are separate to the same rule, for example:
div,
span {
& :hover,
& :active {
color: red;
}
}
Will translate to:
div:hover,
span:hover,
div:active,
span:active {
color: red
}
The compiler doesn't know what you're typing, it compiles based on the tokens you type. Using the @
operator will automatically start a new style sheet inside the body, and concatenate to the parent style:
div {
color: red;
}
@blablabla {
div {
color: blue;
& .yellow {
color: yellow;
}
}
}
Compiles to:
div {
color: red
}
@blablabla {
div {
color: blue
}
div.yellow {
color: yellow
}
}
Considerations
- Nesting
@
blocks is not supported. - Properties and values is trimmed.
- The last
;
in the rule is removed. - Content inside selectors are not trimmed.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. |
-
net6.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated | |
---|---|---|---|
1.0.3 | 195 | 8/29/2023 | |
1.0.2-beta | 156 | 8/19/2023 | |
1.0.1-beta | 140 | 8/18/2023 | |
1.0.0-beta | 131 | 8/17/2023 |