CSS compressor written in OCaml
|
|
11 tahun lalu | |
|---|---|---|
| .gitignore | 11 tahun lalu | |
| Makefile | 11 tahun lalu | |
| README.md | 11 tahun lalu | |
| color_names.ml | 11 tahun lalu | |
| duplicates.ml | 11 tahun lalu | |
| lexer.mll | 11 tahun lalu | |
| main.ml | 11 tahun lalu | |
| parse.ml | 11 tahun lalu | |
| parser.mly | 11 tahun lalu | |
| selector.ml | 11 tahun lalu | |
| shorthand.ml | 11 tahun lalu | |
| simple.ml | 11 tahun lalu | |
| stringify.ml | 11 tahun lalu | |
| types.ml | 11 tahun lalu | |
| util.ml | 11 tahun lalu |
mincss is an extendible CSS minifier written in OCaml. It contains a complete parser for the CSS3 language, along with consistent type definitions and a traversal utility function for use in transformation passes.
mincss is currently still in development, finished components are the parser, stringification (along with whitespace compression), and color compression. Rulset merging is partially documented below but currently unimplemented.
font and background)Apart from simply writing the CSS in a shorter format (i.e. whitespace/color/shorthand compression), mincss attempts to restructure rule sets such that the resulting stylesheet is the minimal representation of the input. For example:
a { color: red }
p { color: red }
can be written much shorter as:
a, p { color: red }
Merging selectors is something that is done by the programmer in most cases,
but the example above may occur when multiple different CSS files are merged
into one, or when a large CSS file is structured in such a way that the
definitions of a and p are far apart. Another thing that may happen is that
some framework file defines a default style for a selector, that is then
overwritten in a custom stylesheet, for example:
/* file: framework.css */
a {
border: 1px solid red;
}
...
/* file: my-special-page.css */
a {
border-color: blue;
}
which can be merged into:
a {
border: 1px solid blue;
}
To achieve the features listed above, the input stylesheet is rewritten in a number of steps:
a,p{color:red;border:blue} becomes a{color:red}
a{border:blue} p{color:red} p{border:blue}.--no-prune for stylesheets
that contain duplication hacks.TODO
TODO: compare to existing minifiers