summaryrefslogtreecommitdiffstats
path: root/src/_props.scss
diff options
context:
space:
mode:
authorVolpeon <git@volpeon.ink>2024-10-17 16:45:00 +0200
committerVolpeon <git@volpeon.ink>2024-10-17 16:45:00 +0200
commit50f6acc739f24bfa2ca080d08e90d82f8fa83543 (patch)
tree404dbe97d34b7e4fc3293c8e6a8c92d9941ac51e /src/_props.scss
parentColors (diff)
downloadiro-design-50f6acc739f24bfa2ca080d08e90d82f8fa83543.tar.gz
iro-design-50f6acc739f24bfa2ca080d08e90d82f8fa83543.tar.bz2
iro-design-50f6acc739f24bfa2ca080d08e90d82f8fa83543.zip
Revamped variable management
Diffstat (limited to 'src/_props.scss')
-rw-r--r--src/_props.scss105
1 files changed, 105 insertions, 0 deletions
diff --git a/src/_props.scss b/src/_props.scss
new file mode 100644
index 0000000..f7f54c5
--- /dev/null
+++ b/src/_props.scss
@@ -0,0 +1,105 @@
1@use 'sass:list';
2@use 'sass:map';
3@use 'sass:meta';
4
5@use 'iro-sass/src/functions' as functions;
6
7@function is-prop-ref($value) {
8 @if meta.type-of($value) != 'list' {
9 @return false;
10 }
11 @if list.length($value) != 3 {
12 @return false;
13 }
14 @if list.nth($value, 1) != 'prop-ref' {
15 @return false;
16 }
17 @return true;
18}
19
20@function def($name, $value: ()) {
21 @return ('prop-ref' $name $value);
22}
23
24@function merge($ref, $value) {
25 @if not is-prop-ref($ref) {
26 @return $ref;
27 }
28
29 $v: list.nth($ref, 3);
30 $ref: list.set-nth($ref, 3, map.deep-merge($v, $value));
31 @return $ref;
32}
33
34@function get-deep($name, $value, $key: (), $keys...) {
35 @if is-prop-ref($value) {
36 // $value: list.nth($value, 3);
37 @return get($value, $key, $keys);
38 }
39 @if meta.type-of($value) == 'map' {
40 @if list.length($keys) == 0 {
41 @return #{$name}#{$key} map.get($value, $key);
42 } @else {
43 @return get-deep(#{$name}#{$key}, map.get($value, $key), $keys...);
44 }
45 }
46 @return $name $value;
47}
48
49@function map-to-vars($name, $map) {
50 @if meta.type-of($map) != 'map' {
51 @return var($name);
52 }
53
54 $out: ();
55
56 @each $key, $value in $map {
57 $out: map.set($out, $key, map-to-vars(#{$name}#{$key}, $value));
58 }
59
60 @return $out;
61}
62
63@function get($ref, $key: (), $keys...) {
64 @if not is-prop-ref($ref) {
65 @return $ref;
66 }
67
68 $name: list.nth($ref, 2);
69 $value: get(list.nth($ref, 3));
70
71 @if meta.type-of($value) == 'map' {
72 $res: get-deep($name, $value, $key, $keys...);
73 $name: list.nth($res, 1);
74 $value: list.nth($res, 2);
75 } @else if meta.type-of($value) == 'list' {
76 $i: 1;
77 @each $item in $value {
78 $value: list.set-nth($value, $i, get($item));
79 $i: $i + 1;
80 }
81 }
82
83 @return map-to-vars($name, $value);
84}
85
86@mixin declare-helper($name, $value) {
87 @if meta.type-of($value) == 'map' {
88 @each $key, $value in $value {
89 @include declare-helper(#{$name}#{$key}, $value);
90 }
91 } @else {
92 #{$name}: #{$value};
93 }
94}
95
96@mixin materialize($refs) {
97 @each $ref in $refs {
98 @if is-prop-ref($ref) {
99 $name: list.nth($ref, 2);
100 $value: get(list.nth($ref, 3));
101
102 @include declare-helper($name, $value);
103 }
104 }
105}