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
549f708f
Commit
549f708f
authored
Apr 05, 2012
by
Aaron Leung
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implemented the "mix" builtin function.
parent
e4af18b0
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
74 additions
and
9 deletions
+74
-9
context.cpp
context.cpp
+3
-0
eval_apply.cpp
eval_apply.cpp
+6
-1
functions.cpp
functions.cpp
+40
-3
functions.hpp
functions.hpp
+6
-0
node.cpp
node.cpp
+11
-4
input.scss
spec/basic/22_colors_with_alpha/input.scss
+4
-0
output.css
spec/basic/22_colors_with_alpha/output.css
+4
-1
No files found.
context.cpp
View file @
549f708f
...
@@ -36,6 +36,8 @@ namespace Sass {
...
@@ -36,6 +36,8 @@ namespace Sass {
register_function
(
red_descriptor
,
red
);
register_function
(
red_descriptor
,
red
);
register_function
(
green_descriptor
,
green
);
register_function
(
green_descriptor
,
green
);
register_function
(
blue_descriptor
,
blue
);
register_function
(
blue_descriptor
,
blue
);
register_function
(
mix_2_descriptor
,
mix_2
);
register_function
(
mix_3_descriptor
,
mix_3
);
}
}
}
}
\ No newline at end of file
eval_apply.cpp
View file @
549f708f
...
@@ -114,7 +114,12 @@ namespace Sass {
...
@@ -114,7 +114,12 @@ namespace Sass {
}
}
}
break
;
}
break
;
case
Node
:
:
textual_percentage
:
case
Node
:
:
textual_percentage
:
{
Node
pct
(
expr
.
line_number
,
std
::
atof
(
expr
.
content
.
token
.
begin
));
pct
.
type
=
Node
::
numeric_percentage
;
return
pct
;
}
break
;
case
Node
:
:
textual_dimension
:
{
case
Node
:
:
textual_dimension
:
{
return
Node
(
expr
.
line_number
,
return
Node
(
expr
.
line_number
,
std
::
atof
(
expr
.
content
.
token
.
begin
),
std
::
atof
(
expr
.
content
.
token
.
begin
),
...
...
functions.cpp
View file @
549f708f
...
@@ -10,10 +10,11 @@ namespace Sass {
...
@@ -10,10 +10,11 @@ namespace Sass {
Function_Descriptor
rgb_descriptor
=
Function_Descriptor
rgb_descriptor
=
{
"rgb"
,
"$red"
,
"$green"
,
"$blue"
,
0
};
{
"rgb"
,
"$red"
,
"$green"
,
"$blue"
,
0
};
Node
rgb
(
const
vector
<
Token
>&
parameters
,
map
<
Token
,
Node
>&
bindings
)
{
Node
rgb
(
const
vector
<
Token
>&
parameters
,
map
<
Token
,
Node
>&
bindings
)
{
Node
color
(
Node
::
numeric_color
,
0
,
3
);
Node
color
(
Node
::
numeric_color
,
0
,
4
);
color
<<
bindings
[
parameters
[
0
]]
color
<<
bindings
[
parameters
[
0
]]
<<
bindings
[
parameters
[
1
]]
<<
bindings
[
parameters
[
1
]]
<<
bindings
[
parameters
[
2
]];
<<
bindings
[
parameters
[
2
]]
<<
Node
(
0
,
1.0
);
return
color
;
return
color
;
}
}
...
@@ -31,7 +32,9 @@ namespace Sass {
...
@@ -31,7 +32,9 @@ namespace Sass {
Function_Descriptor
rgba_2_descriptor
=
Function_Descriptor
rgba_2_descriptor
=
{
"rgba"
,
"$color"
,
"$alpha"
,
0
};
{
"rgba"
,
"$color"
,
"$alpha"
,
0
};
Node
rgba_2
(
const
vector
<
Token
>&
parameters
,
map
<
Token
,
Node
>&
bindings
)
{
Node
rgba_2
(
const
vector
<
Token
>&
parameters
,
map
<
Token
,
Node
>&
bindings
)
{
return
bindings
[
parameters
[
0
]].
clone
()
<<
bindings
[
parameters
[
1
]];
Node
color
(
bindings
[
parameters
[
0
]].
clone
());
color
[
3
]
=
bindings
[
parameters
[
1
]];
return
color
;
}
}
Function_Descriptor
red_descriptor
=
Function_Descriptor
red_descriptor
=
...
@@ -52,5 +55,38 @@ namespace Sass {
...
@@ -52,5 +55,38 @@ namespace Sass {
return
bindings
[
parameters
[
0
]][
2
];
return
bindings
[
parameters
[
0
]][
2
];
}
}
Node
mix_impl
(
Node
color1
,
Node
color2
,
double
weight
)
{
double
p
=
weight
/
100
;
double
w
=
2
*
p
-
1
;
double
a
=
color1
[
3
].
content
.
numeric_value
-
color2
[
3
].
content
.
numeric_value
;
double
w1
=
(((
w
*
a
==
-
1
)
?
w
:
(
w
+
a
)
/
(
1
+
w
*
a
))
+
1
)
/
2.0
;
double
w2
=
1
-
w1
;
Node
mixed
(
Node
::
numeric_color
,
color1
.
line_number
,
4
);
for
(
int
i
=
0
;
i
<
3
;
++
i
)
{
mixed
<<
Node
(
mixed
.
line_number
,
w1
*
color1
[
i
].
content
.
numeric_value
+
w2
*
color2
[
i
].
content
.
numeric_value
);
}
double
alpha
=
color1
[
3
].
content
.
numeric_value
*
p
+
color2
[
3
].
content
.
numeric_value
*
(
1
-
p
);
mixed
<<
Node
(
mixed
.
line_number
,
alpha
);
return
mixed
;
}
Function_Descriptor
mix_2_descriptor
=
{
"mix"
,
"$color1"
,
"$color2"
,
0
};
Node
mix_2
(
const
vector
<
Token
>&
parameters
,
map
<
Token
,
Node
>&
bindings
)
{
return
mix_impl
(
bindings
[
parameters
[
0
]],
bindings
[
parameters
[
1
]],
50
);
}
Function_Descriptor
mix_3_descriptor
=
{
"mix"
,
"$color1"
,
"$color2"
,
"$weight"
,
0
};
Node
mix_3
(
const
vector
<
Token
>&
parameters
,
map
<
Token
,
Node
>&
bindings
)
{
return
mix_impl
(
bindings
[
parameters
[
0
]],
bindings
[
parameters
[
1
]],
bindings
[
parameters
[
2
]].
content
.
numeric_value
);
}
}
}
}
}
\ No newline at end of file
functions.hpp
View file @
549f708f
...
@@ -60,6 +60,12 @@ namespace Sass {
...
@@ -60,6 +60,12 @@ namespace Sass {
extern
Function_Descriptor
blue_descriptor
;
extern
Function_Descriptor
blue_descriptor
;
Node
blue
(
const
vector
<
Token
>&
parameters
,
map
<
Token
,
Node
>&
bindings
);
Node
blue
(
const
vector
<
Token
>&
parameters
,
map
<
Token
,
Node
>&
bindings
);
extern
Function_Descriptor
mix_2_descriptor
;
Node
mix_2
(
const
vector
<
Token
>&
parameters
,
map
<
Token
,
Node
>&
bindings
);
extern
Function_Descriptor
mix_3_descriptor
;
Node
mix_3
(
const
vector
<
Token
>&
parameters
,
map
<
Token
,
Node
>&
bindings
);
}
}
}
}
node.cpp
View file @
549f708f
...
@@ -141,6 +141,13 @@ namespace Sass {
...
@@ -141,6 +141,13 @@ namespace Sass {
return
"/"
;
return
"/"
;
}
break
;
}
break
;
case
numeric_percentage
:
{
stringstream
ss
;
ss
<<
content
.
dimension
.
numeric_value
;
ss
<<
'%'
;
return
ss
.
str
();
}
case
numeric_dimension
:
{
case
numeric_dimension
:
{
stringstream
ss
;
stringstream
ss
;
ss
<<
content
.
dimension
.
numeric_value
;
ss
<<
content
.
dimension
.
numeric_value
;
...
@@ -193,11 +200,11 @@ namespace Sass {
...
@@ -193,11 +200,11 @@ namespace Sass {
}
}
else
{
else
{
stringstream
ss
;
stringstream
ss
;
ss
<<
"rgba("
<<
at
(
0
).
content
.
numeric_value
;
ss
<<
"rgba("
<<
static_cast
<
unsigned
long
>
(
at
(
0
).
content
.
numeric_value
)
;
for
(
int
i
=
1
;
i
<
4
;
++
i
)
{
for
(
int
i
=
1
;
i
<
3
;
++
i
)
{
ss
<<
", "
<<
at
(
i
).
content
.
numeric_value
;
ss
<<
", "
<<
static_cast
<
unsigned
long
>
(
at
(
i
).
content
.
numeric_value
)
;
}
}
ss
<<
')'
;
ss
<<
", "
<<
at
(
3
).
content
.
numeric_value
<<
')'
;
return
ss
.
str
();
return
ss
.
str
();
}
}
}
break
;
}
break
;
...
...
spec/basic/22_colors_with_alpha/input.scss
View file @
549f708f
...
@@ -16,4 +16,8 @@ div {
...
@@ -16,4 +16,8 @@ div {
hoo
:
red
(
$x
);
hoo
:
red
(
$x
);
moo
:
green
(
$x
);
moo
:
green
(
$x
);
poo
:
blue
(
$x
);
poo
:
blue
(
$x
);
roo
:
mix
(
#f00
,
#00f
);
doo
:
mix
(
#f00
,
#00f
,
25%
);
goo
:
mix
(
rgba
(
255
,
0
,
0
,
0
.5
)
,
#00f
);
}
}
spec/basic/22_colors_with_alpha/output.css
View file @
549f708f
...
@@ -9,4 +9,7 @@ div {
...
@@ -9,4 +9,7 @@ div {
groo
:
aqua
;
groo
:
aqua
;
hoo
:
123
;
hoo
:
123
;
moo
:
45
;
moo
:
45
;
poo
:
6
;
}
poo
:
6
;
roo
:
#7f007f
;
doo
:
#3f00bf
;
goo
:
rgba
(
63
,
0
,
191
,
0.75
);
}
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