One emoji image set for picker, composition, message bubble

This commit is contained in:
Ken Powers
2019-07-25 12:28:44 -04:00
committed by Scott Nonnenberg
parent 464361b2eb
commit 6c0365a770
10 changed files with 84 additions and 201 deletions

View File

@@ -1,106 +0,0 @@
// @ts-ignore
import EmojiConvertor from 'emoji-js';
const instance = new EmojiConvertor();
instance.init_unified();
instance.init_colons();
instance.img_sets.apple.path =
'node_modules/emoji-datasource-apple/img/apple/64/';
instance.include_title = true;
instance.replace_mode = 'img';
instance.supports_css = false; // needed to avoid spans with background-image
export type SizeClassType = '' | 'small' | 'medium' | 'large' | 'jumbo';
export function getRegex(): RegExp {
return instance.rx_unified;
}
export function getTitle(value: string): string | undefined {
return instance.data[value][3][0];
}
export function findImage(value: string, variation?: string) {
return instance.find_image(value, variation);
}
function getCountOfAllMatches(str: string, regex: RegExp) {
let match = regex.exec(str);
let count = 0;
if (!regex.global) {
return match ? 1 : 0;
}
while (match) {
count += 1;
match = regex.exec(str);
}
return count;
}
function hasNormalCharacters(str: string) {
const noEmoji = str.replace(instance.rx_unified, '').trim();
return noEmoji.length > 0;
}
export function getSizeClass(str: string): SizeClassType {
if (hasNormalCharacters(str)) {
return '';
}
const emojiCount = getCountOfAllMatches(str, instance.rx_unified);
if (emojiCount > 8) {
return '';
} else if (emojiCount > 6) {
return 'small';
} else if (emojiCount > 4) {
return 'medium';
} else if (emojiCount > 2) {
return 'large';
} else {
return 'jumbo';
}
}
const VARIATION_LOOKUP: { [index: string]: string } = {
'\uD83C\uDFFB': '1f3fb',
'\uD83C\uDFFC': '1f3fc',
'\uD83C\uDFFD': '1f3fd',
'\uD83C\uDFFE': '1f3fe',
'\uD83C\uDFFF': '1f3ff',
};
// Taken from emoji-js/replace_unified
export function getReplacementData(
m: string,
p1: string | undefined,
p2: string | undefined
): string | { value: string; variation?: string } {
const unified = instance.map.unified[p1];
if (unified) {
const variation = VARIATION_LOOKUP[p2 || ''];
if (variation) {
return {
value: unified,
variation,
};
}
return {
value: unified,
};
}
const unifiedVars = instance.map.unified_vars[p1];
if (unifiedVars) {
return {
value: unifiedVars[0],
variation: unifiedVars[1],
};
}
return m;
}

View File

@@ -231,7 +231,7 @@
"rule": "jQuery-load(",
"path": "js/modules/emojis.js",
"line": "async function load() {",
"lineNumber": 17,
"lineNumber": 13,
"reasonCategory": "falseMatch",
"updated": "2019-05-23T22:27:53.554Z"
},
@@ -3549,24 +3549,6 @@
"reasonCategory": "otherUtilityCode",
"updated": "2019-04-03T00:52:04.925Z"
},
{
"rule": "jQuery-$(",
"path": "node_modules/emoji-js/lib/jquery.emoji.js",
"line": "\t\t$(this).html(function (i, oldHtml){",
"lineNumber": 5,
"reasonCategory": "usageTrusted",
"updated": "2018-09-19T21:59:32.770Z",
"reasonDetail": "Protected from arbitrary input"
},
{
"rule": "jQuery-html(",
"path": "node_modules/emoji-js/lib/jquery.emoji.js",
"line": "\t\t$(this).html(function (i, oldHtml){",
"lineNumber": 5,
"reasonCategory": "usageTrusted",
"updated": "2018-09-18T19:19:27.699Z",
"reasonDetail": "It's setting the html of the element to the previous HTML, just with the emoji replaced"
},
{
"rule": "thenify-multiArgs",
"path": "node_modules/es6-promisify/dist/promisify.js",
@@ -7904,4 +7886,4 @@
"reasonCategory": "falseMatch",
"updated": "2019-05-02T20:44:56.470Z"
}
]
]