@fibrae/semi-foundation

中文文档
0.7.0发布于 2026/11/14MITES Module构建来源已验证近 30 天下载 2345
原始使用文档
文档目录7 节
  1. Foundation and Adapter
  2. Installation
  3. Usage
  4. Directories
  5. Locale packs
  6. Related packages
  7. Development

@fibrae/semi-foundation

简体中文

The framework-agnostic part of Semi Design Next: component logic (Foundation), SCSS styles, theme tokens and locale packs. The component libraries of every framework share it. Applications usually use it through a UI package rather than depending on it directly.

Foundation and Adapter

The JavaScript of each component has two parts so it can be reused across frameworks:

  • Foundation: holds the component's business logic and references no DOM. Logic that needs the DOM is delegated to the Adapter.
  • Adapter: the interface of the methods a Foundation needs, implemented by each framework package with its native mechanism (such as a React hook or a Vue composable).

This is why the package depends on no framework or UI package.

Installation

pnpm add @fibrae/semi-foundation

Build plugins need it to resolve semi: addresses, and the UI packages already depend on it.

Usage

This package has no root entry. The base, utils and locale directories each have an entry that gathers the directory's exports. Other modules are imported by deep file paths, which map one-to-one to the directories under src/. All come with type declarations:

import { BaseFoundation, FocusScope } from '@fibrae/semi-foundation/base';
import InputFoundation from '@fibrae/semi-foundation/components/input/foundation';
import type { Locale } from '@fibrae/semi-foundation/locale';
import { utcToZonedTime } from '@fibrae/semi-foundation/utils/date-fns-extra';

The utils entry leaves out the date modules (date-fns-extra, date-fns-locale, zoned-time), and the base entry leaves out base/env. Import those by deep path.

exports also includes ./*.css and ./*.scss. The component CSS is compiled by vp pack. The published .scss contains semi: addresses and cannot be compiled by Sass directly; it goes through a build plugin or @fibrae/semi-scss-compile.

Directories

DirectoryContents
components/One directory per component, containing foundation.ts, constants.ts and *.scss as needed (variables.scss, mixin.scss and similar ship only as source)
base/BaseFoundation, common constants and the stateful classes a foundation composes (focus scope, popup lifecycle, modal resources and similar)
utils/Stateless utilities: DOM, date, focus helpers, layer stack and similar
theme/The one theme: global tokens, palettes and mixins, loaded by component SCSS through semi:theme
locale/Locale packs, the Locale and LocaleInput types and the locale resolution shared by every framework

Locale packs

src/locale/source/ holds the two built-in packs, zh_CN and en_US. Each file default-exports a Locale. src/locale/index.ts exports both packs and the Locale, LocaleInput, LocaleComponentName and LocaleResult types, and other packages import from @fibrae/semi-foundation/locale:

  • code: the language code. Date components pick their date-fns locale by it (src/utils/date-fns-locale.ts builds in only zh-CN and en-US; others come from ConfigProvider's dateFnsLocale).
  • currency: the ISO 4217 currency code, passed by InputNumber to Intl.NumberFormat.
  • The other keys are grouped by component and hold built-in text and accessible names. Values with ${name} are placeholders; do not translate the placeholder itself.

Every UI package exports zh_CN and en_US from its locale entry. Pass one to the UI package's LocaleProvider or ConfigProvider:

import { LocaleProvider } from '@fibrae/semi-ui-react';
import { en_US } from '@fibrae/semi-ui-react/locale';

<LocaleProvider locale={en_US}>
    <App />
</LocaleProvider>;

Both providers also take a custom pack typed LocaleInput: only code is required, and every text or currency it leaves out comes from en_US. src/locale/resolve-locale.ts fills the gaps once per pack object and reuses the result, so create the pack once (at module level or memoized) and replace it rather than mutating it in place.

The Vue package's LocaleProvider has the same name and takes :locale. For adding text or accessible names to both built-in packs, see locale-text.

  • Depends on @fibrae/semi-json-viewer-core. Framework-agnostic rendering logic for Markdown, MDX, Lottie and code highlighting also lives here.
  • Used by the UI package of each framework, @fibrae/semi-ai-foundation and the AI component packages.

Development

pnpm --filter @fibrae/semi-foundation build runs vp pack: src/**/*.ts emits ESM and type declarations file by file, component SCSS compiles to CSS, and theme tokens compile into base/tokens.css. Type checks in the UI packages read the types built here.

For general commands, see CONTRIBUTING.md at the repository root. For how to write styles, the semi: importer and the theme token protocol, see the 「组件 SCSS」, 「Sass 模块与 semi: importer」 and 「主题 token 协议」 sections of styles.

版本与发布记录

@fibrae/semi-foundation 共发布 10 个版本,首次发布于 2026/10/28;过去 12 个月发布了 10 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.7.0latest2026/11/14今天
0.6.02026/11/113 天前
0.5.02026/11/086 天前
0.4.02026/11/077 天前
0.3.12026/11/0410 天前
0.3.02026/11/0212 天前

关于 @fibrae/semi-foundation 的常见问题

如何安装 @fibrae/semi-foundation?

在项目目录运行 npm install @fibrae/semi-foundation,或使用 pnpm add / yarn add / bun add。

@fibrae/semi-foundation 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/fibrae__semi-foundation 是否存在。

@fibrae/semi-foundation 支持 ESM 还是 CommonJS?

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

@fibrae/semi-foundation 可以商用吗?

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

@fibrae/semi-foundation 的下载量有多少?

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

@fibrae/semi-foundation 还在维护吗?

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