node-resource-utils 0.0.0-stage → 1.1.8

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.
Files changed (229) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +35 -2
  3. package/lib/sync.js +121 -0
  4. package/package.json +14 -4
  5. package/resources/.cache/ref.b64 +1 -0
  6. package/resources/README.md +97 -0
  7. package/resources/_.env +6 -0
  8. package/resources/_.env.example +25 -0
  9. package/resources/_.gitignore +18 -0
  10. package/resources/_.lintstagedrc.json +9 -0
  11. package/resources/_.npmrc +5 -0
  12. package/resources/_.prettierrc +7 -0
  13. package/resources/commitlint.config.mjs +1 -0
  14. package/resources/content/docs/README.md +63 -0
  15. package/resources/content/docs/faq.md +107 -0
  16. package/resources/content/docs/features/_meta.json +5 -0
  17. package/resources/content/docs/features/ai.md +71 -0
  18. package/resources/content/docs/features/appearance.md +47 -0
  19. package/resources/content/docs/features/feedback.md +79 -0
  20. package/resources/content/docs/features/files.md +74 -0
  21. package/resources/content/docs/features/graph.md +66 -0
  22. package/resources/content/docs/features/inbox.md +61 -0
  23. package/resources/content/docs/guide/_meta.json +5 -0
  24. package/resources/content/docs/guide/account.md +76 -0
  25. package/resources/content/docs/guide/data.md +87 -0
  26. package/resources/content/docs/guide/navigation.md +81 -0
  27. package/resources/content/docs/guide/permissions.md +67 -0
  28. package/resources/content/docs/guide/system.md +92 -0
  29. package/resources/content/docs/quick-start.md +70 -0
  30. package/resources/content/docs/shortcuts.md +69 -0
  31. package/resources/eslint.config.mjs +17 -0
  32. package/resources/next-env.d.ts +6 -0
  33. package/resources/next.config.ts +13 -0
  34. package/resources/postcss.config.mjs +7 -0
  35. package/resources/prisma/org.config.ts +98 -0
  36. package/resources/prisma/schema.prisma +336 -0
  37. package/resources/prisma/seed.ts +721 -0
  38. package/resources/prisma/seedSafe.ts +347 -0
  39. package/resources/prisma.config.ts +14 -0
  40. package/resources/scripts/check-config.mjs +773 -0
  41. package/resources/scripts/lib/schema-graph.mjs +410 -0
  42. package/resources/scripts/patch-next-trace.mjs +86 -0
  43. package/resources/scripts/suggest-relations.mjs +105 -0
  44. package/resources/src/app/(admin)/ai/page.tsx +469 -0
  45. package/resources/src/app/(admin)/dashboard/page.tsx +260 -0
  46. package/resources/src/app/(admin)/demo/employees/page.tsx +508 -0
  47. package/resources/src/app/(admin)/demo/files/page.tsx +451 -0
  48. package/resources/src/app/(admin)/demo/loading/page.tsx +513 -0
  49. package/resources/src/app/(admin)/error.tsx +96 -0
  50. package/resources/src/app/(admin)/feedback/page.tsx +573 -0
  51. package/resources/src/app/(admin)/graph/page.tsx +1224 -0
  52. package/resources/src/app/(admin)/inbox/page.tsx +31 -0
  53. package/resources/src/app/(admin)/layout.tsx +58 -0
  54. package/resources/src/app/(admin)/loading.tsx +31 -0
  55. package/resources/src/app/(admin)/system/depts/page.tsx +415 -0
  56. package/resources/src/app/(admin)/system/logs/page.tsx +215 -0
  57. package/resources/src/app/(admin)/system/menus/page.tsx +403 -0
  58. package/resources/src/app/(admin)/system/roles/page.tsx +433 -0
  59. package/resources/src/app/(admin)/system/users/page.tsx +620 -0
  60. package/resources/src/app/api/account-recovery/route.ts +132 -0
  61. package/resources/src/app/api/ai/act/route.ts +70 -0
  62. package/resources/src/app/api/ai/ask/route.ts +82 -0
  63. package/resources/src/app/api/ai/chat/route.ts +404 -0
  64. package/resources/src/app/api/ai/report/route.ts +164 -0
  65. package/resources/src/app/api/auth/[...nextauth]/route.ts +3 -0
  66. package/resources/src/app/api/auth/change-password/route.ts +57 -0
  67. package/resources/src/app/api/auth/forgot/route.ts +98 -0
  68. package/resources/src/app/api/auth/register/route.ts +95 -0
  69. package/resources/src/app/api/auth/register-config/route.ts +51 -0
  70. package/resources/src/app/api/badges/route.ts +39 -0
  71. package/resources/src/app/api/depts/[id]/route.ts +145 -0
  72. package/resources/src/app/api/depts/route.ts +126 -0
  73. package/resources/src/app/api/docs/export/route.ts +87 -0
  74. package/resources/src/app/api/docs/parse/route.ts +57 -0
  75. package/resources/src/app/api/docs/search/route.ts +22 -0
  76. package/resources/src/app/api/employees/[id]/route.ts +147 -0
  77. package/resources/src/app/api/employees/export/route.ts +115 -0
  78. package/resources/src/app/api/employees/import/route.ts +205 -0
  79. package/resources/src/app/api/employees/route.ts +149 -0
  80. package/resources/src/app/api/export/route.ts +254 -0
  81. package/resources/src/app/api/favorites/route.ts +56 -0
  82. package/resources/src/app/api/feedback/ai/route.ts +31 -0
  83. package/resources/src/app/api/feedback/approve/route.ts +67 -0
  84. package/resources/src/app/api/feedback/report/route.ts +213 -0
  85. package/resources/src/app/api/feedback/route.ts +246 -0
  86. package/resources/src/app/api/files/[name]/route.ts +82 -0
  87. package/resources/src/app/api/graph/focus/route.ts +75 -0
  88. package/resources/src/app/api/graph/node/move/route.ts +48 -0
  89. package/resources/src/app/api/graph/node/route.ts +274 -0
  90. package/resources/src/app/api/graph/route.ts +272 -0
  91. package/resources/src/app/api/health/route.ts +11 -0
  92. package/resources/src/app/api/inbox/read/route.ts +36 -0
  93. package/resources/src/app/api/inbox/summary/route.ts +15 -0
  94. package/resources/src/app/api/logs/route.ts +82 -0
  95. package/resources/src/app/api/menus/[id]/route.ts +132 -0
  96. package/resources/src/app/api/menus/mine/route.ts +23 -0
  97. package/resources/src/app/api/menus/route.ts +89 -0
  98. package/resources/src/app/api/roles/[id]/menus/route.ts +73 -0
  99. package/resources/src/app/api/roles/[id]/route.ts +96 -0
  100. package/resources/src/app/api/roles/route.ts +114 -0
  101. package/resources/src/app/api/search/route.ts +22 -0
  102. package/resources/src/app/api/stats/route.ts +92 -0
  103. package/resources/src/app/api/upload/route.ts +38 -0
  104. package/resources/src/app/api/users/[id]/password/route.ts +55 -0
  105. package/resources/src/app/api/users/[id]/route.ts +145 -0
  106. package/resources/src/app/api/users/route.ts +153 -0
  107. package/resources/src/app/api/visits/route.ts +48 -0
  108. package/resources/src/app/change-password/ChangePasswordForm.tsx +174 -0
  109. package/resources/src/app/change-password/page.tsx +19 -0
  110. package/resources/src/app/docs/[[...slug]]/page.tsx +56 -0
  111. package/resources/src/app/docs/layout.tsx +34 -0
  112. package/resources/src/app/docs/loading.tsx +19 -0
  113. package/resources/src/app/docs/not-found.tsx +25 -0
  114. package/resources/src/app/forgot/page.tsx +392 -0
  115. package/resources/src/app/global-error.tsx +75 -0
  116. package/resources/src/app/globals.css +235 -0
  117. package/resources/src/app/layout.tsx +44 -0
  118. package/resources/src/app/login/page.tsx +267 -0
  119. package/resources/src/app/page.tsx +14 -0
  120. package/resources/src/app/register/page.tsx +237 -0
  121. package/resources/src/auth.ts +215 -0
  122. package/resources/src/components/AiPanel.tsx +970 -0
  123. package/resources/src/components/AuthContext.tsx +82 -0
  124. package/resources/src/components/DataTable.tsx +459 -0
  125. package/resources/src/components/EChart.tsx +140 -0
  126. package/resources/src/components/FeedbackAiModal.tsx +476 -0
  127. package/resources/src/components/FeedbackReportModal.tsx +479 -0
  128. package/resources/src/components/Markdown.tsx +532 -0
  129. package/resources/src/components/OntologyGraph.tsx +1196 -0
  130. package/resources/src/components/Providers.tsx +99 -0
  131. package/resources/src/components/VisitTracker.tsx +89 -0
  132. package/resources/src/components/admin/AdminShell.tsx +749 -0
  133. package/resources/src/components/admin/CountBadge.tsx +67 -0
  134. package/resources/src/components/admin/GlobalSearch.tsx +509 -0
  135. package/resources/src/components/admin/InboxBell.tsx +78 -0
  136. package/resources/src/components/admin/VisitStats.tsx +145 -0
  137. package/resources/src/components/admin/menu-icons.tsx +56 -0
  138. package/resources/src/components/ai/AiInputForm.tsx +351 -0
  139. package/resources/src/components/appearance/AppearanceDrawer.tsx +268 -0
  140. package/resources/src/components/appearance/AppearanceProvider.tsx +160 -0
  141. package/resources/src/components/docs/DocArticle.tsx +106 -0
  142. package/resources/src/components/docs/DocToc.tsx +100 -0
  143. package/resources/src/components/docs/DocsChrome.tsx +259 -0
  144. package/resources/src/components/docs/DocsHome.tsx +209 -0
  145. package/resources/src/components/docs/DocsSearch.tsx +365 -0
  146. package/resources/src/components/docs/docs.css +1458 -0
  147. package/resources/src/components/feedback/AsyncButton.tsx +108 -0
  148. package/resources/src/components/feedback/LoadingOverlay.tsx +125 -0
  149. package/resources/src/components/feedback/PressableCard.tsx +92 -0
  150. package/resources/src/components/feedback/README.md +97 -0
  151. package/resources/src/components/feedback/RouteProgress.tsx +108 -0
  152. package/resources/src/components/feedback/Skeleton.tsx +249 -0
  153. package/resources/src/components/feedback/StatCard.tsx +70 -0
  154. package/resources/src/components/feedback/TaskHint.tsx +153 -0
  155. package/resources/src/components/feedback/index.ts +93 -0
  156. package/resources/src/components/feedback/motion.css +204 -0
  157. package/resources/src/components/feedback/motion.ts +63 -0
  158. package/resources/src/components/feedback/useCountUp.ts +110 -0
  159. package/resources/src/components/feedback/usePending.ts +209 -0
  160. package/resources/src/components/feedback/useRowFlash.ts +40 -0
  161. package/resources/src/components/inbox/InboxView.tsx +409 -0
  162. package/resources/src/components/ui/button.tsx +35 -0
  163. package/resources/src/components/ui/card.tsx +37 -0
  164. package/resources/src/components/ui/input.tsx +19 -0
  165. package/resources/src/lib/ai.ts +310 -0
  166. package/resources/src/lib/aiContext.ts +357 -0
  167. package/resources/src/lib/aiForm.test.ts +191 -0
  168. package/resources/src/lib/aiForm.ts +532 -0
  169. package/resources/src/lib/aiFormTypes.ts +83 -0
  170. package/resources/src/lib/aiToken.ts +72 -0
  171. package/resources/src/lib/aiTools.ts +823 -0
  172. package/resources/src/lib/api.ts +160 -0
  173. package/resources/src/lib/appInfo.ts +128 -0
  174. package/resources/src/lib/appearance.ts +643 -0
  175. package/resources/src/lib/badge-count.ts +146 -0
  176. package/resources/src/lib/badges.test.ts +58 -0
  177. package/resources/src/lib/badges.ts +79 -0
  178. package/resources/src/lib/brand-mark.test.ts +87 -0
  179. package/resources/src/lib/brand-mark.ts +45 -0
  180. package/resources/src/lib/docs-shared.test.ts +148 -0
  181. package/resources/src/lib/docs-shared.ts +422 -0
  182. package/resources/src/lib/docs.ts +381 -0
  183. package/resources/src/lib/err-text.ts +21 -0
  184. package/resources/src/lib/excel.ts +152 -0
  185. package/resources/src/lib/favorite-path.ts +60 -0
  186. package/resources/src/lib/favorites.ts +59 -0
  187. package/resources/src/lib/features.ts +69 -0
  188. package/resources/src/lib/feedback-access.ts +17 -0
  189. package/resources/src/lib/feedbackAi.ts +1621 -0
  190. package/resources/src/lib/formRules.ts +76 -0
  191. package/resources/src/lib/format.ts +52 -0
  192. package/resources/src/lib/graph-cascade.ts +304 -0
  193. package/resources/src/lib/graph-focus.ts +301 -0
  194. package/resources/src/lib/graph-link.ts +17 -0
  195. package/resources/src/lib/graph-node-write.ts +150 -0
  196. package/resources/src/lib/graph-schema.ts +475 -0
  197. package/resources/src/lib/graph-scope.test.ts +46 -0
  198. package/resources/src/lib/graph-scope.ts +28 -0
  199. package/resources/src/lib/http.ts +157 -0
  200. package/resources/src/lib/inbox-types.ts +57 -0
  201. package/resources/src/lib/inbox.ts +55 -0
  202. package/resources/src/lib/menu-service.ts +204 -0
  203. package/resources/src/lib/notifications.ts +113 -0
  204. package/resources/src/lib/office.ts +531 -0
  205. package/resources/src/lib/ontology.ts +277 -0
  206. package/resources/src/lib/openaiCompat.ts +257 -0
  207. package/resources/src/lib/pending.ts +98 -0
  208. package/resources/src/lib/prisma.ts +30 -0
  209. package/resources/src/lib/rbac.test.ts +106 -0
  210. package/resources/src/lib/rbac.ts +185 -0
  211. package/resources/src/lib/search-data.ts +158 -0
  212. package/resources/src/lib/security-questions.ts +20 -0
  213. package/resources/src/lib/skin-theme.ts +155 -0
  214. package/resources/src/lib/system-config.ts +55 -0
  215. package/resources/src/lib/theme.ts +96 -0
  216. package/resources/src/lib/todos/feedback.ts +86 -0
  217. package/resources/src/lib/todos/index.ts +73 -0
  218. package/resources/src/lib/todos/types.ts +33 -0
  219. package/resources/src/lib/upload.ts +106 -0
  220. package/resources/src/lib/utils.test.ts +9 -0
  221. package/resources/src/lib/utils.ts +6 -0
  222. package/resources/src/lib/validation.test.ts +297 -0
  223. package/resources/src/lib/validation.ts +658 -0
  224. package/resources/src/lib/visit-stats.ts +109 -0
  225. package/resources/src/lib/visits.ts +111 -0
  226. package/resources/src/lib/zodField.ts +44 -0
  227. package/resources/tsconfig.json +41 -0
  228. package/resources/vitest.config.ts +16 -0
  229. package/resources/vitest.setup.ts +1 -0
