You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+47-21Lines changed: 47 additions & 21 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -133,6 +133,16 @@ Return a boolean indicating whether the color was successfully parsed. Note: if
133
133
color2.isValid(); // false
134
134
color2.toString(); // "#000000"
135
135
136
+
### getBrightness
137
+
138
+
Returns the perceived brightness of a color, from `0-255`, as defined by [Web Content Accessibility Guidelines (Version 1.0)](http://www.w3.org/TR/AERT#color-contrast).
139
+
140
+
var color1 = tinycolor("#fff");
141
+
color1.getBrightness(); // 255
142
+
143
+
var color2 = tinycolor("#000");
144
+
color2.getBrightness(); // 0
145
+
136
146
### isLight
137
147
138
148
Return a boolean indicating whether the color's perceived brightness is light.
@@ -153,6 +163,16 @@ Return a boolean indicating whether the color's perceived brightness is dark.
153
163
var color2 = tinycolor("#000");
154
164
color2.isDark(); // true
155
165
166
+
### getLuminance
167
+
168
+
Returns the perceived luminance of a color, from `0-1` as defined by [Web Content Accessibility Guidelines (Version 2.0).](http://www.w3.org/TR/2008/REC-WCAG20-20081211/#contrast-ratiodef)
169
+
170
+
var color1 = tinycolor("#fff");
171
+
color1.getLuminance(); // 1
172
+
173
+
var color2 = tinycolor("#000");
174
+
color2.getLuminance(); // 0
175
+
156
176
### getAlpha
157
177
158
178
Returns the alpha value of a color, from `0-1`.
@@ -166,16 +186,6 @@ Returns the alpha value of a color, from `0-1`.
166
186
var color3 = tinycolor("transparent");
167
187
color3.getAlpha(); // 0
168
188
169
-
### getBrightness
170
-
171
-
Returns the perceived brightness of a color, from `0-255`.
172
-
173
-
var color1 = tinycolor("#fff");
174
-
color1.getBrightness(); // 255
175
-
176
-
var color2 = tinycolor("#000");
177
-
color2.getBrightness(); // 0
178
-
179
189
### setAlpha
180
190
181
191
Sets the alpha value on a current color. Accepted range is in between `0-1`.
@@ -274,7 +284,7 @@ Print to a string, depending on the input format. You can also override this by
274
284
275
285
var color1 = tinycolor("red");
276
286
color1.toString(); // "red"
277
-
color1.toString("hsv"); // ""hsv(0, 100%, 100%)"
287
+
color1.toString("hsv"); // "hsv(0, 100%, 100%)"
278
288
279
289
var color2 = tinycolor("rgb(255, 0, 0)");
280
290
color2.toString(); // "rgb(255, 0, 0)"
@@ -396,29 +406,45 @@ Combination functions return an array of TinyColor objects unless otherwise note
396
406
397
407
### random
398
408
399
-
Returns a random color
409
+
Returns a random color.
400
410
```js
401
411
var color =tinycolor.random();
402
412
color.toRgb(); // "{r: 145, g: 40, b: 198, a: 1}"
403
413
```
404
414
405
-
### readability
415
+
### Readability
416
+
TinyColor assesses readability based on the [Web Content Accessibility Guidelines (Version 2.0)](http://www.w3.org/TR/2008/REC-WCAG20-20081211/#contrast-ratiodef).
`readable: function(TinyColor, TinyColor) -> Object`. Analyze 2 colors and returns an object with the following properties. `brightness` is difference in brightness between the two colors. `color`: difference in color/hue between the two colors.
equal(tinycolor.mostReadable("#ff0088",["#2e0c3a"],{includeFallbackColors:true,level:"AAA",size:"large"}).toHexString(),"#2e0c3a","readable color present");
603
+
equal(tinycolor.mostReadable("#ff0088",["#2e0c3a"],{includeFallbackColors:true,level:"AAA",size:"small"}).toHexString(),"#000000","no readable color in list");
equal(tinycolor.mostReadable("#371b2c",["#a9acb6"],{includeFallbackColors:true,level:"AAA",size:"large"}).toHexString(),"#a9acb6","readable color present");
607
+
equal(tinycolor.mostReadable("#371b2c",["#a9acb6"],{includeFallbackColors:true,level:"AAA",size:"small"}).toHexString(),"#ffffff","no readable color in list");
0 commit comments