Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support for custom emoji fonts (#308)
Fixes #82
- Loading branch information
1 parent
af58a92
commit da524c2
Showing
14 changed files
with
258 additions
and
128 deletions.
There are no files selected for viewing
This file contains 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 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 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 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,27 @@ | ||
<!doctype html> | ||
<html lang=en> | ||
<head> | ||
<title>emoji-picker-element: using Twemoji Mozilla COLR font</title> | ||
<style> | ||
@font-face { | ||
font-family: "MozillaTwemojiColr"; | ||
src: url("https://cdn.jsdelivr.net/npm/twemoji-colr-font@^14/twemoji.woff2") format("woff2"); | ||
} | ||
|
||
emoji-picker { | ||
--emoji-font-family: MozillaTwemojiColr; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<h1>emoji-picker-element: using Twemoji Mozilla COLR font</h1> | ||
<p> | ||
This demo shows how to use emoji-picker-element with the <a href="https://github.com/mozilla/twemoji-colr">Twemoji Mozilla COLR font</a> as a custom emoji font. | ||
Note that this carries a performance cost due to downloading the additional font file. Also note that alignment may be off in Safari due to <a href="https://bugs.webkit.org/show_bug.cgi?id=249943">a WebKit bug</a>, and | ||
that <a href="https://caniuse.com/colr">not all browsers support COLR fonts</a>. | ||
Use this approach with care. | ||
</p> | ||
<emoji-picker emoji-version="14.0"></emoji-picker> | ||
<script type="module" src="https://cdn.jsdelivr.net/npm/emoji-picker-element@^1/index.js"></script> | ||
</body> | ||
</html> |
This file was deleted.
Oops, something went wrong.
This file contains 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 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 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 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 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 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 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 |
---|---|---|
@@ -1,18 +1,28 @@ | ||
import { determineEmojiSupportLevel } from './determineEmojiSupportLevel' | ||
import { requestIdleCallback } from './requestIdleCallback' | ||
import { requestIdleCallback } from './requestIdleCallback.js' | ||
|
||
// Check which emojis we know for sure aren't supported, based on Unicode version level | ||
export const emojiSupportLevelPromise = new Promise(resolve => ( | ||
requestIdleCallback(() => ( | ||
resolve(determineEmojiSupportLevel()) // delay so ideally this can run while IDB is first populating | ||
)) | ||
)) | ||
let promise | ||
export const detectEmojiSupportLevel = () => { | ||
if (!promise) { | ||
// Delay so it can run while the IDB database is being created by the browser (on another thread). | ||
// This helps especially with first load – we want to start pre-populating the database on the main thread, | ||
// and then wait for IDB to commit everything, and while waiting we run this check. | ||
promise = new Promise(resolve => ( | ||
requestIdleCallback(() => ( | ||
resolve(determineEmojiSupportLevel()) // delay so ideally this can run while IDB is first populating | ||
)) | ||
)) | ||
|
||
/* istanbul ignore else */ | ||
if (process.env.NODE_ENV !== 'production') { | ||
promise.then(emojiSupportLevel => { | ||
console.log('emoji support level', emojiSupportLevel) | ||
}) | ||
} | ||
} | ||
return promise | ||
} | ||
// determine which emojis containing ZWJ (zero width joiner) characters | ||
// are supported (rendered as one glyph) rather than unsupported (rendered as two or more glyphs) | ||
export const supportedZwjEmojis = new Map() | ||
|
||
/* istanbul ignore else */ | ||
if (process.env.NODE_ENV !== 'production') { | ||
emojiSupportLevelPromise.then(emojiSupportLevel => { | ||
console.log('emoji support level', emojiSupportLevel) | ||
}) | ||
} |
Oops, something went wrong.