diff options
| author | Volpeon <git@volpeon.ink> | 2025-08-13 12:01:46 +0200 |
|---|---|---|
| committer | Volpeon <git@volpeon.ink> | 2025-08-13 12:01:46 +0200 |
| commit | f0f84513f8efe533b6ee670a6f1a0c074387b2ec (patch) | |
| tree | 845bc4bacf1bd99acb0dfcc7e4545a36b544d2f8 /src/bem/_validators.scss | |
| parent | More fix (diff) | |
| download | iro-sass-f0f84513f8efe533b6ee670a6f1a0c074387b2ec.tar.gz iro-sass-f0f84513f8efe533b6ee670a6f1a0c074387b2ec.tar.bz2 iro-sass-f0f84513f8efe533b6ee670a6f1a0c074387b2ec.zip | |
Make use of SASS modules
Diffstat (limited to 'src/bem/_validators.scss')
| -rw-r--r-- | src/bem/_validators.scss | 137 |
1 files changed, 70 insertions, 67 deletions
diff --git a/src/bem/_validators.scss b/src/bem/_validators.scss index 042e15e..bc3c9b7 100644 --- a/src/bem/_validators.scss +++ b/src/bem/_validators.scss | |||
| @@ -16,6 +16,9 @@ | |||
| 16 | /// @access public | 16 | /// @access public |
| 17 | //// | 17 | //// |
| 18 | 18 | ||
| 19 | @use 'sass:list'; | ||
| 20 | @use 'sass:map'; | ||
| 21 | @use 'sass:meta'; | ||
| 19 | @use './vars'; | 22 | @use './vars'; |
| 20 | @use '../functions'; | 23 | @use '../functions'; |
| 21 | @use '../contexts'; | 24 | @use '../contexts'; |
| @@ -46,7 +49,7 @@ $validators: (); | |||
| 46 | /// @param {string} $func-names - Other function names. | 49 | /// @param {string} $func-names - Other function names. |
| 47 | /// | 50 | /// |
| 48 | @mixin add($func-name, $func-names...) { | 51 | @mixin add($func-name, $func-names...) { |
| 49 | $noop: add($func-name, $func-names...); | 52 | $noop: add($func-name, $func-names...); |
| 50 | } | 53 | } |
| 51 | 54 | ||
| 52 | /// | 55 | /// |
| @@ -55,11 +58,11 @@ $validators: (); | |||
| 55 | /// @see {mixin} add | 58 | /// @see {mixin} add |
| 56 | /// | 59 | /// |
| 57 | @function add($func-name, $func-names...) { | 60 | @function add($func-name, $func-names...) { |
| 58 | @each $fn-name in join($func-name, $func-names) { | 61 | @each $fn-name in list.join($func-name, $func-names) { |
| 59 | $fn: get-function($fn-name); | 62 | $fn: meta.get-function($fn-name); |
| 60 | $validators: map-merge($validators, ($fn-name: $fn)); | 63 | $validators: map.merge($validators, ($fn-name: $fn)); |
| 61 | } | 64 | } |
| 62 | @return null; | 65 | @return null; |
| 63 | } | 66 | } |
| 64 | 67 | ||
| 65 | /// | 68 | /// |
| @@ -69,7 +72,7 @@ $validators: (); | |||
| 69 | /// @param {string} $func-names - Other function names. | 72 | /// @param {string} $func-names - Other function names. |
| 70 | /// | 73 | /// |
| 71 | @mixin remove($func-name, $func-names...) { | 74 | @mixin remove($func-name, $func-names...) { |
| 72 | $noop: remove($func-name, $func-names...); | 75 | $noop: remove($func-name, $func-names...); |
| 73 | } | 76 | } |
| 74 | 77 | ||
| 75 | /// | 78 | /// |
| @@ -78,20 +81,20 @@ $validators: (); | |||
| 78 | /// @see {mixin} remove | 81 | /// @see {mixin} remove |
| 79 | /// | 82 | /// |
| 80 | @function remove($func-name, $func-names...) { | 83 | @function remove($func-name, $func-names...) { |
| 81 | $validators: map-remove($validators, $func-name, $func-names...); | 84 | $validators: map.remove($validators, $func-name, $func-names...); |
| 82 | @return null; | 85 | @return null; |
| 83 | } | 86 | } |
| 84 | 87 | ||
| 85 | /// | 88 | /// |
| 86 | /// @access private | 89 | /// @access private |
| 87 | /// | 90 | /// |
| 88 | @mixin validate($type, $args, $selector, $context) { | 91 | @mixin validate($type, $args, $selector, $context) { |
| 89 | @each $id, $fn in $validators { | 92 | @each $id, $fn in $validators { |
| 90 | $result: call($fn, $type, $args, $selector, $context); | 93 | $result: meta.call($fn, $type, $args, $selector, $context); |
| 91 | @if not nth($result, 1) { | 94 | @if not list.nth($result, 1) { |
| 92 | @error 'A BEM validator rejected this mixin usage due to the following reason: #{nth($result, 2)}'; | 95 | @error 'A BEM validator rejected this mixin usage due to the following reason: #{nth($result, 2)}'; |
| 93 | } | 96 | } |
| 94 | } | 97 | } |
| 95 | } | 98 | } |
| 96 | 99 | ||
| 97 | // | 100 | // |
| @@ -105,76 +108,76 @@ $validators: (); | |||
| 105 | /// namespace used. | 108 | /// namespace used. |
| 106 | /// | 109 | /// |
| 107 | @function enforce-namespace-order($type, $args, $selector, $context) { | 110 | @function enforce-namespace-order($type, $args, $selector, $context) { |
| 108 | @if not global-variable-exists(namespace-order, vars) { | 111 | @if not meta.global-variable-exists(namespace-order, vars) { |
| 109 | vars.$namespace-order: map-keys(vars.$namespaces); | 112 | vars.$namespace-order: map.keys(vars.$namespaces); |
| 110 | } | 113 | } |
| 111 | @if not global-variable-exists(cur-namespace-index, vars) { | 114 | @if not meta.global-variable-exists(cur-namespace-index, vars) { |
| 112 | vars.$cur-namespace-index: 1; | 115 | vars.$cur-namespace-index: 1; |
| 113 | } | 116 | } |
| 114 | 117 | ||
| 115 | @if $type == 'block' { | 118 | @if $type == 'block' { |
| 116 | $block-type: map-get($args, 'type'); | 119 | $block-type: map.get($args, 'type'); |
| 117 | 120 | ||
| 118 | @if $block-type != null { | 121 | @if $block-type != null { |
| 119 | $ns-index: index(vars.$namespace-order, $block-type); | 122 | $ns-index: list.index(vars.$namespace-order, $block-type); |
| 120 | 123 | ||
| 121 | @if $ns-index != null { | 124 | @if $ns-index != null { |
| 122 | @if $ns-index < vars.$cur-namespace-index { | 125 | @if $ns-index < vars.$cur-namespace-index { |
| 123 | @return false 'Namespace "#{$block-type}" comes before current namespace #{nth(vars.$namespace-order, vars.$cur-namespace-index)}'; | 126 | @return false 'Namespace "#{$block-type}" comes before current namespace #{nth(vars.$namespace-order, vars.$cur-namespace-index)}'; |
| 124 | } | 127 | } |
| 125 | 128 | ||
| 126 | vars.$cur-namespace-index: $ns-index; | 129 | vars.$cur-namespace-index: $ns-index; |
| 127 | } | 130 | } |
| 128 | } | 131 | } |
| 129 | } | 132 | } |
| 130 | 133 | ||
| 131 | @return true ''; | 134 | @return true ''; |
| 132 | } | 135 | } |
| 133 | 136 | ||
| 134 | /// | 137 | /// |
| 135 | /// A validator that makes all BEM entities immutable. | 138 | /// A validator that makes all BEM entities immutable. |
| 136 | /// | 139 | /// |
| 137 | @function immutable-entities($type, $args, $selector, $context) { | 140 | @function immutable-entities($type, $args, $selector, $context) { |
| 138 | @if not global-variable-exists(generated-selectors, vars) { | 141 | @if not meta.global-variable-exists(generated-selectors, vars) { |
| 139 | vars.$generated-selectors: (); | 142 | vars.$generated-selectors: (); |
| 140 | } | 143 | } |
| 141 | 144 | ||
| 142 | $block-name: null; | 145 | $block-name: null; |
| 143 | $block-type: null; | 146 | $block-type: null; |
| 144 | $block-id: null; | 147 | $block-id: null; |
| 145 | 148 | ||
| 146 | @if $type == 'block' { | 149 | @if $type == 'block' { |
| 147 | $block-name: map-get($args, 'name'); | 150 | $block-name: map.get($args, 'name'); |
| 148 | $block-type: map-get($args, 'type'); | 151 | $block-type: map.get($args, 'type'); |
| 149 | } @else { | 152 | } @else { |
| 150 | $block-context: contexts.get(vars.$context-id, 'block'); | 153 | $block-context: contexts.get(vars.$context-id, 'block'); |
| 151 | $block-name: map-get(nth($block-context, 2), 'name'); | 154 | $block-name: map.get(list.nth($block-context, 2), 'name'); |
| 152 | $block-type: map-get(nth($block-context, 2), 'type'); | 155 | $block-type: map.get(list.nth($block-context, 2), 'type'); |
| 153 | } | 156 | } |
| 154 | 157 | ||
| 155 | @if $block-type != null { | 158 | @if $block-type != null { |
| 156 | $block-id: $block-name + '_' + $block-type; | 159 | $block-id: $block-name + '_' + $block-type; |
| 157 | } @else { | 160 | } @else { |
| 158 | $block-id: $block-name; | 161 | $block-id: $block-name; |
| 159 | } | 162 | } |
| 160 | 163 | ||
| 161 | @if $type == 'block' { | 164 | @if $type == 'block' { |
| 162 | @if map-has-key(vars.$generated-selectors, $block-id) { | 165 | @if map.has-key(vars.$generated-selectors, $block-id) { |
| 163 | @return false 'Entity "#{$type}" with arguments [ #{functions.map-print($args)} ] was already defined.'; | 166 | @return false 'Entity "#{$type}" with arguments [ #{functions.map-print($args)} ] was already defined.'; |
| 164 | } | 167 | } |
| 165 | 168 | ||
| 166 | vars.$generated-selectors: map-merge(vars.$generated-selectors, ($block-id: ())); | 169 | vars.$generated-selectors: map.merge(vars.$generated-selectors, ($block-id: ())); |
| 167 | } @else { | 170 | } @else { |
| 168 | $selectors: map-get(vars.$generated-selectors, $block-id); | 171 | $selectors: map.get(vars.$generated-selectors, $block-id); |
| 169 | 172 | ||
| 170 | @if index($selectors, $selector) { | 173 | @if list.index($selectors, $selector) { |
| 171 | @return false 'Entity "#{$type}" with arguments [ #{functions.map-print($args)} ] was already defined.'; | 174 | @return false 'Entity "#{$type}" with arguments [ #{functions.map-print($args)} ] was already defined.'; |
| 172 | } | 175 | } |
| 173 | 176 | ||
| 174 | $selectors: append($selectors, $selector); | 177 | $selectors: list.append($selectors, $selector); |
| 175 | 178 | ||
| 176 | vars.$generated-selectors: map-merge(vars.$generated-selectors, ($block-id: $selectors)); | 179 | vars.$generated-selectors: map.merge(vars.$generated-selectors, ($block-id: $selectors)); |
| 177 | } | 180 | } |
| 178 | 181 | ||
| 179 | @return true ''; | 182 | @return true ''; |
| 180 | } | 183 | } |
