flow like the river

This commit is contained in:
root 2025-11-07 00:06:12 +01:00
commit 013fe673f3
42435 changed files with 5764238 additions and 0 deletions

View file

@ -0,0 +1,10 @@
"use strict";
exports.__esModule = true;
exports["default"] = void 0;
// @private
function capitalizeString(string) {
return string.charAt(0).toUpperCase() + string.slice(1);
}
var _default = exports["default"] = capitalizeString;
module.exports = exports.default;

View file

@ -0,0 +1,8 @@
// @flow
// @private
function capitalizeString(string: string): string {
return string.charAt(0).toUpperCase() + string.slice(1)
}
export default capitalizeString

View file

@ -0,0 +1,31 @@
"use strict";
exports.__esModule = true;
exports["default"] = void 0;
function constructGradientValue(literals) {
var template = '';
for (var _len = arguments.length, substitutions = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
substitutions[_key - 1] = arguments[_key];
}
for (var i = 0; i < literals.length; i += 1) {
template += literals[i];
if (i === substitutions.length - 1 && substitutions[i]) {
var definedValues = substitutions.filter(function (substitute) {
return !!substitute;
});
// Adds leading coma if properties preceed color-stops
if (definedValues.length > 1) {
template = template.slice(0, -1);
template += ", " + substitutions[i];
// No trailing space if color-stops is the only param provided
} else if (definedValues.length === 1) {
template += "" + substitutions[i];
}
} else if (substitutions[i]) {
template += substitutions[i] + " ";
}
}
return template.trim();
}
var _default = exports["default"] = constructGradientValue;
module.exports = exports.default;

View file

@ -0,0 +1,23 @@
// @flow
function constructGradientValue(literals: Array<string>, ...substitutions: Array<string>): string {
let template = ''
for (let i = 0; i < literals.length; i += 1) {
template += literals[i]
if (i === substitutions.length - 1 && substitutions[i]) {
const definedValues = substitutions.filter(substitute => !!substitute)
// Adds leading coma if properties preceed color-stops
if (definedValues.length > 1) {
template = template.slice(0, -1)
template += `, ${substitutions[i]}`
// No trailing space if color-stops is the only param provided
} else if (definedValues.length === 1) {
template += `${substitutions[i]}`
}
} else if (substitutions[i]) {
template += `${substitutions[i]} `
}
}
return template.trim()
}
export default constructGradientValue

View file

@ -0,0 +1,22 @@
"use strict";
exports.__esModule = true;
exports["default"] = curry;
// Type definitions taken from https://github.com/gcanti/flow-static-land/blob/master/src/Fun.js
// eslint-disable-next-line no-unused-vars
// eslint-disable-next-line no-unused-vars
// eslint-disable-next-line no-redeclare
function curried(f, length, acc) {
return function fn() {
// eslint-disable-next-line prefer-rest-params
var combined = acc.concat(Array.prototype.slice.call(arguments));
return combined.length >= length ? f.apply(this, combined) : curried(f, length, combined);
};
}
// eslint-disable-next-line no-redeclare
function curry(f) {
// eslint-disable-line no-redeclare
return curried(f, f.length, []);
}
module.exports = exports.default;

View file

@ -0,0 +1,29 @@
// @flow
// Type definitions taken from https://github.com/gcanti/flow-static-land/blob/master/src/Fun.js
type Fn1<A, B> = (a: A, ...rest: Array<void>) => B
type Fn2<A, B, C> = (a: A, b: B, ...rest: Array<void>) => C
type Fn3<A, B, C, D> = (a: A, b: B, c: C, ...rest: Array<void>) => D
type CurriedFn2<A, B, C> = Fn1<A, Fn1<B, C>> & Fn2<A, B, C>
// eslint-disable-next-line no-unused-vars
type CurriedFn3<A, B, C, D> = Fn1<A, CurriedFn2<B, C, D>> & Fn2<A, B, Fn1<C, D>> & Fn3<A, B, C, D>
// eslint-disable-next-line no-unused-vars
declare function curry<A, B, C>(f: Fn2<A, B, C>): CurriedFn2<A, B, C>
// eslint-disable-next-line no-redeclare
declare function curry<A, B, C, D>(f: Fn3<A, B, C, D>): CurriedFn3<A, B, C, D>
function curried(f: Function, length: number, acc: Array<any>): Function {
return function fn() {
// eslint-disable-next-line prefer-rest-params
const combined = acc.concat(Array.prototype.slice.call(arguments))
return combined.length >= length ? f.apply(this, combined) : curried(f, length, combined)
}
}
// eslint-disable-next-line no-redeclare
export default function curry(f: Function): Function {
// eslint-disable-line no-redeclare
return curried(f, f.length, [])
}

View file

@ -0,0 +1,12 @@
"use strict";
exports.__esModule = true;
exports["default"] = endsWith;
/**
* Check if a string ends with something
* @private
*/
function endsWith(string, suffix) {
return string.substr(-suffix.length) === suffix;
}
module.exports = exports.default;

View file

@ -0,0 +1,9 @@
// @flow
/**
* Check if a string ends with something
* @private
*/
export default function endsWith(string: string, suffix: string): boolean {
return string.substr(-suffix.length) === suffix
}

