soma-kit 0.1.7 → 0.1.9
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.
- package/package.json +2 -2
- package/spec/generated/kit-app.schema.json +27 -0
- package/spec/generated/kit-page.schema.json +7 -0
- package/spec/kit-grammar.json +105 -6
- package/src/app/app-config.ts +558 -20
- package/src/app/component-gate.ts +203 -0
- package/src/app/define-kit-app.ts +3 -0
- package/src/app/server.ts +10 -1
- package/src/base/shared.ts +48 -5
- package/src/base/text.ts +8 -2
- package/src/biz/index.ts +30 -0
- package/src/biz/page-templates/domain-templates.ts +184 -0
- package/src/compile/compile-page.ts +149 -4
- package/src/compile/parse.ts +4 -0
- package/src/compile/types.ts +5 -1
- package/src/data/embed.ts +2 -0
- package/src/data/navbar.ts +2 -2
- package/src/generated/kit-grammar-runtime.ts +7 -4
- package/src/theme/nine-dim-palettes.ts +1274 -0
- package/src/theme/theme-tokens.ts +17 -3
package/src/app/app-config.ts
CHANGED
|
@@ -3,19 +3,258 @@
|
|
|
3
3
|
import type { KitDiagnostic } from '../object-renderer/types';
|
|
4
4
|
import { parseKitEnvelope, type KitEnvelope } from './envelope';
|
|
5
5
|
|
|
6
|
-
/**
|
|
6
|
+
/** 01 · 主题配色枚举(24 套全行业主题配色) */
|
|
7
|
+
export type KitThemePalette =
|
|
8
|
+
| 'CLASSIC_TECH_BLUE'
|
|
9
|
+
| 'BUSINESS_INDIGO_BLUE'
|
|
10
|
+
| 'FAR_MOUNTAIN_SKY'
|
|
11
|
+
| 'GLACIER_STEEL_BLUE'
|
|
12
|
+
| 'GOVERNMENT_RED'
|
|
13
|
+
| 'PROSPEROUS_CHINA_RED'
|
|
14
|
+
| 'AMBER_TERRACOTTA'
|
|
15
|
+
| 'GILT_BUSINESS_BROWN'
|
|
16
|
+
| 'FINANCIAL_EMERALD'
|
|
17
|
+
| 'BAMBOO_FOREST_CYAN'
|
|
18
|
+
| 'TURQUOISE_LAKE'
|
|
19
|
+
| 'OLIVE_EARTH_GREEN'
|
|
20
|
+
| 'INNOVATIVE_VIOLET'
|
|
21
|
+
| 'LILAC_TWILIGHT'
|
|
22
|
+
| 'CORAL_PEACH_PINK'
|
|
23
|
+
| 'NEBULA_PLUM_PURPLE'
|
|
24
|
+
| 'MINIMAL_MONOCHROME'
|
|
25
|
+
| 'INDUSTRIAL_STEEL_GRAY'
|
|
26
|
+
| 'WARM_XUAN_PAPER'
|
|
27
|
+
| 'MATCHA_EYE_CARE'
|
|
28
|
+
| 'DEEP_OCEAN_DARK'
|
|
29
|
+
| 'GEEK_VIOLET_DARK'
|
|
30
|
+
| 'OBSIDIAN_NIGHT_DARK'
|
|
31
|
+
| 'FOREST_PINE_DARK';
|
|
32
|
+
|
|
33
|
+
export const KIT_THEME_PALETTES: readonly KitThemePalette[] = [
|
|
34
|
+
'CLASSIC_TECH_BLUE',
|
|
35
|
+
'BUSINESS_INDIGO_BLUE',
|
|
36
|
+
'FAR_MOUNTAIN_SKY',
|
|
37
|
+
'GLACIER_STEEL_BLUE',
|
|
38
|
+
'GOVERNMENT_RED',
|
|
39
|
+
'PROSPEROUS_CHINA_RED',
|
|
40
|
+
'AMBER_TERRACOTTA',
|
|
41
|
+
'GILT_BUSINESS_BROWN',
|
|
42
|
+
'FINANCIAL_EMERALD',
|
|
43
|
+
'BAMBOO_FOREST_CYAN',
|
|
44
|
+
'TURQUOISE_LAKE',
|
|
45
|
+
'OLIVE_EARTH_GREEN',
|
|
46
|
+
'INNOVATIVE_VIOLET',
|
|
47
|
+
'LILAC_TWILIGHT',
|
|
48
|
+
'CORAL_PEACH_PINK',
|
|
49
|
+
'NEBULA_PLUM_PURPLE',
|
|
50
|
+
'MINIMAL_MONOCHROME',
|
|
51
|
+
'INDUSTRIAL_STEEL_GRAY',
|
|
52
|
+
'WARM_XUAN_PAPER',
|
|
53
|
+
'MATCHA_EYE_CARE',
|
|
54
|
+
'DEEP_OCEAN_DARK',
|
|
55
|
+
'GEEK_VIOLET_DARK',
|
|
56
|
+
'OBSIDIAN_NIGHT_DARK',
|
|
57
|
+
'FOREST_PINE_DARK',
|
|
58
|
+
];
|
|
59
|
+
|
|
60
|
+
/** 02 · 颜色深浅枚举(5 档,在当前主题配色基础上调淡或调深) */
|
|
61
|
+
export type KitThemeColorDepth =
|
|
62
|
+
| 'NORMAL'
|
|
63
|
+
| 'LIGHTENED'
|
|
64
|
+
| 'DARKENED'
|
|
65
|
+
| 'VERY_LIGHT'
|
|
66
|
+
| 'SLIGHTLY_LIGHT'
|
|
67
|
+
| 'STANDARD_DEPTH'
|
|
68
|
+
| 'SLIGHTLY_DEEP'
|
|
69
|
+
| 'VERY_DEEP';
|
|
70
|
+
|
|
71
|
+
export const KIT_THEME_COLOR_DEPTHS: readonly KitThemeColorDepth[] = [
|
|
72
|
+
'NORMAL',
|
|
73
|
+
'LIGHTENED',
|
|
74
|
+
'DARKENED',
|
|
75
|
+
'VERY_LIGHT',
|
|
76
|
+
'SLIGHTLY_LIGHT',
|
|
77
|
+
'STANDARD_DEPTH',
|
|
78
|
+
'SLIGHTLY_DEEP',
|
|
79
|
+
'VERY_DEEP',
|
|
80
|
+
];
|
|
81
|
+
|
|
82
|
+
/** 03 · 颜色鲜艳度枚举(4 档) */
|
|
83
|
+
export type KitThemeColorSaturation =
|
|
84
|
+
| 'VIVID'
|
|
85
|
+
| 'STANDARD_SATURATION'
|
|
86
|
+
| 'SOFT_MUTED'
|
|
87
|
+
| 'LOW_COLOR';
|
|
88
|
+
|
|
89
|
+
export const KIT_THEME_COLOR_SATURATIONS: readonly KitThemeColorSaturation[] = [
|
|
90
|
+
'VIVID',
|
|
91
|
+
'STANDARD_SATURATION',
|
|
92
|
+
'SOFT_MUTED',
|
|
93
|
+
'LOW_COLOR',
|
|
94
|
+
];
|
|
95
|
+
|
|
96
|
+
/** 04 · 字体类型枚举(6 种) */
|
|
97
|
+
export type KitThemeFontFamily =
|
|
98
|
+
| 'SYSTEM_SANS'
|
|
99
|
+
| 'GEOMETRIC_ROUNDED'
|
|
100
|
+
| 'INDUSTRIAL_REPORT'
|
|
101
|
+
| 'EDITORIAL_SERIF'
|
|
102
|
+
| 'GEEK_MONO'
|
|
103
|
+
| 'BOLD_DISPLAY';
|
|
104
|
+
|
|
105
|
+
export const KIT_THEME_FONT_FAMILIES: readonly KitThemeFontFamily[] = [
|
|
106
|
+
'SYSTEM_SANS',
|
|
107
|
+
'GEOMETRIC_ROUNDED',
|
|
108
|
+
'INDUSTRIAL_REPORT',
|
|
109
|
+
'EDITORIAL_SERIF',
|
|
110
|
+
'GEEK_MONO',
|
|
111
|
+
'BOLD_DISPLAY',
|
|
112
|
+
];
|
|
113
|
+
|
|
114
|
+
/** 05 · 字体大小与行距枚举(4 档) */
|
|
115
|
+
export type KitThemeFontScale =
|
|
116
|
+
| 'SMALL_COMPACT'
|
|
117
|
+
| 'MEDIUM_STANDARD'
|
|
118
|
+
| 'LARGE_LOOSE'
|
|
119
|
+
| 'XLARGE_DISPLAY';
|
|
120
|
+
|
|
121
|
+
export const KIT_THEME_FONT_SCALES: readonly KitThemeFontScale[] = [
|
|
122
|
+
'SMALL_COMPACT',
|
|
123
|
+
'MEDIUM_STANDARD',
|
|
124
|
+
'LARGE_LOOSE',
|
|
125
|
+
'XLARGE_DISPLAY',
|
|
126
|
+
];
|
|
127
|
+
|
|
128
|
+
/** 06 · 组件边界方案枚举(严格二选一) */
|
|
129
|
+
export type KitThemeBoundary =
|
|
130
|
+
| 'HAIRLINE_BORDER'
|
|
131
|
+
| 'BORDERLESS_SHADOW';
|
|
132
|
+
|
|
133
|
+
export const KIT_THEME_BOUNDARIES: readonly KitThemeBoundary[] = [
|
|
134
|
+
'HAIRLINE_BORDER',
|
|
135
|
+
'BORDERLESS_SHADOW',
|
|
136
|
+
];
|
|
137
|
+
|
|
138
|
+
/** 07 · 组件圆角与形状枚举(4 档) */
|
|
139
|
+
export type KitThemeShape =
|
|
140
|
+
| 'STANDARD_ROUNDED'
|
|
141
|
+
| 'SMALL_SHARP'
|
|
142
|
+
| 'PILL_CAPSULE'
|
|
143
|
+
| 'PURE_SQUARE';
|
|
144
|
+
|
|
145
|
+
export const KIT_THEME_SHAPES: readonly KitThemeShape[] = [
|
|
146
|
+
'STANDARD_ROUNDED',
|
|
147
|
+
'SMALL_SHARP',
|
|
148
|
+
'PILL_CAPSULE',
|
|
149
|
+
'PURE_SQUARE',
|
|
150
|
+
];
|
|
151
|
+
|
|
152
|
+
/** 08 · 组件表面质感枚举(3 档) */
|
|
153
|
+
export type KitThemeSurfaceTexture =
|
|
154
|
+
| 'SOLID_MATTE'
|
|
155
|
+
| 'FROSTED_GLASS'
|
|
156
|
+
| 'SUBTLE_RELIEF';
|
|
157
|
+
|
|
158
|
+
export const KIT_THEME_SURFACE_TEXTURES: readonly KitThemeSurfaceTexture[] = [
|
|
159
|
+
'SOLID_MATTE',
|
|
160
|
+
'FROSTED_GLASS',
|
|
161
|
+
'SUBTLE_RELIEF',
|
|
162
|
+
];
|
|
163
|
+
|
|
164
|
+
/** 09 · 空间松紧度枚举(3 档,兼容旧值) */
|
|
165
|
+
export type KitThemeDensity =
|
|
166
|
+
| 'COMPACT_DENSE'
|
|
167
|
+
| 'STANDARD_BALANCED'
|
|
168
|
+
| 'SPACIOUS_AIRY'
|
|
169
|
+
| 'compact'
|
|
170
|
+
| 'comfortable'
|
|
171
|
+
| 'spacious'
|
|
172
|
+
| 'standard';
|
|
173
|
+
|
|
174
|
+
export const KIT_THEME_DENSITIES: readonly KitThemeDensity[] = [
|
|
175
|
+
'COMPACT_DENSE',
|
|
176
|
+
'STANDARD_BALANCED',
|
|
177
|
+
'SPACIOUS_AIRY',
|
|
178
|
+
'compact',
|
|
179
|
+
'comfortable',
|
|
180
|
+
'spacious',
|
|
181
|
+
'standard',
|
|
182
|
+
];
|
|
183
|
+
|
|
184
|
+
/** kit.app.yaml 的 theme 段(9 维正交页面主题 DSL 规格 + 基础编译可选兼容字段) */
|
|
7
185
|
export interface KitAppTheme {
|
|
186
|
+
/** 01 · 主题配色枚举(24 套全行业主题配色) */
|
|
187
|
+
palette?: KitThemePalette;
|
|
188
|
+
/** 02 · 颜色深浅枚举(5 档) */
|
|
189
|
+
color_depth?: KitThemeColorDepth;
|
|
190
|
+
colorDepth?: KitThemeColorDepth;
|
|
191
|
+
/** 03 · 颜色鲜艳度枚举(4 档) */
|
|
192
|
+
color_saturation?: KitThemeColorSaturation;
|
|
193
|
+
colorSaturation?: KitThemeColorSaturation;
|
|
194
|
+
/** 04 · 字体类型枚举(6 种) */
|
|
195
|
+
font_family?: KitThemeFontFamily;
|
|
196
|
+
fontFamily?: KitThemeFontFamily;
|
|
197
|
+
/** 05 · 字体大小与行距枚举(4 档) */
|
|
198
|
+
font_scale?: KitThemeFontScale;
|
|
199
|
+
fontScale?: KitThemeFontScale;
|
|
200
|
+
/** 06 · 组件边界方案枚举(严格二选一) */
|
|
201
|
+
boundary?: KitThemeBoundary;
|
|
202
|
+
/** 07 · 组件圆角与形状枚举(4 档) */
|
|
203
|
+
shape?: KitThemeShape;
|
|
204
|
+
/** 08 · 组件表面质感枚举(3 档) */
|
|
205
|
+
surface_texture?: KitThemeSurfaceTexture;
|
|
206
|
+
surfaceTexture?: KitThemeSurfaceTexture;
|
|
207
|
+
/** 09 · 空间松紧度枚举(3 档,兼容旧值) */
|
|
208
|
+
density?: KitThemeDensity;
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
/** 保留基础 preset/polarity/density/radius 作为底层编译可选兼容字段 */
|
|
212
|
+
preset?: string;
|
|
213
|
+
polarity?: string;
|
|
214
|
+
radius?: string;
|
|
215
|
+
mode?: string;
|
|
216
|
+
color?: string;
|
|
8
217
|
paletteScheme?: string;
|
|
9
218
|
fontScheme?: string;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
219
|
+
colorScheme?: string;
|
|
220
|
+
tone?: string;
|
|
221
|
+
typographyScheme?: string;
|
|
222
|
+
componentStyle?: string;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
export interface KitAppLayoutNavItem {
|
|
226
|
+
id: string;
|
|
227
|
+
label: string;
|
|
228
|
+
href?: string;
|
|
229
|
+
url?: string;
|
|
230
|
+
icon?: string;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
export interface KitAppLayout {
|
|
234
|
+
frame?: string;
|
|
235
|
+
maxWidth?: 'narrow' | 'medium' | 'wide' | 'full';
|
|
236
|
+
stickyHeader?: boolean;
|
|
237
|
+
header?: {
|
|
238
|
+
brand?: { text: string; href?: string };
|
|
239
|
+
nav?: KitAppLayoutNavItem[];
|
|
240
|
+
actions?: KitAppLayoutNavItem[];
|
|
241
|
+
};
|
|
242
|
+
sidebar?: {
|
|
243
|
+
title?: string;
|
|
244
|
+
width?: number;
|
|
245
|
+
menu?: KitAppLayoutNavItem[];
|
|
246
|
+
};
|
|
247
|
+
footer?: {
|
|
248
|
+
text?: string;
|
|
249
|
+
links?: Array<{ label: string; href: string }>;
|
|
250
|
+
};
|
|
14
251
|
}
|
|
15
252
|
|
|
16
253
|
export interface KitAppConfig {
|
|
17
|
-
/**
|
|
254
|
+
/** 主题:9 维正交页面主题 DSL 规格或基础方案 */
|
|
18
255
|
theme?: KitAppTheme;
|
|
256
|
+
/** 默认页面布局配置:继承给子页面 */
|
|
257
|
+
layout?: KitAppLayout;
|
|
19
258
|
/** 主题头文件路径(相对应用根);缺省用内置 kit-theme.css */
|
|
20
259
|
style?: string;
|
|
21
260
|
/** 应用扩展的基础组件:名字 -> 说明 */
|
|
@@ -27,10 +266,48 @@ export interface KitAppConfig {
|
|
|
27
266
|
}
|
|
28
267
|
|
|
29
268
|
const APP_NAME = /^App[A-Z][A-Za-z0-9]*$/;
|
|
30
|
-
const TOP_KEYS = ['style', 'theme', 'baseComponents', 'staticObjectComponents', 'envelope'];
|
|
31
|
-
const THEME_KEYS = [
|
|
32
|
-
|
|
269
|
+
const TOP_KEYS = ['style', 'theme', 'layout', 'baseComponents', 'staticObjectComponents', 'envelope'];
|
|
270
|
+
const THEME_KEYS = [
|
|
271
|
+
'palette',
|
|
272
|
+
'color_depth',
|
|
273
|
+
'colorDepth',
|
|
274
|
+
'color_saturation',
|
|
275
|
+
'colorSaturation',
|
|
276
|
+
'font_family',
|
|
277
|
+
'fontFamily',
|
|
278
|
+
'font_scale',
|
|
279
|
+
'fontScale',
|
|
280
|
+
'boundary',
|
|
281
|
+
'shape',
|
|
282
|
+
'surface_texture',
|
|
283
|
+
'surfaceTexture',
|
|
284
|
+
'density',
|
|
285
|
+
'preset',
|
|
286
|
+
'polarity',
|
|
287
|
+
'radius',
|
|
288
|
+
'mode',
|
|
289
|
+
'color',
|
|
290
|
+
'palette_scheme',
|
|
291
|
+
'paletteScheme',
|
|
292
|
+
'font_scheme',
|
|
293
|
+
'fontScheme',
|
|
294
|
+
'color_scheme',
|
|
295
|
+
'colorScheme',
|
|
296
|
+
'tone',
|
|
297
|
+
'typography_scheme',
|
|
298
|
+
'typographyScheme',
|
|
299
|
+
'component_style',
|
|
300
|
+
'componentStyle',
|
|
301
|
+
];
|
|
33
302
|
const STATIC_KEYS = ['accept', 'desc'];
|
|
303
|
+
const LAYOUT_TOP_KEYS = ['frame', 'max_width', 'sticky_header', 'header', 'sidebar', 'footer'];
|
|
304
|
+
const MAX_WIDTH_VALUES = ['narrow', 'medium', 'wide', 'full'] as const;
|
|
305
|
+
const LAYOUT_HEADER_KEYS = ['brand', 'nav', 'actions'];
|
|
306
|
+
const LAYOUT_SIDEBAR_KEYS = ['title', 'width', 'menu'];
|
|
307
|
+
const LAYOUT_FOOTER_KEYS = ['text', 'links'];
|
|
308
|
+
const NAV_ITEM_KEYS = ['id', 'label', 'href', 'url', 'icon'];
|
|
309
|
+
const BRAND_KEYS = ['text', 'href'];
|
|
310
|
+
const FOOTER_LINK_KEYS = ['label', 'href'];
|
|
34
311
|
|
|
35
312
|
function isRecord(v: unknown): v is Record<string, unknown> {
|
|
36
313
|
return v !== null && typeof v === 'object' && !Array.isArray(v);
|
|
@@ -40,6 +317,38 @@ function bad(path: string, message: string, out: KitDiagnostic[]): void {
|
|
|
40
317
|
out.push({ code: 'KIT-APP-001', path, message });
|
|
41
318
|
}
|
|
42
319
|
|
|
320
|
+
function parseNavItem(raw: unknown, path: string, diagnostics: KitDiagnostic[]): KitAppLayoutNavItem | undefined {
|
|
321
|
+
if (!isRecord(raw)) {
|
|
322
|
+
bad(path, `${path} 必须是对象 { id, label, href?, url?, icon? }`, diagnostics);
|
|
323
|
+
return undefined;
|
|
324
|
+
}
|
|
325
|
+
for (const k of Object.keys(raw)) {
|
|
326
|
+
if (!NAV_ITEM_KEYS.includes(k)) bad(`${path}.${k}`, `未知键 ${k}(允许:${NAV_ITEM_KEYS.join(' / ')})`, diagnostics);
|
|
327
|
+
}
|
|
328
|
+
if (typeof raw.id !== 'string' || raw.id.trim() === '') {
|
|
329
|
+
bad(`${path}.id`, 'id 必须是非空字符串', diagnostics);
|
|
330
|
+
return undefined;
|
|
331
|
+
}
|
|
332
|
+
if (typeof raw.label !== 'string' || raw.label.trim() === '') {
|
|
333
|
+
bad(`${path}.label`, 'label 必须是非空字符串', diagnostics);
|
|
334
|
+
return undefined;
|
|
335
|
+
}
|
|
336
|
+
const item: KitAppLayoutNavItem = { id: raw.id.trim(), label: raw.label.trim() };
|
|
337
|
+
if (raw.href !== undefined) {
|
|
338
|
+
if (typeof raw.href === 'string') item.href = raw.href;
|
|
339
|
+
else bad(`${path}.href`, 'href 必须是字符串', diagnostics);
|
|
340
|
+
}
|
|
341
|
+
if (raw.url !== undefined) {
|
|
342
|
+
if (typeof raw.url === 'string') item.url = raw.url;
|
|
343
|
+
else bad(`${path}.url`, 'url 必须是字符串', diagnostics);
|
|
344
|
+
}
|
|
345
|
+
if (raw.icon !== undefined) {
|
|
346
|
+
if (typeof raw.icon === 'string') item.icon = raw.icon;
|
|
347
|
+
else bad(`${path}.icon`, 'icon 必须是字符串', diagnostics);
|
|
348
|
+
}
|
|
349
|
+
return item;
|
|
350
|
+
}
|
|
351
|
+
|
|
43
352
|
/** 检查并规整 kit.app.yaml(已解析对象)。raw 为 undefined / null 视为空配置 */
|
|
44
353
|
export function parseAppConfig(raw: unknown, diagnostics: KitDiagnostic[]): KitAppConfig {
|
|
45
354
|
const cfg: KitAppConfig = { baseComponents: {}, staticObjectComponents: {} };
|
|
@@ -60,24 +369,253 @@ export function parseAppConfig(raw: unknown, diagnostics: KitDiagnostic[]): KitA
|
|
|
60
369
|
if (envelope !== undefined) cfg.envelope = envelope;
|
|
61
370
|
}
|
|
62
371
|
if (raw.theme !== undefined) {
|
|
63
|
-
if (!isRecord(raw.theme)) bad('kit.app.yaml.theme', 'theme
|
|
372
|
+
if (!isRecord(raw.theme)) bad('kit.app.yaml.theme', 'theme 必须是对象', diagnostics);
|
|
64
373
|
else {
|
|
65
374
|
const theme: KitAppTheme = {};
|
|
66
375
|
for (const [k, v] of Object.entries(raw.theme)) {
|
|
67
|
-
if (!THEME_KEYS.includes(k))
|
|
68
|
-
|
|
69
|
-
else if (
|
|
70
|
-
|
|
71
|
-
else
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
376
|
+
if (!THEME_KEYS.includes(k)) {
|
|
377
|
+
bad(`kit.app.yaml.theme.${k}`, `未知键 ${k}(允许:${THEME_KEYS.join(' / ')})`, diagnostics);
|
|
378
|
+
} else if (typeof v !== 'string' || v.trim() === '') {
|
|
379
|
+
bad(`kit.app.yaml.theme.${k}`, `${k} 必须是非空字符串`, diagnostics);
|
|
380
|
+
} else {
|
|
381
|
+
const val = v.trim();
|
|
382
|
+
if (k === 'palette') {
|
|
383
|
+
if (!(KIT_THEME_PALETTES as readonly string[]).includes(val)) {
|
|
384
|
+
bad('kit.app.yaml.theme.palette', `palette「${val}」只能是 ${KIT_THEME_PALETTES.join(' / ')}`, diagnostics);
|
|
385
|
+
} else {
|
|
386
|
+
theme.palette = val as KitThemePalette;
|
|
387
|
+
}
|
|
388
|
+
} else if (k === 'color_depth' || k === 'colorDepth') {
|
|
389
|
+
if (!(KIT_THEME_COLOR_DEPTHS as readonly string[]).includes(val)) {
|
|
390
|
+
bad(`kit.app.yaml.theme.${k}`, `${k}「${val}」只能是 ${KIT_THEME_COLOR_DEPTHS.join(' / ')}`, diagnostics);
|
|
391
|
+
} else {
|
|
392
|
+
theme.color_depth = val as KitThemeColorDepth;
|
|
393
|
+
theme.colorDepth = val as KitThemeColorDepth;
|
|
394
|
+
}
|
|
395
|
+
} else if (k === 'color_saturation' || k === 'colorSaturation') {
|
|
396
|
+
if (!(KIT_THEME_COLOR_SATURATIONS as readonly string[]).includes(val)) {
|
|
397
|
+
bad(`kit.app.yaml.theme.${k}`, `${k}「${val}」只能是 ${KIT_THEME_COLOR_SATURATIONS.join(' / ')}`, diagnostics);
|
|
398
|
+
} else {
|
|
399
|
+
theme.color_saturation = val as KitThemeColorSaturation;
|
|
400
|
+
theme.colorSaturation = val as KitThemeColorSaturation;
|
|
401
|
+
}
|
|
402
|
+
} else if (k === 'font_family' || k === 'fontFamily') {
|
|
403
|
+
if (!(KIT_THEME_FONT_FAMILIES as readonly string[]).includes(val)) {
|
|
404
|
+
bad(`kit.app.yaml.theme.${k}`, `${k}「${val}」只能是 ${KIT_THEME_FONT_FAMILIES.join(' / ')}`, diagnostics);
|
|
405
|
+
} else {
|
|
406
|
+
theme.font_family = val as KitThemeFontFamily;
|
|
407
|
+
theme.fontFamily = val as KitThemeFontFamily;
|
|
408
|
+
}
|
|
409
|
+
} else if (k === 'font_scale' || k === 'fontScale') {
|
|
410
|
+
if (!(KIT_THEME_FONT_SCALES as readonly string[]).includes(val)) {
|
|
411
|
+
bad(`kit.app.yaml.theme.${k}`, `${k}「${val}」只能是 ${KIT_THEME_FONT_SCALES.join(' / ')}`, diagnostics);
|
|
412
|
+
} else {
|
|
413
|
+
theme.font_scale = val as KitThemeFontScale;
|
|
414
|
+
theme.fontScale = val as KitThemeFontScale;
|
|
415
|
+
}
|
|
416
|
+
} else if (k === 'boundary') {
|
|
417
|
+
if (!(KIT_THEME_BOUNDARIES as readonly string[]).includes(val)) {
|
|
418
|
+
bad('kit.app.yaml.theme.boundary', `boundary「${val}」只能是 ${KIT_THEME_BOUNDARIES.join(' / ')}`, diagnostics);
|
|
419
|
+
} else {
|
|
420
|
+
theme.boundary = val as KitThemeBoundary;
|
|
421
|
+
}
|
|
422
|
+
} else if (k === 'shape') {
|
|
423
|
+
if (!(KIT_THEME_SHAPES as readonly string[]).includes(val)) {
|
|
424
|
+
bad('kit.app.yaml.theme.shape', `shape「${val}」只能是 ${KIT_THEME_SHAPES.join(' / ')}`, diagnostics);
|
|
425
|
+
} else {
|
|
426
|
+
theme.shape = val as KitThemeShape;
|
|
427
|
+
}
|
|
428
|
+
} else if (k === 'surface_texture' || k === 'surfaceTexture') {
|
|
429
|
+
if (!(KIT_THEME_SURFACE_TEXTURES as readonly string[]).includes(val)) {
|
|
430
|
+
bad(`kit.app.yaml.theme.${k}`, `${k}「${val}」只能是 ${KIT_THEME_SURFACE_TEXTURES.join(' / ')}`, diagnostics);
|
|
431
|
+
} else {
|
|
432
|
+
theme.surface_texture = val as KitThemeSurfaceTexture;
|
|
433
|
+
theme.surfaceTexture = val as KitThemeSurfaceTexture;
|
|
434
|
+
}
|
|
435
|
+
} else if (k === 'density') {
|
|
436
|
+
if (!(KIT_THEME_DENSITIES as readonly string[]).includes(val)) {
|
|
437
|
+
bad('kit.app.yaml.theme.density', `density「${val}」只能是 ${KIT_THEME_DENSITIES.join(' / ')}`, diagnostics);
|
|
438
|
+
} else {
|
|
439
|
+
theme.density = val as KitThemeDensity;
|
|
440
|
+
}
|
|
441
|
+
} else if (k === 'preset') {
|
|
442
|
+
theme.preset = val;
|
|
443
|
+
} else if (k === 'polarity') {
|
|
444
|
+
theme.polarity = val;
|
|
445
|
+
} else if (k === 'radius') {
|
|
446
|
+
theme.radius = val;
|
|
447
|
+
} else if (k === 'palette_scheme' || k === 'paletteScheme') {
|
|
448
|
+
theme.paletteScheme = val;
|
|
449
|
+
} else if (k === 'font_scheme' || k === 'fontScheme') {
|
|
450
|
+
theme.fontScheme = val;
|
|
451
|
+
} else if (k === 'color') {
|
|
452
|
+
theme.color = val;
|
|
453
|
+
} else if (k === 'color_scheme' || k === 'colorScheme') {
|
|
454
|
+
theme.colorScheme = val;
|
|
455
|
+
} else if (k === 'tone') {
|
|
456
|
+
theme.tone = val;
|
|
457
|
+
} else if (k === 'typography_scheme' || k === 'typographyScheme') {
|
|
458
|
+
theme.typographyScheme = val;
|
|
459
|
+
} else if (k === 'component_style' || k === 'componentStyle') {
|
|
460
|
+
theme.componentStyle = val;
|
|
461
|
+
} else if (k === 'mode') {
|
|
462
|
+
theme.mode = val;
|
|
463
|
+
}
|
|
464
|
+
}
|
|
77
465
|
}
|
|
78
466
|
cfg.theme = theme;
|
|
79
467
|
}
|
|
80
468
|
}
|
|
469
|
+
if (raw.layout !== undefined) {
|
|
470
|
+
if (!isRecord(raw.layout)) {
|
|
471
|
+
bad('kit.app.yaml.layout', 'layout 必须是对象', diagnostics);
|
|
472
|
+
} else {
|
|
473
|
+
for (const k of Object.keys(raw.layout)) {
|
|
474
|
+
if (!LAYOUT_TOP_KEYS.includes(k)) bad(`kit.app.yaml.layout.${k}`, `未知键 ${k}(允许:${LAYOUT_TOP_KEYS.join(' / ')})`, diagnostics);
|
|
475
|
+
}
|
|
476
|
+
const layout: KitAppLayout = {};
|
|
477
|
+
if (raw.layout.frame !== undefined) {
|
|
478
|
+
if (typeof raw.layout.frame === 'string' && raw.layout.frame.trim() !== '') layout.frame = raw.layout.frame.trim();
|
|
479
|
+
else bad('kit.app.yaml.layout.frame', 'frame 必须是非空字符串', diagnostics);
|
|
480
|
+
}
|
|
481
|
+
if (raw.layout.max_width !== undefined) {
|
|
482
|
+
const mw = typeof raw.layout.max_width === 'string' ? raw.layout.max_width.trim() : '';
|
|
483
|
+
if (!(MAX_WIDTH_VALUES as readonly string[]).includes(mw)) bad('kit.app.yaml.layout.max_width', `max_width「${String(raw.layout.max_width)}」只能是 ${MAX_WIDTH_VALUES.join(' / ')}`, diagnostics);
|
|
484
|
+
else layout.maxWidth = mw as 'narrow' | 'medium' | 'wide' | 'full';
|
|
485
|
+
}
|
|
486
|
+
if (raw.layout.sticky_header !== undefined) {
|
|
487
|
+
if (typeof raw.layout.sticky_header === 'boolean') layout.stickyHeader = raw.layout.sticky_header;
|
|
488
|
+
else bad('kit.app.yaml.layout.sticky_header', 'sticky_header 必须是布尔值', diagnostics);
|
|
489
|
+
}
|
|
490
|
+
if (raw.layout.header !== undefined) {
|
|
491
|
+
if (!isRecord(raw.layout.header)) {
|
|
492
|
+
bad('kit.app.yaml.layout.header', 'header 必须是对象', diagnostics);
|
|
493
|
+
} else {
|
|
494
|
+
for (const k of Object.keys(raw.layout.header)) {
|
|
495
|
+
if (!LAYOUT_HEADER_KEYS.includes(k)) bad(`kit.app.yaml.layout.header.${k}`, `未知键 ${k}(允许:${LAYOUT_HEADER_KEYS.join(' / ')})`, diagnostics);
|
|
496
|
+
}
|
|
497
|
+
const header: NonNullable<KitAppLayout['header']> = {};
|
|
498
|
+
if (raw.layout.header.brand !== undefined) {
|
|
499
|
+
if (!isRecord(raw.layout.header.brand)) {
|
|
500
|
+
bad('kit.app.yaml.layout.header.brand', 'brand 必须是对象', diagnostics);
|
|
501
|
+
} else {
|
|
502
|
+
for (const k of Object.keys(raw.layout.header.brand)) {
|
|
503
|
+
if (!BRAND_KEYS.includes(k)) bad(`kit.app.yaml.layout.header.brand.${k}`, `未知键 ${k}(允许:${BRAND_KEYS.join(' / ')})`, diagnostics);
|
|
504
|
+
}
|
|
505
|
+
if (typeof raw.layout.header.brand.text !== 'string' || raw.layout.header.brand.text.trim() === '') {
|
|
506
|
+
bad('kit.app.yaml.layout.header.brand.text', 'brand.text 必须是非空字符串', diagnostics);
|
|
507
|
+
} else {
|
|
508
|
+
header.brand = { text: raw.layout.header.brand.text.trim() };
|
|
509
|
+
if (raw.layout.header.brand.href !== undefined) {
|
|
510
|
+
if (typeof raw.layout.header.brand.href === 'string') header.brand.href = raw.layout.header.brand.href;
|
|
511
|
+
else bad('kit.app.yaml.layout.header.brand.href', 'brand.href 必须是字符串', diagnostics);
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
if (raw.layout.header.nav !== undefined) {
|
|
517
|
+
if (!Array.isArray(raw.layout.header.nav)) {
|
|
518
|
+
bad('kit.app.yaml.layout.header.nav', 'nav 必须是数组', diagnostics);
|
|
519
|
+
} else {
|
|
520
|
+
const nav: KitAppLayoutNavItem[] = [];
|
|
521
|
+
raw.layout.header.nav.forEach((it, i) => {
|
|
522
|
+
const parsed = parseNavItem(it, `kit.app.yaml.layout.header.nav[${i}]`, diagnostics);
|
|
523
|
+
if (parsed) nav.push(parsed);
|
|
524
|
+
});
|
|
525
|
+
header.nav = nav;
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
if (raw.layout.header.actions !== undefined) {
|
|
529
|
+
if (!Array.isArray(raw.layout.header.actions)) {
|
|
530
|
+
bad('kit.app.yaml.layout.header.actions', 'actions 必须是数组', diagnostics);
|
|
531
|
+
} else {
|
|
532
|
+
const actions: KitAppLayoutNavItem[] = [];
|
|
533
|
+
raw.layout.header.actions.forEach((it, i) => {
|
|
534
|
+
const parsed = parseNavItem(it, `kit.app.yaml.layout.header.actions[${i}]`, diagnostics);
|
|
535
|
+
if (parsed) actions.push(parsed);
|
|
536
|
+
});
|
|
537
|
+
header.actions = actions;
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
layout.header = header;
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
if (raw.layout.sidebar !== undefined) {
|
|
544
|
+
if (!isRecord(raw.layout.sidebar)) {
|
|
545
|
+
bad('kit.app.yaml.layout.sidebar', 'sidebar 必须是对象', diagnostics);
|
|
546
|
+
} else {
|
|
547
|
+
for (const k of Object.keys(raw.layout.sidebar)) {
|
|
548
|
+
if (!LAYOUT_SIDEBAR_KEYS.includes(k)) bad(`kit.app.yaml.layout.sidebar.${k}`, `未知键 ${k}(允许:${LAYOUT_SIDEBAR_KEYS.join(' / ')})`, diagnostics);
|
|
549
|
+
}
|
|
550
|
+
const sidebar: NonNullable<KitAppLayout['sidebar']> = {};
|
|
551
|
+
if (raw.layout.sidebar.title !== undefined) {
|
|
552
|
+
if (typeof raw.layout.sidebar.title === 'string') sidebar.title = raw.layout.sidebar.title;
|
|
553
|
+
else bad('kit.app.yaml.layout.sidebar.title', 'sidebar.title 必须是字符串', diagnostics);
|
|
554
|
+
}
|
|
555
|
+
if (raw.layout.sidebar.width !== undefined) {
|
|
556
|
+
if (typeof raw.layout.sidebar.width === 'number' && !Number.isNaN(raw.layout.sidebar.width)) sidebar.width = raw.layout.sidebar.width;
|
|
557
|
+
else bad('kit.app.yaml.layout.sidebar.width', 'sidebar.width 必须是数字', diagnostics);
|
|
558
|
+
}
|
|
559
|
+
if (raw.layout.sidebar.menu !== undefined) {
|
|
560
|
+
if (!Array.isArray(raw.layout.sidebar.menu)) {
|
|
561
|
+
bad('kit.app.yaml.layout.sidebar.menu', 'sidebar.menu 必须是数组', diagnostics);
|
|
562
|
+
} else {
|
|
563
|
+
const menu: KitAppLayoutNavItem[] = [];
|
|
564
|
+
raw.layout.sidebar.menu.forEach((it, i) => {
|
|
565
|
+
const parsed = parseNavItem(it, `kit.app.yaml.layout.sidebar.menu[${i}]`, diagnostics);
|
|
566
|
+
if (parsed) menu.push(parsed);
|
|
567
|
+
});
|
|
568
|
+
sidebar.menu = menu;
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
layout.sidebar = sidebar;
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
if (raw.layout.footer !== undefined) {
|
|
575
|
+
if (!isRecord(raw.layout.footer)) {
|
|
576
|
+
bad('kit.app.yaml.layout.footer', 'footer 必须是对象', diagnostics);
|
|
577
|
+
} else {
|
|
578
|
+
for (const k of Object.keys(raw.layout.footer)) {
|
|
579
|
+
if (!LAYOUT_FOOTER_KEYS.includes(k)) bad(`kit.app.yaml.layout.footer.${k}`, `未知键 ${k}(允许:${LAYOUT_FOOTER_KEYS.join(' / ')})`, diagnostics);
|
|
580
|
+
}
|
|
581
|
+
const footer: NonNullable<KitAppLayout['footer']> = {};
|
|
582
|
+
if (raw.layout.footer.text !== undefined) {
|
|
583
|
+
if (typeof raw.layout.footer.text === 'string') footer.text = raw.layout.footer.text;
|
|
584
|
+
else bad('kit.app.yaml.layout.footer.text', 'footer.text 必须是字符串', diagnostics);
|
|
585
|
+
}
|
|
586
|
+
if (raw.layout.footer.links !== undefined) {
|
|
587
|
+
if (!Array.isArray(raw.layout.footer.links)) {
|
|
588
|
+
bad('kit.app.yaml.layout.footer.links', 'footer.links 必须是数组', diagnostics);
|
|
589
|
+
} else {
|
|
590
|
+
const links: Array<{ label: string; href: string }> = [];
|
|
591
|
+
raw.layout.footer.links.forEach((link, i) => {
|
|
592
|
+
const lp = `kit.app.yaml.layout.footer.links[${i}]`;
|
|
593
|
+
if (!isRecord(link)) {
|
|
594
|
+
bad(lp, `${lp} 必须是对象 { label, href }`, diagnostics);
|
|
595
|
+
return;
|
|
596
|
+
}
|
|
597
|
+
for (const k of Object.keys(link)) {
|
|
598
|
+
if (!FOOTER_LINK_KEYS.includes(k)) bad(`${lp}.${k}`, `未知键 ${k}(允许:${FOOTER_LINK_KEYS.join(' / ')})`, diagnostics);
|
|
599
|
+
}
|
|
600
|
+
if (typeof link.label !== 'string' || link.label.trim() === '') {
|
|
601
|
+
bad(`${lp}.label`, 'label 必须是非空字符串', diagnostics);
|
|
602
|
+
return;
|
|
603
|
+
}
|
|
604
|
+
if (typeof link.href !== 'string' || link.href.trim() === '') {
|
|
605
|
+
bad(`${lp}.href`, 'href 必须是非空字符串', diagnostics);
|
|
606
|
+
return;
|
|
607
|
+
}
|
|
608
|
+
links.push({ label: link.label.trim(), href: link.href.trim() });
|
|
609
|
+
});
|
|
610
|
+
footer.links = links;
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
layout.footer = footer;
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
cfg.layout = layout;
|
|
617
|
+
}
|
|
618
|
+
}
|
|
81
619
|
if (raw.baseComponents !== undefined) {
|
|
82
620
|
if (!isRecord(raw.baseComponents)) bad('kit.app.yaml.baseComponents', 'baseComponents 必须是 { 名字: 说明 }', diagnostics);
|
|
83
621
|
else {
|