Farbe
About Farbe
Section titled “About Farbe”Farbe is a powerful JavaScript library for working with colors. It provides extensive functionality for creating, converting, manipulating, and analyzing colors in various formats (HEX, RGB, RGBA, HSL, HSLA, HSV, CMYK).
In Metro UI Farbe stored in the global class Farbe and fabric method farbe().
Installation
Section titled “Installation”Metro UI already includes the Farbe library.
You can use it without any additional installation, but if you want to use it in your project, you can install it with package manager:
npm install @olton/farbepnpm install @olton/farbeyarn add @olton/farbeor use CDN:
<script type="module"> import { Farbe } from "https://esm.run/@olton/farbe";</script>Main Farbe Class
Section titled “Main Farbe Class”Constructor
Section titled “Constructor”new Farbe(color, options)Creates a new instance of Farbe.
color- color in any supported format (HEX, RGB, RGBA, HSL, HSLA, HSV, CMYK). Default is#000000.options- configuration object for color manipulations.
Properties
Section titled “Properties”options
Section titled “options”Get or set options for color manipulations.
const color = new Farbe("#ff0000");console.log(color.options); // Get optionscolor.options = { angle: 45 }; // Set optionsGet or set the current color value.
const color = new Farbe("#ff0000");console.log(color.value); // Get current color valuecolor.value = "rgb(0, 255, 0)"; // Set new color valueGet the type of the current color (HEX, RGB, RGBA, HSL, HSLA, HSV, CMYK).
const color = new Farbe("#ff0000");console.log(color.type); // "hex"Get the color in RGB format.
const color = new Farbe("#ff0000");console.log(color.rgb); // RGB {r: 255, g: 0, b: 0}Get the color in RGBA format.
const color = new Farbe("#ff0000");console.log(color.rgba); // RGBA {r: 255, g: 0, b: 0, a: 1}Get the color in HEX format.
const color = new Farbe("rgb(255, 0, 0)");console.log(color.hex); // "#ff0000"Get the color in HSV format.
const color = new Farbe("#ff0000");console.log(color.hsv); // HSV {h: 0, s: 1, v: 1}Get the color in HSL format.
const color = new Farbe("#ff0000");console.log(color.hsl); // HSL {h: 0, s: 1, l: 0.5}Get the color in HSLA format.
const color = new Farbe("#ff0000");console.log(color.hsla); // HSLA {h: 0, s: 1, l: 0.5, a: 1}Get the color in CMYK format.
const color = new Farbe("#ff0000");console.log(color.cmyk); // CMYK {c: 0, m: 100, y: 100, k: 0}websafe
Section titled “websafe”Get the color in websafe format.
const color = new Farbe("#ff0012");console.log(color.websafe); // "#ff0000"Conversion Methods
Section titled “Conversion Methods”toRGB()
Section titled “toRGB()”Converts the current color to RGB format.
const color = new Farbe("#ff0000");color.toRGB();console.log(color.type); // "rgb"toRGBA(alpha)
Section titled “toRGBA(alpha)”Converts the current color to RGBA format with the specified or current alpha value.
const color = new Farbe("#ff0000");color.toRGBA(0.5);console.log(color.type); // "rgba"console.log(color.value.a); // 0.5toHEX()
Section titled “toHEX()”Converts the current color to HEX format.
const color = new Farbe("rgb(255, 0, 0)");color.toHEX();console.log(color.type); // "hex"toHSV()
Section titled “toHSV()”Converts the current color to HSV format.
const color = new Farbe("#ff0000");color.toHSV();console.log(color.type); // "hsv"toHSL()
Section titled “toHSL()”Converts the current color to HSL format.
const color = new Farbe("#ff0000");color.toHSL();console.log(color.type); // "hsl"toHSLA(alpha)
Section titled “toHSLA(alpha)”Converts the current color to HSLA format with the specified or current alpha value.
const color = new Farbe("#ff0000");color.toHSLA(0.5);console.log(color.type); // "hsla"console.log(color.value.a); // 0.5toCMYK()
Section titled “toCMYK()”Converts the current color to CMYK format.
const color = new Farbe("#ff0000");color.toCMYK();console.log(color.type); // "cmyk"toWebsafe()
Section titled “toWebsafe()”Converts the current color to the closest websafe color.
const color = new Farbe("#ff0012");color.toWebsafe();console.log(color.value); // "#ff0000"Manipulation Methods
Section titled “Manipulation Methods”darken(amount)
Section titled “darken(amount)”Darkens the color by the specified percentage.
const color = new Farbe("#ff0000");color.darken(20);console.log(color.hex); // "#990000"lighten(amount)
Section titled “lighten(amount)”Lightens the color by the specified percentage.
const color = new Farbe("#ff0000");color.lighten(20);console.log(color.hex); // "#ff6666"hueShift(angle)
Section titled “hueShift(angle)”Shifts the color on the color wheel by the specified angle.
const color = new Farbe("#ff0000");color.hueShift(120);console.log(color.hex); // "#00ff00"grayscale()
Section titled “grayscale()”Converts the color to a grayscale shade.
const color = new Farbe("#ff0000");color.grayscale();console.log(color.hex); // "#363636"add(color)
Section titled “add(color)”Adds another color to the current one (blends colors).
const color = new Farbe("#ff0000");color.add("#0000ff");console.log(color.hex); // "#7f007f"mix(color, amount)
Section titled “mix(color, amount)”Mixes the current color with another one in the specified proportion.
const color = new Farbe("#ff0000");color.mix("#0000ff", 50);console.log(color.hex); // "#800080"multiply(color)
Section titled “multiply(color)”Multiplies the colors (like the “Multiply” blend mode in Photoshop).
const color = new Farbe("#ff0000");color.multiply("#00ff00");console.log(color.hex); // "#000000"shade(amount)
Section titled “shade(amount)”Adds black or white to the color depending on the value.
const color = new Farbe("#ff0000");color.shade(20);console.log(color.hex); // "#ff3333"saturate(amount)
Section titled “saturate(amount)”Increases the color saturation.
const color = new Farbe("hsl(0, 50%, 50%)");color.saturate(20);console.log(color.hsl); // HSL {h: 0, s: 1, l: 0.5}desaturate(amount)
Section titled “desaturate(amount)”Decreases the color saturation.
const color = new Farbe("hsl(0, 100%, 50%)");color.desaturate(20);console.log(color.hsl); // HSL {h: 0, s: 0.8, l: 0.5}spin(amount)
Section titled “spin(amount)”Rotates the hue of the color by the specified number of degrees.
const color = new Farbe("#ff0000");color.spin(120);console.log(color.hex); // "#00ff00"brighten(amount)
Section titled “brighten(amount)”Makes the color brighter.
const color = new Farbe("#880000");color.brighten(20);console.log(color.hex); // "#bb3333"channel(ch, val)
Section titled “channel(ch, val)”Changes the value of a specific color channel.
const color = new Farbe("#ff0000");color.channel("red", 128);console.log(color.rgb); // RGB {r: 128, g: 0, b: 0}Checking and Analysis Methods
Section titled “Checking and Analysis Methods”isDark()
Section titled “isDark()”Checks if the color is dark.
const color = new Farbe("#000000");console.log(color.isDark()); // trueisLight()
Section titled “isLight()”Checks if the color is light.
const color = new Farbe("#ffffff");console.log(color.isLight()); // trueequal(color)
Section titled “equal(color)”Checks if the current color equals the specified one.
const color = new Farbe("#ff0000");console.log(color.equal("#ff0000")); // trueconsole.log(color.equal("rgb(255, 0, 0)")); // trueconsole.log(color.equal("#00ff00")); // falsetoString()
Section titled “toString()”Returns a string representation of the color.
const color = new Farbe("rgb(255, 0, 0)");console.log(color.toString()); // "rgb(255,0,0)"Other Methods
Section titled “Other Methods”getScheme(name, format, options)
Section titled “getScheme(name, format, options)”Creates a color scheme based on the current color.
const color = new Farbe("#ff0000");const scheme = color.getScheme("complementary", "hex");console.log(scheme); // ["#ff0000", "#00ffff"]Supported schemes:
- monochromatic (mono)
- complementary (complement, comp)
- double-complementary (double-complement, double)
- analogous (analog)
- triadic (triad)
- tetradic (tetra)
- square
- split-complementary (split-complement, split)
- material
random(colorType, alpha)
Section titled “random(colorType, alpha)”Sets a random color of the specified type.
const color = new Farbe();color.random("rgb");console.log(color.rgb); // RGB with random valuesHelper Classes and Objects
Section titled “Helper Classes and Objects”Primitives
Section titled “Primitives”Primitive classes for representing colors in different formats.
HSVHSLHSLARGBRGBACMYK
Palette
Section titled “Palette”Object for working with color palettes.
Available Palettes
Section titled “Available Palettes”StandardColorPalette- standard color paletteMetroColorPalette- Metro UI color palette
Palette Methods
Section titled “Palette Methods”Palette.color("red"); // Get color by namePalette.palette(); // Get all color names in the palettePalette.colors(); // Get all colors in the paletteinfo() Function
Section titled “info() Function”Outputs information about the current library version to the console.
info(); // Displays Farbe version informationUsage Examples
Section titled “Usage Examples”// Creating a new colorconst color = new Farbe("#ff0000");
// Converting the colorcolor.toHSL();console.log(color.value); // HSL {h: 0, s: 1, l: 0.5}
// Manipulating the colorcolor.lighten(20);console.log(color.value); // HSL {h: 0, s: 1, l: 0.7}
// Getting the color in different formatsconsole.log(color.hex); // "#ff6666"console.log(color.rgb); // RGB {r: 255, g: 102, b: 102}
// Creating a color schemeconst scheme = color.getScheme("complementary", "hex");console.log(scheme); // ["#ff6666", "#66ffff"]This library provides all the necessary tools for professional color work in JavaScript projects.