Skip to content

feat(unocss): add namespace support for UnoCSS with token prefixing#9

Closed
cc-hearts wants to merge 1 commit into
mainfrom
feat/unocss-namespace
Closed

feat(unocss): add namespace support for UnoCSS with token prefixing#9
cc-hearts wants to merge 1 commit into
mainfrom
feat/unocss-namespace

Conversation

@cc-hearts
Copy link
Copy Markdown
Member

@cc-hearts cc-hearts commented May 17, 2026

Summary

UnoCSS 版本命名空间支持,对应 Tailwind 版本 PR #8,共同实现 Issue #7 的 Antdv Next Token 命名空间设计。

  • 引入 prefix 配置项,支持为工具类添加命名空间前缀(如 a-text-sma-p-lg
  • allowUnprefixed 控制是否同时生成无前缀版本
  • Token 级别前缀隔离,避免 Antdv Next token 污染 UnoCSS 原生命名空间
  • 完善类型定义和 autocomplete 支持

Related

Test plan

  • 设置 prefix: 'a-',验证生成 a-text-sm 等带前缀工具类
  • 设置 allowUnprefixed: true,验证同时生成有/无前缀版本
  • 设置 prefix: 'a-' + allowUnprefixed: false,验证只生成带前缀版本
  • 不设置 prefix,验证行为与之前一致(无前缀)

… prefixed/unprefixed utilities

- Refactor color, border, spacing, text, rounded, and shadow rules to support token prefixes.
- Introduce options to allow or disallow prefixed and unprefixed utilities.
- Update BasePresetOptions to include tokenPrefix and allowPrefixedUtilities.
- Modify tests to validate new utility generation behavior and options.
@aibayanyu20
Copy link
Copy Markdown
Member

感谢 @cc-hearts 的设计与实现,这套 namespace 方案已经按 #7 RFC 的方向移植到 main:

  • commit: 88a5581 (UnoCSS namespace + 1.3.0 token 对齐)
  • commit: dd1c59b (Tailwind v4 compat.css)

落地后的行为与本 PR 完全一致:

  • 新增 tokenPrefixallowPrefixedUtilities 配置项
  • 默认输出三类工具类:a-bg-primary / bg-ant-primary / bg-primary
  • 移除 withThemeTokenPrefix 对 theme key 的改写(命名空间只在规则层处理)
  • allowUnprefixed: false 只关闭旧裸写法,theme key 保持稳定

同时在 antdv-next 主仓更新了中英文文档说明:antdv-next/antdv-next@9f3317c4

本 PR 关闭,由 main 上的实现接力。再次感谢方向上的贡献 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants