antd-theme-generator
Advanced tools
Comparing version 1.1.7 to 1.1.8
22
index.js
@@ -57,3 +57,3 @@ const fs = require("fs"); | ||
*/ | ||
function generateColorMap(content) { | ||
function generateColorMap(content, customColorRegexArray = []) { | ||
return content | ||
@@ -73,5 +73,5 @@ .split("\n") | ||
color = getColor(color, prev); | ||
if (!isValidColor(color)) return prev; | ||
if (!isValidColor(color, customColorRegexArray)) return prev; | ||
prev[varName] = color; | ||
} else if (isValidColor(color)) { | ||
} else if (isValidColor(color, customColorRegexArray)) { | ||
prev[varName] = color; | ||
@@ -211,3 +211,3 @@ } | ||
*/ | ||
function isValidColor(color) { | ||
function isValidColor(color, customColorRegexArray = []) { | ||
if (!color || color.match(/px/g)) return false; | ||
@@ -221,5 +221,12 @@ if (color.match(/colorPalette|fade/g)) return true; | ||
} | ||
return /^(rgb|hsl|hsv)a?\((\d+%?(deg|rad|grad|turn)?[,\s]+){2,3}[\s\/]*[\d\.]+%?\)$/i.test( | ||
const isColor = /^(rgb|hsl|hsv)a?\((\d+%?(deg|rad|grad|turn)?[,\s]+){2,3}[\s\/]*[\d\.]+%?\)$/i.test( | ||
color | ||
); | ||
if (isColor) return true; | ||
if (customColorRegexArray.length > 0) { | ||
return customColorRegexArray.reduce((prev, regex) => { | ||
return prev || regex.test(color); | ||
}, false); | ||
} | ||
return false; | ||
} | ||
@@ -264,3 +271,4 @@ | ||
cssModules = false, | ||
themeVariables = ['@primary-color'] | ||
themeVariables = ['@primary-color'], | ||
customColorRegexArray = [] | ||
}) { | ||
@@ -320,3 +328,3 @@ return new Promise((resolve, reject) => { | ||
.then(colorsLess => { | ||
const mappings = Object.assign(generateColorMap(colorsLess), generateColorMap(mainLessFile)); | ||
const mappings = Object.assign(generateColorMap(colorsLess, customColorRegexArray), generateColorMap(mainLessFile, customColorRegexArray)); | ||
return [mappings, colorsLess]; | ||
@@ -323,0 +331,0 @@ }) |
{ | ||
"name": "antd-theme-generator", | ||
"version": "1.1.7", | ||
"version": "1.1.8", | ||
"description": "This a script to generate color specific styles less file and which you can use to change theme dynamically in browser", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
29588
387