@ethlete/core 5.0.0-next.3 → 5.0.0-next.30

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.
@@ -0,0 +1,459 @@
1
+ import { formatFiles, logger, visitNotIgnoredFiles } from '@nx/devkit';
2
+ import { Project, SyntaxKind } from 'ts-morph';
3
+ export default async function generate(tree, schema) {
4
+ logger.log('\nšŸ”„ Starting Tailwind 4 surface theme generator...\n');
5
+ const themesPath = schema.themesPath || 'src/surface-themes.ts';
6
+ const outputPath = schema.outputPath || 'src/styles/generated-tailwind-surface-themes.css';
7
+ const prefix = schema.prefix || 'et';
8
+ // The runtime prefix drives the theme-swap CSS variables (--<runtimePrefix>-surface-*)
9
+ // and selectors (.<runtimePrefix>-surface--<name>). It defaults to `prefix` so existing
10
+ // consumers who only ever passed one prefix see no change in output.
11
+ const runtimePrefix = schema.runtimePrefix || prefix;
12
+ if (!tree.exists(themesPath)) {
13
+ logger.error(`āŒ Surface themes file not found at: ${themesPath}`);
14
+ logger.log(`\nPlease specify the correct path using --themesPath option.`);
15
+ logger.log(`Example: nx g @ethlete/core:tailwind-4-surface-theme --themesPath=src/app/surface-themes.ts\n`);
16
+ return;
17
+ }
18
+ logger.log(`šŸ“ Reading surface themes from: ${themesPath}`);
19
+ const themesContent = tree.read(themesPath, 'utf-8');
20
+ if (!themesContent) {
21
+ logger.error('āŒ Failed to read surface themes file');
22
+ return;
23
+ }
24
+ let themes;
25
+ try {
26
+ themes = extractSurfaceThemesFromContent(themesContent, themesPath);
27
+ logger.log(`āœ… Found ${themes.length} surface theme(s)`);
28
+ }
29
+ catch (error) {
30
+ logger.error('āŒ Failed to parse surface themes file');
31
+ logger.error(` ${error instanceof Error ? error.message : String(error)}`);
32
+ logger.log('\nThe surface themes file must export themes as:');
33
+ logger.log(' export const SURFACE_THEMES = [...] satisfies SurfaceTheme[];\n');
34
+ return;
35
+ }
36
+ // Apply the generation-time default overrides, if any. The shared theme definitions may
37
+ // mark defaults via isDefault, but in a monorepo each app picks its own defaults at its
38
+ // generation invocation — the options win over the definitions (per surface type).
39
+ try {
40
+ if (schema.defaultLightTheme) {
41
+ const name = applyDefaultSurfaceThemeOverride(themes, schema.defaultLightTheme, 'light');
42
+ logger.log(`šŸŽÆ Default light surface theme set at generation time: ${name}`);
43
+ }
44
+ if (schema.defaultDarkTheme) {
45
+ const name = applyDefaultSurfaceThemeOverride(themes, schema.defaultDarkTheme, 'dark');
46
+ logger.log(`šŸŽÆ Default dark surface theme set at generation time: ${name}`);
47
+ }
48
+ }
49
+ catch (error) {
50
+ logger.error('āŒ Invalid default theme option');
51
+ logger.error(` ${error instanceof Error ? error.message : String(error)}`);
52
+ return;
53
+ }
54
+ try {
55
+ validateSurfaceThemeConfiguration(themes);
56
+ }
57
+ catch (error) {
58
+ logger.error('āŒ Surface theme configuration error');
59
+ logger.error(` ${error instanceof Error ? error.message : String(error)}`);
60
+ return;
61
+ }
62
+ logger.log('\nšŸŽØ Generating Tailwind surface theme CSS...');
63
+ const css = generateSurfaceThemeCss(themes, prefix, runtimePrefix, schema);
64
+ tree.write(outputPath, css);
65
+ logger.log(`āœ… Generated Tailwind surface themes at: ${outputPath}`);
66
+ // Generate the `EthleteSurfaceThemeNameRegistry` augmentation, so `etProvideSurface` (and
67
+ // anything else that accepts a `RegisteredSurfaceThemeName`) is checked/autocompleted
68
+ // against this app's actual surface theme names, instead of a plain `string`.
69
+ const typesOutputPath = schema.typesOutputPath || outputPath.replace(/\.css$/, '.d.ts');
70
+ const typesDts = generateSurfaceThemeNameTypes(themes, schema);
71
+ tree.write(typesOutputPath, typesDts);
72
+ logger.log(`āœ… Generated surface theme name types at: ${typesOutputPath}`);
73
+ const mainStylesFiles = findMainStylesFile(tree);
74
+ if (mainStylesFiles.length > 0) {
75
+ logger.log('\nšŸ“ Found potential main styles files:');
76
+ mainStylesFiles.forEach((file) => logger.log(` - ${file}`));
77
+ logger.log('\nāš ļø Please manually import the generated themes:');
78
+ logger.log(` @import './${outputPath.replace('src/styles/', '')}';`);
79
+ }
80
+ if (!schema.skipFormat) {
81
+ await formatFiles(tree);
82
+ }
83
+ logger.log('\nāœ… Generation completed successfully!\n');
84
+ }
85
+ //#endregion
86
+ //#region Parsing
87
+ function extractSurfaceThemesFromContent(content, filePath) {
88
+ const project = new Project({
89
+ useInMemoryFileSystem: true,
90
+ compilerOptions: {
91
+ target: 99,
92
+ module: 99,
93
+ },
94
+ });
95
+ const sourceFile = project.createSourceFile(filePath, content);
96
+ const themes = [];
97
+ const exportedDeclarations = sourceFile.getVariableDeclarations().filter((decl) => {
98
+ const statement = decl.getVariableStatement();
99
+ return statement?.isExported();
100
+ });
101
+ const themesArray = exportedDeclarations.find((decl) => {
102
+ const name = decl.getName();
103
+ return name === 'SURFACE_THEMES' || name === 'surfaceThemes';
104
+ });
105
+ if (!themesArray) {
106
+ throw new Error('Could not find SURFACE_THEMES or surfaceThemes export');
107
+ }
108
+ let initializer = themesArray.getInitializer();
109
+ if (!initializer) {
110
+ throw new Error('SURFACE_THEMES export has no initializer');
111
+ }
112
+ // Handle 'satisfies X'/'as const' wrappers, in either order: [array] satisfies Type[],
113
+ // [array] as const, or both combined.
114
+ while (initializer.isKind(SyntaxKind.SatisfiesExpression) || initializer.isKind(SyntaxKind.AsExpression)) {
115
+ initializer = initializer.getExpression();
116
+ }
117
+ if (!initializer.isKind(SyntaxKind.ArrayLiteralExpression)) {
118
+ throw new Error('SURFACE_THEMES export must be an array literal');
119
+ }
120
+ const elements = initializer.getElements();
121
+ for (const element of elements) {
122
+ if (element.isKind(SyntaxKind.Identifier)) {
123
+ const name = element.getText();
124
+ const themeDecl = exportedDeclarations.find((decl) => decl.getName() === name);
125
+ if (!themeDecl) {
126
+ logger.warn(`āš ļø Could not find declaration for surface theme: ${name}`);
127
+ continue;
128
+ }
129
+ let themeObj = themeDecl.getInitializer();
130
+ if (!themeObj) {
131
+ logger.warn(`āš ļø Surface theme ${name} has no initializer`);
132
+ continue;
133
+ }
134
+ // Handle 'as const' and 'satisfies X' wrappers on individual theme objects, in
135
+ // either order (e.g. `{...} satisfies SurfaceTheme`, `{...} as const`, or both).
136
+ while (themeObj.isKind(SyntaxKind.AsExpression) || themeObj.isKind(SyntaxKind.SatisfiesExpression)) {
137
+ themeObj = themeObj.getExpression();
138
+ }
139
+ if (!themeObj.isKind(SyntaxKind.ObjectLiteralExpression)) {
140
+ logger.warn(`āš ļø Surface theme ${name} is not an object literal`);
141
+ continue;
142
+ }
143
+ try {
144
+ const theme = parseSurfaceThemeObject(themeObj);
145
+ themes.push(theme);
146
+ }
147
+ catch (error) {
148
+ logger.warn(`āš ļø Failed to parse surface theme ${name}: ${error instanceof Error ? error.message : String(error)}`);
149
+ }
150
+ }
151
+ }
152
+ if (themes.length === 0) {
153
+ throw new Error('No valid surface themes found in SURFACE_THEMES array');
154
+ }
155
+ return themes;
156
+ }
157
+ function parseSurfaceThemeObject(obj) {
158
+ const properties = obj.getProperties();
159
+ const theme = {};
160
+ const STRING_PROPS = ['name', 'background', 'color', 'colorMuted', 'colorSubtle', 'border'];
161
+ for (const prop of properties) {
162
+ if (!prop.isKind(SyntaxKind.PropertyAssignment)) {
163
+ continue;
164
+ }
165
+ const propName = prop.getName();
166
+ const initializer = prop.getInitializer();
167
+ if (!initializer) {
168
+ continue;
169
+ }
170
+ if (propName === 'isDefault') {
171
+ if (initializer.isKind(SyntaxKind.TrueKeyword)) {
172
+ theme.isDefault = true;
173
+ }
174
+ continue;
175
+ }
176
+ if (propName === 'interactionColor' && initializer.isKind(SyntaxKind.ObjectLiteralExpression)) {
177
+ const interactionProps = initializer.getProperties();
178
+ const interactionColor = {};
179
+ for (const iProp of interactionProps) {
180
+ if (!iProp.isKind(SyntaxKind.PropertyAssignment))
181
+ continue;
182
+ const iPropName = iProp.getName();
183
+ const iInit = iProp.getInitializer();
184
+ if (iInit?.isKind(SyntaxKind.StringLiteral)) {
185
+ interactionColor[iPropName] = iInit.getLiteralValue();
186
+ }
187
+ }
188
+ if (interactionColor.default &&
189
+ interactionColor.hover &&
190
+ interactionColor.focus &&
191
+ interactionColor.active &&
192
+ interactionColor.disabled) {
193
+ theme.interactionColor = interactionColor;
194
+ }
195
+ continue;
196
+ }
197
+ if (propName === 'elevation') {
198
+ if (initializer.isKind(SyntaxKind.NumericLiteral)) {
199
+ theme.elevation = Number(initializer.getLiteralValue());
200
+ }
201
+ continue;
202
+ }
203
+ if (propName === 'type' && initializer.isKind(SyntaxKind.StringLiteral)) {
204
+ theme.type = initializer.getLiteralValue();
205
+ continue;
206
+ }
207
+ if (STRING_PROPS.includes(propName) && initializer.isKind(SyntaxKind.StringLiteral)) {
208
+ theme[propName] = initializer.getLiteralValue();
209
+ }
210
+ }
211
+ if (!theme.name ||
212
+ !theme.type ||
213
+ theme.elevation === undefined ||
214
+ !theme.background ||
215
+ !theme.color ||
216
+ !theme.colorMuted ||
217
+ !theme.colorSubtle ||
218
+ !theme.border) {
219
+ throw new Error('SurfaceTheme must have name, type, elevation, background, color, colorMuted, colorSubtle, and border properties');
220
+ }
221
+ return theme;
222
+ }
223
+ // Makes the named theme the sole default of its surface type, overriding any isDefault
224
+ // flags on themes of that type. Matches the theme's name or its CSS-safe form. Themes of
225
+ // the other type keep their flags. Returns the resolved name.
226
+ function applyDefaultSurfaceThemeOverride(themes, defaultTheme, type) {
227
+ const wanted = createCssSurfaceName(defaultTheme);
228
+ const matches = themes.filter((t) => t.name === defaultTheme || createCssSurfaceName(t.name) === wanted);
229
+ const target = matches.find((t) => t.type === type);
230
+ if (!target) {
231
+ if (matches.length > 0) {
232
+ throw new Error(`Theme "${defaultTheme}" has type '${matches[0].type}', but was passed as the default '${type}' theme`);
233
+ }
234
+ const available = themes.filter((t) => t.type === type).map((t) => t.name);
235
+ throw new Error(`No surface theme named "${defaultTheme}" found. Available '${type}' themes: ${available.join(', ')}`);
236
+ }
237
+ for (const theme of themes) {
238
+ if (theme.type === type) {
239
+ theme.isDefault = theme === target;
240
+ }
241
+ }
242
+ return target.name;
243
+ }
244
+ function validateSurfaceThemeConfiguration(themes) {
245
+ const defaultThemes = themes.filter((t) => t.isDefault);
246
+ if (defaultThemes.length === 0) {
247
+ throw new Error('No default surface theme found. Each type (light/dark) must have exactly one theme with isDefault: true');
248
+ }
249
+ const types = new Set(themes.map((t) => t.type));
250
+ for (const type of types) {
251
+ const defaultsForType = defaultThemes.filter((t) => t.type === type);
252
+ if (defaultsForType.length === 0) {
253
+ throw new Error(`No default surface theme found for type '${type}'. Add isDefault: true to one '${type}' theme`);
254
+ }
255
+ if (defaultsForType.length > 1) {
256
+ throw new Error(`Multiple default surface themes found for type '${type}': ${defaultsForType.map((t) => t.name).join(', ')}. Only one theme per type can have isDefault: true`);
257
+ }
258
+ }
259
+ }
260
+ //#endregion
261
+ //#region CSS Generation
262
+ function createCssSurfaceName(name) {
263
+ return name
264
+ .toLowerCase()
265
+ .replace(/\s+/g, '-')
266
+ .replace(/[^a-z0-9-]/g, '');
267
+ }
268
+ function generateSurfaceThemeNameTypes(themes, schema) {
269
+ const themesPath = schema.themesPath || 'src/surface-themes.ts';
270
+ const outputPath = schema.outputPath || 'src/styles/generated-tailwind-surface-themes.css';
271
+ const typesOutputPath = schema.typesOutputPath || outputPath.replace(/\.css$/, '.d.ts');
272
+ const names = themes.map((theme) => `'${theme.name}'`).join(' | ');
273
+ return `/*
274
+ * Auto-generated by @ethlete/core:tailwind-4-surface-theme
275
+ * DO NOT EDIT THIS FILE MANUALLY
276
+ *
277
+ * Regenerate by running:
278
+ * nx g @ethlete/core:tailwind-4-surface-theme --themesPath=${themesPath}${schema.outputPath ? ` --outputPath=${outputPath}` : ''}${schema.typesOutputPath ? ` --typesOutputPath=${typesOutputPath}` : ''}${schema.prefix && schema.prefix !== 'et' ? ` --prefix=${schema.prefix}` : ''}${schema.defaultLightTheme ? ` --defaultLightTheme=${schema.defaultLightTheme}` : ''}${schema.defaultDarkTheme ? ` --defaultDarkTheme=${schema.defaultDarkTheme}` : ''}
279
+ */
280
+
281
+ declare module '@ethlete/core' {
282
+ interface EthleteSurfaceThemeNameRegistry {
283
+ name: ${names};
284
+ }
285
+ }
286
+
287
+ export {};
288
+ `;
289
+ }
290
+ function generateSurfaceThemeCss(themes, utilityPrefix, runtimePrefix, schema) {
291
+ const tailwindVars = [];
292
+ const themeVars = [];
293
+ const themesPath = schema.themesPath || 'src/surface-themes.ts';
294
+ const outputPath = schema.outputPath || 'src/styles/generated-tailwind-surface-themes.css';
295
+ const header = `/*
296
+ * Auto-generated Tailwind 4 surface theme colors from @ethlete/core
297
+ * DO NOT EDIT THIS FILE MANUALLY
298
+ *
299
+ * Generated from your surface theme definitions
300
+ * This file can be regenerated by running:
301
+ * nx g @ethlete/core:tailwind-4-surface-theme --themesPath=${themesPath}${schema.outputPath ? ` --outputPath=${outputPath}` : ''}${schema.prefix && schema.prefix !== 'et' ? ` --prefix=${schema.prefix}` : ''}${schema.runtimePrefix && schema.runtimePrefix !== schema.prefix ? ` --runtimePrefix=${schema.runtimePrefix}` : ''}${schema.defaultLightTheme ? ` --defaultLightTheme=${schema.defaultLightTheme}` : ''}${schema.defaultDarkTheme ? ` --defaultDarkTheme=${schema.defaultDarkTheme}` : ''}
302
+ */
303
+
304
+ `;
305
+ const defaultThemes = themes.filter((t) => t.isDefault);
306
+ const regularThemes = themes.filter((t) => !t.isDefault);
307
+ // Static Tailwind @theme block — one color set per surface theme
308
+ for (const theme of themes) {
309
+ const name = createCssSurfaceName(theme.name);
310
+ tailwindVars.push(` /* ${theme.name} surface */`);
311
+ tailwindVars.push(` --color-${utilityPrefix}-surface-${name}-bg: rgb(${theme.background});`);
312
+ tailwindVars.push(` --color-${utilityPrefix}-surface-${name}: rgb(${theme.color});`);
313
+ tailwindVars.push(` --color-${utilityPrefix}-surface-${name}-muted: rgb(${theme.colorMuted});`);
314
+ tailwindVars.push(` --color-${utilityPrefix}-surface-${name}-subtle: rgb(${theme.colorSubtle});`);
315
+ tailwindVars.push(` --color-${utilityPrefix}-surface-${name}-border: rgb(${theme.border});`);
316
+ if (theme.interactionColor) {
317
+ tailwindVars.push(` --color-${utilityPrefix}-surface-${name}-interaction: rgb(${theme.interactionColor.default});`);
318
+ tailwindVars.push(` --color-${utilityPrefix}-surface-${name}-interaction-hover: rgb(${theme.interactionColor.hover});`);
319
+ tailwindVars.push(` --color-${utilityPrefix}-surface-${name}-interaction-focus: rgb(${theme.interactionColor.focus});`);
320
+ tailwindVars.push(` --color-${utilityPrefix}-surface-${name}-interaction-active: rgb(${theme.interactionColor.active});`);
321
+ tailwindVars.push(` --color-${utilityPrefix}-surface-${name}-interaction-disabled: rgb(${theme.interactionColor.disabled});`);
322
+ }
323
+ tailwindVars.push('');
324
+ }
325
+ // Dynamic surface colors (reference runtime CSS variables).
326
+ // These are ALSO re-declared on every surface selector in the alias block below. A Tailwind
327
+ // `@theme` variable only lands on `:root`, so `rgb(var(--<runtime>-surface-*))` resolves once
328
+ // against the root surface and inherits that concrete color into descendants — which means
329
+ // `bg-<prefix>-surface-*` utilities would ignore nested surface scopes (e.g. an elevated
330
+ // surface). Re-declaring them per surface selector makes the utilities resolve against the
331
+ // nearest surface instead.
332
+ const dynamicSurfaceColors = buildDynamicSurfaceColors(utilityPrefix, runtimePrefix);
333
+ tailwindVars.push(' /* Dynamic surface colors (references runtime CSS variables) */');
334
+ tailwindVars.push(...dynamicSurfaceColors.map((decl) => ` ${decl}`));
335
+ // Runtime CSS — theme selector classes
336
+ for (const theme of themes) {
337
+ const name = createCssSurfaceName(theme.name);
338
+ const isDefault = theme.isDefault;
339
+ if (isDefault) {
340
+ const selectors = [`.${runtimePrefix}-surface--default-${theme.type}`, `.${runtimePrefix}-surface--${name}`];
341
+ themeVars.push(`${selectors.join(', ')} {`);
342
+ }
343
+ else {
344
+ themeVars.push(`.${runtimePrefix}-surface--${name} {`);
345
+ }
346
+ pushSurfaceVars(themeVars, runtimePrefix, theme, ' ');
347
+ themeVars.push('}\n');
348
+ }
349
+ // Media query defaults — apply surface vars to :root based on prefers-color-scheme
350
+ const defaultLight = themes.find((t) => t.isDefault && t.type === 'light');
351
+ const defaultDark = themes.find((t) => t.isDefault && t.type === 'dark');
352
+ if (defaultLight) {
353
+ themeVars.push(`@media (prefers-color-scheme: light) {`);
354
+ themeVars.push(` :root {`);
355
+ pushSurfaceVars(themeVars, runtimePrefix, defaultLight, ' ');
356
+ themeVars.push(` }`);
357
+ themeVars.push(`}\n`);
358
+ }
359
+ if (defaultDark) {
360
+ themeVars.push(`@media (prefers-color-scheme: dark) {`);
361
+ themeVars.push(` :root {`);
362
+ pushSurfaceVars(themeVars, runtimePrefix, defaultDark, ' ');
363
+ themeVars.push(` }`);
364
+ themeVars.push(`}\n`);
365
+ }
366
+ // Convenience var aliases — available on any element with a surface class or :root (via media queries)
367
+ const aliasBlock = `/* Convenience aliases (rgb + solid variants) */
368
+ @layer base {
369
+ :root, :where([class*="${runtimePrefix}-surface--"]) {
370
+ --${runtimePrefix}-surface-background-rgb: var(--${runtimePrefix}-surface-background);
371
+ --${runtimePrefix}-surface-background-solid: rgb(var(--${runtimePrefix}-surface-background-rgb));
372
+
373
+ --${runtimePrefix}-surface-color-rgb: var(--${runtimePrefix}-surface-color);
374
+ --${runtimePrefix}-surface-color-solid: rgb(var(--${runtimePrefix}-surface-color-rgb));
375
+
376
+ --${runtimePrefix}-surface-color-muted-rgb: var(--${runtimePrefix}-surface-color-muted);
377
+ --${runtimePrefix}-surface-color-muted-solid: rgb(var(--${runtimePrefix}-surface-color-muted-rgb));
378
+
379
+ --${runtimePrefix}-surface-color-subtle-rgb: var(--${runtimePrefix}-surface-color-subtle);
380
+ --${runtimePrefix}-surface-color-subtle-solid: rgb(var(--${runtimePrefix}-surface-color-subtle-rgb));
381
+
382
+ --${runtimePrefix}-surface-border-rgb: var(--${runtimePrefix}-surface-border);
383
+ --${runtimePrefix}-surface-border-solid: rgb(var(--${runtimePrefix}-surface-border-rgb));
384
+
385
+ --${runtimePrefix}-surface-interaction-rgb: var(--${runtimePrefix}-surface-interaction);
386
+ --${runtimePrefix}-surface-interaction-solid: rgb(var(--${runtimePrefix}-surface-interaction-rgb));
387
+
388
+ --${runtimePrefix}-surface-interaction-hover-rgb: var(--${runtimePrefix}-surface-interaction-hover);
389
+ --${runtimePrefix}-surface-interaction-hover-solid: rgb(var(--${runtimePrefix}-surface-interaction-hover-rgb));
390
+
391
+ --${runtimePrefix}-surface-interaction-focus-rgb: var(--${runtimePrefix}-surface-interaction-focus);
392
+ --${runtimePrefix}-surface-interaction-focus-solid: rgb(var(--${runtimePrefix}-surface-interaction-focus-rgb));
393
+
394
+ --${runtimePrefix}-surface-interaction-active-rgb: var(--${runtimePrefix}-surface-interaction-active);
395
+ --${runtimePrefix}-surface-interaction-active-solid: rgb(var(--${runtimePrefix}-surface-interaction-active-rgb));
396
+
397
+ --${runtimePrefix}-surface-interaction-disabled-rgb: var(--${runtimePrefix}-surface-interaction-disabled);
398
+ --${runtimePrefix}-surface-interaction-disabled-solid: rgb(var(--${runtimePrefix}-surface-interaction-disabled-rgb));
399
+
400
+ /* Dynamic Tailwind surface colors — re-declared per surface scope so that
401
+ bg-${utilityPrefix}-surface-* utilities resolve against the nearest surface
402
+ (e.g. a nested elevated surface) instead of the value computed once at :root. */
403
+ ${dynamicSurfaceColors.map((decl) => ` ${decl}`).join('\n')}
404
+ }
405
+ }
406
+ `;
407
+ return `${header}@theme {
408
+ ${tailwindVars.join('\n')}
409
+ }
410
+
411
+ @layer base {
412
+ ${themeVars.join('\n')}
413
+ }
414
+
415
+ ${aliasBlock}`;
416
+ }
417
+ // Dynamic surface color declarations (unindented). Emitted in `@theme` (so Tailwind generates
418
+ // the utilities) and re-declared on every surface selector (so the utilities resolve per scope).
419
+ function buildDynamicSurfaceColors(utilityPrefix, runtimePrefix) {
420
+ return [
421
+ `--color-${utilityPrefix}-surface-bg: rgb(var(--${runtimePrefix}-surface-background));`,
422
+ `--color-${utilityPrefix}-surface: rgb(var(--${runtimePrefix}-surface-color));`,
423
+ `--color-${utilityPrefix}-surface-muted: rgb(var(--${runtimePrefix}-surface-color-muted));`,
424
+ `--color-${utilityPrefix}-surface-subtle: rgb(var(--${runtimePrefix}-surface-color-subtle));`,
425
+ `--color-${utilityPrefix}-surface-border: rgb(var(--${runtimePrefix}-surface-border));`,
426
+ `--color-${utilityPrefix}-surface-interaction: rgb(var(--${runtimePrefix}-surface-interaction));`,
427
+ `--color-${utilityPrefix}-surface-interaction-hover: rgb(var(--${runtimePrefix}-surface-interaction-hover));`,
428
+ `--color-${utilityPrefix}-surface-interaction-focus: rgb(var(--${runtimePrefix}-surface-interaction-focus));`,
429
+ `--color-${utilityPrefix}-surface-interaction-active: rgb(var(--${runtimePrefix}-surface-interaction-active));`,
430
+ `--color-${utilityPrefix}-surface-interaction-disabled: rgb(var(--${runtimePrefix}-surface-interaction-disabled));`,
431
+ ];
432
+ }
433
+ function pushSurfaceVars(vars, runtimePrefix, theme, indent) {
434
+ vars.push(`${indent}--${runtimePrefix}-surface-background: ${theme.background};`);
435
+ vars.push(`${indent}--${runtimePrefix}-surface-color: ${theme.color};`);
436
+ vars.push(`${indent}--${runtimePrefix}-surface-color-muted: ${theme.colorMuted};`);
437
+ vars.push(`${indent}--${runtimePrefix}-surface-color-subtle: ${theme.colorSubtle};`);
438
+ vars.push(`${indent}--${runtimePrefix}-surface-border: ${theme.border};`);
439
+ vars.push(`${indent}--${runtimePrefix}-surface-type: ${theme.type};`);
440
+ vars.push(`${indent}--${runtimePrefix}-surface-elevation: ${theme.elevation};`);
441
+ if (theme.interactionColor) {
442
+ vars.push(`${indent}--${runtimePrefix}-surface-interaction: ${theme.interactionColor.default};`);
443
+ vars.push(`${indent}--${runtimePrefix}-surface-interaction-hover: ${theme.interactionColor.hover};`);
444
+ vars.push(`${indent}--${runtimePrefix}-surface-interaction-focus: ${theme.interactionColor.focus};`);
445
+ vars.push(`${indent}--${runtimePrefix}-surface-interaction-active: ${theme.interactionColor.active};`);
446
+ vars.push(`${indent}--${runtimePrefix}-surface-interaction-disabled: ${theme.interactionColor.disabled};`);
447
+ }
448
+ }
449
+ function findMainStylesFile(tree) {
450
+ const potentialFiles = [];
451
+ visitNotIgnoredFiles(tree, '', (path) => {
452
+ if (path.match(/styles\.(css|scss)$/) && !path.includes('node_modules') && !path.includes('dist')) {
453
+ potentialFiles.push(path);
454
+ }
455
+ });
456
+ return potentialFiles;
457
+ }
458
+ //#endregion
459
+ //# sourceMappingURL=generator.js.map
@@ -0,0 +1,48 @@
1
+ {
2
+ "$schema": "http://json-schema.org/schema",
3
+ "$id": "tailwind-4-surface-theme",
4
+ "title": "Tailwind 4 Surface Theming Generator",
5
+ "description": "Generates Tailwind 4 compatible CSS from your Ethlete surface theme definitions",
6
+ "type": "object",
7
+ "properties": {
8
+ "themesPath": {
9
+ "type": "string",
10
+ "description": "Path to your surface themes file (relative to workspace root)",
11
+ "default": "src/surface-themes.ts",
12
+ "x-prompt": "Where is your surface themes file located?"
13
+ },
14
+ "outputPath": {
15
+ "type": "string",
16
+ "description": "Where to output the generated Tailwind surface themes CSS",
17
+ "default": "src/styles/generated-tailwind-surface-themes.css",
18
+ "x-prompt": "Where should the generated CSS be saved?"
19
+ },
20
+ "typesOutputPath": {
21
+ "type": "string",
22
+ "description": "Where to output the generated `EthleteSurfaceThemeNameRegistry` augmentation (a .d.ts that narrows `etProvideSurface` and other surface-theme-name APIs to your actual surface theme names). Defaults to `outputPath` with its extension swapped to `.d.ts`."
23
+ },
24
+ "prefix": {
25
+ "type": "string",
26
+ "description": "Prefix for Tailwind utility surface variable names (e.g., 'et' creates --color-et-surface-*, usable as bg-et-surface)",
27
+ "default": "et"
28
+ },
29
+ "runtimePrefix": {
30
+ "type": "string",
31
+ "description": "Prefix for the runtime theme-swap mechanism: the CSS custom properties (--<runtimePrefix>-surface-*) and selectors (.<runtimePrefix>-surface--<name>) that ProvideSurfaceDirective (etProvideSurface) toggles between. Defaults to the same value as 'prefix'. Set this separately when your Tailwind utility prefix needs to differ from your runtime theme-switching prefix."
32
+ },
33
+ "defaultLightTheme": {
34
+ "type": "string",
35
+ "description": "Name of the 'light' surface theme to use as the default, overriding any isDefault flags on light themes in the definitions. Use this when multiple apps share one surface theme definition set (e.g. in a monorepo) but each app needs a different default."
36
+ },
37
+ "defaultDarkTheme": {
38
+ "type": "string",
39
+ "description": "Name of the 'dark' surface theme to use as the default, overriding any isDefault flags on dark themes in the definitions. Use this when multiple apps share one surface theme definition set (e.g. in a monorepo) but each app needs a different default."
40
+ },
41
+ "skipFormat": {
42
+ "type": "boolean",
43
+ "description": "Skip formatting files after generation",
44
+ "default": false
45
+ }
46
+ },
47
+ "required": []
48
+ }
package/package.json CHANGED
@@ -1,24 +1,24 @@
1
1
  {
2
2
  "name": "@ethlete/core",
3
- "version": "5.0.0-next.3",
3
+ "version": "5.0.0-next.30",
4
4
  "license": "MIT",
5
5
  "sideEffects": false,
6
6
  "peerDependencies": {
7
- "@analogjs/vite-plugin-angular": "2.3.1",
8
- "@angular/cdk": "21.2.1",
9
- "@angular/common": "21.2.1",
10
- "@angular/core": "21.2.1",
11
- "@angular/forms": "21.2.1",
12
- "@angular/platform-browser": "21.2.1",
13
- "@angular/router": "21.2.1",
14
- "@ethlete/types": "^2.0.0-next.0",
7
+ "@analogjs/vite-plugin-angular": "2.6.2",
8
+ "@angular/cdk": "22.0.3",
9
+ "@angular/common": "22.0.5",
10
+ "@angular/core": "22.0.5",
11
+ "@angular/forms": "22.0.5",
12
+ "@angular/platform-browser": "22.0.5",
13
+ "@angular/router": "22.0.5",
14
+ "@ethlete/types": "^2.0.0-beta.4",
15
15
  "@floating-ui/dom": "1.7.6",
16
- "@nx/devkit": "22.5.4",
17
- "@nx/vite": "22.5.4",
16
+ "@nx/devkit": "23.1.0-beta.7",
17
+ "@nx/vite": "23.1.0-beta.7",
18
18
  "rxjs": "7.8.2",
19
19
  "ts-morph": "21.0.1",
20
- "typescript": "5.9.3",
21
- "vite": "^7.0.0"
20
+ "typescript": "6.0.3",
21
+ "vite": "8.0.13"
22
22
  },
23
23
  "generators": "./generators/generators.json",
24
24
  "module": "fesm2022/ethlete-core.mjs",
@@ -32,6 +32,7 @@
32
32
  "default": "./fesm2022/ethlete-core.mjs"
33
33
  }
34
34
  },
35
+ "type": "module",
35
36
  "dependencies": {
36
37
  "tslib": "^2.3.0"
37
38
  }