From fe2a1be19419dbc02b195ecd5dac394fc6312956 Mon Sep 17 00:00:00 2001 From: ShareVB Date: Sun, 5 Jul 2026 13:51:22 +0200 Subject: [PATCH] feat(Color Converter): add oklab/oklch and lab as CSS Fix #1798 --- locales/en.yml | 2 ++ package.json | 1 + pnpm-lock.yaml | 8 +++++++ src/tools/color-converter/color-converter.vue | 21 ++++++++++++++++--- 4 files changed, 29 insertions(+), 3 deletions(-) diff --git a/locales/en.yml b/locales/en.yml index fa16ac63..ce1ddf52 100644 --- a/locales/en.yml +++ b/locales/en.yml @@ -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. diff --git a/package.json b/package.json index a24d17cd..765063f6 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 05f4a754..d62fbb7c 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -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 diff --git a/src/tools/color-converter/color-converter.vue b/src/tools/color-converter/color-converter.vue index a6294b77..51f36fc2 100644 --- a/src/tools/color-converter/color-converter.vue +++ b/src/tools/color-converter/color-converter.vue @@ -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',