@idealyst/tooling 1.2.29 → 1.2.31

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,29 +1,54 @@
1
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
2
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
3
+ }) : x)(function(x) {
4
+ if (typeof require !== "undefined") return require.apply(this, arguments);
5
+ throw Error('Dynamic require of "' + x + '" is not supported');
6
+ });
7
+
1
8
  // src/analyzer/component-analyzer.ts
9
+ import * as ts3 from "typescript";
10
+ import * as fs3 from "fs";
11
+ import * as path3 from "path";
12
+
13
+ // src/analyzer/theme-analyzer.ts
2
14
  import * as ts2 from "typescript";
3
15
  import * as fs2 from "fs";
4
16
  import * as path2 from "path";
5
17
 
6
- // src/analyzer/theme-analyzer.ts
18
+ // src/analyzer/theme-source-analyzer.ts
7
19
  import * as ts from "typescript";
8
20
  import * as fs from "fs";
9
21
  import * as path from "path";
10
- function analyzeTheme(themePath, verbose = false) {
22
+ function analyzeThemeSource(themePath, options = {}) {
11
23
  const resolvedPath = path.resolve(themePath);
24
+ const verbose = options.verbose ?? false;
25
+ const aliases = options.aliases ?? {};
26
+ const log = (...args) => {
27
+ if (verbose) console.log("[theme-source-analyzer]", ...args);
28
+ };
12
29
  if (!fs.existsSync(resolvedPath)) {
13
30
  throw new Error(`Theme file not found: ${resolvedPath}`);
14
31
  }
15
- const log = (...args) => {
16
- if (verbose) console.log("[theme-analyzer]", ...args);
17
- };
18
32
  log("Analyzing theme file:", resolvedPath);
19
- const program = ts.createProgram([resolvedPath], {
33
+ const configPath = ts.findConfigFile(path.dirname(resolvedPath), ts.sys.fileExists, "tsconfig.json");
34
+ let compilerOptions = {
20
35
  target: ts.ScriptTarget.ES2020,
21
36
  module: ts.ModuleKind.ESNext,
37
+ moduleResolution: ts.ModuleResolutionKind.Node10,
22
38
  strict: true,
23
39
  esModuleInterop: true,
24
40
  skipLibCheck: true,
25
- allowSyntheticDefaultImports: true
26
- });
41
+ allowSyntheticDefaultImports: true,
42
+ resolveJsonModule: true
43
+ };
44
+ if (configPath) {
45
+ const configFile = ts.readConfigFile(configPath, ts.sys.readFile);
46
+ if (!configFile.error) {
47
+ const parsed = ts.parseJsonConfigFileContent(configFile.config, ts.sys, path.dirname(configPath));
48
+ compilerOptions = { ...compilerOptions, ...parsed.options };
49
+ }
50
+ }
51
+ const program = ts.createProgram([resolvedPath], compilerOptions);
27
52
  const sourceFile = program.getSourceFile(resolvedPath);
28
53
  if (!sourceFile) {
29
54
  throw new Error(`Failed to parse theme file: ${resolvedPath}`);
@@ -31,7 +56,9 @@ function analyzeTheme(themePath, verbose = false) {
31
56
  const ctx = {
32
57
  program,
33
58
  typeChecker: program.getTypeChecker(),
34
- verbose
59
+ verbose,
60
+ aliases,
61
+ analyzedFiles: /* @__PURE__ */ new Set([resolvedPath])
35
62
  };
36
63
  const values = {
37
64
  intents: [],
@@ -54,13 +81,377 @@ function analyzeTheme(themePath, verbose = false) {
54
81
  const localName = element.name.text;
55
82
  const importedName = element.propertyName?.text ?? localName;
56
83
  imports.set(localName, { source, imported: importedName });
84
+ log(` Import: ${localName} from '${source}'`);
57
85
  }
58
86
  }
59
87
  }
60
88
  });
89
+ function resolveImportPath(source, fromFile) {
90
+ for (const [aliasPrefix, aliasPath] of Object.entries(ctx.aliases)) {
91
+ if (source === aliasPrefix || source.startsWith(aliasPrefix + "/")) {
92
+ const remainder = source.slice(aliasPrefix.length);
93
+ let resolved = aliasPath + remainder;
94
+ if (!path.isAbsolute(resolved)) {
95
+ resolved = path.resolve(path.dirname(fromFile), resolved);
96
+ }
97
+ return resolved;
98
+ }
99
+ }
100
+ if (source.startsWith(".")) {
101
+ return path.resolve(path.dirname(fromFile), source);
102
+ }
103
+ try {
104
+ return __require.resolve(source, { paths: [path.dirname(fromFile)] });
105
+ } catch {
106
+ return null;
107
+ }
108
+ }
109
+ function findThemeFile(basePath, preferDark) {
110
+ const themeFileName = preferDark ? "darkTheme" : "lightTheme";
111
+ const candidates = [
112
+ basePath,
113
+ `${basePath}.ts`,
114
+ `${basePath}.tsx`,
115
+ path.join(basePath, "src", `${themeFileName}.ts`),
116
+ path.join(basePath, `${themeFileName}.ts`),
117
+ path.join(basePath, "src", "index.ts"),
118
+ path.join(basePath, "index.ts")
119
+ ];
120
+ for (const candidate of candidates) {
121
+ if (fs.existsSync(candidate) && fs.statSync(candidate).isFile()) {
122
+ return candidate;
123
+ }
124
+ }
125
+ return null;
126
+ }
127
+ function analyzeBaseTheme2(varName) {
128
+ const importInfo = imports.get(varName);
129
+ if (!importInfo) {
130
+ log(`Could not find import for base theme: ${varName}`);
131
+ return;
132
+ }
133
+ log(`Analyzing base theme '${varName}' from '${importInfo.source}'`);
134
+ const resolvedBase = resolveImportPath(importInfo.source, resolvedPath);
135
+ if (!resolvedBase) {
136
+ log(`Could not resolve import path: ${importInfo.source}`);
137
+ return;
138
+ }
139
+ const preferDark = varName.toLowerCase().includes("dark");
140
+ const themeFile = findThemeFile(resolvedBase, preferDark);
141
+ if (!themeFile) {
142
+ log(`Could not find theme file for: ${resolvedBase}`);
143
+ return;
144
+ }
145
+ if (ctx.analyzedFiles.has(themeFile)) {
146
+ log(`Already analyzed: ${themeFile}`);
147
+ return;
148
+ }
149
+ ctx.analyzedFiles.add(themeFile);
150
+ log(`Recursively analyzing: ${themeFile}`);
151
+ const baseValues = analyzeThemeSource(themeFile, { verbose, aliases });
152
+ mergeThemeValues(values, baseValues, false);
153
+ }
154
+ function traceBuilderCalls(node, calls = []) {
155
+ if (!ts.isPropertyAccessExpression(node.expression)) {
156
+ if (ts.isCallExpression(node) && ts.isIdentifier(node.expression)) {
157
+ const fnName = node.expression.text;
158
+ if (fnName === "fromTheme" && node.arguments.length > 0) {
159
+ const arg = node.arguments[0];
160
+ if (ts.isIdentifier(arg)) {
161
+ return { calls, baseThemeVar: arg.text };
162
+ }
163
+ }
164
+ }
165
+ return { calls, baseThemeVar: null };
166
+ }
167
+ const methodName = node.expression.name.text;
168
+ calls.unshift({ method: methodName, args: node.arguments });
169
+ const obj = node.expression.expression;
170
+ if (ts.isCallExpression(obj)) {
171
+ return traceBuilderCalls(obj, calls);
172
+ }
173
+ return { calls, baseThemeVar: null };
174
+ }
175
+ function getStringValue2(node) {
176
+ if (!node) return null;
177
+ if (ts.isStringLiteral(node)) return node.text;
178
+ if (ts.isIdentifier(node)) return node.text;
179
+ if (ts.isNoSubstitutionTemplateLiteral(node)) return node.text;
180
+ return null;
181
+ }
182
+ function getObjectKeys2(node) {
183
+ return node.properties.filter((prop) => ts.isPropertyAssignment(prop)).map((prop) => {
184
+ if (ts.isIdentifier(prop.name)) return prop.name.text;
185
+ if (ts.isStringLiteral(prop.name)) return prop.name.text;
186
+ return null;
187
+ }).filter((k) => k !== null);
188
+ }
189
+ function processCalls(calls) {
190
+ log(`Processing ${calls.length} builder method calls`);
191
+ for (const { method, args } of calls) {
192
+ switch (method) {
193
+ case "addIntent": {
194
+ const name = getStringValue2(args[0]);
195
+ if (name && !values.intents.includes(name)) {
196
+ values.intents.push(name);
197
+ log(` Found intent: ${name}`);
198
+ }
199
+ break;
200
+ }
201
+ case "addRadius": {
202
+ const name = getStringValue2(args[0]);
203
+ if (name && !values.radii.includes(name)) {
204
+ values.radii.push(name);
205
+ log(` Found radius: ${name}`);
206
+ }
207
+ break;
208
+ }
209
+ case "addShadow": {
210
+ const name = getStringValue2(args[0]);
211
+ if (name && !values.shadows.includes(name)) {
212
+ values.shadows.push(name);
213
+ log(` Found shadow: ${name}`);
214
+ }
215
+ break;
216
+ }
217
+ case "addBreakpoint": {
218
+ const name = getStringValue2(args[0]);
219
+ if (name && !values.breakpoints.includes(name)) {
220
+ values.breakpoints.push(name);
221
+ log(` Found breakpoint: ${name}`);
222
+ }
223
+ break;
224
+ }
225
+ case "setBreakpoints": {
226
+ if (args[0] && ts.isObjectLiteralExpression(args[0])) {
227
+ const keys = getObjectKeys2(args[0]);
228
+ for (const key of keys) {
229
+ if (!values.breakpoints.includes(key)) {
230
+ values.breakpoints.push(key);
231
+ }
232
+ }
233
+ log(` Found breakpoints: ${values.breakpoints.join(", ")}`);
234
+ }
235
+ break;
236
+ }
237
+ case "setSizes": {
238
+ if (args[0] && ts.isObjectLiteralExpression(args[0])) {
239
+ for (const prop of args[0].properties) {
240
+ if (ts.isPropertyAssignment(prop)) {
241
+ let componentName = null;
242
+ if (ts.isIdentifier(prop.name)) {
243
+ componentName = prop.name.text;
244
+ } else if (ts.isStringLiteral(prop.name)) {
245
+ componentName = prop.name.text;
246
+ }
247
+ if (componentName && ts.isObjectLiteralExpression(prop.initializer)) {
248
+ const sizeKeys = getObjectKeys2(prop.initializer);
249
+ values.sizes[componentName] = sizeKeys;
250
+ log(` Found sizes for ${componentName}: ${sizeKeys.join(", ")}`);
251
+ if (componentName === "typography") {
252
+ for (const key of sizeKeys) {
253
+ if (!values.typography.includes(key)) {
254
+ values.typography.push(key);
255
+ }
256
+ }
257
+ }
258
+ }
259
+ }
260
+ }
261
+ } else if (args[0] && ts.isPropertyAccessExpression(args[0])) {
262
+ const propAccess = args[0];
263
+ if (ts.isIdentifier(propAccess.expression) && propAccess.name.text === "sizes") {
264
+ const themeVarName = propAccess.expression.text;
265
+ log(` Found sizes reference: ${themeVarName}.sizes`);
266
+ const importInfo = imports.get(themeVarName);
267
+ if (importInfo) {
268
+ log(` Resolving sizes from imported theme: ${importInfo.source}`);
269
+ const resolvedBase = resolveImportPath(importInfo.source, resolvedPath);
270
+ if (resolvedBase) {
271
+ const preferDark = themeVarName.toLowerCase().includes("dark");
272
+ const themeFile = findThemeFile(resolvedBase, preferDark);
273
+ if (themeFile && !ctx.analyzedFiles.has(themeFile)) {
274
+ ctx.analyzedFiles.add(themeFile);
275
+ const baseValues = analyzeThemeSource(themeFile, { verbose, aliases });
276
+ for (const [comp, sizes] of Object.entries(baseValues.sizes)) {
277
+ if (!values.sizes[comp]) {
278
+ values.sizes[comp] = sizes;
279
+ log(` Inherited sizes for ${comp}: ${sizes.join(", ")}`);
280
+ }
281
+ }
282
+ for (const typo of baseValues.typography) {
283
+ if (!values.typography.includes(typo)) {
284
+ values.typography.push(typo);
285
+ }
286
+ }
287
+ }
288
+ }
289
+ }
290
+ }
291
+ }
292
+ break;
293
+ }
294
+ case "setColors": {
295
+ if (args[0] && ts.isObjectLiteralExpression(args[0])) {
296
+ for (const prop of args[0].properties) {
297
+ if (ts.isPropertyAssignment(prop)) {
298
+ let colorType = null;
299
+ if (ts.isIdentifier(prop.name)) {
300
+ colorType = prop.name.text;
301
+ } else if (ts.isStringLiteral(prop.name)) {
302
+ colorType = prop.name.text;
303
+ }
304
+ if (colorType && ts.isObjectLiteralExpression(prop.initializer)) {
305
+ const colorKeys = getObjectKeys2(prop.initializer);
306
+ switch (colorType) {
307
+ case "surface":
308
+ values.surfaceColors = colorKeys;
309
+ log(` Found surface colors: ${colorKeys.join(", ")}`);
310
+ break;
311
+ case "text":
312
+ values.textColors = colorKeys;
313
+ log(` Found text colors: ${colorKeys.join(", ")}`);
314
+ break;
315
+ case "border":
316
+ values.borderColors = colorKeys;
317
+ log(` Found border colors: ${colorKeys.join(", ")}`);
318
+ break;
319
+ }
320
+ }
321
+ }
322
+ }
323
+ }
324
+ break;
325
+ }
326
+ case "build":
327
+ break;
328
+ default:
329
+ log(` Skipping unknown method: ${method}`);
330
+ }
331
+ }
332
+ }
61
333
  function processBuilderChain(node) {
62
334
  if (!ts.isCallExpression(node)) return;
63
- if (ts.isPropertyAccessExpression(node.expression)) {
335
+ if (ts.isPropertyAccessExpression(node.expression) && node.expression.name.text === "build") {
336
+ log("Found .build() call, tracing chain...");
337
+ const { calls, baseThemeVar } = traceBuilderCalls(node);
338
+ if (baseThemeVar) {
339
+ log(`Found fromTheme(${baseThemeVar})`);
340
+ analyzeBaseTheme2(baseThemeVar);
341
+ }
342
+ processCalls(calls);
343
+ return;
344
+ }
345
+ ts.forEachChild(node, processBuilderChain);
346
+ }
347
+ ts.forEachChild(sourceFile, (node) => {
348
+ if (ts.isVariableStatement(node)) {
349
+ for (const decl of node.declarationList.declarations) {
350
+ if (decl.initializer) {
351
+ processBuilderChain(decl.initializer);
352
+ }
353
+ }
354
+ }
355
+ if (ts.isExportAssignment(node)) {
356
+ processBuilderChain(node.expression);
357
+ }
358
+ });
359
+ log("Analysis complete:");
360
+ log(` Intents: ${values.intents.join(", ")}`);
361
+ log(` Radii: ${values.radii.join(", ")}`);
362
+ log(` Shadows: ${values.shadows.join(", ")}`);
363
+ log(` Breakpoints: ${values.breakpoints.join(", ")}`);
364
+ log(` Typography: ${values.typography.join(", ")}`);
365
+ log(` Size components: ${Object.keys(values.sizes).join(", ")}`);
366
+ return values;
367
+ }
368
+ function mergeThemeValues(target, source, sourceOverrides) {
369
+ const mergeArrays = (targetArr, sourceArr) => {
370
+ for (const item of sourceArr) {
371
+ if (!targetArr.includes(item)) {
372
+ targetArr.push(item);
373
+ }
374
+ }
375
+ };
376
+ mergeArrays(target.intents, source.intents);
377
+ mergeArrays(target.radii, source.radii);
378
+ mergeArrays(target.shadows, source.shadows);
379
+ mergeArrays(target.breakpoints, source.breakpoints);
380
+ mergeArrays(target.typography, source.typography);
381
+ mergeArrays(target.surfaceColors, source.surfaceColors);
382
+ mergeArrays(target.textColors, source.textColors);
383
+ mergeArrays(target.borderColors, source.borderColors);
384
+ for (const [component, sizes] of Object.entries(source.sizes)) {
385
+ if (sourceOverrides || !target.sizes[component]) {
386
+ target.sizes[component] = sizes;
387
+ }
388
+ }
389
+ }
390
+ function toBabelThemeKeys(values) {
391
+ return {
392
+ intents: values.intents,
393
+ sizes: values.sizes,
394
+ radii: values.radii,
395
+ shadows: values.shadows,
396
+ typography: values.typography
397
+ };
398
+ }
399
+
400
+ // src/analyzer/theme-analyzer.ts
401
+ function analyzeTheme(themePath, verbose = false) {
402
+ const resolvedPath = path2.resolve(themePath);
403
+ if (!fs2.existsSync(resolvedPath)) {
404
+ throw new Error(`Theme file not found: ${resolvedPath}`);
405
+ }
406
+ const log = (...args) => {
407
+ if (verbose) console.log("[theme-analyzer]", ...args);
408
+ };
409
+ log("Analyzing theme file:", resolvedPath);
410
+ const program = ts2.createProgram([resolvedPath], {
411
+ target: ts2.ScriptTarget.ES2020,
412
+ module: ts2.ModuleKind.ESNext,
413
+ strict: true,
414
+ esModuleInterop: true,
415
+ skipLibCheck: true,
416
+ allowSyntheticDefaultImports: true
417
+ });
418
+ const sourceFile = program.getSourceFile(resolvedPath);
419
+ if (!sourceFile) {
420
+ throw new Error(`Failed to parse theme file: ${resolvedPath}`);
421
+ }
422
+ const ctx = {
423
+ program,
424
+ typeChecker: program.getTypeChecker(),
425
+ verbose
426
+ };
427
+ const values = {
428
+ intents: [],
429
+ sizes: {},
430
+ radii: [],
431
+ shadows: [],
432
+ breakpoints: [],
433
+ typography: [],
434
+ surfaceColors: [],
435
+ textColors: [],
436
+ borderColors: []
437
+ };
438
+ const imports = /* @__PURE__ */ new Map();
439
+ ts2.forEachChild(sourceFile, (node) => {
440
+ if (ts2.isImportDeclaration(node)) {
441
+ const source = node.moduleSpecifier.text;
442
+ const clause = node.importClause;
443
+ if (clause?.namedBindings && ts2.isNamedImports(clause.namedBindings)) {
444
+ for (const element of clause.namedBindings.elements) {
445
+ const localName = element.name.text;
446
+ const importedName = element.propertyName?.text ?? localName;
447
+ imports.set(localName, { source, imported: importedName });
448
+ }
449
+ }
450
+ }
451
+ });
452
+ function processBuilderChain(node) {
453
+ if (!ts2.isCallExpression(node)) return;
454
+ if (ts2.isPropertyAccessExpression(node.expression)) {
64
455
  const methodName = node.expression.name.text;
65
456
  if (methodName === "build") {
66
457
  const calls = traceBuilderCalls(node);
@@ -68,15 +459,15 @@ function analyzeTheme(themePath, verbose = false) {
68
459
  return;
69
460
  }
70
461
  }
71
- ts.forEachChild(node, processBuilderChain);
462
+ ts2.forEachChild(node, processBuilderChain);
72
463
  }
73
464
  function traceBuilderCalls(node, calls = []) {
74
- if (!ts.isPropertyAccessExpression(node.expression)) {
75
- if (ts.isCallExpression(node) && ts.isIdentifier(node.expression)) {
465
+ if (!ts2.isPropertyAccessExpression(node.expression)) {
466
+ if (ts2.isCallExpression(node) && ts2.isIdentifier(node.expression)) {
76
467
  const fnName = node.expression.text;
77
468
  if (fnName === "fromTheme" && node.arguments.length > 0) {
78
469
  const arg = node.arguments[0];
79
- if (ts.isIdentifier(arg)) {
470
+ if (ts2.isIdentifier(arg)) {
80
471
  analyzeBaseTheme(arg.text, imports, values, ctx);
81
472
  }
82
473
  }
@@ -86,7 +477,7 @@ function analyzeTheme(themePath, verbose = false) {
86
477
  const methodName = node.expression.name.text;
87
478
  calls.unshift({ method: methodName, args: node.arguments });
88
479
  const obj = node.expression.expression;
89
- if (ts.isCallExpression(obj)) {
480
+ if (ts2.isCallExpression(obj)) {
90
481
  return traceBuilderCalls(obj, calls);
91
482
  }
92
483
  return calls;
@@ -120,11 +511,11 @@ function analyzeTheme(themePath, verbose = false) {
120
511
  break;
121
512
  }
122
513
  case "setSizes": {
123
- if (args[0] && ts.isObjectLiteralExpression(args[0])) {
514
+ if (args[0] && ts2.isObjectLiteralExpression(args[0])) {
124
515
  for (const prop of args[0].properties) {
125
- if (ts.isPropertyAssignment(prop)) {
516
+ if (ts2.isPropertyAssignment(prop)) {
126
517
  const componentName = getPropertyName(prop.name);
127
- if (componentName && ts.isObjectLiteralExpression(prop.initializer)) {
518
+ if (componentName && ts2.isObjectLiteralExpression(prop.initializer)) {
128
519
  values.sizes[componentName] = getObjectKeys(prop.initializer);
129
520
  log(" Found sizes for", componentName + ":", values.sizes[componentName]);
130
521
  }
@@ -134,18 +525,18 @@ function analyzeTheme(themePath, verbose = false) {
134
525
  break;
135
526
  }
136
527
  case "setBreakpoints": {
137
- if (args[0] && ts.isObjectLiteralExpression(args[0])) {
528
+ if (args[0] && ts2.isObjectLiteralExpression(args[0])) {
138
529
  values.breakpoints = getObjectKeys(args[0]);
139
530
  log(" Found breakpoints:", values.breakpoints);
140
531
  }
141
532
  break;
142
533
  }
143
534
  case "setColors": {
144
- if (args[0] && ts.isObjectLiteralExpression(args[0])) {
535
+ if (args[0] && ts2.isObjectLiteralExpression(args[0])) {
145
536
  for (const prop of args[0].properties) {
146
- if (ts.isPropertyAssignment(prop)) {
537
+ if (ts2.isPropertyAssignment(prop)) {
147
538
  const colorType = getPropertyName(prop.name);
148
- if (ts.isObjectLiteralExpression(prop.initializer)) {
539
+ if (ts2.isObjectLiteralExpression(prop.initializer)) {
149
540
  const keys = getObjectKeys(prop.initializer);
150
541
  switch (colorType) {
151
542
  case "surface":
@@ -174,15 +565,15 @@ function analyzeTheme(themePath, verbose = false) {
174
565
  }
175
566
  }
176
567
  }
177
- ts.forEachChild(sourceFile, (node) => {
178
- if (ts.isVariableStatement(node)) {
568
+ ts2.forEachChild(sourceFile, (node) => {
569
+ if (ts2.isVariableStatement(node)) {
179
570
  for (const decl of node.declarationList.declarations) {
180
571
  if (decl.initializer) {
181
572
  processBuilderChain(decl.initializer);
182
573
  }
183
574
  }
184
575
  }
185
- if (ts.isExportAssignment(node)) {
576
+ if (ts2.isExportAssignment(node)) {
186
577
  processBuilderChain(node.expression);
187
578
  }
188
579
  });
@@ -203,18 +594,40 @@ function analyzeBaseTheme(varName, imports, values, ctx) {
203
594
  }
204
595
  log("Base theme", varName, "imported from", importInfo.source);
205
596
  if (importInfo.source === "@idealyst/theme" || importInfo.source.includes("@idealyst/theme")) {
206
- const defaultValues = getDefaultThemeValues();
207
- mergeThemeValues(values, defaultValues);
597
+ const aliasPath = packageAliases["@idealyst/theme"];
598
+ if (aliasPath) {
599
+ const themeFileName = varName.toLowerCase().includes("dark") ? "darkTheme.ts" : "lightTheme.ts";
600
+ const themePath = path2.join(aliasPath, "src", themeFileName);
601
+ if (fs2.existsSync(themePath)) {
602
+ log(`Analyzing @idealyst/theme from source: ${themePath}`);
603
+ try {
604
+ const sourceValues = analyzeThemeSource(themePath, {
605
+ verbose: ctx.verbose,
606
+ aliases: packageAliases
607
+ });
608
+ mergeThemeValues2(values, sourceValues);
609
+ log("Successfully extracted values from source");
610
+ return;
611
+ } catch (err) {
612
+ log("Failed to analyze source, falling back to defaults:", err.message);
613
+ }
614
+ } else {
615
+ log(`Theme file not found at alias path: ${themePath}`);
616
+ }
617
+ }
208
618
  log("Using default @idealyst/theme values");
619
+ const defaultValues = getDefaultThemeValues();
620
+ mergeThemeValues2(values, defaultValues);
209
621
  return;
210
622
  }
211
623
  log("Skipping base theme analysis for:", importInfo.source);
212
624
  }
213
625
  function getDefaultThemeValues() {
214
626
  return {
215
- intents: ["primary", "success", "error", "warning", "neutral", "info"],
627
+ intents: ["primary", "success", "danger", "warning", "neutral", "info"],
216
628
  sizes: {
217
629
  button: ["xs", "sm", "md", "lg", "xl"],
630
+ iconButton: ["xs", "sm", "md", "lg", "xl"],
218
631
  chip: ["xs", "sm", "md", "lg", "xl"],
219
632
  badge: ["xs", "sm", "md", "lg", "xl"],
220
633
  icon: ["xs", "sm", "md", "lg", "xl"],
@@ -228,6 +641,7 @@ function getDefaultThemeValues() {
228
641
  progress: ["xs", "sm", "md", "lg", "xl"],
229
642
  accordion: ["xs", "sm", "md", "lg", "xl"],
230
643
  activityIndicator: ["xs", "sm", "md", "lg", "xl"],
644
+ alert: ["xs", "sm", "md", "lg", "xl"],
231
645
  breadcrumb: ["xs", "sm", "md", "lg", "xl"],
232
646
  list: ["xs", "sm", "md", "lg", "xl"],
233
647
  menu: ["xs", "sm", "md", "lg", "xl"],
@@ -248,7 +662,7 @@ function getDefaultThemeValues() {
248
662
  borderColors: ["primary", "secondary", "tertiary", "disabled"]
249
663
  };
250
664
  }
251
- function mergeThemeValues(target, source) {
665
+ function mergeThemeValues2(target, source) {
252
666
  target.intents.push(...source.intents.filter((k) => !target.intents.includes(k)));
253
667
  target.radii.push(...source.radii.filter((k) => !target.radii.includes(k)));
254
668
  target.shadows.push(...source.shadows.filter((k) => !target.shadows.includes(k)));
@@ -265,32 +679,58 @@ function mergeThemeValues(target, source) {
265
679
  }
266
680
  function getStringValue(node) {
267
681
  if (!node) return null;
268
- if (ts.isStringLiteral(node)) return node.text;
269
- if (ts.isIdentifier(node)) return node.text;
682
+ if (ts2.isStringLiteral(node)) return node.text;
683
+ if (ts2.isIdentifier(node)) return node.text;
270
684
  return null;
271
685
  }
272
686
  function getPropertyName(node) {
273
- if (ts.isIdentifier(node)) return node.text;
274
- if (ts.isStringLiteral(node)) return node.text;
687
+ if (ts2.isIdentifier(node)) return node.text;
688
+ if (ts2.isStringLiteral(node)) return node.text;
275
689
  return null;
276
690
  }
277
691
  function getObjectKeys(node) {
278
- return node.properties.filter(ts.isPropertyAssignment).map((prop) => getPropertyName(prop.name)).filter((k) => k !== null);
692
+ return node.properties.filter(ts2.isPropertyAssignment).map((prop) => getPropertyName(prop.name)).filter((k) => k !== null);
279
693
  }
280
694
  var themeKeysCache = null;
281
695
  var themeLoadAttempted = false;
696
+ var packageAliases = {};
697
+ function resolveWithAliases(source, fromDir) {
698
+ for (const [aliasPrefix, aliasPath] of Object.entries(packageAliases)) {
699
+ if (source === aliasPrefix || source.startsWith(aliasPrefix + "/")) {
700
+ const remainder = source.slice(aliasPrefix.length);
701
+ let resolved = aliasPath + remainder;
702
+ if (!path2.isAbsolute(resolved)) {
703
+ resolved = path2.resolve(fromDir, resolved);
704
+ }
705
+ return resolved;
706
+ }
707
+ }
708
+ return null;
709
+ }
282
710
  function loadThemeKeys(opts, rootDir, _babelTypes, verboseMode = false) {
283
711
  if (themeLoadAttempted && themeKeysCache) {
284
712
  return themeKeysCache;
285
713
  }
286
714
  themeLoadAttempted = true;
715
+ if (opts.aliases && typeof opts.aliases === "object") {
716
+ packageAliases = opts.aliases;
717
+ if (verboseMode) {
718
+ console.log("[idealyst-plugin] Configured aliases:", packageAliases);
719
+ }
720
+ }
287
721
  const themePath = opts.themePath;
288
722
  if (!themePath) {
289
723
  throw new Error(
290
724
  '[idealyst-plugin] themePath is required!\nAdd it to your babel config:\n ["@idealyst/theme/plugin", { themePath: "./src/theme/styles.ts" }]'
291
725
  );
292
726
  }
293
- const resolvedPath = themePath.startsWith(".") ? path.resolve(rootDir, themePath) : themePath;
727
+ let resolvedPath;
728
+ const aliasResolved = resolveWithAliases(themePath, rootDir);
729
+ if (aliasResolved && fs2.existsSync(aliasResolved)) {
730
+ resolvedPath = aliasResolved;
731
+ } else {
732
+ resolvedPath = themePath.startsWith(".") ? path2.resolve(rootDir, themePath) : themePath;
733
+ }
294
734
  if (verboseMode) {
295
735
  console.log("[idealyst-plugin] Analyzing theme file via @idealyst/tooling:", resolvedPath);
296
736
  }
@@ -325,14 +765,14 @@ function analyzeComponents(options) {
325
765
  const registry = {};
326
766
  const themeValues = analyzeTheme(themePath, false);
327
767
  for (const componentPath of componentPaths) {
328
- const resolvedPath = path2.resolve(componentPath);
329
- if (!fs2.existsSync(resolvedPath)) {
768
+ const resolvedPath = path3.resolve(componentPath);
769
+ if (!fs3.existsSync(resolvedPath)) {
330
770
  console.warn(`[component-analyzer] Path not found: ${resolvedPath}`);
331
771
  continue;
332
772
  }
333
773
  const componentDirs = findComponentDirs(resolvedPath);
334
774
  for (const dir of componentDirs) {
335
- const componentName = path2.basename(dir);
775
+ const componentName = path3.basename(dir);
336
776
  if (include && !include.includes(componentName)) continue;
337
777
  if (exclude && exclude.includes(componentName)) continue;
338
778
  if (!includeInternal && componentName.startsWith("_")) continue;
@@ -346,12 +786,12 @@ function analyzeComponents(options) {
346
786
  }
347
787
  function findComponentDirs(basePath) {
348
788
  const dirs = [];
349
- const entries = fs2.readdirSync(basePath, { withFileTypes: true });
789
+ const entries = fs3.readdirSync(basePath, { withFileTypes: true });
350
790
  for (const entry of entries) {
351
791
  if (!entry.isDirectory()) continue;
352
- const dirPath = path2.join(basePath, entry.name);
353
- const hasIndex = fs2.existsSync(path2.join(dirPath, "index.ts"));
354
- const hasTypes = fs2.existsSync(path2.join(dirPath, "types.ts"));
792
+ const dirPath = path3.join(basePath, entry.name);
793
+ const hasIndex = fs3.existsSync(path3.join(dirPath, "index.ts"));
794
+ const hasTypes = fs3.existsSync(path3.join(dirPath, "types.ts"));
355
795
  if (hasIndex || hasTypes) {
356
796
  dirs.push(dirPath);
357
797
  }
@@ -359,14 +799,14 @@ function findComponentDirs(basePath) {
359
799
  return dirs;
360
800
  }
361
801
  function analyzeComponentDir(dir, componentName, themeValues) {
362
- const tsFiles = fs2.readdirSync(dir).filter((f) => f.endsWith(".ts") || f.endsWith(".tsx")).map((f) => path2.join(dir, f));
802
+ const tsFiles = fs3.readdirSync(dir).filter((f) => f.endsWith(".ts") || f.endsWith(".tsx")).map((f) => path3.join(dir, f));
363
803
  if (tsFiles.length === 0) {
364
804
  return null;
365
805
  }
366
- const program = ts2.createProgram(tsFiles, {
367
- target: ts2.ScriptTarget.ES2020,
368
- module: ts2.ModuleKind.ESNext,
369
- jsx: ts2.JsxEmit.React,
806
+ const program = ts3.createProgram(tsFiles, {
807
+ target: ts3.ScriptTarget.ES2020,
808
+ module: ts3.ModuleKind.ESNext,
809
+ jsx: ts3.JsxEmit.React,
370
810
  strict: true,
371
811
  esModuleInterop: true,
372
812
  skipLibCheck: true
@@ -379,12 +819,12 @@ function analyzeComponentDir(dir, componentName, themeValues) {
379
819
  for (const filePath of tsFiles) {
380
820
  const sourceFile = program.getSourceFile(filePath);
381
821
  if (!sourceFile) continue;
382
- ts2.forEachChild(sourceFile, (node) => {
383
- if (ts2.isInterfaceDeclaration(node) && node.name.text === propsInterfaceName) {
822
+ ts3.forEachChild(sourceFile, (node) => {
823
+ if (ts3.isInterfaceDeclaration(node) && node.name.text === propsInterfaceName) {
384
824
  propsInterface = node;
385
825
  interfaceDescription = getJSDocDescription(node);
386
826
  }
387
- if (ts2.isTypeAliasDeclaration(node) && node.name.text === propsInterfaceName) {
827
+ if (ts3.isTypeAliasDeclaration(node) && node.name.text === propsInterfaceName) {
388
828
  propsInterface = node;
389
829
  interfaceDescription = getJSDocDescription(node);
390
830
  }
@@ -396,8 +836,8 @@ function analyzeComponentDir(dir, componentName, themeValues) {
396
836
  for (const filePath of tsFiles) {
397
837
  const sourceFile = program.getSourceFile(filePath);
398
838
  if (!sourceFile) continue;
399
- ts2.forEachChild(sourceFile, (node) => {
400
- if ((ts2.isInterfaceDeclaration(node) || ts2.isTypeAliasDeclaration(node)) && node.name.text === altName) {
839
+ ts3.forEachChild(sourceFile, (node) => {
840
+ if ((ts3.isInterfaceDeclaration(node) || ts3.isTypeAliasDeclaration(node)) && node.name.text === altName) {
401
841
  propsInterface = node;
402
842
  interfaceDescription = getJSDocDescription(node);
403
843
  }
@@ -429,32 +869,32 @@ function analyzeComponentDir(dir, componentName, themeValues) {
429
869
  description,
430
870
  props,
431
871
  category,
432
- filePath: path2.relative(process.cwd(), dir),
872
+ filePath: path3.relative(process.cwd(), dir),
433
873
  sampleProps
434
874
  };
435
875
  }
436
876
  function extractSampleProps(dir) {
437
- const docsPath = path2.join(dir, "docs.ts");
438
- if (!fs2.existsSync(docsPath)) {
877
+ const docsPath = path3.join(dir, "docs.ts");
878
+ if (!fs3.existsSync(docsPath)) {
439
879
  return void 0;
440
880
  }
441
881
  try {
442
- const content = fs2.readFileSync(docsPath, "utf-8");
443
- const sourceFile = ts2.createSourceFile(
882
+ const content = fs3.readFileSync(docsPath, "utf-8");
883
+ const sourceFile = ts3.createSourceFile(
444
884
  "docs.ts",
445
885
  content,
446
- ts2.ScriptTarget.ES2020,
886
+ ts3.ScriptTarget.ES2020,
447
887
  true,
448
- ts2.ScriptKind.TS
888
+ ts3.ScriptKind.TS
449
889
  );
450
890
  let samplePropsNode = null;
451
- ts2.forEachChild(sourceFile, (node) => {
452
- if (ts2.isVariableStatement(node)) {
453
- const isExported = node.modifiers?.some((m) => m.kind === ts2.SyntaxKind.ExportKeyword);
891
+ ts3.forEachChild(sourceFile, (node) => {
892
+ if (ts3.isVariableStatement(node)) {
893
+ const isExported = node.modifiers?.some((m) => m.kind === ts3.SyntaxKind.ExportKeyword);
454
894
  if (isExported) {
455
895
  for (const decl of node.declarationList.declarations) {
456
- if (ts2.isIdentifier(decl.name) && decl.name.text === "sampleProps" && decl.initializer) {
457
- if (ts2.isObjectLiteralExpression(decl.initializer)) {
896
+ if (ts3.isIdentifier(decl.name) && decl.name.text === "sampleProps" && decl.initializer) {
897
+ if (ts3.isObjectLiteralExpression(decl.initializer)) {
458
898
  samplePropsNode = decl.initializer;
459
899
  }
460
900
  }
@@ -468,13 +908,13 @@ function extractSampleProps(dir) {
468
908
  const result = {};
469
909
  const propsNode = samplePropsNode;
470
910
  for (const prop of propsNode.properties) {
471
- if (ts2.isPropertyAssignment(prop) && ts2.isIdentifier(prop.name)) {
911
+ if (ts3.isPropertyAssignment(prop) && ts3.isIdentifier(prop.name)) {
472
912
  const propName = prop.name.text;
473
- if (propName === "props" && ts2.isObjectLiteralExpression(prop.initializer)) {
913
+ if (propName === "props" && ts3.isObjectLiteralExpression(prop.initializer)) {
474
914
  result.props = extractObjectLiteral(prop.initializer, content);
475
915
  } else if (propName === "children") {
476
916
  result.children = prop.initializer.getText(sourceFile);
477
- } else if (propName === "state" && ts2.isObjectLiteralExpression(prop.initializer)) {
917
+ } else if (propName === "state" && ts3.isObjectLiteralExpression(prop.initializer)) {
478
918
  result.state = extractObjectLiteral(prop.initializer, content);
479
919
  }
480
920
  }
@@ -488,20 +928,20 @@ function extractSampleProps(dir) {
488
928
  function extractObjectLiteral(node, sourceContent) {
489
929
  const result = {};
490
930
  for (const prop of node.properties) {
491
- if (ts2.isPropertyAssignment(prop) && ts2.isIdentifier(prop.name)) {
931
+ if (ts3.isPropertyAssignment(prop) && ts3.isIdentifier(prop.name)) {
492
932
  const key = prop.name.text;
493
933
  const init = prop.initializer;
494
- if (ts2.isStringLiteral(init)) {
934
+ if (ts3.isStringLiteral(init)) {
495
935
  result[key] = init.text;
496
- } else if (ts2.isNumericLiteral(init)) {
936
+ } else if (ts3.isNumericLiteral(init)) {
497
937
  result[key] = Number(init.text);
498
- } else if (init.kind === ts2.SyntaxKind.TrueKeyword) {
938
+ } else if (init.kind === ts3.SyntaxKind.TrueKeyword) {
499
939
  result[key] = true;
500
- } else if (init.kind === ts2.SyntaxKind.FalseKeyword) {
940
+ } else if (init.kind === ts3.SyntaxKind.FalseKeyword) {
501
941
  result[key] = false;
502
- } else if (ts2.isArrayLiteralExpression(init)) {
942
+ } else if (ts3.isArrayLiteralExpression(init)) {
503
943
  result[key] = extractArrayLiteral(init, sourceContent);
504
- } else if (ts2.isObjectLiteralExpression(init)) {
944
+ } else if (ts3.isObjectLiteralExpression(init)) {
505
945
  result[key] = extractObjectLiteral(init, sourceContent);
506
946
  } else {
507
947
  result[key] = init.getText();
@@ -513,17 +953,17 @@ function extractObjectLiteral(node, sourceContent) {
513
953
  function extractArrayLiteral(node, sourceContent) {
514
954
  const result = [];
515
955
  for (const element of node.elements) {
516
- if (ts2.isStringLiteral(element)) {
956
+ if (ts3.isStringLiteral(element)) {
517
957
  result.push(element.text);
518
- } else if (ts2.isNumericLiteral(element)) {
958
+ } else if (ts3.isNumericLiteral(element)) {
519
959
  result.push(Number(element.text));
520
- } else if (element.kind === ts2.SyntaxKind.TrueKeyword) {
960
+ } else if (element.kind === ts3.SyntaxKind.TrueKeyword) {
521
961
  result.push(true);
522
- } else if (element.kind === ts2.SyntaxKind.FalseKeyword) {
962
+ } else if (element.kind === ts3.SyntaxKind.FalseKeyword) {
523
963
  result.push(false);
524
- } else if (ts2.isObjectLiteralExpression(element)) {
964
+ } else if (ts3.isObjectLiteralExpression(element)) {
525
965
  result.push(extractObjectLiteral(element, sourceContent));
526
- } else if (ts2.isArrayLiteralExpression(element)) {
966
+ } else if (ts3.isArrayLiteralExpression(element)) {
527
967
  result.push(extractArrayLiteral(element, sourceContent));
528
968
  } else {
529
969
  result.push(element.getText());
@@ -538,8 +978,8 @@ function analyzeProperty(symbol, typeChecker, themeValues) {
538
978
  const declaration = declarations[0];
539
979
  const type = typeChecker.getTypeOfSymbolAtLocation(symbol, declaration);
540
980
  const typeString = typeChecker.typeToString(type);
541
- const description = ts2.displayPartsToString(symbol.getDocumentationComment(typeChecker)) || void 0;
542
- const required = !(symbol.flags & ts2.SymbolFlags.Optional);
981
+ const description = ts3.displayPartsToString(symbol.getDocumentationComment(typeChecker)) || void 0;
982
+ const required = !(symbol.flags & ts3.SymbolFlags.Optional);
543
983
  const values = extractPropValues(type, typeString, typeChecker, themeValues);
544
984
  const defaultValue = extractDefaultValue(symbol);
545
985
  return {
@@ -580,7 +1020,7 @@ function extractDefaultValue(symbol) {
580
1020
  const tags = symbol.getJsDocTags();
581
1021
  for (const tag of tags) {
582
1022
  if (tag.name === "default" && tag.text) {
583
- const value = ts2.displayPartsToString(tag.text);
1023
+ const value = ts3.displayPartsToString(tag.text);
584
1024
  try {
585
1025
  return JSON.parse(value);
586
1026
  } catch {
@@ -684,7 +1124,9 @@ function inferCategory(componentName) {
684
1124
  export {
685
1125
  analyzeComponents,
686
1126
  analyzeTheme,
1127
+ analyzeThemeSource,
687
1128
  loadThemeKeys,
688
- resetThemeCache
1129
+ resetThemeCache,
1130
+ toBabelThemeKeys
689
1131
  };
690
1132
  //# sourceMappingURL=index.js.map