@ctrl/tinycolor
Advanced tools
Comparing version 2.0.1 to 2.1.0
@@ -1,7 +0,1 @@ | ||
/** | ||
* Handle bounds / percentage checking to conform to CSS color spec | ||
* <http://www.w3.org/TR/css3-color/> | ||
* *Assumes:* r, g, b in [0, 255] or [0, 1] | ||
* *Returns:* { r, g, b } in [0, 255] | ||
*/ | ||
export declare function rgbToRgb(r: number, g: number, b: number): { | ||
@@ -12,7 +6,2 @@ r: number; | ||
}; | ||
/** | ||
* Converts an RGB color value to HSL. | ||
* *Assumes:* r, g, and b are contained in [0, 255] or [0, 1] | ||
* *Returns:* { h, s, l } in [0,1] | ||
*/ | ||
export declare function rgbToHsl(r: number, g: number, b: number): { | ||
@@ -23,8 +12,2 @@ h: number; | ||
}; | ||
/** | ||
* Converts an HSL color value to RGB. | ||
* | ||
* *Assumes:* h is contained in [0, 1] or [0, 360] and s and l are contained [0, 1] or [0, 100] | ||
* *Returns:* { r, g, b } in the set [0, 255] | ||
*/ | ||
export declare function hslToRgb(h: number, s: number, l: number): { | ||
@@ -35,8 +18,2 @@ r: number; | ||
}; | ||
/** | ||
* Converts an RGB color value to HSV | ||
* | ||
* *Assumes:* r, g, and b are contained in the set [0, 255] or [0, 1] | ||
* *Returns:* { h, s, v } in [0,1] | ||
*/ | ||
export declare function rgbToHsv(r: number, g: number, b: number): { | ||
@@ -47,8 +24,2 @@ h: number; | ||
}; | ||
/** | ||
* Converts an HSV color value to RGB. | ||
* | ||
* *Assumes:* h is contained in [0, 1] or [0, 360] and s and v are contained in [0, 1] or [0, 100] | ||
* *Returns:* { r, g, b } in the set [0, 255] | ||
*/ | ||
export declare function hsvToRgb(h: number, s: number, v: number): { | ||
@@ -59,26 +30,7 @@ r: number; | ||
}; | ||
/** | ||
* Converts an RGB color to hex | ||
* | ||
* Assumes r, g, and b are contained in the set [0, 255] | ||
* Returns a 3 or 6 character hex | ||
*/ | ||
export declare function rgbToHex(r: number, g: number, b: number, allow3Char: boolean): string; | ||
/** | ||
* Converts an RGBA color plus alpha transparency to hex | ||
* | ||
* Assumes r, g, b are contained in the set [0, 255] and | ||
* a in [0, 1]. Returns a 4 or 8 character rgba hex | ||
*/ | ||
export declare function rgbaToHex(r: number, g: number, b: number, a: number, allow4Char: boolean): string; | ||
/** | ||
* Converts an RGBA color to an ARGB Hex8 string | ||
* Rarely used, but required for "toFilter()" | ||
*/ | ||
export declare function rgbaToArgbHex(r: number, g: number, b: number, a: number): string; | ||
/** Converts a decimal to a hex value */ | ||
export declare function convertDecimalToHex(d: string | number): string; | ||
/** Converts a hex value to a decimal */ | ||
export declare function convertHexToDecimal(h: string): number; | ||
/** Parse a base-16 hex value into a base-10 integer */ | ||
export declare function parseIntFromHex(val: string): number; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const util_1 = require("./util"); | ||
// `rgbToHsl`, `rgbToHsv`, `hslToRgb`, `hsvToRgb` modified from: | ||
// <http://mjijackson.com/2008/02/rgb-to-hsl-and-rgb-to-hsv-color-model-conversion-algorithms-in-javascript> | ||
/** | ||
* Handle bounds / percentage checking to conform to CSS color spec | ||
* <http://www.w3.org/TR/css3-color/> | ||
* *Assumes:* r, g, b in [0, 255] or [0, 1] | ||
* *Returns:* { r, g, b } in [0, 255] | ||
*/ | ||
var util_1 = require("./util"); | ||
function rgbToRgb(r, g, b) { | ||
@@ -20,7 +12,2 @@ return { | ||
exports.rgbToRgb = rgbToRgb; | ||
/** | ||
* Converts an RGB color value to HSL. | ||
* *Assumes:* r, g, and b are contained in [0, 255] or [0, 1] | ||
* *Returns:* { h, s, l } in [0,1] | ||
*/ | ||
function rgbToHsl(r, g, b) { | ||
@@ -30,12 +17,12 @@ r = util_1.bound01(r, 255); | ||
b = util_1.bound01(b, 255); | ||
const max = Math.max(r, g, b); | ||
const min = Math.min(r, g, b); | ||
let h = 0; | ||
let s = 0; | ||
const l = (max + min) / 2; | ||
var max = Math.max(r, g, b); | ||
var min = Math.min(r, g, b); | ||
var h = 0; | ||
var s = 0; | ||
var l = (max + min) / 2; | ||
if (max === min) { | ||
h = s = 0; // achromatic | ||
h = s = 0; | ||
} | ||
else { | ||
const d = max - min; | ||
var d = max - min; | ||
s = l > 0.5 ? d / (2 - max - min) : d / (max + min); | ||
@@ -55,15 +42,9 @@ switch (max) { | ||
} | ||
return { h, s, l }; | ||
return { h: h, s: s, l: l }; | ||
} | ||
exports.rgbToHsl = rgbToHsl; | ||
/** | ||
* Converts an HSL color value to RGB. | ||
* | ||
* *Assumes:* h is contained in [0, 1] or [0, 360] and s and l are contained [0, 1] or [0, 100] | ||
* *Returns:* { r, g, b } in the set [0, 255] | ||
*/ | ||
function hslToRgb(h, s, l) { | ||
let r; | ||
let g; | ||
let b; | ||
var r; | ||
var g; | ||
var b; | ||
h = util_1.bound01(h, 360); | ||
@@ -89,7 +70,7 @@ s = util_1.bound01(s, 100); | ||
if (s === 0) { | ||
r = g = b = l; // achromatic | ||
r = g = b = l; | ||
} | ||
else { | ||
const q = l < 0.5 ? l * (1 + s) : l + s - l * s; | ||
const p = 2 * l - q; | ||
var q = l < 0.5 ? l * (1 + s) : l + s - l * s; | ||
var p = 2 * l - q; | ||
r = hue2rgb(p, q, h + 1 / 3); | ||
@@ -102,8 +83,2 @@ g = hue2rgb(p, q, h); | ||
exports.hslToRgb = hslToRgb; | ||
/** | ||
* Converts an RGB color value to HSV | ||
* | ||
* *Assumes:* r, g, and b are contained in the set [0, 255] or [0, 1] | ||
* *Returns:* { h, s, v } in [0,1] | ||
*/ | ||
function rgbToHsv(r, g, b) { | ||
@@ -113,10 +88,10 @@ r = util_1.bound01(r, 255); | ||
b = util_1.bound01(b, 255); | ||
const max = Math.max(r, g, b); | ||
const min = Math.min(r, g, b); | ||
let h = 0; | ||
const v = max; | ||
const d = max - min; | ||
const s = max === 0 ? 0 : d / max; | ||
var max = Math.max(r, g, b); | ||
var min = Math.min(r, g, b); | ||
var h = 0; | ||
var v = max; | ||
var d = max - min; | ||
var s = max === 0 ? 0 : d / max; | ||
if (max === min) { | ||
h = 0; // achromatic | ||
h = 0; | ||
} | ||
@@ -140,8 +115,2 @@ else { | ||
exports.rgbToHsv = rgbToHsv; | ||
/** | ||
* Converts an HSV color value to RGB. | ||
* | ||
* *Assumes:* h is contained in [0, 1] or [0, 360] and s and v are contained in [0, 1] or [0, 100] | ||
* *Returns:* { r, g, b } in the set [0, 255] | ||
*/ | ||
function hsvToRgb(h, s, v) { | ||
@@ -151,22 +120,16 @@ h = util_1.bound01(h, 360) * 6; | ||
v = util_1.bound01(v, 100); | ||
const i = Math.floor(h); | ||
const f = h - i; | ||
const p = v * (1 - s); | ||
const q = v * (1 - f * s); | ||
const t = v * (1 - (1 - f) * s); | ||
const mod = i % 6; | ||
const r = [v, q, p, p, t, v][mod]; | ||
const g = [t, v, v, q, p, p][mod]; | ||
const b = [p, p, t, v, v, q][mod]; | ||
var i = Math.floor(h); | ||
var f = h - i; | ||
var p = v * (1 - s); | ||
var q = v * (1 - f * s); | ||
var t = v * (1 - (1 - f) * s); | ||
var mod = i % 6; | ||
var r = [v, q, p, p, t, v][mod]; | ||
var g = [t, v, v, q, p, p][mod]; | ||
var b = [p, p, t, v, v, q][mod]; | ||
return { r: r * 255, g: g * 255, b: b * 255 }; | ||
} | ||
exports.hsvToRgb = hsvToRgb; | ||
/** | ||
* Converts an RGB color to hex | ||
* | ||
* Assumes r, g, and b are contained in the set [0, 255] | ||
* Returns a 3 or 6 character hex | ||
*/ | ||
function rgbToHex(r, g, b, allow3Char) { | ||
const hex = [ | ||
var hex = [ | ||
util_1.pad2(Math.round(r).toString(16)), | ||
@@ -176,3 +139,2 @@ util_1.pad2(Math.round(g).toString(16)), | ||
]; | ||
// Return a 3 character hex if possible | ||
if (allow3Char && | ||
@@ -187,10 +149,4 @@ hex[0].charAt(0) === hex[0].charAt(1) && | ||
exports.rgbToHex = rgbToHex; | ||
/** | ||
* Converts an RGBA color plus alpha transparency to hex | ||
* | ||
* Assumes r, g, b are contained in the set [0, 255] and | ||
* a in [0, 1]. Returns a 4 or 8 character rgba hex | ||
*/ | ||
function rgbaToHex(r, g, b, a, allow4Char) { | ||
const hex = [ | ||
var hex = [ | ||
util_1.pad2(Math.round(r).toString(16)), | ||
@@ -201,3 +157,2 @@ util_1.pad2(Math.round(g).toString(16)), | ||
]; | ||
// Return a 4 character hex if possible | ||
if (allow4Char && | ||
@@ -213,8 +168,4 @@ hex[0].charAt(0) === hex[0].charAt(1) && | ||
exports.rgbaToHex = rgbaToHex; | ||
/** | ||
* Converts an RGBA color to an ARGB Hex8 string | ||
* Rarely used, but required for "toFilter()" | ||
*/ | ||
function rgbaToArgbHex(r, g, b, a) { | ||
const hex = [ | ||
var hex = [ | ||
util_1.pad2(convertDecimalToHex(a)), | ||
@@ -228,3 +179,2 @@ util_1.pad2(Math.round(r).toString(16)), | ||
exports.rgbaToArgbHex = rgbaToArgbHex; | ||
/** Converts a decimal to a hex value */ | ||
function convertDecimalToHex(d) { | ||
@@ -234,3 +184,2 @@ return Math.round(parseFloat(d) * 255).toString(16); | ||
exports.convertDecimalToHex = convertDecimalToHex; | ||
/** Converts a hex value to a decimal */ | ||
function convertHexToDecimal(h) { | ||
@@ -240,3 +189,2 @@ return parseIntFromHex(h) / 255; | ||
exports.convertHexToDecimal = convertHexToDecimal; | ||
/** Parse a base-16 hex value into a base-10 integer */ | ||
function parseIntFromHex(val) { | ||
@@ -246,2 +194,1 @@ return parseInt(val, 16); | ||
exports.parseIntFromHex = parseIntFromHex; | ||
//# sourceMappingURL=conversion.js.map |
@@ -1,6 +0,3 @@ | ||
/** | ||
* @hidden | ||
*/ | ||
export declare const names: { | ||
[key: string]: string; | ||
}; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
// https://github.com/bahamas10/css-color-names/blob/master/css-color-names.json | ||
/** | ||
* @hidden | ||
*/ | ||
exports.names = { | ||
@@ -157,2 +153,1 @@ aliceblue: '#f0f8ff', | ||
}; | ||
//# sourceMappingURL=css-color-names.js.map |
import { HSL, HSLA, HSV, HSVA, RGB, RGBA } from './interfaces'; | ||
/** | ||
* Given a string or object, convert that input to RGB | ||
* | ||
* Possible string inputs: | ||
* ``` | ||
* "red" | ||
* "#f00" or "f00" | ||
* "#ff0000" or "ff0000" | ||
* "#ff000000" or "ff000000" | ||
* "rgb 255 0 0" or "rgb (255, 0, 0)" | ||
* "rgb 1.0 0 0" or "rgb (1, 0, 0)" | ||
* "rgba (255, 0, 0, 1)" or "rgba 255, 0, 0, 1" | ||
* "rgba (1.0, 0, 0, 1)" or "rgba 1.0, 0, 0, 1" | ||
* "hsl(0, 100%, 50%)" or "hsl 0 100% 50%" | ||
* "hsla(0, 100%, 50%, 1)" or "hsla 0 100% 50%, 1" | ||
* "hsv(0, 100%, 100%)" or "hsv 0 100% 100%" | ||
* ``` | ||
*/ | ||
export declare function inputToRGB(color: string | RGB | RGBA | HSL | HSLA | HSV | HSVA | any): { | ||
@@ -28,11 +10,3 @@ ok: boolean; | ||
}; | ||
/** | ||
* Permissive string parsing. Take in a number of formats, and output an object | ||
* based on detected format. Returns `{ r, g, b }` or `{ h, s, l }` or `{ h, s, v}` | ||
*/ | ||
export declare function stringInputToObject(color: string): any; | ||
/** | ||
* Check to see if it looks like a CSS unit | ||
* (see `matchers` above for definition). | ||
*/ | ||
export declare function isValidCSSUnit(color: string | number): boolean; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const conversion_1 = require("./conversion"); | ||
const css_color_names_1 = require("./css-color-names"); | ||
const util_1 = require("./util"); | ||
/** | ||
* Given a string or object, convert that input to RGB | ||
* | ||
* Possible string inputs: | ||
* ``` | ||
* "red" | ||
* "#f00" or "f00" | ||
* "#ff0000" or "ff0000" | ||
* "#ff000000" or "ff000000" | ||
* "rgb 255 0 0" or "rgb (255, 0, 0)" | ||
* "rgb 1.0 0 0" or "rgb (1, 0, 0)" | ||
* "rgba (255, 0, 0, 1)" or "rgba 255, 0, 0, 1" | ||
* "rgba (1.0, 0, 0, 1)" or "rgba 1.0, 0, 0, 1" | ||
* "hsl(0, 100%, 50%)" or "hsl 0 100% 50%" | ||
* "hsla(0, 100%, 50%, 1)" or "hsla 0 100% 50%, 1" | ||
* "hsv(0, 100%, 100%)" or "hsv 0 100% 100%" | ||
* ``` | ||
*/ | ||
var conversion_1 = require("./conversion"); | ||
var css_color_names_1 = require("./css-color-names"); | ||
var util_1 = require("./util"); | ||
function inputToRGB(color) { | ||
let rgb = { r: 0, g: 0, b: 0 }; | ||
let a = 1; | ||
let s = null; | ||
let v = null; | ||
let l = null; | ||
let ok = false; | ||
let format = false; | ||
var rgb = { r: 0, g: 0, b: 0 }; | ||
var a = 1; | ||
var s = null; | ||
var v = null; | ||
var l = null; | ||
var ok = false; | ||
var format = false; | ||
if (typeof color === 'string') { | ||
@@ -61,3 +43,3 @@ color = stringInputToObject(color); | ||
return { | ||
ok, | ||
ok: ok, | ||
format: color.format || format, | ||
@@ -67,18 +49,12 @@ r: Math.min(255, Math.max(rgb.r, 0)), | ||
b: Math.min(255, Math.max(rgb.b, 0)), | ||
a, | ||
a: a, | ||
}; | ||
} | ||
exports.inputToRGB = inputToRGB; | ||
// <http://www.w3.org/TR/css3-values/#integers> | ||
const CSS_INTEGER = '[-\\+]?\\d+%?'; | ||
// <http://www.w3.org/TR/css3-values/#number-value> | ||
const CSS_NUMBER = '[-\\+]?\\d*\\.\\d+%?'; | ||
// Allow positive/negative integer/number. Don't capture the either/or, just the entire outcome. | ||
const CSS_UNIT = `(?:${CSS_NUMBER})|(?:${CSS_INTEGER})`; | ||
// Actual matching. | ||
// Parentheses and commas are optional, but not required. | ||
// Whitespace can take the place of commas or opening paren | ||
const PERMISSIVE_MATCH3 = `[\\s|\\(]+(${CSS_UNIT})[,|\\s]+(${CSS_UNIT})[,|\\s]+(${CSS_UNIT})\\s*\\)?`; | ||
const PERMISSIVE_MATCH4 = `[\\s|\\(]+(${CSS_UNIT})[,|\\s]+(${CSS_UNIT})[,|\\s]+(${CSS_UNIT})[,|\\s]+(${CSS_UNIT})\\s*\\)?`; | ||
const matchers = { | ||
var CSS_INTEGER = '[-\\+]?\\d+%?'; | ||
var CSS_NUMBER = '[-\\+]?\\d*\\.\\d+%?'; | ||
var CSS_UNIT = "(?:" + CSS_NUMBER + ")|(?:" + CSS_INTEGER + ")"; | ||
var PERMISSIVE_MATCH3 = "[\\s|\\(]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")\\s*\\)?"; | ||
var PERMISSIVE_MATCH4 = "[\\s|\\(]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")\\s*\\)?"; | ||
var matchers = { | ||
CSS_UNIT: new RegExp(CSS_UNIT), | ||
@@ -96,6 +72,2 @@ rgb: new RegExp('rgb' + PERMISSIVE_MATCH3), | ||
}; | ||
/** | ||
* Permissive string parsing. Take in a number of formats, and output an object | ||
* based on detected format. Returns `{ r, g, b }` or `{ h, s, l }` or `{ h, s, v}` | ||
*/ | ||
function stringInputToObject(color) { | ||
@@ -106,3 +78,3 @@ color = color.trim().toLowerCase(); | ||
} | ||
let named = false; | ||
var named = false; | ||
if (css_color_names_1.names[color]) { | ||
@@ -115,7 +87,3 @@ color = css_color_names_1.names[color]; | ||
} | ||
// Try to match string input using regular expressions. | ||
// Keep most of the number bounding out of this function - don't worry about [0,1] or [0,100] or [0,360] | ||
// Just return an object and let the conversion functions handle that. | ||
// This way the result will be the same whether the tinycolor is initialized with string or object. | ||
let match = matchers.rgb.exec(color); | ||
var match = matchers.rgb.exec(color); | ||
if (match) { | ||
@@ -185,6 +153,2 @@ return { r: match[1], g: match[2], b: match[3] }; | ||
exports.stringInputToObject = stringInputToObject; | ||
/** | ||
* Check to see if it looks like a CSS unit | ||
* (see `matchers` above for definition). | ||
*/ | ||
function isValidCSSUnit(color) { | ||
@@ -194,2 +158,1 @@ return !!matchers.CSS_UNIT.exec(String(color)); | ||
exports.isValidCSSUnit = isValidCSSUnit; | ||
//# sourceMappingURL=format-input.js.map |
@@ -8,8 +8,3 @@ import { TinyColor } from './index'; | ||
} | ||
/** | ||
* If input is an object, force 1 into "1.0" to handle ratios properly | ||
* String input requires "1.0" as input, so 1 will be treated as 1 | ||
*/ | ||
export declare function fromRatio(ratio: RatioInput, opts?: any): TinyColor; | ||
/** old random function */ | ||
export declare function legacyRandom(): TinyColor; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const index_1 = require("./index"); | ||
const util_1 = require("./util"); | ||
/** | ||
* If input is an object, force 1 into "1.0" to handle ratios properly | ||
* String input requires "1.0" as input, so 1 will be treated as 1 | ||
*/ | ||
var index_1 = require("./index"); | ||
var util_1 = require("./util"); | ||
function fromRatio(ratio, opts) { | ||
const newColor = { | ||
var newColor = { | ||
r: util_1.convertToPercentage(ratio.r), | ||
@@ -21,3 +17,2 @@ g: util_1.convertToPercentage(ratio.g), | ||
exports.fromRatio = fromRatio; | ||
/** old random function */ | ||
function legacyRandom() { | ||
@@ -31,2 +26,1 @@ return new index_1.TinyColor({ | ||
exports.legacyRandom = legacyRandom; | ||
//# sourceMappingURL=from-ratio.js.map |
121
index.d.ts
@@ -9,18 +9,10 @@ import { HSL, HSLA, HSV, HSVA, RGB, RGBA } from './interfaces'; | ||
export declare class TinyColor { | ||
/** red */ | ||
r: number; | ||
/** green */ | ||
g: number; | ||
/** blue */ | ||
b: number; | ||
/** alpha */ | ||
a: number; | ||
/** the format used to create the tinycolor instance */ | ||
format: ColorFormats; | ||
/** input passed into the constructer used to create the tinycolor instance */ | ||
originalInput: ColorInput; | ||
/** the color was successfully parsed */ | ||
isValid: boolean; | ||
gradientType?: string; | ||
/** rounded alpha */ | ||
roundA: number; | ||
@@ -30,19 +22,5 @@ constructor(color?: ColorInput, opts?: Partial<TinyColorOptions>); | ||
isLight(): boolean; | ||
/** | ||
* Returns the perceived brightness of the color, from 0-255. | ||
*/ | ||
getBrightness(): number; | ||
/** | ||
* Returns the perceived luminance of a color, from 0-1. | ||
*/ | ||
getLuminance(): number; | ||
/** | ||
* Sets the alpha value on the current color. | ||
* | ||
* @param alpha - The new alpha value. The accepted range is 0-1. | ||
*/ | ||
setAlpha(alpha?: string | number): TinyColor; | ||
/** | ||
* Returns the object as a HSVA object. | ||
*/ | ||
toHsv(): { | ||
@@ -54,10 +32,3 @@ h: number; | ||
}; | ||
/** | ||
* Returns the hsva values interpolated into a string with the following format: | ||
* "hsva(xxx, xxx, xxx, xx)". | ||
*/ | ||
toHsvString(): string; | ||
/** | ||
* Returns the object as a HSLA object. | ||
*/ | ||
toHsl(): { | ||
@@ -69,30 +40,7 @@ h: number; | ||
}; | ||
/** | ||
* Returns the hsla values interpolated into a string with the following format: | ||
* "hsla(xxx, xxx, xxx, xx)". | ||
*/ | ||
toHslString(): string; | ||
/** | ||
* Returns the hex value of the color. | ||
* @param allow3Char will shorten hex value to 3 char if possible | ||
*/ | ||
toHex(allow3Char?: boolean): string; | ||
/** | ||
* Returns the hex value of the color -with a # appened. | ||
* @param allow3Char will shorten hex value to 3 char if possible | ||
*/ | ||
toHexString(allow3Char?: boolean): string; | ||
/** | ||
* Returns the hex 8 value of the color. | ||
* @param allow4Char will shorten hex value to 4 char if possible | ||
*/ | ||
toHex8(allow4Char?: boolean): string; | ||
/** | ||
* Returns the hex 8 value of the color -with a # appened. | ||
* @param allow4Char will shorten hex value to 4 char if possible | ||
*/ | ||
toHex8String(allow4Char?: boolean): string; | ||
/** | ||
* Returns the object as a RGBA object. | ||
*/ | ||
toRgb(): { | ||
@@ -104,10 +52,3 @@ r: number; | ||
}; | ||
/** | ||
* Returns the RGBA values interpolated into a string with the following format: | ||
* "RGBA(xxx, xxx, xxx, xx)". | ||
*/ | ||
toRgbString(): string; | ||
/** | ||
* Returns the object as a RGBA object. | ||
*/ | ||
toPercentageRgb(): { | ||
@@ -119,71 +60,17 @@ r: string; | ||
}; | ||
/** | ||
* Returns the RGBA relative values interpolated into a string | ||
*/ | ||
toPercentageRgbString(): string; | ||
/** | ||
* The 'real' name of the color -if there is one. | ||
*/ | ||
toName(): string | false; | ||
/** | ||
* String representation of the color. | ||
* | ||
* @param format - The format to be used when displaying the string representation. | ||
*/ | ||
toString(format?: ColorFormats): string | false; | ||
clone(): TinyColor; | ||
/** | ||
* Lighten the color a given amount. Providing 100 will always return white. | ||
* @param amount - valid between 1-100 | ||
*/ | ||
lighten(amount?: number): TinyColor; | ||
/** | ||
* Brighten the color a given amount, from 0 to 100. | ||
* @param amount - valid between 1-100 | ||
*/ | ||
brighten(amount?: number): TinyColor; | ||
/** | ||
* Darken the color a given amount, from 0 to 100. | ||
* Providing 100 will always return black. | ||
* @param amount - valid between 1-100 | ||
*/ | ||
darken(amount?: number): TinyColor; | ||
/** | ||
* Mix the color with pure white, from 0 to 100. | ||
* Providing 0 will do nothing, providing 100 will always return white. | ||
* @param amount - valid between 1-100 | ||
*/ | ||
tint(amount?: number): TinyColor; | ||
/** | ||
* Mix the color with pure black, from 0 to 100. | ||
* Providing 0 will do nothing, providing 100 will always return black. | ||
* @param amount - valid between 1-100 | ||
*/ | ||
shade(amount?: number): TinyColor; | ||
/** | ||
* Desaturate the color a given amount, from 0 to 100. | ||
* Providing 100 will is the same as calling greyscale | ||
* @param amount - valid between 1-100 | ||
*/ | ||
desaturate(amount?: number): TinyColor; | ||
/** | ||
* Saturate the color a given amount, from 0 to 100. | ||
* @param amount - valid between 1-100 | ||
*/ | ||
saturate(amount?: number): TinyColor; | ||
/** | ||
* Completely desaturates a color into greyscale. | ||
* Same as calling `desaturate(100)` | ||
*/ | ||
greyscale(): TinyColor; | ||
/** | ||
* Spin takes a positive or negative amount within [-360, 360] indicating the change of hue. | ||
* Values outside of this range will be wrapped into this range. | ||
*/ | ||
spin(amount: number): TinyColor; | ||
mix(color: ColorInput, amount?: number): TinyColor; | ||
analogous(results?: number, slices?: number): TinyColor[]; | ||
/** | ||
* taken from https://github.com/infusion/jQuery-xcolor/blob/master/jquery.xcolor.js | ||
*/ | ||
complement(): TinyColor; | ||
@@ -194,11 +81,5 @@ monochromatic(results?: number): TinyColor[]; | ||
tetrad(): TinyColor[]; | ||
/** | ||
* Get polyad colors, like (for 1, 2, 3, 4, 5, 6, 7, 8, etc...) | ||
* monad, dyad, triad, tetrad, pentad, hexad, heptad, octad, etc... | ||
*/ | ||
polyad(n: number): TinyColor[]; | ||
/** | ||
* compare color vs current color | ||
*/ | ||
equals(color?: ColorInput): boolean; | ||
} | ||
export declare function tinycolor(color?: ColorInput, opts?: Partial<TinyColorOptions>): TinyColor; |
441
index.js
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const conversion_1 = require("./conversion"); | ||
const css_color_names_1 = require("./css-color-names"); | ||
const format_input_1 = require("./format-input"); | ||
const util_1 = require("./util"); | ||
class TinyColor { | ||
constructor(color = '', opts = {}) { | ||
// If input is already a tinycolor, return itself | ||
var conversion_1 = require("./conversion"); | ||
var css_color_names_1 = require("./css-color-names"); | ||
var format_input_1 = require("./format-input"); | ||
var util_1 = require("./util"); | ||
var TinyColor = (function () { | ||
function TinyColor(color, opts) { | ||
if (color === void 0) { color = ''; } | ||
if (opts === void 0) { opts = {}; } | ||
if (color instanceof TinyColor) { | ||
@@ -14,3 +15,3 @@ return color; | ||
this.originalInput = color; | ||
const rgb = format_input_1.inputToRGB(color); | ||
var rgb = format_input_1.inputToRGB(color); | ||
this.originalInput = color; | ||
@@ -24,6 +25,2 @@ this.r = rgb.r; | ||
this.gradientType = opts.gradientType; | ||
// Don't let the range of [0,255] come back in [0,1]. | ||
// Potentially lose a little bit of precision here, but will fix issues where | ||
// .5 gets interpreted as half of the total, instead of half of 1 | ||
// If it was supposed to be 128, this was already taken care of by `inputToRgb` | ||
if (this.r < 1) { | ||
@@ -40,28 +37,20 @@ this.r = Math.round(this.r); | ||
} | ||
isDark() { | ||
TinyColor.prototype.isDark = function () { | ||
return this.getBrightness() < 128; | ||
} | ||
isLight() { | ||
}; | ||
TinyColor.prototype.isLight = function () { | ||
return !this.isDark(); | ||
} | ||
/** | ||
* Returns the perceived brightness of the color, from 0-255. | ||
*/ | ||
getBrightness() { | ||
// http://www.w3.org/TR/AERT#color-contrast | ||
const rgb = this.toRgb(); | ||
}; | ||
TinyColor.prototype.getBrightness = function () { | ||
var rgb = this.toRgb(); | ||
return (rgb.r * 299 + rgb.g * 587 + rgb.b * 114) / 1000; | ||
} | ||
/** | ||
* Returns the perceived luminance of a color, from 0-1. | ||
*/ | ||
getLuminance() { | ||
// http://www.w3.org/TR/2008/REC-WCAG20-20081211/#relativeluminancedef | ||
const rgb = this.toRgb(); | ||
let R; | ||
let G; | ||
let B; | ||
const RsRGB = rgb.r / 255; | ||
const GsRGB = rgb.g / 255; | ||
const BsRGB = rgb.b / 255; | ||
}; | ||
TinyColor.prototype.getLuminance = function () { | ||
var rgb = this.toRgb(); | ||
var R; | ||
var G; | ||
var B; | ||
var RsRGB = rgb.r / 255; | ||
var GsRGB = rgb.g / 255; | ||
var BsRGB = rgb.b / 255; | ||
if (RsRGB <= 0.03928) { | ||
@@ -86,81 +75,47 @@ R = RsRGB / 12.92; | ||
return 0.2126 * R + 0.7152 * G + 0.0722 * B; | ||
} | ||
/** | ||
* Sets the alpha value on the current color. | ||
* | ||
* @param alpha - The new alpha value. The accepted range is 0-1. | ||
*/ | ||
setAlpha(alpha) { | ||
}; | ||
TinyColor.prototype.setAlpha = function (alpha) { | ||
this.a = util_1.boundAlpha(alpha); | ||
this.roundA = Math.round(100 * this.a) / 100; | ||
return this; | ||
} | ||
/** | ||
* Returns the object as a HSVA object. | ||
*/ | ||
toHsv() { | ||
const hsv = conversion_1.rgbToHsv(this.r, this.g, this.b); | ||
}; | ||
TinyColor.prototype.toHsv = function () { | ||
var hsv = conversion_1.rgbToHsv(this.r, this.g, this.b); | ||
return { h: hsv.h * 360, s: hsv.s, v: hsv.v, a: this.a }; | ||
} | ||
/** | ||
* Returns the hsva values interpolated into a string with the following format: | ||
* "hsva(xxx, xxx, xxx, xx)". | ||
*/ | ||
toHsvString() { | ||
const hsv = conversion_1.rgbToHsv(this.r, this.g, this.b); | ||
const h = Math.round(hsv.h * 360); | ||
const s = Math.round(hsv.s * 100); | ||
const v = Math.round(hsv.v * 100); | ||
return this.a === 1 ? `hsv(${h}, ${s}%, ${v}%)` : `hsva(${h}, ${s}%, ${v}%, ${this.roundA})`; | ||
} | ||
/** | ||
* Returns the object as a HSLA object. | ||
*/ | ||
toHsl() { | ||
const hsl = conversion_1.rgbToHsl(this.r, this.g, this.b); | ||
}; | ||
TinyColor.prototype.toHsvString = function () { | ||
var hsv = conversion_1.rgbToHsv(this.r, this.g, this.b); | ||
var h = Math.round(hsv.h * 360); | ||
var s = Math.round(hsv.s * 100); | ||
var v = Math.round(hsv.v * 100); | ||
return this.a === 1 ? "hsv(" + h + ", " + s + "%, " + v + "%)" : "hsva(" + h + ", " + s + "%, " + v + "%, " + this.roundA + ")"; | ||
}; | ||
TinyColor.prototype.toHsl = function () { | ||
var hsl = conversion_1.rgbToHsl(this.r, this.g, this.b); | ||
return { h: hsl.h * 360, s: hsl.s, l: hsl.l, a: this.a }; | ||
} | ||
/** | ||
* Returns the hsla values interpolated into a string with the following format: | ||
* "hsla(xxx, xxx, xxx, xx)". | ||
*/ | ||
toHslString() { | ||
const hsl = conversion_1.rgbToHsl(this.r, this.g, this.b); | ||
const h = Math.round(hsl.h * 360); | ||
const s = Math.round(hsl.s * 100); | ||
const l = Math.round(hsl.l * 100); | ||
return this.a === 1 ? `hsl(${h}, ${s}%, ${l}%)` : `hsla(${h}, ${s}%, ${l}%, ${this.roundA})`; | ||
} | ||
/** | ||
* Returns the hex value of the color. | ||
* @param allow3Char will shorten hex value to 3 char if possible | ||
*/ | ||
toHex(allow3Char = false) { | ||
}; | ||
TinyColor.prototype.toHslString = function () { | ||
var hsl = conversion_1.rgbToHsl(this.r, this.g, this.b); | ||
var h = Math.round(hsl.h * 360); | ||
var s = Math.round(hsl.s * 100); | ||
var l = Math.round(hsl.l * 100); | ||
return this.a === 1 ? "hsl(" + h + ", " + s + "%, " + l + "%)" : "hsla(" + h + ", " + s + "%, " + l + "%, " + this.roundA + ")"; | ||
}; | ||
TinyColor.prototype.toHex = function (allow3Char) { | ||
if (allow3Char === void 0) { allow3Char = false; } | ||
return conversion_1.rgbToHex(this.r, this.g, this.b, allow3Char); | ||
} | ||
/** | ||
* Returns the hex value of the color -with a # appened. | ||
* @param allow3Char will shorten hex value to 3 char if possible | ||
*/ | ||
toHexString(allow3Char = false) { | ||
}; | ||
TinyColor.prototype.toHexString = function (allow3Char) { | ||
if (allow3Char === void 0) { allow3Char = false; } | ||
return '#' + this.toHex(allow3Char); | ||
} | ||
/** | ||
* Returns the hex 8 value of the color. | ||
* @param allow4Char will shorten hex value to 4 char if possible | ||
*/ | ||
toHex8(allow4Char = false) { | ||
}; | ||
TinyColor.prototype.toHex8 = function (allow4Char) { | ||
if (allow4Char === void 0) { allow4Char = false; } | ||
return conversion_1.rgbaToHex(this.r, this.g, this.b, this.a, allow4Char); | ||
} | ||
/** | ||
* Returns the hex 8 value of the color -with a # appened. | ||
* @param allow4Char will shorten hex value to 4 char if possible | ||
*/ | ||
toHex8String(allow4Char = false) { | ||
}; | ||
TinyColor.prototype.toHex8String = function (allow4Char) { | ||
if (allow4Char === void 0) { allow4Char = false; } | ||
return '#' + this.toHex8(allow4Char); | ||
} | ||
/** | ||
* Returns the object as a RGBA object. | ||
*/ | ||
toRgb() { | ||
}; | ||
TinyColor.prototype.toRgb = function () { | ||
return { | ||
@@ -172,18 +127,11 @@ r: Math.round(this.r), | ||
}; | ||
} | ||
/** | ||
* Returns the RGBA values interpolated into a string with the following format: | ||
* "RGBA(xxx, xxx, xxx, xx)". | ||
*/ | ||
toRgbString() { | ||
const r = Math.round(this.r); | ||
const g = Math.round(this.g); | ||
const b = Math.round(this.b); | ||
return this.a === 1 ? `rgb(${r}, ${g}, ${b})` : `rgba(${r}, ${g}, ${b}, ${this.roundA})`; | ||
} | ||
/** | ||
* Returns the object as a RGBA object. | ||
*/ | ||
toPercentageRgb() { | ||
const fmt = (x) => Math.round(util_1.bound01(x, 255) * 100) + '%'; | ||
}; | ||
TinyColor.prototype.toRgbString = function () { | ||
var r = Math.round(this.r); | ||
var g = Math.round(this.g); | ||
var b = Math.round(this.b); | ||
return this.a === 1 ? "rgb(" + r + ", " + g + ", " + b + ")" : "rgba(" + r + ", " + g + ", " + b + ", " + this.roundA + ")"; | ||
}; | ||
TinyColor.prototype.toPercentageRgb = function () { | ||
var fmt = function (x) { return Math.round(util_1.bound01(x, 255) * 100) + '%'; }; | ||
return { | ||
@@ -195,16 +143,10 @@ r: fmt(this.r), | ||
}; | ||
} | ||
/** | ||
* Returns the RGBA relative values interpolated into a string | ||
*/ | ||
toPercentageRgbString() { | ||
const rnd = (x) => Math.round(util_1.bound01(x, 255) * 100); | ||
}; | ||
TinyColor.prototype.toPercentageRgbString = function () { | ||
var rnd = function (x) { return Math.round(util_1.bound01(x, 255) * 100); }; | ||
return this.a === 1 | ||
? `rgb(${rnd(this.r)}%, ${rnd(this.g)}%, ${rnd(this.b)}%)` | ||
: `rgba(${rnd(this.r)}%, ${rnd(this.g)}%, ${rnd(this.b)}%, ${this.roundA})`; | ||
} | ||
/** | ||
* The 'real' name of the color -if there is one. | ||
*/ | ||
toName() { | ||
? "rgb(" + rnd(this.r) + "%, " + rnd(this.g) + "%, " + rnd(this.b) + "%)" | ||
: "rgba(" + rnd(this.r) + "%, " + rnd(this.g) + "%, " + rnd(this.b) + "%, " + this.roundA + ")"; | ||
}; | ||
TinyColor.prototype.toName = function () { | ||
if (this.a === 0) { | ||
@@ -216,4 +158,5 @@ return 'transparent'; | ||
} | ||
const hex = '#' + conversion_1.rgbToHex(this.r, this.g, this.b, false); | ||
for (const key of Object.keys(css_color_names_1.names)) { | ||
var hex = '#' + conversion_1.rgbToHex(this.r, this.g, this.b, false); | ||
for (var _i = 0, _a = Object.keys(css_color_names_1.names); _i < _a.length; _i++) { | ||
var key = _a[_i]; | ||
if (css_color_names_1.names[key] === hex) { | ||
@@ -224,17 +167,10 @@ return key; | ||
return false; | ||
} | ||
/** | ||
* String representation of the color. | ||
* | ||
* @param format - The format to be used when displaying the string representation. | ||
*/ | ||
toString(format) { | ||
const formatSet = !!format; | ||
}; | ||
TinyColor.prototype.toString = function (format) { | ||
var formatSet = !!format; | ||
format = format || this.format; | ||
let formattedString = false; | ||
const hasAlpha = this.a < 1 && this.a >= 0; | ||
const needsAlphaFormat = !formatSet && hasAlpha && (format.startsWith('hex') || format === 'name'); | ||
var formattedString = false; | ||
var hasAlpha = this.a < 1 && this.a >= 0; | ||
var needsAlphaFormat = !formatSet && hasAlpha && (format.startsWith('hex') || format === 'name'); | ||
if (needsAlphaFormat) { | ||
// Special case for "transparent", all other non-alpha formats | ||
// will return rgba when there is transparency. | ||
if (format === 'name' && this.a === 0) { | ||
@@ -273,22 +209,16 @@ return this.toName(); | ||
return formattedString || this.toHexString(); | ||
} | ||
clone() { | ||
}; | ||
TinyColor.prototype.clone = function () { | ||
return new TinyColor(this.toString()); | ||
} | ||
/** | ||
* Lighten the color a given amount. Providing 100 will always return white. | ||
* @param amount - valid between 1-100 | ||
*/ | ||
lighten(amount = 10) { | ||
const hsl = this.toHsl(); | ||
}; | ||
TinyColor.prototype.lighten = function (amount) { | ||
if (amount === void 0) { amount = 10; } | ||
var hsl = this.toHsl(); | ||
hsl.l += amount / 100; | ||
hsl.l = util_1.clamp01(hsl.l); | ||
return new TinyColor(hsl); | ||
} | ||
/** | ||
* Brighten the color a given amount, from 0 to 100. | ||
* @param amount - valid between 1-100 | ||
*/ | ||
brighten(amount = 10) { | ||
const rgb = this.toRgb(); | ||
}; | ||
TinyColor.prototype.brighten = function (amount) { | ||
if (amount === void 0) { amount = 10; } | ||
var rgb = this.toRgb(); | ||
rgb.r = Math.max(0, Math.min(255, rgb.r - Math.round(255 * -(amount / 100)))); | ||
@@ -298,73 +228,47 @@ rgb.g = Math.max(0, Math.min(255, rgb.g - Math.round(255 * -(amount / 100)))); | ||
return new TinyColor(rgb); | ||
} | ||
/** | ||
* Darken the color a given amount, from 0 to 100. | ||
* Providing 100 will always return black. | ||
* @param amount - valid between 1-100 | ||
*/ | ||
darken(amount = 10) { | ||
const hsl = this.toHsl(); | ||
}; | ||
TinyColor.prototype.darken = function (amount) { | ||
if (amount === void 0) { amount = 10; } | ||
var hsl = this.toHsl(); | ||
hsl.l -= amount / 100; | ||
hsl.l = util_1.clamp01(hsl.l); | ||
return new TinyColor(hsl); | ||
} | ||
/** | ||
* Mix the color with pure white, from 0 to 100. | ||
* Providing 0 will do nothing, providing 100 will always return white. | ||
* @param amount - valid between 1-100 | ||
*/ | ||
tint(amount = 10) { | ||
}; | ||
TinyColor.prototype.tint = function (amount) { | ||
if (amount === void 0) { amount = 10; } | ||
return this.mix('white', amount); | ||
} | ||
/** | ||
* Mix the color with pure black, from 0 to 100. | ||
* Providing 0 will do nothing, providing 100 will always return black. | ||
* @param amount - valid between 1-100 | ||
*/ | ||
shade(amount = 10) { | ||
}; | ||
TinyColor.prototype.shade = function (amount) { | ||
if (amount === void 0) { amount = 10; } | ||
return this.mix('black', amount); | ||
} | ||
/** | ||
* Desaturate the color a given amount, from 0 to 100. | ||
* Providing 100 will is the same as calling greyscale | ||
* @param amount - valid between 1-100 | ||
*/ | ||
desaturate(amount = 10) { | ||
const hsl = this.toHsl(); | ||
}; | ||
TinyColor.prototype.desaturate = function (amount) { | ||
if (amount === void 0) { amount = 10; } | ||
var hsl = this.toHsl(); | ||
hsl.s -= amount / 100; | ||
hsl.s = util_1.clamp01(hsl.s); | ||
return new TinyColor(hsl); | ||
} | ||
/** | ||
* Saturate the color a given amount, from 0 to 100. | ||
* @param amount - valid between 1-100 | ||
*/ | ||
saturate(amount = 10) { | ||
const hsl = this.toHsl(); | ||
}; | ||
TinyColor.prototype.saturate = function (amount) { | ||
if (amount === void 0) { amount = 10; } | ||
var hsl = this.toHsl(); | ||
hsl.s += amount / 100; | ||
hsl.s = util_1.clamp01(hsl.s); | ||
return new TinyColor(hsl); | ||
} | ||
/** | ||
* Completely desaturates a color into greyscale. | ||
* Same as calling `desaturate(100)` | ||
*/ | ||
greyscale() { | ||
}; | ||
TinyColor.prototype.greyscale = function () { | ||
return this.desaturate(100); | ||
} | ||
/** | ||
* Spin takes a positive or negative amount within [-360, 360] indicating the change of hue. | ||
* Values outside of this range will be wrapped into this range. | ||
*/ | ||
spin(amount) { | ||
const hsl = this.toHsl(); | ||
const hue = (hsl.h + amount) % 360; | ||
}; | ||
TinyColor.prototype.spin = function (amount) { | ||
var hsl = this.toHsl(); | ||
var hue = (hsl.h + amount) % 360; | ||
hsl.h = hue < 0 ? 360 + hue : hue; | ||
return new TinyColor(hsl); | ||
} | ||
mix(color, amount = 50) { | ||
const rgb1 = this.toRgb(); | ||
const rgb2 = new TinyColor(color).toRgb(); | ||
const p = amount / 100; | ||
const rgba = { | ||
}; | ||
TinyColor.prototype.mix = function (color, amount) { | ||
if (amount === void 0) { amount = 50; } | ||
var rgb1 = this.toRgb(); | ||
var rgb2 = new TinyColor(color).toRgb(); | ||
var p = amount / 100; | ||
var rgba = { | ||
r: (rgb2.r - rgb1.r) * p + rgb1.r, | ||
@@ -376,7 +280,9 @@ g: (rgb2.g - rgb1.g) * p + rgb1.g, | ||
return new TinyColor(rgba); | ||
} | ||
analogous(results = 6, slices = 30) { | ||
const hsl = this.toHsl(); | ||
const part = 360 / slices; | ||
const ret = [this]; | ||
}; | ||
TinyColor.prototype.analogous = function (results, slices) { | ||
if (results === void 0) { results = 6; } | ||
if (slices === void 0) { slices = 30; } | ||
var hsl = this.toHsl(); | ||
var part = 360 / slices; | ||
var ret = [this]; | ||
for (hsl.h = (hsl.h - ((part * results) >> 1) + 720) % 360; --results;) { | ||
@@ -387,27 +293,25 @@ hsl.h = (hsl.h + part) % 360; | ||
return ret; | ||
} | ||
/** | ||
* taken from https://github.com/infusion/jQuery-xcolor/blob/master/jquery.xcolor.js | ||
*/ | ||
complement() { | ||
const hsl = this.toHsl(); | ||
}; | ||
TinyColor.prototype.complement = function () { | ||
var hsl = this.toHsl(); | ||
hsl.h = (hsl.h + 180) % 360; | ||
return new TinyColor(hsl); | ||
} | ||
monochromatic(results = 6) { | ||
const hsv = this.toHsv(); | ||
const h = hsv.h; | ||
const s = hsv.s; | ||
let v = hsv.v; | ||
const res = []; | ||
const modification = 1 / results; | ||
}; | ||
TinyColor.prototype.monochromatic = function (results) { | ||
if (results === void 0) { results = 6; } | ||
var hsv = this.toHsv(); | ||
var h = hsv.h; | ||
var s = hsv.s; | ||
var v = hsv.v; | ||
var res = []; | ||
var modification = 1 / results; | ||
while (results--) { | ||
res.push(new TinyColor({ h, s, v })); | ||
res.push(new TinyColor({ h: h, s: s, v: v })); | ||
v = (v + modification) % 1; | ||
} | ||
return res; | ||
} | ||
splitcomplement() { | ||
const hsl = this.toHsl(); | ||
const h = hsl.h; | ||
}; | ||
TinyColor.prototype.splitcomplement = function () { | ||
var hsl = this.toHsl(); | ||
var h = hsl.h; | ||
return [ | ||
@@ -418,31 +322,30 @@ this, | ||
]; | ||
} | ||
triad() { | ||
}; | ||
TinyColor.prototype.triad = function () { | ||
return this.polyad(3); | ||
} | ||
tetrad() { | ||
}; | ||
TinyColor.prototype.tetrad = function () { | ||
return this.polyad(4); | ||
} | ||
/** | ||
* Get polyad colors, like (for 1, 2, 3, 4, 5, 6, 7, 8, etc...) | ||
* monad, dyad, triad, tetrad, pentad, hexad, heptad, octad, etc... | ||
*/ | ||
polyad(n) { | ||
const hsl = this.toHsl(); | ||
const h = hsl.h; | ||
const result = [this]; | ||
const increment = 360 / n; | ||
for (let i = 1; i < n; i++) { | ||
}; | ||
TinyColor.prototype.polyad = function (n) { | ||
var hsl = this.toHsl(); | ||
var h = hsl.h; | ||
var result = [this]; | ||
var increment = 360 / n; | ||
for (var i = 1; i < n; i++) { | ||
result.push(new TinyColor({ h: (h + i * increment) % 360, s: hsl.s, l: hsl.l })); | ||
} | ||
return result; | ||
} | ||
/** | ||
* compare color vs current color | ||
*/ | ||
equals(color) { | ||
}; | ||
TinyColor.prototype.equals = function (color) { | ||
return this.toRgbString() === new TinyColor(color).toRgbString(); | ||
} | ||
}; | ||
return TinyColor; | ||
}()); | ||
exports.TinyColor = TinyColor; | ||
function tinycolor(color, opts) { | ||
if (color === void 0) { color = ''; } | ||
if (opts === void 0) { opts = {}; } | ||
return new TinyColor(color, opts); | ||
} | ||
exports.TinyColor = TinyColor; | ||
//# sourceMappingURL=index.js.map | ||
exports.tinycolor = tinycolor; |
@@ -1,7 +0,1 @@ | ||
/** | ||
* A representation of additive color mixing. | ||
* Projection of primary color lights on a white screen shows secondary | ||
* colors where two overlap; the combination of all three of red, green, | ||
* and blue in equal intensities makes white. | ||
*/ | ||
export interface RGB { | ||
@@ -15,7 +9,2 @@ r: number | string; | ||
} | ||
/** | ||
* The HSL model describes colors in terms of hue, saturation, | ||
* and lightness (also called luminance). | ||
* @link https://en.wikibooks.org/wiki/Color_Models:_RGB,_HSV,_HSL#HSL | ||
*/ | ||
export interface HSL { | ||
@@ -29,7 +18,2 @@ h: number | string; | ||
} | ||
/** | ||
* The HSV, or HSB, model describes colors in terms of | ||
* hue, saturation, and value (brightness). | ||
* @link https://en.wikibooks.org/wiki/Color_Models:_RGB,_HSV,_HSL#HSV | ||
*/ | ||
export interface HSV { | ||
@@ -36,0 +20,0 @@ h: number | string; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
//# sourceMappingURL=interfaces.js.map |
{ | ||
"name": "@ctrl/tinycolor", | ||
"version": "2.0.1", | ||
"version": "2.1.0", | ||
"description": "Fast, small color manipulation and conversion for JavaScript", | ||
@@ -31,3 +31,5 @@ "author": "Scott Cooper <scttcper@gmail.com>", | ||
"prebuild": "rimraf dist", | ||
"build": "tsc -p tsconfig.json && tsc -p tsconfig.esm.json && ts-node ./build.ts", | ||
"build": "npm run build-es6; npm run build-cmjs; ts-node build", | ||
"build-es6": "tsc -P ./tsconfig-build.json --outDir 'dist/es' --module es2015 -d false --moduleResolution node", | ||
"build-cmjs": "tsc -P ./tsconfig-build.json", | ||
"build:docs": "typedoc src && touch docs/.nojekyll", | ||
@@ -39,5 +41,4 @@ "test": "jest", | ||
"travis-deploy-once": "travis-deploy-once", | ||
"semantic-release": "cd dist/package-dist && semantic-release" | ||
"semantic-release": "cd dist && semantic-release" | ||
}, | ||
"dependencies": {}, | ||
"devDependencies": { | ||
@@ -53,4 +54,5 @@ "@types/fs-extra": "5.0.4", | ||
"rimraf": "2.6.2", | ||
"rollup": "0.63.4", | ||
"rollup": "0.63.5", | ||
"rollup-plugin-sourcemaps": "0.4.2", | ||
"rollup-plugin-terser": "1.0.1", | ||
"rollup-plugin-typescript2": "0.16.1", | ||
@@ -57,0 +59,0 @@ "rollup-plugin-uglify": "4.0.0", |
@@ -0,1 +1,2 @@ | ||
import { tinycolor } from './index'; | ||
export * from './index'; | ||
@@ -8,1 +9,2 @@ export * from './css-color-names'; | ||
export * from './random'; | ||
export default tinycolor; |
@@ -6,2 +6,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var index_1 = require("./index"); | ||
__export(require("./index")); | ||
@@ -14,2 +15,2 @@ __export(require("./css-color-names")); | ||
__export(require("./random")); | ||
//# sourceMappingURL=public_api.js.map | ||
exports.default = index_1.tinycolor; |
@@ -13,5 +13,2 @@ import { TinyColor } from './index'; | ||
export declare function random(options?: RandomCountOptions): TinyColor[]; | ||
/** | ||
* @hidden | ||
*/ | ||
export interface ColorBound { | ||
@@ -22,5 +19,2 @@ name: string; | ||
} | ||
/** | ||
* @hidden | ||
*/ | ||
export declare const bounds: ColorBound[]; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
// randomColor by David Merfield under the CC0 license | ||
// https://github.com/davidmerfield/randomColor/ | ||
const index_1 = require("./index"); | ||
function random(options = {}) { | ||
// Check if we need to generate multiple colors | ||
var index_1 = require("./index"); | ||
function random(options) { | ||
if (options === void 0) { options = {}; } | ||
if (options.count !== undefined && options.count !== null) { | ||
const totalColors = options.count; | ||
const colors = []; | ||
var totalColors = options.count; | ||
var colors = []; | ||
options.count = undefined; | ||
while (totalColors > colors.length) { | ||
// Since we're generating multiple colors, | ||
// incremement the seed. Otherwise we'd just | ||
// generate the same color each time... | ||
options.count = null; | ||
@@ -25,13 +20,9 @@ if (options.seed) { | ||
} | ||
// First we pick a hue (H) | ||
const h = pickHue(options.hue, options.seed); | ||
// Then use H to determine saturation (S) | ||
const s = pickSaturation(h, options); | ||
// Then use S and H to determine brightness (B). | ||
const v = pickBrightness(h, s, options); | ||
const res = { h, s, v }; | ||
var h = pickHue(options.hue, options.seed); | ||
var s = pickSaturation(h, options); | ||
var v = pickBrightness(h, s, options); | ||
var res = { h: h, s: s, v: v }; | ||
if (options.alpha !== undefined) { | ||
res.a = options.alpha; | ||
} | ||
// Then we return the HSB color in the desired format | ||
return new index_1.TinyColor(res); | ||
@@ -41,6 +32,4 @@ } | ||
function pickHue(hue, seed) { | ||
const hueRange = getHueRange(hue); | ||
let res = randomWithin(hueRange, seed); | ||
// Instead of storing red as two seperate ranges, | ||
// we group them, using negative numbers | ||
var hueRange = getHueRange(hue); | ||
var res = randomWithin(hueRange, seed); | ||
if (res < 0) { | ||
@@ -58,5 +47,5 @@ res = 360 + res; | ||
} | ||
const saturationRange = getColorInfo(hue).saturationRange; | ||
let sMin = saturationRange[0]; | ||
let sMax = saturationRange[1]; | ||
var saturationRange = getColorInfo(hue).saturationRange; | ||
var sMin = saturationRange[0]; | ||
var sMax = saturationRange[1]; | ||
switch (options.luminosity) { | ||
@@ -76,4 +65,4 @@ case 'bright': | ||
function pickBrightness(H, S, options) { | ||
let bMin = getMinimumBrightness(H, S); | ||
let bMax = 100; | ||
var bMin = getMinimumBrightness(H, S); | ||
var bMax = 100; | ||
switch (options.luminosity) { | ||
@@ -94,11 +83,11 @@ case 'dark': | ||
function getMinimumBrightness(H, S) { | ||
const lowerBounds = getColorInfo(H).lowerBounds; | ||
for (let i = 0; i < lowerBounds.length - 1; i++) { | ||
const s1 = lowerBounds[i][0]; | ||
const v1 = lowerBounds[i][1]; | ||
const s2 = lowerBounds[i + 1][0]; | ||
const v2 = lowerBounds[i + 1][1]; | ||
var lowerBounds = getColorInfo(H).lowerBounds; | ||
for (var i = 0; i < lowerBounds.length - 1; i++) { | ||
var s1 = lowerBounds[i][0]; | ||
var v1 = lowerBounds[i][1]; | ||
var s2 = lowerBounds[i + 1][0]; | ||
var v2 = lowerBounds[i + 1][1]; | ||
if (S >= s1 && S <= s2) { | ||
const m = (v2 - v1) / (s2 - s1); | ||
const b = v1 - m * s1; | ||
var m = (v2 - v1) / (s2 - s1); | ||
var b = v1 - m * s1; | ||
return m * S + b; | ||
@@ -110,3 +99,3 @@ } | ||
function getHueRange(colorInput) { | ||
const num = parseInt(colorInput, 10); | ||
var num = parseInt(colorInput, 10); | ||
if (!Number.isNaN(num) && num < 360 && num > 0) { | ||
@@ -116,5 +105,5 @@ return [num, num]; | ||
if (typeof colorInput === 'string') { | ||
const namedColor = exports.bounds.find(n => n.name === colorInput); | ||
var namedColor = exports.bounds.find(function (n) { return n.name === colorInput; }); | ||
if (namedColor) { | ||
const color = defineColor(namedColor); | ||
var color = defineColor(namedColor); | ||
if (color.hueRange) { | ||
@@ -124,5 +113,5 @@ return color.hueRange; | ||
} | ||
const parsed = new index_1.TinyColor(colorInput); | ||
var parsed = new index_1.TinyColor(colorInput); | ||
if (parsed.isValid) { | ||
const hue = parsed.toHsv().h; | ||
var hue = parsed.toHsv().h; | ||
return [hue, hue]; | ||
@@ -134,8 +123,8 @@ } | ||
function getColorInfo(hue) { | ||
// Maps red colors to make picking hue easier | ||
if (hue >= 334 && hue <= 360) { | ||
hue -= 360; | ||
} | ||
for (const bound of exports.bounds) { | ||
const color = defineColor(bound); | ||
for (var _i = 0, bounds_1 = exports.bounds; _i < bounds_1.length; _i++) { | ||
var bound = bounds_1[_i]; | ||
var color = defineColor(bound); | ||
if (color.hueRange && hue >= color.hueRange[0] && hue <= color.hueRange[1]) { | ||
@@ -152,7 +141,6 @@ return color; | ||
else { | ||
// Seeded random algorithm from http://indiegamr.com/generate-repeatable-random-numbers-in-js/ | ||
const max = range[1] || 1; | ||
const min = range[0] || 0; | ||
var max = range[1] || 1; | ||
var min = range[0] || 0; | ||
seed = (seed * 9301 + 49297) % 233280; | ||
const rnd = seed / 233280.0; | ||
var rnd = seed / 233280.0; | ||
return Math.floor(min + rnd * (max - min)); | ||
@@ -162,6 +150,6 @@ } | ||
function defineColor(bound) { | ||
const sMin = bound.lowerBounds[0][0]; | ||
const sMax = bound.lowerBounds[bound.lowerBounds.length - 1][0]; | ||
const bMin = bound.lowerBounds[bound.lowerBounds.length - 1][1]; | ||
const bMax = bound.lowerBounds[0][1]; | ||
var sMin = bound.lowerBounds[0][0]; | ||
var sMax = bound.lowerBounds[bound.lowerBounds.length - 1][0]; | ||
var bMin = bound.lowerBounds[bound.lowerBounds.length - 1][1]; | ||
var bMax = bound.lowerBounds[0][1]; | ||
return { | ||
@@ -175,5 +163,2 @@ name: bound.name, | ||
} | ||
/** | ||
* @hidden | ||
*/ | ||
exports.bounds = [ | ||
@@ -251,2 +236,1 @@ { | ||
]; | ||
//# sourceMappingURL=random.js.map |
import { ColorInput, TinyColor } from './index'; | ||
/** | ||
* AKA `contrast` | ||
* | ||
* Analyze the 2 colors and returns the color contrast defined by (WCAG Version 2) | ||
*/ | ||
export declare function readability(color1: ColorInput, color2: ColorInput): number; | ||
@@ -12,15 +7,2 @@ export interface WCAG2Parms { | ||
} | ||
/** | ||
* Ensure that foreground and background color combinations meet WCAG2 guidelines. | ||
* The third argument is an object. | ||
* the 'level' property states 'AA' or 'AAA' - if missing or invalid, it defaults to 'AA'; | ||
* the 'size' property states 'large' or 'small' - if missing or invalid, it defaults to 'small'. | ||
* If the entire object is absent, isReadable defaults to {level:"AA",size:"small"}. | ||
* | ||
* Example | ||
* ```ts | ||
* new TinyColor().isReadable('#000', '#111') => false | ||
* new TinyColor().isReadable('#000', '#111', { level: 'AA', size: 'large' }) => false | ||
* ``` | ||
*/ | ||
export declare function isReadable(color1: ColorInput, color2: ColorInput, wcag2?: WCAG2Parms): boolean; | ||
@@ -30,19 +12,2 @@ export interface WCAG2FallbackParms extends WCAG2Parms { | ||
} | ||
/** | ||
* Given a base color and a list of possible foreground or background | ||
* colors for that base, returns the most readable color. | ||
* Optionally returns Black or White if the most readable color is unreadable. | ||
* | ||
* @param baseColor - the base color. | ||
* @param colorList - array of colors to pick the most readable one from. | ||
* @param args - and object with extra arguments | ||
* | ||
* Example | ||
* ```ts | ||
* new TinyColor().mostReadable('#123', ['#124", "#125'], { includeFallbackColors: false }).toHexString(); // "#112255" | ||
* new TinyColor().mostReadable('#123', ['#124", "#125'],{ includeFallbackColors: true }).toHexString(); // "#ffffff" | ||
* new TinyColor().mostReadable('#a8015a', ["#faf3f3"], { includeFallbackColors:true, level: 'AAA', size: 'large' }).toHexString(); // "#faf3f3" | ||
* new TinyColor().mostReadable('#a8015a', ["#faf3f3"], { includeFallbackColors:true, level: 'AAA', size: 'small' }).toHexString(); // "#ffffff" | ||
* ``` | ||
*/ | ||
export declare function mostReadable(baseColor: ColorInput, colorList: string[], args?: WCAG2FallbackParms): TinyColor | null; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const index_1 = require("./index"); | ||
// Readability Functions | ||
// --------------------- | ||
// <http://www.w3.org/TR/2008/REC-WCAG20-20081211/#contrast-ratiodef (WCAG Version 2) | ||
/** | ||
* AKA `contrast` | ||
* | ||
* Analyze the 2 colors and returns the color contrast defined by (WCAG Version 2) | ||
*/ | ||
var index_1 = require("./index"); | ||
function readability(color1, color2) { | ||
const c1 = new index_1.TinyColor(color1); | ||
const c2 = new index_1.TinyColor(color2); | ||
var c1 = new index_1.TinyColor(color1); | ||
var c2 = new index_1.TinyColor(color2); | ||
return ((Math.max(c1.getLuminance(), c2.getLuminance()) + 0.05) / | ||
@@ -19,17 +11,5 @@ (Math.min(c1.getLuminance(), c2.getLuminance()) + 0.05)); | ||
exports.readability = readability; | ||
/** | ||
* Ensure that foreground and background color combinations meet WCAG2 guidelines. | ||
* The third argument is an object. | ||
* the 'level' property states 'AA' or 'AAA' - if missing or invalid, it defaults to 'AA'; | ||
* the 'size' property states 'large' or 'small' - if missing or invalid, it defaults to 'small'. | ||
* If the entire object is absent, isReadable defaults to {level:"AA",size:"small"}. | ||
* | ||
* Example | ||
* ```ts | ||
* new TinyColor().isReadable('#000', '#111') => false | ||
* new TinyColor().isReadable('#000', '#111', { level: 'AA', size: 'large' }) => false | ||
* ``` | ||
*/ | ||
function isReadable(color1, color2, wcag2 = { level: 'AA', size: 'small' }) { | ||
const readabilityLevel = readability(color1, color2); | ||
function isReadable(color1, color2, wcag2) { | ||
if (wcag2 === void 0) { wcag2 = { level: 'AA', size: 'small' }; } | ||
var readabilityLevel = readability(color1, color2); | ||
switch ((wcag2.level || 'AA') + (wcag2.size || 'small')) { | ||
@@ -47,27 +27,12 @@ case 'AAsmall': | ||
exports.isReadable = isReadable; | ||
/** | ||
* Given a base color and a list of possible foreground or background | ||
* colors for that base, returns the most readable color. | ||
* Optionally returns Black or White if the most readable color is unreadable. | ||
* | ||
* @param baseColor - the base color. | ||
* @param colorList - array of colors to pick the most readable one from. | ||
* @param args - and object with extra arguments | ||
* | ||
* Example | ||
* ```ts | ||
* new TinyColor().mostReadable('#123', ['#124", "#125'], { includeFallbackColors: false }).toHexString(); // "#112255" | ||
* new TinyColor().mostReadable('#123', ['#124", "#125'],{ includeFallbackColors: true }).toHexString(); // "#ffffff" | ||
* new TinyColor().mostReadable('#a8015a', ["#faf3f3"], { includeFallbackColors:true, level: 'AAA', size: 'large' }).toHexString(); // "#faf3f3" | ||
* new TinyColor().mostReadable('#a8015a', ["#faf3f3"], { includeFallbackColors:true, level: 'AAA', size: 'small' }).toHexString(); // "#ffffff" | ||
* ``` | ||
*/ | ||
function mostReadable(baseColor, colorList, args = { includeFallbackColors: false, level: 'AA', size: 'small' }) { | ||
let bestColor = null; | ||
let bestScore = 0; | ||
const includeFallbackColors = args.includeFallbackColors; | ||
const level = args.level; | ||
const size = args.size; | ||
for (const color of colorList) { | ||
const score = readability(baseColor, color); | ||
function mostReadable(baseColor, colorList, args) { | ||
if (args === void 0) { args = { includeFallbackColors: false, level: 'AA', size: 'small' }; } | ||
var bestColor = null; | ||
var bestScore = 0; | ||
var includeFallbackColors = args.includeFallbackColors; | ||
var level = args.level; | ||
var size = args.size; | ||
for (var _i = 0, colorList_1 = colorList; _i < colorList_1.length; _i++) { | ||
var color = colorList_1[_i]; | ||
var score = readability(baseColor, color); | ||
if (score > bestScore) { | ||
@@ -78,3 +43,3 @@ bestScore = score; | ||
} | ||
if (isReadable(baseColor, bestColor, { level, size }) || !includeFallbackColors) { | ||
if (isReadable(baseColor, bestColor, { level: level, size: size }) || !includeFallbackColors) { | ||
return bestColor; | ||
@@ -88,2 +53,1 @@ } | ||
exports.mostReadable = mostReadable; | ||
//# sourceMappingURL=readability.js.map |
import { ColorInput } from './index'; | ||
/** | ||
* Returns the color represented as a Microsoft filter for use in old versions of IE. | ||
*/ | ||
export declare function toMsFilter(firstColor: ColorInput, secondColor?: ColorInput): string; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const conversion_1 = require("./conversion"); | ||
const index_1 = require("./index"); | ||
/** | ||
* Returns the color represented as a Microsoft filter for use in old versions of IE. | ||
*/ | ||
var conversion_1 = require("./conversion"); | ||
var index_1 = require("./index"); | ||
function toMsFilter(firstColor, secondColor) { | ||
const color = new index_1.TinyColor(firstColor); | ||
const hex8String = '#' + conversion_1.rgbaToArgbHex(color.r, color.g, color.b, color.a); | ||
let secondHex8String = hex8String; | ||
const gradientType = color.gradientType ? 'GradientType = 1, ' : ''; | ||
var color = new index_1.TinyColor(firstColor); | ||
var hex8String = '#' + conversion_1.rgbaToArgbHex(color.r, color.g, color.b, color.a); | ||
var secondHex8String = hex8String; | ||
var gradientType = color.gradientType ? 'GradientType = 1, ' : ''; | ||
if (secondColor) { | ||
const s = new index_1.TinyColor(secondColor); | ||
var s = new index_1.TinyColor(secondColor); | ||
secondHex8String = '#' + conversion_1.rgbaToArgbHex(s.r, s.g, s.b, s.a); | ||
} | ||
return `progid:DXImageTransform.Microsoft.gradient(${gradientType}startColorstr=${hex8String},endColorstr=${secondHex8String})`; | ||
return "progid:DXImageTransform.Microsoft.gradient(" + gradientType + "startColorstr=" + hex8String + ",endColorstr=" + secondHex8String + ")"; | ||
} | ||
exports.toMsFilter = toMsFilter; | ||
//# sourceMappingURL=to-ms-filter.js.map |
@@ -1,36 +0,7 @@ | ||
/** | ||
* Take input from [0, n] and return it as [0, 1] | ||
* @hidden | ||
*/ | ||
export declare function bound01(n: any, max: number): any; | ||
/** | ||
* Force a number between 0 and 1 | ||
* @hidden | ||
*/ | ||
export declare function clamp01(val: number): number; | ||
/** | ||
* Need to handle 1.0 as 100%, since once it is a number, there is no difference between it and 1 | ||
* <http://stackoverflow.com/questions/7422072/javascript-how-to-detect-number-as-a-decimal-including-1-0> | ||
* @hidden | ||
*/ | ||
export declare function isOnePointZero(n: string | number): boolean; | ||
/** | ||
* Check to see if string passed in is a percentage | ||
* @hidden | ||
*/ | ||
export declare function isPercentage(n: string | number): boolean; | ||
/** | ||
* Return a valid alpha value [0,1] with all invalid values being set to 1 | ||
* @hidden | ||
*/ | ||
export declare function boundAlpha(a?: number | string): number; | ||
/** | ||
* Replace a decimal with it's percentage value | ||
* @hidden | ||
*/ | ||
export declare function convertToPercentage(n: number | string): string | number; | ||
/** | ||
* Force a hex value to have 2 characters | ||
* @hidden | ||
*/ | ||
export declare function pad2(c: string): string; |
40
util.js
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
/** | ||
* Take input from [0, n] and return it as [0, 1] | ||
* @hidden | ||
*/ | ||
function bound01(n, max) { | ||
@@ -11,22 +7,14 @@ if (isOnePointZero(n)) { | ||
} | ||
const processPercent = isPercentage(n); | ||
var processPercent = isPercentage(n); | ||
n = max === 360 ? n : Math.min(max, Math.max(0, parseFloat(n))); | ||
// Automatically convert percentage into number | ||
if (processPercent) { | ||
n = parseInt(String(n * max), 10) / 100; | ||
} | ||
// Handle floating point rounding errors | ||
if (Math.abs(n - max) < 0.000001) { | ||
return 1; | ||
} | ||
// Convert into [0, 1] range if it isn't already | ||
if (max === 360) { | ||
// If n is a hue given in degrees, | ||
// wrap around out-of-range values into [0, 360] range | ||
// then convert into [0, 1]. | ||
n = (n < 0 ? n % max + max : n % max) / parseFloat(String(max)); | ||
} | ||
else { | ||
// If n not a hue given in degrees | ||
// Convert into [0, 1] range if it isn't already. | ||
n = (n % max) / parseFloat(String(max)); | ||
@@ -37,6 +25,2 @@ } | ||
exports.bound01 = bound01; | ||
/** | ||
* Force a number between 0 and 1 | ||
* @hidden | ||
*/ | ||
function clamp01(val) { | ||
@@ -46,7 +30,2 @@ return Math.min(1, Math.max(0, val)); | ||
exports.clamp01 = clamp01; | ||
/** | ||
* Need to handle 1.0 as 100%, since once it is a number, there is no difference between it and 1 | ||
* <http://stackoverflow.com/questions/7422072/javascript-how-to-detect-number-as-a-decimal-including-1-0> | ||
* @hidden | ||
*/ | ||
function isOnePointZero(n) { | ||
@@ -56,6 +35,2 @@ return typeof n === 'string' && n.indexOf('.') !== -1 && parseFloat(n) === 1; | ||
exports.isOnePointZero = isOnePointZero; | ||
/** | ||
* Check to see if string passed in is a percentage | ||
* @hidden | ||
*/ | ||
function isPercentage(n) { | ||
@@ -65,6 +40,2 @@ return typeof n === 'string' && n.indexOf('%') !== -1; | ||
exports.isPercentage = isPercentage; | ||
/** | ||
* Return a valid alpha value [0,1] with all invalid values being set to 1 | ||
* @hidden | ||
*/ | ||
function boundAlpha(a) { | ||
@@ -78,6 +49,2 @@ a = parseFloat(a); | ||
exports.boundAlpha = boundAlpha; | ||
/** | ||
* Replace a decimal with it's percentage value | ||
* @hidden | ||
*/ | ||
function convertToPercentage(n) { | ||
@@ -90,6 +57,2 @@ if (n <= 1) { | ||
exports.convertToPercentage = convertToPercentage; | ||
/** | ||
* Force a hex value to have 2 characters | ||
* @hidden | ||
*/ | ||
function pad2(c) { | ||
@@ -99,2 +62,1 @@ return c.length === 1 ? '0' + c : '' + c; | ||
exports.pad2 = pad2; | ||
//# sourceMappingURL=util.js.map |
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
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
183744
23
2619
1