@@ -316,6 +316,7 @@ public function execute($path = null, $parents = array())
316316 $ css = $ this ->replace ($ css );
317317
318318 $ css = $ this ->stripWhitespace ($ css );
319+ $ css = $ this ->cleanupNEWColors ($ css );
319320 $ css = $ this ->shortenRGBColors ($ css );
320321 $ css = $ this ->shortenHEXColors ($ css );
321322 $ css = $ this ->shortenZeroes ($ css );
@@ -595,6 +596,49 @@ function ($match)
595596 );
596597 }
597598
599+ /**
600+ * Cleanup HSL|HWB|LCH|LAB
601+ *
602+ * @param string $content The CSS content to cleanup HSL|HWB|LCH|LAB
603+ *
604+ * @return string
605+ */
606+ protected function cleanupNEWColors ($ content )
607+ {
608+ /*
609+ https://developer.mozilla.org/en-US/docs/Web/CSS/color_value/hsl()
610+ */
611+ $ hue = '([-+]?(?:(?:[012]?[0-9]?[0-9]|3[0-5][0-9])(\.[0-9]+)|360(?:\.0+))(?:degs|rads|grads|turn)?) ' ;// -/+ [000.*-360] def
612+ $ pct = '((100(?:\.0+)|0?[0-9]?[0-9])(\.[0-9]+)%) ' ;// [000.*-100] %
613+
614+ // remove alpha channel if it's pointless ..
615+ $ content = preg_replace ("/(hsl)a?\(([^,\s]+)[,\s]([^,\s]+)[,\s]([^,\s]+)\s?[,\/]\s?1(?:[\.\d]*|00%)?\)/i " , '$1($2 $3 $4) ' , $ content );
616+
617+ // replace `transparent` with shortcut ..
618+ #$content = preg_replace("/hsla?\([^,\s]+[,\s][^,\s]+[,\s][^,\s]+\s?[,\/]\s?0(?:[\.0%]*)?\)/i", '#0000', $content); CHECK safari
619+
620+ # ToRGB ?: https://github.com/mexitek/phpColors/blob/a74808eaf7cd918681aab0cd30f142025556bc8a/src/Mexitek/PHPColors/Color.php#L124
621+ #"/(hsl)a?\($hue[,\s]$pct[,\s]$pct[,\/]1(?:[\.\d]*|00%)?\)/i"
622+
623+ /*
624+ https://developer.mozilla.org/en-US/docs/Web/CSS/color_value/hwb()
625+ https://developer.mozilla.org/en-US/docs/Web/CSS/color_value/lch()
626+ https://developer.mozilla.org/en-US/docs/Web/CSS/color_value/lab()
627+ https://drafts.csswg.org/css-color/#color
628+ */
629+
630+ // remove alpha channel if it's pointless ..
631+ $ content = preg_replace ("/(lch|lab|hwba?)\(([^\s]+)\s([^\s]+)\s([^\s]+)\s?\/\s?1(?:[\.\d]*|00%)?\)/i " , '$1($2 $3 $4) ' , $ content );
632+
633+ // replace `transparent` with shortcut ..
634+ #$content = preg_replace("/(lch|lab)\([^\s]+\s[^\s]+\s[^\s]+\s?\/\s?0(?:[\.0%]*)?\)/i", '#0000', $content); CHECK safari
635+
636+ #"/(hwb)a?\($hue\s$pct\s$pct\s?\/\s?1(?:[\.\d]*|00%)?\)/i"
637+ #"/(lch|lab)\($pct\s$VAR\s$VAR\s?\/\s?1(?:[\.\d]*|00%)?\)/i"
638+
639+ return $ content ;
640+ }
641+
598642 /**
599643 * Shorten CSS font weights.
600644 *
0 commit comments