@brandsync/wc

中文文档
1.32.0发布于 2026/11/06MITTypeScriptESM + CJS近 30 天下载 8758

Brandsync design system components as framework-agnostic Web Components

原始使用文档
文档目录5 节
  1. Getting started
  2. Typography
  3. Usage
  4. Design tokens — required, not optional
  5. Browser support, RTL and forced-colors

@brandsync/wc

Brandsync's design system components as framework-agnostic Web Components — real, self-contained custom elements consumed the same way by React, Angular, Blazor, or plain HTML. Built with Stencil, styled entirely from brandsync-tokens CSS Custom Properties.

See CONVENTIONS.md for the customization surface every component follows (CSS Custom Properties, Shadow Parts, slots), and docs/blazor-interop/ for a worked Blazor/MudBlazor consumption example.

Getting started

npm install
npm run build      # compiles all components, generates React/Angular wrapper packages
npm test           # runs the component test suite
npm run storybook  # interactive component catalog at http://localhost:6006

Typography

brandsync-tokens specifies Roboto (--bs-typography-font-family-*) and every component's shadow styles inherit font-family from the document root — but loading the actual Roboto font file is the consuming app's job, same convention already used across eg-brandsync (a Google Fonts <link>, or next/font/google in Next.js apps). This library ships styling, not a font file.

<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Roboto:wght@100;300;400;500;700;900&display=swap">

Those are the static Roboto weights Google Fonts actually serves (100/300/400/500/700/900). --bs-font-weight-semibold is 600, and the static stylesheet has no 600, so semibold text is synthesized from 500 or 700. Load the variable font (next/font/google with Roboto, or @fontsource-variable/roboto) when semibold has to be a real 600. If Roboto isn't loaded, components still work — text just falls back to the browser's default sans-serif.

Usage

<script type="module" src="https://unpkg.com/@brandsync/wc"></script>
<bs-button variant="primary">Book room</bs-button>

Or from node_modules, per-component:

import '@brandsync/wc/dist/components/bs-button.js';

React and Angular get auto-generated wrapper packages (@stencil/react-output-target / @stencil/angular-output-target) built from the same source — see stencil.config.ts.

Design tokens — required, not optional

Every component's shadow-DOM CSS is written entirely against --bs-* custom properties (--bs-input-bg-default, --bs-composer-button-size, --bs-spacing-150, ...). This package does not inject those variables anywhere -- it only consumes them. If the consuming app hasn't defined them, every var(--bs-something) (none of these declarations have a fallback) resolves to its CSS-invalid-at-computed-value fallback: border: none, background: transparent, width/height/padding/gap: 0, browser-default font-size. The component still renders in the DOM -- it just silently collapses (no visible border/box, buttons shrink to nothing, text fields push onto their own line) with no console error or exception pointing at the missing tokens, which makes it a confusing first bug to debug.

Fix: load the token stylesheet this package ships (vendored from brandsync-tokens) once, globally, in the consuming app -- before any bs-* element renders:

/* e.g. src/styles.css / global.css / angular.json "styles" array */
@import '@brandsync/wc/dist/brandsync-wc/brandsync-wc.css';
<!-- plain HTML/CDN consumption -->
<link rel="stylesheet" href="https://unpkg.com/@brandsync/wc/dist/brandsync-wc/brandsync-wc.css">

This applies identically to the HTML/CDN path, npm+bundler path, and the React/Angular wrapper packages -- none of them auto-inject it. If a consuming app already has its own differently-named design tokens (e.g. --surface-base instead of --bs-color-surface-base), that app-level token file does not satisfy this requirement even if the values match conceptually -- the shadow-DOM CSS only resolves --bs-*-prefixed names, so the vendored stylesheet above must be loaded regardless.

Known harmless noise: the vendored brandsync-wc.css currently contains a handful of malformed token declarations from an upstream brandsync-tokens export step (e.g. --bs-5-brand-colors-jade-brand-700: {Brand Colors.teal.700};), which some build tools (e.g. Angular's CSS budget/lint step) warn about. These are pre-existing in the vendored dependency, not introduced by this package, and don't affect any token this library actually uses.

Browser support, RTL and forced-colors

  • Browsers: evergreen Chrome/Edge, Firefox and Safari (latest two major versions). Components rely on Shadow DOM, Custom Elements and ElementInternals (form association). Only Chromium is exercised in CI today; Firefox/Safari are expected to work but are not yet verified by the automated suite.
  • RTL: layout uses CSS logical properties. Exceptions: bs-slider and bs-progress-linear keep physical geometry (value-driven), and centered overlays use left: 50% + translateX.
  • Windows High Contrast (forced-colors): button, checkbox, switch, radio, input, menu, card and dialog have explicit rules; other components have not been audited.
  • SSR: not verified. Stencil can hydrate, but no SSR integration (Next.js, Angular Universal) is tested or documented yet.

版本与发布记录

@brandsync/wc 共发布 55 个版本,首次发布于 2026/09/08;过去 12 个月发布了 55 个版本。

版本发布日期距今
1.32.0latest2026/11/062 天前
1.31.02026/11/062 天前
1.30.02026/11/035 天前
1.29.02026/11/026 天前
1.28.02026/10/2910 天前
1.27.02026/10/2910 天前

关于 @brandsync/wc 的常见问题

@brandsync/wc 是什么?

Brandsync design system components as framework-agnostic Web Components

如何安装 @brandsync/wc?

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

@brandsync/wc 支持 TypeScript 吗?

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

@brandsync/wc 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@brandsync/wc 可以商用吗?

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

@brandsync/wc 的下载量有多少?

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

@brandsync/wc 还在维护吗?

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