# @type-dom/css-type

> 基于TypeScript的CSS类型定义库，提供类型安全的CSS属性、值和工具类型，帮助开发者在TypeScript项目中编写更可靠的CSS代码。

Latest version **0.9.0** (published 2026-09-10) · 0 weekly downloads

## Install

```sh
npm install @type-dom/css-type
pnpm add @type-dom/css-type
yarn add @type-dom/css-type
bun add @type-dom/css-type
```

## Health

**Score 65/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; recently updated; high maintenance score.

Warnings: low downloads; pre 1.0.

## Facts

| | |
|---|---|
| Version | 0.9.0 |
| Published | 2026-09-10 |
| First published | 2024-11-01 |
| Weekly downloads | 0 |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 1.1 MB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Maintainers | xjf7711 |

## Links

- npm: https://www.npmjs.com/package/@type-dom/css-type
- Repository: https://github.com/type-dom/css-type
- Homepage: https://github.com/type-dom/css-type#readme
- Issues: https://github.com/type-dom/css-type/issues
- npm.io page: https://npm.io/package/@type-dom/css-type

## Dependencies (1)

- [tslib](https://npm.io/package/tslib.md) ^2.3.0

## Recent versions

- 0.9.0 (latest) — 2026-09-10
- 0.2.1 — 2026-09-10
- 0.2.0 — 2025-07-02
- 0.1.0 — 2025-04-29
- 0.0.2 — 2024-11-01

## README

# css-type

基于TypeScript的CSS类型定义库，提供类型安全的CSS属性、值和工具类型，帮助开发者在TypeScript项目中编写更可靠的CSS代码。

---

## 特性

- 完整的CSS属性类型定义（如`color`, `flex`, `transition`等）
- 常用CSS值类型集合（如颜色值、长度单位、定位值等）
- 基于CSS规范的类型推导
- 支持自定义类型扩展
- 兼容现代CSS特性（如CSS Grid, Flexbox等）

---

## 安装

    bash npm install @type-dom/css-type --save
    或
    yarn add @type-dom/css-type

---

## 快速上手

### 基础用法
    
    typescript
    import type { CSSProperties } from '@type-dom/css-type';
    const componentStyle: CSSProperties = { display: 'flex', // ✅ 合法值
    flexDirection: 'row', // ✅ 合法值
    invalidProp: 'error', // ❌ 类型报错
    padding: '1rem 2rem', // ✅ 合法值
    borderRadius: '50%', // ✅ 合法值 };

### 扩展类型定义

    typescript
    import type { CSSProperties, CSSLength } from '@type-dom/css-type';
    type CustomCSSProperties = CSSProperties & { '--custom-var': CSSLength; // 声明自定义CSS变量类型 };
    const extendedStyle: CustomCSSProperties = { '--custom-padding': '1.5rem', // ✅ 合法值 };

---

## 核心类型

### `CSSProperties`

包含所有标准CSS属性的类型定义，例如：

| 属性名           | 允许值类型                                                 |
|------------------|-------------------------------------------------------|
| `color`          | CSSColor                                              |
| `display`        | CSSDisplay                                            |
| `padding`        | CSSLength                            \| CSSPercentage |
| `transition`     | CSSTransitionProperty                                 |
| `gap`            | CSSLength                                             |

### 基础值类型

- **CSSColor**：支持`#RRGGBB`、`rgb()`、`hsl()`等格式
- **CSSLength**：支持`px`、`rem`、`em`、`%`等单位
- **CSSPosition**：`top`、`bottom`、`left`、`right`等定位值
- **CSSDisplay**：所有合法display属性值集合

---

## 兼容性

- 支持所有现代浏览器
- 需要 TypeScript 4.0+ 版本
- 兼容主流CSS预处理器（Sass/Less）

---

## 贡献指南

1. Fork仓库并创建新分支
2. 修改类型定义时请参考最新[CSS规范](https://www.w3.org/Style/CSS/)
3. 提交PR前运行测试：`npm run test`
4. 遵循[贡献规范](CONTRIBUTING.md)

---

## 许可证

MIT License © TypeDom Team

---
_Source: https://npm.io/package/@type-dom/css-type · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
