mirror of
https://github.com/zoriya/react-native-svg.git
synced 2026-05-29 13:21:50 +00:00
Hoist color parsing regular expressions
This commit is contained in:
+12
-10
@@ -153,13 +153,13 @@ function clamp(num, min, max) {
|
||||
return Math.min(Math.max(min, num), max);
|
||||
}
|
||||
|
||||
function rgbFromString(string) {
|
||||
const abbr = /^#([a-f0-9]{3,4})$/i;
|
||||
const hex = /^#([a-f0-9]{6})([a-f0-9]{2})?$/i;
|
||||
const rgba = /^rgba?\(\s*([+-]?\d+)\s*,\s*([+-]?\d+)\s*,\s*([+-]?\d+)\s*(?:,\s*([+-]?[\d.]+)\s*)?\)$/;
|
||||
const per = /^rgba?\(\s*([+-]?[\d.]+)%\s*,\s*([+-]?[\d.]+)%\s*,\s*([+-]?[\d.]+)%\s*(?:,\s*([+-]?[\d.]+)\s*)?\)$/;
|
||||
const keyword = /(\D+)/;
|
||||
const abbr = /^#([a-f0-9]{3,4})$/i;
|
||||
const hex = /^#([a-f0-9]{6})([a-f0-9]{2})?$/i;
|
||||
const rgba = /^rgba?\(\s*([+-]?\d+)\s*,\s*([+-]?\d+)\s*,\s*([+-]?\d+)\s*(?:,\s*([+-]?[\d.]+)\s*)?\)$/;
|
||||
const per = /^rgba?\(\s*([+-]?[\d.]+)%\s*,\s*([+-]?[\d.]+)%\s*,\s*([+-]?[\d.]+)%\s*(?:,\s*([+-]?[\d.]+)\s*)?\)$/;
|
||||
const keyword = /(\D+)/;
|
||||
|
||||
function rgbFromString(string) {
|
||||
let rgb = [0, 0, 0, 1];
|
||||
let match;
|
||||
let i;
|
||||
@@ -232,9 +232,10 @@ function rgbFromString(string) {
|
||||
return rgb;
|
||||
}
|
||||
|
||||
const hslRegEx = /^hsla?\(\s*([+-]?(?:\d*\.)?\d+)(?:deg)?\s*,\s*([+-]?[\d.]+)%\s*,\s*([+-]?[\d.]+)%\s*(?:,\s*([+-]?[\d.]+)\s*)?\)$/;
|
||||
|
||||
function hslFromString(string) {
|
||||
const hsl = /^hsla?\(\s*([+-]?(?:\d*\.)?\d+)(?:deg)?\s*,\s*([+-]?[\d.]+)%\s*,\s*([+-]?[\d.]+)%\s*(?:,\s*([+-]?[\d.]+)\s*)?\)$/;
|
||||
const match = string.match(hsl);
|
||||
const match = string.match(hslRegEx);
|
||||
|
||||
if (match) {
|
||||
const alpha = parseFloat(match[4]);
|
||||
@@ -249,9 +250,10 @@ function hslFromString(string) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const hwbRegEx = /^hwb\(\s*([+-]?\d*[.]?\d+)(?:deg)?\s*,\s*([+-]?[\d.]+)%\s*,\s*([+-]?[\d.]+)%\s*(?:,\s*([+-]?[\d.]+)\s*)?\)$/;
|
||||
|
||||
function hwbFromString(string) {
|
||||
const hwb = /^hwb\(\s*([+-]?\d*[.]?\d+)(?:deg)?\s*,\s*([+-]?[\d.]+)%\s*,\s*([+-]?[\d.]+)%\s*(?:,\s*([+-]?[\d.]+)\s*)?\)$/;
|
||||
const match = string.match(hwb);
|
||||
const match = string.match(hwbRegEx);
|
||||
|
||||
if (match) {
|
||||
const alpha = parseFloat(match[4]);
|
||||
|
||||
Reference in New Issue
Block a user