Skip to content

Commit 69a9fbc

Browse files
committed
chore: wip
1 parent c31cbbd commit 69a9fbc

File tree

3 files changed

+75
-4
lines changed

3 files changed

+75
-4
lines changed

packages/headwind/src/generator.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,17 @@ export class CSSGenerator {
389389
// Add preflight CSS first (if requested)
390390
if (includePreflight) {
391391
for (const preflight of this.config.preflights) {
392-
const preflightCSS = preflight.getCSS()
392+
let preflightCSS = preflight.getCSS()
393+
// Replace hardcoded font-family in preflight with theme's sans font
394+
const sansFonts = this.config.theme?.fontFamily?.sans
395+
if (sansFonts && Array.isArray(sansFonts)) {
396+
const fontFamilyValue = sansFonts.join(', ')
397+
// Replace the default ui-sans-serif stack in html/:host selector
398+
preflightCSS = preflightCSS.replace(
399+
/font-family:\s*ui-sans-serif[^;]+;/g,
400+
`font-family: ${fontFamilyValue};`,
401+
)
402+
}
393403
parts.push(minify ? preflightCSS.replace(/\s+/g, ' ').trim() : preflightCSS)
394404
}
395405
}

packages/headwind/src/rules-layout.ts

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,15 +169,40 @@ export const insetRule: UtilityRule = (parsed, config) => {
169169
if (!props || !parsed.value)
170170
return undefined
171171

172+
// Helper to resolve inset value (handles fractions, spacing, keywords)
173+
const resolveInsetValue = (val: string): string => {
174+
// Handle fractions: 1/2 -> 50%, 1/3 -> 33.333333%, etc.
175+
if (val.includes('/')) {
176+
const [num, denom] = val.split('/').map(Number)
177+
if (!Number.isNaN(num) && !Number.isNaN(denom) && denom !== 0) {
178+
return `${(num / denom) * 100}%`
179+
}
180+
}
181+
// Handle special keywords
182+
if (val === 'full')
183+
return '100%'
184+
if (val === 'auto')
185+
return 'auto'
186+
// Check spacing config, then fall back to raw value
187+
return config.theme.spacing[val] || val
188+
}
189+
172190
// Handle negative values
173191
let value: string
174192
if (parsed.value.startsWith('-')) {
175193
const positiveValue = parsed.value.slice(1)
176-
const spacing = config.theme.spacing[positiveValue]
177-
value = spacing ? `-${spacing}` : parsed.value
194+
const resolved = resolveInsetValue(positiveValue)
195+
// For percentage values, negate properly
196+
if (resolved.endsWith('%')) {
197+
const numericPart = Number.parseFloat(resolved)
198+
value = `${-numericPart}%`
199+
}
200+
else {
201+
value = resolved.startsWith('-') ? resolved : `-${resolved}`
202+
}
178203
}
179204
else {
180-
value = config.theme.spacing[parsed.value] || parsed.value
205+
value = resolveInsetValue(parsed.value)
181206
}
182207

183208
const result: Record<string, string> = {}

packages/headwind/test/layout.test.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,42 @@ describe('Layout Utilities', () => {
8989
gen.generate('-top-4')
9090
expect(gen.toCSS(false)).toContain('top: -1rem;')
9191
})
92+
93+
it('should generate left-1/2 as 50%', () => {
94+
const gen = new CSSGenerator(defaultConfig)
95+
gen.generate('left-1/2')
96+
expect(gen.toCSS(false)).toContain('left: 50%;')
97+
})
98+
99+
it('should generate top-1/3 as 33.333333%', () => {
100+
const gen = new CSSGenerator(defaultConfig)
101+
gen.generate('top-1/3')
102+
expect(gen.toCSS(false)).toContain('top: 33.33333333333333%;')
103+
})
104+
105+
it('should generate right-3/4 as 75%', () => {
106+
const gen = new CSSGenerator(defaultConfig)
107+
gen.generate('right-3/4')
108+
expect(gen.toCSS(false)).toContain('right: 75%;')
109+
})
110+
111+
it('should generate negative -left-1/2 as -50%', () => {
112+
const gen = new CSSGenerator(defaultConfig)
113+
gen.generate('-left-1/2')
114+
expect(gen.toCSS(false)).toContain('left: -50%;')
115+
})
116+
117+
it('should generate left-full as 100%', () => {
118+
const gen = new CSSGenerator(defaultConfig)
119+
gen.generate('left-full')
120+
expect(gen.toCSS(false)).toContain('left: 100%;')
121+
})
122+
123+
it('should generate top-auto', () => {
124+
const gen = new CSSGenerator(defaultConfig)
125+
gen.generate('top-auto')
126+
expect(gen.toCSS(false)).toContain('top: auto;')
127+
})
92128
})
93129

94130
describe('Z-index', () => {

0 commit comments

Comments
 (0)