@dxos/util 0.4.6 → 0.4.7-main.0a4f1cd
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/dist/lib/browser/index.mjs +190 -0
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs +199 -0
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/types/src/index.d.ts +1 -0
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/to-fallback.d.ts +17 -0
- package/dist/types/src/to-fallback.d.ts.map +1 -0
- package/dist/types/src/types.d.ts.map +1 -1
- package/package.json +6 -6
- package/src/index.ts +1 -0
- package/src/to-fallback.ts +195 -0
- package/src/types.ts +2 -1
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2023 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { type PublicKey } from '@dxos/keys';
|
|
6
|
+
|
|
7
|
+
export const idEmoji = [
|
|
8
|
+
// When changing this set, please check the result in a console or e.g. RunKit (https://runkit.com/thure/642214441dd6ae000855a8de)
|
|
9
|
+
// Emoji sometimes use a combination of code points, and some code points aren't visible on their own, so by adding or deleting you may unintentionally create non-visible items.
|
|
10
|
+
// This set was chosen from the characters in Unicode Emoji v15.0 based on the following criteria:
|
|
11
|
+
// – not people or isolated anthropomorphic faces
|
|
12
|
+
// – not flags
|
|
13
|
+
// – more concrete than abstract
|
|
14
|
+
// – less culturally specific
|
|
15
|
+
// – less easily confused with another emoji in the set
|
|
16
|
+
// – requires less special knowledge to identify
|
|
17
|
+
// – less likely to evoke negative feelings (no meat, no drugs, no weapons, etc)
|
|
18
|
+
// – less common as a signifier in UX
|
|
19
|
+
// NOTE that this is intentionally an array of strings because of the way emoji graphemes work.
|
|
20
|
+
'👹',
|
|
21
|
+
'👻',
|
|
22
|
+
'👽',
|
|
23
|
+
'🤖',
|
|
24
|
+
'🎃',
|
|
25
|
+
'🦾',
|
|
26
|
+
'🦿',
|
|
27
|
+
'🦷',
|
|
28
|
+
'👣',
|
|
29
|
+
'👁️',
|
|
30
|
+
'🧶',
|
|
31
|
+
'👑',
|
|
32
|
+
'🐒',
|
|
33
|
+
'🦆',
|
|
34
|
+
'🦉',
|
|
35
|
+
'🐴',
|
|
36
|
+
'🦄',
|
|
37
|
+
'🐝',
|
|
38
|
+
'🦋',
|
|
39
|
+
'🐞',
|
|
40
|
+
'🪲',
|
|
41
|
+
'🐢',
|
|
42
|
+
'🦎',
|
|
43
|
+
'🦕',
|
|
44
|
+
'🦑',
|
|
45
|
+
'🦀',
|
|
46
|
+
'🐠',
|
|
47
|
+
'🐬',
|
|
48
|
+
'🐋',
|
|
49
|
+
'🦭',
|
|
50
|
+
'🐅',
|
|
51
|
+
'🐆',
|
|
52
|
+
'🦓',
|
|
53
|
+
'🦍',
|
|
54
|
+
'🦧',
|
|
55
|
+
'🐘',
|
|
56
|
+
'🐫',
|
|
57
|
+
'🦒',
|
|
58
|
+
'🦘',
|
|
59
|
+
'🦬',
|
|
60
|
+
'🐖',
|
|
61
|
+
'🐏',
|
|
62
|
+
'🦌',
|
|
63
|
+
'🐕',
|
|
64
|
+
'🐈',
|
|
65
|
+
'🐓',
|
|
66
|
+
'🦚',
|
|
67
|
+
'🦜',
|
|
68
|
+
'🦢',
|
|
69
|
+
'🦩',
|
|
70
|
+
'🦦',
|
|
71
|
+
'🐁',
|
|
72
|
+
'🐿️',
|
|
73
|
+
'🌵',
|
|
74
|
+
'🌲',
|
|
75
|
+
'🌳',
|
|
76
|
+
'🪵',
|
|
77
|
+
'🌱',
|
|
78
|
+
'🍁',
|
|
79
|
+
'🪺',
|
|
80
|
+
'🍄',
|
|
81
|
+
'🐚',
|
|
82
|
+
'🪸',
|
|
83
|
+
'🪨',
|
|
84
|
+
'🌾',
|
|
85
|
+
'🌷',
|
|
86
|
+
'🌻',
|
|
87
|
+
'☀️',
|
|
88
|
+
'🌙',
|
|
89
|
+
'🪐',
|
|
90
|
+
'⭐️',
|
|
91
|
+
'⚡️',
|
|
92
|
+
'☄️',
|
|
93
|
+
'🔥',
|
|
94
|
+
'🌈',
|
|
95
|
+
'☁️',
|
|
96
|
+
'💧',
|
|
97
|
+
'⛱️',
|
|
98
|
+
'🌊',
|
|
99
|
+
'🍎',
|
|
100
|
+
'🍋',
|
|
101
|
+
'🍉',
|
|
102
|
+
'🍇',
|
|
103
|
+
'🫐',
|
|
104
|
+
'🍈',
|
|
105
|
+
'🍒',
|
|
106
|
+
'🍑',
|
|
107
|
+
'🥭',
|
|
108
|
+
'🍍',
|
|
109
|
+
'🥥',
|
|
110
|
+
'🥝',
|
|
111
|
+
'🥑',
|
|
112
|
+
'🌶️',
|
|
113
|
+
'🌽',
|
|
114
|
+
'🥕',
|
|
115
|
+
'🍬',
|
|
116
|
+
'🥜',
|
|
117
|
+
'🫖',
|
|
118
|
+
'☕️',
|
|
119
|
+
'🍵',
|
|
120
|
+
'🧊',
|
|
121
|
+
'🧂',
|
|
122
|
+
'🏔️',
|
|
123
|
+
'⚓️',
|
|
124
|
+
'🛟',
|
|
125
|
+
'🏝️',
|
|
126
|
+
'🛶',
|
|
127
|
+
'🚀',
|
|
128
|
+
'🛰️',
|
|
129
|
+
'⛲️',
|
|
130
|
+
'🏰',
|
|
131
|
+
'🚲',
|
|
132
|
+
'⛺️',
|
|
133
|
+
'🎙️',
|
|
134
|
+
'🧲',
|
|
135
|
+
'⚙️',
|
|
136
|
+
'🔩',
|
|
137
|
+
'🔮',
|
|
138
|
+
'🔭',
|
|
139
|
+
'🔬',
|
|
140
|
+
'🧬',
|
|
141
|
+
'🌡️',
|
|
142
|
+
'🧺',
|
|
143
|
+
'🛎️',
|
|
144
|
+
'🔑',
|
|
145
|
+
'🪑',
|
|
146
|
+
'🧸',
|
|
147
|
+
'🎈',
|
|
148
|
+
'🎀',
|
|
149
|
+
'🎊',
|
|
150
|
+
'♻️',
|
|
151
|
+
'🎵',
|
|
152
|
+
];
|
|
153
|
+
|
|
154
|
+
export const idHue = [
|
|
155
|
+
'red' as const,
|
|
156
|
+
// 'orange' as const, /* More shades in these palettes are considered “ugly” */
|
|
157
|
+
'amber' as const, // Amber arcs between red-orange and yellow as it gets lighter, so improves aesthetics.
|
|
158
|
+
// 'yellow' as const, /* More shades in these palettes are considered “ugly” */
|
|
159
|
+
'lime' as const,
|
|
160
|
+
'green' as const,
|
|
161
|
+
'emerald' as const,
|
|
162
|
+
'teal' as const,
|
|
163
|
+
'cyan' as const,
|
|
164
|
+
// 'sky' as const, /* Omitted since it is quite similar to the primary accent palette */
|
|
165
|
+
// 'blue' as const, /* Omitted since it is quite similar to the primary accent palette */
|
|
166
|
+
// 'indigo' as const, /* Omitted since it is quite similar to the primary accent palette */
|
|
167
|
+
'violet' as const,
|
|
168
|
+
'purple' as const,
|
|
169
|
+
'fuchsia' as const,
|
|
170
|
+
'pink' as const,
|
|
171
|
+
'rose' as const,
|
|
172
|
+
];
|
|
173
|
+
|
|
174
|
+
export const keyToEmoji = (key: PublicKey) => hexToEmoji(key.toHex());
|
|
175
|
+
|
|
176
|
+
export const hexToEmoji = (hex: string) => toEmoji(parseInt(hex, 16));
|
|
177
|
+
|
|
178
|
+
export const toEmoji = (hash: number) => idEmoji[hash % idEmoji.length];
|
|
179
|
+
|
|
180
|
+
export const keyToHue = (key: PublicKey) => hexToHue(key.toHex());
|
|
181
|
+
|
|
182
|
+
export const hexToHue = (hex: string) => toHue(parseInt(hex, 16));
|
|
183
|
+
|
|
184
|
+
export const toHue = (hash: number) => idHue[hash % idHue.length];
|
|
185
|
+
|
|
186
|
+
export type FallbackValue = {
|
|
187
|
+
emoji: string;
|
|
188
|
+
hue: (typeof idHue)[number];
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
export const keyToFallback = (key: PublicKey) => hexToFallback(key.toHex());
|
|
192
|
+
|
|
193
|
+
export const hexToFallback = (hex: string) => toFallback(parseInt(hex, 16));
|
|
194
|
+
|
|
195
|
+
export const toFallback = (hash: number): FallbackValue => ({ emoji: toEmoji(hash), hue: toHue(hash) });
|
package/src/types.ts
CHANGED
|
@@ -23,10 +23,11 @@ export type MaybeFunction<T> = T | (() => T);
|
|
|
23
23
|
* NOTE: To filter by type:
|
|
24
24
|
* items.filter((item: any): item is RangeSet<Decoration> => item instanceof RangeSet)
|
|
25
25
|
*/
|
|
26
|
-
// TODO(burdon): Reconcile names.
|
|
26
|
+
// TODO(burdon): Reconcile names and variants.
|
|
27
27
|
export const isNotFalsy = <T>(value: T): value is Exclude<T, Falsy> => !!value;
|
|
28
28
|
export const nonNullable = <T>(value: T): value is NonNullable<T> => value !== null && value !== undefined;
|
|
29
29
|
export const isNotNullOrUndefined = <T>(value: T): value is Exclude<T, null | undefined> => value != null;
|
|
30
|
+
// export const isNotNullish = <T>(value: T | null | undefined): value is T => value !== undefined && value !== null;
|
|
30
31
|
export const boolGuard = <T>(value: T | null | undefined): value is T => Boolean(value);
|
|
31
32
|
|
|
32
33
|
/**
|