Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
m1k1o
GitHub Repository: m1k1o/neko
Path: blob/master/client/tools/emoji.ts
1300 views
1
import * as fs from 'fs'
2
import { custom } from './emoji_custom'
3
4
const datasource = require('emoji-datasource/emoji.json') as EmojiDatasource[]
5
const emojis = require('emojilib')
6
7
interface EmojiDatasource {
8
name: string
9
unified: string
10
non_qualified: string | null
11
docomo: string | null
12
au: string | null
13
softbank: string | null
14
google: string | null
15
image: string
16
sheet_x: number
17
sheet_y: number
18
short_name: string
19
short_names: string[]
20
text: string | null
21
texts: string | null
22
category: string
23
sort_order: number
24
added_in: string
25
has_img_apple: boolean
26
has_img_google: boolean
27
has_img_twitter: boolean
28
has_img_facebook: boolean
29
skin_variations: {
30
[id: string]: {
31
unified: string
32
image: string
33
sheet_x: number
34
sheet_y: number
35
added_in: string
36
has_img_apple: boolean
37
has_img_google: boolean
38
has_img_twitter: boolean
39
has_img_facebook: boolean
40
}
41
}
42
obsoletes: string
43
obsoleted_by: string
44
}
45
46
const SHEET_COLUMNS = 58
47
const MULTIPLY = 100 / (SHEET_COLUMNS - 1)
48
49
const css: string[] = []
50
const keywords: { [name: string]: string[] } = {}
51
const list: string[] = []
52
const groups: { [name: string]: string[] } = { neko: [] }
53
54
for (const emoji of custom) {
55
groups['neko'].push(emoji.name)
56
list.push(emoji.name)
57
keywords[emoji.name] = emoji.keywords
58
59
// prettier-ignore
60
css.push(`&[data-emoji='${emoji.name}'] { background-size: contain; background-image: url('../images/emoji/${emoji.file}'); }`)
61
}
62
63
for (const source of datasource) {
64
const unified = source.unified.split('-').map(v => v.toLowerCase())
65
66
if (!source.has_img_twitter) {
67
console.log(source.short_name, 'not avalible for set twitter')
68
continue
69
}
70
71
// keywords
72
let words: string[] = []
73
for (const id of Object.keys(emojis)) {
74
if (unified.includes(id.codePointAt(0)!.toString(16))) {
75
words = [id, ...emojis[id]]
76
break
77
}
78
}
79
80
if (words.length == 0) {
81
console.log(source.short_name, 'no keywords')
82
}
83
84
for (const name of source.short_names) {
85
if (!words.includes(name)) {
86
words.push(name)
87
}
88
}
89
90
keywords[source.short_name] = words
91
92
// keywords
93
let group = ''
94
switch (source.category) {
95
case 'Symbols':
96
group = 'symbols'
97
break
98
case 'Activities':
99
group = 'activity'
100
break
101
case 'Flags':
102
group = 'flags'
103
break
104
case 'Travel & Places':
105
group = 'travel'
106
break
107
case 'Food & Drink':
108
group = 'food'
109
break
110
case 'Animals & Nature':
111
group = 'nature'
112
break
113
case 'People & Body':
114
group = 'people'
115
break
116
case 'Smileys & Emotion':
117
group = 'emotion'
118
break
119
case 'Objects':
120
group = 'objects'
121
break
122
case 'Skin Tones':
123
continue
124
default:
125
console.log(`unknown category ${source.category}`)
126
continue
127
}
128
129
if (!groups[group]) {
130
groups[group] = [source.short_name]
131
} else {
132
groups[group].push(source.short_name)
133
}
134
135
// list
136
list.push(source.short_name)
137
138
// css
139
// prettier-ignore
140
css.push(`&[data-emoji='${source.short_name}'] { background-position: ${MULTIPLY * source.sheet_x}% ${MULTIPLY * source.sheet_y}% }`)
141
}
142
143
fs.writeFile(
144
'src/assets/styles/vendor/_emoji.scss',
145
`
146
.emoji {
147
display: inline-block;
148
background-size: ${SHEET_COLUMNS * 100}%;
149
background-image: url('~emoji-datasource/img/twitter/sheets/32.png');
150
background-repeat: no-repeat;
151
vertical-align: bottom;
152
height: 22px;
153
width: 22px;
154
155
${css.map(v => ` ${v}`).join('\n')}
156
}
157
`,
158
() => {
159
console.log('_emoji.scss done')
160
},
161
)
162
163
const data = {
164
groups: [
165
{
166
id: 'neko',
167
name: 'Neko',
168
list: groups['neko'] ? groups['neko'] : [],
169
},
170
{
171
id: 'emotion',
172
name: 'Emotion',
173
list: groups['emotion'] ? groups['emotion'] : [],
174
},
175
{
176
id: 'people',
177
name: 'People',
178
list: groups['people'] ? groups['people'] : [],
179
},
180
{
181
id: 'nature',
182
name: 'Nature',
183
list: groups['nature'] ? groups['nature'] : [],
184
},
185
{
186
id: 'food',
187
name: 'Food',
188
list: groups['food'] ? groups['food'] : [],
189
},
190
{
191
id: 'activity',
192
name: 'Activity',
193
list: groups['activity'] ? groups['activity'] : [],
194
},
195
{
196
id: 'travel',
197
name: 'Travel',
198
list: groups['travel'] ? groups['travel'] : [],
199
},
200
{
201
id: 'objects',
202
name: 'Objects',
203
list: groups['objects'] ? groups['objects'] : [],
204
},
205
{
206
id: 'symbols',
207
name: 'Symbols',
208
list: groups['symbols'] ? groups['symbols'] : [],
209
},
210
{
211
id: 'flags',
212
name: 'Flags',
213
list: groups['flags'] ? groups['flags'] : [],
214
},
215
],
216
list,
217
keywords,
218
}
219
220
fs.writeFile('public/emoji.json', JSON.stringify(data), () => {
221
console.log('emoji.json done')
222
})
223
224