oo-loop 1.0.2 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # Loop changelog
2
2
 
3
+ ## 1.0.3: 2022-04-05
4
+
5
+ ### Feature
6
+ - Set up function to return the alias information
7
+ ### Fixes
8
+ - Return the reference value and send a warning if the alias function cannot be performed
9
+
3
10
  ## 1.0.2: 2022-04-04
4
11
 
5
12
  ### Fixes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oo-loop",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "Loop CSS framework, flexible and expressive CSS",
5
5
  "keywords": [
6
6
  "scss",
@@ -2,12 +2,12 @@ $ooAlias: (
2
2
  (
3
3
  name: 'ooDarken',
4
4
  function: 'darken',
5
- params: ('color', 'number'),
5
+ paramType: ('color', 'number'),
6
6
  ),
7
7
  (
8
8
  name: 'ooLighten',
9
9
  function: 'lighten',
10
- params: ('color', 'number'),
10
+ paramType: ('color', 'number'),
11
11
  ),
12
12
  );
13
13
 
@@ -48,49 +48,79 @@ $ooAlias: (
48
48
  @return $isAlias;
49
49
  }
50
50
 
51
+ /// getAliasInfo
52
+ /// retrieve the alias information
53
+ /// @param string $aliasFunction The complete alias function
54
+ /// @return map|null
55
+
56
+ @function getAliasInfo($aliasFunction) {
57
+ @each $alias in $ooAlias {
58
+ $aliasName: getMapValue($alias, 'name');
59
+ $aliasLength: str-length($aliasName);
60
+ $aliasFunctionName: stripSpaces(str-slice($aliasFunction, 1, $aliasLength));
61
+
62
+ @if $aliasFunctionName == $aliasName {
63
+ $currentAlias: $alias;
64
+ $functionName: getMapValue($alias, 'function');
65
+
66
+ @return (
67
+ name: $aliasName,
68
+ nameLength: $aliasLength,
69
+ function: if(function-exists('get-function'), get-function($functionName), $functionName),
70
+ functionName: $functionName,
71
+ paramType: getMapValue($alias, 'paramType'),
72
+ );
73
+ }
74
+ }
75
+
76
+ @return null;
77
+ }
51
78
 
52
79
  /// getAliasValue
53
80
  /// retrieve the value of an alias function
54
- /// @param string $string The complete alias function
81
+ /// @param string $aliasFunction The complete alias function
55
82
  /// @param string $value Value of the 1st parameter
56
83
  /// @return bool
57
84
 
58
- /// @todo review, simplify
59
-
60
- @function getAliasValue($string, $param:null) {
61
- $currentAlias: null;
85
+ @function getAliasValue($aliasFunction, $value:null) {
86
+ $name: null;
87
+ $paramType: null;
62
88
  $function: null;
63
- $params: split(',', inspect($string));
64
-
89
+ $params: split(',', inspect($aliasFunction));
65
90
  $param1: nth($params, 1);
66
- @each $alias in $ooAlias {
67
- $aliasName: getMapValue($alias, 'name');
68
- $aliasLength: str-length($aliasName);
69
- @if str-slice($string, 1, $aliasLength) == $aliasName {
70
- $currentAlias: $alias;
71
- $function: getMapValue($alias, 'function');
72
- $param1: stripSpaces(str-slice($param1, $aliasLength + 2, str-length($param1)));
73
- @if function-exists('get-function') {
74
- $function: get-function($function);
75
- }
76
- }
91
+
92
+ $aliasInfo: getAliasInfo($aliasFunction);
93
+
94
+ @if $aliasInfo != null {
95
+ $name: getMapValue($aliasInfo, 'name');
96
+ $function: getMapValue($aliasInfo, 'function');
97
+ $paramType: getMapValue($aliasInfo, 'paramType');
98
+ $param1: stripSpaces(str-slice($param1, getMapValue($aliasInfo, 'nameLength') + 2, str-length($param1)));
77
99
  }
78
100
 
79
- $param1: if($param == null, $param1, $param);
101
+ $param1: if($value==null, $param1, $value);
80
102
 
81
103
  @if length($params) > 1 {
82
- $paramLeft: removeInList($params, 1);
83
- $param2: stripSpaces(str-slice(#{$paramLeft}, 1, -2));
104
+ $param2: stripSpaces(str-slice(#{nth($params, 2)}, 1, -2));
105
+
106
+ $param1Type: null;
107
+ $param2Type: null;
84
108
 
85
- $currentAliasParams: getMapValue($currentAlias, 'params');
86
- $param1: toType(nth($currentAliasParams, 1), $param1);
87
- $param2: toType(nth($currentAliasParams, 2), $param2);
109
+ @if $paramType != null {
110
+ $param1Type: nth($paramType, 1);
111
+ $param2Type: nth($paramType, 2);
112
+ }
88
113
 
89
- @if type-of($param1) != nth($currentAliasParams, 1) or type-of($param2) != nth($currentAliasParams, 2) {
90
- @return $string;
114
+ $param1: toType($param1Type, $param1);
115
+ $param2: toType($param2Type, $param2);
116
+
117
+ @if type-of($param1) != $param1Type or type-of($param2) != $param2Type {
118
+ @warn('The alias `#{$aliasFunction}` is targetting `#{$value}` and therefore cannot be used with the sass function `#{getMapValue($aliasInfo, 'functionName')}`');
119
+ @return $value;
91
120
  }
92
121
 
93
122
  @return call($function, $param1, $param2);
94
123
  }
124
+
95
125
  @return call($function, $param1);
96
- }
126
+ }