Skip to content

Commit

Permalink
feat: Font Variant Numeric
Browse files Browse the repository at this point in the history
  • Loading branch information
sastan committed Dec 9, 2020
1 parent 1817e7d commit 809cbf1
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 20 deletions.
1 change: 0 additions & 1 deletion examples/svelte/README.md
@@ -1,7 +1,6 @@
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->


- [New Project](#new-project)
- [Available Scripts](#available-scripts)

Expand Down
16 changes: 15 additions & 1 deletion packages/core/src/__tests__/api.json
Expand Up @@ -683,5 +683,19 @@
"@media (min-width: 768px){@media (min-width: 1280px){.md\\:container{max-width:1280px}}}",
"@media (min-width: 768px){@media (min-width: 1536px){.md\\:container{max-width:1536px}}}"
]
]
],
"ordinal slashed-zero tabular-nums md:normal-nums": [
"ordinal slashed-zero tabular-nums md:normal-nums",
[
".slashed-zero{--tw-slashed-zero:slashed-zero;font-variant-numeric:var(--tw-ordinal,/*!*/ /*!*/) var(--tw-slashed-zero,/*!*/ /*!*/) var(--tw-numeric-figure,/*!*/ /*!*/) var(--tw-numeric-spacing,/*!*/ /*!*/) var(--tw-numeric-fraction,/*!*/ /*!*/)}",
".tabular-nums{--tw-numeric-spacing:tabular-nums;font-variant-numeric:var(--tw-ordinal,/*!*/ /*!*/) var(--tw-slashed-zero,/*!*/ /*!*/) var(--tw-numeric-figure,/*!*/ /*!*/) var(--tw-numeric-spacing,/*!*/ /*!*/) var(--tw-numeric-fraction,/*!*/ /*!*/)}",
".ordinal{--tw-ordinal:ordinal;font-variant-numeric:var(--tw-ordinal,/*!*/ /*!*/) var(--tw-slashed-zero,/*!*/ /*!*/) var(--tw-numeric-figure,/*!*/ /*!*/) var(--tw-numeric-spacing,/*!*/ /*!*/) var(--tw-numeric-fraction,/*!*/ /*!*/)}",
"@media (min-width: 768px){.md\\:normal-nums{font-variant-numeric:normal}}"
]
],
"lining-nums": ".lining-nums{--tw-numeric-figure:lining-nums;font-variant-numeric:var(--tw-ordinal,/*!*/ /*!*/) var(--tw-slashed-zero,/*!*/ /*!*/) var(--tw-numeric-figure,/*!*/ /*!*/) var(--tw-numeric-spacing,/*!*/ /*!*/) var(--tw-numeric-fraction,/*!*/ /*!*/)}",
"oldstyle-nums": ".oldstyle-nums{--tw-numeric-figure:oldstyle-nums;font-variant-numeric:var(--tw-ordinal,/*!*/ /*!*/) var(--tw-slashed-zero,/*!*/ /*!*/) var(--tw-numeric-figure,/*!*/ /*!*/) var(--tw-numeric-spacing,/*!*/ /*!*/) var(--tw-numeric-fraction,/*!*/ /*!*/)}",
"proportional-nums": ".proportional-nums{--tw-numeric-spacing:proportional-nums;font-variant-numeric:var(--tw-ordinal,/*!*/ /*!*/) var(--tw-slashed-zero,/*!*/ /*!*/) var(--tw-numeric-figure,/*!*/ /*!*/) var(--tw-numeric-spacing,/*!*/ /*!*/) var(--tw-numeric-fraction,/*!*/ /*!*/)}",
"diagonal-fractions": ".diagonal-fractions{--tw-numeric-fraction:diagonal-fractions;font-variant-numeric:var(--tw-ordinal,/*!*/ /*!*/) var(--tw-slashed-zero,/*!*/ /*!*/) var(--tw-numeric-figure,/*!*/ /*!*/) var(--tw-numeric-spacing,/*!*/ /*!*/) var(--tw-numeric-fraction,/*!*/ /*!*/)}",
"stacked-fractions": ".stacked-fractions{--tw-numeric-fraction:stacked-fractions;font-variant-numeric:var(--tw-ordinal,/*!*/ /*!*/) var(--tw-slashed-zero,/*!*/ /*!*/) var(--tw-numeric-figure,/*!*/ /*!*/) var(--tw-numeric-spacing,/*!*/ /*!*/) var(--tw-numeric-fraction,/*!*/ /*!*/)}"
}
17 changes: 2 additions & 15 deletions packages/core/src/__tests__/tailwind-compat.test.ts
Expand Up @@ -11,21 +11,8 @@ test('all tailwind directives are available', async () => {
try {
expect(tw(directive)).toBeTruthy()
} catch (error) {
if (isFontVariantNumeric(directive)) {
// TODO https://tailwindcss.com/docs/font-variant-numeric
} else {
console.warn(directive, directives[directive])
throw error
}
console.warn(directive, directives[directive])
throw error
}
}
})

function isFontVariantNumeric(directive: string): boolean {
return (
directive === 'ordinal' ||
directive.endsWith('-zero') ||
directive.endsWith('-nums') ||
directive.endsWith('-fractions')
)
}
4 changes: 1 addition & 3 deletions packages/core/src/internal/presedence.ts
Expand Up @@ -143,9 +143,7 @@ const propertyPrecedence = (property: string): number => {
_ = PROPERTY_PRECEDENCE_CORRECTION_GROUPS.exec(unprefixedProperty)

return (
seperatorPrecedence(unprefixedProperty) +
(_ ? +!!_[1] /* +1 */ || -!!_[2] /* -1 */ : 0) +
1
seperatorPrecedence(unprefixedProperty) + (_ ? +!!_[1] /* +1 */ || -!!_[2] /* -1 */ : 0) + 1
)
}

Expand Down
16 changes: 16 additions & 0 deletions packages/core/src/tailwind/plugins.ts
Expand Up @@ -49,6 +49,12 @@ const position = property('position')
const textTransform = property('textTransform')
const textDecoration = property('textDecoration')
const fontStyle = property('fontStyle')
const fontVariantNumeric = (key: string): DirectiveHandler => (params, context, id) => ({
['--tw-' + key]: id,
fontVariantNumeric:
'var(--tw-ordinal,/*!*/ /*!*/) var(--tw-slashed-zero,/*!*/ /*!*/) var(--tw-numeric-figure,/*!*/ /*!*/) var(--tw-numeric-spacing,/*!*/ /*!*/) var(--tw-numeric-fraction,/*!*/ /*!*/)',
})

const inset: DirectiveHandler = (params, { theme }, id) => ({ [id]: theme('inset', params) })

const opacityProperty = (
Expand Down Expand Up @@ -517,6 +523,16 @@ export const corePlugins: Plugins = {

whitespace: propertyValue('whiteSpace'),

'normal-nums': { fontVariantNumeric: 'normal' },
ordinal: fontVariantNumeric('ordinal'),
'slashed-zero': fontVariantNumeric('slashed-zero'),
'lining-nums': fontVariantNumeric('numeric-figure'),
'oldstyle-nums': fontVariantNumeric('numeric-figure'),
'proportional-nums': fontVariantNumeric('numeric-spacing'),
'tabular-nums': fontVariantNumeric('numeric-spacing'),
'diagonal-fractions': fontVariantNumeric('numeric-fraction'),
'stacked-fractions': fontVariantNumeric('numeric-fraction'),

// 'overflow-visible'
// 'overflow-x-hidden'
overflow: (params) =>
Expand Down

0 comments on commit 809cbf1

Please sign in to comment.