From 31769ce1b1873e5e584bfdb68f2c71ff6460ad96 Mon Sep 17 00:00:00 2001 From: Romain Menke <11521496+romainmenke@users.noreply.github.com> Date: Sat, 10 Aug 2024 14:57:33 +0200 Subject: [PATCH] out of gamut `hwb` (#1452) --- package-lock.json | 60 +---- packages/color-helpers/CHANGELOG.md | 4 + packages/color-helpers/dist/index.cjs | 230 +++++++++--------- packages/color-helpers/dist/index.mjs | 222 ++++++++--------- .../color-helpers/scripts/check-changes.mjs | 1 + packages/color-helpers/scripts/hashes.json | 5 +- .../src/conversions/srgb-to-hue.ts | 28 +++ .../src/conversions/xyz/index.ts | 70 +++--- packages/css-color-parser/package.json | 2 +- packages/css-color-parser/test/basic/hwb.mjs | 12 +- .../css-color-parser/test/util/serialize.mjs | 8 +- .../package.json | 2 +- .../package.json | 2 +- 13 files changed, 318 insertions(+), 328 deletions(-) create mode 100644 packages/color-helpers/src/conversions/srgb-to-hue.ts diff --git a/package-lock.json b/package-lock.json index 5f3f35bcd..e43dd41da 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9459,7 +9459,7 @@ ], "license": "MIT", "dependencies": { - "@csstools/color-helpers": "^4.2.1", + "@csstools/color-helpers": "^5.0.0", "@csstools/css-calc": "^2.0.0" }, "engines": { @@ -9470,24 +9470,6 @@ "@csstools/css-tokenizer": "^3.0.0" } }, - "packages/css-color-parser/node_modules/@csstools/color-helpers": { - "version": "4.2.1", - "resolved": "https://registry.npmjs.org/@csstools/color-helpers/-/color-helpers-4.2.1.tgz", - "integrity": "sha512-CEypeeykO9AN7JWkr1OEOQb0HRzZlPWGwV0Ya6DuVgFdDi6g3ma/cPZ5ZPZM4AWQikDpq/0llnGGlIL+j8afzw==", - "funding": [ - { - "type": "github", - "url": "https://github.com/sponsors/csstools" - }, - { - "type": "opencollective", - "url": "https://opencollective.com/csstools" - } - ], - "engines": { - "node": "^14 || ^16 || >=18" - } - }, "packages/css-parser-algorithms": { "name": "@csstools/css-parser-algorithms", "version": "3.0.0", @@ -10602,7 +10584,7 @@ ], "license": "MIT-0", "dependencies": { - "@csstools/color-helpers": "^4.2.1", + "@csstools/color-helpers": "^5.0.0", "@csstools/css-color-parser": "^3.0.0", "@csstools/css-parser-algorithms": "^3.0.0", "@csstools/css-tokenizer": "^3.0.0", @@ -10619,24 +10601,6 @@ "postcss": "^8.4" } }, - "plugins/postcss-contrast-color-function/node_modules/@csstools/color-helpers": { - "version": "4.2.1", - "resolved": "https://registry.npmjs.org/@csstools/color-helpers/-/color-helpers-4.2.1.tgz", - "integrity": "sha512-CEypeeykO9AN7JWkr1OEOQb0HRzZlPWGwV0Ya6DuVgFdDi6g3ma/cPZ5ZPZM4AWQikDpq/0llnGGlIL+j8afzw==", - "funding": [ - { - "type": "github", - "url": "https://github.com/sponsors/csstools" - }, - { - "type": "opencollective", - "url": "https://opencollective.com/csstools" - } - ], - "engines": { - "node": "^14 || ^16 || >=18" - } - }, "plugins/postcss-custom-media": { "version": "11.0.0", "funding": [ @@ -12250,7 +12214,7 @@ ], "license": "MIT-0", "dependencies": { - "@csstools/color-helpers": "^4.2.1", + "@csstools/color-helpers": "^5.0.0", "postcss-value-parser": "^4.2.0" }, "devDependencies": { @@ -12264,24 +12228,6 @@ "postcss": "^8.4" } }, - "plugins/postcss-text-decoration-shorthand/node_modules/@csstools/color-helpers": { - "version": "4.2.1", - "resolved": "https://registry.npmjs.org/@csstools/color-helpers/-/color-helpers-4.2.1.tgz", - "integrity": "sha512-CEypeeykO9AN7JWkr1OEOQb0HRzZlPWGwV0Ya6DuVgFdDi6g3ma/cPZ5ZPZM4AWQikDpq/0llnGGlIL+j8afzw==", - "funding": [ - { - "type": "github", - "url": "https://github.com/sponsors/csstools" - }, - { - "type": "opencollective", - "url": "https://opencollective.com/csstools" - } - ], - "engines": { - "node": "^14 || ^16 || >=18" - } - }, "plugins/postcss-todo-or-die": { "name": "@csstools/postcss-todo-or-die", "version": "3.0.0", diff --git a/packages/color-helpers/CHANGELOG.md b/packages/color-helpers/CHANGELOG.md index 2d6822d22..51c3eca10 100644 --- a/packages/color-helpers/CHANGELOG.md +++ b/packages/color-helpers/CHANGELOG.md @@ -1,5 +1,9 @@ # Changes to Color Helpers +### Unreleased (patch) + +- fix `XYZ_D50_to_HWB` to not do corrections for out of gamut colors. + ### 5.0.0 _August 3, 2024_ diff --git a/packages/color-helpers/dist/index.cjs b/packages/color-helpers/dist/index.cjs index 77709e145..f607a60fb 100644 --- a/packages/color-helpers/dist/index.cjs +++ b/packages/color-helpers/dist/index.cjs @@ -1,10 +1,16 @@ -"use strict";function multiplyMatrices(t,n){return[t[0]*n[0]+t[1]*n[1]+t[2]*n[2],t[3]*n[0]+t[4]*n[1]+t[5]*n[2],t[6]*n[0]+t[7]*n[1]+t[8]*n[2]]}const t=[1.0479297925449969,.022946870601609652,-.05019226628920524,.02962780877005599,.9904344267538799,-.017073799063418826,-.009243040646204504,.015055191490298152,.7518742814281371]; +"use strict";function multiplyMatrices(t,n){return[t[0]*n[0]+t[1]*n[1]+t[2]*n[2],t[3]*n[0]+t[4]*n[1]+t[5]*n[2],t[6]*n[0]+t[7]*n[1]+t[8]*n[2]]}const t=[.955473421488075,-.02309845494876471,.06325924320057072,-.0283697093338637,1.0099953980813041,.021041441191917323,.012314014864481998,-.020507649298898964,1.330365926242124]; +/** + * Bradford chromatic adaptation from D50 to D65 + * + * @license W3C https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document + * @copyright This software or document includes material copied from or derived from https://github.com/w3c/csswg-drafts/blob/main/css-color-4/conversions.js. Copyright © 2022 W3C® (MIT, ERCIM, Keio, Beihang). + */function D50_to_D65(n){return multiplyMatrices(t,n)}const n=[1.0479297925449969,.022946870601609652,-.05019226628920524,.02962780877005599,.9904344267538799,-.017073799063418826,-.009243040646204504,.015055191490298152,.7518742814281371]; /** * Bradford chromatic adaptation from D65 to D50 * @license W3C https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document * @copyright This software or document includes material copied from or derived from https://github.com/w3c/csswg-drafts/blob/main/css-color-4/conversions.js. Copyright © 2022 W3C® (MIT, ERCIM, Keio, Beihang). * @see http://www.brucelindbloom.com/index.html?Eqn_ChromAdapt.html - */function D65_to_D50(n){return multiplyMatrices(t,n)} + */function D65_to_D50(t){return multiplyMatrices(n,t)} /** * @param {number} hue - Hue as degrees 0..360 * @param {number} sat - Saturation as percentage 0..100 @@ -28,18 +34,27 @@ /** * @license W3C https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document * @copyright This software or document includes material copied from or derived from https://github.com/w3c/csswg-drafts/blob/main/css-color-4/conversions.js. Copyright © 2022 W3C® (MIT, ERCIM, Keio, Beihang). - */function LCH_to_Lab(t){const n=t[2]*Math.PI/180;return[t[0],t[1]*Math.cos(n),t[1]*Math.sin(n)]}const n=[.3457/.3585,1,.2958/.3585]; + */function LCH_to_Lab(t){const n=t[2]*Math.PI/180;return[t[0],t[1]*Math.cos(n),t[1]*Math.sin(n)]} +/** + * @license W3C https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document + * @copyright This software or document includes material copied from or derived from https://github.com/w3c/csswg-drafts/blob/main/css-color-4/conversions.js. Copyright © 2022 W3C® (MIT, ERCIM, Keio, Beihang). + */function Lab_to_LCH(t){const n=180*Math.atan2(t[2],t[1])/Math.PI;return[t[0],Math.sqrt(Math.pow(t[1],2)+Math.pow(t[2],2)),n>=0?n:n+360]}const _=[.3457/.3585,1,.2958/.3585]; /** * Convert Lab to D50-adapted XYZ * @license W3C https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document * @copyright This software or document includes material copied from or derived from https://github.com/w3c/csswg-drafts/blob/main/css-color-4/conversions.js. Copyright © 2022 W3C® (MIT, ERCIM, Keio, Beihang). * @see http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html - */function Lab_to_XYZ(t){const _=24389/27,o=216/24389,e=(t[0]+16)/116,r=t[1]/500+e,a=e-t[2]/200;return[(Math.pow(r,3)>o?Math.pow(r,3):(116*r-16)/_)*n[0],(t[0]>8?Math.pow((t[0]+16)/116,3):t[0]/_)*n[1],(Math.pow(a,3)>o?Math.pow(a,3):(116*a-16)/_)*n[2]]} + */function Lab_to_XYZ(t){const n=24389/27,o=216/24389,e=(t[0]+16)/116,r=t[1]/500+e,a=e-t[2]/200;return[(Math.pow(r,3)>o?Math.pow(r,3):(116*r-16)/n)*_[0],(t[0]>8?Math.pow((t[0]+16)/116,3):t[0]/n)*_[1],(Math.pow(a,3)>o?Math.pow(a,3):(116*a-16)/n)*_[2]]} +/** + * @license W3C https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document + * @copyright This software or document includes material copied from or derived from https://github.com/w3c/csswg-drafts/blob/main/css-color-4/conversions.js. Copyright © 2022 W3C® (MIT, ERCIM, Keio, Beihang). + * @see https://github.com/w3c/csswg-drafts/blob/main/css-color-4/conversions.js + */function OKLCH_to_OKLab(t){const n=t[2]*Math.PI/180;return[t[0],t[1]*Math.cos(n),t[1]*Math.sin(n)]} /** * @license W3C https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document * @copyright This software or document includes material copied from or derived from https://github.com/w3c/csswg-drafts/blob/main/css-color-4/conversions.js. Copyright © 2022 W3C® (MIT, ERCIM, Keio, Beihang). * @see https://github.com/w3c/csswg-drafts/blob/main/css-color-4/conversions.js - */function OKLCH_to_OKLab(t){const n=t[2]*Math.PI/180;return[t[0],t[1]*Math.cos(n),t[1]*Math.sin(n)]}const _=[1.2268798758459243,-.5578149944602171,.2813910456659647,-.0405757452148008,1.112286803280317,-.0717110580655164,-.0763729366746601,-.4214933324022432,1.5869240198367816],o=[1,.3963377773761749,.2158037573099136,1,-.1055613458156586,-.0638541728258133,1,-.0894841775298119,-1.2914855480194092]; + */function OKLab_to_OKLCH(t){const n=180*Math.atan2(t[2],t[1])/Math.PI;return[t[0],Math.sqrt(t[1]**2+t[2]**2),n>=0?n:n+360]}const o=[1.2268798758459243,-.5578149944602171,.2813910456659647,-.0405757452148008,1.112286803280317,-.0717110580655164,-.0763729366746601,-.4214933324022432,1.5869240198367816],e=[1,.3963377773761749,.2158037573099136,1,-.1055613458156586,-.0638541728258133,1,-.0894841775298119,-1.2914855480194092]; /** * Given OKLab, convert to XYZ relative to D65 * @@ -47,7 +62,90 @@ * @copyright This software or document includes material copied from or derived from https://github.com/w3c/csswg-drafts/blob/main/css-color-4/conversions.js. Copyright © 2022 W3C® (MIT, ERCIM, Keio, Beihang). * @see https://github.com/w3c/csswg-drafts/blob/main/css-color-4/conversions.js */ -function OKLab_to_XYZ(t){const n=multiplyMatrices(o,t);return multiplyMatrices(_,[n[0]**3,n[1]**3,n[2]**3])} +function OKLab_to_XYZ(t){const n=multiplyMatrices(e,t);return multiplyMatrices(o,[n[0]**3,n[1]**3,n[2]**3])} +/** + * Assuming XYZ is relative to D50, convert to CIE Lab + * from CIE standard, which now defines these as a rational fraction + * + * @license W3C https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document + * @copyright This software or document includes material copied from or derived from https://github.com/w3c/csswg-drafts/blob/main/css-color-4/conversions.js. Copyright © 2022 W3C® (MIT, ERCIM, Keio, Beihang). + */function XYZ_to_Lab(t){const n=compute_f(t[0]/_[0]),o=compute_f(t[1]/_[1]);return[116*o-16,500*(n-o),200*(o-compute_f(t[2]/_[2]))]}const r=216/24389,a=24389/27;function compute_f(t){return t>r?Math.cbrt(t):(a*t+16)/116}const i=[.819022437996703,.3619062600528904,-.1288737815209879,.0329836539323885,.9292868615863434,.0361446663506424,.0481771893596242,.2642395317527308,.6335478284694309],l=[.210454268309314,.7936177747023054,-.0040720430116193,1.9779985324311684,-2.42859224204858,.450593709617411,.0259040424655478,.7827717124575296,-.8086757549230774]; +/** + * @license W3C https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document + * @copyright This software or document includes material copied from or derived from https://github.com/w3c/csswg-drafts/blob/main/css-color-4/conversions.js. Copyright © 2022 W3C® (MIT, ERCIM, Keio, Beihang). + * + * XYZ <-> LMS matrices recalculated for consistent reference white + * @see https://github.com/w3c/csswg-drafts/issues/6642#issuecomment-943521484 + */ +function XYZ_to_OKLab(t){const n=multiplyMatrices(i,t);return multiplyMatrices(l,[Math.cbrt(n[0]),Math.cbrt(n[1]),Math.cbrt(n[2])])}const s=[30757411/17917100,-6372589/17917100,-4539589/17917100,-.666684351832489,1.616481236634939,467509/29648200,792561/44930125,-1921689/44930125,.942103121235474]; +/** + * Convert XYZ to linear-light rec2020 + * + * @license W3C https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document + * @copyright This software or document includes material copied from or derived from https://github.com/w3c/csswg-drafts/blob/main/css-color-4/conversions.js. Copyright © 2022 W3C® (MIT, ERCIM, Keio, Beihang). + */const c=[446124/178915,-333277/357830,-72051/178915,-14852/17905,63121/35810,423/17905,11844/330415,-50337/660830,316169/330415]; +/** + * Convert XYZ to linear-light P3 + * + * @license W3C https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document + * @copyright This software or document includes material copied from or derived from https://github.com/w3c/csswg-drafts/blob/main/css-color-4/conversions.js. Copyright © 2022 W3C® (MIT, ERCIM, Keio, Beihang). + */function XYZ_to_lin_P3(t){return multiplyMatrices(c,t)}const u=[1.3457868816471583,-.25557208737979464,-.05110186497554526,-.5446307051249019,1.5082477428451468,.02052744743642139,0,0,1.2119675456389452]; +/** + * Convert D50 XYZ to linear-light prophoto-rgb + * + * @license W3C https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document + * @copyright This software or document includes material copied from or derived from https://github.com/w3c/csswg-drafts/blob/main/css-color-4/conversions.js. Copyright © 2022 W3C® (MIT, ERCIM, Keio, Beihang). + * @see http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html + */const h=[1829569/896150,-506331/896150,-308931/896150,-851781/878810,1648619/878810,36519/878810,16779/1248040,-147721/1248040,1266979/1248040]; +/** + * Convert XYZ to linear-light a98-rgb + * + * @license W3C https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document + * @copyright This software or document includes material copied from or derived from https://github.com/w3c/csswg-drafts/blob/main/css-color-4/conversions.js. Copyright © 2022 W3C® (MIT, ERCIM, Keio, Beihang). + */const m=[12831/3959,-329/214,-1974/3959,-851781/878810,1648619/878810,36519/878810,705/12673,-2585/12673,705/667]; +/** + * @license W3C https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document + * @copyright This software or document includes material copied from or derived from https://github.com/w3c/csswg-drafts/blob/main/css-color-4/conversions.js. Copyright © 2022 W3C® (MIT, ERCIM, Keio, Beihang). + */function XYZ_to_lin_sRGB(t){return multiplyMatrices(m,t)} +/** + * Convert an array of linear-light rec2020 RGB in the range 0.0-1.0 + * to gamma corrected form ITU-R BT.2020-2 p.4 + * + * @license W3C https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document + * @copyright This software or document includes material copied from or derived from https://github.com/w3c/csswg-drafts/blob/main/css-color-4/conversions.js. Copyright © 2022 W3C® (MIT, ERCIM, Keio, Beihang). + */const p=1.09929682680944,D=.018053968510807;function gam_2020_channel(t){const n=t<0?-1:1,_=Math.abs(t);return _>D?n*(p*Math.pow(_,.45)-(p-1)):4.5*t} +/** + * Convert an array of linear-light sRGB values in the range 0.0-1.0 to gamma corrected form + * Extended transfer function: + * For negative values, linear portion extends on reflection + * of axis, then uses reflected pow below that + * + * @license W3C https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document + * @copyright This software or document includes material copied from or derived from https://github.com/w3c/csswg-drafts/blob/main/css-color-4/conversions.js. Copyright © 2022 W3C® (MIT, ERCIM, Keio, Beihang). + * @see https://en.wikipedia.org/wiki/SRGB + */function gam_sRGB(t){return[gam_sRGB_channel(t[0]),gam_sRGB_channel(t[1]),gam_sRGB_channel(t[2])]}function gam_sRGB_channel(t){const n=t<0?-1:1,_=Math.abs(t);return _>.0031308?n*(1.055*Math.pow(_,1/2.4)-.055):12.92*t} +/** + * Convert an array of linear-light display-p3 RGB in the range 0.0-1.0 + * to gamma corrected form + * + * @license W3C https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document + * @copyright This software or document includes material copied from or derived from https://github.com/w3c/csswg-drafts/blob/main/css-color-4/conversions.js. Copyright © 2022 W3C® (MIT, ERCIM, Keio, Beihang). + */function gam_P3(t){return gam_sRGB(t)} +/** + * Convert an array of linear-light prophoto-rgb in the range 0.0-1.0 + * to gamma corrected form. + * Transfer curve is gamma 1.8 with a small linear portion. + * + * @license W3C https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document + * @copyright This software or document includes material copied from or derived from https://github.com/w3c/csswg-drafts/blob/main/css-color-4/conversions.js. Copyright © 2022 W3C® (MIT, ERCIM, Keio, Beihang). + */const b=1/512;function gam_ProPhoto_channel(t){const n=t<0?-1:1,_=Math.abs(t);return _>=b?n*Math.pow(_,1/1.8):16*t} +/** + * Convert an array of linear-light a98-rgb in the range 0.0-1.0 + * to gamma corrected form. Negative values are also now accepted + * + * @license W3C https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document + * @copyright This software or document includes material copied from or derived from https://github.com/w3c/csswg-drafts/blob/main/css-color-4/conversions.js. Copyright © 2022 W3C® (MIT, ERCIM, Keio, Beihang). + */function gam_a98rgb_channel(t){const n=t<0?-1:1,_=Math.abs(t);return n*Math.pow(_,256/563)} /** * Convert an array of rec2020 RGB values in the range 0.0 - 1.0 * to linear light (un-companded) form. @@ -55,7 +153,7 @@ function OKLab_to_XYZ(t){const n=multiplyMatrices(o,t);return multiplyMatrices(_ * * @license W3C https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document * @copyright This software or document includes material copied from or derived from https://github.com/w3c/csswg-drafts/blob/main/css-color-4/conversions.js. Copyright © 2022 W3C® (MIT, ERCIM, Keio, Beihang). - */const e=1.09929682680944,r=.018053968510807;function lin_2020_channel(t){const n=t<0?-1:1,_=Math.abs(t);return _<4.5*r?t/4.5:n*Math.pow((_+e-1)/e,1/.45)}const a=[63426534/99577255,20160776/139408157,47086771/278816314,26158966/99577255,.677998071518871,8267143/139408157,0,19567812/697040785,1.0609850577107909]; + */const g=1.09929682680944,X=.018053968510807;function lin_2020_channel(t){const n=t<0?-1:1,_=Math.abs(t);return _<4.5*X?t/4.5:n*Math.pow((_+g-1)/g,1/.45)}const Y=[63426534/99577255,20160776/139408157,47086771/278816314,26158966/99577255,.677998071518871,8267143/139408157,0,19567812/697040785,1.0609850577107909]; /** * Convert an array of linear-light rec2020 values to CIE XYZ * using D65 (no chromatic adaptation) @@ -82,7 +180,7 @@ function lin_sRGB(t){return[lin_sRGB_channel(t[0]),lin_sRGB_channel(t[1]),lin_sR * * @license W3C https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document * @copyright This software or document includes material copied from or derived from https://github.com/w3c/csswg-drafts/blob/main/css-color-4/conversions.js. Copyright © 2022 W3C® (MIT, ERCIM, Keio, Beihang). - */function lin_P3(t){return lin_sRGB(t)}const l=[608311/1250200,189793/714400,198249/1000160,35783/156275,247089/357200,198249/2500400,0,32229/714400,5220557/5000800]; + */function lin_P3(t){return lin_sRGB(t)}const Z=[608311/1250200,189793/714400,198249/1000160,35783/156275,247089/357200,198249/2500400,0,32229/714400,5220557/5000800]; /** * Convert an array of linear-light display-p3 values to CIE XYZ * using D65 (no chromatic adaptation) @@ -90,7 +188,7 @@ function lin_sRGB(t){return[lin_sRGB_channel(t[0]),lin_sRGB_channel(t[1]),lin_sR * @license W3C https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document * @copyright This software or document includes material copied from or derived from https://github.com/w3c/csswg-drafts/blob/main/css-color-4/conversions.js. Copyright © 2022 W3C® (MIT, ERCIM, Keio, Beihang). * @see http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html - */function lin_P3_to_XYZ(t){return multiplyMatrices(l,t)} + */function lin_P3_to_XYZ(t){return multiplyMatrices(Z,t)} /** * Convert an array of prophoto-rgb values where in-gamut Colors are in the * range [0.0 - 1.0] to linear light (un-companded) form. Transfer curve is @@ -98,7 +196,7 @@ function lin_sRGB(t){return[lin_sRGB_channel(t[0]),lin_sRGB_channel(t[1]),lin_sR * * @license W3C https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document * @copyright This software or document includes material copied from or derived from https://github.com/w3c/csswg-drafts/blob/main/css-color-4/conversions.js. Copyright © 2022 W3C® (MIT, ERCIM, Keio, Beihang). - */const i=16/512;function lin_ProPhoto_channel(t){const n=t<0?-1:1,_=Math.abs(t);return _<=i?t/16:n*Math.pow(_,1.8)}const s=[.7977666449006423,.13518129740053308,.0313477341283922,.2880748288194013,.711835234241873,8993693872564e-17,0,0,.8251046025104602]; + */const f=16/512;function lin_ProPhoto_channel(t){const n=t<0?-1:1,_=Math.abs(t);return _<=f?t/16:n*Math.pow(_,1.8)}const L=[.7977666449006423,.13518129740053308,.0313477341283922,.2880748288194013,.711835234241873,8993693872564e-17,0,0,.8251046025104602]; /** * Convert an array of linear-light prophoto-rgb values to CIE D50 XYZ. * Matrix cannot be expressed in rational form, but is calculated to 64 bit accuracy. @@ -106,7 +204,7 @@ function lin_sRGB(t){return[lin_sRGB_channel(t[0]),lin_sRGB_channel(t[1]),lin_sR * @license W3C https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document * @copyright This software or document includes material copied from or derived from https://github.com/w3c/csswg-drafts/blob/main/css-color-4/conversions.js. Copyright © 2022 W3C® (MIT, ERCIM, Keio, Beihang). * @see see https://github.com/w3c/csswg-drafts/issues/7675 - */function lin_a98rgb_channel(t){const n=t<0?-1:1,_=Math.abs(t);return n*Math.pow(_,563/256)}const c=[573536/994567,263643/1420810,187206/994567,591459/1989134,6239551/9945670,374412/4972835,53769/1989134,351524/4972835,4929758/4972835]; + */function lin_a98rgb_channel(t){const n=t<0?-1:1,_=Math.abs(t);return n*Math.pow(_,563/256)}const M=[573536/994567,263643/1420810,187206/994567,591459/1989134,6239551/9945670,374412/4972835,53769/1989134,351524/4972835,4929758/4972835]; /** * Convert an array of linear-light a98-rgb values to CIE XYZ * http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html @@ -120,34 +218,14 @@ function lin_sRGB(t){return[lin_sRGB_channel(t[0]),lin_sRGB_channel(t[1]),lin_sR * @see http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html * @see https://www.adobe.com/digitalimag/pdfs/AdobeRGB1998.pdf * @see https://github.com/w3c/csswg-drafts/blob/main/css-color-4/matrixmaker.html - */const u=[506752/1228815,87881/245763,12673/70218,87098/409605,175762/245763,12673/175545,7918/409605,87881/737289,1001167/1053270]; + */const d=[506752/1228815,87881/245763,12673/70218,87098/409605,175762/245763,12673/175545,7918/409605,87881/737289,1001167/1053270]; /** * Convert an array of linear-light sRGB values to CIE XYZ * using sRGB's own white, D65 (no chromatic adaptation) * * @license W3C https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document * @copyright This software or document includes material copied from or derived from https://github.com/w3c/csswg-drafts/blob/main/css-color-4/conversions.js. Copyright © 2022 W3C® (MIT, ERCIM, Keio, Beihang). - */function lin_sRGB_to_XYZ(t){return multiplyMatrices(u,t)}const h=[.955473421488075,-.02309845494876471,.06325924320057072,-.0283697093338637,1.0099953980813041,.021041441191917323,.012314014864481998,-.020507649298898964,1.330365926242124]; -/** - * Bradford chromatic adaptation from D50 to D65 - * - * @license W3C https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document - * @copyright This software or document includes material copied from or derived from https://github.com/w3c/csswg-drafts/blob/main/css-color-4/conversions.js. Copyright © 2022 W3C® (MIT, ERCIM, Keio, Beihang). - */function D50_to_D65(t){return multiplyMatrices(h,t)}const m=[12831/3959,-329/214,-1974/3959,-851781/878810,1648619/878810,36519/878810,705/12673,-2585/12673,705/667]; -/** - * @license W3C https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document - * @copyright This software or document includes material copied from or derived from https://github.com/w3c/csswg-drafts/blob/main/css-color-4/conversions.js. Copyright © 2022 W3C® (MIT, ERCIM, Keio, Beihang). - */function XYZ_to_lin_sRGB(t){return multiplyMatrices(m,t)} -/** - * Convert an array of linear-light sRGB values in the range 0.0-1.0 to gamma corrected form - * Extended transfer function: - * For negative values, linear portion extends on reflection - * of axis, then uses reflected pow below that - * - * @license W3C https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document - * @copyright This software or document includes material copied from or derived from https://github.com/w3c/csswg-drafts/blob/main/css-color-4/conversions.js. Copyright © 2022 W3C® (MIT, ERCIM, Keio, Beihang). - * @see https://en.wikipedia.org/wiki/SRGB - */function gam_sRGB(t){return[gam_sRGB_channel(t[0]),gam_sRGB_channel(t[1]),gam_sRGB_channel(t[2])]}function gam_sRGB_channel(t){const n=t<0?-1:1,_=Math.abs(t);return _>.0031308?n*(1.055*Math.pow(_,1/2.4)-.055):12.92*t} + */function lin_sRGB_to_XYZ(t){return multiplyMatrices(d,t)} /** * Convert an array of gamma-corrected sRGB values in the 0.0 to 1.0 range to HSL. * @@ -161,63 +239,7 @@ function lin_sRGB(t){return[lin_sRGB_channel(t[0]),lin_sRGB_channel(t[1]),lin_sR * @copyright This software or document includes material copied from or derived from https://github.com/w3c/csswg-drafts/blob/main/css-color-4/utilities.js. Copyright © 2022 W3C® (MIT, ERCIM, Keio, Beihang). * * @see https://github.com/w3c/csswg-drafts/blob/main/css-color-4/better-rgbToHsl.js - */function sRGB_to_HSL(t){const n=t[0],_=t[1],o=t[2],e=Math.max(n,_,o),r=Math.min(n,_,o),a=(r+e)/2,l=e-r;let i=NaN,s=0;if(0!==Math.round(1e5*l)){const t=Math.round(1e5*a);switch(s=0===t||1e5===t?0:(e-a)/Math.min(a,1-a),e){case n:i=(_-o)/l+(_=360&&(i-=360),[i,100*s,100*a]}const p=[446124/178915,-333277/357830,-72051/178915,-14852/17905,63121/35810,423/17905,11844/330415,-50337/660830,316169/330415]; -/** - * Convert XYZ to linear-light P3 - * - * @license W3C https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document - * @copyright This software or document includes material copied from or derived from https://github.com/w3c/csswg-drafts/blob/main/css-color-4/conversions.js. Copyright © 2022 W3C® (MIT, ERCIM, Keio, Beihang). - */function XYZ_to_lin_P3(t){return multiplyMatrices(p,t)} -/** - * Convert an array of linear-light display-p3 RGB in the range 0.0-1.0 - * to gamma corrected form - * - * @license W3C https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document - * @copyright This software or document includes material copied from or derived from https://github.com/w3c/csswg-drafts/blob/main/css-color-4/conversions.js. Copyright © 2022 W3C® (MIT, ERCIM, Keio, Beihang). - */function gam_P3(t){return gam_sRGB(t)} -/** - * Assuming XYZ is relative to D50, convert to CIE Lab - * from CIE standard, which now defines these as a rational fraction - * - * @license W3C https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document - * @copyright This software or document includes material copied from or derived from https://github.com/w3c/csswg-drafts/blob/main/css-color-4/conversions.js. Copyright © 2022 W3C® (MIT, ERCIM, Keio, Beihang). - */function XYZ_to_Lab(t){const _=compute_f(t[0]/n[0]),o=compute_f(t[1]/n[1]);return[116*o-16,500*(_-o),200*(o-compute_f(t[2]/n[2]))]}const D=216/24389,g=24389/27;function compute_f(t){return t>D?Math.cbrt(t):(g*t+16)/116}const b=[.819022437996703,.3619062600528904,-.1288737815209879,.0329836539323885,.9292868615863434,.0361446663506424,.0481771893596242,.2642395317527308,.6335478284694309],X=[.210454268309314,.7936177747023054,-.0040720430116193,1.9779985324311684,-2.42859224204858,.450593709617411,.0259040424655478,.7827717124575296,-.8086757549230774]; -/** - * @license W3C https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document - * @copyright This software or document includes material copied from or derived from https://github.com/w3c/csswg-drafts/blob/main/css-color-4/conversions.js. Copyright © 2022 W3C® (MIT, ERCIM, Keio, Beihang). - * - * XYZ <-> LMS matrices recalculated for consistent reference white - * @see https://github.com/w3c/csswg-drafts/issues/6642#issuecomment-943521484 - */ -function XYZ_to_OKLab(t){const n=multiplyMatrices(b,t);return multiplyMatrices(X,[Math.cbrt(n[0]),Math.cbrt(n[1]),Math.cbrt(n[2])])} -/** - * @license W3C https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document - * @copyright This software or document includes material copied from or derived from https://github.com/w3c/csswg-drafts/blob/main/css-color-4/conversions.js. Copyright © 2022 W3C® (MIT, ERCIM, Keio, Beihang). - */function Lab_to_LCH(t){const n=180*Math.atan2(t[2],t[1])/Math.PI;return[t[0],Math.sqrt(Math.pow(t[1],2)+Math.pow(t[2],2)),n>=0?n:n+360]} -/** - * @license W3C https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document - * @copyright This software or document includes material copied from or derived from https://github.com/w3c/csswg-drafts/blob/main/css-color-4/conversions.js. Copyright © 2022 W3C® (MIT, ERCIM, Keio, Beihang). - * @see https://github.com/w3c/csswg-drafts/blob/main/css-color-4/conversions.js - */function OKLab_to_OKLCH(t){const n=180*Math.atan2(t[2],t[1])/Math.PI;return[t[0],Math.sqrt(t[1]**2+t[2]**2),n>=0?n:n+360]}const Y=[1829569/896150,-506331/896150,-308931/896150,-851781/878810,1648619/878810,36519/878810,16779/1248040,-147721/1248040,1266979/1248040]; -/** - * Convert XYZ to linear-light a98-rgb - * - * @license W3C https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document - * @copyright This software or document includes material copied from or derived from https://github.com/w3c/csswg-drafts/blob/main/css-color-4/conversions.js. Copyright © 2022 W3C® (MIT, ERCIM, Keio, Beihang). - */function gam_a98rgb_channel(t){const n=t<0?-1:1,_=Math.abs(t);return n*Math.pow(_,256/563)}const Z=[30757411/17917100,-6372589/17917100,-4539589/17917100,-.666684351832489,1.616481236634939,467509/29648200,792561/44930125,-1921689/44930125,.942103121235474]; -/** - * Convert XYZ to linear-light rec2020 - * - * @license W3C https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document - * @copyright This software or document includes material copied from or derived from https://github.com/w3c/csswg-drafts/blob/main/css-color-4/conversions.js. Copyright © 2022 W3C® (MIT, ERCIM, Keio, Beihang). - */const f=1.09929682680944,L=.018053968510807;function gam_2020_channel(t){const n=t<0?-1:1,_=Math.abs(t);return _>L?n*(f*Math.pow(_,.45)-(f-1)):4.5*t}const M=[1.3457868816471583,-.25557208737979464,-.05110186497554526,-.5446307051249019,1.5082477428451468,.02052744743642139,0,0,1.2119675456389452]; -/** - * Convert D50 XYZ to linear-light prophoto-rgb - * - * @license W3C https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document - * @copyright This software or document includes material copied from or derived from https://github.com/w3c/csswg-drafts/blob/main/css-color-4/conversions.js. Copyright © 2022 W3C® (MIT, ERCIM, Keio, Beihang). - * @see http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html - */const d=1/512;function gam_ProPhoto_channel(t){const n=t<0?-1:1,_=Math.abs(t);return _>=d?n*Math.pow(_,1/1.8):16*t}function inGamut(t){return t[0]>=-1e-4&&t[0]<=1.0001&&t[1]>=-1e-4&&t[1]<=1.0001&&t[2]>=-1e-4&&t[2]<=1.0001}function clip(t){return[t[0]<0?0:t[0]>1?1:t[0],t[1]<0?0:t[1]>1?1:t[1],t[2]<0?0:t[2]>1?1:t[2]]} + */function sRGB_to_HSL(t){const n=t[0],_=t[1],o=t[2],e=Math.max(n,_,o),r=Math.min(n,_,o),a=(r+e)/2,i=e-r;let l=NaN,s=0;if(0!==Math.round(1e5*i)){const t=Math.round(1e5*a);switch(s=0===t||1e5===t?0:(e-a)/Math.min(a,1-a),e){case n:l=(_-o)/i+(_=360&&(l-=360),[l,100*s,100*a]}function sRGB_to_Hue(t){const n=t[0],_=t[1],o=t[2],e=Math.max(n,_,o);let r=NaN;const a=e-Math.min(n,_,o);if(0!==a){switch(e){case n:r=(_-o)/a+(_=360&&(r-=360),r}function inGamut(t){return t[0]>=-1e-4&&t[0]<=1.0001&&t[1]>=-1e-4&&t[1]<=1.0001&&t[2]>=-1e-4&&t[2]<=1.0001}function clip(t){return[t[0]<0?0:t[0]>1?1:t[0],t[1]<0?0:t[1]>1?1:t[1],t[2]<0?0:t[2]>1?1:t[2]]} /** * @description Calculate deltaE OK which is the simple root sum of squares * @param {number[]} reference - Array of OKLab values: L as 0..1, a and b as -1..1 @@ -227,29 +249,7 @@ function XYZ_to_OKLab(t){const n=multiplyMatrices(b,t);return multiplyMatrices(X * @license W3C https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document * @copyright This software or document includes material copied from or derived from https://github.com/w3c/csswg-drafts/blob/main/css-color-4/deltaEOK.js. Copyright © 2022 W3C® (MIT, ERCIM, Keio, Beihang). * @see https://github.com/w3c/csswg-drafts/blob/main/css-color-4/deltaEOK.js - */function deltaEOK(t,n){const[_,o,e]=t,[r,a,l]=n,i=_-r,s=o-a,c=e-l;return Math.sqrt(i**2+s**2+c**2)}const B=.02,G=1e-4;function rayTraceBox(t,n){let _=1/0,o=-1/0;const e=[0,0,0];for(let r=0;r<3;r++){const a=t[r],l=n[r]-a;e[r]=l;const i=0,s=1;if(l){const t=1/l,n=(i-a)*t,e=(s-a)*t;o=Math.max(Math.min(n,e),o),_=Math.min(Math.max(n,e),_)}else if(as)return!1}return!(o>_||_<0)&&(o<0&&(o=_),!!isFinite(o)&&[t[0]+e[0]*o,t[1]+e[1]*o,t[2]+e[2]*o])}function luminance(t){const[n,_,o]=t.map((t=>t<=.03928?t/12.92:Math.pow((t+.055)/1.055,2.4)));return.2126*n+.7152*_+.0722*o}exports.HSL_to_XYZ_D50=function HSL_to_XYZ_D50(t){let n=t;return n=HSL_to_sRGB(n),n=lin_sRGB(n),n=lin_sRGB_to_XYZ(n),n=D65_to_D50(n),n},exports.HWB_to_XYZ_D50=function HWB_to_XYZ_D50(t){let n=t;return n=HWB_to_sRGB(n),n=lin_sRGB(n),n=lin_sRGB_to_XYZ(n),n=D65_to_D50(n),n},exports.LCH_to_XYZ_D50=function LCH_to_XYZ_D50(t){let n=t;return n=LCH_to_Lab(n),n=Lab_to_XYZ(n),n},exports.Lab_to_XYZ_D50=function Lab_to_XYZ_D50(t){let n=t;return n=Lab_to_XYZ(n),n},exports.OKLCH_to_OKLab=OKLCH_to_OKLab,exports.OKLCH_to_XYZ_D50=function OKLCH_to_XYZ_D50(t){let n=t;return n=OKLCH_to_OKLab(n),n=OKLab_to_XYZ(n),n=D65_to_D50(n),n},exports.OKLab_to_OKLCH=OKLab_to_OKLCH,exports.OKLab_to_XYZ=OKLab_to_XYZ,exports.OKLab_to_XYZ_D50=function OKLab_to_XYZ_D50(t){let n=t;return n=OKLab_to_XYZ(n),n=D65_to_D50(n),n},exports.P3_to_XYZ_D50=function P3_to_XYZ_D50(t){let n=t;return n=lin_P3(n),n=lin_P3_to_XYZ(n),n=D65_to_D50(n),n},exports.ProPhoto_RGB_to_XYZ_D50=function ProPhoto_RGB_to_XYZ_D50(t){let n=t;var _;return n=[lin_ProPhoto_channel((_=n)[0]),lin_ProPhoto_channel(_[1]),lin_ProPhoto_channel(_[2])],n=multiplyMatrices(s,n),n},exports.XYZ_D50_to_HSL=function XYZ_D50_to_HSL(t){let n=t;return n=D50_to_D65(n),n=XYZ_to_lin_sRGB(n),n=gam_sRGB(n),n=sRGB_to_HSL(n),n},exports.XYZ_D50_to_HWB=function XYZ_D50_to_HWB(t){let n=t;n=D50_to_D65(n),n=XYZ_to_lin_sRGB(n);const _=gam_sRGB(n);n=sRGB_to_HSL(_);const o=Math.min(_[0],_[1],_[2]),e=1-Math.max(_[0],_[1],_[2]);return[n[0],100*o,100*e]},exports.XYZ_D50_to_LCH=function XYZ_D50_to_LCH(t){let n=t;return n=XYZ_to_Lab(n),n=Lab_to_LCH(n),n},exports.XYZ_D50_to_Lab=function XYZ_D50_to_Lab(t){let n=t;return n=XYZ_to_Lab(n),n},exports.XYZ_D50_to_OKLCH=function XYZ_D50_to_OKLCH(t){let n=t;return n=D50_to_D65(n),n=XYZ_to_OKLab(n),n=OKLab_to_OKLCH(n),n},exports.XYZ_D50_to_OKLab=function XYZ_D50_to_OKLab(t){let n=t;return n=D50_to_D65(n),n=XYZ_to_OKLab(n),n},exports.XYZ_D50_to_P3=function XYZ_D50_to_P3(t){let n=t;return n=D50_to_D65(n),n=XYZ_to_lin_P3(n),n=gam_P3(n),n},exports.XYZ_D50_to_ProPhoto=function XYZ_D50_to_ProPhoto(t){let n=t;var _; -/** - * Convert an array of linear-light prophoto-rgb in the range 0.0-1.0 - * to gamma corrected form. - * Transfer curve is gamma 1.8 with a small linear portion. - * - * @license W3C https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document - * @copyright This software or document includes material copied from or derived from https://github.com/w3c/csswg-drafts/blob/main/css-color-4/conversions.js. Copyright © 2022 W3C® (MIT, ERCIM, Keio, Beihang). - */return n=multiplyMatrices(M,n),n=[gam_ProPhoto_channel((_=n)[0]),gam_ProPhoto_channel(_[1]),gam_ProPhoto_channel(_[2])],n},exports.XYZ_D50_to_XYZ_D50=function XYZ_D50_to_XYZ_D50(t){return t},exports.XYZ_D50_to_XYZ_D65=function XYZ_D50_to_XYZ_D65(t){let n=t;return n=D50_to_D65(n),n},exports.XYZ_D50_to_a98_RGB=function XYZ_D50_to_a98_RGB(t){let n=t;var _; -/** - * Convert an array of linear-light a98-rgb in the range 0.0-1.0 - * to gamma corrected form. Negative values are also now accepted - * - * @license W3C https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document - * @copyright This software or document includes material copied from or derived from https://github.com/w3c/csswg-drafts/blob/main/css-color-4/conversions.js. Copyright © 2022 W3C® (MIT, ERCIM, Keio, Beihang). - */return n=D50_to_D65(n),n=multiplyMatrices(Y,n),n=[gam_a98rgb_channel((_=n)[0]),gam_a98rgb_channel(_[1]),gam_a98rgb_channel(_[2])],n},exports.XYZ_D50_to_lin_sRGB=function XYZ_D50_to_lin_sRGB(t){let n=t;return n=D50_to_D65(n),n=XYZ_to_lin_sRGB(n),n},exports.XYZ_D50_to_rec_2020=function XYZ_D50_to_rec_2020(t){let n=t;var _; -/** - * Convert an array of linear-light rec2020 RGB in the range 0.0-1.0 - * to gamma corrected form ITU-R BT.2020-2 p.4 - * - * @license W3C https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document - * @copyright This software or document includes material copied from or derived from https://github.com/w3c/csswg-drafts/blob/main/css-color-4/conversions.js. Copyright © 2022 W3C® (MIT, ERCIM, Keio, Beihang). - */return n=D50_to_D65(n),n=multiplyMatrices(Z,n),n=[gam_2020_channel((_=n)[0]),gam_2020_channel(_[1]),gam_2020_channel(_[2])],n},exports.XYZ_D50_to_sRGB=function XYZ_D50_to_sRGB(t){let n=t;return n=D50_to_D65(n),n=XYZ_to_lin_sRGB(n),n=gam_sRGB(n),n},exports.XYZ_D65_to_XYZ_D50=function XYZ_D65_to_XYZ_D50(t){let n=t;return n=D65_to_D50(n),n},exports.XYZ_to_OKLab=XYZ_to_OKLab,exports.XYZ_to_lin_P3=XYZ_to_lin_P3,exports.XYZ_to_lin_sRGB=XYZ_to_lin_sRGB,exports.a98_RGB_to_XYZ_D50=function a98_RGB_to_XYZ_D50(t){let n=t; + */function deltaEOK(t,n){const[_,o,e]=t,[r,a,i]=n,l=_-r,s=o-a,c=e-i;return Math.sqrt(l**2+s**2+c**2)}const B=.02,G=1e-4;function rayTraceBox(t,n){let _=1/0,o=-1/0;const e=[0,0,0];for(let r=0;r<3;r++){const a=t[r],i=n[r]-a;e[r]=i;const l=0,s=1;if(i){const t=1/i,n=(l-a)*t,e=(s-a)*t;o=Math.max(Math.min(n,e),o),_=Math.min(Math.max(n,e),_)}else if(as)return!1}return!(o>_||_<0)&&(o<0&&(o=_),!!isFinite(o)&&[t[0]+e[0]*o,t[1]+e[1]*o,t[2]+e[2]*o])}function luminance(t){const[n,_,o]=t.map((t=>t<=.03928?t/12.92:Math.pow((t+.055)/1.055,2.4)));return.2126*n+.7152*_+.0722*o}exports.HSL_to_XYZ_D50=function HSL_to_XYZ_D50(t){let n=t;return n=HSL_to_sRGB(n),n=lin_sRGB(n),n=lin_sRGB_to_XYZ(n),n=D65_to_D50(n),n},exports.HWB_to_XYZ_D50=function HWB_to_XYZ_D50(t){let n=t;return n=HWB_to_sRGB(n),n=lin_sRGB(n),n=lin_sRGB_to_XYZ(n),n=D65_to_D50(n),n},exports.LCH_to_XYZ_D50=function LCH_to_XYZ_D50(t){let n=t;return n=LCH_to_Lab(n),n=Lab_to_XYZ(n),n},exports.Lab_to_XYZ_D50=function Lab_to_XYZ_D50(t){let n=t;return n=Lab_to_XYZ(n),n},exports.OKLCH_to_OKLab=OKLCH_to_OKLab,exports.OKLCH_to_XYZ_D50=function OKLCH_to_XYZ_D50(t){let n=t;return n=OKLCH_to_OKLab(n),n=OKLab_to_XYZ(n),n=D65_to_D50(n),n},exports.OKLab_to_OKLCH=OKLab_to_OKLCH,exports.OKLab_to_XYZ=OKLab_to_XYZ,exports.OKLab_to_XYZ_D50=function OKLab_to_XYZ_D50(t){let n=t;return n=OKLab_to_XYZ(n),n=D65_to_D50(n),n},exports.P3_to_XYZ_D50=function P3_to_XYZ_D50(t){let n=t;return n=lin_P3(n),n=lin_P3_to_XYZ(n),n=D65_to_D50(n),n},exports.ProPhoto_RGB_to_XYZ_D50=function ProPhoto_RGB_to_XYZ_D50(t){let n=t;var _;return n=[lin_ProPhoto_channel((_=n)[0]),lin_ProPhoto_channel(_[1]),lin_ProPhoto_channel(_[2])],n=multiplyMatrices(L,n),n},exports.XYZ_D50_to_HSL=function XYZ_D50_to_HSL(t){let n=t;return n=D50_to_D65(n),n=XYZ_to_lin_sRGB(n),n=gam_sRGB(n),n=sRGB_to_HSL(n),n},exports.XYZ_D50_to_HWB=function XYZ_D50_to_HWB(t){let n=t;n=D50_to_D65(n),n=XYZ_to_lin_sRGB(n);const _=gam_sRGB(n),o=Math.min(_[0],_[1],_[2]),e=1-Math.max(_[0],_[1],_[2]);return[sRGB_to_Hue(_),100*o,100*e]},exports.XYZ_D50_to_LCH=function XYZ_D50_to_LCH(t){let n=t;return n=XYZ_to_Lab(n),n=Lab_to_LCH(n),n},exports.XYZ_D50_to_Lab=function XYZ_D50_to_Lab(t){let n=t;return n=XYZ_to_Lab(n),n},exports.XYZ_D50_to_OKLCH=function XYZ_D50_to_OKLCH(t){let n=t;return n=D50_to_D65(n),n=XYZ_to_OKLab(n),n=OKLab_to_OKLCH(n),n},exports.XYZ_D50_to_OKLab=function XYZ_D50_to_OKLab(t){let n=t;return n=D50_to_D65(n),n=XYZ_to_OKLab(n),n},exports.XYZ_D50_to_P3=function XYZ_D50_to_P3(t){let n=t;return n=D50_to_D65(n),n=XYZ_to_lin_P3(n),n=gam_P3(n),n},exports.XYZ_D50_to_ProPhoto=function XYZ_D50_to_ProPhoto(t){let n=t;var _;return n=multiplyMatrices(u,n),n=[gam_ProPhoto_channel((_=n)[0]),gam_ProPhoto_channel(_[1]),gam_ProPhoto_channel(_[2])],n},exports.XYZ_D50_to_XYZ_D50=function XYZ_D50_to_XYZ_D50(t){return t},exports.XYZ_D50_to_XYZ_D65=function XYZ_D50_to_XYZ_D65(t){let n=t;return n=D50_to_D65(n),n},exports.XYZ_D50_to_a98_RGB=function XYZ_D50_to_a98_RGB(t){let n=t;var _;return n=D50_to_D65(n),n=multiplyMatrices(h,n),n=[gam_a98rgb_channel((_=n)[0]),gam_a98rgb_channel(_[1]),gam_a98rgb_channel(_[2])],n},exports.XYZ_D50_to_lin_sRGB=function XYZ_D50_to_lin_sRGB(t){let n=t;return n=D50_to_D65(n),n=XYZ_to_lin_sRGB(n),n},exports.XYZ_D50_to_rec_2020=function XYZ_D50_to_rec_2020(t){let n=t;var _;return n=D50_to_D65(n),n=multiplyMatrices(s,n),n=[gam_2020_channel((_=n)[0]),gam_2020_channel(_[1]),gam_2020_channel(_[2])],n},exports.XYZ_D50_to_sRGB=function XYZ_D50_to_sRGB(t){let n=t;return n=D50_to_D65(n),n=XYZ_to_lin_sRGB(n),n=gam_sRGB(n),n},exports.XYZ_D65_to_XYZ_D50=function XYZ_D65_to_XYZ_D50(t){let n=t;return n=D65_to_D50(n),n},exports.XYZ_to_OKLab=XYZ_to_OKLab,exports.XYZ_to_lin_P3=XYZ_to_lin_P3,exports.XYZ_to_lin_sRGB=XYZ_to_lin_sRGB,exports.a98_RGB_to_XYZ_D50=function a98_RGB_to_XYZ_D50(t){let n=t; /** * Convert an array of a98-rgb values in the range 0.0 - 1.0 * to linear light (un-companded) form. Negative values are also now accepted @@ -257,7 +257,7 @@ function XYZ_to_OKLab(t){const n=multiplyMatrices(b,t);return multiplyMatrices(X * @license W3C https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document * @copyright This software or document includes material copied from or derived from https://github.com/w3c/csswg-drafts/blob/main/css-color-4/conversions.js. Copyright © 2022 W3C® (MIT, ERCIM, Keio, Beihang). */ -var _;return n=[lin_a98rgb_channel((_=n)[0]),lin_a98rgb_channel(_[1]),lin_a98rgb_channel(_[2])],n=multiplyMatrices(c,n),n=D65_to_D50(n),n},exports.clip=clip,exports.contrast_ratio_wcag_2_1=function contrast_ratio_wcag_2_1(t,n){const _=luminance(t),o=luminance(n);return(Math.max(_,o)+.05)/(Math.min(_,o)+.05)},exports.gam_P3=gam_P3,exports.gam_sRGB=gam_sRGB,exports.inGamut=inGamut,exports.lin_P3=lin_P3,exports.lin_P3_to_XYZ=lin_P3_to_XYZ,exports.lin_sRGB=lin_sRGB,exports.lin_sRGB_to_XYZ=lin_sRGB_to_XYZ,exports.lin_sRGB_to_XYZ_D50=function lin_sRGB_to_XYZ_D50(t){let n=t;return n=lin_sRGB_to_XYZ(n),n=D65_to_D50(n),n},exports.mapGamut=function mapGamut(t,n,_){const o=t;let e=clip(n(o)),r=deltaEOK(OKLCH_to_OKLab(_(e)),OKLCH_to_OKLab(o));if(rG;){const t=(a+l)/2;if(o[1]=t,i&&inGamut(n(o)))a=t;else if(e=clip(n(o)),r=deltaEOK(OKLCH_to_OKLab(_(e)),OKLCH_to_OKLab(o)),rG;){const t=(a+i)/2;if(o[1]=t,l&&inGamut(n(o)))a=t;else if(e=clip(n(o)),r=deltaEOK(OKLCH_to_OKLab(_(e)),OKLCH_to_OKLab(o)),r0){const t=_(r);t[0]=o,t[2]=e,r=n(t)}const l=rayTraceBox(a,r);if(!l)break;r=l}return clip(r)},exports.namedColors={aliceblue:[240,248,255],antiquewhite:[250,235,215],aqua:[0,255,255],aquamarine:[127,255,212],azure:[240,255,255],beige:[245,245,220],bisque:[255,228,196],black:[0,0,0],blanchedalmond:[255,235,205],blue:[0,0,255],blueviolet:[138,43,226],brown:[165,42,42],burlywood:[222,184,135],cadetblue:[95,158,160],chartreuse:[127,255,0],chocolate:[210,105,30],coral:[255,127,80],cornflowerblue:[100,149,237],cornsilk:[255,248,220],crimson:[220,20,60],cyan:[0,255,255],darkblue:[0,0,139],darkcyan:[0,139,139],darkgoldenrod:[184,134,11],darkgray:[169,169,169],darkgreen:[0,100,0],darkgrey:[169,169,169],darkkhaki:[189,183,107],darkmagenta:[139,0,139],darkolivegreen:[85,107,47],darkorange:[255,140,0],darkorchid:[153,50,204],darkred:[139,0,0],darksalmon:[233,150,122],darkseagreen:[143,188,143],darkslateblue:[72,61,139],darkslategray:[47,79,79],darkslategrey:[47,79,79],darkturquoise:[0,206,209],darkviolet:[148,0,211],deeppink:[255,20,147],deepskyblue:[0,191,255],dimgray:[105,105,105],dimgrey:[105,105,105],dodgerblue:[30,144,255],firebrick:[178,34,34],floralwhite:[255,250,240],forestgreen:[34,139,34],fuchsia:[255,0,255],gainsboro:[220,220,220],ghostwhite:[248,248,255],gold:[255,215,0],goldenrod:[218,165,32],gray:[128,128,128],green:[0,128,0],greenyellow:[173,255,47],grey:[128,128,128],honeydew:[240,255,240],hotpink:[255,105,180],indianred:[205,92,92],indigo:[75,0,130],ivory:[255,255,240],khaki:[240,230,140],lavender:[230,230,250],lavenderblush:[255,240,245],lawngreen:[124,252,0],lemonchiffon:[255,250,205],lightblue:[173,216,230],lightcoral:[240,128,128],lightcyan:[224,255,255],lightgoldenrodyellow:[250,250,210],lightgray:[211,211,211],lightgreen:[144,238,144],lightgrey:[211,211,211],lightpink:[255,182,193],lightsalmon:[255,160,122],lightseagreen:[32,178,170],lightskyblue:[135,206,250],lightslategray:[119,136,153],lightslategrey:[119,136,153],lightsteelblue:[176,196,222],lightyellow:[255,255,224],lime:[0,255,0],limegreen:[50,205,50],linen:[250,240,230],magenta:[255,0,255],maroon:[128,0,0],mediumaquamarine:[102,205,170],mediumblue:[0,0,205],mediumorchid:[186,85,211],mediumpurple:[147,112,219],mediumseagreen:[60,179,113],mediumslateblue:[123,104,238],mediumspringgreen:[0,250,154],mediumturquoise:[72,209,204],mediumvioletred:[199,21,133],midnightblue:[25,25,112],mintcream:[245,255,250],mistyrose:[255,228,225],moccasin:[255,228,181],navajowhite:[255,222,173],navy:[0,0,128],oldlace:[253,245,230],olive:[128,128,0],olivedrab:[107,142,35],orange:[255,165,0],orangered:[255,69,0],orchid:[218,112,214],palegoldenrod:[238,232,170],palegreen:[152,251,152],paleturquoise:[175,238,238],palevioletred:[219,112,147],papayawhip:[255,239,213],peachpuff:[255,218,185],peru:[205,133,63],pink:[255,192,203],plum:[221,160,221],powderblue:[176,224,230],purple:[128,0,128],rebeccapurple:[102,51,153],red:[255,0,0],rosybrown:[188,143,143],royalblue:[65,105,225],saddlebrown:[139,69,19],salmon:[250,128,114],sandybrown:[244,164,96],seagreen:[46,139,87],seashell:[255,245,238],sienna:[160,82,45],silver:[192,192,192],skyblue:[135,206,235],slateblue:[106,90,205],slategray:[112,128,144],slategrey:[112,128,144],snow:[255,250,250],springgreen:[0,255,127],steelblue:[70,130,180],tan:[210,180,140],teal:[0,128,128],thistle:[216,191,216],tomato:[255,99,71],turquoise:[64,224,208],violet:[238,130,238],wheat:[245,222,179],white:[255,255,255],whitesmoke:[245,245,245],yellow:[255,255,0],yellowgreen:[154,205,50]},exports.rec_2020_to_XYZ_D50=function rec_2020_to_XYZ_D50(t){let n=t;var _;return n=[lin_2020_channel((_=n)[0]),lin_2020_channel(_[1]),lin_2020_channel(_[2])],n=multiplyMatrices(a,n),n=D65_to_D50(n),n},exports.sRGB_to_XYZ_D50=function sRGB_to_XYZ_D50(t){let n=t;return n=lin_sRGB(n),n=lin_sRGB_to_XYZ(n),n=D65_to_D50(n),n}; + */,exports.mapGamutRayTrace=function mapGamutRayTrace(t,n,_){const o=t[0],e=t[2];let r=n(t);const a=n([o,0,e]);for(let t=0;t<4;t++){if(t>0){const t=_(r);t[0]=o,t[2]=e,r=n(t)}const i=rayTraceBox(a,r);if(!i)break;r=i}return clip(r)},exports.namedColors={aliceblue:[240,248,255],antiquewhite:[250,235,215],aqua:[0,255,255],aquamarine:[127,255,212],azure:[240,255,255],beige:[245,245,220],bisque:[255,228,196],black:[0,0,0],blanchedalmond:[255,235,205],blue:[0,0,255],blueviolet:[138,43,226],brown:[165,42,42],burlywood:[222,184,135],cadetblue:[95,158,160],chartreuse:[127,255,0],chocolate:[210,105,30],coral:[255,127,80],cornflowerblue:[100,149,237],cornsilk:[255,248,220],crimson:[220,20,60],cyan:[0,255,255],darkblue:[0,0,139],darkcyan:[0,139,139],darkgoldenrod:[184,134,11],darkgray:[169,169,169],darkgreen:[0,100,0],darkgrey:[169,169,169],darkkhaki:[189,183,107],darkmagenta:[139,0,139],darkolivegreen:[85,107,47],darkorange:[255,140,0],darkorchid:[153,50,204],darkred:[139,0,0],darksalmon:[233,150,122],darkseagreen:[143,188,143],darkslateblue:[72,61,139],darkslategray:[47,79,79],darkslategrey:[47,79,79],darkturquoise:[0,206,209],darkviolet:[148,0,211],deeppink:[255,20,147],deepskyblue:[0,191,255],dimgray:[105,105,105],dimgrey:[105,105,105],dodgerblue:[30,144,255],firebrick:[178,34,34],floralwhite:[255,250,240],forestgreen:[34,139,34],fuchsia:[255,0,255],gainsboro:[220,220,220],ghostwhite:[248,248,255],gold:[255,215,0],goldenrod:[218,165,32],gray:[128,128,128],green:[0,128,0],greenyellow:[173,255,47],grey:[128,128,128],honeydew:[240,255,240],hotpink:[255,105,180],indianred:[205,92,92],indigo:[75,0,130],ivory:[255,255,240],khaki:[240,230,140],lavender:[230,230,250],lavenderblush:[255,240,245],lawngreen:[124,252,0],lemonchiffon:[255,250,205],lightblue:[173,216,230],lightcoral:[240,128,128],lightcyan:[224,255,255],lightgoldenrodyellow:[250,250,210],lightgray:[211,211,211],lightgreen:[144,238,144],lightgrey:[211,211,211],lightpink:[255,182,193],lightsalmon:[255,160,122],lightseagreen:[32,178,170],lightskyblue:[135,206,250],lightslategray:[119,136,153],lightslategrey:[119,136,153],lightsteelblue:[176,196,222],lightyellow:[255,255,224],lime:[0,255,0],limegreen:[50,205,50],linen:[250,240,230],magenta:[255,0,255],maroon:[128,0,0],mediumaquamarine:[102,205,170],mediumblue:[0,0,205],mediumorchid:[186,85,211],mediumpurple:[147,112,219],mediumseagreen:[60,179,113],mediumslateblue:[123,104,238],mediumspringgreen:[0,250,154],mediumturquoise:[72,209,204],mediumvioletred:[199,21,133],midnightblue:[25,25,112],mintcream:[245,255,250],mistyrose:[255,228,225],moccasin:[255,228,181],navajowhite:[255,222,173],navy:[0,0,128],oldlace:[253,245,230],olive:[128,128,0],olivedrab:[107,142,35],orange:[255,165,0],orangered:[255,69,0],orchid:[218,112,214],palegoldenrod:[238,232,170],palegreen:[152,251,152],paleturquoise:[175,238,238],palevioletred:[219,112,147],papayawhip:[255,239,213],peachpuff:[255,218,185],peru:[205,133,63],pink:[255,192,203],plum:[221,160,221],powderblue:[176,224,230],purple:[128,0,128],rebeccapurple:[102,51,153],red:[255,0,0],rosybrown:[188,143,143],royalblue:[65,105,225],saddlebrown:[139,69,19],salmon:[250,128,114],sandybrown:[244,164,96],seagreen:[46,139,87],seashell:[255,245,238],sienna:[160,82,45],silver:[192,192,192],skyblue:[135,206,235],slateblue:[106,90,205],slategray:[112,128,144],slategrey:[112,128,144],snow:[255,250,250],springgreen:[0,255,127],steelblue:[70,130,180],tan:[210,180,140],teal:[0,128,128],thistle:[216,191,216],tomato:[255,99,71],turquoise:[64,224,208],violet:[238,130,238],wheat:[245,222,179],white:[255,255,255],whitesmoke:[245,245,245],yellow:[255,255,0],yellowgreen:[154,205,50]},exports.rec_2020_to_XYZ_D50=function rec_2020_to_XYZ_D50(t){let n=t;var _;return n=[lin_2020_channel((_=n)[0]),lin_2020_channel(_[1]),lin_2020_channel(_[2])],n=multiplyMatrices(Y,n),n=D65_to_D50(n),n},exports.sRGB_to_XYZ_D50=function sRGB_to_XYZ_D50(t){let n=t;return n=lin_sRGB(n),n=lin_sRGB_to_XYZ(n),n=D65_to_D50(n),n}; diff --git a/packages/color-helpers/dist/index.mjs b/packages/color-helpers/dist/index.mjs index 56332f62e..3dbd2bc46 100644 --- a/packages/color-helpers/dist/index.mjs +++ b/packages/color-helpers/dist/index.mjs @@ -1,10 +1,16 @@ -function multiplyMatrices(t,n){return[t[0]*n[0]+t[1]*n[1]+t[2]*n[2],t[3]*n[0]+t[4]*n[1]+t[5]*n[2],t[6]*n[0]+t[7]*n[1]+t[8]*n[2]]}const t=[1.0479297925449969,.022946870601609652,-.05019226628920524,.02962780877005599,.9904344267538799,-.017073799063418826,-.009243040646204504,.015055191490298152,.7518742814281371]; +function multiplyMatrices(t,n){return[t[0]*n[0]+t[1]*n[1]+t[2]*n[2],t[3]*n[0]+t[4]*n[1]+t[5]*n[2],t[6]*n[0]+t[7]*n[1]+t[8]*n[2]]}const t=[.955473421488075,-.02309845494876471,.06325924320057072,-.0283697093338637,1.0099953980813041,.021041441191917323,.012314014864481998,-.020507649298898964,1.330365926242124]; +/** + * Bradford chromatic adaptation from D50 to D65 + * + * @license W3C https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document + * @copyright This software or document includes material copied from or derived from https://github.com/w3c/csswg-drafts/blob/main/css-color-4/conversions.js. Copyright © 2022 W3C® (MIT, ERCIM, Keio, Beihang). + */function D50_to_D65(n){return multiplyMatrices(t,n)}const n=[1.0479297925449969,.022946870601609652,-.05019226628920524,.02962780877005599,.9904344267538799,-.017073799063418826,-.009243040646204504,.015055191490298152,.7518742814281371]; /** * Bradford chromatic adaptation from D65 to D50 * @license W3C https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document * @copyright This software or document includes material copied from or derived from https://github.com/w3c/csswg-drafts/blob/main/css-color-4/conversions.js. Copyright © 2022 W3C® (MIT, ERCIM, Keio, Beihang). * @see http://www.brucelindbloom.com/index.html?Eqn_ChromAdapt.html - */function D65_to_D50(n){return multiplyMatrices(t,n)} + */function D65_to_D50(t){return multiplyMatrices(n,t)} /** * @param {number} hue - Hue as degrees 0..360 * @param {number} sat - Saturation as percentage 0..100 @@ -28,116 +34,86 @@ function multiplyMatrices(t,n){return[t[0]*n[0]+t[1]*n[1]+t[2]*n[2],t[3]*n[0]+t[ /** * @license W3C https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document * @copyright This software or document includes material copied from or derived from https://github.com/w3c/csswg-drafts/blob/main/css-color-4/conversions.js. Copyright © 2022 W3C® (MIT, ERCIM, Keio, Beihang). - */function LCH_to_Lab(t){const n=t[2]*Math.PI/180;return[t[0],t[1]*Math.cos(n),t[1]*Math.sin(n)]}const n=[.3457/.3585,1,.2958/.3585]; + */function LCH_to_Lab(t){const n=t[2]*Math.PI/180;return[t[0],t[1]*Math.cos(n),t[1]*Math.sin(n)]} /** - * Convert Lab to D50-adapted XYZ * @license W3C https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document * @copyright This software or document includes material copied from or derived from https://github.com/w3c/csswg-drafts/blob/main/css-color-4/conversions.js. Copyright © 2022 W3C® (MIT, ERCIM, Keio, Beihang). - * @see http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html - */function Lab_to_XYZ(t){const _=24389/27,o=216/24389,e=(t[0]+16)/116,a=t[1]/500+e,r=e-t[2]/200;return[(Math.pow(a,3)>o?Math.pow(a,3):(116*a-16)/_)*n[0],(t[0]>8?Math.pow((t[0]+16)/116,3):t[0]/_)*n[1],(Math.pow(r,3)>o?Math.pow(r,3):(116*r-16)/_)*n[2]]} + */function Lab_to_LCH(t){const n=180*Math.atan2(t[2],t[1])/Math.PI;return[t[0],Math.sqrt(Math.pow(t[1],2)+Math.pow(t[2],2)),n>=0?n:n+360]}const _=[.3457/.3585,1,.2958/.3585]; /** + * Convert Lab to D50-adapted XYZ * @license W3C https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document * @copyright This software or document includes material copied from or derived from https://github.com/w3c/csswg-drafts/blob/main/css-color-4/conversions.js. Copyright © 2022 W3C® (MIT, ERCIM, Keio, Beihang). - * @see https://github.com/w3c/csswg-drafts/blob/main/css-color-4/conversions.js - */function OKLCH_to_OKLab(t){const n=t[2]*Math.PI/180;return[t[0],t[1]*Math.cos(n),t[1]*Math.sin(n)]}const _=[1.2268798758459243,-.5578149944602171,.2813910456659647,-.0405757452148008,1.112286803280317,-.0717110580655164,-.0763729366746601,-.4214933324022432,1.5869240198367816],o=[1,.3963377773761749,.2158037573099136,1,-.1055613458156586,-.0638541728258133,1,-.0894841775298119,-1.2914855480194092]; + * @see http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html + */function Lab_to_XYZ(t){const n=24389/27,o=216/24389,e=(t[0]+16)/116,a=t[1]/500+e,r=e-t[2]/200;return[(Math.pow(a,3)>o?Math.pow(a,3):(116*a-16)/n)*_[0],(t[0]>8?Math.pow((t[0]+16)/116,3):t[0]/n)*_[1],(Math.pow(r,3)>o?Math.pow(r,3):(116*r-16)/n)*_[2]]} /** - * Given OKLab, convert to XYZ relative to D65 - * * @license W3C https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document * @copyright This software or document includes material copied from or derived from https://github.com/w3c/csswg-drafts/blob/main/css-color-4/conversions.js. Copyright © 2022 W3C® (MIT, ERCIM, Keio, Beihang). * @see https://github.com/w3c/csswg-drafts/blob/main/css-color-4/conversions.js - */ -function OKLab_to_XYZ(t){const n=multiplyMatrices(o,t);return multiplyMatrices(_,[n[0]**3,n[1]**3,n[2]**3])} + */function OKLCH_to_OKLab(t){const n=t[2]*Math.PI/180;return[t[0],t[1]*Math.cos(n),t[1]*Math.sin(n)]} /** - * Convert an array of rec2020 RGB values in the range 0.0 - 1.0 - * to linear light (un-companded) form. - * ITU-R BT.2020-2 p.4 - * * @license W3C https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document * @copyright This software or document includes material copied from or derived from https://github.com/w3c/csswg-drafts/blob/main/css-color-4/conversions.js. Copyright © 2022 W3C® (MIT, ERCIM, Keio, Beihang). - */const e=1.09929682680944,a=.018053968510807;function lin_2020_channel(t){const n=t<0?-1:1,_=Math.abs(t);return _<4.5*a?t/4.5:n*Math.pow((_+e-1)/e,1/.45)}const r=[63426534/99577255,20160776/139408157,47086771/278816314,26158966/99577255,.677998071518871,8267143/139408157,0,19567812/697040785,1.0609850577107909]; + * @see https://github.com/w3c/csswg-drafts/blob/main/css-color-4/conversions.js + */function OKLab_to_OKLCH(t){const n=180*Math.atan2(t[2],t[1])/Math.PI;return[t[0],Math.sqrt(t[1]**2+t[2]**2),n>=0?n:n+360]}const o=[1.2268798758459243,-.5578149944602171,.2813910456659647,-.0405757452148008,1.112286803280317,-.0717110580655164,-.0763729366746601,-.4214933324022432,1.5869240198367816],e=[1,.3963377773761749,.2158037573099136,1,-.1055613458156586,-.0638541728258133,1,-.0894841775298119,-1.2914855480194092]; /** - * Convert an array of linear-light rec2020 values to CIE XYZ - * using D65 (no chromatic adaptation) + * Given OKLab, convert to XYZ relative to D65 * * @license W3C https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document * @copyright This software or document includes material copied from or derived from https://github.com/w3c/csswg-drafts/blob/main/css-color-4/conversions.js. Copyright © 2022 W3C® (MIT, ERCIM, Keio, Beihang). - * @see http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html + * @see https://github.com/w3c/csswg-drafts/blob/main/css-color-4/conversions.js */ +function OKLab_to_XYZ(t){const n=multiplyMatrices(e,t);return multiplyMatrices(o,[n[0]**3,n[1]**3,n[2]**3])} /** - * Convert an array of of sRGB values where in-gamut values are in the range - * [0 - 1] to linear light (un-companded) form. - * Extended transfer function: - * For negative values, linear portion is extended on reflection of axis, - * then reflected power function is used. + * Assuming XYZ is relative to D50, convert to CIE Lab + * from CIE standard, which now defines these as a rational fraction * * @license W3C https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document * @copyright This software or document includes material copied from or derived from https://github.com/w3c/csswg-drafts/blob/main/css-color-4/conversions.js. Copyright © 2022 W3C® (MIT, ERCIM, Keio, Beihang). - * @see https://en.wikipedia.org/wiki/SRGB - */ -function lin_sRGB(t){return[lin_sRGB_channel(t[0]),lin_sRGB_channel(t[1]),lin_sRGB_channel(t[2])]}function lin_sRGB_channel(t){const n=t<0?-1:1,_=Math.abs(t);return _<=.04045?t/12.92:n*Math.pow((_+.055)/1.055,2.4)} + */function XYZ_to_Lab(t){const n=compute_f(t[0]/_[0]),o=compute_f(t[1]/_[1]);return[116*o-16,500*(n-o),200*(o-compute_f(t[2]/_[2]))]}const a=216/24389,r=24389/27;function compute_f(t){return t>a?Math.cbrt(t):(r*t+16)/116}const l=[.819022437996703,.3619062600528904,-.1288737815209879,.0329836539323885,.9292868615863434,.0361446663506424,.0481771893596242,.2642395317527308,.6335478284694309],i=[.210454268309314,.7936177747023054,-.0040720430116193,1.9779985324311684,-2.42859224204858,.450593709617411,.0259040424655478,.7827717124575296,-.8086757549230774]; /** - * Convert an array of display-p3 RGB values in the range 0.0 - 1.0 - * to linear light (un-companded) form. - * * @license W3C https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document * @copyright This software or document includes material copied from or derived from https://github.com/w3c/csswg-drafts/blob/main/css-color-4/conversions.js. Copyright © 2022 W3C® (MIT, ERCIM, Keio, Beihang). - */function lin_P3(t){return lin_sRGB(t)}const l=[608311/1250200,189793/714400,198249/1000160,35783/156275,247089/357200,198249/2500400,0,32229/714400,5220557/5000800]; -/** - * Convert an array of linear-light display-p3 values to CIE XYZ - * using D65 (no chromatic adaptation) * - * @license W3C https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document - * @copyright This software or document includes material copied from or derived from https://github.com/w3c/csswg-drafts/blob/main/css-color-4/conversions.js. Copyright © 2022 W3C® (MIT, ERCIM, Keio, Beihang). - * @see http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html - */function lin_P3_to_XYZ(t){return multiplyMatrices(l,t)} + * XYZ <-> LMS matrices recalculated for consistent reference white + * @see https://github.com/w3c/csswg-drafts/issues/6642#issuecomment-943521484 + */ +function XYZ_to_OKLab(t){const n=multiplyMatrices(l,t);return multiplyMatrices(i,[Math.cbrt(n[0]),Math.cbrt(n[1]),Math.cbrt(n[2])])}const c=[30757411/17917100,-6372589/17917100,-4539589/17917100,-.666684351832489,1.616481236634939,467509/29648200,792561/44930125,-1921689/44930125,.942103121235474]; /** - * Convert an array of prophoto-rgb values where in-gamut Colors are in the - * range [0.0 - 1.0] to linear light (un-companded) form. Transfer curve is - * gamma 1.8 with a small linear portion. Extended transfer function + * Convert XYZ to linear-light rec2020 * * @license W3C https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document * @copyright This software or document includes material copied from or derived from https://github.com/w3c/csswg-drafts/blob/main/css-color-4/conversions.js. Copyright © 2022 W3C® (MIT, ERCIM, Keio, Beihang). - */const i=16/512;function lin_ProPhoto_channel(t){const n=t<0?-1:1,_=Math.abs(t);return _<=i?t/16:n*Math.pow(_,1.8)}const c=[.7977666449006423,.13518129740053308,.0313477341283922,.2880748288194013,.711835234241873,8993693872564e-17,0,0,.8251046025104602]; + */const u=[446124/178915,-333277/357830,-72051/178915,-14852/17905,63121/35810,423/17905,11844/330415,-50337/660830,316169/330415]; /** - * Convert an array of linear-light prophoto-rgb values to CIE D50 XYZ. - * Matrix cannot be expressed in rational form, but is calculated to 64 bit accuracy. + * Convert XYZ to linear-light P3 * * @license W3C https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document * @copyright This software or document includes material copied from or derived from https://github.com/w3c/csswg-drafts/blob/main/css-color-4/conversions.js. Copyright © 2022 W3C® (MIT, ERCIM, Keio, Beihang). - * @see see https://github.com/w3c/csswg-drafts/issues/7675 - */function lin_a98rgb_channel(t){const n=t<0?-1:1,_=Math.abs(t);return n*Math.pow(_,563/256)}const u=[573536/994567,263643/1420810,187206/994567,591459/1989134,6239551/9945670,374412/4972835,53769/1989134,351524/4972835,4929758/4972835]; + */function XYZ_to_lin_P3(t){return multiplyMatrices(u,t)}const s=[1.3457868816471583,-.25557208737979464,-.05110186497554526,-.5446307051249019,1.5082477428451468,.02052744743642139,0,0,1.2119675456389452]; /** - * Convert an array of linear-light a98-rgb values to CIE XYZ - * http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html - * has greater numerical precision than section 4.3.5.3 of - * https://www.adobe.com/digitalimag/pdfs/AdobeRGB1998.pdf - * but the values below were calculated from first principles - * from the chromaticity coordinates of R G B W + * Convert D50 XYZ to linear-light prophoto-rgb * * @license W3C https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document * @copyright This software or document includes material copied from or derived from https://github.com/w3c/csswg-drafts/blob/main/css-color-4/conversions.js. Copyright © 2022 W3C® (MIT, ERCIM, Keio, Beihang). * @see http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html - * @see https://www.adobe.com/digitalimag/pdfs/AdobeRGB1998.pdf - * @see https://github.com/w3c/csswg-drafts/blob/main/css-color-4/matrixmaker.html - */const s=[506752/1228815,87881/245763,12673/70218,87098/409605,175762/245763,12673/175545,7918/409605,87881/737289,1001167/1053270]; + */const h=[1829569/896150,-506331/896150,-308931/896150,-851781/878810,1648619/878810,36519/878810,16779/1248040,-147721/1248040,1266979/1248040]; /** - * Convert an array of linear-light sRGB values to CIE XYZ - * using sRGB's own white, D65 (no chromatic adaptation) + * Convert XYZ to linear-light a98-rgb * * @license W3C https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document * @copyright This software or document includes material copied from or derived from https://github.com/w3c/csswg-drafts/blob/main/css-color-4/conversions.js. Copyright © 2022 W3C® (MIT, ERCIM, Keio, Beihang). - */function lin_sRGB_to_XYZ(t){return multiplyMatrices(s,t)}const h=[.955473421488075,-.02309845494876471,.06325924320057072,-.0283697093338637,1.0099953980813041,.021041441191917323,.012314014864481998,-.020507649298898964,1.330365926242124]; + */const m=[12831/3959,-329/214,-1974/3959,-851781/878810,1648619/878810,36519/878810,705/12673,-2585/12673,705/667]; /** - * Bradford chromatic adaptation from D50 to D65 - * * @license W3C https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document * @copyright This software or document includes material copied from or derived from https://github.com/w3c/csswg-drafts/blob/main/css-color-4/conversions.js. Copyright © 2022 W3C® (MIT, ERCIM, Keio, Beihang). - */function D50_to_D65(t){return multiplyMatrices(h,t)}const m=[12831/3959,-329/214,-1974/3959,-851781/878810,1648619/878810,36519/878810,705/12673,-2585/12673,705/667]; + */function XYZ_to_lin_sRGB(t){return multiplyMatrices(m,t)} /** + * Convert an array of linear-light rec2020 RGB in the range 0.0-1.0 + * to gamma corrected form ITU-R BT.2020-2 p.4 + * * @license W3C https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document * @copyright This software or document includes material copied from or derived from https://github.com/w3c/csswg-drafts/blob/main/css-color-4/conversions.js. Copyright © 2022 W3C® (MIT, ERCIM, Keio, Beihang). - */function XYZ_to_lin_sRGB(t){return multiplyMatrices(m,t)} + */const D=1.09929682680944,g=.018053968510807;function gam_2020_channel(t){const n=t<0?-1:1,_=Math.abs(t);return _>g?n*(D*Math.pow(_,.45)-(D-1)):4.5*t} /** * Convert an array of linear-light sRGB values in the range 0.0-1.0 to gamma corrected form * Extended transfer function: @@ -149,105 +125,129 @@ function lin_sRGB(t){return[lin_sRGB_channel(t[0]),lin_sRGB_channel(t[1]),lin_sR * @see https://en.wikipedia.org/wiki/SRGB */function gam_sRGB(t){return[gam_sRGB_channel(t[0]),gam_sRGB_channel(t[1]),gam_sRGB_channel(t[2])]}function gam_sRGB_channel(t){const n=t<0?-1:1,_=Math.abs(t);return _>.0031308?n*(1.055*Math.pow(_,1/2.4)-.055):12.92*t} /** - * Convert an array of gamma-corrected sRGB values in the 0.0 to 1.0 range to HSL. - * - * @param {Color} RGB [r, g, b] - * - Red component 0..1 - * - Green component 0..1 - * - Blue component 0..1 - * @return {number[]} Array of HSL values: Hue as degrees 0..360, Saturation and Lightness as percentages 0..100 + * Convert an array of linear-light display-p3 RGB in the range 0.0-1.0 + * to gamma corrected form * * @license W3C https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document - * @copyright This software or document includes material copied from or derived from https://github.com/w3c/csswg-drafts/blob/main/css-color-4/utilities.js. Copyright © 2022 W3C® (MIT, ERCIM, Keio, Beihang). - * - * @see https://github.com/w3c/csswg-drafts/blob/main/css-color-4/better-rgbToHsl.js - */function sRGB_to_HSL(t){const n=t[0],_=t[1],o=t[2],e=Math.max(n,_,o),a=Math.min(n,_,o),r=(a+e)/2,l=e-a;let i=NaN,c=0;if(0!==Math.round(1e5*l)){const t=Math.round(1e5*r);switch(c=0===t||1e5===t?0:(e-r)/Math.min(r,1-r),e){case n:i=(_-o)/l+(_=360&&(i-=360),[i,100*c,100*r]}const D=[446124/178915,-333277/357830,-72051/178915,-14852/17905,63121/35810,423/17905,11844/330415,-50337/660830,316169/330415]; + * @copyright This software or document includes material copied from or derived from https://github.com/w3c/csswg-drafts/blob/main/css-color-4/conversions.js. Copyright © 2022 W3C® (MIT, ERCIM, Keio, Beihang). + */function gam_P3(t){return gam_sRGB(t)} /** - * Convert XYZ to linear-light P3 + * Convert an array of linear-light prophoto-rgb in the range 0.0-1.0 + * to gamma corrected form. + * Transfer curve is gamma 1.8 with a small linear portion. * * @license W3C https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document * @copyright This software or document includes material copied from or derived from https://github.com/w3c/csswg-drafts/blob/main/css-color-4/conversions.js. Copyright © 2022 W3C® (MIT, ERCIM, Keio, Beihang). - */function XYZ_to_lin_P3(t){return multiplyMatrices(D,t)} + */const b=1/512;function gam_ProPhoto_channel(t){const n=t<0?-1:1,_=Math.abs(t);return _>=b?n*Math.pow(_,1/1.8):16*t} /** - * Convert an array of linear-light display-p3 RGB in the range 0.0-1.0 - * to gamma corrected form + * Convert an array of linear-light a98-rgb in the range 0.0-1.0 + * to gamma corrected form. Negative values are also now accepted * * @license W3C https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document * @copyright This software or document includes material copied from or derived from https://github.com/w3c/csswg-drafts/blob/main/css-color-4/conversions.js. Copyright © 2022 W3C® (MIT, ERCIM, Keio, Beihang). - */function gam_P3(t){return gam_sRGB(t)} + */function gam_a98rgb_channel(t){const n=t<0?-1:1,_=Math.abs(t);return n*Math.pow(_,256/563)} /** - * Assuming XYZ is relative to D50, convert to CIE Lab - * from CIE standard, which now defines these as a rational fraction + * Convert an array of rec2020 RGB values in the range 0.0 - 1.0 + * to linear light (un-companded) form. + * ITU-R BT.2020-2 p.4 * * @license W3C https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document * @copyright This software or document includes material copied from or derived from https://github.com/w3c/csswg-drafts/blob/main/css-color-4/conversions.js. Copyright © 2022 W3C® (MIT, ERCIM, Keio, Beihang). - */function XYZ_to_Lab(t){const _=compute_f(t[0]/n[0]),o=compute_f(t[1]/n[1]);return[116*o-16,500*(_-o),200*(o-compute_f(t[2]/n[2]))]}const g=216/24389,b=24389/27;function compute_f(t){return t>g?Math.cbrt(t):(b*t+16)/116}const f=[.819022437996703,.3619062600528904,-.1288737815209879,.0329836539323885,.9292868615863434,.0361446663506424,.0481771893596242,.2642395317527308,.6335478284694309],X=[.210454268309314,.7936177747023054,-.0040720430116193,1.9779985324311684,-2.42859224204858,.450593709617411,.0259040424655478,.7827717124575296,-.8086757549230774]; + */const f=1.09929682680944,X=.018053968510807;function lin_2020_channel(t){const n=t<0?-1:1,_=Math.abs(t);return _<4.5*X?t/4.5:n*Math.pow((_+f-1)/f,1/.45)}const Y=[63426534/99577255,20160776/139408157,47086771/278816314,26158966/99577255,.677998071518871,8267143/139408157,0,19567812/697040785,1.0609850577107909]; /** + * Convert an array of linear-light rec2020 values to CIE XYZ + * using D65 (no chromatic adaptation) + * * @license W3C https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document * @copyright This software or document includes material copied from or derived from https://github.com/w3c/csswg-drafts/blob/main/css-color-4/conversions.js. Copyright © 2022 W3C® (MIT, ERCIM, Keio, Beihang). - * - * XYZ <-> LMS matrices recalculated for consistent reference white - * @see https://github.com/w3c/csswg-drafts/issues/6642#issuecomment-943521484 + * @see http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html */ -function XYZ_to_OKLab(t){const n=multiplyMatrices(f,t);return multiplyMatrices(X,[Math.cbrt(n[0]),Math.cbrt(n[1]),Math.cbrt(n[2])])} /** + * Convert an array of of sRGB values where in-gamut values are in the range + * [0 - 1] to linear light (un-companded) form. + * Extended transfer function: + * For negative values, linear portion is extended on reflection of axis, + * then reflected power function is used. + * * @license W3C https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document * @copyright This software or document includes material copied from or derived from https://github.com/w3c/csswg-drafts/blob/main/css-color-4/conversions.js. Copyright © 2022 W3C® (MIT, ERCIM, Keio, Beihang). - */function Lab_to_LCH(t){const n=180*Math.atan2(t[2],t[1])/Math.PI;return[t[0],Math.sqrt(Math.pow(t[1],2)+Math.pow(t[2],2)),n>=0?n:n+360]} + * @see https://en.wikipedia.org/wiki/SRGB + */ +function lin_sRGB(t){return[lin_sRGB_channel(t[0]),lin_sRGB_channel(t[1]),lin_sRGB_channel(t[2])]}function lin_sRGB_channel(t){const n=t<0?-1:1,_=Math.abs(t);return _<=.04045?t/12.92:n*Math.pow((_+.055)/1.055,2.4)} /** + * Convert an array of display-p3 RGB values in the range 0.0 - 1.0 + * to linear light (un-companded) form. + * * @license W3C https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document * @copyright This software or document includes material copied from or derived from https://github.com/w3c/csswg-drafts/blob/main/css-color-4/conversions.js. Copyright © 2022 W3C® (MIT, ERCIM, Keio, Beihang). - * @see https://github.com/w3c/csswg-drafts/blob/main/css-color-4/conversions.js - */function OKLab_to_OKLCH(t){const n=180*Math.atan2(t[2],t[1])/Math.PI;return[t[0],Math.sqrt(t[1]**2+t[2]**2),n>=0?n:n+360]}const Y=[1829569/896150,-506331/896150,-308931/896150,-851781/878810,1648619/878810,36519/878810,16779/1248040,-147721/1248040,1266979/1248040]; + */function lin_P3(t){return lin_sRGB(t)}const Z=[608311/1250200,189793/714400,198249/1000160,35783/156275,247089/357200,198249/2500400,0,32229/714400,5220557/5000800]; /** - * Convert XYZ to linear-light a98-rgb + * Convert an array of linear-light display-p3 values to CIE XYZ + * using D65 (no chromatic adaptation) * * @license W3C https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document * @copyright This software or document includes material copied from or derived from https://github.com/w3c/csswg-drafts/blob/main/css-color-4/conversions.js. Copyright © 2022 W3C® (MIT, ERCIM, Keio, Beihang). - */function gam_a98rgb_channel(t){const n=t<0?-1:1,_=Math.abs(t);return n*Math.pow(_,256/563)}const Z=[30757411/17917100,-6372589/17917100,-4539589/17917100,-.666684351832489,1.616481236634939,467509/29648200,792561/44930125,-1921689/44930125,.942103121235474]; + * @see http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html + */function lin_P3_to_XYZ(t){return multiplyMatrices(Z,t)} /** - * Convert XYZ to linear-light rec2020 + * Convert an array of prophoto-rgb values where in-gamut Colors are in the + * range [0.0 - 1.0] to linear light (un-companded) form. Transfer curve is + * gamma 1.8 with a small linear portion. Extended transfer function * * @license W3C https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document * @copyright This software or document includes material copied from or derived from https://github.com/w3c/csswg-drafts/blob/main/css-color-4/conversions.js. Copyright © 2022 W3C® (MIT, ERCIM, Keio, Beihang). - */const p=1.09929682680944,M=.018053968510807;function gam_2020_channel(t){const n=t<0?-1:1,_=Math.abs(t);return _>M?n*(p*Math.pow(_,.45)-(p-1)):4.5*t}const d=[1.3457868816471583,-.25557208737979464,-.05110186497554526,-.5446307051249019,1.5082477428451468,.02052744743642139,0,0,1.2119675456389452]; + */const M=16/512;function lin_ProPhoto_channel(t){const n=t<0?-1:1,_=Math.abs(t);return _<=M?t/16:n*Math.pow(_,1.8)}const p=[.7977666449006423,.13518129740053308,.0313477341283922,.2880748288194013,.711835234241873,8993693872564e-17,0,0,.8251046025104602]; /** - * Convert D50 XYZ to linear-light prophoto-rgb + * Convert an array of linear-light prophoto-rgb values to CIE D50 XYZ. + * Matrix cannot be expressed in rational form, but is calculated to 64 bit accuracy. * * @license W3C https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document * @copyright This software or document includes material copied from or derived from https://github.com/w3c/csswg-drafts/blob/main/css-color-4/conversions.js. Copyright © 2022 W3C® (MIT, ERCIM, Keio, Beihang). - * @see http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html - */const L=1/512;function gam_ProPhoto_channel(t){const n=t<0?-1:1,_=Math.abs(t);return _>=L?n*Math.pow(_,1/1.8):16*t}function sRGB_to_XYZ_D50(t){let n=t;return n=lin_sRGB(n),n=lin_sRGB_to_XYZ(n),n=D65_to_D50(n),n}function XYZ_D50_to_sRGB(t){let n=t;return n=D50_to_D65(n),n=XYZ_to_lin_sRGB(n),n=gam_sRGB(n),n}function HSL_to_XYZ_D50(t){let n=t;return n=HSL_to_sRGB(n),n=lin_sRGB(n),n=lin_sRGB_to_XYZ(n),n=D65_to_D50(n),n}function XYZ_D50_to_HSL(t){let n=t;return n=D50_to_D65(n),n=XYZ_to_lin_sRGB(n),n=gam_sRGB(n),n=sRGB_to_HSL(n),n}function HWB_to_XYZ_D50(t){let n=t;return n=HWB_to_sRGB(n),n=lin_sRGB(n),n=lin_sRGB_to_XYZ(n),n=D65_to_D50(n),n}function XYZ_D50_to_HWB(t){let n=t;n=D50_to_D65(n),n=XYZ_to_lin_sRGB(n);const _=gam_sRGB(n);n=sRGB_to_HSL(_);const o=Math.min(_[0],_[1],_[2]),e=1-Math.max(_[0],_[1],_[2]);return[n[0],100*o,100*e]}function Lab_to_XYZ_D50(t){let n=t;return n=Lab_to_XYZ(n),n}function XYZ_D50_to_Lab(t){let n=t;return n=XYZ_to_Lab(n),n}function LCH_to_XYZ_D50(t){let n=t;return n=LCH_to_Lab(n),n=Lab_to_XYZ(n),n}function XYZ_D50_to_LCH(t){let n=t;return n=XYZ_to_Lab(n),n=Lab_to_LCH(n),n}function OKLab_to_XYZ_D50(t){let n=t;return n=OKLab_to_XYZ(n),n=D65_to_D50(n),n}function XYZ_D50_to_OKLab(t){let n=t;return n=D50_to_D65(n),n=XYZ_to_OKLab(n),n}function OKLCH_to_XYZ_D50(t){let n=t;return n=OKLCH_to_OKLab(n),n=OKLab_to_XYZ(n),n=D65_to_D50(n),n}function XYZ_D50_to_OKLCH(t){let n=t;return n=D50_to_D65(n),n=XYZ_to_OKLab(n),n=OKLab_to_OKLCH(n),n}function lin_sRGB_to_XYZ_D50(t){let n=t;return n=lin_sRGB_to_XYZ(n),n=D65_to_D50(n),n}function XYZ_D50_to_lin_sRGB(t){let n=t;return n=D50_to_D65(n),n=XYZ_to_lin_sRGB(n),n}function a98_RGB_to_XYZ_D50(t){let n=t; + * @see see https://github.com/w3c/csswg-drafts/issues/7675 + */function lin_a98rgb_channel(t){const n=t<0?-1:1,_=Math.abs(t);return n*Math.pow(_,563/256)}const d=[573536/994567,263643/1420810,187206/994567,591459/1989134,6239551/9945670,374412/4972835,53769/1989134,351524/4972835,4929758/4972835]; /** - * Convert an array of a98-rgb values in the range 0.0 - 1.0 - * to linear light (un-companded) form. Negative values are also now accepted + * Convert an array of linear-light a98-rgb values to CIE XYZ + * http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html + * has greater numerical precision than section 4.3.5.3 of + * https://www.adobe.com/digitalimag/pdfs/AdobeRGB1998.pdf + * but the values below were calculated from first principles + * from the chromaticity coordinates of R G B W * * @license W3C https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document * @copyright This software or document includes material copied from or derived from https://github.com/w3c/csswg-drafts/blob/main/css-color-4/conversions.js. Copyright © 2022 W3C® (MIT, ERCIM, Keio, Beihang). - */ -var _;return n=[lin_a98rgb_channel((_=n)[0]),lin_a98rgb_channel(_[1]),lin_a98rgb_channel(_[2])],n=multiplyMatrices(u,n),n=D65_to_D50(n),n}function XYZ_D50_to_a98_RGB(t){let n=t;var _; + * @see http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html + * @see https://www.adobe.com/digitalimag/pdfs/AdobeRGB1998.pdf + * @see https://github.com/w3c/csswg-drafts/blob/main/css-color-4/matrixmaker.html + */const L=[506752/1228815,87881/245763,12673/70218,87098/409605,175762/245763,12673/175545,7918/409605,87881/737289,1001167/1053270]; /** - * Convert an array of linear-light a98-rgb in the range 0.0-1.0 - * to gamma corrected form. Negative values are also now accepted + * Convert an array of linear-light sRGB values to CIE XYZ + * using sRGB's own white, D65 (no chromatic adaptation) * * @license W3C https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document * @copyright This software or document includes material copied from or derived from https://github.com/w3c/csswg-drafts/blob/main/css-color-4/conversions.js. Copyright © 2022 W3C® (MIT, ERCIM, Keio, Beihang). - */return n=D50_to_D65(n),n=multiplyMatrices(Y,n),n=[gam_a98rgb_channel((_=n)[0]),gam_a98rgb_channel(_[1]),gam_a98rgb_channel(_[2])],n}function P3_to_XYZ_D50(t){let n=t;return n=lin_P3(n),n=lin_P3_to_XYZ(n),n=D65_to_D50(n),n}function XYZ_D50_to_P3(t){let n=t;return n=D50_to_D65(n),n=XYZ_to_lin_P3(n),n=gam_P3(n),n}function rec_2020_to_XYZ_D50(t){let n=t;var _;return n=[lin_2020_channel((_=n)[0]),lin_2020_channel(_[1]),lin_2020_channel(_[2])],n=multiplyMatrices(r,n),n=D65_to_D50(n),n}function XYZ_D50_to_rec_2020(t){let n=t;var _; + */function lin_sRGB_to_XYZ(t){return multiplyMatrices(L,t)} /** - * Convert an array of linear-light rec2020 RGB in the range 0.0-1.0 - * to gamma corrected form ITU-R BT.2020-2 p.4 + * Convert an array of gamma-corrected sRGB values in the 0.0 to 1.0 range to HSL. + * + * @param {Color} RGB [r, g, b] + * - Red component 0..1 + * - Green component 0..1 + * - Blue component 0..1 + * @return {number[]} Array of HSL values: Hue as degrees 0..360, Saturation and Lightness as percentages 0..100 * * @license W3C https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document - * @copyright This software or document includes material copied from or derived from https://github.com/w3c/csswg-drafts/blob/main/css-color-4/conversions.js. Copyright © 2022 W3C® (MIT, ERCIM, Keio, Beihang). - */return n=D50_to_D65(n),n=multiplyMatrices(Z,n),n=[gam_2020_channel((_=n)[0]),gam_2020_channel(_[1]),gam_2020_channel(_[2])],n}function ProPhoto_RGB_to_XYZ_D50(t){let n=t;var _;return n=[lin_ProPhoto_channel((_=n)[0]),lin_ProPhoto_channel(_[1]),lin_ProPhoto_channel(_[2])],n=multiplyMatrices(c,n),n}function XYZ_D50_to_ProPhoto(t){let n=t;var _; + * @copyright This software or document includes material copied from or derived from https://github.com/w3c/csswg-drafts/blob/main/css-color-4/utilities.js. Copyright © 2022 W3C® (MIT, ERCIM, Keio, Beihang). + * + * @see https://github.com/w3c/csswg-drafts/blob/main/css-color-4/better-rgbToHsl.js + */function sRGB_to_HSL(t){const n=t[0],_=t[1],o=t[2],e=Math.max(n,_,o),a=Math.min(n,_,o),r=(a+e)/2,l=e-a;let i=NaN,c=0;if(0!==Math.round(1e5*l)){const t=Math.round(1e5*r);switch(c=0===t||1e5===t?0:(e-r)/Math.min(r,1-r),e){case n:i=(_-o)/l+(_=360&&(i-=360),[i,100*c,100*r]}function sRGB_to_Hue(t){const n=t[0],_=t[1],o=t[2],e=Math.max(n,_,o);let a=NaN;const r=e-Math.min(n,_,o);if(0!==r){switch(e){case n:a=(_-o)/r+(_=360&&(a-=360),a}function sRGB_to_XYZ_D50(t){let n=t;return n=lin_sRGB(n),n=lin_sRGB_to_XYZ(n),n=D65_to_D50(n),n}function XYZ_D50_to_sRGB(t){let n=t;return n=D50_to_D65(n),n=XYZ_to_lin_sRGB(n),n=gam_sRGB(n),n}function HSL_to_XYZ_D50(t){let n=t;return n=HSL_to_sRGB(n),n=lin_sRGB(n),n=lin_sRGB_to_XYZ(n),n=D65_to_D50(n),n}function XYZ_D50_to_HSL(t){let n=t;return n=D50_to_D65(n),n=XYZ_to_lin_sRGB(n),n=gam_sRGB(n),n=sRGB_to_HSL(n),n}function HWB_to_XYZ_D50(t){let n=t;return n=HWB_to_sRGB(n),n=lin_sRGB(n),n=lin_sRGB_to_XYZ(n),n=D65_to_D50(n),n}function XYZ_D50_to_HWB(t){let n=t;n=D50_to_D65(n),n=XYZ_to_lin_sRGB(n);const _=gam_sRGB(n),o=Math.min(_[0],_[1],_[2]),e=1-Math.max(_[0],_[1],_[2]);return[sRGB_to_Hue(_),100*o,100*e]}function Lab_to_XYZ_D50(t){let n=t;return n=Lab_to_XYZ(n),n}function XYZ_D50_to_Lab(t){let n=t;return n=XYZ_to_Lab(n),n}function LCH_to_XYZ_D50(t){let n=t;return n=LCH_to_Lab(n),n=Lab_to_XYZ(n),n}function XYZ_D50_to_LCH(t){let n=t;return n=XYZ_to_Lab(n),n=Lab_to_LCH(n),n}function OKLab_to_XYZ_D50(t){let n=t;return n=OKLab_to_XYZ(n),n=D65_to_D50(n),n}function XYZ_D50_to_OKLab(t){let n=t;return n=D50_to_D65(n),n=XYZ_to_OKLab(n),n}function OKLCH_to_XYZ_D50(t){let n=t;return n=OKLCH_to_OKLab(n),n=OKLab_to_XYZ(n),n=D65_to_D50(n),n}function XYZ_D50_to_OKLCH(t){let n=t;return n=D50_to_D65(n),n=XYZ_to_OKLab(n),n=OKLab_to_OKLCH(n),n}function lin_sRGB_to_XYZ_D50(t){let n=t;return n=lin_sRGB_to_XYZ(n),n=D65_to_D50(n),n}function XYZ_D50_to_lin_sRGB(t){let n=t;return n=D50_to_D65(n),n=XYZ_to_lin_sRGB(n),n}function a98_RGB_to_XYZ_D50(t){let n=t; /** - * Convert an array of linear-light prophoto-rgb in the range 0.0-1.0 - * to gamma corrected form. - * Transfer curve is gamma 1.8 with a small linear portion. + * Convert an array of a98-rgb values in the range 0.0 - 1.0 + * to linear light (un-companded) form. Negative values are also now accepted * * @license W3C https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document * @copyright This software or document includes material copied from or derived from https://github.com/w3c/csswg-drafts/blob/main/css-color-4/conversions.js. Copyright © 2022 W3C® (MIT, ERCIM, Keio, Beihang). - */return n=multiplyMatrices(d,n),n=[gam_ProPhoto_channel((_=n)[0]),gam_ProPhoto_channel(_[1]),gam_ProPhoto_channel(_[2])],n}function XYZ_D65_to_XYZ_D50(t){let n=t;return n=D65_to_D50(n),n}function XYZ_D50_to_XYZ_D65(t){let n=t;return n=D50_to_D65(n),n}function XYZ_D50_to_XYZ_D50(t){return t}function inGamut(t){return t[0]>=-1e-4&&t[0]<=1.0001&&t[1]>=-1e-4&&t[1]<=1.0001&&t[2]>=-1e-4&&t[2]<=1.0001}function clip(t){return[t[0]<0?0:t[0]>1?1:t[0],t[1]<0?0:t[1]>1?1:t[1],t[2]<0?0:t[2]>1?1:t[2]]} + */ +var _;return n=[lin_a98rgb_channel((_=n)[0]),lin_a98rgb_channel(_[1]),lin_a98rgb_channel(_[2])],n=multiplyMatrices(d,n),n=D65_to_D50(n),n}function XYZ_D50_to_a98_RGB(t){let n=t;var _;return n=D50_to_D65(n),n=multiplyMatrices(h,n),n=[gam_a98rgb_channel((_=n)[0]),gam_a98rgb_channel(_[1]),gam_a98rgb_channel(_[2])],n}function P3_to_XYZ_D50(t){let n=t;return n=lin_P3(n),n=lin_P3_to_XYZ(n),n=D65_to_D50(n),n}function XYZ_D50_to_P3(t){let n=t;return n=D50_to_D65(n),n=XYZ_to_lin_P3(n),n=gam_P3(n),n}function rec_2020_to_XYZ_D50(t){let n=t;var _;return n=[lin_2020_channel((_=n)[0]),lin_2020_channel(_[1]),lin_2020_channel(_[2])],n=multiplyMatrices(Y,n),n=D65_to_D50(n),n}function XYZ_D50_to_rec_2020(t){let n=t;var _;return n=D50_to_D65(n),n=multiplyMatrices(c,n),n=[gam_2020_channel((_=n)[0]),gam_2020_channel(_[1]),gam_2020_channel(_[2])],n}function ProPhoto_RGB_to_XYZ_D50(t){let n=t;var _;return n=[lin_ProPhoto_channel((_=n)[0]),lin_ProPhoto_channel(_[1]),lin_ProPhoto_channel(_[2])],n=multiplyMatrices(p,n),n}function XYZ_D50_to_ProPhoto(t){let n=t;var _;return n=multiplyMatrices(s,n),n=[gam_ProPhoto_channel((_=n)[0]),gam_ProPhoto_channel(_[1]),gam_ProPhoto_channel(_[2])],n}function XYZ_D65_to_XYZ_D50(t){let n=t;return n=D65_to_D50(n),n}function XYZ_D50_to_XYZ_D65(t){let n=t;return n=D50_to_D65(n),n}function XYZ_D50_to_XYZ_D50(t){return t}function inGamut(t){return t[0]>=-1e-4&&t[0]<=1.0001&&t[1]>=-1e-4&&t[1]<=1.0001&&t[2]>=-1e-4&&t[2]<=1.0001}function clip(t){return[t[0]<0?0:t[0]>1?1:t[0],t[1]<0?0:t[1]>1?1:t[1],t[2]<0?0:t[2]>1?1:t[2]]} /** * @description Calculate deltaE OK which is the simple root sum of squares * @param {number[]} reference - Array of OKLab values: L as 0..1, a and b as -1..1 diff --git a/packages/color-helpers/scripts/check-changes.mjs b/packages/color-helpers/scripts/check-changes.mjs index 6a8caaa50..a4a960da3 100644 --- a/packages/color-helpers/scripts/check-changes.mjs +++ b/packages/color-helpers/scripts/check-changes.mjs @@ -16,6 +16,7 @@ const WATCHED_FILES = [ 'https://raw.githubusercontent.com/w3c/csswg-drafts/main/css-color-4/hslToRgb.js', 'https://raw.githubusercontent.com/w3c/csswg-drafts/main/css-color-4/better-rgbToHsl.js', 'https://raw.githubusercontent.com/w3c/csswg-drafts/main/css-color-4/hwbToRgb.js', + 'https://raw.githubusercontent.com/w3c/csswg-drafts/main/css-color-4/rgbToHwb.js', ]; const newHashes = await Promise.all(WATCHED_FILES.map(async urlPath => { diff --git a/packages/color-helpers/scripts/hashes.json b/packages/color-helpers/scripts/hashes.json index c00396a4c..2f8eabfee 100644 --- a/packages/color-helpers/scripts/hashes.json +++ b/packages/color-helpers/scripts/hashes.json @@ -3,7 +3,8 @@ "cd99f5e1c28fc9df18684e351049e7a6", "094c9859b0960c4e394947cc4832b54f", "c9e2f2a3b2cba543a01cb8aa5d77c04a", - "1d05413ce5d8b0669b6048f87338b106", + "7aba804ac76ce5d733956b4251194344", "d575d036af8c4a813217192a15982021", - "f912dea8d7d9813556f3ece0730f5392" + "f912dea8d7d9813556f3ece0730f5392", + "45dd3fb5a146c0865a4ed06d4d230eb0" ] \ No newline at end of file diff --git a/packages/color-helpers/src/conversions/srgb-to-hue.ts b/packages/color-helpers/src/conversions/srgb-to-hue.ts new file mode 100644 index 000000000..47a055a33 --- /dev/null +++ b/packages/color-helpers/src/conversions/srgb-to-hue.ts @@ -0,0 +1,28 @@ +import type { Color } from "../types/color"; + +export function sRGB_to_Hue(x: Color): number { + const red = x[0]; + const green = x[1]; + const blue = x[2]; + + const max = Math.max(red, green, blue); + const min = Math.min(red, green, blue); + let hue = NaN; + const d = max - min; + + if (d !== 0) { + switch (max) { + case red: hue = (green - blue) / d + (green < blue ? 6 : 0); break; + case green: hue = (blue - red) / d + 2; break; + case blue: hue = (red - green) / d + 4; + } + + hue *= 60; + } + + if (hue >= 360) { + hue -= 360; + } + + return hue; +} diff --git a/packages/color-helpers/src/conversions/xyz/index.ts b/packages/color-helpers/src/conversions/xyz/index.ts index 28f5c5a27..f4cc7535e 100644 --- a/packages/color-helpers/src/conversions/xyz/index.ts +++ b/packages/color-helpers/src/conversions/xyz/index.ts @@ -1,37 +1,38 @@ import type { Color } from '../../types/color'; -import { D65_to_D50 } from '../../conversions/d65-to-d50'; -import { HSL_to_sRGB } from '../../conversions/hsl-to-srgb'; -import { HWB_to_sRGB } from '../../conversions/hwb-to-srgb'; -import { LCH_to_Lab } from '../../conversions/lch-to-lab'; -import { Lab_to_XYZ } from '../../conversions/lab-to-xyz'; -import { OKLCH_to_OKLab } from '../../conversions/oklch-to-oklab'; -import { OKLab_to_XYZ } from '../../conversions/oklab-to-xyz'; -import { lin_2020 } from '../../conversions/lin-2020'; -import { lin_2020_to_XYZ } from '../../conversions/lin-2020-to-xyz'; -import { lin_P3 } from '../../conversions/lin-p3'; -import { lin_P3_to_XYZ } from '../../conversions/lin-p3-to-xyz'; -import { lin_ProPhoto } from '../../conversions/lin-pro-photo'; -import { lin_ProPhoto_to_XYZ } from '../../conversions/lin-pro-photo-to-xyz'; -import { lin_a98rgb } from '../../conversions/lin-a98rgb'; -import { lin_a98rgb_to_XYZ } from '../../conversions/lin-a98rgb-to-xyz'; -import { lin_sRGB } from '../../conversions/lin-srgb'; -import { lin_sRGB_to_XYZ } from '../../conversions/lin-srgb-to-xyz'; -import { D50_to_D65 } from '../../conversions/d50-to-d65'; -import { XYZ_to_lin_sRGB } from '../../conversions/xyz-to-lin-srgb'; -import { gam_sRGB } from '../../conversions/gam-srgb'; -import { sRGB_to_HSL } from '../../conversions/srgb-to-hsl'; -import { XYZ_to_lin_P3 } from '../../conversions/xyz-to-lin-p3'; -import { gam_P3 } from '../../conversions/gam-p3'; -import { XYZ_to_Lab } from '../../conversions/xyz-to-lab'; -import { XYZ_to_OKLab } from '../../conversions/xyz-to-oklab'; -import { Lab_to_LCH } from '../../conversions/lab-to-lch'; -import { OKLab_to_OKLCH } from '../../conversions/oklab-to-oklch'; -import { XYZ_to_lin_a98rgb } from '../../conversions/xyz-to-lin-a98rgb'; -import { gam_a98rgb } from '../../conversions/gam-a98rgb'; -import { XYZ_to_lin_2020 } from '../../conversions/xyz-to-lin-2020'; -import { gam_2020 } from '../../conversions/gam-2020'; -import { XYZ_to_lin_ProPhoto } from '../../conversions/xyz-to-lin-pro-photo'; -import { gam_ProPhoto } from '../../conversions/gam-pro-photo'; +import { D50_to_D65 } from '../d50-to-d65'; +import { D65_to_D50 } from '../d65-to-d50'; +import { HSL_to_sRGB } from '../hsl-to-srgb'; +import { HWB_to_sRGB } from '../hwb-to-srgb'; +import { LCH_to_Lab } from '../lch-to-lab'; +import { Lab_to_LCH } from '../lab-to-lch'; +import { Lab_to_XYZ } from '../lab-to-xyz'; +import { OKLCH_to_OKLab } from '../oklch-to-oklab'; +import { OKLab_to_OKLCH } from '../oklab-to-oklch'; +import { OKLab_to_XYZ } from '../oklab-to-xyz'; +import { XYZ_to_Lab } from '../xyz-to-lab'; +import { XYZ_to_OKLab } from '../xyz-to-oklab'; +import { XYZ_to_lin_2020 } from '../xyz-to-lin-2020'; +import { XYZ_to_lin_P3 } from '../xyz-to-lin-p3'; +import { XYZ_to_lin_ProPhoto } from '../xyz-to-lin-pro-photo'; +import { XYZ_to_lin_a98rgb } from '../xyz-to-lin-a98rgb'; +import { XYZ_to_lin_sRGB } from '../xyz-to-lin-srgb'; +import { gam_2020 } from '../gam-2020'; +import { gam_P3 } from '../gam-p3'; +import { gam_ProPhoto } from '../gam-pro-photo'; +import { gam_a98rgb } from '../gam-a98rgb'; +import { gam_sRGB } from '../gam-srgb'; +import { lin_2020 } from '../lin-2020'; +import { lin_2020_to_XYZ } from '../lin-2020-to-xyz'; +import { lin_P3 } from '../lin-p3'; +import { lin_P3_to_XYZ } from '../lin-p3-to-xyz'; +import { lin_ProPhoto } from '../lin-pro-photo'; +import { lin_ProPhoto_to_XYZ } from '../lin-pro-photo-to-xyz'; +import { lin_a98rgb } from '../lin-a98rgb'; +import { lin_a98rgb_to_XYZ } from '../lin-a98rgb-to-xyz'; +import { lin_sRGB } from '../lin-srgb'; +import { lin_sRGB_to_XYZ } from '../lin-srgb-to-xyz'; +import { sRGB_to_HSL } from '../srgb-to-hsl'; +import { sRGB_to_Hue } from '../srgb-to-hue'; /** * @param {Color} color [r, g, b] @@ -132,11 +133,10 @@ export function XYZ_D50_to_HWB(x: Color): Color { y = D50_to_D65(y); y = XYZ_to_lin_sRGB(y); const srgb = gam_sRGB(y); - y = sRGB_to_HSL(srgb); const white = Math.min(srgb[0], srgb[1], srgb[2]); const black = 1 - Math.max(srgb[0], srgb[1], srgb[2]); - return ([y[0], white * 100, black * 100]); + return [sRGB_to_Hue(srgb), white * 100, black * 100]; } /** diff --git a/packages/css-color-parser/package.json b/packages/css-color-parser/package.json index e7a7d7480..8ad66e4b8 100644 --- a/packages/css-color-parser/package.json +++ b/packages/css-color-parser/package.json @@ -48,7 +48,7 @@ "dist" ], "dependencies": { - "@csstools/color-helpers": "^4.2.1", + "@csstools/color-helpers": "^5.0.0", "@csstools/css-calc": "^2.0.0" }, "peerDependencies": { diff --git a/packages/css-color-parser/test/basic/hwb.mjs b/packages/css-color-parser/test/basic/hwb.mjs index 0ef5d2219..a44eb4d4f 100644 --- a/packages/css-color-parser/test/basic/hwb.mjs +++ b/packages/css-color-parser/test/basic/hwb.mjs @@ -1,7 +1,7 @@ import { color } from '@csstools/css-color-parser'; import assert from 'node:assert'; import { parse } from '../util/parse.mjs'; -import { serialize_sRGB_data } from '../util/serialize.mjs'; +import { serialize_P3_data, serialize_sRGB_data } from '../util/serialize.mjs'; assert.deepStrictEqual( serialize_sRGB_data(color(parse('hwb(90deg 25% 25%)'))), @@ -12,3 +12,13 @@ assert.deepStrictEqual( serialize_sRGB_data(color(parse('hwb(90deg 25 25)'))), 'rgb(128, 191, 64)', ); + +assert.deepStrictEqual( + serialize_P3_data(color(parse('hwb(from color(srgb 1.59343 0.58802 1.40564) h w b / alpha)')), false), + 'color(display-p3 1.47868 0.65877 1.37065)', +); + +assert.deepStrictEqual( + serialize_P3_data(color(parse('hwb(from lab(100 104.3 -50.9) h w b)')), false), + 'color(display-p3 1.47874 0.65856 1.37055)', +); diff --git a/packages/css-color-parser/test/util/serialize.mjs b/packages/css-color-parser/test/util/serialize.mjs index b68d85bcf..c94011e42 100644 --- a/packages/css-color-parser/test/util/serialize.mjs +++ b/packages/css-color-parser/test/util/serialize.mjs @@ -1,11 +1,11 @@ import { serializeRGB, serializeP3, serializeOKLCH, serializeHSL } from '@csstools/css-color-parser'; -export function serialize_sRGB_data(x) { +export function serialize_sRGB_data(x, gamutMapping = true) { if (!x) { return ''; } - return serializeRGB(x).toString(); + return serializeRGB(x, gamutMapping).toString(); } export function serialize_HSL_data(x) { @@ -16,12 +16,12 @@ export function serialize_HSL_data(x) { return serializeHSL(x).toString(); } -export function serialize_P3_data(x) { +export function serialize_P3_data(x, gamutMapping = true) { if (!x) { return ''; } - return serializeP3(x).toString(); + return serializeP3(x, gamutMapping).toString(); } export function serialize_OKLCH_data(x) { diff --git a/plugins/postcss-contrast-color-function/package.json b/plugins/postcss-contrast-color-function/package.json index 0af9a36dd..4c487112f 100644 --- a/plugins/postcss-contrast-color-function/package.json +++ b/plugins/postcss-contrast-color-function/package.json @@ -48,7 +48,7 @@ "dist" ], "dependencies": { - "@csstools/color-helpers": "^4.2.1", + "@csstools/color-helpers": "^5.0.0", "@csstools/css-color-parser": "^3.0.0", "@csstools/css-parser-algorithms": "^3.0.0", "@csstools/css-tokenizer": "^3.0.0", diff --git a/plugins/postcss-text-decoration-shorthand/package.json b/plugins/postcss-text-decoration-shorthand/package.json index b337e0b8a..dbfbbd845 100644 --- a/plugins/postcss-text-decoration-shorthand/package.json +++ b/plugins/postcss-text-decoration-shorthand/package.json @@ -48,7 +48,7 @@ "dist" ], "dependencies": { - "@csstools/color-helpers": "^4.2.1", + "@csstools/color-helpers": "^5.0.0", "postcss-value-parser": "^4.2.0" }, "peerDependencies": {