Skip to content

AI-native knowledge base & Evernote/Obsidian alternative with instant sync & native MCP. Free on Cloudflare or self-hosted via Docker.

11.4 KB
Raw Blame
import { OFFLINE_SANS_FAMILY } from "./font-defaults";

/** Shared optional font catalog. Only metadata ships in clients; files stay on the CDN. */
export const FONT_CATALOG = {
  smiley: { zh: "得意黑", en: "Smiley Sans", posterFamily: "得意黑", labelKey: "editor.imageShare.fontStyles.smiley", family: "EdgeEver Share Smiley", path: "@chinese-fonts/[email protected]/dist/SmileySans-Oblique/result.css" },
  wenkai: { zh: "霞鹜文楷", en: "LXGW WenKai", posterFamily: "霞鹜文楷", labelKey: "editor.imageShare.fontStyles.wenkai", family: "EdgeEver Share WenKai", path: "@chinese-fonts/[email protected]/dist/LXGWWenKai-Regular/result.css" },
  zhuque: { zh: "朱雀仿宋", en: "Zhuque Fangsong", posterFamily: "朱雀仿宋", labelKey: "editor.imageShare.fontStyles.zhuque", family: "EdgeEver Share Zhuque", path: "@chinese-fonts/[email protected]/dist/ZhuqueFangsong-Regular/result.css" },
  heavy: { zh: "思源黑体 Heavy", en: "Noto Sans SC Heavy", posterFamily: "思源黑体 Heavy", labelKey: "editor.imageShare.fontStyles.heavy", family: "EdgeEver Share Noto Heavy", path: "@fontsource/[email protected]/900.css" },
  // Preserve the original containers for fonts whose terms do not permit subsetting.
  puhui: { zh: "普惠体", en: "PuHuiTi", posterFamily: "阿里巴巴普惠体", labelKey: "editor.imageShare.fontStyles.puhui", family: "EdgeEver Share Puhui", path: "@fontpkg/[email protected]/AlibabaPuHuiTi-3-55-Regular.ttf", weight: "400", bytes: 8532824, sha256: "be33bc8d45ced30fa5c542f6f056565baf85003d4e079522110d76016f8a04e2" },
  "puhui-heavy": { zh: "普惠体 Heavy", en: "PuHuiTi Heavy", posterFamily: "阿里巴巴普惠体 Heavy", labelKey: "editor.imageShare.fontStyles.puhuiHeavy", family: "EdgeEver Share Puhui Heavy", path: "@fontpkg/[email protected]/AlibabaPuHuiTi-3-105-Heavy.ttf", weight: "900", bytes: 2536300, sha256: "94cbb24e451a68b44d932d343579fb31571c743df2cfcd144ba60e0a9aa86e64" },
  youshe: { zh: "优设标题黑", en: "YouShe Title", posterFamily: "优设标题黑", labelKey: "editor.imageShare.fontStyles.youshe", family: "EdgeEver Share Youshe", path: "@fontpkg/[email protected]/%E4%BC%98%E8%AE%BE%E6%A0%87%E9%A2%98%E9%BB%91.ttf", weight: "400", bytes: 1414784, sha256: "dab883d69fb713233ea5d9aff8d1f27ccc2b71e249143edf6ea08367784c5dba" },
  shuhei: { zh: "阿里妈妈数黑体", en: "Alimama ShuHei", posterFamily: "阿里妈妈数黑体", labelKey: "editor.imageShare.fontStyles.shuhei", family: "EdgeEver Share Shuhei", path: "@fontpkg/[email protected]/AlimamaShuHeiTi-Bold.ttf", weight: "700", bytes: 1360708, sha256: "3ef4ec3f5bac4b71cdee9190aabd5b20995016a59ffee60de87c9a204ac2a684" },

  // Reuse existing poster assets unchanged, pinned to a repository commit.
  "source-han-serif": {"zh": "思源宋体", "en": "Noto Serif SC", "posterFamily": "思源宋体", "labelKey": "editor.imageShare.fontStyles.source-han-serif", "family": "EdgeEver Share Noto Serif SC", "path": "gh/tianma-if/edgeever@0da78f6ce8a4643b2dfb7afe9f7a5101472c4ffb/apps/web/public/poster-fonts/notoserif.woff2", "weight": "400", "bytes": 1662732, "sha256": "de134adb512429992d47096d5e5d94d0488d3890f4e9a592aaabcf4fc6fb3355"},
  "anton": {"zh": "Anton", "en": "Anton", "posterFamily": "Anton", "labelKey": "editor.imageShare.fontStyles.anton", "family": "EdgeEver Share Anton", "path": "gh/tianma-if/edgeever@0da78f6ce8a4643b2dfb7afe9f7a5101472c4ffb/apps/web/public/poster-fonts/anton.woff2", "weight": "400", "bytes": 19460, "sha256": "5aa51ca1a8d65846f52724d0e3c6f728347f19df1f4ee88acde613ef403f50c1"},
  "douyin": {"zh": "抖音美好体", "en": "Douyin Sans", "posterFamily": "抖音美好体", "labelKey": "editor.imageShare.fontStyles.douyin", "family": "EdgeEver Share Douyin Sans", "path": "gh/tianma-if/edgeever@0da78f6ce8a4643b2dfb7afe9f7a5101472c4ffb/apps/web/public/poster-fonts/douyin.ttf", "weight": "400", "bytes": 1919404, "sha256": "fbecfacdfac33982774e301073a8d357a09c698cd3134bb6ddec0f5bfc268fa1"},
  "mashan": {"zh": "马善政楷书", "en": "Ma Shan Zheng", "posterFamily": "马善政楷书", "labelKey": "editor.imageShare.fontStyles.mashan", "family": "EdgeEver Share Ma Shan Zheng", "path": "gh/tianma-if/edgeever@0da78f6ce8a4643b2dfb7afe9f7a5101472c4ffb/apps/web/public/poster-fonts/mashan.woff2", "weight": "400", "bytes": 3233640, "sha256": "9bb3130d1b7e752e1df902891a41c7aeb5b94697951acf54eec60b954d7a1cb2"},
  "jiangcheng": {"zh": "江城圆体", "en": "Jiangcheng Rounded", "posterFamily": "江城圆体", "labelKey": "editor.imageShare.fontStyles.jiangcheng", "family": "EdgeEver Share Jiangcheng Rounded", "path": "gh/tianma-if/edgeever@0da78f6ce8a4643b2dfb7afe9f7a5101472c4ffb/apps/web/public/poster-fonts/jiangcheng.woff2", "weight": "400", "bytes": 1565164, "sha256": "0be9728fe58f3c69ad93a2a952ab0e78089873f06ebe80110b67664ffa22cbdc"},
  "huangyou": {"zh": "站酷庆科黄油体", "en": "ZCOOL QingKe HuangYou", "posterFamily": "站酷庆科黄油体", "labelKey": "editor.imageShare.fontStyles.huangyou", "family": "EdgeEver Share ZCOOL QingKe HuangYou", "path": "gh/tianma-if/edgeever@0da78f6ce8a4643b2dfb7afe9f7a5101472c4ffb/apps/web/public/poster-fonts/huangyou.woff2", "weight": "400", "bytes": 1742972, "sha256": "a15d7e72cd7ad20b67ecf6adf46d08bab5764ea700ec8fae7cc29055e9cb9fbc"},
  "glow": {"zh": "未来荧黑", "en": "Glow Sans", "posterFamily": "未来荧黑", "labelKey": "editor.imageShare.fontStyles.glow", "family": "EdgeEver Share Glow Sans", "path": "gh/tianma-if/edgeever@0da78f6ce8a4643b2dfb7afe9f7a5101472c4ffb/apps/web/public/poster-fonts/glow.woff2", "weight": "900", "bytes": 1826500, "sha256": "c12d4668a33019c757a9ec2c6d7fc43629189a8d5e8636d9bb38c3936020684c"},
  "kuaile": {"zh": "站酷快乐体", "en": "ZCOOL KuaiLe", "posterFamily": "站酷快乐体", "labelKey": "editor.imageShare.fontStyles.kuaile", "family": "EdgeEver Share ZCOOL KuaiLe", "path": "gh/tianma-if/edgeever@0da78f6ce8a4643b2dfb7afe9f7a5101472c4ffb/apps/web/public/poster-fonts/kuaile.woff2", "weight": "400", "bytes": 855692, "sha256": "19d11b1154b2e5f37371d7be9640dbae97d06fbf2331cb5fc257ae5f813ea5e8"},
  "source-han-sans": {"zh": "思源黑体", "en": "Noto Sans SC", "posterFamily": "思源黑体", "labelKey": "editor.imageShare.fontStyles.source-han-sans", "family": "EdgeEver Share Noto Sans SC", "path": "gh/tianma-if/edgeever@0da78f6ce8a4643b2dfb7afe9f7a5101472c4ffb/apps/web/public/poster-fonts/notosans.woff2", "weight": "400", "bytes": 1263476, "sha256": "3ca125c45785eab24bdcd4d4039431479fef196c3aa9913fed4b0f255336101f"},
  "source-han-serif-heavy": {"zh": "思源宋体 Heavy", "en": "Noto Serif SC Heavy", "posterFamily": "思源宋体 Heavy", "labelKey": "editor.imageShare.fontStyles.source-han-serif-heavy", "family": "EdgeEver Share Noto Serif SC Heavy", "path": "gh/tianma-if/edgeever@0da78f6ce8a4643b2dfb7afe9f7a5101472c4ffb/apps/web/public/poster-fonts/notoserif-heavy.woff2", "weight": "900", "bytes": 1580648, "sha256": "729c42f795041ba47f794be1729e6d515b51f73d9baf2085c5b0941e30e6bfb3"},
  "inter": {"zh": "Inter", "en": "Inter", "posterFamily": "Inter", "labelKey": "editor.imageShare.fontStyles.inter", "family": "EdgeEver Share Inter", "path": "gh/tianma-if/edgeever@0da78f6ce8a4643b2dfb7afe9f7a5101472c4ffb/apps/web/public/poster-fonts/inter.woff2", "weight": "400", "bytes": 24980, "sha256": "47084ea0d235fbca0b0c5ec663969a906daaeb667fd5f191007ec5c80b62ed5c"},
  "dmserif": {"zh": "DM Serif Display", "en": "DM Serif Display", "posterFamily": "DM Serif Display", "labelKey": "editor.imageShare.fontStyles.dmserif", "family": "EdgeEver Share DM Serif Display", "path": "gh/tianma-if/edgeever@0da78f6ce8a4643b2dfb7afe9f7a5101472c4ffb/apps/web/public/poster-fonts/dmserif.woff2", "weight": "400", "bytes": 27692, "sha256": "c0652f22903b1a547ad50495aa3f5314e4f666e34921e9e953e3f545fdde14ba"},
  "bebas": {"zh": "Bebas Neue", "en": "Bebas Neue", "posterFamily": "Bebas Neue", "labelKey": "editor.imageShare.fontStyles.bebas", "family": "EdgeEver Share Bebas Neue", "path": "gh/tianma-if/edgeever@0da78f6ce8a4643b2dfb7afe9f7a5101472c4ffb/apps/web/public/poster-fonts/bebas.woff2", "weight": "400", "bytes": 15428, "sha256": "83baf2705cd75f7047e8d11dc9aceeb4ee50407a72f1981937b0b909227b1e68"},
  "spacegrotesk": {"zh": "Space Grotesk", "en": "Space Grotesk", "posterFamily": "Space Grotesk", "labelKey": "editor.imageShare.fontStyles.spacegrotesk", "family": "EdgeEver Share Space Grotesk", "path": "gh/tianma-if/edgeever@0da78f6ce8a4643b2dfb7afe9f7a5101472c4ffb/apps/web/public/poster-fonts/spacegrotesk.woff2", "weight": "400", "bytes": 15600, "sha256": "8c3d72df71f151bd549c89d78b146858c25e4d16d3a3bfe79bf93bf37ee2c9ae"},
  "maple-mono-cn": { zh: "Maple Mono CN", en: "Maple Mono CN", posterFamily: "Maple Mono CN", labelKey: "editor.imageShare.fontStyles.mapleMonoCn", family: "EdgeEver Share Maple Mono CN", path: "@chinese-fonts/[email protected]/dist/MapleMono-CN-Regular/result.css", downloadOnSelect: true, monospace: true },
  "jetbrains": {"monospace": true, "zh": "JetBrains Mono", "en": "JetBrains Mono", "posterFamily": "JetBrains Mono", "labelKey": "editor.imageShare.fontStyles.jetbrains", "family": "EdgeEver Share JetBrains Mono", "path": "gh/tianma-if/edgeever@0da78f6ce8a4643b2dfb7afe9f7a5101472c4ffb/apps/web/public/poster-fonts/jetbrains.woff2", "weight": "400", "bytes": 22516, "sha256": "1d5b5738120473ecb0d758290426d6d4b59873b7f3d4608541989cd0ab5452e3"},
} as const;

