@kong/design-tokens 1.18.2 → 1.18.3-pr.613.5525a1e.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.
@@ -1,3 +1,4 @@
1
1
  import useProperToken from './rules/use-proper-token/index.mjs'
2
+ import useCssToken from './rules/use-css-token/index.mjs'
2
3
 
3
- export default [useProperToken]
4
+ export default [useProperToken, useCssToken]
@@ -0,0 +1,175 @@
1
+ import stylelint from 'stylelint'
2
+ import { KONG_TOKEN_PREFIX, RULE_NAME_PREFIX } from '../../utilities/index.mjs'
3
+
4
+ const { ruleMessages, validateOptions, report } = stylelint.utils
5
+ const ruleName = `${RULE_NAME_PREFIX}/use-css-token`
6
+ const messages = ruleMessages(ruleName, {
7
+ expected: 'SCSS tokens must be used as fallback values in CSS custom properties. Use format: var(--kui-design-token, $kui-design-token)',
8
+ })
9
+ const meta = {
10
+ url: 'https://github.com/Kong/design-tokens/blob/main/stylelint-plugin/README.md',
11
+ fixable: true,
12
+ }
13
+
14
+ // Convert SCSS token ($kui-token) to CSS token (--kui-token)
15
+ const getCssToken = (scssToken) => {
16
+ const tokenName = scssToken.substring(1) // Remove $
17
+ return `--${tokenName}`
18
+ }
19
+
20
+ // Find all occurrences of a token in a value
21
+ const findAllTokenOccurrences = (value, token) => {
22
+ const occurrences = []
23
+ let searchIndex = 0
24
+ while (true) {
25
+ const index = value.indexOf(token, searchIndex)
26
+ if (index === -1) {
27
+ break
28
+ }
29
+ occurrences.push(index)
30
+ searchIndex = index + 1
31
+ }
32
+ return occurrences
33
+ }
34
+
35
+ // Check if token at given position is properly wrapped in var()
36
+ const isTokenProperlyWrapped = (value, tokenIndex, token, cssToken) => {
37
+ // Find the var() expression that contains this token
38
+ // Look backwards to find the nearest var( before the token
39
+ const beforeToken = value.substring(0, tokenIndex)
40
+ const varStartIndex = beforeToken.lastIndexOf('var(')
41
+
42
+ if (varStartIndex === -1) {
43
+ return false
44
+ }
45
+
46
+ // Find the matching closing parenthesis starting from var(
47
+ let parenCount = 0
48
+ let searchIndex = varStartIndex
49
+ let varEndIndex = -1
50
+
51
+ while (searchIndex < value.length) {
52
+ const char = value[searchIndex]
53
+ if (char === '(') {
54
+ parenCount++
55
+ } else if (char === ')') {
56
+ parenCount--
57
+ if (parenCount === 0) {
58
+ varEndIndex = searchIndex
59
+ break
60
+ }
61
+ }
62
+ searchIndex++
63
+ }
64
+
65
+ if (varEndIndex === -1) {
66
+ return false
67
+ }
68
+
69
+ // Verify the token is actually inside this var() expression
70
+ const tokenEndIndex = tokenIndex + token.length
71
+ if (tokenIndex < varStartIndex || tokenEndIndex > varEndIndex) {
72
+ return false
73
+ }
74
+
75
+ // Extract the full var() expression and check if it matches the pattern
76
+ const varExpression = value.substring(varStartIndex, varEndIndex + 1)
77
+ const expectedPattern = new RegExp(`^var\\(\\s*${cssToken}\\s*,\\s*${token}\\s*\\)$`)
78
+ return expectedPattern.test(varExpression)
79
+ }
80
+
81
+ const ruleFunction = () => {
82
+ return (postcssRoot, postcssResult) => {
83
+ const validOptions = validateOptions(postcssResult, ruleName, {})
84
+
85
+ if (!validOptions) {
86
+ return
87
+ }
88
+
89
+ postcssRoot.walkDecls((decl) => {
90
+ const declValue = decl.value
91
+
92
+ // Extract all SCSS tokens (starting with $kui-)
93
+ const scssTokenRegex = new RegExp(`\\$${KONG_TOKEN_PREFIX}[a-z0-9-]+`, 'g')
94
+ const scssTokens = declValue.match(scssTokenRegex)
95
+
96
+ // If no SCSS tokens are used, skip validation
97
+ if (!scssTokens || scssTokens.length === 0) {
98
+ return
99
+ }
100
+
101
+ // Get unique SCSS tokens
102
+ const uniqueScssTokens = Array.from(new Set(scssTokens))
103
+
104
+ // Check if each SCSS token is properly wrapped in var()
105
+ // Pattern: var(--kui-token-name, $kui-token-name)
106
+ const improperlyUsedTokens = []
107
+
108
+ uniqueScssTokens.forEach((scssToken) => {
109
+ const cssToken = getCssToken(scssToken)
110
+ const tokenOccurrences = findAllTokenOccurrences(declValue, scssToken)
111
+
112
+ // Check each occurrence to see if it's properly wrapped
113
+ const hasImproperUsage = tokenOccurrences.some((tokenIndex) => {
114
+ return !isTokenProperlyWrapped(declValue, tokenIndex, scssToken, cssToken)
115
+ })
116
+
117
+ if (hasImproperUsage) {
118
+ improperlyUsedTokens.push(scssToken)
119
+ }
120
+ })
121
+
122
+ if (improperlyUsedTokens.length > 0) {
123
+ // Create fix function
124
+ const fix = () => {
125
+ let fixedValue = declValue
126
+ const replacements = []
127
+
128
+ // First, identify all positions that need to be replaced
129
+ improperlyUsedTokens.forEach((scssToken) => {
130
+ const cssToken = getCssToken(scssToken)
131
+ const tokenOccurrences = findAllTokenOccurrences(fixedValue, scssToken)
132
+ const properFormat = `var(${cssToken}, ${scssToken})`
133
+
134
+ tokenOccurrences.forEach((index) => {
135
+ // Check if this occurrence is in proper format
136
+ if (!isTokenProperlyWrapped(fixedValue, index, scssToken, cssToken)) {
137
+ // This occurrence needs to be replaced
138
+ replacements.push({
139
+ start: index,
140
+ end: index + scssToken.length,
141
+ replacement: properFormat,
142
+ })
143
+ }
144
+ })
145
+ })
146
+
147
+ // Sort replacements by position (descending) to avoid offset issues
148
+ replacements.sort((a, b) => b.start - a.start)
149
+
150
+ // Apply replacements from end to start
151
+ replacements.forEach(({ start, end, replacement }) => {
152
+ fixedValue = fixedValue.substring(0, start) + replacement + fixedValue.substring(end)
153
+ })
154
+
155
+ decl.value = fixedValue
156
+ }
157
+
158
+ report({
159
+ message: messages.expected,
160
+ node: decl,
161
+ result: postcssResult,
162
+ ruleName,
163
+ fix,
164
+ })
165
+ }
166
+ })
167
+ }
168
+ }
169
+
170
+ ruleFunction.ruleName = ruleName
171
+ ruleFunction.messages = messages
172
+ ruleFunction.meta = meta
173
+
174
+ export default stylelint.createPlugin(ruleName, ruleFunction)
175
+
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Do not edit directly, this file was auto-generated.
3
- * Generated on Tue, 25 Nov 2025 21:23:14 GMT
3
+ * Generated on Mon, 05 Jan 2026 18:35:18 GMT
4
4
  *
