Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for the following HSL syntax #900

Closed
wants to merge 1 commit into from
Closed
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
8 changes: 4 additions & 4 deletions src/lib/colors/strategies/hsl-strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import { convertHslaToRgba } from '../../util/color-util';
import { DOT_VALUE, ALPHA, EOL } from '../../util/regexp';
import ColorStrategy from './__strategy-base';

const R_HUE = `\\d*${DOT_VALUE}?`;
const R_HUE = `(?:\\d*${DOT_VALUE}?)(deg)?`;
const R_SATURATION = `(?:\\d{1,3}${DOT_VALUE}?|${DOT_VALUE})%`;
const R_LUMINANCE = R_SATURATION;

export const REGEXP = new RegExp(`((?:hsl\\(\\s*${R_HUE}\\s*,\\s*${R_SATURATION}\\s*,\\s*${R_LUMINANCE}\\s*\\))|(?:hsla\\(\\s*${R_HUE}\\s*,\\s*${R_SATURATION}\\s*,\\s*${R_LUMINANCE}\\s*,\\s*${ALPHA}\\s*\\)))${EOL}`, 'gi');
export const REGEXP_ONE = new RegExp(`^((?:hsl\\(\\s*${R_HUE}\\s*,\\s*${R_SATURATION}\\s*,\\s*${R_LUMINANCE}\\s*\\))|(?:hsla\\(\\s*${R_HUE}\\s*,\\s*${R_SATURATION}\\s*,\\s*${R_LUMINANCE}\\s*,\\s*${ALPHA}\\s*\\)))${EOL}`, 'i');
export const REGEXP = new RegExp(`((?:hsl\\(\\s*${R_HUE}\\s*[ ,]\\s*${R_SATURATION}\\s*[ ,]\\s*${R_LUMINANCE}\\s*\\))|(?:hsla\\(\\s*${R_HUE}\\s*[ ,]\\s*${R_SATURATION}\\s*[ ,]\\s*${R_LUMINANCE}\\s*[ ,]\\s*${ALPHA}\\s*\\)))`, "gi");
export const REGEXP_ONE = new RegExp(`^((?:hsl\\(\\s*${R_HUE}\\s*[ ,]\\s*${R_SATURATION}\\s*[ ,]\\s*${R_LUMINANCE}\\s*\\))|(?:hsla\\(\\s*${R_HUE}\\s*[ ,]\\s*${R_SATURATION}\\s*[ ,]\\s*${R_LUMINANCE}\\s*[ ,]\\s*${ALPHA}\\s*\\)))`, "i");
// export const REGEXP_ONE = /^((?:hsl\(\d*\s*,\s*\d{1,3}%\s*,\s*\d{1,3}%\))|(?:hsla\(\d*\s*,\s*(?:\d{1,3}%\s*,\s*){2}(?:[0-1]|1\.0|[0](?:\.\d+){0,1}|(?:\.\d+))\)))(?:$|"|'|,| |;|\)|\r|\n)/i;

/**
Expand All @@ -20,7 +20,7 @@ export const REGEXP_ONE = new RegExp(`^((?:hsl\\(\\s*${R_HUE}\\s*,\\s*${R_SATURA
* @memberof HSLColorExtractor
*/
function extractHSLValue(value) {
const [h, s, l, a]: number[] = value.replace(/hsl(a){0,1}\(/, '').replace(/\)/, '').replace(/%/g, '').split(/,/gi).map(c => parseFloat(c));
const [h, s, l, a]: number[] = value.replace(/hsl(a){0,1}\(/, '').replace(/\)/, '').replace(/%/g, '').replace(/deg/, '').split(/[ ,]+/gi).map(c => parseFloat(c));
return [h, s, l, a];
}

Expand Down
Loading