Skip to content

Commit d3bd93a

Browse files
committed
chore: wip
1 parent 11ce8e7 commit d3bd93a

23 files changed

+912
-891
lines changed

packages/headwind/src/build.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export async function build(config: HeadwindConfig): Promise<BuildResult> {
5353
}
5454

5555
// Preflight CSS is now added by generator.toCSS()
56-
const css = generator.toCSS(config.minify)
56+
const css = generator.toCSS(true, config.minify)
5757
const duration = performance.now() - startTime
5858

5959
return {

packages/headwind/src/generator.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -318,13 +318,15 @@ export class CSSGenerator {
318318
/**
319319
* Generate final CSS output
320320
*/
321-
toCSS(minify = false): string {
321+
toCSS(includePreflight = true, minify = false): string {
322322
const parts: string[] = []
323323

324-
// Add preflight CSS first
325-
for (const preflight of this.config.preflights) {
326-
const preflightCSS = preflight.getCSS()
327-
parts.push(minify ? preflightCSS.replace(/\s+/g, ' ').trim() : preflightCSS)
324+
// Add preflight CSS first (if requested)
325+
if (includePreflight) {
326+
for (const preflight of this.config.preflights) {
327+
const preflightCSS = preflight.getCSS()
328+
parts.push(minify ? preflightCSS.replace(/\s+/g, ' ').trim() : preflightCSS)
329+
}
328330
}
329331

330332
// Base rules (no media query)

packages/headwind/src/parser.ts

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -238,22 +238,32 @@ export function parseClass(className: string): ParsedClass {
238238
}
239239

240240
// Regular negative value
241-
const match = positiveUtility.match(/^([a-z]+(?:-[a-z]+)*)(?:-(.+))?$/)
241+
const match = positiveUtility.match(/^([a-z]+(?:-[a-z]+)*?)-(.+)$/)
242242
if (match) {
243243
return {
244244
raw: className,
245245
variants,
246246
utility: match[1],
247-
value: match[2] ? `-${match[2]}` : undefined,
247+
value: `-${match[2]}`,
248248
important,
249249
arbitrary: false,
250250
}
251251
}
252+
// If no match, it's a standalone utility with just a negative sign (e.g., -flex doesn't make sense)
253+
// Return as-is
254+
return {
255+
raw: className,
256+
variants,
257+
utility: positiveUtility,
258+
value: undefined,
259+
important,
260+
arbitrary: false,
261+
}
252262
}
253263

254264
// Check for color opacity modifiers: bg-blue-500/50, text-red-500/75
255265
// Must come before fractional values to avoid conflict
256-
const opacityMatch = utility.match(/^([a-z]+(?:-[a-z]+)*)-(.+?)\/(\d+)$/)
266+
const opacityMatch = utility.match(/^([a-z]+(?:-[a-z]+)*?)-(.+?)\/(\d+)$/)
257267
if (opacityMatch && ['bg', 'text', 'border', 'ring', 'placeholder', 'divide'].includes(opacityMatch[1])) {
258268
return {
259269
raw: className,
@@ -266,7 +276,7 @@ export function parseClass(className: string): ParsedClass {
266276
}
267277

268278
// Check for fractional values: w-1/2, h-3/4
269-
const fractionMatch = utility.match(/^([a-z-]+)-(\d+)\/(\d+)$/)
279+
const fractionMatch = utility.match(/^([a-z]+(?:-[a-z]+)*?)-(\d+)\/(\d+)$/)
270280
if (fractionMatch) {
271281
return {
272282
raw: className,
@@ -279,22 +289,25 @@ export function parseClass(className: string): ParsedClass {
279289
}
280290

281291
// Regular parsing - split on last dash
282-
const match = utility.match(/^([a-z]+(?:-[a-z]+)*)(?:-(.+))?$/)
283-
if (!match) {
292+
// First try: utility-value pattern (e.g., text-current, p-4)
293+
const matchWithValue = utility.match(/^([a-z]+(?:-[a-z]+)*?)-(.+)$/)
294+
if (matchWithValue) {
284295
return {
285296
raw: className,
286297
variants,
287-
utility,
298+
utility: matchWithValue[1],
299+
value: matchWithValue[2],
288300
important,
289301
arbitrary: false,
290302
}
291303
}
292304

305+
// If no dash, treat entire string as utility with no value (e.g., flex, block)
293306
return {
294307
raw: className,
295308
variants,
296-
utility: match[1],
297-
value: match[2],
309+
utility,
310+
value: undefined,
298311
important,
299312
arbitrary: false,
300313
}

packages/headwind/src/rules.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,13 @@ export const spacingRule: UtilityRule = (parsed, config) => {
185185
if (parsed.value.startsWith('-')) {
186186
const positiveValue = parsed.value.slice(1)
187187
const spacing = config.theme.spacing[positiveValue]
188-
value = spacing ? `-${spacing}` : parsed.value
188+
// Special case: -0 should just be 0
189+
if (positiveValue === '0') {
190+
value = spacing || '0'
191+
}
192+
else {
193+
value = spacing ? `-${spacing}` : parsed.value
194+
}
189195
}
190196
else {
191197
value = config.theme.spacing[parsed.value] || parsed.value

0 commit comments

Comments
 (0)