From f0f84513f8efe533b6ee670a6f1a0c074387b2ec Mon Sep 17 00:00:00 2001 From: Volpeon Date: Wed, 13 Aug 2025 12:01:46 +0200 Subject: Make use of SASS modules --- src/bem/_block.scss | 250 ++++++++++++++++++++++++++-------------------------- 1 file changed, 127 insertions(+), 123 deletions(-) (limited to 'src/bem/_block.scss') diff --git a/src/bem/_block.scss b/src/bem/_block.scss index cfa9f33..a4b2a47 100644 --- a/src/bem/_block.scss +++ b/src/bem/_block.scss @@ -4,6 +4,10 @@ /// @access public //// +@use 'sass:list'; +@use 'sass:map'; +@use 'sass:meta'; +@use 'sass:selector'; @use './validators'; @use './vars'; @use './functions' as bemfunctions; @@ -37,34 +41,34 @@ /// } /// @mixin block($name, $type: null) { - $result: block($name, $type); - $selector: nth($result, 1); - $context: nth($result, 2); - - @include validators.validate( - 'block', - (name: $name, type: $type), - $selector, - $context - ); - - @if $type != null { - vars.$blocks: append(vars.$blocks, $name + '_' + $type); - } @else { - vars.$blocks: append(vars.$blocks, $name); - } - - @include contexts.push(vars.$context-id, $context...); - @at-root #{$selector} { - @if $type != null { - @layer #{$type} { - @content; - } - } @else { - @content; - } - } - @include contexts.pop(vars.$context-id); + $result: block($name, $type); + $selector: list.nth($result, 1); + $context: list.nth($result, 2); + + @include validators.validate( + 'block', + (name: $name, type: $type), + $selector, + $context + ); + + @if $type != null { + vars.$blocks: list.append(vars.$blocks, $name + '_' + $type); + } @else { + vars.$blocks: list.append(vars.$blocks, $name); + } + + @include contexts.push(vars.$context-id, $context...); + @at-root #{$selector} { + @if $type != null { + @layer #{$type} { + @content; + } + } @else { + @content; + } + } + @include contexts.pop(vars.$context-id); } /// @@ -75,47 +79,47 @@ /// @see {mixin} block /// @function block($name, $type: null) { - // - // Possible outcomes: - // - ({b,e,m,s}) block - // - - $noop: contexts.assert-stack-count(vars.$context-id, vars.$max-depth); - - $selector: null; - $base-selector: null; - - @if $type != null { - $namespace: map-get(vars.$namespaces, $type); - - @if not $namespace { - @error '"#{$type}" is not a valid type.'; - } - - $base-selector: selector-parse('.' + $namespace + '-' + $name); - - @if $type != 'theme' or & { - $selector: $base-selector; - } @else if not & { - $selector: bemfunctions.theme-selector($name); - } - } @else { - $base-selector: selector-parse('.' + $name); - $selector: $base-selector; - } - - @if & { - $selector: selector-nest(&, $selector); - } - - $context: 'block', ( - 'name': $name, - 'type': $type, - 'selector': $selector, - 'base-selector': $base-selector - ); - - @return $selector $context; + // + // Possible outcomes: + // - ({b,e,m,s}) block + // + + $noop: contexts.assert-stack-count(vars.$context-id, vars.$max-depth); + + $selector: null; + $base-selector: null; + + @if $type != null { + $namespace: map.get(vars.$namespaces, $type); + + @if not $namespace { + @error '"#{$type}" is not a valid type.'; + } + + $base-selector: selector.parse('.' + $namespace + '-' + $name); + + @if $type != 'theme' or & { + $selector: $base-selector; + } @else if not & { + $selector: bemfunctions.theme-selector($name); + } + } @else { + $base-selector: selector.parse('.' + $name); + $selector: $base-selector; + } + + @if & { + $selector: selector.nest(&, $selector); + } + + $context: 'block', ( + 'name': $name, + 'type': $type, + 'selector': $selector, + 'base-selector': $base-selector + ); + + @return $selector $context; } /// @@ -126,9 +130,9 @@ /// @content /// @mixin object($name) { - @include block($name, 'object') { - @content; - } + @include block($name, 'object') { + @content; + } } /// @@ -139,7 +143,7 @@ /// @see {mixin} object /// @function object($name) { - @return block($name, 'object'); + @return block($name, 'object'); } /// @@ -150,9 +154,9 @@ /// @content /// @mixin component($name) { - @include block($name, 'component') { - @content; - } + @include block($name, 'component') { + @content; + } } /// @@ -163,7 +167,7 @@ /// @see {mixin} component /// @function component($name) { - @return block($name, 'component'); + @return block($name, 'component'); } /// @@ -174,9 +178,9 @@ /// @content /// @mixin layout($name) { - @include block($name, 'layout') { - @content; - } + @include block($name, 'layout') { + @content; + } } /// @@ -187,7 +191,7 @@ /// @see {mixin} layout /// @function layout($name) { - @return block($name, 'layout'); + @return block($name, 'layout'); } /// @@ -198,9 +202,9 @@ /// @content /// @mixin utility($name) { - @include block($name, 'utility') { - @content; - } + @include block($name, 'utility') { + @content; + } } /// @@ -211,7 +215,7 @@ /// @see {mixin} utility /// @function utility($name) { - @return block($name, 'utility'); + @return block($name, 'utility'); } /// @@ -222,9 +226,9 @@ /// @content /// @mixin scope($name) { - @include block($name, 'scope') { - @content; - } + @include block($name, 'scope') { + @content; + } } /// @@ -235,7 +239,7 @@ /// @see {mixin} scope /// @function scope($name) { - @return block($name, 'scope'); + @return block($name, 'scope'); } /// @@ -246,9 +250,9 @@ /// @content /// @mixin theme($name) { - @include block($name, 'theme') { - @content; - } + @include block($name, 'theme') { + @content; + } } /// @@ -259,7 +263,7 @@ /// @see {mixin} theme /// @function theme($name) { - @return block($name, 'theme'); + @return block($name, 'theme'); } /// @@ -270,9 +274,9 @@ /// @content /// @mixin js($name) { - @include block($name, 'js') { - @content; - } + @include block($name, 'js') { + @content; + } } /// @@ -283,7 +287,7 @@ /// @see {mixin} js /// @function js($name) { - @return block($name, 'js'); + @return block($name, 'js'); } /// @@ -294,9 +298,9 @@ /// @content /// @mixin qa($name) { - @include block($name, 'qa') { - @content; - } + @include block($name, 'qa') { + @content; + } } /// @@ -307,7 +311,7 @@ /// @see {mixin} qa /// @function qa($name) { - @return block($name, 'qa'); + @return block($name, 'qa'); } /// @@ -318,9 +322,9 @@ /// @content /// @mixin hack($name) { - @include block($name, 'hack') { - @content; - } + @include block($name, 'hack') { + @content; + } } /// @@ -331,7 +335,7 @@ /// @see {mixin} hack /// @function hack($name) { - @return block($name, 'hack'); + @return block($name, 'hack'); } /// @@ -383,22 +387,22 @@ /// // Compilation will fail because c-someBlock is defined after c-anotherBlock__elem /// @mixin composed-of($block, $blocks...) { - @each $block in functions.list-prepend($blocks, $block) { - @if type-of($block) == string { - @if not index(vars.$blocks, $block) { - @error 'Block "#{$block}" does not exist.'; - } - } @else { - $name: nth($block, 1); - $type: nth($block, 2); - - @if not map-get(vars.$namespaces, $type) { - @error '"#{$type}" is not a valid type.'; - } - - @if not index(vars.$blocks, $name + '_' + $type) { - @error 'Block "#{$name}" does not exist.'; - } - } - } + @each $block in functions.list-prepend($blocks, $block) { + @if meta.type-of($block) == string { + @if not list.index(vars.$blocks, $block) { + @error 'Block "#{$block}" does not exist.'; + } + } @else { + $name: list.nth($block, 1); + $type: list.nth($block, 2); + + @if not map.get(vars.$namespaces, $type) { + @error '"#{$type}" is not a valid type.'; + } + + @if not list.index(vars.$blocks, $name + '_' + $type) { + @error 'Block "#{$name}" does not exist.'; + } + } + } } -- cgit v1.2.3-70-g09d2