@adea-ai/ui 0.147.13 → 0.149.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adea-ai/ui",
3
- "version": "0.147.13",
3
+ "version": "0.149.0",
4
4
  "description": "The Adea design system: Kobalte-backed Solid components, semantic OKLCH tokens, and the app-shell layout primitives shared by Adea and Cortana.",
5
5
  "keywords": [
6
6
  "adea",
@@ -66,6 +66,11 @@
66
66
  "types": "./dist/lint/index.d.ts",
67
67
  "default": "./dist/lint.js"
68
68
  },
69
+ "./testing/solid-transform": "./src/testing/solid-transform.ts",
70
+ "./vite": {
71
+ "types": "./dist/vite/index.d.ts",
72
+ "default": "./dist/vite.js"
73
+ },
69
74
  "./globals.css": "./src/styles/globals.css",
70
75
  "./theme.css": "./src/styles/theme.css",
71
76
  "./theme-variants.css": "./src/styles/theme-variants.css",
@@ -115,7 +120,7 @@
115
120
  "build": "bun run cn:build && vite build && tsc -p tsconfig.json --emitDeclarationOnly",
116
121
  "dev": "bun run cn:build && vite build --watch",
117
122
  "lint": "oxlint",
118
- "test": "bun run cn:check && bun test --conditions=browser --preload ./tests/helpers/solid-transform.ts tests",
123
+ "test": "bun run cn:check && bun test --conditions=browser --preload ./src/testing/solid-transform.ts tests",
119
124
  "typecheck": "bun check -p tsconfig.check.json",
120
125
  "cn:build": "bun scripts/build-cn-tables.ts",
121
126
  "cn:check": "bun scripts/check-cn-tables.ts",
@@ -164,6 +169,7 @@
164
169
  },
165
170
  "devDependencies": {
166
171
  "@babel/core": "^8.0.6",
172
+ "@babel/parser": "^8.0.7",
167
173
  "@babel/preset-typescript": "^8.0.1",
168
174
  "@storybook/addon-docs": "^10.6.1",
169
175
  "babel-preset-solid": "^1.9.15",
@@ -179,13 +185,30 @@
179
185
  "vite-plugin-solid": "^2.11.14"
180
186
  },
181
187
  "peerDependencies": {
188
+ "@babel/core": "^8.0.6",
189
+ "@babel/parser": "^8.0.7",
190
+ "@babel/preset-typescript": "^8.0.1",
191
+ "babel-preset-solid": "^1.9.15",
182
192
  "chart.js": "^4.5.1",
183
193
  "embla-carousel": "^8.6.0",
184
194
  "embla-carousel-solid": "^8.6.0",
185
195
  "solid-chartjs": "^1.3.11",
186
- "solid-js": "^1.9.0"
196
+ "solid-js": "^1.9.0",
197
+ "vite": "^8.3.2"
187
198
  },
188
199
  "peerDependenciesMeta": {
200
+ "@babel/core": {
201
+ "optional": true
202
+ },
203
+ "@babel/parser": {
204
+ "optional": true
205
+ },
206
+ "@babel/preset-typescript": {
207
+ "optional": true
208
+ },
209
+ "babel-preset-solid": {
210
+ "optional": true
211
+ },
189
212
  "chart.js": {
190
213
  "optional": true
191
214
  },
@@ -197,6 +220,9 @@
197
220
  },
198
221
  "solid-chartjs": {
199
222
  "optional": true
223
+ },
224
+ "vite": {
225
+ "optional": true
200
226
  }
201
227
  }
202
228
  }
