2020-11-22 01:54:59 +03:00
|
|
|
/*! Copyright Twitter Inc. and other contributors. Licensed under MIT */
|
|
|
|
/*
|
|
|
|
https://github.com/twitter/twemoji/blob/gh-pages/LICENSE
|
2020-08-13 23:32:35 +03:00
|
|
|
|
2020-11-22 01:54:59 +03:00
|
|
|
Stripped down for usage in Fernschreiber.
|
|
|
|
*/
|
|
|
|
.pragma library
|
2020-08-13 23:32:35 +03:00
|
|
|
|
2020-11-22 01:54:59 +03:00
|
|
|
// RegExp based on emoji's official Unicode standards
|
|
|
|
// http://www.unicode.org/Public/UNIDATA/EmojiSources.txt
|
|
|
|
var re = /(?:\ud83d\udc68\ud83c\udffb\u200d\ud83e\udd1d\u200d\ud83d\udc68\ud83c[\udffc-\udfff]|\ud83d\udc68\ud83c\udffc\u200d\ud83e\udd1d\u200d\ud83d\udc68\ud83c[\udffb\udffd-\udfff]|\ud83d\udc68\ud83c\udffd\u200d\ud83e\udd1d\u200d\ud83d\udc68\ud83c[\udffb\udffc\udffe\udfff]|\ud83d\udc68\ud83c\udffe\u200d\ud83e\udd1d\u200d\ud83d\udc68\ud83c[\udffb-\udffd\udfff]|\ud83d\udc68\ud83c\udfff\u200d\ud83e\udd1d\u200d\ud83d\udc68\ud83c[\udffb-\udffe]|\ud83d\udc69\ud83c\udffb\u200d\ud83e\udd1d\u200d\ud83d\udc68\ud83c[\udffc-\udfff]|\ud83d\udc69\ud83c\udffb\u200d\ud83e\udd1d\u200d\ud83d\udc69\ud83c[\udffc-\udfff]|\ud83d\udc69\ud83c\udffc\u200d\ud83e\udd1d\u200d\ud83d\udc68\ud83c[\udffb\udffd-\udfff]|\ud83d\udc69\ud83c\udffc\u200d\ud83e\udd1d\u200d\ud83d\udc69\ud83c[\udffb\udffd-\udfff]|\ud83d\udc69\ud83c\udffd\u200d\ud83e\udd1d\u200d\ud83d\udc68\ud83c[\udffb\udffc\udffe\udfff]|\ud83d\udc69\ud83c\udffd\u200d\ud83e\udd1d\u200d\ud83d\udc69\ud83c[\udffb\udffc\udffe\udfff]|\ud83d\udc69\ud83c\udffe\u200d\ud83e\udd1d\u200d\ud83d\udc68\ud83c[\udffb-\udffd\udfff]|\ud83d\udc69\ud83c\udffe\u200d\ud83e\udd1d\u200d\ud83d\udc69\ud83c[\udffb-\udffd\udfff]|\ud83d\udc69\ud83c\udfff\u200d\ud83e\udd1d\u200d\ud83d\udc68\ud83c[\udffb-\udffe]|\ud83d\udc69\ud83c\udfff\u200d\ud83e\udd1d\u200d\ud83d\udc69\ud83c[\udffb-\udffe]|\ud83e\uddd1\ud83c\udffb\u200d\ud83e\udd1d\u200d\ud83e\uddd1\ud83c[\udffb-\udfff]|\ud83e\uddd1\ud83c\udffc\u200d\ud83e\udd1d\u200d\ud83e\uddd1\ud83c[\udffb-\udfff]|\ud83e\uddd1\ud83c\udffd\u200d\ud83e\udd1d\u200d\ud83e\uddd1\ud83c[\udffb-\udfff]|\ud83e\uddd1\ud83c\udffe\u200d\ud83e\udd1d\u200d\ud83e\uddd1\ud83c[\udffb-\udfff]|\ud83e\uddd1\ud83c\udfff\u200d\ud83e\udd1d\u200d\ud83e\uddd1\ud83c[\udffb-\udfff]|\ud83e\uddd1\u200d\ud83e\udd1d\u200d\ud83e\uddd1|\ud83d\udc6b\ud83c[\udffb-\udfff]|\ud83d\udc6c\ud83c[\udffb-\udfff]|\ud83d\udc6d\ud83c[\udffb-\udfff]|\ud83d[\udc6b-\udc6d])|(?:\ud83d[\udc68\udc69]|\ud83e\uddd1)(?:\ud83c[\udffb-\udfff])?\u200d(?:\u2695\ufe0f|\u2696\ufe0f|\u2708\ufe0f|\ud83c[\udf3e\udf73\udf7c\udf84\udf93\udfa4\udfa8\udfeb\udfed]|\ud83d[\udcbb\udcbc\udd27\udd2c\ude80\ude92]|\ud83e[\uddaf-\uddb3\uddbc\uddbd])|(?:\ud83c[\udfcb\udfcc]|\ud83d[\udd74\udd75]|\u26f9)((?:\ud83c[\udffb-\udfff]|\ufe0f)\u200d[\u2640\u2642]\ufe0f)|(?:\ud83c[\udfc3\udfc4\udfca]|\ud83d[\udc6e\udc70\udc71\udc73\udc77\udc81\udc82\udc86\udc87\ude45-\ude47\ude4b\ude4d\ude4e\udea3\udeb4-\udeb6]|\ud83e[\udd26\udd35\udd37-\udd39\udd3d\udd3e\uddb8\uddb9\uddcd-\uddcf\uddd6-\udddd])(?:\ud83c[\udffb-\udfff])?\u200d[\u2640\u2642]\ufe0f|(?:\ud83d\udc68\u200d\u2764\ufe0f\u200d\ud83d\udc8b\u200d\ud83d\udc68|\ud83d\udc68\u200d\ud83d\udc68\u200d\ud83d\udc66\u200d\ud83d\udc66|\ud83d\udc68\u200d\ud83d\udc68\u200d\ud83d\udc67\u200d\ud83d[\udc66\udc67]|\ud83d\udc68\u200d\ud83d\udc69\u200d\ud83d\udc66\u200d\ud83d\udc66|\ud83d\udc68\u200d\ud83d\udc69\u200d\ud83d\udc67\u200d\ud83d[\udc66\udc67]|\ud83d\udc69\u200d\u2764\ufe0f\u200d\ud83d\udc8b\u200d\ud83d[\udc68\udc69]|\ud83d\udc69\u200d\ud83d\udc69\u200d\ud83d\udc66\u200d\ud83d\udc66|\ud83d\udc69\u200d\ud83d\udc69\u200d\ud83d\udc67\u200d\ud83d[\udc66\udc67]|\ud83d\udc68\u200d\u2764\ufe0f\u200d\ud83d\udc68|\ud83d\udc68\u200d\ud83d\udc66\u200d\ud83d\udc66|\ud83d\udc68\u200d\ud83d\udc67\u200d\ud83d[\udc66\udc67]|\ud83d\udc68\u200d\ud83d\udc68\u200d\ud83d[\udc66\udc67]|\ud83d\udc68\u200d\ud83d\udc69\u200d\ud83d[\udc66\udc67]|\ud83d\udc69\u200d\u2764\ufe0f\u200d\ud83d[\udc68\udc69]|\ud83d\udc69\u200d\ud83d\udc66\u200d\ud83d\udc66|\ud83d\udc69\u200d\ud83d\udc67\u200d\ud83d[\udc66\udc67]|\ud83d\udc69\u200d\ud83d\udc69\u200d\ud83d[\udc66\udc67]|\ud83c\udff3\ufe0f\u200d\u26a7\ufe0f|\ud83c\udff3\ufe0f\u200d\ud83c\udf08|\ud83c\udff4\u200d\u2620\ufe0f|\ud83d\udc15\u200d\ud83e\uddba|\ud83d\udc3b\u200d\u2744\ufe0f|\ud83d\udc41\u200d\ud83d\udde8|\ud83d\udc68\u200d\ud83d[\udc66\udc67]|\ud83d\udc69\u200d\ud83d[\udc66\udc67]|\ud83d\udc6f\u200d\u2640\ufe0f|\ud83d\udc6f\u200d\u2642\ufe0f|\ud83e\udd3c\u200d\u2640\ufe0f|\ud83e\udd3c\u200d\u2642\ufe0f|\ud83e\uddde\u200d\u2640\ufe0f|\ud83e\uddde\u200d\u2642\ufe0f|\ud83e\udddf\u200d\u2640\ufe0f
|
2020-08-13 23:32:35 +03:00
|
|
|
|
2020-11-22 01:54:59 +03:00
|
|
|
// avoid runtime RegExp creation for not so smart,
|
|
|
|
// not JIT based, and old browsers / engines
|
|
|
|
UFE0Fg = /\uFE0F/g,
|
2020-08-13 23:32:35 +03:00
|
|
|
|
2020-11-22 01:54:59 +03:00
|
|
|
// avoid using a string literal like '\u200D' here because minifiers expand it inline
|
|
|
|
U200D = String.fromCharCode(0x200D),
|
|
|
|
basePath = Qt.resolvedUrl("./emoji/"),
|
|
|
|
ampersandRe = /\&(?!amp;)/g;
|
2020-08-13 23:32:35 +03:00
|
|
|
|
2020-11-22 01:54:59 +03:00
|
|
|
function toCodePoint(unicodeSurrogates) {
|
|
|
|
var
|
|
|
|
r = [],
|
|
|
|
c = 0,
|
|
|
|
p = 0,
|
|
|
|
i = 0;
|
|
|
|
while (i < unicodeSurrogates.length) {
|
|
|
|
c = unicodeSurrogates.charCodeAt(i++);
|
|
|
|
if (p) {
|
|
|
|
r.push((0x10000 + ((p - 0xD800) << 10) + (c - 0xDC00)).toString(16));
|
|
|
|
p = 0;
|
|
|
|
} else if (0xD800 <= c && c <= 0xDBFF) {
|
|
|
|
p = c;
|
|
|
|
} else {
|
|
|
|
r.push(c.toString(16));
|
2020-08-13 23:32:35 +03:00
|
|
|
}
|
|
|
|
}
|
2020-11-22 01:54:59 +03:00
|
|
|
return r.join('-');
|
|
|
|
}
|
2020-08-13 23:32:35 +03:00
|
|
|
|
2020-11-22 01:54:59 +03:00
|
|
|
function emojify(str, emojiSize) {
|
|
|
|
return String(str).replace(re, function (rawText) {
|
|
|
|
var ret = rawText,
|
|
|
|
iconId = toCodePoint(rawText.indexOf(U200D) < 0 ?
|
|
|
|
rawText.replace(UFE0Fg, '') :
|
|
|
|
rawText
|
|
|
|
);
|
|
|
|
if (iconId) {
|
|
|
|
// recycle the match string replacing the emoji
|
|
|
|
// with its image counter part
|
|
|
|
ret = '<img '.concat(
|
|
|
|
'src="',
|
|
|
|
basePath,
|
|
|
|
iconId,
|
|
|
|
'.svg',
|
|
|
|
'" align="middle" width="',
|
|
|
|
emojiSize,
|
|
|
|
'" height="',
|
|
|
|
emojiSize,
|
|
|
|
'"/>'
|
|
|
|
);
|
2020-08-13 23:32:35 +03:00
|
|
|
}
|
2020-11-22 01:54:59 +03:00
|
|
|
return ret.replace(ampersandRe, "&");
|
|
|
|
});
|
|
|
|
}
|