Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions assets/js/Components/Forms/ContrastForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,21 @@ export default function ContrastForm({
handleIssueSave,
markAsReviewed,
}) {

const GRADIENT_KEYWORDS = new Set([
'linear', 'radial', 'repeating-linear', 'repeating-radial', 'gradient',
'to', 'top', 'bottom', 'left', 'right', 'circle', 'ellipse', 'at', 'center'
]);

// Extract color strings from gradients
// Regex matches color codes and names, keywords are excluded to just leave colors
const extractColors = (gradientString) => {
const colorRegex = /#(?:[0-9a-fA-F]{3,8})\b|(?:rgba?|hsla?)\([^)]*\)/g
return gradientString.match(colorRegex) || []
}
const colorRegex = /#(?:[0-9a-fA-F]{3,8})\b|(?:rgba?|hsla?)\([^)]*\)|\b[a-zA-Z]+\b/g;
const matches = gradientString.match(colorRegex) || [];
return matches.filter(
c => !GRADIENT_KEYWORDS.has(c.toLowerCase())
);
};

// Get all background colors (including gradients)
const getBackgroundColors = () => {
Expand Down