@rien7/design-surface 0.0.0-stage → 0.1.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.
Files changed (214) hide show
  1. package/bin/design-surface.mjs +286 -0
  2. package/dist/cli/init.mjs +411 -0
  3. package/dist/cli/propose.mjs +172 -0
  4. package/dist/cli/reviewOps.mjs +127 -0
  5. package/dist/editor/AgentProposalCard.d.ts +10 -0
  6. package/dist/editor/AgentProposalCard.d.ts.map +1 -0
  7. package/dist/editor/AgentProposalCard.js +28 -0
  8. package/dist/editor/AgentProposalCard.js.map +1 -0
  9. package/dist/editor/App.d.ts +2 -0
  10. package/dist/editor/App.d.ts.map +1 -0
  11. package/dist/editor/App.js +1813 -0
  12. package/dist/editor/App.js.map +1 -0
  13. package/dist/editor/CanvasHud.d.ts +12 -0
  14. package/dist/editor/CanvasHud.d.ts.map +1 -0
  15. package/dist/editor/CanvasHud.js +13 -0
  16. package/dist/editor/CanvasHud.js.map +1 -0
  17. package/dist/editor/CanvasSurface.d.ts +20 -0
  18. package/dist/editor/CanvasSurface.d.ts.map +1 -0
  19. package/dist/editor/CanvasSurface.js +252 -0
  20. package/dist/editor/CanvasSurface.js.map +1 -0
  21. package/dist/editor/Changes.d.ts +17 -0
  22. package/dist/editor/Changes.d.ts.map +1 -0
  23. package/dist/editor/Changes.js +59 -0
  24. package/dist/editor/Changes.js.map +1 -0
  25. package/dist/editor/CommentPopover.d.ts +17 -0
  26. package/dist/editor/CommentPopover.d.ts.map +1 -0
  27. package/dist/editor/CommentPopover.js +62 -0
  28. package/dist/editor/CommentPopover.js.map +1 -0
  29. package/dist/editor/Comments.d.ts +13 -0
  30. package/dist/editor/Comments.d.ts.map +1 -0
  31. package/dist/editor/Comments.js +39 -0
  32. package/dist/editor/Comments.js.map +1 -0
  33. package/dist/editor/History.d.ts +7 -0
  34. package/dist/editor/History.d.ts.map +1 -0
  35. package/dist/editor/History.js +43 -0
  36. package/dist/editor/History.js.map +1 -0
  37. package/dist/editor/Inspector.d.ts +22 -0
  38. package/dist/editor/Inspector.d.ts.map +1 -0
  39. package/dist/editor/Inspector.js +241 -0
  40. package/dist/editor/Inspector.js.map +1 -0
  41. package/dist/editor/LazyMount.d.ts +10 -0
  42. package/dist/editor/LazyMount.d.ts.map +1 -0
  43. package/dist/editor/LazyMount.js +29 -0
  44. package/dist/editor/LazyMount.js.map +1 -0
  45. package/dist/editor/LocaleSwitch.d.ts +2 -0
  46. package/dist/editor/LocaleSwitch.d.ts.map +1 -0
  47. package/dist/editor/LocaleSwitch.js +13 -0
  48. package/dist/editor/LocaleSwitch.js.map +1 -0
  49. package/dist/editor/NodeInspector.d.ts +9 -0
  50. package/dist/editor/NodeInspector.d.ts.map +1 -0
  51. package/dist/editor/NodeInspector.js +9 -0
  52. package/dist/editor/NodeInspector.js.map +1 -0
  53. package/dist/editor/PreviewFrame.d.ts +10 -0
  54. package/dist/editor/PreviewFrame.d.ts.map +1 -0
  55. package/dist/editor/PreviewFrame.js +22 -0
  56. package/dist/editor/PreviewFrame.js.map +1 -0
  57. package/dist/editor/ProjectIndex.d.ts +12 -0
  58. package/dist/editor/ProjectIndex.d.ts.map +1 -0
  59. package/dist/editor/ProjectIndex.js +43 -0
  60. package/dist/editor/ProjectIndex.js.map +1 -0
  61. package/dist/editor/StyleEditor.d.ts +37 -0
  62. package/dist/editor/StyleEditor.d.ts.map +1 -0
  63. package/dist/editor/StyleEditor.js +275 -0
  64. package/dist/editor/StyleEditor.js.map +1 -0
  65. package/dist/editor/TokenWorkbench.d.ts +37 -0
  66. package/dist/editor/TokenWorkbench.d.ts.map +1 -0
  67. package/dist/editor/TokenWorkbench.js +146 -0
  68. package/dist/editor/TokenWorkbench.js.map +1 -0
  69. package/dist/editor/Tokens.d.ts +21 -0
  70. package/dist/editor/Tokens.d.ts.map +1 -0
  71. package/dist/editor/Tokens.js +56 -0
  72. package/dist/editor/Tokens.js.map +1 -0
  73. package/dist/editor/VariablesPage.d.ts +28 -0
  74. package/dist/editor/VariablesPage.d.ts.map +1 -0
  75. package/dist/editor/VariablesPage.js +14 -0
  76. package/dist/editor/VariablesPage.js.map +1 -0
  77. package/dist/editor/api.d.ts +13 -0
  78. package/dist/editor/api.d.ts.map +1 -0
  79. package/dist/editor/api.js +70 -0
  80. package/dist/editor/api.js.map +1 -0
  81. package/dist/editor/camera.d.ts +18 -0
  82. package/dist/editor/camera.d.ts.map +1 -0
  83. package/dist/editor/camera.js +40 -0
  84. package/dist/editor/camera.js.map +1 -0
  85. package/dist/editor/canvas.d.ts +26 -0
  86. package/dist/editor/canvas.d.ts.map +1 -0
  87. package/dist/editor/canvas.js +51 -0
  88. package/dist/editor/canvas.js.map +1 -0
  89. package/dist/editor/chrome/EditorChrome.d.ts +42 -0
  90. package/dist/editor/chrome/EditorChrome.d.ts.map +1 -0
  91. package/dist/editor/chrome/EditorChrome.js +21 -0
  92. package/dist/editor/chrome/EditorChrome.js.map +1 -0
  93. package/dist/editor/i18n.d.ts +18 -0
  94. package/dist/editor/i18n.d.ts.map +1 -0
  95. package/dist/editor/i18n.js +762 -0
  96. package/dist/editor/i18n.js.map +1 -0
  97. package/dist/editor/main.d.ts +3 -0
  98. package/dist/editor/main.d.ts.map +1 -0
  99. package/dist/editor/main.js +12 -0
  100. package/dist/editor/main.js.map +1 -0
  101. package/dist/editor/model.d.ts +17 -0
  102. package/dist/editor/model.d.ts.map +1 -0
  103. package/dist/editor/model.js +12 -0
  104. package/dist/editor/model.js.map +1 -0
  105. package/dist/editor/reviewLifecycle.d.ts +9 -0
  106. package/dist/editor/reviewLifecycle.d.ts.map +1 -0
  107. package/dist/editor/reviewLifecycle.js +30 -0
  108. package/dist/editor/reviewLifecycle.js.map +1 -0
  109. package/dist/editor/styles.css +6626 -0
  110. package/dist/editor/ui/Button.d.ts +3 -0
  111. package/dist/editor/ui/Button.d.ts.map +1 -0
  112. package/dist/editor/ui/Button.js +6 -0
  113. package/dist/editor/ui/Button.js.map +1 -0
  114. package/dist/editor/ui/CommentBox.d.ts +23 -0
  115. package/dist/editor/ui/CommentBox.d.ts.map +1 -0
  116. package/dist/editor/ui/CommentBox.js +41 -0
  117. package/dist/editor/ui/CommentBox.js.map +1 -0
  118. package/dist/editor/ui/Icon.d.ts +9 -0
  119. package/dist/editor/ui/Icon.d.ts.map +1 -0
  120. package/dist/editor/ui/Icon.js +6 -0
  121. package/dist/editor/ui/Icon.js.map +1 -0
  122. package/dist/editor/ui/IconButton.d.ts +11 -0
  123. package/dist/editor/ui/IconButton.d.ts.map +1 -0
  124. package/dist/editor/ui/IconButton.js +6 -0
  125. package/dist/editor/ui/IconButton.js.map +1 -0
  126. package/dist/editor/ui/NumberInput.d.ts +14 -0
  127. package/dist/editor/ui/NumberInput.d.ts.map +1 -0
  128. package/dist/editor/ui/NumberInput.js +6 -0
  129. package/dist/editor/ui/NumberInput.js.map +1 -0
  130. package/dist/editor/ui/PageLine.d.ts +14 -0
  131. package/dist/editor/ui/PageLine.d.ts.map +1 -0
  132. package/dist/editor/ui/PageLine.js +7 -0
  133. package/dist/editor/ui/PageLine.js.map +1 -0
  134. package/dist/editor/ui/Select.d.ts +15 -0
  135. package/dist/editor/ui/Select.d.ts.map +1 -0
  136. package/dist/editor/ui/Select.js +11 -0
  137. package/dist/editor/ui/Select.js.map +1 -0
  138. package/dist/editor/ui/TokenField.d.ts +14 -0
  139. package/dist/editor/ui/TokenField.d.ts.map +1 -0
  140. package/dist/editor/ui/TokenField.js +41 -0
  141. package/dist/editor/ui/TokenField.js.map +1 -0
  142. package/dist/editor-ui.d.ts +14 -0
  143. package/dist/editor-ui.d.ts.map +1 -0
  144. package/dist/editor-ui.js +13 -0
  145. package/dist/editor-ui.js.map +1 -0
  146. package/dist/inspector/runtime.d.ts +18 -0
  147. package/dist/inspector/runtime.d.ts.map +1 -0
  148. package/dist/inspector/runtime.js +987 -0
  149. package/dist/inspector/runtime.js.map +1 -0
  150. package/dist/preview/main.d.ts +3 -0
  151. package/dist/preview/main.d.ts.map +1 -0
  152. package/dist/preview/main.js +72 -0
  153. package/dist/preview/main.js.map +1 -0
  154. package/dist/preview/preview.css +39 -0
  155. package/dist/runtime/flow.d.ts +15 -0
  156. package/dist/runtime/flow.d.ts.map +1 -0
  157. package/dist/runtime/flow.js +48 -0
  158. package/dist/runtime/flow.js.map +1 -0
  159. package/dist/runtime/free.d.ts +18 -0
  160. package/dist/runtime/free.d.ts.map +1 -0
  161. package/dist/runtime/free.js +8 -0
  162. package/dist/runtime/free.js.map +1 -0
  163. package/dist/runtime/index.d.ts +11 -0
  164. package/dist/runtime/index.d.ts.map +1 -0
  165. package/dist/runtime/index.js +46 -0
  166. package/dist/runtime/index.js.map +1 -0
  167. package/dist/runtime/types.d.ts +57 -0
  168. package/dist/runtime/types.d.ts.map +1 -0
  169. package/dist/runtime/types.js +14 -0
  170. package/dist/runtime/types.js.map +1 -0
  171. package/dist/shared/prompt.d.mts +13 -0
  172. package/dist/shared/prompt.mjs +97 -0
  173. package/dist/shared/protocol.d.ts +79 -0
  174. package/dist/shared/protocol.d.ts.map +1 -0
  175. package/dist/shared/protocol.js +7 -0
  176. package/dist/shared/protocol.js.map +1 -0
  177. package/dist/shared/tokens.d.ts +66 -0
  178. package/dist/shared/tokens.d.ts.map +1 -0
  179. package/dist/shared/tokens.js +2 -0
  180. package/dist/shared/tokens.js.map +1 -0
  181. package/dist/shared/types.d.ts +301 -0
  182. package/dist/shared/types.d.ts.map +1 -0
  183. package/dist/shared/types.js +13 -0
  184. package/dist/shared/types.js.map +1 -0
  185. package/dist/tokens/adapters/css.mjs +44 -0
  186. package/dist/tokens/adapters/cssInCode.mjs +277 -0
  187. package/dist/tokens/adapters/oxcShared.mjs +59 -0
  188. package/dist/tokens/adapters/preprocessor.mjs +63 -0
  189. package/dist/tokens/adapters/registry.mjs +53 -0
  190. package/dist/tokens/adapters/tailwindcss.mjs +360 -0
  191. package/dist/tokens/adapters/types.mjs +117 -0
  192. package/dist/tokens/extract.mjs +328 -0
  193. package/dist/tokens/pipeline.mjs +688 -0
  194. package/dist/vite/events.d.ts +25 -0
  195. package/dist/vite/events.d.ts.map +1 -0
  196. package/dist/vite/events.js +137 -0
  197. package/dist/vite/events.js.map +1 -0
  198. package/dist/vite/layout.d.ts +4 -0
  199. package/dist/vite/layout.d.ts.map +1 -0
  200. package/dist/vite/layout.js +78 -0
  201. package/dist/vite/layout.js.map +1 -0
  202. package/dist/vite/plugin.d.ts +33 -0
  203. package/dist/vite/plugin.d.ts.map +1 -0
  204. package/dist/vite/plugin.js +403 -0
  205. package/dist/vite/plugin.js.map +1 -0
  206. package/dist/vite/review.d.ts +7 -0
  207. package/dist/vite/review.d.ts.map +1 -0
  208. package/dist/vite/review.js +334 -0
  209. package/dist/vite/review.js.map +1 -0
  210. package/package.json +87 -4
  211. package/skills/design-surface/SKILL.md +190 -0
  212. package/skills/design-surface-authoring/SKILL.md +257 -0
  213. package/skills/design-surface-tokens/SKILL.md +235 -0
  214. package/README.md +0 -3
