Skip to content

Commit

Permalink
feat(preset-mini): support font-stretch rules (#3565)
Browse files Browse the repository at this point in the history
Co-authored-by: Anthony Fu <github@antfu.me>
  • Loading branch information
zyyv and antfu committed Mar 14, 2024
1 parent 2ac413e commit ad1bd4b
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 1 deletion.
16 changes: 16 additions & 0 deletions packages/preset-mini/src/_rules/typography.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,22 @@ export const fonts: Rule<Theme>[] = [
{ autocomplete: 'word-spacing-$wordSpacing' },
],

// stretch
['font-stretch-normal', { 'font-stretch': 'normal' }],
['font-stretch-ultra-condensed', { 'font-stretch': 'ultra-condensed' }],
['font-stretch-extra-condensed', { 'font-stretch': 'extra-condensed' }],
['font-stretch-condensed', { 'font-stretch': 'condensed' }],
['font-stretch-semi-condensed', { 'font-stretch': 'semi-condensed' }],
['font-stretch-semi-expanded', { 'font-stretch': 'semi-expanded' }],
['font-stretch-expanded', { 'font-stretch': 'expanded' }],
['font-stretch-extra-expanded', { 'font-stretch': 'extra-expanded' }],
['font-stretch-ultra-expanded', { 'font-stretch': 'ultra-expanded' }],
[
/^font-stretch-(.+)$/,
([, s]) => ({ 'font-stretch': h.bracket.cssvar.fraction.global(s) }),
{ autocomplete: 'font-stretch-<percentage>' },
],

// family
[
/^font-(.+)$/,
Expand Down
2 changes: 2 additions & 0 deletions playground/src/auto-imports.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,7 @@ declare global {
// for vue template auto import
import { UnwrapRef } from 'vue'
declare module 'vue' {
interface GlobalComponents {}
interface ComponentCustomProperties {
readonly EffectScope: UnwrapRef<typeof import('vue')['EffectScope']>
readonly STORAGE_KEY: UnwrapRef<typeof import('./composables/constants')['STORAGE_KEY']>
Expand Down Expand Up @@ -679,6 +680,7 @@ declare module 'vue' {
}
}
declare module '@vue/runtime-core' {
interface GlobalComponents {}
interface ComponentCustomProperties {
readonly EffectScope: UnwrapRef<typeof import('vue')['EffectScope']>
readonly STORAGE_KEY: UnwrapRef<typeof import('./composables/constants')['STORAGE_KEY']>
Expand Down
3 changes: 3 additions & 0 deletions test/assets/output/preset-mini-targets.css
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,9 @@ unocss .scope-\[unocss\]\:block{display:block;}
.word-spacing-2{word-spacing:0.5rem;}
.word-spacing-inherit{word-spacing:inherit;}
.word-spacing-wide{word-spacing:0.025em;}
.font-stretch-normal{font-stretch:normal;}
.font-stretch-\[ultra-expanded\]{font-stretch:ultra-expanded;}
.font-stretch-1\/2{font-stretch:50%;}
.font-\[\"custom_fontFamily_name\"\]{font-family:"custom fontFamily name";}
.font-\[system-ui\]{font-family:system-ui;}
.font-\$font-name{font-family:var(--font-name);}
Expand Down
3 changes: 3 additions & 0 deletions test/assets/preset-mini-targets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -879,6 +879,9 @@ export const presetMiniTargets: string[] = [
'tracking-[2/5]',
'tracking-inherit',
'font-tracking-1em',
'font-stretch-normal',
'font-stretch-[ultra-expanded]',
'font-stretch-1/2',
'word-spacing-1',
'word-spacing-wide',
'word-spacing-2',
Expand Down
1 change: 0 additions & 1 deletion test/autocomplete.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ describe('autocomplete', () => {
'filter-',
'fle',
'font-',
'font-',
'grow-',
'keyframes-',
'leading-',
Expand Down

0 comments on commit ad1bd4b

Please sign in to comment.