@lo-tek/interfaces

中文文档
0.39.0发布于 2026/11/02MITTypeScriptES Module零依赖构建来源已验证

Framework-agnostic design system: tokens, CSS components and web components.

原始使用文档
文档目录8 节
  1. Installation
  2. CSS components
  3. The attributes as functions
  4. Web components
  5. The server writes the markup
  6. Your own colour theme
  7. Customising
  8. Licence

@lo-tek/interfaces

A framework-agnostic design system for the web: tokens, CSS components and web components. Everything is built on things the browser already understands, so the same components work in plain HTML, React, Astro and Datastar.

LO-TEK is pre-1.0. A minor version can contain breaking changes, and they are listed under "Breaking" (in versions up to 0.36.0, "Brytende") in the changelog.

The full documentation, with component pages, tokens, patterns and examples for four environments, is at lo-tek.sobernetics.no.

Coding agents find the rules at lo-tek.sobernetics.no/llms.txt, with one rulebook per environment, described under Coding agents. The same rulebooks ship in the package, in node_modules/@lo-tek/interfaces/agent/.

Installation

npm install @lo-tek/interfaces

The package has no dependencies. The web components are plain HTMLElement classes, and nothing is registered on import alone, so you only pay for what you actually call.

CSS components

A class and a few data-* attributes, no JavaScript. tokens.css defines the variables everything else builds on, so it has to be loaded. It comes first out of habit; the order makes no difference.

With a build step you import only the stylesheets you use, so a page with only buttons does not load CSS for a dialog:

import "@lo-tek/interfaces/tokens.css"
import "@lo-tek/interfaces/button.css"

Without a build step you link the combined file, which has everything in it:

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@lo-tek/interfaces/dist/lotek.css" />

The markup is the same whichever of the two you chose:

<button class="lt-button">Submit application</button>
<button class="lt-button" data-variant="secondary">Save draft</button>

The attributes as functions

lt gives the same classes and attributes with completion and type checking in the editor. Each component takes one object of options and returns the attributes:

import { lt } from "@lo-tek/interfaces"

lt.button({ variant: "secondary" })
// { class: "lt-button", "data-variant": "secondary" }

In React you import from @lo-tek/interfaces/react, which gives className and htmlFor instead of the HTML names:

import { lt } from "@lo-tek/interfaces/react"

<button {...lt.button({ variant: "secondary" })}>Save draft</button>

Web components

Nothing is registered on import alone. You call defineLt* yourself, so you decide when the element exists:

import { defineLtToast } from "@lo-tek/interfaces/toast"
import "@lo-tek/interfaces/tokens.css"
import "@lo-tek/interfaces/toast.css"

defineLtToast()
<lt-toast class="lt-toast" role="status" aria-live="polite" aria-atomic="false"
          aria-label="Notifications" data-ignore-morph></lt-toast>

Every defineLt* also takes a tag name of your choice, such as defineLtToast("app-toast"), and repeated calls are harmless, also alongside defineLt(). The stylesheets are still written for the lt-* names: an <lt-field> registered as <my-field> still wires the label to the field, but the display rule on the element name does not follow, <lt-tabs> and <lt-suggestion> do not hide their content before registration, and <lt-dialog> no longer positions a dialog that is open before it is modal. The four that set their class themselves, <lt-toast>, <lt-session-timeout>, <lt-connection-status> and <lt-error-summary>, look the same under another name.

The server writes the markup

LO-TEK is built for apps where the HTML comes from the server, whether that is TanStack Start, React Server Components or Datastar. No web component creates nodes in markup the server has sent, because the surrounding framework would tear them out again on the next update.

The builder functions in lt give the markup, the components give the behaviour, and the two do not overlap:

import { lt } from "@lo-tek/interfaces"

lt.errorSummary({ count: 2, id: "errors" })
// { host:  { class: "lt-error-summary", role: "alert", tabindex: "-1", id: "errors",
//            "aria-labelledby": "errors-title" },
//   title: { class: "lt-error-summary__title", id: "errors-title" } }

id is required in lt.field(), lt.suggestion(), lt.tabs() and lt.popover(), and titleId in lt.dialog(). lt.tabs() and lt.suggestion() also take keys, one key from the data per tab or option, and lt.tabs() requires label, the name of the tab list. The reason is hydration: if the function creates the id itself, the server and the browser each create their own, and the wiring between the parts is broken until React has corrected it. In React it comes from useId(). In lt.errorSummary() both are optional: id names the box so that something else can point to it, and titleId, the heading's id that names the box, defaults to the id with -title. Without either, the heading has no id and the box no name, and the web component says so in the console.

The full reasoning, with the tests behind it, is on Markup and behaviour.

Your own colour theme

The CLI creates a complete theme from your brand colours, with the contrast requirements computed in OKLCH:

npx @lo-tek/interfaces theme --accent=#7c3aed --danger=#b3261e \
  --success=#2b6940 --warning=#8a5a00 --neutral=#1a1a1a --out=theme.css

If customising through CSS is not enough, takeover copies the source code of one component into your project, with the imports rewritten:

npx @lo-tek/interfaces takeover button --out=src/ui

npx @lo-tek/interfaces --help shows the rest.

Customising

The components are in @layer lotek, so your own rules win without !important. If you embed a component in a page you do not control, data-lt-boundary on the root element gives LO-TEK its styles back where the host's unlayered CSS would otherwise take them; see Customising in the documentation. Shape and size are read from --lt-* variables with the token value as fallback:

.lt-button {
  --lt-button-padding: var(--lt-spacing-3) var(--lt-spacing-6);
}

Tailwind is optional. The theme is a plain CSS file, @lo-tek/interfaces/tailwind.css, so the package has no dependency on Tailwind and cannot conflict with your version.

Licence

MIT

版本与发布记录

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

版本发布日期距今
0.39.0latest2026/11/021 天前
0.38.02026/11/012 天前
0.37.02026/10/268 天前
0.0.02026/10/268 天前
0.0.0-stage2026/10/268 天前

关于 @lo-tek/interfaces 的常见问题

@lo-tek/interfaces 是什么?

框架无关的设计系统:令牌、CSS组件和web组件。

如何安装 @lo-tek/interfaces?

在项目目录运行 npm install @lo-tek/interfaces,或使用 pnpm add / yarn add / bun add。它还提供命令行工具 lotek,可以用 npx lotek 直接运行。

@lo-tek/interfaces 支持 TypeScript 吗?

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

@lo-tek/interfaces 支持 ESM 还是 CommonJS?

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

@lo-tek/interfaces 需要什么版本的 Node.js?

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

@lo-tek/interfaces 可以商用吗?

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

@lo-tek/interfaces 还在维护吗?

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