Skip to content

Commit b5c003b

Browse files
chore: wip
1 parent 0547ef5 commit b5c003b

File tree

7 files changed

+119
-14
lines changed

7 files changed

+119
-14
lines changed

bun.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/headwind/src/generator.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ export class CSSGenerator {
4141
}
4242
}
4343

44+
// Merge theme.extend into theme (allows users to add custom values without replacing defaults)
45+
if (config.theme.extend) {
46+
const { extend, ...baseTheme } = this.config.theme
47+
this.config.theme = deepMerge(baseTheme, extend) as typeof this.config.theme
48+
}
49+
4450
// Pre-compile blocklist patterns for performance
4551
for (const pattern of this.config.blocklist) {
4652
if (pattern.includes('*')) {

packages/headwind/src/parser.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1142,6 +1142,9 @@ function parseClassImpl(className: string): ParsedClass {
11421142
'mix-blend',
11431143
'bg-blend',
11441144
'line-clamp',
1145+
'border-spacing',
1146+
'border-spacing-x',
1147+
'border-spacing-y',
11451148
]
11461149

11471150
// Special case for divide-x and divide-y (without values, they should be treated as compound)

packages/headwind/src/rules-advanced.ts

Lines changed: 45 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -378,17 +378,51 @@ export const alignSelfRule: UtilityRule = (parsed) => {
378378
}
379379
}
380380

381-
// Container utility
382-
// TODO: Requires nested media query support in generator
383-
export const containerRule: UtilityRule = (parsed, _config) => {
384-
if (parsed.utility === 'container' && !parsed.value) {
385-
// Simplified version without responsive max-widths
386-
return {
387-
'width': '100%',
388-
'margin-left': 'auto',
389-
'margin-right': 'auto',
390-
'padding-left': '1rem',
391-
'padding-right': '1rem',
381+
// Container utility with responsive max-widths
382+
export const containerRule: UtilityRule = (parsed, config) => {
383+
if (parsed.utility === 'container') {
384+
// container without value - centered container with responsive max-width
385+
if (!parsed.value) {
386+
// Use clamp for modern responsive max-width behavior
387+
// Max-width scales with breakpoints: sm=640, md=768, lg=1024, xl=1280, 2xl=1536
388+
const xl = config.theme.screens['xl'] || '1280px'
389+
return {
390+
'width': '100%',
391+
'margin-left': 'auto',
392+
'margin-right': 'auto',
393+
'max-width': xl,
394+
}
395+
}
396+
397+
// container-{breakpoint} for specific max-widths
398+
const breakpointMap: Record<string, string> = {
399+
'sm': config.theme.screens['sm'] || '640px',
400+
'md': config.theme.screens['md'] || '768px',
401+
'lg': config.theme.screens['lg'] || '1024px',
402+
'xl': config.theme.screens['xl'] || '1280px',
403+
'2xl': config.theme.screens['2xl'] || '1536px',
404+
'full': '100%',
405+
'prose': '65ch',
406+
'3xl': '1920px',
407+
}
408+
409+
if (breakpointMap[parsed.value]) {
410+
return {
411+
'width': '100%',
412+
'margin-left': 'auto',
413+
'margin-right': 'auto',
414+
'max-width': breakpointMap[parsed.value],
415+
}
416+
}
417+
418+
// Arbitrary value support: container-[800px]
419+
if (parsed.arbitrary) {
420+
return {
421+
'width': '100%',
422+
'margin-left': 'auto',
423+
'margin-right': 'auto',
424+
'max-width': parsed.value,
425+
}
392426
}
393427
}
394428
}

packages/headwind/src/rules-interactivity.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,16 @@ export const borderCollapseRule: UtilityRule = (parsed) => {
9595

9696
export const borderSpacingRule: UtilityRule = (parsed, config) => {
9797
if (parsed.utility === 'border-spacing' && parsed.value) {
98-
return { 'border-spacing': config.theme.spacing[parsed.value] || parsed.value }
98+
const value = config.theme.spacing[parsed.value] || parsed.value
99+
return { 'border-spacing': `${value} ${value}` }
100+
}
101+
if (parsed.utility === 'border-spacing-x' && parsed.value) {
102+
const value = config.theme.spacing[parsed.value] || parsed.value
103+
return { 'border-spacing': `${value} 0` }
104+
}
105+
if (parsed.utility === 'border-spacing-y' && parsed.value) {
106+
const value = config.theme.spacing[parsed.value] || parsed.value
107+
return { 'border-spacing': `0 ${value}` }
99108
}
100109
}
101110

packages/headwind/src/rules-layout.ts

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,58 @@ export const aspectRatioRule: UtilityRule = (parsed) => {
1414
}
1515

1616
export const columnsRule: UtilityRule = (parsed, config) => {
17-
if (parsed.utility === 'columns') {
18-
return parsed.value ? { columns: config.theme.spacing[parsed.value] || parsed.value } : undefined
17+
if (parsed.utility === 'columns' && parsed.value) {
18+
// Named column counts
19+
const columnCounts: Record<string, string> = {
20+
'1': '1',
21+
'2': '2',
22+
'3': '3',
23+
'4': '4',
24+
'5': '5',
25+
'6': '6',
26+
'7': '7',
27+
'8': '8',
28+
'9': '9',
29+
'10': '10',
30+
'11': '11',
31+
'12': '12',
32+
'auto': 'auto',
33+
}
34+
35+
// Named column widths (like Tailwind)
36+
const columnWidths: Record<string, string> = {
37+
'3xs': '16rem',
38+
'2xs': '18rem',
39+
'xs': '20rem',
40+
'sm': '24rem',
41+
'md': '28rem',
42+
'lg': '32rem',
43+
'xl': '36rem',
44+
'2xl': '42rem',
45+
'3xl': '48rem',
46+
'4xl': '56rem',
47+
'5xl': '64rem',
48+
'6xl': '72rem',
49+
'7xl': '80rem',
50+
}
51+
52+
// Check column counts first
53+
if (columnCounts[parsed.value]) {
54+
return { columns: columnCounts[parsed.value] }
55+
}
56+
57+
// Check named widths
58+
if (columnWidths[parsed.value]) {
59+
return { columns: columnWidths[parsed.value] }
60+
}
61+
62+
// Check spacing config
63+
if (config.theme.spacing[parsed.value]) {
64+
return { columns: config.theme.spacing[parsed.value] }
65+
}
66+
67+
// Arbitrary value support
68+
return { columns: parsed.value }
1969
}
2070
}
2171

packages/headwind/src/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ export interface Theme {
8989
screens: Record<string, string>
9090
borderRadius: Record<string, string>
9191
boxShadow: Record<string, string>
92+
/** Extend theme values without replacing defaults */
93+
extend?: Partial<Omit<Theme, 'extend'>>
9294
}
9395

9496
export interface VariantConfig {

0 commit comments

Comments
 (0)