stylelint-gamut 1.3.4 → 2.0.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 CHANGED
@@ -27,9 +27,7 @@ npm install stylelint stylelint-config-standard --save-dev
27
27
  npm install stylelint-gamut --save-dev
28
28
  ```
29
29
 
30
- # Usage
31
-
32
- Add `stylelint-gamut` to your Stylelint config `plugins` array, then add rules you need to the rules list. All rules from `stylelint-gamut` need to be namespaced with `gamut`.
30
+ 3. Add `stylelint-gamut` to your Stylelint config `plugins` array, then add rules you need to the rules list. All rules from `stylelint-gamut` need to be namespaced with `gamut`.
33
31
 
34
32
  ```json
35
33
  {
package/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "stylelint-gamut",
3
- "version": "1.3.4",
3
+ "version": "2.0.0",
4
4
  "description": "Stylelint plugin for working with different color spaces",
5
+ "type": "module",
5
6
  "main": "src/index.js",
6
7
  "scripts": {
7
8
  "format": "prettier --write .",
8
9
  "lint": "eslint --fix *.js",
9
- "test": "jest",
10
+ "test": "node --experimental-vm-modules node_modules/jest/bin/jest.js",
10
11
  "prepare": "husky install"
11
12
  },
12
13
  "lint-staged": {
@@ -14,7 +15,7 @@
14
15
  ".": "prettier -write"
15
16
  },
16
17
  "engines": {
17
- "node": ">=16.0.0"
18
+ "node": ">=20.19.0"
18
19
  },
19
20
  "repository": {
20
21
  "type": "git",
@@ -40,7 +41,7 @@
40
41
  },
41
42
  "homepage": "https://github.com/fpetrakov/stylelint-gamut#readme",
42
43
  "peerDependencies": {
43
- "stylelint": "^14.0.0 || ^15.0.0 || ^16.0.0"
44
+ "stylelint": "^14.0.0 || ^15.0.0 || ^16.0.0 || ^17.0.0"
44
45
  },
45
46
  "devDependencies": {
46
47
  "eslint": "^8.43.0",
@@ -50,12 +51,12 @@
50
51
  "eslint-plugin-n": "^16.0.0",
51
52
  "eslint-plugin-promise": "^6.1.1",
52
53
  "husky": "^8.0.3",
53
- "jest": "^29.5.0",
54
- "jest-cli": "^29.5.0",
55
- "jest-preset-stylelint": "^6.1.0",
54
+ "jest": "^30.0.0",
55
+ "jest-cli": "^30.0.0",
56
+ "jest-preset-stylelint": "^9.0.0",
56
57
  "lint-staged": "^15.0.2",
57
58
  "prettier": "^3.0.3",
58
- "stylelint": "^15.7.0"
59
+ "stylelint": "^17.0.0"
59
60
  },
60
61
  "dependencies": {
61
62
  "colorjs.io": "^0.4.5"
package/src/index.js CHANGED
@@ -1,15 +1,13 @@
1
- "use strict";
1
+ import stylelint from "stylelint";
2
+ import Color from "colorjs.io";
2
3
 
3
- const stylelint = require("stylelint");
4
- const Color = require("colorjs.io").default;
5
-
6
- const {
4
+ import {
7
5
  isInColorGamutP3MediaQuery,
8
6
  isStandardSyntaxProperty,
9
7
  declarationValueIndex,
10
8
  isInColorGamutRec2020MediaQuery,
11
9
  startsWithNumber,
12
- } = require("./utils");
10
+ } from "./utils.js";
13
11
 
14
12
  const ruleName = "gamut/color-no-out-gamut-range";
15
13
 
@@ -107,4 +105,7 @@ ruleFunction.ruleName = ruleName;
107
105
  ruleFunction.messages = messages;
108
106
  ruleFunction.meta = meta;
109
107
 
110
- module.exports = stylelint.createPlugin(ruleName, ruleFunction);
108
+ const plugin = stylelint.createPlugin(ruleName, ruleFunction);
109
+
110
+ export default plugin;
111
+ export { ruleName, messages, meta };
package/src/utils.js CHANGED
@@ -1,12 +1,10 @@
1
- "use strict";
2
-
3
1
  /**
4
2
  * Get the index of a declaration's value
5
3
  *
6
4
  * @param {import('postcss').Declaration} decl
7
5
  * @returns {number}
8
6
  */
9
- const declarationValueIndex = (decl) => {
7
+ export const declarationValueIndex = (decl) => {
10
8
  const raws = decl.raws;
11
9
 
12
10
  return [
@@ -30,7 +28,7 @@ const declarationValueIndex = (decl) => {
30
28
  * @param {string} property
31
29
  * @return {boolean} If `true`, the property is standard
32
30
  */
33
- const isStandardSyntaxProperty = (property) => {
31
+ export const isStandardSyntaxProperty = (property) => {
34
32
  // SCSS var (e.g. $var: x), list (e.g. $list: (x)) or map (e.g. $map: (key:value))
35
33
  if (property.startsWith("$")) {
36
34
  return false;
@@ -53,7 +51,7 @@ const isStandardSyntaxProperty = (property) => {
53
51
  * @param {import('postcss').Declaration} decl
54
52
  * @returns {boolean}
55
53
  */
56
- const isInColorGamutP3MediaQuery = (decl) => {
54
+ export const isInColorGamutP3MediaQuery = (decl) => {
57
55
  const parentMediaQuery = getMediaQueryParent(decl);
58
56
 
59
57
  if (
@@ -70,7 +68,7 @@ const isInColorGamutP3MediaQuery = (decl) => {
70
68
  * @param {import('postcss').Declaration} decl
71
69
  * @returns {boolean}
72
70
  */
73
- const isInColorGamutRec2020MediaQuery = (decl) => {
71
+ export const isInColorGamutRec2020MediaQuery = (decl) => {
74
72
  const parentMediaQuery = getMediaQueryParent(decl);
75
73
 
76
74
  if (
@@ -103,12 +101,4 @@ const getMediaQueryParent = (decl) => {
103
101
  */
104
102
  const isMediaQuery = (decl) => decl.type === "atrule" && decl.name === "media";
105
103
 
106
- const startsWithNumber = (str) => /^\d/.test(str);
107
-
108
- module.exports = {
109
- isStandardSyntaxProperty,
110
- declarationValueIndex,
111
- isInColorGamutP3MediaQuery,
112
- isInColorGamutRec2020MediaQuery,
113
- startsWithNumber,
114
- };
104
+ export const startsWithNumber = (str) => /^\d/.test(str);
package/src/README.md DELETED
@@ -1,124 +0,0 @@
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) } /* This color is out of sRGB gamut range */
8
- ```
9
-
10
- 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.
11
-
12
- 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:
13
-
14
- ```css
15
- @media (color-gamut: p3) {
16
- a {
17
- color: lch(29.8% 42.5 109.485);
18
- /* This color is in p3 gamut range */
19
- }
20
- }
21
- ```
22
-
23
- ```css
24
- @media (color-gamut: rec2020) {
25
- a {
26
- color: lch(25.1% 42.5 109.485);
27
- /* This color is in rec2020 gamut range */
28
- }
29
- }
30
- ```
31
-
32
- In case of **css custom properties** you should wrap either the custom property declaration:
33
-
34
- ```css
35
- @media (color-gamut: p3) {
36
- :root {
37
- --my-var: lch(48% 82 283);
38
- }
39
- }
40
- ```
41
-
42
- or the rule that uses the custom property:
43
-
44
- ```css
45
- @media (color-gamut: p3) {
46
- a {
47
- color: var(--my-var);
48
- }
49
- }
50
- ```
51
-
52
- Custom properties inside color declaration are ignored:
53
-
54
- ```css
55
- background-color: oklch(
56
- var(--oklch-primary) / var(--alpha-bg)
57
- ); /* not checked */
58
- ```
59
-
60
- Please note that conditional imports are not checked, e.g.:
61
-
62
- ```html
63
- <link href="p3-custom-props.css" rel="stylesheet" media="(color-gamut: p3)" />
64
- ```
65
-
66
- ```css
67
- @import url("p3-custom-props.css") (color-gamut: p3);
68
- ```
69
-
70
- ## Options
71
-
72
- ### `true`
73
-
74
- The following patterns are considered problems:
75
-
76
- <!-- prettier-ignore -->
77
- ```css
78
- a { color: lch(48% 82 283) }
79
- ```
80
-
81
- <!-- prettier-ignore -->
82
- ```css
83
- a { color: oklch(57.35% 0.23 259.06) }
84
- ```
85
-
86
- <!-- prettier-ignore -->
87
- ```css
88
- a { color: lab(82.2345% 40.1645 59.9971 / .5) }
89
- ```
90
-
91
- <!-- prettier-ignore -->
92
- ```css
93
- a { color: oklab(85.69% 0.1007 0.1191 / .5) }
94
- ```
95
-
96
- The following patterns are _not_ considered problems:
97
-
98
- <!-- prettier-ignore -->
99
- ```css
100
- @media (color-gamut: p3) {
101
- a { color: lch(48% 82 283) }
102
- }
103
- ```
104
-
105
- <!-- prettier-ignore -->
106
- ```css
107
- @media (color-gamut: p3) {
108
- a { color: oklch(57.35% 0.23 259.06) }
109
- }
110
- ```
111
-
112
- <!-- prettier-ignore -->
113
- ```css
114
- @media (color-gamut: rec2020) {
115
- a { color: lab(82.2345% 40.1645 59.9971 / .5) }
116
- }
117
- ```
118
-
119
- <!-- prettier-ignore -->
120
- ```css
121
- @media (color-gamut: rec2020) {
122
- a { color: oklab(85.69% 0.1007 0.1191 / .5) }
123
- }
124
- ```