mirror of
https://github.com/tailwindlabs/tailwindcss.git
synced 2025-12-08 21:36:08 +00:00
* implement matchUtilities2 * ensure animation names without keyframes are not prefixed * remove matchBase * call addUtilities for each group individually * WIP: Write plugins using matchUtilities2 * MORE * Fix arbitrary value support for fontSize * Fixes, update fixtures * Rebuild fixtures * Don't generate `divide` class with no modifier * Fixes, rebuild fixtures * Rename matchUtilities2 to matchUtilities * Delete bad tests * Remove temp files GROSS * Clean stuff up * Support no return in matchUtilities Co-authored-by: Adam Wathan <adam.wathan@gmail.com>
47 lines
1.4 KiB
JavaScript
47 lines
1.4 KiB
JavaScript
import transformThemeValue from './transformThemeValue'
|
|
import { asValue, asList, asColor, asAngle, asLength, asLookupValue } from '../util/pluginUtils'
|
|
|
|
let asMap = new Map([
|
|
[asValue, 'any'],
|
|
[asList, 'list'],
|
|
[asColor, 'color'],
|
|
[asAngle, 'angle'],
|
|
[asLength, 'length'],
|
|
[asLookupValue, 'lookup'],
|
|
])
|
|
|
|
export default function createUtilityPlugin(
|
|
themeKey,
|
|
utilityVariations = [[themeKey, [themeKey]]],
|
|
{ filterDefault = false, resolveArbitraryValue = asValue } = {}
|
|
) {
|
|
let transformValue = transformThemeValue(themeKey)
|
|
return function ({ matchUtilities, variants, theme }) {
|
|
for (let utilityVariation of utilityVariations) {
|
|
let group = Array.isArray(utilityVariation[0]) ? utilityVariation : [utilityVariation]
|
|
|
|
matchUtilities(
|
|
group.reduce((obj, [classPrefix, properties]) => {
|
|
return Object.assign(obj, {
|
|
[classPrefix]: (value) => {
|
|
return properties.reduce(
|
|
(obj, name) => Object.assign(obj, { [name]: transformValue(value) }),
|
|
{}
|
|
)
|
|
},
|
|
})
|
|
}, {}),
|
|
{
|
|
values: filterDefault
|
|
? Object.fromEntries(
|
|
Object.entries(theme(themeKey)).filter(([modifier]) => modifier !== 'DEFAULT')
|
|
)
|
|
: theme(themeKey),
|
|
variants: variants(themeKey),
|
|
type: asMap.get(resolveArbitraryValue) ?? 'any',
|
|
}
|
|
)
|
|
}
|
|
}
|
|
}
|