@minnalstack/editor-plugin-emoji 0.0.0-stage → 0.3.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Aranghat
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,9 @@
1
- # Temporary Holding Version
1
+ # @minnalstack/editor-plugin-emoji
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Emoji as Unicode characters: a picker in the toolbar and the slash menu, and suggestions while typing.
4
+
5
+ ```sh
6
+ npm install @minnalstack/editor-plugin-emoji
7
+ ```
8
+
9
+ MIT licensed.
@@ -0,0 +1,69 @@
1
+ # Third-party notices
2
+
3
+ The emoji, their names and shortcodes come from emojibase-data 16.0.3, which draws on the Unicode emoji data.
4
+
5
+ ## emojibase
6
+
7
+ MIT License
8
+
9
+ Copyright (c) 2017-2019 Miles Johnson
10
+
11
+ Permission is hereby granted, free of charge, to any person obtaining a copy
12
+ of this software and associated documentation files (the "Software"), to deal
13
+ in the Software without restriction, including without limitation the rights
14
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15
+ copies of the Software, and to permit persons to whom the Software is
16
+ furnished to do so, subject to the following conditions:
17
+
18
+ The above copyright notice and this permission notice shall be included in all
19
+ copies or substantial portions of the Software.
20
+
21
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27
+ SOFTWARE.
28
+
29
+ ## Unicode
30
+
31
+ UNICODE LICENSE V3
32
+
33
+ COPYRIGHT AND PERMISSION NOTICE
34
+
35
+ Copyright © 1991-2026 Unicode, Inc.
36
+
37
+ NOTICE TO USER: Carefully read the following legal agreement. BY
38
+ DOWNLOADING, INSTALLING, COPYING OR OTHERWISE USING DATA FILES, AND/OR
39
+ SOFTWARE, YOU UNEQUIVOCALLY ACCEPT, AND AGREE TO BE BOUND BY, ALL OF THE
40
+ TERMS AND CONDITIONS OF THIS AGREEMENT. IF YOU DO NOT AGREE, DO NOT
41
+ DOWNLOAD, INSTALL, COPY, DISTRIBUTE OR USE THE DATA FILES OR SOFTWARE.
42
+
43
+ Permission is hereby granted, free of charge, to any person obtaining a
44
+ copy of data files and any associated documentation (the "Data Files") or
45
+ software and any associated documentation (the "Software") to deal in the
46
+ Data Files or Software without restriction, including without limitation
47
+ the rights to use, copy, modify, merge, publish, distribute, and/or sell
48
+ copies of the Data Files or Software, and to permit persons to whom the
49
+ Data Files or Software are furnished to do so, provided that either (a)
50
+ this copyright and permission notice appear with all copies of the Data
51
+ Files or Software, or (b) this copyright and permission notice appear in
52
+ associated Documentation.
53
+
54
+ THE DATA FILES AND SOFTWARE ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
55
+ KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
56
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
57
+ THIRD PARTY RIGHTS.
58
+
59
+ IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS INCLUDED IN THIS NOTICE
60
+ BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES,
61
+ OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
62
+ WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
63
+ ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THE DATA
64
+ FILES OR SOFTWARE.
65
+
66
+ Except as contained in this notice, the name of a copyright holder shall
67
+ not be used in advertising or otherwise to promote the sale, use or other
68
+ dealings in these Data Files or Software without prior written
69
+ authorization of the copyright holder.
@@ -0,0 +1,14 @@
1
+ import type { PickerContent } from '@minnalstack/editor-core';
2
+ import { type SkinTone } from './skin-tones.js';
3
+ /** What the plugin reads from its data, which is in a module of its own so that a page loads it only when someone wants an emoji. */
4
+ export interface EmojiContent extends PickerContent {
5
+ /** The characters of the emoji with this shortcode, in the chosen skin tone, if there is one. */
6
+ find(code: string): string | undefined;
7
+ }
8
+ /** Where the skin tone is kept, which is the plugin, because it outlasts a picker. */
9
+ export interface ToneKeeper {
10
+ readonly current: () => SkinTone;
11
+ readonly choose: (tone: SkinTone) => void;
12
+ }
13
+ export declare function emojiContent(tones: ToneKeeper): EmojiContent;
14
+ //# sourceMappingURL=content.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"content.d.ts","sourceRoot":"","sources":["../src/content.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAgB,aAAa,EAAe,MAAM,0BAA0B,CAAC;AAEzF,OAAO,EAAE,KAAK,QAAQ,EAA2B,MAAM,iBAAiB,CAAC;AASzE,qIAAqI;AACrI,MAAM,WAAW,YAAa,SAAQ,aAAa;IACjD,iGAAiG;IACjG,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;CACxC;AAED,sFAAsF;AACtF,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,OAAO,EAAE,MAAM,QAAQ,CAAC;IACjC,QAAQ,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,QAAQ,KAAK,IAAI,CAAC;CAC3C;AAmBD,wBAAgB,YAAY,CAAC,KAAK,EAAE,UAAU,GAAG,YAAY,CAmD5D"}
@@ -0,0 +1,79 @@
1
+ import { emojiData } from './data.js';
2
+ import { skinTones, withSkinTone } from './skin-tones.js';
3
+ function parse(row) {
4
+ const [text, name, codes, words, takesTone] = row.split(';');
5
+ const shortcodes = codes === '' ? [] : codes.split(',');
6
+ return { text, name, codes: shortcodes, words: words === '' ? [] : words.split(','), takesTone: takesTone === '1', ...(shortcodes[0] === undefined ? {} : { detail: `:${shortcodes[0]}:` }) };
7
+ }
8
+ /** How well an emoji matches a word: lower is better, and undefined is no match. */
9
+ function score(emoji, word) {
10
+ if (emoji.codes.includes(word))
11
+ return 0;
12
+ if (emoji.codes.some((code) => code.startsWith(word)))
13
+ return 1;
14
+ if (emoji.name.startsWith(word))
15
+ return 2;
16
+ if (emoji.name.includes(` ${word}`))
17
+ return 3;
18
+ if (emoji.words.some((other) => other.startsWith(word)))
19
+ return 4;
20
+ if (emoji.name.includes(word) || emoji.codes.some((code) => code.includes(word)))
21
+ return 5;
22
+ return undefined;
23
+ }
24
+ export function emojiContent(tones) {
25
+ const byCode = new Map();
26
+ const everything = [];
27
+ /** Made when it is drawn, so that a tone costs nothing for emoji that don't show. */
28
+ const shownIn = (emoji) => {
29
+ const tone = tones.current();
30
+ return tone === 'none' || !emoji.takesTone ? emoji : { ...emoji, text: withSkinTone(emoji.text, tone) };
31
+ };
32
+ const groups = emojiData.split('\n\n').map((section) => {
33
+ const [title, ...rows] = section.split('\n');
34
+ const [name, mark] = title.split(';');
35
+ const list = rows.map(parse);
36
+ for (const emoji of list) {
37
+ everything.push(emoji);
38
+ for (const code of emoji.codes)
39
+ byCode.set(code, emoji);
40
+ }
41
+ return { name, mark, size: list.length, choice: (index) => shownIn(list[index]) };
42
+ });
43
+ return {
44
+ groups,
45
+ variants: {
46
+ label: 'Skin tone',
47
+ options: skinTones.map(({ value, name }) => ({ value, name, mark: withSkinTone('✋', value) })),
48
+ current: tones.current,
49
+ choose: (value) => tones.choose(value),
50
+ },
51
+ find: (code) => {
52
+ const emoji = byCode.get(code);
53
+ return emoji === undefined ? undefined : shownIn(emoji).text;
54
+ },
55
+ search: (query, limit) => {
56
+ const words = query.toLowerCase().replaceAll(':', ' ').trim().split(/[\s_]+/).filter((word) => word !== '');
57
+ if (words.length === 0)
58
+ return [];
59
+ const whole = words.join('_');
60
+ const found = [];
61
+ for (const emoji of everything) {
62
+ let rank = emoji.codes.includes(whole) ? -1 : 0;
63
+ for (const word of words) {
64
+ const one = score(emoji, word);
65
+ if (one === undefined) {
66
+ rank = Number.NaN;
67
+ break;
68
+ }
69
+ rank += one;
70
+ }
71
+ if (!Number.isNaN(rank))
72
+ found.push({ emoji, rank });
73
+ }
74
+ // Array.sort is stable, so emoji that match as well keep the order Unicode gives them.
75
+ return found.sort((a, b) => a.rank - b.rank).slice(0, limit).map(({ emoji }) => shownIn(emoji));
76
+ },
77
+ };
78
+ }
79
+ //# sourceMappingURL=content.js.map
@@ -0,0 +1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}
package/dist/data.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export declare const emojiData: string;
2
+ //# sourceMappingURL=data.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"data.d.ts","sourceRoot":"","sources":["../src/data.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,SAAS,EAAE,MA03DoB,CAAC"}