@idealyst/theme 1.2.39 → 1.2.41

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": "@idealyst/theme",
3
- "version": "1.2.39",
3
+ "version": "1.2.41",
4
4
  "description": "Theming system for Idealyst Framework",
5
5
  "readme": "README.md",
6
6
  "main": "src/index.ts",
@@ -435,6 +435,15 @@ function expandCompoundVariantsArray(t, arrayNode, themeParam, keys, verbose, ex
435
435
  } else if (iteratorInfo.type === 'sizes' && iteratorInfo.componentName) {
436
436
  keysToExpand = keys?.sizes?.[iteratorInfo.componentName] || [];
437
437
  variantKeyName = 'size';
438
+ } else if (iteratorInfo.type === 'surfaceColors') {
439
+ keysToExpand = keys?.surfaceColors || [];
440
+ variantKeyName = 'background';
441
+ } else if (iteratorInfo.type === 'textColors') {
442
+ keysToExpand = keys?.textColors || [];
443
+ variantKeyName = 'color';
444
+ } else if (iteratorInfo.type === 'borderColors') {
445
+ keysToExpand = keys?.borderColors || [];
446
+ variantKeyName = 'borderColor';
438
447
  }
439
448
 
440
449
  if (keysToExpand.length === 0) {
@@ -498,6 +507,32 @@ function findIteratorPattern(t, node, themeParam, debugLog = () => {}) {
498
507
  return;
499
508
  }
500
509
 
510
+ // Color iterators: theme.colors.$surface, theme.colors.$text, theme.colors.$border
511
+ // Pattern: theme.colors.$surface expands to screen, primary, secondary, etc.
512
+ if (i > 0 && chain[i - 1] === 'colors') {
513
+ if (iteratorName === 'surface') {
514
+ result = {
515
+ type: 'surfaceColors',
516
+ accessPath: chain.slice(i + 1),
517
+ };
518
+ return;
519
+ }
520
+ if (iteratorName === 'text') {
521
+ result = {
522
+ type: 'textColors',
523
+ accessPath: chain.slice(i + 1),
524
+ };
525
+ return;
526
+ }
527
+ if (iteratorName === 'border') {
528
+ result = {
529
+ type: 'borderColors',
530
+ accessPath: chain.slice(i + 1),
531
+ };
532
+ return;
533
+ }
534
+ }
535
+
501
536
  if (i > 0 && chain[i - 1] === 'sizes') {
502
537
  result = {
503
538
  type: 'sizes',
@@ -561,6 +596,12 @@ function expandVariantWithIterator(t, valueNode, themeParam, keys, iteratorInfo,
561
596
  keysToExpand = keys?.typography || [];
562
597
  } else if (iteratorInfo.type === 'sizes' && iteratorInfo.componentName) {
563
598
  keysToExpand = keys?.sizes?.[iteratorInfo.componentName] || [];
599
+ } else if (iteratorInfo.type === 'surfaceColors') {
600
+ keysToExpand = keys?.surfaceColors || [];
601
+ } else if (iteratorInfo.type === 'textColors') {
602
+ keysToExpand = keys?.textColors || [];
603
+ } else if (iteratorInfo.type === 'borderColors') {
604
+ keysToExpand = keys?.borderColors || [];
564
605
  }
565
606
 
566
607
  if (keysToExpand.length === 0) {
@@ -573,9 +614,14 @@ function expandVariantWithIterator(t, valueNode, themeParam, keys, iteratorInfo,
573
614
 
574
615
  for (const key of keysToExpand) {
575
616
  const expandedValue = replaceIteratorRefs(t, valueNode, themeParam, iteratorInfo, key);
617
+ // Use string literal for keys with special characters (like hyphens)
618
+ // e.g., 'inverse-secondary' cannot be a valid identifier
619
+ const keyNode = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(key)
620
+ ? t.identifier(key)
621
+ : t.stringLiteral(key);
576
622
  expandedProps.push(
577
623
  t.objectProperty(
578
- t.identifier(key),
624
+ keyNode,
579
625
  expandedValue
580
626
  )
581
627
  );
@@ -621,6 +667,22 @@ function replaceIteratorRefs(t, node, themeParam, iteratorInfo, key) {
621
667
  dollarIndex = i;
622
668
  break;
623
669
  }
670
+ // Color iterators: theme.colors.$surface -> theme.colors.surface.{key}
671
+ if (iteratorInfo.type === 'surfaceColors' && iterName === 'surface' && i > 0 && chain[i - 1] === 'colors') {
672
+ hasIterator = true;
673
+ dollarIndex = i;
674
+ break;
675
+ }
676
+ if (iteratorInfo.type === 'textColors' && iterName === 'text' && i > 0 && chain[i - 1] === 'colors') {
677
+ hasIterator = true;
678
+ dollarIndex = i;
679
+ break;
680
+ }
681
+ if (iteratorInfo.type === 'borderColors' && iterName === 'border' && i > 0 && chain[i - 1] === 'colors') {
682
+ hasIterator = true;
683
+ dollarIndex = i;
684
+ break;
685
+ }
624
686
  }
625
687
  }
626
688
 
@@ -664,7 +726,14 @@ function replaceIteratorRefs(t, node, themeParam, iteratorInfo, key) {
664
726
  function buildMemberExpression(t, base, chain) {
665
727
  let expr = t.identifier(base);
666
728
  for (const part of chain) {
667
- expr = t.memberExpression(expr, t.identifier(part));
729
+ // Use bracket notation for keys with special characters (like hyphens)
730
+ // e.g., theme.colors.surface['inverse-secondary'] instead of theme.colors.surface.inverse-secondary
731
+ const isValidIdentifier = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(part);
732
+ if (isValidIdentifier) {
733
+ expr = t.memberExpression(expr, t.identifier(part));
734
+ } else {
735
+ expr = t.memberExpression(expr, t.stringLiteral(part), true); // computed = true
736
+ }
668
737
  }
669
738
  return expr;
670
739
  }
package/src/builder.ts CHANGED
@@ -173,6 +173,25 @@ export class ThemeBuilder<
173
173
  return newBuilder;
174
174
  }
175
175
 
176
+ /**
177
+ * Set (replace) an existing intent in the theme.
178
+ * Use this to override an intent inherited from a base theme.
179
+ */
180
+ setIntent<K extends TIntents>(
181
+ name: K,
182
+ value: IntentValue
183
+ ): ThemeBuilder<TIntents, TRadii, TShadows, TPallet, TSurface, TText, TBorder, TSize, TBreakpoints> {
184
+ const newBuilder = new ThemeBuilder<TIntents, TRadii, TShadows, TPallet, TSurface, TText, TBorder, TSize, TBreakpoints>();
185
+ newBuilder.config = {
186
+ ...this.config,
187
+ intents: {
188
+ ...this.config.intents,
189
+ [name]: value,
190
+ } as any,
191
+ };
192
+ return newBuilder;
193
+ }
194
+
176
195
  /**
177
196
  * Add a custom border radius value.
178
197
  */
@@ -245,6 +264,182 @@ export class ThemeBuilder<
245
264
  return newBuilder;
246
265
  }
247
266
 
267
+ /**
268
+ * Add a new pallet color to the theme.
269
+ * Expands the available pallet colors.
270
+ */
271
+ addPalletColor<K extends string>(
272
+ name: K,
273
+ shades: Record<Shade, ColorValue>
274
+ ): ThemeBuilder<TIntents, TRadii, TShadows, TPallet | K, TSurface, TText, TBorder, TSize, TBreakpoints> {
275
+ const newBuilder = new ThemeBuilder<TIntents, TRadii, TShadows, TPallet | K, TSurface, TText, TBorder, TSize, TBreakpoints>();
276
+ newBuilder.config = {
277
+ ...this.config,
278
+ colors: {
279
+ ...this.config.colors,
280
+ pallet: {
281
+ ...this.config.colors.pallet,
282
+ [name]: shades,
283
+ } as any,
284
+ },
285
+ };
286
+ return newBuilder;
287
+ }
288
+
289
+ /**
290
+ * Set (replace) an existing pallet color in the theme.
291
+ * Use this to override a pallet color inherited from a base theme.
292
+ */
293
+ setPalletColor<K extends TPallet>(
294
+ name: K,
295
+ shades: Record<Shade, ColorValue>
296
+ ): ThemeBuilder<TIntents, TRadii, TShadows, TPallet, TSurface, TText, TBorder, TSize, TBreakpoints> {
297
+ const newBuilder = new ThemeBuilder<TIntents, TRadii, TShadows, TPallet, TSurface, TText, TBorder, TSize, TBreakpoints>();
298
+ newBuilder.config = {
299
+ ...this.config,
300
+ colors: {
301
+ ...this.config.colors,
302
+ pallet: {
303
+ ...this.config.colors.pallet,
304
+ [name]: shades,
305
+ } as any,
306
+ },
307
+ };
308
+ return newBuilder;
309
+ }
310
+
311
+ /**
312
+ * Add a new surface color to the theme.
313
+ * Expands the available surface colors.
314
+ */
315
+ addSurfaceColor<K extends string>(
316
+ name: K,
317
+ value: ColorValue
318
+ ): ThemeBuilder<TIntents, TRadii, TShadows, TPallet, TSurface | K, TText, TBorder, TSize, TBreakpoints> {
319
+ const newBuilder = new ThemeBuilder<TIntents, TRadii, TShadows, TPallet, TSurface | K, TText, TBorder, TSize, TBreakpoints>();
320
+ newBuilder.config = {
321
+ ...this.config,
322
+ colors: {
323
+ ...this.config.colors,
324
+ surface: {
325
+ ...this.config.colors.surface,
326
+ [name]: value,
327
+ } as any,
328
+ },
329
+ };
330
+ return newBuilder;
331
+ }
332
+
333
+ /**
334
+ * Set (replace) an existing surface color in the theme.
335
+ * Use this to override a surface color inherited from a base theme.
336
+ */
337
+ setSurfaceColor<K extends TSurface>(
338
+ name: K,
339
+ value: ColorValue
340
+ ): ThemeBuilder<TIntents, TRadii, TShadows, TPallet, TSurface, TText, TBorder, TSize, TBreakpoints> {
341
+ const newBuilder = new ThemeBuilder<TIntents, TRadii, TShadows, TPallet, TSurface, TText, TBorder, TSize, TBreakpoints>();
342
+ newBuilder.config = {
343
+ ...this.config,
344
+ colors: {
345
+ ...this.config.colors,
346
+ surface: {
347
+ ...this.config.colors.surface,
348
+ [name]: value,
349
+ } as any,
350
+ },
351
+ };
352
+ return newBuilder;
353
+ }
354
+
355
+ /**
356
+ * Add a new text color to the theme.
357
+ * Expands the available text colors.
358
+ */
359
+ addTextColor<K extends string>(
360
+ name: K,
361
+ value: ColorValue
362
+ ): ThemeBuilder<TIntents, TRadii, TShadows, TPallet, TSurface, TText | K, TBorder, TSize, TBreakpoints> {
363
+ const newBuilder = new ThemeBuilder<TIntents, TRadii, TShadows, TPallet, TSurface, TText | K, TBorder, TSize, TBreakpoints>();
364
+ newBuilder.config = {
365
+ ...this.config,
366
+ colors: {
367
+ ...this.config.colors,
368
+ text: {
369
+ ...this.config.colors.text,
370
+ [name]: value,
371
+ } as any,
372
+ },
373
+ };
374
+ return newBuilder;
375
+ }
376
+
377
+ /**
378
+ * Set (replace) an existing text color in the theme.
379
+ * Use this to override a text color inherited from a base theme.
380
+ */
381
+ setTextColor<K extends TText>(
382
+ name: K,
383
+ value: ColorValue
384
+ ): ThemeBuilder<TIntents, TRadii, TShadows, TPallet, TSurface, TText, TBorder, TSize, TBreakpoints> {
385
+ const newBuilder = new ThemeBuilder<TIntents, TRadii, TShadows, TPallet, TSurface, TText, TBorder, TSize, TBreakpoints>();
386
+ newBuilder.config = {
387
+ ...this.config,
388
+ colors: {
389
+ ...this.config.colors,
390
+ text: {
391
+ ...this.config.colors.text,
392
+ [name]: value,
393
+ } as any,
394
+ },
395
+ };
396
+ return newBuilder;
397
+ }
398
+
399
+ /**
400
+ * Add a new border color to the theme.
401
+ * Expands the available border colors.
402
+ */
403
+ addBorderColor<K extends string>(
404
+ name: K,
405
+ value: ColorValue
406
+ ): ThemeBuilder<TIntents, TRadii, TShadows, TPallet, TSurface, TText, TBorder | K, TSize, TBreakpoints> {
407
+ const newBuilder = new ThemeBuilder<TIntents, TRadii, TShadows, TPallet, TSurface, TText, TBorder | K, TSize, TBreakpoints>();
408
+ newBuilder.config = {
409
+ ...this.config,
410
+ colors: {
411
+ ...this.config.colors,
412
+ border: {
413
+ ...this.config.colors.border,
414
+ [name]: value,
415
+ } as any,
416
+ },
417
+ };
418
+ return newBuilder;
419
+ }
420
+
421
+ /**
422
+ * Set (replace) an existing border color in the theme.
423
+ * Use this to override a border color inherited from a base theme.
424
+ */
425
+ setBorderColor<K extends TBorder>(
426
+ name: K,
427
+ value: ColorValue
428
+ ): ThemeBuilder<TIntents, TRadii, TShadows, TPallet, TSurface, TText, TBorder, TSize, TBreakpoints> {
429
+ const newBuilder = new ThemeBuilder<TIntents, TRadii, TShadows, TPallet, TSurface, TText, TBorder, TSize, TBreakpoints>();
430
+ newBuilder.config = {
431
+ ...this.config,
432
+ colors: {
433
+ ...this.config.colors,
434
+ border: {
435
+ ...this.config.colors.border,
436
+ [name]: value,
437
+ } as any,
438
+ },
439
+ };
440
+ return newBuilder;
441
+ }
442
+
248
443
  /**
249
444
  * Set the sizes configuration.
250
445
  */