diff options
Diffstat (limited to 'src/_props.scss')
| -rw-r--r-- | src/_props.scss | 200 |
1 files changed, 102 insertions, 98 deletions
diff --git a/src/_props.scss b/src/_props.scss index ec10b1f..17e9de7 100644 --- a/src/_props.scss +++ b/src/_props.scss | |||
| @@ -3,133 +3,137 @@ | |||
| 3 | @use 'sass:meta'; | 3 | @use 'sass:meta'; |
| 4 | 4 | ||
| 5 | @function is-prop-ref($value) { | 5 | @function is-prop-ref($value) { |
| 6 | @if meta.type-of($value) != 'list' { | 6 | @if meta.type-of($value) != 'list' { |
| 7 | @return false; | 7 | @return false; |
| 8 | } | 8 | } |
| 9 | @if list.length($value) != 4 { | 9 | @if list.length($value) != 4 { |
| 10 | @return false; | 10 | @return false; |
| 11 | } | 11 | } |
| 12 | @if list.nth($value, 1) != 'prop-ref' { | 12 | @if list.nth($value, 1) != 'prop-ref' { |
| 13 | @return false; | 13 | @return false; |
| 14 | } | 14 | } |
| 15 | @return true; | 15 | @return true; |
| 16 | } | 16 | } |
| 17 | 17 | ||
| 18 | @function def($name, $value: (), $metadata: ()) { | 18 | @function def($name, $value: (), $metadata: ()) { |
| 19 | @return ('prop-ref' $name $value $metadata); | 19 | @return ('prop-ref' $name $value $metadata); |
| 20 | } | 20 | } |
| 21 | 21 | ||
| 22 | @function merge($ref, $value) { | 22 | @function merge($ref, $value) { |
| 23 | @if not is-prop-ref($ref) { | 23 | @if not is-prop-ref($ref) { |
| 24 | @return $ref; | 24 | @return $ref; |
| 25 | } | 25 | } |
| 26 | 26 | ||
| 27 | $v: list.nth($ref, 3); | 27 | $v: list.nth($ref, 3); |
| 28 | $ref: list.set-nth($ref, 3, map.deep-merge($v, $value)); | 28 | $ref: list.set-nth($ref, 3, map.deep-merge($v, $value)); |
| 29 | @return $ref; | 29 | @return $ref; |
| 30 | } | 30 | } |
| 31 | 31 | ||
| 32 | @function get-deep($name, $value, $key: null, $keys...) { | 32 | @function get-deep($name, $value, $key: null, $keys...) { |
| 33 | @if is-prop-ref($value) { | 33 | @if is-prop-ref($value) { |
| 34 | @return get($value, $key, $keys); | 34 | @return get($value, $key, $keys); |
| 35 | } | 35 | } |
| 36 | @if meta.type-of($value) == 'map' and $key != null { | 36 | @if meta.type-of($value) == 'map' and $key != null { |
| 37 | @if meta.type-of($key) != 'string' { | 37 | @if meta.type-of($key) != 'string' { |
| 38 | @error 'Expected string, got #{$key}'; | 38 | @error 'Expected string, got #{$key}'; |
| 39 | } | 39 | } |
| 40 | @return get-deep(#{$name}#{$key}, map.get($value, $key), $keys...); | 40 | @return get-deep(#{$name}#{$key}, map.get($value, $key), $keys...); |
| 41 | } | 41 | } |
| 42 | @return $name $value; | 42 | @return $name $value; |
| 43 | } | 43 | } |
| 44 | 44 | ||
| 45 | @function map-to-vars($name, $map) { | 45 | @function map-to-vars($name, $map) { |
| 46 | @if meta.type-of($map) != 'map' { | 46 | @if meta.type-of($map) != 'map' { |
| 47 | @if meta.type-of($name) != 'string' { | 47 | @if meta.type-of($name) != 'string' { |
| 48 | @error 'Expected variable name, got #{$name} instead'; | 48 | @error 'Expected variable name, got #{$name} instead'; |
| 49 | } | 49 | } |
| 50 | @return var($name); | 50 | @return var($name); |
| 51 | } | 51 | } |
| 52 | 52 | ||
| 53 | $out: (); | 53 | $out: (); |
| 54 | 54 | ||
| 55 | @each $key, $value in $map { | 55 | @each $key, $value in $map { |
| 56 | $out: map.set($out, $key, map-to-vars(#{$name}#{$key}, $value)); | 56 | $out: map.set($out, $key, map-to-vars(#{$name}#{$key}, $value)); |
| 57 | } | 57 | } |
| 58 | 58 | ||
| 59 | @return $out; | 59 | @return $out; |
| 60 | } | 60 | } |
| 61 | 61 | ||
| 62 | @function get($ref, $key: null, $keys...) { | 62 | @function get($ref, $key: null, $keys...) { |
| 63 | @if not is-prop-ref($ref) { | 63 | @if not is-prop-ref($ref) { |
| 64 | @return $ref; | 64 | @return $ref; |
| 65 | } | 65 | } |
| 66 | 66 | ||
| 67 | $name: list.nth($ref, 2); | 67 | $name: list.nth($ref, 2); |
| 68 | $value: get(list.nth($ref, 3)); | 68 | $value: get(list.nth($ref, 3)); |
| 69 | 69 | ||
| 70 | @if meta.type-of($value) == 'map' { | 70 | @if meta.type-of($value) == 'map' { |
| 71 | $res: get-deep($name, $value, $key, $keys...); | 71 | $res: get-deep($name, $value, $key, $keys...); |
| 72 | $name: list.nth($res, 1); | 72 | $name: list.nth($res, 1); |
| 73 | $value: list.nth($res, 2); | 73 | $value: list.nth($res, 2); |
| 74 | } @else if meta.type-of($value) == 'list' { | 74 | } @else if meta.type-of($value) == 'list' { |
| 75 | $i: 1; | 75 | $i: 1; |
| 76 | @each $item in $value { | 76 | @each $item in $value { |
| 77 | $value: list.set-nth($value, $i, get($item)); | 77 | $value: list.set-nth($value, $i, get($item)); |
| 78 | $i: $i + 1; | 78 | $i: $i + 1; |
| 79 | } | 79 | } |
| 80 | } | 80 | } |
| 81 | 81 | ||
| 82 | @return map-to-vars($name, $value); | 82 | @return map-to-vars($name, $value); |
| 83 | } | 83 | } |
| 84 | 84 | ||
| 85 | @mixin materialize-helper($name, $value) { | 85 | @mixin materialize-helper($name, $value) { |
| 86 | @if meta.type-of($value) == 'map' { | 86 | @if meta.type-of($value) == 'map' { |
| 87 | @each $key, $value in $value { | 87 | @each $key, $value in $value { |
| 88 | @include materialize-helper(#{$name}#{$key}, $value); | 88 | @include materialize-helper(#{$name}#{$key}, $value); |
| 89 | } | 89 | } |
| 90 | } @else { | 90 | } @else { |
| 91 | #{$name}: #{$value}; | 91 | #{$name}: #{$value}; |
| 92 | } | 92 | } |
| 93 | } | 93 | } |
| 94 | 94 | ||
| 95 | @mixin materialize($ref, $match-meta: null) { | 95 | @mixin materialize($ref, $match-meta: ()) { |
| 96 | @if is-prop-ref($ref) { | 96 | @if is-prop-ref($ref) { |
| 97 | $name: list.nth($ref, 2); | 97 | $name: list.nth($ref, 2); |
| 98 | $value: get(list.nth($ref, 3)); | 98 | $value: get(list.nth($ref, 3)); |
| 99 | $meta: get(list.nth($ref, 4)); | 99 | $meta: get(list.nth($ref, 4)); |
| 100 | 100 | ||
| 101 | $match: true; | 101 | $match: true; |
| 102 | @if meta.type-of($match-meta) == 'list' { | 102 | @if meta.type-of($match-meta) == 'list' { |
| 103 | @each $item in $match-meta { | 103 | @each $item in $match-meta { |
| 104 | $match: $match and list.index($meta, $item) != null; | 104 | $match: $match and list.index($meta, $item) != null; |
| 105 | } | 105 | } |
| 106 | } @else { | 106 | } @else if $match-meta == null and list.length($meta) == 0 { |
| 107 | $match: $match and list.index($meta, $match-meta) != null; | 107 | $match: true; |
| 108 | } | 108 | } @else { |
| 109 | $match: list.index($meta, $match-meta) != null; | ||
| 110 | } | ||
| 109 | 111 | ||
| 110 | @if $match-meta == null or $match { | 112 | @if $match { |
| 111 | @include materialize-helper($name, $value); | 113 | @include materialize-helper($name, $value); |
| 112 | } | 114 | } |
| 113 | } @else if meta.type-of($ref) == 'list' { | 115 | } @else if meta.type-of($ref) == 'list' { |
| 114 | @each $r in $ref { | 116 | @each $r in $ref { |
| 115 | @if is-prop-ref($r) { | 117 | @if is-prop-ref($r) { |
| 116 | $name: list.nth($r, 2); | 118 | $name: list.nth($r, 2); |
| 117 | $value: get(list.nth($r, 3)); | 119 | $value: get(list.nth($r, 3)); |
| 118 | $meta: get(list.nth($r, 4)); | 120 | $meta: get(list.nth($r, 4)); |
| 119 | 121 | ||
| 120 | $match: true; | 122 | $match: true; |
| 121 | @if meta.type-of($match-meta) == 'list' { | 123 | @if meta.type-of($match-meta) == 'list' { |
| 122 | @each $item in $match-meta { | 124 | @each $item in $match-meta { |
| 123 | $match: $match and list.index($meta, $item) != null; | 125 | $match: $match and list.index($meta, $item) != null; |
| 124 | } | 126 | } |
| 125 | } @else { | 127 | } @else if $match-meta == null and list.length($meta) == 0 { |
| 126 | $match: $match and list.index($meta, $match-meta) != null; | 128 | $match: true; |
| 127 | } | 129 | } @else { |
| 130 | $match: list.index($meta, $match-meta) != null; | ||
| 131 | } | ||
| 128 | 132 | ||
| 129 | @if $match-meta == null or $match { | 133 | @if $match { |
| 130 | @include materialize-helper($name, $value); | 134 | @include materialize-helper($name, $value); |
| 131 | } | 135 | } |
| 132 | } | 136 | } |
| 133 | } | 137 | } |
| 134 | } | 138 | } |
| 135 | } | 139 | } |
