fix(preset-mini): resolve nested theme colors with dashed keys#5021
Conversation
Theme colors defined with dashes in nested objects (e.g.,
`{ brand: { 'dark-blue': 'unocss#123' } }`) were not resolving at runtime when used as `text-brand-dark-blue`.
The color lookup only tried camelCase conversion (`darkBlue`) but never checked the original dashed form (`dark-blue`).
Closes unocss#4770
✅ Deploy Preview for unocss ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
commit: |
| brand: { | ||
| 'dark-blue': '#123456', | ||
| }, |
There was a problem hiding this comment.
brand: {
'dark-blue': {
DEFAULT: '#123456',
'foo-bar': {
baz: '#fff'
}
},
},Can you help test more complex test cases?
There was a problem hiding this comment.
Thanks for your review, @zyyv!
I added a more complex test case and refactored the getThemeColorForKey function by borrowing wind4 algorithm.
I posted a similar issue in TW. Since tailwind.config.js (or unocss.config.js) is still supported in TW4, that would make sense to port it to wind3.
Ideally, all theme values should be resolved using that logic, not only colors.
Let me know if you would like to go further.
Theme colors defined with dashes in nested objects were not resolving at runtime. Ported wind4's deepGet algorithm that tries progressively shorter flat keys to find the best match.
Supports complex nesting like:
{ brand: { 'dark-blue': { DEFAULT: 'unocss#123', 'foo-bar': { baz: '#fff' } } } }
Resolves: text-brand-dark-blue, text-brand-dark-blue-foo-bar-baz
Closes unocss#4770
|
thanks @zyyv ! |
Theme colors defined with dashes in nested objects (e.g.,
{ brand: { 'dark-blue': '#123' } }) were not resolving at runtime when used astext-brand-dark-blue.The color lookup only tried camelCase conversion (
darkBlue) but never checked the original dashed form (dark-blue).Closes #4770