/** The five entries in Qiaomu's approximately 15 MB designer starter pack. */
export const NOTE_IMAGE_RECOMMENDED_FONT_IDS = ["puhui", "puhui-heavy", "youshe", "shuhei", "smiley"] as const;

export type RemoteNoteImageFont = keyof typeof FONT_CATALOG;
export const isRemoteNoteImageFont = (value: string): value is RemoteNoteImageFont => Object.hasOwn(FONT_CATALOG, value);

export const FONT_IDS = Object.keys(FONT_CATALOG) as RemoteNoteImageFont[];

/** Note-body settings menu only. Poster and image-share lists keep FONT_IDS order. */
export const NOTE_BODY_FONT_MENU_GROUPS = {
  chineseReading: ["wenkai", "zhuque", "source-han-serif", "source-han-sans", "puhui", "maple-mono-cn"],
  chineseDisplay: ["smiley", "heavy", "puhui-heavy", "youshe", "shuhei", "douyin", "mashan", "jiangcheng", "huangyou", "glow", "kuaile", "source-han-serif-heavy"],
  latin: ["inter", "spacegrotesk", "dmserif", "anton", "bebas", "jetbrains"],
} as const satisfies Record<"chineseReading" | "chineseDisplay" | "latin", readonly RemoteNoteImageFont[]>;
export const findCatalogFont = (idOrFamily: string) => FONT_IDS.find(id => id === idOrFamily || FONT_CATALOG[id].family === idOrFamily || FONT_CATALOG[id].posterFamily === idOrFamily);
export const catalogFontStack = (id: RemoteNoteImageFont) => `"${FONT_CATALOG[id].family}", "${OFFLINE_SANS_FAMILY}", system-ui, sans-serif`;
export const CATALOG_FONT_STACKS = Object.fromEntries(FONT_IDS.map(id => [id, catalogFontStack(id)])) as Record<RemoteNoteImageFont, string>;

/** Selection-only fonts must not download merely because their menu row is visible. */
export const shouldLoadFontPreview = (id: string | undefined, selected: boolean) => {
  if (!id || !isRemoteNoteImageFont(id)) return true;
  const font = FONT_CATALOG[id];
  return selected || !("downloadOnSelect" in font && font.downloadOnSelect);
};

/** Only verified monospace choices can replace a code editor's font. */
export const catalogCodeFontStack = (id: string | null | undefined): string | null => {
  if (!id || !isRemoteNoteImageFont(id)) return null;
  const font = FONT_CATALOG[id];
  return "monospace" in font && font.monospace
    ? `"${font.family}", ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace`
    : null;
};