stylelint-gamut 1.3.1 → 1.3.2
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/package.json +1 -1
- package/src/index.js +16 -6
- package/src/utils.js +6 -5
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -2,7 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
const stylelint = require('stylelint')
|
|
4
4
|
const Color = require('colorjs.io').default
|
|
5
|
-
const {
|
|
5
|
+
const {
|
|
6
|
+
isInColorGamutP3MediaQuery,
|
|
7
|
+
isStandardSyntaxProperty,
|
|
8
|
+
declarationValueIndex,
|
|
9
|
+
isInColorGamutRec2020MediaQuery,
|
|
10
|
+
startsWithNumber
|
|
11
|
+
} = require('./utils')
|
|
6
12
|
|
|
7
13
|
const ruleName = 'gamut/color-no-out-gamut-range'
|
|
8
14
|
|
|
@@ -37,13 +43,20 @@ const ruleFunction = (primary) => {
|
|
|
37
43
|
}
|
|
38
44
|
}
|
|
39
45
|
|
|
46
|
+
// value is e.g. lch(48% 82 283 / 67%)
|
|
40
47
|
function check (value) {
|
|
41
|
-
|
|
48
|
+
const shouldBeIgnored =
|
|
49
|
+
!value.startsWith('var(--') &&
|
|
50
|
+
(
|
|
51
|
+
value.includes('var(--') ||
|
|
52
|
+
!startsWithNumber(value.split('(')[1])
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
if (shouldBeIgnored) return
|
|
42
56
|
|
|
43
57
|
let customPropValue
|
|
44
58
|
if (value.startsWith('var(--')) {
|
|
45
59
|
const varName = value.slice(4, -1)
|
|
46
|
-
|
|
47
60
|
if (customProperties[varName] && !customProperties[varName].inQuery) {
|
|
48
61
|
customPropValue = customProperties[varName].value
|
|
49
62
|
} else {
|
|
@@ -54,9 +67,7 @@ const ruleFunction = (primary) => {
|
|
|
54
67
|
const color = new Color(customPropValue || value)
|
|
55
68
|
|
|
56
69
|
if (color.inGamut('srgb')) return
|
|
57
|
-
|
|
58
70
|
if (color.inGamut('p3') && isInColorGamutP3MediaQuery(decl)) return
|
|
59
|
-
|
|
60
71
|
if (color.inGamut('rec2020') && isInColorGamutRec2020MediaQuery(decl)) return
|
|
61
72
|
|
|
62
73
|
if (decl.prop && decl.prop.startsWith('--')) {
|
|
@@ -66,7 +77,6 @@ const ruleFunction = (primary) => {
|
|
|
66
77
|
|
|
67
78
|
const index = declarationValueIndex(decl)
|
|
68
79
|
const endIndex = index + decl.value.length
|
|
69
|
-
|
|
70
80
|
stylelint.utils.report({
|
|
71
81
|
message: messages.rejected(value),
|
|
72
82
|
node: decl,
|
package/src/utils.js
CHANGED
|
@@ -10,14 +10,10 @@ function declarationValueIndex (decl) {
|
|
|
10
10
|
const raws = decl.raws
|
|
11
11
|
|
|
12
12
|
return [
|
|
13
|
-
// @ts-expect-error -- TS2571: Object is of type 'unknown'.
|
|
14
13
|
raws.prop && raws.prop.prefix,
|
|
15
|
-
// @ts-expect-error -- TS2571: Object is of type 'unknown'.
|
|
16
14
|
(raws.prop && raws.prop.raw) || decl.prop,
|
|
17
|
-
// @ts-expect-error -- TS2571: Object is of type 'unknown'.
|
|
18
15
|
raws.prop && raws.prop.suffix,
|
|
19
16
|
raws.between || ':',
|
|
20
|
-
// @ts-expect-error -- TS2339: Property 'prefix' does not exist on type '{ value: string; raw: string; }'.
|
|
21
17
|
raws.value && raws.value.prefix
|
|
22
18
|
].reduce((count, str) => {
|
|
23
19
|
if (str) {
|
|
@@ -103,9 +99,14 @@ function isMediaQuery (decl) {
|
|
|
103
99
|
return decl.type === 'atrule' && decl.name === 'media'
|
|
104
100
|
}
|
|
105
101
|
|
|
102
|
+
function startsWithNumber (str) {
|
|
103
|
+
return /^\d/.test(str)
|
|
104
|
+
}
|
|
105
|
+
|
|
106
106
|
module.exports = {
|
|
107
107
|
isStandardSyntaxProperty,
|
|
108
108
|
declarationValueIndex,
|
|
109
109
|
isInColorGamutP3MediaQuery,
|
|
110
|
-
isInColorGamutRec2020MediaQuery
|
|
110
|
+
isInColorGamutRec2020MediaQuery,
|
|
111
|
+
startsWithNumber
|
|
111
112
|
}
|