View file

@ -0,0 +1,140 @@
"use strict";
exports.__esModule = true;
exports["default"] = void 0;
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
function _wrapNativeSuper(Class) { var _cache = typeof Map === "function" ? new Map() : undefined; _wrapNativeSuper = function _wrapNativeSuper(Class) { if (Class === null || !_isNativeFunction(Class)) return Class; if (typeof Class !== "function") { throw new TypeError("Super expression must either be null or a function"); } if (typeof _cache !== "undefined") { if (_cache.has(Class)) return _cache.get(Class); _cache.set(Class, Wrapper); } function Wrapper() { return _construct(Class, arguments, _getPrototypeOf(this).constructor); } Wrapper.prototype = Object.create(Class.prototype, { constructor: { value: Wrapper, enumerable: false, writable: true, configurable: true } }); return _setPrototypeOf(Wrapper, Class); }; return _wrapNativeSuper(Class); }
function _construct(t, e, r) { if (_isNativeReflectConstruct()) return Reflect.construct.apply(null, arguments); var o = [null]; o.push.apply(o, e); var p = new (t.bind.apply(t, o))(); return r && _setPrototypeOf(p, r.prototype), p; }
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
function _isNativeFunction(fn) { try { return Function.toString.call(fn).indexOf("[native code]") !== -1; } catch (e) { return typeof fn === "function"; } }
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
// based on https://github.com/styled-components/styled-components/blob/fcf6f3804c57a14dd7984dfab7bc06ee2edca044/src/utils/error.js
/**
* Parse errors.md and turn it into a simple hash of code: message
* @private
*/
var ERRORS = {
"1": "Passed invalid arguments to hsl, please pass multiple numbers e.g. hsl(360, 0.75, 0.4) or an object e.g. rgb({ hue: 255, saturation: 0.4, lightness: 0.75 }).\n\n",
"2": "Passed invalid arguments to hsla, please pass multiple numbers e.g. hsla(360, 0.75, 0.4, 0.7) or an object e.g. rgb({ hue: 255, saturation: 0.4, lightness: 0.75, alpha: 0.7 }).\n\n",
"3": "Passed an incorrect argument to a color function, please pass a string representation of a color.\n\n",
"4": "Couldn't generate valid rgb string from %s, it returned %s.\n\n",
"5": "Couldn't parse the color string. Please provide the color as a string in hex, rgb, rgba, hsl or hsla notation.\n\n",
"6": "Passed invalid arguments to rgb, please pass multiple numbers e.g. rgb(255, 205, 100) or an object e.g. rgb({ red: 255, green: 205, blue: 100 }).\n\n",
"7": "Passed invalid arguments to rgba, please pass multiple numbers e.g. rgb(255, 205, 100, 0.75) or an object e.g. rgb({ red: 255, green: 205, blue: 100, alpha: 0.75 }).\n\n",
"8": "Passed invalid argument to toColorString, please pass a RgbColor, RgbaColor, HslColor or HslaColor object.\n\n",
"9": "Please provide a number of steps to the modularScale helper.\n\n",
"10": "Please pass a number or one of the predefined scales to the modularScale helper as the ratio.\n\n",
"11": "Invalid value passed as base to modularScale, expected number or em string but got \"%s\"\n\n",
"12": "Expected a string ending in \"px\" or a number passed as the first argument to %s(), got \"%s\" instead.\n\n",
"13": "Expected a string ending in \"px\" or a number passed as the second argument to %s(), got \"%s\" instead.\n\n",
"14": "Passed invalid pixel value (\"%s\") to %s(), please pass a value like \"12px\" or 12.\n\n",
"15": "Passed invalid base value (\"%s\") to %s(), please pass a value like \"12px\" or 12.\n\n",
"16": "You must provide a template to this method.\n\n",
"17": "You passed an unsupported selector state to this method.\n\n",
"18": "minScreen and maxScreen must be provided as stringified numbers with the same units.\n\n",
"19": "fromSize and toSize must be provided as stringified numbers with the same units.\n\n",
"20": "expects either an array of objects or a single object with the properties prop, fromSize, and toSize.\n\n",
"21": "expects the objects in the first argument array to have the properties `prop`, `fromSize`, and `toSize`.\n\n",
"22": "expects the first argument object to have the properties `prop`, `fromSize`, and `toSize`.\n\n",
"23": "fontFace expects a name of a font-family.\n\n",
"24": "fontFace expects either the path to the font file(s) or a name of a local copy.\n\n",
"25": "fontFace expects localFonts to be an array.\n\n",
"26": "fontFace expects fileFormats to be an array.\n\n",
"27": "radialGradient requries at least 2 color-stops to properly render.\n\n",
"28": "Please supply a filename to retinaImage() as the first argument.\n\n",
"29": "Passed invalid argument to triangle, please pass correct pointingDirection e.g. 'right'.\n\n",
"30": "Passed an invalid value to `height` or `width`. Please provide a pixel based unit.\n\n",
"31": "The animation shorthand only takes 8 arguments. See the specification for more information: http://mdn.io/animation\n\n",
"32": "To pass multiple animations please supply them in arrays, e.g. animation(['rotate', '2s'], ['move', '1s'])\nTo pass a single animation please supply them in simple values, e.g. animation('rotate', '2s')\n\n",
"33": "The animation shorthand arrays can only have 8 elements. See the specification for more information: http://mdn.io/animation\n\n",
"34": "borderRadius expects a radius value as a string or number as the second argument.\n\n",
"35": "borderRadius expects one of \"top\", \"bottom\", \"left\" or \"right\" as the first argument.\n\n",
"36": "Property must be a string value.\n\n",
"37": "Syntax Error at %s.\n\n",
"38": "Formula contains a function that needs parentheses at %s.\n\n",
"39": "Formula is missing closing parenthesis at %s.\n\n",
"40": "Formula has too many closing parentheses at %s.\n\n",
"41": "All values in a formula must have the same unit or be unitless.\n\n",
"42": "Please provide a number of steps to the modularScale helper.\n\n",
"43": "Please pass a number or one of the predefined scales to the modularScale helper as the ratio.\n\n",
"44": "Invalid value passed as base to modularScale, expected number or em/rem string but got %s.\n\n",
"45": "Passed invalid argument to hslToColorString, please pass a HslColor or HslaColor object.\n\n",
"46": "Passed invalid argument to rgbToColorString, please pass a RgbColor or RgbaColor object.\n\n",
"47": "minScreen and maxScreen must be provided as stringified numbers with the same units.\n\n",
"48": "fromSize and toSize must be provided as stringified numbers with the same units.\n\n",
"49": "Expects either an array of objects or a single object with the properties prop, fromSize, and toSize.\n\n",
"50": "Expects the objects in the first argument array to have the properties prop, fromSize, and toSize.\n\n",
"51": "Expects the first argument object to have the properties prop, fromSize, and toSize.\n\n",
"52": "fontFace expects either the path to the font file(s) or a name of a local copy.\n\n",
"53": "fontFace expects localFonts to be an array.\n\n",
"54": "fontFace expects fileFormats to be an array.\n\n",
"55": "fontFace expects a name of a font-family.\n\n",
"56": "linearGradient requries at least 2 color-stops to properly render.\n\n",
"57": "radialGradient requries at least 2 color-stops to properly render.\n\n",
"58": "Please supply a filename to retinaImage() as the first argument.\n\n",
"59": "Passed invalid argument to triangle, please pass correct pointingDirection e.g. 'right'.\n\n",
"60": "Passed an invalid value to `height` or `width`. Please provide a pixel based unit.\n\n",
"61": "Property must be a string value.\n\n",
"62": "borderRadius expects a radius value as a string or number as the second argument.\n\n",
"63": "borderRadius expects one of \"top\", \"bottom\", \"left\" or \"right\" as the first argument.\n\n",
"64": "The animation shorthand only takes 8 arguments. See the specification for more information: http://mdn.io/animation.\n\n",
"65": "To pass multiple animations please supply them in arrays, e.g. animation(['rotate', '2s'], ['move', '1s'])\\nTo pass a single animation please supply them in simple values, e.g. animation('rotate', '2s').\n\n",
"66": "The animation shorthand arrays can only have 8 elements. See the specification for more information: http://mdn.io/animation.\n\n",
"67": "You must provide a template to this method.\n\n",
"68": "You passed an unsupported selector state to this method.\n\n",
"69": "Expected a string ending in \"px\" or a number passed as the first argument to %s(), got %s instead.\n\n",
"70": "Expected a string ending in \"px\" or a number passed as the second argument to %s(), got %s instead.\n\n",
"71": "Passed invalid pixel value %s to %s(), please pass a value like \"12px\" or 12.\n\n",
"72": "Passed invalid base value %s to %s(), please pass a value like \"12px\" or 12.\n\n",
"73": "Please provide a valid CSS variable.\n\n",
"74": "CSS variable not found and no default was provided.\n\n",
"75": "important requires a valid style object, got a %s instead.\n\n",
"76": "fromSize and toSize must be provided as stringified numbers with the same units as minScreen and maxScreen.\n\n",
"77": "remToPx expects a value in \"rem\" but you provided it in \"%s\".\n\n",
"78": "base must be set in \"px\" or \"%\" but you set it in \"%s\".\n"
};
/**
* super basic version of sprintf
* @private
*/
function format() {
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
var a = args[0];
var b = [];
var c;
for (c = 1; c < args.length; c += 1) {
b.push(args[c]);
}
b.forEach(function (d) {
a = a.replace(/%[a-z]/, d);
});
return a;
}
/**
* Create an error file out of errors.md for development and a simple web link to the full errors
* in production mode.
* @private
*/
var PolishedError = exports["default"] = /*#__PURE__*/function (_Error) {
_inheritsLoose(PolishedError, _Error);
function PolishedError(code) {
var _this;
if (process.env.NODE_ENV === 'production') {
_this = _Error.call(this, "An error occurred. See https://github.com/styled-components/polished/blob/main/src/internalHelpers/errors.md#" + code + " for more information.") || this;
} else {
for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
args[_key2 - 1] = arguments[_key2];
}
_this = _Error.call(this, format.apply(void 0, [ERRORS[code]].concat(args))) || this;
}
return _assertThisInitialized(_this);
}
return PolishedError;
}( /*#__PURE__*/_wrapNativeSuper(Error));
module.exports = exports.default;

