Compare commits

...
Sign in to create a new pull request.

6 commits

Author SHA1 Message Date
Jordan Pittman
7eaa7a1e79 Update intellisense snapshot 2025-12-02 13:17:49 -05:00
Jordan Pittman
e4948ed09b Suggest spacing scale values for text-* modifiers 2025-12-02 13:16:05 -05:00
Jordan Pittman
afc92049e4 Add tests 2025-12-02 13:15:46 -05:00
Jordan Pittman
66be2a6bb5 Support bare spacing scale values for font-size 2025-12-02 13:14:47 -05:00
Jordan Pittman
d573991871 Read from --spacing namespace for font sizes 2025-12-02 13:14:47 -05:00
Jordan Pittman
939b319acd Read from --spacing namespace for line height modifiers 2025-12-02 13:14:43 -05:00
4 changed files with 1320 additions and 7 deletions

View file

@ -243,7 +243,7 @@ export class Theme {
}
resolveWith(
candidateValue: string,
candidateValue: string | null,
themeKeys: ThemeKey[],
nestedKeys: `--${string}`[] = [],
): [string, Record<string, string>] | null {

View file

@ -24173,6 +24173,7 @@ test('text', async () => {
css`
@theme {
--spacing: 0.25rem;
--spacing-superbig: 25rem;
--color-red-500: #ef4444;
--text-color-blue-500: #3b82f6;
--text-sm: 0.875rem;
@ -24233,11 +24234,27 @@ test('text', async () => {
'text-[clamp(1rem,2rem,3rem)]',
'text-[clamp(1rem,var(--size),3rem)]',
'text-[clamp(1rem,var(--size),3rem)]/9',
// font-size / line-height / letter-spacing / font-weight
'text-20',
'text-20/6',
'text-20/none',
'text-20/snug',
'text-20/superbig',
'text-20/[4px]',
'text-superbig',
'text-superbig/6',
'text-superbig/none',
'text-superbig/snug',
'text-superbig/superbig',
'text-superbig/[4px]',
],
),
).toMatchInlineSnapshot(`
":root, :host {
--spacing: .25rem;
--spacing-superbig: 25rem;
--color-red-500: #ef4444;
--text-color-blue-500: #3b82f6;
--text-sm: .875rem;
@ -24245,6 +24262,31 @@ test('text', async () => {
--leading-snug: 1.375;
}
.text-20\\/6 {
font-size: calc(var(--spacing) * 20);
line-height: calc(var(--spacing) * 6);
}
.text-20\\/\\[4px\\] {
font-size: calc(var(--spacing) * 20);
line-height: 4px;
}
.text-20\\/none {
font-size: calc(var(--spacing) * 20);
line-height: 1;
}
.text-20\\/snug {
font-size: calc(var(--spacing) * 20);
line-height: var(--leading-snug);
}
.text-20\\/superbig {
font-size: calc(var(--spacing) * 20);
line-height: var(--spacing-superbig);
}
.text-\\[10px\\]\\/none {
font-size: 10px;
line-height: 1;
@ -24300,6 +24342,35 @@ test('text', async () => {
line-height: var(--leading-snug);
}
.text-superbig\\/6 {
font-size: var(--spacing-superbig);
line-height: calc(var(--spacing) * 6);
}
.text-superbig\\/\\[4px\\] {
font-size: var(--spacing-superbig);
line-height: 4px;
}
.text-superbig\\/none {
font-size: var(--spacing-superbig);
line-height: 1;
}
.text-superbig\\/snug {
font-size: var(--spacing-superbig);
line-height: var(--leading-snug);
}
.text-superbig\\/superbig {
font-size: var(--spacing-superbig);
line-height: var(--spacing-superbig);
}
.text-20 {
font-size: calc(var(--spacing) * 20);
}
.text-\\[12px\\] {
font-size: 12px;
}
@ -24332,6 +24403,10 @@ test('text', async () => {
font-size: xx-large;
}
.text-superbig {
font-size: var(--spacing-superbig);
}
.text-\\[\\#0088cc\\] {
color: #08c;
}

View file

@ -5092,9 +5092,23 @@ export function createUtilities(theme: Theme) {
{
let value = theme.resolveWith(
candidate.value.value,
['--text'],
['--text', '--spacing'],
['--line-height', '--letter-spacing', '--font-weight'],
)
// Bare values use the spacing scale
if (!value) {
let multiplier = theme.resolveWith(
null,
['--spacing'],
['--line-height', '--letter-spacing', '--font-weight'],
)
if (!multiplier) return
if (!isValidSpacingMultiplier(candidate.value.value)) return
value = [`calc(${multiplier[0]} * ${candidate.value.value})`, multiplier[1]]
}
if (value) {
let [fontSize, options = {}] = Array.isArray(value) ? value : [value]
@ -5102,7 +5116,7 @@ export function createUtilities(theme: Theme) {
let modifier =
candidate.modifier.kind === 'arbitrary'
? candidate.modifier.value
: theme.resolve(candidate.modifier.value, ['--leading'])
: theme.resolve(candidate.modifier.value, ['--leading', '--spacing'])
if (!modifier && isValidSpacingMultiplier(candidate.modifier.value)) {
let multiplier = theme.resolve(null, ['--spacing'])
@ -5158,10 +5172,10 @@ export function createUtilities(theme: Theme) {
modifiers: Array.from({ length: 21 }, (_, index) => `${index * 5}`),
},
{
values: [],
valueThemeKeys: ['--text'],
modifiers: [],
modifierThemeKeys: ['--leading'],
values: theme.get(['--spacing']) ? DEFAULT_SPACING_SUGGESTIONS : [],
valueThemeKeys: ['--text', '--spacing'],
modifiers: theme.get(['--spacing']) ? DEFAULT_SPACING_SUGGESTIONS : [],
modifierThemeKeys: ['--leading', '--spacing'],
},
])