@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.
- package/bin/design-surface.mjs +286 -0
- package/dist/cli/init.mjs +411 -0
- package/dist/cli/propose.mjs +172 -0
- package/dist/cli/reviewOps.mjs +127 -0
- package/dist/editor/AgentProposalCard.d.ts +10 -0
- package/dist/editor/AgentProposalCard.d.ts.map +1 -0
- package/dist/editor/AgentProposalCard.js +28 -0
- package/dist/editor/AgentProposalCard.js.map +1 -0
- package/dist/editor/App.d.ts +2 -0
- package/dist/editor/App.d.ts.map +1 -0
- package/dist/editor/App.js +1813 -0
- package/dist/editor/App.js.map +1 -0
- package/dist/editor/CanvasHud.d.ts +12 -0
- package/dist/editor/CanvasHud.d.ts.map +1 -0
- package/dist/editor/CanvasHud.js +13 -0
- package/dist/editor/CanvasHud.js.map +1 -0
- package/dist/editor/CanvasSurface.d.ts +20 -0
- package/dist/editor/CanvasSurface.d.ts.map +1 -0
- package/dist/editor/CanvasSurface.js +252 -0
- package/dist/editor/CanvasSurface.js.map +1 -0
- package/dist/editor/Changes.d.ts +17 -0
- package/dist/editor/Changes.d.ts.map +1 -0
- package/dist/editor/Changes.js +59 -0
- package/dist/editor/Changes.js.map +1 -0
- package/dist/editor/CommentPopover.d.ts +17 -0
- package/dist/editor/CommentPopover.d.ts.map +1 -0
- package/dist/editor/CommentPopover.js +62 -0
- package/dist/editor/CommentPopover.js.map +1 -0
- package/dist/editor/Comments.d.ts +13 -0
- package/dist/editor/Comments.d.ts.map +1 -0
- package/dist/editor/Comments.js +39 -0
- package/dist/editor/Comments.js.map +1 -0
- package/dist/editor/History.d.ts +7 -0
- package/dist/editor/History.d.ts.map +1 -0
- package/dist/editor/History.js +43 -0
- package/dist/editor/History.js.map +1 -0
- package/dist/editor/Inspector.d.ts +22 -0
- package/dist/editor/Inspector.d.ts.map +1 -0
- package/dist/editor/Inspector.js +241 -0
- package/dist/editor/Inspector.js.map +1 -0
- package/dist/editor/LazyMount.d.ts +10 -0
- package/dist/editor/LazyMount.d.ts.map +1 -0
- package/dist/editor/LazyMount.js +29 -0
- package/dist/editor/LazyMount.js.map +1 -0
- package/dist/editor/LocaleSwitch.d.ts +2 -0
- package/dist/editor/LocaleSwitch.d.ts.map +1 -0
- package/dist/editor/LocaleSwitch.js +13 -0
- package/dist/editor/LocaleSwitch.js.map +1 -0
- package/dist/editor/NodeInspector.d.ts +9 -0
- package/dist/editor/NodeInspector.d.ts.map +1 -0
- package/dist/editor/NodeInspector.js +9 -0
- package/dist/editor/NodeInspector.js.map +1 -0
- package/dist/editor/PreviewFrame.d.ts +10 -0
- package/dist/editor/PreviewFrame.d.ts.map +1 -0
- package/dist/editor/PreviewFrame.js +22 -0
- package/dist/editor/PreviewFrame.js.map +1 -0
- package/dist/editor/ProjectIndex.d.ts +12 -0
- package/dist/editor/ProjectIndex.d.ts.map +1 -0
- package/dist/editor/ProjectIndex.js +43 -0
- package/dist/editor/ProjectIndex.js.map +1 -0
- package/dist/editor/StyleEditor.d.ts +37 -0
- package/dist/editor/StyleEditor.d.ts.map +1 -0
- package/dist/editor/StyleEditor.js +275 -0
- package/dist/editor/StyleEditor.js.map +1 -0
- package/dist/editor/TokenWorkbench.d.ts +37 -0
- package/dist/editor/TokenWorkbench.d.ts.map +1 -0
- package/dist/editor/TokenWorkbench.js +146 -0
- package/dist/editor/TokenWorkbench.js.map +1 -0
- package/dist/editor/Tokens.d.ts +21 -0
- package/dist/editor/Tokens.d.ts.map +1 -0
- package/dist/editor/Tokens.js +56 -0
- package/dist/editor/Tokens.js.map +1 -0
- package/dist/editor/VariablesPage.d.ts +28 -0
- package/dist/editor/VariablesPage.d.ts.map +1 -0
- package/dist/editor/VariablesPage.js +14 -0
- package/dist/editor/VariablesPage.js.map +1 -0
- package/dist/editor/api.d.ts +13 -0
- package/dist/editor/api.d.ts.map +1 -0
- package/dist/editor/api.js +70 -0
- package/dist/editor/api.js.map +1 -0
- package/dist/editor/camera.d.ts +18 -0
- package/dist/editor/camera.d.ts.map +1 -0
- package/dist/editor/camera.js +40 -0
- package/dist/editor/camera.js.map +1 -0
- package/dist/editor/canvas.d.ts +26 -0
- package/dist/editor/canvas.d.ts.map +1 -0
- package/dist/editor/canvas.js +51 -0
- package/dist/editor/canvas.js.map +1 -0
- package/dist/editor/chrome/EditorChrome.d.ts +42 -0
- package/dist/editor/chrome/EditorChrome.d.ts.map +1 -0
- package/dist/editor/chrome/EditorChrome.js +21 -0
- package/dist/editor/chrome/EditorChrome.js.map +1 -0
- package/dist/editor/i18n.d.ts +18 -0
- package/dist/editor/i18n.d.ts.map +1 -0
- package/dist/editor/i18n.js +762 -0
- package/dist/editor/i18n.js.map +1 -0
- package/dist/editor/main.d.ts +3 -0
- package/dist/editor/main.d.ts.map +1 -0
- package/dist/editor/main.js +12 -0
- package/dist/editor/main.js.map +1 -0
- package/dist/editor/model.d.ts +17 -0
- package/dist/editor/model.d.ts.map +1 -0
- package/dist/editor/model.js +12 -0
- package/dist/editor/model.js.map +1 -0
- package/dist/editor/reviewLifecycle.d.ts +9 -0
- package/dist/editor/reviewLifecycle.d.ts.map +1 -0
- package/dist/editor/reviewLifecycle.js +30 -0
- package/dist/editor/reviewLifecycle.js.map +1 -0
- package/dist/editor/styles.css +6626 -0
- package/dist/editor/ui/Button.d.ts +3 -0
- package/dist/editor/ui/Button.d.ts.map +1 -0
- package/dist/editor/ui/Button.js +6 -0
- package/dist/editor/ui/Button.js.map +1 -0
- package/dist/editor/ui/CommentBox.d.ts +23 -0
- package/dist/editor/ui/CommentBox.d.ts.map +1 -0
- package/dist/editor/ui/CommentBox.js +41 -0
- package/dist/editor/ui/CommentBox.js.map +1 -0
- package/dist/editor/ui/Icon.d.ts +9 -0
- package/dist/editor/ui/Icon.d.ts.map +1 -0
- package/dist/editor/ui/Icon.js +6 -0
- package/dist/editor/ui/Icon.js.map +1 -0
- package/dist/editor/ui/IconButton.d.ts +11 -0
- package/dist/editor/ui/IconButton.d.ts.map +1 -0
- package/dist/editor/ui/IconButton.js +6 -0
- package/dist/editor/ui/IconButton.js.map +1 -0
- package/dist/editor/ui/NumberInput.d.ts +14 -0
- package/dist/editor/ui/NumberInput.d.ts.map +1 -0
- package/dist/editor/ui/NumberInput.js +6 -0
- package/dist/editor/ui/NumberInput.js.map +1 -0
- package/dist/editor/ui/PageLine.d.ts +14 -0
- package/dist/editor/ui/PageLine.d.ts.map +1 -0
- package/dist/editor/ui/PageLine.js +7 -0
- package/dist/editor/ui/PageLine.js.map +1 -0
- package/dist/editor/ui/Select.d.ts +15 -0
- package/dist/editor/ui/Select.d.ts.map +1 -0
- package/dist/editor/ui/Select.js +11 -0
- package/dist/editor/ui/Select.js.map +1 -0
- package/dist/editor/ui/TokenField.d.ts +14 -0
- package/dist/editor/ui/TokenField.d.ts.map +1 -0
- package/dist/editor/ui/TokenField.js +41 -0
- package/dist/editor/ui/TokenField.js.map +1 -0
- package/dist/editor-ui.d.ts +14 -0
- package/dist/editor-ui.d.ts.map +1 -0
- package/dist/editor-ui.js +13 -0
- package/dist/editor-ui.js.map +1 -0
- package/dist/inspector/runtime.d.ts +18 -0
- package/dist/inspector/runtime.d.ts.map +1 -0
- package/dist/inspector/runtime.js +987 -0
- package/dist/inspector/runtime.js.map +1 -0
- package/dist/preview/main.d.ts +3 -0
- package/dist/preview/main.d.ts.map +1 -0
- package/dist/preview/main.js +72 -0
- package/dist/preview/main.js.map +1 -0
- package/dist/preview/preview.css +39 -0
- package/dist/runtime/flow.d.ts +15 -0
- package/dist/runtime/flow.d.ts.map +1 -0
- package/dist/runtime/flow.js +48 -0
- package/dist/runtime/flow.js.map +1 -0
- package/dist/runtime/free.d.ts +18 -0
- package/dist/runtime/free.d.ts.map +1 -0
- package/dist/runtime/free.js +8 -0
- package/dist/runtime/free.js.map +1 -0
- package/dist/runtime/index.d.ts +11 -0
- package/dist/runtime/index.d.ts.map +1 -0
- package/dist/runtime/index.js +46 -0
- package/dist/runtime/index.js.map +1 -0
- package/dist/runtime/types.d.ts +57 -0
- package/dist/runtime/types.d.ts.map +1 -0
- package/dist/runtime/types.js +14 -0
- package/dist/runtime/types.js.map +1 -0
- package/dist/shared/prompt.d.mts +13 -0
- package/dist/shared/prompt.mjs +97 -0
- package/dist/shared/protocol.d.ts +79 -0
- package/dist/shared/protocol.d.ts.map +1 -0
- package/dist/shared/protocol.js +7 -0
- package/dist/shared/protocol.js.map +1 -0
- package/dist/shared/tokens.d.ts +66 -0
- package/dist/shared/tokens.d.ts.map +1 -0
- package/dist/shared/tokens.js +2 -0
- package/dist/shared/tokens.js.map +1 -0
- package/dist/shared/types.d.ts +301 -0
- package/dist/shared/types.d.ts.map +1 -0
- package/dist/shared/types.js +13 -0
- package/dist/shared/types.js.map +1 -0
- package/dist/tokens/adapters/css.mjs +44 -0
- package/dist/tokens/adapters/cssInCode.mjs +277 -0
- package/dist/tokens/adapters/oxcShared.mjs +59 -0
- package/dist/tokens/adapters/preprocessor.mjs +63 -0
- package/dist/tokens/adapters/registry.mjs +53 -0
- package/dist/tokens/adapters/tailwindcss.mjs +360 -0
- package/dist/tokens/adapters/types.mjs +117 -0
- package/dist/tokens/extract.mjs +328 -0
- package/dist/tokens/pipeline.mjs +688 -0
- package/dist/vite/events.d.ts +25 -0
- package/dist/vite/events.d.ts.map +1 -0
- package/dist/vite/events.js +137 -0
- package/dist/vite/events.js.map +1 -0
- package/dist/vite/layout.d.ts +4 -0
- package/dist/vite/layout.d.ts.map +1 -0
- package/dist/vite/layout.js +78 -0
- package/dist/vite/layout.js.map +1 -0
- package/dist/vite/plugin.d.ts +33 -0
- package/dist/vite/plugin.d.ts.map +1 -0
- package/dist/vite/plugin.js +403 -0
- package/dist/vite/plugin.js.map +1 -0
- package/dist/vite/review.d.ts +7 -0
- package/dist/vite/review.d.ts.map +1 -0
- package/dist/vite/review.js +334 -0
- package/dist/vite/review.js.map +1 -0
- package/package.json +87 -4
- package/skills/design-surface/SKILL.md +190 -0
- package/skills/design-surface-authoring/SKILL.md +257 -0
- package/skills/design-surface-tokens/SKILL.md +235 -0
- package/README.md +0 -3
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
import {
|
|
2
|
+
camelToKebab,
|
|
3
|
+
parseSourceAst,
|
|
4
|
+
propertyKeyName,
|
|
5
|
+
staticStringOf,
|
|
6
|
+
walkAst,
|
|
7
|
+
} from './oxcShared.mjs'
|
|
8
|
+
import { extractCssValueDiagnostics } from './types.mjs'
|
|
9
|
+
|
|
10
|
+
const CODE_EXT_RE = /\.(?:tsx|jsx|ts|js|mts|cts|mjs|cjs)$/i
|
|
11
|
+
const STYLE_OBJECT_NAME_RE = /(?:^|_|-)styles?$/i
|
|
12
|
+
|
|
13
|
+
function analyzeStyleObject(objNode, { file, content, locationAt, adapter, diagnostics, nested = false }) {
|
|
14
|
+
for (const prop of objNode.properties ?? []) {
|
|
15
|
+
if (prop.type === 'SpreadElement') {
|
|
16
|
+
const loc = locationAt(prop.start)
|
|
17
|
+
diagnostics.push({
|
|
18
|
+
file,
|
|
19
|
+
...loc,
|
|
20
|
+
adapter,
|
|
21
|
+
kind: 'unsupported',
|
|
22
|
+
property: '...spread',
|
|
23
|
+
value: content.slice(prop.start, Math.min(prop.end, prop.start + 60)),
|
|
24
|
+
reason: 'dynamic-style-expression',
|
|
25
|
+
})
|
|
26
|
+
continue
|
|
27
|
+
}
|
|
28
|
+
if (prop.type !== 'Property') continue
|
|
29
|
+
if (prop.computed) {
|
|
30
|
+
const loc = locationAt(prop.start)
|
|
31
|
+
diagnostics.push({
|
|
32
|
+
file,
|
|
33
|
+
...loc,
|
|
34
|
+
adapter,
|
|
35
|
+
kind: 'unsupported',
|
|
36
|
+
value: content.slice(prop.start, Math.min(prop.end, prop.start + 60)),
|
|
37
|
+
reason: 'dynamic-style-expression',
|
|
38
|
+
})
|
|
39
|
+
continue
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const rawKey = propertyKeyName(prop.key)
|
|
43
|
+
const property = rawKey ? camelToKebab(rawKey) : undefined
|
|
44
|
+
const valNode = prop.value
|
|
45
|
+
|
|
46
|
+
if (
|
|
47
|
+
nested &&
|
|
48
|
+
valNode?.type === 'ObjectExpression' &&
|
|
49
|
+
rawKey &&
|
|
50
|
+
(rawKey.startsWith(':') || rawKey.startsWith('@') || rawKey === 'default')
|
|
51
|
+
) {
|
|
52
|
+
analyzeStyleObject(valNode, { file, content, locationAt, adapter, diagnostics, nested: true })
|
|
53
|
+
continue
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (nested && valNode?.type === 'ObjectExpression') {
|
|
57
|
+
// Nested pseudo/media map inside stylex.create({ card: { color: { default: ..., ':hover': ... } } })
|
|
58
|
+
analyzeStyleObject(valNode, { file, content, locationAt, adapter, diagnostics, nested: true })
|
|
59
|
+
continue
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const strVal = staticStringOf(valNode)
|
|
63
|
+
if (strVal !== null) {
|
|
64
|
+
const loc = locationAt(valNode.start)
|
|
65
|
+
diagnostics.push(
|
|
66
|
+
...extractCssValueDiagnostics({
|
|
67
|
+
file,
|
|
68
|
+
...loc,
|
|
69
|
+
adapter,
|
|
70
|
+
property,
|
|
71
|
+
value: strVal,
|
|
72
|
+
includeLiterals: true,
|
|
73
|
+
}),
|
|
74
|
+
)
|
|
75
|
+
continue
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (
|
|
79
|
+
valNode?.type === 'Literal' &&
|
|
80
|
+
(typeof valNode.value === 'number' || typeof valNode.value === 'boolean' || valNode.value === null)
|
|
81
|
+
) {
|
|
82
|
+
continue
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (valNode) {
|
|
86
|
+
const loc = locationAt(valNode.start)
|
|
87
|
+
diagnostics.push({
|
|
88
|
+
file,
|
|
89
|
+
...loc,
|
|
90
|
+
adapter,
|
|
91
|
+
kind: 'unsupported',
|
|
92
|
+
...(property ? { property } : {}),
|
|
93
|
+
value: content.slice(valNode.start, Math.min(valNode.end, valNode.start + 60)),
|
|
94
|
+
reason: 'dynamic-style-expression',
|
|
95
|
+
})
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export const cssInCodeAdapter = {
|
|
101
|
+
id: 'css-in-code',
|
|
102
|
+
detect(file) {
|
|
103
|
+
return CODE_EXT_RE.test(file)
|
|
104
|
+
},
|
|
105
|
+
analyze(file, content, ctx) {
|
|
106
|
+
const { program, locationAt } = parseSourceAst(file, content, ctx)
|
|
107
|
+
const diagnostics = []
|
|
108
|
+
const stylexNamespaces = new Set()
|
|
109
|
+
const stylexCreators = new Set()
|
|
110
|
+
const stylexVarDefiners = new Set()
|
|
111
|
+
const stylexEnabled = !ctx?.enabledIds || ctx.enabledIds.has('stylex')
|
|
112
|
+
const visitedObjects = new Set()
|
|
113
|
+
|
|
114
|
+
walkAst(program, (node) => {
|
|
115
|
+
if (node.type === 'ImportDeclaration' && node.source?.value === '@stylexjs/stylex') {
|
|
116
|
+
for (const spec of node.specifiers ?? []) {
|
|
117
|
+
if (spec.type === 'ImportNamespaceSpecifier' || spec.type === 'ImportDefaultSpecifier') {
|
|
118
|
+
stylexNamespaces.add(spec.local.name)
|
|
119
|
+
} else if (spec.type === 'ImportSpecifier') {
|
|
120
|
+
const imported = spec.imported?.name ?? spec.imported?.value
|
|
121
|
+
if (imported === 'create') stylexCreators.add(spec.local.name)
|
|
122
|
+
if (imported === 'defineVars') stylexVarDefiners.add(spec.local.name)
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return false
|
|
126
|
+
}
|
|
127
|
+
})
|
|
128
|
+
|
|
129
|
+
walkAst(program, (node) => {
|
|
130
|
+
if (node.type === 'JSXAttribute' && node.name?.type === 'JSXIdentifier' && node.name.name === 'style') {
|
|
131
|
+
const container = node.value
|
|
132
|
+
if (!container || container.type !== 'JSXExpressionContainer') return false
|
|
133
|
+
const expr = container.expression
|
|
134
|
+
if (!expr || expr.type === 'JSXEmptyExpression') return false
|
|
135
|
+
if (expr.type === 'ObjectExpression') {
|
|
136
|
+
visitedObjects.add(expr)
|
|
137
|
+
analyzeStyleObject(expr, {
|
|
138
|
+
file,
|
|
139
|
+
content,
|
|
140
|
+
locationAt,
|
|
141
|
+
adapter: 'css-in-code',
|
|
142
|
+
diagnostics,
|
|
143
|
+
})
|
|
144
|
+
} else {
|
|
145
|
+
const loc = locationAt(expr.start)
|
|
146
|
+
diagnostics.push({
|
|
147
|
+
file,
|
|
148
|
+
...loc,
|
|
149
|
+
adapter: 'css-in-code',
|
|
150
|
+
kind: 'unsupported',
|
|
151
|
+
property: 'style',
|
|
152
|
+
value: content.slice(expr.start, Math.min(expr.end, expr.start + 60)),
|
|
153
|
+
reason: 'dynamic-style-expression',
|
|
154
|
+
})
|
|
155
|
+
}
|
|
156
|
+
return false
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
if (node.type === 'CallExpression') {
|
|
160
|
+
const callee = node.callee
|
|
161
|
+
const isStylexCreate =
|
|
162
|
+
(callee?.type === 'MemberExpression' &&
|
|
163
|
+
callee.object?.type === 'Identifier' &&
|
|
164
|
+
stylexNamespaces.has(callee.object.name) &&
|
|
165
|
+
callee.property?.type === 'Identifier' &&
|
|
166
|
+
callee.property.name === 'create') ||
|
|
167
|
+
(callee?.type === 'Identifier' && stylexCreators.has(callee.name))
|
|
168
|
+
|
|
169
|
+
const isStylexDefineVars =
|
|
170
|
+
(callee?.type === 'MemberExpression' &&
|
|
171
|
+
callee.object?.type === 'Identifier' &&
|
|
172
|
+
stylexNamespaces.has(callee.object.name) &&
|
|
173
|
+
callee.property?.type === 'Identifier' &&
|
|
174
|
+
callee.property.name === 'defineVars') ||
|
|
175
|
+
(callee?.type === 'Identifier' && stylexVarDefiners.has(callee.name))
|
|
176
|
+
|
|
177
|
+
if (isStylexDefineVars && stylexEnabled) {
|
|
178
|
+
const loc = locationAt(node.start)
|
|
179
|
+
diagnostics.push({
|
|
180
|
+
file,
|
|
181
|
+
...loc,
|
|
182
|
+
adapter: 'stylex',
|
|
183
|
+
kind: 'unsupported',
|
|
184
|
+
value: content.slice(node.start, Math.min(node.end, node.start + 60)),
|
|
185
|
+
reason: 'stylex-define-vars',
|
|
186
|
+
})
|
|
187
|
+
return false
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
if (isStylexCreate) {
|
|
191
|
+
const arg = node.arguments?.[0]
|
|
192
|
+
if (arg?.type === 'ObjectExpression') {
|
|
193
|
+
visitedObjects.add(arg)
|
|
194
|
+
for (const ruleProp of arg.properties ?? []) {
|
|
195
|
+
if (ruleProp.type !== 'Property') continue
|
|
196
|
+
const ruleName = propertyKeyName(ruleProp.key)
|
|
197
|
+
if (ruleProp.value?.type === 'ObjectExpression') {
|
|
198
|
+
visitedObjects.add(ruleProp.value)
|
|
199
|
+
analyzeStyleObject(ruleProp.value, {
|
|
200
|
+
file,
|
|
201
|
+
content,
|
|
202
|
+
locationAt,
|
|
203
|
+
adapter: 'css-in-code',
|
|
204
|
+
diagnostics,
|
|
205
|
+
nested: true,
|
|
206
|
+
})
|
|
207
|
+
} else if (
|
|
208
|
+
stylexEnabled &&
|
|
209
|
+
(ruleProp.value?.type === 'ArrowFunctionExpression' ||
|
|
210
|
+
ruleProp.value?.type === 'FunctionExpression')
|
|
211
|
+
) {
|
|
212
|
+
const loc = locationAt(ruleProp.value.start)
|
|
213
|
+
diagnostics.push({
|
|
214
|
+
file,
|
|
215
|
+
...loc,
|
|
216
|
+
adapter: 'stylex',
|
|
217
|
+
kind: 'unsupported',
|
|
218
|
+
...(ruleName ? { property: ruleName } : {}),
|
|
219
|
+
value: content.slice(ruleProp.value.start, Math.min(ruleProp.value.end, ruleProp.value.start + 60)),
|
|
220
|
+
reason: 'dynamic-stylex-function',
|
|
221
|
+
})
|
|
222
|
+
} else if (stylexEnabled && ruleProp.value) {
|
|
223
|
+
const loc = locationAt(ruleProp.value.start)
|
|
224
|
+
diagnostics.push({
|
|
225
|
+
file,
|
|
226
|
+
...loc,
|
|
227
|
+
adapter: 'stylex',
|
|
228
|
+
kind: 'unsupported',
|
|
229
|
+
...(ruleName ? { property: ruleName } : {}),
|
|
230
|
+
value: content.slice(ruleProp.value.start, Math.min(ruleProp.value.end, ruleProp.value.start + 60)),
|
|
231
|
+
reason: 'dynamic-style-expression',
|
|
232
|
+
})
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
} else if (stylexEnabled && arg) {
|
|
236
|
+
const loc = locationAt(arg.start)
|
|
237
|
+
diagnostics.push({
|
|
238
|
+
file,
|
|
239
|
+
...loc,
|
|
240
|
+
adapter: 'stylex',
|
|
241
|
+
kind: 'unsupported',
|
|
242
|
+
value: content.slice(arg.start, Math.min(arg.end, arg.start + 60)),
|
|
243
|
+
reason: 'dynamic-style-expression',
|
|
244
|
+
})
|
|
245
|
+
}
|
|
246
|
+
return false
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
if (
|
|
251
|
+
node.type === 'VariableDeclarator' &&
|
|
252
|
+
node.id?.type === 'Identifier' &&
|
|
253
|
+
node.init?.type === 'ObjectExpression' &&
|
|
254
|
+
!visitedObjects.has(node.init)
|
|
255
|
+
) {
|
|
256
|
+
const nameMatch = STYLE_OBJECT_NAME_RE.test(node.id.name)
|
|
257
|
+
const typeText = node.id.typeAnnotation
|
|
258
|
+
? content.slice(node.id.typeAnnotation.start, node.id.typeAnnotation.end)
|
|
259
|
+
: ''
|
|
260
|
+
const typeMatch = /\bCSSProperties\b/.test(typeText)
|
|
261
|
+
if (nameMatch || typeMatch) {
|
|
262
|
+
visitedObjects.add(node.init)
|
|
263
|
+
analyzeStyleObject(node.init, {
|
|
264
|
+
file,
|
|
265
|
+
content,
|
|
266
|
+
locationAt,
|
|
267
|
+
adapter: 'css-in-code',
|
|
268
|
+
diagnostics,
|
|
269
|
+
})
|
|
270
|
+
return false
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
})
|
|
274
|
+
|
|
275
|
+
return diagnostics
|
|
276
|
+
},
|
|
277
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { parseSync } from 'oxc-parser'
|
|
2
|
+
|
|
3
|
+
import { createLineIndex } from './types.mjs'
|
|
4
|
+
|
|
5
|
+
export function parseSourceAst(file, content, ctx) {
|
|
6
|
+
const cache = ctx?.parseCache
|
|
7
|
+
const existing = cache?.get(file)
|
|
8
|
+
if (existing && existing.content === content) return existing
|
|
9
|
+
|
|
10
|
+
const result = parseSync(file, content)
|
|
11
|
+
const locationAt = createLineIndex(content)
|
|
12
|
+
const entry = {
|
|
13
|
+
content,
|
|
14
|
+
program: result.program,
|
|
15
|
+
errors: result.errors ?? [],
|
|
16
|
+
locationAt,
|
|
17
|
+
}
|
|
18
|
+
cache?.set(file, entry)
|
|
19
|
+
return entry
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function walkAst(node, visitor, parent = null) {
|
|
23
|
+
if (!node || typeof node !== 'object') return
|
|
24
|
+
if (Array.isArray(node)) {
|
|
25
|
+
for (const item of node) walkAst(item, visitor, parent)
|
|
26
|
+
return
|
|
27
|
+
}
|
|
28
|
+
if (typeof node.type === 'string') {
|
|
29
|
+
const stop = visitor(node, parent)
|
|
30
|
+
if (stop === false) return
|
|
31
|
+
}
|
|
32
|
+
for (const [key, value] of Object.entries(node)) {
|
|
33
|
+
if (key === 'type' || key === 'start' || key === 'end' || key === 'loc') continue
|
|
34
|
+
if (value && typeof value === 'object') {
|
|
35
|
+
walkAst(value, visitor, node)
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function staticStringOf(node) {
|
|
41
|
+
if (!node) return null
|
|
42
|
+
if (node.type === 'Literal' && typeof node.value === 'string') return node.value
|
|
43
|
+
if (node.type === 'TemplateLiteral' && (!node.expressions || node.expressions.length === 0)) {
|
|
44
|
+
return (node.quasis ?? []).map((quasi) => quasi.value?.cooked ?? quasi.value?.raw ?? '').join('')
|
|
45
|
+
}
|
|
46
|
+
return null
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function propertyKeyName(keyNode) {
|
|
50
|
+
if (!keyNode) return null
|
|
51
|
+
if (keyNode.type === 'Identifier') return keyNode.name
|
|
52
|
+
if (keyNode.type === 'Literal' && typeof keyNode.value === 'string') return keyNode.value
|
|
53
|
+
return null
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function camelToKebab(name) {
|
|
57
|
+
if (name.startsWith('--')) return name
|
|
58
|
+
return name.replace(/([a-z0-9])([A-Z])/g, '$1-$2').toLowerCase()
|
|
59
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import path from 'node:path'
|
|
2
|
+
|
|
3
|
+
import { analyzeCssAst } from './css.mjs'
|
|
4
|
+
|
|
5
|
+
async function tryImportParser(pkgName) {
|
|
6
|
+
try {
|
|
7
|
+
const mod = await import(pkgName)
|
|
8
|
+
return mod.default ?? mod
|
|
9
|
+
} catch {
|
|
10
|
+
return null
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export const scssAdapter = {
|
|
15
|
+
id: 'scss',
|
|
16
|
+
detect(file) {
|
|
17
|
+
return /\.(?:scss|sass)$/i.test(file)
|
|
18
|
+
},
|
|
19
|
+
async analyze(file, content) {
|
|
20
|
+
const parserPkg = /\.sass$/i.test(file) ? 'postcss-sass' : 'postcss-scss'
|
|
21
|
+
const parser = await tryImportParser(parserPkg)
|
|
22
|
+
if (!parser || typeof parser.parse !== 'function') {
|
|
23
|
+
return [
|
|
24
|
+
{
|
|
25
|
+
file,
|
|
26
|
+
line: 1,
|
|
27
|
+
column: 1,
|
|
28
|
+
adapter: 'scss',
|
|
29
|
+
kind: 'unsupported',
|
|
30
|
+
value: path.basename(file),
|
|
31
|
+
reason: 'parser-not-installed',
|
|
32
|
+
},
|
|
33
|
+
]
|
|
34
|
+
}
|
|
35
|
+
const rootAst = parser.parse(content, { from: file })
|
|
36
|
+
return analyzeCssAst({ file, rootAst, adapter: 'scss' })
|
|
37
|
+
},
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export const lessAdapter = {
|
|
41
|
+
id: 'less',
|
|
42
|
+
detect(file) {
|
|
43
|
+
return /\.less$/i.test(file)
|
|
44
|
+
},
|
|
45
|
+
async analyze(file, content) {
|
|
46
|
+
const parser = await tryImportParser('postcss-less')
|
|
47
|
+
if (!parser || typeof parser.parse !== 'function') {
|
|
48
|
+
return [
|
|
49
|
+
{
|
|
50
|
+
file,
|
|
51
|
+
line: 1,
|
|
52
|
+
column: 1,
|
|
53
|
+
adapter: 'less',
|
|
54
|
+
kind: 'unsupported',
|
|
55
|
+
value: path.basename(file),
|
|
56
|
+
reason: 'parser-not-installed',
|
|
57
|
+
},
|
|
58
|
+
]
|
|
59
|
+
}
|
|
60
|
+
const rootAst = parser.parse(content, { from: file })
|
|
61
|
+
return analyzeCssAst({ file, rootAst, adapter: 'less' })
|
|
62
|
+
},
|
|
63
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs'
|
|
2
|
+
import { relative, sep } from 'node:path'
|
|
3
|
+
|
|
4
|
+
import { cssAdapter } from './css.mjs'
|
|
5
|
+
import { cssInCodeAdapter } from './cssInCode.mjs'
|
|
6
|
+
import { lessAdapter, scssAdapter } from './preprocessor.mjs'
|
|
7
|
+
import { tailwindcssAdapter } from './tailwindcss.mjs'
|
|
8
|
+
|
|
9
|
+
export const DEFAULT_ADAPTERS = [
|
|
10
|
+
cssAdapter,
|
|
11
|
+
cssInCodeAdapter,
|
|
12
|
+
tailwindcssAdapter,
|
|
13
|
+
scssAdapter,
|
|
14
|
+
lessAdapter,
|
|
15
|
+
]
|
|
16
|
+
|
|
17
|
+
const toPosix = (file) => file.split(sep).join('/')
|
|
18
|
+
|
|
19
|
+
export function resolveAdapters(configuredIds) {
|
|
20
|
+
if (!Array.isArray(configuredIds) || configuredIds.length === 0) {
|
|
21
|
+
return {
|
|
22
|
+
adapters: DEFAULT_ADAPTERS,
|
|
23
|
+
enabledIds: null,
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
const enabledIds = new Set(configuredIds.map(String))
|
|
27
|
+
return {
|
|
28
|
+
adapters: DEFAULT_ADAPTERS.filter((adapter) => enabledIds.has(adapter.id)),
|
|
29
|
+
enabledIds,
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export async function analyzeFilesWithAdapters({ root, files, adapters: configuredIds }) {
|
|
34
|
+
const { adapters, enabledIds } = resolveAdapters(configuredIds)
|
|
35
|
+
const parseCache = new Map()
|
|
36
|
+
const diagnostics = []
|
|
37
|
+
|
|
38
|
+
for (const absFile of files) {
|
|
39
|
+
const relFile = toPosix(relative(root, absFile))
|
|
40
|
+
const matching = adapters.filter((adapter) => adapter.detect(relFile))
|
|
41
|
+
if (!matching.length) continue
|
|
42
|
+
const content = readFileSync(absFile, 'utf8')
|
|
43
|
+
const ctx = { root, parseCache, enabledIds }
|
|
44
|
+
for (const adapter of matching) {
|
|
45
|
+
const results = await adapter.analyze(relFile, content, ctx)
|
|
46
|
+
if (Array.isArray(results) && results.length) {
|
|
47
|
+
diagnostics.push(...results)
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return diagnostics
|
|
53
|
+
}
|