feat: introduce font picker (#8012)

Co-authored-by: dwelle <5153846+dwelle@users.noreply.github.com>
This commit is contained in:
Marcel Mraz 2024-07-25 18:55:55 +02:00 committed by GitHub
parent 4c5408263c
commit 62228e0bbb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
120 changed files with 3390 additions and 1106 deletions

View file

@ -88,6 +88,7 @@ export const getFontFamilyString = ({
}) => {
for (const [fontFamilyString, id] of Object.entries(FONT_FAMILY)) {
if (id === fontFamily) {
// TODO: we should fallback first to generic family names first, rather than directly to the emoji font
return `${fontFamilyString}, ${WINDOWS_EMOJI_FALLBACK_FONT}`;
}
}
@ -676,13 +677,45 @@ export const arrayToMapWithIndex = <T extends { id: string }>(
*/
export const arrayToObject = <T>(
array: readonly T[],
groupBy?: (value: T) => string,
groupBy?: (value: T) => string | number,
) =>
array.reduce((acc, value) => {
acc[groupBy ? groupBy(value) : String(value)] = value;
return acc;
}, {} as { [key: string]: T });
/** Doubly linked node */
export type Node<T> = T & {
prev: Node<T> | null;
next: Node<T> | null;
};
/**
* Creates a circular doubly linked list by adding `prev` and `next` props to the existing array nodes.
*/
export const arrayToList = <T>(array: readonly T[]): Node<T>[] =>
array.reduce((acc, curr, index) => {
const node: Node<T> = { ...curr, prev: null, next: null };
// no-op for first item, we don't want circular references on a single item
if (index !== 0) {
const prevNode = acc[index - 1];
node.prev = prevNode;
prevNode.next = node;
if (index === array.length - 1) {
// make the references circular and connect head & tail
const firstNode = acc[0];
node.next = firstNode;
firstNode.prev = node;
}
}
acc.push(node);
return acc;
}, [] as Node<T>[]);
export const isTestEnv = () => import.meta.env.MODE === "test";
export const isDevEnv = () => import.meta.env.MODE === "development";