@@ -0,0 +1,643 @@
1
+ /**
2
+ * 外观设置 —— 皮肤(配色 + 材质)与字体大小的唯一来源。
3
+ *
4
+ * 为什么要有这一层:
5
+ * 题目一换,页面全是新写的,但"换个外观"这种全站能力不能跟着重写。
6
+ * 所以这里只描述 **token**(颜色、阴影、侧栏材质、品牌区渐变),
7
+ * 页面永远只引用语义(MILITARY.primary / var(--wb-text)),
8
+ * 皮肤切换就是把另一套 token 换上去,页面代码一行都不用动。
9
+ *
10
+ * 三层结构:
11
+ * 1. `SKINS`:每套皮肤的字面值(hex / 渐变串 / rgba)。
12
+ * —— 图表(canvas 不认 CSS 变量)和 SSR 首屏需要字面值,所以必须留在 JS 里。
13
+ * 2. `buildAppearanceCss()`:把字面值编译成 CSS 变量(`--wb-*`),
14
+ * 由根布局一次性写进 <head>。**所有皮肤**的变量块都在首屏 HTML 里,
15
+ * 切换皮肤只改 <html data-wb-skin>,不动任何组件 —— 零重排、零闪烁。
16
+ * 3. `buildBootScript()`:首屏渲染前跑的一行脚本,把本机保存的皮肤/字号
17
+ * 写回 <html>,避免"先按原版画一遍再跳成暗色"。
18
+ *
19
+ * 新增一套皮肤 = 往 `SKINS` 里加一条(含字面色板 + 侧栏/品牌区材质),
20
+ * 再在 `SKIN_LIST` 里排好序。不需要改任何页面。
21
+ *
22
+ * 新增一档字号 = 往 `FONT_SCALES` 里加一条(scale 是乘数)。
23
+ * 页面里的字号统一用 `fs(13)`(见 lib/theme.ts),它会乘上 `--wb-fs`。
24
+ */
25
+
26
+ export type SkinId = 'classic' | 'minimal' | 'deck';
27
+ export type FontId = 'sm' | 'md' | 'lg' | 'xl';
28
+
29
+ /** 本地保存键。改结构才升版本号(v1 起) */
30
+ export const APPEARANCE_KEY = 'wb.appearance.v1';
31
+
32
+ /** 字体栈:三套皮肤共用,离线环境只有系统字体可用 */
33
+ export const FONT_STACK =
34
+ "system-ui, -apple-system, 'Segoe UI', 'Microsoft YaHei', 'PingFang SC', sans-serif";
35
+
36
+ export interface AppearanceSettings {
37
+ skin: SkinId;
38
+ font: FontId;
39
+ }
40
+
41
+ export const DEFAULT_APPEARANCE: AppearanceSettings = { skin: 'classic', font: 'md' };
42
+
43
+ /* ------------------------------------------------------------------ *
44
+ * 字体档位
45
+ * ------------------------------------------------------------------ */
46
+
47
+ export interface FontScale {
48
+ id: FontId;
49
+ name: string;
50
+ /** 乘数:页面字号 `fs(13)` → 13px * scale */
51
+ scale: number;
52
+ hint: string;
53
+ }
54
+
55
+ export const FONT_SCALES: FontScale[] = [
56
+ { id: 'sm', name: '小', scale: 0.9, hint: '一屏能看更多行' },
57
+ { id: 'md', name: '标准', scale: 1, hint: '默认' },
58
+ { id: 'lg', name: '大', scale: 1.1, hint: '长时间阅读更轻松' },
59
+ { id: 'xl', name: '特大', scale: 1.2, hint: '投屏 / 视力不佳时用' },
60
+ ];
61
+
62
+ export function fontScaleOf(id: FontId): number {
63
+ return (FONT_SCALES.find((f) => f.id === id) ?? FONT_SCALES[1]).scale;
64
+ }
65
+
66
+ /* ------------------------------------------------------------------ *
67
+ * 皮肤
68
+ * ------------------------------------------------------------------ */
69
+
70
+ /** 字面色板:图表、canvas、以及任何"必须有真实颜色值"的地方用它 */
71
+ export interface SkinPalette {
72
+ primary: string;
73
+ primaryHover: string;
74
+ primaryActive: string;
75
+ /** 主色上的文字色(深色皮肤的主色偏亮,压深文字更清楚) */
76
+ onPrimary: string;
77
+ primaryDark: string;
78
+ primaryDeep: string;
79
+ soft: string;
80
+ softStrong: string;
81
+ accent: string;
82
+ accentSoft: string;
83
+ bg: string;
84
+ card: string;
85
+ /** 内容区(卡片外那层纸) */
86
+ paper: string;
87
+ border: string;
88
+ borderSoft: string;
89
+ text: string;
90
+ text2: string;
91
+ text3: string;
92
+ success: string;
93
+ warning: string;
94
+ error: string;
95
+ successBg: string;
96
+ warningBg: string;
97
+ errorBg: string;
98
+ dark: boolean;
99
+ radius: number;
100
+ shadow: string;
101
+ shadowSm: string;
102
+ /** 图表默认色板(canvas 用字面值) */
103
+ chart: string[];
104
+ /** 图谱连线(canvas 用字面值;深色皮肤要提亮,否则线全糊在底色里) */
105
+ edge: string;
106
+ }
107
+
108
+ /** 侧边栏材质:深色皮肤是作训服/舱壁,浅色皮肤是纸面 */
109
+ export interface SiderTokens {
110
+ /** 作为 background-image,'none' 表示只用底色 */
111
+ bg: string;
112
+ dark: boolean;
113
+ text: string;
114
+ textStrong: string;
115
+ textMuted: string;
116
+ hover: string;
117
+ active: string;
118
+ line: string;
119
+ /** 选中项左侧那条定位条 */
120
+ mark: string;
121
+ border: string;
122
+ }
123
+
124
+ /** 品牌区(登录页左栏、AI 指挥带、报告封面) */
125
+ export interface BrandTokens {
126
+ /** 整块品牌底(登录页整屏) */
127
+ bg: string;
128
+ /** 内嵌的小指挥带(AI 页、报告封面) */
129
+ panel: string;
130
+ text: string;
131
+ textSoft: string;
132
+ textMuted: string;
133
+ /** 眉标(kicker)颜色 */
134
+ kicker: string;
135
+ line: string;
136
+ /** 四角定位角标 / 强调描边 */
137
+ tint: string;
138
+ /** 半透明玻璃块(指标胶囊) */
139
+ glass: string;
140
+ shadow: string;
141
+ }
142
+
143
+ /**
144
+ * 操作反馈层(components/feedback/motion.css)的取材:
145
+ * 悬停/按下的阴影与描边。深色皮肤不能沿用"深色半透明阴影",
146
+ * 否则抬起动作完全看不见,得换成一点白光。
147
+ */
148
+ export interface MotionTokens {
149
+ shadeIdle: string;
150
+ shadeHover: string;
151
+ shadePress: string;
152
+ borderIdle: string;
153
+ borderHover: string;
154
+ surfaceHover: string;
155
+ /** 「结果落在这里」那一闪的底色 */
156
+ flash: string;
157
+ }
158
+
159
+ export interface Skin {
160
+ id: SkinId;
161
+ name: string;
162
+ /** 一句话描述,面板里显示 */
163
+ blurb: string;
164
+ palette: SkinPalette;
165
+ sider: SiderTokens;
166
+ brand: BrandTokens;
167
+ motion: MotionTokens;
168
+ skeleton: { a: string; b: string };
169
+ scrollbar: { a: string; b: string };
170
+ selection: string;
171
+ selectionText: string;
172
+ /** 皮肤独有的装饰规则(只放 shell 级签名元素,不碰业务页) */
173
+ extraCss: string;
174
+ }
175
+
176
+ /* ----------------------------- 1. 原版 ----------------------------- */
177
+
178
+ const classic: Skin = {
179
+ id: 'classic',
180
+ name: '原版',
181
+ blurb: '军绿与黄铜,纸感底纹',
182
+ palette: {
183
+ primary: '#4E5F3C',
184
+ primaryHover: '#61764D',
185
+ primaryActive: '#3D4C2F',
186
+ onPrimary: '#FFFFFF',
187
+ primaryDark: '#2B3721',
188
+ primaryDeep: '#1F2918',
189
+ soft: '#EDF0E3',
190
+ softStrong: '#DCE3CC',
191
+ accent: '#C0A97E',
192
+ accentSoft: '#F4EEDF',
193
+ bg: '#F2F3EA',
194
+ card: '#FFFFFF',
195
+ paper: '#F8F9F3',
196
+ border: '#E3E5D6',
197
+ borderSoft: '#EEF0E5',
198
+ text: '#202619',
199
+ text2: '#5B6252',
200
+ text3: '#8B9181',
201
+ success: '#5E7C4E',
202
+ warning: '#B08A3E',
203
+ error: '#B4472F',
204
+ successBg: '#ECF2E4',
205
+ warningBg: '#F7F0DE',
206
+ errorBg: '#F9ECE8',
207
+ dark: false,
208
+ radius: 8,
209
+ shadow: '0 8px 24px rgba(32,38,25,.10)',
210
+ shadowSm: '0 1px 2px rgba(32,38,25,.05)',
211
+ chart: ['#4E5F3C', '#7C8F63', '#B99C6B', '#5F7050', '#9A7B52'],
212
+ edge: '#C8CEB8',
213
+ },
214
+ sider: {
215
+ bg: 'repeating-linear-gradient(135deg, rgba(255,255,255,.028) 0 2px, transparent 2px 10px), linear-gradient(180deg, #2B3721 0%, #1F2918 100%)',
216
+ dark: true,
217
+ text: 'rgba(245,246,238,.72)',
218
+ textStrong: '#F5F6EE',
219
+ textMuted: 'rgba(245,246,238,.34)',
220
+ hover: 'rgba(255,255,255,.07)',
221
+ active: 'rgba(192,169,126,.16)',
222
+ line: 'rgba(255,255,255,.07)',
223
+ mark: '#C0A97E',
224
+ border: 'rgba(0,0,0,.28)',
225
+ },
226
+ brand: {
227
+ bg:
228
+ 'radial-gradient(900px 520px at 10% 5%, rgba(192,169,126,.18), transparent 62%), ' +
229
+ 'repeating-linear-gradient(135deg, rgba(255,255,255,.03) 0 2px, transparent 2px 14px), ' +
230
+ 'linear-gradient(135deg, #1C2415 0%, #2B3721 46%, #43542F 100%)',
231
+ panel:
232
+ 'radial-gradient(600px 220px at 8% 0%, rgba(192,169,126,.18), transparent 65%), ' +
233
+ 'repeating-linear-gradient(135deg, rgba(255,255,255,.035) 0 2px, transparent 2px 12px), ' +
234
+ 'linear-gradient(118deg, #1F2918 0%, #2B3721 52%, #47583A 100%)',
235
+ text: '#F7F8F1',
236
+ textSoft: 'rgba(240,242,232,.78)',
237
+ textMuted: 'rgba(240,242,232,.5)',
238
+ kicker: '#CBB98D',
239
+ line: 'rgba(192,169,126,.22)',
240
+ tint: 'rgba(192,169,126,.5)',
241
+ glass: 'rgba(255,255,255,.06)',
242
+ shadow: '0 18px 50px rgba(20,26,15,.3)',
243
+ },
244
+ motion: {
245
+ shadeIdle: 'rgba(32,38,25,.05)',
246
+ shadeHover: 'rgba(32,38,25,.1)',
247
+ shadePress: 'rgba(32,38,25,.07)',
248
+ borderIdle: '#E3E5D6',
249
+ borderHover: '#D5DAC4',
250
+ surfaceHover: '#FCFDF6',
251
+ flash: 'rgba(192,169,126,.32)',
252
+ },
253
+ skeleton: { a: '#EDF0E3', b: '#F6F7EF' },
254
+ scrollbar: { a: '#C9CFBA', b: '#A9B195' },
255
+ selection: 'rgba(78,95,60,.2)',
256
+ selectionText: '#1B2116',
257
+ extraCss: '',
258
+ };
259
+
260
+ /* ----------------------------- 2. 简洁 ----------------------------- */
261
+
262
+ /**
263
+ * 简洁版:纸白 + 发丝线 + 石墨青。
264
+ * 签名元素是"浅色侧栏 + 一条 2px 定位线"——把原版的深色面料整个翻过来,
265
+ * 不靠阴影堆层次,只靠留白和 1px 线的深浅差。
266
+ */
267
+ const minimal: Skin = {
268
+ id: 'minimal',
269
+ name: '简洁',
270
+ blurb: '纸白与发丝线,浅色侧栏',
271
+ palette: {
272
+ primary: '#2C4A52',
273
+ primaryHover: '#3C6270',
274
+ primaryActive: '#213B42',
275
+ onPrimary: '#FFFFFF',
276
+ primaryDark: '#2C4A52',
277
+ primaryDeep: '#1B2E34',
278
+ soft: '#EDF1F3',
279
+ softStrong: '#DCE4E8',
280
+ accent: '#9BA8AE',
281
+ accentSoft: '#F2F5F6',
282
+ bg: '#F6F7F8',
283
+ card: '#FFFFFF',
284
+ paper: '#FFFFFF',
285
+ border: '#E5E8EA',
286
+ borderSoft: '#EFF1F2',
287
+ text: '#16191C',
288
+ text2: '#5A646B',
289
+ text3: '#8B959C',
290
+ success: '#2E7D5B',
291
+ warning: '#B07C2E',
292
+ error: '#B4453C',
293
+ successBg: '#E8F3EE',
294
+ warningBg: '#F8F1E2',
295
+ errorBg: '#F9EBE9',
296
+ dark: false,
297
+ radius: 6,
298
+ shadow: '0 6px 20px rgba(20,35,42,.08)',
299
+ shadowSm: '0 1px 0 rgba(20,35,42,.04)',
300
+ chart: ['#2C4A52', '#5C7C86', '#8FA6AD', '#3E6470', '#B3C2C7'],
301
+ edge: '#D2DDE2',
302
+ },
303
+ sider: {
304
+ bg: 'linear-gradient(180deg, #FFFFFF 0%, #FCFDFD 100%)',
305
+ dark: false,
306
+ text: '#55626A',
307
+ textStrong: '#16191C',
308
+ textMuted: '#9AA6AD',
309
+ hover: '#F2F5F6',
310
+ active: '#E9EFF2',
311
+ line: '#EDF1F3',
312
+ mark: '#2C4A52',
313
+ border: '#E5E8EA',
314
+ },
315
+ brand: {
316
+ bg:
317
+ 'radial-gradient(760px 520px at 8% 0%, #E9F0F2, transparent 62%), ' +
318
+ 'linear-gradient(160deg, #FFFFFF 0%, #F5F8F9 55%, #E7EDEF 100%)',
319
+ panel: 'linear-gradient(160deg, #FFFFFF 0%, #F2F6F7 100%)',
320
+ text: '#16191C',
321
+ textSoft: '#4E5A61',
322
+ textMuted: '#7C8990',
323
+ kicker: '#2C4A52',
324
+ line: '#DFE6E9',
325
+ tint: '#B9C9CE',
326
+ glass: 'rgba(255,255,255,.72)',
327
+ shadow: '0 18px 50px rgba(20,35,42,.12)',
328
+ },
329
+ motion: {
330
+ shadeIdle: 'rgba(20,35,42,.04)',
331
+ shadeHover: 'rgba(20,35,42,.09)',
332
+ shadePress: 'rgba(20,35,42,.06)',
333
+ borderIdle: '#E5E8EA',
334
+ borderHover: '#D2DCE0',
335
+ surfaceHover: '#FAFCFC',
336
+ flash: 'rgba(44,74,82,.16)',
337
+ },
338
+ skeleton: { a: '#EFF2F4', b: '#FAFBFC' },
339
+ scrollbar: { a: '#D7DEE1', b: '#BFCACE' },
340
+ selection: 'rgba(44,74,82,.16)',
341
+ selectionText: '#16191C',
342
+ extraCss: `
343
+ /* 简洁版:顶栏不投影,只留一条发丝线;卡片靠线不靠影 */
344
+ html[data-wb-skin='minimal'] .wb-header { box-shadow: none; }
345
+ html[data-wb-skin='minimal'] .ant-card { box-shadow: none !important; }
346
+ /* 登录页:品牌区与表单区之间只放一条发丝线,其余交给留白 */
347
+ html[data-wb-skin='minimal'] .wb-brand-copy { border-right: 1px solid var(--wb-border); }
348
+ html[data-wb-skin='minimal'] .wb-brand-card .ant-card { border-color: var(--wb-border); }
349
+ `,
350
+ };
351
+
352
+ /* ----------------------------- 3. 炫酷 ----------------------------- */
353
+
354
+ /**
355
+ * 炫酷版:深色指挥舱。
356
+ * 底色压到近黑,面板靠 1px 荧光描边 + 顶部微光分层;
357
+ * 主色是荧光橄榄(夜间可读性比纯青绿更好),琥珀只用在极小面积。
358
+ * 签名元素:侧栏的竖向细网格 + 顶栏底部那条冷光。
359
+ */
360
+ const deck: Skin = {
361
+ id: 'deck',
362
+ name: '炫酷',
363
+ blurb: '深色指挥舱,荧光描边',
364
+ palette: {
365
+ primary: '#9FD166',
366
+ primaryHover: '#B7E083',
367
+ primaryActive: '#86B94F',
368
+ onPrimary: '#0B1208',
369
+ primaryDark: '#0C1710',
370
+ primaryDeep: '#060B08',
371
+ soft: 'rgba(159,209,102,.14)',
372
+ softStrong: 'rgba(159,209,102,.24)',
373
+ accent: '#E6B968',
374
+ accentSoft: 'rgba(230,185,104,.16)',
375
+ bg: '#080D0A',
376
+ card: '#111A14',
377
+ paper: '#0C1210',
378
+ border: '#25322B',
379
+ borderSoft: '#1B2621',
380
+ text: '#E7F0E4',
381
+ text2: '#A4B3A0',
382
+ text3: '#6F7F6B',
383
+ success: '#6FD39A',
384
+ warning: '#E6B968',
385
+ error: '#FF7E6B',
386
+ successBg: 'rgba(111,211,154,.14)',
387
+ warningBg: 'rgba(230,185,104,.14)',
388
+ errorBg: 'rgba(255,126,107,.14)',
389
+ dark: true,
390
+ radius: 10,
391
+ shadow: '0 0 0 1px rgba(159,209,102,.10), 0 10px 28px rgba(0,0,0,.5)',
392
+ shadowSm: '0 1px 2px rgba(0,0,0,.55)',
393
+ chart: ['#9FD166', '#5FD3C0', '#E6B968', '#7FA5FF', '#C58BFF'],
394
+ edge: '#44614F',
395
+ },
396
+ sider: {
397
+ bg:
398
+ 'repeating-linear-gradient(90deg, rgba(159,209,102,.05) 0 1px, transparent 1px 34px), ' +
399
+ 'linear-gradient(180deg, #0C1710 0%, #060B08 100%)',
400
+ dark: true,
401
+ text: 'rgba(231,240,228,.74)',
402
+ textStrong: '#EAF3E7',
403
+ textMuted: 'rgba(231,240,228,.38)',
404
+ hover: 'rgba(159,209,102,.08)',
405
+ active: 'rgba(159,209,102,.16)',
406
+ line: 'rgba(159,209,102,.12)',
407
+ mark: '#9FD166',
408
+ border: '#101A13',
409
+ },
410
+ brand: {
411
+ bg:
412
+ 'radial-gradient(760px 420px at 12% 0%, rgba(159,209,102,.18), transparent 62%), ' +
413
+ 'radial-gradient(520px 360px at 92% 88%, rgba(230,185,104,.12), transparent 60%), ' +
414
+ 'linear-gradient(150deg, #070C09 0%, #0F1A12 55%, #16241A 100%)',
415
+ panel:
416
+ 'radial-gradient(560px 220px at 10% 0%, rgba(159,209,102,.16), transparent 65%), ' +
417
+ 'linear-gradient(118deg, #0A120C 0%, #101C13 52%, #16281A 100%)',
418
+ text: '#EAF3E7',
419
+ textSoft: 'rgba(231,240,228,.78)',
420
+ textMuted: 'rgba(231,240,228,.5)',
421
+ kicker: '#E6B968',
422
+ line: 'rgba(159,209,102,.24)',
423
+ tint: 'rgba(159,209,102,.45)',
424
+ glass: 'rgba(255,255,255,.05)',
425
+ shadow: '0 24px 60px rgba(0,0,0,.55)',
426
+ },
427
+ motion: {
428
+ shadeIdle: 'rgba(255,255,255,.05)',
429
+ shadeHover: 'rgba(255,255,255,.09)',
430
+ shadePress: 'rgba(255,255,255,.07)',
431
+ borderIdle: '#25322B',
432
+ borderHover: '#3A4B40',
433
+ surfaceHover: '#16211A',
434
+ flash: 'rgba(159,209,102,.24)',
435
+ },
436
+ skeleton: { a: '#18221B', b: '#223028' },
437
+ scrollbar: { a: '#27352C', b: '#38493C' },
438
+ selection: 'rgba(159,209,102,.22)',
439
+ selectionText: '#EAF3E7',
440
+ extraCss: `
441
+ /* 炫酷版:顶栏底部一道冷光,内容区一圈极淡的舱壁描边 */
442
+ html[data-wb-skin='deck'] .wb-header {
443
+ box-shadow: inset 0 -1px 0 rgba(159,209,102,.22), 0 1px 28px rgba(159,209,102,.07);
444
+ }
445
+ html[data-wb-skin='deck'] .wb-content { box-shadow: inset 0 0 0 1px rgba(159,209,102,.07); }
446
+ html[data-wb-skin='deck'] .ant-card { box-shadow: inset 0 1px 0 rgba(255,255,255,.03); }
447
+ /* 登录卡片:暗底上靠一圈冷光而不是投影分层 */
448
+ html[data-wb-skin='deck'] .wb-brand-card .ant-card {
449
+ box-shadow: 0 0 0 1px rgba(159,209,102,.16), 0 26px 60px rgba(0,0,0,.6);
450
+ }
451
+ `,
452
+ };
453
+
454
+ export const SKINS: Record<SkinId, Skin> = { classic, minimal, deck };
455
+
456
+ /** 面板里的展示顺序:原版永远排第一,它是基准 */
457
+ export const SKIN_LIST: Skin[] = [classic, minimal, deck];
458
+
459
+ /* ------------------------------------------------------------------ *
460
+ * token → CSS 变量
461
+ * ------------------------------------------------------------------ */
462
+
463
+ /**
464
+ * 语义变量表。页面/组件只准用这些名字,不许自己拼 rgba。
465
+ * 新增视觉语义时先在这里加,再去 SKINS 里给三套皮肤各填一个值。
466
+ */
467
+ export function varsOfSkin(s: Skin): Record<string, string> {
468
+ const p = s.palette;
469
+ return {
470
+ '--wb-primary': p.primary,
471
+ '--wb-primary-hover': p.primaryHover,
472
+ '--wb-primary-active': p.primaryActive,
473
+ '--wb-on-primary': p.onPrimary,
474
+ '--wb-primary-dark': p.primaryDark,
475
+ '--wb-primary-deep': p.primaryDeep,
476
+ '--wb-soft': p.soft,
477
+ '--wb-soft-strong': p.softStrong,
478
+ '--wb-accent': p.accent,
479
+ '--wb-accent-soft': p.accentSoft,
480
+ '--wb-bg': p.bg,
481
+ '--wb-card': p.card,
482
+ '--wb-paper': p.paper,
483
+ '--wb-border': p.border,
484
+ '--wb-border-soft': p.borderSoft,
485
+ '--wb-text': p.text,
486
+ '--wb-text-2': p.text2,
487
+ '--wb-text-3': p.text3,
488
+ '--wb-success': p.success,
489
+ '--wb-warning': p.warning,
490
+ '--wb-error': p.error,
491
+ '--wb-success-bg': p.successBg,
492
+ '--wb-warning-bg': p.warningBg,
493
+ '--wb-error-bg': p.errorBg,
494
+ '--wb-shadow': p.shadow,
495
+ '--wb-shadow-sm': p.shadowSm,
496
+ '--wb-radius': `${p.radius}px`,
497
+ '--wb-radius-sm': `${Math.max(2, p.radius - 2)}px`,
498
+ '--wb-sider-bg': s.sider.bg,
499
+ '--wb-sider-text': s.sider.text,
500
+ '--wb-sider-text-strong': s.sider.textStrong,
501
+ '--wb-sider-text-muted': s.sider.textMuted,
502
+ '--wb-sider-hover': s.sider.hover,
503
+ '--wb-sider-active': s.sider.active,
504
+ '--wb-sider-line': s.sider.line,
505
+ '--wb-sider-mark': s.sider.mark,
506
+ '--wb-sider-border': s.sider.border,
507
+ '--wb-brand-bg': s.brand.bg,
508
+ '--wb-brand-panel': s.brand.panel,
509
+ '--wb-brand-text': s.brand.text,
510
+ '--wb-brand-text-soft': s.brand.textSoft,
511
+ '--wb-brand-text-muted': s.brand.textMuted,
512
+ '--wb-brand-kicker': s.brand.kicker,
513
+ '--wb-brand-line': s.brand.line,
514
+ '--wb-brand-tint': s.brand.tint,
515
+ '--wb-brand-glass': s.brand.glass,
516
+ '--wb-brand-shadow': s.brand.shadow,
517
+ '--wb-skeleton-a': s.skeleton.a,
518
+ '--wb-skeleton-b': s.skeleton.b,
519
+ '--wb-scrollbar': s.scrollbar.a,
520
+ '--wb-scrollbar-hover': s.scrollbar.b,
521
+ '--wb-selection': s.selection,
522
+ '--wb-selection-text': s.selectionText,
523
+ '--wb-shade-idle': s.motion.shadeIdle,
524
+ '--wb-shade-hover': s.motion.shadeHover,
525
+ '--wb-shade-press': s.motion.shadePress,
526
+ '--wb-border-idle': s.motion.borderIdle,
527
+ '--wb-border-hover': s.motion.borderHover,
528
+ '--wb-surface-hover': s.motion.surfaceHover,
529
+ '--wb-flash': s.motion.flash,
530
+ '--wb-graph-edge': p.edge,
531
+ };
532
+ }
533
+
534
+ /** 一次性生成全站外观 CSS:所有皮肤 + 所有字号档 + shell 级签名规则 */
535
+ export function buildAppearanceCss(): string {
536
+ const skinBlocks = SKIN_LIST.map(
537
+ (s) =>
538
+ `html[data-wb-skin='${s.id}']{${Object.entries(varsOfSkin(s))
539
+ .map(([k, v]) => `${k}:${v}`)
540
+ .join(';')}}`
541
+ ).join('\n');
542
+
543
+ const fontBlocks = FONT_SCALES.map(
544
+ (f) => `html[data-wb-font='${f.id}']{--wb-fs:${f.scale}}`
545
+ ).join('\n');
546
+
547
+ const extras = SKIN_LIST.map((s) => s.extraCss).filter(Boolean).join('\n');
548
+
549
+ return `/* 外观底座:由 lib/appearance.ts 按皮肤定义生成,勿手改 */
550
+ :root{${Object.entries(varsOfSkin(classic))
551
+ .map(([k, v]) => `${k}:${v}`)
552
+ .join(';')};--wb-fs:1}
553
+ ${skinBlocks}
554
+ ${fontBlocks}
555
+ html{background:var(--wb-bg);color:var(--wb-text)}
556
+ html[data-wb-skin='deck']{color-scheme:dark}
557
+ html[data-wb-skin='classic'],html[data-wb-skin='minimal']{color-scheme:light}
558
+ /* 切换皮肤时让颜色平滑过渡(只过渡颜色类属性,不动布局) */
559
+ html.wb-skin-anim,html.wb-skin-anim *{transition:background-color .18s ease,background-image .18s ease,border-color .18s ease,color .18s ease,box-shadow .18s ease !important}
560
+ @media (prefers-reduced-motion: reduce){html.wb-skin-anim,html.wb-skin-anim *{transition:none !important}}
561
+ ${extras}
562
+ `;
563
+ }
564
+
565
+ /**
566
+ * 首屏脚本:在 React 挂载前把本机外观写回 <html>。
567
+ * 必须内联执行(阻塞),否则会先按原版画一帧再跳成暗色。
568
+ */
569
+ export const APPEARANCE_BOOT = (() => {
570
+ const skinIds = SKIN_LIST.map((s) => s.id).join('|');
571
+ const fontIds = FONT_SCALES.map((f) => f.id).join('|');
572
+ return (
573
+ `(function(){try{var v=JSON.parse(localStorage.getItem('${APPEARANCE_KEY}')||'null')||{};` +
574
+ `var e=document.documentElement;` +
575
+ `if(new RegExp('^(${skinIds})$').test(v.skin))e.dataset.wbSkin=v.skin;` +
576
+ `if(new RegExp('^(${fontIds})$').test(v.font))e.dataset.wbFont=v.font;` +
577
+ `}catch(_){}})();`
578
+ );
579
+ })();
580
+
581
+ /* ------------------------------------------------------------------ *
582
+ * 读写 / 应用
583
+ * ------------------------------------------------------------------ */
584
+
585
+ function isSkinId(v: unknown): v is SkinId {
586
+ return typeof v === 'string' && Object.prototype.hasOwnProperty.call(SKINS, v);
587
+ }
588
+
589
+ function isFontId(v: unknown): v is FontId {
590
+ return typeof v === 'string' && FONT_SCALES.some((f) => f.id === v);
591
+ }
592
+
593
+ /** 容错解析:版本升级、手工改坏、存了别的值,一律回落到默认 */
594
+ export function parseAppearance(raw: string | null | undefined): AppearanceSettings {
595
+ if (!raw) return DEFAULT_APPEARANCE;
596
+ try {
597
+ const v = JSON.parse(raw) as Partial<AppearanceSettings> | null;
598
+ return {
599
+ skin: isSkinId(v?.skin) ? v.skin : DEFAULT_APPEARANCE.skin,
600
+ font: isFontId(v?.font) ? v.font : DEFAULT_APPEARANCE.font,
601
+ };
602
+ } catch {
603
+ return DEFAULT_APPEARANCE;
604
+ }
605
+ }
606
+
607
+ /** 读本机设置;SSR 环境返回默认值 */
608
+ export function readAppearance(): AppearanceSettings {
609
+ if (typeof window === 'undefined') return DEFAULT_APPEARANCE;
610
+ try {
611
+ return parseAppearance(window.localStorage.getItem(APPEARANCE_KEY));
612
+ } catch {
613
+ return DEFAULT_APPEARANCE;
614
+ }
615
+ }
616
+
617
+ export function saveAppearance(s: AppearanceSettings): void {
618
+ if (typeof window === 'undefined') return;
619
+ try {
620
+ window.localStorage.setItem(APPEARANCE_KEY, JSON.stringify(s));
621
+ } catch {
622
+ /* 隐私模式下写不进去:本次会话仍然生效,只是刷新后回到默认 */
623
+ }
624
+ }
625
+
626
+ /** 把设置写到 <html> 上;CSS 变量由 buildAppearanceCss 提供,这里只切开关 */
627
+ export function applyAppearance(s: AppearanceSettings): void {
628
+ if (typeof document === 'undefined') return;
629
+ const el = document.documentElement;
630
+ el.dataset.wbSkin = s.skin;
631
+ el.dataset.wbFont = s.font;
632
+ }
633
+
634
+ /**
635
+ * 取某个 CSS 变量的当前真实值。
636
+ * 图表(ECharts / canvas)不认 var(),必须先把颜色解析成 hex。
637
+ * 只在浏览器里调用;SSR 返回 fallback。
638
+ */
639
+ export function cssVar(name: string, fallback = ''): string {
640
+ if (typeof window === 'undefined') return fallback;
641
+ const v = getComputedStyle(document.documentElement).getPropertyValue(name).trim();
642
+ return v || fallback;
643
+ }