From 0adc2b7014d9909869bc9888ac90a3ec142d9488 Mon Sep 17 00:00:00 2001 From: Volpeon Date: Tue, 8 Oct 2024 12:36:57 +0200 Subject: Replace Oddbird with native SASS color functions --- src/functions/colors/_apca.scss | 54 ++++++++++++------------ src/functions/colors/_index.scss | 1 - src/functions/colors/_oklch.scss | 88 ---------------------------------------- 3 files changed, 27 insertions(+), 116 deletions(-) delete mode 100644 src/functions/colors/_oklch.scss (limited to 'src/functions') diff --git a/src/functions/colors/_apca.scss b/src/functions/colors/_apca.scss index d9236b2..c848db7 100644 --- a/src/functions/colors/_apca.scss +++ b/src/functions/colors/_apca.scss @@ -9,34 +9,36 @@ $SA98G: ( mainTRC: 2.4, - sRco: 0.2126729, - sGco: 0.7151522, - sBco: 0.0721750, + sRco: .2126729, + sGco: .7151522, + sBco: .072175, - normBG: 0.56, - normTXT: 0.57, - revTXT: 0.62, - revBG: 0.65, + normBG: .56, + normTXT: .57, + revTXT: .62, + revBG: .65, - blkThrs: 0.022, + blkThrs: .022, blkClmp: 1.414, scaleBoW: 1.14, scaleWoB: 1.14, - loBoWoffset: 0.027, - loWoBoffset: 0.027, - deltaYmin: 0.0005, - loClip: 0.0001, - - mFactor: 1.94685544331710, - mOffsetIn: 0.03873938165714010, - mExpAdj: 0.2833433964208690, - mOffsetOut: 0.3128657958707580, + loBoWoffset: .027, + loWoBoffset: .027, + deltaYmin: .0005, + loClip: .0001, + + mFactor: 1.9468554433171, + mOffsetIn: .0387393816571401, + mExpAdj: .283343396420869, + mOffsetOut: .312865795870758, ); @function apca_sRGB_to_Y($color) { - @return map.get($SA98G, sRco) * math.pow(math.div(color.red($color), 255), map.get($SA98G, mainTRC)) + - map.get($SA98G, sGco) * math.pow(math.div(color.green($color), 255), map.get($SA98G, mainTRC)) + - map.get($SA98G, sBco) * math.pow(math.div(color.blue($color), 255), map.get($SA98G, mainTRC)); + $rgb: color.to-space($color, rgb); + + @return map.get($SA98G, sRco) * math.pow(math.div(color.channel($rgb, 'red'), 255), map.get($SA98G, mainTRC)) + + map.get($SA98G, sGco) * math.pow(math.div(color.channel($rgb, 'green'), 255), map.get($SA98G, mainTRC)) + + map.get($SA98G, sBco) * math.pow(math.div(color.channel($rgb, 'blue'), 255), map.get($SA98G, mainTRC)); } @function apca_Y_to_sRGB($y) { @@ -45,7 +47,7 @@ $SA98G: ( } @function apcaContrast($txtY, $bgY) { - $icp: 0.0 1.1; + $icp: 1.1; @if math.min($txtY, $bgY) < list.nth($icp, 1) or math.max($txtY, $bgY) > list.nth($icp, 2) { @return 0; @@ -78,7 +80,7 @@ $SA98G: ( } } - @return $outputContrast * 100.0; + @return $outputContrast * 100; } @function apcaReverse($contrast, $knownY, $knownType: 'bg') { @@ -90,7 +92,7 @@ $SA98G: ( $scale: map.get($SA98G, if($contrast > 0, scaleBoW, scaleWoB)); $offset: map.get($SA98G, if($contrast > 0, loBoWoffset, loWoBoffset)); - $contrast: math.div($contrast * 0.01 + $offset, $scale); + $contrast: math.div($contrast * .01 + $offset, $scale); @if $knownY <= map.get($SA98G, blkThrs) { $knownY: $knownY + math.pow(map.get($SA98G, blkThrs) - $knownY, map.get($SA98G, blkClmp)); @@ -115,10 +117,8 @@ $SA98G: ( } @if $unknownY <= map.get($SA98G, blkThrs) { - $unknownY: math.pow( - ($unknownY + map.get($SA98G, mOffsetIn)) * map.get($SA98G, mFactor), - math.div(map.get($SA98G, mExpAdj), map.get($SA98G, blkClmp)) - ) * math.div(1, map.get($SA98G, mFactor)) - map.get($SA98G, mOffsetOut); + $unknownY: math.pow(($unknownY + map.get($SA98G, mOffsetIn)) * map.get($SA98G, mFactor), + math.div(map.get($SA98G, mExpAdj), map.get($SA98G, blkClmp))) * math.div(1, map.get($SA98G, mFactor)) - map.get($SA98G, mOffsetOut); } $unknownY: math.max(math.min($unknownY, 1), 0); diff --git a/src/functions/colors/_index.scss b/src/functions/colors/_index.scss index 26c3027..9dad0f9 100644 --- a/src/functions/colors/_index.scss +++ b/src/functions/colors/_index.scss @@ -1,2 +1 @@ @forward 'apca'; -@forward 'oklch'; diff --git a/src/functions/colors/_oklch.scss b/src/functions/colors/_oklch.scss deleted file mode 100644 index e3df041..0000000 --- a/src/functions/colors/_oklch.scss +++ /dev/null @@ -1,88 +0,0 @@ -/* stylelint-disable scss/dollar-variable-pattern */ -/* stylelint-disable scss/at-function-pattern */ - -@use 'sass:list'; -@use 'sass:math'; -@use 'sass:meta'; -@use 'sass:string'; -@use '@oddbird/blend/sass/convert' as blend-convert; -@use '@oddbird/blend/sass/utils/pow'; -@use 'iro-sass/src/index' as iro; - -@function lin_sRGB_to_Oklab($color) { - $r_: list.nth($color, 1); - $g_: list.nth($color, 2); - $b_: list.nth($color, 3); - - $l: pow.cbrt(0.4122214708 * $r_ + 0.5363325363 * $g_ + 0.0514459929 * $b_); - $m: pow.cbrt(0.2119034982 * $r_ + 0.6806995451 * $g_ + 0.1073969566 * $b_); - $s: pow.cbrt(0.0883024619 * $r_ + 0.2817188376 * $g_ + 0.6299787005 * $b_); - - @return ( - 0.2104542553 * $l + 0.7936177850 * $m - 0.0040720468 * $s, - 1.9779984951 * $l - 2.4285922050 * $m + 0.4505937099 * $s, - 0.0259040371 * $l + 0.7827717662 * $m - 0.8086757660 * $s, - ); -} - -@function Oklab_to_lin_sRGB($color) { - $l_: list.nth($color, 1); - $a_: list.nth($color, 2); - $b_: list.nth($color, 3); - - $l: $l_ + 0.3963377774 * $a_ + 0.2158037573 * $b_; - $m: $l_ - 0.1055613458 * $a_ - 0.0638541728 * $b_; - $s: $l_ - 0.0894841775 * $a_ - 1.2914855480 * $b_; - - $l: $l * $l * $l; - $m: $m * $m * $m; - $s: $s * $s * $s; - - @return ( - 4.0767416621 * $l - 3.3077115913 * $m + 0.2309699292 * $s, - -1.2684380046 * $l + 2.6097574011 * $m - 0.3413193965 * $s, - -0.0041960863 * $l - 0.7034186147 * $m + 1.7076147010 * $s, - ); -} - -@function oklch($arg) { - $l: math.div(list.nth($arg, 1), 100%); - $c: list.nth($arg, 2); - $h: list.nth($arg, 3); - - @return blend-convert.rgbToSass( - blend-convert.gam_sRGB( - Oklab_to_lin_sRGB( - blend-convert.LCH_to_Lab($l $c $h) - ) - ) - ); -} - -@function parse-oklch($color) { - @if meta.type-of($color) == 'color' { - @return blend-convert.Lab_to_LCH( - lin_sRGB_to_Oklab( - blend-convert.lin_sRGB( - blend-convert.sassToRgb($color) - ) - ) - ); - } - - @if meta.type-of($color) != 'string' { - @return null; - } - - @if string.slice($color, 1, 6) == 'oklch(' { - $args: string.split(string.slice($color, 7, -2), ' '); - - $l: math.div(iro.fn-to-number(list.nth($args, 1)), 100%); - $c: iro.fn-to-number(list.nth($args, 2)); - $h: iro.fn-to-number(list.nth($args, 3)); - - @return $l $c $h; - } - - @return null; -} -- cgit v1.2.3-70-g09d2