UNPKG

@platform/css

Version:

Helpers for working with inline CSS.

85 lines (84 loc) 2.06 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var tinycolor = require("tinycolor2"); exports.RED = "rgba(255, 0, 0, 0.1)"; function create(value) { return tinycolor(value); } exports.create = create; exports.black = function () { return create('black'); }; exports.white = function () { return create('white'); }; function mix(color1, color2, amount) { return tinycolor.mix(color1, color2, amount); } exports.mix = mix; function format(value) { if (value === undefined) { return undefined; } if (value === true) { return exports.RED; } if (typeof value === 'number') { return toGrayAlpha(value); } if (typeof value === 'string' && !value.includes('#') && !value.includes('rgb')) { return "#" + value; } return value; } exports.format = format; function toGrayAlpha(value) { if (value < -1) { value = -1; } if (value > 1) { value = 1; } if (value < 0) { return "rgba(0, 0, 0, " + Math.abs(value) + ")"; } if (value > 0) { return "rgba(255, 255, 255, " + value + ")"; } return "rgba(0, 0, 0, 0.0)"; } exports.toGrayAlpha = toGrayAlpha; function toGrayHex(value) { if (value < -1) { value = -1; } if (value > 1) { value = 1; } if (value < 0) { return exports.white() .darken(Math.abs(value) * 100) .toHexString(); } if (value > 0) { return exports.black() .lighten(value * 100) .toHexString(); } return exports.white().toHexString(); } exports.toGrayHex = toGrayHex; function alpha(color, alpha) { return create(color) .setAlpha(alpha) .toRgbString(); } exports.alpha = alpha; function lighten(color, amount) { return create(color) .lighten(amount) .toRgbString(); } exports.lighten = lighten; function darken(color, amount) { return create(color) .darken(amount) .toRgbString(); } exports.darken = darken;