View file

@ -0,0 +1,56 @@
// @flow
// based on https://github.com/styled-components/styled-components/blob/fcf6f3804c57a14dd7984dfab7bc06ee2edca044/src/utils/error.js
declare var preval: Function
/**
* Parse errors.md and turn it into a simple hash of code: message
* @private
*/
const ERRORS = preval`
const fs = require('fs');
const md = fs.readFileSync(__dirname + '/errors.md', 'utf8');
module.exports = md.split(/^#/gm).slice(1).reduce((errors, str) => {
const [, code, message] = str.split(/^.*?(\\d+)\\s*\\n/)
errors[code] = message
return errors;
}, {});
`
/**
* super basic version of sprintf
* @private
*/
function format(...args) {
let a = args[0]
const b = []
let c
for (c = 1; c < args.length; c += 1) {
b.push(args[c])
}
b.forEach(d => {
a = a.replace(/%[a-z]/, d)
})
return a
}
/**
* Create an error file out of errors.md for development and a simple web link to the full errors
* in production mode.
* @private
*/
export default class PolishedError extends Error {
constructor(code: string | number, ...args: Array<any>) {
if (process.env.NODE_ENV === 'production') {
super(
`An error occurred. See https://github.com/styled-components/polished/blob/main/src/internalHelpers/errors.md#${code} for more information.`,
)
} else {
super(format(ERRORS[code], ...args))
}
}
}

