beathers 5.4.0 → 5.4.1

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.
@@ -1,251 +1,251 @@
1
- @use 'sass:meta';
2
- @use 'sass:list';
3
- @use 'sass:map';
4
- @use 'sass:string';
5
- @use '../variables' as vars;
6
- @use '../settings/defaults' as defs;
7
- @use '../settings/configs' as configs;
8
-
9
- // Definitions
10
- $opacities: if(vars.$opacities != (), vars.$opacities, defs.$opacities);
11
-
12
- // Basics validations functions
13
-
14
- // @function number
15
- // @description Validates if a value is a number.
16
- // @param {*} $number - The value to validate.
17
- // @param {String | Null} $in - Optional context for the error message.
18
- // @return {*} The original value if it's a number.
19
- // @error If the value is not a number.
20
- @function number($number, $in: null) {
21
- @if $number != null and (meta.type-of($number) != 'number') {
22
- $in: if($in != null, ' | in #{$in}', '.');
23
- @error '❌ Error at "validate.number()": Please enter a valid number | Expected a number, but got "#{$number}"#{$in}';
24
- }
25
- @return $number;
26
- }
27
-
28
- // @function string
29
- // @description Validates if a value is a string.
30
- // @param {*} $string - The value to validate.
31
- // @param {String | Null} $in - Optional context for the error message.
32
- // @return {*} The original value if it's a string.
33
- // @error If the value is not a string.
34
- @function string($string, $in: null) {
35
- @if $string != null and (meta.type-of($string) != 'string') {
36
- $in: if($in != null, ' | in #{$in}', '.');
37
- @error '❌ Error at "validate.string()": Please enter a valid string | Expected a string, but got "#{$string}"#{$in}';
38
- }
39
- @return $string;
40
- }
41
-
42
- // @function boolean
43
- // @description Validates if a value is a boolean.
44
- // @param {*} $boolean - The value to validate.
45
- // @param {String | Null} $in - Optional context for the error message.
46
- // @return {*} The original value if it's a boolean.
47
- // @error If the value is not a boolean.
48
- @function boolean($boolean, $in: null) {
49
- @if $boolean != null and (meta.type-of($boolean) != 'bool') {
50
- $in: if($in != null, ' | in #{$in}', '.');
51
- @error '❌ Error at "validate.boolean()": Please enter a valid boolean | Expected a (true or false), but got "#{$boolean}"#{$in}';
52
- }
53
- @return $boolean;
54
- }
55
-
56
- // @function notNull
57
- // @description Validates if a value is not null.
58
- // @param {*} $value - The value to validate.
59
- // @param {String | Null} $in - Optional context for the error message.
60
- // @return {*} The original value if it's not null.
61
- // @error If the value is null.
62
- @function notNull($value, $in: null) {
63
- @if $value == null {
64
- $in: if($in != null, ' | in #{$in}', '.');
65
- @error '❌ Error at "validate.notNull()": Please enter a valid value | Value must not be null#{$in}';
66
- }
67
- @return $value;
68
- }
69
-
70
- // Colors validations functions
71
-
72
- // @function opacity
73
- // @description Validates if a value is a valid opacity (number between 0 and 1).
74
- // @param {*} $opacity - The value to validate.
75
- // @param {String | Null} $in - Optional context for the error message.
76
- // @return {*} The original value if it's a valid opacity.
77
- // @error If the value is not a number or not between 0 and 1.
78
- @function opacity($opacity, $in: null) {
79
- @if $opacity != null and (meta.type-of($opacity) != 'number' or $opacity < 0 or $opacity > 1) {
80
- $in: if($in != null, ' | in #{$in}', '.');
81
- @error '❌ Error at "validate.opacity()": Please enter a valid number | Opacity must be a number between 0 and 1. You entered: "#{$opacity}"#{$in}';
82
- }
83
- @return $opacity;
84
- }
85
-
86
- // @function colorMode
87
- // @description Validates if a value is a valid color mode ('light' or 'dark').
88
- // @param {*} $mode - The value to validate.
89
- // @param {String | Null} $in - Optional context for the error message.
90
- // @return {*} The original value if it's a valid color mode.
91
- // @error If the value is not 'light' or 'dark'.
92
- @function colorMode($mode, $in: null) {
93
- @if $mode != null and not($mode == 'light' or $mode == 'dark') {
94
- $in: if($in != null, ' | in #{$in}', '.');
95
- @error '❌ Error at "validate.colorMode()": Please enter a valid mode | Allowed values are "light" or "dark"#{$in}';
96
- }
97
- @return $mode;
98
- }
99
-
100
- // @function hexColor
101
- // @description Validates if a value is a valid hex color.
102
- // @param {String} $key - The key name of the color (for error messages).
103
- // @param {*} $value - The value to validate.
104
- // @param {String | Null} $in - Optional context for the error message.
105
- // @return {*} The original value if it's a valid hex color.
106
- // @error If the value is null, not a string/color, or doesn't start with '#'.
107
- @function hexColor($key, $value, $in: null) {
108
- $in: if($in != null, ' | in #{$in}', '.');
109
-
110
- @if $value == null {
111
- @error '❌ Error at "validate.hexColor()": Invalid "#{$key}" value | "#{$key}" value is null#{$in}';
112
- } @else if meta.type-of($value) != 'string' and meta.type-of($value) != 'color' {
113
- @error '❌ Error at "validate.hexColor()": Invalid "#{$key}" value | "#{$key}" value must be a string or color, got type #{meta.type-of($value)}#{$in}';
114
- } @else if meta.type-of($value) == 'string' and string.index($value, '#') != 1 {
115
- @error '❌ Error at "validate.hexColor()": Invalid "#{$key}" value | "#{$key}" value must start with "#", got "#{$value}"#{$in}';
116
- }
117
-
118
- @return $value;
119
- }
120
-
121
- // Map validations functions
122
-
123
- // @function map
124
- // @description Validates if a value is a map.
125
- // @param {*} $map - The value to validate.
126
- // @param {String | Null} $in - Optional context for the error message.
127
- // @return {*} The original value if it's a map.
128
- // @error If the value is not a map.
129
- @function map($map, $in: null) {
130
- @if meta.type-of($map) != map {
131
- $in: if($in != null, ' | in #{$in}', '.');
132
- @error '❌ Error at "validate.map()": Invalid type provided | Expected a map, but got "#{$map}" of type "#{meta.type-of($map)}"#{$in}';
133
- }
134
- @return $map;
135
- }
136
-
137
- // @function mapItem
138
- // @description Validates if a map contains a specific key.
139
- // @param {Map} $map - The map to validate.
140
- // @param {String} $key - The key to check for.
141
- // @param {List} $expectedKeys - A list of expected keys (for error messages).
142
- // @param {String | Null} $in - Optional context for the error message.
143
- // @return {Map} The original map if the key exists.
144
- // @error If the key is missing from the map.
145
- @function mapItem($map, $key, $expectedKeys, $in: null) {
146
- @if not map.has-key($map, $key) {
147
- $in: if($in != null, ' | in #{$in}', '.');
148
- @error '❌ Error at "validate.mapItem()": Missing key | Missing key "#{$key}" in the map "#{$map}" | Expected keys: "#{$expectedKeys}"#{$in}';
149
- }
150
- @return $map;
151
- }
152
-
153
- // List validations functions
154
-
155
- // @function list
156
- // @description Validates if a value is a list. If it's a single string, number, boolean, or color, it's converted to a single-item list.
157
- // @param {*} $list - The value to validate.
158
- // @param {String | Null} $in - Optional context for the error message.
159
- // @return {List} The original value if it's a list, or a new list containing the value.
160
- // @error If the value is not a list and cannot be converted.
161
- @function list($list, $in: null) {
162
- $list-type: meta.type-of($list);
163
-
164
- @if $list != null and $list-type != 'list' {
165
- @if $list-type == 'string' or $list-type == 'number' or $list-type == 'bool' or $list-type == 'color' {
166
- @return ($list);
167
- } @else {
168
- $in: if($in != null, ' | in #{$in}', '.');
169
- @error '❌ Error at "validate.list()": Please enter a valid list | Expected a list, but got "#{$list}" of type "#{$list-type}"#{$in}';
170
- }
171
- }
172
-
173
- @return $list;
174
- }
175
-
176
- // @function listItem
177
- // @description Validates if an item exists in a list.
178
- // @param {List} $list - The list to search in.
179
- // @param {*} $item - The item to search for.
180
- // @param {String | Null} $in - Optional context for the error message.
181
- // @return {*} The item if it's found in the list.
182
- // @error If the item is not found in the list.
183
- @function listItem($list, $item, $in: null) {
184
- @if not list.index($list, $item) {
185
- $in: if($in != null, ' | in #{$in}', '.');
186
- @error '❌ Error at "validate.listItem()": Invalid item | Missing item "#{$item}" not found in the list "#{$list}"#{$in}';
187
- }
188
- @return $item;
189
- }
190
-
191
- // Custom colors validations functions
192
-
193
- // @function colorMap
194
- // @description Validates a map of colors, ensuring each color has 'light' and 'dark' variants that are valid hex colors.
195
- // @param {Map} $map - The color map to validate.
196
- // @param {String | Null} $in - Optional context for the error message.
197
- // @return {Map} The original map if all colors and variants are valid.
198
- // @error If the map structure is incorrect or color values are invalid.
199
- @function colorMap($map, $in: null) {
200
- $mapVal: map($map);
201
-
202
- @each $key, $value in $map {
203
- $mapVal: map($value, $in);
204
- $lightKey: colorMode($value, $in);
205
- $darkKey: colorMode($value, $in);
206
- $light: hexColor('#{$key}.light', map.get($value, 'light'), $in);
207
- $dark: hexColor('#{$key}.dark', map.get($value, 'dark'), $in);
208
- }
209
-
210
- @return $map;
211
- }
212
-
213
- // @function colorOpacity
214
- // @description Validates if an opacity value is one of the predefined opacities in `$opacities`.
215
- // @param {*} $opacity - The opacity value to validate.
216
- // @param {String | Null} $in - Optional context for the error message.
217
- // @return {*} The original opacity value if it's valid.
218
- // @error If the opacity value is not in `$opacities`.
219
- @function colorOpacity($opacity, $in: null) {
220
- @if $opacity != null and $opacity != 100 and not(list.index($opacities, $opacity)) {
221
- $in: if($in != null, ' | in #{$in}', '.');
222
- @error '❌ Error at "validate.colorOpacity()": Invalid color property value | Expected one of (#{$opacities}), but got "#{$opacity}"#{$in}';
223
- }
224
- @return $opacity;
225
- }
226
-
227
- // @function colorProperty
228
- // @description Validates if a color property value is one of the allowed values in `configs.$colorsPropertiesMap`.
229
- // @param {*} $value - The color property value to validate.
230
- // @param {String | Null} $in - Optional context for the error message.
231
- // @return {*} The original value if it's a valid color property.
232
- // @error If the value is not an allowed color property.
233
- @function colorProperty($value, $in: null) {
234
- @if $value != null and not(list.index(map.values(configs.$colorsPropertiesMap), $value)) {
235
- @error '❌ Error at "validate.colorProperty()": Invalid color property value | Expected one of #{map.values(configs.$colorsPropertiesMap)}, but got "#{$value}"#{$in}';
236
- }
237
- @return $value;
238
- }
239
-
240
- // @function colorClass
241
- // @description Validates if a color class value is one of the allowed keys in `configs.$colorsPropertiesMap`.
242
- // @param {*} $value - The color class value to validate.
243
- // @param {String | Null} $in - Optional context for the error message.
244
- // @return {*} The original value if it's a valid color class.
245
- // @error If the value is not an allowed color class.
246
- @function colorClass($value, $in: null) {
247
- @if $value != null and not($value == null or list.index(map.keys(configs.$colorsPropertiesMap), $value)) {
248
- @error '❌ Error at "validate.colorClass()": Invalid color class value | Expected one of #{map.keys(configs.$colorsPropertiesMap)}, but got "#{$value}"#{$in}';
249
- }
250
- @return $value;
251
- }
1
+ @use 'sass:meta';
2
+ @use 'sass:list';
3
+ @use 'sass:map';
4
+ @use 'sass:string';
5
+ @use '../variables' as vars;
6
+ @use '../settings/defaults' as defs;
7
+ @use '../settings/configs' as configs;
8
+
9
+ // Definitions
10
+ $opacities: if(vars.$opacities != (), vars.$opacities, defs.$opacities);
11
+
12
+ // Basics validations functions
13
+
14
+ // @function number
15
+ // @description Validates if a value is a number.
16
+ // @param {*} $number - The value to validate.
17
+ // @param {String | Null} $in - Optional context for the error message.
18
+ // @return {*} The original value if it's a number.
19
+ // @error If the value is not a number.
20
+ @function number($number, $in: null) {
21
+ @if $number != null and (meta.type-of($number) != 'number') {
22
+ $in: if($in != null, ' | in #{$in}', '.');
23
+ @error '❌ Error at "validate.number()": Please enter a valid number | Expected a number, but got "#{$number}"#{$in}';
24
+ }
25
+ @return $number;
26
+ }
27
+
28
+ // @function string
29
+ // @description Validates if a value is a string.
30
+ // @param {*} $string - The value to validate.
31
+ // @param {String | Null} $in - Optional context for the error message.
32
+ // @return {*} The original value if it's a string.
33
+ // @error If the value is not a string.
34
+ @function string($string, $in: null) {
35
+ @if $string != null and (meta.type-of($string) != 'string') {
36
+ $in: if($in != null, ' | in #{$in}', '.');
37
+ @error '❌ Error at "validate.string()": Please enter a valid string | Expected a string, but got "#{$string}"#{$in}';
38
+ }
39
+ @return $string;
40
+ }
41
+
42
+ // @function boolean
43
+ // @description Validates if a value is a boolean.
44
+ // @param {*} $boolean - The value to validate.
45
+ // @param {String | Null} $in - Optional context for the error message.
46
+ // @return {*} The original value if it's a boolean.
47
+ // @error If the value is not a boolean.
48
+ @function boolean($boolean, $in: null) {
49
+ @if $boolean != null and (meta.type-of($boolean) != 'bool') {
50
+ $in: if($in != null, ' | in #{$in}', '.');
51
+ @error '❌ Error at "validate.boolean()": Please enter a valid boolean | Expected a (true or false), but got "#{$boolean}"#{$in}';
52
+ }
53
+ @return $boolean;
54
+ }
55
+
56
+ // @function notNull
57
+ // @description Validates if a value is not null.
58
+ // @param {*} $value - The value to validate.
59
+ // @param {String | Null} $in - Optional context for the error message.
60
+ // @return {*} The original value if it's not null.
61
+ // @error If the value is null.
62
+ @function notNull($value, $in: null) {
63
+ @if $value == null {
64
+ $in: if($in != null, ' | in #{$in}', '.');
65
+ @error '❌ Error at "validate.notNull()": Please enter a valid value | Value must not be null#{$in}';
66
+ }
67
+ @return $value;
68
+ }
69
+
70
+ // Colors validations functions
71
+
72
+ // @function opacity
73
+ // @description Validates if a value is a valid opacity (number between 0 and 1).
74
+ // @param {*} $opacity - The value to validate.
75
+ // @param {String | Null} $in - Optional context for the error message.
76
+ // @return {*} The original value if it's a valid opacity.
77
+ // @error If the value is not a number or not between 0 and 1.
78
+ @function opacity($opacity, $in: null) {
79
+ @if $opacity != null and (meta.type-of($opacity) != 'number' or $opacity < 0 or $opacity > 1) {
80
+ $in: if($in != null, ' | in #{$in}', '.');
81
+ @error '❌ Error at "validate.opacity()": Please enter a valid number | Opacity must be a number between 0 and 1. You entered: "#{$opacity}"#{$in}';
82
+ }
83
+ @return $opacity;
84
+ }
85
+
86
+ // @function colorMode
87
+ // @description Validates if a value is a valid color mode ('light' or 'dark').
88
+ // @param {*} $mode - The value to validate.
89
+ // @param {String | Null} $in - Optional context for the error message.
90
+ // @return {*} The original value if it's a valid color mode.
91
+ // @error If the value is not 'light' or 'dark'.
92
+ @function colorMode($mode, $in: null) {
93
+ @if $mode != null and not($mode == 'light' or $mode == 'dark') {
94
+ $in: if($in != null, ' | in #{$in}', '.');
95
+ @error '❌ Error at "validate.colorMode()": Please enter a valid mode | Allowed values are "light" or "dark"#{$in}';
96
+ }
97
+ @return $mode;
98
+ }
99
+
100
+ // @function hexColor
101
+ // @description Validates if a value is a valid hex color.
102
+ // @param {String} $key - The key name of the color (for error messages).
103
+ // @param {*} $value - The value to validate.
104
+ // @param {String | Null} $in - Optional context for the error message.
105
+ // @return {*} The original value if it's a valid hex color.
106
+ // @error If the value is null, not a string/color, or doesn't start with '#'.
107
+ @function hexColor($key, $value, $in: null) {
108
+ $in: if($in != null, ' | in #{$in}', '.');
109
+
110
+ @if $value == null {
111
+ @error '❌ Error at "validate.hexColor()": Invalid "#{$key}" value | "#{$key}" value is null#{$in}';
112
+ } @else if meta.type-of($value) != 'string' and meta.type-of($value) != 'color' {
113
+ @error '❌ Error at "validate.hexColor()": Invalid "#{$key}" value | "#{$key}" value must be a string or color, got type #{meta.type-of($value)}#{$in}';
114
+ } @else if meta.type-of($value) == 'string' and string.index($value, '#') != 1 {
115
+ @error '❌ Error at "validate.hexColor()": Invalid "#{$key}" value | "#{$key}" value must start with "#", got "#{$value}"#{$in}';
116
+ }
117
+
118
+ @return $value;
119
+ }
120
+
121
+ // Map validations functions
122
+
123
+ // @function map
124
+ // @description Validates if a value is a map.
125
+ // @param {*} $map - The value to validate.
126
+ // @param {String | Null} $in - Optional context for the error message.
127
+ // @return {*} The original value if it's a map.
128
+ // @error If the value is not a map.
129
+ @function map($map, $in: null) {
130
+ @if meta.type-of($map) != map {
131
+ $in: if($in != null, ' | in #{$in}', '.');
132
+ @error '❌ Error at "validate.map()": Invalid type provided | Expected a map, but got "#{$map}" of type "#{meta.type-of($map)}"#{$in}';
133
+ }
134
+ @return $map;
135
+ }
136
+
137
+ // @function mapItem
138
+ // @description Validates if a map contains a specific key.
139
+ // @param {Map} $map - The map to validate.
140
+ // @param {String} $key - The key to check for.
141
+ // @param {List} $expectedKeys - A list of expected keys (for error messages).
142
+ // @param {String | Null} $in - Optional context for the error message.
143
+ // @return {Map} The original map if the key exists.
144
+ // @error If the key is missing from the map.
145
+ @function mapItem($map, $key, $expectedKeys, $in: null) {
146
+ @if not map.has-key($map, $key) {
147
+ $in: if($in != null, ' | in #{$in}', '.');
148
+ @error '❌ Error at "validate.mapItem()": Missing key | Missing key "#{$key}" in the map "#{$map}" | Expected keys: "#{$expectedKeys}"#{$in}';
149
+ }
150
+ @return $map;
151
+ }
152
+
153
+ // List validations functions
154
+
155
+ // @function list
156
+ // @description Validates if a value is a list. If it's a single string, number, boolean, or color, it's converted to a single-item list.
157
+ // @param {*} $list - The value to validate.
158
+ // @param {String | Null} $in - Optional context for the error message.
159
+ // @return {List} The original value if it's a list, or a new list containing the value.
160
+ // @error If the value is not a list and cannot be converted.
161
+ @function list($list, $in: null) {
162
+ $list-type: meta.type-of($list);
163
+
164
+ @if $list != null and $list-type != 'list' {
165
+ @if $list-type == 'string' or $list-type == 'number' or $list-type == 'bool' or $list-type == 'color' {
166
+ @return ($list);
167
+ } @else {
168
+ $in: if($in != null, ' | in #{$in}', '.');
169
+ @error '❌ Error at "validate.list()": Please enter a valid list | Expected a list, but got "#{$list}" of type "#{$list-type}"#{$in}';
170
+ }
171
+ }
172
+
173
+ @return $list;
174
+ }
175
+
176
+ // @function listItem
177
+ // @description Validates if an item exists in a list.
178
+ // @param {List} $list - The list to search in.
179
+ // @param {*} $item - The item to search for.
180
+ // @param {String | Null} $in - Optional context for the error message.
181
+ // @return {*} The item if it's found in the list.
182
+ // @error If the item is not found in the list.
183
+ @function listItem($list, $item, $in: null) {
184
+ @if not list.index($list, $item) {
185
+ $in: if($in != null, ' | in #{$in}', '.');
186
+ @error '❌ Error at "validate.listItem()": Invalid item | Missing item "#{$item}" not found in the list "#{$list}"#{$in}';
187
+ }
188
+ @return $item;
189
+ }
190
+
191
+ // Custom colors validations functions
192
+
193
+ // @function colorMap
194
+ // @description Validates a map of colors, ensuring each color has 'light' and 'dark' variants that are valid hex colors.
195
+ // @param {Map} $map - The color map to validate.
196
+ // @param {String | Null} $in - Optional context for the error message.
197
+ // @return {Map} The original map if all colors and variants are valid.
198
+ // @error If the map structure is incorrect or color values are invalid.
199
+ @function colorMap($map, $in: null) {
200
+ $mapVal: map($map);
201
+
202
+ @each $key, $value in $map {
203
+ $mapVal: map($value, $in);
204
+ $lightKey: colorMode($value, $in);
205
+ $darkKey: colorMode($value, $in);
206
+ $light: hexColor('#{$key}.light', map.get($value, 'light'), $in);
207
+ $dark: hexColor('#{$key}.dark', map.get($value, 'dark'), $in);
208
+ }
209
+
210
+ @return $map;
211
+ }
212
+
213
+ // @function colorOpacity
214
+ // @description Validates if an opacity value is one of the predefined opacities in `$opacities`.
215
+ // @param {*} $opacity - The opacity value to validate.
216
+ // @param {String | Null} $in - Optional context for the error message.
217
+ // @return {*} The original opacity value if it's valid.
218
+ // @error If the opacity value is not in `$opacities`.
219
+ @function colorOpacity($opacity, $in: null) {
220
+ @if $opacity != null and $opacity != 100 and not(list.index($opacities, $opacity)) {
221
+ $in: if($in != null, ' | in #{$in}', '.');
222
+ @error '❌ Error at "validate.colorOpacity()": Invalid color property value | Expected one of (#{$opacities}), but got "#{$opacity}"#{$in}';
223
+ }
224
+ @return $opacity;
225
+ }
226
+
227
+ // @function colorProperty
228
+ // @description Validates if a color property value is one of the allowed values in `configs.$colorsPropertiesMap`.
229
+ // @param {*} $value - The color property value to validate.
230
+ // @param {String | Null} $in - Optional context for the error message.
231
+ // @return {*} The original value if it's a valid color property.
232
+ // @error If the value is not an allowed color property.
233
+ @function colorProperty($value, $in: null) {
234
+ @if $value != null and not(list.index(map.values(configs.$colorsPropertiesMap), $value)) {
235
+ @error '❌ Error at "validate.colorProperty()": Invalid color property value | Expected one of #{map.values(configs.$colorsPropertiesMap)}, but got "#{$value}"#{$in}';
236
+ }
237
+ @return $value;
238
+ }
239
+
240
+ // @function colorClass
241
+ // @description Validates if a color class value is one of the allowed keys in `configs.$colorsPropertiesMap`.
242
+ // @param {*} $value - The color class value to validate.
243
+ // @param {String | Null} $in - Optional context for the error message.
244
+ // @return {*} The original value if it's a valid color class.
245
+ // @error If the value is not an allowed color class.
246
+ @function colorClass($value, $in: null) {
247
+ @if $value != null and not($value == null or list.index(map.keys(configs.$colorsPropertiesMap), $value)) {
248
+ @error '❌ Error at "validate.colorClass()": Invalid color class value | Expected one of #{map.keys(configs.$colorsPropertiesMap)}, but got "#{$value}"#{$in}';
249
+ }
250
+ @return $value;
251
+ }