@khanacademy/wonder-blocks-color
Advanced tools
Comparing version 1.1.17 to 1.1.18
@@ -1,50 +0,3 @@ | ||
function _defineProperty(obj, key, value) { | ||
if (key in obj) { | ||
Object.defineProperty(obj, key, { | ||
value: value, | ||
enumerable: true, | ||
configurable: true, | ||
writable: true | ||
}); | ||
} else { | ||
obj[key] = value; | ||
} | ||
import _extends from '@babel/runtime/helpers/extends'; | ||
return obj; | ||
} | ||
function ownKeys(object, enumerableOnly) { | ||
var keys = Object.keys(object); | ||
if (Object.getOwnPropertySymbols) { | ||
var symbols = Object.getOwnPropertySymbols(object); | ||
if (enumerableOnly) symbols = symbols.filter(function (sym) { | ||
return Object.getOwnPropertyDescriptor(object, sym).enumerable; | ||
}); | ||
keys.push.apply(keys, symbols); | ||
} | ||
return keys; | ||
} | ||
function _objectSpread2(target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i] != null ? arguments[i] : {}; | ||
if (i % 2) { | ||
ownKeys(Object(source), true).forEach(function (key) { | ||
_defineProperty(target, key, source[key]); | ||
}); | ||
} else if (Object.getOwnPropertyDescriptors) { | ||
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); | ||
} else { | ||
ownKeys(Object(source)).forEach(function (key) { | ||
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); | ||
}); | ||
} | ||
} | ||
return target; | ||
} | ||
/** | ||
@@ -54,20 +7,20 @@ * A color manipulation library useful for dynamically | ||
*/ | ||
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; | ||
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; | ||
// Parse a color in #abcdef, rgb(...), or rgba(...) form into an object | ||
// with r,g,b,a keys. | ||
var parse = function parse(color) { | ||
const parse = color => { | ||
if (typeof color !== "string") { | ||
throw new Error("Failed to parse color: ".concat(color)); | ||
throw new Error(`Failed to parse color: ${color}`); | ||
} | ||
var color3Match = color.match(color3Regexp); | ||
const color3Match = color.match(color3Regexp); | ||
if (color3Match) { | ||
return { | ||
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), | ||
r: parseInt(`${color3Match[1]}${color3Match[1]}`, 16), | ||
g: parseInt(`${color3Match[2]}${color3Match[2]}`, 16), | ||
b: parseInt(`${color3Match[3]}${color3Match[3]}`, 16), | ||
a: 1 | ||
@@ -77,3 +30,3 @@ }; | ||
var color6Match = color.match(color6Regexp); | ||
const color6Match = color.match(color6Regexp); | ||
@@ -89,3 +42,3 @@ if (color6Match) { | ||
var rgbaMatch = color.match(rgbaRegexp); | ||
const rgbaMatch = color.match(rgbaRegexp); | ||
@@ -101,20 +54,20 @@ if (rgbaMatch) { | ||
throw new Error("Failed to parse color: ".concat(color)); | ||
throw new Error(`Failed to parse color: ${color}`); | ||
}; // Stringify the color in an `rgba()` or `#abcdef` format. | ||
var format = function format(color) { | ||
var r = Math.round(color.r); | ||
var g = Math.round(color.g); | ||
var b = Math.round(color.b); | ||
const format = color => { | ||
const r = Math.round(color.r); | ||
const g = Math.round(color.g); | ||
const b = Math.round(color.b); | ||
if (color.a === 1) { | ||
var _s = function _s(c) { | ||
var asString = c.toString(16); | ||
const _s = c => { | ||
const asString = c.toString(16); | ||
return asString.length === 1 ? asString + asString : asString; | ||
}; | ||
return "#".concat(_s(r)).concat(_s(g)).concat(_s(b)); | ||
return `#${_s(r)}${_s(g)}${_s(b)}`; | ||
} else { | ||
return "rgba(".concat(r, ",").concat(g, ",").concat(b, ",").concat(color.a.toFixed(2), ")"); | ||
return `rgba(${r},${g},${b},${color.a.toFixed(2)})`; | ||
} | ||
@@ -124,3 +77,3 @@ }; // Adjust the alpha value of a color. | ||
var fade = function fade(color, percentage) { | ||
const fade = (color, percentage) => { | ||
if (percentage < 0 || percentage > 1) { | ||
@@ -130,4 +83,4 @@ throw new Error("Percentage must be between 0 and 1"); | ||
var components = parse(color); | ||
return format(_objectSpread2(_objectSpread2({}, components), {}, { | ||
const components = parse(color); | ||
return format(_extends({}, components, { | ||
a: components.a * percentage | ||
@@ -138,5 +91,5 @@ })); | ||
var mix = function mix(color, background) { | ||
var colorObj = parse(color); | ||
var bgObj = parse(background); | ||
const mix = (color, background) => { | ||
const colorObj = parse(color); | ||
const bgObj = parse(background); | ||
return format({ | ||
@@ -150,5 +103,5 @@ r: colorObj.r * colorObj.a + bgObj.r * (1 - colorObj.a), | ||
var offBlack = "#21242c"; | ||
var white = "#ffffff"; | ||
var Color = { | ||
const offBlack = "#21242c"; | ||
const white = "#ffffff"; | ||
const Color = { | ||
// Product | ||
@@ -161,3 +114,3 @@ blue: "#1865f2", | ||
// Neutral | ||
offBlack: offBlack, | ||
offBlack, | ||
offBlack64: fade(offBlack, 0.64), | ||
@@ -169,3 +122,3 @@ offBlack50: fade(offBlack, 0.5), | ||
offWhite: "#f7f8fa", | ||
white: white, | ||
white, | ||
white64: fade(white, 0.64), | ||
@@ -179,3 +132,3 @@ white50: fade(white, 0.5), | ||
}; | ||
var SemanticColor = { | ||
const SemanticColor = { | ||
controlDefault: Color.blue, | ||
@@ -182,0 +135,0 @@ controlDestructive: Color.red |
@@ -85,3 +85,3 @@ module.exports = | ||
/******/ // Load entry module and return exports | ||
/******/ return __webpack_require__(__webpack_require__.s = 0); | ||
/******/ return __webpack_require__(__webpack_require__.s = 1); | ||
/******/ }) | ||
@@ -91,2 +91,28 @@ /************************************************************************/ | ||
/* 0 */ | ||
/***/ (function(module, exports) { | ||
function _extends() { | ||
module.exports = _extends = Object.assign || function (target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i]; | ||
for (var key in source) { | ||
if (Object.prototype.hasOwnProperty.call(source, key)) { | ||
target[key] = source[key]; | ||
} | ||
} | ||
} | ||
return target; | ||
}; | ||
module.exports["default"] = module.exports, module.exports.__esModule = true; | ||
return _extends.apply(this, arguments); | ||
} | ||
module.exports = _extends; | ||
module.exports["default"] = module.exports, module.exports.__esModule = true; | ||
/***/ }), | ||
/* 1 */ | ||
/***/ (function(module, __webpack_exports__, __webpack_require__) { | ||
@@ -104,9 +130,9 @@ | ||
// EXTERNAL MODULE: ./node_modules/@babel/runtime/helpers/extends.js | ||
var helpers_extends = __webpack_require__(0); | ||
var extends_default = /*#__PURE__*/__webpack_require__.n(helpers_extends); | ||
// CONCATENATED MODULE: ./packages/wonder-blocks-color/src/util/utils.js | ||
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; } | ||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } | ||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
/** | ||
@@ -116,20 +142,20 @@ * A color manipulation library useful for dynamically | ||
*/ | ||
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; | ||
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; | ||
// Parse a color in #abcdef, rgb(...), or rgba(...) form into an object | ||
// with r,g,b,a keys. | ||
var parse = function parse(color) { | ||
const parse = color => { | ||
if (typeof color !== "string") { | ||
throw new Error("Failed to parse color: ".concat(color)); | ||
throw new Error(`Failed to parse color: ${color}`); | ||
} | ||
var color3Match = color.match(color3Regexp); | ||
const color3Match = color.match(color3Regexp); | ||
if (color3Match) { | ||
return { | ||
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), | ||
r: parseInt(`${color3Match[1]}${color3Match[1]}`, 16), | ||
g: parseInt(`${color3Match[2]}${color3Match[2]}`, 16), | ||
b: parseInt(`${color3Match[3]}${color3Match[3]}`, 16), | ||
a: 1 | ||
@@ -139,3 +165,3 @@ }; | ||
var color6Match = color.match(color6Regexp); | ||
const color6Match = color.match(color6Regexp); | ||
@@ -151,3 +177,3 @@ if (color6Match) { | ||
var rgbaMatch = color.match(rgbaRegexp); | ||
const rgbaMatch = color.match(rgbaRegexp); | ||
@@ -163,20 +189,20 @@ if (rgbaMatch) { | ||
throw new Error("Failed to parse color: ".concat(color)); | ||
throw new Error(`Failed to parse color: ${color}`); | ||
}; // Stringify the color in an `rgba()` or `#abcdef` format. | ||
var format = function format(color) { | ||
var r = Math.round(color.r); | ||
var g = Math.round(color.g); | ||
var b = Math.round(color.b); | ||
const format = color => { | ||
const r = Math.round(color.r); | ||
const g = Math.round(color.g); | ||
const b = Math.round(color.b); | ||
if (color.a === 1) { | ||
var _s = function _s(c) { | ||
var asString = c.toString(16); | ||
const _s = c => { | ||
const asString = c.toString(16); | ||
return asString.length === 1 ? asString + asString : asString; | ||
}; | ||
return "#".concat(_s(r)).concat(_s(g)).concat(_s(b)); | ||
return `#${_s(r)}${_s(g)}${_s(b)}`; | ||
} else { | ||
return "rgba(".concat(r, ",").concat(g, ",").concat(b, ",").concat(color.a.toFixed(2), ")"); | ||
return `rgba(${r},${g},${b},${color.a.toFixed(2)})`; | ||
} | ||
@@ -186,3 +212,3 @@ }; // Adjust the alpha value of a color. | ||
var fade = function fade(color, percentage) { | ||
const fade = (color, percentage) => { | ||
if (percentage < 0 || percentage > 1) { | ||
@@ -192,4 +218,4 @@ throw new Error("Percentage must be between 0 and 1"); | ||
var components = parse(color); | ||
return format(_objectSpread(_objectSpread({}, components), {}, { | ||
const components = parse(color); | ||
return format(extends_default()({}, components, { | ||
a: components.a * percentage | ||
@@ -200,5 +226,5 @@ })); | ||
var mix = function mix(color, background) { | ||
var colorObj = parse(color); | ||
var bgObj = parse(background); | ||
const mix = (color, background) => { | ||
const colorObj = parse(color); | ||
const bgObj = parse(background); | ||
return format({ | ||
@@ -213,5 +239,5 @@ r: colorObj.r * colorObj.a + bgObj.r * (1 - colorObj.a), | ||
var offBlack = "#21242c"; | ||
var white = "#ffffff"; | ||
var Color = { | ||
const offBlack = "#21242c"; | ||
const white = "#ffffff"; | ||
const Color = { | ||
// Product | ||
@@ -224,3 +250,3 @@ blue: "#1865f2", | ||
// Neutral | ||
offBlack: offBlack, | ||
offBlack, | ||
offBlack64: fade(offBlack, 0.64), | ||
@@ -232,3 +258,3 @@ offBlack50: fade(offBlack, 0.5), | ||
offWhite: "#f7f8fa", | ||
white: white, | ||
white, | ||
white64: fade(white, 0.64), | ||
@@ -242,3 +268,3 @@ white50: fade(white, 0.5), | ||
}; | ||
var SemanticColor = { | ||
const SemanticColor = { | ||
controlDefault: Color.blue, | ||
@@ -245,0 +271,0 @@ controlDestructive: Color.red |
{ | ||
"name": "@khanacademy/wonder-blocks-color", | ||
"version": "1.1.17", | ||
"version": "1.1.18", | ||
"design": "v2", | ||
@@ -16,7 +16,7 @@ "publishConfig": { | ||
"devDependencies": { | ||
"wb-dev-build-settings": "^0.0.4" | ||
"wb-dev-build-settings": "^0.1.0" | ||
}, | ||
"author": "", | ||
"license": "MIT", | ||
"gitHead": "4aff5c505331e91477e1c8b454b9b2298004bd2d" | ||
"gitHead": "8022bb419eed74be37f71f71c7621854794a731c" | ||
} |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
0
126883
13
959