@fiscozen/style

中文文档
0.5.0发布于 2026/09/07ISCCommonJS零依赖近 30 天下载 1.3万

Design System package providing design tokens, CSS variables, and Vue.js custom directives

原始使用文档
文档目录26 节
  1. Features
  2. Installation
  3. Setup
  4. Basic Usage
  5. v-color
  6. v-bold
  7. v-small
  8. Vue Custom Directives
  9. v-color
  10. v-bold
  11. v-small
  12. Combining Directives
  13. Examples
  14. Basic Typography Styling
  15. Form Feedback Messages
  16. Dynamic Color Changes
  17. Validation
  18. Accessibility
  19. Architecture
  20. Token Flow
  21. Key Components
  22. Build & Customization
  23. Regenerate Tokens
  24. Build Steps
  25. Extending the System
  26. References

@fiscozen/style

Design system package providing design tokens, CSS variables, and Vue.js custom directives to maintain visual consistency across all FiscoZen projects.

Features

  • Design Tokens: Single source of truth for colors, spacing, typography, and more
  • CSS Variables: All tokens available as CSS custom properties
  • Vue Custom Directives: Typography styling directives (v-color, v-bold, v-small)
  • Tailwind Integration: Seamless integration with Tailwind CSS utility classes
  • Type Safety: Full TypeScript support with validation rules
  • Build Pipeline: Automated token transformation and CSS generation

Installation

npm install @fiscozen/style

Setup

Register the directives in your Vue application:

// main.ts
import { createApp } from 'vue'
import { setupFzStyle } from '@fiscozen/style'
import '@fiscozen/style/output/global.css'
import App from './App.vue'

const app = createApp(App)

// Register FiscoZen custom directives
setupFzStyle(app)

app.mount('#app')

Basic Usage

v-color

Apply design system colors to text elements:

<template>
  <!-- Default weights (500 for base colors, 200 for semantic) -->
  <p v-color:blue>Blue text</p>
  <h1 v-color:semantic-error>Error heading</h1>
  
  <!-- Explicit weights -->
  <p v-color:blue="300">Light blue text</p>
  <h2 v-color:purple="700">Dark purple heading</h2>
</template>

v-bold

Apply semibold font weight to paragraphs:

<template>
  <p v-bold>This text is bold</p>
  <p v-bold="false">This text is normal weight</p>
</template>

v-small

Apply small text size to paragraphs:

<template>
  <p v-small>This text is small</p>
  <p v-small="false">This text is normal size</p>
</template>

Vue Custom Directives

v-color

Applies design system text colors to heading and paragraph elements.

Supported Elements:

  • Paragraphs (<p>)
  • Headings (<h1>, <h2>, <h3>)

Available Colors:

Base Colors:

  • blue, purple, orange, pink, yellow, grey, core
  • Weights: 50, 100, 200, 300, 400, 500 (default), 600, 700, 800, 900
  • For core: white, black (named values instead of numeric weights)

Semantic Colors:

  • semantic-error, semantic-warning, semantic-success, semantic-info
  • Weights: 50, 100, 200 (default), 300

Default Weights:

  • Base colors → 500
  • Semantic colors → 200
  • Core colors → black

Examples:

<template>
  <!-- Base colors with default weight -->
  <p v-color:blue>Blue text (weight 500)</p>
  <p v-color:purple>Purple text (weight 500)</p>
  
  <!-- Explicit weights -->
  <p v-color:blue="300">Light blue text</p>
  <p v-color:blue="700">Dark blue text</p>
  
  <!-- Semantic colors -->
  <p v-color:semantic-error>Error message</p>
  <p v-color:semantic-success>Success message</p>
  <h3 v-color:semantic-error="300">Critical error</h3>
  
  <!-- Headings -->
  <h1 v-color:blue="700">Main title</h1>
  <h2 v-color:grey="600">Subtitle</h2>
  
  <!-- Remove color classes -->
  <p v-color:blue="false">Removes all color classes</p>
</template>

v-bold

Applies semibold font weight (font-semibold) to paragraph elements.

Supported Elements:

  • Paragraphs (<p>)

Examples:

<template>
  <p v-bold>This text is bold</p>
  <p v-bold="false">This text is normal weight</p>
</template>

v-small

Applies small text size (text-sm) to paragraph elements.

Supported Elements:

  • Paragraphs (<p>)

Examples:

<template>
  <p v-small>This text is small</p>
  <p v-small="false">This text is normal size</p>
</template>

Combining Directives

You can combine multiple directives on the same element:

<template>
  <p v-bold v-small v-color:blue>Bold, small, blue text</p>
  <p v-bold v-color:semantic-error>Bold error message</p>
