@ckeditor/ckeditor5-emoji 44.2.0-alpha.0 → 44.2.0-alpha.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +1 -0
- package/build/emoji.js +1 -1
- package/build/translations/ar.js +1 -1
- package/build/translations/bg.js +1 -1
- package/build/translations/bn.js +1 -1
- package/build/translations/ca.js +1 -1
- package/build/translations/cs.js +1 -1
- package/build/translations/da.js +1 -1
- package/build/translations/de.js +1 -1
- package/build/translations/el.js +1 -1
- package/build/translations/es.js +1 -1
- package/build/translations/et.js +1 -1
- package/build/translations/fi.js +1 -1
- package/build/translations/fr.js +1 -1
- package/build/translations/he.js +1 -1
- package/build/translations/hi.js +1 -1
- package/build/translations/hu.js +1 -1
- package/build/translations/id.js +1 -1
- package/build/translations/it.js +1 -1
- package/build/translations/ja.js +1 -1
- package/build/translations/ko.js +1 -1
- package/build/translations/lt.js +1 -1
- package/build/translations/lv.js +1 -1
- package/build/translations/ms.js +1 -1
- package/build/translations/nl.js +1 -1
- package/build/translations/no.js +1 -1
- package/build/translations/pl.js +1 -1
- package/build/translations/pt-br.js +1 -1
- package/build/translations/pt.js +1 -1
- package/build/translations/ro.js +1 -1
- package/build/translations/ru.js +1 -1
- package/build/translations/sk.js +1 -1
- package/build/translations/sr.js +1 -1
- package/build/translations/sv.js +1 -1
- package/build/translations/th.js +1 -1
- package/build/translations/tr.js +1 -1
- package/build/translations/uk.js +1 -1
- package/build/translations/vi.js +1 -1
- package/build/translations/zh-cn.js +1 -1
- package/build/translations/zh.js +1 -1
- package/ckeditor5-metadata.json +15 -2
- package/dist/index-editor.css +1 -1
- package/dist/index.css +1 -1
- package/dist/index.css.map +1 -1
- package/dist/index.js +312 -154
- package/dist/index.js.map +1 -1
- package/dist/translations/ar.js +1 -1
- package/dist/translations/ar.umd.js +1 -1
- package/dist/translations/bg.js +1 -1
- package/dist/translations/bg.umd.js +1 -1
- package/dist/translations/bn.js +1 -1
- package/dist/translations/bn.umd.js +1 -1
- package/dist/translations/ca.js +1 -1
- package/dist/translations/ca.umd.js +1 -1
- package/dist/translations/cs.js +1 -1
- package/dist/translations/cs.umd.js +1 -1
- package/dist/translations/da.js +1 -1
- package/dist/translations/da.umd.js +1 -1
- package/dist/translations/de.js +1 -1
- package/dist/translations/de.umd.js +1 -1
- package/dist/translations/el.js +1 -1
- package/dist/translations/el.umd.js +1 -1
- package/dist/translations/es.js +1 -1
- package/dist/translations/es.umd.js +1 -1
- package/dist/translations/et.js +1 -1
- package/dist/translations/et.umd.js +1 -1
- package/dist/translations/fi.js +1 -1
- package/dist/translations/fi.umd.js +1 -1
- package/dist/translations/fr.js +1 -1
- package/dist/translations/fr.umd.js +1 -1
- package/dist/translations/he.js +1 -1
- package/dist/translations/he.umd.js +1 -1
- package/dist/translations/hi.js +1 -1
- package/dist/translations/hi.umd.js +1 -1
- package/dist/translations/hu.js +1 -1
- package/dist/translations/hu.umd.js +1 -1
- package/dist/translations/id.js +1 -1
- package/dist/translations/id.umd.js +1 -1
- package/dist/translations/it.js +1 -1
- package/dist/translations/it.umd.js +1 -1
- package/dist/translations/ja.js +1 -1
- package/dist/translations/ja.umd.js +1 -1
- package/dist/translations/ko.js +1 -1
- package/dist/translations/ko.umd.js +1 -1
- package/dist/translations/lt.js +1 -1
- package/dist/translations/lt.umd.js +1 -1
- package/dist/translations/lv.js +1 -1
- package/dist/translations/lv.umd.js +1 -1
- package/dist/translations/ms.js +1 -1
- package/dist/translations/ms.umd.js +1 -1
- package/dist/translations/nl.js +1 -1
- package/dist/translations/nl.umd.js +1 -1
- package/dist/translations/no.js +1 -1
- package/dist/translations/no.umd.js +1 -1
- package/dist/translations/pl.js +1 -1
- package/dist/translations/pl.umd.js +1 -1
- package/dist/translations/pt-br.js +1 -1
- package/dist/translations/pt-br.umd.js +1 -1
- package/dist/translations/pt.js +1 -1
- package/dist/translations/pt.umd.js +1 -1
- package/dist/translations/ro.js +1 -1
- package/dist/translations/ro.umd.js +1 -1
- package/dist/translations/ru.js +1 -1
- package/dist/translations/ru.umd.js +1 -1
- package/dist/translations/sk.js +1 -1
- package/dist/translations/sk.umd.js +1 -1
- package/dist/translations/sr.js +1 -1
- package/dist/translations/sr.umd.js +1 -1
- package/dist/translations/sv.js +1 -1
- package/dist/translations/sv.umd.js +1 -1
- package/dist/translations/th.js +1 -1
- package/dist/translations/th.umd.js +1 -1
- package/dist/translations/tr.js +1 -1
- package/dist/translations/tr.umd.js +1 -1
- package/dist/translations/uk.js +1 -1
- package/dist/translations/uk.umd.js +1 -1
- package/dist/translations/vi.js +1 -1
- package/dist/translations/vi.umd.js +1 -1
- package/dist/translations/zh-cn.js +1 -1
- package/dist/translations/zh-cn.umd.js +1 -1
- package/dist/translations/zh.js +1 -1
- package/dist/translations/zh.umd.js +1 -1
- package/lang/translations/ar.po +22 -22
- package/lang/translations/bg.po +22 -22
- package/lang/translations/bn.po +22 -22
- package/lang/translations/ca.po +22 -22
- package/lang/translations/cs.po +22 -22
- package/lang/translations/da.po +22 -22
- package/lang/translations/de.po +22 -22
- package/lang/translations/el.po +22 -22
- package/lang/translations/es.po +22 -22
- package/lang/translations/et.po +22 -22
- package/lang/translations/fi.po +22 -22
- package/lang/translations/fr.po +22 -22
- package/lang/translations/he.po +22 -22
- package/lang/translations/hi.po +22 -22
- package/lang/translations/hu.po +22 -22
- package/lang/translations/id.po +22 -22
- package/lang/translations/it.po +22 -22
- package/lang/translations/ja.po +22 -22
- package/lang/translations/ko.po +22 -22
- package/lang/translations/lt.po +22 -22
- package/lang/translations/lv.po +22 -22
- package/lang/translations/ms.po +22 -22
- package/lang/translations/nl.po +22 -22
- package/lang/translations/no.po +22 -22
- package/lang/translations/pl.po +22 -22
- package/lang/translations/pt-br.po +22 -22
- package/lang/translations/pt.po +22 -22
- package/lang/translations/ro.po +22 -22
- package/lang/translations/ru.po +22 -22
- package/lang/translations/sk.po +22 -22
- package/lang/translations/sr.po +22 -22
- package/lang/translations/sv.po +22 -22
- package/lang/translations/th.po +22 -22
- package/lang/translations/tr.po +22 -22
- package/lang/translations/uk.po +22 -22
- package/lang/translations/vi.po +22 -22
- package/lang/translations/zh-cn.po +22 -22
- package/lang/translations/zh.po +22 -22
- package/package.json +7 -7
- package/src/augmentation.d.ts +2 -1
- package/src/emojiconfig.d.ts +2 -1
- package/src/emojimention.d.ts +13 -6
- package/src/emojimention.js +39 -26
- package/src/emojipicker.d.ts +3 -3
- package/src/emojipicker.js +14 -14
- package/src/emojirepository.d.ts +35 -17
- package/src/emojirepository.js +86 -126
- package/src/emojiutils.d.ts +58 -0
- package/src/emojiutils.js +141 -0
- package/src/index.d.ts +1 -0
- package/src/index.js +1 -0
- package/src/ui/emojipickerview.js +1 -0
- package/src/utils/isemojisupported.d.ts +11 -0
- package/src/utils/isemojisupported.js +68 -0
- package/theme/emojigrid.css +1 -1
package/src/emojirepository.js
CHANGED
|
@@ -8,25 +8,23 @@
|
|
|
8
8
|
import Fuse from 'fuse.js';
|
|
9
9
|
import { groupBy } from 'lodash-es';
|
|
10
10
|
import { Plugin } from 'ckeditor5/src/core.js';
|
|
11
|
-
import { logWarning } from 'ckeditor5/src/utils.js';
|
|
12
|
-
|
|
11
|
+
import { logWarning, version } from 'ckeditor5/src/utils.js';
|
|
12
|
+
import EmojiUtils from './emojiutils.js';
|
|
13
|
+
// An endpoint from which the emoji data will be downloaded during plugin initialization.
|
|
13
14
|
// The `{version}` placeholder is replaced with the value from editor config.
|
|
14
15
|
const EMOJI_DATABASE_URL = 'https://cdn.ckeditor.com/ckeditor5/data/emoji/{version}/en.json';
|
|
15
|
-
const SKIN_TONE_MAP = {
|
|
16
|
-
0: 'default',
|
|
17
|
-
1: 'light',
|
|
18
|
-
2: 'medium-light',
|
|
19
|
-
3: 'medium',
|
|
20
|
-
4: 'medium-dark',
|
|
21
|
-
5: 'dark'
|
|
22
|
-
};
|
|
23
|
-
const BASELINE_EMOJI_WIDTH = 24;
|
|
24
16
|
/**
|
|
25
17
|
* The emoji repository plugin.
|
|
26
18
|
*
|
|
27
|
-
* Loads the emoji
|
|
19
|
+
* Loads the emoji repository from URL during plugin initialization and provides utility methods to search it.
|
|
28
20
|
*/
|
|
29
21
|
class EmojiRepository extends Plugin {
|
|
22
|
+
/**
|
|
23
|
+
* @inheritDoc
|
|
24
|
+
*/
|
|
25
|
+
static get requires() {
|
|
26
|
+
return [EmojiUtils];
|
|
27
|
+
}
|
|
30
28
|
/**
|
|
31
29
|
* @inheritDoc
|
|
32
30
|
*/
|
|
@@ -44,13 +42,13 @@ class EmojiRepository extends Plugin {
|
|
|
44
42
|
*/
|
|
45
43
|
constructor(editor) {
|
|
46
44
|
super(editor);
|
|
47
|
-
|
|
45
|
+
editor.config.define('emoji', {
|
|
48
46
|
version: 16,
|
|
49
47
|
skinTone: 'default'
|
|
50
48
|
});
|
|
51
|
-
this.
|
|
52
|
-
this.
|
|
53
|
-
this.
|
|
49
|
+
this._version = editor.config.get('emoji.version');
|
|
50
|
+
this._repositoryPromise = new Promise(resolve => {
|
|
51
|
+
this._repositoryPromiseResolveCallback = resolve;
|
|
54
52
|
});
|
|
55
53
|
this._fuseSearch = null;
|
|
56
54
|
}
|
|
@@ -58,23 +56,18 @@ class EmojiRepository extends Plugin {
|
|
|
58
56
|
* @inheritDoc
|
|
59
57
|
*/
|
|
60
58
|
async init() {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
if
|
|
67
|
-
|
|
59
|
+
if (!(this._version in EmojiRepository._results)) {
|
|
60
|
+
const cdnResult = await this._loadItemsFromCdn();
|
|
61
|
+
EmojiRepository._results[this._version] = this._normalizeEmoji(cdnResult);
|
|
62
|
+
}
|
|
63
|
+
const items = this._getItems();
|
|
64
|
+
// Skip plugin initialization if the emoji repository is not available.
|
|
65
|
+
// The initialization of other dependent plugins, such as `EmojiMention` and `EmojiPicker`, is prevented as well.
|
|
66
|
+
if (!items) {
|
|
67
|
+
return this._repositoryPromiseResolveCallback(false);
|
|
68
68
|
}
|
|
69
|
-
const container = createEmojiWidthTestingContainer();
|
|
70
|
-
// Store the emoji database after normalizing the raw data.
|
|
71
|
-
this._database = emojiDatabase
|
|
72
|
-
.filter(item => isEmojiCategoryAllowed(item))
|
|
73
|
-
.filter(item => EmojiRepository._isEmojiSupported(item, container))
|
|
74
|
-
.map(item => normalizeEmojiSkinTone(item));
|
|
75
|
-
container.remove();
|
|
76
69
|
// Create instance of the Fuse.js library with configured weighted search keys and disabled fuzzy search.
|
|
77
|
-
this._fuseSearch = new Fuse(
|
|
70
|
+
this._fuseSearch = new Fuse(items, {
|
|
78
71
|
keys: [
|
|
79
72
|
{ name: 'emoticon', weight: 5 },
|
|
80
73
|
{ name: 'annotation', weight: 3 },
|
|
@@ -84,11 +77,11 @@ class EmojiRepository extends Plugin {
|
|
|
84
77
|
threshold: 0,
|
|
85
78
|
ignoreLocation: true
|
|
86
79
|
});
|
|
87
|
-
return this.
|
|
80
|
+
return this._repositoryPromiseResolveCallback(true);
|
|
88
81
|
}
|
|
89
82
|
/**
|
|
90
83
|
* Returns an array of emoji entries that match the search query.
|
|
91
|
-
* If the emoji
|
|
84
|
+
* If the emoji repository is not loaded, the [Fuse.js](https://www.fusejs.io/) instance is not created,
|
|
92
85
|
* hence this method returns an empty array.
|
|
93
86
|
*
|
|
94
87
|
* @param searchQuery A search query to match emoji.
|
|
@@ -122,12 +115,13 @@ class EmojiRepository extends Plugin {
|
|
|
122
115
|
}
|
|
123
116
|
/**
|
|
124
117
|
* Groups all emojis by categories.
|
|
125
|
-
* If the emoji
|
|
118
|
+
* If the emoji repository is not loaded, it returns an empty array.
|
|
126
119
|
*
|
|
127
120
|
* @returns An array of emoji entries grouped by categories.
|
|
128
121
|
*/
|
|
129
122
|
getEmojiCategories() {
|
|
130
|
-
|
|
123
|
+
const repository = this._getItems();
|
|
124
|
+
if (!repository) {
|
|
131
125
|
return [];
|
|
132
126
|
}
|
|
133
127
|
const { t } = this.editor.locale;
|
|
@@ -142,7 +136,7 @@ class EmojiRepository extends Plugin {
|
|
|
142
136
|
{ title: t('Symbols'), icon: '🟢', groupId: 8 },
|
|
143
137
|
{ title: t('Flags'), icon: '🏁', groupId: 9 }
|
|
144
138
|
];
|
|
145
|
-
const groups = groupBy(
|
|
139
|
+
const groups = groupBy(repository, 'group');
|
|
146
140
|
return categories.map(category => {
|
|
147
141
|
return {
|
|
148
142
|
...category,
|
|
@@ -165,103 +159,69 @@ class EmojiRepository extends Plugin {
|
|
|
165
159
|
];
|
|
166
160
|
}
|
|
167
161
|
/**
|
|
168
|
-
* Indicates whether the emoji
|
|
162
|
+
* Indicates whether the emoji repository has been successfully downloaded and the plugin is operational.
|
|
169
163
|
*/
|
|
170
164
|
isReady() {
|
|
171
|
-
return this.
|
|
165
|
+
return this._repositoryPromise;
|
|
172
166
|
}
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
167
|
+
/**
|
|
168
|
+
* Returns the emoji repository in a configured version if it is a non-empty array. Returns `null` otherwise.
|
|
169
|
+
*/
|
|
170
|
+
_getItems() {
|
|
171
|
+
const repository = EmojiRepository._results[this._version];
|
|
172
|
+
return repository && repository.length ? repository : null;
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Makes the HTTP request to download the emoji repository in a configured version.
|
|
176
|
+
*/
|
|
177
|
+
async _loadItemsFromCdn() {
|
|
178
|
+
const repositoryUrl = new URL(EMOJI_DATABASE_URL.replace('{version}', `${this._version}`));
|
|
179
|
+
repositoryUrl.searchParams.set('editorVersion', version);
|
|
180
|
+
const result = await fetch(repositoryUrl, { cache: 'force-cache' })
|
|
181
|
+
.then(response => {
|
|
182
|
+
if (!response.ok) {
|
|
183
|
+
return [];
|
|
184
|
+
}
|
|
185
|
+
return response.json();
|
|
186
|
+
})
|
|
187
|
+
.catch(() => {
|
|
188
188
|
return [];
|
|
189
|
+
});
|
|
190
|
+
if (!result.length) {
|
|
191
|
+
/**
|
|
192
|
+
* Unable to load the emoji repository from CDN.
|
|
193
|
+
*
|
|
194
|
+
* If the CDN works properly and there is no disruption of communication, please check your
|
|
195
|
+
* {@glink getting-started/setup/csp Content Security Policy (CSP)} setting and make sure
|
|
196
|
+
* the CDN connection is allowed by the editor.
|
|
197
|
+
*
|
|
198
|
+
* @error emoji-repository-load-failed
|
|
199
|
+
*/
|
|
200
|
+
logWarning('emoji-repository-load-failed');
|
|
189
201
|
}
|
|
190
|
-
return
|
|
191
|
-
})
|
|
192
|
-
.catch(() => {
|
|
193
|
-
return [];
|
|
194
|
-
});
|
|
195
|
-
if (!result.length) {
|
|
196
|
-
/**
|
|
197
|
-
* Unable to load the emoji database from CDN.
|
|
198
|
-
*
|
|
199
|
-
* TODO: It could be a problem of CKEditor 5 CDN, but also, Content Security Policy that disallow the request.
|
|
200
|
-
* It would be good to explain what to do in such a case.
|
|
201
|
-
*
|
|
202
|
-
* @error emoji-database-load-failed
|
|
203
|
-
*/
|
|
204
|
-
logWarning('emoji-database-load-failed');
|
|
202
|
+
return result;
|
|
205
203
|
}
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
*/
|
|
224
|
-
function getNodeWidth(container, node) {
|
|
225
|
-
const span = document.createElement('span');
|
|
226
|
-
span.textContent = node;
|
|
227
|
-
container.appendChild(span);
|
|
228
|
-
const nodeWidth = span.offsetWidth;
|
|
229
|
-
container.removeChild(span);
|
|
230
|
-
return nodeWidth;
|
|
231
|
-
}
|
|
232
|
-
/**
|
|
233
|
-
* Checks whether the emoji is supported in the operating system.
|
|
234
|
-
*/
|
|
235
|
-
function isEmojiSupported(item, container) {
|
|
236
|
-
const emojiWidth = getNodeWidth(container, item.emoji);
|
|
237
|
-
// On Windows, some supported emoji are ~50% bigger than the baseline emoji, but what we really want to guard
|
|
238
|
-
// against are the ones that are 2x the size, because those are truly broken (person with red hair = person with
|
|
239
|
-
// floating red wig, black cat = cat with black square, polar bear = bear with snowflake, etc.)
|
|
240
|
-
// So here we set the threshold at 1.8 times the size of the baseline emoji.
|
|
241
|
-
return (emojiWidth / 1.8 < BASELINE_EMOJI_WIDTH) && (emojiWidth >= BASELINE_EMOJI_WIDTH);
|
|
242
|
-
}
|
|
243
|
-
/**
|
|
244
|
-
* Adds default skin tone property to each emoji. If emoji defines other skin tones, they are added as well.
|
|
245
|
-
*/
|
|
246
|
-
function normalizeEmojiSkinTone(item) {
|
|
247
|
-
const entry = {
|
|
248
|
-
...item,
|
|
249
|
-
skins: {
|
|
250
|
-
default: item.emoji
|
|
251
|
-
}
|
|
252
|
-
};
|
|
253
|
-
if (item.skins) {
|
|
254
|
-
item.skins.forEach(skin => {
|
|
255
|
-
const skinTone = SKIN_TONE_MAP[skin.tone];
|
|
256
|
-
entry.skins[skinTone] = skin.emoji;
|
|
257
|
-
});
|
|
204
|
+
/**
|
|
205
|
+
* Normalizes the raw data fetched from CDN. By normalization, we meant:
|
|
206
|
+
*
|
|
207
|
+
* * Filter out unsupported emoji (these that will not render correctly),
|
|
208
|
+
* * Prepare skin tone variants if an emoji defines them.
|
|
209
|
+
*/
|
|
210
|
+
_normalizeEmoji(data) {
|
|
211
|
+
const emojiUtils = this.editor.plugins.get('EmojiUtils');
|
|
212
|
+
const emojiSupportedVersionByOs = emojiUtils.getEmojiSupportedVersionByOs();
|
|
213
|
+
const container = emojiUtils.createEmojiWidthTestingContainer();
|
|
214
|
+
document.body.appendChild(container);
|
|
215
|
+
const results = data
|
|
216
|
+
.filter(item => emojiUtils.isEmojiCategoryAllowed(item))
|
|
217
|
+
.filter(item => emojiUtils.isEmojiSupported(item, emojiSupportedVersionByOs, container))
|
|
218
|
+
.map(item => emojiUtils.normalizeEmojiSkinTone(item));
|
|
219
|
+
container.remove();
|
|
220
|
+
return results;
|
|
258
221
|
}
|
|
259
|
-
return entry;
|
|
260
222
|
}
|
|
261
223
|
/**
|
|
262
|
-
*
|
|
224
|
+
* Versioned emoji repository.
|
|
263
225
|
*/
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
return item.group !== 2;
|
|
267
|
-
}
|
|
226
|
+
EmojiRepository._results = {};
|
|
227
|
+
export default EmojiRepository;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2025, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
|
|
4
|
+
*/
|
|
5
|
+
import { Plugin } from 'ckeditor5/src/core.js';
|
|
6
|
+
import type { EmojiCdnResource, EmojiEntry } from './emojirepository.js';
|
|
7
|
+
/**
|
|
8
|
+
* The Emoji utilities plugin.
|
|
9
|
+
*/
|
|
10
|
+
export default class EmojiUtils extends Plugin {
|
|
11
|
+
/**
|
|
12
|
+
* @inheritDoc
|
|
13
|
+
*/
|
|
14
|
+
static get pluginName(): "EmojiUtils";
|
|
15
|
+
/**
|
|
16
|
+
* @inheritDoc
|
|
17
|
+
*/
|
|
18
|
+
static get isOfficialPlugin(): true;
|
|
19
|
+
/**
|
|
20
|
+
* Checks if the emoji is supported by verifying the emoji version supported by the system first.
|
|
21
|
+
* Then checks if emoji contains a zero width joiner (ZWJ), and if yes, then checks if it is supported by the system.
|
|
22
|
+
*/
|
|
23
|
+
isEmojiSupported(item: EmojiCdnResource, emojiSupportedVersionByOs: number, container: HTMLDivElement): boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Checks the supported emoji version by the OS, by sampling some representatives from different emoji releases.
|
|
26
|
+
*/
|
|
27
|
+
getEmojiSupportedVersionByOs(): number;
|
|
28
|
+
/**
|
|
29
|
+
* Check for ZWJ (zero width joiner) character.
|
|
30
|
+
*/
|
|
31
|
+
hasZwj(emoji: string): boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Checks whether the emoji is supported in the operating system.
|
|
34
|
+
*/
|
|
35
|
+
isEmojiZwjSupported(item: EmojiCdnResource, container: HTMLDivElement): boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Returns the width of the provided node.
|
|
38
|
+
*/
|
|
39
|
+
getNodeWidth(container: HTMLDivElement, node: string): number;
|
|
40
|
+
/**
|
|
41
|
+
* Creates a div for emoji width testing purposes.
|
|
42
|
+
*/
|
|
43
|
+
createEmojiWidthTestingContainer(): HTMLDivElement;
|
|
44
|
+
/**
|
|
45
|
+
* Adds default skin tone property to each emoji. If emoji defines other skin tones, they are added as well.
|
|
46
|
+
*/
|
|
47
|
+
normalizeEmojiSkinTone(item: EmojiCdnResource): EmojiEntry;
|
|
48
|
+
/**
|
|
49
|
+
* Checks whether the emoji belongs to a group that is allowed.
|
|
50
|
+
*/
|
|
51
|
+
isEmojiCategoryAllowed(item: EmojiCdnResource): boolean;
|
|
52
|
+
/**
|
|
53
|
+
* A function used to determine if emoji is supported by detecting pixels.
|
|
54
|
+
*
|
|
55
|
+
* Referenced for unit testing purposes. Kept in a separate file because of licensing.
|
|
56
|
+
*/
|
|
57
|
+
private static _isEmojiSupported;
|
|
58
|
+
}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2025, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
|
|
4
|
+
*/
|
|
5
|
+
import { Plugin } from 'ckeditor5/src/core.js';
|
|
6
|
+
import isEmojiSupported from './utils/isemojisupported.js';
|
|
7
|
+
/**
|
|
8
|
+
* @module emoji/emojiutils
|
|
9
|
+
*/
|
|
10
|
+
const SKIN_TONE_MAP = {
|
|
11
|
+
0: 'default',
|
|
12
|
+
1: 'light',
|
|
13
|
+
2: 'medium-light',
|
|
14
|
+
3: 'medium',
|
|
15
|
+
4: 'medium-dark',
|
|
16
|
+
5: 'dark'
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* A map representing an emoji and its release version.
|
|
20
|
+
* It's used to identify a user's minimal supported emoji level.
|
|
21
|
+
*/
|
|
22
|
+
const EMOJI_SUPPORT_LEVEL = {
|
|
23
|
+
'': 16,
|
|
24
|
+
'🫨': 15.1 // Shaking head. Although the version of emoji is 15, it is used to detect versions 15 and 15.1.
|
|
25
|
+
};
|
|
26
|
+
const BASELINE_EMOJI_WIDTH = 24;
|
|
27
|
+
/**
|
|
28
|
+
* The Emoji utilities plugin.
|
|
29
|
+
*/
|
|
30
|
+
class EmojiUtils extends Plugin {
|
|
31
|
+
/**
|
|
32
|
+
* @inheritDoc
|
|
33
|
+
*/
|
|
34
|
+
static get pluginName() {
|
|
35
|
+
return 'EmojiUtils';
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* @inheritDoc
|
|
39
|
+
*/
|
|
40
|
+
static get isOfficialPlugin() {
|
|
41
|
+
return true;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Checks if the emoji is supported by verifying the emoji version supported by the system first.
|
|
45
|
+
* Then checks if emoji contains a zero width joiner (ZWJ), and if yes, then checks if it is supported by the system.
|
|
46
|
+
*/
|
|
47
|
+
isEmojiSupported(item, emojiSupportedVersionByOs, container) {
|
|
48
|
+
const isEmojiVersionSupported = item.version <= emojiSupportedVersionByOs;
|
|
49
|
+
if (!isEmojiVersionSupported) {
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
if (!this.hasZwj(item.emoji)) {
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
55
|
+
return this.isEmojiZwjSupported(item, container);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Checks the supported emoji version by the OS, by sampling some representatives from different emoji releases.
|
|
59
|
+
*/
|
|
60
|
+
getEmojiSupportedVersionByOs() {
|
|
61
|
+
return Object.entries(EMOJI_SUPPORT_LEVEL)
|
|
62
|
+
.reduce((currentVersion, [emoji, newVersion]) => {
|
|
63
|
+
if (newVersion > currentVersion && EmojiUtils._isEmojiSupported(emoji)) {
|
|
64
|
+
return newVersion;
|
|
65
|
+
}
|
|
66
|
+
return currentVersion;
|
|
67
|
+
}, 0);
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Check for ZWJ (zero width joiner) character.
|
|
71
|
+
*/
|
|
72
|
+
hasZwj(emoji) {
|
|
73
|
+
return emoji.includes('\u200d');
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Checks whether the emoji is supported in the operating system.
|
|
77
|
+
*/
|
|
78
|
+
isEmojiZwjSupported(item, container) {
|
|
79
|
+
const emojiWidth = this.getNodeWidth(container, item.emoji);
|
|
80
|
+
// On Windows, some supported emoji are ~50% bigger than the baseline emoji, but what we really want to guard
|
|
81
|
+
// against are the ones that are 2x the size, because those are truly broken (person with red hair = person with
|
|
82
|
+
// floating red wig, black cat = cat with black square, polar bear = bear with snowflake, etc.)
|
|
83
|
+
// So here we set the threshold at 1.8 times the size of the baseline emoji.
|
|
84
|
+
return emojiWidth < BASELINE_EMOJI_WIDTH * 1.8;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Returns the width of the provided node.
|
|
88
|
+
*/
|
|
89
|
+
getNodeWidth(container, node) {
|
|
90
|
+
const span = document.createElement('span');
|
|
91
|
+
span.textContent = node;
|
|
92
|
+
container.appendChild(span);
|
|
93
|
+
const nodeWidth = span.offsetWidth;
|
|
94
|
+
container.removeChild(span);
|
|
95
|
+
return nodeWidth;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Creates a div for emoji width testing purposes.
|
|
99
|
+
*/
|
|
100
|
+
createEmojiWidthTestingContainer() {
|
|
101
|
+
const container = document.createElement('div');
|
|
102
|
+
container.setAttribute('aria-hidden', 'true');
|
|
103
|
+
container.style.position = 'absolute';
|
|
104
|
+
container.style.left = '-9999px';
|
|
105
|
+
container.style.whiteSpace = 'nowrap';
|
|
106
|
+
container.style.fontSize = BASELINE_EMOJI_WIDTH + 'px';
|
|
107
|
+
return container;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Adds default skin tone property to each emoji. If emoji defines other skin tones, they are added as well.
|
|
111
|
+
*/
|
|
112
|
+
normalizeEmojiSkinTone(item) {
|
|
113
|
+
const entry = {
|
|
114
|
+
...item,
|
|
115
|
+
skins: {
|
|
116
|
+
default: item.emoji
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
if (item.skins) {
|
|
120
|
+
item.skins.forEach(skin => {
|
|
121
|
+
const skinTone = SKIN_TONE_MAP[skin.tone];
|
|
122
|
+
entry.skins[skinTone] = skin.emoji;
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
return entry;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Checks whether the emoji belongs to a group that is allowed.
|
|
129
|
+
*/
|
|
130
|
+
isEmojiCategoryAllowed(item) {
|
|
131
|
+
// Category group=2 contains skin tones only, which we do not want to render.
|
|
132
|
+
return item.group !== 2;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* A function used to determine if emoji is supported by detecting pixels.
|
|
137
|
+
*
|
|
138
|
+
* Referenced for unit testing purposes. Kept in a separate file because of licensing.
|
|
139
|
+
*/
|
|
140
|
+
EmojiUtils._isEmojiSupported = isEmojiSupported;
|
|
141
|
+
export default EmojiUtils;
|
package/src/index.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ export { default as Emoji } from './emoji.js';
|
|
|
9
9
|
export { default as EmojiMention } from './emojimention.js';
|
|
10
10
|
export { default as EmojiPicker } from './emojipicker.js';
|
|
11
11
|
export { default as EmojiRepository } from './emojirepository.js';
|
|
12
|
+
export { default as EmojiUtils } from './emojiutils.js';
|
|
12
13
|
export { default as EmojiCommand } from './emojicommand.js';
|
|
13
14
|
export type { EmojiConfig } from './emojiconfig.js';
|
|
14
15
|
import './augmentation.js';
|
package/src/index.js
CHANGED
|
@@ -9,5 +9,6 @@ export { default as Emoji } from './emoji.js';
|
|
|
9
9
|
export { default as EmojiMention } from './emojimention.js';
|
|
10
10
|
export { default as EmojiPicker } from './emojipicker.js';
|
|
11
11
|
export { default as EmojiRepository } from './emojirepository.js';
|
|
12
|
+
export { default as EmojiUtils } from './emojiutils.js';
|
|
12
13
|
export { default as EmojiCommand } from './emojicommand.js';
|
|
13
14
|
import './augmentation.js';
|
|
@@ -156,6 +156,7 @@ export default class EmojiPickerView extends View {
|
|
|
156
156
|
// Emit an update event to react to balloon dimensions changes.
|
|
157
157
|
this.searchView.on('search', () => {
|
|
158
158
|
this.fire('update');
|
|
159
|
+
this.gridView.element.scrollTo(0, 0);
|
|
159
160
|
});
|
|
160
161
|
// Update the grid of emojis when the selected category is changed.
|
|
161
162
|
this.categoriesView.on('change:categoryName', (ev, args, categoryName) => {
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2023, Koala Interactive SAS
|
|
3
|
+
* For licensing, see https://github.com/koala-interactive/is-emoji-supported/blob/master/LICENSE.md
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* @module emoji/utils/isemojisupported
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Checks if the two pixels parts are the same using canvas.
|
|
10
|
+
*/
|
|
11
|
+
export default function isEmojiSupported(unicode: string): boolean;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2023, Koala Interactive SAS
|
|
3
|
+
* For licensing, see https://github.com/koala-interactive/is-emoji-supported/blob/master/LICENSE.md
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* @module emoji/utils/isemojisupported
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Checks if the two pixels parts are the same using canvas.
|
|
10
|
+
*/
|
|
11
|
+
export default function isEmojiSupported(unicode) {
|
|
12
|
+
const ctx = getCanvas();
|
|
13
|
+
/* istanbul ignore next -- @preserve */
|
|
14
|
+
if (!ctx) {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
const CANVAS_HEIGHT = 25;
|
|
18
|
+
const CANVAS_WIDTH = 20;
|
|
19
|
+
const textSize = Math.floor(CANVAS_HEIGHT / 2);
|
|
20
|
+
// Initialize canvas context.
|
|
21
|
+
ctx.font = textSize + 'px Arial, Sans-Serif';
|
|
22
|
+
ctx.textBaseline = 'top';
|
|
23
|
+
ctx.canvas.width = CANVAS_WIDTH * 2;
|
|
24
|
+
ctx.canvas.height = CANVAS_HEIGHT;
|
|
25
|
+
ctx.clearRect(0, 0, CANVAS_WIDTH * 2, CANVAS_HEIGHT);
|
|
26
|
+
// Draw in red on the left.
|
|
27
|
+
ctx.fillStyle = '#FF0000';
|
|
28
|
+
ctx.fillText(unicode, 0, 22);
|
|
29
|
+
// Draw in blue on right.
|
|
30
|
+
ctx.fillStyle = '#0000FF';
|
|
31
|
+
ctx.fillText(unicode, CANVAS_WIDTH, 22);
|
|
32
|
+
const a = ctx.getImageData(0, 0, CANVAS_WIDTH, CANVAS_HEIGHT).data;
|
|
33
|
+
const count = a.length;
|
|
34
|
+
let i = 0;
|
|
35
|
+
// Search the first visible pixel.
|
|
36
|
+
for (; i < count && !a[i + 3]; i += 4)
|
|
37
|
+
;
|
|
38
|
+
// No visible pixel.
|
|
39
|
+
/* istanbul ignore next -- @preserve */
|
|
40
|
+
if (i >= count) {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
// Emoji has immutable color, so we check the color of the emoji in two different colors.
|
|
44
|
+
// the result show be the same.
|
|
45
|
+
const x = CANVAS_WIDTH + ((i / 4) % CANVAS_WIDTH);
|
|
46
|
+
const y = Math.floor(i / 4 / CANVAS_WIDTH);
|
|
47
|
+
const b = ctx.getImageData(x, y, 1, 1).data;
|
|
48
|
+
if (a[i] !== b[0] || a[i + 2] !== b[2]) {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
//Some emojis consist of different ones, so they will show multiple characters if they are not supported.
|
|
52
|
+
/* istanbul ignore next -- @preserve */
|
|
53
|
+
if (ctx.measureText(unicode).width >= CANVAS_WIDTH) {
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
// Supported.
|
|
57
|
+
return true;
|
|
58
|
+
}
|
|
59
|
+
;
|
|
60
|
+
function getCanvas() {
|
|
61
|
+
try {
|
|
62
|
+
return document.createElement('canvas').getContext('2d', { willReadFrequently: true });
|
|
63
|
+
}
|
|
64
|
+
catch {
|
|
65
|
+
/* istanbul ignore next -- @preserve */
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
}
|