import type { Config } from '../../../../tailwindcss/src/compat/plugin-api'
import type { DesignSystem } from '../../../../tailwindcss/src/design-system'
import * as version from '../../utils/version'
const LEGACY_CLASS_MAP: Record<string, string> = {
'overflow-ellipsis': 'text-ellipsis',
'flex-grow': 'grow',
'flex-grow-0': 'grow-0',
'flex-shrink': 'shrink',
'flex-shrink-0': 'shrink-0',
'decoration-clone': 'box-decoration-clone',
'decoration-slice': 'box-decoration-slice',
'bg-left-top': 'bg-top-left',
'bg-left-bottom': 'bg-bottom-left',
'bg-right-top': 'bg-top-right',
'bg-right-bottom': 'bg-bottom-right',
'object-left-top': 'object-top-left',
'object-left-bottom': 'object-bottom-left',
'object-right-top': 'object-top-right',
'object-right-bottom': 'object-bottom-right',
}
let seenDesignSystems = new WeakSet<DesignSystem>()
export function migrateSimpleLegacyClasses(
designSystem: DesignSystem,
_userConfig: Config | null,
rawCandidate: string,
): string {
if (version.isMajor(3)) {
LEGACY_CLASS_MAP['outline-none'] = 'outline-hidden'
}
if (!seenDesignSystems.has(designSystem)) {
for (let old in LEGACY_CLASS_MAP) {
designSystem.utilities.static(old, () => [])
}
seenDesignSystems.add(designSystem)
}
for (let candidate of designSystem.parseCandidate(rawCandidate)) {
if (candidate.kind === 'static' && Object.hasOwn(LEGACY_CLASS_MAP, candidate.root)) {
return designSystem.printCandidate({
...candidate,
root: LEGACY_CLASS_MAP[candidate.root as keyof typeof LEGACY_CLASS_MAP],
})
}
}
return rawCandidate
}