@svgmoji/core
Advanced tools
Comparing version 0.2.0 to 1.0.0
# @svgmoji/core | ||
## 1.0.0 | ||
> 2021-01-16 | ||
### Major Changes | ||
- b549183a: This update contains breaking the following breaking changes. | ||
- **BREAKING**: Rename `getUrl` method on `Moji` abstract class to `url`. | ||
- **BREAKING**: Store `fallback` as a `FlatEmoji` rather than the provided string. | ||
The remaining changes are non-breaking. | ||
- Add `fallbackUrl` property to `Moji` abstract class. | ||
- Add `find` method to `Moji` to allow searching for emoji by `unicode`, `hexcode` or `emoticon`. | ||
- Add `search` method which allows fuzzy searching the emoji. The search algorithm is provided the library [`match-sorter`](https://github.com/kentcdodds/match-sorter) and may be adapted in future releases. | ||
- Clean up dependencies. | ||
## 0.2.0 | ||
@@ -17,3 +35,2 @@ | ||
- aa3e427: Create the initial launch of the `svgmoji` project packages. Improvements will be added | ||
as it is used within the [`remirror`](https://remirror.io) codebase. | ||
- aa3e427: Create the initial launch of the `svgmoji` project packages. Improvements will be added as it is used within the [`remirror`](https://remirror.io) codebase. |
import type { SpriteCollectionType } from './constants'; | ||
import type { FlatEmoji } from './flatten-emoji-data'; | ||
import type { MinifiedEmoji } from './minify-emoji'; | ||
import type { FlatEmoji, MinifiedEmoji } from './types'; | ||
interface MojiProps { | ||
@@ -32,4 +31,8 @@ /** | ||
*/ | ||
data: FlatEmoji[]; | ||
readonly data: FlatEmoji[]; | ||
/** | ||
* Only data without tones included. | ||
*/ | ||
readonly tonelessData: FlatEmoji[]; | ||
/** | ||
* The type of sprite to load. | ||
@@ -39,5 +42,7 @@ */ | ||
/** | ||
* The fallback svg to use when none can be found. | ||
* The fallback emoji to use when none can be found. | ||
*/ | ||
fallback: string; | ||
fallback: FlatEmoji; | ||
get cdn(): string; | ||
get fallbackUrl(): string; | ||
/** | ||
@@ -48,9 +53,32 @@ * @param data - data which is used to lookup the groups and subgroups for the emoji instance | ||
constructor({ data, type, fallback }: MojiProps); | ||
get cdn(): string; | ||
/** | ||
* Get the CDN url from the provided emoji. | ||
* Get the CDN url from the provided emoji hexcode, emoticon or unicode string. | ||
*/ | ||
getUrl(emoji: string): string; | ||
getUrlFromHexcode(hexcode: string): string; | ||
url(code: string, options: { | ||
fallback: false; | ||
}): string | undefined; | ||
url(code: string, options?: { | ||
fallback?: true; | ||
}): string; | ||
/** | ||
* Get an the emoji object of a value by it's hexcode, emoticon or unicode string. | ||
*/ | ||
find(code: string): FlatEmoji | undefined; | ||
/** | ||
* Search for the nearest emoji using the `match-sorter` algorithm. | ||
*/ | ||
search(query: string, options?: BaseMojiProps): FlatEmoji[]; | ||
/** | ||
* Get skins from emoji | ||
*/ | ||
getTones(emoji: FlatEmoji): FlatEmoji[]; | ||
} | ||
interface BaseMojiProps { | ||
/** | ||
* When true only emoji without tone data will be used. | ||
* | ||
* @default true; | ||
*/ | ||
excludeTone?: boolean; | ||
} | ||
export {}; |
@@ -1,3 +0,2 @@ | ||
import type { FlatEmoji } from './flatten-emoji-data'; | ||
import type { MinifiedEmoji } from './minify-emoji'; | ||
import type { FlatEmoji, MinifiedEmoji } from './types'; | ||
export declare function isMinifiedEmoji(value: unknown): value is MinifiedEmoji; | ||
@@ -4,0 +3,0 @@ export declare function isFlatEmoji(value: unknown): value is FlatEmoji; |
import type { Locale, ShortcodePreset } from 'emojibase'; | ||
import { FetchFromCDNOptions } from './fetch-from-cdn'; | ||
import { FlatEmoji } from './flatten-emoji-data'; | ||
import type { FlatEmoji } from './types'; | ||
export interface FetchEmojisOptions<Type extends Locale> extends FetchFromCDNOptions { | ||
@@ -5,0 +5,0 @@ shortcodes?: Array<EmojiShortcodeLocale<Type> | ShortcodePreset>; |
@@ -1,2 +0,1 @@ | ||
import 'isomorphic-fetch'; | ||
export interface FetchFromCDNOptions extends RequestInit { | ||
@@ -3,0 +2,0 @@ /** |
@@ -1,17 +0,3 @@ | ||
import type { Emoji, ShortcodesDataset, SkinTone } from 'emojibase'; | ||
export interface FlatEmoji extends Omit<Emoji, 'skins' | 'tone'> { | ||
/** | ||
* The hexcodes for the skins contained. | ||
*/ | ||
skins?: string[]; | ||
/** | ||
* The skin tone. | ||
*/ | ||
tone?: SkinToneTuple; | ||
} | ||
/** | ||
* The skin tone which allows a second tone for complex emoji that support multiple tones for | ||
* different characters. | ||
*/ | ||
export declare type SkinToneTuple = [primary: SkinTone, secondary?: SkinTone]; | ||
export declare function flattenEmojiData(data: Emoji[], shortcodeDatasets?: ShortcodesDataset[]): FlatEmoji[]; | ||
import type { Emoji as BaseEmoji, ShortcodesDataset } from 'emojibase'; | ||
import type { FlatEmoji } from './types'; | ||
export declare function flattenEmojiData(data: BaseEmoji[], shortcodeDatasets?: ShortcodesDataset[]): FlatEmoji[]; |
@@ -10,3 +10,5 @@ export * from './base-moji'; | ||
export * from './populate-minified-emoji'; | ||
export * from './regexp'; | ||
export * from './types'; | ||
export type { Emoticon } from 'emojibase'; | ||
export { fromUnicodeToHexcode, generateEmoticonPermutations, stripHexcode } from 'emojibase'; |
@@ -1,69 +0,3 @@ | ||
import type { FlatEmoji } from './flatten-emoji-data'; | ||
import type { FlatEmoji, MinifiedEmoji } from './types'; | ||
/** | ||
* A minified emoji object which takes the flattened emoji value and minifies all the keys to | ||
* prevent a bloated json file. | ||
*/ | ||
export interface MinifiedEmoji { | ||
/** | ||
* Alias for `annotation` property. | ||
*/ | ||
a: FlatEmoji['annotation']; | ||
/** | ||
* Alias for `emoji` property. | ||
*/ | ||
e: FlatEmoji['emoji']; | ||
/** | ||
* Alias for `emoticon` property. | ||
*/ | ||
u?: FlatEmoji['emoticon']; | ||
/** | ||
* Alias for `gender` property. | ||
*/ | ||
g?: FlatEmoji['gender']; | ||
/** | ||
* Alias for `group` property. | ||
*/ | ||
b?: FlatEmoji['group']; | ||
/** | ||
* Alias for `hexcode` property. | ||
*/ | ||
h: FlatEmoji['hexcode']; | ||
/** | ||
* Alias for `order` property. | ||
*/ | ||
o?: FlatEmoji['order']; | ||
/** | ||
* Alias for `shortcodes` property. | ||
*/ | ||
s?: FlatEmoji['shortcodes']; | ||
/** | ||
* Alias for `skins` property. | ||
*/ | ||
k?: FlatEmoji['skins']; | ||
/** | ||
* Alias for `subgroup` property. | ||
*/ | ||
c?: FlatEmoji['subgroup']; | ||
/** | ||
* Alias for `tags` property. | ||
*/ | ||
t?: FlatEmoji['tags']; | ||
/** | ||
* Alias for `text` property. | ||
*/ | ||
d: FlatEmoji['text']; | ||
/** | ||
* Alias for `tone` property. | ||
*/ | ||
f?: FlatEmoji['tone']; | ||
/** | ||
* Alias for `type` property. | ||
*/ | ||
i: FlatEmoji['type']; | ||
/** | ||
* Alias for `version` property. | ||
*/ | ||
v: FlatEmoji['version']; | ||
} | ||
/** | ||
* Minify emoji which can be useful for reducing the json bundlesize. | ||
@@ -70,0 +4,0 @@ */ |
@@ -1,3 +0,2 @@ | ||
import type { FlatEmoji } from './flatten-emoji-data'; | ||
import type { MinifiedEmoji } from './minify-emoji'; | ||
import type { FlatEmoji, MinifiedEmoji } from './types'; | ||
/** | ||
@@ -4,0 +3,0 @@ * Populate the minified emoji into a readable format. |
@@ -6,32 +6,63 @@ 'use strict'; | ||
var emojibase = require('emojibase'); | ||
var groups_json = require('emojibase-data/meta/groups.json'); | ||
var omit = require('object.omit'); | ||
var matchSorter = require('match-sorter'); | ||
var EMOTICON_REGEX = require('emojibase-regex/emoticon'); | ||
var SHORTCODE_REGEX = require('emojibase-regex/shortcode'); | ||
var _objectWithoutProperties = require('@babel/runtime/helpers/objectWithoutProperties'); | ||
require('isomorphic-fetch'); | ||
var idbKeyval = require('idb-keyval'); | ||
function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; } | ||
function _interopNamespace(e) { | ||
if (e && e.__esModule) return e; | ||
var n = Object.create(null); | ||
if (e) { | ||
Object.keys(e).forEach(function (k) { | ||
if (k !== 'default') { | ||
var d = Object.getOwnPropertyDescriptor(e, k); | ||
Object.defineProperty(n, k, d.get ? d : { | ||
enumerable: true, | ||
get: function () { | ||
return e[k]; | ||
} | ||
}); | ||
} | ||
var EMOTICON_REGEX__default = /*#__PURE__*/_interopDefault(EMOTICON_REGEX); | ||
var SHORTCODE_REGEX__default = /*#__PURE__*/_interopDefault(SHORTCODE_REGEX); | ||
var _objectWithoutProperties__default = /*#__PURE__*/_interopDefault(_objectWithoutProperties); | ||
function _defineProperty(obj, key, value) { | ||
if (key in obj) { | ||
Object.defineProperty(obj, key, { | ||
value: value, | ||
enumerable: true, | ||
configurable: true, | ||
writable: true | ||
}); | ||
} else { | ||
obj[key] = value; | ||
} | ||
n['default'] = e; | ||
return Object.freeze(n); | ||
return obj; | ||
} | ||
var omit__default = /*#__PURE__*/_interopDefault(omit); | ||
var _objectWithoutProperties__default = /*#__PURE__*/_interopDefault(_objectWithoutProperties); | ||
function ownKeys(object, enumerableOnly) { | ||
var keys = Object.keys(object); | ||
if (Object.getOwnPropertySymbols) { | ||
var symbols = Object.getOwnPropertySymbols(object); | ||
if (enumerableOnly) symbols = symbols.filter(function (sym) { | ||
return Object.getOwnPropertyDescriptor(object, sym).enumerable; | ||
}); | ||
keys.push.apply(keys, symbols); | ||
} | ||
return keys; | ||
} | ||
function _objectSpread2(target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i] != null ? arguments[i] : {}; | ||
if (i % 2) { | ||
ownKeys(Object(source), true).forEach(function (key) { | ||
_defineProperty(target, key, source[key]); | ||
}); | ||
} else if (Object.getOwnPropertyDescriptors) { | ||
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); | ||
} else { | ||
ownKeys(Object(source)).forEach(function (key) { | ||
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); | ||
}); | ||
} | ||
} | ||
return target; | ||
} | ||
const SpriteCollection = { | ||
@@ -109,3 +140,3 @@ /** | ||
function omitUndefined(object) { | ||
return omit__default['default'](object, value => value !== undefined); | ||
return JSON.parse(JSON.stringify(object)); | ||
} | ||
@@ -116,3 +147,2 @@ | ||
*/ | ||
function populateMinifiedEmoji(minified) { | ||
@@ -138,2 +168,122 @@ return minified.map(emoji => omitUndefined({ | ||
/** | ||
* Simple regexp for testing if a string passed in is a hexcode. | ||
*/ | ||
const HEXCODE_REGEX = /^[\dA-Fa-f][\dA-Fa-f-]+[\dA-Fa-f]$/; | ||
const groups = ([{ | ||
"0": "smileys-emotion", | ||
"1": "people-body", | ||
"2": "component", | ||
"3": "animals-nature", | ||
"4": "food-drink", | ||
"5": "travel-places", | ||
"6": "activities", | ||
"7": "objects", | ||
"8": "symbols", | ||
"9": "flags" | ||
}][0]); | ||
const subgroups = ([{ | ||
"0": "face-smiling", | ||
"1": "face-affection", | ||
"2": "face-tongue", | ||
"3": "face-hand", | ||
"4": "face-neutral-skeptical", | ||
"5": "face-sleepy", | ||
"6": "face-unwell", | ||
"7": "face-hat", | ||
"8": "face-glasses", | ||
"9": "face-concerned", | ||
"10": "face-negative", | ||
"11": "face-costume", | ||
"12": "cat-face", | ||
"13": "monkey-face", | ||
"14": "emotion", | ||
"15": "hand-fingers-open", | ||
"16": "hand-fingers-partial", | ||
"17": "hand-single-finger", | ||
"18": "hand-fingers-closed", | ||
"19": "hands", | ||
"20": "hand-prop", | ||
"21": "body-parts", | ||
"22": "person", | ||
"23": "person-gesture", | ||
"24": "person-role", | ||
"25": "person-fantasy", | ||
"26": "person-activity", | ||
"27": "person-sport", | ||
"28": "person-resting", | ||
"29": "family", | ||
"30": "person-symbol", | ||
"31": "skin-tone", | ||
"32": "hair-style", | ||
"33": "animal-mammal", | ||
"34": "animal-bird", | ||
"35": "animal-amphibian", | ||
"36": "animal-reptile", | ||
"37": "animal-marine", | ||
"38": "animal-bug", | ||
"39": "plant-flower", | ||
"40": "plant-other", | ||
"41": "food-fruit", | ||
"42": "food-vegetable", | ||
"43": "food-prepared", | ||
"44": "food-asian", | ||
"45": "food-marine", | ||
"46": "food-sweet", | ||
"47": "drink", | ||
"48": "dishware", | ||
"49": "place-map", | ||
"50": "place-geographic", | ||
"51": "place-building", | ||
"52": "place-religious", | ||
"53": "place-other", | ||
"54": "transport-ground", | ||
"55": "transport-water", | ||
"56": "transport-air", | ||
"57": "hotel", | ||
"58": "time", | ||
"59": "sky-weather", | ||
"60": "event", | ||
"61": "award-medal", | ||
"62": "sport", | ||
"63": "game", | ||
"64": "arts-crafts", | ||
"65": "clothing", | ||
"66": "sound", | ||
"67": "music", | ||
"68": "musical-instrument", | ||
"69": "phone", | ||
"70": "computer", | ||
"71": "light-video", | ||
"72": "book-paper", | ||
"73": "money", | ||
"74": "mail", | ||
"75": "writing", | ||
"76": "office", | ||
"77": "lock", | ||
"78": "tool", | ||
"79": "science", | ||
"80": "medical", | ||
"81": "household", | ||
"82": "other-object", | ||
"83": "transport-sign", | ||
"84": "warning", | ||
"85": "arrow", | ||
"86": "religion", | ||
"87": "zodiac", | ||
"88": "av-symbol", | ||
"89": "gender", | ||
"90": "math", | ||
"91": "punctuation", | ||
"92": "currency", | ||
"93": "other-symbol", | ||
"94": "keycap", | ||
"95": "alphanum", | ||
"96": "geometric", | ||
"97": "flag", | ||
"98": "country-flag", | ||
"99": "subdivision-flag" | ||
}][0]); | ||
class Moji { | ||
@@ -153,2 +303,6 @@ /** | ||
/** | ||
* Only data without tones included. | ||
*/ | ||
/** | ||
* The type of sprite to load. | ||
@@ -158,5 +312,11 @@ */ | ||
/** | ||
* The fallback svg to use when none can be found. | ||
* The fallback emoji to use when none can be found. | ||
*/ | ||
get cdn() { | ||
return "https://cdn.jsdelivr.net/npm/@svgmoji/".concat(this.name, "@").concat(this.version, "/"); | ||
} | ||
get fallbackUrl() { | ||
return "".concat(this.cdn, "/svg/").concat(this.fallback.hexcode, ".svg"); | ||
} | ||
/** | ||
@@ -166,2 +326,4 @@ * @param data - data which is used to lookup the groups and subgroups for the emoji instance | ||
*/ | ||
constructor(_ref) { | ||
@@ -173,108 +335,141 @@ let { | ||
} = _ref; | ||
this.type = type; | ||
this.data = isMinifiedEmojiList(data) ? populateMinifiedEmoji(data) : data; | ||
this.type = type; | ||
this.fallback = fallback; | ||
} | ||
this.tonelessData = this.data.filter(emoji => !emoji.tone); | ||
const fallbackEmoji = this.find(fallback); | ||
get cdn() { | ||
return "https://cdn.jsdelivr.net/npm/@svgmoji/".concat(this.name, "@").concat(this.version, "/"); | ||
if (!fallbackEmoji) { | ||
throw new Error("\u274C No emoji exists for the provided fallback value: '".concat(fallback, "'")); | ||
} | ||
this.fallback = fallbackEmoji; | ||
} | ||
/** | ||
* Get the CDN url from the provided emoji. | ||
* Get the CDN url from the provided emoji hexcode, emoticon or unicode string. | ||
*/ | ||
getUrl(emoji) { | ||
return this.getUrlFromHexcode(emojibase.fromUnicodeToHexcode(emoji)); | ||
} | ||
url(code) { | ||
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
const { | ||
fallback = true | ||
} = options; | ||
const emoji = this.find(code); | ||
const fallbackUrl = fallback ? this.fallbackUrl : undefined; | ||
getUrlFromHexcode(hexcode) { | ||
if (!emoji) { | ||
return fallbackUrl; | ||
} | ||
if (this.type === SpriteCollection.All) { | ||
return "".concat(this.cdn, "/sprites/all.svg#").concat(hexcode); | ||
return "".concat(this.cdn, "/sprites/all.svg#").concat(emoji.hexcode); | ||
} | ||
if (this.type === SpriteCollection.Individual) { | ||
return "".concat(this.cdn, "/svg/").concat(hexcode, ".svg"); | ||
return "".concat(this.cdn, "/svg/").concat(emoji.hexcode, ".svg"); | ||
} | ||
const emoji = this.data.find(emoji => emoji.hexcode === hexcode); | ||
if (this.type === SpriteCollection.Group && emoji !== null && emoji !== void 0 && emoji.group) { | ||
var _groups$emoji$group; | ||
if (this.type === SpriteCollection.Group && emoji !== null && emoji !== void 0 && emoji.group) { | ||
const name = groups_json.groups["".concat(emoji.group)]; | ||
return "".concat(this.cdn, "/sprites/group/").concat(name, ".svg#").concat(hexcode); | ||
const name = (_groups$emoji$group = groups[emoji.group]) !== null && _groups$emoji$group !== void 0 ? _groups$emoji$group : 'other'; | ||
return "".concat(this.cdn, "/sprites/group/").concat(name, ".svg#").concat(emoji.hexcode); | ||
} | ||
if (this.type === SpriteCollection.Subgroup && emoji !== null && emoji !== void 0 && emoji.subgroup) { | ||
const name = groups_json.subgroups["".concat(emoji.subgroup)]; | ||
return "".concat(this.cdn, "/sprites/subgroup/").concat(name, ".svg#").concat(hexcode); | ||
var _subgroups$emoji$subg; | ||
const name = (_subgroups$emoji$subg = subgroups[emoji.subgroup]) !== null && _subgroups$emoji$subg !== void 0 ? _subgroups$emoji$subg : 'other'; | ||
return "".concat(this.cdn, "/sprites/subgroup/").concat(name, ".svg#").concat(emoji.hexcode); | ||
} | ||
return "".concat(this.cdn, "/svg/").concat(this.fallback, ".svg"); | ||
return fallbackUrl; | ||
} | ||
/** | ||
* Get an the emoji object of a value by it's hexcode, emoticon or unicode string. | ||
*/ | ||
} | ||
function _defineProperty(obj, key, value) { | ||
if (key in obj) { | ||
Object.defineProperty(obj, key, { | ||
value: value, | ||
enumerable: true, | ||
configurable: true, | ||
writable: true | ||
}); | ||
} else { | ||
obj[key] = value; | ||
find(code) { | ||
if (EMOTICON_REGEX__default['default'].test(code)) { | ||
return this.data.find(emoji => !!emoji.emoticon && emojibase.generateEmoticonPermutations(emoji.emoticon).includes(code)); | ||
} | ||
if (SHORTCODE_REGEX__default['default'].test(code)) { | ||
return this.data.find(emoji => { | ||
var _emoji$shortcodes; | ||
return (_emoji$shortcodes = emoji.shortcodes) === null || _emoji$shortcodes === void 0 ? void 0 : _emoji$shortcodes.map(shortcode => ":".concat(shortcode, ":")).includes(code); | ||
}); | ||
} | ||
if (HEXCODE_REGEX.test(code)) { | ||
return this.data.find(emoji => emoji.hexcode === code); | ||
} // Assume that the string passed is a native emoji string. | ||
return this.data.find(emoji => emoji.emoji === code || emoji.text === code); | ||
} | ||
/** | ||
* Search for the nearest emoji using the `match-sorter` algorithm. | ||
*/ | ||
return obj; | ||
} | ||
function ownKeys(object, enumerableOnly) { | ||
var keys = Object.keys(object); | ||
search(query) { | ||
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
if (Object.getOwnPropertySymbols) { | ||
var symbols = Object.getOwnPropertySymbols(object); | ||
if (enumerableOnly) symbols = symbols.filter(function (sym) { | ||
return Object.getOwnPropertyDescriptor(object, sym).enumerable; | ||
const { | ||
excludeTone | ||
} = _objectSpread2(_objectSpread2({}, DEFAULT_OPTIONS), options); | ||
const data = excludeTone ? this.tonelessData : this.data; | ||
return matchSorter.matchSorter(data, query, { | ||
threshold: matchSorter.rankings.WORD_STARTS_WITH, | ||
keys: [{ | ||
threshold: matchSorter.rankings.STARTS_WITH, | ||
key: 'shortcodes' | ||
}, 'tags', 'annotation', item => { | ||
var _subgroups$item$subgr, _subgroups$item$subgr2; | ||
return item.subgroup ? (_subgroups$item$subgr = (_subgroups$item$subgr2 = subgroups[item.subgroup]) === null || _subgroups$item$subgr2 === void 0 ? void 0 : _subgroups$item$subgr2.split('-').join(' ')) !== null && _subgroups$item$subgr !== void 0 ? _subgroups$item$subgr : '' : ''; | ||
}, item => { | ||
var _groups$item$group$sp, _groups$item$group; | ||
return item.group ? (_groups$item$group$sp = (_groups$item$group = groups[item.group]) === null || _groups$item$group === void 0 ? void 0 : _groups$item$group.split('-').join(' ')) !== null && _groups$item$group$sp !== void 0 ? _groups$item$group$sp : '' : ''; | ||
}] | ||
}); | ||
keys.push.apply(keys, symbols); | ||
} | ||
/** | ||
* Get skins from emoji | ||
*/ | ||
return keys; | ||
} | ||
function _objectSpread2(target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i] != null ? arguments[i] : {}; | ||
getTones(emoji) { | ||
const skins = []; | ||
if (i % 2) { | ||
ownKeys(Object(source), true).forEach(function (key) { | ||
_defineProperty(target, key, source[key]); | ||
}); | ||
} else if (Object.getOwnPropertyDescriptors) { | ||
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); | ||
} else { | ||
ownKeys(Object(source)).forEach(function (key) { | ||
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); | ||
}); | ||
for (const skin of (_emoji$skins = emoji.skins) !== null && _emoji$skins !== void 0 ? _emoji$skins : []) { | ||
var _emoji$skins; | ||
const skinEmoji = this.find(skin); | ||
if (skinEmoji) { | ||
skins.push(); | ||
} | ||
} | ||
return skins; | ||
} | ||
return target; | ||
} | ||
const DEFAULT_OPTIONS = { | ||
excludeTone: true | ||
}; | ||
async function get(key) { | ||
async function runInBrowser(callback) { | ||
const { | ||
get: idbGet | ||
} = await Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require('idb-keyval')); }); | ||
return idbGet(key); | ||
} | ||
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { | ||
args[_key - 1] = arguments[_key]; | ||
} | ||
async function set(key, value) { | ||
const { | ||
set: idbSet | ||
} = await Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require('idb-keyval')); }); | ||
await idbSet(key, value); | ||
return callback(...args); | ||
} | ||
@@ -301,3 +496,3 @@ | ||
const cacheKey = "svgmoji/".concat(version, "/").concat(path); | ||
const cachedData = await get(cacheKey); // Check the cache first | ||
const cachedData = await runInBrowser(idbKeyval.get, cacheKey); // Check the cache first | ||
@@ -321,3 +516,3 @@ if (cachedData) { | ||
try { | ||
await set(cacheKey, data); | ||
await runInBrowser(idbKeyval.set, cacheKey, data); | ||
} catch (_unused) {// Do nothing. | ||
@@ -373,2 +568,13 @@ } | ||
/** | ||
* Throws an error if the tone is undefined. | ||
*/ | ||
function getTone(tone) { | ||
if (!tone) { | ||
throw new Error('A tone is required when using `getTone`'); | ||
} | ||
return Array.isArray(tone) ? [tone[0], tone[1]] : [tone]; | ||
} | ||
function createFlatEmoji(base, skins, tone) { | ||
@@ -378,3 +584,3 @@ const flatEmoji = _objectSpread2({}, base); | ||
if (tone) { | ||
flatEmoji.tone = Array.isArray(tone) ? [tone[0], tone[1]] : [tone]; | ||
flatEmoji.tone = getTone(tone); | ||
} | ||
@@ -388,8 +594,3 @@ | ||
} | ||
/** | ||
* The skin tone which allows a second tone for complex emoji that support multiple tones for | ||
* different characters. | ||
*/ | ||
function flattenEmojiData(data) { | ||
@@ -480,2 +681,15 @@ let shortcodeDatasets = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : []; | ||
}); | ||
Object.defineProperty(exports, 'EMOTICON_REGEX', { | ||
enumerable: true, | ||
get: function () { | ||
return EMOTICON_REGEX__default['default']; | ||
} | ||
}); | ||
Object.defineProperty(exports, 'SHORTCODE_REGEX', { | ||
enumerable: true, | ||
get: function () { | ||
return SHORTCODE_REGEX__default['default']; | ||
} | ||
}); | ||
exports.HEXCODE_REGEX = HEXCODE_REGEX; | ||
exports.Moji = Moji; | ||
@@ -482,0 +696,0 @@ exports.SpriteCollection = SpriteCollection; |
@@ -1,8 +0,60 @@ | ||
import { fromUnicodeToHexcode, NON_LATIN_LOCALES } from 'emojibase'; | ||
import { generateEmoticonPermutations, NON_LATIN_LOCALES } from 'emojibase'; | ||
export { fromUnicodeToHexcode, generateEmoticonPermutations, stripHexcode } from 'emojibase'; | ||
import { groups, subgroups } from 'emojibase-data/meta/groups.json'; | ||
import omit from 'object.omit'; | ||
import { matchSorter, rankings } from 'match-sorter'; | ||
import EMOTICON_REGEX from 'emojibase-regex/emoticon'; | ||
export { default as EMOTICON_REGEX } from 'emojibase-regex/emoticon'; | ||
import SHORTCODE_REGEX from 'emojibase-regex/shortcode'; | ||
export { default as SHORTCODE_REGEX } from 'emojibase-regex/shortcode'; | ||
import _objectWithoutProperties from '@babel/runtime/helpers/esm/objectWithoutProperties'; | ||
import 'isomorphic-fetch'; | ||
import { set, get } from 'idb-keyval'; | ||
function _defineProperty(obj, key, value) { | ||
if (key in obj) { | ||
Object.defineProperty(obj, key, { | ||
value: value, | ||
enumerable: true, | ||
configurable: true, | ||
writable: true | ||
}); | ||
} else { | ||
obj[key] = value; | ||
} | ||
return obj; | ||
} | ||
function ownKeys(object, enumerableOnly) { | ||
var keys = Object.keys(object); | ||
if (Object.getOwnPropertySymbols) { | ||
var symbols = Object.getOwnPropertySymbols(object); | ||
if (enumerableOnly) symbols = symbols.filter(function (sym) { | ||
return Object.getOwnPropertyDescriptor(object, sym).enumerable; | ||
}); | ||
keys.push.apply(keys, symbols); | ||
} | ||
return keys; | ||
} | ||
function _objectSpread2(target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i] != null ? arguments[i] : {}; | ||
if (i % 2) { | ||
ownKeys(Object(source), true).forEach(function (key) { | ||
_defineProperty(target, key, source[key]); | ||
}); | ||
} else if (Object.getOwnPropertyDescriptors) { | ||
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); | ||
} else { | ||
ownKeys(Object(source)).forEach(function (key) { | ||
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); | ||
}); | ||
} | ||
} | ||
return target; | ||
} | ||
const SpriteCollection = { | ||
@@ -80,3 +132,3 @@ /** | ||
function omitUndefined(object) { | ||
return omit(object, value => value !== undefined); | ||
return JSON.parse(JSON.stringify(object)); | ||
} | ||
@@ -87,3 +139,2 @@ | ||
*/ | ||
function populateMinifiedEmoji(minified) { | ||
@@ -109,2 +160,122 @@ return minified.map(emoji => omitUndefined({ | ||
/** | ||
* Simple regexp for testing if a string passed in is a hexcode. | ||
*/ | ||
const HEXCODE_REGEX = /^[\dA-Fa-f][\dA-Fa-f-]+[\dA-Fa-f]$/; | ||
const groups = ([{ | ||
"0": "smileys-emotion", | ||
"1": "people-body", | ||
"2": "component", | ||
"3": "animals-nature", | ||
"4": "food-drink", | ||
"5": "travel-places", | ||
"6": "activities", | ||
"7": "objects", | ||
"8": "symbols", | ||
"9": "flags" | ||
}][0]); | ||
const subgroups = ([{ | ||
"0": "face-smiling", | ||
"1": "face-affection", | ||
"2": "face-tongue", | ||
"3": "face-hand", | ||
"4": "face-neutral-skeptical", | ||
"5": "face-sleepy", | ||
"6": "face-unwell", | ||
"7": "face-hat", | ||
"8": "face-glasses", | ||
"9": "face-concerned", | ||
"10": "face-negative", | ||
"11": "face-costume", | ||
"12": "cat-face", | ||
"13": "monkey-face", | ||
"14": "emotion", | ||
"15": "hand-fingers-open", | ||
"16": "hand-fingers-partial", | ||
"17": "hand-single-finger", | ||
"18": "hand-fingers-closed", | ||
"19": "hands", | ||
"20": "hand-prop", | ||
"21": "body-parts", | ||
"22": "person", | ||
"23": "person-gesture", | ||
"24": "person-role", | ||
"25": "person-fantasy", | ||
"26": "person-activity", | ||
"27": "person-sport", | ||
"28": "person-resting", | ||
"29": "family", | ||
"30": "person-symbol", | ||
"31": "skin-tone", | ||
"32": "hair-style", | ||
"33": "animal-mammal", | ||
"34": "animal-bird", | ||
"35": "animal-amphibian", | ||
"36": "animal-reptile", | ||
"37": "animal-marine", | ||
"38": "animal-bug", | ||
"39": "plant-flower", | ||
"40": "plant-other", | ||
"41": "food-fruit", | ||
"42": "food-vegetable", | ||
"43": "food-prepared", | ||
"44": "food-asian", | ||
"45": "food-marine", | ||
"46": "food-sweet", | ||
"47": "drink", | ||
"48": "dishware", | ||
"49": "place-map", | ||
"50": "place-geographic", | ||
"51": "place-building", | ||
"52": "place-religious", | ||
"53": "place-other", | ||
"54": "transport-ground", | ||
"55": "transport-water", | ||
"56": "transport-air", | ||
"57": "hotel", | ||
"58": "time", | ||
"59": "sky-weather", | ||
"60": "event", | ||
"61": "award-medal", | ||
"62": "sport", | ||
"63": "game", | ||
"64": "arts-crafts", | ||
"65": "clothing", | ||
"66": "sound", | ||
"67": "music", | ||
"68": "musical-instrument", | ||
"69": "phone", | ||
"70": "computer", | ||
"71": "light-video", | ||
"72": "book-paper", | ||
"73": "money", | ||
"74": "mail", | ||
"75": "writing", | ||
"76": "office", | ||
"77": "lock", | ||
"78": "tool", | ||
"79": "science", | ||
"80": "medical", | ||
"81": "household", | ||
"82": "other-object", | ||
"83": "transport-sign", | ||
"84": "warning", | ||
"85": "arrow", | ||
"86": "religion", | ||
"87": "zodiac", | ||
"88": "av-symbol", | ||
"89": "gender", | ||
"90": "math", | ||
"91": "punctuation", | ||
"92": "currency", | ||
"93": "other-symbol", | ||
"94": "keycap", | ||
"95": "alphanum", | ||
"96": "geometric", | ||
"97": "flag", | ||
"98": "country-flag", | ||
"99": "subdivision-flag" | ||
}][0]); | ||
class Moji { | ||
@@ -124,2 +295,6 @@ /** | ||
/** | ||
* Only data without tones included. | ||
*/ | ||
/** | ||
* The type of sprite to load. | ||
@@ -129,5 +304,11 @@ */ | ||
/** | ||
* The fallback svg to use when none can be found. | ||
* The fallback emoji to use when none can be found. | ||
*/ | ||
get cdn() { | ||
return "https://cdn.jsdelivr.net/npm/@svgmoji/".concat(this.name, "@").concat(this.version, "/"); | ||
} | ||
get fallbackUrl() { | ||
return "".concat(this.cdn, "/svg/").concat(this.fallback.hexcode, ".svg"); | ||
} | ||
/** | ||
@@ -137,2 +318,4 @@ * @param data - data which is used to lookup the groups and subgroups for the emoji instance | ||
*/ | ||
constructor(_ref) { | ||
@@ -144,108 +327,141 @@ let { | ||
} = _ref; | ||
this.type = type; | ||
this.data = isMinifiedEmojiList(data) ? populateMinifiedEmoji(data) : data; | ||
this.type = type; | ||
this.fallback = fallback; | ||
} | ||
this.tonelessData = this.data.filter(emoji => !emoji.tone); | ||
const fallbackEmoji = this.find(fallback); | ||
get cdn() { | ||
return "https://cdn.jsdelivr.net/npm/@svgmoji/".concat(this.name, "@").concat(this.version, "/"); | ||
if (!fallbackEmoji) { | ||
throw new Error("\u274C No emoji exists for the provided fallback value: '".concat(fallback, "'")); | ||
} | ||
this.fallback = fallbackEmoji; | ||
} | ||
/** | ||
* Get the CDN url from the provided emoji. | ||
* Get the CDN url from the provided emoji hexcode, emoticon or unicode string. | ||
*/ | ||
getUrl(emoji) { | ||
return this.getUrlFromHexcode(fromUnicodeToHexcode(emoji)); | ||
} | ||
url(code) { | ||
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
const { | ||
fallback = true | ||
} = options; | ||
const emoji = this.find(code); | ||
const fallbackUrl = fallback ? this.fallbackUrl : undefined; | ||
getUrlFromHexcode(hexcode) { | ||
if (!emoji) { | ||
return fallbackUrl; | ||
} | ||
if (this.type === SpriteCollection.All) { | ||
return "".concat(this.cdn, "/sprites/all.svg#").concat(hexcode); | ||
return "".concat(this.cdn, "/sprites/all.svg#").concat(emoji.hexcode); | ||
} | ||
if (this.type === SpriteCollection.Individual) { | ||
return "".concat(this.cdn, "/svg/").concat(hexcode, ".svg"); | ||
return "".concat(this.cdn, "/svg/").concat(emoji.hexcode, ".svg"); | ||
} | ||
const emoji = this.data.find(emoji => emoji.hexcode === hexcode); | ||
if (this.type === SpriteCollection.Group && emoji !== null && emoji !== void 0 && emoji.group) { | ||
var _groups$emoji$group; | ||
if (this.type === SpriteCollection.Group && emoji !== null && emoji !== void 0 && emoji.group) { | ||
const name = groups["".concat(emoji.group)]; | ||
return "".concat(this.cdn, "/sprites/group/").concat(name, ".svg#").concat(hexcode); | ||
const name = (_groups$emoji$group = groups[emoji.group]) !== null && _groups$emoji$group !== void 0 ? _groups$emoji$group : 'other'; | ||
return "".concat(this.cdn, "/sprites/group/").concat(name, ".svg#").concat(emoji.hexcode); | ||
} | ||
if (this.type === SpriteCollection.Subgroup && emoji !== null && emoji !== void 0 && emoji.subgroup) { | ||
const name = subgroups["".concat(emoji.subgroup)]; | ||
return "".concat(this.cdn, "/sprites/subgroup/").concat(name, ".svg#").concat(hexcode); | ||
var _subgroups$emoji$subg; | ||
const name = (_subgroups$emoji$subg = subgroups[emoji.subgroup]) !== null && _subgroups$emoji$subg !== void 0 ? _subgroups$emoji$subg : 'other'; | ||
return "".concat(this.cdn, "/sprites/subgroup/").concat(name, ".svg#").concat(emoji.hexcode); | ||
} | ||
return "".concat(this.cdn, "/svg/").concat(this.fallback, ".svg"); | ||
return fallbackUrl; | ||
} | ||
/** | ||
* Get an the emoji object of a value by it's hexcode, emoticon or unicode string. | ||
*/ | ||
} | ||
function _defineProperty(obj, key, value) { | ||
if (key in obj) { | ||
Object.defineProperty(obj, key, { | ||
value: value, | ||
enumerable: true, | ||
configurable: true, | ||
writable: true | ||
}); | ||
} else { | ||
obj[key] = value; | ||
find(code) { | ||
if (EMOTICON_REGEX.test(code)) { | ||
return this.data.find(emoji => !!emoji.emoticon && generateEmoticonPermutations(emoji.emoticon).includes(code)); | ||
} | ||
if (SHORTCODE_REGEX.test(code)) { | ||
return this.data.find(emoji => { | ||
var _emoji$shortcodes; | ||
return (_emoji$shortcodes = emoji.shortcodes) === null || _emoji$shortcodes === void 0 ? void 0 : _emoji$shortcodes.map(shortcode => ":".concat(shortcode, ":")).includes(code); | ||
}); | ||
} | ||
if (HEXCODE_REGEX.test(code)) { | ||
return this.data.find(emoji => emoji.hexcode === code); | ||
} // Assume that the string passed is a native emoji string. | ||
return this.data.find(emoji => emoji.emoji === code || emoji.text === code); | ||
} | ||
/** | ||
* Search for the nearest emoji using the `match-sorter` algorithm. | ||
*/ | ||
return obj; | ||
} | ||
function ownKeys(object, enumerableOnly) { | ||
var keys = Object.keys(object); | ||
search(query) { | ||
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
if (Object.getOwnPropertySymbols) { | ||
var symbols = Object.getOwnPropertySymbols(object); | ||
if (enumerableOnly) symbols = symbols.filter(function (sym) { | ||
return Object.getOwnPropertyDescriptor(object, sym).enumerable; | ||
const { | ||
excludeTone | ||
} = _objectSpread2(_objectSpread2({}, DEFAULT_OPTIONS), options); | ||
const data = excludeTone ? this.tonelessData : this.data; | ||
return matchSorter(data, query, { | ||
threshold: rankings.WORD_STARTS_WITH, | ||
keys: [{ | ||
threshold: rankings.STARTS_WITH, | ||
key: 'shortcodes' | ||
}, 'tags', 'annotation', item => { | ||
var _subgroups$item$subgr, _subgroups$item$subgr2; | ||
return item.subgroup ? (_subgroups$item$subgr = (_subgroups$item$subgr2 = subgroups[item.subgroup]) === null || _subgroups$item$subgr2 === void 0 ? void 0 : _subgroups$item$subgr2.split('-').join(' ')) !== null && _subgroups$item$subgr !== void 0 ? _subgroups$item$subgr : '' : ''; | ||
}, item => { | ||
var _groups$item$group$sp, _groups$item$group; | ||
return item.group ? (_groups$item$group$sp = (_groups$item$group = groups[item.group]) === null || _groups$item$group === void 0 ? void 0 : _groups$item$group.split('-').join(' ')) !== null && _groups$item$group$sp !== void 0 ? _groups$item$group$sp : '' : ''; | ||
}] | ||
}); | ||
keys.push.apply(keys, symbols); | ||
} | ||
/** | ||
* Get skins from emoji | ||
*/ | ||
return keys; | ||
} | ||
function _objectSpread2(target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i] != null ? arguments[i] : {}; | ||
getTones(emoji) { | ||
const skins = []; | ||
if (i % 2) { | ||
ownKeys(Object(source), true).forEach(function (key) { | ||
_defineProperty(target, key, source[key]); | ||
}); | ||
} else if (Object.getOwnPropertyDescriptors) { | ||
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); | ||
} else { | ||
ownKeys(Object(source)).forEach(function (key) { | ||
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); | ||
}); | ||
for (const skin of (_emoji$skins = emoji.skins) !== null && _emoji$skins !== void 0 ? _emoji$skins : []) { | ||
var _emoji$skins; | ||
const skinEmoji = this.find(skin); | ||
if (skinEmoji) { | ||
skins.push(); | ||
} | ||
} | ||
return skins; | ||
} | ||
return target; | ||
} | ||
const DEFAULT_OPTIONS = { | ||
excludeTone: true | ||
}; | ||
async function get(key) { | ||
async function runInBrowser(callback) { | ||
const { | ||
get: idbGet | ||
} = await import('idb-keyval'); | ||
return idbGet(key); | ||
} | ||
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { | ||
args[_key - 1] = arguments[_key]; | ||
} | ||
async function set(key, value) { | ||
const { | ||
set: idbSet | ||
} = await import('idb-keyval'); | ||
await idbSet(key, value); | ||
return callback(...args); | ||
} | ||
@@ -272,3 +488,3 @@ | ||
const cacheKey = "svgmoji/".concat(version, "/").concat(path); | ||
const cachedData = await get(cacheKey); // Check the cache first | ||
const cachedData = await runInBrowser(get, cacheKey); // Check the cache first | ||
@@ -292,3 +508,3 @@ if (cachedData) { | ||
try { | ||
await set(cacheKey, data); | ||
await runInBrowser(set, cacheKey, data); | ||
} catch (_unused) {// Do nothing. | ||
@@ -344,2 +560,13 @@ } | ||
/** | ||
* Throws an error if the tone is undefined. | ||
*/ | ||
function getTone(tone) { | ||
if (!tone) { | ||
throw new Error('A tone is required when using `getTone`'); | ||
} | ||
return Array.isArray(tone) ? [tone[0], tone[1]] : [tone]; | ||
} | ||
function createFlatEmoji(base, skins, tone) { | ||
@@ -349,3 +576,3 @@ const flatEmoji = _objectSpread2({}, base); | ||
if (tone) { | ||
flatEmoji.tone = Array.isArray(tone) ? [tone[0], tone[1]] : [tone]; | ||
flatEmoji.tone = getTone(tone); | ||
} | ||
@@ -359,8 +586,3 @@ | ||
} | ||
/** | ||
* The skin tone which allows a second tone for complex emoji that support multiple tones for | ||
* different characters. | ||
*/ | ||
function flattenEmojiData(data) { | ||
@@ -433,2 +655,2 @@ let shortcodeDatasets = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : []; | ||
export { Moji, SpriteCollection, fetchEmojis, fetchFromCDN, flattenEmojiData, isFlatEmoji, isFlatEmojiList, isMinifiedEmoji, isMinifiedEmojiList, joinShortcodesToEmoji, minifyEmoji, omitUndefined, populateMinifiedEmoji }; | ||
export { HEXCODE_REGEX, Moji, SpriteCollection, fetchEmojis, fetchFromCDN, flattenEmojiData, isFlatEmoji, isFlatEmojiList, isMinifiedEmoji, isMinifiedEmojiList, joinShortcodesToEmoji, minifyEmoji, omitUndefined, populateMinifiedEmoji }; |
@@ -6,32 +6,63 @@ 'use strict'; | ||
var emojibase = require('emojibase'); | ||
var groups_json = require('emojibase-data/meta/groups.json'); | ||
var omit = require('object.omit'); | ||
var matchSorter = require('match-sorter'); | ||
var EMOTICON_REGEX = require('emojibase-regex/emoticon'); | ||
var SHORTCODE_REGEX = require('emojibase-regex/shortcode'); | ||
var _objectWithoutProperties = require('@babel/runtime/helpers/objectWithoutProperties'); | ||
require('isomorphic-fetch'); | ||
var idbKeyval = require('idb-keyval'); | ||
function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; } | ||
function _interopNamespace(e) { | ||
if (e && e.__esModule) return e; | ||
var n = Object.create(null); | ||
if (e) { | ||
Object.keys(e).forEach(function (k) { | ||
if (k !== 'default') { | ||
var d = Object.getOwnPropertyDescriptor(e, k); | ||
Object.defineProperty(n, k, d.get ? d : { | ||
enumerable: true, | ||
get: function () { | ||
return e[k]; | ||
} | ||
}); | ||
} | ||
var EMOTICON_REGEX__default = /*#__PURE__*/_interopDefault(EMOTICON_REGEX); | ||
var SHORTCODE_REGEX__default = /*#__PURE__*/_interopDefault(SHORTCODE_REGEX); | ||
var _objectWithoutProperties__default = /*#__PURE__*/_interopDefault(_objectWithoutProperties); | ||
function _defineProperty(obj, key, value) { | ||
if (key in obj) { | ||
Object.defineProperty(obj, key, { | ||
value: value, | ||
enumerable: true, | ||
configurable: true, | ||
writable: true | ||
}); | ||
} else { | ||
obj[key] = value; | ||
} | ||
n['default'] = e; | ||
return Object.freeze(n); | ||
return obj; | ||
} | ||
var omit__default = /*#__PURE__*/_interopDefault(omit); | ||
var _objectWithoutProperties__default = /*#__PURE__*/_interopDefault(_objectWithoutProperties); | ||
function ownKeys(object, enumerableOnly) { | ||
var keys = Object.keys(object); | ||
if (Object.getOwnPropertySymbols) { | ||
var symbols = Object.getOwnPropertySymbols(object); | ||
if (enumerableOnly) symbols = symbols.filter(function (sym) { | ||
return Object.getOwnPropertyDescriptor(object, sym).enumerable; | ||
}); | ||
keys.push.apply(keys, symbols); | ||
} | ||
return keys; | ||
} | ||
function _objectSpread2(target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i] != null ? arguments[i] : {}; | ||
if (i % 2) { | ||
ownKeys(Object(source), true).forEach(function (key) { | ||
_defineProperty(target, key, source[key]); | ||
}); | ||
} else if (Object.getOwnPropertyDescriptors) { | ||
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); | ||
} else { | ||
ownKeys(Object(source)).forEach(function (key) { | ||
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); | ||
}); | ||
} | ||
} | ||
return target; | ||
} | ||
const SpriteCollection = { | ||
@@ -109,3 +140,3 @@ /** | ||
function omitUndefined(object) { | ||
return omit__default['default'](object, value => value !== undefined); | ||
return JSON.parse(JSON.stringify(object)); | ||
} | ||
@@ -116,3 +147,2 @@ | ||
*/ | ||
function populateMinifiedEmoji(minified) { | ||
@@ -138,2 +168,122 @@ return minified.map(emoji => omitUndefined({ | ||
/** | ||
* Simple regexp for testing if a string passed in is a hexcode. | ||
*/ | ||
const HEXCODE_REGEX = /^[\dA-Fa-f][\dA-Fa-f-]+[\dA-Fa-f]$/; | ||
const groups = ([{ | ||
"0": "smileys-emotion", | ||
"1": "people-body", | ||
"2": "component", | ||
"3": "animals-nature", | ||
"4": "food-drink", | ||
"5": "travel-places", | ||
"6": "activities", | ||
"7": "objects", | ||
"8": "symbols", | ||
"9": "flags" | ||
}][0]); | ||
const subgroups = ([{ | ||
"0": "face-smiling", | ||
"1": "face-affection", | ||
"2": "face-tongue", | ||
"3": "face-hand", | ||
"4": "face-neutral-skeptical", | ||
"5": "face-sleepy", | ||
"6": "face-unwell", | ||
"7": "face-hat", | ||
"8": "face-glasses", | ||
"9": "face-concerned", | ||
"10": "face-negative", | ||
"11": "face-costume", | ||
"12": "cat-face", | ||
"13": "monkey-face", | ||
"14": "emotion", | ||
"15": "hand-fingers-open", | ||
"16": "hand-fingers-partial", | ||
"17": "hand-single-finger", | ||
"18": "hand-fingers-closed", | ||
"19": "hands", | ||
"20": "hand-prop", | ||
"21": "body-parts", | ||
"22": "person", | ||
"23": "person-gesture", | ||
"24": "person-role", | ||
"25": "person-fantasy", | ||
"26": "person-activity", | ||
"27": "person-sport", | ||
"28": "person-resting", | ||
"29": "family", | ||
"30": "person-symbol", | ||
"31": "skin-tone", | ||
"32": "hair-style", | ||
"33": "animal-mammal", | ||
"34": "animal-bird", | ||
"35": "animal-amphibian", | ||
"36": "animal-reptile", | ||
"37": "animal-marine", | ||
"38": "animal-bug", | ||
"39": "plant-flower", | ||
"40": "plant-other", | ||
"41": "food-fruit", | ||
"42": "food-vegetable", | ||
"43": "food-prepared", | ||
"44": "food-asian", | ||
"45": "food-marine", | ||
"46": "food-sweet", | ||
"47": "drink", | ||
"48": "dishware", | ||
"49": "place-map", | ||
"50": "place-geographic", | ||
"51": "place-building", | ||
"52": "place-religious", | ||
"53": "place-other", | ||
"54": "transport-ground", | ||
"55": "transport-water", | ||
"56": "transport-air", | ||
"57": "hotel", | ||
"58": "time", | ||
"59": "sky-weather", | ||
"60": "event", | ||
"61": "award-medal", | ||
"62": "sport", | ||
"63": "game", | ||
"64": "arts-crafts", | ||
"65": "clothing", | ||
"66": "sound", | ||
"67": "music", | ||
"68": "musical-instrument", | ||
"69": "phone", | ||
"70": "computer", | ||
"71": "light-video", | ||
"72": "book-paper", | ||
"73": "money", | ||
"74": "mail", | ||
"75": "writing", | ||
"76": "office", | ||
"77": "lock", | ||
"78": "tool", | ||
"79": "science", | ||
"80": "medical", | ||
"81": "household", | ||
"82": "other-object", | ||
"83": "transport-sign", | ||
"84": "warning", | ||
"85": "arrow", | ||
"86": "religion", | ||
"87": "zodiac", | ||
"88": "av-symbol", | ||
"89": "gender", | ||
"90": "math", | ||
"91": "punctuation", | ||
"92": "currency", | ||
"93": "other-symbol", | ||
"94": "keycap", | ||
"95": "alphanum", | ||
"96": "geometric", | ||
"97": "flag", | ||
"98": "country-flag", | ||
"99": "subdivision-flag" | ||
}][0]); | ||
class Moji { | ||
@@ -153,2 +303,6 @@ /** | ||
/** | ||
* Only data without tones included. | ||
*/ | ||
/** | ||
* The type of sprite to load. | ||
@@ -158,5 +312,11 @@ */ | ||
/** | ||
* The fallback svg to use when none can be found. | ||
* The fallback emoji to use when none can be found. | ||
*/ | ||
get cdn() { | ||
return "https://cdn.jsdelivr.net/npm/@svgmoji/".concat(this.name, "@").concat(this.version, "/"); | ||
} | ||
get fallbackUrl() { | ||
return "".concat(this.cdn, "/svg/").concat(this.fallback.hexcode, ".svg"); | ||
} | ||
/** | ||
@@ -166,2 +326,4 @@ * @param data - data which is used to lookup the groups and subgroups for the emoji instance | ||
*/ | ||
constructor(_ref) { | ||
@@ -173,95 +335,135 @@ let { | ||
} = _ref; | ||
this.type = type; | ||
this.data = isMinifiedEmojiList(data) ? populateMinifiedEmoji(data) : data; | ||
this.type = type; | ||
this.fallback = fallback; | ||
} | ||
this.tonelessData = this.data.filter(emoji => !emoji.tone); | ||
const fallbackEmoji = this.find(fallback); | ||
get cdn() { | ||
return "https://cdn.jsdelivr.net/npm/@svgmoji/".concat(this.name, "@").concat(this.version, "/"); | ||
if (!fallbackEmoji) { | ||
throw new Error("\u274C No emoji exists for the provided fallback value: '".concat(fallback, "'")); | ||
} | ||
this.fallback = fallbackEmoji; | ||
} | ||
/** | ||
* Get the CDN url from the provided emoji. | ||
* Get the CDN url from the provided emoji hexcode, emoticon or unicode string. | ||
*/ | ||
getUrl(emoji) { | ||
return this.getUrlFromHexcode(emojibase.fromUnicodeToHexcode(emoji)); | ||
} | ||
url(code) { | ||
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
const { | ||
fallback = true | ||
} = options; | ||
const emoji = this.find(code); | ||
const fallbackUrl = fallback ? this.fallbackUrl : undefined; | ||
getUrlFromHexcode(hexcode) { | ||
if (!emoji) { | ||
return fallbackUrl; | ||
} | ||
if (this.type === SpriteCollection.All) { | ||
return "".concat(this.cdn, "/sprites/all.svg#").concat(hexcode); | ||
return "".concat(this.cdn, "/sprites/all.svg#").concat(emoji.hexcode); | ||
} | ||
if (this.type === SpriteCollection.Individual) { | ||
return "".concat(this.cdn, "/svg/").concat(hexcode, ".svg"); | ||
return "".concat(this.cdn, "/svg/").concat(emoji.hexcode, ".svg"); | ||
} | ||
const emoji = this.data.find(emoji => emoji.hexcode === hexcode); | ||
if (this.type === SpriteCollection.Group && emoji !== null && emoji !== void 0 && emoji.group) { | ||
var _groups$emoji$group; | ||
if (this.type === SpriteCollection.Group && emoji !== null && emoji !== void 0 && emoji.group) { | ||
const name = groups_json.groups["".concat(emoji.group)]; | ||
return "".concat(this.cdn, "/sprites/group/").concat(name, ".svg#").concat(hexcode); | ||
const name = (_groups$emoji$group = groups[emoji.group]) !== null && _groups$emoji$group !== void 0 ? _groups$emoji$group : 'other'; | ||
return "".concat(this.cdn, "/sprites/group/").concat(name, ".svg#").concat(emoji.hexcode); | ||
} | ||
if (this.type === SpriteCollection.Subgroup && emoji !== null && emoji !== void 0 && emoji.subgroup) { | ||
const name = groups_json.subgroups["".concat(emoji.subgroup)]; | ||
return "".concat(this.cdn, "/sprites/subgroup/").concat(name, ".svg#").concat(hexcode); | ||
var _subgroups$emoji$subg; | ||
const name = (_subgroups$emoji$subg = subgroups[emoji.subgroup]) !== null && _subgroups$emoji$subg !== void 0 ? _subgroups$emoji$subg : 'other'; | ||
return "".concat(this.cdn, "/sprites/subgroup/").concat(name, ".svg#").concat(emoji.hexcode); | ||
} | ||
return "".concat(this.cdn, "/svg/").concat(this.fallback, ".svg"); | ||
return fallbackUrl; | ||
} | ||
/** | ||
* Get an the emoji object of a value by it's hexcode, emoticon or unicode string. | ||
*/ | ||
} | ||
function _defineProperty(obj, key, value) { | ||
if (key in obj) { | ||
Object.defineProperty(obj, key, { | ||
value: value, | ||
enumerable: true, | ||
configurable: true, | ||
writable: true | ||
}); | ||
} else { | ||
obj[key] = value; | ||
find(code) { | ||
if (EMOTICON_REGEX__default['default'].test(code)) { | ||
return this.data.find(emoji => !!emoji.emoticon && emojibase.generateEmoticonPermutations(emoji.emoticon).includes(code)); | ||
} | ||
if (SHORTCODE_REGEX__default['default'].test(code)) { | ||
return this.data.find(emoji => { | ||
var _emoji$shortcodes; | ||
return (_emoji$shortcodes = emoji.shortcodes) === null || _emoji$shortcodes === void 0 ? void 0 : _emoji$shortcodes.map(shortcode => ":".concat(shortcode, ":")).includes(code); | ||
}); | ||
} | ||
if (HEXCODE_REGEX.test(code)) { | ||
return this.data.find(emoji => emoji.hexcode === code); | ||
} // Assume that the string passed is a native emoji string. | ||
return this.data.find(emoji => emoji.emoji === code || emoji.text === code); | ||
} | ||
/** | ||
* Search for the nearest emoji using the `match-sorter` algorithm. | ||
*/ | ||
return obj; | ||
} | ||
function ownKeys(object, enumerableOnly) { | ||
var keys = Object.keys(object); | ||
search(query) { | ||
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
if (Object.getOwnPropertySymbols) { | ||
var symbols = Object.getOwnPropertySymbols(object); | ||
if (enumerableOnly) symbols = symbols.filter(function (sym) { | ||
return Object.getOwnPropertyDescriptor(object, sym).enumerable; | ||
const { | ||
excludeTone | ||
} = _objectSpread2(_objectSpread2({}, DEFAULT_OPTIONS), options); | ||
const data = excludeTone ? this.tonelessData : this.data; | ||
return matchSorter.matchSorter(data, query, { | ||
threshold: matchSorter.rankings.WORD_STARTS_WITH, | ||
keys: [{ | ||
threshold: matchSorter.rankings.STARTS_WITH, | ||
key: 'shortcodes' | ||
}, 'tags', 'annotation', item => { | ||
var _subgroups$item$subgr, _subgroups$item$subgr2; | ||
return item.subgroup ? (_subgroups$item$subgr = (_subgroups$item$subgr2 = subgroups[item.subgroup]) === null || _subgroups$item$subgr2 === void 0 ? void 0 : _subgroups$item$subgr2.split('-').join(' ')) !== null && _subgroups$item$subgr !== void 0 ? _subgroups$item$subgr : '' : ''; | ||
}, item => { | ||
var _groups$item$group$sp, _groups$item$group; | ||
return item.group ? (_groups$item$group$sp = (_groups$item$group = groups[item.group]) === null || _groups$item$group === void 0 ? void 0 : _groups$item$group.split('-').join(' ')) !== null && _groups$item$group$sp !== void 0 ? _groups$item$group$sp : '' : ''; | ||
}] | ||
}); | ||
keys.push.apply(keys, symbols); | ||
} | ||
/** | ||
* Get skins from emoji | ||
*/ | ||
return keys; | ||
} | ||
function _objectSpread2(target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i] != null ? arguments[i] : {}; | ||
getTones(emoji) { | ||
const skins = []; | ||
if (i % 2) { | ||
ownKeys(Object(source), true).forEach(function (key) { | ||
_defineProperty(target, key, source[key]); | ||
}); | ||
} else if (Object.getOwnPropertyDescriptors) { | ||
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); | ||
} else { | ||
ownKeys(Object(source)).forEach(function (key) { | ||
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); | ||
}); | ||
for (const skin of (_emoji$skins = emoji.skins) !== null && _emoji$skins !== void 0 ? _emoji$skins : []) { | ||
var _emoji$skins; | ||
const skinEmoji = this.find(skin); | ||
if (skinEmoji) { | ||
skins.push(); | ||
} | ||
} | ||
return skins; | ||
} | ||
return target; | ||
} | ||
const DEFAULT_OPTIONS = { | ||
excludeTone: true | ||
}; | ||
async function get(key) { | ||
async function runInBrowser(callback) { | ||
if (typeof document === 'undefined') { | ||
@@ -271,17 +473,7 @@ return; | ||
const { | ||
get: idbGet | ||
} = await Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require('idb-keyval')); }); | ||
return idbGet(key); | ||
} | ||
async function set(key, value) { | ||
if (typeof document === 'undefined') { | ||
return; | ||
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { | ||
args[_key - 1] = arguments[_key]; | ||
} | ||
const { | ||
set: idbSet | ||
} = await Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require('idb-keyval')); }); | ||
await idbSet(key, value); | ||
return callback(...args); | ||
} | ||
@@ -308,3 +500,3 @@ | ||
const cacheKey = "svgmoji/".concat(version, "/").concat(path); | ||
const cachedData = await get(cacheKey); // Check the cache first | ||
const cachedData = await runInBrowser(idbKeyval.get, cacheKey); // Check the cache first | ||
@@ -328,3 +520,3 @@ if (cachedData) { | ||
try { | ||
await set(cacheKey, data); | ||
await runInBrowser(idbKeyval.set, cacheKey, data); | ||
} catch (_unused) {// Do nothing. | ||
@@ -380,2 +572,13 @@ } | ||
/** | ||
* Throws an error if the tone is undefined. | ||
*/ | ||
function getTone(tone) { | ||
if (!tone) { | ||
throw new Error('A tone is required when using `getTone`'); | ||
} | ||
return Array.isArray(tone) ? [tone[0], tone[1]] : [tone]; | ||
} | ||
function createFlatEmoji(base, skins, tone) { | ||
@@ -385,3 +588,3 @@ const flatEmoji = _objectSpread2({}, base); | ||
if (tone) { | ||
flatEmoji.tone = Array.isArray(tone) ? [tone[0], tone[1]] : [tone]; | ||
flatEmoji.tone = getTone(tone); | ||
} | ||
@@ -395,8 +598,3 @@ | ||
} | ||
/** | ||
* The skin tone which allows a second tone for complex emoji that support multiple tones for | ||
* different characters. | ||
*/ | ||
function flattenEmojiData(data) { | ||
@@ -487,2 +685,15 @@ let shortcodeDatasets = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : []; | ||
}); | ||
Object.defineProperty(exports, 'EMOTICON_REGEX', { | ||
enumerable: true, | ||
get: function () { | ||
return EMOTICON_REGEX__default['default']; | ||
} | ||
}); | ||
Object.defineProperty(exports, 'SHORTCODE_REGEX', { | ||
enumerable: true, | ||
get: function () { | ||
return SHORTCODE_REGEX__default['default']; | ||
} | ||
}); | ||
exports.HEXCODE_REGEX = HEXCODE_REGEX; | ||
exports.Moji = Moji; | ||
@@ -489,0 +700,0 @@ exports.SpriteCollection = SpriteCollection; |
@@ -6,32 +6,63 @@ 'use strict'; | ||
var emojibase = require('emojibase'); | ||
var groups_json = require('emojibase-data/meta/groups.json'); | ||
var omit = require('object.omit'); | ||
var matchSorter = require('match-sorter'); | ||
var EMOTICON_REGEX = require('emojibase-regex/emoticon'); | ||
var SHORTCODE_REGEX = require('emojibase-regex/shortcode'); | ||
var _objectWithoutProperties = require('@babel/runtime/helpers/objectWithoutProperties'); | ||
require('isomorphic-fetch'); | ||
var idbKeyval = require('idb-keyval'); | ||
function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; } | ||
function _interopNamespace(e) { | ||
if (e && e.__esModule) return e; | ||
var n = Object.create(null); | ||
if (e) { | ||
Object.keys(e).forEach(function (k) { | ||
if (k !== 'default') { | ||
var d = Object.getOwnPropertyDescriptor(e, k); | ||
Object.defineProperty(n, k, d.get ? d : { | ||
enumerable: true, | ||
get: function () { | ||
return e[k]; | ||
} | ||
}); | ||
} | ||
var EMOTICON_REGEX__default = /*#__PURE__*/_interopDefault(EMOTICON_REGEX); | ||
var SHORTCODE_REGEX__default = /*#__PURE__*/_interopDefault(SHORTCODE_REGEX); | ||
var _objectWithoutProperties__default = /*#__PURE__*/_interopDefault(_objectWithoutProperties); | ||
function _defineProperty(obj, key, value) { | ||
if (key in obj) { | ||
Object.defineProperty(obj, key, { | ||
value: value, | ||
enumerable: true, | ||
configurable: true, | ||
writable: true | ||
}); | ||
} else { | ||
obj[key] = value; | ||
} | ||
n['default'] = e; | ||
return Object.freeze(n); | ||
return obj; | ||
} | ||
var omit__default = /*#__PURE__*/_interopDefault(omit); | ||
var _objectWithoutProperties__default = /*#__PURE__*/_interopDefault(_objectWithoutProperties); | ||
function ownKeys(object, enumerableOnly) { | ||
var keys = Object.keys(object); | ||
if (Object.getOwnPropertySymbols) { | ||
var symbols = Object.getOwnPropertySymbols(object); | ||
if (enumerableOnly) symbols = symbols.filter(function (sym) { | ||
return Object.getOwnPropertyDescriptor(object, sym).enumerable; | ||
}); | ||
keys.push.apply(keys, symbols); | ||
} | ||
return keys; | ||
} | ||
function _objectSpread2(target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i] != null ? arguments[i] : {}; | ||
if (i % 2) { | ||
ownKeys(Object(source), true).forEach(function (key) { | ||
_defineProperty(target, key, source[key]); | ||
}); | ||
} else if (Object.getOwnPropertyDescriptors) { | ||
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); | ||
} else { | ||
ownKeys(Object(source)).forEach(function (key) { | ||
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); | ||
}); | ||
} | ||
} | ||
return target; | ||
} | ||
const SpriteCollection = { | ||
@@ -109,3 +140,3 @@ /** | ||
function omitUndefined(object) { | ||
return omit__default['default'](object, value => value !== undefined); | ||
return JSON.parse(JSON.stringify(object)); | ||
} | ||
@@ -116,3 +147,2 @@ | ||
*/ | ||
function populateMinifiedEmoji(minified) { | ||
@@ -138,2 +168,122 @@ return minified.map(emoji => omitUndefined({ | ||
/** | ||
* Simple regexp for testing if a string passed in is a hexcode. | ||
*/ | ||
const HEXCODE_REGEX = /^[\dA-Fa-f][\dA-Fa-f-]+[\dA-Fa-f]$/; | ||
const groups = ([{ | ||
"0": "smileys-emotion", | ||
"1": "people-body", | ||
"2": "component", | ||
"3": "animals-nature", | ||
"4": "food-drink", | ||
"5": "travel-places", | ||
"6": "activities", | ||
"7": "objects", | ||
"8": "symbols", | ||
"9": "flags" | ||
}][0]); | ||
const subgroups = ([{ | ||
"0": "face-smiling", | ||
"1": "face-affection", | ||
"2": "face-tongue", | ||
"3": "face-hand", | ||
"4": "face-neutral-skeptical", | ||
"5": "face-sleepy", | ||
"6": "face-unwell", | ||
"7": "face-hat", | ||
"8": "face-glasses", | ||
"9": "face-concerned", | ||
"10": "face-negative", | ||
"11": "face-costume", | ||
"12": "cat-face", | ||
"13": "monkey-face", | ||
"14": "emotion", | ||
"15": "hand-fingers-open", | ||
"16": "hand-fingers-partial", | ||
"17": "hand-single-finger", | ||
"18": "hand-fingers-closed", | ||
"19": "hands", | ||
"20": "hand-prop", | ||
"21": "body-parts", | ||
"22": "person", | ||
"23": "person-gesture", | ||
"24": "person-role", | ||
"25": "person-fantasy", | ||
"26": "person-activity", | ||
"27": "person-sport", | ||
"28": "person-resting", | ||
"29": "family", | ||
"30": "person-symbol", | ||
"31": "skin-tone", | ||
"32": "hair-style", | ||
"33": "animal-mammal", | ||
"34": "animal-bird", | ||
"35": "animal-amphibian", | ||
"36": "animal-reptile", | ||
"37": "animal-marine", | ||
"38": "animal-bug", | ||
"39": "plant-flower", | ||
"40": "plant-other", | ||
"41": "food-fruit", | ||
"42": "food-vegetable", | ||
"43": "food-prepared", | ||
"44": "food-asian", | ||
"45": "food-marine", | ||
"46": "food-sweet", | ||
"47": "drink", | ||
"48": "dishware", | ||
"49": "place-map", | ||
"50": "place-geographic", | ||
"51": "place-building", | ||
"52": "place-religious", | ||
"53": "place-other", | ||
"54": "transport-ground", | ||
"55": "transport-water", | ||
"56": "transport-air", | ||
"57": "hotel", | ||
"58": "time", | ||
"59": "sky-weather", | ||
"60": "event", | ||
"61": "award-medal", | ||
"62": "sport", | ||
"63": "game", | ||
"64": "arts-crafts", | ||
"65": "clothing", | ||
"66": "sound", | ||
"67": "music", | ||
"68": "musical-instrument", | ||
"69": "phone", | ||
"70": "computer", | ||
"71": "light-video", | ||
"72": "book-paper", | ||
"73": "money", | ||
"74": "mail", | ||
"75": "writing", | ||
"76": "office", | ||
"77": "lock", | ||
"78": "tool", | ||
"79": "science", | ||
"80": "medical", | ||
"81": "household", | ||
"82": "other-object", | ||
"83": "transport-sign", | ||
"84": "warning", | ||
"85": "arrow", | ||
"86": "religion", | ||
"87": "zodiac", | ||
"88": "av-symbol", | ||
"89": "gender", | ||
"90": "math", | ||
"91": "punctuation", | ||
"92": "currency", | ||
"93": "other-symbol", | ||
"94": "keycap", | ||
"95": "alphanum", | ||
"96": "geometric", | ||
"97": "flag", | ||
"98": "country-flag", | ||
"99": "subdivision-flag" | ||
}][0]); | ||
class Moji { | ||
@@ -153,2 +303,6 @@ /** | ||
/** | ||
* Only data without tones included. | ||
*/ | ||
/** | ||
* The type of sprite to load. | ||
@@ -158,5 +312,11 @@ */ | ||
/** | ||
* The fallback svg to use when none can be found. | ||
* The fallback emoji to use when none can be found. | ||
*/ | ||
get cdn() { | ||
return "https://cdn.jsdelivr.net/npm/@svgmoji/".concat(this.name, "@").concat(this.version, "/"); | ||
} | ||
get fallbackUrl() { | ||
return "".concat(this.cdn, "/svg/").concat(this.fallback.hexcode, ".svg"); | ||
} | ||
/** | ||
@@ -166,2 +326,4 @@ * @param data - data which is used to lookup the groups and subgroups for the emoji instance | ||
*/ | ||
constructor(_ref) { | ||
@@ -173,95 +335,135 @@ let { | ||
} = _ref; | ||
this.type = type; | ||
this.data = isMinifiedEmojiList(data) ? populateMinifiedEmoji(data) : data; | ||
this.type = type; | ||
this.fallback = fallback; | ||
} | ||
this.tonelessData = this.data.filter(emoji => !emoji.tone); | ||
const fallbackEmoji = this.find(fallback); | ||
get cdn() { | ||
return "https://cdn.jsdelivr.net/npm/@svgmoji/".concat(this.name, "@").concat(this.version, "/"); | ||
if (!fallbackEmoji) { | ||
throw new Error("\u274C No emoji exists for the provided fallback value: '".concat(fallback, "'")); | ||
} | ||
this.fallback = fallbackEmoji; | ||
} | ||
/** | ||
* Get the CDN url from the provided emoji. | ||
* Get the CDN url from the provided emoji hexcode, emoticon or unicode string. | ||
*/ | ||
getUrl(emoji) { | ||
return this.getUrlFromHexcode(emojibase.fromUnicodeToHexcode(emoji)); | ||
} | ||
url(code) { | ||
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
const { | ||
fallback = true | ||
} = options; | ||
const emoji = this.find(code); | ||
const fallbackUrl = fallback ? this.fallbackUrl : undefined; | ||
getUrlFromHexcode(hexcode) { | ||
if (!emoji) { | ||
return fallbackUrl; | ||
} | ||
if (this.type === SpriteCollection.All) { | ||
return "".concat(this.cdn, "/sprites/all.svg#").concat(hexcode); | ||
return "".concat(this.cdn, "/sprites/all.svg#").concat(emoji.hexcode); | ||
} | ||
if (this.type === SpriteCollection.Individual) { | ||
return "".concat(this.cdn, "/svg/").concat(hexcode, ".svg"); | ||
return "".concat(this.cdn, "/svg/").concat(emoji.hexcode, ".svg"); | ||
} | ||
const emoji = this.data.find(emoji => emoji.hexcode === hexcode); | ||
if (this.type === SpriteCollection.Group && emoji !== null && emoji !== void 0 && emoji.group) { | ||
var _groups$emoji$group; | ||
if (this.type === SpriteCollection.Group && emoji !== null && emoji !== void 0 && emoji.group) { | ||
const name = groups_json.groups["".concat(emoji.group)]; | ||
return "".concat(this.cdn, "/sprites/group/").concat(name, ".svg#").concat(hexcode); | ||
const name = (_groups$emoji$group = groups[emoji.group]) !== null && _groups$emoji$group !== void 0 ? _groups$emoji$group : 'other'; | ||
return "".concat(this.cdn, "/sprites/group/").concat(name, ".svg#").concat(emoji.hexcode); | ||
} | ||
if (this.type === SpriteCollection.Subgroup && emoji !== null && emoji !== void 0 && emoji.subgroup) { | ||
const name = groups_json.subgroups["".concat(emoji.subgroup)]; | ||
return "".concat(this.cdn, "/sprites/subgroup/").concat(name, ".svg#").concat(hexcode); | ||
var _subgroups$emoji$subg; | ||
const name = (_subgroups$emoji$subg = subgroups[emoji.subgroup]) !== null && _subgroups$emoji$subg !== void 0 ? _subgroups$emoji$subg : 'other'; | ||
return "".concat(this.cdn, "/sprites/subgroup/").concat(name, ".svg#").concat(emoji.hexcode); | ||
} | ||
return "".concat(this.cdn, "/svg/").concat(this.fallback, ".svg"); | ||
return fallbackUrl; | ||
} | ||
/** | ||
* Get an the emoji object of a value by it's hexcode, emoticon or unicode string. | ||
*/ | ||
} | ||
function _defineProperty(obj, key, value) { | ||
if (key in obj) { | ||
Object.defineProperty(obj, key, { | ||
value: value, | ||
enumerable: true, | ||
configurable: true, | ||
writable: true | ||
}); | ||
} else { | ||
obj[key] = value; | ||
find(code) { | ||
if (EMOTICON_REGEX__default['default'].test(code)) { | ||
return this.data.find(emoji => !!emoji.emoticon && emojibase.generateEmoticonPermutations(emoji.emoticon).includes(code)); | ||
} | ||
if (SHORTCODE_REGEX__default['default'].test(code)) { | ||
return this.data.find(emoji => { | ||
var _emoji$shortcodes; | ||
return (_emoji$shortcodes = emoji.shortcodes) === null || _emoji$shortcodes === void 0 ? void 0 : _emoji$shortcodes.map(shortcode => ":".concat(shortcode, ":")).includes(code); | ||
}); | ||
} | ||
if (HEXCODE_REGEX.test(code)) { | ||
return this.data.find(emoji => emoji.hexcode === code); | ||
} // Assume that the string passed is a native emoji string. | ||
return this.data.find(emoji => emoji.emoji === code || emoji.text === code); | ||
} | ||
/** | ||
* Search for the nearest emoji using the `match-sorter` algorithm. | ||
*/ | ||
return obj; | ||
} | ||
function ownKeys(object, enumerableOnly) { | ||
var keys = Object.keys(object); | ||
search(query) { | ||
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
if (Object.getOwnPropertySymbols) { | ||
var symbols = Object.getOwnPropertySymbols(object); | ||
if (enumerableOnly) symbols = symbols.filter(function (sym) { | ||
return Object.getOwnPropertyDescriptor(object, sym).enumerable; | ||
const { | ||
excludeTone | ||
} = _objectSpread2(_objectSpread2({}, DEFAULT_OPTIONS), options); | ||
const data = excludeTone ? this.tonelessData : this.data; | ||
return matchSorter.matchSorter(data, query, { | ||
threshold: matchSorter.rankings.WORD_STARTS_WITH, | ||
keys: [{ | ||
threshold: matchSorter.rankings.STARTS_WITH, | ||
key: 'shortcodes' | ||
}, 'tags', 'annotation', item => { | ||
var _subgroups$item$subgr, _subgroups$item$subgr2; | ||
return item.subgroup ? (_subgroups$item$subgr = (_subgroups$item$subgr2 = subgroups[item.subgroup]) === null || _subgroups$item$subgr2 === void 0 ? void 0 : _subgroups$item$subgr2.split('-').join(' ')) !== null && _subgroups$item$subgr !== void 0 ? _subgroups$item$subgr : '' : ''; | ||
}, item => { | ||
var _groups$item$group$sp, _groups$item$group; | ||
return item.group ? (_groups$item$group$sp = (_groups$item$group = groups[item.group]) === null || _groups$item$group === void 0 ? void 0 : _groups$item$group.split('-').join(' ')) !== null && _groups$item$group$sp !== void 0 ? _groups$item$group$sp : '' : ''; | ||
}] | ||
}); | ||
keys.push.apply(keys, symbols); | ||
} | ||
/** | ||
* Get skins from emoji | ||
*/ | ||
return keys; | ||
} | ||
function _objectSpread2(target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i] != null ? arguments[i] : {}; | ||
getTones(emoji) { | ||
const skins = []; | ||
if (i % 2) { | ||
ownKeys(Object(source), true).forEach(function (key) { | ||
_defineProperty(target, key, source[key]); | ||
}); | ||
} else if (Object.getOwnPropertyDescriptors) { | ||
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); | ||
} else { | ||
ownKeys(Object(source)).forEach(function (key) { | ||
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); | ||
}); | ||
for (const skin of (_emoji$skins = emoji.skins) !== null && _emoji$skins !== void 0 ? _emoji$skins : []) { | ||
var _emoji$skins; | ||
const skinEmoji = this.find(skin); | ||
if (skinEmoji) { | ||
skins.push(); | ||
} | ||
} | ||
return skins; | ||
} | ||
return target; | ||
} | ||
const DEFAULT_OPTIONS = { | ||
excludeTone: true | ||
}; | ||
async function get(key) { | ||
async function runInBrowser(callback) { | ||
if (typeof document === 'undefined') { | ||
@@ -271,17 +473,7 @@ return; | ||
const { | ||
get: idbGet | ||
} = await Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require('idb-keyval')); }); | ||
return idbGet(key); | ||
} | ||
async function set(key, value) { | ||
if (typeof document === 'undefined') { | ||
return; | ||
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { | ||
args[_key - 1] = arguments[_key]; | ||
} | ||
const { | ||
set: idbSet | ||
} = await Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require('idb-keyval')); }); | ||
await idbSet(key, value); | ||
return callback(...args); | ||
} | ||
@@ -298,3 +490,3 @@ | ||
const cacheKey = "svgmoji/".concat(version, "/").concat(path); | ||
const cachedData = await get(cacheKey); // Check the cache first | ||
const cachedData = await runInBrowser(idbKeyval.get, cacheKey); // Check the cache first | ||
@@ -318,3 +510,3 @@ if (cachedData) { | ||
try { | ||
await set(cacheKey, data); | ||
await runInBrowser(idbKeyval.set, cacheKey, data); | ||
} catch (_unused) {// Do nothing. | ||
@@ -370,2 +562,13 @@ } | ||
/** | ||
* Throws an error if the tone is undefined. | ||
*/ | ||
function getTone(tone) { | ||
if (!tone) { | ||
throw new Error('A tone is required when using `getTone`'); | ||
} | ||
return Array.isArray(tone) ? [tone[0], tone[1]] : [tone]; | ||
} | ||
function createFlatEmoji(base, skins, tone) { | ||
@@ -375,3 +578,3 @@ const flatEmoji = _objectSpread2({}, base); | ||
if (tone) { | ||
flatEmoji.tone = Array.isArray(tone) ? [tone[0], tone[1]] : [tone]; | ||
flatEmoji.tone = getTone(tone); | ||
} | ||
@@ -385,8 +588,3 @@ | ||
} | ||
/** | ||
* The skin tone which allows a second tone for complex emoji that support multiple tones for | ||
* different characters. | ||
*/ | ||
function flattenEmojiData(data) { | ||
@@ -477,2 +675,15 @@ let shortcodeDatasets = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : []; | ||
}); | ||
Object.defineProperty(exports, 'EMOTICON_REGEX', { | ||
enumerable: true, | ||
get: function () { | ||
return EMOTICON_REGEX__default['default']; | ||
} | ||
}); | ||
Object.defineProperty(exports, 'SHORTCODE_REGEX', { | ||
enumerable: true, | ||
get: function () { | ||
return SHORTCODE_REGEX__default['default']; | ||
} | ||
}); | ||
exports.HEXCODE_REGEX = HEXCODE_REGEX; | ||
exports.Moji = Moji; | ||
@@ -479,0 +690,0 @@ exports.SpriteCollection = SpriteCollection; |
@@ -1,8 +0,60 @@ | ||
import { fromUnicodeToHexcode, NON_LATIN_LOCALES } from 'emojibase'; | ||
import { generateEmoticonPermutations, NON_LATIN_LOCALES } from 'emojibase'; | ||
export { fromUnicodeToHexcode, generateEmoticonPermutations, stripHexcode } from 'emojibase'; | ||
import { groups, subgroups } from 'emojibase-data/meta/groups.json'; | ||
import omit from 'object.omit'; | ||
import { matchSorter, rankings } from 'match-sorter'; | ||
import EMOTICON_REGEX from 'emojibase-regex/emoticon'; | ||
export { default as EMOTICON_REGEX } from 'emojibase-regex/emoticon'; | ||
import SHORTCODE_REGEX from 'emojibase-regex/shortcode'; | ||
export { default as SHORTCODE_REGEX } from 'emojibase-regex/shortcode'; | ||
import _objectWithoutProperties from '@babel/runtime/helpers/esm/objectWithoutProperties'; | ||
import 'isomorphic-fetch'; | ||
import { set, get } from 'idb-keyval'; | ||
function _defineProperty(obj, key, value) { | ||
if (key in obj) { | ||
Object.defineProperty(obj, key, { | ||
value: value, | ||
enumerable: true, | ||
configurable: true, | ||
writable: true | ||
}); | ||
} else { | ||
obj[key] = value; | ||
} | ||
return obj; | ||
} | ||
function ownKeys(object, enumerableOnly) { | ||
var keys = Object.keys(object); | ||
if (Object.getOwnPropertySymbols) { | ||
var symbols = Object.getOwnPropertySymbols(object); | ||
if (enumerableOnly) symbols = symbols.filter(function (sym) { | ||
return Object.getOwnPropertyDescriptor(object, sym).enumerable; | ||
}); | ||
keys.push.apply(keys, symbols); | ||
} | ||
return keys; | ||
} | ||
function _objectSpread2(target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i] != null ? arguments[i] : {}; | ||
if (i % 2) { | ||
ownKeys(Object(source), true).forEach(function (key) { | ||
_defineProperty(target, key, source[key]); | ||
}); | ||
} else if (Object.getOwnPropertyDescriptors) { | ||
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); | ||
} else { | ||
ownKeys(Object(source)).forEach(function (key) { | ||
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); | ||
}); | ||
} | ||
} | ||
return target; | ||
} | ||
const SpriteCollection = { | ||
@@ -80,3 +132,3 @@ /** | ||
function omitUndefined(object) { | ||
return omit(object, value => value !== undefined); | ||
return JSON.parse(JSON.stringify(object)); | ||
} | ||
@@ -87,3 +139,2 @@ | ||
*/ | ||
function populateMinifiedEmoji(minified) { | ||
@@ -109,2 +160,122 @@ return minified.map(emoji => omitUndefined({ | ||
/** | ||
* Simple regexp for testing if a string passed in is a hexcode. | ||
*/ | ||
const HEXCODE_REGEX = /^[\dA-Fa-f][\dA-Fa-f-]+[\dA-Fa-f]$/; | ||
const groups = ([{ | ||
"0": "smileys-emotion", | ||
"1": "people-body", | ||
"2": "component", | ||
"3": "animals-nature", | ||
"4": "food-drink", | ||
"5": "travel-places", | ||
"6": "activities", | ||
"7": "objects", | ||
"8": "symbols", | ||
"9": "flags" | ||
}][0]); | ||
const subgroups = ([{ | ||
"0": "face-smiling", | ||
"1": "face-affection", | ||
"2": "face-tongue", | ||
"3": "face-hand", | ||
"4": "face-neutral-skeptical", | ||
"5": "face-sleepy", | ||
"6": "face-unwell", | ||
"7": "face-hat", | ||
"8": "face-glasses", | ||
"9": "face-concerned", | ||
"10": "face-negative", | ||
"11": "face-costume", | ||
"12": "cat-face", | ||
"13": "monkey-face", | ||
"14": "emotion", | ||
"15": "hand-fingers-open", | ||
"16": "hand-fingers-partial", | ||
"17": "hand-single-finger", | ||
"18": "hand-fingers-closed", | ||
"19": "hands", | ||
"20": "hand-prop", | ||
"21": "body-parts", | ||
"22": "person", | ||
"23": "person-gesture", | ||
"24": "person-role", | ||
"25": "person-fantasy", | ||
"26": "person-activity", | ||
"27": "person-sport", | ||
"28": "person-resting", | ||
"29": "family", | ||
"30": "person-symbol", | ||
"31": "skin-tone", | ||
"32": "hair-style", | ||
"33": "animal-mammal", | ||
"34": "animal-bird", | ||
"35": "animal-amphibian", | ||
"36": "animal-reptile", | ||
"37": "animal-marine", | ||
"38": "animal-bug", | ||
"39": "plant-flower", | ||
"40": "plant-other", | ||
"41": "food-fruit", | ||
"42": "food-vegetable", | ||
"43": "food-prepared", | ||
"44": "food-asian", | ||
"45": "food-marine", | ||
"46": "food-sweet", | ||
"47": "drink", | ||
"48": "dishware", | ||
"49": "place-map", | ||
"50": "place-geographic", | ||
"51": "place-building", | ||
"52": "place-religious", | ||
"53": "place-other", | ||
"54": "transport-ground", | ||
"55": "transport-water", | ||
"56": "transport-air", | ||
"57": "hotel", | ||
"58": "time", | ||
"59": "sky-weather", | ||
"60": "event", | ||
"61": "award-medal", | ||
"62": "sport", | ||
"63": "game", | ||
"64": "arts-crafts", | ||
"65": "clothing", | ||
"66": "sound", | ||
"67": "music", | ||
"68": "musical-instrument", | ||
"69": "phone", | ||
"70": "computer", | ||
"71": "light-video", | ||
"72": "book-paper", | ||
"73": "money", | ||
"74": "mail", | ||
"75": "writing", | ||
"76": "office", | ||
"77": "lock", | ||
"78": "tool", | ||
"79": "science", | ||
"80": "medical", | ||
"81": "household", | ||
"82": "other-object", | ||
"83": "transport-sign", | ||
"84": "warning", | ||
"85": "arrow", | ||
"86": "religion", | ||
"87": "zodiac", | ||
"88": "av-symbol", | ||
"89": "gender", | ||
"90": "math", | ||
"91": "punctuation", | ||
"92": "currency", | ||
"93": "other-symbol", | ||
"94": "keycap", | ||
"95": "alphanum", | ||
"96": "geometric", | ||
"97": "flag", | ||
"98": "country-flag", | ||
"99": "subdivision-flag" | ||
}][0]); | ||
class Moji { | ||
@@ -124,2 +295,6 @@ /** | ||
/** | ||
* Only data without tones included. | ||
*/ | ||
/** | ||
* The type of sprite to load. | ||
@@ -129,5 +304,11 @@ */ | ||
/** | ||
* The fallback svg to use when none can be found. | ||
* The fallback emoji to use when none can be found. | ||
*/ | ||
get cdn() { | ||
return "https://cdn.jsdelivr.net/npm/@svgmoji/".concat(this.name, "@").concat(this.version, "/"); | ||
} | ||
get fallbackUrl() { | ||
return "".concat(this.cdn, "/svg/").concat(this.fallback.hexcode, ".svg"); | ||
} | ||
/** | ||
@@ -137,2 +318,4 @@ * @param data - data which is used to lookup the groups and subgroups for the emoji instance | ||
*/ | ||
constructor(_ref) { | ||
@@ -144,95 +327,135 @@ let { | ||
} = _ref; | ||
this.type = type; | ||
this.data = isMinifiedEmojiList(data) ? populateMinifiedEmoji(data) : data; | ||
this.type = type; | ||
this.fallback = fallback; | ||
} | ||
this.tonelessData = this.data.filter(emoji => !emoji.tone); | ||
const fallbackEmoji = this.find(fallback); | ||
get cdn() { | ||
return "https://cdn.jsdelivr.net/npm/@svgmoji/".concat(this.name, "@").concat(this.version, "/"); | ||
if (!fallbackEmoji) { | ||
throw new Error("\u274C No emoji exists for the provided fallback value: '".concat(fallback, "'")); | ||
} | ||
this.fallback = fallbackEmoji; | ||
} | ||
/** | ||
* Get the CDN url from the provided emoji. | ||
* Get the CDN url from the provided emoji hexcode, emoticon or unicode string. | ||
*/ | ||
getUrl(emoji) { | ||
return this.getUrlFromHexcode(fromUnicodeToHexcode(emoji)); | ||
} | ||
url(code) { | ||
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
const { | ||
fallback = true | ||
} = options; | ||
const emoji = this.find(code); | ||
const fallbackUrl = fallback ? this.fallbackUrl : undefined; | ||
getUrlFromHexcode(hexcode) { | ||
if (!emoji) { | ||
return fallbackUrl; | ||
} | ||
if (this.type === SpriteCollection.All) { | ||
return "".concat(this.cdn, "/sprites/all.svg#").concat(hexcode); | ||
return "".concat(this.cdn, "/sprites/all.svg#").concat(emoji.hexcode); | ||
} | ||
if (this.type === SpriteCollection.Individual) { | ||
return "".concat(this.cdn, "/svg/").concat(hexcode, ".svg"); | ||
return "".concat(this.cdn, "/svg/").concat(emoji.hexcode, ".svg"); | ||
} | ||
const emoji = this.data.find(emoji => emoji.hexcode === hexcode); | ||
if (this.type === SpriteCollection.Group && emoji !== null && emoji !== void 0 && emoji.group) { | ||
var _groups$emoji$group; | ||
if (this.type === SpriteCollection.Group && emoji !== null && emoji !== void 0 && emoji.group) { | ||
const name = groups["".concat(emoji.group)]; | ||
return "".concat(this.cdn, "/sprites/group/").concat(name, ".svg#").concat(hexcode); | ||
const name = (_groups$emoji$group = groups[emoji.group]) !== null && _groups$emoji$group !== void 0 ? _groups$emoji$group : 'other'; | ||
return "".concat(this.cdn, "/sprites/group/").concat(name, ".svg#").concat(emoji.hexcode); | ||
} | ||
if (this.type === SpriteCollection.Subgroup && emoji !== null && emoji !== void 0 && emoji.subgroup) { | ||
const name = subgroups["".concat(emoji.subgroup)]; | ||
return "".concat(this.cdn, "/sprites/subgroup/").concat(name, ".svg#").concat(hexcode); | ||
var _subgroups$emoji$subg; | ||
const name = (_subgroups$emoji$subg = subgroups[emoji.subgroup]) !== null && _subgroups$emoji$subg !== void 0 ? _subgroups$emoji$subg : 'other'; | ||
return "".concat(this.cdn, "/sprites/subgroup/").concat(name, ".svg#").concat(emoji.hexcode); | ||
} | ||
return "".concat(this.cdn, "/svg/").concat(this.fallback, ".svg"); | ||
return fallbackUrl; | ||
} | ||
/** | ||
* Get an the emoji object of a value by it's hexcode, emoticon or unicode string. | ||
*/ | ||
} | ||
function _defineProperty(obj, key, value) { | ||
if (key in obj) { | ||
Object.defineProperty(obj, key, { | ||
value: value, | ||
enumerable: true, | ||
configurable: true, | ||
writable: true | ||
}); | ||
} else { | ||
obj[key] = value; | ||
find(code) { | ||
if (EMOTICON_REGEX.test(code)) { | ||
return this.data.find(emoji => !!emoji.emoticon && generateEmoticonPermutations(emoji.emoticon).includes(code)); | ||
} | ||
if (SHORTCODE_REGEX.test(code)) { | ||
return this.data.find(emoji => { | ||
var _emoji$shortcodes; | ||
return (_emoji$shortcodes = emoji.shortcodes) === null || _emoji$shortcodes === void 0 ? void 0 : _emoji$shortcodes.map(shortcode => ":".concat(shortcode, ":")).includes(code); | ||
}); | ||
} | ||
if (HEXCODE_REGEX.test(code)) { | ||
return this.data.find(emoji => emoji.hexcode === code); | ||
} // Assume that the string passed is a native emoji string. | ||
return this.data.find(emoji => emoji.emoji === code || emoji.text === code); | ||
} | ||
/** | ||
* Search for the nearest emoji using the `match-sorter` algorithm. | ||
*/ | ||
return obj; | ||
} | ||
function ownKeys(object, enumerableOnly) { | ||
var keys = Object.keys(object); | ||
search(query) { | ||
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
if (Object.getOwnPropertySymbols) { | ||
var symbols = Object.getOwnPropertySymbols(object); | ||
if (enumerableOnly) symbols = symbols.filter(function (sym) { | ||
return Object.getOwnPropertyDescriptor(object, sym).enumerable; | ||
const { | ||
excludeTone | ||
} = _objectSpread2(_objectSpread2({}, DEFAULT_OPTIONS), options); | ||
const data = excludeTone ? this.tonelessData : this.data; | ||
return matchSorter(data, query, { | ||
threshold: rankings.WORD_STARTS_WITH, | ||
keys: [{ | ||
threshold: rankings.STARTS_WITH, | ||
key: 'shortcodes' | ||
}, 'tags', 'annotation', item => { | ||
var _subgroups$item$subgr, _subgroups$item$subgr2; | ||
return item.subgroup ? (_subgroups$item$subgr = (_subgroups$item$subgr2 = subgroups[item.subgroup]) === null || _subgroups$item$subgr2 === void 0 ? void 0 : _subgroups$item$subgr2.split('-').join(' ')) !== null && _subgroups$item$subgr !== void 0 ? _subgroups$item$subgr : '' : ''; | ||
}, item => { | ||
var _groups$item$group$sp, _groups$item$group; | ||
return item.group ? (_groups$item$group$sp = (_groups$item$group = groups[item.group]) === null || _groups$item$group === void 0 ? void 0 : _groups$item$group.split('-').join(' ')) !== null && _groups$item$group$sp !== void 0 ? _groups$item$group$sp : '' : ''; | ||
}] | ||
}); | ||
keys.push.apply(keys, symbols); | ||
} | ||
/** | ||
* Get skins from emoji | ||
*/ | ||
return keys; | ||
} | ||
function _objectSpread2(target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i] != null ? arguments[i] : {}; | ||
getTones(emoji) { | ||
const skins = []; | ||
if (i % 2) { | ||
ownKeys(Object(source), true).forEach(function (key) { | ||
_defineProperty(target, key, source[key]); | ||
}); | ||
} else if (Object.getOwnPropertyDescriptors) { | ||
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); | ||
} else { | ||
ownKeys(Object(source)).forEach(function (key) { | ||
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); | ||
}); | ||
for (const skin of (_emoji$skins = emoji.skins) !== null && _emoji$skins !== void 0 ? _emoji$skins : []) { | ||
var _emoji$skins; | ||
const skinEmoji = this.find(skin); | ||
if (skinEmoji) { | ||
skins.push(); | ||
} | ||
} | ||
return skins; | ||
} | ||
return target; | ||
} | ||
const DEFAULT_OPTIONS = { | ||
excludeTone: true | ||
}; | ||
async function get(key) { | ||
async function runInBrowser(callback) { | ||
if (typeof document === 'undefined') { | ||
@@ -242,17 +465,7 @@ return; | ||
const { | ||
get: idbGet | ||
} = await import('idb-keyval'); | ||
return idbGet(key); | ||
} | ||
async function set(key, value) { | ||
if (typeof document === 'undefined') { | ||
return; | ||
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { | ||
args[_key - 1] = arguments[_key]; | ||
} | ||
const { | ||
set: idbSet | ||
} = await import('idb-keyval'); | ||
await idbSet(key, value); | ||
return callback(...args); | ||
} | ||
@@ -279,3 +492,3 @@ | ||
const cacheKey = "svgmoji/".concat(version, "/").concat(path); | ||
const cachedData = await get(cacheKey); // Check the cache first | ||
const cachedData = await runInBrowser(get, cacheKey); // Check the cache first | ||
@@ -299,3 +512,3 @@ if (cachedData) { | ||
try { | ||
await set(cacheKey, data); | ||
await runInBrowser(set, cacheKey, data); | ||
} catch (_unused) {// Do nothing. | ||
@@ -351,2 +564,13 @@ } | ||
/** | ||
* Throws an error if the tone is undefined. | ||
*/ | ||
function getTone(tone) { | ||
if (!tone) { | ||
throw new Error('A tone is required when using `getTone`'); | ||
} | ||
return Array.isArray(tone) ? [tone[0], tone[1]] : [tone]; | ||
} | ||
function createFlatEmoji(base, skins, tone) { | ||
@@ -356,3 +580,3 @@ const flatEmoji = _objectSpread2({}, base); | ||
if (tone) { | ||
flatEmoji.tone = Array.isArray(tone) ? [tone[0], tone[1]] : [tone]; | ||
flatEmoji.tone = getTone(tone); | ||
} | ||
@@ -366,8 +590,3 @@ | ||
} | ||
/** | ||
* The skin tone which allows a second tone for complex emoji that support multiple tones for | ||
* different characters. | ||
*/ | ||
function flattenEmojiData(data) { | ||
@@ -440,2 +659,2 @@ let shortcodeDatasets = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : []; | ||
export { Moji, SpriteCollection, fetchEmojis, fetchFromCDN, flattenEmojiData, isFlatEmoji, isFlatEmojiList, isMinifiedEmoji, isMinifiedEmojiList, joinShortcodesToEmoji, minifyEmoji, omitUndefined, populateMinifiedEmoji }; | ||
export { HEXCODE_REGEX, Moji, SpriteCollection, fetchEmojis, fetchFromCDN, flattenEmojiData, isFlatEmoji, isFlatEmojiList, isMinifiedEmoji, isMinifiedEmojiList, joinShortcodesToEmoji, minifyEmoji, omitUndefined, populateMinifiedEmoji }; |
{ | ||
"name": "@svgmoji/core", | ||
"version": "0.2.0", | ||
"version": "1.0.0", | ||
"description": "Utilities forked from emojibase for working with svgmoji", | ||
@@ -38,10 +38,11 @@ "keywords": [ | ||
"@babel/runtime": "^7.12.5", | ||
"@types/object.omit": "^3.0.0", | ||
"emojibase": "^5.1.0", | ||
"emojibase-data": "^6.1.0", | ||
"emojibase-regex": "^5.1.0", | ||
"idb-keyval": "^5.0.1", | ||
"isomorphic-fetch": "^3.0.0", | ||
"object.omit": "^3.0.0", | ||
"match-sorter": "^6.1.0", | ||
"type-fest": "^0.20.2" | ||
}, | ||
"devDependencies": { | ||
"emojibase-data": "^6.1.0" | ||
}, | ||
"publishConfig": { | ||
@@ -48,0 +49,0 @@ "access": "public" |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
100301
6
24
3080
1
1
+ Addedemojibase-regex@^5.1.0
+ Addedmatch-sorter@^6.1.0
+ Addedemojibase-regex@5.1.3(transitive)
+ Addedmatch-sorter@6.4.0(transitive)
+ Addedremove-accents@0.5.0(transitive)
- Removed@types/object.omit@^3.0.0
- Removedemojibase-data@^6.1.0
- Removedisomorphic-fetch@^3.0.0
- Removedobject.omit@^3.0.0
- Removed@types/object.omit@3.0.3(transitive)
- Removedemojibase-data@6.2.0(transitive)
- Removedis-extendable@1.0.1(transitive)
- Removedis-plain-object@2.0.4(transitive)
- Removedisobject@3.0.1(transitive)
- Removedisomorphic-fetch@3.0.0(transitive)
- Removednode-fetch@2.7.0(transitive)
- Removedobject.omit@3.0.0(transitive)
- Removedtr46@0.0.3(transitive)
- Removedwebidl-conversions@3.0.1(transitive)
- Removedwhatwg-fetch@3.6.20(transitive)
- Removedwhatwg-url@5.0.0(transitive)