simpler-color
Advanced tools
Comparing version 1.0.0 to 1.0.1
export function toDegrees(angle, unit) { | ||
var _a; | ||
const multiplier = { | ||
@@ -7,3 +9,3 @@ rad: 180 / Math.PI, | ||
}; | ||
return angle * (multiplier[unit.toLowerCase()] ?? 1); | ||
return angle * ((_a = multiplier[unit.toLowerCase()]) !== null && _a !== void 0 ? _a : 1); | ||
} | ||
@@ -14,5 +16,7 @@ export function normalizeAngle(degrees) { | ||
export default function angle(str) { | ||
var _a, _b; | ||
const num = parseFloat(str); | ||
const unit = str.match(/deg|rad|grad|turn/i)?.[0] ?? 'deg'; | ||
const unit = (_b = (_a = str.match(/deg|rad|grad|turn/i)) === null || _a === void 0 ? void 0 : _a[0]) !== null && _b !== void 0 ? _b : 'deg'; | ||
return normalizeAngle(toDegrees(num, unit)); | ||
} |
@@ -19,6 +19,8 @@ import { clamp } from '../utils'; | ||
function hslFromParsedHslString(match) { | ||
var _a, _b; | ||
const hslValues = match.map(val => parseFloat(val)); | ||
let alpha = hslValues[3] ?? 1; | ||
let alpha = (_a = hslValues[3]) !== null && _a !== void 0 ? _a : 1; | ||
if (match[3]?.indexOf('%') > -1) { | ||
if (((_b = match[3]) === null || _b === void 0 ? void 0 : _b.indexOf('%')) > -1) { | ||
alpha *= 0.01; | ||
@@ -47,5 +49,7 @@ } | ||
export default function hsl(colorString) { | ||
const hslObj = hslFromColorString(colorString) ?? hslFromRgbString(colorString); | ||
var _a; | ||
const hslObj = (_a = hslFromColorString(colorString)) !== null && _a !== void 0 ? _a : hslFromRgbString(colorString); | ||
if (hslObj === null) throw new Error('Invalid color string'); | ||
return hslObj; | ||
} |
@@ -9,4 +9,6 @@ import { exact, extractValuesFromMatch } from './utils'; | ||
export function matchHexString(colorString) { | ||
const match = exact(hexColorMatcher).exec(colorString) ?? exact(shortHexColorMatcher).exec(colorString); | ||
var _a; | ||
const match = (_a = exact(hexColorMatcher).exec(colorString)) !== null && _a !== void 0 ? _a : exact(shortHexColorMatcher).exec(colorString); | ||
return match ? extractValuesFromMatch(match) : null; | ||
} |
@@ -20,2 +20,4 @@ import { clamp } from '../utils'; | ||
function rgbFromParsedHexString(match) { | ||
var _a; | ||
const rgbValues = match.map(val => { | ||
@@ -28,3 +30,3 @@ if (val.length === 1) { | ||
}); | ||
const alpha = (rgbValues[3] ?? 255) / 255; | ||
const alpha = ((_a = rgbValues[3]) !== null && _a !== void 0 ? _a : 255) / 255; | ||
return { | ||
@@ -39,2 +41,4 @@ r: rgbValues[0], | ||
function rgbFromParsedRgbString(match) { | ||
var _a; | ||
const rgbValues = match.map((val, index) => { | ||
@@ -57,3 +61,3 @@ let num = parseFloat(val); | ||
b: rgbValues[2], | ||
a: rgbValues[3] ?? 1 | ||
a: (_a = rgbValues[3]) !== null && _a !== void 0 ? _a : 1 | ||
}); | ||
@@ -86,5 +90,7 @@ } | ||
export default function rgb(colorString) { | ||
const rgbObj = rgbFromColorString(colorString) ?? rgbFromHslString(colorString); | ||
var _a; | ||
const rgbObj = (_a = rgbFromColorString(colorString)) !== null && _a !== void 0 ? _a : rgbFromHslString(colorString); | ||
if (rgbObj === null) throw new Error('Invalid color string'); | ||
return rgbObj; | ||
} |
@@ -6,5 +6,5 @@ import colorSet from './colorSet'; | ||
noCache | ||
} = options ?? {}; | ||
} = options !== null && options !== void 0 ? options : {}; | ||
const colors = colorSet(baseColors, colorMapping, noCache); | ||
return roleMapping(colors); | ||
} |
@@ -1,2 +0,1 @@ | ||
import _extends from "@babel/runtime/helpers/esm/extends"; | ||
import palette from './palette'; | ||
@@ -6,3 +5,3 @@ export default function colorSet(baseColors, colorMapping, noCache) { | ||
return colorClasses.reduce((palettes, colorClass) => { | ||
return _extends({}, palettes, { | ||
return Object.assign(Object.assign({}, palettes), { | ||
[colorClass]: palette(baseColors[colorClass], colorMapping, noCache) | ||
@@ -9,0 +8,0 @@ }); |
@@ -1,2 +0,1 @@ | ||
import _extends from "@babel/runtime/helpers/esm/extends"; | ||
import colorString from '../color/colorString'; | ||
@@ -9,3 +8,3 @@ import hsl from '../color/hsl'; | ||
const targetL = Math.min(Math.max(key, 0), 100); | ||
return colorString(_extends({}, base, { | ||
return colorString(Object.assign(Object.assign({}, base), { | ||
l: targetL | ||
@@ -12,0 +11,0 @@ })); |
@@ -1,2 +0,1 @@ | ||
import _extends from "@babel/runtime/helpers/esm/extends"; | ||
import colorString from '../color/colorString'; | ||
@@ -9,3 +8,3 @@ import rgb from '../color/rgb'; | ||
const targetA = Math.min(Math.max(key, 0), 1); | ||
return colorString(_extends({}, base, { | ||
return colorString(Object.assign(Object.assign({}, base), { | ||
a: targetA | ||
@@ -12,0 +11,0 @@ })); |
@@ -1,2 +0,1 @@ | ||
import _extends from "@babel/runtime/helpers/esm/extends"; | ||
import colorString from '../color/colorString'; | ||
@@ -9,3 +8,3 @@ import hsl from '../color/hsl'; | ||
const targetH = (base.h + key) % 360; | ||
return colorString(_extends({}, base, { | ||
return colorString(Object.assign(Object.assign({}, base), { | ||
h: targetH | ||
@@ -12,0 +11,0 @@ })); |
@@ -1,2 +0,1 @@ | ||
import _extends from "@babel/runtime/helpers/esm/extends"; | ||
import colorString from '../color/colorString'; | ||
@@ -9,3 +8,3 @@ import hsl from '../color/hsl'; | ||
const targetS = Math.min(Math.max(key, 0), 100); | ||
return colorString(_extends({}, base, { | ||
return colorString(Object.assign(Object.assign({}, base), { | ||
s: targetS | ||
@@ -12,0 +11,0 @@ })); |
@@ -9,3 +9,3 @@ "use strict"; | ||
function toDegrees(angle, unit) { | ||
var _multiplier$unit$toLo; | ||
var _a; | ||
@@ -17,3 +17,3 @@ var multiplier = { | ||
}; | ||
return angle * ((_multiplier$unit$toLo = multiplier[unit.toLowerCase()]) != null ? _multiplier$unit$toLo : 1); | ||
return angle * ((_a = multiplier[unit.toLowerCase()]) !== null && _a !== void 0 ? _a : 1); | ||
} | ||
@@ -26,7 +26,7 @@ | ||
function angle(str) { | ||
var _str$match$, _str$match; | ||
var _a, _b; | ||
var num = parseFloat(str); | ||
var unit = (_str$match$ = (_str$match = str.match(/deg|rad|grad|turn/i)) == null ? void 0 : _str$match[0]) != null ? _str$match$ : 'deg'; | ||
var unit = (_b = (_a = str.match(/deg|rad|grad|turn/i)) === null || _a === void 0 ? void 0 : _a[0]) !== null && _b !== void 0 ? _b : 'deg'; | ||
return normalizeAngle(toDegrees(num, unit)); | ||
} |
@@ -39,3 +39,3 @@ "use strict"; | ||
function hslFromParsedHslString(match) { | ||
var _hslValues$, _match$; | ||
var _a, _b; | ||
@@ -45,5 +45,5 @@ var hslValues = match.map(function (val) { | ||
}); | ||
var alpha = (_hslValues$ = hslValues[3]) != null ? _hslValues$ : 1; | ||
var alpha = (_a = hslValues[3]) !== null && _a !== void 0 ? _a : 1; | ||
if (((_match$ = match[3]) == null ? void 0 : _match$.indexOf('%')) > -1) { | ||
if (((_b = match[3]) === null || _b === void 0 ? void 0 : _b.indexOf('%')) > -1) { | ||
alpha *= 0.01; | ||
@@ -73,7 +73,7 @@ } | ||
function hsl(colorString) { | ||
var _hslFromColorString; | ||
var _a; | ||
var hslObj = (_hslFromColorString = hslFromColorString(colorString)) != null ? _hslFromColorString : hslFromRgbString(colorString); | ||
var hslObj = (_a = hslFromColorString(colorString)) !== null && _a !== void 0 ? _a : hslFromRgbString(colorString); | ||
if (hslObj === null) throw new Error('Invalid color string'); | ||
return hslObj; | ||
} |
@@ -22,6 +22,6 @@ "use strict"; | ||
function matchHexString(colorString) { | ||
var _exact$exec; | ||
var _a; | ||
var match = (_exact$exec = (0, _utils.exact)(hexColorMatcher).exec(colorString)) != null ? _exact$exec : (0, _utils.exact)(shortHexColorMatcher).exec(colorString); | ||
var match = (_a = (0, _utils.exact)(hexColorMatcher).exec(colorString)) !== null && _a !== void 0 ? _a : (0, _utils.exact)(shortHexColorMatcher).exec(colorString); | ||
return match ? (0, _utils.extractValuesFromMatch)(match) : null; | ||
} |
@@ -37,3 +37,3 @@ "use strict"; | ||
function rgbFromParsedHexString(match) { | ||
var _rgbValues$; | ||
var _a; | ||
@@ -47,3 +47,3 @@ var rgbValues = match.map(function (val) { | ||
}); | ||
var alpha = ((_rgbValues$ = rgbValues[3]) != null ? _rgbValues$ : 255) / 255; | ||
var alpha = ((_a = rgbValues[3]) !== null && _a !== void 0 ? _a : 255) / 255; | ||
return { | ||
@@ -58,3 +58,3 @@ r: rgbValues[0], | ||
function rgbFromParsedRgbString(match) { | ||
var _rgbValues$2; | ||
var _a; | ||
@@ -78,3 +78,3 @@ var rgbValues = match.map(function (val, index) { | ||
b: rgbValues[2], | ||
a: (_rgbValues$2 = rgbValues[3]) != null ? _rgbValues$2 : 1 | ||
a: (_a = rgbValues[3]) !== null && _a !== void 0 ? _a : 1 | ||
}); | ||
@@ -108,7 +108,7 @@ } | ||
function rgb(colorString) { | ||
var _rgbFromColorString; | ||
var _a; | ||
var rgbObj = (_rgbFromColorString = rgbFromColorString(colorString)) != null ? _rgbFromColorString : rgbFromHslString(colorString); | ||
var rgbObj = (_a = rgbFromColorString(colorString)) !== null && _a !== void 0 ? _a : rgbFromHslString(colorString); | ||
if (rgbObj === null) throw new Error('Invalid color string'); | ||
return rgbObj; | ||
} |
@@ -11,3 +11,3 @@ "use strict"; | ||
function colorScheme(baseColors, roleMapping, options) { | ||
var _ref = options != null ? options : {}, | ||
var _ref = options !== null && options !== void 0 ? options : {}, | ||
colorMapping = _ref.colorMapping, | ||
@@ -14,0 +14,0 @@ noCache = _ref.noCache; |
@@ -8,4 +8,2 @@ "use strict"; | ||
var _extends3 = _interopRequireDefault(require("@babel/runtime/helpers/extends")); | ||
var _palette = _interopRequireDefault(require("./palette")); | ||
@@ -16,6 +14,6 @@ | ||
return colorClasses.reduce(function (palettes, colorClass) { | ||
var _extends2; | ||
var _Object$assign; | ||
return (0, _extends3.default)({}, palettes, (_extends2 = {}, _extends2[colorClass] = (0, _palette.default)(baseColors[colorClass], colorMapping, noCache), _extends2)); | ||
return Object.assign(Object.assign({}, palettes), (_Object$assign = {}, _Object$assign[colorClass] = (0, _palette.default)(baseColors[colorClass], colorMapping, noCache), _Object$assign)); | ||
}, {}); | ||
} |
@@ -8,4 +8,2 @@ "use strict"; | ||
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")); | ||
var _colorString = _interopRequireDefault(require("../color/colorString")); | ||
@@ -19,3 +17,3 @@ | ||
var targetL = Math.min(Math.max(key, 0), 100); | ||
return (0, _colorString.default)((0, _extends2.default)({}, base, { | ||
return (0, _colorString.default)(Object.assign(Object.assign({}, base), { | ||
l: targetL | ||
@@ -22,0 +20,0 @@ })); |
@@ -8,4 +8,2 @@ "use strict"; | ||
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")); | ||
var _colorString = _interopRequireDefault(require("../color/colorString")); | ||
@@ -19,3 +17,3 @@ | ||
var targetA = Math.min(Math.max(key, 0), 1); | ||
return (0, _colorString.default)((0, _extends2.default)({}, base, { | ||
return (0, _colorString.default)(Object.assign(Object.assign({}, base), { | ||
a: targetA | ||
@@ -22,0 +20,0 @@ })); |
@@ -8,4 +8,2 @@ "use strict"; | ||
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")); | ||
var _colorString = _interopRequireDefault(require("../color/colorString")); | ||
@@ -19,3 +17,3 @@ | ||
var targetH = (base.h + key) % 360; | ||
return (0, _colorString.default)((0, _extends2.default)({}, base, { | ||
return (0, _colorString.default)(Object.assign(Object.assign({}, base), { | ||
h: targetH | ||
@@ -22,0 +20,0 @@ })); |
@@ -8,4 +8,2 @@ "use strict"; | ||
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")); | ||
var _colorString = _interopRequireDefault(require("../color/colorString")); | ||
@@ -19,3 +17,3 @@ | ||
var targetS = Math.min(Math.max(key, 0), 100); | ||
return (0, _colorString.default)((0, _extends2.default)({}, base, { | ||
return (0, _colorString.default)(Object.assign(Object.assign({}, base), { | ||
s: targetS | ||
@@ -22,0 +20,0 @@ })); |
{ | ||
"name": "simpler-color", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Simpler Color - Create your own complete color system fast and easy!", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
92960
2087