Skip to content

Commit 45c6e04

Browse files
committed
Simplify
1 parent e8fe386 commit 45c6e04

File tree

1 file changed

+14
-78
lines changed

1 file changed

+14
-78
lines changed

packages/tailwindcss/src/compat/apply-config-to-theme.ts

Lines changed: 14 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -169,81 +169,6 @@ export function keyPathToCssProperty(path: string[]) {
169169
if (path[0] === 'screens') path[0] = 'breakpoint'
170170
if (path[0] === 'transitionTimingFunction') path[0] = 'ease'
171171

172-
if (path[0] == 'accentColor') path[0] = 'accent-color'
173-
if (path[0] == 'backdropBlur') path[0] = 'backdrop-blur'
174-
if (path[0] == 'backdropBrightness') path[0] = 'backdrop-brightness'
175-
if (path[0] == 'backdropContrast') path[0] = 'backdrop-contrast'
176-
if (path[0] == 'backdropGrayscale') path[0] = 'backdrop-grayscale'
177-
if (path[0] == 'backdropHueRotate') path[0] = 'backdrop-hue-rotate'
178-
if (path[0] == 'backdropInvert') path[0] = 'backdrop-invert'
179-
if (path[0] == 'backdropOpacity') path[0] = 'backdrop-opacity'
180-
if (path[0] == 'backdropSaturate') path[0] = 'backdrop-saturate'
181-
if (path[0] == 'backdropSepia') path[0] = 'backdrop-sepia'
182-
if (path[0] == 'backgroundColor') path[0] = 'background-color'
183-
if (path[0] == 'backgroundOpacity') path[0] = 'background-opacity'
184-
if (path[0] == 'borderColor') path[0] = 'border-color'
185-
if (path[0] == 'borderOpacity') path[0] = 'border-opacity'
186-
if (path[0] == 'borderSpacing') path[0] = 'border-spacing'
187-
if (path[0] == 'boxShadowColor') path[0] = 'box-shadow-color'
188-
if (path[0] == 'caretColor') path[0] = 'caret-color'
189-
if (path[0] == 'divideColor') path[0] = 'divide-color'
190-
if (path[0] == 'divideOpacity') path[0] = 'divide-opacity'
191-
if (path[0] == 'divideWidth') path[0] = 'divide-width'
192-
if (path[0] == 'flexBasis') path[0] = 'flex-basis'
193-
if (path[0] == 'gradientColorStops') path[0] = 'gradient-color-stops'
194-
if (path[0] == 'maxHeight') path[0] = 'max-height'
195-
if (path[0] == 'minHeight') path[0] = 'min-height'
196-
if (path[0] == 'minWidth') path[0] = 'min-width'
197-
if (path[0] == 'outlineColor') path[0] = 'outline-color'
198-
if (path[0] == 'placeholderColor') path[0] = 'placeholder-color'
199-
if (path[0] == 'placeholderOpacity') path[0] = 'placeholder-opacity'
200-
if (path[0] == 'ringColor') path[0] = 'ring-color'
201-
if (path[0] == 'ringOffsetColor') path[0] = 'ring-offset-color'
202-
if (path[0] == 'ringOpacity') path[0] = 'ring-opacity'
203-
if (path[0] == 'scrollMargin') path[0] = 'scroll-margin'
204-
if (path[0] == 'scrollPadding') path[0] = 'scroll-padding'
205-
if (path[0] == 'textColor') path[0] = 'text-color'
206-
if (path[0] == 'textDecorationColor') path[0] = 'text-decoration-color'
207-
if (path[0] == 'textIndent') path[0] = 'text-indent'
208-
if (path[0] == 'textOpacity') path[0] = 'text-opacity'
209-
if (path[0] == 'backgroundImage') path[0] = 'background-image'
210-
if (path[0] == 'backgroundPosition') path[0] = 'background-position'
211-
if (path[0] == 'backgroundSize') path[0] = 'background-size'
212-
if (path[0] == 'borderWidth') path[0] = 'border-width'
213-
if (path[0] == 'dropShadow') path[0] = 'drop-shadow'
214-
if (path[0] == 'flexGrow') path[0] = 'flex-grow'
215-
if (path[0] == 'flexShrink') path[0] = 'flex-shrink'
216-
if (path[0] == 'fontWeight') path[0] = 'font-weight'
217-
if (path[0] == 'gradientColorStopPositions') path[0] = 'gradient-color-stop-positions'
218-
if (path[0] == 'gridAutoColumns') path[0] = 'grid-auto-columns'
219-
if (path[0] == 'gridAutoRows') path[0] = 'grid-auto-rows'
220-
if (path[0] == 'gridColumn') path[0] = 'grid-column'
221-
if (path[0] == 'gridColumnEnd') path[0] = 'grid-column-end'
222-
if (path[0] == 'gridColumnStart') path[0] = 'grid-column-start'
223-
if (path[0] == 'gridRow') path[0] = 'grid-row'
224-
if (path[0] == 'gridRowEnd') path[0] = 'grid-row-end'
225-
if (path[0] == 'gridRowStart') path[0] = 'grid-row-start'
226-
if (path[0] == 'gridTemplateColumns') path[0] = 'grid-template-columns'
227-
if (path[0] == 'gridTemplateRows') path[0] = 'grid-template-rows'
228-
if (path[0] == 'hueRotate') path[0] = 'hue-rotate'
229-
if (path[0] == 'listStyleType') path[0] = 'list-style-type'
230-
if (path[0] == 'listStyleImage') path[0] = 'list-style-image'
231-
if (path[0] == 'lineClamp') path[0] = 'line-clamp'
232-
if (path[0] == 'objectPosition') path[0] = 'object-position'
233-
if (path[0] == 'outlineOffset') path[0] = 'outline-offset'
234-
if (path[0] == 'outlineWidth') path[0] = 'outline-width'
235-
if (path[0] == 'ringOffsetWidth') path[0] = 'ring-offset-width'
236-
if (path[0] == 'ringWidth') path[0] = 'ring-width'
237-
if (path[0] == 'strokeWidth') path[0] = 'stroke-width'
238-
if (path[0] == 'textDecorationThickness') path[0] = 'text-decoration-thickness'
239-
if (path[0] == 'textUnderlineOffset') path[0] = 'text-underline-offset'
240-
if (path[0] == 'transformOrigin') path[0] = 'transform-origin'
241-
if (path[0] == 'transitionDelay') path[0] = 'transition-delay'
242-
if (path[0] == 'transitionDuration') path[0] = 'transition-duration'
243-
if (path[0] == 'transitionProperty') path[0] = 'transition-property'
244-
if (path[0] == 'willChange') path[0] = 'will-change'
245-
if (path[0] == 'zIndex') path[0] = 'z-index'
246-
247172
for (let part of path) {
248173
if (!IS_VALID_KEY.test(part)) return null
249174
}
@@ -260,11 +185,22 @@ export function keyPathToCssProperty(path: string[]) {
260185
.map((path, idx, all) => (path === '1' && idx !== all.length - 1 ? '' : path))
261186

262187
// Resolve the key path to a CSS variable segment
263-
.map((part) => {
188+
.map((part, idx) => {
264189
part = part.replaceAll('.', '_')
265190

266-
if (part === 'lineHeight') return 'line-height'
267-
if (part.startsWith('-')) {
191+
let shouldConvert =
192+
// The first "namespace" part should be converted to kebab-case
193+
// This converts things like backgroundColor to `background-color`
194+
idx === 0 ||
195+
// Any tuple nested key should be converted to kebab-case
196+
// These are identified with a leading `-`
197+
// e.g. `fontSize.xs.1.lineHeight` -> `font-size-xs--line-height`
198+
part.startsWith('-') ||
199+
// `lineHeight` is a bit of a special case in which it does not
200+
// always begin with a leading `-` even when as a nested tuple key
201+
part === 'lineHeight'
202+
203+
if (shouldConvert) {
268204
part = part.replace(/([a-z])([A-Z])/g, (_, a, b) => `${a}-${b.toLowerCase()}`)
269205
}
270206

0 commit comments

Comments
 (0)