@chromaglyph/节点
粘合剂 铬数字 : 将语法突出显示为 OpenType 颜色字体,在进程内.
import { buildFontSafe } from '@chromaglyph/node'
const result = buildFontSafe({
font: fontBytes, // static TTF / OTF (CFF) / WOFF1 / .ttc Buffer
fontIndex: 0, // member of a .ttc collection (default 0)
themes: ['dark-plus', 'light-plus'], // builtin names or .json/.tmTheme paths
blocks: [ // batch any number of code blocks into ONE font
{ id: 'block-0', lang: 'rust', text: 'fn main() {}' },
{ id: 'block-1', lang: 'js', text: 'const x = 1' },
],
verify: true, // harfrust oracle (default on)
ligatures: true, // keep the font's != -> ligatures, highlighted
format: 'woff2', // output container: 'woff' (default) | 'woff2'
cacheDir: '.cache', // optional on-disk cache
})
// → { woff, ttf, css, themes, report, contentHash, cached }
buildFont丢入无效输入;buildFontSafe返回时null(建造管道的沉积退化).- 出处字体:静态 TrueType (TTF)和名键 CFF (OTF); WOFF1
集装箱和
.ttc收款(fontIndex)是未包装的,可变 TrueType字体被钉入默认实例. CFF2(可变 OTF)和CID键CFF被明确错误地拒绝. format: 'woff2'在 WOFF2 (Brotli, 小于 15-30%) 中将输出包起来 而不是默认的 WOFF1 ;result.woff然后携带WOFF2字节. 两者都概括出其中的口味(TrueType as-is,CFF null-transform). 格式是内容散列的一部分, 所以两个变体缓存 独立.ligatures: true将源字体的绳索再现实化 (单位:千美元)!=, (中文(简体) ),->)作为构建时的规则,所以它们精确地渲染出字体 意图同时突出显示; 跨多颜色的网站 分解为纯正的每char文本( 颜色胜出) .generic: 'rust' | 'js' | 'ts' | 'python' | 'go' | 'java'构建字体 突出内容 该语言的任何文本(关键词、评论、字符串、数字) -blocks财务报告和审定财务报表semantic在此模式中被忽略.- 人工活性通过内容散列来缓存(font +主题来源 +块文本)
- 通用语言 + 选项: 进程内 LRU 外加可选的磁盘 缓存目录 .
- 一个GSUB规则集服务于每个主题(CPAL调色板);切换是一个
支助科
@font-palette-values翻转. themes使用内建名称或路径。 建筑是奇克的 主题 收集(64个主题,仅MIT/Apache-2.0);listThemes()返回时 登记处 -name, (中文(简体) ),displayName, (中文(简体) ),type(单位:千美元)'dark' | 'light', (中文(简体) ),license, (中文(简体) ),source, (中文(简体) ),foreground, (中文(简体) ),background和范围swatches——足够在不编译字体的情况下构建取题器.tmThemesVersion()告诉哪些收藏版本已嵌入 .
从源构建 : pnpm --filter @chromaglyph/node build (须取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取出.