mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-24 05:48:59 +08:00
1f45cc5dec
**Directory Structure Changes** - Renamed multiple block-related directories by removing the "block-" prefix: - `block-attachment` → `attachment` - `block-bookmark` → `bookmark` - `block-callout` → `callout` - `block-code` → `code` - `block-data-view` → `data-view` - `block-database` → `database` - `block-divider` → `divider` - `block-edgeless-text` → `edgeless-text` - `block-embed` → `embed`
48 lines
1.3 KiB
TypeScript
48 lines
1.3 KiB
TypeScript
import type { FontFamily } from '@blocksuite/affine-model';
|
|
import { IS_FIREFOX } from '@blocksuite/global/env';
|
|
|
|
export function wrapFontFamily(fontFamily: FontFamily | string): string {
|
|
return `"${fontFamily}"`;
|
|
}
|
|
|
|
export const getFontFaces = IS_FIREFOX
|
|
? () => {
|
|
const keys = document.fonts.keys();
|
|
const fonts = [];
|
|
let done = false;
|
|
while (!done) {
|
|
const item = keys.next();
|
|
done = !!item.done;
|
|
if (item.value) {
|
|
fonts.push(item.value);
|
|
}
|
|
}
|
|
return fonts;
|
|
}
|
|
: () => [...document.fonts.keys()];
|
|
|
|
export const isSameFontFamily = IS_FIREFOX
|
|
? (fontFamily: FontFamily | string) => (fontFace: FontFace) =>
|
|
fontFace.family === `"${fontFamily}"`
|
|
: (fontFamily: FontFamily | string) => (fontFace: FontFace) =>
|
|
fontFace.family === fontFamily;
|
|
|
|
export function getFontFacesByFontFamily(
|
|
fontFamily: FontFamily | string
|
|
): FontFace[] {
|
|
return (
|
|
getFontFaces()
|
|
.filter(isSameFontFamily(fontFamily))
|
|
// remove duplicate font faces
|
|
.filter(
|
|
(item, index, arr) =>
|
|
arr.findIndex(
|
|
fontFace =>
|
|
fontFace.family === item.family &&
|
|
fontFace.weight === item.weight &&
|
|
fontFace.style === item.style
|
|
) === index
|
|
)
|
|
);
|
|
}
|