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
3dbeb341
Commit
3dbeb341
authored
Jul 24, 2014
by
Taddeüs Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added some comments, implemented margin/padding shortening
parent
aaaf2601
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
10 deletions
+31
-10
shorthand.ml
shorthand.ml
+31
-10
No files found.
shorthand.ml
View file @
3dbeb341
...
@@ -15,7 +15,8 @@ let subprops = function
...
@@ -15,7 +15,8 @@ let subprops = function
|
"font"
->
[
"style"
;
"variant"
;
"weight"
;
"size"
;
"family"
]
|
"font"
->
[
"style"
;
"variant"
;
"weight"
;
"size"
;
"family"
]
|
"list-style"
->
[
"type"
;
"position"
;
"image"
]
|
"list-style"
->
[
"type"
;
"position"
;
"image"
]
|
"outline"
->
[
"color"
;
"style"
;
"width"
]
|
"outline"
->
[
"color"
;
"style"
;
"width"
]
|
"margin"
|
"padding"
->
[
"top"
;
"right"
;
"bottom"
;
"left"
]
|
"margin"
|
"padding"
->
[
"top"
;
"right"
;
"bottom"
;
"left"
]
|
_
->
failwith
"not a shorthand property"
|
_
->
failwith
"not a shorthand property"
let
rec
decls_mem
name
=
function
let
rec
decls_mem
name
=
function
...
@@ -31,30 +32,50 @@ let rec decls_find name = function
...
@@ -31,30 +32,50 @@ let rec decls_find name = function
let
order
base
decls
=
let
order
base
decls
=
let
rec
filter
=
function
let
rec
filter
=
function
|
[]
->
[]
|
[]
->
[]
(* `font-size` and `line-height` are slash-separated in `font` *)
|
"size"
::
tl
when
base
=
"font"
&&
decls_mem
"line-height"
decls
->
|
"size"
::
tl
when
base
=
"font"
&&
decls_mem
"line-height"
decls
->
let
font_size
=
decls_find
"font-size"
decls
in
let
font_size
=
decls_find
"font-size"
decls
in
let
line_height
=
decls_find
"line-height"
decls
in
let
line_height
=
decls_find
"line-height"
decls
in
Nary
(
"/"
,
[
font_size
;
line_height
])
::
filter
tl
Nary
(
"/"
,
[
font_size
;
line_height
])
::
filter
tl
|
name
::
tl
when
decls_mem
(
base
^
"-"
^
name
)
decls
->
|
name
::
tl
when
decls_mem
(
base
^
"-"
^
name
)
decls
->
decls_find
(
base
^
"-"
^
name
)
decls
::
filter
tl
decls_find
(
base
^
"-"
^
name
)
decls
::
filter
tl
|
_
::
tl
->
filter
tl
|
_
::
tl
->
filter
tl
in
in
filter
(
subprops
base
)
filter
(
subprops
base
)
let
rec
shorten
decls
=
function
let
shorten_box_dims
=
function
|
"font"
when
not
(
decls_mem
"font-size"
decls
)
->
|
[
top
;
right
;
bottom
;
left
]
shorten
((
"font-size"
,
Ident
"medium"
,
false
)
::
decls
)
"font"
when
top
=
bottom
&&
right
=
left
&&
top
=
right
->
[
top
]
|
"font"
when
decls_mem
"font-family"
decls
->
|
[
top
;
right
;
bottom
;
left
]
when
top
=
bottom
&&
right
=
left
->
[
top
;
right
]
|
[
top
;
right
;
bottom
;
left
]
when
right
=
left
->
[
top
;
right
;
bottom
]
|
dims
->
dims
let
shorten
decls
=
function
(* `font-size` and `font-family` are required for `font` *)
|
"font"
when
decls_mem
"font-size"
decls
&&
decls_mem
"font-family"
decls
->
Some
(
Concat
(
order
"font"
decls
))
Some
(
Concat
(
order
"font"
decls
))
(* `border-style` is required for `border` *)
|
"border"
when
decls_mem
"border-style"
decls
->
|
"border"
when
decls_mem
"border-style"
decls
->
Some
(
Concat
(
order
"border"
decls
))
Some
(
Concat
(
order
"border"
decls
))
(* others require at least one property, which is the case when this function
* is called *)
|
(
"background"
|
"list-style"
|
"outline"
)
as
base
->
|
(
"background"
|
"list-style"
|
"outline"
)
as
base
->
Some
(
Concat
(
order
base
decls
))
Some
(
Concat
(
order
base
decls
))
(* margin and padding can only be shorthanded when all directions are known,
* merging into even shorter shorthands is done by `shorten_box_dims` *)
|
(
"margin"
|
"padding"
)
as
base
when
|
(
"margin"
|
"padding"
)
as
base
when
let
has
dir
=
decls_mem
(
base
^
"-"
^
dir
)
decls
in
let
has
dir
=
decls_mem
(
base
^
"-"
^
dir
)
decls
in
has
"top"
&&
has
"right"
&&
has
"bottom"
&&
has
"left"
->
has
"top"
&&
has
"right"
&&
has
"bottom"
&&
has
"left"
->
let
get
dir
=
decls_find
(
base
^
"-"
^
dir
)
decls
in
let
get
dir
=
decls_find
(
base
^
"-"
^
dir
)
decls
in
Some
(
Concat
[
get
"top"
;
get
"right"
;
get
"bottom"
;
get
"left"
])
Some
(
Concat
(
shorten_box_dims
[
get
"top"
;
get
"right"
;
get
"bottom"
;
get
"left"
]))
|
_
->
None
|
_
->
None
let
make_shorthands
decls
=
let
make_shorthands
decls
=
...
...
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