This repository has been archived by the owner on Apr 2, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
75 lines (74 loc) · 2.12 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
const color = require('color')
module.exports = (pluginContext) => {
return {
respondsTo: (query) => {
return query.match(/^#(?:[0-9a-f]{1,6})$/i) ||
query.match(/^rgb\(.*$/i) ||
query.match(/^hsl\(.*$/i)
},
search: (query, env = {}) => {
let colorData = query
if (colorData.match(/^#(?:[0-9a-f]{1,6})$/i)) {
for (let i = 0; i < 9; i++) {
if (colorData.length > 1 && colorData.length < 4) {
colorData = `${colorData}0`
} else if (colorData.length > 4 && colorData.length < 7) {
colorData = `${colorData}0`
}
}
}
const c = color(colorData)
const prev = (bgColor, textColor, text) => (`
<style>
body {
background-color:${bgColor};
display:flex;
align-items: center;
justify-content: center;
}
.prev-text {
font-family: monospace;
color: ${textColor};
}
</style>
<div class="prev-text">${text}</div>`)
const tColor = c.dark() ? '#fff' : '#000'
const cHex = c.hex()
const cRgb = c.rgb().string()
const cRgbPerc = c.rgb().percentString()
const cHsl = c.hsl().round().string()
return new Promise((resolve, reject) => {
resolve([
{
icon: 'fa-paint-brush',
title: cHex,
subtitle: 'CSS - Hexadecimal',
value: cHex,
preview: prev(cHex, tColor, cHex)
},
{
icon: 'fa-paint-brush',
title: cRgb,
subtitle: 'CSS - RGB',
value: cRgb,
preview: prev(cHex, tColor, cRgb)
},
{
icon: 'fa-paint-brush',
title: cRgbPerc,
subtitle: 'CSS - RGB Percent',
value: cRgbPerc,
preview: prev(cHex, tColor, cRgbPerc)
},
{
icon: 'fa-paint-brush',
title: cHsl,
subtitle: 'CSS - HSL',
value: cHsl,
preview: prev(cHex, tColor, cHsl)
}
])
})
}
}
}