@ckeditor/ckeditor5-emoji 44.2.0-alpha.6 → 44.2.0-alpha.8
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/ckeditor5-metadata.json +8 -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 +211 -91
- package/dist/index.js.map +1 -1
- package/package.json +7 -7
- package/src/augmentation.d.ts +2 -1
- package/src/emojimention.d.ts +3 -2
- package/src/emojimention.js +8 -8
- package/src/emojipicker.d.ts +3 -3
- package/src/emojipicker.js +14 -14
- package/src/emojirepository.d.ts +13 -14
- package/src/emojirepository.js +15 -81
- 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/utils/isemojisupported.d.ts +11 -0
- package/src/utils/isemojisupported.js +68 -0
- package/theme/emojigrid.css +1 -1
|
@@ -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');
|
|
63
|
+
}
|
|
64
|
+
catch {
|
|
65
|
+
/* istanbul ignore next -- @preserve */
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
}
|