sassc 2.0.0 → 2.4.0
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.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/.gitmodules +1 -1
- data/.travis.yml +9 -3
- data/CHANGELOG.md +36 -0
- data/CODE_OF_CONDUCT.md +1 -1
- data/README.md +1 -1
- data/Rakefile +43 -7
- data/ext/depend +4 -0
- data/ext/extconf.rb +92 -0
- data/ext/libsass/VERSION +1 -0
- data/ext/libsass/include/sass/base.h +9 -1
- data/ext/libsass/include/sass/context.h +5 -1
- data/ext/libsass/src/MurmurHash2.hpp +91 -0
- data/ext/libsass/src/ast.cpp +755 -2028
- data/ext/libsass/src/ast.hpp +492 -2477
- data/ext/libsass/src/{to_c.cpp → ast2c.cpp} +22 -16
- data/ext/libsass/src/ast2c.hpp +39 -0
- data/ext/libsass/src/ast_def_macros.hpp +70 -10
- data/ext/libsass/src/ast_fwd_decl.cpp +5 -3
- data/ext/libsass/src/ast_fwd_decl.hpp +107 -296
- data/ext/libsass/src/ast_helpers.hpp +292 -0
- data/ext/libsass/src/ast_sel_cmp.cpp +396 -0
- data/ext/libsass/src/ast_sel_super.cpp +539 -0
- data/ext/libsass/src/ast_sel_unify.cpp +275 -0
- data/ext/libsass/src/ast_sel_weave.cpp +616 -0
- data/ext/libsass/src/ast_selectors.cpp +1043 -0
- data/ext/libsass/src/ast_selectors.hpp +522 -0
- data/ext/libsass/src/ast_supports.cpp +114 -0
- data/ext/libsass/src/ast_supports.hpp +121 -0
- data/ext/libsass/src/ast_values.cpp +1154 -0
- data/ext/libsass/src/ast_values.hpp +498 -0
- data/ext/libsass/src/backtrace.cpp +11 -7
- data/ext/libsass/src/backtrace.hpp +5 -5
- data/ext/libsass/src/base64vlq.cpp +5 -2
- data/ext/libsass/src/base64vlq.hpp +1 -1
- data/ext/libsass/src/bind.cpp +35 -34
- data/ext/libsass/src/bind.hpp +3 -1
- data/ext/libsass/src/c2ast.cpp +64 -0
- data/ext/libsass/src/c2ast.hpp +14 -0
- data/ext/libsass/src/cencode.c +4 -6
- data/ext/libsass/src/check_nesting.cpp +83 -88
- data/ext/libsass/src/check_nesting.hpp +39 -34
- data/ext/libsass/src/color_maps.cpp +168 -164
- data/ext/libsass/src/color_maps.hpp +152 -160
- data/ext/libsass/src/constants.cpp +20 -0
- data/ext/libsass/src/constants.hpp +19 -0
- data/ext/libsass/src/context.cpp +104 -121
- data/ext/libsass/src/context.hpp +43 -55
- data/ext/libsass/src/cssize.cpp +103 -188
- data/ext/libsass/src/cssize.hpp +45 -51
- data/ext/libsass/src/dart_helpers.hpp +199 -0
- data/ext/libsass/src/debugger.hpp +524 -361
- data/ext/libsass/src/emitter.cpp +26 -26
- data/ext/libsass/src/emitter.hpp +20 -18
- data/ext/libsass/src/environment.cpp +41 -27
- data/ext/libsass/src/environment.hpp +33 -22
- data/ext/libsass/src/error_handling.cpp +92 -94
- data/ext/libsass/src/error_handling.hpp +73 -50
- data/ext/libsass/src/eval.cpp +380 -515
- data/ext/libsass/src/eval.hpp +64 -57
- data/ext/libsass/src/eval_selectors.cpp +75 -0
- data/ext/libsass/src/expand.cpp +322 -263
- data/ext/libsass/src/expand.hpp +55 -39
- data/ext/libsass/src/extender.cpp +1188 -0
- data/ext/libsass/src/extender.hpp +399 -0
- data/ext/libsass/src/extension.cpp +43 -0
- data/ext/libsass/src/extension.hpp +89 -0
- data/ext/libsass/src/file.cpp +134 -88
- data/ext/libsass/src/file.hpp +28 -37
- data/ext/libsass/src/fn_colors.cpp +596 -0
- data/ext/libsass/src/fn_colors.hpp +85 -0
- data/ext/libsass/src/fn_lists.cpp +285 -0
- data/ext/libsass/src/fn_lists.hpp +34 -0
- data/ext/libsass/src/fn_maps.cpp +94 -0
- data/ext/libsass/src/fn_maps.hpp +30 -0
- data/ext/libsass/src/fn_miscs.cpp +244 -0
- data/ext/libsass/src/fn_miscs.hpp +40 -0
- data/ext/libsass/src/fn_numbers.cpp +227 -0
- data/ext/libsass/src/fn_numbers.hpp +45 -0
- data/ext/libsass/src/fn_selectors.cpp +205 -0
- data/ext/libsass/src/fn_selectors.hpp +35 -0
- data/ext/libsass/src/fn_strings.cpp +268 -0
- data/ext/libsass/src/fn_strings.hpp +34 -0
- data/ext/libsass/src/fn_utils.cpp +158 -0
- data/ext/libsass/src/fn_utils.hpp +62 -0
- data/ext/libsass/src/inspect.cpp +253 -266
- data/ext/libsass/src/inspect.hpp +72 -74
- data/ext/libsass/src/json.cpp +2 -2
- data/ext/libsass/src/lexer.cpp +25 -84
- data/ext/libsass/src/lexer.hpp +5 -16
- data/ext/libsass/src/listize.cpp +27 -43
- data/ext/libsass/src/listize.hpp +14 -11
- data/ext/libsass/src/mapping.hpp +1 -0
- data/ext/libsass/src/memory.hpp +12 -0
- data/ext/libsass/src/memory/allocator.cpp +48 -0
- data/ext/libsass/src/memory/allocator.hpp +138 -0
- data/ext/libsass/src/memory/config.hpp +20 -0
- data/ext/libsass/src/memory/memory_pool.hpp +186 -0
- data/ext/libsass/src/memory/shared_ptr.cpp +33 -0
- data/ext/libsass/src/memory/shared_ptr.hpp +332 -0
- data/ext/libsass/src/operation.hpp +193 -143
- data/ext/libsass/src/operators.cpp +56 -29
- data/ext/libsass/src/operators.hpp +11 -11
- data/ext/libsass/src/ordered_map.hpp +112 -0
- data/ext/libsass/src/output.cpp +59 -75
- data/ext/libsass/src/output.hpp +15 -22
- data/ext/libsass/src/parser.cpp +662 -818
- data/ext/libsass/src/parser.hpp +96 -100
- data/ext/libsass/src/parser_selectors.cpp +189 -0
- data/ext/libsass/src/permutate.hpp +164 -0
- data/ext/libsass/src/plugins.cpp +12 -8
- data/ext/libsass/src/plugins.hpp +8 -8
- data/ext/libsass/src/position.cpp +10 -26
- data/ext/libsass/src/position.hpp +44 -21
- data/ext/libsass/src/prelexer.cpp +14 -8
- data/ext/libsass/src/prelexer.hpp +9 -9
- data/ext/libsass/src/remove_placeholders.cpp +59 -57
- data/ext/libsass/src/remove_placeholders.hpp +20 -18
- data/ext/libsass/src/sass.cpp +25 -18
- data/ext/libsass/src/sass.hpp +22 -14
- data/ext/libsass/src/sass2scss.cpp +49 -18
- data/ext/libsass/src/sass_context.cpp +104 -132
- data/ext/libsass/src/sass_context.hpp +2 -2
- data/ext/libsass/src/sass_functions.cpp +7 -4
- data/ext/libsass/src/sass_functions.hpp +1 -1
- data/ext/libsass/src/sass_values.cpp +26 -21
- data/ext/libsass/src/settings.hpp +19 -0
- data/ext/libsass/src/source.cpp +69 -0
- data/ext/libsass/src/source.hpp +95 -0
- data/ext/libsass/src/source_data.hpp +32 -0
- data/ext/libsass/src/source_map.cpp +27 -20
- data/ext/libsass/src/source_map.hpp +14 -11
- data/ext/libsass/src/stylesheet.cpp +22 -0
- data/ext/libsass/src/stylesheet.hpp +57 -0
- data/ext/libsass/src/to_value.cpp +24 -22
- data/ext/libsass/src/to_value.hpp +18 -22
- data/ext/libsass/src/units.cpp +28 -22
- data/ext/libsass/src/units.hpp +9 -8
- data/ext/libsass/src/utf8/checked.h +12 -10
- data/ext/libsass/src/utf8/core.h +3 -0
- data/ext/libsass/src/utf8_string.cpp +12 -10
- data/ext/libsass/src/utf8_string.hpp +7 -6
- data/ext/libsass/src/util.cpp +97 -107
- data/ext/libsass/src/util.hpp +74 -30
- data/ext/libsass/src/util_string.cpp +125 -0
- data/ext/libsass/src/util_string.hpp +73 -0
- data/ext/libsass/src/values.cpp +33 -24
- data/ext/libsass/src/values.hpp +2 -2
- data/lib/sassc.rb +24 -0
- data/lib/sassc/engine.rb +7 -5
- data/lib/sassc/functions_handler.rb +11 -13
- data/lib/sassc/native.rb +10 -9
- data/lib/sassc/native/native_functions_api.rb +0 -5
- data/lib/sassc/script.rb +4 -6
- data/lib/sassc/version.rb +1 -1
- data/sassc.gemspec +32 -12
- data/test/engine_test.rb +32 -2
- data/test/functions_test.rb +38 -1
- data/test/native_test.rb +4 -4
- metadata +95 -109
- data/ext/Rakefile +0 -3
- data/ext/libsass/.editorconfig +0 -15
- data/ext/libsass/.gitattributes +0 -2
- data/ext/libsass/.github/CONTRIBUTING.md +0 -65
- data/ext/libsass/.github/ISSUE_TEMPLATE.md +0 -54
- data/ext/libsass/.gitignore +0 -85
- data/ext/libsass/.travis.yml +0 -64
- data/ext/libsass/COPYING +0 -25
- data/ext/libsass/GNUmakefile.am +0 -88
- data/ext/libsass/INSTALL +0 -1
- data/ext/libsass/LICENSE +0 -25
- data/ext/libsass/Makefile +0 -351
- data/ext/libsass/Makefile.conf +0 -55
- data/ext/libsass/Readme.md +0 -104
- data/ext/libsass/SECURITY.md +0 -10
- data/ext/libsass/appveyor.yml +0 -91
- data/ext/libsass/configure.ac +0 -138
- data/ext/libsass/contrib/libsass.spec +0 -66
- data/ext/libsass/docs/README.md +0 -20
- data/ext/libsass/docs/api-context-example.md +0 -45
- data/ext/libsass/docs/api-context-internal.md +0 -163
- data/ext/libsass/docs/api-context.md +0 -295
- data/ext/libsass/docs/api-doc.md +0 -215
- data/ext/libsass/docs/api-function-example.md +0 -67
- data/ext/libsass/docs/api-function-internal.md +0 -8
- data/ext/libsass/docs/api-function.md +0 -74
- data/ext/libsass/docs/api-importer-example.md +0 -112
- data/ext/libsass/docs/api-importer-internal.md +0 -20
- data/ext/libsass/docs/api-importer.md +0 -86
- data/ext/libsass/docs/api-value-example.md +0 -55
- data/ext/libsass/docs/api-value-internal.md +0 -76
- data/ext/libsass/docs/api-value.md +0 -154
- data/ext/libsass/docs/build-on-darwin.md +0 -27
- data/ext/libsass/docs/build-on-gentoo.md +0 -55
- data/ext/libsass/docs/build-on-windows.md +0 -139
- data/ext/libsass/docs/build-shared-library.md +0 -35
- data/ext/libsass/docs/build-with-autotools.md +0 -78
- data/ext/libsass/docs/build-with-makefiles.md +0 -68
- data/ext/libsass/docs/build-with-mingw.md +0 -107
- data/ext/libsass/docs/build-with-visual-studio.md +0 -90
- data/ext/libsass/docs/build.md +0 -97
- data/ext/libsass/docs/compatibility-plan.md +0 -48
- data/ext/libsass/docs/contributing.md +0 -17
- data/ext/libsass/docs/custom-functions-internal.md +0 -122
- data/ext/libsass/docs/dev-ast-memory.md +0 -223
- data/ext/libsass/docs/implementations.md +0 -56
- data/ext/libsass/docs/plugins.md +0 -47
- data/ext/libsass/docs/setup-environment.md +0 -68
- data/ext/libsass/docs/source-map-internals.md +0 -51
- data/ext/libsass/docs/trace.md +0 -26
- data/ext/libsass/docs/triage.md +0 -17
- data/ext/libsass/docs/unicode.md +0 -39
- data/ext/libsass/extconf.rb +0 -6
- data/ext/libsass/include/sass/version.h.in +0 -12
- data/ext/libsass/m4/.gitkeep +0 -0
- data/ext/libsass/m4/m4-ax_cxx_compile_stdcxx_11.m4 +0 -167
- data/ext/libsass/res/resource.rc +0 -35
- data/ext/libsass/script/bootstrap +0 -13
- data/ext/libsass/script/branding +0 -10
- data/ext/libsass/script/ci-build-libsass +0 -134
- data/ext/libsass/script/ci-build-plugin +0 -62
- data/ext/libsass/script/ci-install-compiler +0 -6
- data/ext/libsass/script/ci-install-deps +0 -20
- data/ext/libsass/script/ci-report-coverage +0 -42
- data/ext/libsass/script/spec +0 -5
- data/ext/libsass/script/tap-driver +0 -652
- data/ext/libsass/script/tap-runner +0 -1
- data/ext/libsass/script/test-leaks.pl +0 -103
- data/ext/libsass/src/GNUmakefile.am +0 -54
- data/ext/libsass/src/extend.cpp +0 -2130
- data/ext/libsass/src/extend.hpp +0 -86
- data/ext/libsass/src/functions.cpp +0 -2234
- data/ext/libsass/src/functions.hpp +0 -198
- data/ext/libsass/src/memory/SharedPtr.cpp +0 -114
- data/ext/libsass/src/memory/SharedPtr.hpp +0 -206
- data/ext/libsass/src/node.cpp +0 -319
- data/ext/libsass/src/node.hpp +0 -118
- data/ext/libsass/src/paths.hpp +0 -71
- data/ext/libsass/src/sass_util.cpp +0 -149
- data/ext/libsass/src/sass_util.hpp +0 -256
- data/ext/libsass/src/subset_map.cpp +0 -55
- data/ext/libsass/src/subset_map.hpp +0 -76
- data/ext/libsass/src/support/libsass.pc.in +0 -11
- data/ext/libsass/src/to_c.hpp +0 -39
- data/ext/libsass/test/test_node.cpp +0 -94
- data/ext/libsass/test/test_paths.cpp +0 -28
- data/ext/libsass/test/test_selector_difference.cpp +0 -25
- data/ext/libsass/test/test_specificity.cpp +0 -25
- data/ext/libsass/test/test_subset_map.cpp +0 -472
- data/ext/libsass/test/test_superselector.cpp +0 -69
- data/ext/libsass/test/test_unification.cpp +0 -31
- data/ext/libsass/version.sh +0 -10
- data/ext/libsass/win/libsass.sln +0 -39
- data/ext/libsass/win/libsass.sln.DotSettings +0 -9
- data/ext/libsass/win/libsass.targets +0 -118
- data/ext/libsass/win/libsass.vcxproj +0 -188
- data/ext/libsass/win/libsass.vcxproj.filters +0 -357
- data/lib/sassc/native/lib_c.rb +0 -21
- data/lib/tasks/libsass.rb +0 -33
data/ext/libsass/src/file.hpp
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
#ifndef SASS_FILE_H
|
|
2
2
|
#define SASS_FILE_H
|
|
3
3
|
|
|
4
|
+
// sass.hpp must go before all system headers to get the
|
|
5
|
+
// __EXTENSIONS__ fix on Solaris.
|
|
6
|
+
#include "sass.hpp"
|
|
7
|
+
|
|
4
8
|
#include <string>
|
|
5
9
|
#include <vector>
|
|
6
10
|
|
|
@@ -13,56 +17,56 @@ namespace Sass {
|
|
|
13
17
|
|
|
14
18
|
// return the current directory
|
|
15
19
|
// always with forward slashes
|
|
16
|
-
|
|
20
|
+
sass::string get_cwd();
|
|
17
21
|
|
|
18
22
|
// test if path exists and is a file
|
|
19
|
-
bool file_exists(const
|
|
23
|
+
bool file_exists(const sass::string& file);
|
|
20
24
|
|
|
21
25
|
// return if given path is absolute
|
|
22
26
|
// works with *nix and windows paths
|
|
23
|
-
bool is_absolute_path(const
|
|
27
|
+
bool is_absolute_path(const sass::string& path);
|
|
24
28
|
|
|
25
29
|
// return only the directory part of path
|
|
26
|
-
|
|
30
|
+
sass::string dir_name(const sass::string& path);
|
|
27
31
|
|
|
28
32
|
// return only the filename part of path
|
|
29
|
-
|
|
33
|
+
sass::string base_name(const sass::string&);
|
|
30
34
|
|
|
31
35
|
// do a locigal clean up of the path
|
|
32
36
|
// no physical check on the filesystem
|
|
33
|
-
|
|
37
|
+
sass::string make_canonical_path (sass::string path);
|
|
34
38
|
|
|
35
39
|
// join two path segments cleanly together
|
|
36
40
|
// but only if right side is not absolute yet
|
|
37
|
-
|
|
41
|
+
sass::string join_paths(sass::string root, sass::string name);
|
|
38
42
|
|
|
39
43
|
// if the relative path is outside of the cwd we want want to
|
|
40
44
|
// show the absolute path in console messages
|
|
41
|
-
|
|
45
|
+
sass::string path_for_console(const sass::string& rel_path, const sass::string& abs_path, const sass::string& orig_path);
|
|
42
46
|
|
|
43
47
|
// create an absolute path by resolving relative paths with cwd
|
|
44
|
-
|
|
48
|
+
sass::string rel2abs(const sass::string& path, const sass::string& base = ".", const sass::string& cwd = get_cwd());
|
|
45
49
|
|
|
46
50
|
// create a path that is relative to the given base directory
|
|
47
51
|
// path and base will first be resolved against cwd to make them absolute
|
|
48
|
-
|
|
52
|
+
sass::string abs2rel(const sass::string& path, const sass::string& base = ".", const sass::string& cwd = get_cwd());
|
|
49
53
|
|
|
50
54
|
// helper function to resolve a filename
|
|
51
55
|
// searching without variations in all paths
|
|
52
|
-
|
|
53
|
-
|
|
56
|
+
sass::string find_file(const sass::string& file, struct Sass_Compiler* options);
|
|
57
|
+
sass::string find_file(const sass::string& file, const sass::vector<sass::string> paths);
|
|
54
58
|
|
|
55
59
|
// helper function to resolve a include filename
|
|
56
60
|
// this has the original resolve logic for sass include
|
|
57
|
-
|
|
61
|
+
sass::string find_include(const sass::string& file, const sass::vector<sass::string> paths);
|
|
58
62
|
|
|
59
63
|
// split a path string delimited by semicolons or colons (OS dependent)
|
|
60
|
-
|
|
64
|
+
sass::vector<sass::string> split_path_list(const char* paths);
|
|
61
65
|
|
|
62
66
|
// try to load the given filename
|
|
63
67
|
// returned memory must be freed
|
|
64
68
|
// will auto convert .sass files
|
|
65
|
-
char* read_file(const
|
|
69
|
+
char* read_file(const sass::string& file);
|
|
66
70
|
|
|
67
71
|
}
|
|
68
72
|
|
|
@@ -70,14 +74,14 @@ namespace Sass {
|
|
|
70
74
|
class Importer {
|
|
71
75
|
public:
|
|
72
76
|
// requested import path
|
|
73
|
-
|
|
77
|
+
sass::string imp_path;
|
|
74
78
|
// parent context path
|
|
75
|
-
|
|
79
|
+
sass::string ctx_path;
|
|
76
80
|
// base derived from context path
|
|
77
81
|
// this really just acts as a cache
|
|
78
|
-
|
|
82
|
+
sass::string base_path;
|
|
79
83
|
public:
|
|
80
|
-
Importer(
|
|
84
|
+
Importer(sass::string imp_path, sass::string ctx_path)
|
|
81
85
|
: imp_path(File::make_canonical_path(imp_path)),
|
|
82
86
|
ctx_path(File::make_canonical_path(ctx_path)),
|
|
83
87
|
base_path(File::dir_name(ctx_path))
|
|
@@ -88,9 +92,9 @@ namespace Sass {
|
|
|
88
92
|
class Include : public Importer {
|
|
89
93
|
public:
|
|
90
94
|
// resolved absolute path
|
|
91
|
-
|
|
95
|
+
sass::string abs_path;
|
|
92
96
|
public:
|
|
93
|
-
Include(const Importer& imp,
|
|
97
|
+
Include(const Importer& imp, sass::string abs_path)
|
|
94
98
|
: Importer(imp), abs_path(abs_path)
|
|
95
99
|
{ }
|
|
96
100
|
};
|
|
@@ -100,7 +104,7 @@ namespace Sass {
|
|
|
100
104
|
public:
|
|
101
105
|
// the file contents
|
|
102
106
|
char* contents;
|
|
103
|
-
//
|
|
107
|
+
// connected sourcemap
|
|
104
108
|
char* srcmap;
|
|
105
109
|
public:
|
|
106
110
|
Resource(char* contents, char* srcmap)
|
|
@@ -108,23 +112,10 @@ namespace Sass {
|
|
|
108
112
|
{ }
|
|
109
113
|
};
|
|
110
114
|
|
|
111
|
-
// parsed stylesheet from loaded resource
|
|
112
|
-
class StyleSheet : public Resource {
|
|
113
|
-
public:
|
|
114
|
-
// parsed root block
|
|
115
|
-
Block_Obj root;
|
|
116
|
-
public:
|
|
117
|
-
StyleSheet(const Resource& res, Block_Obj root)
|
|
118
|
-
: Resource(res), root(root)
|
|
119
|
-
{ }
|
|
120
|
-
};
|
|
121
|
-
|
|
122
115
|
namespace File {
|
|
123
116
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
std::vector<Include> resolve_includes(const std::string& root, const std::string& file,
|
|
127
|
-
const std::vector<std::string>& exts = defaultExtensions);
|
|
117
|
+
sass::vector<Include> resolve_includes(const sass::string& root, const sass::string& file,
|
|
118
|
+
const sass::vector<sass::string>& exts = { ".scss", ".sass", ".css" });
|
|
128
119
|
|
|
129
120
|
}
|
|
130
121
|
|
|
@@ -0,0 +1,596 @@
|
|
|
1
|
+
// sass.hpp must go before all system headers to get the
|
|
2
|
+
// __EXTENSIONS__ fix on Solaris.
|
|
3
|
+
#include "sass.hpp"
|
|
4
|
+
|
|
5
|
+
#include <iomanip>
|
|
6
|
+
#include "ast.hpp"
|
|
7
|
+
#include "fn_utils.hpp"
|
|
8
|
+
#include "fn_colors.hpp"
|
|
9
|
+
#include "util.hpp"
|
|
10
|
+
#include "util_string.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 sass::string& str = s->value();
|
|
20
|
+
return starts_with(str, "calc(") ||
|
|
21
|
+
starts_with(str, "var(");
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
void hsla_alpha_percent_deprecation(const SourceSpan& pstate, const sass::string val)
|
|
25
|
+
{
|
|
26
|
+
|
|
27
|
+
sass::string msg("Passing a percentage as the alpha value to hsla() will be interpreted");
|
|
28
|
+
sass::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
|
+
sass::ostream 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, SourceSpan& 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($color1, $color2, $weight: 50%)";
|
|
167
|
+
BUILT_IN(mix)
|
|
168
|
+
{
|
|
169
|
+
Color_Obj color1 = ARG("$color1", Color);
|
|
170
|
+
Color_Obj color2 = ARG("$color2", 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
|
+
sass::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
|
+
double weight = DARG_U_PRCT("$weight");
|
|
365
|
+
if (amount) {
|
|
366
|
+
// TODO: does not throw on 100% manually passed as value
|
|
367
|
+
if (weight < 100.0) {
|
|
368
|
+
error("Only one argument may be passed to the plain-CSS invert() function.", pstate, traces);
|
|
369
|
+
}
|
|
370
|
+
return SASS_MEMORY_NEW(String_Quoted, pstate, "invert(" + amount->to_string(ctx.c_options) + ")");
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
Color* col = ARG("$color", Color);
|
|
374
|
+
Color_RGBA_Obj inv = col->copyAsRGBA();
|
|
375
|
+
inv->r(clip(255.0 - inv->r(), 0.0, 255.0));
|
|
376
|
+
inv->g(clip(255.0 - inv->g(), 0.0, 255.0));
|
|
377
|
+
inv->b(clip(255.0 - inv->b(), 0.0, 255.0));
|
|
378
|
+
return colormix(ctx, pstate, inv, col, weight);
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
/////////////////////////////////////////////////////////////////////////
|
|
382
|
+
// Opacity functions
|
|
383
|
+
/////////////////////////////////////////////////////////////////////////
|
|
384
|
+
|
|
385
|
+
Signature alpha_sig = "alpha($color)";
|
|
386
|
+
Signature opacity_sig = "opacity($color)";
|
|
387
|
+
BUILT_IN(alpha)
|
|
388
|
+
{
|
|
389
|
+
String_Constant* ie_kwd = Cast<String_Constant>(env["$color"]);
|
|
390
|
+
if (ie_kwd) {
|
|
391
|
+
return SASS_MEMORY_NEW(String_Quoted, pstate, "alpha(" + ie_kwd->value() + ")");
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
// CSS3 filter function overload: pass literal through directly
|
|
395
|
+
Number* amount = Cast<Number>(env["$color"]);
|
|
396
|
+
if (amount) {
|
|
397
|
+
return SASS_MEMORY_NEW(String_Quoted, pstate, "opacity(" + amount->to_string(ctx.c_options) + ")");
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
return SASS_MEMORY_NEW(Number, pstate, ARG("$color", Color)->a());
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
Signature opacify_sig = "opacify($color, $amount)";
|
|
404
|
+
Signature fade_in_sig = "fade-in($color, $amount)";
|
|
405
|
+
BUILT_IN(opacify)
|
|
406
|
+
{
|
|
407
|
+
Color* col = ARG("$color", Color);
|
|
408
|
+
double amount = DARG_U_FACT("$amount");
|
|
409
|
+
Color_Obj copy = SASS_MEMORY_COPY(col);
|
|
410
|
+
copy->a(clip(col->a() + amount, 0.0, 1.0));
|
|
411
|
+
return copy.detach();
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
Signature transparentize_sig = "transparentize($color, $amount)";
|
|
415
|
+
Signature fade_out_sig = "fade-out($color, $amount)";
|
|
416
|
+
BUILT_IN(transparentize)
|
|
417
|
+
{
|
|
418
|
+
Color* col = ARG("$color", Color);
|
|
419
|
+
double amount = DARG_U_FACT("$amount");
|
|
420
|
+
Color_Obj copy = SASS_MEMORY_COPY(col);
|
|
421
|
+
copy->a(std::max(col->a() - amount, 0.0));
|
|
422
|
+
return copy.detach();
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
////////////////////////
|
|
426
|
+
// OTHER COLOR FUNCTIONS
|
|
427
|
+
////////////////////////
|
|
428
|
+
|
|
429
|
+
Signature adjust_color_sig = "adjust-color($color, $red: false, $green: false, $blue: false, $hue: false, $saturation: false, $lightness: false, $alpha: false)";
|
|
430
|
+
BUILT_IN(adjust_color)
|
|
431
|
+
{
|
|
432
|
+
Color* col = ARG("$color", Color);
|
|
433
|
+
Number* r = Cast<Number>(env["$red"]);
|
|
434
|
+
Number* g = Cast<Number>(env["$green"]);
|
|
435
|
+
Number* b = Cast<Number>(env["$blue"]);
|
|
436
|
+
Number* h = Cast<Number>(env["$hue"]);
|
|
437
|
+
Number* s = Cast<Number>(env["$saturation"]);
|
|
438
|
+
Number* l = Cast<Number>(env["$lightness"]);
|
|
439
|
+
Number* a = Cast<Number>(env["$alpha"]);
|
|
440
|
+
|
|
441
|
+
bool rgb = r || g || b;
|
|
442
|
+
bool hsl = h || s || l;
|
|
443
|
+
|
|
444
|
+
if (rgb && hsl) {
|
|
445
|
+
error("Cannot specify HSL and RGB values for a color at the same time for `adjust-color'", pstate, traces);
|
|
446
|
+
}
|
|
447
|
+
else if (rgb) {
|
|
448
|
+
Color_RGBA_Obj c = col->copyAsRGBA();
|
|
449
|
+
if (r) c->r(c->r() + DARG_R_BYTE("$red"));
|
|
450
|
+
if (g) c->g(c->g() + DARG_R_BYTE("$green"));
|
|
451
|
+
if (b) c->b(c->b() + DARG_R_BYTE("$blue"));
|
|
452
|
+
if (a) c->a(c->a() + DARG_R_FACT("$alpha"));
|
|
453
|
+
return c.detach();
|
|
454
|
+
}
|
|
455
|
+
else if (hsl) {
|
|
456
|
+
Color_HSLA_Obj c = col->copyAsHSLA();
|
|
457
|
+
if (h) c->h(c->h() + absmod(h->value(), 360.0));
|
|
458
|
+
if (s) c->s(c->s() + DARG_R_PRCT("$saturation"));
|
|
459
|
+
if (l) c->l(c->l() + DARG_R_PRCT("$lightness"));
|
|
460
|
+
if (a) c->a(c->a() + DARG_R_FACT("$alpha"));
|
|
461
|
+
return c.detach();
|
|
462
|
+
}
|
|
463
|
+
else if (a) {
|
|
464
|
+
Color_Obj c = SASS_MEMORY_COPY(col);
|
|
465
|
+
c->a(c->a() + DARG_R_FACT("$alpha"));
|
|
466
|
+
c->a(clip(c->a(), 0.0, 1.0));
|
|
467
|
+
return c.detach();
|
|
468
|
+
}
|
|
469
|
+
error("not enough arguments for `adjust-color'", pstate, traces);
|
|
470
|
+
// unreachable
|
|
471
|
+
return col;
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
Signature scale_color_sig = "scale-color($color, $red: false, $green: false, $blue: false, $hue: false, $saturation: false, $lightness: false, $alpha: false)";
|
|
475
|
+
BUILT_IN(scale_color)
|
|
476
|
+
{
|
|
477
|
+
Color* col = ARG("$color", Color);
|
|
478
|
+
Number* r = Cast<Number>(env["$red"]);
|
|
479
|
+
Number* g = Cast<Number>(env["$green"]);
|
|
480
|
+
Number* b = Cast<Number>(env["$blue"]);
|
|
481
|
+
Number* h = Cast<Number>(env["$hue"]);
|
|
482
|
+
Number* s = Cast<Number>(env["$saturation"]);
|
|
483
|
+
Number* l = Cast<Number>(env["$lightness"]);
|
|
484
|
+
Number* a = Cast<Number>(env["$alpha"]);
|
|
485
|
+
|
|
486
|
+
bool rgb = r || g || b;
|
|
487
|
+
bool hsl = h || s || l;
|
|
488
|
+
|
|
489
|
+
if (rgb && hsl) {
|
|
490
|
+
error("Cannot specify HSL and RGB values for a color at the same time for `scale-color'", pstate, traces);
|
|
491
|
+
}
|
|
492
|
+
else if (rgb) {
|
|
493
|
+
Color_RGBA_Obj c = col->copyAsRGBA();
|
|
494
|
+
double rscale = (r ? DARG_R_PRCT("$red") : 0.0) / 100.0;
|
|
495
|
+
double gscale = (g ? DARG_R_PRCT("$green") : 0.0) / 100.0;
|
|
496
|
+
double bscale = (b ? DARG_R_PRCT("$blue") : 0.0) / 100.0;
|
|
497
|
+
double ascale = (a ? DARG_R_PRCT("$alpha") : 0.0) / 100.0;
|
|
498
|
+
if (rscale) c->r(c->r() + rscale * (rscale > 0.0 ? 255.0 - c->r() : c->r()));
|
|
499
|
+
if (gscale) c->g(c->g() + gscale * (gscale > 0.0 ? 255.0 - c->g() : c->g()));
|
|
500
|
+
if (bscale) c->b(c->b() + bscale * (bscale > 0.0 ? 255.0 - c->b() : c->b()));
|
|
501
|
+
if (ascale) c->a(c->a() + ascale * (ascale > 0.0 ? 1.0 - c->a() : c->a()));
|
|
502
|
+
return c.detach();
|
|
503
|
+
}
|
|
504
|
+
else if (hsl) {
|
|
505
|
+
Color_HSLA_Obj c = col->copyAsHSLA();
|
|
506
|
+
double hscale = (h ? DARG_R_PRCT("$hue") : 0.0) / 100.0;
|
|
507
|
+
double sscale = (s ? DARG_R_PRCT("$saturation") : 0.0) / 100.0;
|
|
508
|
+
double lscale = (l ? DARG_R_PRCT("$lightness") : 0.0) / 100.0;
|
|
509
|
+
double ascale = (a ? DARG_R_PRCT("$alpha") : 0.0) / 100.0;
|
|
510
|
+
if (hscale) c->h(c->h() + hscale * (hscale > 0.0 ? 360.0 - c->h() : c->h()));
|
|
511
|
+
if (sscale) c->s(c->s() + sscale * (sscale > 0.0 ? 100.0 - c->s() : c->s()));
|
|
512
|
+
if (lscale) c->l(c->l() + lscale * (lscale > 0.0 ? 100.0 - c->l() : c->l()));
|
|
513
|
+
if (ascale) c->a(c->a() + ascale * (ascale > 0.0 ? 1.0 - c->a() : c->a()));
|
|
514
|
+
return c.detach();
|
|
515
|
+
}
|
|
516
|
+
else if (a) {
|
|
517
|
+
Color_Obj c = SASS_MEMORY_COPY(col);
|
|
518
|
+
double ascale = DARG_R_PRCT("$alpha") / 100.0;
|
|
519
|
+
c->a(c->a() + ascale * (ascale > 0.0 ? 1.0 - c->a() : c->a()));
|
|
520
|
+
c->a(clip(c->a(), 0.0, 1.0));
|
|
521
|
+
return c.detach();
|
|
522
|
+
}
|
|
523
|
+
error("not enough arguments for `scale-color'", pstate, traces);
|
|
524
|
+
// unreachable
|
|
525
|
+
return col;
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
Signature change_color_sig = "change-color($color, $red: false, $green: false, $blue: false, $hue: false, $saturation: false, $lightness: false, $alpha: false)";
|
|
529
|
+
BUILT_IN(change_color)
|
|
530
|
+
{
|
|
531
|
+
Color* col = ARG("$color", Color);
|
|
532
|
+
Number* r = Cast<Number>(env["$red"]);
|
|
533
|
+
Number* g = Cast<Number>(env["$green"]);
|
|
534
|
+
Number* b = Cast<Number>(env["$blue"]);
|
|
535
|
+
Number* h = Cast<Number>(env["$hue"]);
|
|
536
|
+
Number* s = Cast<Number>(env["$saturation"]);
|
|
537
|
+
Number* l = Cast<Number>(env["$lightness"]);
|
|
538
|
+
Number* a = Cast<Number>(env["$alpha"]);
|
|
539
|
+
|
|
540
|
+
bool rgb = r || g || b;
|
|
541
|
+
bool hsl = h || s || l;
|
|
542
|
+
|
|
543
|
+
if (rgb && hsl) {
|
|
544
|
+
error("Cannot specify HSL and RGB values for a color at the same time for `change-color'", pstate, traces);
|
|
545
|
+
}
|
|
546
|
+
else if (rgb) {
|
|
547
|
+
Color_RGBA_Obj c = col->copyAsRGBA();
|
|
548
|
+
if (r) c->r(DARG_U_BYTE("$red"));
|
|
549
|
+
if (g) c->g(DARG_U_BYTE("$green"));
|
|
550
|
+
if (b) c->b(DARG_U_BYTE("$blue"));
|
|
551
|
+
if (a) c->a(DARG_U_FACT("$alpha"));
|
|
552
|
+
return c.detach();
|
|
553
|
+
}
|
|
554
|
+
else if (hsl) {
|
|
555
|
+
Color_HSLA_Obj c = col->copyAsHSLA();
|
|
556
|
+
if (h) c->h(absmod(h->value(), 360.0));
|
|
557
|
+
if (s) c->s(DARG_U_PRCT("$saturation"));
|
|
558
|
+
if (l) c->l(DARG_U_PRCT("$lightness"));
|
|
559
|
+
if (a) c->a(DARG_U_FACT("$alpha"));
|
|
560
|
+
return c.detach();
|
|
561
|
+
}
|
|
562
|
+
else if (a) {
|
|
563
|
+
Color_Obj c = SASS_MEMORY_COPY(col);
|
|
564
|
+
c->a(clip(DARG_U_FACT("$alpha"), 0.0, 1.0));
|
|
565
|
+
return c.detach();
|
|
566
|
+
}
|
|
567
|
+
error("not enough arguments for `change-color'", pstate, traces);
|
|
568
|
+
// unreachable
|
|
569
|
+
return col;
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
Signature ie_hex_str_sig = "ie-hex-str($color)";
|
|
573
|
+
BUILT_IN(ie_hex_str)
|
|
574
|
+
{
|
|
575
|
+
Color* col = ARG("$color", Color);
|
|
576
|
+
Color_RGBA_Obj c = col->toRGBA();
|
|
577
|
+
double r = clip(c->r(), 0.0, 255.0);
|
|
578
|
+
double g = clip(c->g(), 0.0, 255.0);
|
|
579
|
+
double b = clip(c->b(), 0.0, 255.0);
|
|
580
|
+
double a = clip(c->a(), 0.0, 1.0) * 255.0;
|
|
581
|
+
|
|
582
|
+
sass::ostream ss;
|
|
583
|
+
ss << '#' << std::setw(2) << std::setfill('0');
|
|
584
|
+
ss << std::hex << std::setw(2) << static_cast<unsigned long>(Sass::round(a, ctx.c_options.precision));
|
|
585
|
+
ss << std::hex << std::setw(2) << static_cast<unsigned long>(Sass::round(r, ctx.c_options.precision));
|
|
586
|
+
ss << std::hex << std::setw(2) << static_cast<unsigned long>(Sass::round(g, ctx.c_options.precision));
|
|
587
|
+
ss << std::hex << std::setw(2) << static_cast<unsigned long>(Sass::round(b, ctx.c_options.precision));
|
|
588
|
+
|
|
589
|
+
sass::string result = ss.str();
|
|
590
|
+
Util::ascii_str_toupper(&result);
|
|
591
|
+
return SASS_MEMORY_NEW(String_Quoted, pstate, result);
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
}
|