aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorVolpeon <git@volpeon.ink>2022-02-07 12:28:59 +0100
committerVolpeon <git@volpeon.ink>2022-02-07 12:28:59 +0100
commit4c9a427806b47b916849dbc98330fdbb469b659b (patch)
tree5dc85968bea6569aa4ff47c46e5d4994a24cdcaf /src
parentRename next-twin-element to next-twin-elem (diff)
downloadiro-sass-4c9a427806b47b916849dbc98330fdbb469b659b.tar.gz
iro-sass-4c9a427806b47b916849dbc98330fdbb469b659b.tar.bz2
iro-sass-4c9a427806b47b916849dbc98330fdbb469b659b.zip
Replace deep map functions with built-ins
Diffstat (limited to 'src')
-rw-r--r--src/_functions.scss73
-rw-r--r--src/_props.scss3
2 files changed, 12 insertions, 64 deletions
diff --git a/src/_functions.scss b/src/_functions.scss
index d091afa..236b548 100644
--- a/src/_functions.scss
+++ b/src/_functions.scss
@@ -9,6 +9,7 @@
9/// @access public 9/// @access public
10//// 10////
11 11
12@use 'sass:map';
12@use 'sass:math'; 13@use 'sass:math';
13@use './vars'; 14@use './vars';
14 15
@@ -65,9 +66,11 @@
65@function list-slice($list, $start: 1, $end: length($list)) { 66@function list-slice($list, $start: 1, $end: length($list)) {
66 $result: (); 67 $result: ();
67 68
68 @for $i from $start through $end { 69 @if $end >= $start {
69 @if $i != 0 { 70 @for $i from $start through $end {
70 $result: append($result, nth($list, $i), list-separator($list)); 71 @if $i != 0 {
72 $result: append($result, nth($list, $i), list-separator($list));
73 }
71 } 74 }
72 } 75 }
73 76
@@ -162,67 +165,11 @@
162/// 165///
163/// @return {any} Either the value assigned to $key or $default 166/// @return {any} Either the value assigned to $key or $default
164/// 167///
165@function map-get-default($map, $key, $default) { 168@function map-get-default($map, $key, $keys...) {
166 @return if(map-has-key($map, $key), map-get($map, $key), $default); 169 $default: nth($keys, length($keys));
167} 170 $keys: list-slice($keys, 1, length($keys) - 1);
168
169///
170/// Get the value for a map within a map (or deeper).
171///
172/// @param {map} $map
173/// @param {string | list} $key
174/// @param {any} $default [null]
175///
176/// @return {any} Either the value assigned to $key or $default
177///
178@function map-get-deep($map, $key, $default: null) {
179 $value: null;
180
181 @if type-of($key) == list {
182 $value: $map;
183
184 @each $k in $key {
185 $value: map-get($value, $k);
186
187 @if $value == null {
188 @return $default;
189 }
190 }
191 } @else {
192 $value: map-get($map, $key);
193 171
194 @if $value == null { 172 @return if(map-has-key($map, $key, $keys...), map-get($map, $key, $keys...), $default);
195 @return $default;
196 }
197 }
198
199 @return $value;
200}
201
202///
203/// Merge two maps recursively.
204///
205/// @param {map} $map1
206/// @param {map} $map2
207///
208/// @return {map} The result of a recursive merge of $map1 and $map2
209///
210@function map-merge-recursive($map1, $map2) {
211 @if type-of($map1) != map or type-of($map2) != map {
212 @error 'Two maps expected.';
213 }
214
215 $result: $map1;
216
217 @each $key, $value in $map2 {
218 @if type-of(map-get($result, $key)) == map and type-of($value) == map {
219 $result: map-merge($result, ($key: map-merge-recursive(map-get($result, $key), $value)));
220 } @else {
221 $result: map-merge($result, ($key: $value));
222 }
223 }
224
225 @return $result;
226} 173}
227 174
228/// 175///
diff --git a/src/_props.scss b/src/_props.scss
index db24dff..196e2f9 100644
--- a/src/_props.scss
+++ b/src/_props.scss
@@ -10,6 +10,7 @@
10/// @access public 10/// @access public
11//// 11////
12 12
13@use 'sass:map';
13@use './functions'; 14@use './functions';
14@use './contexts'; 15@use './contexts';
15 16
@@ -127,7 +128,7 @@ $namespace-context-id: 'namespace' !default;
127 128
128 @if map-has-key($trees, $tree) { 129 @if map-has-key($trees, $tree) {
129 @if $merge { 130 @if $merge {
130 $map: functions.map-merge-recursive(map-get($trees, $tree), $map); 131 $map: map.deep-merge(map-get($trees, $tree), $map);
131 } @else { 132 } @else {
132 @error 'Property tree #{inspect($tree)} does already exist.'; 133 @error 'Property tree #{inspect($tree)} does already exist.';
133 } 134 }