Skip to content

Commit

Permalink
added oklab colour utilities
Browse files Browse the repository at this point in the history
  • Loading branch information
floatingdino committed Oct 12, 2023
1 parent 608de00 commit f045b13
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/oklab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const oklabPlugin = plugin(function addOkLab({ matchUtilities, addVariant }) {
"@supports (background-image: linear-gradient(in oklab, #fff, #fff))"
)
addVariant("supports-oklab", "@supports (color: oklab(0 0 0))")

matchUtilities(
{
"bg-gradient-oklab-to": (value) => ({
Expand All @@ -35,6 +36,33 @@ const oklabPlugin = plugin(function addOkLab({ matchUtilities, addVariant }) {
},
}
)

matchUtilities({
"from-oklab": (value) => ({
"--tw-gradient-from": `oklab(${value}) var(--tw-gradient-from-position)`,
}),
"via-oklab": (value) => ({
"--tw-gradient-stops": `var(--tw-gradient-from), oklab(${value}) var(--tw-gradient-via-position), var(--tw-gradient-to)`,
}),
"to-oklab": (value) => ({
"--tw-gradient-to": `oklab(${value}) var(--tw-gradient-to-position)`,
}),
})

matchUtilities({
"text-oklab": (value) => {
return {
"--tw-text-opacity": "1",
color: `oklab(${value} / --tw-text-opacity)`,
}
},
"bg-oklab": (value) => {
return {
"--tw-bg-opacity": "1",
backgroundColor: `oklab(${value} / var(--tw-bg-opacity))`,
}
},
})
})

export default oklabPlugin

0 comments on commit f045b13

Please sign in to comment.