@c2n/components

中文文档
1.0.23发布于 2026/11/08MITTypeScriptES Module近 30 天下载 2855

Every c2n web component in one package: one import per component, JSX and Vue template types for every tag, and the base theme

原始使用文档
文档目录4 节
  1. Entries
  2. React and Vue
  3. Not included
  4. Maintaining this package

@c2n/components

Every c2n web component, in the one package c2n publishes for them.

npm install @c2n/components

The components are built in this repository as separate workspace packages, but only this package is published: it bundles all of them. Each entry is a separate module and what entries share sits in common chunks, so an application that imports three components ships those three and what they use. Its dependencies are what the bundle still imports: Lit, @c2n/core, @c2n/theme, the icon sets two components draw with, and the third-party libraries of a few components (Shiki, ProseMirror, d3-geo, …).

Entries

ImportWhat it gives you
@c2n/components/<name>One component: its classes and types, and it registers each of its elements
@c2n/componentsEvery component, registered at once
@c2n/components/reactJSX types for every c2-* tag
@c2n/components/vueVolar template types for every c2-* tag
@c2n/components/theme.cssThe base theme (base.css and tokens.css separately, as in @c2n/theme)
import '@c2n/components/theme.css'
import '@c2n/components/table'
import '@c2n/components/select'
import type { TableRow } from '@c2n/components/table'

<name> is the component's name: @c2n/components/text-field for c2-text-field, @c2n/components/chart for every chart element.

Prefer the per-component entries in an application you ship. Registering a custom element is a side effect, so no bundler can drop one that is never used: import '@c2n/components' puts every component in the bundle. The barrel suits prototypes, internal tools and a <script type="module"> from a CDN.

React and Vue

// src/c2-elements.d.ts
import '@c2n/components/react' // or '@c2n/components/vue'

These declare every tag, with props and events typed from the element classes. The rules each framework needs followed (register the elements before the first render, kebab-case attribute names in server-rendered React, the isCustomElement option in Vue) are in the Frameworks guide.

Not included

  • Icon sets. @c2n/feather-icons, @c2n/phosphor-icons and @c2n/symbols are one element per icon (Phosphor alone is 1,512), so they stay their own install.
  • Optional engines. c2-*-chart renders with uplot or echarts, c2-code-editor with CodeMirror and c2-mermaid (with the diagrams in c2-markdown) with mermaid. They are optional peer dependencies: install the ones you use.

Maintaining this package

The component packages (packages/components/*, open-packages/*) are private workspaces. Everything here except this README, scripts/ and the hand-written fields of package.json (name, description, scripts, …) is generated:

  • npm run build -w packages/tools/framework-types writes the bundle inputs under src/ (one entry per component package, the barrel, the React and Vue declarations), the three stylesheets, and the exports, files, customElements, dependencies, peerDependencies and devDependencies of package.json. A new component package joins the next time it runs; CI fails when the committed output is stale.
  • npm run build -w packages/umbrella (scripts/bundle.ts) builds dist/ from src/ with Vite, inlining the workspace packages, copies their declarations under dist/types/ with @c2n/<name> specifiers rewritten to relative paths, and merges their manifests into custom-elements.json. It fails when the bundle imports a package package.json does not list. prepack runs it, so npm pack and lerna publish always ship a fresh build.

npm run type-check -w packages/umbrella compiles the bundled declarations with skipLibCheck off, which is what reports two packages exporting the same name from the barrel, and type-checks the React and Vue fixtures in test/. test/umbrella.spec.ts imports the barrel in a browser and checks that every tag in the merged manifest is registered.

版本与发布记录

@c2n/components 共发布 30 个版本,首次发布于 2026/09/30;过去 12 个月发布了 30 个版本。

版本发布日期距今
1.0.23latest2026/11/081 天前
1.0.222026/11/072 天前
1.0.212026/11/054 天前
1.0.202026/11/035 天前
1.0.192026/11/035 天前
1.0.182026/10/2811 天前

关于 @c2n/components 的常见问题

@c2n/components 是什么?

Every c2n web component in one package: one import per component, JSX and Vue template types for every tag, and the base theme

如何安装 @c2n/components?

在项目目录运行 npm install @c2n/components,或使用 pnpm add / yarn add / bun add。

@c2n/components 支持 TypeScript 吗?

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

@c2n/components 支持 ESM 还是 CommonJS?

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

@c2n/components 可以商用吗?

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

@c2n/components 的下载量有多少?

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

@c2n/components 还在维护吗?

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