diff options
| author | Volpeon <git@volpeon.ink> | 2024-06-22 08:14:44 +0200 |
|---|---|---|
| committer | Volpeon <git@volpeon.ink> | 2024-06-22 08:14:44 +0200 |
| commit | 828a12ffac60b2fb7e6b0931f610b7ca9f53ffc2 (patch) | |
| tree | 3572fbd90d4e6c98f986b90f18681b13f49b598b /src/_props.scss | |
| parent | Update (diff) | |
| download | iro-sass-828a12ffac60b2fb7e6b0931f610b7ca9f53ffc2.tar.gz iro-sass-828a12ffac60b2fb7e6b0931f610b7ca9f53ffc2.tar.bz2 iro-sass-828a12ffac60b2fb7e6b0931f610b7ca9f53ffc2.zip | |
Props: Support recursive var() if referring to subtree
Diffstat (limited to 'src/_props.scss')
| -rw-r--r-- | src/_props.scss | 99 |
1 files changed, 55 insertions, 44 deletions
diff --git a/src/_props.scss b/src/_props.scss index 1494203..14295bd 100644 --- a/src/_props.scss +++ b/src/_props.scss | |||
| @@ -11,6 +11,9 @@ | |||
| 11 | //// | 11 | //// |
| 12 | 12 | ||
| 13 | @use 'sass:map'; | 13 | @use 'sass:map'; |
| 14 | @use 'sass:list'; | ||
| 15 | @use 'sass:string'; | ||
| 16 | @use 'sass:meta'; | ||
| 14 | @use './functions'; | 17 | @use './functions'; |
| 15 | @use './contexts'; | 18 | @use './contexts'; |
| 16 | 19 | ||
| @@ -63,7 +66,7 @@ $namespace-context-id: 'namespace' !default; | |||
| 63 | $ns-key: get-ns-key(); | 66 | $ns-key: get-ns-key(); |
| 64 | 67 | ||
| 65 | @if $ns-key != null { | 68 | @if $ns-key != null { |
| 66 | $key: append($ns-key, $key); | 69 | $key: list.append($ns-key, $key); |
| 67 | } @else { | 70 | } @else { |
| 68 | $key: ($key); | 71 | $key: ($key); |
| 69 | } | 72 | } |
| @@ -84,8 +87,8 @@ $namespace-context-id: 'namespace' !default; | |||
| 84 | @function namespace() { | 87 | @function namespace() { |
| 85 | $noop: contexts.assert-stack-must-contain($namespace-context-id, 'namespace'); | 88 | $noop: contexts.assert-stack-must-contain($namespace-context-id, 'namespace'); |
| 86 | 89 | ||
| 87 | $data: nth(contexts.get($namespace-context-id, 'namespace'), 2); | 90 | $data: list.nth(contexts.get($namespace-context-id, 'namespace'), 2); |
| 88 | $name: map-get($data, 'name'); | 91 | $name: map.get($data, 'name'); |
| 89 | 92 | ||
| 90 | @return $name; | 93 | @return $name; |
| 91 | } | 94 | } |
| @@ -126,15 +129,15 @@ $namespace-context-id: 'namespace' !default; | |||
| 126 | } | 129 | } |
| 127 | } | 130 | } |
| 128 | 131 | ||
| 129 | @if map-has-key($trees, $tree) { | 132 | @if map.has-key($trees, $tree) { |
| 130 | @if $merge { | 133 | @if $merge { |
| 131 | $map: map.deep-merge(map-get($trees, $tree), $map); | 134 | $map: map.deep-merge(map.get($trees, $tree), $map); |
| 132 | } @else { | 135 | } @else { |
| 133 | @error 'Property tree #{inspect($tree)} does already exist.'; | 136 | @error 'Property tree #{inspect($tree)} does already exist.'; |
| 134 | } | 137 | } |
| 135 | } | 138 | } |
| 136 | 139 | ||
| 137 | $trees: map-merge($trees, ($tree: $map)) !global; | 140 | $trees: map.merge($trees, ($tree: $map)) !global; |
| 138 | 141 | ||
| 139 | @return null; | 142 | @return null; |
| 140 | } | 143 | } |
| @@ -156,11 +159,11 @@ $namespace-context-id: 'namespace' !default; | |||
| 156 | /// @throw If the property tree does not exist | 159 | /// @throw If the property tree does not exist |
| 157 | /// | 160 | /// |
| 158 | @function clear($tree: $default-tree) { | 161 | @function clear($tree: $default-tree) { |
| 159 | @if not map-has-key($trees, $tree) { | 162 | @if not map.has-key($trees, $tree) { |
| 160 | @error 'Property tree "#{inspect($tree)}" does not exist.'; | 163 | @error 'Property tree "#{inspect($tree)}" does not exist.'; |
| 161 | } | 164 | } |
| 162 | 165 | ||
| 163 | $trees: map-remove($trees, $tree) !global; | 166 | $trees: map.remove($trees, $tree) !global; |
| 164 | 167 | ||
| 165 | @return null; | 168 | @return null; |
| 166 | } | 169 | } |
| @@ -177,11 +180,11 @@ $namespace-context-id: 'namespace' !default; | |||
| 177 | /// @throw If there was no match for $key and $default is null | 180 | /// @throw If there was no match for $key and $default is null |
| 178 | /// | 181 | /// |
| 179 | @function get-static($key: (), $tree: $default-tree, $default: null, $global: false) { | 182 | @function get-static($key: (), $tree: $default-tree, $default: null, $global: false) { |
| 180 | @if not map-has-key($trees, $tree) { | 183 | @if not map.has-key($trees, $tree) { |
| 181 | @error 'Unknown tree "#{$tree}".'; | 184 | @error 'Unknown tree "#{$tree}".'; |
| 182 | } | 185 | } |
| 183 | 186 | ||
| 184 | $result: map-get($trees, $tree); | 187 | $result: map.get($trees, $tree); |
| 185 | 188 | ||
| 186 | @if not $global { | 189 | @if not $global { |
| 187 | $ns-key: get-ns-key(); | 190 | $ns-key: get-ns-key(); |
| @@ -190,28 +193,28 @@ $namespace-context-id: 'namespace' !default; | |||
| 190 | $orig-key: $key; | 193 | $orig-key: $key; |
| 191 | $key: $ns-key; | 194 | $key: $ns-key; |
| 192 | 195 | ||
| 193 | @if type-of($orig-key) == list { | 196 | @if meta.type-of($orig-key) == list { |
| 194 | @each $subkey in $orig-key { | 197 | @each $subkey in $orig-key { |
| 195 | $key: append($key, $subkey); | 198 | $key: list.append($key, $subkey); |
| 196 | } | 199 | } |
| 197 | } @else { | 200 | } @else { |
| 198 | $key: append($key, $orig-key); | 201 | $key: list.append($key, $orig-key); |
| 199 | } | 202 | } |
| 200 | } | 203 | } |
| 201 | } | 204 | } |
| 202 | 205 | ||
| 203 | @if type-of($key) == list { | 206 | @if meta.type-of($key) == list { |
| 204 | $stop: false; | 207 | $stop: false; |
| 205 | 208 | ||
| 206 | @each $k in $key { | 209 | @each $k in $key { |
| 207 | @if not $stop and map-has-key($result, $k) { | 210 | @if not $stop and map.has-key($result, $k) { |
| 208 | $result: map-get($result, $k); | 211 | $result: map.get($result, $k); |
| 209 | 212 | ||
| 210 | @if type-of($result) == list and nth($result, 1) == 'iro-prop-ref' { | 213 | @if meta.type-of($result) == list and list.nth($result, 1) == 'iro-prop-ref' { |
| 211 | @if length($result) == 2 { | 214 | @if list.length($result) == 2 { |
| 212 | $result: get-static($tree: nth($result, 2), $global: true); | 215 | $result: get-static($tree: list.nth($result, 2), $global: true); |
| 213 | } @else { | 216 | } @else { |
| 214 | $result: get-static(nth($result, 3), nth($result, 2), $global: true); | 217 | $result: get-static(list.nth($result, 3), nth($result, 2), $global: true); |
| 215 | } | 218 | } |
| 216 | } | 219 | } |
| 217 | } @else { | 220 | } @else { |
| @@ -223,13 +226,13 @@ $namespace-context-id: 'namespace' !default; | |||
| 223 | $result: null; | 226 | $result: null; |
| 224 | } | 227 | } |
| 225 | } @else { | 228 | } @else { |
| 226 | $result: map-get($result, $key); | 229 | $result: map.get($result, $key); |
| 227 | 230 | ||
| 228 | @if type-of($result) == list and nth($result, 1) == 'iro-prop-ref' { | 231 | @if meta.type-of($result) == list and list.nth($result, 1) == 'iro-prop-ref' { |
| 229 | @if length($result) == 2 { | 232 | @if list.length($result) == 2 { |
| 230 | $result: get-static($tree: nth($result, 2), $global: true); | 233 | $result: get-static($tree: list.nth($result, 2), $global: true); |
| 231 | } @else { | 234 | } @else { |
| 232 | $result: get-static(nth($result, 3), nth($result, 2), $global: true); | 235 | $result: get-static(list.nth($result, 3), nth($result, 2), $global: true); |
| 233 | } | 236 | } |
| 234 | } | 237 | } |
| 235 | } | 238 | } |
| @@ -256,7 +259,15 @@ $namespace-context-id: 'namespace' !default; | |||
| 256 | /// | 259 | /// |
| 257 | @function get($key, $tree: $default-tree, $default: null, $global: false) { | 260 | @function get($key, $tree: $default-tree, $default: null, $global: false) { |
| 258 | @if $tree != null { | 261 | @if $tree != null { |
| 259 | $noop: get-static($key, $tree, $default, $global); | 262 | $value: get-static($key, $tree, $default, $global); |
| 263 | |||
| 264 | @if meta.type-of($value) == map { | ||
| 265 | $result: (); | ||
| 266 | @each $k in map.keys($value) { | ||
| 267 | $result: map.set($result, $k, get(list.append($key, $k), $tree, $default, $global)); | ||
| 268 | } | ||
| 269 | @return $result; | ||
| 270 | } | ||
| 260 | } | 271 | } |
| 261 | 272 | ||
| 262 | @if not $global { | 273 | @if not $global { |
| @@ -266,19 +277,19 @@ $namespace-context-id: 'namespace' !default; | |||
| 266 | $orig-key: $key; | 277 | $orig-key: $key; |
| 267 | $key: $ns-key; | 278 | $key: $ns-key; |
| 268 | 279 | ||
| 269 | @if type-of($orig-key) == list { | 280 | @if meta.type-of($orig-key) == list { |
| 270 | @each $subkey in $orig-key { | 281 | @each $subkey in $orig-key { |
| 271 | $key: append($key, $subkey); | 282 | $key: list.append($key, $subkey); |
| 272 | } | 283 | } |
| 273 | } @else { | 284 | } @else { |
| 274 | $key: append($key, $orig-key); | 285 | $key: list.append($key, $orig-key); |
| 275 | } | 286 | } |
| 276 | } | 287 | } |
| 277 | } | 288 | } |
| 278 | 289 | ||
| 279 | $native-var: ''; | 290 | $native-var: ''; |
| 280 | 291 | ||
| 281 | @if type-of($key) == list { | 292 | @if meta.type-of($key) == list { |
| 282 | @each $subkey in $key { | 293 | @each $subkey in $key { |
| 283 | $native-var: $native-var + $subkey; | 294 | $native-var: $native-var + $subkey; |
| 284 | } | 295 | } |
| @@ -301,9 +312,9 @@ $namespace-context-id: 'namespace' !default; | |||
| 301 | /// | 312 | /// |
| 302 | @mixin assign($tree: $default-tree, $root: (), $skip: (), $prefix: $root, $global: false) { | 313 | @mixin assign($tree: $default-tree, $root: (), $skip: (), $prefix: $root, $global: false) { |
| 303 | $map: get-static($root, $tree, $global: $global); | 314 | $map: get-static($root, $tree, $global: $global); |
| 304 | $map: map-remove($map, $skip...); | 315 | $map: map.remove($map, $skip...); |
| 305 | 316 | ||
| 306 | @if type-of($prefix) == list { | 317 | @if meta.type-of($prefix) == list { |
| 307 | $prefix: functions.str-implode($prefix); | 318 | $prefix: functions.str-implode($prefix); |
| 308 | } | 319 | } |
| 309 | 320 | ||
| @@ -324,19 +335,19 @@ $namespace-context-id: 'namespace' !default; | |||
| 324 | @mixin assign-internal($map, $prefix: '', $ref-depth: $native-assign-max-depth) { | 335 | @mixin assign-internal($map, $prefix: '', $ref-depth: $native-assign-max-depth) { |
| 325 | @each $key, $value in $map { | 336 | @each $key, $value in $map { |
| 326 | $rd: $ref-depth; | 337 | $rd: $ref-depth; |
| 327 | @if type-of($value) == list and length($value) > 0 and nth($value, 1) == 'iro-prop-ref' { | 338 | @if meta.type-of($value) == list and list.length($value) > 0 and list.nth($value, 1) == 'iro-prop-ref' { |
| 328 | @if $ref-depth != 0 { | 339 | @if $ref-depth != 0 { |
| 329 | $rd: $rd - 1; | 340 | $rd: $rd - 1; |
| 330 | @if length($value) == 2 { | 341 | @if list.length($value) == 2 { |
| 331 | $value: get-static($tree: nth($value, 2)); | 342 | $value: get-static($tree: list.nth($value, 2)); |
| 332 | } @else { | 343 | } @else { |
| 333 | $value: get-static(nth($value, 3), nth($value, 2)); | 344 | $value: get-static(list.nth($value, 3), nth($value, 2)); |
| 334 | } | 345 | } |
| 335 | } @else { | 346 | } @else { |
| 336 | $value: null; | 347 | $value: null; |
| 337 | } | 348 | } |
| 338 | } | 349 | } |
| 339 | @if type-of($value) != map and $value != () { | 350 | @if meta.type-of($value) != map and $value != () { |
| 340 | #{$prefix + $key}: #{$value}; | 351 | #{$prefix + $key}: #{$value}; |
| 341 | } @else { | 352 | } @else { |
| 342 | @include assign-internal($value, $prefix + $key, $rd); | 353 | @include assign-internal($value, $prefix + $key, $rd); |
| @@ -351,11 +362,11 @@ $namespace-context-id: 'namespace' !default; | |||
| 351 | /// | 362 | /// |
| 352 | @function validate($map) { | 363 | @function validate($map) { |
| 353 | @each $key, $value in $map { | 364 | @each $key, $value in $map { |
| 354 | @if str-index($key, '--') != 1 { | 365 | @if string.index($key, '--') != 1 { |
| 355 | @return false; | 366 | @return false; |
| 356 | } | 367 | } |
| 357 | 368 | ||
| 358 | @if type-of($value) == map { | 369 | @if meta.type-of($value) == map { |
| 359 | @if not validate($value) { | 370 | @if not validate($value) { |
| 360 | @return false; | 371 | @return false; |
| 361 | } | 372 | } |
| @@ -384,12 +395,12 @@ $namespace-context-id: 'namespace' !default; | |||
| 384 | $key: $ns-key; | 395 | $key: $ns-key; |
| 385 | 396 | ||
| 386 | @if $orig-key != null { | 397 | @if $orig-key != null { |
| 387 | @if type-of($orig-key) == list { | 398 | @if meta.type-of($orig-key) == list { |
| 388 | @each $subkey in $orig-key { | 399 | @each $subkey in $orig-key { |
| 389 | $key: append($key, $subkey); | 400 | $key: list.append($key, $subkey); |
| 390 | } | 401 | } |
| 391 | } @else { | 402 | } @else { |
| 392 | $key: append($key, $orig-key); | 403 | $key: list.append($key, $orig-key); |
| 393 | } | 404 | } |
| 394 | } | 405 | } |
| 395 | } | 406 | } |
| @@ -414,8 +425,8 @@ $namespace-context-id: 'namespace' !default; | |||
| 414 | @return null; | 425 | @return null; |
| 415 | } | 426 | } |
| 416 | 427 | ||
| 417 | $data: nth($ctx, 2); | 428 | $data: list.nth($ctx, 2); |
| 418 | $key: map-get($data, 'key'); | 429 | $key: map.get($data, 'key'); |
| 419 | 430 | ||
| 420 | @return $key; | 431 | @return $key; |
| 421 | } | 432 | } |
