Skip to content

Commit 069f919

Browse files
refactor: Simplify named colors map in _getRGBA
Simplify the `namedColors` map in `src/dotwave.js` by storing only the RGB string values instead of the entire string format. Extracted alpha string interpolation to the point of function return. Co-authored-by: jsem-nerad <88319121+jsem-nerad@users.noreply.github.com>
1 parent 2a7c2e2 commit 069f919

1 file changed

Lines changed: 26 additions & 26 deletions

File tree

src/dotwave.js

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -534,34 +534,34 @@
534534

535535
// For named colors, use a predefined map
536536
const namedColors = {
537-
'white': 'rgba(255, 255, 255, ' + alpha + ')',
538-
'black': 'rgba(0, 0, 0, ' + alpha + ')',
539-
'red': 'rgba(255, 0, 0, ' + alpha + ')',
540-
'green': 'rgba(0, 128, 0, ' + alpha + ')',
541-
'blue': 'rgba(0, 0, 255, ' + alpha + ')',
542-
'yellow': 'rgba(255, 255, 0, ' + alpha + ')',
543-
'orange': 'rgba(255, 165, 0, ' + alpha + ')',
544-
'purple': 'rgba(128, 0, 128, ' + alpha + ')',
545-
'pink': 'rgba(255, 192, 203, ' + alpha + ')',
546-
'brown': 'rgba(165, 42, 42, ' + alpha + ')',
547-
'gray': 'rgba(128, 128, 128, ' + alpha + ')',
548-
'grey': 'rgba(128, 128, 128, ' + alpha + ')',
549-
'cyan': 'rgba(0, 255, 255, ' + alpha + ')',
550-
'magenta': 'rgba(255, 0, 255, ' + alpha + ')',
551-
'lime': 'rgba(0, 255, 0, ' + alpha + ')',
552-
'maroon': 'rgba(128, 0, 0, ' + alpha + ')',
553-
'navy': 'rgba(0, 0, 128, ' + alpha + ')',
554-
'olive': 'rgba(128, 128, 0, ' + alpha + ')',
555-
'teal': 'rgba(0, 128, 128, ' + alpha + ')',
556-
'silver': 'rgba(192, 192, 192, ' + alpha + ')',
557-
'gold': 'rgba(255, 215, 0, ' + alpha + ')',
558-
'indigo': 'rgba(75, 0, 130, ' + alpha + ')',
559-
'violet': 'rgba(238, 130, 238, ' + alpha + ')',
560-
'turquoise': 'rgba(64, 224, 208, ' + alpha + ')'
537+
'white': '255, 255, 255',
538+
'black': '0, 0, 0',
539+
'red': '255, 0, 0',
540+
'green': '0, 128, 0',
541+
'blue': '0, 0, 255',
542+
'yellow': '255, 255, 0',
543+
'orange': '255, 165, 0',
544+
'purple': '128, 0, 128',
545+
'pink': '255, 192, 203',
546+
'brown': '165, 42, 42',
547+
'gray': '128, 128, 128',
548+
'grey': '128, 128, 128',
549+
'cyan': '0, 255, 255',
550+
'magenta': '255, 0, 255',
551+
'lime': '0, 255, 0',
552+
'maroon': '128, 0, 0',
553+
'navy': '0, 0, 128',
554+
'olive': '128, 128, 0',
555+
'teal': '0, 128, 128',
556+
'silver': '192, 192, 192',
557+
'gold': '255, 215, 0',
558+
'indigo': '75, 0, 130',
559+
'violet': '238, 130, 238',
560+
'turquoise': '64, 224, 208'
561561
};
562-
563562

564-
return namedColors[color.toLowerCase()] || `rgba(255, 255, 255, ${alpha})`;
563+
const namedColor = namedColors[color.toLowerCase()];
564+
return namedColor ? `rgba(${namedColor}, ${alpha})` : `rgba(255, 255, 255, ${alpha})`;
565565
};
566566

567567
/**

0 commit comments

Comments
 (0)