@alacris/ui

中文文档
0.12.1发布于 2026/10/11MITTypeScriptES Module近 30 天下载 1969

Themeable design system for Alacris — Material defaults, seventy-one custom elements, ESM-only, no build step.

原始使用文档
文档目录9 节
  1. Install
  2. Without a bundler
  3. Theming
  4. Motion
  5. Forms
  6. Mobile viewport
  7. Entry points
  8. In this repository
  9. License

Alacris UI

A complete, themeable design system built with Alacris and nothing else. No other runtime dependencies, no build step, no CSS framework — 71 components, a three-tier token system, a theme engine that re-skins the whole page with one stylesheet write, and a documented motion layer.

Material Design is the default. Your design system is the point. Every visual decision flows through tokens you can override at three levels — from "change the brand color" (one line) to "this is no longer Material at all".

The tags are real custom elements, so they work in plain HTML and inside React, Vue, Svelte, Angular, Rails, Django, and Alacris-Go — anywhere that renders a tag.

Docs: Live catalog · Getting started

Install

npm install @alacris/ui

That pulls in @alacris/core as well. Do not also load a second copy of Alacris from a CDN on the same page — two copies means two reactive graphs, and updates stop crossing the boundary.

import { applyTheme } from '@alacris/ui';

applyTheme({ seed: '#0b57d0' });
<ui-button>Hello</ui-button>
<ui-text-field label="Email" clearable></ui-text-field>
<ui-switch label="Dark mode"></ui-switch>

Importing @alacris/ui registers every component. For a smaller page, import only what you use — each component module is self-contained:

import { applyTheme } from '@alacris/ui/theme';
import '@alacris/ui/components/ui-button.js';
import '@alacris/ui/components/ui-text-field.js';

applyTheme({ seed: '#0b57d0' });

Without a bundler

The published package is plain ESM. Point an import map at a pinned CDN build of Alacris (the only bare specifier the UI source uses) and at this package:

<script type="importmap">
{
  "imports": {
    "@alacris/core": "https://cdn.jsdelivr.net/npm/@alacris/[email protected]/dist/alacris.js",
    "@alacris/ui": "https://cdn.jsdelivr.net/npm/@alacris/[email protected]/src/index.js",
    "@alacris/ui/theme": "https://cdn.jsdelivr.net/npm/@alacris/[email protected]/src/theme/index.js",
    "@alacris/ui/components/": "https://cdn.jsdelivr.net/npm/@alacris/[email protected]/src/components/"
  }
}
</script>
<script type="module">
  import { applyTheme } from '@alacris/ui';
  applyTheme({ seed: '#0b57d0' });
</script>

<ui-button>Hello</ui-button>

Never mix two versions of @alacris/core on one page — two copies means two reactive graphs.

Theming

import { createTheme, applyTheme, setScheme, toggleScheme } from '@alacris/ui/theme';

applyTheme({ seed: '#6750a4' });
applyTheme({ seed: '#b3261e', density: -1 });
setScheme('dark');
toggleScheme();

applyTheme(createTheme({
  colors: { primary: '#0b57d0', tertiary: '#00695c' },
  typography: 'google-sans',
  shape: { radius: 0.5 },
  overrides: { light: { 'color-surface': '#faf7f2' } },
}));

applyTheme writes one document-level stylesheet of --ui-* custom properties and replaces it in place on the next call. Scheme switching after that is data-ui-scheme on <html> (light | dark | auto).

Three places to intervene, from broadest to narrowest:

  1. Re-theme the system — applyTheme({ seed, shape, … }). Every component follows. Dark mode is generated automatically.
  2. Re-skin one component type — ui-button { --ui-button-radius: 4px; }.
  3. Reach inside one instance — ui-dialog::part(surface) { backdrop-filter: blur(8px) }.

Full guide: docs/theming.md.

Motion

import { animate, fx, presence, withFlip } from '@alacris/ui/motion';

animate(el, fx.slideInUp, { duration: 'medium2', easing: 'emphasizedDecelerate' });

