@botharness/botui-core

中文文档
0.3.0发布于 2026/10/02MITTypeScriptES Module零依赖近 30 天下载 4100

The framework-agnostic engine behind BotUI components

原始使用文档
文档目录7 节
  1. Install
  2. Use
  3. The two renderers
  4. The five layers
  5. Your own traversal
  6. Documentation
  7. License

@botharness/botui-core

The framework-agnostic engine behind BotUI components — no DOM library, no framework, one dependency: none.

This is the layer that decides which cells exist, what order the light moves in, how bright each cell is over the cycle, and how one dot is drawn. Those are independent questions, so they are independent tables you can extend without touching each other.

Install

You probably don't need this package. The recommended path is to copy the source into your repo:

npx @botharness/botui add dot-matrix

Install it from npm when you want the engine as a dependency, or when you are building tooling on top of it:

npm install @botharness/botui-core

Use

import { createDotMatrix } from "@botharness/botui-core";
import "@botharness/botui-core/style.css"; // required for renderer: "css"

const field = createDotMatrix(document.querySelector("#loading")!, {
  size: 32,
  cols: 5,
  rows: 5,
  silhouette: "circle",
  dot: "circle",
  preset: "spiral",
});

field.start();
// …later
field.destroy();

The two renderers

rendererCostUse when
"svg" (default)one attribute write per visible dot per frameyou animate size, shape, or dot count
"css"zero JS per frame — one @keyframes rulethe geometry is fixed and only brightness moves

Both are driven by the same field(options, t), a pure function of the options and a phase. That is the whole reason the CSS path is trustworthy: it is not a second implementation, so it cannot drift from the SVG one.

cssRenderable(options) tells you up front whether a motion can be expressed as keyframes. Some cannot — columns staggers each column's entry, which a per-dot animation-delay does not model — and the function returns false rather than silently rendering something else.

The five layers

LayerQuestion it answers
Latticewhich cells exist (square, circle, diamond, hex, ring, cross)
Traversalwhat order the light moves in (spiral, columnSnake, radial, ring)
Envelopehow bright a cell is over the cycle (comet, wave, plateau, chase)
Glyphhow one dot is drawn — a polygon plus two corner radii
RendererSVG or CSS

Your own traversal

The Traversal layer is a plain function of the lattice position returning 0…1, so anything you can compute per cell you can animate. Pass it as order and it replaces the preset's:

// a chevron that speeds up toward its tip: the traversal value is eased, so successive
// dots along each arm start closer together in phase than a linear ramp would
const chevron = (col: number, row: number, cols: number, rows: number) => {
  const mid = (rows - 1) / 2;
  const arm = Math.abs(row - mid) / (mid || 1); // 0 at the spine, 1 at the tips
  const along = col / (cols - 1 || 1);
  const v = arm * 0.6 + along * 0.4; // down one arm, then along the other
  return v * v; // ease-in: faster toward the tip
};

createDotMatrix(el, { cols: 9, rows: 9, preset: "morph", order: chevron });

Two things worth knowing:

  • It works in both renderers. The CSS host derives each cell's animation-delay from this same value, so a custom traversal costs zero per-frame JS there as well.
  • It is a function, so it is not copyable. A component carrying a custom traversal is a component whose motion is code — keep it in the source. The playground's copy button omits it rather than pretending a function is a value.

direction arrives as a fifth argument, so a traversal with no sense of direction can stay four-argument and ignore it, and one that does can read dir?.includes("rightToLeft") without re-deriving anything.

The full option list, and the reasoning behind the size algebra, are in src/types.ts.

Documentation

ui.botharness.ai — a live playground for every control, in English and 中文.

License

MIT © BotHarness

版本与发布记录

@botharness/botui-core 共发布 5 个版本,首次发布于 2026/09/30;过去 12 个月发布了 5 个版本。

版本发布日期距今
0.3.0latest2026/10/021 个月前
0.2.02026/10/011 个月前
0.1.22026/10/011 个月前
0.1.12026/09/301 个月前
0.1.02026/09/301 个月前

关于 @botharness/botui-core 的常见问题

@botharness/botui-core 是什么?

The framework-agnostic engine behind BotUI components

如何安装 @botharness/botui-core?

在项目目录运行 npm install @botharness/botui-core,或使用 pnpm add / yarn add / bun add。

@botharness/botui-core 支持 TypeScript 吗?

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

@botharness/botui-core 支持 ESM 还是 CommonJS?

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

@botharness/botui-core 可以商用吗?

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

@botharness/botui-core 的下载量有多少?

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

@botharness/botui-core 还在维护吗?

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