2017-04-22 22:49:49 +00:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
2018-03-19 03:23:05 +00:00
|
|
|
const make = require('../make')
|
|
|
|
const random = require('../random')
|
|
|
|
|
|
|
|
class colors extends make {
|
|
|
|
static any () {
|
2017-04-22 22:49:49 +00:00
|
|
|
return random.pick([
|
2018-04-06 22:15:55 +00:00
|
|
|
colors.rgb,
|
|
|
|
colors.hsl,
|
|
|
|
colors.keyword
|
2017-04-25 22:21:31 +00:00
|
|
|
])
|
2018-03-19 03:23:05 +00:00
|
|
|
}
|
2017-04-22 22:49:49 +00:00
|
|
|
|
2018-03-19 03:23:05 +00:00
|
|
|
static rgb () {
|
2017-04-25 22:21:31 +00:00
|
|
|
let values
|
2017-04-22 22:49:49 +00:00
|
|
|
|
|
|
|
switch (random.number(4)) {
|
|
|
|
case 0:
|
|
|
|
// Rgb functional notation
|
|
|
|
if (random.bool()) {
|
|
|
|
// Ints
|
2017-04-25 22:21:31 +00:00
|
|
|
values = [random.number(255), random.number(255), random.number(255)]
|
2017-04-22 22:49:49 +00:00
|
|
|
} else {
|
|
|
|
// Percents
|
2017-04-25 22:21:31 +00:00
|
|
|
values = ['%' + random.number(255), '%' + random.number(255), '%' + random.number(255)]
|
2017-04-22 22:49:49 +00:00
|
|
|
}
|
2017-04-25 22:21:31 +00:00
|
|
|
return 'rgba(' + values.join(',') + ')'
|
2017-04-22 22:49:49 +00:00
|
|
|
case 1:
|
|
|
|
// Rgba functional notation
|
2017-04-25 22:21:31 +00:00
|
|
|
values = [random.number(255), random.number(255), random.number(255), random.float()]
|
|
|
|
return 'rgba(' + values.join(',') + ')'
|
2017-04-22 22:49:49 +00:00
|
|
|
case 2:
|
|
|
|
// 4 char hex
|
2017-04-25 22:21:31 +00:00
|
|
|
return '#' + random.hex(4)
|
2017-04-22 22:49:49 +00:00
|
|
|
default:
|
|
|
|
// 8 char hex
|
2017-04-25 22:21:31 +00:00
|
|
|
return '#' + random.hex(8)
|
2017-04-22 22:49:49 +00:00
|
|
|
}
|
2018-03-19 03:23:05 +00:00
|
|
|
}
|
2017-04-22 22:49:49 +00:00
|
|
|
|
2018-03-19 03:23:05 +00:00
|
|
|
static hsl () {
|
2017-04-25 22:21:31 +00:00
|
|
|
let values, opt
|
2017-04-22 22:49:49 +00:00
|
|
|
|
|
|
|
switch (random.number(4)) {
|
|
|
|
case 0:
|
2017-04-25 22:21:31 +00:00
|
|
|
values = [random.number(255), '%' + random.number(255), '%' + random.number(255)]
|
|
|
|
return 'hsl(' + values.join(',') + ')'
|
2017-04-22 22:49:49 +00:00
|
|
|
case 1:
|
2017-04-25 22:21:31 +00:00
|
|
|
values = [random.number(255), '%' + random.number(255), '%' + random.number(255), '%' + random.number(255)]
|
|
|
|
return 'hsl(' + values.join(',') + ')'
|
2017-04-22 22:49:49 +00:00
|
|
|
case 2:
|
2017-04-25 22:21:31 +00:00
|
|
|
opt = random.pick(['deg', 'rad', 'grad', 'turn'])
|
|
|
|
values = [random.number(255) + opt, '%' + random.number(255), '%' + random.number(255), '%' + random.number(255)]
|
|
|
|
return 'hsl(' + values.join(',') + ')'
|
2017-04-22 22:49:49 +00:00
|
|
|
default:
|
2017-04-25 22:21:31 +00:00
|
|
|
values = [random.number(255), '%' + random.number(255), '%' + random.number(255), random.float()]
|
|
|
|
return 'hsl(' + values.join(',') + ')'
|
2017-04-22 22:49:49 +00:00
|
|
|
}
|
2018-03-19 03:23:05 +00:00
|
|
|
}
|
2017-04-22 22:49:49 +00:00
|
|
|
|
2018-03-19 03:23:05 +00:00
|
|
|
static keyword () {
|
2017-04-22 22:49:49 +00:00
|
|
|
return random.pick([
|
2017-04-25 22:21:31 +00:00
|
|
|
'lime', 'red', 'blue', 'invert', 'currentColor', 'ActiveBorder', 'ActiveCaption',
|
|
|
|
'AppWorkspace', 'Background', 'ButtonFace', 'ButtonHighlight', 'ButtonShadow',
|
|
|
|
'ButtonText', 'CaptionText', 'GrayText', 'Highlight', 'HighlightText',
|
|
|
|
'InactiveBorder', 'InactiveCaption', 'InactiveCaptionText', 'InfoBackground',
|
|
|
|
'InfoText', 'Menu', 'MenuText', 'Scrollbar', 'ThreeDDarkShadow', 'ThreeDFace',
|
|
|
|
'ThreeDHighlight', 'ThreeDLightShadow', 'ThreeDShadow', 'Window', 'WindowFrame',
|
|
|
|
'WindowText', '-moz-ButtonDefault', '-moz-ButtonHoverFace', '-moz-ButtonHoverText',
|
|
|
|
'-moz-CellHighlight', '-moz-CellHighlightText', '-moz-Combobox', '-moz-ComboboxText',
|
|
|
|
'-moz-Dialog', '-moz-DialogText', '-moz-dragtargetzone', '-moz-EvenTreeRow',
|
|
|
|
'-moz-Field', '-moz-FieldText', '-moz-html-CellHighlight',
|
|
|
|
'-moz-html-CellHighlightText', '-moz-mac-accentdarkestshadow',
|
|
|
|
'-moz-mac-accentdarkshadow', '-moz-mac-accentface',
|
|
|
|
'-moz-mac-accentlightesthighlight', '-moz-mac-accentlightshadow',
|
|
|
|
'-moz-mac-accentregularhighlight', '-moz-mac-accentregularshadow',
|
|
|
|
'-moz-mac-chrome-active', '-moz-mac-chrome-inactive', '-moz-mac-focusring',
|
|
|
|
'-moz-mac-menuselect', '-moz-mac-menushadow', '-moz-mac-menutextselect',
|
|
|
|
'-moz-MenuHover', '-moz-MenuHoverText', '-moz-MenuBarText', '-moz-MenuBarHoverText',
|
|
|
|
'-moz-nativehyperlinktext', '-moz-OddTreeRow', '-moz-win-communicationstext',
|
|
|
|
'-moz-win-mediatext', '-moz-activehyperlinktext', '-moz-default-background-color',
|
|
|
|
'-moz-default-color', '-moz-hyperlinktext', '-moz-visitedhyperlinktext'
|
|
|
|
])
|
2017-04-22 22:49:49 +00:00
|
|
|
}
|
2017-04-25 22:21:31 +00:00
|
|
|
}
|
2018-03-19 03:23:05 +00:00
|
|
|
|
|
|
|
module.exports = colors
|