5
5
  * Kong Design Tokens
6
6
  * GitHub: https://github.com/Kong/design-tokens
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Do not edit directly, this file was auto-generated.
3
- * Generated on Tue, 25 Nov 2025 21:23:14 GMT
3
+ * Generated on Mon, 05 Jan 2026 18:35:17 GMT
4
4
  *
5
5
  * Kong Design Tokens
6
6
  * GitHub: https://github.com/Kong/design-tokens
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Do not edit directly, this file was auto-generated.
3
- * Generated on Tue, 25 Nov 2025 21:23:14 GMT
3
+ * Generated on Mon, 05 Jan 2026 18:35:17 GMT
4
4
  *
5
5
  * Kong Design Tokens
6
6
  * GitHub: https://github.com/Kong/design-tokens
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Do not edit directly, this file was auto-generated.
3
- * Generated on Tue, 25 Nov 2025 21:23:14 GMT
3
+ * Generated on Mon, 05 Jan 2026 18:35:17 GMT
4
4
  *
5
5
  * Kong Design Tokens
6
6
  * GitHub: https://github.com/Kong/design-tokens
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Do not edit directly, this file was auto-generated.
3
- * Generated on Tue, 25 Nov 2025 21:23:14 GMT
3
+ * Generated on Mon, 05 Jan 2026 18:35:17 GMT
4
4
  *
5
5
  * Kong Design Tokens
