sassc 2.0.1 → 2.1.0.pre1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (200) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.gitmodules +1 -1
  4. data/.travis.yml +7 -3
  5. data/CHANGELOG.md +3 -0
  6. data/CODE_OF_CONDUCT.md +1 -1
  7. data/README.md +1 -1
  8. data/Rakefile +23 -8
  9. data/ext/extconf.rb +39 -0
  10. data/ext/libsass/.gitignore +1 -0
  11. data/ext/libsass/GNUmakefile.am +23 -39
  12. data/ext/libsass/Makefile +56 -91
  13. data/ext/libsass/Makefile.conf +16 -2
  14. data/ext/libsass/configure.ac +8 -12
  15. data/ext/libsass/include/sass/base.h +1 -0
  16. data/ext/libsass/include/sass/context.h +1 -1
  17. data/ext/libsass/src/GNUmakefile.am +1 -5
  18. data/ext/libsass/src/ast.cpp +747 -2010
  19. data/ext/libsass/src/ast.hpp +239 -2383
  20. data/ext/libsass/src/{to_c.cpp → ast2c.cpp} +22 -16
  21. data/ext/libsass/src/ast2c.hpp +39 -0
  22. data/ext/libsass/src/ast_def_macros.hpp +62 -10
  23. data/ext/libsass/src/ast_fwd_decl.cpp +1 -0
  24. data/ext/libsass/src/ast_fwd_decl.hpp +43 -165
  25. data/ext/libsass/src/ast_sel_cmp.cpp +909 -0
  26. data/ext/libsass/src/ast_sel_unify.cpp +280 -0
  27. data/ext/libsass/src/ast_selectors.cpp +1475 -0
  28. data/ext/libsass/src/ast_selectors.hpp +568 -0
  29. data/ext/libsass/src/ast_supports.cpp +130 -0
  30. data/ext/libsass/src/ast_supports.hpp +121 -0
  31. data/ext/libsass/src/ast_values.cpp +967 -0
  32. data/ext/libsass/src/ast_values.hpp +489 -0
  33. data/ext/libsass/src/backtrace.cpp +4 -0
  34. data/ext/libsass/src/base64vlq.cpp +3 -0
  35. data/ext/libsass/src/bind.cpp +18 -17
  36. data/ext/libsass/src/bind.hpp +3 -1
  37. data/ext/libsass/src/c2ast.cpp +64 -0
  38. data/ext/libsass/src/c2ast.hpp +14 -0
  39. data/ext/libsass/src/cencode.c +2 -2
  40. data/ext/libsass/src/check_nesting.cpp +52 -56
  41. data/ext/libsass/src/check_nesting.hpp +35 -34
  42. data/ext/libsass/src/color_maps.cpp +156 -153
  43. data/ext/libsass/src/color_maps.hpp +152 -152
  44. data/ext/libsass/src/constants.cpp +15 -0
  45. data/ext/libsass/src/constants.hpp +13 -0
  46. data/ext/libsass/src/context.cpp +24 -14
  47. data/ext/libsass/src/context.hpp +6 -6
  48. data/ext/libsass/src/cssize.cpp +69 -71
  49. data/ext/libsass/src/cssize.hpp +50 -50
  50. data/ext/libsass/src/debugger.hpp +117 -110
  51. data/ext/libsass/src/emitter.cpp +13 -12
  52. data/ext/libsass/src/emitter.hpp +13 -9
  53. data/ext/libsass/src/environment.cpp +15 -1
  54. data/ext/libsass/src/environment.hpp +6 -0
  55. data/ext/libsass/src/error_handling.cpp +36 -59
  56. data/ext/libsass/src/error_handling.hpp +29 -16
  57. data/ext/libsass/src/eval.cpp +302 -323
  58. data/ext/libsass/src/eval.hpp +64 -55
  59. data/ext/libsass/src/expand.cpp +94 -88
  60. data/ext/libsass/src/expand.hpp +33 -37
  61. data/ext/libsass/src/extend.cpp +38 -36
  62. data/ext/libsass/src/extend.hpp +15 -15
  63. data/ext/libsass/src/file.cpp +34 -2
  64. data/ext/libsass/src/fn_colors.cpp +594 -0
  65. data/ext/libsass/src/fn_colors.hpp +85 -0
  66. data/ext/libsass/src/fn_lists.cpp +284 -0
  67. data/ext/libsass/src/fn_lists.hpp +34 -0
  68. data/ext/libsass/src/fn_maps.cpp +94 -0
  69. data/ext/libsass/src/fn_maps.hpp +30 -0
  70. data/ext/libsass/src/fn_miscs.cpp +256 -0
  71. data/ext/libsass/src/fn_miscs.hpp +40 -0
  72. data/ext/libsass/src/fn_numbers.cpp +220 -0
  73. data/ext/libsass/src/fn_numbers.hpp +45 -0
  74. data/ext/libsass/src/fn_selectors.cpp +235 -0
  75. data/ext/libsass/src/fn_selectors.hpp +35 -0
  76. data/ext/libsass/src/fn_strings.cpp +254 -0
  77. data/ext/libsass/src/fn_strings.hpp +34 -0
  78. data/ext/libsass/src/fn_utils.cpp +156 -0
  79. data/ext/libsass/src/fn_utils.hpp +56 -0
  80. data/ext/libsass/src/inspect.cpp +101 -152
  81. data/ext/libsass/src/inspect.hpp +69 -73
  82. data/ext/libsass/src/json.cpp +2 -2
  83. data/ext/libsass/src/lexer.cpp +6 -3
  84. data/ext/libsass/src/listize.cpp +9 -11
  85. data/ext/libsass/src/listize.hpp +11 -7
  86. data/ext/libsass/src/memory/SharedPtr.cpp +2 -83
  87. data/ext/libsass/src/memory/SharedPtr.hpp +127 -143
  88. data/ext/libsass/src/node.cpp +13 -10
  89. data/ext/libsass/src/node.hpp +3 -3
  90. data/ext/libsass/src/operation.hpp +184 -144
  91. data/ext/libsass/src/operators.cpp +43 -17
  92. data/ext/libsass/src/operators.hpp +5 -5
  93. data/ext/libsass/src/output.cpp +21 -18
  94. data/ext/libsass/src/output.hpp +14 -21
  95. data/ext/libsass/src/parser.cpp +215 -183
  96. data/ext/libsass/src/parser.hpp +28 -24
  97. data/ext/libsass/src/plugins.cpp +5 -1
  98. data/ext/libsass/src/position.cpp +3 -0
  99. data/ext/libsass/src/prelexer.cpp +9 -3
  100. data/ext/libsass/src/prelexer.hpp +9 -9
  101. data/ext/libsass/src/remove_placeholders.cpp +14 -11
  102. data/ext/libsass/src/remove_placeholders.hpp +8 -9
  103. data/ext/libsass/src/sass.cpp +9 -3
  104. data/ext/libsass/src/sass.hpp +12 -9
  105. data/ext/libsass/src/sass2scss.cpp +45 -14
  106. data/ext/libsass/src/sass_context.cpp +18 -15
  107. data/ext/libsass/src/sass_functions.cpp +6 -3
  108. data/ext/libsass/src/sass_functions.hpp +1 -1
  109. data/ext/libsass/src/sass_util.cpp +3 -0
  110. data/ext/libsass/src/sass_values.cpp +21 -13
  111. data/ext/libsass/src/source_map.cpp +5 -2
  112. data/ext/libsass/src/source_map.hpp +2 -2
  113. data/ext/libsass/src/subset_map.cpp +4 -1
  114. data/ext/libsass/src/to_value.cpp +23 -21
  115. data/ext/libsass/src/to_value.hpp +18 -22
  116. data/ext/libsass/src/units.cpp +4 -0
  117. data/ext/libsass/src/units.hpp +1 -0
  118. data/ext/libsass/src/utf8/checked.h +12 -10
  119. data/ext/libsass/src/utf8/core.h +3 -0
  120. data/ext/libsass/src/utf8_string.cpp +3 -0
  121. data/ext/libsass/src/util.cpp +67 -75
  122. data/ext/libsass/src/util.hpp +64 -19
  123. data/ext/libsass/src/util_string.cpp +75 -0
  124. data/ext/libsass/src/util_string.hpp +19 -0
  125. data/ext/libsass/src/values.cpp +22 -13
  126. data/ext/libsass/src/values.hpp +2 -2
  127. data/ext/libsass/win/libsass.targets +30 -4
  128. data/ext/libsass/win/libsass.vcxproj.filters +82 -4
  129. data/lib/sassc.rb +24 -0
  130. data/lib/sassc/engine.rb +2 -2
  131. data/lib/sassc/native.rb +8 -1
  132. data/lib/sassc/version.rb +1 -1
  133. data/sassc.gemspec +19 -11
  134. data/test/engine_test.rb +26 -1
  135. data/test/native_test.rb +1 -1
  136. metadata +66 -72
  137. data/ext/Rakefile +0 -3
  138. data/ext/libsass/.github/CONTRIBUTING.md +0 -65
  139. data/ext/libsass/.github/ISSUE_TEMPLATE.md +0 -54
  140. data/ext/libsass/.travis.yml +0 -64
  141. data/ext/libsass/Readme.md +0 -104
  142. data/ext/libsass/SECURITY.md +0 -10
  143. data/ext/libsass/appveyor.yml +0 -91
  144. data/ext/libsass/docs/README.md +0 -20
  145. data/ext/libsass/docs/api-context-example.md +0 -45
  146. data/ext/libsass/docs/api-context-internal.md +0 -163
  147. data/ext/libsass/docs/api-context.md +0 -295
  148. data/ext/libsass/docs/api-doc.md +0 -215
  149. data/ext/libsass/docs/api-function-example.md +0 -67
  150. data/ext/libsass/docs/api-function-internal.md +0 -8
  151. data/ext/libsass/docs/api-function.md +0 -74
  152. data/ext/libsass/docs/api-importer-example.md +0 -112
  153. data/ext/libsass/docs/api-importer-internal.md +0 -20
  154. data/ext/libsass/docs/api-importer.md +0 -86
  155. data/ext/libsass/docs/api-value-example.md +0 -55
  156. data/ext/libsass/docs/api-value-internal.md +0 -76
  157. data/ext/libsass/docs/api-value.md +0 -154
  158. data/ext/libsass/docs/build-on-darwin.md +0 -27
  159. data/ext/libsass/docs/build-on-gentoo.md +0 -55
  160. data/ext/libsass/docs/build-on-windows.md +0 -139
  161. data/ext/libsass/docs/build-shared-library.md +0 -35
  162. data/ext/libsass/docs/build-with-autotools.md +0 -78
  163. data/ext/libsass/docs/build-with-makefiles.md +0 -68
  164. data/ext/libsass/docs/build-with-mingw.md +0 -107
  165. data/ext/libsass/docs/build-with-visual-studio.md +0 -90
  166. data/ext/libsass/docs/build.md +0 -97
  167. data/ext/libsass/docs/compatibility-plan.md +0 -48
  168. data/ext/libsass/docs/contributing.md +0 -17
  169. data/ext/libsass/docs/custom-functions-internal.md +0 -122
  170. data/ext/libsass/docs/dev-ast-memory.md +0 -223
  171. data/ext/libsass/docs/implementations.md +0 -56
  172. data/ext/libsass/docs/plugins.md +0 -47
  173. data/ext/libsass/docs/setup-environment.md +0 -68
  174. data/ext/libsass/docs/source-map-internals.md +0 -51
  175. data/ext/libsass/docs/trace.md +0 -26
  176. data/ext/libsass/docs/triage.md +0 -17
  177. data/ext/libsass/docs/unicode.md +0 -39
  178. data/ext/libsass/extconf.rb +0 -6
  179. data/ext/libsass/script/bootstrap +0 -13
  180. data/ext/libsass/script/branding +0 -10
  181. data/ext/libsass/script/ci-build-libsass +0 -134
  182. data/ext/libsass/script/ci-build-plugin +0 -62
  183. data/ext/libsass/script/ci-install-compiler +0 -6
  184. data/ext/libsass/script/ci-install-deps +0 -20
  185. data/ext/libsass/script/ci-report-coverage +0 -42
  186. data/ext/libsass/script/spec +0 -5
  187. data/ext/libsass/script/tap-driver +0 -652
  188. data/ext/libsass/script/tap-runner +0 -1
  189. data/ext/libsass/script/test-leaks.pl +0 -103
  190. data/ext/libsass/src/functions.cpp +0 -2234
  191. data/ext/libsass/src/functions.hpp +0 -198
  192. data/ext/libsass/src/to_c.hpp +0 -39
  193. data/ext/libsass/test/test_node.cpp +0 -94
  194. data/ext/libsass/test/test_paths.cpp +0 -28
  195. data/ext/libsass/test/test_selector_difference.cpp +0 -25
  196. data/ext/libsass/test/test_specificity.cpp +0 -25
  197. data/ext/libsass/test/test_subset_map.cpp +0 -472
  198. data/ext/libsass/test/test_superselector.cpp +0 -69
  199. data/ext/libsass/test/test_unification.cpp +0 -31
  200. data/lib/tasks/libsass.rb +0 -33
