stylelint-gamut 1.1.5 → 1.2.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 +1 -1
- package/package.json +2 -2
- package/src/index.js +33 -29
- package/src/utils/isCustomProperty.js +0 -10
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
**stylelint-gamut** is a [Stylelint] plugin that helps you to work with different color spaces.
|
|
6
6
|
|
|
7
|
-
Right now it's working with **node version ≥ 16.0.0**.
|
|
7
|
+
Right now it's working with **node version ≥ 16.0.0** and **Stylelint version ≥ 14.0.0**.
|
|
8
8
|
|
|
9
9
|
# Installation
|
|
10
10
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "stylelint-gamut",
|
|
3
|
-
"version": "1.1
|
|
3
|
+
"version": "1.2.1",
|
|
4
4
|
"description": "Stylelint plugin for working with different color spaces",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
},
|
|
34
34
|
"homepage": "https://github.com/fpetrakov/stylelint-gamut#readme",
|
|
35
35
|
"peerDependencies": {
|
|
36
|
-
"stylelint": "
|
|
36
|
+
"stylelint": "^14.0.0"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"eslint": "^8.22.0",
|
package/src/index.js
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const valueParser = require('postcss-value-parser')
|
|
4
3
|
const stylelint = require('stylelint')
|
|
5
4
|
const Color = require('colorjs.io').default
|
|
6
5
|
const isStandardSyntaxProperty = require('./utils/isStandardSyntaxProperty')
|
|
7
|
-
const isCustomProperty = require('./utils/isCustomProperty')
|
|
8
6
|
const isAtRule = require('./utils/isAtRule')
|
|
9
7
|
const declarationValueIndex = require('./utils/declarationValueIndex')
|
|
10
8
|
|
|
@@ -29,45 +27,51 @@ const ruleFunction = (primary) => {
|
|
|
29
27
|
return
|
|
30
28
|
}
|
|
31
29
|
|
|
30
|
+
const customProperties = {}
|
|
31
|
+
|
|
32
32
|
root.walkDecls((decl) => {
|
|
33
33
|
if (!isStandardSyntaxProperty(decl.prop)) return
|
|
34
34
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
if (colors) {
|
|
40
|
-
for (const color of colors) {
|
|
41
|
-
checkColor(color)
|
|
42
|
-
}
|
|
35
|
+
const values = decl.value.match(/(oklch|oklab|lab|lch|var)\([^)]+\)/g)
|
|
36
|
+
if (values) {
|
|
37
|
+
for (const value of values) {
|
|
38
|
+
check(value)
|
|
43
39
|
}
|
|
44
40
|
}
|
|
45
41
|
|
|
46
|
-
function
|
|
47
|
-
|
|
42
|
+
function check (value) {
|
|
43
|
+
let customPropValue
|
|
44
|
+
if (value.startsWith('var(--')) {
|
|
45
|
+
const varName = value.slice(4, -1)
|
|
48
46
|
|
|
49
|
-
|
|
50
|
-
|
|
47
|
+
if (customProperties[varName] && !customProperties[varName].inQuery) {
|
|
48
|
+
customPropValue = customProperties[varName].value
|
|
49
|
+
} else {
|
|
50
|
+
return
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const isInSrgbGamut = new Color(customPropValue || value).inGamut('srgb')
|
|
51
55
|
|
|
52
|
-
|
|
53
|
-
'srgb'
|
|
54
|
-
)
|
|
56
|
+
if (isInSrgbGamut) return
|
|
55
57
|
|
|
56
|
-
|
|
58
|
+
if (isInColorGamutP3MediaQuery(decl)) return
|
|
57
59
|
|
|
58
|
-
|
|
60
|
+
if (decl.prop && decl.prop.startsWith('--')) {
|
|
61
|
+
customProperties[decl.prop] = { value: decl.value.trim(), inQuery: false }
|
|
62
|
+
return
|
|
63
|
+
}
|
|
59
64
|
|
|
60
|
-
|
|
61
|
-
|
|
65
|
+
const index = declarationValueIndex(decl)
|
|
66
|
+
const endIndex = index + decl.value.length
|
|
62
67
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
})
|
|
68
|
+
stylelint.utils.report({
|
|
69
|
+
message: messages.rejected(value),
|
|
70
|
+
node: decl,
|
|
71
|
+
index,
|
|
72
|
+
endIndex,
|
|
73
|
+
result,
|
|
74
|
+
ruleName
|
|
71
75
|
})
|
|
72
76
|
}
|
|
73
77
|
})
|