-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Fixed emoji filtering and improved the filtering performance. #17864
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
a421188
Fixed emoji filtering and improved the filtering performance.
martnpaneq c858510
Wording.
martnpaneq cac496e
Modified `EMOJI_SUPPORT_LEVEL` to properly filter emojis in version 1…
martnpaneq 7343da3
Introduced `EmojiUtils` class in emoji picker.
martnpaneq 8533e60
Wording.
martnpaneq c72fb15
Removed "substitutePlugins" from tests.
pomek 4f46e7b
Merge branch 'release' into ck/17834-fix-emoji-filtering
pomek 6e5549e
Minor changes.
pomek 1d88927
Fixed license.
pomek File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| /** | ||
| * @license Copyright (c) 2023, Koala Interactive SAS | ||
| * For licensing, see https://github.com/koala-interactive/is-emoji-supported/blob/master/LICENSE.md | ||
| */ | ||
|
|
||
| /** | ||
| * Checks if the two pixels parts are the same using canvas. | ||
| */ | ||
| export default function isEmojiSupported( unicode: string ): boolean { | ||
| const ctx = getCanvas(); | ||
|
|
||
| /* istanbul ignore next -- @preserve */ | ||
| if ( !ctx ) { | ||
| return false; | ||
| } | ||
|
|
||
| const CANVAS_HEIGHT = 25; | ||
| const CANVAS_WIDTH = 20; | ||
| const textSize = Math.floor( CANVAS_HEIGHT / 2 ); | ||
|
|
||
| // Initialize canvas context. | ||
| ctx.font = textSize + 'px Arial, Sans-Serif'; | ||
| ctx.textBaseline = 'top'; | ||
| ctx.canvas.width = CANVAS_WIDTH * 2; | ||
| ctx.canvas.height = CANVAS_HEIGHT; | ||
|
|
||
| ctx.clearRect( 0, 0, CANVAS_WIDTH * 2, CANVAS_HEIGHT ); | ||
|
|
||
| // Draw in red on the left. | ||
| ctx.fillStyle = '#FF0000'; | ||
| ctx.fillText( unicode, 0, 22 ); | ||
|
|
||
| // Draw in blue on right. | ||
| ctx.fillStyle = '#0000FF'; | ||
| ctx.fillText( unicode, CANVAS_WIDTH, 22 ); | ||
|
|
||
| const a = ctx.getImageData( 0, 0, CANVAS_WIDTH, CANVAS_HEIGHT ).data; | ||
| const count = a.length; | ||
| let i = 0; | ||
|
|
||
| // Search the first visible pixel. | ||
| for ( ; i < count && !a[ i + 3 ]; i += 4 ) ; | ||
martnpaneq marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| // No visible pixel. | ||
| /* istanbul ignore next -- @preserve */ | ||
| if ( i >= count ) { | ||
| return false; | ||
| } | ||
|
|
||
| // Emoji has immutable color, so we check the color of the emoji in two different colors. | ||
| // the result show be the same. | ||
| const x = CANVAS_WIDTH + ( ( i / 4 ) % CANVAS_WIDTH ); | ||
| const y = Math.floor( i / 4 / CANVAS_WIDTH ); | ||
| const b = ctx.getImageData( x, y, 1, 1 ).data; | ||
|
|
||
| if ( a[ i ] !== b[ 0 ] || a[ i + 2 ] !== b[ 2 ]) { | ||
| return false; | ||
| } | ||
|
|
||
| // Some emojis are a contraction of different ones, so if it's not supported, it will show multiple characters. | ||
martnpaneq marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| /* istanbul ignore next -- @preserve */ | ||
| if ( ctx.measureText( unicode ).width >= CANVAS_WIDTH ) { | ||
| return false; | ||
| } | ||
|
|
||
| // Supported. | ||
| return true; | ||
| }; | ||
|
|
||
| function getCanvas(): CanvasRenderingContext2D | null { | ||
| try { | ||
| return document.createElement( 'canvas' ).getContext( '2d' ); | ||
| } catch { | ||
| /* istanbul ignore next -- @preserve */ | ||
| return null; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.