weifuwu 0.63.0 → 0.64.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,130 @@
1
+ # 样式定制指南
2
+
3
+ > 本页为 weifuwu 官方文档拆分页 · [返回 README](../README.md)
4
+
5
+ ## 组件定制钩子(零覆盖 CSS)
6
+
7
+ 关键组件视觉全部变量化——定制只需设一个变量(默认值 = 现有 token):
8
+
9
+ ```html
10
+ <style>
11
+ :root {
12
+ --wf-brand-500: #7c3aed; /* 品牌换色:改原始层一个值,全站跟随 */
13
+ --wf-dark-brand-500: #a78bfa; /* 暗色品牌(可选) */
14
+ --wf-modal-width: 640px; /* 组件定制:设一个变量 */
15
+ --wf-btn-radius: 999px;
16
+ --wf-field-height: 44px;
17
+ --wf-card-shadow: 0 8px 24px rgba(0,0,0,.12);
18
+ }
19
+ </style>
20
+ ```
21
+
22
+ 钩子清单:`--wf-btn-*` `--wf-card-*` `--wf-field-*` `--wf-modal-*` `--wf-drawer-width` `--wf-toast-*` `--wf-alert-radius` `--wf-badge-radius` `--wf-tag-radius` `--wf-switch-radius` `--wf-popover-*` `--wf-tooltip-radius` `--wf-dropdown-min-width` `--wf-datepicker-*`。
23
+
24
+ **覆盖优先级(@layer)**:`@layer tokens, base, layout, utilities, components`——你写的未分层 CSS 天然最高优先级;也可用 `@layer utilities` 精准覆盖我们。
25
+
26
+ ## 零自定义 CSS 模式(推荐)
27
+
28
+ 一个项目只需要引用**一个 CSS 文件**(`weifuwu/components/style.css`,内含 Token + 布局原语 + 组件样式),
29
+ 业务代码全部由组件 + `wf-*` 原语承担,**不需要再写 `style.css`**:
30
+
31
+ ```tsx
32
+ // 组件 → 页面功能块;wf-* 原语 → 块之间的空间关系;--wf-* → 业务色值
33
+ <PageHeader title="仪表盘" sub="欢迎回来">
34
+ <Button variant="primary">+ 新建</Button>
35
+ </PageHeader>
36
+ <div class="wf-row wf-gap-lg">
37
+ <StatCard label="总用户" value="1,234" trend="up" trendLabel="12%" />
38
+ </div>
39
+ ```
40
+
41
+ 主题定制(品牌色/圆角/字体)不需要独立文件——**内联在 HTML 的 `<style>` 里即可**:
42
+
43
+ ```html
44
+ <style>
45
+ :root {
46
+ --wf-color-primary: #6366f1;
47
+ --wf-radius: 8px;
48
+ }
49
+ </style>
50
+ ```
51
+
52
+ 完整的零样式示例:`apps/components-demo`(组件 + 原语即插即用,无手写样式)。
53
+
54
+ 诚实例外(合理场景,仍可内联 `<style>` 解决):打印/PDF 导出规则、第三方库宿主样式、
55
+ 业务特有的一次性视觉(如色板选择器交互)。
56
+
57
+ ## 全局主题变量
58
+
59
+ 所有组件引用 `--wf-*` CSS 变量。在根元素覆盖即可定制主题:
60
+
61
+ ```css
62
+ :root {
63
+ --wf-color-primary: #6366f1;
64
+ --wf-color-primary-hover: #4f46e5;
65
+ --wf-radius: 8px;
66
+ --wf-font-sans: 'Inter', system-ui, sans-serif;
67
+ }
68
+ ```
69
+
70
+ ## 暗色模式
71
+
72
+ 两种激活方式(显式 `data-theme` 优先级高于系统偏好):
73
+
74
+ ```ts
75
+ // 手动切换
76
+ document.documentElement.setAttribute('data-theme', 'dark')
77
+
78
+ // 强制亮色(系统为暗色时也保持亮色)
79
+ document.documentElement.setAttribute('data-theme', 'light')
80
+ ```
81
+
82
+ 未设置 `data-theme` 时,自动跟随系统偏好:`@media (prefers-color-scheme: dark)` 下自动切换暗色。
83
+
84
+ 所有 `--wf-*` 变量在暗色下自动切换。可自定义暗色变量:
85
+
86
+ ```css
87
+ [data-theme="dark"] {
88
+ --wf-color-bg: #1a1a2e;
89
+ --wf-color-text: #e0e0e0;
90
+ --wf-color-border: #2a2a4a;
91
+ }
92
+
93
+ /* 自定义系统自动暗色的变量(需与上面同步) */
94
+ @media (prefers-color-scheme: dark) {
95
+ :root:not([data-theme="light"]) {
96
+ --wf-color-bg: #1a1a2e;
97
+ --wf-color-text: #e0e0e0;
98
+ --wf-color-border: #2a2a4a;
99
+ }
100
+ }
101
+ ```
102
+
103
+ ## 组件级覆盖
104
+
105
+ ```css
106
+ /* 覆盖 Button 主色 */
107
+ .wf-btn--primary {
108
+ background: #06b6d4;
109
+ border-color: #06b6d4;
110
+ }
111
+
112
+ /* 覆盖 Modal 圆角 */
113
+ .wf-modal-content {
114
+ border-radius: 16px;
115
+ }
116
+ ```
117
+
118
+ ## 作用域主题
119
+
120
+ ```html
121
+ <div style="--wf-color-primary: #f59e0b;">
122
+ <!-- 此区域内组件使用金色主题,外部不受影响 -->
123
+ <button class="wf-btn wf-btn--primary">金色按钮</button>
124
+ </div>
125
+ ```
126
+
127
+ CSS 变量会沿 DOM 树继承,利用这一点可实现多主题共存。
128
+
129
+ ---
130
+
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "weifuwu",
3
3
  "type": "module",
4
- "version": "0.63.0",
4
+ "version": "0.64.0",
5
5
  "description": "AI SaaS framework — (req, ctx) => Response",
6
6
  "exports": {
7
7
  ".": {
@@ -27,14 +27,15 @@
27
27
  },
28
28
  "files": [
29
29
  "dist/",
30
- "README.md"
30
+ "README.md",
31
+ "docs/"
31
32
  ],
32
33
  "scripts": {
33
34
  "build": "node scripts/build.mjs",
34
35
  "prepublishOnly": "npm run build && tsc --emitDeclarationOnly --outdir dist",
35
36
  "typecheck": "tsc --noEmit",
36
37
  "pretest": "docker compose up -d --wait postgres redis 2>/dev/null; sleep 1",
37
- "test": "node --env-file=.env --test 'src/test/**/*.test.ts' 'src/components/**/*.test.ts' 'src/db/**/*.test.ts'",
38
+ "test": "node --env-file=.env --test --test-concurrency=8 'src/test/**/*.test.ts' 'src/components/**/*.test.ts' 'src/db/**/*.test.ts'",
38
39
  "release": "node scripts/release.mjs",
39
40
  "release:dry": "node scripts/release.mjs --dry-run"
40
41
  },