View file

@ -0,0 +1,9 @@
"use strict";
exports.__esModule = true;
exports["default"] = void 0;
function guard(lowerBoundary, upperBoundary, value) {
return Math.max(lowerBoundary, Math.min(upperBoundary, value));
}
var _default = exports["default"] = guard;
module.exports = exports.default;

View file

@ -0,0 +1,7 @@
// @flow
function guard(lowerBoundary: number, upperBoundary: number, value: number): number {
return Math.max(lowerBoundary, Math.min(upperBoundary, value))
}
export default guard

View file

@ -0,0 +1,19 @@
"use strict";
exports.__esModule = true;
exports["default"] = void 0;
var _hslToRgb = _interopRequireDefault(require("./_hslToRgb"));
var _reduceHexValue = _interopRequireDefault(require("./_reduceHexValue"));
var _numberToHex = _interopRequireDefault(require("./_numberToHex"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
function colorToHex(color) {
return (0, _numberToHex["default"])(Math.round(color * 255));
}
function convertToHex(red, green, blue) {
return (0, _reduceHexValue["default"])("#" + colorToHex(red) + colorToHex(green) + colorToHex(blue));
}
function hslToHex(hue, saturation, lightness) {
return (0, _hslToRgb["default"])(hue, saturation, lightness, convertToHex);
}
var _default = exports["default"] = hslToHex;
module.exports = exports.default;

View file

@ -0,0 +1,18 @@
// @flow
import hslToRgb from './_hslToRgb'
import reduceHexValue from './_reduceHexValue'
import toHex from './_numberToHex'
function colorToHex(color: number): string {
return toHex(Math.round(color * 255))
}
function convertToHex(red: number, green: number, blue: number): string {
return reduceHexValue(`#${colorToHex(red)}${colorToHex(green)}${colorToHex(blue)}`)
}
function hslToHex(hue: number, saturation: number, lightness: number): string {
return hslToRgb(hue, saturation, lightness, convertToHex)
}
export default hslToHex

View file

@ -0,0 +1,53 @@
"use strict";
exports.__esModule = true;
exports["default"] = void 0;
function colorToInt(color) {
return Math.round(color * 255);
}
function convertToInt(red, green, blue) {
return colorToInt(red) + "," + colorToInt(green) + "," + colorToInt(blue);
}
function hslToRgb(hue, saturation, lightness, convert) {
if (convert === void 0) {
convert = convertToInt;
}
if (saturation === 0) {
// achromatic
return convert(lightness, lightness, lightness);
}
// formulae from https://en.wikipedia.org/wiki/HSL_and_HSV
var huePrime = (hue % 360 + 360) % 360 / 60;
var chroma = (1 - Math.abs(2 * lightness - 1)) * saturation;
var secondComponent = chroma * (1 - Math.abs(huePrime % 2 - 1));
var red = 0;
var green = 0;
var blue = 0;
if (huePrime >= 0 && huePrime < 1) {
red = chroma;
green = secondComponent;
} else if (huePrime >= 1 && huePrime < 2) {
red = secondComponent;
green = chroma;
} else if (huePrime >= 2 && huePrime < 3) {
green = chroma;
blue = secondComponent;
} else if (huePrime >= 3 && huePrime < 4) {
green = secondComponent;
blue = chroma;
} else if (huePrime >= 4 && huePrime < 5) {
red = secondComponent;
blue = chroma;
} else if (huePrime >= 5 && huePrime < 6) {
red = chroma;
blue = secondComponent;
}
var lightnessModification = lightness - chroma / 2;
var finalRed = red + lightnessModification;
var finalGreen = green + lightnessModification;
var finalBlue = blue + lightnessModification;
return convert(finalRed, finalGreen, finalBlue);
}
var _default = exports["default"] = hslToRgb;
module.exports = exports.default;

View file

@ -0,0 +1,60 @@
// @flow
type ConversionFunction = (red: number, green: number, blue: number) => string
function colorToInt(color: number): number {
return Math.round(color * 255)
}
function convertToInt(red: number, green: number, blue: number): string {
return `${colorToInt(red)},${colorToInt(green)},${colorToInt(blue)}`
}
function hslToRgb(
hue: number,
saturation: number,
lightness: number,
convert: ConversionFunction = convertToInt,
): string {
if (saturation === 0) {
// achromatic
return convert(lightness, lightness, lightness)
}
// formulae from https://en.wikipedia.org/wiki/HSL_and_HSV
const huePrime = (((hue % 360) + 360) % 360) / 60
const chroma = (1 - Math.abs(2 * lightness - 1)) * saturation
const secondComponent = chroma * (1 - Math.abs((huePrime % 2) - 1))
let red = 0
let green = 0
let blue = 0
if (huePrime >= 0 && huePrime < 1) {
red = chroma
green = secondComponent
} else if (huePrime >= 1 && huePrime < 2) {
red = secondComponent
green = chroma
} else if (huePrime >= 2 && huePrime < 3) {
green = chroma
blue = secondComponent
} else if (huePrime >= 3 && huePrime < 4) {
green = secondComponent
blue = chroma
} else if (huePrime >= 4 && huePrime < 5) {
red = secondComponent
blue = chroma
} else if (huePrime >= 5 && huePrime < 6) {
red = chroma
blue = secondComponent
}
const lightnessModification = lightness - chroma / 2
const finalRed = red + lightnessModification
const finalGreen = green + lightnessModification
const finalBlue = blue + lightnessModification
return convert(finalRed, finalGreen, finalBlue)
}
export default hslToRgb

View file

@ -0,0 +1,166 @@
"use strict";
exports.__esModule = true;
exports["default"] = void 0;
var namedColorMap = {
aliceblue: 'f0f8ff',
antiquewhite: 'faebd7',
aqua: '00ffff',
aquamarine: '7fffd4',
azure: 'f0ffff',
beige: 'f5f5dc',
bisque: 'ffe4c4',
black: '000',
blanchedalmond: 'ffebcd',
blue: '0000ff',
blueviolet: '8a2be2',
brown: 'a52a2a',
burlywood: 'deb887',
cadetblue: '5f9ea0',
chartreuse: '7fff00',
chocolate: 'd2691e',
coral: 'ff7f50',
cornflowerblue: '6495ed',
cornsilk: 'fff8dc',
crimson: 'dc143c',
cyan: '00ffff',
darkblue: '00008b',
darkcyan: '008b8b',
darkgoldenrod: 'b8860b',
darkgray: 'a9a9a9',
darkgreen: '006400',
darkgrey: 'a9a9a9',
darkkhaki: 'bdb76b',
darkmagenta: '8b008b',
darkolivegreen: '556b2f',
darkorange: 'ff8c00',
darkorchid: '9932cc',
darkred: '8b0000',
darksalmon: 'e9967a',
darkseagreen: '8fbc8f',
darkslateblue: '483d8b',
darkslategray: '2f4f4f',
darkslategrey: '2f4f4f',
darkturquoise: '00ced1',
darkviolet: '9400d3',
deeppink: 'ff1493',
deepskyblue: '00bfff',
dimgray: '696969',
dimgrey: '696969',
dodgerblue: '1e90ff',
firebrick: 'b22222',
floralwhite: 'fffaf0',
forestgreen: '228b22',
fuchsia: 'ff00ff',
gainsboro: 'dcdcdc',
ghostwhite: 'f8f8ff',
gold: 'ffd700',
goldenrod: 'daa520',
gray: '808080',
green: '008000',
greenyellow: 'adff2f',
grey: '808080',
honeydew: 'f0fff0',
hotpink: 'ff69b4',
indianred: 'cd5c5c',
indigo: '4b0082',
ivory: 'fffff0',
khaki: 'f0e68c',
lavender: 'e6e6fa',
lavenderblush: 'fff0f5',
lawngreen: '7cfc00',
lemonchiffon: 'fffacd',
lightblue: 'add8e6',
lightcoral: 'f08080',
lightcyan: 'e0ffff',
lightgoldenrodyellow: 'fafad2',
lightgray: 'd3d3d3',
lightgreen: '90ee90',
lightgrey: 'd3d3d3',
lightpink: 'ffb6c1',
lightsalmon: 'ffa07a',
lightseagreen: '20b2aa',
lightskyblue: '87cefa',
lightslategray: '789',
lightslategrey: '789',
lightsteelblue: 'b0c4de',
lightyellow: 'ffffe0',
lime: '0f0',
limegreen: '32cd32',
linen: 'faf0e6',
magenta: 'f0f',
maroon: '800000',
mediumaquamarine: '66cdaa',
mediumblue: '0000cd',
mediumorchid: 'ba55d3',
mediumpurple: '9370db',
mediumseagreen: '3cb371',
mediumslateblue: '7b68ee',
mediumspringgreen: '00fa9a',
mediumturquoise: '48d1cc',
mediumvioletred: 'c71585',
midnightblue: '191970',
mintcream: 'f5fffa',
mistyrose: 'ffe4e1',
moccasin: 'ffe4b5',
navajowhite: 'ffdead',
navy: '000080',
oldlace: 'fdf5e6',
olive: '808000',
olivedrab: '6b8e23',
orange: 'ffa500',
orangered: 'ff4500',
orchid: 'da70d6',
palegoldenrod: 'eee8aa',
palegreen: '98fb98',
paleturquoise: 'afeeee',
palevioletred: 'db7093',
papayawhip: 'ffefd5',
peachpuff: 'ffdab9',
peru: 'cd853f',
pink: 'ffc0cb',
plum: 'dda0dd',
powderblue: 'b0e0e6',
purple: '800080',
rebeccapurple: '639',
red: 'f00',
rosybrown: 'bc8f8f',
royalblue: '4169e1',
saddlebrown: '8b4513',
salmon: 'fa8072',
sandybrown: 'f4a460',
seagreen: '2e8b57',
seashell: 'fff5ee',
sienna: 'a0522d',
silver: 'c0c0c0',
skyblue: '87ceeb',
slateblue: '6a5acd',
slategray: '708090',
slategrey: '708090',
snow: 'fffafa',
springgreen: '00ff7f',
steelblue: '4682b4',
tan: 'd2b48c',
teal: '008080',
thistle: 'd8bfd8',
tomato: 'ff6347',
turquoise: '40e0d0',
violet: 'ee82ee',
wheat: 'f5deb3',
white: 'fff',
whitesmoke: 'f5f5f5',
yellow: 'ff0',
yellowgreen: '9acd32'
};
/**
* Checks if a string is a CSS named color and returns its equivalent hex value, otherwise returns the original color.
* @private
*/
function nameToHex(color) {
if (typeof color !== 'string') return color;
var normalizedColorName = color.toLowerCase();
return namedColorMap[normalizedColorName] ? "#" + namedColorMap[normalizedColorName] : color;
}
var _default = exports["default"] = nameToHex;
module.exports = exports.default;

View file

@ -0,0 +1,163 @@
// @flow
const namedColorMap = {
aliceblue: 'f0f8ff',
antiquewhite: 'faebd7',
aqua: '00ffff',
aquamarine: '7fffd4',
azure: 'f0ffff',
beige: 'f5f5dc',
bisque: 'ffe4c4',
black: '000',
blanchedalmond: 'ffebcd',
blue: '0000ff',
blueviolet: '8a2be2',
brown: 'a52a2a',
burlywood: 'deb887',
cadetblue: '5f9ea0',
chartreuse: '7fff00',
chocolate: 'd2691e',
coral: 'ff7f50',
cornflowerblue: '6495ed',
cornsilk: 'fff8dc',
crimson: 'dc143c',
cyan: '00ffff',
darkblue: '00008b',
darkcyan: '008b8b',
darkgoldenrod: 'b8860b',
darkgray: 'a9a9a9',
darkgreen: '006400',
darkgrey: 'a9a9a9',
darkkhaki: 'bdb76b',
darkmagenta: '8b008b',
darkolivegreen: '556b2f',
darkorange: 'ff8c00',
darkorchid: '9932cc',
darkred: '8b0000',
darksalmon: 'e9967a',
darkseagreen: '8fbc8f',
darkslateblue: '483d8b',
darkslategray: '2f4f4f',
darkslategrey: '2f4f4f',
darkturquoise: '00ced1',
darkviolet: '9400d3',
deeppink: 'ff1493',
deepskyblue: '00bfff',
dimgray: '696969',
dimgrey: '696969',
dodgerblue: '1e90ff',
firebrick: 'b22222',
floralwhite: 'fffaf0',
forestgreen: '228b22',
fuchsia: 'ff00ff',
gainsboro: 'dcdcdc',
ghostwhite: 'f8f8ff',
gold: 'ffd700',
goldenrod: 'daa520',
gray: '808080',
green: '008000',
greenyellow: 'adff2f',
grey: '808080',
honeydew: 'f0fff0',
hotpink: 'ff69b4',
indianred: 'cd5c5c',
indigo: '4b0082',
ivory: 'fffff0',
khaki: 'f0e68c',
lavender: 'e6e6fa',
lavenderblush: 'fff0f5',
lawngreen: '7cfc00',
lemonchiffon: 'fffacd',
lightblue: 'add8e6',
lightcoral: 'f08080',
lightcyan: 'e0ffff',
lightgoldenrodyellow: 'fafad2',
lightgray: 'd3d3d3',
lightgreen: '90ee90',
lightgrey: 'd3d3d3',
lightpink: 'ffb6c1',
lightsalmon: 'ffa07a',
lightseagreen: '20b2aa',
lightskyblue: '87cefa',
lightslategray: '789',
lightslategrey: '789',
lightsteelblue: 'b0c4de',
lightyellow: 'ffffe0',
lime: '0f0',
limegreen: '32cd32',
linen: 'faf0e6',
magenta: 'f0f',
maroon: '800000',
mediumaquamarine: '66cdaa',
mediumblue: '0000cd',
mediumorchid: 'ba55d3',
mediumpurple: '9370db',
mediumseagreen: '3cb371',
mediumslateblue: '7b68ee',
mediumspringgreen: '00fa9a',
mediumturquoise: '48d1cc',
mediumvioletred: 'c71585',
midnightblue: '191970',
mintcream: 'f5fffa',
mistyrose: 'ffe4e1',
moccasin: 'ffe4b5',
navajowhite: 'ffdead',
navy: '000080',
oldlace: 'fdf5e6',
olive: '808000',
olivedrab: '6b8e23',
orange: 'ffa500',
orangered: 'ff4500',
orchid: 'da70d6',
palegoldenrod: 'eee8aa',
palegreen: '98fb98',
paleturquoise: 'afeeee',
palevioletred: 'db7093',
papayawhip: 'ffefd5',
peachpuff: 'ffdab9',
peru: 'cd853f',
pink: 'ffc0cb',
plum: 'dda0dd',
powderblue: 'b0e0e6',
purple: '800080',
rebeccapurple: '639',
red: 'f00',
rosybrown: 'bc8f8f',
royalblue: '4169e1',
saddlebrown: '8b4513',
salmon: 'fa8072',
sandybrown: 'f4a460',
seagreen: '2e8b57',
seashell: 'fff5ee',
sienna: 'a0522d',
silver: 'c0c0c0',
skyblue: '87ceeb',
slateblue: '6a5acd',
slategray: '708090',
slategrey: '708090',
snow: 'fffafa',
springgreen: '00ff7f',
steelblue: '4682b4',
tan: 'd2b48c',
teal: '008080',
thistle: 'd8bfd8',
tomato: 'ff6347',
turquoise: '40e0d0',
violet: 'ee82ee',
wheat: 'f5deb3',
white: 'fff',
whitesmoke: 'f5f5f5',
yellow: 'ff0',
yellowgreen: '9acd32',
}
/**
* Checks if a string is a CSS named color and returns its equivalent hex value, otherwise returns the original color.
* @private
*/
function nameToHex(color: string): string {
if (typeof color !== 'string') return color
const normalizedColorName = color.toLowerCase()
return namedColorMap[normalizedColorName] ? `#${namedColorMap[normalizedColorName]}` : color
}
export default nameToHex

View file

@ -0,0 +1,10 @@
"use strict";
exports.__esModule = true;
exports["default"] = void 0;
function numberToHex(value) {
var hex = value.toString(16);
return hex.length === 1 ? "0" + hex : hex;
}
var _default = exports["default"] = numberToHex;
module.exports = exports.default;

View file

@ -0,0 +1,7 @@
// @flow
function numberToHex(value: number): string {
const hex = value.toString(16)
return hex.length === 1 ? `0${hex}` : hex
}
export default numberToHex

View file

@ -0,0 +1,42 @@
"use strict";
exports.__esModule = true;
exports["default"] = void 0;
var _endsWith = _interopRequireDefault(require("./_endsWith"));
var _stripUnit = _interopRequireDefault(require("../helpers/stripUnit"));
var _errors = _interopRequireDefault(require("./_errors"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
/**
* Factory function that creates pixel-to-x converters
* @private
*/
var pxtoFactory = function pxtoFactory(to) {
return function (pxval, base) {
if (base === void 0) {
base = '16px';
}
var newPxval = pxval;
var newBase = base;
if (typeof pxval === 'string') {
if (!(0, _endsWith["default"])(pxval, 'px')) {
throw new _errors["default"](69, to, pxval);
}
newPxval = (0, _stripUnit["default"])(pxval);
}
if (typeof base === 'string') {
if (!(0, _endsWith["default"])(base, 'px')) {
throw new _errors["default"](70, to, base);
}
newBase = (0, _stripUnit["default"])(base);
}
if (typeof newPxval === 'string') {
throw new _errors["default"](71, pxval, to);
}
if (typeof newBase === 'string') {
throw new _errors["default"](72, base, to);
}
return "" + newPxval / newBase + to;
};
};
var _default = exports["default"] = pxtoFactory;
module.exports = exports.default;

View file

@ -0,0 +1,41 @@
// @flow
import endsWith from './_endsWith'
import stripUnit from '../helpers/stripUnit'
import PolishedError from './_errors'
/**
* Factory function that creates pixel-to-x converters
* @private
*/
const pxtoFactory = (to: string) => (
pxval: string | number,
base?: string | number = '16px',
): string => {
let newPxval = pxval
let newBase = base
if (typeof pxval === 'string') {
if (!endsWith(pxval, 'px')) {
throw new PolishedError(69, to, pxval)
}
newPxval = stripUnit(pxval)
}
if (typeof base === 'string') {
if (!endsWith(base, 'px')) {
throw new PolishedError(70, to, base)
}
newBase = stripUnit(base)
}
if (typeof newPxval === 'string') {
throw new PolishedError(71, pxval, to)
}
if (typeof newBase === 'string') {
throw new PolishedError(72, base, to)
}
return `${newPxval / newBase}${to}`
}
export default pxtoFactory

View file

@ -0,0 +1,16 @@
"use strict";
exports.__esModule = true;
exports["default"] = void 0;
/**
* Reduces hex values if possible e.g. #ff8866 to #f86
* @private
*/
var reduceHexValue = function reduceHexValue(value) {
if (value.length === 7 && value[1] === value[2] && value[3] === value[4] && value[5] === value[6]) {
return "#" + value[1] + value[3] + value[5];
}
return value;
};
var _default = exports["default"] = reduceHexValue;
module.exports = exports.default;

View file

@ -0,0 +1,19 @@
// @flow
/**
* Reduces hex values if possible e.g. #ff8866 to #f86
* @private
*/
const reduceHexValue = (value: string): string => {
if (
value.length === 7
&& value[1] === value[2]
&& value[3] === value[4]
&& value[5] === value[6]
) {
return `#${value[1]}${value[3]}${value[5]}`
}
return value
}
export default reduceHexValue

View file

@ -0,0 +1,61 @@
"use strict";
exports.__esModule = true;
exports["default"] = void 0;
function rgbToHsl(color) {
// make sure rgb are contained in a set of [0, 255]
var red = color.red / 255;
var green = color.green / 255;
var blue = color.blue / 255;
var max = Math.max(red, green, blue);
var min = Math.min(red, green, blue);
var lightness = (max + min) / 2;
if (max === min) {
// achromatic
if (color.alpha !== undefined) {
return {
hue: 0,
saturation: 0,
lightness: lightness,
alpha: color.alpha
};
} else {
return {
hue: 0,
saturation: 0,
lightness: lightness
};
}
}
var hue;
var delta = max - min;
var saturation = lightness > 0.5 ? delta / (2 - max - min) : delta / (max + min);
switch (max) {
case red:
hue = (green - blue) / delta + (green < blue ? 6 : 0);
break;
case green:
hue = (blue - red) / delta + 2;
break;
default:
// blue case
hue = (red - green) / delta + 4;
break;
}
hue *= 60;
if (color.alpha !== undefined) {
return {
hue: hue,
saturation: saturation,
lightness: lightness,
alpha: color.alpha
};
}
return {
hue: hue,
saturation: saturation,
lightness: lightness
};
}
var _default = exports["default"] = rgbToHsl;
module.exports = exports.default;

View file

@ -0,0 +1,59 @@
// @flow
import type {
HslColor, HslaColor, RgbColor, RgbaColor,
} from '../types/color'
function rgbToHsl(color: RgbColor | RgbaColor): HslColor | HslaColor {
// make sure rgb are contained in a set of [0, 255]
const red = color.red / 255
const green = color.green / 255
const blue = color.blue / 255
const max = Math.max(red, green, blue)
const min = Math.min(red, green, blue)
const lightness = (max + min) / 2
if (max === min) {
// achromatic
if (color.alpha !== undefined) {
return {
hue: 0,
saturation: 0,
lightness,
alpha: color.alpha,
}
} else {
return { hue: 0, saturation: 0, lightness }
}
}
let hue
const delta = max - min
const saturation = lightness > 0.5 ? delta / (2 - max - min) : delta / (max + min)
switch (max) {
case red:
hue = (green - blue) / delta + (green < blue ? 6 : 0)
break
case green:
hue = (blue - red) / delta + 2
break
default:
// blue case
hue = (red - green) / delta + 4
break
}
hue *= 60
if (color.alpha !== undefined) {
return {
hue,
saturation,
lightness,
alpha: color.alpha,
}
}
return { hue, saturation, lightness }
}
export default rgbToHsl

View file

@ -0,0 +1,30 @@
"use strict";
exports.__esModule = true;
exports["default"] = void 0;
var _errors = _interopRequireDefault(require("./_errors"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
function generateSelectors(template, state) {
var stateSuffix = state ? ":" + state : '';
return template(stateSuffix);
}
/**
* Function helper that adds an array of states to a template of selectors. Used in textInputs and buttons.
* @private
*/
function statefulSelectors(states, template, stateMap) {
if (!template) throw new _errors["default"](67);
if (states.length === 0) return generateSelectors(template, null);
var selectors = [];
for (var i = 0; i < states.length; i += 1) {
if (stateMap && stateMap.indexOf(states[i]) < 0) {
throw new _errors["default"](68);
}
selectors.push(generateSelectors(template, states[i]));
}
selectors = selectors.join(',');
return selectors;
}
var _default = exports["default"] = statefulSelectors;
module.exports = exports.default;

View file

@ -0,0 +1,33 @@
// @flow
import PolishedError from './_errors'
import type { InteractionState } from '../types/interactionState'
function generateSelectors(template: Function, state: InteractionState): string {
const stateSuffix = state ? `:${state}` : ''
return template(stateSuffix)
}
/**
* Function helper that adds an array of states to a template of selectors. Used in textInputs and buttons.
* @private
*/
function statefulSelectors(
states: Array<InteractionState>,
template: Function,
stateMap?: Array<InteractionState>,
): string {
if (!template) throw new PolishedError(67)
if (states.length === 0) return generateSelectors(template, null)
let selectors = []
for (let i = 0; i < states.length; i += 1) {
if (stateMap && stateMap.indexOf(states[i]) < 0) {
throw new PolishedError(68)
}
selectors.push(generateSelectors(template, states[i]))
}
selectors = selectors.join(',')
return selectors
}
export default statefulSelectors