748286b5 |
1 | /// Removes a specific item from a list.\r |
2 | /// @author Hugo Giraudel\r |
3 | /// @param {list} $list List.\r |
4 | /// @param {integer} $index Index.\r |
5 | /// @return {list} Updated list.\r |
6 | @function remove-nth($list, $index) {\r |
7 | \r |
8 | $result: null;\r |
9 | \r |
10 | @if type-of($index) != number {\r |
11 | @warn "$index: #{quote($index)} is not a number for `remove-nth`.";\r |
12 | }\r |
13 | @else if $index == 0 {\r |
14 | @warn "List index 0 must be a non-zero integer for `remove-nth`.";\r |
15 | }\r |
16 | @else if abs($index) > length($list) {\r |
17 | @warn "List index is #{$index} but list is only #{length($list)} item long for `remove-nth`.";\r |
18 | }\r |
19 | @else {\r |
20 | \r |
21 | $result: ();\r |
22 | $index: if($index < 0, length($list) + $index + 1, $index);\r |
23 | \r |
24 | @for $i from 1 through length($list) {\r |
25 | \r |
26 | @if $i != $index {\r |
27 | $result: append($result, nth($list, $i));\r |
28 | }\r |
29 | \r |
30 | }\r |
31 | \r |
32 | }\r |
33 | \r |
34 | @return $result;\r |
35 | \r |
36 | }\r |
37 | \r |
38 | /// Gets a value from a map.\r |
39 | /// @author Hugo Giraudel\r |
40 | /// @param {map} $map Map.\r |
41 | /// @param {string} $keys Key(s).\r |
42 | /// @return {string} Value.\r |
43 | @function val($map, $keys...) {\r |
44 | \r |
45 | @if nth($keys, 1) == null {\r |
46 | $keys: remove-nth($keys, 1);\r |
47 | }\r |
48 | \r |
49 | @each $key in $keys {\r |
50 | $map: map-get($map, $key);\r |
51 | }\r |
52 | \r |
53 | @return $map;\r |
54 | \r |
55 | }\r |
56 | \r |
57 | /// Gets a duration value.\r |
58 | /// @param {string} $keys Key(s).\r |
59 | /// @return {string} Value.\r |
60 | @function _duration($keys...) {\r |
61 | @return val($duration, $keys...);\r |
62 | }\r |
63 | \r |
64 | /// Gets a font value.\r |
65 | /// @param {string} $keys Key(s).\r |
66 | /// @return {string} Value.\r |
67 | @function _font($keys...) {\r |
68 | @return val($font, $keys...);\r |
69 | }\r |
70 | \r |
71 | /// Gets a misc value.\r |
72 | /// @param {string} $keys Key(s).\r |
73 | /// @return {string} Value.\r |
74 | @function _misc($keys...) {\r |
75 | @return val($misc, $keys...);\r |
76 | }\r |
77 | \r |
78 | /// Gets a palette value.\r |
79 | /// @param {string} $keys Key(s).\r |
80 | /// @return {string} Value.\r |
81 | @function _palette($keys...) {\r |
82 | @return val($palette, $keys...);\r |
83 | }\r |
84 | \r |
85 | /// Gets a size value.\r |
86 | /// @param {string} $keys Key(s).\r |
87 | /// @return {string} Value.\r |
88 | @function _size($keys...) {\r |
89 | @return val($size, $keys...);\r |
90 | } |