6
6
  * GitHub: https://github.com/Kong/design-tokens
@@ -1,6 +1,6 @@
1
1
 
2
2
  // Do not edit directly, this file was auto-generated.
3
- // Generated on Tue, 25 Nov 2025 21:23:14 GMT
3
+ // Generated on Mon, 05 Jan 2026 18:35:18 GMT
4
4
  //
5
5
  // Kong Design Tokens
6
6
  // GitHub: https://github.com/Kong/design-tokens
@@ -1,7 +1,7 @@
1
1
 
2
2
  /**
3
3
  * Do not edit directly, this file was auto-generated.
4
- * Generated on Tue, 25 Nov 2025 21:23:14 GMT
4
+ * Generated on Mon, 05 Jan 2026 18:35:18 GMT
5
5
  *
6
6
  * Kong Design Tokens
7
7
  * GitHub: https://github.com/Kong/design-tokens
@@ -1,6 +1,6 @@
1
1
 
2
2
  // Do not edit directly, this file was auto-generated.
3
- // Generated on Tue, 25 Nov 2025 21:23:14 GMT
3
+ // Generated on Mon, 05 Jan 2026 18:35:18 GMT
4
4
  //
5
5
  // Kong Design Tokens
6
6
  // GitHub: https://github.com/Kong/design-tokens
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kong/design-tokens",
3
- "version": "1.18.2",
3
+ "version": "1.18.3-pr.613.5525a1e.0",
4
4
  "description": "Kong UI Design Tokens and style dictionary",
5
5
  "type": "module",
6
6
  "scripts": {
@@ -53,30 +53,30 @@
53
53
  "url": "https://github.com/Kong/design-tokens/issues"
54
54
  },
55
55
  "devDependencies": {
56
- "@commitlint/cli": "^20.1.0",
57
- "@commitlint/config-conventional": "^20.0.0",
56
+ "@commitlint/cli": "^20.3.0",
57
+ "@commitlint/config-conventional": "^20.3.0",
58
58
  "@digitalroute/cz-conventional-changelog-for-jira": "^8.0.1",
59
- "@evilmartians/lefthook": "^2.0.2",
60
- "@kong/eslint-config-kong-ui": "^1.5.6",
59
+ "@evilmartians/lefthook": "^2.0.13",
60
+ "@kong/eslint-config-kong-ui": "^1.6.0",
61
61
  "@semantic-release/changelog": "^6.0.3",
62
62
  "@semantic-release/git": "^10.0.1",
63
- "@vitejs/plugin-vue": "^6.0.1",
63
+ "@vitejs/plugin-vue": "^6.0.3",
64
64
  "chokidar-cli": "^3.0.0",
65
65
  "commitizen": "^4.3.1",
66
66
  "cz-conventional-changelog": "^3.3.0",
67
- "eslint": "^9.39.1",
67
+ "eslint": "^9.39.2",
68
68
  "npm-run-all2": "^8.0.4",
69
- "rimraf": "^6.1.0",
70
- "sass": "^1.93.3",
71
- "semantic-release": "^25.0.1",
69
+ "rimraf": "^6.1.2",
70
+ "sass": "^1.97.1",
71
+ "semantic-release": "^25.0.2",
72
72
  "shx": "^0.4.0",
73
73
  "style-dictionary": "^4.4.0",
74
74
  "typescript": "^5.9.3",
75
- "vite": "^7.1.12",
75
+ "vite": "^7.3.0",
76
76
  "vite-plugin-restart": "^2.0.0",
77
- "vite-plugin-vue-devtools": "^8.0.3",
78
- "vue": "^3.5.22",
79
- "vue-router": "^4.6.3"
77
+ "vite-plugin-vue-devtools": "^8.0.5",
78
+ "vue": "^3.5.26",
79
+ "vue-router": "^4.6.4"
80
80
  },
81
81
  "release": {
82
82
  "branches": [
@@ -126,13 +126,13 @@
126
126
  "jiraAppend": "]"
127
127
  }
128
128
  },
129
- "packageManager": "pnpm@10.20.0",
129
+ "packageManager": "pnpm@10.27.0",
130
130
  "engines": {
131
131
  "node": ">=20.19.5",
132
132
  "pnpm": ">=9.14.4 || >=10.1.0"
133
133
  },
134
134
  "volta": {
135
- "node": "24.11.0"
135
+ "node": "24.12.0"
136
136
  },
137
137
  "pnpm": {
138
138
  "onlyBuiltDependencies": [