</template>

Examples

Basic Typography Styling

<template>
  <div>
    <h1 v-color:blue>Welcome to FiscoZen</h1>
    <h2 v-color:grey="600">Your Financial Partner</h2>
    
    <p>Standard paragraph text</p>
    <p v-bold>Bold paragraph for emphasis</p>
    <p v-small>Small paragraph for secondary information</p>
    
    <p v-color:semantic-error>Error: Please check your input</p>
    <p v-color:semantic-success>Success: Changes saved!</p>
  </div>
</template>

Form Feedback Messages

<template>
  <form>
    <div v-if="error">
      <p v-color:semantic-error v-bold>Error: {{ error }}</p>
    </div>
    <div v-if="success">
      <p v-color:semantic-success>Success: {{ success }}</p>
    </div>
  </form>
</template>

Dynamic Color Changes

<script setup>
import { ref } from 'vue'

const status = ref('info')
const colorMap = {
  info: 'semantic-info',
  success: 'semantic-success',
  error: 'semantic-error',
  warning: 'semantic-warning'
}
</script>

<template>
  <p :v-color="colorMap[status]">Status message</p>
</template>

Validation

The directives automatically validate that they are used on supported element types. Invalid usage will log console errors:

  • v-color can be used on <p>, <h1>, <h2>, <h3>
  • v-bold can only be used on <p>
  • v-small can only be used on <p>

Accessibility

All directives maintain semantic HTML structure and do not interfere with screen readers:

  • Color directives only apply visual styling, maintaining text content
  • Bold and small directives preserve text semantics
  • Invalid element usage is logged but does not break functionality
  • All styling is applied via CSS classes, preserving semantic meaning

Architecture

Token Flow

tokens.json (Design tokens)
    ↓
token-transformer (Figma format → Style Dictionary format)
    ↓
tokens/global.json
    ↓
Style Dictionary (Custom formatters & transformers)
    ↓
    ├── output/global.css (CSS variables)
    └── output/global.json (JSON tokens)
    ↓
tailwind.config.js (Integrates tokens with Tailwind)
    ↓
Utility classes (text-blue-500, gap-4, etc.)

Key Components

1. Design Tokens (tokens.json)

  • Single source of truth for design values
  • Managed via Figma Tokens plugin or manual editing
  • Contains colors, spacing, typography, etc.

2. Build Pipeline (build.js)

  • Orchestrates token transformation
  • Generates CSS variables and JSON output
  • Appends additional CSS (typography, components)

3. Tailwind Integration (tailwind.config.js)

  • Transforms tokens into Tailwind theme
  • Generates safelist for dynamically-used classes
  • Provides semantic spacing and color defaults

4. Vue Directives (src/custom-directives/)

  • v-color: Apply design system colors to text
  • v-bold: Apply semibold font weight
  • v-small: Apply small text size

Build & Customization

Regenerate Tokens

If you modify token source files:

cd packages/style
npm run build

Build Steps

  1. build:transform: Converts tokens.json to Style Dictionary format
  2. build-sd: Runs Style Dictionary to generate CSS and JSON
  3. tsc: Compiles TypeScript directives to JavaScript

Extending the System

Add New Colors:

  1. Add color to tokens.json
  2. Add color name to safe-colors.json (for safelist)
  3. Run npm run build

Add New Semantic Colors:

  1. Add semantic color to tokens.json under semantic.*
  2. Add semantic type to safe-semantic-colors.json
  3. Run npm run build

Add Custom CSS:

  1. Create CSS file in src/ (e.g., components.css)
  2. Add filename to ADDITIONAL_CSS_FILES in build.js
  3. Run npm run build

References

版本与发布记录

@fiscozen/style 共发布 14 个版本,首次发布于 2024/05/08;过去 12 个月发布了 5 个版本。

版本发布日期距今
0.5.0latest2026/09/072 个月前
0.4.02026/07/173 个月前
0.3.02026/03/028 个月前
0.2.02026/02/139 个月前
0.1.8-next.0next2025/11/2611 个月前
0.1.72025/10/081.1 年前

其他发布通道:alpha → 0.1.5-alpha.0,next → 0.1.8-next.0。

关于 @fiscozen/style 的常见问题

@fiscozen/style 是什么?

Design System package providing design tokens, CSS variables, and Vue.js custom directives

如何安装 @fiscozen/style?

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

@fiscozen/style 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/fiscozen__style 是否存在。

@fiscozen/style 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@fiscozen/style 可以商用吗?

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

@fiscozen/style 的下载量有多少?

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

@fiscozen/style 还在维护吗?

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