55// Modules.
66@use ' ../../function' ;
77@use ' ../../meta' ;
8+ @use ' ../../values' ;
89@use ' ../../variant' ;
910@use ' ../name' ;
1011@use ' color' ;
1112
1213// Functions.
1314@use ' ../../list/get/get.list.function' as list-get-list ;
14- @use ' ../../list/list.insert-nth.function' as list-insert-nth ;
15- @use ' ../../list/list.invert.function' as list-invert ;
15+ @use ' ../../list/list.append.function' as list-append ;
1616@use ' ../../list/list.range.function' as list-range ;
1717@use ' ../../list/remove/remove.nth.function' as list-remove-nth ;
1818
@@ -30,45 +30,51 @@ function.$functions: map.set(function.$functions, color, name, meta.get-function
3030@function create ($values ... ) {
3131 $palette : ();
3232
33- // FEATURE: Get additional colors.
34- $variant-colors : ();
33+ // FEATURE: Prepare variant colors.
34+ $additional-colors : ();
35+
36+ // Iterate `$values`.
3537 $i : 1 ;
3638 @each $variant in $values {
3739 @if type-of ($variant ) == map {
3840 @each $class , $colors in $variant {
39- $j : 1 ;
41+ // Variant colors to add after iterate.
42+ $variant-colors : ();
43+
44+ // Iterate colors to obtain variant colors.
4045 @each $color in $colors {
46+ // Get indicator index.
47+ $indicator-index : variant .indicator-index ($color , ' +' );
48+
4149 // FEATURE: Nest colors.
42- @if variant .indicator-index ($color , ' +' ) {
43- $indicator-index : variant .indicator-index ($color , ' +' );
50+ @if $indicator-index {
4451 $color : list .set-nth (
4552 $color ,
4653 $indicator-index ,
4754 variant .indicator-remove (list .nth ($color , $indicator-index ), ' +' )
4855 );
49- $nested-colors : list-invert .invert (name .nest ($color ... ));
50- @each $nested-color in $nested-colors {
51- $colors : list-insert-nth .insert-nth ($colors , $j , $nested-color );
52- }
53-
54- $colors : list-remove-nth .nth ($colors , $j + list .length ($nested-colors ));
56+ $variant-colors : values .join ((separator: comma), $variant-colors , name .nest ($color ... ));
5557 }
5658
5759 // FEATURE: Get additional colors.
5860 @else if list .separator ($color ) == space and list .length ($color ) > 1 and list .length (list-get-list .list ($color , last )) == 0 {
61+ // Retrieve variant color.
5962 $variant-color : name .retrieve (list .nth ($color , 1 ));
60- $variant-colors : map .deep-merge (
61- $variant-colors ,
62- ($class : (map .get ($variant-color , name ): list-range .range ($color , 2 )))
63+
64+ // Add additional colors from range 2.
65+ $additional-colors : map .deep-merge (
66+ $additional-colors ,
67+ (variant .indicator-remove ($class , ' +' ): (map .get ($variant-color , name ): list-range .range ($color , 2 )))
6368 );
64- $color : list .nth ($color , 1 );
65- $colors : list .set-nth ($colors , $j , $color );
66- }
6769
68- $j : $j + 1 ;
70+ // Append color to variant colors.
71+ $variant-colors : list-append .append ($variant-colors , list .nth ($color , 1 ), comma );
72+ } @else {
73+ $variant-colors : list-append .append ($variant-colors , $color , comma );
74+ }
6975 }
7076
71- $variant : map .deep-merge ($variant , ($class : $colors ));
77+ $variant : map .deep-merge ($variant , ($class : $variant- colors ));
7278 }
7379
7480 $values : list .set-nth ($values , $i , $variant );
@@ -94,10 +100,9 @@ function.$functions: map.set(function.$functions, color, name, meta.get-function
94100 }
95101
96102 // FEATURE: Add additional colors to variant.
97- @if list .length ($variant -colors ) > 0 {
98- @each $name , $variant in $variant -colors {
103+ @if list .length ($additional -colors ) > 0 {
104+ @each $name , $variant in $additional -colors {
99105 @each $name in if (list .separator ($name ) == space , ($name ,), $name ) {
100- $name : variant .indicator-remove ($name , ' +' );
101106 @each $class , $colors in $variant {
102107 $palette : color .add ($palette , $name , $class , space , $colors ... );
103108 }
0 commit comments