@khanacademy/wonder-blocks-color
Advanced tools
Comparing version 1.0.12 to 1.0.13
@@ -39,20 +39,20 @@ function _defineProperty(obj, key, value) { | ||
*/ | ||
const color6Regexp = /^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i; | ||
const color3Regexp = /^#([0-9a-f])([0-9a-f])([0-9a-f])$/i; | ||
const rgbaRegexp = /^rgba?\(\s*(\d+),\s*(\d+),\s*(\d+)(?:,\s*([\d.]+))?\s*\)$/i; | ||
var color6Regexp = /^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i; | ||
var color3Regexp = /^#([0-9a-f])([0-9a-f])([0-9a-f])$/i; | ||
var rgbaRegexp = /^rgba?\(\s*(\d+),\s*(\d+),\s*(\d+)(?:,\s*([\d.]+))?\s*\)$/i; | ||
// Parse a color in #abcdef, rgb(...), or rgba(...) form into an object | ||
// with r,g,b,a keys. | ||
const parse = color => { | ||
var parse = function parse(color) { | ||
if (typeof color !== "string") { | ||
throw new Error(`Failed to parse color: ${color}`); | ||
throw new Error("Failed to parse color: ".concat(color)); | ||
} | ||
const color3Match = color.match(color3Regexp); | ||
var color3Match = color.match(color3Regexp); | ||
if (color3Match) { | ||
return { | ||
r: parseInt(`${color3Match[1]}${color3Match[1]}`, 16), | ||
g: parseInt(`${color3Match[2]}${color3Match[2]}`, 16), | ||
b: parseInt(`${color3Match[3]}${color3Match[3]}`, 16), | ||
r: parseInt("".concat(color3Match[1]).concat(color3Match[1]), 16), | ||
g: parseInt("".concat(color3Match[2]).concat(color3Match[2]), 16), | ||
b: parseInt("".concat(color3Match[3]).concat(color3Match[3]), 16), | ||
a: 1 | ||
@@ -62,3 +62,3 @@ }; | ||
const color6Match = color.match(color6Regexp); | ||
var color6Match = color.match(color6Regexp); | ||
@@ -74,3 +74,3 @@ if (color6Match) { | ||
const rgbaMatch = color.match(rgbaRegexp); | ||
var rgbaMatch = color.match(rgbaRegexp); | ||
@@ -86,20 +86,20 @@ if (rgbaMatch) { | ||
throw new Error(`Failed to parse color: ${color}`); | ||
throw new Error("Failed to parse color: ".concat(color)); | ||
}; // Stringify the color in an `rgba()` or `#abcdef` format. | ||
const format = color => { | ||
const r = Math.round(color.r); | ||
const g = Math.round(color.g); | ||
const b = Math.round(color.b); | ||
var format = function format(color) { | ||
var r = Math.round(color.r); | ||
var g = Math.round(color.g); | ||
var b = Math.round(color.b); | ||
if (color.a === 1) { | ||
const _s = c => { | ||
const asString = c.toString(16); | ||
var _s = function _s(c) { | ||
var asString = c.toString(16); | ||
return asString.length === 1 ? asString + asString : asString; | ||
}; | ||
return `#${_s(r)}${_s(g)}${_s(b)}`; | ||
return "#".concat(_s(r)).concat(_s(g)).concat(_s(b)); | ||
} else { | ||
return `rgba(${r},${g},${b},${color.a.toFixed(2)})`; | ||
return "rgba(".concat(r, ",").concat(g, ",").concat(b, ",").concat(color.a.toFixed(2), ")"); | ||
} | ||
@@ -109,3 +109,3 @@ }; // Adjust the alpha value of a color. | ||
const fade = (color, percentage) => { | ||
var fade = function fade(color, percentage) { | ||
if (percentage < 0 || percentage > 1) { | ||
@@ -115,3 +115,3 @@ throw new Error("Percentage must be between 0 and 1"); | ||
const components = parse(color); | ||
var components = parse(color); | ||
return format(_objectSpread({}, components, { | ||
@@ -123,5 +123,5 @@ a: components.a * percentage | ||
const mix = (color, background) => { | ||
const colorObj = parse(color); | ||
const bgObj = parse(background); | ||
var mix = function mix(color, background) { | ||
var colorObj = parse(color); | ||
var bgObj = parse(background); | ||
return format({ | ||
@@ -135,5 +135,5 @@ r: colorObj.r * colorObj.a + bgObj.r * (1 - colorObj.a), | ||
const offBlack = "#21242c"; | ||
const white = "#ffffff"; | ||
const Color = { | ||
var offBlack = "#21242c"; | ||
var white = "#ffffff"; | ||
var Color = { | ||
// Product | ||
@@ -146,3 +146,3 @@ blue: "#1865f2", | ||
// Neutral | ||
offBlack, | ||
offBlack: offBlack, | ||
offBlack64: fade(offBlack, 0.64), | ||
@@ -154,3 +154,3 @@ offBlack50: fade(offBlack, 0.5), | ||
offWhite: "#f7f8fa", | ||
white, | ||
white: white, | ||
white64: fade(white, 0.64), | ||
@@ -164,3 +164,3 @@ white50: fade(white, 0.5), | ||
}; | ||
const SemanticColor = { | ||
var SemanticColor = { | ||
controlDefault: Color.blue, | ||
@@ -167,0 +167,0 @@ controlDestructive: Color.red |
@@ -104,20 +104,20 @@ module.exports = | ||
*/ | ||
const color6Regexp = /^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i; | ||
const color3Regexp = /^#([0-9a-f])([0-9a-f])([0-9a-f])$/i; | ||
const rgbaRegexp = /^rgba?\(\s*(\d+),\s*(\d+),\s*(\d+)(?:,\s*([\d.]+))?\s*\)$/i; | ||
var color6Regexp = /^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i; | ||
var color3Regexp = /^#([0-9a-f])([0-9a-f])([0-9a-f])$/i; | ||
var rgbaRegexp = /^rgba?\(\s*(\d+),\s*(\d+),\s*(\d+)(?:,\s*([\d.]+))?\s*\)$/i; | ||
// Parse a color in #abcdef, rgb(...), or rgba(...) form into an object | ||
// with r,g,b,a keys. | ||
const parse = color => { | ||
var parse = function parse(color) { | ||
if (typeof color !== "string") { | ||
throw new Error(`Failed to parse color: ${color}`); | ||
throw new Error("Failed to parse color: ".concat(color)); | ||
} | ||
const color3Match = color.match(color3Regexp); | ||
var color3Match = color.match(color3Regexp); | ||
if (color3Match) { | ||
return { | ||
r: parseInt(`${color3Match[1]}${color3Match[1]}`, 16), | ||
g: parseInt(`${color3Match[2]}${color3Match[2]}`, 16), | ||
b: parseInt(`${color3Match[3]}${color3Match[3]}`, 16), | ||
r: parseInt("".concat(color3Match[1]).concat(color3Match[1]), 16), | ||
g: parseInt("".concat(color3Match[2]).concat(color3Match[2]), 16), | ||
b: parseInt("".concat(color3Match[3]).concat(color3Match[3]), 16), | ||
a: 1 | ||
@@ -127,3 +127,3 @@ }; | ||
const color6Match = color.match(color6Regexp); | ||
var color6Match = color.match(color6Regexp); | ||
@@ -139,3 +139,3 @@ if (color6Match) { | ||
const rgbaMatch = color.match(rgbaRegexp); | ||
var rgbaMatch = color.match(rgbaRegexp); | ||
@@ -151,20 +151,20 @@ if (rgbaMatch) { | ||
throw new Error(`Failed to parse color: ${color}`); | ||
throw new Error("Failed to parse color: ".concat(color)); | ||
}; // Stringify the color in an `rgba()` or `#abcdef` format. | ||
const format = color => { | ||
const r = Math.round(color.r); | ||
const g = Math.round(color.g); | ||
const b = Math.round(color.b); | ||
var format = function format(color) { | ||
var r = Math.round(color.r); | ||
var g = Math.round(color.g); | ||
var b = Math.round(color.b); | ||
if (color.a === 1) { | ||
const _s = c => { | ||
const asString = c.toString(16); | ||
var _s = function _s(c) { | ||
var asString = c.toString(16); | ||
return asString.length === 1 ? asString + asString : asString; | ||
}; | ||
return `#${_s(r)}${_s(g)}${_s(b)}`; | ||
return "#".concat(_s(r)).concat(_s(g)).concat(_s(b)); | ||
} else { | ||
return `rgba(${r},${g},${b},${color.a.toFixed(2)})`; | ||
return "rgba(".concat(r, ",").concat(g, ",").concat(b, ",").concat(color.a.toFixed(2), ")"); | ||
} | ||
@@ -174,3 +174,3 @@ }; // Adjust the alpha value of a color. | ||
const fade = (color, percentage) => { | ||
var fade = function fade(color, percentage) { | ||
if (percentage < 0 || percentage > 1) { | ||
@@ -180,3 +180,3 @@ throw new Error("Percentage must be between 0 and 1"); | ||
const components = parse(color); | ||
var components = parse(color); | ||
return format(_objectSpread({}, components, { | ||
@@ -188,5 +188,5 @@ a: components.a * percentage | ||
const mix = (color, background) => { | ||
const colorObj = parse(color); | ||
const bgObj = parse(background); | ||
var mix = function mix(color, background) { | ||
var colorObj = parse(color); | ||
var bgObj = parse(background); | ||
return format({ | ||
@@ -205,5 +205,5 @@ r: colorObj.r * colorObj.a + bgObj.r * (1 - colorObj.a), | ||
const offBlack = "#21242c"; | ||
const white = "#ffffff"; | ||
const Color = { | ||
var offBlack = "#21242c"; | ||
var white = "#ffffff"; | ||
var Color = { | ||
// Product | ||
@@ -216,3 +216,3 @@ blue: "#1865f2", | ||
// Neutral | ||
offBlack, | ||
offBlack: offBlack, | ||
offBlack64: fade(offBlack, 0.64), | ||
@@ -224,3 +224,3 @@ offBlack50: fade(offBlack, 0.5), | ||
offWhite: "#f7f8fa", | ||
white, | ||
white: white, | ||
white64: fade(white, 0.64), | ||
@@ -234,3 +234,3 @@ white50: fade(white, 0.5), | ||
}; | ||
const SemanticColor = { | ||
var SemanticColor = { | ||
controlDefault: Color.blue, | ||
@@ -237,0 +237,0 @@ controlDestructive: Color.red |
{ | ||
"name": "@khanacademy/wonder-blocks-color", | ||
"version": "1.0.12", | ||
"version": "1.0.13", | ||
"design": "v2", | ||
@@ -16,4 +16,5 @@ "publishConfig": { | ||
"devDependencies": { | ||
"@khanacademy/wonder-blocks-core": "^1.2.5", | ||
"@khanacademy/wonder-blocks-typography": "^1.0.12" | ||
"@khanacademy/wonder-blocks-core": "^1.2.6", | ||
"@khanacademy/wonder-blocks-typography": "^1.0.13", | ||
"wb-dev-build-settings": "^0.0.2" | ||
}, | ||
@@ -20,0 +21,0 @@ "author": "", |
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
125896
3