@asamuzakjp/css-color
Advanced tools
Comparing version
@@ -41,3 +41,3 @@ { | ||
"neostandard": "^0.12.0", | ||
"npm-run-all2": "^7.0.1", | ||
"npm-run-all2": "^7.0.2", | ||
"sinon": "^19.0.2", | ||
@@ -55,3 +55,3 @@ "typescript": "^5.7.2" | ||
}, | ||
"version": "2.6.2" | ||
"version": "2.6.3" | ||
} |
@@ -70,3 +70,3 @@ # CSS color | ||
}; | ||
``` | ||
``` | ||
* `opt.dimension` **[object][135]?** | ||
@@ -73,0 +73,0 @@ * dimension, e.g. for converting relative length to pixels |
@@ -12,8 +12,9 @@ /** | ||
export const CS_MIX = `(?:ok)?l(?:ab|ch)|h(?:sl|wb)|${CS_SRGB}|${CS_XYZ}`; | ||
export const FUNC_CALC = 'calc('; | ||
export const FUNC_CALC_ESC = '^calc\\(|(?<=[\\s*\\/\\(])calc\\('; | ||
export const FUNC_CALC = '(?:abs|calc|sign)\\('; | ||
export const FUNC_CALC_ESC = | ||
'^(?:abs|calc|sign)\\(|(?<=[*\\/\\s\\(])(?:abs|calc|sign)\\('; | ||
export const FUNC_COLOR = 'color('; | ||
export const FUNC_MIX = 'color-mix('; | ||
export const FUNC_VAR = 'var('; | ||
export const FUNC_VAR_ESC = '^var\\(|(?<=[\\s*\\/\\(])var\\('; | ||
export const FUNC_VAR_ESC = '^var\\(|(?<=[*\\/\\s\\(])var\\('; | ||
export const NONE = 'none'; | ||
@@ -20,0 +21,0 @@ export const NUM = `[+-]?(?:${_DIGIT}(?:\\.\\d*)?|\\.\\d+)(?:e-?${_DIGIT})?`; |
@@ -21,6 +21,7 @@ /** | ||
/* regexp */ | ||
const REG_CALC_START = new RegExp(`^${FUNC_CALC}`); | ||
const REG_FUNC_CALC = new RegExp(FUNC_CALC_ESC); | ||
const REG_FUNC_SIGN = /^(?:abs|sign)\($/; | ||
const REG_FUNC_VAR = new RegExp(FUNC_VAR_ESC); | ||
const REG_UNIT = new RegExp(`^(${NUM})([a-z]+|%)$`); | ||
const REG_LENGTH = new RegExp(`^(${NUM})([a-z]+|%)$`); | ||
@@ -178,5 +179,5 @@ /* cached results */ | ||
let resolvedValue = calc(values.join('')); | ||
if (value.startsWith(FUNC_CALC)) { | ||
if (REG_UNIT.test(resolvedValue)) { | ||
const [, val, unit] = REG_UNIT.exec(resolvedValue); | ||
if (REG_CALC_START.test(value)) { | ||
if (REG_LENGTH.test(resolvedValue)) { | ||
const [, val, unit] = REG_LENGTH.exec(resolvedValue); | ||
resolvedValue = `${parseFloat(Number(val).toPrecision(6))}${unit}`; | ||
@@ -183,0 +184,0 @@ } |
@@ -6,8 +6,8 @@ export const ANGLE: "deg|g?rad|turn"; | ||
export const CS_MIX: "(?:ok)?l(?:ab|ch)|h(?:sl|wb)|srgb(?:-linear)?|xyz(?:-d(?:50|65))?"; | ||
export const FUNC_CALC: "calc("; | ||
export const FUNC_CALC_ESC: "^calc\\(|(?<=[\\s*\\/\\(])calc\\("; | ||
export const FUNC_CALC: "(?:abs|calc|sign)\\("; | ||
export const FUNC_CALC_ESC: "^(?:abs|calc|sign)\\(|(?<=[*\\/\\s\\(])(?:abs|calc|sign)\\("; | ||
export const FUNC_COLOR: "color("; | ||
export const FUNC_MIX: "color-mix("; | ||
export const FUNC_VAR: "var("; | ||
export const FUNC_VAR_ESC: "^var\\(|(?<=[\\s*\\/\\(])var\\("; | ||
export const FUNC_VAR_ESC: "^var\\(|(?<=[*\\/\\s\\(])var\\("; | ||
export const NONE: "none"; | ||
@@ -14,0 +14,0 @@ export const NUM: "[+-]?(?:(?:0|[1-9]\\d*)(?:\\.\\d*)?|\\.\\d+)(?:e-?(?:0|[1-9]\\d*))?"; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
1345324
0.04%5780
0.03%