@docfonts/fallbacks

中文文档
0.16.0发布于 2026/06/11MITTypeScriptES Module零依赖近 30 天下载 51.2万

Measured open-font fallbacks for proprietary document fonts.

原始使用文档
文档目录6 节
  1. Install
  2. Render a font
  3. Explain a decision
  4. Build a resolver map
  5. Fidelity fields
  6. Provenance

@docfonts/fallbacks

Measured open-font fallbacks for proprietary document fonts.

The package ships decisions, not fonts: which open family to render when one is reviewed, how faithful it is, and when no open fallback should be used.

Install

npm install @docfonts/fallbacks

ESM-only.

Render a font

Use getRenderableFallback when you need one family to render now. Pass canRenderFamily so the result only includes fonts your app can load.

import { getRenderableFallback } from "@docfonts/fallbacks";

const fallback = getRenderableFallback("Helvetica", {
  canRenderFamily: (family) => bundledFamilies.has(family),
});

Returns null when docfonts has no renderable fallback from your available assets.

Explain a decision

Use getFallbackDecision for UI, diagnostics, and reports.

import { getFallbackDecision } from "@docfonts/fallbacks";

getFallbackDecision("Aptos");
// { kind: "customer_supplied", evidenceId: "aptos", generic: "sans-serif" }

getFallbackDecision("Georgia", {
  canRenderFamily: (family) => bundledFamilies.has(family),
});
// { kind: "asset_missing", substituteFamily: "Gelasio", verdict: "near_metric", ... }

Important decision kinds:

  • fallback - render fallback.substituteFamily.
  • asset_missing - docfonts has a fallback, but your app does not load it.
  • face_missing - the fallback does not provide the requested face.
  • customer_supplied, preserve_only, or no_recommended_fallback - do not substitute.
  • unknown - docfonts has no evidence for this family.

Build a resolver map

Use createFallbackMap when wiring a resolver. canRenderFamily is required so the map never points at fonts you cannot load.

import { createFallbackMap, normalizeFamilyName } from "@docfonts/fallbacks";

const map = createFallbackMap({
  canRenderFamily: (family) => bundledFamilies.has(family),
});

map[normalizeFamilyName("Times New Roman")];

Some fallbacks are face-scoped. faces reports real face coverage. Use getRenderableFallbackForFace for styled text; a result may include faceSource, where synthetic means render from the indicated face and let your renderer synthesize the requested style.

Fidelity fields

  • verdict - measured fidelity, such as metric_safe, near_metric, cell_width_only, or visual_only.
  • lineBreakSafe - true when advances preserve line breaks.
  • glyphExceptions - named glyphs that can reflow.
  • advance.basis - sample/model used for mean and max deltas, such as latin_full, latin_text, or monospace_cell.
  • generic - CSS generic family for last-resort fallback.
  • evidenceId - stable id for the reviewed evidence row.

SUBSTITUTION_EVIDENCE exposes the full reviewed rows for richer reporting.

Provenance

Measurements are produced against licensed originals. This package distributes no proprietary binaries, raw proprietary metrics, or font files.

candidateLicense is a candidate license id or expression: SPDX when exact, stable docfonts label otherwise.

版本与发布记录

@docfonts/fallbacks 共发布 16 个版本,首次发布于 2026/06/06;过去 12 个月发布了 16 个版本。

版本发布日期距今
0.16.0latest2026/06/115 个月前
0.15.02026/06/105 个月前
0.14.02026/06/105 个月前
0.13.02026/06/105 个月前
0.12.02026/06/105 个月前
0.11.02026/06/095 个月前

关于 @docfonts/fallbacks 的常见问题

@docfonts/fallbacks 是什么?

Measured open-font fallbacks for proprietary document fonts.

如何安装 @docfonts/fallbacks?

在项目目录运行 npm install @docfonts/fallbacks,或使用 pnpm add / yarn add / bun add。

@docfonts/fallbacks 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@docfonts/fallbacks 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@docfonts/fallbacks 可以商用吗?

@docfonts/fallbacks 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@docfonts/fallbacks 的下载量有多少?

根据 npm 官方下载统计,@docfonts/fallbacks 在 2026/10/13 – 2026/11/11 这 30 天内被下载 511,719 次,日均约 17,057 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@docfonts/fallbacks 还在维护吗?

最新版本 0.16.0 发布于 2026/06/11(5 个月前);至今共发布 16 个版本,其中过去 12 个月发布了 16 个;首次发布于 2026/06/06。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。