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
74e8c9f1
Commit
74e8c9f1
authored
Sep 05, 2012
by
Aaron Leung
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Working on the change-color function.
parent
1090c26d
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
77 additions
and
6 deletions
+77
-6
context.cpp
context.cpp
+2
-1
functions.cpp
functions.cpp
+70
-3
functions.hpp
functions.hpp
+5
-2
No files found.
context.cpp
View file @
74e8c9f1
...
...
@@ -111,8 +111,9 @@ namespace Sass {
// HSL Functions
register_function
(
hsla_sig
,
hsla
);
register_function
(
hsl_sig
,
hsl
);
register_function
(
adjust_color_sig
,
adjust_color
);
register_function
(
adjust_hue_sig
,
adjust_hue
);
register_function
(
adjust_color_sig
,
adjust_color
);
register_function
(
change_color_sig
,
change_color
);
register_function
(
invert_sig
,
invert
);
// Opacity Functions
register_function
(
alpha_sig
,
alpha
);
...
...
functions.cpp
View file @
74e8c9f1
...
...
@@ -151,25 +151,41 @@ namespace Sass {
// Utility rgb to hsl function so we can do hsl operations
Node
rgb_to_hsl
(
double
r
,
double
g
,
double
b
,
Node_Factory
&
new_Node
)
{
cerr
<<
"rgb to hsl: "
<<
r
<<
" "
<<
g
<<
" "
<<
b
<<
endl
;
r
/=
255.0
;
g
/=
255.0
;
b
/=
255.0
;
double
max
=
std
::
max
(
r
,
std
::
max
(
g
,
b
));
double
min
=
std
::
min
(
r
,
std
::
min
(
g
,
b
));
double
del
=
max
-
min
;
double
h
=
(
max
+
min
)
/
2
;
double
s
=
h
;
double
l
=
s
;
double
h
=
0
,
s
=
0
,
l
=
(
max
+
min
)
/
2
;
if
(
max
==
min
)
{
h
=
s
=
0
;
// achromatic
}
else
{
/*
double delta = max - min;
s = (l > 0.5) ? (2 - max - min) : (delta / (max + min));
if (max == r) h = (g - b) / delta + (g < b ? 6 : 0);
else if (max == g) h = (b - r) / delta + 2;
else if (max == b) h = (r - g) / delta + 4;
h /= 6;
*/
if
(
l
<
0.5
)
s
=
del
/
(
max
+
min
);
else
s
=
del
/
(
2.0
-
max
-
min
);
double
dr
=
(((
max
-
r
)
/
6.0
)
+
(
del
/
2.0
))
/
del
;
double
dg
=
(((
max
-
g
)
/
6.0
)
+
(
del
/
2.0
))
/
del
;
double
db
=
(((
max
-
b
)
/
6.0
)
+
(
del
/
2.0
))
/
del
;
if
(
r
==
max
)
h
=
db
-
dg
;
else
if
(
g
==
max
)
h
=
(
1.0
/
3.0
)
+
dr
-
db
;
else
if
(
b
==
max
)
h
=
(
2.0
/
3.0
)
+
dg
-
dr
;
if
(
h
<
0
)
h
+=
1
;
else
if
(
h
>
1
)
h
-=
1
;
}
return
new_Node
(
""
,
0
,
static_cast
<
int
>
(
h
*
360
)
%
360
,
s
*
100
,
l
*
100
);
}
...
...
@@ -295,6 +311,57 @@ namespace Sass {
return
Node
();
}
extern
Signature
change_color_sig
=
"change-color($color, $red: false, $green: false, $blue: false, $hue: false, $saturation: false, $lightness: false, $alpha: false)"
;
Node
change_color
(
const
Node
parameter_names
,
Environment
&
bindings
,
Node_Factory
&
new_Node
)
{
Node
color
(
bindings
[
parameter_names
[
0
].
token
()]);
Node
r
(
bindings
[
parameter_names
[
1
].
token
()]);
Node
g
(
bindings
[
parameter_names
[
2
].
token
()]);
Node
b
(
bindings
[
parameter_names
[
3
].
token
()]);
Node
h
(
bindings
[
parameter_names
[
4
].
token
()]);
Node
s
(
bindings
[
parameter_names
[
5
].
token
()]);
Node
l
(
bindings
[
parameter_names
[
6
].
token
()]);
Node
a
(
bindings
[
parameter_names
[
7
].
token
()]);
bool
no_rgb
=
r
.
is_false
()
&&
g
.
is_false
()
&&
b
.
is_false
();
bool
no_hsl
=
h
.
is_false
()
&&
s
.
is_false
()
&&
l
.
is_false
();
if
(
!
no_rgb
&&
!
no_hsl
)
{
throw_eval_error
(
"cannot specify RGB and HSL values for a color at the same time for 'change-color'"
,
r
.
path
(),
r
.
line
());
}
else
if
(
!
no_rgb
)
{
double
new_r
=
(
r
.
is_false
()
?
color
[
0
]
:
r
).
numeric_value
();
double
new_g
=
(
g
.
is_false
()
?
color
[
1
]
:
g
).
numeric_value
();
double
new_b
=
(
b
.
is_false
()
?
color
[
2
]
:
b
).
numeric_value
();
double
new_a
=
(
a
.
is_false
()
?
color
[
3
]
:
a
).
numeric_value
();
return
new_Node
(
""
,
0
,
new_r
,
new_g
,
new_b
,
new_a
);
}
else
if
(
!
no_hsl
)
{
cerr
<<
color
.
to_string
()
<<
endl
;
Node
hsl_node
(
rgb_to_hsl
(
color
[
0
].
numeric_value
(),
color
[
1
].
numeric_value
(),
color
[
2
].
numeric_value
(),
new_Node
));
cerr
<<
hsl_node
.
to_string
()
<<
endl
;
double
new_h
=
(
h
.
is_false
()
?
hsl_node
[
0
].
numeric_value
()
:
h
.
numeric_value
());
double
new_s
=
(
s
.
is_false
()
?
hsl_node
[
1
].
numeric_value
()
:
s
.
numeric_value
());
double
new_l
=
(
l
.
is_false
()
?
hsl_node
[
2
].
numeric_value
()
:
l
.
numeric_value
());
double
new_a
=
(
a
.
is_false
()
?
color
[
3
].
numeric_value
()
:
a
.
numeric_value
());
return
hsla_impl
(
new_h
,
new_s
,
new_l
,
new_a
,
new_Node
);
}
else
if
(
!
a
.
is_false
())
{
return
new_Node
(
""
,
0
,
color
[
0
].
numeric_value
(),
color
[
1
].
numeric_value
(),
color
[
2
].
numeric_value
(),
a
.
numeric_value
());
}
else
{
throw_eval_error
(
"not enough arguments for 'change-color'"
,
color
.
path
(),
color
.
line
());
}
// unreachable statement
return
Node
();
}
extern
Signature
invert_sig
=
"invert($color)"
;
Node
invert
(
const
Node
parameter_names
,
Environment
&
bindings
,
Node_Factory
&
new_Node
)
{
Node
orig
(
bindings
[
parameter_names
[
0
].
token
()]);
...
...
functions.hpp
View file @
74e8c9f1
...
...
@@ -92,11 +92,14 @@ namespace Sass {
extern
Signature
hsl_sig
;
Node
hsl
(
const
Node
,
Environment
&
,
Node_Factory
&
);
extern
Signature
adjust_hue_sig
;
Node
adjust_hue
(
const
Node
,
Environment
&
,
Node_Factory
&
);
extern
Signature
adjust_color_sig
;
Node
adjust_color
(
const
Node
,
Environment
&
,
Node_Factory
&
);
extern
Signature
adjust_hue
_sig
;
Node
adjust_hue
(
const
Node
,
Environment
&
,
Node_Factory
&
);
extern
Signature
change_color
_sig
;
Node
change_color
(
const
Node
,
Environment
&
,
Node_Factory
&
);
extern
Signature
invert_sig
;
Node
invert
(
const
Node
,
Environment
&
,
Node_Factory
&
);
...
...
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