sass-apca 1.1.0 → 1.2.0
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/README.md +19 -2
- package/apca.scss +37 -17
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -50,6 +50,24 @@ body {
|
|
|
50
50
|
}
|
|
51
51
|
```
|
|
52
52
|
|
|
53
|
+
### Warning levels configuration
|
|
54
|
+
|
|
55
|
+
Control the verbosity of the warnings when loading the module, default is `90`.
|
|
56
|
+
|
|
57
|
+
To *only warn for critical issues* (e.g., lower than 45):
|
|
58
|
+
```scss
|
|
59
|
+
@use "sass-apca/apca" with (
|
|
60
|
+
$warning-threshold: 45
|
|
61
|
+
);
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
To *disable all warnings*:
|
|
65
|
+
```scss
|
|
66
|
+
@use "sass-apca/apca" with (
|
|
67
|
+
$warning-threshold: 0
|
|
68
|
+
);
|
|
69
|
+
```
|
|
70
|
+
|
|
53
71
|
## About contrast levels
|
|
54
72
|
These general levels are appropriate for use by themselves, without the need to reference a lookup table. APCA reports contrast as an L<sup>c</sup> value (lightness contrast) from L<sup>c</sup> 0 to L<sup>c</sup> 105+. For accessibility, consider L<sup>c</sup> 15 the point of invisibility for many users, and L<sup>c</sup> 90 is preferred for body text. [^2]
|
|
55
73
|
|
|
@@ -61,7 +79,6 @@ These general levels are appropriate for use by themselves, without the need to
|
|
|
61
79
|
- **L<sup>c</sup> 15** • The absolute minimum for any non-text that needs to be discernible and differentiable, and is no less than 6px in its smallest dimension. This may include disabled large buttons. Designers should treat anything below this level as invisible, as it will not be visible for many users. This minimum level should be avoided for any items important to the use, understanding, or interaction of the site.
|
|
62
80
|
|
|
63
81
|
## Roadmap
|
|
64
|
-
- Polarity function for figuring out if light or dark text has a higher contrast on any given background
|
|
65
82
|
- Compliance check for getting the current level of compliance of a given contrast ratio
|
|
66
83
|
|
|
67
84
|
|
|
@@ -71,4 +88,4 @@ These general levels are appropriate for use by themselves, without the need to
|
|
|
71
88
|
Code published in this repository licensed under the [MIT license](https://github.com/gfellerph/sass-apca/blob/main/LICENSE).
|
|
72
89
|
|
|
73
90
|
[^1]: APCA contrast calculator (https://www.myndex.com/APCA/)
|
|
74
|
-
[^2]: Why APCA (https://git.apcacontrast.com/documentation/WhyAPCA#use-case-ranges)
|
|
91
|
+
[^2]: Why APCA (https://git.apcacontrast.com/documentation/WhyAPCA#use-case-ranges)
|
package/apca.scss
CHANGED
|
@@ -10,6 +10,24 @@
|
|
|
10
10
|
//
|
|
11
11
|
// -------------------
|
|
12
12
|
|
|
13
|
+
/**
|
|
14
|
+
* Configuration: Warning Threshold
|
|
15
|
+
*
|
|
16
|
+
* Defines the APCA contrast level below which the library will output warnings.
|
|
17
|
+
* The default is 90, which is the preferred level for fluent body text.
|
|
18
|
+
*
|
|
19
|
+
* To disable all warnings, set this value to 0.
|
|
20
|
+
* To only receive warnings for critical contrast issues, set this to a lower value (e.g., 30 or 45).
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```
|
|
24
|
+
* @use "sass-apca" with (
|
|
25
|
+
* $warning-threshold: 0
|
|
26
|
+
* );
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
$warning-threshold: 90 !default;
|
|
30
|
+
|
|
13
31
|
// Powercurve exponents
|
|
14
32
|
$_Strc: 2.4;
|
|
15
33
|
$_Ntx: 0.57;
|
|
@@ -30,9 +48,9 @@ $_greenMultiplier: 0.7151522;
|
|
|
30
48
|
$_blueMultiplier: 0.072175;
|
|
31
49
|
|
|
32
50
|
@function _luminance($color) {
|
|
33
|
-
$red: color.
|
|
34
|
-
$green: color.
|
|
35
|
-
$blue: color.
|
|
51
|
+
$red: color.channel($color, "red", $space: rgb);
|
|
52
|
+
$green: color.channel($color, "green", $space: rgb);
|
|
53
|
+
$blue: color.channel($color, "blue", $space: rgb);
|
|
36
54
|
|
|
37
55
|
$redLuminance: math.pow(math.div($red, 255), $_Strc) * $_redMultiplier;
|
|
38
56
|
$greenLuminance: math.pow(math.div($green, 255), $_Strc) * $_greenMultiplier;
|
|
@@ -69,7 +87,7 @@ $_blueMultiplier: 0.072175;
|
|
|
69
87
|
* @param {color} $textColor Text color
|
|
70
88
|
* @param {color} $backgroundColor Background color
|
|
71
89
|
*
|
|
72
|
-
* @return {number} A number between -108 and 107 representing the lightness contrast
|
|
90
|
+
* @return {number} A number between -108 and 107 representing the lightness contrast
|
|
73
91
|
*/
|
|
74
92
|
@function contrast($textColor, $backgroundColor) {
|
|
75
93
|
@if (meta.type-of($textColor) != 'color') {
|
|
@@ -113,7 +131,7 @@ $_blueMultiplier: 0.072175;
|
|
|
113
131
|
@if (meta.type-of($backgroundColor) != 'color') {
|
|
114
132
|
@error "Type Error: apca.recommend-text-color expects a color as third argument but received #{meta.type-of($darkColor)}. Please provide a valid color.";
|
|
115
133
|
}
|
|
116
|
-
|
|
134
|
+
|
|
117
135
|
$lightContrast: math.abs(contrast($lightColor, $backgroundColor));
|
|
118
136
|
$darkContrast: math.abs(contrast($darkColor, $backgroundColor));
|
|
119
137
|
$contrastColor: null;
|
|
@@ -127,18 +145,20 @@ $_blueMultiplier: 0.072175;
|
|
|
127
145
|
$bestContrast: $lightContrast
|
|
128
146
|
}
|
|
129
147
|
|
|
130
|
-
@if ($bestContrast <
|
|
131
|
-
@
|
|
132
|
-
|
|
133
|
-
@
|
|
134
|
-
|
|
135
|
-
@
|
|
136
|
-
|
|
137
|
-
@
|
|
138
|
-
|
|
139
|
-
@
|
|
140
|
-
|
|
141
|
-
@
|
|
148
|
+
@if ($bestContrast < $warning-threshold) {
|
|
149
|
+
@if ($bestContrast < 15) {
|
|
150
|
+
@warn "Your best contrast is #{$bestContrast}. This is lower than 15, the absolute minimum for any non-text that needs to be discernible and differentiable, and is no less than 6px in its smallest dimension. This may include disabled large buttons. Designers should treat anything below this level as invisible, as it will not be visible for many users. This minimum level should be avoided for any items important to the use, understanding, or interaction of the site.";
|
|
151
|
+
} @else if ($bestContrast < 30) {
|
|
152
|
+
@warn "Your best contrast is #{$bestContrast}. This is lower than 30, the absolute minimum for any text not listed above. This includes placeholder text and disabled element text. This is also the minimum for large/solid semantic & understandable non-text elements.";
|
|
153
|
+
} @else if ($bestContrast < 45) {
|
|
154
|
+
@warn "Your best contrast is #{$bestContrast}. This is lower than 45, the minimum for larger, heavier text (36px normal weight or 24px bold) such as headlines. This is also the minimum for pictograms with fine details.";
|
|
155
|
+
} @else if ($bestContrast < 60) {
|
|
156
|
+
@warn "Your best contrast is #{$bestContrast}. This is lower than 60, the minimum level recommended for content text that is not body, column, or block text. In other words, text you want people to read. The minimums: 24px normal weight (400) or 16px/700 (bold). These values based on the reference font Helvetica.";
|
|
157
|
+
} @else if ($bestContrast < 75) {
|
|
158
|
+
@warn "Your best contrast is #{$bestContrast}. This is lower than 75, the minimum level for columns of body text with a font no smaller than 18px/400. Lc 75 should be considered a minimum for text where readability is important.";
|
|
159
|
+
} @else if ($bestContrast < 90) {
|
|
160
|
+
@warn "Your best contrast is #{$bestContrast}. This is lower than 90, the preferred level for fluent text and columns of body text with a font no smaller than 14px/weight 400 (normal).";
|
|
161
|
+
}
|
|
142
162
|
}
|
|
143
163
|
|
|
144
164
|
@return $contrastColor;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sass-apca",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "Sass implementation of the [Accessible Perceptual Contrast Algorithm (APCA)](https://git.apcacontrast.com/) for the WCAG 3.0 specification.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sass",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@semantic-release/changelog": "6.0.3",
|
|
31
31
|
"@semantic-release/git": "10.0.1",
|
|
32
|
-
"sass": "1.
|
|
33
|
-
"semantic-release": "
|
|
32
|
+
"sass": "1.98.0",
|
|
33
|
+
"semantic-release": "25.0.1"
|
|
34
34
|
}
|
|
35
35
|
}
|