@@ -0,0 +1,48 @@
1
+ import { plugin } from 'bun'
2
+ import { readFileSync } from 'node:fs'
3
+
4
+ import { transformSync } from '@babel/core'
5
+ import presetTypescript from '@babel/preset-typescript'
6
+ import presetSolid from 'babel-preset-solid'
7
+
8
+ // Bun's native test runner does not load vite-plugin-solid, so a test that imports
9
+ // a `.tsx` module gets the same DOM transform the build uses: babel-preset-solid
10
+ // compiles JSX to solid-js/web calls and preset-typescript strips types, leaving
11
+ // plain JavaScript for Bun's module loader. Without it Bun compiles the JSX as
12
+ // automatic dev JSX (`solid-js/jsx-dev-runtime`, which exports no `jsxDEV`) and
13
+ // the module fails to link.
14
+ plugin({
15
+ name: 'solid-jsx',
16
+ setup(build) {
17
+ build.onLoad({ filter: /\.tsx$/ }, ({ path }) => {
18
+ const source = readFileSync(path, 'utf8')
19
+ // Babel installs an `Error.prepareStackTrace` rewriter on its first call and
20
+ // raises `Error.stackTraceLimit`. With a custom `prepareStackTrace` set, Bun's
21
+ // `Error.captureStackTrace` throws for any object that is not an Error, which
22
+ // breaks `vite` (follow-redirects builds error types that way) in every later
23
+ // test file of the same process. Restore both once Babel is done. The transform is
24
+ // synchronous on purpose: `transformAsync` changes the globals before it returns its
25
+ // promise, so overlapping `onLoad` callbacks would save each other's changed values
26
+ // and restore them last.
27
+ const { prepareStackTrace, stackTraceLimit } = Error
28
+ try {
29
+ const result = transformSync(source, {
30
+ filename: path,
31
+ babelrc: false,
32
+ configFile: false,
33
+ sourceMaps: 'inline',
34
+ presets: [
35
+ // preset-typescript 8 dropped .isTSX/.allExtensions: JSX detection
36
+ // is filename-based, and the onLoad filter only sees .tsx paths.
37
+ presetTypescript,
38
+ [presetSolid, { generate: 'dom', hydratable: false }],
39
+ ],
40
+ })
41
+ return { contents: result?.code ?? source, loader: 'js' }
42
+ } finally {
43
+ Error.prepareStackTrace = prepareStackTrace
44
+ Error.stackTraceLimit = stackTraceLimit
45
+ }
46
+ })
47
+ },
48
+ })
@@ -0,0 +1,17 @@
1
+ export {
2
+ collectLinkedImports,
3
+ collectUiSourceFiles,
4
+ formatUiSourceDirectives,
5
+ frameworkSourceRoots,
6
+ missingRenderedUiSources,
7
+ tailwindSources,
8
+ uiSourcePaths,
9
+ type GraphCheckContext,
10
+ type LinkedImport,
11
+ type LinkedImportOptions,
12
+ type Selection,
13
+ type SourceDirectiveOptions,
14
+ type SourceDiscoveryOptions,
15
+ type TailwindSourcesOptions,
16
+ type UiSourcePaths,
17
+ } from './tailwind-sources'
@@ -0,0 +1,358 @@
1
+ import { parse } from '@babel/parser'
2
+ import { extname } from 'node:path'
3
+
4
+ // Babel's node unions are too wide to narrow usefully across this many shapes;
5
+ // every reader below checks `type` before it touches a field.
6
+ // oxlint-disable-next-line typescript/no-explicit-any
7
+ export type SyntaxNode = any
8
+
9
+ export type Selection = { kind: 'all' } | { kind: 'named'; names: string[] }
10
+
11
+ export interface StaticRuntimeImport {
12
+ specifier: string
13
+ kind: 'side-effect' | 'bindings'
14
+ bindings: Array<{ imported: string; local: string }>
15
+ }
16
+
17
+ export type RuntimeReexport =
18
+ | { kind: 'star'; source: string }
19
+ | { kind: 'empty'; source: string }
20
+ | { kind: 'namespace'; source?: string; exported: string }
21
+ | { kind: 'named'; source?: string; exported: string; imported: string }
22
+
23
+ /** Parse source without depending on the TypeScript compiler's JavaScript API. */
24
+ export function parseSource(file: string, source: string): SyntaxNode {
25
+ const extension = extname(file).toLowerCase()
26
+ const typed = ['.ts', '.tsx', '.mts', '.cts'].includes(extension)
27
+ const jsx = ['.jsx', '.tsx'].includes(extension)
28
+ const ast = parse(source, {
29
+ sourceFilename: file,
30
+ sourceType: 'unambiguous',
31
+ allowUndeclaredExports: true,
32
+ allowReturnOutsideFunction: extension === '.cjs',
33
+ allowNewTargetOutsideFunction: extension === '.cjs',
34
+ plugins: [...(typed ? (['typescript'] as const) : []), ...(jsx ? (['jsx'] as const) : [])],
35
+ })
36
+ Object.defineProperty(ast, 'sourceText', { value: source })
37
+ return ast
38
+ }
39
+
40
+ /** Visit syntax nodes with their actual parent, without traversing location metadata. */
41
+ export function visitSource(
42
+ node: SyntaxNode,
43
+ visit: (node: SyntaxNode, parent: SyntaxNode) => void,
44
+ parent: SyntaxNode = null
45
+ ): void {
46
+ if (!node || typeof node !== 'object' || typeof node.type !== 'string') return
47
+ visit(node, parent)
48
+ for (const [key, value] of Object.entries(node)) {
49
+ if (key === 'loc' || key === 'tokens' || key === 'comments' || key === 'errors') continue
50
+ if (Array.isArray(value)) {
51
+ for (const child of value) visitSource(child, visit, node)
52
+ } else visitSource(value, visit, node)
53
+ }
54
+ }
55
+
56
+ /** Describe statically imported runtime bindings without treating type imports as runtime edges. */
57
+ export function staticRuntimeImports(ast: SyntaxNode): StaticRuntimeImport[] {
58
+ const imports: StaticRuntimeImport[] = []
59
+ for (const declaration of ast.program.body) {
60
+ if (declaration.type !== 'ImportDeclaration' || declaration.importKind === 'type') continue
61
+ if (declaration.specifiers.length === 0) {
62
+ const prefix = ast.sourceText
63
+ .slice(declaration.start, declaration.source.start)
64
+ .replace(/\/\*[\s\S]*?\*\/|\/\/[^\n\r]*/g, '')
65
+ .trim()
66
+ // Preserve the existing collector's distinction between bare imports and `import {}`.
67
+ if (prefix === 'import')
68
+ imports.push({
69
+ specifier: declaration.source.value,
70
+ kind: 'side-effect',
71
+ bindings: [],
72
+ })
73
+ continue
74
+ }
75
+ const bindings: StaticRuntimeImport['bindings'] = []
76
+ for (const binding of declaration.specifiers) {
77
+ if (binding.importKind === 'type') continue
78
+ const imported =
79
+ binding.type === 'ImportDefaultSpecifier'
80
+ ? 'default'
81
+ : binding.type === 'ImportNamespaceSpecifier'
82
+ ? '*'
83
+ : (binding.imported.name ?? binding.imported.value)
84
+ bindings.push({ imported, local: binding.local.name })
85
+ }
86
+ if (bindings.length)
87
+ imports.push({
88
+ specifier: declaration.source.value,
89
+ kind: 'bindings',
90
+ bindings,
91
+ })
92
+ }
93
+ return imports
94
+ }
95
+
96
+ /** Conservatively select members used through a namespace import. */
97
+ export function selectNamespace(
98
+ ast: SyntaxNode,
99
+ local: string,
100
+ ignoredBinding: SyntaxNode = null
101
+ ): Selection | undefined {
102
+ const names = new Set<string>()
103
+ let used = false
104
+ let opaque = false
105
+ let shadowed = false
106
+ visitSource(ast, (node, parent) => {
107
+ if (
108
+ !parent ||
109
+ node === ignoredBinding ||
110
+ !['Identifier', 'JSXIdentifier'].includes(node.type) ||
111
+ node.name !== local
112
+ )
113
+ return
114
+ if (parent.type.startsWith('Import')) return
115
+ const binding =
116
+ (parent.type === 'VariableDeclarator' && parent.id === node) ||
117
+ (parent.type === 'CatchClause' && parent.param === node) ||
118
+ (/^(?:Function|Class|TSInterface|TSTypeAlias|TSEnum|TSModule)/.test(parent.type) &&
119
+ (parent.id === node || parent.params?.includes(node)))
120
+ if (binding) {
121
+ shadowed = true
122
+ return
123
+ }
124
+ if (['MemberExpression', 'OptionalMemberExpression'].includes(parent.type)) {
125
+ if (parent.property === node && !parent.computed) return
126
+ if (parent.object === node) {
127
+ used = true
128
+ if (!parent.computed && parent.property.type === 'Identifier')
129
+ names.add(parent.property.name)
130
+ else if (parent.computed && parent.property.type === 'StringLiteral')
131
+ names.add(String(parent.property.value))
132
+ else if (
133
+ parent.computed &&
134
+ parent.property.type === 'TemplateLiteral' &&
135
+ parent.property.expressions.length === 0 &&
136
+ typeof parent.property.quasis[0].value.cooked === 'string'
137
+ )
138
+ names.add(parent.property.quasis[0].value.cooked)
139
+ else opaque = true
140
+ return
141
+ }
142
+ }
143
+ if (parent.type === 'JSXMemberExpression') {
144
+ if (parent.property === node) return
145
+ if (parent.object === node) {
146
+ used = true
147
+ names.add(parent.property.name)
148
+ return
149
+ }
150
+ }
151
+ if (parent.type === 'JSXAttribute' && parent.name === node) return
152
+ used = true
153
+ opaque = true
154
+ })
155
+ if (!used) return undefined
156
+ return shadowed || opaque ? { kind: 'all' } : { kind: 'named', names: [...names].toSorted() }
157
+ }
158
+
159
+ /** Collect literal dynamic imports and require edges, rejecting opaque dynamic paths. */
160
+ export function dynamicRuntimeImports(
161
+ ast: SyntaxNode,
162
+ file: string,
163
+ label = 'ui-tailwind-sources'
164
+ ): Array<{ specifier: string; selection: Selection }> {
165
+ const parents = new WeakMap<SyntaxNode, SyntaxNode>()
166
+ const nodes: SyntaxNode[] = []
167
+ visitSource(ast, (node, parent) => {
168
+ if (parent) parents.set(node, parent)
169
+ if (['ImportExpression', 'CallExpression', 'OptionalCallExpression'].includes(node.type))
170
+ nodes.push(node)
171
+ })
172
+ const result: Array<{ specifier: string; selection: Selection }> = []
173
+ for (const node of nodes) {
174
+ if (node.type === 'ImportExpression') {
175
+ const argument = node.source
176
+ const specifier: string | undefined =
177
+ argument.type === 'StringLiteral'
178
+ ? argument.value
179
+ : argument.type === 'TemplateLiteral' && argument.expressions.length === 0
180
+ ? argument.quasis[0].value.cooked
181
+ : undefined
182
+ if (specifier == null)
183
+ throw new Error(
184
+ `[${label}] non-literal runtime import in ${file}; use a literal import path so shared UI sources remain discoverable`
185
+ )
186
+ let selection: Selection = { kind: 'all' }
187
+ let current = node
188
+ while (parents.has(current)) {
189
+ current = parents.get(current)
190
+ if (
191
+ ['CallExpression', 'OptionalCallExpression'].includes(current.type) &&
192
+ ['MemberExpression', 'OptionalMemberExpression'].includes(current.callee.type) &&
193
+ !current.callee.computed &&
194
+ current.callee.property.name === 'then'
195
+ ) {
196
+ const callback = current.arguments[0]
197
+ const parameter = ['ArrowFunctionExpression', 'FunctionExpression'].includes(
198
+ callback?.type
199
+ )
200
+ ? callback.params[0]
201
+ : undefined
202
+ if (parameter?.type === 'Identifier')
203
+ selection = selectNamespace(callback, parameter.name, parameter) ?? selection
204
+ else if (parameter?.type === 'ObjectPattern') {
205
+ const names: string[] = []
206
+ let valid = true
207
+ for (const property of parameter.properties) {
208
+ if (
209
+ property.type !== 'ObjectProperty' ||
210
+ property.computed ||
211
+ (property.value.type !== 'Identifier' &&
212
+ !(
213
+ property.value.type === 'AssignmentPattern' &&
214
+ property.value.left.type === 'Identifier'
215
+ )) ||
216
+ !['Identifier', 'StringLiteral', 'NumericLiteral'].includes(property.key.type)
217
+ ) {
218
+ valid = false
219
+ break
220
+ }
221
+ names.push(String(property.key.name ?? property.key.value))
222
+ }
223
+ if (valid && names.length) selection = { kind: 'named', names: names.toSorted() }
224
+ }
225
+ break
226
+ }
227
+ if (current.type.endsWith('Statement') || current.type === 'Program') break
228
+ }
229
+ result.push({ specifier, selection })
230
+ } else if (
231
+ node.callee?.type === 'Identifier' &&
232
+ node.callee.name === 'require' &&
233
+ node.arguments[0]?.type === 'StringLiteral'
234
+ ) {
235
+ result.push({
236
+ specifier: node.arguments[0].value,
237
+ selection: { kind: 'all' },
238
+ })
239
+ }
240
+ }
241
+ return result
242
+ }
243
+
244
+ function bindingNames(node: SyntaxNode): string[] {
245
+ if (!node) return []
246
+ if (node.type === 'Identifier') return [node.name]
247
+ if (node.type === 'RestElement') return bindingNames(node.argument)
248
+ if (node.type === 'AssignmentPattern') return bindingNames(node.left)
249
+ if (node.type === 'ArrayPattern') return node.elements.flatMap(bindingNames)
250
+ if (node.type === 'ObjectPattern')
251
+ return node.properties.flatMap((property: SyntaxNode) =>
252
+ bindingNames(property.type === 'RestElement' ? property.argument : property.value)
253
+ )
254
+ return []
255
+ }
256
+
257
+ function declarationNames(declaration: SyntaxNode, includeModule = true): string[] {
258
+ if (!declaration || declaration.declare) return []
259
+ if (declaration.type === 'VariableDeclaration')
260
+ return declaration.declarations.flatMap((item: SyntaxNode) => bindingNames(item.id))
261
+ if (
262
+ [
263
+ 'FunctionDeclaration',
264
+ 'ClassDeclaration',
265
+ 'TSEnumDeclaration',
266
+ ...(includeModule ? ['TSModuleDeclaration'] : []),
267
+ ].includes(declaration.type)
268
+ )
269
+ return declaration.id?.type === 'Identifier' ? [declaration.id.name] : []
270
+ return []
271
+ }
272
+
273
+ /** Runtime declarations exported directly with a modifier or default export. */
274
+ export function directRuntimeExports(ast: SyntaxNode): string[] {
275
+ const names: string[] = []
276
+ for (const statement of ast.program.body) {
277
+ if (statement.type === 'ExportDefaultDeclaration') {
278
+ if (
279
+ ['TSInterfaceDeclaration', 'TSTypeAliasDeclaration'].includes(statement.declaration.type) ||
280
+ statement.declaration.declare
281
+ )
282
+ continue
283
+ names.push(...declarationNames(statement.declaration), 'default')
284
+ } else if (
285
+ statement.type === 'ExportNamedDeclaration' &&
286
+ statement.exportKind !== 'type' &&
287
+ statement.declaration
288
+ ) {
289
+ names.push(...declarationNames(statement.declaration))
290
+ } else if (statement.type === 'TSExportAssignment') names.push('default')
291
+ }
292
+ return names
293
+ }
294
+
295
+ /** Runtime declarations local to this module, excluding type-only declarations. */
296
+ export function hasRuntimeDeclaration(ast: SyntaxNode, name: string): boolean {
297
+ return ast.program.body.some((statement: SyntaxNode) => {
298
+ const declaration = ['ExportDefaultDeclaration', 'ExportNamedDeclaration'].includes(
299
+ statement.type
300
+ )
301
+ ? statement.declaration
302
+ : statement
303
+ return declarationNames(declaration, false).includes(name)
304
+ })
305
+ }
306
+
307
+ /** Runtime re-exports, preserving aliases and type-only exclusions. */
308
+ export function runtimeReexports(ast: SyntaxNode): RuntimeReexport[] {
309
+ const entries: RuntimeReexport[] = []
310
+ for (const statement of ast.program.body) {
311
+ if (statement.exportKind === 'type') continue
312
+ if (statement.type === 'ExportAllDeclaration') {
313
+ entries.push({ kind: 'star', source: statement.source.value })
314
+ } else if (statement.type === 'ExportNamedDeclaration' && !statement.declaration) {
315
+ const first = entries.length
316
+ for (const specifier of statement.specifiers) {
317
+ if (specifier.exportKind === 'type') continue
318
+ const exported = specifier.exported.name ?? specifier.exported.value
319
+ if (specifier.type === 'ExportNamespaceSpecifier') {
320
+ entries.push({
321
+ kind: 'namespace',
322
+ source: statement.source?.value,
323
+ exported,
324
+ })
325
+ } else if (specifier.type === 'ExportSpecifier') {
326
+ entries.push({
327
+ kind: 'named',
328
+ source: statement.source?.value,
329
+ exported,
330
+ imported: specifier.local.name ?? specifier.local.value,
331
+ })
332
+ }
333
+ }
334
+ if (statement.source && entries.length === first)
335
+ entries.push({ kind: 'empty', source: statement.source.value })
336
+ }
337
+ }
338
+ return entries
339
+ }
340
+
341
+ export function defaultExport(
342
+ ast: SyntaxNode
343
+ ): { kind: 'expression' } | { kind: 'identifier'; name: string } | undefined {
344
+ const statement = ast.program.body.find(
345
+ (item: SyntaxNode) =>
346
+ item.type === 'ExportDefaultDeclaration' || item.type === 'TSExportAssignment'
347
+ )
348
+ if (!statement) return undefined
349
+ if (statement.type === 'TSExportAssignment') return { kind: 'expression' }
350
+ if (
351
+ ['TSInterfaceDeclaration', 'TSTypeAliasDeclaration'].includes(statement.declaration.type) ||
352
+ statement.declaration.declare
353
+ )
354
+ return undefined
355
+ return statement.declaration.type === 'Identifier'
356
+ ? { kind: 'identifier', name: statement.declaration.name }
357
+ : { kind: 'expression' }
358
+ }