emoji-picker-react 5.1.0 → 5.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -7,10 +7,10 @@ const skinToneVariations = [
7
7
  SkinTones.MEDIUM_DARK,
8
8
  SkinTones.DARK,
9
9
  ];
10
- export const skinTonesNamed = Object.entries(SkinTones).reduce((acc, [key, value]) => {
10
+ export const skinTonesNamed = /* @__PURE__ */ (() => Object.entries(SkinTones).reduce((acc, [key, value]) => {
11
11
  acc[value] = key;
12
12
  return acc;
13
- }, {});
13
+ }, {}))();
14
14
  export const skinTonesMapped = skinToneVariations.reduce((mapped, skinTone) => Object.assign(mapped, {
15
15
  [skinTone]: skinTone,
16
16
  }), {});
@@ -0,0 +1,144 @@
1
+ // src/data/defaultEmojiData.ts
2
+ var registered = null;
3
+
4
+ function registerDefaultEmojiData(data) {
5
+ registered = data;
6
+ }
7
+
8
+ function getRegisteredDefaultEmojiData() {
9
+ return registered;
10
+ }
11
+
12
+ var EMPTY_EMOJI_DATA = Object.freeze({
13
+ categories: {},
14
+ emojis: {}
15
+ });
16
+
17
+ function defaultEmojiDataOrEmpty() {
18
+ return registered ?? EMPTY_EMOJI_DATA;
19
+ }
20
+
21
+ var pending = null;
22
+
23
+ function loadDefaultEmojiData() {
24
+ return registered ? Promise.resolve(registered) : (pending || (pending = import("./emojis-VTEL5M5C.mjs").then((module => {
25
+ const data = module.default ?? module;
26
+ return registered = registered ?? data;
27
+ })).catch((error => {
28
+ throw pending = null, error;
29
+ }))), pending);
30
+ }
31
+
32
+ // src/dataUtils/parseNativeEmoji.ts
33
+ function parseNativeEmoji(unified) {
34
+ return String.fromCodePoint(...unified.split("-").map((hex => parseInt(hex, 16))));
35
+ }
36
+
37
+ // src/data-core/prepare.ts
38
+ var coreCache = /* @__PURE__ */ new WeakMap, prepareCount = 0;
39
+
40
+ function normalizeUnified(input) {
41
+ return input.trim().toLowerCase();
42
+ }
43
+
44
+ function normalizeQuery(input) {
45
+ return input && "string" == typeof input ? input.trim().toLowerCase() : "";
46
+ }
47
+
48
+ function readStringArray(raw) {
49
+ return Array.isArray(raw) ? raw.filter((value => "string" == typeof value)).map((value => value.toLowerCase())) : [];
50
+ }
51
+
52
+ function appendEntry(byUnified, byCharMutable, records, entry) {
53
+ const rawUnified = entry.u;
54
+ if ("string" != typeof rawUnified || 0 === rawUnified.length) return;
55
+ const unified = rawUnified.toLowerCase();
56
+ if (byUnified.has(unified)) return;
57
+ const names = readStringArray(entry.n), variations = readStringArray(entry.v), addedIn = String(entry.a ?? ""), info = Object.freeze({
58
+ unified,
59
+ emoji: parseNativeEmoji(unified),
60
+ name: names[names.length - 1] || "",
61
+ names: Object.freeze(names),
62
+ variations: Object.freeze(variations),
63
+ addedIn
64
+ });
65
+ records.push(info), byUnified.set(unified, info);
66
+ for (const variation of info.variations) byUnified.has(variation) || byUnified.set(variation, info);
67
+ indexCharBucket(byCharMutable, names, info);
68
+ }
69
+
70
+ function indexCharBucket(byCharMutable, names, info) {
71
+ for (const char of names.join("")) {
72
+ const bucket = byCharMutable.get(char);
73
+ bucket ? bucket[bucket.length - 1] !== info && bucket.push(info) : byCharMutable.set(char, [ info ]);
74
+ }
75
+ }
76
+
77
+ function getPreparedCore(emojiData) {
78
+ const source = emojiData ?? defaultEmojiDataOrEmpty(), cached = coreCache.get(source);
79
+ if (cached) return cached;
80
+ prepareCount += 1;
81
+ const byUnified = /* @__PURE__ */ new Map, byCharMutable = /* @__PURE__ */ new Map, records = [], groups = source.emojis ?? {};
82
+ for (const key of Object.keys(groups)) {
83
+ const list = groups[key] ?? [];
84
+ for (const entry of list) appendEntry(byUnified, byCharMutable, records, entry);
85
+ }
86
+ byCharMutable.forEach(Object.freeze);
87
+ const core = {
88
+ records,
89
+ byUnified,
90
+ byChar: byCharMutable,
91
+ queryMemo: /* @__PURE__ */ new Map
92
+ };
93
+ return coreCache.set(source, core), core;
94
+ }
95
+
96
+ // src/data-core/search.ts
97
+ var EMPTY_RESULTS = Object.freeze([]), MAX_QUERY_MEMO_SIZE = 500;
98
+
99
+ function memoizeQuery(core, normalized, results) {
100
+ const memo = core.queryMemo;
101
+ if (memo.has(normalized)) memo.delete(normalized); else if (memo.size >= MAX_QUERY_MEMO_SIZE) {
102
+ const oldest = memo.keys().next();
103
+ oldest.done || memo.delete(oldest.value);
104
+ }
105
+ memo.set(normalized, results);
106
+ }
107
+
108
+ function smallestCandidateBucket(core, normalized) {
109
+ let smallest = core.records;
110
+ for (const char of Array.from(normalized)) {
111
+ const bucket = core.byChar.get(char);
112
+ if (!bucket) return EMPTY_RESULTS;
113
+ bucket.length < smallest.length && (smallest = bucket);
114
+ }
115
+ return smallest;
116
+ }
117
+
118
+ function getEmojiByUnified(unified, options) {
119
+ if (!unified || "string" != typeof unified) return;
120
+ const normalized = normalizeUnified(unified);
121
+ return normalized ? getPreparedCore(options?.emojiData).byUnified.get(normalized) : void 0;
122
+ }
123
+
124
+ function searchEmojis(query, options) {
125
+ const normalized = normalizeQuery(query);
126
+ if (!normalized) return EMPTY_RESULTS;
127
+ const core = getPreparedCore(options?.emojiData), memoized = core.queryMemo.get(normalized);
128
+ if (memoized) return memoizeQuery(core, normalized, memoized), Object.freeze([ ...memoized ]);
129
+ if (1 === normalized.length) {
130
+ const bucket = core.byChar.get(normalized) ?? EMPTY_RESULTS;
131
+ return memoizeQuery(core, normalized, bucket), Object.freeze([ ...bucket ]);
132
+ }
133
+ const matches = [];
134
+ for (const record of smallestCandidateBucket(core, normalized)) {
135
+ const names = record.names;
136
+ for (let i = 0; i < names.length; i += 1) if (names[i].includes(normalized)) {
137
+ matches.push(record);
138
+ break;
139
+ }
140
+ }
141
+ return memoizeQuery(core, normalized, matches), Object.freeze([ ...matches ]);
142
+ }
143
+
144
+ export { registerDefaultEmojiData, getRegisteredDefaultEmojiData, EMPTY_EMOJI_DATA, defaultEmojiDataOrEmpty, loadDefaultEmojiData, parseNativeEmoji, normalizeQuery, getPreparedCore, getEmojiByUnified, searchEmojis };