advanced-chat-kai 0.1.0

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.
@@ -0,0 +1,1422 @@
1
+ function P(t) {
2
+ if (typeof t != "string" || !t)
3
+ throw new Error("expected a non-empty string, got: " + t);
4
+ }
5
+ function Y(t) {
6
+ if (typeof t != "number")
7
+ throw new Error("expected a number, got: " + t);
8
+ }
9
+ const ut = 1, dt = 1, L = "emoji", $ = "keyvalue", le = "favorites", ft = "tokens", _e = "tokens", mt = "unicode", Ie = "count", pt = "group", ht = "order", Ae = "group-order", ie = "eTag", W = "url", ye = "skinTone", M = "readonly", ue = "readwrite", Le = "skinUnicodes", gt = "skinUnicodes", bt = "https://cdn.jsdelivr.net/npm/emoji-picker-element-data@^1/en/emojibase/data.json", yt = "en";
10
+ function kt(t, e) {
11
+ const n = /* @__PURE__ */ new Set(), i = [];
12
+ for (const r of t) {
13
+ const o = e(r);
14
+ n.has(o) || (n.add(o), i.push(r));
15
+ }
16
+ return i;
17
+ }
18
+ function ke(t) {
19
+ return kt(t, (e) => e.unicode);
20
+ }
21
+ function Et(t) {
22
+ function e(n, i, r) {
23
+ const o = i ? t.createObjectStore(n, { keyPath: i }) : t.createObjectStore(n);
24
+ if (r)
25
+ for (const [a, [d, m]] of Object.entries(r))
26
+ o.createIndex(a, d, { multiEntry: m });
27
+ return o;
28
+ }
29
+ e($), e(
30
+ L,
31
+ /* keyPath */
32
+ mt,
33
+ {
34
+ [_e]: [
35
+ ft,
36
+ /* multiEntry */
37
+ !0
38
+ ],
39
+ [Ae]: [[pt, ht]],
40
+ [Le]: [
41
+ gt,
42
+ /* multiEntry */
43
+ !0
44
+ ]
45
+ }
46
+ ), e(le, void 0, {
47
+ [Ie]: [""]
48
+ });
49
+ }
50
+ const re = {}, G = {}, V = {};
51
+ function Oe(t, e, n) {
52
+ n.onerror = () => e(n.error), n.onblocked = () => e(new Error("IDB blocked")), n.onsuccess = () => t(n.result);
53
+ }
54
+ async function vt(t) {
55
+ const e = await new Promise((n, i) => {
56
+ const r = indexedDB.open(t, ut);
57
+ re[t] = r, r.onupgradeneeded = (o) => {
58
+ o.oldVersion < dt && Et(r.result);
59
+ }, Oe(n, i, r);
60
+ });
61
+ return e.onclose = () => de(t), e;
62
+ }
63
+ function wt(t) {
64
+ return G[t] || (G[t] = vt(t)), G[t];
65
+ }
66
+ function I(t, e, n, i) {
67
+ return new Promise((r, o) => {
68
+ const a = t.transaction(e, n, { durability: "relaxed" }), d = typeof e == "string" ? a.objectStore(e) : e.map((c) => a.objectStore(c));
69
+ let m;
70
+ i(d, a, (c) => {
71
+ m = c;
72
+ }), a.oncomplete = () => r(m), a.onerror = () => o(a.error);
73
+ });
74
+ }
75
+ function de(t) {
76
+ const e = re[t], n = e && e.result;
77
+ if (n) {
78
+ n.close();
79
+ const i = V[t];
80
+ if (i)
81
+ for (const r of i)
82
+ r();
83
+ }
84
+ delete re[t], delete G[t], delete V[t];
85
+ }
86
+ function Tt(t) {
87
+ return new Promise((e, n) => {
88
+ de(t);
89
+ const i = indexedDB.deleteDatabase(t);
90
+ Oe(e, n, i);
91
+ });
92
+ }
93
+ function jt(t, e) {
94
+ let n = V[t];
95
+ n || (n = V[t] = []), n.push(e);
96
+ }
97
+ const St = /* @__PURE__ */ new Set([
98
+ ":D",
99
+ "XD",
100
+ ":'D",
101
+ "O:)",
102
+ ":X",
103
+ ":P",
104
+ ";P",
105
+ "XP",
106
+ ":L",
107
+ ":Z",
108
+ ":j",
109
+ "8D",
110
+ "XO",
111
+ "8)",
112
+ ":B",
113
+ ":O",
114
+ ":S",
115
+ ":'o",
116
+ "Dx",
117
+ "X(",
118
+ "D:",
119
+ ":C",
120
+ ">0)",
121
+ ":3",
122
+ "</3",
123
+ "<3",
124
+ "\\M/",
125
+ ":E",
126
+ "8#"
127
+ ]);
128
+ function D(t) {
129
+ return t.split(/[\s_]+/).map((e) => !e.match(/\w/) || St.has(e) ? e.toLowerCase() : e.replace(/[)(:,]/g, "").replace(/’/g, "'").toLowerCase()).filter(Boolean);
130
+ }
131
+ const xt = 2;
132
+ function De(t) {
133
+ return t.filter(Boolean).map((e) => e.toLowerCase()).filter((e) => e.length >= xt);
134
+ }
135
+ function Ct(t) {
136
+ return t.map(({ annotation: n, emoticon: i, group: r, order: o, shortcodes: a, skins: d, tags: m, emoji: c, version: u }) => {
137
+ const p = [...new Set(
138
+ De([
139
+ ...(a || []).map(D).flat(),
140
+ ...(m || []).map(D).flat(),
141
+ ...D(n),
142
+ i
143
+ ])
144
+ )].sort(), f = {
145
+ annotation: n,
146
+ group: r,
147
+ order: o,
148
+ tags: m,
149
+ tokens: p,
150
+ unicode: c,
151
+ version: u
152
+ };
153
+ if (i && (f.emoticon = i), a && (f.shortcodes = a), d) {
154
+ f.skinTones = [], f.skinUnicodes = [], f.skinVersions = [];
155
+ for (const { tone: b, emoji: T, version: j } of d)
156
+ f.skinTones.push(b), f.skinUnicodes.push(T), f.skinVersions.push(j);
157
+ }
158
+ return f;
159
+ });
160
+ }
161
+ function $e(t, e, n, i) {
162
+ t[e](n).onsuccess = (r) => i && i(r.target.result);
163
+ }
164
+ function A(t, e, n) {
165
+ $e(t, "get", e, n);
166
+ }
167
+ function Me(t, e, n) {
168
+ $e(t, "getAll", e, n);
169
+ }
170
+ function fe(t) {
171
+ t.commit && t.commit();
172
+ }
173
+ function _t(t, e) {
174
+ let n = t[0];
175
+ for (let i = 1; i < t.length; i++) {
176
+ const r = t[i];
177
+ e(n) > e(r) && (n = r);
178
+ }
179
+ return n;
180
+ }
181
+ function Fe(t, e) {
182
+ const n = _t(t, (r) => r.length), i = [];
183
+ for (const r of n)
184
+ t.some((o) => o.findIndex((a) => e(a) === e(r)) === -1) || i.push(r);
185
+ return i;
186
+ }
187
+ async function It(t) {
188
+ return !await me(t, $, W);
189
+ }
190
+ async function At(t, e, n) {
191
+ const [i, r] = await Promise.all([ie, W].map((o) => me(t, $, o)));
192
+ return i === n && r === e;
193
+ }
194
+ async function Lt(t, e) {
195
+ return I(t, L, M, (i, r, o) => {
196
+ let a;
197
+ const d = () => {
198
+ i.getAll(a && IDBKeyRange.lowerBound(a, !0), 50).onsuccess = (m) => {
199
+ const c = m.target.result;
200
+ for (const u of c)
201
+ if (a = u.unicode, e(u))
202
+ return o(u);
203
+ if (c.length < 50)
204
+ return o();
205
+ d();
206
+ };
207
+ };
208
+ d();
209
+ });
210
+ }
211
+ async function Be(t, e, n, i) {
212
+ try {
213
+ const r = Ct(e);
214
+ await I(t, [L, $], ue, ([o, a], d) => {
215
+ let m, c, u = 0;
216
+ function p() {
217
+ ++u === 2 && f();
218
+ }
219
+ function f() {
220
+ if (!(m === i && c === n)) {
221
+ o.clear();
222
+ for (const b of r)
223
+ o.put(b);
224
+ a.put(i, ie), a.put(n, W), fe(d);
225
+ }
226
+ }
227
+ A(a, ie, (b) => {
228
+ m = b, p();
229
+ }), A(a, W, (b) => {
230
+ c = b, p();
231
+ });
232
+ });
233
+ } finally {
234
+ }
235
+ }
236
+ async function Ot(t, e) {
237
+ return I(t, L, M, (n, i, r) => {
238
+ const o = IDBKeyRange.bound([e, 0], [e + 1, 0], !1, !0);
239
+ Me(n.index(Ae), o, r);
240
+ });
241
+ }
242
+ async function Re(t, e) {
243
+ const n = De(D(e));
244
+ return n.length ? I(t, L, M, (i, r, o) => {
245
+ const a = [], d = () => {
246
+ a.length === n.length && m();
247
+ }, m = () => {
248
+ const c = Fe(a, (u) => u.unicode);
249
+ o(c.sort((u, p) => u.order < p.order ? -1 : 1));
250
+ };
251
+ for (let c = 0; c < n.length; c++) {
252
+ const u = n[c], p = c === n.length - 1 ? IDBKeyRange.bound(u, u + "￿", !1, !0) : IDBKeyRange.only(u);
253
+ Me(i.index(_e), p, (f) => {
254
+ a.push(f), d();
255
+ });
256
+ }
257
+ }) : [];
258
+ }
259
+ async function Dt(t, e) {
260
+ const n = await Re(t, e);
261
+ return n.length ? n.filter((i) => (i.shortcodes || []).map((o) => o.toLowerCase()).includes(e.toLowerCase()))[0] || null : await Lt(t, (r) => (r.shortcodes || []).includes(e.toLowerCase())) || null;
262
+ }
263
+ async function $t(t, e) {
264
+ return I(t, L, M, (n, i, r) => A(n, e, (o) => {
265
+ if (o)
266
+ return r(o);
267
+ A(n.index(Le), e, (a) => r(a || null));
268
+ }));
269
+ }
270
+ function me(t, e, n) {
271
+ return I(t, e, M, (i, r, o) => A(i, n, o));
272
+ }
273
+ function Mt(t, e, n, i) {
274
+ return I(t, e, ue, (r, o) => {
275
+ r.put(i, n), fe(o);
276
+ });
277
+ }
278
+ function Ft(t, e) {
279
+ return I(t, le, ue, (n, i) => A(n, e, (r) => {
280
+ n.put((r || 0) + 1, e), fe(i);
281
+ }));
282
+ }
283
+ function Bt(t, e, n) {
284
+ return n === 0 ? [] : I(t, [le, L], M, ([i, r], o, a) => {
285
+ const d = [];
286
+ i.index(Ie).openCursor(void 0, "prev").onsuccess = (m) => {
287
+ const c = m.target.result;
288
+ if (!c)
289
+ return a(d);
290
+ function u(b) {
291
+ if (d.push(b), d.length === n)
292
+ return a(d);
293
+ c.continue();
294
+ }
295
+ const p = c.primaryKey, f = e.byName(p);
296
+ if (f)
297
+ return u(f);
298
+ A(r, p, (b) => {
299
+ if (b)
300
+ return u(b);
301
+ c.continue();
302
+ });
303
+ };
304
+ });
305
+ }
306
+ const z = "";
307
+ function Rt(t, e) {
308
+ const n = /* @__PURE__ */ new Map();
309
+ for (const r of t) {
310
+ const o = e(r);
311
+ for (const a of o) {
312
+ let d = n;
313
+ for (let c = 0; c < a.length; c++) {
314
+ const u = a.charAt(c);
315
+ let p = d.get(u);
316
+ p || (p = /* @__PURE__ */ new Map(), d.set(u, p)), d = p;
317
+ }
318
+ let m = d.get(z);
319
+ m || (m = [], d.set(z, m)), m.push(r);
320
+ }
321
+ }
322
+ return (r, o) => {
323
+ let a = n;
324
+ for (let c = 0; c < r.length; c++) {
325
+ const u = r.charAt(c), p = a.get(u);
326
+ if (p)
327
+ a = p;
328
+ else
329
+ return [];
330
+ }
331
+ if (o)
332
+ return a.get(z) || [];
333
+ const d = [], m = [a];
334
+ for (; m.length; ) {
335
+ const u = [...m.shift().entries()].sort((p, f) => p[0] < f[0] ? -1 : 1);
336
+ for (const [p, f] of u)
337
+ p === z ? d.push(...f) : m.push(f);
338
+ }
339
+ return d;
340
+ };
341
+ }
342
+ const Nt = [
343
+ "name",
344
+ "url"
345
+ ];
346
+ function Pt(t) {
347
+ const e = t && Array.isArray(t), n = e && t.length && (!t[0] || Nt.some((i) => !(i in t[0])));
348
+ if (!e || n)
349
+ throw new Error("Custom emojis are in the wrong format");
350
+ }
351
+ function Ee(t) {
352
+ Pt(t);
353
+ const e = (f, b) => f.name.toLowerCase() < b.name.toLowerCase() ? -1 : 1, n = t.sort(e), r = Rt(t, (f) => {
354
+ const b = /* @__PURE__ */ new Set();
355
+ if (f.shortcodes)
356
+ for (const T of f.shortcodes)
357
+ for (const j of D(T))
358
+ b.add(j);
359
+ return b;
360
+ }), o = (f) => r(f, !0), a = (f) => r(f, !1), d = (f) => {
361
+ const b = D(f), T = b.map((j, x) => (x < b.length - 1 ? o : a)(j));
362
+ return Fe(T, (j) => j.name).sort(e);
363
+ }, m = /* @__PURE__ */ new Map(), c = /* @__PURE__ */ new Map();
364
+ for (const f of t) {
365
+ c.set(f.name.toLowerCase(), f);
366
+ for (const b of f.shortcodes || [])
367
+ m.set(b.toLowerCase(), f);
368
+ }
369
+ return {
370
+ all: n,
371
+ search: d,
372
+ byShortcode: (f) => m.get(f.toLowerCase()),
373
+ byName: (f) => c.get(f.toLowerCase())
374
+ };
375
+ }
376
+ const zt = typeof wrappedJSObject < "u";
377
+ function B(t) {
378
+ if (!t)
379
+ return t;
380
+ if (zt && (t = structuredClone(t)), delete t.tokens, t.skinTones) {
381
+ const e = t.skinTones.length;
382
+ t.skins = Array(e);
383
+ for (let n = 0; n < e; n++)
384
+ t.skins[n] = {
385
+ tone: t.skinTones[n],
386
+ unicode: t.skinUnicodes[n],
387
+ version: t.skinVersions[n]
388
+ };
389
+ delete t.skinTones, delete t.skinUnicodes, delete t.skinVersions;
390
+ }
391
+ return t;
392
+ }
393
+ function Ne(t) {
394
+ t || console.warn("emoji-picker-element is more efficient if the dataSource server exposes an ETag header.");
395
+ }
396
+ const Ut = [
397
+ "annotation",
398
+ "emoji",
399
+ "group",
400
+ "order",
401
+ "version"
402
+ ];
403
+ function Gt(t) {
404
+ if (!t || !Array.isArray(t) || !t[0] || typeof t[0] != "object" || Ut.some((e) => !(e in t[0])))
405
+ throw new Error("Emoji data is in the wrong format");
406
+ }
407
+ function Pe(t, e) {
408
+ if (Math.floor(t.status / 100) !== 2)
409
+ throw new Error("Failed to fetch: " + e + ": " + t.status);
410
+ }
411
+ async function Kt(t) {
412
+ const e = await fetch(t, { method: "HEAD" });
413
+ Pe(e, t);
414
+ const n = e.headers.get("etag");
415
+ return Ne(n), n;
416
+ }
417
+ async function se(t) {
418
+ const e = await fetch(t);
419
+ Pe(e, t);
420
+ const n = e.headers.get("etag");
421
+ Ne(n);
422
+ const i = await e.json();
423
+ return Gt(i), [n, i];
424
+ }
425
+ function Wt(t) {
426
+ for (var e = "", n = new Uint8Array(t), i = n.byteLength, r = -1; ++r < i; )
427
+ e += String.fromCharCode(n[r]);
428
+ return e;
429
+ }
430
+ function Vt(t) {
431
+ for (var e = t.length, n = new ArrayBuffer(e), i = new Uint8Array(n), r = -1; ++r < e; )
432
+ i[r] = t.charCodeAt(r);
433
+ return n;
434
+ }
435
+ async function ze(t) {
436
+ const e = JSON.stringify(t);
437
+ let n = Vt(e);
438
+ const i = await crypto.subtle.digest("SHA-1", n), r = Wt(i);
439
+ return btoa(r);
440
+ }
441
+ async function Ht(t, e) {
442
+ let n, i = await Kt(e);
443
+ if (!i) {
444
+ const r = await se(e);
445
+ i = r[0], n = r[1], i || (i = await ze(n));
446
+ }
447
+ await At(t, e, i) || (n || (n = (await se(e))[1]), await Be(t, n, e, i));
448
+ }
449
+ async function qt(t, e) {
450
+ let [n, i] = await se(e);
451
+ n || (n = await ze(i)), await Be(t, i, e, n);
452
+ }
453
+ async function Xt(t, e) {
454
+ try {
455
+ await Ht(t, e);
456
+ } catch (n) {
457
+ if (n.name !== "InvalidStateError")
458
+ throw n;
459
+ }
460
+ }
461
+ class Yt {
462
+ constructor({ dataSource: e = bt, locale: n = yt, customEmoji: i = [] } = {}) {
463
+ this.dataSource = e, this.locale = n, this._dbName = `emoji-picker-element-${this.locale}`, this._db = void 0, this._lazyUpdate = void 0, this._custom = Ee(i), this._clear = this._clear.bind(this), this._ready = this._init();
464
+ }
465
+ async _init() {
466
+ const e = this._db = await wt(this._dbName);
467
+ jt(this._dbName, this._clear);
468
+ const n = this.dataSource;
469
+ await It(e) ? await qt(e, n) : this._lazyUpdate = Xt(e, n);
470
+ }
471
+ async ready() {
472
+ const e = async () => (this._ready || (this._ready = this._init()), this._ready);
473
+ await e(), this._db || await e();
474
+ }
475
+ async getEmojiByGroup(e) {
476
+ return Y(e), await this.ready(), ke(await Ot(this._db, e)).map(B);
477
+ }
478
+ async getEmojiBySearchQuery(e) {
479
+ P(e), await this.ready();
480
+ const n = this._custom.search(e), i = ke(await Re(this._db, e)).map(B);
481
+ return [
482
+ ...n,
483
+ ...i
484
+ ];
485
+ }
486
+ async getEmojiByShortcode(e) {
487
+ P(e), await this.ready();
488
+ const n = this._custom.byShortcode(e);
489
+ return n || B(await Dt(this._db, e));
490
+ }
491
+ async getEmojiByUnicodeOrName(e) {
492
+ P(e), await this.ready();
493
+ const n = this._custom.byName(e);
494
+ return n || B(await $t(this._db, e));
495
+ }
496
+ async getPreferredSkinTone() {
497
+ return await this.ready(), await me(this._db, $, ye) || 0;
498
+ }
499
+ async setPreferredSkinTone(e) {
500
+ return Y(e), await this.ready(), Mt(this._db, $, ye, e);
501
+ }
502
+ async incrementFavoriteEmojiCount(e) {
503
+ return P(e), await this.ready(), Ft(this._db, e);
504
+ }
505
+ async getTopFavoriteEmoji(e) {
506
+ return Y(e), await this.ready(), (await Bt(this._db, this._custom, e)).map(B);
507
+ }
508
+ set customEmoji(e) {
509
+ this._custom = Ee(e);
510
+ }
511
+ get customEmoji() {
512
+ return this._custom.all;
513
+ }
514
+ async _shutdown() {
515
+ await this.ready();
516
+ try {
517
+ await this._lazyUpdate;
518
+ } catch {
519
+ }
520
+ }
521
+ // clear references to IDB, e.g. during a close event
522
+ _clear() {
523
+ this._db = this._ready = this._lazyUpdate = void 0;
524
+ }
525
+ async close() {
526
+ await this._shutdown(), await de(this._dbName);
527
+ }
528
+ async delete() {
529
+ await this._shutdown(), await Tt(this._dbName);
530
+ }
531
+ }
532
+ const ae = [
533
+ [-1, "✨", "custom"],
534
+ [0, "😀", "smileys-emotion"],
535
+ [1, "👋", "people-body"],
536
+ [3, "🐱", "animals-nature"],
537
+ [4, "🍎", "food-drink"],
538
+ [5, "🏠️", "travel-places"],
539
+ [6, "⚽", "activities"],
540
+ [7, "📝", "objects"],
541
+ [8, "⛔️", "symbols"],
542
+ [9, "🏁", "flags"]
543
+ ].map(([t, e, n]) => ({ id: t, emoji: e, name: n })), Z = ae.slice(1), Zt = 2, ve = 6, Ue = typeof requestIdleCallback == "function" ? requestIdleCallback : setTimeout;
544
+ function we(t) {
545
+ return t.unicode.includes("‍");
546
+ }
547
+ const Jt = {
548
+ "🫩": 16,
549
+ // face with bags under eyes
550
+ "🫨": 15.1,
551
+ // shaking head, technically from v15 but see note above
552
+ "🫠": 14,
553
+ "🥲": 13.1,
554
+ // smiling face with tear, technically from v13 but see note above
555
+ "🥻": 12.1,
556
+ // sari, technically from v12 but see note above
557
+ "🥰": 11,
558
+ "🤩": 5,
559
+ "👱‍♀️": 4,
560
+ "🤣": 3,
561
+ "👁️‍🗨️": 2,
562
+ "😀": 1,
563
+ "😐️": 0.7,
564
+ "😃": 0.6
565
+ }, Qt = 1e3, en = "🖐️", tn = 8, nn = [
566
+ "😊",
567
+ "😒",
568
+ "❤️",
569
+ "👍️",
570
+ "😍",
571
+ "😂",
572
+ "😭",
573
+ "☺️",
574
+ "😔",
575
+ "😩",
576
+ "😏",
577
+ "💕",
578
+ "🙌",
579
+ "😘"
580
+ ], Ge = '"Twemoji Mozilla","Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol","Noto Color Emoji","EmojiOne Color","Android Emoji",sans-serif', on = (t, e) => t < e ? -1 : t > e ? 1 : 0, Te = (t, e) => {
581
+ const n = document.createElement("canvas");
582
+ n.width = n.height = 1;
583
+ const i = n.getContext("2d", {
584
+ // Improves the performance of `getImageData()`
585
+ // https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/getContextAttributes#willreadfrequently
586
+ willReadFrequently: !0
587
+ });
588
+ return i.textBaseline = "top", i.font = `100px ${Ge}`, i.fillStyle = e, i.scale(0.01, 0.01), i.fillText(t, 0, 0), i.getImageData(0, 0, 1, 1).data;
589
+ }, rn = (t, e) => {
590
+ const n = [...t].join(","), i = [...e].join(",");
591
+ return n === i && !n.startsWith("0,0,0,");
592
+ };
593
+ function sn(t) {
594
+ const e = Te(t, "#000"), n = Te(t, "#fff");
595
+ return e && n && rn(e, n);
596
+ }
597
+ function an() {
598
+ const t = Object.entries(Jt);
599
+ try {
600
+ for (const [e, n] of t)
601
+ if (sn(e))
602
+ return n;
603
+ } catch {
604
+ } finally {
605
+ }
606
+ return t[0][1];
607
+ }
608
+ let J;
609
+ const Q = () => (J || (J = new Promise((t) => Ue(() => t(an())))), J), ce = /* @__PURE__ */ new Map(), cn = "️", ln = "\uD83C", un = "‍", dn = 127995, fn = 57339;
610
+ function mn(t, e) {
611
+ if (e === 0)
612
+ return t;
613
+ const n = t.indexOf(un);
614
+ return n !== -1 ? t.substring(0, n) + String.fromCodePoint(dn + e - 1) + t.substring(n) : (t.endsWith(cn) && (t = t.substring(0, t.length - 1)), t + ln + String.fromCodePoint(fn + e - 1));
615
+ }
616
+ function _(t) {
617
+ t.preventDefault(), t.stopPropagation();
618
+ }
619
+ function ee(t, e, n) {
620
+ return e += t ? -1 : 1, e < 0 ? e = n.length - 1 : e >= n.length && (e = 0), e;
621
+ }
622
+ function Ke(t, e) {
623
+ const n = /* @__PURE__ */ new Set(), i = [];
624
+ for (const r of t) {
625
+ const o = e(r);
626
+ n.has(o) || (n.add(o), i.push(r));
627
+ }
628
+ return i;
629
+ }
630
+ function pn(t, e) {
631
+ const n = (i) => {
632
+ const r = {};
633
+ for (const o of i)
634
+ typeof o.tone == "number" && o.version <= e && (r[o.tone] = o.unicode);
635
+ return r;
636
+ };
637
+ return t.map(({ unicode: i, skins: r, shortcodes: o, url: a, name: d, category: m, annotation: c }) => ({
638
+ unicode: i,
639
+ name: d,
640
+ shortcodes: o,
641
+ url: a,
642
+ category: m,
643
+ annotation: c,
644
+ id: i || d,
645
+ skins: r && n(r)
646
+ }));
647
+ }
648
+ const K = requestAnimationFrame;
649
+ let hn = typeof ResizeObserver == "function";
650
+ function gn(t, e, n) {
651
+ let i;
652
+ hn ? (i = new ResizeObserver(n), i.observe(t)) : K(n), e.addEventListener("abort", () => {
653
+ i && i.disconnect();
654
+ });
655
+ }
656
+ function je(t) {
657
+ {
658
+ const e = document.createRange();
659
+ return e.selectNode(t.firstChild), e.getBoundingClientRect().width;
660
+ }
661
+ }
662
+ let te;
663
+ function bn(t, e, n) {
664
+ let i = !0;
665
+ for (const r of t) {
666
+ const o = n(r);
667
+ if (!o)
668
+ continue;
669
+ const a = je(o);
670
+ typeof te > "u" && (te = je(e));
671
+ const d = a / 1.8 < te;
672
+ ce.set(r.unicode, d), d || (i = !1);
673
+ }
674
+ return i;
675
+ }
676
+ function yn(t) {
677
+ return Ke(t, (e) => e);
678
+ }
679
+ function kn(t) {
680
+ t && (t.scrollTop = 0);
681
+ }
682
+ function R(t, e, n) {
683
+ let i = t.get(e);
684
+ return i || (i = n(), t.set(e, i)), i;
685
+ }
686
+ function Se(t) {
687
+ return "" + t;
688
+ }
689
+ function En(t) {
690
+ const e = document.createElement("template");
691
+ return e.innerHTML = t, e;
692
+ }
693
+ const vn = /* @__PURE__ */ new WeakMap(), wn = /* @__PURE__ */ new WeakMap(), Tn = Symbol("un-keyed"), jn = "replaceChildren" in Element.prototype;
694
+ function Sn(t, e) {
695
+ jn ? t.replaceChildren(...e) : (t.innerHTML = "", t.append(...e));
696
+ }
697
+ function xn(t, e) {
698
+ let n = t.firstChild, i = 0;
699
+ for (; n; ) {
700
+ if (e[i] !== n)
701
+ return !0;
702
+ n = n.nextSibling, i++;
703
+ }
704
+ return i !== e.length;
705
+ }
706
+ function Cn(t, e) {
707
+ const { targetNode: n } = e;
708
+ let { targetParentNode: i } = e, r = !1;
709
+ i ? r = xn(i, t) : (r = !0, e.targetNode = void 0, e.targetParentNode = i = n.parentNode), r && Sn(i, t);
710
+ }
711
+ function _n(t, e) {
712
+ for (const n of e) {
713
+ const {
714
+ targetNode: i,
715
+ currentExpression: r,
716
+ binding: {
717
+ expressionIndex: o,
718
+ attributeName: a,
719
+ attributeValuePre: d,
720
+ attributeValuePost: m
721
+ }
722
+ } = n, c = t[o];
723
+ if (r !== c)
724
+ if (n.currentExpression = c, a)
725
+ if (c === null)
726
+ i.removeAttribute(a);
727
+ else {
728
+ const u = d + Se(c) + m;
729
+ i.setAttribute(a, u);
730
+ }
731
+ else {
732
+ let u;
733
+ Array.isArray(c) ? Cn(c, n) : c instanceof Element ? (u = c, i.replaceWith(u)) : i.nodeValue = Se(c), u && (n.targetNode = u);
734
+ }
735
+ }
736
+ }
737
+ function In(t) {
738
+ let e = "", n = !1, i = !1, r = -1;
739
+ const o = /* @__PURE__ */ new Map(), a = [];
740
+ let d = 0;
741
+ for (let c = 0, u = t.length; c < u; c++) {
742
+ const p = t[c];
743
+ if (e += p.slice(d), c === u - 1)
744
+ break;
745
+ for (let h = 0; h < p.length; h++)
746
+ switch (p.charAt(h)) {
747
+ case "<": {
748
+ p.charAt(h + 1) === "/" ? a.pop() : (n = !0, a.push(++r));
749
+ break;
750
+ }
751
+ case ">": {
752
+ n = !1, i = !1;
753
+ break;
754
+ }
755
+ case "=": {
756
+ i = !0;
757
+ break;
758
+ }
759
+ }
760
+ const f = a[a.length - 1], b = R(o, f, () => []);
761
+ let T, j, x;
762
+ if (i) {
763
+ const h = /(\S+)="?([^"=]*)$/.exec(p);
764
+ T = h[1], j = h[2];
765
+ const k = /^([^">]*)("?)/.exec(t[c + 1]);
766
+ x = k[1], e = e.slice(0, -1 * h[0].length), d = k[0].length;
767
+ } else
768
+ d = 0;
769
+ const O = {
770
+ attributeName: T,
771
+ attributeValuePre: j,
772
+ attributeValuePost: x,
773
+ expressionIndex: c
774
+ };
775
+ b.push(O), !n && !i && (e += " ");
776
+ }
777
+ return {
778
+ template: En(e),
779
+ elementsToBindings: o
780
+ };
781
+ }
782
+ function xe(t, e, n) {
783
+ for (let i = 0; i < t.length; i++) {
784
+ const r = t[i], o = r.attributeName ? e : e.firstChild, a = {
785
+ binding: r,
786
+ targetNode: o,
787
+ targetParentNode: void 0,
788
+ currentExpression: void 0
789
+ };
790
+ n.push(a);
791
+ }
792
+ }
793
+ function An(t, e) {
794
+ const n = [];
795
+ let i;
796
+ if (e.size === 1 && (i = e.get(0)))
797
+ xe(i, t, n);
798
+ else {
799
+ const r = document.createTreeWalker(t, NodeFilter.SHOW_ELEMENT);
800
+ let o = t, a = -1;
801
+ do {
802
+ const d = e.get(++a);
803
+ d && xe(d, o, n);
804
+ } while (o = r.nextNode());
805
+ }
806
+ return n;
807
+ }
808
+ function Ln(t) {
809
+ const { template: e, elementsToBindings: n } = R(vn, t, () => In(t)), i = e.cloneNode(!0).content.firstElementChild, r = An(i, n);
810
+ return function(a) {
811
+ return _n(a, r), i;
812
+ };
813
+ }
814
+ function On(t) {
815
+ const e = R(wn, t, () => /* @__PURE__ */ new Map());
816
+ let n = Tn;
817
+ function i(o, ...a) {
818
+ const d = R(e, o, () => /* @__PURE__ */ new Map());
819
+ return R(d, n, () => Ln(o))(a);
820
+ }
821
+ function r(o, a, d) {
822
+ return o.map((m, c) => {
823
+ const u = n;
824
+ n = d(m);
825
+ try {
826
+ return a(m, c);
827
+ } finally {
828
+ n = u;
829
+ }
830
+ });
831
+ }
832
+ return { map: r, html: i };
833
+ }
834
+ function Dn(t, e, n, i, r, o, a, d, m) {
835
+ const { labelWithSkin: c, titleForEmoji: u, unicodeWithSkin: p } = n, { html: f, map: b } = On(e);
836
+ function T(h, k, w) {
837
+ return b(h, (S, F) => f`<button role="${k ? "option" : "menuitem"}" aria-selected="${k ? F === e.activeSearchItem : null}" aria-label="${c(S, e.currentSkinTone)}" title="${u(S)}" class="${"emoji" + (k && F === e.activeSearchItem ? " active" : "") + (S.unicode ? "" : " custom-emoji")}" id="${`${w}-${S.id}`}" style="${S.unicode ? null : `--custom-emoji-background: url(${JSON.stringify(S.url)})`}">${S.unicode ? p(S, e.currentSkinTone) : ""}</button>`, (S) => `${w}-${S.id}`);
838
+ }
839
+ const x = f`<section data-ref="rootElement" class="picker" aria-label="${e.i18n.regionLabel}" style="${e.pickerStyle || ""}"><div class="pad-top"></div><div class="search-row"><div class="search-wrapper"><input id="search" class="search" type="search" role="combobox" enterkeyhint="search" placeholder="${e.i18n.searchLabel}" autocapitalize="none" autocomplete="off" spellcheck="true" aria-expanded="${!!(e.searchMode && e.currentEmojis.length)}" aria-controls="search-results" aria-describedby="search-description" aria-autocomplete="list" aria-activedescendant="${e.activeSearchItemId ? `emo-${e.activeSearchItemId}` : null}" data-ref="searchElement" data-on-input="onSearchInput" data-on-keydown="onSearchKeydown"><label class="sr-only" for="search">${e.i18n.searchLabel}</label> <span id="search-description" class="sr-only">${e.i18n.searchDescription}</span></div><div class="skintone-button-wrapper ${e.skinTonePickerExpandedAfterAnimation ? "expanded" : ""}"><button id="skintone-button" class="emoji ${e.skinTonePickerExpanded ? "hide-focus" : ""}" aria-label="${e.skinToneButtonLabel}" title="${e.skinToneButtonLabel}" aria-describedby="skintone-description" aria-haspopup="listbox" aria-expanded="${e.skinTonePickerExpanded}" aria-controls="skintone-list" data-on-click="onClickSkinToneButton">${e.skinToneButtonText || ""}</button></div><span id="skintone-description" class="sr-only">${e.i18n.skinToneDescription}</span><div data-ref="skinToneDropdown" id="skintone-list" class="skintone-list hide-focus ${e.skinTonePickerExpanded ? "" : "hidden no-animate"}" style="transform:translateY(${e.skinTonePickerExpanded ? 0 : "calc(-1 * var(--num-skintones) * var(--total-emoji-size))"})" role="listbox" aria-label="${e.i18n.skinTonesLabel}" aria-activedescendant="skintone-${e.activeSkinTone}" aria-hidden="${!e.skinTonePickerExpanded}" tabIndex="-1" data-on-focusout="onSkinToneOptionsFocusOut" data-on-click="onSkinToneOptionsClick" data-on-keydown="onSkinToneOptionsKeydown" data-on-keyup="onSkinToneOptionsKeyup">${b(e.skinTones, (h, k) => f`<div id="skintone-${k}" class="emoji ${k === e.activeSkinTone ? "active" : ""}" aria-selected="${k === e.activeSkinTone}" role="option" title="${e.i18n.skinTones[k]}" aria-label="${e.i18n.skinTones[k]}">${h}</div>`, (h) => h)}</div></div><div class="nav" role="tablist" style="grid-template-columns:repeat(${e.groups.length},1fr)" aria-label="${e.i18n.categoriesLabel}" data-on-keydown="onNavKeydown" data-on-click="onNavClick">${b(e.groups, (h) => f`<button role="tab" class="nav-button" aria-controls="tab-${h.id}" aria-label="${e.i18n.categories[h.name]}" aria-selected="${!e.searchMode && e.currentGroup.id === h.id}" title="${e.i18n.categories[h.name]}" data-group-id="${h.id}"><div class="nav-emoji emoji">${h.emoji}</div></button>`, (h) => h.id)}</div><div class="indicator-wrapper"><div class="indicator" style="transform:translateX(${/* istanbul ignore next */
840
+ (e.isRtl ? -1 : 1) * e.currentGroupIndex * 100}%)"></div></div><div class="message ${e.message ? "" : "gone"}" role="alert" aria-live="polite">${e.message || ""}</div><div data-ref="tabpanelElement" class="tabpanel ${!e.databaseLoaded || e.message ? "gone" : ""}" role="${e.searchMode ? "region" : "tabpanel"}" aria-label="${e.searchMode ? e.i18n.searchResultsLabel : e.i18n.categories[e.currentGroup.name]}" id="${e.searchMode ? null : `tab-${e.currentGroup.id}`}" tabIndex="0" data-on-click="onEmojiClick"><div data-action="calculateEmojiGridStyle">${b(e.currentEmojisWithCategories, (h, k) => f`<div><div id="menu-label-${k}" class="category ${e.currentEmojisWithCategories.length === 1 && e.currentEmojisWithCategories[0].category === "" ? "gone" : ""}" aria-hidden="true">${e.searchMode ? e.i18n.searchResultsLabel : h.category ? h.category : e.currentEmojisWithCategories.length > 1 ? e.i18n.categories.custom : e.i18n.categories[e.currentGroup.name]}</div><div class="emoji-menu ${k !== 0 && !e.searchMode && e.currentGroup.id === -1 ? "visibility-auto" : ""}" style="${`--num-rows: ${Math.ceil(h.emojis.length / e.numColumns)}`}" data-action="updateOnIntersection" role="${e.searchMode ? "listbox" : "menu"}" aria-labelledby="menu-label-${k}" id="${e.searchMode ? "search-results" : null}">${T(
841
+ h.emojis,
842
+ e.searchMode,
843
+ /* prefix */
844
+ "emo"
845
+ )}</div></div>`, (h) => h.category)}</div></div><div class="favorites onscreen emoji-menu ${e.message ? "gone" : ""}" role="menu" aria-label="${e.i18n.favoritesLabel}" data-on-click="onEmojiClick">${T(
846
+ e.currentFavorites,
847
+ /* searchMode */
848
+ !1,
849
+ /* prefix */
850
+ "fav"
851
+ )}</div><button data-ref="baselineEmoji" aria-hidden="true" tabindex="-1" class="abs-pos hidden emoji baseline-emoji">😀</button></section>`, O = (h, k) => {
852
+ for (const w of t.querySelectorAll(`[${h}]`))
853
+ k(w, w.getAttribute(h));
854
+ };
855
+ if (m) {
856
+ t.appendChild(x);
857
+ for (const h of ["click", "focusout", "input", "keydown", "keyup"])
858
+ O(`data-on-${h}`, (k, w) => {
859
+ k.addEventListener(h, i[w]);
860
+ });
861
+ O("data-ref", (h, k) => {
862
+ o[k] = h;
863
+ }), a.addEventListener("abort", () => {
864
+ t.removeChild(x);
865
+ });
866
+ }
867
+ O("data-action", (h, k) => {
868
+ let w = d.get(k);
869
+ w || d.set(k, w = /* @__PURE__ */ new WeakSet()), w.has(h) || (w.add(h), r[k](h));
870
+ });
871
+ }
872
+ const H = typeof queueMicrotask == "function" ? queueMicrotask : (t) => Promise.resolve().then(t);
873
+ function $n(t) {
874
+ let e = !1, n;
875
+ const i = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Set();
876
+ let o;
877
+ const a = () => {
878
+ if (e)
879
+ return;
880
+ const c = [...r];
881
+ r.clear();
882
+ try {
883
+ for (const u of c)
884
+ u();
885
+ } finally {
886
+ o = !1, r.size && (o = !0, H(a));
887
+ }
888
+ }, d = new Proxy({}, {
889
+ get(c, u) {
890
+ if (n) {
891
+ let p = i.get(u);
892
+ p || (p = /* @__PURE__ */ new Set(), i.set(u, p)), p.add(n);
893
+ }
894
+ return c[u];
895
+ },
896
+ set(c, u, p) {
897
+ if (c[u] !== p) {
898
+ c[u] = p;
899
+ const f = i.get(u);
900
+ if (f) {
901
+ for (const b of f)
902
+ r.add(b);
903
+ o || (o = !0, H(a));
904
+ }
905
+ }
906
+ return !0;
907
+ }
908
+ }), m = (c) => {
909
+ const u = () => {
910
+ const p = n;
911
+ n = u;
912
+ try {
913
+ return c();
914
+ } finally {
915
+ n = p;
916
+ }
917
+ };
918
+ return u();
919
+ };
920
+ return t.addEventListener("abort", () => {
921
+ e = !0;
922
+ }), {
923
+ state: d,
924
+ createEffect: m
925
+ };
926
+ }
927
+ function ne(t, e, n) {
928
+ if (t.length !== e.length)
929
+ return !1;
930
+ for (let i = 0; i < t.length; i++)
931
+ if (!n(t[i], e[i]))
932
+ return !1;
933
+ return !0;
934
+ }
935
+ const Ce = /* @__PURE__ */ new WeakMap();
936
+ function Mn(t, e, n) {
937
+ {
938
+ const i = t.closest(".tabpanel");
939
+ let r = Ce.get(i);
940
+ r || (r = new IntersectionObserver(n, {
941
+ root: i,
942
+ // trigger if we are 1/2 scroll container height away so that the images load a bit quicker while scrolling
943
+ rootMargin: "50% 0px 50% 0px",
944
+ // trigger if any part of the emoji grid is intersecting
945
+ threshold: 0
946
+ }), Ce.set(i, r), e.addEventListener("abort", () => {
947
+ r.disconnect();
948
+ })), r.observe(t);
949
+ }
950
+ }
951
+ const oe = [], { assign: U } = Object;
952
+ function Fn(t, e) {
953
+ const n = {}, i = new AbortController(), r = i.signal, { state: o, createEffect: a } = $n(r), d = /* @__PURE__ */ new Map();
954
+ U(o, {
955
+ skinToneEmoji: void 0,
956
+ i18n: void 0,
957
+ database: void 0,
958
+ customEmoji: void 0,
959
+ customCategorySorting: void 0,
960
+ emojiVersion: void 0
961
+ }), U(o, e), U(o, {
962
+ initialLoad: !0,
963
+ currentEmojis: [],
964
+ currentEmojisWithCategories: [],
965
+ rawSearchText: "",
966
+ searchText: "",
967
+ searchMode: !1,
968
+ activeSearchItem: -1,
969
+ message: void 0,
970
+ skinTonePickerExpanded: !1,
971
+ skinTonePickerExpandedAfterAnimation: !1,
972
+ currentSkinTone: 0,
973
+ activeSkinTone: 0,
974
+ skinToneButtonText: void 0,
975
+ pickerStyle: void 0,
976
+ skinToneButtonLabel: "",
977
+ skinTones: [],
978
+ currentFavorites: [],
979
+ defaultFavoriteEmojis: void 0,
980
+ numColumns: tn,
981
+ isRtl: !1,
982
+ currentGroupIndex: 0,
983
+ groups: Z,
984
+ databaseLoaded: !1,
985
+ activeSearchItemId: void 0
986
+ }), a(() => {
987
+ o.currentGroup !== o.groups[o.currentGroupIndex] && (o.currentGroup = o.groups[o.currentGroupIndex]);
988
+ });
989
+ const m = (s) => {
990
+ t.getElementById(s).focus();
991
+ }, c = (s) => t.getElementById(`emo-${s.id}`), u = (s, l) => {
992
+ n.rootElement.dispatchEvent(new CustomEvent(s, {
993
+ detail: l,
994
+ bubbles: !0,
995
+ composed: !0
996
+ }));
997
+ }, p = (s, l) => s.id === l.id, f = (s, l) => {
998
+ const { category: g, emojis: y } = s, { category: E, emojis: v } = l;
999
+ return g !== E ? !1 : ne(y, v, p);
1000
+ }, b = (s) => {
1001
+ ne(o.currentEmojis, s, p) || (o.currentEmojis = s);
1002
+ }, T = (s) => {
1003
+ o.searchMode !== s && (o.searchMode = s);
1004
+ }, j = (s) => {
1005
+ ne(o.currentEmojisWithCategories, s, f) || (o.currentEmojisWithCategories = s);
1006
+ }, x = (s, l) => l && s.skins && s.skins[l] || s.unicode, k = {
1007
+ labelWithSkin: (s, l) => yn([
1008
+ s.name || x(s, l),
1009
+ s.annotation,
1010
+ ...s.shortcodes || oe
1011
+ ].filter(Boolean)).join(", "),
1012
+ titleForEmoji: (s) => s.annotation || (s.shortcodes || oe).join(", "),
1013
+ unicodeWithSkin: x
1014
+ }, w = {
1015
+ onClickSkinToneButton: rt,
1016
+ onEmojiClick: ot,
1017
+ onNavClick: tt,
1018
+ onNavKeydown: nt,
1019
+ onSearchKeydown: et,
1020
+ onSkinToneOptionsClick: it,
1021
+ onSkinToneOptionsFocusOut: ct,
1022
+ onSkinToneOptionsKeydown: st,
1023
+ onSkinToneOptionsKeyup: at,
1024
+ onSearchInput: lt
1025
+ }, S = {
1026
+ calculateEmojiGridStyle: qe,
1027
+ updateOnIntersection: Xe
1028
+ };
1029
+ let F = !0;
1030
+ a(() => {
1031
+ Dn(t, o, k, w, S, n, r, d, F), F = !1;
1032
+ }), o.emojiVersion || Q().then((s) => {
1033
+ s || (o.message = o.i18n.emojiUnsupportedMessage);
1034
+ }), a(() => {
1035
+ async function s() {
1036
+ let l = !1;
1037
+ const g = setTimeout(() => {
1038
+ l = !0, o.message = o.i18n.loadingMessage;
1039
+ }, Qt);
1040
+ try {
1041
+ await o.database.ready(), o.databaseLoaded = !0;
1042
+ } catch (y) {
1043
+ console.error(y), o.message = o.i18n.networkErrorMessage;
1044
+ } finally {
1045
+ clearTimeout(g), l && (l = !1, o.message = "");
1046
+ }
1047
+ }
1048
+ o.database && s();
1049
+ }), a(() => {
1050
+ o.pickerStyle = `
1051
+ --num-groups: ${o.groups.length};
1052
+ --indicator-opacity: ${o.searchMode ? 0 : 1};
1053
+ --num-skintones: ${ve};`;
1054
+ }), a(() => {
1055
+ o.customEmoji && o.database && pe();
1056
+ }), a(() => {
1057
+ o.customEmoji && o.customEmoji.length ? o.groups !== ae && (o.groups = ae) : o.groups !== Z && (o.currentGroupIndex && o.currentGroupIndex--, o.groups = Z);
1058
+ }), a(() => {
1059
+ async function s() {
1060
+ o.databaseLoaded && (o.currentSkinTone = await o.database.getPreferredSkinTone());
1061
+ }
1062
+ s();
1063
+ }), a(() => {
1064
+ o.skinTones = Array(ve).fill().map((s, l) => mn(o.skinToneEmoji, l));
1065
+ }), a(() => {
1066
+ o.skinToneButtonText = o.skinTones[o.currentSkinTone];
1067
+ }), a(() => {
1068
+ o.skinToneButtonLabel = o.i18n.skinToneLabel.replace("{skinTone}", o.i18n.skinTones[o.currentSkinTone]);
1069
+ }), a(() => {
1070
+ async function s() {
1071
+ const { database: l } = o, g = (await Promise.all(nn.map((y) => l.getEmojiByUnicodeOrName(y)))).filter(Boolean);
1072
+ o.defaultFavoriteEmojis = g;
1073
+ }
1074
+ o.databaseLoaded && s();
1075
+ });
1076
+ function pe() {
1077
+ const { customEmoji: s, database: l } = o, g = s || oe;
1078
+ l.customEmoji !== g && (l.customEmoji = g);
1079
+ }
1080
+ a(() => {
1081
+ async function s() {
1082
+ pe();
1083
+ const { database: l, defaultFavoriteEmojis: g, numColumns: y } = o, E = await l.getTopFavoriteEmoji(y), v = await q(Ke([
1084
+ ...E,
1085
+ ...g
1086
+ ], (C) => C.unicode || C.name).slice(0, y));
1087
+ o.currentFavorites = v;
1088
+ }
1089
+ o.databaseLoaded && o.defaultFavoriteEmojis && s();
1090
+ });
1091
+ function qe(s) {
1092
+ gn(s, r, () => {
1093
+ {
1094
+ const l = getComputedStyle(n.rootElement), g = parseInt(l.getPropertyValue("--num-columns"), 10), y = l.getPropertyValue("direction") === "rtl";
1095
+ o.numColumns = g, o.isRtl = y;
1096
+ }
1097
+ });
1098
+ }
1099
+ function Xe(s) {
1100
+ Mn(s, r, (l) => {
1101
+ for (const { target: g, isIntersecting: y } of l)
1102
+ g.classList.toggle("onscreen", y);
1103
+ });
1104
+ }
1105
+ a(() => {
1106
+ async function s() {
1107
+ const { searchText: l, currentGroup: g, databaseLoaded: y, customEmoji: E } = o;
1108
+ if (!y)
1109
+ o.currentEmojis = [], o.searchMode = !1;
1110
+ else if (l.length >= Zt) {
1111
+ const v = await Qe(l);
1112
+ o.searchText === l && (b(v), T(!0));
1113
+ } else {
1114
+ const { id: v } = g;
1115
+ if (v !== -1 || E && E.length) {
1116
+ const C = await Je(v);
1117
+ o.currentGroup.id === v && (b(C), T(!1));
1118
+ }
1119
+ }
1120
+ }
1121
+ s();
1122
+ });
1123
+ const he = () => {
1124
+ K(() => kn(n.tabpanelElement));
1125
+ };
1126
+ a(() => {
1127
+ const { currentEmojis: s, emojiVersion: l } = o, g = s.filter((y) => y.unicode).filter((y) => we(y) && !ce.has(y.unicode));
1128
+ if (!l && g.length)
1129
+ b(s), K(() => Ye(g));
1130
+ else {
1131
+ const y = l ? s : s.filter(Ze);
1132
+ b(y), he();
1133
+ }
1134
+ });
1135
+ function Ye(s) {
1136
+ bn(s, n.baselineEmoji, c) ? he() : o.currentEmojis = [...o.currentEmojis];
1137
+ }
1138
+ function Ze(s) {
1139
+ return !s.unicode || !we(s) || ce.get(s.unicode);
1140
+ }
1141
+ async function ge(s) {
1142
+ const l = o.emojiVersion || await Q();
1143
+ return s.filter(({ version: g }) => !g || g <= l);
1144
+ }
1145
+ async function q(s) {
1146
+ return pn(s, o.emojiVersion || await Q());
1147
+ }
1148
+ async function Je(s) {
1149
+ const l = s === -1 ? o.customEmoji : await o.database.getEmojiByGroup(s);
1150
+ return q(await ge(l));
1151
+ }
1152
+ async function Qe(s) {
1153
+ return q(await ge(await o.database.getEmojiBySearchQuery(s)));
1154
+ }
1155
+ a(() => {
1156
+ }), a(() => {
1157
+ function s() {
1158
+ const { searchMode: g, currentEmojis: y } = o;
1159
+ if (g)
1160
+ return [
1161
+ {
1162
+ category: "",
1163
+ emojis: y
1164
+ }
1165
+ ];
1166
+ const E = /* @__PURE__ */ new Map();
1167
+ for (const v of y) {
1168
+ const C = v.category || "";
1169
+ let N = E.get(C);
1170
+ N || (N = [], E.set(C, N)), N.push(v);
1171
+ }
1172
+ return [...E.entries()].map(([v, C]) => ({ category: v, emojis: C })).sort((v, C) => o.customCategorySorting(v.category, C.category));
1173
+ }
1174
+ const l = s();
1175
+ j(l);
1176
+ }), a(() => {
1177
+ o.activeSearchItemId = o.activeSearchItem !== -1 && o.currentEmojis[o.activeSearchItem].id;
1178
+ }), a(() => {
1179
+ const { rawSearchText: s } = o;
1180
+ Ue(() => {
1181
+ o.searchText = (s || "").trim(), o.activeSearchItem = -1;
1182
+ });
1183
+ });
1184
+ function et(s) {
1185
+ if (!o.searchMode || !o.currentEmojis.length)
1186
+ return;
1187
+ const l = (g) => {
1188
+ _(s), o.activeSearchItem = ee(g, o.activeSearchItem, o.currentEmojis);
1189
+ };
1190
+ switch (s.key) {
1191
+ case "ArrowDown":
1192
+ return l(!1);
1193
+ case "ArrowUp":
1194
+ return l(!0);
1195
+ case "Enter":
1196
+ if (o.activeSearchItem === -1)
1197
+ o.activeSearchItem = 0;
1198
+ else
1199
+ return _(s), be(o.currentEmojis[o.activeSearchItem].id);
1200
+ }
1201
+ }
1202
+ function tt(s) {
1203
+ const { target: l } = s, g = l.closest(".nav-button");
1204
+ if (!g)
1205
+ return;
1206
+ const y = parseInt(g.dataset.groupId, 10);
1207
+ n.searchElement.value = "", o.rawSearchText = "", o.searchText = "", o.activeSearchItem = -1, o.currentGroupIndex = o.groups.findIndex((E) => E.id === y);
1208
+ }
1209
+ function nt(s) {
1210
+ const { target: l, key: g } = s, y = (E) => {
1211
+ E && (_(s), E.focus());
1212
+ };
1213
+ switch (g) {
1214
+ case "ArrowLeft":
1215
+ return y(l.previousElementSibling);
1216
+ case "ArrowRight":
1217
+ return y(l.nextElementSibling);
1218
+ case "Home":
1219
+ return y(l.parentElement.firstElementChild);
1220
+ case "End":
1221
+ return y(l.parentElement.lastElementChild);
1222
+ }
1223
+ }
1224
+ async function be(s) {
1225
+ const l = await o.database.getEmojiByUnicodeOrName(s), g = [...o.currentEmojis, ...o.currentFavorites].find((E) => E.id === s), y = g.unicode && x(g, o.currentSkinTone);
1226
+ await o.database.incrementFavoriteEmojiCount(s), u("emoji-click", {
1227
+ emoji: l,
1228
+ skinTone: o.currentSkinTone,
1229
+ ...y && { unicode: y },
1230
+ ...g.name && { name: g.name }
1231
+ });
1232
+ }
1233
+ async function ot(s) {
1234
+ const { target: l } = s;
1235
+ if (!l.classList.contains("emoji"))
1236
+ return;
1237
+ _(s);
1238
+ const g = l.id.substring(4);
1239
+ be(g);
1240
+ }
1241
+ function X(s) {
1242
+ o.currentSkinTone = s, o.skinTonePickerExpanded = !1, m("skintone-button"), u("skin-tone-change", { skinTone: s }), o.database.setPreferredSkinTone(s);
1243
+ }
1244
+ function it(s) {
1245
+ const { target: { id: l } } = s, g = l && l.match(/^skintone-(\d)/);
1246
+ if (!g)
1247
+ return;
1248
+ _(s);
1249
+ const y = parseInt(g[1], 10);
1250
+ X(y);
1251
+ }
1252
+ function rt(s) {
1253
+ o.skinTonePickerExpanded = !o.skinTonePickerExpanded, o.activeSkinTone = o.currentSkinTone, o.skinTonePickerExpanded && (_(s), K(() => m("skintone-list")));
1254
+ }
1255
+ a(() => {
1256
+ o.skinTonePickerExpanded ? n.skinToneDropdown.addEventListener("transitionend", () => {
1257
+ o.skinTonePickerExpandedAfterAnimation = !0;
1258
+ }, { once: !0 }) : o.skinTonePickerExpandedAfterAnimation = !1;
1259
+ });
1260
+ function st(s) {
1261
+ if (!o.skinTonePickerExpanded)
1262
+ return;
1263
+ const l = async (g) => {
1264
+ _(s), o.activeSkinTone = g;
1265
+ };
1266
+ switch (s.key) {
1267
+ case "ArrowUp":
1268
+ return l(ee(!0, o.activeSkinTone, o.skinTones));
1269
+ case "ArrowDown":
1270
+ return l(ee(!1, o.activeSkinTone, o.skinTones));
1271
+ case "Home":
1272
+ return l(0);
1273
+ case "End":
1274
+ return l(o.skinTones.length - 1);
1275
+ case "Enter":
1276
+ return _(s), X(o.activeSkinTone);
1277
+ case "Escape":
1278
+ return _(s), o.skinTonePickerExpanded = !1, m("skintone-button");
1279
+ }
1280
+ }
1281
+ function at(s) {
1282
+ if (o.skinTonePickerExpanded)
1283
+ switch (s.key) {
1284
+ case " ":
1285
+ return _(s), X(o.activeSkinTone);
1286
+ }
1287
+ }
1288
+ async function ct(s) {
1289
+ const { relatedTarget: l } = s;
1290
+ (!l || l.id !== "skintone-list") && (o.skinTonePickerExpanded = !1);
1291
+ }
1292
+ function lt(s) {
1293
+ o.rawSearchText = s.target.value;
1294
+ }
1295
+ return {
1296
+ $set(s) {
1297
+ U(o, s);
1298
+ },
1299
+ $destroy() {
1300
+ i.abort();
1301
+ }
1302
+ };
1303
+ }
1304
+ const Bn = "https://cdn.jsdelivr.net/npm/emoji-picker-element-data@^1/en/emojibase/data.json", Rn = "en";
1305
+ var Nn = {
1306
+ categoriesLabel: "Categories",
1307
+ emojiUnsupportedMessage: "Your browser does not support color emoji.",
1308
+ favoritesLabel: "Favorites",
1309
+ loadingMessage: "Loading…",
1310
+ networkErrorMessage: "Could not load emoji.",
1311
+ regionLabel: "Emoji picker",
1312
+ searchDescription: "When search results are available, press up or down to select and enter to choose.",
1313
+ searchLabel: "Search",
1314
+ searchResultsLabel: "Search results",
1315
+ skinToneDescription: "When expanded, press up or down to select and enter to choose.",
1316
+ skinToneLabel: "Choose a skin tone (currently {skinTone})",
1317
+ skinTonesLabel: "Skin tones",
1318
+ skinTones: [
1319
+ "Default",
1320
+ "Light",
1321
+ "Medium-Light",
1322
+ "Medium",
1323
+ "Medium-Dark",
1324
+ "Dark"
1325
+ ],
1326
+ categories: {
1327
+ custom: "Custom",
1328
+ "smileys-emotion": "Smileys and emoticons",
1329
+ "people-body": "People and body",
1330
+ "animals-nature": "Animals and nature",
1331
+ "food-drink": "Food and drink",
1332
+ "travel-places": "Travel and places",
1333
+ activities: "Activities",
1334
+ objects: "Objects",
1335
+ symbols: "Symbols",
1336
+ flags: "Flags"
1337
+ }
1338
+ }, Pn = ':host{--emoji-size:1.375rem;--emoji-padding:0.5rem;--category-emoji-size:var(--emoji-size);--category-emoji-padding:var(--emoji-padding);--indicator-height:3px;--input-border-radius:0.5rem;--input-border-size:1px;--input-font-size:1rem;--input-line-height:1.5;--input-padding:0.25rem;--num-columns:8;--outline-size:2px;--border-size:1px;--border-radius:0;--skintone-border-radius:1rem;--category-font-size:1rem;display:flex;width:min-content;height:400px}:host,:host(.light){color-scheme:light;--background:#fff;--border-color:#e0e0e0;--indicator-color:#385ac1;--input-border-color:#999;--input-font-color:#111;--input-placeholder-color:#999;--outline-color:#999;--category-font-color:#111;--button-active-background:#e6e6e6;--button-hover-background:#d9d9d9}:host(.dark){color-scheme:dark;--background:#222;--border-color:#444;--indicator-color:#5373ec;--input-border-color:#ccc;--input-font-color:#efefef;--input-placeholder-color:#ccc;--outline-color:#fff;--category-font-color:#efefef;--button-active-background:#555555;--button-hover-background:#484848}@media (prefers-color-scheme:dark){:host{color-scheme:dark;--background:#222;--border-color:#444;--indicator-color:#5373ec;--input-border-color:#ccc;--input-font-color:#efefef;--input-placeholder-color:#ccc;--outline-color:#fff;--category-font-color:#efefef;--button-active-background:#555555;--button-hover-background:#484848}}:host([hidden]){display:none}button{margin:0;padding:0;border:0;background:0 0;box-shadow:none;-webkit-tap-highlight-color:transparent}button::-moz-focus-inner{border:0}input{padding:0;margin:0;line-height:1.15;font-family:inherit}input[type=search]{-webkit-appearance:none}:focus{outline:var(--outline-color) solid var(--outline-size);outline-offset:calc(-1*var(--outline-size))}:host([data-js-focus-visible]) :focus:not([data-focus-visible-added]){outline:0}:focus:not(:focus-visible){outline:0}.hide-focus{outline:0}*{box-sizing:border-box}.picker{contain:content;display:flex;flex-direction:column;background:var(--background);border:var(--border-size) solid var(--border-color);border-radius:var(--border-radius);width:100%;height:100%;overflow:hidden;--total-emoji-size:calc(var(--emoji-size) + (2 * var(--emoji-padding)));--total-category-emoji-size:calc(var(--category-emoji-size) + (2 * var(--category-emoji-padding)))}.sr-only{position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);border:0}.hidden{opacity:0;pointer-events:none}.abs-pos{position:absolute;left:0;top:0}.gone{display:none!important}.skintone-button-wrapper,.skintone-list{background:var(--background);z-index:3}.skintone-button-wrapper.expanded{z-index:1}.skintone-list{position:absolute;inset-inline-end:0;top:0;z-index:2;overflow:visible;border-bottom:var(--border-size) solid var(--border-color);border-radius:0 0 var(--skintone-border-radius) var(--skintone-border-radius);will-change:transform;transition:transform .2s ease-in-out;transform-origin:center 0}@media (prefers-reduced-motion:reduce){.skintone-list{transition-duration:.001s}}@supports not (inset-inline-end:0){.skintone-list{right:0}}.skintone-list.no-animate{transition:none}.tabpanel{overflow-y:auto;scrollbar-gutter:stable;-webkit-overflow-scrolling:touch;will-change:transform;min-height:0;flex:1;contain:content}.emoji-menu{display:grid;grid-template-columns:repeat(var(--num-columns),var(--total-emoji-size));justify-content:space-around;align-items:flex-start;width:100%}.emoji-menu.visibility-auto{content-visibility:auto;contain-intrinsic-size:calc(var(--num-columns)*var(--total-emoji-size)) calc(var(--num-rows)*var(--total-emoji-size))}.category{padding:var(--emoji-padding);font-size:var(--category-font-size);color:var(--category-font-color)}.emoji,button.emoji{font-size:var(--emoji-size);display:flex;align-items:center;justify-content:center;border-radius:100%;height:var(--total-emoji-size);width:var(--total-emoji-size);line-height:1;overflow:hidden;font-family:var(--emoji-font-family);cursor:pointer}@media (hover:hover) and (pointer:fine){.emoji:hover,button.emoji:hover{background:var(--button-hover-background)}}.emoji.active,.emoji:active,button.emoji.active,button.emoji:active{background:var(--button-active-background)}.onscreen .custom-emoji::after{content:"";width:var(--emoji-size);height:var(--emoji-size);background-repeat:no-repeat;background-position:center center;background-size:contain;background-image:var(--custom-emoji-background)}.nav,.nav-button{align-items:center}.nav{display:grid;justify-content:space-between;contain:content}.nav-button{display:flex;justify-content:center}.nav-emoji{font-size:var(--category-emoji-size);width:var(--total-category-emoji-size);height:var(--total-category-emoji-size)}.indicator-wrapper{display:flex;border-bottom:1px solid var(--border-color)}.indicator{width:calc(100%/var(--num-groups));height:var(--indicator-height);opacity:var(--indicator-opacity);background-color:var(--indicator-color);will-change:transform,opacity;transition:opacity .1s linear,transform .25s ease-in-out}@media (prefers-reduced-motion:reduce){.indicator{will-change:opacity;transition:opacity .1s linear}}.pad-top,input.search{background:var(--background);width:100%}.pad-top{height:var(--emoji-padding);z-index:3}.search-row{display:flex;align-items:center;position:relative;padding-inline-start:var(--emoji-padding);padding-bottom:var(--emoji-padding)}.search-wrapper{flex:1;min-width:0}input.search{padding:var(--input-padding);border-radius:var(--input-border-radius);border:var(--input-border-size) solid var(--input-border-color);color:var(--input-font-color);font-size:var(--input-font-size);line-height:var(--input-line-height)}input.search::placeholder{color:var(--input-placeholder-color)}.favorites{overflow-y:auto;scrollbar-gutter:stable;display:flex;flex-direction:row;border-top:var(--border-size) solid var(--border-color);contain:content}.message{padding:var(--emoji-padding)}';
1339
+ const We = [
1340
+ "customEmoji",
1341
+ "customCategorySorting",
1342
+ "database",
1343
+ "dataSource",
1344
+ "i18n",
1345
+ "locale",
1346
+ "skinToneEmoji",
1347
+ "emojiVersion"
1348
+ ], zn = `:host{--emoji-font-family:${Ge}}`;
1349
+ class Ve extends HTMLElement {
1350
+ constructor(e) {
1351
+ super(), this.attachShadow({ mode: "open" });
1352
+ const n = document.createElement("style");
1353
+ n.textContent = Pn + zn, this.shadowRoot.appendChild(n), this._ctx = {
1354
+ // Set defaults
1355
+ locale: Rn,
1356
+ dataSource: Bn,
1357
+ skinToneEmoji: en,
1358
+ customCategorySorting: on,
1359
+ customEmoji: null,
1360
+ i18n: Nn,
1361
+ emojiVersion: null,
1362
+ ...e
1363
+ };
1364
+ for (const i of We)
1365
+ i !== "database" && Object.prototype.hasOwnProperty.call(this, i) && (this._ctx[i] = this[i], delete this[i]);
1366
+ this._dbFlush();
1367
+ }
1368
+ connectedCallback() {
1369
+ this._cmp || (this._cmp = Fn(this.shadowRoot, this._ctx));
1370
+ }
1371
+ disconnectedCallback() {
1372
+ H(() => {
1373
+ if (!this.isConnected && this._cmp) {
1374
+ this._cmp.$destroy(), this._cmp = void 0;
1375
+ const { database: e } = this._ctx;
1376
+ e.close().catch((n) => console.error(n));
1377
+ }
1378
+ });
1379
+ }
1380
+ static get observedAttributes() {
1381
+ return ["locale", "data-source", "skin-tone-emoji", "emoji-version"];
1382
+ }
1383
+ attributeChangedCallback(e, n, i) {
1384
+ this._set(
1385
+ // convert from kebab-case to camelcase
1386
+ // see https://github.com/sveltejs/svelte/issues/3852#issuecomment-665037015
1387
+ e.replace(/-([a-z])/g, (r, o) => o.toUpperCase()),
1388
+ // convert string attribute to float if necessary
1389
+ e === "emoji-version" ? parseFloat(i) : i
1390
+ );
1391
+ }
1392
+ _set(e, n) {
1393
+ this._ctx[e] = n, this._cmp && this._cmp.$set({ [e]: n }), ["locale", "dataSource"].includes(e) && this._dbFlush();
1394
+ }
1395
+ _dbCreate() {
1396
+ const { locale: e, dataSource: n, database: i } = this._ctx;
1397
+ (!i || i.locale !== e || i.dataSource !== n) && this._set("database", new Yt({ locale: e, dataSource: n }));
1398
+ }
1399
+ // Update the Database in one microtask if the locale/dataSource change. We do one microtask
1400
+ // so we don't create two Databases if e.g. both the locale and the dataSource change
1401
+ _dbFlush() {
1402
+ H(() => this._dbCreate());
1403
+ }
1404
+ }
1405
+ const He = {};
1406
+ for (const t of We)
1407
+ He[t] = {
1408
+ get() {
1409
+ return t === "database" && this._dbCreate(), this._ctx[t];
1410
+ },
1411
+ set(e) {
1412
+ if (t === "database")
1413
+ throw new Error("database is read-only");
1414
+ this._set(t, e);
1415
+ }
1416
+ };
1417
+ Object.defineProperties(Ve.prototype, He);
1418
+ customElements.get("emoji-picker") || customElements.define("emoji-picker", Ve);
1419
+ export {
1420
+ Yt as Database,
1421
+ Ve as Picker
1422
+ };