Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
mincss
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Taddeüs Kroes
mincss
Commits
52cdbb3c
Commit
52cdbb3c
authored
Oct 01, 2014
by
Taddeüs Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Grouped font-weight and color optimizations in simple.ml
parent
a9d17d07
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
26 additions
and
41 deletions
+26
-41
Makefile
Makefile
+5
-5
font.ml
font.ml
+0
-13
main.ml
main.ml
+10
-19
simple.ml
simple.ml
+11
-4
No files found.
Makefile
View file @
52cdbb3c
RESULT
:=
mincss
PRE_TGTS
:=
types
MODULES
:=
color_names util stringify parser lexer parse selector
color
\
shorthand duplicates
font
main
MODULES
:=
color_names util stringify parser lexer parse selector
simple
\
shorthand duplicates main
ALL_NAMES
:=
$(PRE_TGTS)
$(MODULES)
OCAMLCFLAGS
:=
-g
...
...
@@ -36,10 +36,10 @@ lexer.cmi: lexer.ml
parser.cmx
:
parser.cmi lexer.cmx
parser.mli
:
parser.ml
parse.cmx
:
lexer.cmi parser.cmx
main.cmx
:
parse.cmx util.cmx
color.cmx shorthand.cmx duplicates.cmx font
.cmx
main.cmx
:
parse.cmx util.cmx
simple.cmx shorthand.cmx duplicates
.cmx
util.cmx
:
OCAMLCFLAGS += -pp cpp
util.cmx
color
.cmx
:
color_names.cmx
stringify.cmx parser.cmx
color
.cmx shorthand.cmx
:
util.cmi
util.cmx
simple
.cmx
:
color_names.cmx
stringify.cmx parser.cmx
simple
.cmx shorthand.cmx
:
util.cmi
$(addsuffix .cmx,$(MODULES))
:
$(addsuffix .cmi
,
$(PRE_TGTS))
clean
:
...
...
font.ml
deleted
100644 → 0
View file @
a9d17d07
open
Types
let
rec
shorten
=
function
|
Ident
"normal"
->
Number
(
400
.
0
,
None
)
|
Ident
"bold"
->
Number
(
700
.
0
,
None
)
|
v
->
v
let
transform
=
function
|
Declaration
(
"font-weight"
,
value
,
imp
)
->
Declaration
(
"font-weight"
,
shorten
value
,
imp
)
|
v
->
v
let
compress
=
Util
.
transform_stylesheet
transform
main.ml
View file @
52cdbb3c
...
...
@@ -6,8 +6,7 @@ type args = {
outfile
:
string
option
;
verbose
:
bool
;
whitespace
:
bool
;
color
:
bool
;
font
:
bool
;
simple
:
bool
;
shorthands
:
bool
;
duplicates
:
bool
;
echo
:
bool
;
...
...
@@ -27,12 +26,11 @@ let parse_args () =
Optimization flags (if none are specified, all are enabled):
\n
\
-w, --whitespace Eliminate unnecessary whitespaces (has the greatest \
effect, omit for pretty-printing)
\n
\
-c, --color Shorten colors
\n
\
-f, --font Shorten font weights
\n
\
-c, --simple Shorten colors and font weights
\n
\
-s, --shorthands Generate shorthand properties
\n
\
-d, --duplicates Prune duplicate properties (WARNING: may affect \
cross-browser hacks)
\n
\
-p, --pretty Shorthand for -c -
f -
s -d
\n
\
-p, --pretty Shorthand for -c -s -d
\n
\
-e, --echo Just parse and pretty-print, no optimizations
\n
"
in
...
...
@@ -41,8 +39,7 @@ let parse_args () =
outfile
=
None
;
verbose
=
false
;
whitespace
=
false
;
color
=
false
;
font
=
false
;
simple
=
false
;
shorthands
=
false
;
duplicates
=
false
;
echo
=
false
;
...
...
@@ -53,16 +50,14 @@ let parse_args () =
handle
{
args
with
verbose
=
true
}
tl
|
(
"-w"
|
"--whitespace"
)
::
tl
->
handle
{
args
with
whitespace
=
true
}
tl
|
(
"-c"
|
"--color"
)
::
tl
->
handle
{
args
with
color
=
true
}
tl
|
(
"-f"
|
"--font"
)
::
tl
->
handle
{
args
with
font
=
true
}
tl
|
(
"-c"
|
"--simple"
)
::
tl
->
handle
{
args
with
simple
=
true
}
tl
|
(
"-s"
|
"--shorthands"
)
::
tl
->
handle
{
args
with
shorthands
=
true
}
tl
|
(
"-d"
|
"-duplicates"
)
::
tl
->
handle
{
args
with
duplicates
=
true
}
tl
|
(
"-p"
|
"--pretty"
)
::
tl
->
handle
args
(
"-c"
::
"-f"
::
"-s"
::
"-d"
::
tl
)
handle
{
args
with
simple
=
true
;
shorthands
=
true
;
duplicates
=
true
}
tl
|
(
"-e"
|
"--echo"
)
::
tl
->
handle
{
args
with
echo
=
true
}
tl
...
...
@@ -89,16 +84,14 @@ let parse_args () =
match
handle
default_args
(
List
.
tl
(
Array
.
to_list
Sys
.
argv
))
with
|
{
whitespace
=
false
;
color
=
false
;
font
=
false
;
simple
=
false
;
shorthands
=
false
;
duplicates
=
false
;
echo
=
false
;
_
}
as
args
->
{
args
with
whitespace
=
true
;
color
=
true
;
font
=
true
;
simple
=
true
;
shorthands
=
true
;
duplicates
=
true
}
|
args
->
args
...
...
@@ -130,12 +123,10 @@ let handle_args args =
let
input
,
css
=
parse_files
args
.
infiles
in
let
css
=
css
|>
switch
args
.
color
Color
.
compress
(* unfold before pruning duplicates so that shorthand components are
* correctly pruned *)
|>
switch
args
.
shorthands
Shorthand
.
unfold_stylesheet
|>
switch
args
.
font
Font
.
compress
|>
switch
args
.
simple
Simple
.
compress
|>
switch
args
.
duplicates
Duplicates
.
compress
|>
switch
args
.
shorthands
Shorthand
.
compress
in
...
...
color
.ml
→
simple
.ml
View file @
52cdbb3c
...
...
@@ -12,7 +12,7 @@ let clip = function
|
Number
(
n
,
Some
"%"
)
when
n
>
100
.
->
Number
(
100
.,
Some
"%"
)
|
value
->
value
let
rec
short
=
function
let
rec
short
en_expr
=
function
(* #aabbcc -> #abc *)
|
Hexcolor
h
when
Str
.
string_match
hex6
h
0
->
let
gr
n
=
Str
.
matched_group
n
h
in
...
...
@@ -27,7 +27,7 @@ let rec short = function
|
Number
(
n
,
Some
"%"
)
->
int_of_float
(
n
*.
2
.
55
+.
0
.
5
)
|
_
->
assert
false
in
short
(
Hexcolor
(
Printf
.
sprintf
"%02x%02x%02x"
(
i
r
)
(
i
g
)
(
i
b
)))
short
en_expr
(
Hexcolor
(
Printf
.
sprintf
"%02x%02x%02x"
(
i
r
)
(
i
g
)
(
i
b
)))
(* clip rgb values, e.g. rgb(-1,256,0) -> rgb(0,255,0) *)
|
Function
(
"rgb"
,
Nary
(
","
,
[
r
;
g
;
b
]))
->
...
...
@@ -35,15 +35,22 @@ let rec short = function
(* rgba(r,g,b,1.0) -> rgb(r,g,b) *)
|
Function
(
"rgba"
,
Nary
(
","
,
[
r
;
g
;
b
;
Number
(
1
.,
None
)]))
->
short
(
Function
(
"rgb"
,
Nary
(
","
,
[
r
;
g
;
b
])))
short
en_expr
(
Function
(
"rgb"
,
Nary
(
","
,
[
r
;
g
;
b
])))
(* TODO: hsl[a](...) *)
(* transform color names to shorter hex codes and vice-versa *)
|
v
->
Color_names
.
compress
v
let
shorten_font_weight
=
function
|
Ident
"normal"
->
Number
(
400
.
0
,
None
)
|
Ident
"bold"
->
Number
(
700
.
0
,
None
)
|
v
->
v
let
transform
=
function
|
Expr
value
->
Expr
(
short
value
)
|
Expr
value
->
Expr
(
shorten_expr
value
)
|
Declaration
(
"font-weight"
,
value
,
imp
)
->
Declaration
(
"font-weight"
,
shorten_font_weight
value
,
imp
)
|
v
->
v
let
compress
=
Util
.
transform_stylesheet
transform
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment