Skip to content

Commit 837a645

Browse files
committed
Fix types
1 parent 7f53b0a commit 837a645

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

src/index.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
// @ts-expect-error No types available
12
import withAlphaVariable from 'tailwindcss/lib/util/withAlphaVariable';
3+
// @ts-expect-error No types available
24
import flattenColorPalette from 'tailwindcss/lib/util/flattenColorPalette';
3-
import toColorValue from 'tailwindcss/lib/util/toColorValue';
45
import plugin from 'tailwindcss/plugin';
56
import Color from 'colorjs.io';
67
import utilities from './utilities';
@@ -36,6 +37,7 @@ export default plugin.withOptions<TailwindOklchOptions>(
3637
minContrastLightness = 0,
3738
maxContrastLightness = 1,
3839
} = {}) => {
40+
// @ts-expect-error https://github.com/tailwindlabs/tailwindcss/issues/10514
3941
return ({ matchUtilities, theme, corePlugins, addDefaults }) => {
4042
addDefaults('infinity', {
4143
'--tw-infinite': '99999',
@@ -58,16 +60,18 @@ export default plugin.withOptions<TailwindOklchOptions>(
5860
// Round numbers and turn NaN into 0.
5961
// NaN occurs for the hue gray colors, that also have a chroma of 0,
6062
// 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+$/, '');
6568
};
6669

6770
matchUtilities(
6871
{
69-
[key]: (value) => {
70-
const colorValue = toColorValue(value);
72+
[key]: (value: string | (({}) => string)) => {
73+
const colorValue =
74+
typeof value === 'function' ? value({}) : value;
7175
let color;
7276
try {
7377
color = new Color(colorValue);

0 commit comments

Comments
 (0)