simpler-color
Advanced tools
Comparing version 0.1.3 to 0.2.0
@@ -1,11 +0,14 @@ | ||
import Color from 'color'; | ||
import normalize from '../normalize'; | ||
import _extends from "@babel/runtime/helpers/esm/extends"; | ||
import colorString from '../color/colorString'; | ||
import hsl from '../color/hsl'; | ||
const lightness = (baseColor, key) => { | ||
if (typeof key !== 'number') return baseColor; | ||
const base = Color(baseColor); | ||
const base = hsl(baseColor); | ||
const targetL = Math.min(Math.max(key, 0), 100); | ||
return normalize(base.lightness(targetL)); | ||
return colorString(_extends({}, base, { | ||
l: targetL | ||
})); | ||
}; | ||
export default lightness; |
@@ -1,11 +0,14 @@ | ||
import Color from 'color'; | ||
import normalize from '../normalize'; | ||
import _extends from "@babel/runtime/helpers/esm/extends"; | ||
import colorString from '../color/colorString'; | ||
import rgb from '../color/rgb'; | ||
const opacity = (baseColor, key) => { | ||
if (typeof key !== 'number') return baseColor; | ||
const base = Color(baseColor); | ||
const base = rgb(baseColor); | ||
const targetA = Math.min(Math.max(key, 0), 1); | ||
return normalize(base.alpha(targetA)); | ||
return colorString(_extends({}, base, { | ||
a: targetA | ||
})); | ||
}; | ||
export default opacity; |
@@ -1,11 +0,14 @@ | ||
import Color from 'color'; | ||
import normalize from '../normalize'; | ||
import _extends from "@babel/runtime/helpers/esm/extends"; | ||
import colorString from '../color/colorString'; | ||
import hsl from '../color/hsl'; | ||
const rotation = (baseColor, key) => { | ||
if (typeof key !== 'number' || key === 0) return baseColor; | ||
const base = Color(baseColor); | ||
const targetH = (base.hue() + key) % 360; | ||
return normalize(base.hue(targetH)); | ||
const base = hsl(baseColor); | ||
const targetH = (base.h + key) % 360; | ||
return colorString(_extends({}, base, { | ||
h: targetH | ||
})); | ||
}; | ||
export default rotation; |
@@ -1,11 +0,14 @@ | ||
import Color from 'color'; | ||
import normalize from '../normalize'; | ||
import _extends from "@babel/runtime/helpers/esm/extends"; | ||
import colorString from '../color/colorString'; | ||
import hsl from '../color/hsl'; | ||
const saturation = (baseColor, key) => { | ||
if (typeof key !== 'number') return baseColor; | ||
const base = Color(baseColor); | ||
const base = hsl(baseColor); | ||
const targetS = Math.min(Math.max(key, 0), 100); | ||
return normalize(base.saturationl(targetS)); | ||
return colorString(_extends({}, base, { | ||
s: targetS | ||
})); | ||
}; | ||
export default saturation; |
@@ -1,6 +0,5 @@ | ||
import Color from 'color'; | ||
import colorString from './color/colorString'; | ||
import rgb from './color/rgb'; | ||
export default function normalize(color) { | ||
const colorObj = typeof color === 'string' ? Color(color) : color; | ||
const hasAlpha = colorObj.alpha() < 1; | ||
return hasAlpha ? colorObj.rgb().string() : colorObj.hex(); | ||
return colorString(rgb(color)); | ||
} |
@@ -1,1 +0,3 @@ | ||
export {}; | ||
export function clamp(value, min, max) { | ||
return Math.max(min, Math.min(value, max)); | ||
} |
@@ -8,11 +8,15 @@ "use strict"; | ||
var _color = _interopRequireDefault(require("color")); | ||
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")); | ||
var _normalize = _interopRequireDefault(require("../normalize")); | ||
var _colorString = _interopRequireDefault(require("../color/colorString")); | ||
var _hsl = _interopRequireDefault(require("../color/hsl")); | ||
var lightness = function lightness(baseColor, key) { | ||
if (typeof key !== 'number') return baseColor; | ||
var base = (0, _color.default)(baseColor); | ||
var base = (0, _hsl.default)(baseColor); | ||
var targetL = Math.min(Math.max(key, 0), 100); | ||
return (0, _normalize.default)(base.lightness(targetL)); | ||
return (0, _colorString.default)((0, _extends2.default)({}, base, { | ||
l: targetL | ||
})); | ||
}; | ||
@@ -19,0 +23,0 @@ |
@@ -8,11 +8,15 @@ "use strict"; | ||
var _color = _interopRequireDefault(require("color")); | ||
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")); | ||
var _normalize = _interopRequireDefault(require("../normalize")); | ||
var _colorString = _interopRequireDefault(require("../color/colorString")); | ||
var _rgb = _interopRequireDefault(require("../color/rgb")); | ||
var opacity = function opacity(baseColor, key) { | ||
if (typeof key !== 'number') return baseColor; | ||
var base = (0, _color.default)(baseColor); | ||
var base = (0, _rgb.default)(baseColor); | ||
var targetA = Math.min(Math.max(key, 0), 1); | ||
return (0, _normalize.default)(base.alpha(targetA)); | ||
return (0, _colorString.default)((0, _extends2.default)({}, base, { | ||
a: targetA | ||
})); | ||
}; | ||
@@ -19,0 +23,0 @@ |
@@ -8,11 +8,15 @@ "use strict"; | ||
var _color = _interopRequireDefault(require("color")); | ||
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")); | ||
var _normalize = _interopRequireDefault(require("../normalize")); | ||
var _colorString = _interopRequireDefault(require("../color/colorString")); | ||
var _hsl = _interopRequireDefault(require("../color/hsl")); | ||
var rotation = function rotation(baseColor, key) { | ||
if (typeof key !== 'number' || key === 0) return baseColor; | ||
var base = (0, _color.default)(baseColor); | ||
var targetH = (base.hue() + key) % 360; | ||
return (0, _normalize.default)(base.hue(targetH)); | ||
var base = (0, _hsl.default)(baseColor); | ||
var targetH = (base.h + key) % 360; | ||
return (0, _colorString.default)((0, _extends2.default)({}, base, { | ||
h: targetH | ||
})); | ||
}; | ||
@@ -19,0 +23,0 @@ |
@@ -8,11 +8,15 @@ "use strict"; | ||
var _color = _interopRequireDefault(require("color")); | ||
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")); | ||
var _normalize = _interopRequireDefault(require("../normalize")); | ||
var _colorString = _interopRequireDefault(require("../color/colorString")); | ||
var _hsl = _interopRequireDefault(require("../color/hsl")); | ||
var saturation = function saturation(baseColor, key) { | ||
if (typeof key !== 'number') return baseColor; | ||
var base = (0, _color.default)(baseColor); | ||
var base = (0, _hsl.default)(baseColor); | ||
var targetS = Math.min(Math.max(key, 0), 100); | ||
return (0, _normalize.default)(base.saturationl(targetS)); | ||
return (0, _colorString.default)((0, _extends2.default)({}, base, { | ||
s: targetS | ||
})); | ||
}; | ||
@@ -19,0 +23,0 @@ |
@@ -8,8 +8,8 @@ "use strict"; | ||
var _color = _interopRequireDefault(require("color")); | ||
var _colorString = _interopRequireDefault(require("./color/colorString")); | ||
var _rgb = _interopRequireDefault(require("./color/rgb")); | ||
function normalize(color) { | ||
var colorObj = typeof color === 'string' ? (0, _color.default)(color) : color; | ||
var hasAlpha = colorObj.alpha() < 1; | ||
return hasAlpha ? colorObj.rgb().string() : colorObj.hex(); | ||
return (0, _colorString.default)((0, _rgb.default)(color)); | ||
} |
"use strict"; | ||
exports.__esModule = true; | ||
exports.__esModule = true; | ||
exports.clamp = clamp; | ||
function clamp(value, min, max) { | ||
return Math.max(min, Math.min(value, max)); | ||
} |
{ | ||
"name": "simpler-color", | ||
"version": "0.1.3", | ||
"version": "0.2.0", | ||
"description": "Simpler Color - Create your own complete color system fast and easy!", | ||
@@ -37,4 +37,3 @@ "keywords": [ | ||
"dependencies": { | ||
"@babel/runtime": "^7.17.8", | ||
"color": "^4.2.0" | ||
"@babel/runtime": "^7.17.8" | ||
}, | ||
@@ -41,0 +40,0 @@ "devDependencies": { |
@@ -1,4 +0,3 @@ | ||
import Color from 'color'; | ||
/** | ||
* Normalizes the color value format into either hex or | ||
* Normalizes the color string format into either hex or | ||
* rgba | ||
@@ -14,2 +13,2 @@ * | ||
*/ | ||
export default function normalize(color: string | Color): string; | ||
export default function normalize(color: string): string; |
export declare type StringOrNumber = string | number; | ||
/** | ||
* Restricts a numerical value between a minimum and | ||
* a maximum | ||
* | ||
* @param value - expression to be evaluated | ||
* @param min - the minimum allowed value | ||
* @param max - the maximum allowed value | ||
* @returns either the same value, the min or the max | ||
*/ | ||
export declare function clamp(value: number, min: number, max: number): number; |
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
89356
1
90
2066
1
- Removedcolor@^4.2.0
- Removedcolor@4.2.3(transitive)
- Removedcolor-convert@2.0.1(transitive)
- Removedcolor-name@1.1.4(transitive)
- Removedcolor-string@1.9.1(transitive)
- Removedis-arrayish@0.3.2(transitive)
- Removedsimple-swizzle@0.2.2(transitive)