@@ -0,0 +1,594 @@
1
+ // sass.hpp must go before all system headers to get the
2
+ // __EXTENSIONS__ fix on Solaris.
3
+ #include "sass.hpp"
4
+
5
+ #include <cctype>
6
+ #include <iomanip>
7
+ #include "ast.hpp"
8
+ #include "fn_utils.hpp"
9
+ #include "fn_colors.hpp"
10
+ #include "util.hpp"
11
+
12
+ namespace Sass {
13
+
14
+ namespace Functions {
15
+
16
+ bool string_argument(AST_Node_Obj obj) {
17
+ String_Constant* s = Cast<String_Constant>(obj);
18
+ if (s == nullptr) return false;
19
+ const std::string& str = s->value();
20
+ return starts_with(str, "calc(") ||
21
+ starts_with(str, "var(");
22
+ }
23
+
24
+ void hsla_alpha_percent_deprecation(const ParserState& pstate, const std::string val)
25
+ {
26
+
27
+ std::string msg("Passing a percentage as the alpha value to hsla() will be interpreted");
28
+ std::string tail("differently in future versions of Sass. For now, use " + val + " instead.");
29
+
30
+ deprecated(msg, tail, false, pstate);
31
+
32
+ }
33
+
34
+ Signature rgb_sig = "rgb($red, $green, $blue)";
35
+ BUILT_IN(rgb)
36
+ {
37
+ if (
38
+ string_argument(env["$red"]) ||
39
+ string_argument(env["$green"]) ||
40
+ string_argument(env["$blue"])
41
+ ) {
42
+ return SASS_MEMORY_NEW(String_Constant, pstate, "rgb("
43
+ + env["$red"]->to_string()
44
+ + ", "
45
+ + env["$green"]->to_string()
46
+ + ", "
47
+ + env["$blue"]->to_string()
48
+ + ")"
49
+ );
50
+ }
51
+
52
+ return SASS_MEMORY_NEW(Color_RGBA,
53
+ pstate,
54
+ COLOR_NUM("$red"),
55
+ COLOR_NUM("$green"),
56
+ COLOR_NUM("$blue"));
57
+ }
58
+
59
+ Signature rgba_4_sig = "rgba($red, $green, $blue, $alpha)";
60
+ BUILT_IN(rgba_4)
61
+ {
62
+ if (
63
+ string_argument(env["$red"]) ||
64
+ string_argument(env["$green"]) ||
65
+ string_argument(env["$blue"]) ||
66
+ string_argument(env["$alpha"])
67
+ ) {
68
+ return SASS_MEMORY_NEW(String_Constant, pstate, "rgba("
69
+ + env["$red"]->to_string()
70
+ + ", "
71
+ + env["$green"]->to_string()
72
+ + ", "
73
+ + env["$blue"]->to_string()
74
+ + ", "
75
+ + env["$alpha"]->to_string()
76
+ + ")"
77
+ );
78
+ }
79
+
80
+ return SASS_MEMORY_NEW(Color_RGBA,
81
+ pstate,
82
+ COLOR_NUM("$red"),
83
+ COLOR_NUM("$green"),
84
+ COLOR_NUM("$blue"),
85
+ ALPHA_NUM("$alpha"));
86
+ }
87
+
88
+ Signature rgba_2_sig = "rgba($color, $alpha)";
89
+ BUILT_IN(rgba_2)
90
+ {
91
+ if (
92
+ string_argument(env["$color"])
93
+ ) {
94
+ return SASS_MEMORY_NEW(String_Constant, pstate, "rgba("
95
+ + env["$color"]->to_string()
96
+ + ", "
97
+ + env["$alpha"]->to_string()
98
+ + ")"
99
+ );
100
+ }
101
+
102
+ Color_RGBA_Obj c_arg = ARG("$color", Color)->toRGBA();
103
+
104
+ if (
105
+ string_argument(env["$alpha"])
106
+ ) {
107
+ std::stringstream strm;
108
+ strm << "rgba("
109
+ << (int)c_arg->r() << ", "
110
+ << (int)c_arg->g() << ", "
111
+ << (int)c_arg->b() << ", "
112
+ << env["$alpha"]->to_string()
113
+ << ")";
114
+ return SASS_MEMORY_NEW(String_Constant, pstate, strm.str());
115
+ }
116
+
117
+ Color_RGBA_Obj new_c = SASS_MEMORY_COPY(c_arg);
118
+ new_c->a(ALPHA_NUM("$alpha"));
119
+ new_c->disp("");
120
+ return new_c.detach();
121
+ }
122
+
123
+ ////////////////
124
+ // RGB FUNCTIONS
125
+ ////////////////
126
+
127
+ Signature red_sig = "red($color)";
128
+ BUILT_IN(red)
129
+ {
130
+ Color_RGBA_Obj color = ARG("$color", Color)->toRGBA();
131
+ return SASS_MEMORY_NEW(Number, pstate, color->r());
132
+ }
133
+
134
+ Signature green_sig = "green($color)";
135
+ BUILT_IN(green)
136
+ {
137
+ Color_RGBA_Obj color = ARG("$color", Color)->toRGBA();
138
+ return SASS_MEMORY_NEW(Number, pstate, color->g());
139
+ }
140
+
141
+ Signature blue_sig = "blue($color)";
142
+ BUILT_IN(blue)
143
+ {
144
+ Color_RGBA_Obj color = ARG("$color", Color)->toRGBA();
145
+ return SASS_MEMORY_NEW(Number, pstate, color->b());
146
+ }
147
+
148
+ Color_RGBA* colormix(Context& ctx, ParserState& pstate, Color* color1, Color* color2, double weight) {
149
+ Color_RGBA_Obj c1 = color1->toRGBA();
150
+ Color_RGBA_Obj c2 = color2->toRGBA();
151
+ double p = weight/100;
152
+ double w = 2*p - 1;
153
+ double a = c1->a() - c2->a();
154
+
155
+ double w1 = (((w * a == -1) ? w : (w + a)/(1 + w*a)) + 1)/2.0;
156
+ double w2 = 1 - w1;
157
+
158
+ return SASS_MEMORY_NEW(Color_RGBA,
159
+ pstate,
160
+ Sass::round(w1*c1->r() + w2*c2->r(), ctx.c_options.precision),
161
+ Sass::round(w1*c1->g() + w2*c2->g(), ctx.c_options.precision),
162
+ Sass::round(w1*c1->b() + w2*c2->b(), ctx.c_options.precision),
163
+ c1->a()*p + c2->a()*(1-p));
164
+ }
165
+
166
+ Signature mix_sig = "mix($color-1, $color-2, $weight: 50%)";
167
+ BUILT_IN(mix)
168
+ {
169
+ Color_Obj color1 = ARG("$color-1", Color);
170
+ Color_Obj color2 = ARG("$color-2", Color);
171
+ double weight = DARG_U_PRCT("$weight");
172
+ return colormix(ctx, pstate, color1, color2, weight);
173
+
174
+ }
175
+
176
+ ////////////////
177
+ // HSL FUNCTIONS
178
+ ////////////////
179
+
180
+ Signature hsl_sig = "hsl($hue, $saturation, $lightness)";
181
+ BUILT_IN(hsl)
182
+ {
183
+ if (
184
+ string_argument(env["$hue"]) ||
185
+ string_argument(env["$saturation"]) ||
186
+ string_argument(env["$lightness"])
187
+ ) {
188
+ return SASS_MEMORY_NEW(String_Constant, pstate, "hsl("
189
+ + env["$hue"]->to_string()
190
+ + ", "
191
+ + env["$saturation"]->to_string()
192
+ + ", "
193
+ + env["$lightness"]->to_string()
194
+ + ")"
195
+ );
196
+ }
197
+
198
+ return SASS_MEMORY_NEW(Color_HSLA,
199
+ pstate,
200
+ ARGVAL("$hue"),
201
+ ARGVAL("$saturation"),
202
+ ARGVAL("$lightness"),
203
+ 1.0);
204
+
205
+ }
206
+
207
+ Signature hsla_sig = "hsla($hue, $saturation, $lightness, $alpha)";
208
+ BUILT_IN(hsla)
209
+ {
210
+ if (
211
+ string_argument(env["$hue"]) ||
212
+ string_argument(env["$saturation"]) ||
213
+ string_argument(env["$lightness"]) ||
214
+ string_argument(env["$alpha"])
215
+ ) {
216
+ return SASS_MEMORY_NEW(String_Constant, pstate, "hsla("
217
+ + env["$hue"]->to_string()
218
+ + ", "
219
+ + env["$saturation"]->to_string()
220
+ + ", "
221
+ + env["$lightness"]->to_string()
222
+ + ", "
223
+ + env["$alpha"]->to_string()
224
+ + ")"
225
+ );
226
+ }
227
+
228
+ Number* alpha = ARG("$alpha", Number);
229
+ if (alpha && alpha->unit() == "%") {
230
+ Number_Obj val = SASS_MEMORY_COPY(alpha);
231
+ val->numerators.clear(); // convert
232
+ val->value(val->value() / 100.0);
233
+ std::string nr(val->to_string(ctx.c_options));
234
+ hsla_alpha_percent_deprecation(pstate, nr);
235
+ }
236
+
237
+ return SASS_MEMORY_NEW(Color_HSLA,
238
+ pstate,
239
+ ARGVAL("$hue"),
240
+ ARGVAL("$saturation"),
241
+ ARGVAL("$lightness"),
242
+ ARGVAL("$alpha"));
243
+
244
+ }
245
+
246
+ /////////////////////////////////////////////////////////////////////////
247
+ // Query functions
248
+ /////////////////////////////////////////////////////////////////////////
249
+
250
+ Signature hue_sig = "hue($color)";
251
+ BUILT_IN(hue)
252
+ {
253
+ Color_HSLA_Obj col = ARG("$color", Color)->toHSLA();
254
+ return SASS_MEMORY_NEW(Number, pstate, col->h(), "deg");
255
+ }
256
+
257
+ Signature saturation_sig = "saturation($color)";
258
+ BUILT_IN(saturation)
259
+ {
260
+ Color_HSLA_Obj col = ARG("$color", Color)->toHSLA();
261
+ return SASS_MEMORY_NEW(Number, pstate, col->s(), "%");
262
+ }
263
+
264
+ Signature lightness_sig = "lightness($color)";
265
+ BUILT_IN(lightness)
266
+ {
267
+ Color_HSLA_Obj col = ARG("$color", Color)->toHSLA();
268
+ return SASS_MEMORY_NEW(Number, pstate, col->l(), "%");
269
+ }
270
+
271
+ /////////////////////////////////////////////////////////////////////////
272
+ // HSL manipulation functions
273
+ /////////////////////////////////////////////////////////////////////////
274
+
275
+ Signature adjust_hue_sig = "adjust-hue($color, $degrees)";
276
+ BUILT_IN(adjust_hue)
277
+ {
278
+ Color* col = ARG("$color", Color);
279
+ double degrees = ARGVAL("$degrees");
280
+ Color_HSLA_Obj copy = col->copyAsHSLA();
281
+ copy->h(absmod(copy->h() + degrees, 360.0));
282
+ return copy.detach();
283
+ }
284
+
285
+ Signature lighten_sig = "lighten($color, $amount)";
286
+ BUILT_IN(lighten)
287
+ {
288
+ Color* col = ARG("$color", Color);
289
+ double amount = DARG_U_PRCT("$amount");
290
+ Color_HSLA_Obj copy = col->copyAsHSLA();
291
+ copy->l(clip(copy->l() + amount, 0.0, 100.0));
292
+ return copy.detach();
293
+
294
+ }
295
+
296
+ Signature darken_sig = "darken($color, $amount)";
297
+ BUILT_IN(darken)
298
+ {
299
+ Color* col = ARG("$color", Color);
300
+ double amount = DARG_U_PRCT("$amount");
301
+ Color_HSLA_Obj copy = col->copyAsHSLA();
302
+ copy->l(clip(copy->l() - amount, 0.0, 100.0));
303
+ return copy.detach();
304
+ }
305
+
306
+ Signature saturate_sig = "saturate($color, $amount: false)";
307
+ BUILT_IN(saturate)
308
+ {
309
+ // CSS3 filter function overload: pass literal through directly
310
+ if (!Cast<Number>(env["$amount"])) {
311
+ return SASS_MEMORY_NEW(String_Quoted, pstate, "saturate(" + env["$color"]->to_string(ctx.c_options) + ")");
312
+ }
313
+
314
+ Color* col = ARG("$color", Color);
315
+ double amount = DARG_U_PRCT("$amount");
316
+ Color_HSLA_Obj copy = col->copyAsHSLA();
317
+ copy->s(clip(copy->s() + amount, 0.0, 100.0));
318
+ return copy.detach();
319
+ }
320
+
321
+ Signature desaturate_sig = "desaturate($color, $amount)";
322
+ BUILT_IN(desaturate)
323
+ {
324
+ Color* col = ARG("$color", Color);
325
+ double amount = DARG_U_PRCT("$amount");
326
+ Color_HSLA_Obj copy = col->copyAsHSLA();
327
+ copy->s(clip(copy->s() - amount, 0.0, 100.0));
328
+ return copy.detach();
329
+ }
330
+
331
+ Signature grayscale_sig = "grayscale($color)";
332
+ BUILT_IN(grayscale)
333
+ {
334
+ // CSS3 filter function overload: pass literal through directly
335
+ Number* amount = Cast<Number>(env["$color"]);
336
+ if (amount) {
337
+ return SASS_MEMORY_NEW(String_Quoted, pstate, "grayscale(" + amount->to_string(ctx.c_options) + ")");
338
+ }
339
+
340
+ Color* col = ARG("$color", Color);
341
+ Color_HSLA_Obj copy = col->copyAsHSLA();
342
+ copy->s(0.0); // just reset saturation
343
+ return copy.detach();
344
+ }
345
+
346
+ /////////////////////////////////////////////////////////////////////////
347
+ // Misc manipulation functions
348
+ /////////////////////////////////////////////////////////////////////////
349
+
350
+ Signature complement_sig = "complement($color)";
351
+ BUILT_IN(complement)
352
+ {
353
+ Color* col = ARG("$color", Color);
354
+ Color_HSLA_Obj copy = col->copyAsHSLA();
355
+ copy->h(absmod(copy->h() - 180.0, 360.0));
356
+ return copy.detach();
357
+ }
358
+
359
+ Signature invert_sig = "invert($color, $weight: 100%)";
360
+ BUILT_IN(invert)
361
+ {
362
+ // CSS3 filter function overload: pass literal through directly
363
+ Number* amount = Cast<Number>(env["$color"]);
364
+ if (amount) {
365
+ return SASS_MEMORY_NEW(String_Quoted, pstate, "invert(" + amount->to_string(ctx.c_options) + ")");
366
+ }
367
+
368
+ Color* col = ARG("$color", Color);
369
+ double weight = DARG_U_PRCT("$weight");
370
+ Color_RGBA_Obj inv = col->copyAsRGBA();
371
+ inv->r(clip(255.0 - inv->r(), 0.0, 255.0));
372
+ inv->g(clip(255.0 - inv->g(), 0.0, 255.0));
373
+ inv->b(clip(255.0 - inv->b(), 0.0, 255.0));
374
+ return colormix(ctx, pstate, inv, col, weight);
375
+ }
376
+
377
+ /////////////////////////////////////////////////////////////////////////
378
+ // Opacity functions
379
+ /////////////////////////////////////////////////////////////////////////
380
+
381
+ Signature alpha_sig = "alpha($color)";
382
+ Signature opacity_sig = "opacity($color)";
383
+ BUILT_IN(alpha)
384
+ {
385
+ String_Constant* ie_kwd = Cast<String_Constant>(env["$color"]);
386
+ if (ie_kwd) {
387
+ return SASS_MEMORY_NEW(String_Quoted, pstate, "alpha(" + ie_kwd->value() + ")");
388
+ }
389
+
390
+ // CSS3 filter function overload: pass literal through directly
391
+ Number* amount = Cast<Number>(env["$color"]);
392
+ if (amount) {
393
+ return SASS_MEMORY_NEW(String_Quoted, pstate, "opacity(" + amount->to_string(ctx.c_options) + ")");
394
+ }
395
+
396
+ return SASS_MEMORY_NEW(Number, pstate, ARG("$color", Color)->a());
397
+ }
398
+
399
+ Signature opacify_sig = "opacify($color, $amount)";
400
+ Signature fade_in_sig = "fade-in($color, $amount)";
401
+ BUILT_IN(opacify)
402
+ {
403
+ Color* col = ARG("$color", Color);
404
+ double amount = DARG_U_FACT("$amount");
405
+ Color_Obj copy = SASS_MEMORY_COPY(col);
406
+ copy->a(clip(col->a() + amount, 0.0, 1.0));
407
+ return copy.detach();
408
+ }
409
+
410
+ Signature transparentize_sig = "transparentize($color, $amount)";
411
+ Signature fade_out_sig = "fade-out($color, $amount)";
412
+ BUILT_IN(transparentize)
413
+ {
414
+ Color* col = ARG("$color", Color);
415
+ double amount = DARG_U_FACT("$amount");
416
+ Color_Obj copy = SASS_MEMORY_COPY(col);
417
+ copy->a(std::max(col->a() - amount, 0.0));
418
+ return copy.detach();
419
+ }
420
+
421
+ ////////////////////////
422
+ // OTHER COLOR FUNCTIONS
423
+ ////////////////////////
424
+
425
+ Signature adjust_color_sig = "adjust-color($color, $red: false, $green: false, $blue: false, $hue: false, $saturation: false, $lightness: false, $alpha: false)";
426
+ BUILT_IN(adjust_color)
427
+ {
428
+ Color* col = ARG("$color", Color);
429
+ Number* r = Cast<Number>(env["$red"]);
430
+ Number* g = Cast<Number>(env["$green"]);
431
+ Number* b = Cast<Number>(env["$blue"]);
432
+ Number* h = Cast<Number>(env["$hue"]);
433
+ Number* s = Cast<Number>(env["$saturation"]);
434
+ Number* l = Cast<Number>(env["$lightness"]);
435
+ Number* a = Cast<Number>(env["$alpha"]);
436
+
437
+ bool rgb = r || g || b;
438
+ bool hsl = h || s || l;
439
+
440
+ if (rgb && hsl) {
441
+ error("Cannot specify HSL and RGB values for a color at the same time for `adjust-color'", pstate, traces);
442
+ }
443
+ else if (rgb) {
444
+ Color_RGBA_Obj c = col->copyAsRGBA();
445
+ if (r) c->r(c->r() + DARG_R_BYTE("$red"));
446
+ if (g) c->g(c->g() + DARG_R_BYTE("$green"));
447
+ if (b) c->b(c->b() + DARG_R_BYTE("$blue"));
448
+ if (a) c->a(c->a() + DARG_R_FACT("$alpha"));
449
+ return c.detach();
450
+ }
451
+ else if (hsl) {
452
+ Color_HSLA_Obj c = col->copyAsHSLA();
453
+ if (h) c->h(c->h() + absmod(h->value(), 360.0));
454
+ if (s) c->s(c->s() + DARG_R_PRCT("$saturation"));
455
+ if (l) c->l(c->l() + DARG_R_PRCT("$lightness"));
456
+ if (a) c->a(c->a() + DARG_R_FACT("$alpha"));
457
+ return c.detach();
458
+ }
459
+ else if (a) {
460
+ Color_Obj c = SASS_MEMORY_COPY(col);
461
+ c->a(c->a() + DARG_R_FACT("$alpha"));
462
+ c->a(clip(c->a(), 0.0, 1.0));
463
+ return c.detach();
464
+ }
465
+ error("not enough arguments for `adjust-color'", pstate, traces);
466
+ // unreachable
467
+ return col;
468
+ }
469
+
470
+ Signature scale_color_sig = "scale-color($color, $red: false, $green: false, $blue: false, $hue: false, $saturation: false, $lightness: false, $alpha: false)";
471
+ BUILT_IN(scale_color)
472
+ {
473
+ Color* col = ARG("$color", Color);
474
+ Number* r = Cast<Number>(env["$red"]);
475
+ Number* g = Cast<Number>(env["$green"]);
476
+ Number* b = Cast<Number>(env["$blue"]);
477
+ Number* h = Cast<Number>(env["$hue"]);
478
+ Number* s = Cast<Number>(env["$saturation"]);
479
+ Number* l = Cast<Number>(env["$lightness"]);
480
+ Number* a = Cast<Number>(env["$alpha"]);
481
+
482
+ bool rgb = r || g || b;
483
+ bool hsl = h || s || l;
484
+
485
+ if (rgb && hsl) {
486
+ error("Cannot specify HSL and RGB values for a color at the same time for `scale-color'", pstate, traces);
487
+ }
488
+ else if (rgb) {
489
+ Color_RGBA_Obj c = col->copyAsRGBA();
490
+ double rscale = (r ? DARG_R_PRCT("$red") : 0.0) / 100.0;
491
+ double gscale = (g ? DARG_R_PRCT("$green") : 0.0) / 100.0;
492
+ double bscale = (b ? DARG_R_PRCT("$blue") : 0.0) / 100.0;
493
+ double ascale = (a ? DARG_R_PRCT("$alpha") : 0.0) / 100.0;
494
+ if (rscale) c->r(c->r() + rscale * (rscale > 0.0 ? 255.0 - c->r() : c->r()));
495
+ if (gscale) c->g(c->g() + gscale * (gscale > 0.0 ? 255.0 - c->g() : c->g()));
496
+ if (bscale) c->b(c->b() + bscale * (bscale > 0.0 ? 255.0 - c->b() : c->b()));
497
+ if (ascale) c->a(c->a() + ascale * (ascale > 0.0 ? 1.0 - c->a() : c->a()));
498
+ return c.detach();
499
+ }
500
+ else if (hsl) {
501
+ Color_HSLA_Obj c = col->copyAsHSLA();
502
+ double hscale = (h ? DARG_R_PRCT("$hue") : 0.0) / 100.0;
503
+ double sscale = (s ? DARG_R_PRCT("$saturation") : 0.0) / 100.0;
504
+ double lscale = (l ? DARG_R_PRCT("$lightness") : 0.0) / 100.0;
505
+ double ascale = (a ? DARG_R_PRCT("$alpha") : 0.0) / 100.0;
506
+ if (hscale) c->h(c->h() + hscale * (hscale > 0.0 ? 360.0 - c->h() : c->h()));
507
+ if (sscale) c->s(c->s() + sscale * (sscale > 0.0 ? 100.0 - c->l() : c->s()));
508
+ if (lscale) c->l(c->l() + lscale * (lscale > 0.0 ? 100.0 - c->l() : c->l()));
509
+ if (ascale) c->a(c->a() + ascale * (ascale > 0.0 ? 1.0 - c->a() : c->a()));
510
+ return c.detach();
511
+ }
512
+ else if (a) {
513
+ Color_Obj c = SASS_MEMORY_COPY(col);
514
+ double ascale = DARG_R_PRCT("$alpha") / 100.0;
515
+ c->a(c->a() + ascale * (ascale > 0.0 ? 1.0 - c->a() : c->a()));
516
+ c->a(clip(c->a(), 0.0, 1.0));
517
+ return c.detach();
518
+ }
519
+ error("not enough arguments for `scale-color'", pstate, traces);
520
+ // unreachable
521
+ return col;
522
+ }
523
+
524
+ Signature change_color_sig = "change-color($color, $red: false, $green: false, $blue: false, $hue: false, $saturation: false, $lightness: false, $alpha: false)";
525
+ BUILT_IN(change_color)
526
+ {
527
+ Color* col = ARG("$color", Color);
528
+ Number* r = Cast<Number>(env["$red"]);
529
+ Number* g = Cast<Number>(env["$green"]);
530
+ Number* b = Cast<Number>(env["$blue"]);
531
+ Number* h = Cast<Number>(env["$hue"]);
532
+ Number* s = Cast<Number>(env["$saturation"]);
533
+ Number* l = Cast<Number>(env["$lightness"]);
534
+ Number* a = Cast<Number>(env["$alpha"]);
535
+
536
+ bool rgb = r || g || b;
537
+ bool hsl = h || s || l;
538
+
539
+ if (rgb && hsl) {
540
+ error("Cannot specify HSL and RGB values for a color at the same time for `change-color'", pstate, traces);
541
+ }
542
+ else if (rgb) {
543
+ Color_RGBA_Obj c = col->copyAsRGBA();
544
+ if (r) c->r(DARG_U_BYTE("$red"));
545
+ if (g) c->g(DARG_U_BYTE("$green"));
546
+ if (b) c->b(DARG_U_BYTE("$blue"));
547
+ if (a) c->a(DARG_U_FACT("$alpha"));
548
+ return c.detach();
549
+ }
550
+ else if (hsl) {
551
+ Color_HSLA_Obj c = col->copyAsHSLA();
552
+ if (h) c->h(absmod(h->value(), 360.0));
553
+ if (s) c->s(DARG_U_PRCT("$saturation"));
554
+ if (l) c->l(DARG_U_PRCT("$lightness"));
555
+ if (a) c->a(DARG_U_FACT("$alpha"));
556
+ return c.detach();
557
+ }
558
+ else if (a) {
559
+ Color_Obj c = SASS_MEMORY_COPY(col);
560
+ c->a(clip(DARG_U_FACT("$alpha"), 0.0, 1.0));
561
+ return c.detach();
562
+ }
563
+ error("not enough arguments for `change-color'", pstate, traces);
564
+ // unreachable
565
+ return col;
566
+ }
567
+
568
+ Signature ie_hex_str_sig = "ie-hex-str($color)";
569
+ BUILT_IN(ie_hex_str)
570
+ {
571
+ Color* col = ARG("$color", Color);
572
+ Color_RGBA_Obj c = col->toRGBA();
573
+ double r = clip(c->r(), 0.0, 255.0);
574
+ double g = clip(c->g(), 0.0, 255.0);
575
+ double b = clip(c->b(), 0.0, 255.0);
576
+ double a = clip(c->a(), 0.0, 1.0) * 255.0;
577
+
578
+ std::stringstream ss;
579
+ ss << '#' << std::setw(2) << std::setfill('0');
580
+ ss << std::hex << std::setw(2) << static_cast<unsigned long>(Sass::round(a, ctx.c_options.precision));
581
+ ss << std::hex << std::setw(2) << static_cast<unsigned long>(Sass::round(r, ctx.c_options.precision));
582
+ ss << std::hex << std::setw(2) << static_cast<unsigned long>(Sass::round(g, ctx.c_options.precision));
583
+ ss << std::hex << std::setw(2) << static_cast<unsigned long>(Sass::round(b, ctx.c_options.precision));
584
+
585
+ std::string result(ss.str());
586
+ for (size_t i = 0, L = result.length(); i < L; ++i) {
587
+ result[i] = std::toupper(result[i]);
588
+ }
589
+ return SASS_MEMORY_NEW(String_Quoted, pstate, result);
590
+ }
591
+
592
+ }
593
+
594
+ }