stylelint-gamut 1.2.9 → 1.3.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.
package/README.md CHANGED
@@ -10,7 +10,7 @@
10
10
 
11
11
  # Requirements
12
12
 
13
- - **node version ≥ 16.0.0**
13
+ - **node version ≥ 12.0.0**
14
14
  - **Stylelint version ≥ 14.0.0**.
15
15
 
16
16
  # Installation
@@ -46,6 +46,7 @@ Add `stylelint-gamut` to your Stylelint config `plugins` array, then add rules y
46
46
  It is already used by the creator of [PostCSS] [Andrey Sitnik].
47
47
 
48
48
  Read more about color spaces in css:
49
+ - [OKLCH in CSS: why we moved from RGB and HSL](https://evilmartians.com/chronicles/oklch-in-css-why-quit-rgb-hsl)
49
50
  - [LCH colors in CSS: what, why, and how?](https://lea.verou.me/2020/04/lch-colors-in-css-what-why-and-how/)
50
51
  - [A Guide To Modern CSS Colors](https://www.smashingmagazine.com/2021/11/guide-modern-css-colors/)
51
52
 
package/package.json CHANGED
@@ -1,52 +1,58 @@
1
1
  {
2
- "name": "stylelint-gamut",
3
- "version": "1.2.9",
4
- "description": "Stylelint plugin for working with different color spaces",
5
- "main": "src/index.js",
6
- "scripts": {
7
- "test": "jest"
8
- },
9
- "engines": {
10
- "node": ">=16.0.0"
11
- },
12
- "repository": {
13
- "type": "git",
14
- "url": "git+https://github.com/fpetrakov/stylelint-gamut.git"
15
- },
16
- "files": [
17
- "src/**/*.js",
18
- "!**/**/*.test.js"
19
- ],
20
- "keywords": [
21
- "stylelint",
22
- "stylelint-plugin",
23
- "gamut",
24
- "lch",
25
- "oklch",
26
- "lab",
27
- "oklab"
28
- ],
29
- "author": "Fedya Petrakov",
30
- "license": "MIT",
31
- "bugs": {
32
- "url": "https://github.com/fpetrakov/stylelint-gamut/issues"
33
- },
34
- "homepage": "https://github.com/fpetrakov/stylelint-gamut#readme",
35
- "peerDependencies": {
36
- "stylelint": "^14.0.0"
37
- },
38
- "devDependencies": {
39
- "eslint": "^8.22.0",
40
- "eslint-config-standard": "^17.0.0",
41
- "eslint-plugin-import": "^2.26.0",
42
- "eslint-plugin-n": "^15.2.4",
43
- "eslint-plugin-promise": "^6.0.0",
44
- "jest": "^28.1.3",
45
- "jest-cli": "^28.1.3",
46
- "jest-preset-stylelint": "^5.0.4",
47
- "stylelint": "^14.10.0"
48
- },
49
- "dependencies": {
50
- "colorjs.io": "^0.4.0"
51
- }
2
+ "name": "stylelint-gamut",
3
+ "version": "1.3.1",
4
+ "description": "Stylelint plugin for working with different color spaces",
5
+ "main": "src/index.js",
6
+ "scripts": {
7
+ "test": "jest",
8
+ "prepare": "husky install"
9
+ },
10
+ "lint-staged": {
11
+ "*.js": "eslint --fix"
12
+ },
13
+ "engines": {
14
+ "node": ">=16.0.0"
15
+ },
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+https://github.com/fpetrakov/stylelint-gamut.git"
19
+ },
20
+ "files": [
21
+ "src/**/*.js",
22
+ "!**/**/*.test.js"
23
+ ],
24
+ "keywords": [
25
+ "stylelint",
26
+ "stylelint-plugin",
27
+ "gamut",
28
+ "lch",
29
+ "oklch",
30
+ "lab",
31
+ "oklab"
32
+ ],
33
+ "author": "Fedya Petrakov",
34
+ "license": "MIT",
35
+ "bugs": {
36
+ "url": "https://github.com/fpetrakov/stylelint-gamut/issues"
37
+ },
38
+ "homepage": "https://github.com/fpetrakov/stylelint-gamut#readme",
39
+ "peerDependencies": {
40
+ "stylelint": "^14.0.0 || ^15.0.0"
41
+ },
42
+ "devDependencies": {
43
+ "eslint": "^8.22.0",
44
+ "eslint-config-standard": "^17.0.0",
45
+ "eslint-plugin-import": "^2.26.0",
46
+ "eslint-plugin-n": "^15.2.4",
47
+ "eslint-plugin-promise": "^6.0.0",
48
+ "husky": "^8.0.1",
49
+ "jest": "^28.1.3",
50
+ "jest-cli": "^28.1.3",
51
+ "jest-preset-stylelint": "^5.0.4",
52
+ "lint-staged": "^13.0.3",
53
+ "stylelint": "^14.10.0"
54
+ },
55
+ "dependencies": {
56
+ "colorjs.io": "^0.4.0"
57
+ }
52
58
  }
package/src/README.md ADDED
@@ -0,0 +1,125 @@
1
+ # color-no-out-gamut-range
2
+
3
+ Disallow out of gamut range colors.
4
+
5
+ <!-- prettier-ignore -->
6
+ ```css
7
+ a { color: lch(48% 82 283) }
8
+ /** ↑
9
+ * This color is out of sRGB gamut range */
10
+ ```
11
+
12
+ Colors declared using lch, oklch, lab and oklab functions can move from sRGB to P3 or Rec2020 color spaces, which are not supported by most of screens right now. It can happen by mistake. For instance, by converting colors from one space to another.
13
+
14
+ This rule checks if the color is in sRGB, p3 or rec2020 space. If it's not in sRGB gamut you should wrap it in a proper media query:
15
+
16
+ ```css
17
+ @media (color-gamut: p3) {
18
+ a {
19
+ color: lch(29.8% 42.5 109.485);
20
+ }
21
+ }
22
+ /** ↑
23
+ * This color is in p3 gamut range */
24
+ ```
25
+
26
+ ```css
27
+ @media (color-gamut: rec2020) {
28
+ a {
29
+ color: lch(25.1% 42.5 109.485);
30
+ }
31
+ }
32
+ /** ↑
33
+ * This color is in rec2020 gamut range */
34
+ ```
35
+
36
+ In case of **css custom properties** you should wrap either the custom property declaration:
37
+
38
+ ```css
39
+ @media (color-gamut: p3) {
40
+ :root {
41
+ --my-var: lch(48% 82 283);
42
+ }
43
+ }
44
+ ```
45
+ or the rule that uses the custom property:
46
+
47
+ ```css
48
+ @media (color-gamut: p3) {
49
+ a {
50
+ color: var(--my-var);
51
+ }
52
+ }
53
+ ```
54
+
55
+ Custom properties inside color declaration are ignored:
56
+
57
+ ```css
58
+ background-color: oklch(var(--oklch-primary) / var(--alpha-bg)); /* not checked */
59
+ ```
60
+
61
+ Please note that conditional imports are not checked, e.g.:
62
+
63
+ ```html
64
+ <link href="p3-custom-props.css" rel="stylesheet" media="(color-gamut: p3)" />
65
+ ```
66
+
67
+ ```css
68
+ @import url("p3-custom-props.css") (color-gamut: p3);
69
+ ```
70
+
71
+ ## Options
72
+
73
+ ### `true`
74
+
75
+ The following patterns are considered problems:
76
+
77
+ <!-- prettier-ignore -->
78
+ ```css
79
+ a { color: lch(48% 82 283) }
80
+ ```
81
+
82
+ <!-- prettier-ignore -->
83
+ ```css
84
+ a { color: oklch(57.35% 0.23 259.06) }
85
+ ```
86
+
87
+ <!-- prettier-ignore -->
88
+ ```css
89
+ a { color: lab(82.2345% 40.1645 59.9971 / .5) }
90
+ ```
91
+
92
+ <!-- prettier-ignore -->
93
+ ```css
94
+ a { color: oklab(85.69% 0.1007 0.1191 / .5) }
95
+ ```
96
+
97
+ The following patterns are _not_ considered problems:
98
+
99
+ <!-- prettier-ignore -->
100
+ ```css
101
+ @media (color-gamut: p3) {
102
+ a { color: lch(48% 82 283) }
103
+ }
104
+ ```
105
+
106
+ <!-- prettier-ignore -->
107
+ ```css
108
+ @media (color-gamut: p3) {
109
+ a { color: oklch(57.35% 0.23 259.06) }
110
+ }
111
+ ```
112
+
113
+ <!-- prettier-ignore -->
114
+ ```css
115
+ @media (color-gamut: rec2020) {
116
+ a { color: lab(82.2345% 40.1645 59.9971 / .5) }
117
+ }
118
+ ```
119
+
120
+ <!-- prettier-ignore -->
121
+ ```css
122
+ @media (color-gamut: rec2020) {
123
+ a { color: oklab(85.69% 0.1007 0.1191 / .5) }
124
+ }
125
+ ```
package/src/index.js CHANGED
@@ -38,6 +38,8 @@ const ruleFunction = (primary) => {
38
38
  }
39
39
 
40
40
  function check (value) {
41
+ if (!value.startsWith('var(--') && value.includes('var(--')) return
42
+
41
43
  let customPropValue
42
44
  if (value.startsWith('var(--')) {
43
45
  const varName = value.slice(4, -1)