@@ -0,0 +1,360 @@
1
+ import { parseSourceAst, staticStringOf, walkAst } from './oxcShared.mjs'
2
+
3
+ const CODE_EXT_RE = /\.(?:tsx|jsx|ts|js|mts|cts|mjs|cjs)$/i
4
+ const CLASS_HELPERS = new Set(['clsx', 'cn', 'classNames', 'classnames', 'twMerge', 'cva'])
5
+
6
+ const TW_COLOR_PREFIXES = new Set([
7
+ 'bg',
8
+ 'text',
9
+ 'border',
10
+ 'border-t',
11
+ 'border-r',
12
+ 'border-b',
13
+ 'border-l',
14
+ 'border-x',
15
+ 'border-y',
16
+ 'outline',
17
+ 'ring',
18
+ 'ring-offset',
19
+ 'divide',
20
+ 'accent',
21
+ 'caret',
22
+ 'fill',
23
+ 'stroke',
24
+ 'decoration',
25
+ 'shadow',
26
+ 'from',
27
+ 'via',
28
+ 'to',
29
+ 'placeholder',
30
+ ])
31
+
32
+ const TW_PALETTE_COLORS = new Set([
33
+ 'slate',
34
+ 'gray',
35
+ 'zinc',
36
+ 'neutral',
37
+ 'stone',
38
+ 'red',
39
+ 'orange',
40
+ 'amber',
41
+ 'yellow',
42
+ 'lime',
43
+ 'green',
44
+ 'emerald',
45
+ 'teal',
46
+ 'cyan',
47
+ 'sky',
48
+ 'blue',
49
+ 'indigo',
50
+ 'violet',
51
+ 'purple',
52
+ 'fuchsia',
53
+ 'pink',
54
+ 'rose',
55
+ ])
56
+
57
+ const TW_SHADES = new Set([
58
+ '50',
59
+ '100',
60
+ '200',
61
+ '300',
62
+ '400',
63
+ '500',
64
+ '600',
65
+ '700',
66
+ '800',
67
+ '900',
68
+ '950',
69
+ ])
70
+
71
+ const COLOR_LITERAL_VALUE_RE =
72
+ /^(?:#(?:[0-9a-fA-F]{3,4}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})|(?:rgba?|hsla?|oklch|oklab|color-mix|color)\(.*\))$/i
73
+
74
+ function stripVariants(token) {
75
+ let bracketDepth = 0
76
+ let parenDepth = 0
77
+ let lastColon = -1
78
+ for (let i = 0; i < token.length; i += 1) {
79
+ const ch = token[i]
80
+ if (ch === '[') bracketDepth += 1
81
+ else if (ch === ']' && bracketDepth > 0) bracketDepth -= 1
82
+ else if (ch === '(') parenDepth += 1
83
+ else if (ch === ')' && parenDepth > 0) parenDepth -= 1
84
+ else if (ch === ':' && bracketDepth === 0 && parenDepth === 0) lastColon = i
85
+ }
86
+ const core = lastColon >= 0 ? token.slice(lastColon + 1) : token
87
+ return core.startsWith('!') ? core.slice(1) : core
88
+ }
89
+
90
+ function splitClasses(raw) {
91
+ const tokens = []
92
+ let current = ''
93
+ let bracketDepth = 0
94
+ let parenDepth = 0
95
+ for (let i = 0; i < raw.length; i += 1) {
96
+ const ch = raw[i]
97
+ if (ch === '[') bracketDepth += 1
98
+ else if (ch === ']' && bracketDepth > 0) bracketDepth -= 1
99
+ else if (ch === '(') parenDepth += 1
100
+ else if (ch === ')' && parenDepth > 0) parenDepth -= 1
101
+ if (/\s/.test(ch) && bracketDepth === 0 && parenDepth === 0) {
102
+ if (current) {
103
+ tokens.push(current)
104
+ current = ''
105
+ }
106
+ continue
107
+ }
108
+ current += ch
109
+ }
110
+ if (current) tokens.push(current)
111
+ return tokens
112
+ }
113
+
114
+ function analyzeClassString(raw, { file, line, column, diagnostics }) {
115
+ for (const fullToken of splitClasses(raw)) {
116
+ const core = stripVariants(fullToken)
117
+ if (!core) continue
118
+
119
+ // Tailwind v4 shorthand: bg-(--color-surface), border-(--color-border), etc.
120
+ const parenVarMatch = /^([a-z-]+)-\((--[a-zA-Z0-9_-]+)\)$/.exec(core)
121
+ if (parenVarMatch) {
122
+ diagnostics.push({
123
+ file,
124
+ line,
125
+ column,
126
+ adapter: 'tailwindcss',
127
+ kind: 'token-ref',
128
+ property: parenVarMatch[1],
129
+ value: fullToken,
130
+ token: parenVarMatch[2],
131
+ })
132
+ continue
133
+ }
134
+
135
+ // Arbitrary value: bg-[var(--xxx)] or bg-[#2563eb] or text-[rgb(...)]
136
+ const bracketMatch = /^([a-z-]+)-\[([^\]]+)\]$/.exec(core)
137
+ if (bracketMatch) {
138
+ const property = bracketMatch[1]
139
+ const inner = bracketMatch[2].trim()
140
+ const varMatch = /^var\(\s*(--[a-zA-Z0-9_-]+)/.exec(inner)
141
+ if (varMatch) {
142
+ diagnostics.push({
143
+ file,
144
+ line,
145
+ column,
146
+ adapter: 'tailwindcss',
147
+ kind: 'token-ref',
148
+ property,
149
+ value: fullToken,
150
+ token: varMatch[1],
151
+ })
152
+ continue
153
+ }
154
+ if (COLOR_LITERAL_VALUE_RE.test(inner)) {
155
+ diagnostics.push({
156
+ file,
157
+ line,
158
+ column,
159
+ adapter: 'tailwindcss',
160
+ kind: 'literal',
161
+ property,
162
+ value: inner,
163
+ })
164
+ continue
165
+ }
166
+ }
167
+
168
+ // Default Tailwind palette classes: bg-blue-600, border-red-500/50, text-black, bg-white/80
169
+ const withoutOpacity = core.replace(/\/(?:\d+(?:\.\d+)?|\[[^\]]+\])$/, '')
170
+ const parts = withoutOpacity.split('-')
171
+ if (parts.length >= 2) {
172
+ const last = parts[parts.length - 1]
173
+ const secondLast = parts[parts.length - 2]
174
+ if (parts.length >= 3 && TW_SHADES.has(last) && TW_PALETTE_COLORS.has(secondLast)) {
175
+ const prefix = parts.slice(0, -2).join('-')
176
+ if (TW_COLOR_PREFIXES.has(prefix)) {
177
+ diagnostics.push({
178
+ file,
179
+ line,
180
+ column,
181
+ adapter: 'tailwindcss',
182
+ kind: 'literal',
183
+ property: prefix,
184
+ value: fullToken,
185
+ })
186
+ continue
187
+ }
188
+ } else if (last === 'black' || last === 'white') {
189
+ const prefix = parts.slice(0, -1).join('-')
190
+ if (TW_COLOR_PREFIXES.has(prefix)) {
191
+ diagnostics.push({
192
+ file,
193
+ line,
194
+ column,
195
+ adapter: 'tailwindcss',
196
+ kind: 'literal',
197
+ property: prefix,
198
+ value: fullToken,
199
+ })
200
+ continue
201
+ }
202
+ }
203
+ }
204
+ }
205
+ }
206
+
207
+ function analyzeClassExpression(expr, { file, content, locationAt, diagnostics }) {
208
+ if (!expr) return
209
+ const strVal = staticStringOf(expr)
210
+ if (strVal !== null) {
211
+ const loc = locationAt(expr.start)
212
+ analyzeClassString(strVal, { file, ...loc, diagnostics })
213
+ return
214
+ }
215
+
216
+ if (expr.type === 'TemplateLiteral' && (expr.expressions?.length ?? 0) > 0) {
217
+ const loc = locationAt(expr.start)
218
+ diagnostics.push({
219
+ file,
220
+ ...loc,
221
+ adapter: 'tailwindcss',
222
+ kind: 'unsupported',
223
+ property: 'className',
224
+ value: content.slice(expr.start, Math.min(expr.end, expr.start + 60)),
225
+ reason: 'dynamic-class',
226
+ })
227
+ return
228
+ }
229
+
230
+ if (expr.type === 'ArrayExpression') {
231
+ for (const elem of expr.elements ?? []) {
232
+ if (elem) analyzeClassExpression(elem, { file, content, locationAt, diagnostics })
233
+ }
234
+ return
235
+ }
236
+
237
+ if (expr.type === 'ConditionalExpression') {
238
+ analyzeClassExpression(expr.consequent, { file, content, locationAt, diagnostics })
239
+ analyzeClassExpression(expr.alternate, { file, content, locationAt, diagnostics })
240
+ return
241
+ }
242
+
243
+ if (expr.type === 'LogicalExpression') {
244
+ analyzeClassExpression(expr.right, { file, content, locationAt, diagnostics })
245
+ return
246
+ }
247
+
248
+ if (expr.type === 'ObjectExpression') {
249
+ for (const prop of expr.properties ?? []) {
250
+ if (prop.type !== 'Property') {
251
+ const loc = locationAt(prop.start)
252
+ diagnostics.push({
253
+ file,
254
+ ...loc,
255
+ adapter: 'tailwindcss',
256
+ kind: 'unsupported',
257
+ property: 'className',
258
+ value: content.slice(prop.start, Math.min(prop.end, prop.start + 60)),
259
+ reason: 'dynamic-class',
260
+ })
261
+ continue
262
+ }
263
+ if (prop.key?.type === 'Literal' && typeof prop.key.value === 'string') {
264
+ const loc = locationAt(prop.key.start)
265
+ analyzeClassString(prop.key.value, { file, ...loc, diagnostics })
266
+ } else if (prop.key?.type === 'Identifier' && !prop.computed) {
267
+ const loc = locationAt(prop.key.start)
268
+ analyzeClassString(prop.key.name, { file, ...loc, diagnostics })
269
+ } else {
270
+ const loc = locationAt(prop.start)
271
+ diagnostics.push({
272
+ file,
273
+ ...loc,
274
+ adapter: 'tailwindcss',
275
+ kind: 'unsupported',
276
+ property: 'className',
277
+ value: content.slice(prop.start, Math.min(prop.end, prop.start + 60)),
278
+ reason: 'dynamic-class',
279
+ })
280
+ }
281
+ }
282
+ return
283
+ }
284
+
285
+ if (expr.type === 'CallExpression') {
286
+ const calleeName =
287
+ expr.callee?.type === 'Identifier'
288
+ ? expr.callee.name
289
+ : expr.callee?.type === 'MemberExpression' && expr.callee.property?.type === 'Identifier'
290
+ ? expr.callee.property.name
291
+ : ''
292
+ if (CLASS_HELPERS.has(calleeName)) {
293
+ for (const arg of expr.arguments ?? []) {
294
+ analyzeClassExpression(arg, { file, content, locationAt, diagnostics })
295
+ }
296
+ return
297
+ }
298
+ }
299
+
300
+ if (expr.type === 'Literal' && (expr.value === null || expr.value === false || expr.value === undefined)) {
301
+ return
302
+ }
303
+
304
+ const loc = locationAt(expr.start)
305
+ diagnostics.push({
306
+ file,
307
+ ...loc,
308
+ adapter: 'tailwindcss',
309
+ kind: 'unsupported',
310
+ property: 'className',
311
+ value: content.slice(expr.start, Math.min(expr.end, expr.start + 60)),
312
+ reason: 'dynamic-class',
313
+ })
314
+ }
315
+
316
+ export const tailwindcssAdapter = {
317
+ id: 'tailwindcss',
318
+ detect(file) {
319
+ return CODE_EXT_RE.test(file)
320
+ },
321
+ analyze(file, content, ctx) {
322
+ const { program, locationAt } = parseSourceAst(file, content, ctx)
323
+ const diagnostics = []
324
+
325
+ walkAst(program, (node) => {
326
+ if (
327
+ node.type === 'JSXAttribute' &&
328
+ node.name?.type === 'JSXIdentifier' &&
329
+ (node.name.name === 'className' || node.name.name === 'class')
330
+ ) {
331
+ const value = node.value
332
+ if (!value) return false
333
+ if (value.type === 'Literal' && typeof value.value === 'string') {
334
+ const loc = locationAt(value.start)
335
+ analyzeClassString(value.value, { file, ...loc, diagnostics })
336
+ } else if (value.type === 'JSXExpressionContainer') {
337
+ analyzeClassExpression(value.expression, { file, content, locationAt, diagnostics })
338
+ }
339
+ return false
340
+ }
341
+
342
+ if (node.type === 'CallExpression') {
343
+ const calleeName =
344
+ node.callee?.type === 'Identifier'
345
+ ? node.callee.name
346
+ : node.callee?.type === 'MemberExpression' && node.callee.property?.type === 'Identifier'
347
+ ? node.callee.property.name
348
+ : ''
349
+ if (CLASS_HELPERS.has(calleeName)) {
350
+ for (const arg of node.arguments ?? []) {
351
+ analyzeClassExpression(arg, { file, content, locationAt, diagnostics })
352
+ }
353
+ return false
354
+ }
355
+ }
356
+ })
357
+
358
+ return diagnostics
359
+ },
360
+ }
@@ -0,0 +1,117 @@
1
+ import valueParser from 'postcss-value-parser'
2
+
3
+ const COLOR_FN_RE = /^(?:rgba?|hsla?|oklch|oklab|color-mix|color)$/i
4
+ const HEX_COLOR_RE = /^#(?:[0-9a-fA-F]{3,4}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$/
5
+
6
+ export function createLineIndex(content) {
7
+ const lineStarts = [0]
8
+ for (let i = 0; i < content.length; i += 1) {
9
+ if (content.charCodeAt(i) === 10) lineStarts.push(i + 1)
10
+ }
11
+ return (offset) => {
12
+ const clamped = Math.max(0, Math.min(offset ?? 0, content.length))
13
+ let low = 0
14
+ let high = lineStarts.length - 1
15
+ while (low <= high) {
16
+ const mid = (low + high) >> 1
17
+ if (lineStarts[mid] <= clamped) low = mid + 1
18
+ else high = mid - 1
19
+ }
20
+ const lineIdx = Math.max(0, high)
21
+ return {
22
+ line: lineIdx + 1,
23
+ column: clamped - lineStarts[lineIdx] + 1,
24
+ }
25
+ }
26
+ }
27
+
28
+ export function nodeContainsVar(node) {
29
+ if (!node) return false
30
+ if (node.type === 'function' && node.value.toLowerCase() === 'var') {
31
+ return Array.isArray(node.nodes) && node.nodes.some((child) => child.type === 'word' && child.value.startsWith('--'))
32
+ }
33
+ if (Array.isArray(node.nodes)) {
34
+ return node.nodes.some(nodeContainsVar)
35
+ }
36
+ return false
37
+ }
38
+
39
+ export function extractCssValueDiagnostics({
40
+ file,
41
+ line,
42
+ column = 1,
43
+ adapter,
44
+ property,
45
+ value,
46
+ includeLiterals = true,
47
+ }) {
48
+ const diagnostics = []
49
+ const parsed = valueParser(String(value ?? ''))
50
+
51
+ const visitNodes = (nodes) => {
52
+ for (const node of nodes) {
53
+ if (node.type === 'comment' || node.type === 'string') continue
54
+
55
+ if (node.type === 'function') {
56
+ const fnName = node.value.toLowerCase()
57
+ if (fnName === 'url') continue
58
+ if (fnName === 'var') {
59
+ const arg = (node.nodes ?? []).find((child) => child.type === 'word' && child.value.startsWith('--'))
60
+ if (arg) {
61
+ diagnostics.push({
62
+ file,
63
+ line,
64
+ column: column + (node.sourceIndex ?? 0),
65
+ adapter,
66
+ kind: 'token-ref',
67
+ ...(property ? { property } : {}),
68
+ value: valueParser.stringify(node),
69
+ token: arg.value,
70
+ })
71
+ }
72
+ // Also inspect nested var(...) fallbacks without treating literal fallbacks as hardcoded errors.
73
+ const nestedVars = (node.nodes ?? []).filter(
74
+ (child) => child.type === 'function' && child.value.toLowerCase() === 'var',
75
+ )
76
+ if (nestedVars.length) visitNodes(nestedVars)
77
+ continue
78
+ }
79
+ if (COLOR_FN_RE.test(fnName)) {
80
+ if (nodeContainsVar(node)) {
81
+ visitNodes(node.nodes ?? [])
82
+ } else if (includeLiterals) {
83
+ diagnostics.push({
84
+ file,
85
+ line,
86
+ column: column + (node.sourceIndex ?? 0),
87
+ adapter,
88
+ kind: 'literal',
89
+ ...(property ? { property } : {}),
90
+ value: valueParser.stringify(node),
91
+ })
92
+ }
93
+ continue
94
+ }
95
+ if (Array.isArray(node.nodes) && node.nodes.length) {
96
+ visitNodes(node.nodes)
97
+ }
98
+ continue
99
+ }
100
+
101
+ if (node.type === 'word' && includeLiterals && HEX_COLOR_RE.test(node.value)) {
102
+ diagnostics.push({
103
+ file,
104
+ line,
105
+ column: column + (node.sourceIndex ?? 0),
106
+ adapter,
107
+ kind: 'literal',
108
+ ...(property ? { property } : {}),
109
+ value: node.value,
110
+ })
111
+ }
112
+ }
113
+ }
114
+
115
+ visitNodes(parsed.nodes)
116
+ return diagnostics
117
+ }