From beee4d58888238b3d6a6fe1a5330fdb01c0d62ea Mon Sep 17 00:00:00 2001 From: betossauro Date: Wed, 4 Sep 2024 14:09:42 -0300 Subject: [PATCH] Added support for Color.fromARGB (Flutter) --- src/strategies/functions.js | 9 ++++++++- test/fixture/test.js | 1 + 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/strategies/functions.js b/src/strategies/functions.js index 91594eb..b7d08ff 100644 --- a/src/strategies/functions.js +++ b/src/strategies/functions.js @@ -1,4 +1,4 @@ -const colorRegex = /((rgb|hsl|lch|oklch)a?\(\s*[\d]*\.?[\d]+%?\s*(?\s|,)\s*[\d]*\.?[\d]+%?\s*\k\s*[\d]*\.?[\d]+%?(\s*(\k|\/)\s*[\d]*\.?[\d]+%?)?\s*\))/gi; +const colorRegex = /((rgb|hsl|lch|oklch)a?\(\s*[\d]*\.?[\d]+%?\s*(?\s|,)\s*[\d]*\.?[\d]+%?\s*\k\s*[\d]*\.?[\d]+%?(\s*(\k|\/)\s*[\d]*\.?[\d]+%?)?\s*\))|Color\.fromARGB\(\s*\d{1,3}\s*,\s*\d{1,3}\s*,\s*\d{1,3}\s*,\s*\d{1,3}\s*\)/gi; const cssVarRegex = /(--[\w-]+-(rgb|hsl|lch|oklch)):\s*([\d]*\.?[\d]+\s+[\d]*\.?[\d]+\s+[\d]*\.?[\d]+);/gi; const allowedColorFunctions = ['rgb', 'hsl', 'lch', 'oklch']; @@ -14,6 +14,13 @@ function createColorFunctionObject(match) { const end = start + match[0].length; let color = match[0]; + if (color.startsWith('Color.fromARGB')) { + // Extract ARGB values + const [ , a, r, g, b ] = color.match(/Color\.fromARGB\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)/); + // Convert to rgba format for simplicity in highlighting + color = `rgba(${r}, ${g}, ${b}, ${a / 255})`; + } + const cssVarMatchArray = Array.from(color.matchAll(cssVarRegex)); if (cssVarMatchArray.length > 0) { diff --git a/test/fixture/test.js b/test/fixture/test.js index c258061..ac22d52 100644 --- a/test/fixture/test.js +++ b/test/fixture/test.js @@ -10,3 +10,4 @@ // rgba(255 0 0 / 100%) // hwb(360, 0%, 0%) // hwb(360, 0%, 0%, 1) +// Color.fromARGB(255, 255, 0, 0) \ No newline at end of file