-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
119 lines (107 loc) · 5.18 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/*
* ES-TinyColor v0.4.1
* ────────────────────────────────────────────────────────────────────────────
* © 2016 Mark Griffiths @ The Bespoke Pixel (MIT licensed)
* Based on TinyColor © Brian Grinstead
*/
/* eslint import/no-unassigned-import: 0 */
import TinyColor from './lib/classes/tinycolor.js'
import './lib/extensions/rgb.js'
import './lib/extensions/prgb.js'
import './lib/extensions/hex.js'
import './lib/extensions/hex8.js'
import './lib/extensions/hsl.js'
import './lib/extensions/hsv.js'
import {names} from './lib/extensions/name.js'
function tinycolor(color, options) {
return new TinyColor(color, options)
}
// Expose static methods if called from function.
/**
* Are two TinyColor colours equivalent?
*
* @alias tinycolor.equals
* @param {TinyColor} color1 The first color
* @param {TinyColor} color2 The second color
* @return {boolean} Equivalent or not?
*/
tinycolor.equals = (color1, color2) => TinyColor.equals(color1, color2)
/**
* Register a TinyColor extension
*
* @alias tinycolor.registerFormat
* @param {string} id The plugin identifier
* @param {object} [options={}] Plugin options
* @param {string} options.alphaFormat rgb|hex
* @param {boolean} options.shortHex Short hex codes #ABC, if possible
* @param {boolean} options.upperCaseHex User UPPER case hex
* @return {TinyColorExtension} The TinyColor extension
*/
tinycolor.registerFormat = (id, options = {}) => TinyColor.registerFormat(id, options)
/**
* Create a new TinyColor from values from 0..1
*
* @alias tinycolor.fromRatio
* @param {object} color The color values
* @param {object} options Options to pass to TinyColor constructor
* @return {TinyColor} A TinyColor instance
*/
tinycolor.fromRatio = (color, options) => TinyColor.fromRatio(color, options)
/**
* Mix a second colour into the first
*
* @alias tinycolor.mix
* @param {TinyColor} color1 The first color
* @param {TinyColor} color2 The second color
* @param {number} amount The mix amount of the second color
* @return {TinyColor} A new, mixed TinyColor instance
*/
tinycolor.mix = (color1, color2, amount) => TinyColor.mix(color1, color2, amount)
/**
* How readable is the first color over the second color
*
* @alias tinycolor.readability
* @param {TinyColor} color1 The first color
* @param {TinyColor} color2 The second color
* @return {number} The color contrast defined by (WCAG Version 2)
*/
tinycolor.readability = (color1, color2) => TinyColor.readability(color1, color2)
/**
* Ensure that foreground and background color combinations meet WCAG2 guidelines.
*
* @alias tinycolor.isReadable
* @param {TinyColor} color1 The first color
* @param {TinyColor} color2 The second color
* @param {object} wcag2 The WCAG2 properties to test
* @param {object} wcag2.level The level to test "AA" or "AAA" (default "AA")
* @param {object} wcag2.size The content size to test "large" or "small" (default "small")
* @example tinycolor.isReadable("#000", "#111") → false
* @example tinycolor.isReadable("#000", "#111", {level:"AA",size:"large"}) → false
* @return {(boolean|number)} True if readable, False otherwise.
*/
tinycolor.isReadable = (color1, color2, wcag2) => TinyColor.isReadable(color1, color2, wcag2)
/**
* 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.
*
* @alias tinycolor.mostReadable
* @param {TinyColor} baseColor The base color
* @param {[TinyColor]} colorList An array of TinyColors
* @param {object} [args={}] The arguments
* @param {boolean} args.includeFallbackColors Include fallback colors?
* @param {object} args.level The level to test "AA" or "AAA" (default "AA")
* @param {object} args.size The content size to test "large" or "small" (default "small")
* @example tinycolor.mostReadable(tinycolor.mostReadable("#123", ["#124", "#125"],{includeFallbackColors:false}).toHexString(); // "#112255"
* @example tinycolor.mostReadable(tinycolor.mostReadable("#123", ["#124", "#125"],{includeFallbackColors:true}).toHexString(); // "#ffffff"
* @example tinycolor.mostReadable("#a8015a", ["#faf3f3"], {includeFallbackColors:true,level:"AAA",size:"large"}).toHexString(); // "#faf3f3"
* @example tinycolor.mostReadable("#a8015a", ["#faf3f3"], {includeFallbackColors:true,level:"AAA",size:"small"}).toHexString(); // "#ffffff"
* @return {TinyColor} A TinyColor instance of the msot readable color.
*/
tinycolor.mostReadable = (baseColor, colorList, args) => TinyColor.mostReadable(baseColor, colorList, args)
/**
* Named Colours (as per CSS color names)
*/
tinycolor.names = names
export {TinyColor, tinycolor, names}