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
3a4ed9ee
Commit
3a4ed9ee
authored
Jul 28, 2014
by
Taddeüs Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added utility file for operations on selectors
parent
3b7dc074
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
82 additions
and
0 deletions
+82
-0
cascade.ml
cascade.ml
+82
-0
No files found.
cascade.ml
0 → 100644
View file @
3a4ed9ee
open
Types
(* This file defines functions that construct an element tree with applied
* stylesheet based on:
* - http://www.w3.org/TR/CSS2/cascade.html#specificity
*)
let
is_pseudo_class
=
function
|
Pseudo
(
_
,
(
"link"
|
"hover"
|
"visited"
|
"active"
)
,
None
)
->
true
|
_
->
false
(* Specificity (a, b, c, d):
* a = 0 (1 if in style="" definition which is always false in a stylesheet)
* b = number of ID attributes
* c = number of other (pseudo-)attributes
* d = number of (pseudo-)elements
*)
let
rec
specificity
=
let
add
(
a
,
b
,
c
,
d
)
(
e
,
f
,
g
,
h
)
=
(
a
+
e
,
b
+
f
,
c
+
g
,
d
+
h
)
in
function
|
No_element
|
All_elements
->
(
0
,
0
,
0
,
0
)
|
Element
_
->
(
0
,
0
,
0
,
1
)
|
Id
(
base
,
_
)
->
add
(
0
,
1
,
0
,
0
)
(
specificity
base
)
|
Class
(
base
,
_
)
|
Attribute
(
base
,
_
,
_
)
->
add
(
0
,
0
,
1
,
0
)
(
specificity
base
)
|
Pseudo
(
base
,
_
,
_
)
as
addon
when
is_pseudo_class
addon
->
add
(
0
,
0
,
1
,
0
)
(
specificity
base
)
|
Pseudo
(
base
,
_
,
_
)
->
add
(
0
,
0
,
0
,
1
)
(
specificity
base
)
|
Combinator
(
left
,
_
,
right
)
->
add
(
specificity
left
)
(
specificity
right
)
let
precedes
(
a
,
b
,
c
,
d
)
(
e
,
f
,
g
,
h
)
=
let
rec
loop
=
function
|
[]
->
true
|
0
::
tl
->
loop
tl
|
n
::
_
when
n
>
0
->
true
|
_
->
false
in
loop
[
a
-
e
;
b
-
f
;
c
-
g
;
d
-
h
]
let
overwrites
selector1
selector2
=
precedes
(
specificity
selector1
)
(
specificity
selector2
)
let
can_match_same
selector1
selector2
=
let
unfold
=
let
rec
loop
classes
ids
pseudos
attrs
=
function
|
No_element
->
(
""
,
classes
,
ids
,
pseudos
,
attrs
)
|
All_elements
->
(
"*"
,
classes
,
ids
,
pseudos
,
attrs
)
|
Element
elem
->
(
elem
,
classes
,
ids
,
pseudos
,
attrs
)
|
Id
(
base
,
id
)
->
loop
classes
(
id
::
ids
)
pseudos
attrs
base
|
Class
(
base
,
cls
)
->
loop
(
cls
::
classes
)
ids
pseudos
attrs
base
|
Pseudo
(
base
,
f
,
arg
)
->
(* XXX: what about :not(...) ? *)
loop
classes
ids
((
f
,
arg
)
::
pseudos
)
attrs
base
|
Attribute
(
base
,
attr
,
_
)
->
loop
classes
ids
pseudos
(
attr
::
attrs
)
base
|
Combinator
(
_
,
_
,
right
)
->
loop
classes
ids
pseudos
attrs
right
in
loop
[]
[]
[]
[]
in
let
rec
intersect
l
=
function
|
[]
->
false
|
hd
::
_
when
List
.
mem
hd
l
->
true
|
_
::
tl
->
intersect
l
tl
in
let
elem1
,
classes1
,
ids1
,
pseudos1
,
attrs1
=
unfold
selector1
in
let
elem2
,
classes2
,
ids2
,
pseudos2
,
attrs2
=
unfold
selector2
in
elem1
=
"*"
||
elem2
=
"*"
||
elem1
=
elem2
&&
elem1
<>
""
||
intersect
classes1
classes2
||
intersect
ids1
ids2
||
intersect
pseudos1
pseudos2
||
intersect
attrs1
attrs2
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