@ckeditor/ckeditor5-emoji 46.0.0 → 46.0.1-alpha.0
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/build/emoji.js +1 -1
- package/dist/index.js +31 -2
- package/dist/index.js.map +1 -1
- package/package.json +8 -8
- package/src/emojiutils.d.ts +14 -0
- package/src/emojiutils.js +34 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ckeditor/ckeditor5-emoji",
|
|
3
|
-
"version": "46.0.0",
|
|
3
|
+
"version": "46.0.1-alpha.0",
|
|
4
4
|
"description": "Emoji feature for CKEditor 5.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ckeditor",
|
|
@@ -13,13 +13,13 @@
|
|
|
13
13
|
"type": "module",
|
|
14
14
|
"main": "src/index.js",
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@ckeditor/ckeditor5-core": "46.0.0",
|
|
17
|
-
"@ckeditor/ckeditor5-icons": "46.0.0",
|
|
18
|
-
"@ckeditor/ckeditor5-mention": "46.0.0",
|
|
19
|
-
"@ckeditor/ckeditor5-typing": "46.0.0",
|
|
20
|
-
"@ckeditor/ckeditor5-ui": "46.0.0",
|
|
21
|
-
"@ckeditor/ckeditor5-utils": "46.0.0",
|
|
22
|
-
"ckeditor5": "46.0.0",
|
|
16
|
+
"@ckeditor/ckeditor5-core": "46.0.1-alpha.0",
|
|
17
|
+
"@ckeditor/ckeditor5-icons": "46.0.1-alpha.0",
|
|
18
|
+
"@ckeditor/ckeditor5-mention": "46.0.1-alpha.0",
|
|
19
|
+
"@ckeditor/ckeditor5-typing": "46.0.1-alpha.0",
|
|
20
|
+
"@ckeditor/ckeditor5-ui": "46.0.1-alpha.0",
|
|
21
|
+
"@ckeditor/ckeditor5-utils": "46.0.1-alpha.0",
|
|
22
|
+
"ckeditor5": "46.0.1-alpha.0",
|
|
23
23
|
"fuzzysort": "3.1.0",
|
|
24
24
|
"es-toolkit": "1.39.5"
|
|
25
25
|
},
|
package/src/emojiutils.d.ts
CHANGED
|
@@ -8,6 +8,10 @@ import type { EmojiCdnResource, EmojiEntry } from './emojirepository.js';
|
|
|
8
8
|
* The Emoji utilities plugin.
|
|
9
9
|
*/
|
|
10
10
|
export declare class EmojiUtils extends Plugin {
|
|
11
|
+
/**
|
|
12
|
+
* Used for testing whether the environment supports the given emoji.
|
|
13
|
+
*/
|
|
14
|
+
private _emojiCanvas;
|
|
11
15
|
/**
|
|
12
16
|
* @inheritDoc
|
|
13
17
|
*/
|
|
@@ -16,6 +20,10 @@ export declare class EmojiUtils extends Plugin {
|
|
|
16
20
|
* @inheritDoc
|
|
17
21
|
*/
|
|
18
22
|
static get isOfficialPlugin(): true;
|
|
23
|
+
/**
|
|
24
|
+
* @inheritDoc
|
|
25
|
+
*/
|
|
26
|
+
init(): void;
|
|
19
27
|
/**
|
|
20
28
|
* Checks if the emoji is supported by verifying the emoji version supported by the system first.
|
|
21
29
|
* Then checks if emoji contains a zero width joiner (ZWJ), and if yes, then checks if it is supported by the system.
|
|
@@ -37,6 +45,12 @@ export declare class EmojiUtils extends Plugin {
|
|
|
37
45
|
* Returns the width of the provided node.
|
|
38
46
|
*/
|
|
39
47
|
getNodeWidth(container: HTMLDivElement, node: string): number;
|
|
48
|
+
/**
|
|
49
|
+
* Returns the width of the provided node.
|
|
50
|
+
*
|
|
51
|
+
* This is a faster alternative to `getNodeWidth` method, which works for great majority of emojis.
|
|
52
|
+
*/
|
|
53
|
+
getNodeWidthUsingCanvas(container: HTMLDivElement, node: string): number;
|
|
40
54
|
/**
|
|
41
55
|
* Creates a div for emoji width testing purposes.
|
|
42
56
|
*/
|
package/src/emojiutils.js
CHANGED
|
@@ -40,6 +40,10 @@ const BASELINE_EMOJI_WIDTH = 24;
|
|
|
40
40
|
* The Emoji utilities plugin.
|
|
41
41
|
*/
|
|
42
42
|
class EmojiUtils extends Plugin {
|
|
43
|
+
/**
|
|
44
|
+
* Used for testing whether the environment supports the given emoji.
|
|
45
|
+
*/
|
|
46
|
+
_emojiCanvas = null;
|
|
43
47
|
/**
|
|
44
48
|
* @inheritDoc
|
|
45
49
|
*/
|
|
@@ -52,6 +56,12 @@ class EmojiUtils extends Plugin {
|
|
|
52
56
|
static get isOfficialPlugin() {
|
|
53
57
|
return true;
|
|
54
58
|
}
|
|
59
|
+
/**
|
|
60
|
+
* @inheritDoc
|
|
61
|
+
*/
|
|
62
|
+
init() {
|
|
63
|
+
this._emojiCanvas = document.createElement('canvas').getContext('2d');
|
|
64
|
+
}
|
|
55
65
|
/**
|
|
56
66
|
* Checks if the emoji is supported by verifying the emoji version supported by the system first.
|
|
57
67
|
* Then checks if emoji contains a zero width joiner (ZWJ), and if yes, then checks if it is supported by the system.
|
|
@@ -87,12 +97,18 @@ class EmojiUtils extends Plugin {
|
|
|
87
97
|
* Checks whether the emoji is supported in the operating system.
|
|
88
98
|
*/
|
|
89
99
|
isEmojiZwjSupported(item, container) {
|
|
90
|
-
const emojiWidth = this.getNodeWidth(container, item.emoji);
|
|
91
100
|
// On Windows, some supported emoji are ~50% bigger than the baseline emoji, but what we really want to guard
|
|
92
101
|
// against are the ones that are 2x the size, because those are truly broken (person with red hair = person with
|
|
93
102
|
// floating red wig, black cat = cat with black square, polar bear = bear with snowflake, etc.)
|
|
94
103
|
// So here we set the threshold at 1.8 times the size of the baseline emoji.
|
|
95
|
-
|
|
104
|
+
const canvasWidth = this.getNodeWidthUsingCanvas(container, item.emoji);
|
|
105
|
+
// Checking emoji using canvas is much faster, so always try it first. Unfortunately canvas has worse emoji coverage.
|
|
106
|
+
if (canvasWidth < BASELINE_EMOJI_WIDTH * 1.8) {
|
|
107
|
+
return true;
|
|
108
|
+
}
|
|
109
|
+
const domWidth = this.getNodeWidth(container, item.emoji);
|
|
110
|
+
// Checking emoji using DOM is much slower, so use it as a fallback.
|
|
111
|
+
return domWidth < BASELINE_EMOJI_WIDTH * 1.8;
|
|
96
112
|
}
|
|
97
113
|
/**
|
|
98
114
|
* Returns the width of the provided node.
|
|
@@ -105,6 +121,22 @@ class EmojiUtils extends Plugin {
|
|
|
105
121
|
container.removeChild(span);
|
|
106
122
|
return nodeWidth;
|
|
107
123
|
}
|
|
124
|
+
/**
|
|
125
|
+
* Returns the width of the provided node.
|
|
126
|
+
*
|
|
127
|
+
* This is a faster alternative to `getNodeWidth` method, which works for great majority of emojis.
|
|
128
|
+
*/
|
|
129
|
+
getNodeWidthUsingCanvas(container, node) {
|
|
130
|
+
const style = getComputedStyle(container);
|
|
131
|
+
this._emojiCanvas.font = [
|
|
132
|
+
style.fontStyle,
|
|
133
|
+
style.fontVariant,
|
|
134
|
+
style.fontWeight,
|
|
135
|
+
`${BASELINE_EMOJI_WIDTH}px`,
|
|
136
|
+
`"Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", ${style.fontFamily}`
|
|
137
|
+
].join(' ');
|
|
138
|
+
return Math.ceil(this._emojiCanvas.measureText(node).width);
|
|
139
|
+
}
|
|
108
140
|
/**
|
|
109
141
|
* Creates a div for emoji width testing purposes.
|
|
110
142
|
*/
|