Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
node-sass
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
楚学文
node-sass
Commits
e5b72053
Commit
e5b72053
authored
Apr 08, 2012
by
Aaron Leung
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Some hsl functions. Buggy.
parent
f0efa6ea
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
82 additions
and
1 deletions
+82
-1
basic.scss
basic.scss
+5
-1
context.cpp
context.cpp
+8
-0
context.hpp
context.hpp
+1
-0
functions.cpp
functions.cpp
+47
-0
functions.hpp
functions.hpp
+6
-0
node.hpp
node.hpp
+15
-0
No files found.
basic.scss
View file @
e5b72053
...
...
@@ -71,4 +71,7 @@ div {
a
:
unit
(
10
);
b
:
unit
(
10%
);
c
:
unit
(
10boo
);
}
a
:
hsl
(
23
,
100%
,
50%
);
b
:
hsl
(
120
,
100%
,
50%
);
}
\ No newline at end of file
context.cpp
View file @
e5b72053
...
...
@@ -27,6 +27,12 @@ namespace Sass {
function_env
[
pair
<
string
,
size_t
>
(
f
.
name
,
f
.
parameters
.
size
())]
=
f
;
}
inline
void
Context
::
register_function
(
Function_Descriptor
d
,
Implementation
ip
,
size_t
arity
)
{
Function
f
(
d
,
ip
);
function_env
[
pair
<
string
,
size_t
>
(
f
.
name
,
arity
)]
=
f
;
}
void
Context
::
register_functions
()
{
using
namespace
Functions
;
...
...
@@ -40,6 +46,8 @@ namespace Sass {
register_function
(
mix_2_descriptor
,
mix_2
);
register_function
(
mix_3_descriptor
,
mix_3
);
// HSL Functions
register_function
(
hsla_descriptor
,
hsla
);
register_function
(
hsl_descriptor
,
hsl
);
register_function
(
invert_descriptor
,
invert
);
// Opacity Functions
register_function
(
alpha_descriptor
,
alpha
);
...
...
context.hpp
View file @
e5b72053
...
...
@@ -48,6 +48,7 @@ namespace Sass {
~
Context
();
void
register_function
(
Function_Descriptor
d
,
Implementation
ip
);
void
register_function
(
Function_Descriptor
d
,
Implementation
ip
,
size_t
arity
);
void
register_functions
();
};
...
...
functions.cpp
View file @
e5b72053
...
...
@@ -95,6 +95,53 @@ namespace Sass {
// HSL Functions ///////////////////////////////////////////////////////
double
h_to_rgb
(
double
m1
,
double
m2
,
double
h
)
{
if
(
h
<
0
)
++
h
;
if
(
h
>
1
)
--
h
;
if
(
h
*
6
<
1
)
return
m1
+
(
m2
-
m1
)
*
h
*
6
;
if
(
h
*
2
<
1
)
return
m2
;
if
(
h
*
3
<
2
)
return
m1
+
(
m2
-
m1
)
*
(
2
/
3
-
h
)
*
6
;
return
m1
;
}
Node
hsla_impl
(
double
h
,
double
s
,
double
l
,
double
a
=
1
)
{
h
=
(((
static_cast
<
int
>
(
h
)
%
360
)
+
360
)
%
360
)
/
360
;
s
=
s
/
100
;
l
=
l
/
100
;
double
m2
;
if
(
l
<=
0.5
)
m2
=
l
*
(
s
+
1
);
else
m2
=
l
+
s
-
l
*
s
;
double
m1
=
l
*
2
-
m2
;
double
r
=
h_to_rgb
(
m1
,
m2
,
h
+
1
/
3
);
double
g
=
h_to_rgb
(
m1
,
m2
,
h
);
double
b
=
h_to_rgb
(
m1
,
m2
,
h
-
1
/
3
);
return
Node
(
0
,
r
,
g
,
b
,
a
);
}
Function_Descriptor
hsla_descriptor
=
{
"hsla"
,
"$hue"
,
"$saturation"
,
"$lightness"
,
"$alpha"
,
0
};
Node
hsla
(
const
vector
<
Token
>&
parameters
,
map
<
Token
,
Node
>&
bindings
)
{
double
h
=
bindings
[
parameters
[
0
]].
numeric_value
();
double
s
=
bindings
[
parameters
[
1
]].
numeric_value
();
double
l
=
bindings
[
parameters
[
2
]].
numeric_value
();
double
a
=
bindings
[
parameters
[
3
]].
numeric_value
();
Node
color
(
hsla_impl
(
h
,
s
,
l
,
a
));
color
.
line_number
=
bindings
[
parameters
[
0
]].
line_number
;
return
color
;
}
Function_Descriptor
hsl_descriptor
=
{
"hsl"
,
"$hue"
,
"$saturation"
,
"$lightness"
,
0
};
Node
hsl
(
const
vector
<
Token
>&
parameters
,
map
<
Token
,
Node
>&
bindings
)
{
double
h
=
bindings
[
parameters
[
0
]].
numeric_value
();
double
s
=
bindings
[
parameters
[
1
]].
numeric_value
();
double
l
=
bindings
[
parameters
[
2
]].
numeric_value
();
Node
color
(
hsla_impl
(
h
,
s
,
l
));
color
.
line_number
=
bindings
[
parameters
[
0
]].
line_number
;
return
color
;
}
Function_Descriptor
invert_descriptor
=
{
"invert"
,
"$color"
,
0
};
Node
invert
(
const
vector
<
Token
>&
parameters
,
map
<
Token
,
Node
>&
bindings
)
{
...
...
functions.hpp
View file @
e5b72053
...
...
@@ -71,6 +71,12 @@ namespace Sass {
Node
mix_3
(
const
vector
<
Token
>&
parameters
,
map
<
Token
,
Node
>&
bindings
);
// HSL Functions ///////////////////////////////////////////////////////
extern
Function_Descriptor
hsla_descriptor
;
Node
hsla
(
const
vector
<
Token
>&
parameters
,
map
<
Token
,
Node
>&
bindings
);
extern
Function_Descriptor
hsl_descriptor
;
Node
hsl
(
const
vector
<
Token
>&
parameters
,
map
<
Token
,
Node
>&
bindings
);
extern
Function_Descriptor
invert_descriptor
;
Node
invert
(
const
vector
<
Token
>&
parameters
,
map
<
Token
,
Node
>&
bindings
);
...
...
node.hpp
View file @
e5b72053
...
...
@@ -121,6 +121,21 @@ namespace Sass {
return
*
this
;
}
double
numeric_value
()
{
switch
(
type
)
{
case
number
:
case
numeric_percentage
:
return
content
.
numeric_value
;
case
numeric_dimension
:
return
content
.
dimension
.
numeric_value
;
default
:
break
;
// throw an exception?
}
}
Node
&
operator
+=
(
const
Node
&
n
)
{
for
(
int
i
=
0
;
i
<
n
.
size
();
++
i
)
{
...
...
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