-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_function.insert.function.scss
More file actions
86 lines (73 loc) · 3.44 KB
/
_function.insert.function.scss
File metadata and controls
86 lines (73 loc) · 3.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// Sass.
@use 'sass:list';
@use 'sass:meta';
// Modules.
@use '../list/has';
@use '../list/remove';
// Functions.
@use 'function.has.function' as *;
@use 'function.is.function' as *;
@use 'function.prefix.function' as *;
// Status: TODO: --var-get ()
// The `function.insert()` function adds function(existing) name to specified type in `$value`.
// @param `$value` Value to insert function names on specified types.
// @param `$prefix` Prefixes that can be used for function name.
// @param `$type-function` Map type value indicates which functions are inserted on specified types in `$value`.
// @param `$functions` Additional functions available to insert into `$value`.
// @returns The returned value is `$value` with inserted function names in specified types.
@function insert(
$value,
$prefix: null,
$separator: null,
$type-function,
$functions: null
) {
@if $type-function {
$index: 1;
@each $val in $value {
@each $type, $function in $type-function {
@if list.index($type, type-of($val)) and is($function, $prefix, $separator, $functions) {
@if list.length($val) > 0 and if(list.separator($val) == space, not has($val, $prefix, $separator, $functions), true) {
@if not is($val, $prefix, $separator, $functions) {
@if $index > 1 and meta.type-of(list.nth($value, $index - 1)) == string {
@if not is(list.nth($value, $index - 1), $prefix, $separator, $functions) {
$value: list.set-nth($value, $index, list.append($function, $val));
}
} @else {
$value: list.set-nth($value, $index, list.append($function, $val));
}
}
} @else {
$value: list.set-nth($value, $index, $val);
}
}
}
$index: $index + 1;
}
@if list.separator($value) == comma and list.length($value) == 1 {
$value: list.join((), $value, space);
}
$value: remove.list($value, 0);
}
@return $value;
}
// Examples.
// string
// @debug insert(primary-color-dark, $type-function: ((list, string): --selector-nest)); // (--selector-nest primary-color-dark)
// number
// @debug insert(5px, $type-function: (number: --selector-nest)); // (--selector-nest 5px)
// list(--selector-nest 5px)
// @debug insert((ut 1,), $type-function: (list: --selector-nest)); // (--selector-nest (ut 1))
// @debug insert((padding, (top, bottom)) (), $type-function: (list: --selector-nest)); // (selector-nest (ut 1))
// @debug insert(((primary-color-dark, 15%),), $type-function: (list: --selector-nest)); // ()
// @debug insert((primary-color-dark, 15%) (), $type-function: (list: --selector-nest)); // (selector-nest (primary-color-dark, 15%))
// @debug insert((primary color dark, 15%), $type-function: (list: --selector-nest)); //
// @debug insert((margin (unit 4), color (unit 1)), $type-function: (list: --selector-nest)); //
// @debug insert((unit 1) 10px (unit 20) 15px, $type-function: (list: --selector-nest));
// @debug insert(5px (unit 1) 10px (unit 20, 5) 15px, $type-function: (list: --selector-nest));
// has function
// @debug insert(5px (unit 1) 10px (list-nth (unit 20, 5)) 15px, $type-function: (list: --selector-nest));
// each function different prefix // TODO:
// @debug insert((unit 1) 10px (unit 20) 15px, $type-function: (list: ('--': selector-nest, '__': var-get)));
// map arguments
// @debug insert((unit 10, (arguments: (dictionary: (unit: u)))), $type-function: (list: --selector-nest));