@contraagent/elements

中文文档
0.10.1发布于 2026/10/31MITTypeScriptES Module零依赖构建来源已验证近 30 天下载 3343

Generic web components (Lit) and their parts: design tokens, themes, status pills, legends, a segmented control, a data table, a layered graph, a mark matrix, stat tiles, time lanes, charts (columns, lines, a heatmap, horizontal bars), a check table, a tr

原始使用文档
文档目录3 节
  1. Getting it
  2. Use it from a checkout
  3. Documentation

@contraagent/elements

Generic web components (Lit) and the parts they are built from: the design tokens and the built-in themes, status pills, legends, rows of facts, icons, a segmented control, keyboard focus for a group of items, a data table, stat tiles, time lanes, a check table, a transcript, and elements for a JSON tree, markdown, code, a tree of items and counters. Nothing here knows contraagent's data: an element takes plain data and its words, and reports what the reader did as a cae-* event. @contraagent/ui builds the contraagent monitor from them.

Getting it

Lit is a peer dependency. Importing a module registers nothing and changes no page; a define entry registers its elements under their cae-* tags (and the cae-* elements they render), or you register a class under a tag name of your own. An element speaks English unless the page gives its words in its strings property (Strings), and takes its colours from the themes once adoptThemes(document) has added their rules (Theming).

import '@contraagent/elements/segmented/define'; // <cae-segmented>
import '@contraagent/elements/data-table/define'; // <cae-data-table>
import '@contraagent/elements/tiles/define'; // <cae-stat-tiles>
import '@contraagent/elements/graph/define'; // <cae-layered-graph>, <cae-mark-matrix>, <cae-segmented>
import '@contraagent/elements/charts/define'; // <cae-column-chart>, <cae-line-chart>, <cae-heatmap>, <cae-state-grid>, <cae-bar-chart>
import '@contraagent/elements/code/define'; // <cae-code>
import '@contraagent/elements/tree/define'; // <cae-tree>
import '@contraagent/elements/define'; // every cae-* element
import { pill, legend, base } from '@contraagent/elements';

The subpaths are primitives, styles, themes, data-table, graph, matrix, tiles, lanes, charts, check-table, transcript, json-tree, markdown, code, tree and count, and a define entry for each element (segmented/define, data-table/define, graph/define, matrix/define, tiles/define, lanes/define, charts/define, check-table/define, transcript/define, json-tree/define, markdown/define, code/define, tree/define, count/define).

Install the package from the npm registry:

npm install @contraagent/elements

A checkout of the repository packs its own version (Use it from a checkout).

Use it from a checkout

In the repository's web/ (Node 22, pnpm through corepack enable):

pnpm install && pnpm tarballs

pnpm tarballs builds the packages and writes one .tgz file for each to web/tarballs/. Then, in your project, with npm or pnpm:

npm install <checkout>/web/tarballs/contraagent-elements-*.tgz
pnpm add <checkout>/web/tarballs/contraagent-elements-*.tgz

Documentation

  • Primitives: tones, status pills, legends, rows of facts, icons, the segmented control, roving focus and windowing.
  • Theming: colours, fonts, type and corners as --ca-* custom properties, and the built-in themes.
  • Strings: an element's words, in English unless the host gives its own.
  • Data table: rows in a real table, reached and opened with the keyboard, long lists drawn by window.
  • Layered graph: nodes in layers, joined by edges, in clusters, each a group of marks lined up by series; pan, zoom, a card for the selection and the keyboard.
  • Mark matrix: marks in a table, a row per series, the columns under nested groups.
  • Stat tiles: figures as tiles, each a label, a value that counts up, lines of facts and a link.
  • Lanes: bars on a time axis, a lane per group, running bars growing until now.
  • Charts: columns (stacked or side by side), lines, a heatmap and horizontal bars of plain series, each with a legend, a tooltip and a table of its values.
  • Check table: named values checked one by one, each with what it must be, what it is and the verdict.
  • Code: a text highlighted by its language, its lines numbered and some marked, wrapped or scrolled, copied whole, and cut when long.
  • Tree: items in a tree, folded and opened with the mouse and the keyboard, one of them selected, each with an icon and a badge.
  • Transcript: a conversation with an agent in sessions: bubbles, reasoning, tool cards and web searches, following the end as it grows.
  • Building a page: a CI pipeline's page from several elements: a theme switch, stat tiles, a sortable table, a graph with shards and a retry loop, and a detail panel.

Every element's properties, events and parts are in custom-elements.json, generated from the sources with the package.

A ::code line quotes a file of the package; the documentation site shows the quoted lines in place. The same declarations, with their comments, are in dist/**/*.d.ts.

版本与发布记录

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

版本发布日期距今
0.10.1latest2026/10/3110 天前
0.10.02026/10/3111 天前
0.9.22026/10/2516 天前
0.9.12026/10/2517 天前
0.9.02026/10/2417 天前
0.8.12026/10/2318 天前

关于 @contraagent/elements 的常见问题

@contraagent/elements 是什么?

Generic web components (Lit) and their parts: design tokens, themes, status pills, legends, a segmented control, a data table, a layered graph, a mark matrix, stat tiles, time lanes, charts (columns, lines, a heatmap, horizontal bars), a check table, a tr

如何安装 @contraagent/elements?

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

@contraagent/elements 支持 TypeScript 吗?

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

@contraagent/elements 支持 ESM 还是 CommonJS?

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

@contraagent/elements 可以商用吗?

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

@contraagent/elements 的下载量有多少?

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

@contraagent/elements 还在维护吗?

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