1
+ // @ts -expect-error No types available
1
2
import withAlphaVariable from 'tailwindcss/lib/util/withAlphaVariable' ;
3
+ // @ts -expect-error No types available
2
4
import flattenColorPalette from 'tailwindcss/lib/util/flattenColorPalette' ;
3
- import toColorValue from 'tailwindcss/lib/util/toColorValue' ;
4
5
import plugin from 'tailwindcss/plugin' ;
5
6
import Color from 'colorjs.io' ;
6
7
import utilities from './utilities' ;
@@ -36,6 +37,7 @@ export default plugin.withOptions<TailwindOklchOptions>(
36
37
minContrastLightness = 0 ,
37
38
maxContrastLightness = 1 ,
38
39
} = { } ) => {
40
+ // @ts -expect-error https://github.com/tailwindlabs/tailwindcss/issues/10514
39
41
return ( { matchUtilities, theme, corePlugins, addDefaults } ) => {
40
42
addDefaults ( 'infinity' , {
41
43
'--tw-infinite' : '99999' ,
@@ -58,16 +60,18 @@ export default plugin.withOptions<TailwindOklchOptions>(
58
60
// Round numbers and turn NaN into 0.
59
61
// NaN occurs for the hue gray colors, that also have a chroma of 0,
60
62
// so we can safely set the hue to 0 instead of NaN.
61
- const round = ( value : number | null ) => {
62
- return (
63
- ( value || 0 ) . toFixed ?.( precision ) . replace ( / \. ? 0 + $ / , '' ) || value
64
- ) ;
63
+ const round = ( value : undefined | string | number ) => {
64
+ if ( value === undefined || typeof value === 'string' ) {
65
+ return value ;
66
+ }
67
+ return value . toFixed ( precision ) . replace ( / \. ? 0 + $ / , '' ) ;
65
68
} ;
66
69
67
70
matchUtilities (
68
71
{
69
- [ key ] : ( value ) => {
70
- const colorValue = toColorValue ( value ) ;
72
+ [ key ] : ( value : string | ( ( { } ) => string ) ) => {
73
+ const colorValue =
74
+ typeof value === 'function' ? value ( { } ) : value ;
71
75
let color ;
72
76
try {
73
77
color = new Color ( colorValue ) ;
0 commit comments