var-colors 1.0.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.
- package/LICENSE.txt +21 -0
- package/README.md +74 -0
- package/package.json +31 -0
- package/scss/_config.scss +16 -0
- package/scss/_constants.scss +26 -0
- package/scss/_functions.scss +720 -0
- package/scss/_maps.scss +592 -0
- package/scss/index.scss +106 -0
|
@@ -0,0 +1,720 @@
|
|
|
1
|
+
@use "sass:meta";
|
|
2
|
+
@use "sass:math";
|
|
3
|
+
@use "sass:list";
|
|
4
|
+
@use "sass:map";
|
|
5
|
+
@use "sass:string";
|
|
6
|
+
@use "./_constants" as *;
|
|
7
|
+
@use "./_maps" as *;
|
|
8
|
+
|
|
9
|
+
// 1.Configuration validations
|
|
10
|
+
@function get-valid-colors($colors) {
|
|
11
|
+
$valid-colors: ();
|
|
12
|
+
@if meta.type-of($colors) == "list" {
|
|
13
|
+
@each $key in $colors {
|
|
14
|
+
@if meta.type-of($key) == "string" {
|
|
15
|
+
@if list.index($preset-colors-keys, $key) {
|
|
16
|
+
$valid-colors: list.append($valid-colors, $key);
|
|
17
|
+
} @else {
|
|
18
|
+
@warn For preset colors, only keys from the list "#{$preset-colors-keys}" are allowed,
|
|
19
|
+
the color with the invalid key "#{$key}" was ignored;
|
|
20
|
+
}
|
|
21
|
+
} @else {
|
|
22
|
+
@warn The preset color key must be of type "string",
|
|
23
|
+
the key "#{$key}" has an invalid type "#{meta.type-of($key)}",
|
|
24
|
+
the color was ignored;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
} @else {
|
|
28
|
+
@warn The value of the variable "$colors" must be of type "list",
|
|
29
|
+
value "#{$colors}" with invalid type "#{meta.type-of($colors)}" was ignored;
|
|
30
|
+
}
|
|
31
|
+
@return $valid-colors;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
@function get-valid-levels($levels) {
|
|
35
|
+
$valid-levels: ();
|
|
36
|
+
@if meta.type-of($levels) == "list" {
|
|
37
|
+
$wrong-levels: ();
|
|
38
|
+
$wrong-type-levels: ();
|
|
39
|
+
@each $level in $levels {
|
|
40
|
+
@if meta.type-of($level) == "number" {
|
|
41
|
+
@if $level % 25 == 0 {
|
|
42
|
+
$valid-levels: list.append($valid-levels, $level);
|
|
43
|
+
} @else {
|
|
44
|
+
$wrong-levels: list.append($wrong-levels, $level);
|
|
45
|
+
}
|
|
46
|
+
} @else {
|
|
47
|
+
$wrong-type-levels: list.append($wrong-type-levels, $level);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
@if list.length($wrong-type-levels) > 0 {
|
|
51
|
+
@warn The levels must be of type "number",
|
|
52
|
+
the levels "#{$wrong-type-levels}" with invalid types was ignored;
|
|
53
|
+
}
|
|
54
|
+
@if list.length($wrong-levels) > 0 {
|
|
55
|
+
@warn The levels must be a multiple of 25,
|
|
56
|
+
the levels "#{$wrong-levels}" with invalid values was ignored;
|
|
57
|
+
}
|
|
58
|
+
} @else {
|
|
59
|
+
@warn The value of "$levels" must be of type "list",
|
|
60
|
+
value "#{$levels}" with invalid type "#{meta.type-of($levels)}" was ignored;
|
|
61
|
+
}
|
|
62
|
+
@return $valid-levels;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
@function get-valid-levels-step($levels-step, $levels) {
|
|
66
|
+
@if list.length($levels) == 0 {
|
|
67
|
+
@if meta.type-of($levels-step) == "number" {
|
|
68
|
+
@if not list.index($valid-levels-steps, $levels-step) {
|
|
69
|
+
@warn For "$levels-step" only values from the list "#{$valid-levels-steps}" are allowed,
|
|
70
|
+
the value "#{$levels-step}" was ignored;
|
|
71
|
+
$levels-step: 50;
|
|
72
|
+
}
|
|
73
|
+
} @else {
|
|
74
|
+
@warn The value of "$levels-step" must be of type "number",
|
|
75
|
+
value "#{$levels-step}" with invalid type "#{meta.type-of($levels-step)}" was ignored;
|
|
76
|
+
$levels-step: 50;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
@return $levels-step;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
@function get-valid-consistent-chroma($consistent-chroma) {
|
|
83
|
+
@if meta.type-of($consistent-chroma) != "bool" {
|
|
84
|
+
@warn The value of "$consistent-chroma" must be of type "bool",
|
|
85
|
+
value "#{$consistent-chroma}" with invalid type "#{meta.type-of($consistent-chroma)}" was ignored;
|
|
86
|
+
$consistent-chroma: false;
|
|
87
|
+
}
|
|
88
|
+
@return $consistent-chroma;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
@function get-valid-gamut($gamut) {
|
|
92
|
+
@if meta.type-of($gamut) == "string" {
|
|
93
|
+
@if not list.index($valid-gamuts, $gamut) {
|
|
94
|
+
@warn For "$gamut" only values from the list "#{$valid-gamuts}" are allowed,
|
|
95
|
+
the value "#{$gamut}" was ignored;
|
|
96
|
+
$gamut: "srgb";
|
|
97
|
+
}
|
|
98
|
+
} @else {
|
|
99
|
+
@warn The value of "$gamut" must be of type "string",
|
|
100
|
+
value "#{$gamut}" with invalid type "#{meta.type-of($gamut)}" was ignored;
|
|
101
|
+
$gamut: "srgb";
|
|
102
|
+
}
|
|
103
|
+
@return $gamut;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
@function get-valid-prefix($prefix) {
|
|
107
|
+
@if meta.type-of($prefix) != "string" and meta.type-of($prefix) != "null" {
|
|
108
|
+
@warn The value of "$prefix" must be of type "string" or "null",
|
|
109
|
+
value "#{$prefix}" with invalid type "#{meta.type-of($prefix)}" was ignored;
|
|
110
|
+
$prefix: null;
|
|
111
|
+
}
|
|
112
|
+
@return $prefix;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
@function get-valid-root-rule($root-rule) {
|
|
116
|
+
@if meta.type-of($root-rule) != "bool" {
|
|
117
|
+
@warn The value of "$root-rule" must be of type "bool",
|
|
118
|
+
value "#{$root-rule}" with invalid type "#{meta.type-of($root-rule)}" was ignored;
|
|
119
|
+
$root-rule: false;
|
|
120
|
+
}
|
|
121
|
+
@return $root-rule;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// 2.Getting preset colors by the configuration
|
|
125
|
+
@function get-preset-colors-by-keys($color-keys) {
|
|
126
|
+
$colors: ();
|
|
127
|
+
@each $key in $color-keys {
|
|
128
|
+
$value: map.get($preset-colors, $key);
|
|
129
|
+
$colors: map.merge(
|
|
130
|
+
$colors,
|
|
131
|
+
(
|
|
132
|
+
$key: $value,
|
|
133
|
+
)
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
@return $colors;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// 3.Creating a list of levels
|
|
140
|
+
@function get-levels-by-config($levels, $levels-step) {
|
|
141
|
+
@if (not $levels or list.length($levels) == 0) and $levels-step {
|
|
142
|
+
$levels: ();
|
|
143
|
+
$palette-steps: calc(1000 / $levels-step - 1);
|
|
144
|
+
@for $i from 1 through $palette-steps {
|
|
145
|
+
$levels: list.append($levels, $i * $levels-step);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
@return $levels;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// 4.Setting the max-chroma value for preset colors
|
|
152
|
+
@function get-preset-colors-chroma($colors, $consistent-chroma, $gamut) {
|
|
153
|
+
$preset-colors-with-max-chroma: ();
|
|
154
|
+
@each $key, $color-data in $colors {
|
|
155
|
+
@if $consistent-chroma {
|
|
156
|
+
$color-data-without-max-chroma-lightness: map.remove(
|
|
157
|
+
$color-data,
|
|
158
|
+
"max-chroma-lightness"
|
|
159
|
+
);
|
|
160
|
+
$color-data: map.merge(
|
|
161
|
+
$color-data-without-max-chroma-lightness,
|
|
162
|
+
(
|
|
163
|
+
max-chroma: "consistent",
|
|
164
|
+
)
|
|
165
|
+
);
|
|
166
|
+
} @else {
|
|
167
|
+
$max-chroma: map.get($color-data, "max-chroma", $gamut);
|
|
168
|
+
$color-data: map.merge(
|
|
169
|
+
$color-data,
|
|
170
|
+
(
|
|
171
|
+
max-chroma: $max-chroma,
|
|
172
|
+
)
|
|
173
|
+
);
|
|
174
|
+
}
|
|
175
|
+
$preset-colors-with-max-chroma: map.merge(
|
|
176
|
+
$preset-colors-with-max-chroma,
|
|
177
|
+
(
|
|
178
|
+
$key: $color-data,
|
|
179
|
+
)
|
|
180
|
+
);
|
|
181
|
+
}
|
|
182
|
+
@return $preset-colors-with-max-chroma;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
@function create-variable-hue($key, $color-data, $prefix) {
|
|
186
|
+
@if $prefix {
|
|
187
|
+
$color-data: map.merge(
|
|
188
|
+
$color-data,
|
|
189
|
+
(
|
|
190
|
+
hue: var(--#{$prefix}-#{$color-key}-hue),
|
|
191
|
+
)
|
|
192
|
+
);
|
|
193
|
+
} @else {
|
|
194
|
+
$color-data: map.merge(
|
|
195
|
+
$color-data,
|
|
196
|
+
(
|
|
197
|
+
hue: var(--#{$color-key}-hue),
|
|
198
|
+
)
|
|
199
|
+
);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
@function get-level-by-lightness($darkness-levels, $lightness) {
|
|
204
|
+
$darkness-level: 0;
|
|
205
|
+
@each $level, $color-data in $darkness-levels {
|
|
206
|
+
$min-lightness: map.get($color-data, "min-lightness");
|
|
207
|
+
$max-lightness: map.get($color-data, "max-lightness");
|
|
208
|
+
@if $lightness >= $min-lightness and $lightness < $max-lightness {
|
|
209
|
+
$darkness-level: $level;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
@return $darkness-level;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
@function get-color-max-chroma-level($color-data, $gamut) {
|
|
216
|
+
$max-chroma-lightness-data: map.get($color-data, max-chroma-lightness);
|
|
217
|
+
$max-chroma-lightness: null;
|
|
218
|
+
@if meta.type-of($max-chroma-lightness-data) == "map" {
|
|
219
|
+
$max-chroma-lightness: map.get($max-chroma-lightness-data, $gamut);
|
|
220
|
+
} @else if meta.type-of($max-chroma-lightness-data) == "number" {
|
|
221
|
+
$max-chroma-lightness: $max-chroma-lightness-data;
|
|
222
|
+
}
|
|
223
|
+
$max-chroma-level: get-level-by-lightness(
|
|
224
|
+
$darkness-levels,
|
|
225
|
+
$max-chroma-lightness
|
|
226
|
+
);
|
|
227
|
+
@return $max-chroma-level;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
@function get-lightness-by-level($level) {
|
|
231
|
+
@return map.get($darkness-levels, $level, "lightness");
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
@function get-consistent-chroma-by-level($level) {
|
|
235
|
+
@return map.get($darkness-levels, $level, "consistent-chroma");
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
@function get-regular-chroma-by-level($level, $max-chroma-level, $max-chroma) {
|
|
239
|
+
$chroma: null;
|
|
240
|
+
@if $level == $max-chroma-level {
|
|
241
|
+
$chroma: $max-chroma;
|
|
242
|
+
} @else if $level < $max-chroma-level {
|
|
243
|
+
$chroma: math.div($level, $max-chroma-level) * $max-chroma;
|
|
244
|
+
} @else if $level > $max-chroma-level {
|
|
245
|
+
$chroma: math.div(1000 - $level, 1000 - $max-chroma-level) * $max-chroma;
|
|
246
|
+
}
|
|
247
|
+
@return $chroma;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
@function get-shade-chroma($color-data, $level, $max-chroma-level) {
|
|
251
|
+
$hue: map.get($color-data, "hue");
|
|
252
|
+
$max-chroma: map.get($color-data, "max-chroma");
|
|
253
|
+
$chroma: null;
|
|
254
|
+
@if $hue == none {
|
|
255
|
+
$chroma: 0;
|
|
256
|
+
} @else if $max-chroma == "consistent" {
|
|
257
|
+
$chroma: get-consistent-chroma-by-level($level);
|
|
258
|
+
} @else if $max-chroma and meta.type-of($max-chroma) == number {
|
|
259
|
+
$chroma: get-regular-chroma-by-level(
|
|
260
|
+
$level,
|
|
261
|
+
$max-chroma-level,
|
|
262
|
+
$max-chroma
|
|
263
|
+
);
|
|
264
|
+
} @else {
|
|
265
|
+
$chroma: get-regular-chroma-by-level(
|
|
266
|
+
$level,
|
|
267
|
+
$max-chroma-level,
|
|
268
|
+
$default-max-chroma
|
|
269
|
+
);
|
|
270
|
+
}
|
|
271
|
+
@return $chroma;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
@function get-leading-zeros-level-key($level) {
|
|
275
|
+
$leading-zeros-level: $level;
|
|
276
|
+
@if ($level < 100) {
|
|
277
|
+
$leading-zeros-level: "0" + $leading-zeros-level;
|
|
278
|
+
}
|
|
279
|
+
@return $leading-zeros-level;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
@function round-to($number, $decimals: 0) {
|
|
283
|
+
$multiplier: math.pow(10, $decimals);
|
|
284
|
+
@return math.div(math.round($number * $multiplier), $multiplier);
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
@function get-oklch-value($lightness, $chroma, $hue) {
|
|
288
|
+
$oklch-value: "oklch(" + round-to($lightness, 4) + " " +
|
|
289
|
+
round-to($chroma, 4) + " " + $hue + ")";
|
|
290
|
+
@return $oklch-value;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
@function create-palette-from-color(
|
|
294
|
+
$color-key,
|
|
295
|
+
$color-data,
|
|
296
|
+
$levels,
|
|
297
|
+
$gamut,
|
|
298
|
+
$prefix
|
|
299
|
+
) {
|
|
300
|
+
$hue: map.get($color-data, "hue");
|
|
301
|
+
$max-chroma: map.get($color-data, "max-chroma");
|
|
302
|
+
$max-chroma-level: null;
|
|
303
|
+
$max-chroma-lightness: null;
|
|
304
|
+
@if meta.type-of($hue) == number and map.get($color-data, "var-hue") == true {
|
|
305
|
+
$color-data: create-variable-hue($color-key, $color-data, $prefix);
|
|
306
|
+
}
|
|
307
|
+
@if $max-chroma != "consistent" {
|
|
308
|
+
$max-chroma-level: get-color-max-chroma-level($color-data, $gamut);
|
|
309
|
+
}
|
|
310
|
+
$colors-palette: ();
|
|
311
|
+
@each $level in $levels {
|
|
312
|
+
$color-name: $color-key + "-" + get-leading-zeros-level-key($level);
|
|
313
|
+
$lightness: get-lightness-by-level($level);
|
|
314
|
+
$chroma: get-shade-chroma($color-data, $level, $max-chroma-level);
|
|
315
|
+
$color: (
|
|
316
|
+
$color-name: get-oklch-value($lightness, $chroma, $hue),
|
|
317
|
+
);
|
|
318
|
+
$colors-palette: map.merge($colors-palette, $color);
|
|
319
|
+
}
|
|
320
|
+
@return $colors-palette;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
// 5.Generating a palette of shades of preset colors
|
|
324
|
+
@function get-preset-colors-palette($colors, $levels, $gamut, $prefix) {
|
|
325
|
+
$preset-colors-palette: ();
|
|
326
|
+
@each $color-key, $color-data in $colors {
|
|
327
|
+
$current-color-palette: create-palette-from-color(
|
|
328
|
+
$color-key,
|
|
329
|
+
$color-data,
|
|
330
|
+
$levels,
|
|
331
|
+
$gamut,
|
|
332
|
+
$prefix
|
|
333
|
+
);
|
|
334
|
+
$preset-colors-palette: map.merge(
|
|
335
|
+
$preset-colors-palette,
|
|
336
|
+
$current-color-palette
|
|
337
|
+
);
|
|
338
|
+
}
|
|
339
|
+
@return $preset-colors-palette;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
@function validate-hue($color-key, $color-data) {
|
|
343
|
+
$hue: map.get($color-data, "hue");
|
|
344
|
+
$var-hue: map.get($color-data, "var-hue");
|
|
345
|
+
@if list.index($preset-colors-keys, $color-key + "") {
|
|
346
|
+
@warn Using names from the list of preset colors
|
|
347
|
+
"#{$preset-colors-keys}" to name the custom color
|
|
348
|
+
"#{$color-key}" is invalid, the custom color "#{$color-key}" has been ignored;
|
|
349
|
+
@return false;
|
|
350
|
+
} @else {
|
|
351
|
+
@if meta.type-of($hue) == number {
|
|
352
|
+
@return true;
|
|
353
|
+
} @else if meta.type-of($hue) == string {
|
|
354
|
+
@if list.index($preset-colors-keys, $hue) or $hue == "none" {
|
|
355
|
+
@return true;
|
|
356
|
+
} @else if string.index($hue, "var(") and string.index($hue, ")") {
|
|
357
|
+
@if $var-hue == true {
|
|
358
|
+
@return true;
|
|
359
|
+
} @else {
|
|
360
|
+
@warn Using the "#{$hue}" value for the "hue" property
|
|
361
|
+
of the custom "#{$color-key}" color without the "var-hue: true" flag is invalid,
|
|
362
|
+
the custom "#{$color-key}" color was ignored;
|
|
363
|
+
@return false;
|
|
364
|
+
}
|
|
365
|
+
} @else {
|
|
366
|
+
@warn Using the $hue value for the "hue" property of the
|
|
367
|
+
custom "#{$color-key}" color is invalid, the custom "#{$color-key}" color was ignored;
|
|
368
|
+
@return false;
|
|
369
|
+
}
|
|
370
|
+
} @else if meta.type-of($hue) == calculation {
|
|
371
|
+
@if $var-hue == true {
|
|
372
|
+
@return true;
|
|
373
|
+
} @else {
|
|
374
|
+
@warn Using the "#{$hue}" value for the "hue" property
|
|
375
|
+
of the custom "#{$color-key}" color without the "var-hue: true" flag is invalid,
|
|
376
|
+
the custom "#{$color-key}" color was ignored;
|
|
377
|
+
@return false;
|
|
378
|
+
}
|
|
379
|
+
} @else {
|
|
380
|
+
@warn The absence of the "hue" property \or the use of the "null" value for
|
|
381
|
+
the "hue" property of the custom color "#{$color-key}" is invalid, the custom color "#{$color-key}" was ignored;
|
|
382
|
+
@return false;
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
// 6.Filtering custom colors by valid hue
|
|
388
|
+
@function filter-colors-by-valid-hue($custom-colors) {
|
|
389
|
+
$valid-custom-colors: ();
|
|
390
|
+
@each $key, $value in $custom-colors {
|
|
391
|
+
@if validate-hue($key, $value) {
|
|
392
|
+
$valid-custom-colors: map.merge(
|
|
393
|
+
$valid-custom-colors,
|
|
394
|
+
(
|
|
395
|
+
$key: $value,
|
|
396
|
+
)
|
|
397
|
+
);
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
@return $valid-custom-colors;
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
// 7.Converting string custom colors hue values matching the names of preset colors to numeric values
|
|
404
|
+
@function convert-custom-colors-string-hues-to-numbers($custom-colors) {
|
|
405
|
+
$colors: ();
|
|
406
|
+
@each $key, $value in $custom-colors {
|
|
407
|
+
$hue: map.get($value, "hue");
|
|
408
|
+
@if meta.type-of($hue) == string and list.index($preset-colors-keys, $hue) {
|
|
409
|
+
$hue-number: map.get($preset-colors, $hue, "hue");
|
|
410
|
+
$value: map.merge(
|
|
411
|
+
$value,
|
|
412
|
+
(
|
|
413
|
+
hue: $hue-number,
|
|
414
|
+
)
|
|
415
|
+
);
|
|
416
|
+
}
|
|
417
|
+
$colors: map.merge(
|
|
418
|
+
$colors,
|
|
419
|
+
(
|
|
420
|
+
$key: $value,
|
|
421
|
+
)
|
|
422
|
+
);
|
|
423
|
+
}
|
|
424
|
+
@return $colors;
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
@function get-preset-color-data-by-color-key($color-key) {
|
|
428
|
+
@return map.get($preset-colors, $color-key);
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
@function get-preset-color-data-by-hue($hue) {
|
|
432
|
+
@if meta.type-of($hue) == number {
|
|
433
|
+
$hue: $hue % 360;
|
|
434
|
+
} @else if $hue == "none" {
|
|
435
|
+
@return get-preset-color-data-by-color-key("grey");
|
|
436
|
+
}
|
|
437
|
+
$preset-color-index: list.index($preset-colors-hues, $hue);
|
|
438
|
+
@if $preset-color-index {
|
|
439
|
+
$color-key: list.nth($preset-colors-keys, $preset-color-index);
|
|
440
|
+
@return map.get($preset-colors, $color-key);
|
|
441
|
+
}
|
|
442
|
+
@return null;
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
// 8.Setting the max-chroma value for custom colors
|
|
446
|
+
@function get-custom-color-chroma($custom-colors, $gamut) {
|
|
447
|
+
$colors: ();
|
|
448
|
+
@each $key, $value in $custom-colors {
|
|
449
|
+
$hue: map.get($value, "hue");
|
|
450
|
+
@if meta.type-of($hue) == "number" {
|
|
451
|
+
$hue: $hue % 360;
|
|
452
|
+
}
|
|
453
|
+
$max-chroma: map.get($value, "max-chroma");
|
|
454
|
+
@if $max-chroma == "consistent" {
|
|
455
|
+
$no-lightness-value: map.remove($value, "max-chroma-lightness");
|
|
456
|
+
$value: map.merge(
|
|
457
|
+
$no-lightness-value,
|
|
458
|
+
(
|
|
459
|
+
max-chroma: "consistent",
|
|
460
|
+
)
|
|
461
|
+
);
|
|
462
|
+
} @else if list.index($preset-colors-hues, $hue) and not $max-chroma {
|
|
463
|
+
$preset-color: get-preset-color-data-by-hue($hue);
|
|
464
|
+
$max-chroma: map.get($preset-color, "max-chroma", $gamut);
|
|
465
|
+
$value: map.merge(
|
|
466
|
+
$value,
|
|
467
|
+
(
|
|
468
|
+
max-chroma: $max-chroma,
|
|
469
|
+
)
|
|
470
|
+
);
|
|
471
|
+
} @else if $hue == "none" {
|
|
472
|
+
$no-lightness-value: map.remove($value, "max-chroma-lightness");
|
|
473
|
+
$value: map.merge(
|
|
474
|
+
$no-lightness-value,
|
|
475
|
+
(
|
|
476
|
+
max-chroma: 0,
|
|
477
|
+
)
|
|
478
|
+
);
|
|
479
|
+
} @else if $max-chroma and meta.type-of($max-chroma) == number {
|
|
480
|
+
@if $max-chroma >= 0 and $max-chroma <= 0.4 {
|
|
481
|
+
$value: $value;
|
|
482
|
+
} @else if $max-chroma < 0 {
|
|
483
|
+
@warn 'Using the negative value of the "max-chroma" property of the custom color "#{$key}" does not make sense, the value has been changed to "0"';
|
|
484
|
+
$value: map.merge(
|
|
485
|
+
$value,
|
|
486
|
+
(
|
|
487
|
+
max-chroma: 0,
|
|
488
|
+
)
|
|
489
|
+
);
|
|
490
|
+
} @else {
|
|
491
|
+
@warn 'Using a value greater than 0.4 of the "max-chroma" property of the custom color "#{$key}" can lead to unexpected results';
|
|
492
|
+
$value: $value;
|
|
493
|
+
}
|
|
494
|
+
} @else {
|
|
495
|
+
@if $max-chroma {
|
|
496
|
+
@warn 'Non-negative numeric values should be used for the "max-chroma" property of the custom color, the value "#{$max-chroma}" of the color "#{$key}" was ignored';
|
|
497
|
+
}
|
|
498
|
+
$value: map.merge(
|
|
499
|
+
$value,
|
|
500
|
+
(
|
|
501
|
+
max-chroma: $default-max-chroma,
|
|
502
|
+
)
|
|
503
|
+
);
|
|
504
|
+
}
|
|
505
|
+
$colors: map.merge(
|
|
506
|
+
$colors,
|
|
507
|
+
(
|
|
508
|
+
$key: $value,
|
|
509
|
+
)
|
|
510
|
+
);
|
|
511
|
+
}
|
|
512
|
+
@return $colors;
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
// 9.Adoption of max-chroma-lightness values to the range from 0 to 1
|
|
516
|
+
@function adopt-max-chroma-lightness($color-key, $color-data) {
|
|
517
|
+
$max-chroma-lightness: map.get($color-data, "max-chroma-lightness");
|
|
518
|
+
@if meta.type-of($max-chroma-lightness) == number {
|
|
519
|
+
@if $max-chroma-lightness < 0 {
|
|
520
|
+
@warn 'The use of negative values for the "max-chroma-lightness" property is not allowed, the value "#{$max-chroma-lightness}" of the color "#{$color-key}" has been converted to the value "0"';
|
|
521
|
+
$color-data: map.merge(
|
|
522
|
+
$color-data,
|
|
523
|
+
(
|
|
524
|
+
max-chroma-lightness: 0,
|
|
525
|
+
)
|
|
526
|
+
);
|
|
527
|
+
} @else if $max-chroma-lightness > 1 {
|
|
528
|
+
@warn 'Using values greater than 1 for the "max-chroma-lightness" property is not allowed, the value "#{$max-chroma-lightness}" of the custom color "#{$color-key}" has been converted to the value "1"';
|
|
529
|
+
$color-data: map.merge(
|
|
530
|
+
$color-data,
|
|
531
|
+
(
|
|
532
|
+
max-chroma-lightness: 1,
|
|
533
|
+
)
|
|
534
|
+
);
|
|
535
|
+
}
|
|
536
|
+
} @else if $max-chroma-lightness {
|
|
537
|
+
$color-data: map.remove($color-data, "max-chroma-lightness");
|
|
538
|
+
@warn 'For the "max-chroma-lightness" property of a custom color values from 0 to 1 should be used, the value "#{$max-chroma-lightness}" of the color "#{$color-key}" was ignored';
|
|
539
|
+
}
|
|
540
|
+
$color: (
|
|
541
|
+
$color-key: $color-data,
|
|
542
|
+
);
|
|
543
|
+
@return $color;
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
@function validate-custom-colors-max-chroma-lightness($custom-colors) {
|
|
547
|
+
$colors: ();
|
|
548
|
+
@each $key, $value in $custom-colors {
|
|
549
|
+
$adopted-color: adopt-max-chroma-lightness($key, $value);
|
|
550
|
+
$colors: map.merge($colors, $adopted-color);
|
|
551
|
+
}
|
|
552
|
+
@return $colors;
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
// 10.Setting the max-chroma-lightness value for custom colors
|
|
556
|
+
@function get-custom-colors-max-chroma-lightness($custom-colors, $gamut) {
|
|
557
|
+
$colors: ();
|
|
558
|
+
@each $key, $value in $custom-colors {
|
|
559
|
+
$hue: map.get($value, "hue");
|
|
560
|
+
$max-chroma: map.get($value, "max-chroma");
|
|
561
|
+
$max-chroma-lightness: map.get($value, "max-chroma-lightness");
|
|
562
|
+
@if $max-chroma != "consistent" and not $max-chroma-lightness {
|
|
563
|
+
$preset-color-data: null;
|
|
564
|
+
@if meta.type-of($hue) == number {
|
|
565
|
+
$preset-color-data: get-preset-color-data-by-hue($hue % 360);
|
|
566
|
+
}
|
|
567
|
+
@if meta.type-of($hue) == string {
|
|
568
|
+
@if $hue == none {
|
|
569
|
+
$preset-color-data: get-preset-color-data-by-color-key("grey");
|
|
570
|
+
} @else {
|
|
571
|
+
$preset-color-data: get-preset-color-data-by-color-key($hue);
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
@if $preset-color-data {
|
|
575
|
+
$preset-max-chroma-lightness: map.get(
|
|
576
|
+
$preset-color-data,
|
|
577
|
+
"max-chroma-lightness",
|
|
578
|
+
$gamut
|
|
579
|
+
);
|
|
580
|
+
$value: map.merge(
|
|
581
|
+
$value,
|
|
582
|
+
(
|
|
583
|
+
max-chroma-lightness: $preset-max-chroma-lightness,
|
|
584
|
+
)
|
|
585
|
+
);
|
|
586
|
+
} @else {
|
|
587
|
+
$value: map.merge(
|
|
588
|
+
$value,
|
|
589
|
+
(
|
|
590
|
+
max-chroma-lightness: $default-max-chroma-lightness,
|
|
591
|
+
)
|
|
592
|
+
);
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
$colors: map.merge(
|
|
596
|
+
$colors,
|
|
597
|
+
(
|
|
598
|
+
$key: $value,
|
|
599
|
+
)
|
|
600
|
+
);
|
|
601
|
+
}
|
|
602
|
+
@return $colors;
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
// 11.Getting a list of dynamic hues
|
|
606
|
+
@function get-dynamic-var-hues($custom-colors, $prefix) {
|
|
607
|
+
$hues: ();
|
|
608
|
+
@each $color-name, $color-data in $custom-colors {
|
|
609
|
+
@if map.get($color-data, "var-hue") == true {
|
|
610
|
+
$hues: map.merge(
|
|
611
|
+
$hues,
|
|
612
|
+
(#{$color-name}-hue: map.get($color-data, "hue"))
|
|
613
|
+
);
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
@return $hues;
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
// 12.Creating a list of dynamic hue values
|
|
620
|
+
@function get-custom-colors-variable-hue($custom-colors, $prefix) {
|
|
621
|
+
$colors: ();
|
|
622
|
+
@each $color-name, $color-data in $custom-colors {
|
|
623
|
+
@if map.get($color-data, "var-hue") == true {
|
|
624
|
+
@if $prefix {
|
|
625
|
+
$color-data: map.merge(
|
|
626
|
+
$color-data,
|
|
627
|
+
(
|
|
628
|
+
hue: var(--#{$prefix}-#{$color-name}-hue),
|
|
629
|
+
)
|
|
630
|
+
);
|
|
631
|
+
} @else {
|
|
632
|
+
$color-data: map.merge(
|
|
633
|
+
$color-data,
|
|
634
|
+
(
|
|
635
|
+
hue: var(--#{$color-name}-hue),
|
|
636
|
+
)
|
|
637
|
+
);
|
|
638
|
+
}
|
|
639
|
+
} @else if
|
|
640
|
+
map.has-key($color-data, "var-hue") and
|
|
641
|
+
map.get($color-data, "var-hue") !=
|
|
642
|
+
false
|
|
643
|
+
{
|
|
644
|
+
@warn 'The color property "var-hue" can only take a boolean value, the value of “#{map.get($color-data, 'var-hue') or 'null'}" for the color "#{$color-name}" was ignored';
|
|
645
|
+
$color-data: map.remove($color-data, "var-hue");
|
|
646
|
+
}
|
|
647
|
+
$colors: map.merge(
|
|
648
|
+
$colors,
|
|
649
|
+
(
|
|
650
|
+
$color-name: $color-data,
|
|
651
|
+
)
|
|
652
|
+
);
|
|
653
|
+
}
|
|
654
|
+
@return $colors;
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
// 13.Generating a palette of shades of custom colors
|
|
658
|
+
@function get-custom-colors-palette($custom-colors, $levels, $gamut, $prefix) {
|
|
659
|
+
$palette: ();
|
|
660
|
+
@each $color-key, $color-data in $custom-colors {
|
|
661
|
+
$current-color-palette: create-palette-from-color(
|
|
662
|
+
$color-key,
|
|
663
|
+
$color-data,
|
|
664
|
+
$levels,
|
|
665
|
+
$gamut,
|
|
666
|
+
$prefix
|
|
667
|
+
);
|
|
668
|
+
$palette: map.merge($palette, $current-color-palette);
|
|
669
|
+
}
|
|
670
|
+
@return $palette;
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
// 16.Report on completed work
|
|
674
|
+
@function get-report(
|
|
675
|
+
$custom-hues-count,
|
|
676
|
+
$custom-shades-count,
|
|
677
|
+
$preset-shades-count,
|
|
678
|
+
$root-rule
|
|
679
|
+
) {
|
|
680
|
+
$report-text: "The work of var-colors is completed,";
|
|
681
|
+
@if $custom-hues-count ==
|
|
682
|
+
0 and
|
|
683
|
+
$custom-shades-count ==
|
|
684
|
+
0 and
|
|
685
|
+
$preset-shades-count ==
|
|
686
|
+
0
|
|
687
|
+
{
|
|
688
|
+
$report-text: $report-text +
|
|
689
|
+
" but no custom properties have been created. Check if the configuration is correct";
|
|
690
|
+
} @else {
|
|
691
|
+
$report-text: $report-text + " created";
|
|
692
|
+
@if $custom-hues-count > 0 {
|
|
693
|
+
$report-text: $report-text + " " + $custom-hues-count + " variable hue";
|
|
694
|
+
@if not $root-rule {
|
|
695
|
+
$report-text: $report-text + ' in "$var-hues" scss-variable';
|
|
696
|
+
}
|
|
697
|
+
$report-text: $report-text + ",";
|
|
698
|
+
}
|
|
699
|
+
@if $custom-shades-count > 0 {
|
|
700
|
+
$report-text: $report-text +
|
|
701
|
+
" " +
|
|
702
|
+
$custom-shades-count +
|
|
703
|
+
" shades of custom colors,";
|
|
704
|
+
}
|
|
705
|
+
@if $preset-shades-count > 0 {
|
|
706
|
+
$report-text: $report-text +
|
|
707
|
+
" " +
|
|
708
|
+
$preset-shades-count +
|
|
709
|
+
" shades of preset colors,";
|
|
710
|
+
}
|
|
711
|
+
$report-text: string.slice($report-text, 1, -2);
|
|
712
|
+
@if $root-rule {
|
|
713
|
+
$report-text: $report-text + " in root-rule";
|
|
714
|
+
} @else {
|
|
715
|
+
$report-text: $report-text + ' in "$palette" scss-variable';
|
|
716
|
+
}
|
|
717
|
+
}
|
|
718
|
+
|
|
719
|
+
@return $report-text;
|
|
720
|
+
}
|