-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
44 lines (36 loc) · 1.3 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
(global.ifEmoji = factory());
}(this, function () { 'use strict';
var _ArrayLikeToString = function _ArrayLikeToString(arg) {
return Array.prototype.toString.call(arg);
};
var getTextFeature = function getTextFeature(text, color) {
try {
var canvas = document.createElement('canvas');
canvas.width = 1;
canvas.height = 1;
var ctx = canvas.getContext('2d');
ctx.textBaseline = 'top';
ctx.font = '100px -no-font-family-here-';
ctx.fillStyle = color;
ctx.scale(0.01, 0.01);
ctx.fillText(text, 0, 0);
return ctx.getImageData(0, 0, 1, 1).data;
} catch (e) {
return false;
}
};
var compareFeatures = function compareFeatures(feature1, feature2) {
var feature1Str = _ArrayLikeToString(feature1);
var feature2Str = _ArrayLikeToString(feature2);
return feature1Str === feature2Str && feature1Str !== '0,0,0,0';
};
function index (text) {
var feature1 = getTextFeature(text, '#000');
var feature2 = getTextFeature(text, '#fff');
return feature1 && feature2 && compareFeatures(feature1, feature2);
}
return index;
}));