html`${presence(open, () => html`<div class="sheet">…</div>`, {
  enter: fx.slideInUp, exit: fx.slideOutDown,
})}`;

Durations and easings are tokens, so the theme's motion.scale governs CSS transitions and JS animation alike, and prefers-reduced-motion is honoured automatically. Full guide: docs/motion.md.

Forms

Named controls (ui-text-field, ui-switch, ui-checkbox, ui-select, …) are form-associated custom elements. Give a component a name and it submits, resets, and follows <fieldset disabled> like a native field.

Mobile viewport

Dialogs, sheets, drawers and the modal date picker are position: fixed; inset: 0 overlays sized by the visible viewport, not 100vh (which on phones and tablets is the height with the URL bar hidden, so a 100vh overlay runs off the bottom of the screen). Only the body scrolls, so headlines and actions stay on screen; drawers scroll their content above an optional pinned footer slot.

Two lines in the page's viewport meta finish the job:

<meta name="viewport"
      content="width=device-width, initial-scale=1, viewport-fit=cover, interactive-widget=resizes-content">
  • interactive-widget=resizes-content makes the on-screen keyboard shrink the layout viewport (Chrome on Android, 108+), so open overlays shrink above it with no script. Without it, the components follow window.visualViewport instead and pad themselves above the keyboard; that also covers browsers that ignore the key.
  • viewport-fit=cover lets the page draw under notches and home indicators. Overlays then pad by env(safe-area-inset-*); without it those insets are 0 and nothing changes.

Own overlays can use the same plumbing: fitToViewport(el, host) writes --ui-vv-top / --ui-vv-bottom on el while the keyboard is up and scrolls the focused field back into view; visibleBounds() gives the visible band for positioning.

Entry points

ImportWhat it is
@alacris/uiregisters every component; re-exports theme, motion, tokens, utilities
@alacris/ui/themecreateTheme, applyTheme, scheme switching
@alacris/ui/motionanimate, fx, presence, withFlip, ripple
@alacris/ui/tokenssys and the token engines
@alacris/ui/components/ui-button.jsone element, registered as a side effect

Component modules have side effects (they call define()). Theme, motion and token modules do not.

In this repository

This package lives in ui/ of the Alacris repo so the library and the design system can be developed together. They publish separately: @alacris/ui has its own version, changelog, and npm release. A commit that only changes this folder does not cut an Alacris library release. starter/ in the same repo is a usage example and install guide, not this package.

ui/
  src/           the published modules
  types/         hand-written .d.ts
  demo/          kitchen-sink app (not published)
  docs/          theming, motion, component catalog
  test/          node smoke tests
  CONVENTIONS.md rules every component follows

The live catalog is bmartel.github.io/alacris/ui — every component plus a theme playground, no clone required.

From a clone of the repo:

npm install
npm run demo        # kitchen sink: http://localhost:5173/ui/
                    # starter app:  http://localhost:5173/starter/
cd ui && npm test
cd ui && npm run test:chrome   # overlay geometry in headless Chrome at phone/tablet sizes (skips without Chrome)

License

MIT

版本与发布记录

@alacris/ui 共发布 38 个版本,首次发布于 2026/08/16;过去 12 个月发布了 38 个版本。

版本发布日期距今
0.12.1latest2026/10/1127 天前
0.12.02026/10/1127 天前
0.11.02026/10/1128 天前
0.10.32026/10/1028 天前
0.10.22026/10/1028 天前
0.10.12026/10/1028 天前

关于 @alacris/ui 的常见问题

@alacris/ui 是什么?

Themeable design system for Alacris — Material defaults, seventy-one custom elements, ESM-only, no build step.

如何安装 @alacris/ui?

在项目目录运行 npm install @alacris/ui,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@alacris/core(^0.11.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@alacris/ui 支持 TypeScript 吗?

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

@alacris/ui 支持 ESM 还是 CommonJS?

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

@alacris/ui 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=18。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@alacris/ui 可以商用吗?

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

@alacris/ui 的下载量有多少?

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

@alacris/ui 还在维护吗?

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