feat(Color Converter): add oklab/oklch and lab as CSS

Fix #1798
This commit is contained in:
ShareVB committed 2026-07-05 13:51:22 +02:00
1 parent 2a4fcc6e4d
commit fe2a1be194
4 files changed
+29 -3

No files matched your search

+2
View File
@@ -5212,6 +5212,8 @@ tools:
label-brightness: Brightness
label-grayscale: Grayscale
label-invert: Invert
label-oklab: oklab
label-oklch: oklch
models:
text:
invalid-label-tolowercase-format: Invalid {0} format.
+1
View File
@@ -44,6 +44,7 @@
"dependencies": {
"@boxyhq/saml20": "^1.16.0",
"@chenfengyuan/vue-barcode": "^2.0.2",
"@colordx/core": "^5.5.0",
"@date-fns/utc": "^2.1.1",
"@dice-roller/rpg-dice-roller": "^5.5.1",
"@faker-js/faker": "^10.2.0",
+8
View File
@@ -29,6 +29,9 @@ importers:
'@chenfengyuan/vue-barcode':
specifier: ^2.0.2
version: 2.0.2(jsbarcode@3.12.1)(vue@3.3.4)
'@colordx/core':
specifier: ^5.5.0
version: 5.5.0
'@date-fns/utc':
specifier: ^2.1.1
version: 2.1.1
@@ -2299,6 +2302,9 @@ packages:
'@codemod/utils@1.1.0':
resolution: {integrity: sha512-Zx6A4xDifEqL0s9ejh62/mQmDXje+E62zYHGiGfRHzVhzmA41pDFZW/m7Hl9+fmbODJxlg9ElMsjHdhasSm7TA==}
'@colordx/core@5.5.0':
resolution: {integrity: sha512-3PxTH8itZzltK0U9jTwVVnjLXvnDYuq3m+QXsHkENxWiPRh4WaoLcs1SQjqgZ55kS+QyirpH5BVwzP2gMVG6EQ==}
'@css-render/plugin-bem@0.15.14':
resolution: {integrity: sha512-QK513CJ7yEQxm/P3EwsI+d+ha8kSOcjGvD6SevM41neEMxdULE+18iuQK6tEChAWMOQNQPLG/Rw3Khb69r5neg==}
peerDependencies:
@@ -13612,6 +13618,8 @@ snapshots:
transitivePeerDependencies:
- supports-color
'@colordx/core@5.5.0': {}
'@css-render/plugin-bem@0.15.14(css-render@0.15.14)':
dependencies:
css-render: 0.15.14
+18 -3
View File
@@ -2,6 +2,8 @@
import { useI18n } from 'vue-i18n';
import type { Colord } from 'colord';
import { colord, extend } from 'colord';
import { colordx, extend as extendx } from '@colordx/core';
import xlabPlugin from '@colordx/core/plugins/lab';
import _ from 'lodash';
import cmykPlugin from 'colord/plugins/cmyk';
import hwbPlugin from 'colord/plugins/hwb';
@@ -13,6 +15,7 @@ import { buildColorFormat } from './color-converter.models';
const { t } = useI18n();
extendx([xlabPlugin]);
extend([cmykPlugin, hwbPlugin, namesPlugin, lchPlugin, xyzPlugin, labPlugin]);
const formats = {
@@ -53,9 +56,9 @@ const formats = {
}),
lab: buildColorFormat({
label: t('tools.color-converter.texts.label-lab'),
format: (v: Colord) => JSON.stringify(v.toLab()),
placeholder: 'e.g. { l: 14.89, a: 5.77, b: 14.41, alpha: 0.5 }',
parse: value => colord(JSON.parse(value)),
format: (v: Colord) => colordx(v.toHex()).toLabString(),
placeholder: 'e.g. lab(54.29 80.8 69.89)',
parse: value => colord(colordx(value).toHex()),
}),
xyz: buildColorFormat({
label: t('tools.color-converter.texts.label-xyz'),
@@ -63,6 +66,18 @@ const formats = {
placeholder: 'e.g. { x: 95.047, y: 100, z: 108.883, a: 1 }',
parse: value => colord(JSON.parse(value)),
}),
oklab: buildColorFormat({
label: t('tools.color-converter.texts.label-oklab'),
format: (v: Colord) => colordx(v.toHex()).toOklabString(),
placeholder: 'e.g. oklab(40.1% 0.1143 0.045)',
parse: value => colord(colordx(value).toHex()),
}),
oklch: buildColorFormat({
label: t('tools.color-converter.texts.label-oklch'),
format: (v: Colord) => colordx(v.toHex()).toOklchString(),
placeholder: 'e.g. oklch(40.1% 0.123 21.57)',
parse: value => colord(colordx(value).toHex()),
}),
name: buildColorFormat({
label: t('tools.color-converter.texts.label-name'),
format: (v: Colord) => v.toName({ closest: true }) ?? 'Unknown',